All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Doug Covelli <doug.covelli@broadcom.com>
Subject: Re: [PATCH 1/2] KVM: SVM: Set RFLAGS.IF=1 in C code, to get VMRUN out of the STI shadow
Date: Wed, 19 Feb 2025 17:07:57 -0800	[thread overview]
Message-ID: <Z7aAbSQTjS4MBK7z@google.com> (raw)
In-Reply-To: <20250215010946.1201353-2-seanjc@google.com>

On Fri, Feb 14, 2025, Sean Christopherson wrote:
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index 7640a84e554a..fa0687711c48 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -4189,6 +4189,18 @@ static noinstr void svm_vcpu_enter_exit(struct kvm_vcpu *vcpu, bool spec_ctrl_in
>  
>  	guest_state_enter_irqoff();
>  
> +	/*
> +	 * Set RFLAGS.IF prior to VMRUN, as the host's RFLAGS.IF at the time of
> +	 * VMRUN controls whether or not physical IRQs are masked (KVM always
> +	 * runs with V_INTR_MASKING_MASK).  Toggle RFLAGS.IF here to avoid the
> +	 * temptation to do STI+VMRUN+CLI, as AMD CPUs bleed the STI shadow
> +	 * into guest state if delivery of an event during VMRUN triggers a
> +	 * #VMEXIT, and the guest_state transitions already tell lockdep that
> +	 * IRQs are being enabled/disabled.  Note!  GIF=0 for the entirety of
> +	 * this path, so IRQs aren't actually unmasked while running host code.
> +	 */
> +	local_irq_enable();

Courtesy of the kernel test bot[*], these need to use the raw_ variants to avoid
tracing.  guest_state_{enter,exit}_irqoff() does all of the necessary tracing
updates, so we should be good on that front.

  svm_vcpu_enter_exit+0x39: call to trace_hardirqs_on() leaves .noinstr.text section

[*] https://lore.kernel.org/all/202502170739.2WX98OXk-lkp@intel.com

> +
>  	amd_clear_divider();
>  
>  	if (sev_es_guest(vcpu->kvm))
> @@ -4197,6 +4209,8 @@ static noinstr void svm_vcpu_enter_exit(struct kvm_vcpu *vcpu, bool spec_ctrl_in
>  	else
>  		__svm_vcpu_run(svm, spec_ctrl_intercepted);
>  
> +	local_irq_disable();
> +
>  	guest_state_exit_irqoff();
>  }

  reply	other threads:[~2025-02-20  1:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-15  1:09 [PATCH 0/2] KVM: SVM: Fix an STI shadow on VMRUN bug Sean Christopherson
2025-02-15  1:09 ` [PATCH 1/2] KVM: SVM: Set RFLAGS.IF=1 in C code, to get VMRUN out of the STI shadow Sean Christopherson
2025-02-20  1:07   ` Sean Christopherson [this message]
2025-02-15  1:09 ` [PATCH 2/2] KVM: selftests: Assert that STI blocking isn't set after event injection Sean Christopherson

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=Z7aAbSQTjS4MBK7z@google.com \
    --to=seanjc@google.com \
    --cc=doug.covelli@broadcom.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@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.