mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Josh Poimboeuf <jpoimboe@kernel.org>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
	David.Kaplan@amd.com, Andrew.Cooper3@citrix.com,
	gregkh@linuxfoundation.org
Subject: Re: [RFC][PATCH 06/17] x86/cpu: Add SRSO untrain to retbleed=
Date: Wed, 9 Aug 2023 17:08:52 +0200	[thread overview]
Message-ID: <20230809150852.GS212435@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20230809142847.3prfwo6cclbydfep@treble>

On Wed, Aug 09, 2023 at 10:28:47AM -0400, Josh Poimboeuf wrote:
> On Wed, Aug 09, 2023 at 04:06:03PM +0200, Peter Zijlstra wrote:
> > On Wed, Aug 09, 2023 at 09:42:33AM -0400, Josh Poimboeuf wrote:
> > > On Wed, Aug 09, 2023 at 09:12:24AM +0200, Peter Zijlstra wrote:
> > > >  static enum retbleed_mitigation retbleed_mitigation __ro_after_init =
> > > > @@ -796,6 +802,10 @@ static int __init retbleed_parse_cmdline
> > > >  			retbleed_cmd = RETBLEED_CMD_AUTO;
> > > >  		} else if (!strcmp(str, "unret")) {
> > > >  			retbleed_cmd = RETBLEED_CMD_UNRET;
> > > > +		} else if (!strcmp(str, "srso")) {
> > > > +			retbleed_cmd = RETBLEED_CMD_UNRET_SRSO;
> > > > +		} else if (!strcmp(str, "srso_alias")) {
> > > > +			retbleed_cmd = RETBLEED_CMD_UNRET_SRSO_ALIAS;
> > > 
> > > It doesn't make sense for "srso_alias" to be a separate cmdline option,
> > > as that option is a model-dependent variant of the SRSO mitigation.
> > 
> > so what I did with retbleed, and what should be fixed here too (I
> > forgot) is run with:
> > 
> >   retbleed=force,unret
> > 
> > on any random machine (typically Intel, because I have a distinct lack
> > of AMD machines :-() and look at the life kernel image to see if all the
> > patching worked.
> > 
> > I suppose I should add:
> > 
> >   setup_force_cpu_bug(X86_BUG_SRSO);
> > 
> > to the 'force' option, then:
> > 
> >   retbleed=force,srso_alias
> > 
> > should function the same, irrespective of the hardware.
> > 
> > I'm also of the opinion that the kernel should do as told, even if it
> > doesn't make sense. If you tell it nonsense, you get to keep the pieces.
> > 
> > So in that light, yes I think we should have separate options.
> 
> What if I want the SRSO mitigation regardless of CPU model?

You mean, you want to say 'any of the SRSO things, you pick the right
version?'

Which means the user has an AMD machine, but can't be arsed to figure
out which and somehow doesn't want to use AUTO?




> > They should, the discussions we had back then explained the Zen1/2
> > retbleed case in quite some detail and the srso case matches that
> > exactly with the movabs. A larger instruction is used because we need a
> > larger embedded sequence of instructions, but otherwise it is identical.
> > 
> > The comments provided for srso_alias state the BTB is untrained using
> > the explicit aliasing.
> > 
> > That is to say, AFAIU any of this, yes both srso options untrain the BTB
> > and mitigate the earlier retbleed thing.
> > 
> > SRSO then goes one step further with the RAP/RSB clobber.
> 
> Ah, nice.  Please add that information somewhere (e.g., one of the
> commit logs).

The comment above zen_untrain_ret (or retbleed_untrain_ret as you've
christened it) not clear enough?

/*
 * Safety details here pertain to the AMD Zen{1,2} microarchitecture:
 * 1) The RET at retbleed_return_thunk must be on a 64 byte boundary, for
 *    alignment within the BTB.
 * 2) The instruction at retbleed_untrain_ret must contain, and not
 *    end with, the 0xc3 byte of the RET.
 * 3) STIBP must be enabled, or SMT disabled, to prevent the sibling thread
 *    from re-poisioning the BTB prediction.
 */


Hmm, when compared to:

	.align 64
	.skip 64 - (srso_safe_ret - srso_untrain_ret), 0xcc
SYM_START(srso_untrain_ret, SYM_L_GLOBAL, SYM_A_NONE)
ANNOTATE_NOENDBR
	.byte 0x48, 0xb8

SYM_INNER_LABEL(srso_safe_ret, SYM_L_GLOBAL)
	add $8, %_ASM_SP
	ret
	int3
	int3
	int3
	/* end of movabs */
	lfence
	jmp srso_return_thunk
	int3
SYM_CODE_END(srso_safe_ret)
SYM_FUNC_END(srso_untrain_ret)

Then we match 2, srso_safe_ret is strictly *inside* the movabs, that is,
it is not the first nor the last byte of the outer instruction.

However, we fail at 1, 'add $8, %rsp' sits at the boundary, not ret.

Anybody, help ?

  reply	other threads:[~2023-08-09 15:09 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-09  7:12 [RFC][PATCH 00/17] Fix up the recent SRSO patches Peter Zijlstra
2023-08-09  7:12 ` [RFC][PATCH 01/17] x86/alternative: Unconditional custom return thunk Peter Zijlstra
2023-08-09  9:31   ` Nikolay Borisov
2023-08-10 11:37   ` Borislav Petkov
2023-08-09  7:12 ` [RFC][PATCH 02/17] x86/cpu: Clean up SRSO return thunk mess Peter Zijlstra
2023-08-09 15:45   ` Nikolay Borisov
2023-08-10 11:51   ` Borislav Petkov
2023-08-10 12:37     ` Peter Zijlstra
2023-08-10 12:56       ` Borislav Petkov
2023-08-10 13:22         ` Peter Zijlstra
2023-08-11  7:01       ` Peter Zijlstra
2023-08-11 17:00         ` Nick Desaulniers
2023-08-12 11:20           ` Peter Zijlstra
2023-08-09  7:12 ` [RFC][PATCH 03/17] x86/cpu: Make srso_untrain_ret consistent Peter Zijlstra
2023-08-10 12:00   ` Borislav Petkov
2023-08-09  7:12 ` [RFC][PATCH 04/17] objtool/x86: Fix SRSO mess Peter Zijlstra
2023-08-10 12:06   ` Borislav Petkov
2023-08-10 12:48     ` Peter Zijlstra
2023-08-10 12:50       ` Peter Zijlstra
2023-08-10 15:02         ` Borislav Petkov
2023-08-10 15:22           ` Peter Zijlstra
2023-08-09  7:12 ` [RFC][PATCH 05/17] x86/cpu: Cleanup the untrain mess Peter Zijlstra
2023-08-09 12:51   ` Josh Poimboeuf
2023-08-09 13:12     ` Peter Zijlstra
2023-08-09 13:26       ` Peter Zijlstra
2023-08-12 18:30         ` Borislav Petkov
2023-08-09  7:12 ` [RFC][PATCH 06/17] x86/cpu: Add SRSO untrain to retbleed= Peter Zijlstra
2023-08-09 13:42   ` Josh Poimboeuf
2023-08-09 14:06     ` Peter Zijlstra
2023-08-09 14:28       ` Josh Poimboeuf
2023-08-09 15:08         ` Peter Zijlstra [this message]
2023-08-09 15:43           ` Josh Poimboeuf
2023-08-09 14:31     ` Andrew.Cooper3
2023-08-09 14:39       ` Josh Poimboeuf
2023-08-10 15:44   ` Borislav Petkov
2023-08-10 16:10     ` Josh Poimboeuf
2023-08-11 10:27       ` Borislav Petkov
2023-08-12 11:32         ` Peter Zijlstra
2023-08-12 12:12           ` Borislav Petkov
2023-08-14 15:45           ` David Laight
2023-08-12 11:24       ` Peter Zijlstra
2023-08-12 12:10         ` Borislav Petkov
2023-08-14 10:56           ` Peter Zijlstra
2023-08-09  7:12 ` [RFC][PATCH 07/17] x86/cpu/kvm: Provide UNTRAIN_RET_VM Peter Zijlstra
2023-08-09 13:50   ` Josh Poimboeuf
2023-08-09 14:06     ` Peter Zijlstra
2023-08-09 14:30       ` Josh Poimboeuf
2023-08-09 15:10         ` Peter Zijlstra
2023-08-13 10:36   ` Borislav Petkov
2023-08-14 10:35     ` Peter Zijlstra
2023-08-09  7:12 ` [RFC][PATCH 08/17] x86/cpu: Add IBPB on VMEXIT to retbleed= Peter Zijlstra
2023-08-09  7:12 ` [RFC][PATCH 09/17] x86: Remove CONFIG_CPU_SRSO Peter Zijlstra
2023-08-09 13:57   ` Josh Poimboeuf
2023-08-09  7:12 ` [RFC][PATCH 10/17] x86: Remove CPU_IBPB_ENTRY Peter Zijlstra
2023-08-09  7:12 ` [RFC][PATCH 11/17] x86/cpu: Remove all SRSO interface nonsense Peter Zijlstra
2023-08-09 13:10   ` Andrew.Cooper3
2023-08-09 13:36     ` Peter Zijlstra
2023-08-09 14:05   ` Josh Poimboeuf
2023-08-09 14:43     ` Peter Zijlstra
2023-08-09 14:51       ` Josh Poimboeuf
2023-08-09 15:34   ` Josh Poimboeuf
2023-08-09  7:12 ` [RFC][PATCH 12/17] x86/cpu: Rename original retbleed return thunk Peter Zijlstra
2023-08-09 14:20   ` Josh Poimboeuf
2023-08-09 14:22     ` Peter Zijlstra
2023-08-10 11:06       ` Andrew.Cooper3
2023-08-10 13:02         ` Peter Zijlstra
2023-08-13 15:23           ` Andrew.Cooper3
2023-08-14 10:34             ` Peter Zijlstra
2023-08-14 11:31               ` Andrew.Cooper3
2023-08-14 12:06                 ` Peter Zijlstra
2023-08-09  7:12 ` [RFC][PATCH 13/17] objtool/x86: Add arch_is_offset_insn() Peter Zijlstra
2023-08-09  9:56   ` Nikolay Borisov
2023-08-09 14:34   ` Josh Poimboeuf
2023-08-09  7:12 ` [RFC][PATCH 14/17] objtool: Add comments to the arch_is_$foo() magic symbols Peter Zijlstra
2023-08-09  7:12 ` [RFC][PATCH 15/17] x86/cpu: Rename srso_(.*)_alias to srso_alias_\1 Peter Zijlstra
2023-08-09  7:12 ` [RFC][PATCH 16/17] x86/alternatives: Simplify ALTERNATIVE_n() Peter Zijlstra
2023-08-09  7:12 ` [RFC][PATCH 17/17] x86/cpu: Use fancy alternatives to get rid of entry_untrain_ret() Peter Zijlstra
2023-08-09  9:04 ` [RFC][PATCH 00/17] Fix up the recent SRSO patches Nikolay Borisov
2023-08-09 10:04 ` Andrew.Cooper3
2023-08-09 11:58   ` Peter Zijlstra

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=20230809150852.GS212435@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=Andrew.Cooper3@citrix.com \
    --cc=David.Kaplan@amd.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --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

Powered by JetHome