Skip to content

Commit de8c6a3

Browse files
ubizjakIngo Molnar
authored andcommitted
x86/percpu: Use %RIP-relative address in untagged_addr()
%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 <ubizjak@gmail.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Acked-by: Peter Zijlstra (Intel) <peterz@infradaed.org> Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Link: https://lore.kernel.org/all/20231213150357.5942-1-ubizjak%40gmail.com
1 parent 86ed430 commit de8c6a3

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

arch/x86/include/asm/uaccess_64.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,18 @@
1111
#include <asm/alternative.h>
1212
#include <asm/cpufeatures.h>
1313
#include <asm/page.h>
14+
#include <asm/percpu.h>
1415

1516
#ifdef CONFIG_ADDRESS_MASKING
1617
/*
1718
* Mask out tag bits from the address.
1819
*/
1920
static inline unsigned long __untagged_addr(unsigned long addr)
2021
{
21-
/*
22-
* Refer tlbstate_untag_mask directly to avoid RIP-relative relocation
23-
* in alternative instructions. The relocation gets wrong when gets
24-
* copied to the target place.
25-
*/
2622
asm (ALTERNATIVE("",
27-
"and %%gs:tlbstate_untag_mask, %[addr]\n\t", X86_FEATURE_LAM)
28-
: [addr] "+r" (addr) : "m" (tlbstate_untag_mask));
23+
"and " __percpu_arg([mask]) ", %[addr]", X86_FEATURE_LAM)
24+
: [addr] "+r" (addr)
25+
: [mask] "m" (__my_cpu_var(tlbstate_untag_mask)));
2926

3027
return addr;
3128
}

0 commit comments

Comments
 (0)