From nobody Thu Apr 2 06:27:03 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6D43933F59B; Tue, 3 Mar 2026 00:34:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772498075; cv=none; b=OGU3uwpXrqjWLeITcHCGWShTdKkaihMskS2Kpp9Sac7tcurlIUCVYprZwT0jciOdKVZ8/y9SBBKcFk63FHAkuuUITm9XFb4UOCNUo0aM0zhVntuH+j+9/KpuDGtpJVFj9a+NawdV7vXNbd72/5kGFMy8/l5ukzsiodVKnVM7SdA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772498075; c=relaxed/simple; bh=pfVYV6ekwPfSejRIqjGsbtiBVUUCU0z0cBXBBnz/UA4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SDh6K+sWb6AX0jyhfx4IP+ya0ImEis7Lw0KLQdcW7GYCBJ9UHzDqU/ClEAckjD6iOrCt894e+cNTe48nYcvnSpXHZ5RZOkuoZb9lZWYqyxTeAR1gMINrNu/YkDZJ51+/AnoDOzVuOS8C58CnNP0lInr+aV5pbZa8RFOgV2N6bCM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OsskKh9d; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OsskKh9d" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0AE8C19423; Tue, 3 Mar 2026 00:34:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772498075; bh=pfVYV6ekwPfSejRIqjGsbtiBVUUCU0z0cBXBBnz/UA4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OsskKh9dWKcobmwC3pFq0jOJyEg0ubGc213RZ6cMX8fXxa9mHNTEGGgSEWZpKkWpN aO7tmlAMAVOCB6JQeeHDVqW1M6OxkTYT/gy6Bf37dgXxaNepK2Chf7Q6nDiQI7c2jy grvofOn9DNvUF/iywpJnF7fPgTfiQQR9apyVPll3iGmUrdIPAfnSwzVJWKm6n/jR/J P4rUHgoCiz77Bxm/3TM5iYGU+AzS5bQ0RBnwq2vVuJ4Kvu2tt6dUml4Wv7aE5URXN9 fKdSxlgTXuEKEn1fdCRJvrW8Y5mDKRZP6hnILV1tNL78ceqqzJH9dYO5l2yOpCSQF2 Hpyex0GRhK7zw== 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 v7 09/26] KVM: nSVM: Triple fault if restore host CR3 fails on nested #VMEXIT Date: Tue, 3 Mar 2026 00:34:03 +0000 Message-ID: <20260303003421.2185681-10-yosry@kernel.org> X-Mailer: git-send-email 2.53.0.473.g4a7958ca14-goog In-Reply-To: <20260303003421.2185681-1-yosry@kernel.org> References: <20260303003421.2185681-1-yosry@kernel.org> 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 Content-Type: text/plain; charset="utf-8" If loading L1's CR3 fails on a nested #VMEXIT, nested_svm_vmexit() returns an error code that is ignored by most callers, and continues to run L1 with corrupted state. A sane recovery is not possible in this case, and HW behavior is to cause a shutdown. Inject a triple fault ,nstead, and do not return early from nested_svm_vmexit(). Continue cleaning up the vCPU state (e.g. clear pending exceptions), to handle the failure as gracefully as possible. From the APM: Upon #VMEXIT, the processor performs the following actions in order to return to the host execution context: ... if (illegal host state loaded, or exception while loading host state) shutdown else execute first host instruction following the VMRUN Remove the return value of nested_svm_vmexit(), which is mostly unchecked anyway. Fixes: d82aaef9c88a ("KVM: nSVM: use nested_svm_load_cr3() on guest->host s= witch") CC: stable@vger.kernel.org Signed-off-by: Yosry Ahmed --- arch/x86/kvm/svm/nested.c | 10 +++------- arch/x86/kvm/svm/svm.c | 11 ++--------- arch/x86/kvm/svm/svm.h | 6 +++--- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 5ad0ac3680fdd..bb2cec5fd0434 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -1193,12 +1193,11 @@ static int nested_svm_vmexit_update_vmcb12(struct k= vm_vcpu *vcpu) return 0; } =20 -int nested_svm_vmexit(struct vcpu_svm *svm) +void nested_svm_vmexit(struct vcpu_svm *svm) { struct kvm_vcpu *vcpu =3D &svm->vcpu; struct vmcb *vmcb01 =3D svm->vmcb01.ptr; struct vmcb *vmcb02 =3D svm->nested.vmcb02.ptr; - int rc; =20 if (nested_svm_vmexit_update_vmcb12(vcpu)) kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu); @@ -1317,9 +1316,8 @@ int nested_svm_vmexit(struct vcpu_svm *svm) =20 nested_svm_uninit_mmu_context(vcpu); =20 - rc =3D nested_svm_load_cr3(vcpu, vmcb01->save.cr3, false, true); - if (rc) - return 1; + if (nested_svm_load_cr3(vcpu, vmcb01->save.cr3, false, true)) + kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu); =20 /* * Drop what we picked up for L2 via svm_complete_interrupts() so it @@ -1344,8 +1342,6 @@ int nested_svm_vmexit(struct vcpu_svm *svm) */ if (kvm_apicv_activated(vcpu->kvm)) __kvm_vcpu_update_apicv(vcpu); - - return 0; } =20 static void nested_svm_triple_fault(struct kvm_vcpu *vcpu) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index cb53174583a26..1b31b033d79b0 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -2234,13 +2234,9 @@ static int emulate_svm_instr(struct kvm_vcpu *vcpu, = int opcode) [SVM_INSTR_VMSAVE] =3D vmsave_interception, }; struct vcpu_svm *svm =3D to_svm(vcpu); - int ret; =20 if (is_guest_mode(vcpu)) { - /* Returns '1' or -errno on failure, '0' on success. */ - ret =3D nested_svm_simple_vmexit(svm, guest_mode_exit_codes[opcode]); - if (ret) - return ret; + nested_svm_simple_vmexit(svm, guest_mode_exit_codes[opcode]); return 1; } return svm_instr_handlers[opcode](vcpu); @@ -4796,7 +4792,6 @@ static int svm_enter_smm(struct kvm_vcpu *vcpu, union= kvm_smram *smram) { struct vcpu_svm *svm =3D to_svm(vcpu); struct kvm_host_map map_save; - int ret; =20 if (!is_guest_mode(vcpu)) return 0; @@ -4816,9 +4811,7 @@ static int svm_enter_smm(struct kvm_vcpu *vcpu, union= kvm_smram *smram) svm->vmcb->save.rsp =3D vcpu->arch.regs[VCPU_REGS_RSP]; svm->vmcb->save.rip =3D vcpu->arch.regs[VCPU_REGS_RIP]; =20 - ret =3D nested_svm_simple_vmexit(svm, SVM_EXIT_SW); - if (ret) - return ret; + nested_svm_simple_vmexit(svm, SVM_EXIT_SW); =20 /* * KVM uses VMCB01 to store L1 host state while L2 runs but diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 44d767cd1d25a..7629cb37c9302 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -793,14 +793,14 @@ int nested_svm_vmrun(struct kvm_vcpu *vcpu); void svm_copy_vmrun_state(struct vmcb_save_area *to_save, struct vmcb_save_area *from_save); void svm_copy_vmloadsave_state(struct vmcb *to_vmcb, struct vmcb *from_vmc= b); -int nested_svm_vmexit(struct vcpu_svm *svm); +void nested_svm_vmexit(struct vcpu_svm *svm); =20 -static inline int nested_svm_simple_vmexit(struct vcpu_svm *svm, u32 exit_= code) +static inline void nested_svm_simple_vmexit(struct vcpu_svm *svm, u32 exit= _code) { svm->vmcb->control.exit_code =3D exit_code; svm->vmcb->control.exit_info_1 =3D 0; svm->vmcb->control.exit_info_2 =3D 0; - return nested_svm_vmexit(svm); + nested_svm_vmexit(svm); } =20 int nested_svm_exit_handled(struct vcpu_svm *svm); --=20 2.53.0.473.g4a7958ca14-goog