POWER: Add context-synchronizing instructions to pkey_write [BZ #25954]

Message ID 878shyg4py.fsf@oldenburg2.str.redhat.com
State Committed
Headers
Series POWER: Add context-synchronizing instructions to pkey_write [BZ #25954] |

Commit Message

Florian Weimer May 11, 2020, 10:12 a.m. UTC
  Sandipan Das reported that,

"The Power ISA mandates that all writes to the Authority
Mask Register (AMR) must always be preceded as well as
succeeded by a context-synchronizing instruction. This
applies to both the privileged and unprivileged variants
of the Move To AMR instruction.

This [requirement] is from Table 6 of Chapter 11 in page 1134 of Power
ISA 3.0B. The document can be found here:
<https://ibm.ent.box.com/s/1hzcwkwf8rbju5h9iyf44wm94amnlcrv>
"

See this kernel patch submission:

<https://lore.kernel.org/linuxppc-dev/5f65cf37be993760de8112a88da194e3ccbb2bf8.1588959697.git.sandipan@linux.ibm.com/>

Tested on powerpc64le-linux-gnu on a POWER9 system with disable_radix
and a compatible kernel (kernel-4.18.0-193.el8.ppc64le).

-----
 sysdeps/unix/sysv/linux/powerpc/powerpc64/arch-pkey.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Paul E Murphy May 11, 2020, 2:04 p.m. UTC | #1
On 5/11/20 5:12 AM, Florian Weimer via Libc-alpha wrote:

> @@ -37,7 +37,7 @@ pkey_read (void)
>   static inline void
>   pkey_write (unsigned long int value)
>   {
> -  __asm__ volatile ("mtspr 13, %0" : : "r" (value));
> +  __asm__ volatile ("isync; mtspr 13, %0; isync" : : "r" (value));
>   }
> 
>   /* Number of the largest supported key.  This depends on the width of

LGTM.
  
Lucas A. M. Magalhaes May 11, 2020, 2:08 p.m. UTC | #2
Thanks Florian.

LGTM

---
Lucas A. M. Magalhães
  

Patch

diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/arch-pkey.h b/sysdeps/unix/sysv/linux/powerpc/powerpc64/arch-pkey.h
index 623b073d5a..25d080c9a6 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/arch-pkey.h
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/arch-pkey.h
@@ -37,7 +37,7 @@  pkey_read (void)
 static inline void
 pkey_write (unsigned long int value)
 {
-  __asm__ volatile ("mtspr 13, %0" : : "r" (value));
+  __asm__ volatile ("isync; mtspr 13, %0; isync" : : "r" (value));
 }
 
 /* Number of the largest supported key.  This depends on the width of