From nobody Sat Feb 7 18:15:48 2026 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4629742981E for ; Fri, 6 Feb 2026 19:09:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770404975; cv=none; b=lekL2EFJVNFxHE5z8sVlFTcUBs9jSxvhDT6k6EniYt7lFvcrImNQhNViN0bV55iDGgxywHb8joAc0oovMtMfiZja4a2UV8snBffPonvPqneXia8Id5Wd+X/ZaAUC8nIQGV+f0mr5FSNXSafNNFrYxWtkWUHRiD/A9Ll/qR8rqWE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770404975; c=relaxed/simple; bh=2GCFQgDIIXc/4F8yoRTg5mJZlXIwfwKXQX8YO7VOUEY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s0aGc+zOGulIqGtk5HqwnrjbAoAEpVEc5jBzJSGnz9C56VVPcmVqZBtH4jB/DOmKDctWbfr+d5PHS6+H4G+TQz0YZYmSKtnjaPPX0QeDHuRJ7zZXGGQxO7NyCTC3JfVpKHPM4XiJwyWKYXkwmH0vAxFdTXZUpX0vo4dLD1FWUGM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=L3/uBPc2; arc=none smtp.client-ip=91.218.175.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="L3/uBPc2" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1770404973; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iK+en+N3Sh3Cz5P9nnp8aY0rKVsI9XKonHalz8PlHgA=; b=L3/uBPc2nVHFs3EYCLKt03ZD5Dg1VB8G++tKvueTGgC/JbkdGYq2Knrr4SaflXTPJ082iM CLXGJnATsmGKIPJamXyvhTTKm4jFjP6Zu4RL/GgYdSFhgS6CYoi1cRLsYGRSkDj7EfHaE8 7ahOPYlLBK1a0TxGpyj1FVZLGx09YWE= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed , stable@vger.kernel.org Subject: [PATCH v5 15/26] KVM: nSVM: Clear EVENTINJ field in VMCB12 on nested #VMEXIT Date: Fri, 6 Feb 2026 19:08:40 +0000 Message-ID: <20260206190851.860662-16-yosry.ahmed@linux.dev> In-Reply-To: <20260206190851.860662-1-yosry.ahmed@linux.dev> References: <20260206190851.860662-1-yosry.ahmed@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" According to the APM, from the reference of the VMRUN instruction: Upon #VMEXIT, the processor performs the following actions in order to return to the host execution context: ... clear EVENTINJ field in VMCB KVM correctly cleared EVENTINJ (i.e. event_inj and event_inj_err) on nested #VMEXIT before commit 2d8a42be0e2b ("KVM: nSVM: synchronize VMCB controls updated by the processor on every vmexit"). That commit made sure the fields are synchronized between VMCB02 and KVM's cached VMCB12 on every L2->L0 #VMEXIT, such that they are serialized correctly on save/restore. However, the commit also incorrectly copied the fields from KVM's cached VMCB12 to L1's VMCB12 on nested #VMEXIT. Go back to clearing the fields, and so in __nested_svm_vmexit() instead of nested_svm_vmexit(), such that it also applies to #VMEXITs caused by a failed VMRUN. Fixes: 2d8a42be0e2b ("KVM: nSVM: synchronize VMCB controls updated by the p= rocessor on every vmexit") Cc: stable@vger.kernel.org Signed-off-by: Yosry Ahmed --- arch/x86/kvm/svm/nested.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 918f6a6eaf56..2f43b70930a8 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -982,7 +982,7 @@ int enter_svm_guest_mode(struct kvm_vcpu *vcpu, u64 vmc= b12_gpa, return 0; } =20 -static void __nested_svm_vmexit(struct vcpu_svm *svm) +static void __nested_svm_vmexit(struct vcpu_svm *svm, struct vmcb *vmcb12) { struct vmcb *vmcb01 =3D svm->vmcb01.ptr; struct kvm_vcpu *vcpu =3D &svm->vcpu; @@ -996,6 +996,10 @@ static void __nested_svm_vmexit(struct vcpu_svm *svm) svm_set_gif(svm, false); vmcb01->control.exit_int_info =3D 0; =20 + /* event_inj is cleared on #VMEXIT */ + vmcb12->control.event_inj =3D 0; + vmcb12->control.event_inj_err =3D 0; + nested_svm_uninit_mmu_context(vcpu); if (nested_svm_load_cr3(vcpu, vmcb01->save.cr3, false, true)) { kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu); @@ -1023,7 +1027,7 @@ static void nested_svm_vmrun_error_vmexit(struct kvm_= vcpu *vcpu, struct vmcb *vm vmcb12->control.exit_code =3D SVM_EXIT_ERR; vmcb12->control.exit_info_1 =3D 0; vmcb12->control.exit_info_2 =3D 0; - __nested_svm_vmexit(svm); + __nested_svm_vmexit(svm, vmcb12); } =20 int nested_svm_vmrun(struct kvm_vcpu *vcpu) @@ -1205,8 +1209,6 @@ void nested_svm_vmexit(struct vcpu_svm *svm) vmcb12->control.next_rip =3D vmcb02->control.next_rip; =20 vmcb12->control.int_ctl =3D svm->nested.ctl.int_ctl; - vmcb12->control.event_inj =3D svm->nested.ctl.event_inj; - vmcb12->control.event_inj_err =3D svm->nested.ctl.event_inj_err; =20 if (!kvm_pause_in_guest(vcpu->kvm)) { vmcb01->control.pause_filter_count =3D vmcb02->control.pause_filter_coun= t; @@ -1316,8 +1318,6 @@ void nested_svm_vmexit(struct vcpu_svm *svm) vmcb12->control.exit_int_info_err, KVM_ISA_SVM); =20 - kvm_vcpu_unmap(vcpu, &map); - nested_svm_transition_tlb_flush(vcpu); =20 /* @@ -1339,7 +1339,9 @@ void nested_svm_vmexit(struct vcpu_svm *svm) * Potentially queues an exception, so it needs to be after * kvm_clear_exception_queue() is called above. */ - __nested_svm_vmexit(svm); + __nested_svm_vmexit(svm, vmcb12); + + kvm_vcpu_unmap(vcpu, &map); } =20 static void nested_svm_triple_fault(struct kvm_vcpu *vcpu) --=20 2.53.0.rc2.204.g2597b5adb4-goog