mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Slaby <jirislaby@kernel.org>
To: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
Cc: Nikolay Borisov <nik.borisov@suse.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Borislav Petkov <bp@alien8.de>,
	Peter Zijlstra <peterz@infradead.org>,
	Josh Poimboeuf <jpoimboe@kernel.org>,
	Ingo Molnar <mingo@redhat.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Daniel Sneddon <daniel.sneddon@linux.intel.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] x86/bugs: Use fixed addressing for VERW operand
Date: Thu, 29 Feb 2024 10:19:09 +0100	[thread overview]
Message-ID: <28205b59-50b8-4e05-b267-503179156431@kernel.org> (raw)
In-Reply-To: <20240229091428.lnbcvhm3udzl5jd5@desk>

On 29. 02. 24, 10:14, Pawan Gupta wrote:
> On Wed, Feb 28, 2024 at 05:39:27PM -0800, Pawan Gupta wrote:
>> On Tue, Feb 27, 2024 at 10:43:53AM +0100, Jiri Slaby wrote:
>>> On 27. 02. 24, 9:47, Nikolay Borisov wrote:
>>>>
>>>>
>>>> On 27.02.24 г. 1:52 ч., Pawan Gupta wrote:
>>>>> Macro used for MDS mitigation executes VERW with relative addressing for
>>>>> the operand. This is unnecessary and creates a problem for backports on
>>>>> older kernels that don't support relocations in alternatives. Relocation
>>>>> support was added by commit 270a69c4485d ("x86/alternative: Support
>>>>> relocations in alternatives"). Also asm for fixed addressing is much
>>>>> more cleaner than relative RIP addressing.
>>>>>
>>>>> Simplify the asm by using fixed addressing for VERW operand.
>>>>>
>>>>> Fixes: baf8361e5455 ("x86/bugs: Add asm helpers for executing VERW")
>>>>> Reported-by: Nikolay Borisov <nik.borisov@suse.com>
>>>>> Closes: https://lore.kernel.org/lkml/20558f89-299b-472e-9a96-171403a83bd6@suse.com/
>>>>> Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
>>>>> ---
>>>>>    arch/x86/include/asm/nospec-branch.h | 2 +-
>>>>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/arch/x86/include/asm/nospec-branch.h
>>>>> b/arch/x86/include/asm/nospec-branch.h
>>>>> index 2aa52cab1e46..ab19c7f1167b 100644
>>>>> --- a/arch/x86/include/asm/nospec-branch.h
>>>>> +++ b/arch/x86/include/asm/nospec-branch.h
>>>>> @@ -323,7 +323,7 @@
>>>>>     * Note: Only the memory operand variant of VERW clears the CPU
>>>>> buffers.
>>>>>     */
>>>>>    .macro CLEAR_CPU_BUFFERS
>>>>> -    ALTERNATIVE "", __stringify(verw _ASM_RIP(mds_verw_sel)),
>>>>> X86_FEATURE_CLEAR_CPU_BUF
>>>>> +    ALTERNATIVE "", __stringify(verw mds_verw_sel),
>>>>> X86_FEATURE_CLEAR_CPU_BUF
>>>>
>>>> Actually thinking about it more and discussing with Jiri (cc'ed), will
>>>> this work with KASLR enabled?
>>>
>>> I might of course be wrong. We appear to rely on the asm+linker here.
>>
>> You were right, with KASLR enabled, instructions with fixed addressing
>> in alternatives don't get relocated. I guess we will have to keep
>> rip-relative as is. Thanks for catching that.
> 
> Looks like this is not settled yet, it was naive of me to trust gdb on
> /proc/kcore earlier with KASLR enabled.
> 
> With the below debug patch it appears the relocation with fixed
> addresses is working as expected with KASLR enabled.

As I wrote already, asm+linker converts the fixed address to rip-rela 
anyway:

https://lore.kernel.org/all/fd8f2df0-563e-4f5c-aca4-bc92a14e9426@kernel.org/

I also raised questions in there:
====
The assembler generates a relocation for the fixed address anyway. And
the linker resolves it as rip-relative. At least the pair from my
binutils-2.42.

But if it generates a rip-relative address, is < 6.5 with no support of
rip-rel in alternatives still fine?

Another question: can we rely on the assembler to generate a relocation
and on the linker to resolve it as rip-relative?
====

thanks,
-- 
js
suse labs


  reply	other threads:[~2024-02-29  9:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-26 23:52 Pawan Gupta
2024-02-27  8:47 ` Nikolay Borisov
2024-02-27  9:43   ` Jiri Slaby
2024-02-29  1:39     ` Pawan Gupta
2024-02-29  9:14       ` Pawan Gupta
2024-02-29  9:19         ` Jiri Slaby [this message]
2024-02-29  9:34           ` Pawan Gupta
2024-02-29  2:03 ` Pawan Gupta

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=28205b59-50b8-4e05-b267-503179156431@kernel.org \
    --to=jirislaby@kernel.org \
    --cc=bp@alien8.de \
    --cc=daniel.sneddon@linux.intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=nik.borisov@suse.com \
    --cc=pawan.kumar.gupta@linux.intel.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --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®