From nobody Tue Feb 10 06:05:49 2026 Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) (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 F21901A254E for ; Tue, 10 Feb 2026 00:55:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770684919; cv=none; b=bsbhqDmTz00rT4H/7NKZDj8yZqBiRQ+2rJI/V7rFeXxViq7Ej7o3IeE8AxpQbHCOQzxnnSU1v5rVLqax/Mtv78XEDmtsQ3yGfxWdUBI0SztTuIeqnhDWOWfxOfCsKrQ5AJ/6hGBUEhojTFwgxxny4+vZRC2nliJfLe64vwgIprQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770684919; c=relaxed/simple; bh=0xYTA5O8n2Un7nIegn4K2tJVnxu5c3fQRxZ2nWTeMVI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oHRnCxQGzMlYn8oUTYpNdfP/+BC+ENEUEX7WPgp09++yVechAwnyRf9CrmT6UMxDDyeItKjUZGIo12Q2/SyPKdTFNW2E0uBclc6HcjAAHUfGyTdkCaFLLRIsahTEohsRzWFj2D4hOeyME25VCGyGw4aKu2bjoiVuuCNnf0tICqk= 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=cuQvDLCG; arc=none smtp.client-ip=95.215.58.170 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="cuQvDLCG" 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=1770684916; 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=ojZz514RvzyouqbQnt4yvqck/hytcluQX/sLI1bmLEw=; b=cuQvDLCG8jNbQtONDjaeA868o012sFQs+ompDLcD/Lduo7vbDQU1NIb91Zy+riDbRM6Mcq zWjcdpHUmcDNJy/6e7KBluJSCyf4l0ABntpgJabATXKxwhhvIG4ONGjWF2WGiZh+J70lNm Xm8QIkFqSv3FHwkEKOjOao2s7/Hq+kU= 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 1/4] KVM: nSVM: Sync next_rip to cached vmcb12 after VMRUN of L2 Date: Tue, 10 Feb 2026 00:54:46 +0000 Message-ID: <20260210005449.3125133-2-yosry.ahmed@linux.dev> In-Reply-To: <20260210005449.3125133-1-yosry.ahmed@linux.dev> References: <20260210005449.3125133-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" 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. next_rip is also written by the CPU (in some cases) after VMRUN, but is not sync'd to 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 next_rip to advance RIP after emulating an instruction). Fix this by sync'ing next_rip in nested_sync_control_from_vmcb02(). Move the call to nested_sync_control_from_vmcb02() (and the entire is_guest_mode() block) after svm_complete_interrupts(), as it may update next_rip in vmcb02. Fixes: cc440cdad5b7 ("KVM: nSVM: implement KVM_GET_NESTED_STATE and KVM_SET= _NESTED_STATE") CC: stable@vger.kernel.org Signed-off-by: Yosry Ahmed --- arch/x86/kvm/svm/nested.c | 6 ++++-- arch/x86/kvm/svm/svm.c | 26 +++++++++++++++----------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index de90b104a0dd..70086ba6497f 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -519,8 +519,10 @@ void nested_copy_vmcb_save_to_cache(struct vcpu_svm *s= vm, void nested_sync_control_from_vmcb02(struct vcpu_svm *svm) { u32 mask; - svm->nested.ctl.event_inj =3D svm->vmcb->control.event_inj; - svm->nested.ctl.event_inj_err =3D svm->vmcb->control.event_inj_err; + + svm->nested.ctl.event_inj =3D svm->vmcb->control.event_inj; + svm->nested.ctl.event_inj_err =3D svm->vmcb->control.event_inj_err; + svm->nested.ctl.next_rip =3D svm->vmcb->control.next_rip; =20 /* Only a few fields of int_ctl are written by the processor. */ mask =3D V_IRQ_MASK | V_TPR_MASK; diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 5f0136dbdde6..6d8d4d19455e 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4399,17 +4399,6 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm= _vcpu *vcpu, u64 run_flags) sync_cr8_to_lapic(vcpu); =20 svm->next_rip =3D 0; - if (is_guest_mode(vcpu)) { - nested_sync_control_from_vmcb02(svm); - - /* Track VMRUNs that have made past consistency checking */ - if (svm->nested.nested_run_pending && - !svm_is_vmrun_failure(svm->vmcb->control.exit_code)) - ++vcpu->stat.nested_run; - - svm->nested.nested_run_pending =3D 0; - } - svm->vmcb->control.tlb_ctl =3D TLB_CONTROL_DO_NOTHING; =20 /* @@ -4435,6 +4424,21 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm= _vcpu *vcpu, u64 run_flags) =20 svm_complete_interrupts(vcpu); =20 + /* + * svm_complete_interrupts() may update svm->vmcb->control.next_rip, + * which is sync'd by nested_sync_control_from_vmcb02() below. + */ + if (is_guest_mode(vcpu)) { + nested_sync_control_from_vmcb02(svm); + + /* Track VMRUNs that have made past consistency checking */ + if (svm->nested.nested_run_pending && + !svm_is_vmrun_failure(svm->vmcb->control.exit_code)) + ++vcpu->stat.nested_run; + + svm->nested.nested_run_pending =3D 0; + } + return svm_exit_handlers_fastpath(vcpu); } =20 base-commit: e944fe2c09f405a2e2d147145c9b470084bc4c9a --=20 2.53.0.rc2.204.g2597b5adb4-goog From nobody Tue Feb 10 06:05:49 2026 Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) (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 F015C26F288 for ; Tue, 10 Feb 2026 00:55:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770684922; cv=none; b=MEu5CPN4kq0pJSd+5Mz6hODIHYehuYBhjKv1UQ5TCektDZ7ql+qxV42Pu95gLTd5oJUei+T7EaAmBQbpEi4QEbUuUBp8LWtLJbNU24SmwWgwle4SgK0OvweDpK6HHCyjy9y3y7xlsfzCNPwAp0ofVBy3iBzVkH6PqlzZ541jBfY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770684922; c=relaxed/simple; bh=8qdbIjRxa9nJLV9evrdN17b0sf2bnxg2AJ97er+o+Rw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bydKFfLxG5sf2gEzNJlvpO71o+9O5Y9en87/b7ZoWl1l87T1LMznx1lVZgacVBcWnROb51CIIIpvd9Ii9stQJwzzfYnd7trzOthVecHb53xprDgL+tKNeh6l96QfNGCg8E2BpR7IguKE5n/f1Yhl9QuwqDe0omNks+B42j5ZwwU= 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=u9QMHXYj; arc=none smtp.client-ip=95.215.58.187 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="u9QMHXYj" 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=1770684919; 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=2J5PouiLGGC2lSaBelHHWIjarzEiNNlCjAXNBFFbCqM=; b=u9QMHXYjgL7ULBxfZcR5DWb5xZeuBRaKuH5LatfmAO9CB4tsnF+oUZokxdj3QTnv9pw6yi G3zph5tjf3bSQ577QAzG+eUFUnLT+1Ue+zga+eCaywn4KIFStYJFCAb2Qz6HYV78J6hmh4 yRhU/uS1PoXsodxACXLV9FlHwZDavoI= 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 2/4] KVM: nSVM: Sync int_state to cached vmcb12 after VMRUN of L2 Date: Tue, 10 Feb 2026 00:54:47 +0000 Message-ID: <20260210005449.3125133-3-yosry.ahmed@linux.dev> In-Reply-To: <20260210005449.3125133-1-yosry.ahmed@linux.dev> References: <20260210005449.3125133-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" 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. int_state is also written by the CPU, specifically bit 0 (i.e. SVM_INTERRUPT_SHADOW_MASK) for nested VMs, but it is not sync'd to cached vmcb12. This does not cause a problem if KVM_SET_NESTED_STATE preceeds KVM_SET_VCPU_EVENTS in the restore path, as an interrupt shadow would be correctly restored to vmcb02 (KVM_SET_VCPU_EVENTS overwrites what KVM_SET_NESTED_STATE restored in int_state). However, if KVM_SET_VCPU_EVENTS preceeds KVM_SET_NESTED_STATE, an interrupt shadow would be restored into vmcb01 instead of vmcb02. This would mostly be benign for L1 (delays an interrupt), but not for L2. For L2, the vCPU could hang (e.g. if a wakeup interrupt is delivered before a HLT that should have been in an interrupt shadow). Sync int_state to the cached vmcb12 in nested_sync_control_from_vmcb02() to avoid this problem. With that, KVM_SET_NESTED_STATE restores the correct interrupt shadow state, and if KVM_SET_VCPU_EVENTS follows it would overwrite it with the same value. Fixes: cc440cdad5b7 ("KVM: nSVM: implement KVM_GET_NESTED_STATE and KVM_SET= _NESTED_STATE") CC: stable@vger.kernel.org Signed-off-by: Yosry Ahmed --- arch/x86/kvm/svm/nested.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 70086ba6497f..ff24a5748c7d 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -523,6 +523,7 @@ void nested_sync_control_from_vmcb02(struct vcpu_svm *s= vm) svm->nested.ctl.event_inj =3D svm->vmcb->control.event_inj; svm->nested.ctl.event_inj_err =3D svm->vmcb->control.event_inj_err; svm->nested.ctl.next_rip =3D svm->vmcb->control.next_rip; + svm->nested.ctl.int_state =3D svm->vmcb->control.int_state; =20 /* Only a few fields of int_ctl are written by the processor. */ mask =3D V_IRQ_MASK | V_TPR_MASK; --=20 2.53.0.rc2.204.g2597b5adb4-goog From nobody Tue Feb 10 06:05:49 2026 Received: from out-183.mta1.migadu.com (out-183.mta1.migadu.com [95.215.58.183]) (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 A4AE8272E61 for ; Tue, 10 Feb 2026 00:55:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.183 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770684924; cv=none; b=qcNAJ+AAhLe4agn34QPSlYNFwtmBDFvtzAJfxQCcjhD7mXsHFToTGHM1FLo0EC3rgzBviZfYojLWFOkrg8uQjzoWL7k8VBBtsHJ71An2vbYq9UCDEalp8j3JuF2r6stYbHoNmprTIcTL0EhBkt7ObggTAHvtHeW6TB5EzfH4gpk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770684924; c=relaxed/simple; bh=Ce4bMJFKHMZzZ3HONY928lkH2VpESG7Hgnfctak0/Kw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o183V0lf4BDf9uyZvuW/TOCUwuW6v2PmDt1NJ/1Lqz1Rl7C8lBLg/DTE6ZfxbDhZXz4YQpahAZBwlY1JOP/V4d69Rq8UKqQChPtAxO5+DQ7aEJNxN/+xufE4k8VkzqIvqC+fOAP2+DOZScsEYwtYY6V9kqnSVGdT/Ue3S47gwQo= 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=qitoFcJo; arc=none smtp.client-ip=95.215.58.183 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="qitoFcJo" 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=1770684920; 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=iZKFG8rBXK0TH0NXfkEiSOKxdTpMOu4yndM+D0ocM/s=; b=qitoFcJoD7UL96UJE+PsfZx42Wd8go2WBmmA2+BV9JQ4y3Yr2M0qt00zCuB8arvs5Spi5L Hko5x06LbN52ayZjtWSthfbfvvItG+UuxqxAb43/e5BwZhT9sjS6Tr9cExg+2VGYC2TurQ CmcBDC1x8eOfHpUCoT/XRXKLHJpgly8= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [PATCH 3/4] KVM: selftests: Extend state_test to check vGIF Date: Tue, 10 Feb 2026 00:54:48 +0000 Message-ID: <20260210005449.3125133-4-yosry.ahmed@linux.dev> In-Reply-To: <20260210005449.3125133-1-yosry.ahmed@linux.dev> References: <20260210005449.3125133-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" V_GIF_MASK is one of the fields written by the CPU after VMRUN, and sync'd by KVM from vmcb02 to cached vmcb12 after running L2. Part of the reason is to make sure V_GIF_MASK is saved/restored correctly, as the cached vmcb12 is the payload of nested state. Verify that V_GIF_MASK is saved/restored correctly in state_test by enabling vGIF in vmcb12, toggling GIF in L2 at different GUEST_SYNC() points, and verifying that V_GIF_MASK is correctly propagated to the nested state. Signed-off-by: Yosry Ahmed --- tools/testing/selftests/kvm/x86/state_test.c | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tools/testing/selftests/kvm/x86/state_test.c b/tools/testing/s= elftests/kvm/x86/state_test.c index f2c7a1c297e3..57c7546f3d7c 100644 --- a/tools/testing/selftests/kvm/x86/state_test.c +++ b/tools/testing/selftests/kvm/x86/state_test.c @@ -26,7 +26,9 @@ void svm_l2_guest_code(void) GUEST_SYNC(4); /* Exit to L1 */ vmcall(); + clgi(); GUEST_SYNC(6); + stgi(); /* Done, exit to L1 and never come back. */ vmcall(); } @@ -41,6 +43,8 @@ static void svm_l1_guest_code(struct svm_test_data *svm) generic_svm_setup(svm, svm_l2_guest_code, &l2_guest_stack[L2_GUEST_STACK_SIZE]); =20 + vmcb->control.int_ctl |=3D (V_GIF_ENABLE_MASK | V_GIF_MASK); + GUEST_SYNC(3); run_guest(vmcb, svm->vmcb_gpa); GUEST_ASSERT(vmcb->control.exit_code =3D=3D SVM_EXIT_VMMCALL); @@ -222,6 +226,24 @@ static void __attribute__((__flatten__)) guest_code(vo= id *arg) GUEST_DONE(); } =20 +void svm_check_nested_state(int stage, struct kvm_x86_state *state) +{ + struct vmcb *vmcb =3D (struct vmcb *)state->nested.data.svm; + + if (kvm_cpu_has(X86_FEATURE_VGIF)) { + if (stage =3D=3D 4) + TEST_ASSERT_EQ(!!(vmcb->control.int_ctl & V_GIF_MASK), 1); + if (stage =3D=3D 6) + TEST_ASSERT_EQ(!!(vmcb->control.int_ctl & V_GIF_MASK), 0); + } +} + +void check_nested_state(int stage, struct kvm_x86_state *state) +{ + if (kvm_has_cap(KVM_CAP_NESTED_STATE) && kvm_cpu_has(X86_FEATURE_SVM)) + svm_check_nested_state(stage, state); +} + int main(int argc, char *argv[]) { uint64_t *xstate_bv, saved_xstate_bv; @@ -278,6 +300,8 @@ int main(int argc, char *argv[]) =20 kvm_vm_release(vm); =20 + check_nested_state(stage, state); + /* Restore state in a new VM. */ vcpu =3D vm_recreate_with_one_vcpu(vm); vcpu_load_state(vcpu, state); --=20 2.53.0.rc2.204.g2597b5adb4-goog From nobody Tue Feb 10 06:05:49 2026 Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) (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 CA6E7274B23 for ; Tue, 10 Feb 2026 00:55:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770684925; cv=none; b=nz3PEliAX4xrdEfmFnxYBOwr4OeuHL5WbG3L+vRSizf2B/e52qDZOisLTBQF3vSwPT6FvaTUnwKrh57z29f3l3MSJZPME8UgfNj7Y6B6uYhIhGGl3aIz7baK3WApK2H1R6QqDY5s2O0YlgyKzrEcTyvJkwXr/mMyyvTbq3+690Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770684925; c=relaxed/simple; bh=cwG/NMskJD4ybURXDROCS0IewPftFdK1QqvbrL5qXhE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NRXCDsJUN7J9h9hsA00pyCs6yR8/TyAun4w3ulpwo/fJbUcqrK38LniMtNgsbcNT1g2Hq59CKFxVQYiAIIYW++5aj6YOYc9bvp1aI1VdvaxbR0tDpldw86QVbBBzNK3bKXoVVmUUraLv89IEqmZq56nKOMXEhxNWCsYPYbhbTx8= 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=GC5JiMwk; arc=none smtp.client-ip=95.215.58.187 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="GC5JiMwk" 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=1770684922; 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=vNfLu8p+LHceCLGq3Bp6+ezRZl+1WypRkVGHyFCfSwA=; b=GC5JiMwktNZbPOwY39KefserrlFxIO3WYhQKbvMR2hhSyU4b5RXF28p9RzQNOPNtdNfuB6 FFJq1FRkWclEs+jclg9AUziSu/75ox53XuOApV2RSlMO3kQOiEsrw2d0T9vcTkJS8Gm62j xSzkKfMaRBCZ84c9HIKW18GrE2vQu1M= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [PATCH 4/4] KVM: selftests: Extend state_test to check next_rip Date: Tue, 10 Feb 2026 00:54:49 +0000 Message-ID: <20260210005449.3125133-5-yosry.ahmed@linux.dev> In-Reply-To: <20260210005449.3125133-1-yosry.ahmed@linux.dev> References: <20260210005449.3125133-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" Similar to vGIF, extend state_test to make sure that next_rip is saved correctly in nested state. GUEST_SYNC() in L2 causes IO emulation by KVM, which advances the RIP to the value of next_rip. Hence, if next_rip is saved correctly, its value should match the saved RIP value. Signed-off-by: Yosry Ahmed --- tools/testing/selftests/kvm/x86/state_test.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/testing/selftests/kvm/x86/state_test.c b/tools/testing/s= elftests/kvm/x86/state_test.c index 57c7546f3d7c..992a52504a4a 100644 --- a/tools/testing/selftests/kvm/x86/state_test.c +++ b/tools/testing/selftests/kvm/x86/state_test.c @@ -236,6 +236,17 @@ void svm_check_nested_state(int stage, struct kvm_x86_= state *state) if (stage =3D=3D 6) TEST_ASSERT_EQ(!!(vmcb->control.int_ctl & V_GIF_MASK), 0); } + + if (kvm_cpu_has(X86_FEATURE_NRIPS)) { + /* + * GUEST_SYNC() causes IO emulation in KVM, in which case the + * RIP is advanced before exiting to userspace. Hence, the RIP + * in the saved state should be the same as nRIP saved by the + * CPU in the VMCB. + */ + if (stage =3D=3D 6) + TEST_ASSERT_EQ(vmcb->control.next_rip, state->regs.rip); + } } =20 void check_nested_state(int stage, struct kvm_x86_state *state) --=20 2.53.0.rc2.204.g2597b5adb4-goog