]> Git Repo - linux.git/commitdiff
x86/percpu: Use %RIP-relative address in untagged_addr()
authorUros Bizjak <[email protected]>
Wed, 13 Dec 2023 15:03:15 +0000 (16:03 +0100)
committerIngo Molnar <[email protected]>
Tue, 9 Jan 2024 08:39:15 +0000 (09:39 +0100)
%RIP-relative addresses are nowadays correctly handled in alternative
instructions, so remove misleading comment and improve assembly to
use %RIP-relative address.

Also, explicitly using %gs: prefix will segfault for non-SMP builds.
Use macros from percpu.h which will DTRT with segment prefix register
as far as SMP/non-SMP builds are concerned.

Signed-off-by: Uros Bizjak <[email protected]>
Signed-off-by: Dave Hansen <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
Acked-by: Peter Zijlstra (Intel) <[email protected]>
Acked-by: Kirill A. Shutemov <[email protected]>
Cc: Linus Torvalds <[email protected]>
Link: https://lore.kernel.org/all/20231213150357.5942-1-ubizjak%40gmail.com
arch/x86/include/asm/uaccess_64.h

index f2c02e4469ccc3db6265b2e36a6bd336f5e822fc..01455c0b070ccee053f6de67ec86e4ac20676c41 100644 (file)
@@ -11,6 +11,7 @@
 #include <asm/alternative.h>
 #include <asm/cpufeatures.h>
 #include <asm/page.h>
+#include <asm/percpu.h>
 
 #ifdef CONFIG_ADDRESS_MASKING
 /*
  */
 static inline unsigned long __untagged_addr(unsigned long addr)
 {
-       /*
-        * Refer tlbstate_untag_mask directly to avoid RIP-relative relocation
-        * in alternative instructions. The relocation gets wrong when gets
-        * copied to the target place.
-        */
        asm (ALTERNATIVE("",
-                        "and %%gs:tlbstate_untag_mask, %[addr]\n\t", X86_FEATURE_LAM)
-            : [addr] "+r" (addr) : "m" (tlbstate_untag_mask));
+                        "and " __percpu_arg([mask]) ", %[addr]", X86_FEATURE_LAM)
+            : [addr] "+r" (addr)
+            : [mask] "m" (__my_cpu_var(tlbstate_untag_mask)));
 
        return addr;
 }
This page took 0.0582510000000001 seconds and 4 git commands to generate.