apply FEAT_LSUI instruction to emulate deprecated swpX instruction.
Signed-off-by: Yeoreum Yun <[email protected]>
---
arch/arm64/kernel/armv8_deprecated.c | 52 ++++++++++++++++++++++++++--
1 file changed, 50 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/kernel/armv8_deprecated.c
b/arch/arm64/kernel/armv8_deprecated.c
index d15e35f1075c..424cf51d554f 100644
--- a/arch/arm64/kernel/armv8_deprecated.c
+++ b/arch/arm64/kernel/armv8_deprecated.c
@@ -13,6 +13,7 @@
#include <linux/uaccess.h>
#include <asm/cpufeature.h>
+#include <asm/lsui.h>
#include <asm/insn.h>
#include <asm/sysreg.h>
#include <asm/system_misc.h>
@@ -86,6 +87,53 @@ static unsigned int __maybe_unused
aarch32_check_condition(u32 opcode, u32 psr)
* Rn = address
*/
+#ifdef CONFIG_AS_HAS_LSUI
+static __always_inline int
+__lsui_user_swp_asm(unsigned int *data, unsigned int addr)
+{
+ int err = 0;
+ unsigned int temp;
+
+ asm volatile("// __lsui_user_swp_asm\n"
+ __LSUI_PREAMBLE
+ "1: swpt %w1, %w2, [%3]\n"
+ " mov %w1, %w2\n"
+ "2:\n"
+ _ASM_EXTABLE_UACCESS_ERR(1b, 2b, %w0)
+ : "+r" (err), "+r" (*data), "=&r" (temp)
+ : "r" ((unsigned long)addr)
+ : "memory");
+
+ return err;
+}
+
+static __always_inline int
+__lsui_user_swpb_asm(unsigned int *data, unsigned int addr)
+{
+ unsigned char idx;
+ int err;
+ unsigned int addr_al;
+ union {
+ unsigned int var;
+ unsigned char raw[4];
+ } data_al;
+
+ idx = addr & (sizeof(unsigned int) - 1);
+ addr_al = ALIGN_DOWN(addr, sizeof(unsigned int));
+
+ if (get_user(data_al.var, (unsigned int *)(unsigned long)addr_al))
+ return -EFAULT;
+
+ data_al.raw[idx] = *data;
+
+ err = __lsui_user_swp_asm(&data_al.var, addr_al);
+ if (!err)
+ *data = data_al.raw[idx];
+
+ return err;
+}
+#endif /* CONFIG_AS_HAS_LSUI */
+
/*
* Error-checking SWP macros implemented using ldxr{b}/stxr{b}
*/
@@ -128,9 +176,9 @@ LLSC_USER_SWPX()
LLSC_USER_SWPX(b)
#define __user_swp_asm(data, addr) \
- __llsc_user_swp_asm(data, addr)
+ __lsui_llsc_body(user_swp_asm, data, addr)
#define __user_swpb_asm(data, addr) \
- __llsc_user_swpb_asm(data, addr)
+ __lsui_llsc_body(user_swpb_asm, data, addr)
/*
* Bit 22 of the instruction encoding distinguishes between
--
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}