From: Maxim Levitsky <mlevitsk@redhat.com>
To: Sean Christopherson <seanjc@google.com>
Cc: kvm@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
x86@kernel.org, Borislav Petkov <bp@alien8.de>,
linux-kernel@vger.kernel.org,
Dave Hansen <dave.hansen@linux.intel.com>,
Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH v2 1/2] KVM: nVMX: use vmx_segment_cache_clear
Date: Wed, 24 Jul 2024 14:18:21 -0400 [thread overview]
Message-ID: <ed95389522d5c2767dfa60d121dc04ee73087add.camel@redhat.com> (raw)
In-Reply-To: <ZpbhItUq-p_emFUT@google.com>
On Tue, 2024-07-16 at 14:07 -0700, Sean Christopherson wrote:
> On Mon, Jul 15, 2024, Maxim Levitsky wrote:
> > In prepare_vmcs02_rare, call vmx_segment_cache_clear, instead
> > of setting the segment_cache.bitmask directly.
> >
> > No functional change intended.
> >
> > Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
> > ---
> > arch/x86/kvm/vmx/nested.c | 5 +++--
> > arch/x86/kvm/vmx/vmx.c | 4 ----
> > arch/x86/kvm/vmx/vmx.h | 5 +++++
> > 3 files changed, 8 insertions(+), 6 deletions(-)
> >
> > diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> > index 643935a0f70ab..d3ca1a772ae67 100644
> > --- a/arch/x86/kvm/vmx/nested.c
> > +++ b/arch/x86/kvm/vmx/nested.c
> > @@ -2469,6 +2469,9 @@ static void prepare_vmcs02_rare(struct vcpu_vmx *vmx, struct vmcs12 *vmcs12)
> >
> > if (!hv_evmcs || !(hv_evmcs->hv_clean_fields &
> > HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2)) {
> > +
> > + vmx_segment_cache_clear(vmx);
> > +
> > vmcs_write16(GUEST_ES_SELECTOR, vmcs12->guest_es_selector);
> > vmcs_write16(GUEST_CS_SELECTOR, vmcs12->guest_cs_selector);
> > vmcs_write16(GUEST_SS_SELECTOR, vmcs12->guest_ss_selector);
> > @@ -2505,8 +2508,6 @@ static void prepare_vmcs02_rare(struct vcpu_vmx *vmx, struct vmcs12 *vmcs12)
> > vmcs_writel(GUEST_TR_BASE, vmcs12->guest_tr_base);
> > vmcs_writel(GUEST_GDTR_BASE, vmcs12->guest_gdtr_base);
> > vmcs_writel(GUEST_IDTR_BASE, vmcs12->guest_idtr_base);
> > -
> > - vmx->segment_cache.bitmask = 0;
>
> This actually exacerbates the bug that you're trying fix in patch 2. Clearing
> segment_cache.bitmask _after_ writing the relevant state limits the stale data
> to only the accessor that's running in IRQ context (kvm_arch_vcpu_put()).
>
> Clearing segment_cache.bitmask _before_ writing the relevant statement means
> that kvm_arch_vcpu_put() _and_ all future readers will be exposed to the stale
> data, because the stale data cached by kvm_arch_vcpu_put() won't mark it invalid.
>
I noticed that after I sent the patch series, this makes sense.
Best regards,
Maxim Levitsky
next prev parent reply other threads:[~2024-07-24 18:19 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-16 2:20 [PATCH v2 0/2] Fix for a very old KVM bug in the segment cache Maxim Levitsky
2024-07-16 2:20 ` [PATCH v2 1/2] KVM: nVMX: use vmx_segment_cache_clear Maxim Levitsky
2024-07-16 21:07 ` Sean Christopherson
2024-07-24 18:18 ` Maxim Levitsky [this message]
2024-07-16 2:20 ` [PATCH v2 2/2] KVM: VMX: disable preemption when touching segment fields Maxim Levitsky
2024-07-16 22:36 ` Sean Christopherson
2024-07-25 12:59 ` Maxim Levitsky
2024-07-25 17:37 ` Maxim Levitsky
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=ed95389522d5c2767dfa60d121dc04ee73087add.camel@redhat.com \
--to=mlevitsk@redhat.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--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®