<div dir="ltr"><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 21, 2018 at 5:58 AM, Ram Pai <span dir="ltr"><<a href="mailto:linuxram@us.ibm.com" target="_blank">linuxram@us.ibm.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">On Fri, Mar 09, 2018 at 11:43:00AM +0800, Li Wang wrote:<br>
</span><span class="gmail-">> On Fri, Mar 9, 2018 at 12:45 AM, Ram Pai <[1]<a href="mailto:linuxram@us.ibm.com">linuxram@us.ibm.com</a>> wrote:<br>
><br>
> On Thu, Mar 08, 2018 at 11:19:12PM +1100, Michael Ellerman wrote:<br>
</span><div><div class="gmail-h5">> > Li Wang <[2]<a href="mailto:liwang@redhat.com">liwang@redhat.com</a>> writes:<br>
> > > Hi,<br>
> > ><br>
> > > ltp/mprotect04[1] crashed by SEGV_PKUERR on ppc64(LPAR on P730,<br>
> Power 8<br>
> > > 8247-22L) with kernel-v4.16.0-rc4.<br>
> > ><br>
> > > 10000000-10020000 r-xp 00000000 fd:00 167223 mprotect04<br>
> > > 10020000-10030000 r--p 00010000 fd:00 167223 mprotect04<br>
> > > 10030000-10040000 rw-p 00020000 fd:00 167223 mprotect04<br>
> > > 1001a380000-1001a3b0000 rw-p 00000000 00:00 0 [heap]<br>
> > > 7fffa6c60000-7fffa6c80000 --xp 00000000 00:00 0 <br>
> > ><br>
> > > &exec_func = 0x10030170<br>
> > ><br>
> > > &func = 0x7fffa6c60170<br>
> > ><br>
> > > While perform <br>
> > > "(*func)();" we get the<br>
> > > segmentation fault.<br>
> > > <br>
> > ><br>
> > > strace log:<br>
> > ><br>
> > > -------------------<br>
> > > mprotect(0x7fffaed00000, 131072, PROT_EXEC) = 0<br>
> > > rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0<br>
> > > --- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_PKUERR,<br>
> si_addr=0x7fffaed00170}<br>
> > > ---<br>
> ><br>
> > Looks like a bug to me.<br>
> ><br>
> > Please Cc linuxppc-dev on powerpc bugs.<br>
> ><br>
> > I also can't reproduce this failure on my machine.<br>
> > Not sure what's going on?<br>
><br>
> I could reproduce it on a power7 lpar. But not on a power8 lpar.<br>
><br>
> The problem seems to be that the cpu generates a key exception if<br>
> the page with Read/Write-disable-but-<wbr>execute-enable key is executed<br>
> on power7. If I enable read on that key, the exception disappears.<br>
><br>
> After adding read permission on that key, reproducer get PASS on my power8<br>
> machine too.<br>
> (mprotect(..,PROT_READ | PROT_EXEC))<br>
> <br>
><br>
> BTW: the testcase executes<br>
> mprotect(..,PROT_EXEC).<br>
> The mprotect(, PROT_EXEC) system call internally generates a<br>
> execute-only key and associates it with the pages in the address-range. <br>
><br>
> Now since Li Wang claims that he can reproduce it on power8 as well, i<br>
> am wondering if the slightly different cpu behavior is dependent on the<br>
> version of the firmware/microcode?<br>
><br>
> I also run this reproducer on series ppc kvm machines, but none of them<br>
> get the FAIL.<br>
> If you need some more HW info, pls let me know.<br>
<br>
</div></div>Hi Li,<br>
<br>
Can you try the following patch and see if it solves your problem.<br></blockquote><div><br><div style="font-family:monospace,monospace" class="gmail_default">It only works on power7 lpar machine.<br><br></div><div style="font-family:monospace,monospace" class="gmail_default">But for p8 lpar, it still get failure as that before, the thing I wondered is<br></div><div style="font-family:monospace,monospace" class="gmail_default">that why not disable the pkey_execute_disable_supported on p8 machine? <br><br></div><div style="font-family:monospace,monospace" class="gmail_default">I tried to modify your patch and get PASS with the mprotect04 test on power8 lpar machine.<br><br>--- a/arch/powerpc/mm/pkeys.c<br>+++ b/arch/powerpc/mm/pkeys.c<br>@@ -105,7 +105,9 @@ int pkey_initialize(void)<br> * The device tree cannot be relied to indicate support for<br> * execute_disable support. Instead we use a PVR check.<br> */<br>- if (pvr_version_is(PVR_POWER7) || pvr_version_is(PVR_POWER7p))<br>+ if (pvr_version_is(PVR_POWER7) || pvr_version_is(PVR_POWER7p) \<br>+ || pvr_version_is(PVR_POWER8E) || pvr_version_is(PVR_POWER8NVL) \<br>+ || pvr_version_is(PVR_POWER8))<br> pkey_execute_disable_supported = false;<br> else<br> pkey_execute_disable_supported = true;<br>@@ -395,7 +397,7 @@ int __arch_override_mprotect_pkey(struct vm_area_struct *vma, int prot,<br> * The requested protection is execute-only. Hence let's use an<br> * execute-only pkey.<br> */<br>- if (prot == PROT_EXEC) {<br>+ if (prot == PROT_EXEC && pkey_execute_disable_supported) {<br> pkey = execute_only_pkey(vma->vm_mm);<br> if (pkey > 0)<br> return pkey;<br><br></div><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
<br>
diff --git a/arch/powerpc/mm/pkeys.c b/arch/powerpc/mm/pkeys.c<br>
index c269817..184a10a 100644<br>
--- a/arch/powerpc/mm/pkeys.c<br>
+++ b/arch/powerpc/mm/pkeys.c<br>
@@ -421,7 +421,7 @@ int __arch_override_mprotect_pkey(<wbr>struct vm_area_struct *vma, int prot,<br>
* The requested protection is execute-only. Hence let's use an<br>
* execute-only pkey.<br>
*/<br>
- if (prot == PROT_EXEC) {<br>
<div style="font-family:monospace,monospace;display:inline" class="gmail_default"></div>+ if (prot == PROT_EXEC && pkey_execute_disable_<wbr>supported) {<br>
pkey = execute_only_pkey(vma->vm_mm);<br>
if (pkey > 0)<br>
return pkey;<br>
<br>
<br>
Thanks<br>
<span class="gmail-HOEnZb"><font color="#888888">RP<br>
<br>
</font></span></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature">Li Wang<br><a href="mailto:liwang@redhat.com" target="_blank">liwang@redhat.com</a></div>
</div></div>