All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Jim Mattson <jmattson@google.com>
Cc: kvm@vger.kernel.org, pbonzini@redhat.com
Subject: Re: [PATCH] KVM: VMX: Move VM-exit RSB stuffing out of line
Date: Mon, 27 Jun 2022 15:08:42 +0000	[thread overview]
Message-ID: <YrnH+nhnbhDFAMas@google.com> (raw)
In-Reply-To: <20220622222408.518889-1-jmattson@google.com>

On Wed, Jun 22, 2022, Jim Mattson wrote:
> RSB-stuffing after VM-exit is only needed for legacy CPUs without
> eIBRS. Move the RSB-stuffing code out of line.

I assume the primary justification is purely to avoid the JMP on modern CPUs?

> Preserve the non-sensical correlation of RSB-stuffing with retpoline.

Either omit the blurb about retpoline, or better yet expand on why it's nonsensical
and speculate a bit on why it got tied to retpoline? 

> Signed-off-by: Jim Mattson <jmattson@google.com>
> ---
>  arch/x86/kvm/vmx/vmenter.S | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/kvm/vmx/vmenter.S b/arch/x86/kvm/vmx/vmenter.S
> index 435c187927c4..39009a4c86bd 100644
> --- a/arch/x86/kvm/vmx/vmenter.S
> +++ b/arch/x86/kvm/vmx/vmenter.S
> @@ -76,7 +76,12 @@ SYM_FUNC_END(vmx_vmenter)
>   */
>  SYM_FUNC_START(vmx_vmexit)
>  #ifdef CONFIG_RETPOLINE
> -	ALTERNATIVE "jmp .Lvmexit_skip_rsb", "", X86_FEATURE_RETPOLINE
> +	ALTERNATIVE "", "jmp .Lvmexit_stuff_rsb", X86_FEATURE_RETPOLINE
> +#endif
> +.Lvmexit_return:
> +	RET
> +#ifdef CONFIG_RETPOLINE
> +.Lvmexit_stuff_rsb:
>  	/* Preserve guest's RAX, it's used to stuff the RSB. */
>  	push %_ASM_AX

There's a comment in the code here about stuffiing before RET, I think it makes
sense to keep that before the RET, i.e. hoist it out of the actual stuffing
sequence so that it looks like:

#ifdef CONFIG_RETPOLINE
	/* IMPORTANT: Stuff the RSB immediately after VM-Exit, before RET! */
	ALTERNATIVE "", "jmp .Lvmexit_stuff_rsb", X86_FEATURE_RETPOLINE
#endif
.Lvmexit_return:
	RET

Ha!  Better idea.  Rather than have a bunch of nops to eat through before the
!RETPOLINE case gets to the RET, encode the RET as the default.  That allows using
a single #ifdef and avoids both the JMP over the RET as well as the JMP back to the
RET, and saves 4 nops to boot.

SYM_FUNC_START(vmx_vmexit)
#ifdef CONFIG_RETPOLINE
	/* IMPORTANT: Stuff the RSB immediately after VM-Exit, before RET! */
	ALTERNATIVE "RET", "", X86_FEATURE_RETPOLINE

	/* Preserve guest's RAX, it's used to stuff the RSB. */
	push %_ASM_AX

	FILL_RETURN_BUFFER %_ASM_AX, RSB_CLEAR_LOOPS, X86_FEATURE_RETPOLINE

	/* Clear RFLAGS.CF and RFLAGS.ZF to preserve VM-Exit, i.e. !VM-Fail. */
	or $1, %_ASM_AX

	pop %_ASM_AX
#endif
	RET
SYM_FUNC_END(vmx_vmexit)

  reply	other threads:[~2022-06-27 15:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-22 22:24 [PATCH] KVM: VMX: Move VM-exit RSB stuffing out of line Jim Mattson
2022-06-27 15:08 ` Sean Christopherson [this message]
2022-06-27 17:59   ` Jim Mattson

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=YrnH+nhnbhDFAMas@google.com \
    --to=seanjc@google.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.