From: Yosry Ahmed <yosry@kernel.org>
To: Yosry Ahmed <yosry.ahmed@linux.dev>
Cc: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Jim Mattson <jmattson@google.com>,
David Kaplan <david.kaplan@amd.com>
Subject: Re: [PATCH 1/2] KVM: x86: Defer IBPBs for vCPU and nested transitions until core run loop
Date: Thu, 3 Dec 2026 20:55:16 +0000 [thread overview]
Message-ID: <axHR-j8zG8dx4zAf@google.com> (raw)
In-Reply-To: <lgsgu5rxioy3zt67i6envq45mdvg2y3kxh26aw6qsqeqogbyho@al24pkui5lt2>
> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > index 8acfdfc583a1..e5ae655702b4 100644
> > --- a/arch/x86/kvm/x86.c
> > +++ b/arch/x86/kvm/x86.c
> > @@ -5187,7 +5187,7 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
> > * is handled on the nested VM-Exit path.
> > */
> > if (static_branch_likely(&switch_vcpu_ibpb))
> > - indirect_branch_prediction_barrier();
> > + vcpu->arch.need_ibpb = true;
>
> This means that if we run vCPU A on a pCPU, then load vCPU B without
> running it, we won't do an IBPB. At least not until vCPU B (or any vCPU)
> actually runs on the pCPU.
>
> My question would be, is it possible for training done by vCPU A to lead
> KVM into leaking some of vCPU B's state after loading it, even without
> actually running vCPU B?
Revisiting this (I may or may not have been bribed), and asking an LLM
to verify if the scenario I came up with is legit, the findings were
interesting:
>
> Basically this scenario (all on the same pCPU):
>
> 1. Malicious vCPU A runs and injects branch predictor entries.
>
> 2. KVM loads vCPU B to perform some action without actually running
> vCPU B. The training from (1) leaks some of vCPU B's state into the
> microarchitectural state.
According to the LLM, this step is a guest->host attack which should be
mitigated by guest->host mitigations (IBRS/retpoline/...), so this
scenario isn't feasible.
>
> 3. Malicious vCPU A runs again and extracts the leaked data.
> > per_cpu(last_vcpu, cpu) = vcpu;
However, I think updating the tracking here is a problem.
The following scenario is possible AFAICT:
1. vCPU#A runs on pCPU#1
last_vcpu[pCPU#1] = vCPU#A
2. vCPU#B is loaded on pCPU#1, but doesn't actually VM-Enter
last_vcpu[pCPU#1] updated to vCPU#B
vCPU#B->need_ibpb = true
3. vCPU#B is migrated to pCPU#2 and does VM-Enter
last_vcpu[pCPU#2] updated to vCPU#B
vCPU#B->need_ibpb = false
4. vCPU#B is migrated back to pCPU#1 and does VM-Enter
last_vcpu[pCPU#1] already vCPU#B
vCPU#B->need_ibpb = false
So vCPU#B ends up running on pCPU#1 after vCPU#A without an IBPB. This
is because the tracking is updated before the IBPB is actually executed,
and the vCPU can be migrated in between.
Maybe move some/all of the tracking to vcpu_enter_guest()? Not sure.
> > }
> >
> > @@ -11315,6 +11315,11 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
> > kvm_make_request(KVM_REQ_EVENT, vcpu);
> > }
> >
> > + if (unlikely(vcpu->arch.need_ibpb)) {
> > + indirect_branch_prediction_barrier();
> > + vcpu->arch.need_ibpb = false;
> > + }
> > +
> > fpregs_assert_state_consistent();
> > if (test_thread_flag(TIF_NEED_FPU_LOAD))
> > switch_fpu_return();
> > diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
> > index 70e81f008030..6708142d051d 100644
> > --- a/arch/x86/kvm/x86.h
> > +++ b/arch/x86/kvm/x86.h
> > @@ -169,7 +169,7 @@ static inline void kvm_nested_vmexit_handle_ibrs(struct kvm_vcpu *vcpu)
> >
> > if (guest_cpu_cap_has(vcpu, X86_FEATURE_SPEC_CTRL) ||
> > guest_cpu_cap_has(vcpu, X86_FEATURE_AMD_IBRS))
> > - indirect_branch_prediction_barrier();
> > + vcpu->arch.need_ibpb = true;
>
> I think the same question more-or-less applies here, could an L2 guest
> lead KVM to leak some of L1's state before L1 is actually run? Although
> in this case it could be harder for any leaked state to survive KVM
> running L1 and then going back to L2.
According to the LLM, this would also be a guest->host attack, but the
same per-vCPU vs per-CPU tracking problem exists. For example:
- L2 runs on pCPU#1.
- nested VM-Exit, need_ibpb = true
- vCPU migrates to pCPU#2.
- L1 runs, clears need_ibpb, executes IBPB on pCPU#2.
- L1 migrates back to pCPU#1.
next prev parent reply other threads:[~2026-12-03 20:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-28 1:34 [PATCH 0/2] KVM: x86: Plug an intra-guest Spectre v2 hole Sean Christopherson
2026-01-28 1:34 ` [PATCH 1/2] KVM: x86: Defer IBPBs for vCPU and nested transitions until core run loop Sean Christopherson
2026-01-30 18:21 ` Yosry Ahmed
2026-12-03 20:55 ` Yosry Ahmed [this message]
2026-01-28 1:34 ` [PATCH 2/2] KVM: x86: Emit IBPB on pCPU migration if IBPB is advertised to guest Sean Christopherson
2026-01-30 18:22 ` Yosry Ahmed
2026-12-03 21:47 ` Yosry Ahmed
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=axHR-j8zG8dx4zAf@google.com \
--to=yosry@kernel.org \
--cc=david.kaplan@amd.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=yosry.ahmed@linux.dev \
/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.