From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796331318; b=erSY5uHPUIXQlG/FLUb/akP8ENiKbDitGzurdDDV7g0hyL9KfbZudbDGlrFcAAnT4s5/ QTp+RCcVmBwDutzgCUVHA8Yw2tLFIJxrY6wWZ/WVS9I+isR6NTunnmKXE14TV/PQH8aWk 6WDLg12VxdHKH1WwwcMbEqlnIY8ZUE/bl0TzLiiryJTPoMmHSu6JoFVpdR351aOl1Xrf6 HF9/BmjvU5KtXOVDj3QFnyTYgHkCAcIRXML4wsmgYtm9a8zJ2xdYuxxrVlzJdsg9Qw4Mv ZLWRhBNNJNRbFZMpaJ7UjiuDd2s2kVRbnRjPho5ck62FPGabievXZzGqKlRnerdgfAQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796331318; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=QHjYQ2C08ht6g5TdedWQBHiD71GrIQuuo87AlCrXG+U=; b=w+BQI4VVy+B3elMnnrOkPGRhdoC+ADzZTYIZfQTw1SBunbQNTU3rBr8rXqTYhFT4OhyA RSlOp8eOOryW+xWs+HHK3zyyXzs1E/tvaeYAwm4Pm7aDdSvcZa0i9GQw10okdm9G0cEez Ynnbl1ho3B2pbgJLbGE+GjF/TtcxZ1xDKN8CVLQPWlbSsxrL+TPCorkwQgasygwtaioow lgVepFCvJyAmEOfp0Y0YPlhRuMlHp71N6qKVP03yaqFI+f9USSRM/NlndlJNkCWwSAFjl Dd4d6Jz/bWSZT7IAyoZDf0pD6uzwbPXqoNs97YOnor+NCg0v2+lWiSlTo/yn8Rj0A9A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=CfTnp4X2; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2FE35606A332; Thu, 3 Dec 2026 20:55:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=CfTnp4X2 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 786111F000C2; Thu, 3 Dec 2026 20:55:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796331317; bh=QHjYQ2C08ht6g5TdedWQBHiD71GrIQuuo87AlCrXG+U=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=CfTnp4X2xVhAlEGKJopg93Cq9VfSjQSQLXbZwctlVj2oVIKBQcMEqSKg9B8Wrruqt 6aNass5WA5gvc6ph6/+qgBCohPt9LPvKysGbM72eeW/uJXB/VGRs9rZnee9lTy5RxD 4Aw6/P4ucx4crPWZYeeLcD8MyPPfSo3F9SZ7VfIZSVU/+eBtof67rNpOOh2Ca7i0o9 UcDBRHC+9dmK3XBNB7P73Vx+Kexv3CIAHvmoYGZXv5wyCchZlzRNudDYPu8m7ZTRMz XVGuBF4jhd9Q9fn2U2sWedXO5ufRLpIbJUfGqcoswGzuj3YFFeEnTqFK8bfwiX8YaW GAnQZX9CHUz/A== Date: Thu, 3 Dec 2026 20:55:16 +0000 From: Yosry Ahmed To: Yosry Ahmed Cc: Sean Christopherson , Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Jim Mattson , David Kaplan Subject: Re: [PATCH 1/2] KVM: x86: Defer IBPBs for vCPU and nested transitions until core run loop Message-ID: References: <20260128013432.3250805-1-seanjc@google.com> <20260128013432.3250805-2-seanjc@google.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: > > 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.