[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Zyg1tkDxNR6N16Ga@intel.com>
Date: Mon, 4 Nov 2024 10:47:18 +0800
From: Chao Gao <chao.gao@...el.com>
To: Sean Christopherson <seanjc@...gle.com>
CC: Paolo Bonzini <pbonzini@...hat.com>, <kvm@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, Like Xu <like.xu.linux@...il.com>
Subject: Re: [PATCH] KVM: nVMX: Treat vpid01 as current if L2 is active, but
with VPID disabled
On Thu, Oct 31, 2024 at 01:20:11PM -0700, Sean Christopherson wrote:
>When getting the current VPID, e.g. to emulate a guest TLB flush, return
>vpid01 if L2 is running but with VPID disabled, i.e. if VPID is disabled
>in vmcs12. Architecturally, if VPID is disabled, then the guest and host
>effectively share VPID=0. KVM emulates this behavior by using vpid01 when
>running an L2 with VPID disabled (see prepare_vmcs02_early_rare()), and so
>KVM must also treat vpid01 as the current VPID while L2 is active.
>
>Unconditionally treating vpid02 as the current VPID when L2 is active
>causes KVM to flush TLB entries for vpid02 instead of vpid01, which
>results in TLB entries from L1 being incorrectly preserved across nested
>VM-Enter to L2 (L2=>L1 isn't problematic, because the TLB flush after
>nested VM-Exit flushes vpid01).
>
>The bug manifests as failures in the vmx_apicv_test KVM-Unit-Test, as KVM
>incorrectly retains TLB entries for the APIC-access page across a nested
>VM-Enter.
>
>Opportunisticaly add comments at various touchpoints to explain the
>architectural requirements, and also why KVM uses vpid01 instead of vpid02.
>
>All credit goes to Chao, who root caused the issue and identified the fix.
>
>Link: https://lore.kernel.org/all/ZwzczkIlYGX+QXJz@intel.com
>Fixes: 2b4a5a5d5688 ("KVM: nVMX: Flush current VPID (L1 vs. L2) for KVM_REQ_TLB_FLUSH_GUEST")
>Cc: stable@...r.kernel.org
>Cc: Like Xu <like.xu.linux@...il.com>
>Debugged-by: Chao Gao <chao.gao@...el.com>
>Signed-off-by: Sean Christopherson <seanjc@...gle.com>
Reviewed-by: Chao Gao <chao.gao@...el.com>
I also ran the vmx_apicv_test KVM-Unit-Test. All failures are gone with this
patch applied. So,
Tested-by: Chao Gao <chao.gao@...el.com>
Powered by blists - more mailing lists