From mboxrd@z Thu Jan 1 00:00:00 1970 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 2C6C4355049; Fri, 15 May 2026 16:00:36 +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=1778860836; cv=none; b=tv/5m6GGAzRSNZvCdDP2Yvj1LduWkHOEOteHjM8WRIbe0J1ohQ0iBNT3GmD/mZuWUi7TdNFQPZ5XEQGnbq7i7efEbvZcmsD728BhVriueG5LnH+/hPkl5bR0p3gNRIEKYMuGhQgIqp28K/LnaFPTr7LtA6kpzdpRkLiv1UkhzOo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778860836; c=relaxed/simple; bh=t0jZOCF7ylDsKES2I3eylSbXa8Sr62pl3UQylv59Grc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JRt8iF0KhPt6i9ck3tQd560l2rR2dwiKFFvSqyBbJSh2nnRSca89TefqJjyBX8gzDHJRp3Heoc7CGtJkQSvl9GQYVuSjn55/tgG7gT5NXqZ/uFExOW6K3xMwNx0jQ59eBT0Mkbez3Zm0/iA6oeZ63W1GRv15brSp2FqR5YgmYg8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=tTDhmZVj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="tTDhmZVj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7A17C2BCB0; Fri, 15 May 2026 16:00:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1778860836; bh=t0jZOCF7ylDsKES2I3eylSbXa8Sr62pl3UQylv59Grc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tTDhmZVj1OVPSH5RVZOZ09UEqcvvXbLaI/P4uK67MRQCtCvTEYG73eFd2gNvxc/Y5 y2Fs4+YAmOWn1u+Fw6jiKwDuCw8rrSDe2pTdvvbxtrMB97zFnk23mrlKulP7VLvZMN sTL8yWo33WWYPclHuEl/5DyX6HRsmr/+GQcI3ntM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yosry Ahmed , Sean Christopherson Subject: [PATCH 6.6 096/474] KVM: nSVM: Sync NextRIP to cached vmcb12 after VMRUN of L2 Date: Fri, 15 May 2026 17:43:25 +0200 Message-ID: <20260515154717.117484090@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260515154715.053014143@linuxfoundation.org> References: <20260515154715.053014143@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yosry Ahmed commit 778d8c1b2a6ffe622ddcd3bb35b620e6e41f4da0 upstream. After VMRUN in guest mode, nested_sync_control_from_vmcb02() syncs fields written by the CPU from vmcb02 to the cached vmcb12. This is because the cached vmcb12 is used as the authoritative copy of some of the controls, and is the payload when saving/restoring nested state. NextRIP is also written by the CPU (in some cases) after VMRUN, but is not sync'd to the cached vmcb12. As a result, it is corrupted after save/restore (replaced by the original value written by L1 on nested VMRUN). This could cause problems for both KVM (e.g. when injecting a soft IRQ) or L1 (e.g. when using NextRIP to advance RIP after emulating an instruction). Fix this by sync'ing NextRIP to the cache after VMRUN of L2, but only after completing interrupts (not in nested_sync_control_from_vmcb02()), as KVM may update NextRIP (e.g. when re-injecting a soft IRQ). Fixes: cc440cdad5b7 ("KVM: nSVM: implement KVM_GET_NESTED_STATE and KVM_SET_NESTED_STATE") CC: stable@vger.kernel.org Co-developed-by: Sean Christopherson Signed-off-by: Yosry Ahmed Link: https://patch.msgid.link/20260225005950.3739782-2-yosry@kernel.org Signed-off-by: Sean Christopherson Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/svm/svm.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4339,6 +4339,16 @@ static __no_kcsan fastpath_t svm_vcpu_ru svm_complete_interrupts(vcpu); + /* + * Update the cache after completing interrupts to get an accurate + * NextRIP, e.g. when re-injecting a soft interrupt. + * + * FIXME: Rework svm_get_nested_state() to not pull data from the + * cache (except for maybe int_ctl). + */ + if (is_guest_mode(vcpu)) + svm->nested.ctl.next_rip = svm->vmcb->control.next_rip; + return svm_exit_handlers_fastpath(vcpu); }