arm64: kernel: Add support for Privileged Access Never
[cascardo/linux.git] / arch / arm64 / lib / copy_in_user.S
index 436bcc5..1b94661 100644 (file)
  */
 
 #include <linux/linkage.h>
+
+#include <asm/alternative.h>
 #include <asm/assembler.h>
+#include <asm/cpufeature.h>
+#include <asm/sysreg.h>
 
 /*
  * Copy from user space to user space (alignment handled by the hardware)
@@ -30,6 +34,8 @@
  *     x0 - bytes not copied
  */
 ENTRY(__copy_in_user)
+ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(0)), ARM64_HAS_PAN, \
+           CONFIG_ARM64_PAN)
        add     x5, x0, x2                      // upper user buffer boundary
        subs    x2, x2, #16
        b.mi    1f
@@ -58,6 +64,8 @@ USER(9f, strh w3, [x0], #2    )
 USER(9f, ldrb  w3, [x1]        )
 USER(9f, strb  w3, [x0]        )
 5:     mov     x0, #0
+ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(1)), ARM64_HAS_PAN, \
+           CONFIG_ARM64_PAN)
        ret
 ENDPROC(__copy_in_user)