From: Peter Zijlstra <peterz@infradead.org>
To: Uros Bizjak <ubizjak@gmail.com>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@kernel.org>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H. Peter Anvin" <hpa@zytor.com>,
kirill.shutemov@linux.intel.com
Subject: Re: [PATCH -tip] x86/mm: Use %RIP-relative address in untagged_addr()
Date: Fri, 17 Nov 2023 10:41:03 +0100 [thread overview]
Message-ID: <20231117094103.GM8262@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20231116191127.3446476-1-ubizjak@gmail.com>
On Thu, Nov 16, 2023 at 08:10:59PM +0100, Uros Bizjak wrote:
> %RIP-relative addresses are nowadays correctly handled in alternative
> instructions, so remove misleading comment and improve assembly to
> use %RIP-relative address.
Ha!, it might've been this exact case (and Kirill grumbling) that got me
to fix the alternative code :-)
> 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>
Acked-byL Peter Zijlstra (Intel) <peterz@infradaed.org>
> ---
> arch/x86/include/asm/uaccess_64.h | 11 ++++-------
> 1 file changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
> index f2c02e4469cc..01455c0b070c 100644
> --- a/arch/x86/include/asm/uaccess_64.h
> +++ b/arch/x86/include/asm/uaccess_64.h
> @@ -11,6 +11,7 @@
> #include <asm/alternative.h>
> #include <asm/cpufeatures.h>
> #include <asm/page.h>
> +#include <asm/percpu.h>
>
> #ifdef CONFIG_ADDRESS_MASKING
> /*
> @@ -18,14 +19,10 @@
> */
> 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;
> }
> --
> 2.41.0
>
next prev parent reply other threads:[~2023-11-17 9:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-16 19:10 Uros Bizjak
2023-11-17 9:41 ` Peter Zijlstra [this message]
2023-11-17 10:45 ` kirill.shutemov
2023-11-17 18:15 ` H. Peter Anvin
2023-11-17 19:43 ` Brian Gerst
2023-11-17 20:17 ` H. Peter Anvin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231117094103.GM8262@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=tglx@linutronix.de \
--cc=ubizjak@gmail.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®