OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
* [Devel] [PATCH hci-8.2 0/7] KVM fixes for the 8.2 kernel
@ 2026-11-26 21:52 Konstantin Khorenko
  2026-11-26 21:52 ` [Devel] [PATCH hci-8.2 1/7] ms/KVM: x86/mmu: Conditionally resched when retrying gPTE walk on A/D update failure Konstantin Khorenko
                   ` (7 more replies)
  0 siblings, 8 replies; 16+ messages in thread
From: Konstantin Khorenko @ 2026-11-26 21:52 UTC (permalink / raw)
  To: Pavel Tikhomirov, Vasileios Almpanis; +Cc: devel

The KVM fixes the 8.1 kernel got in 24.4, for the 26.x branch: from
6.12.y stable where it has them, patches 6-7 from mainline.

- Patches 1-4 (VSTOR-157287): a guest can lock up or exhaust the host.
  - Patch 1: CVE-2026-99713.
  - Patch 2: CVE-2026-99712.
  - Patch 3: nVMX MSR unwind on a failed VM-Entry.
  - Patch 4: CVE-2026-99710.
- Patch 5 (VSTOR-157390): CVE-2026-99312, a stale L2 MMU root after
  INIT.
- Patches 6-7 (VSTOR-157390): L2 clearing EFER.SVME without an L1
  intercept now triple-faults L1, with a selftest.

Assisted-by: LLM
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
Sean Christopherson (5):
      ms/KVM: x86/mmu: Conditionally resched when retrying gPTE walk on A/D update failure
      ms/KVM: x86: Conditionally resched when restarting REP string emulation
      ms/KVM: nVMX: Process each host MSR entry at most once when unwinding failed VM-Entry
      ms/KVM: x86/mmu: Cap number of parent PTEs per SP at 1000 (the arbitrary rmap limit)
      ms/KVM: x86: Unconditionally reset MMU context when emulating INIT

Yosry Ahmed (2):
      ms/KVM: SVM: Triple fault L1 on unintercepted EFER.SVME clear by L2
      ms/KVM: selftests: Add a test for L2 clearing EFER.SVME without intercept

 arch/x86/kvm/mmu/mmu.c                             | 10 ++++
 arch/x86/kvm/mmu/paging_tmpl.h                     | 11 ++++-
 arch/x86/kvm/svm/svm.c                             | 13 +++++
 arch/x86/kvm/vmx/nested.c                          |  1 +
 arch/x86/kvm/x86.c                                 | 31 +++++++-----
 tools/testing/selftests/kvm/Makefile.kvm           |  1 +
 .../selftests/kvm/x86/svm_nested_clear_efer_svme.c | 55 ++++++++++++++++++++++
 7 files changed, 109 insertions(+), 13 deletions(-)
---
base-commit: 9d3240d27f8b8c140461a96daa199ed0705ebe91
change-id: 20261126-khorenko-vstor-157390-kvm-fixes-355774e97940

Best regards,
--  
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Devel] [PATCH hci-8.2 1/7] ms/KVM: x86/mmu: Conditionally resched when retrying gPTE walk on A/D update failure
  2026-11-26 21:52 [Devel] [PATCH hci-8.2 0/7] KVM fixes for the 8.2 kernel Konstantin Khorenko
@ 2026-11-26 21:52 ` Konstantin Khorenko
  2026-12-01  0:44   ` no-reply
  2026-11-26 21:53 ` [Devel] [PATCH hci-8.2 2/7] ms/KVM: x86: Conditionally resched when restarting REP string emulation Konstantin Khorenko
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 16+ messages in thread
From: Konstantin Khorenko @ 2026-11-26 21:52 UTC (permalink / raw)
  To: Pavel Tikhomirov, Vasileios Almpanis; +Cc: devel

From: Sean Christopherson <seanjc@google.com>

[ Upstream commit b2691b3a6cd230209736c89684dab90d939aa56b ]

Conditionally reschedule when retrying a guest PTE walk because the CMPXCHG
to update A/D bits failed, e.g. because a different task/vCPU modified the
relevant gPTEs.  On kernels without involuntary preemption of some kind, a
misbehaving guest can "capture" a pCPU effectively indefinitely and trigger
soft lockups by continuously modifying its gPTEs such that the result of
the walk is remains valid.

Fixes: b3e4e63fd9ee ("KVM: MMU: Use cmpxchg for pte updates on walk_addr()")
Cc: stable@vger.kernel.org
Reported-by: Stefan Teodorescu <fane@google.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-ID: <20261022015903.282261-1-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit 399c8c1e2ea42018960a31ef3a2e93554e50f606)

https://virtuozzo.atlassian.net/browse/VSTOR-157287
Feature: fix ms/kvm
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 arch/x86/kvm/mmu/paging_tmpl.h | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/mmu/paging_tmpl.h b/arch/x86/kvm/mmu/paging_tmpl.h
index af220c9c8ab8d..1727399b6899f 100644
--- a/arch/x86/kvm/mmu/paging_tmpl.h
+++ b/arch/x86/kvm/mmu/paging_tmpl.h
@@ -321,6 +321,13 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
 	gpa_t real_gpa;
 	gfn_t gfn;
 
+	/*
+	 * KVM might sleep/resched when retrying the walk if the updating A/D
+	 * fails because the gPTE changed between reading the gPTE and trying
+	 * the CMPXHG to set A/D bits.
+	 */
+	might_sleep();
+
 	trace_kvm_mmu_pagetable_walk(addr, access);
 retry_walk:
 	walker->level = mmu->cpu_role.base.level;
@@ -467,8 +474,10 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
 							addr, write_fault);
 		if (unlikely(ret < 0))
 			goto error;
-		else if (ret)
+		else if (ret) {
+			cond_resched();
 			goto retry_walk;
+		}
 	}
 
 	return 1;

-- 
2.43.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Devel] [PATCH hci-8.2 2/7] ms/KVM: x86: Conditionally resched when restarting REP string emulation
  2026-11-26 21:52 [Devel] [PATCH hci-8.2 0/7] KVM fixes for the 8.2 kernel Konstantin Khorenko
  2026-11-26 21:52 ` [Devel] [PATCH hci-8.2 1/7] ms/KVM: x86/mmu: Conditionally resched when retrying gPTE walk on A/D update failure Konstantin Khorenko
@ 2026-11-26 21:53 ` Konstantin Khorenko
  2026-12-01  0:45   ` no-reply
  2026-11-26 21:53 ` [Devel] [PATCH hci-8.2 3/7] ms/KVM: nVMX: Process each host MSR entry at most once when unwinding failed VM-Entry Konstantin Khorenko
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 16+ messages in thread
From: Konstantin Khorenko @ 2026-11-26 21:53 UTC (permalink / raw)
  To: Pavel Tikhomirov, Vasileios Almpanis; +Cc: devel

From: Sean Christopherson <seanjc@google.com>

[ Upstream commit ae85ac25eb671d174811cc3101549448671fd505 ]

When restarting emulation, e.g. of a REP-prefixed string instruction,
conditionally reschedule as emulating guest writes can be deceptively slow
and expensive, e.g. when shadow paging is in use and each write can trigger
write tracking.

In a perfect world, restarting emulation (or not) would be less arbitrary,
e.g. would honor not only host events (NEED_RESCHED, signals, etc.) but
also guest events (e.g. by checking kvm_vcpu_has_events()).  Unfortunately,
as pointed out by Sashiko, pio_in_emulated()'s read-ahead logic is baked
into the restart logic, as KVM relies on restarting emulation to drain the
cache and avoid duplicate reads from the I/O port.  I.e. re-entering the
guest on kvm_vcpu_has_events() or __xfer_to_guest_mode_work_pending() would
introduce architecturally-incorrect, guest-visible changes.

Fixes: 5cd21917da24 ("KVM: x86 emulator: restart string instruction without going back to a guest.")
Cc: stable@vger.kernel.org
Cc: David Woodhouse <dwmw2@infradead.org>
Reported-by: Stefan Teodorescu <fane@google.com>
Suggested-by: Stefan Teodorescu <fane@google.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-ID: <20261028173638.1765329-1-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit c1293d2134c2d63741b197a1e5a6363894ed4bce)

https://virtuozzo.atlassian.net/browse/VSTOR-157287
Feature: fix ms/kvm
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 arch/x86/kvm/x86.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index de38b59d90161..e0f575bc67f47 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -9252,10 +9252,12 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
 	} else if (vcpu->arch.complete_userspace_io) {
 		writeback = false;
 		r = 0;
-	} else if (r == EMULATION_RESTART)
+	} else if (r == EMULATION_RESTART) {
+		cond_resched();
 		goto restart;
-	else
+	} else {
 		r = 1;
+	}
 
 writeback:
 	if (writeback) {

-- 
2.43.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Devel] [PATCH hci-8.2 3/7] ms/KVM: nVMX: Process each host MSR entry at most once when unwinding failed VM-Entry
  2026-11-26 21:52 [Devel] [PATCH hci-8.2 0/7] KVM fixes for the 8.2 kernel Konstantin Khorenko
  2026-11-26 21:52 ` [Devel] [PATCH hci-8.2 1/7] ms/KVM: x86/mmu: Conditionally resched when retrying gPTE walk on A/D update failure Konstantin Khorenko
  2026-11-26 21:53 ` [Devel] [PATCH hci-8.2 2/7] ms/KVM: x86: Conditionally resched when restarting REP string emulation Konstantin Khorenko
@ 2026-11-26 21:53 ` Konstantin Khorenko
  2026-12-01  0:45   ` no-reply
  2026-11-26 21:53 ` [Devel] [PATCH hci-8.2 4/7] ms/KVM: x86/mmu: Cap number of parent PTEs per SP at 1000 (the arbitrary rmap limit) Konstantin Khorenko
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 16+ messages in thread
From: Konstantin Khorenko @ 2026-11-26 21:53 UTC (permalink / raw)
  To: Pavel Tikhomirov, Vasileios Almpanis; +Cc: devel

From: Sean Christopherson <seanjc@google.com>

[ Upstream commit c33ef9d334059f7cb167569ed7b4779752fe4425 ]

Add a missing "break" in the inner for-loop of the open coded mess that
unwinds MSRs back to the pre-VM-Enter state when VMLAUNCH/VMRESUME VM-Fails
due to a consistency check that is caught by hardware but missed by KVM.
I.e. move on to the next MSR in the VM-Entry load list after performing a
write using a value found in the VM-Exit load list.  Processing *every*
matching entry in the VM-Exit load list makes the processing quadratic,
which is problematic if the load lists are full of MSRs that are expensive
to emulate.  E.g. writing APIC_BASE triggers kvm_recalculate_apic_map() and
a whole pile of unnecessary work.

Functionally, arbitrarily restoring the value of the first matching entry
is "fine", because none of this is architecturally correct: the load lists
are never supposed to have been used in the first place.  In practice, it's
likely a moot point as no well-behaved VMM will have multiple, diverging
entries in the load lists.

Fixes: bd18bffca353 ("KVM: nVMX: restore host state in nested_vmx_vmexit for VMFail")
Cc: stable@vger.kernel.org
Cc: David Woodhouse <dwmw2@infradead.org>
Reported-by: Stefan Teodorescu <fane@google.com>
Suggested-by: Stefan Teodorescu <fane@google.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-ID: <20261027185917.1478906-1-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit 05fae367c6878d08f54a7c5bb6986a5e57e9bd1c)

https://virtuozzo.atlassian.net/browse/VSTOR-157287
Feature: fix ms/kvm
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 arch/x86/kvm/vmx/nested.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 1e34dc5313246..94facc1a2f2e7 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -4956,6 +4956,7 @@ static void nested_vmx_restore_host_state(struct kvm_vcpu *vcpu)
 					__func__, j, h.index, h.value);
 				goto vmabort;
 			}
+			break;
 		}
 	}
 

-- 
2.43.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Devel] [PATCH hci-8.2 4/7] ms/KVM: x86/mmu: Cap number of parent PTEs per SP at 1000 (the arbitrary rmap limit)
  2026-11-26 21:52 [Devel] [PATCH hci-8.2 0/7] KVM fixes for the 8.2 kernel Konstantin Khorenko
                   ` (2 preceding siblings ...)
  2026-11-26 21:53 ` [Devel] [PATCH hci-8.2 3/7] ms/KVM: nVMX: Process each host MSR entry at most once when unwinding failed VM-Entry Konstantin Khorenko
@ 2026-11-26 21:53 ` Konstantin Khorenko
  2026-12-01  0:46   ` no-reply
  2026-11-26 21:53 ` [Devel] [PATCH hci-8.2 5/7] ms/KVM: x86: Unconditionally reset MMU context when emulating INIT Konstantin Khorenko
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 16+ messages in thread
From: Konstantin Khorenko @ 2026-11-26 21:53 UTC (permalink / raw)
  To: Pavel Tikhomirov, Vasileios Almpanis; +Cc: devel

From: Sean Christopherson <seanjc@google.com>

[ Upstream commit e4558c3d7198ed9a0adc3304681f561f4e4d80e1 ]

When potentially reusing a shadow page, zap the shadow page if its number
of parent PTEs exceeds KVM's (mostly) arbitrary rmap recycling threshold.
Letting the guest create a (mostly) unbounded number of parent PTEs allows
the guest to coerce KVM into creating lists containing millions of PTEs,
effectively bounded only by the maximum number of shadow pages.

Because PTE lists are simple singly linked lists, removal is O(n).  Even
worse, if a list is constructed just so, teardown can be O(n^2), e.g. if
SPTEs are built such that zapping child SPTEs always zaps the last entry
in the list.  To cap things off, all paths that walk PTE lists do so
while holding mmu_lock, without conditionally rescheduling.

Using a doubly linked list would not address the issue, as removal would
remain O(n) since KVM still wouldn't know where in the list to remove from.
Removal could be made O(1) by storing a per-SPTE pointer, but that would
largely defeat the purpose of reusing SPs, and would penalize well-behaved
guests, especially for nested TDP where aliasing page tables is uncommon.

So, cap the maximum number of parent PTEs at the rmap limit.  In practice,
well-behaved guests will likely never run afoul of the limit.  E.g. when
running Linux as L1 with TDP, the number of parent PTEs for a single SP
tops out at under 200 (though undoubtedly obscure workloads can push it
higher).  Deliberately use a "greater than or equal" as opposed to rmap's
strictly "greater than", as the rmap code checks the threshold immediately
*after* inserting into the list, i.e. the limit is 1000 for rmaps, KVM just
very briefly blows past it.

Apply the check to both indirect and direct SPs, because while a fully
direct MMU naturally limits the number of parent PTEs to '1', direct SPs in
indirect MMUs have no such constraint.  E.g. if the guest maps a huge PTE
into many locations in its page tables, and KVM is backing the hugepage
with a direct SP, i.e. with a series of smaller pages, then KVM could end
up with a direct SP with many parents.

Note, shadow_mmu_try_split_huge_pages() always restarts the rmap walk or
bails entirely if it gets to the point where it tries to grab a SP, i.e.
there is *no* pre-existing bug that would be tripped by zapping a SP and
thus rmaps when getting a SP.

Cc: Jim Mattson <jmattson@google.com>
Cc: James Houghton <jthoughton@google.com>
Cc: Yosry Ahmed <yosry@kernel.org>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: stable@vger.kernel.org
Reported-by: Stefan Teodorescu <fane@google.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-ID: <20261027171518.1432557-1-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit edf87e07376054eedcd5306e0794a26e3004d97b)

https://virtuozzo.atlassian.net/browse/VSTOR-157287
Feature: fix ms/kvm
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 arch/x86/kvm/mmu/mmu.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 66bda34aeb7f6..d7527f2180e7a 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -2270,6 +2270,16 @@ static struct kvm_mmu_page *kvm_mmu_find_shadow_page(struct kvm *kvm,
 			continue;
 		}
 
+		/*
+		 * Note!  Unlike fully direct MMUs, direct SPs in indirect MMUs
+		 * can have an arbitrary number of parents, e.g if the guest is
+		 * mapping a huge PTE at many points in its page tables.
+		 */
+		if (pte_list_count(&sp->parent_ptes) >= RMAP_RECYCLE_THRESHOLD) {
+			kvm_mmu_prepare_zap_page(kvm, sp, &invalid_list);
+			break;
+		}
+
 		/* unsync and write-flooding only apply to indirect SPs. */
 		if (sp->role.direct)
 			goto out;

-- 
2.43.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Devel] [PATCH hci-8.2 5/7] ms/KVM: x86: Unconditionally reset MMU context when emulating INIT
  2026-11-26 21:52 [Devel] [PATCH hci-8.2 0/7] KVM fixes for the 8.2 kernel Konstantin Khorenko
                   ` (3 preceding siblings ...)
  2026-11-26 21:53 ` [Devel] [PATCH hci-8.2 4/7] ms/KVM: x86/mmu: Cap number of parent PTEs per SP at 1000 (the arbitrary rmap limit) Konstantin Khorenko
@ 2026-11-26 21:53 ` Konstantin Khorenko
  2026-12-01  0:47   ` no-reply
  2026-11-26 21:53 ` [Devel] [PATCH hci-8.2 6/7] ms/KVM: SVM: Triple fault L1 on unintercepted EFER.SVME clear by L2 Konstantin Khorenko
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 16+ messages in thread
From: Konstantin Khorenko @ 2026-11-26 21:53 UTC (permalink / raw)
  To: Pavel Tikhomirov, Vasileios Almpanis; +Cc: devel

From: Sean Christopherson <seanjc@google.com>

[ Upstream commit c7c288d178cb0b78d3464a616b16b1aa0b316049 ]

Force an MMU reset when emulating an INIT even if paging was already
disabled, as the MMU page role includes guest_mode (L2), i.e. an INIT while
L2 is running with CR0.PG=0 will result in KVM running L1 with a stale MMU
context.

Alternatively, the reset could be scoped strictly to paging being enabled
or L2 being active, but SMM is also encoded in the page role.  Even though
it _should_ be impossible for the vCPU to be INIT'd while SMM is active,
there's zero value in not handling SMM.  At that point, the only scenario
where KVM _doesn't_ need to reset the MMU context is on an INIT with the
vCPU running in Real Mode or Unpaged Protect Mode, and while INIT in those
modes is somewhat common, it's far from a hot path and re-initializing the
MMU is not expensive, especially when the role isn't changing (KVM elides
most of the re-configuration in that case).

Note, like the Fixes commit, this bug only affects nested SVM as INIT is an
unconditional intercept on VMX, i.e. it's impossible to emulate INIT while
L2 is active.

Temporarily keep the guest TLB flush when CR0.PG is being cleared even
though it is fully redundant with the flush that is emitted on all INIT
events (KVM itself only does RESET when a vCPU is being created, i.e. when
CR0.PG must be '0').

Fixes: ed129ec9057f ("KVM: x86: forcibly leave nested mode on vCPU reset")
Reported-by: Stefan Teodorescu <fane@google.com>
Reported-by: Oren Yomtov <thenameisoren@gmail.com>
Reported-by: Chris Mason <mason@kernel.org>
Cc: stable@vger.kernel.org
Cc: Yosry Ahmed <yosry@kernel.org>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-ID: <20261022015407.279870-2-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit f55a3e4e08dc004b4bab7c1e9323d7e7e96e266a)

https://virtuozzo.atlassian.net/browse/VSTOR-157390
Feature: fix ms/kvm
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 arch/x86/kvm/x86.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index e0f575bc67f47..a825a48093ae1 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -12596,18 +12596,23 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
 	kvm_x86_call(set_efer)(vcpu, 0);
 	kvm_x86_call(update_exception_bitmap)(vcpu);
 
+	if (old_cr0 & X86_CR0_PG)
+		kvm_make_request(KVM_REQ_TLB_FLUSH_GUEST, vcpu);
+
 	/*
-	 * On the standard CR0/CR4/EFER modification paths, there are several
-	 * complex conditions determining whether the MMU has to be reset and/or
-	 * which PCIDs have to be flushed.  However, CR0.WP and the paging-related
-	 * bits in CR4 and EFER are irrelevant if CR0.PG was '0'; and a reset+flush
-	 * is needed anyway if CR0.PG was '1' (which can only happen for INIT, as
-	 * CR0 will be '0' prior to RESET).  So we only need to check CR0.PG here.
+	 * Unconditionally reset the MMU, even though super strictly speaking,
+	 * a MMU reset is only necessary if and only one of the page role bits
+	 * is changing.  All of the CR0/CR4/EFER bits effectively get covered
+	 * by checking CR0.PG=1, as CR0.WP and the paging-related bits in CR4
+	 * and EFER are irrelevant if CR0.PG was '0'.  Subtly, if the vCPU was
+	 * in guest mode (L2) or SMM (although emulating INIT in SMM _should_
+	 * be impossible), an MMU reset is also necessary as "guest mode" and
+	 * "smm" are both encoded in the shadow page role.  As a result, the
+	 * only scenarios where an MMU reset is *not* needed is if the vCPU is
+	 * in Real Mode or Unpaged Protected Mode, and micro-optimizing those
+	 * paths are not worth the risk of running with a stale MMU context.
 	 */
-	if (old_cr0 & X86_CR0_PG) {
-		kvm_make_request(KVM_REQ_TLB_FLUSH_GUEST, vcpu);
-		kvm_mmu_reset_context(vcpu);
-	}
+	kvm_mmu_reset_context(vcpu);
 
 	/*
 	 * Intel's SDM states that all TLB entries are flushed on INIT.  AMD's

-- 
2.43.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Devel] [PATCH hci-8.2 6/7] ms/KVM: SVM: Triple fault L1 on unintercepted EFER.SVME clear by L2
  2026-11-26 21:52 [Devel] [PATCH hci-8.2 0/7] KVM fixes for the 8.2 kernel Konstantin Khorenko
                   ` (4 preceding siblings ...)
  2026-11-26 21:53 ` [Devel] [PATCH hci-8.2 5/7] ms/KVM: x86: Unconditionally reset MMU context when emulating INIT Konstantin Khorenko
@ 2026-11-26 21:53 ` Konstantin Khorenko
  2026-12-01  0:49   ` no-reply
  2026-11-26 21:53 ` [Devel] [PATCH hci-8.2 7/7] ms/KVM: selftests: Add a test for L2 clearing EFER.SVME without intercept Konstantin Khorenko
  2026-11-27 14:43 ` [Devel] [PATCH hci-8.2 0/7] KVM fixes for the 8.2 kernel Konstantin Khorenko
  7 siblings, 1 reply; 16+ messages in thread
From: Konstantin Khorenko @ 2026-11-26 21:53 UTC (permalink / raw)
  To: Pavel Tikhomirov, Vasileios Almpanis; +Cc: devel

From: Yosry Ahmed <yosry.ahmed@linux.dev>

KVM tracks when EFER.SVME is set and cleared to initialize and tear down
nested state. However, it doesn't differentiate if EFER.SVME is getting
toggled in L1 or L2+. If L2 clears EFER.SVME, and L1 does not intercept
the EFER write, KVM exits guest mode and tears down nested state while
L2 is running, executing L1 without injecting a proper #VMEXIT.

According to the APM:

    The effect of turning off EFER.SVME while a guest is running is
    undefined; therefore, the VMM should always prevent guests from
    writing EFER.

Since the behavior is architecturally undefined, KVM gets to choose what
to do. Inject a triple fault into L1 as a more graceful option that
running L1 with corrupted state.

Co-developed-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Yosry Ahmed <yosry.ahmed@linux.dev>
base-commit: 95deaec3557dced322e2540bfa426e60e5373d46
Link: https://patch.msgid.link/20260209195142.2554532-2-yosry.ahmed@linux.dev
Signed-off-by: Sean Christopherson <seanjc@google.com>
(cherry picked from commit cdc69269b18a19cb76eaf7bf4fa47fe270dcaf11)

https://virtuozzo.atlassian.net/browse/VSTOR-157390
Feature: fix ms/kvm
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 arch/x86/kvm/svm/svm.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 385b6db1698af..f4e581d35c88b 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -222,6 +222,19 @@ int svm_set_efer(struct kvm_vcpu *vcpu, u64 efer)
 
 	if ((old_efer & EFER_SVME) != (efer & EFER_SVME)) {
 		if (!(efer & EFER_SVME)) {
+			/*
+			 * Architecturally, clearing EFER.SVME while a guest is
+			 * running yields undefined behavior, i.e. KVM can do
+			 * literally anything.  Force the vCPU back into L1 as
+			 * that is the safest option for KVM, but synthesize a
+			 * triple fault (for L1!) so that KVM at least doesn't
+			 * run random L2 code in the context of L1.  Do so if
+			 * and only if the vCPU is actively running, e.g. to
+			 * avoid positives if userspace is stuffing state.
+			 */
+			if (is_guest_mode(vcpu) && vcpu->wants_to_run)
+				kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu);
+
 			svm_leave_nested(vcpu);
 			svm_set_gif(svm, true);
 			/* #GP intercept is still needed for vmware backdoor */

-- 
2.43.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Devel] [PATCH hci-8.2 7/7] ms/KVM: selftests: Add a test for L2 clearing EFER.SVME without intercept
  2026-11-26 21:52 [Devel] [PATCH hci-8.2 0/7] KVM fixes for the 8.2 kernel Konstantin Khorenko
                   ` (5 preceding siblings ...)
  2026-11-26 21:53 ` [Devel] [PATCH hci-8.2 6/7] ms/KVM: SVM: Triple fault L1 on unintercepted EFER.SVME clear by L2 Konstantin Khorenko
@ 2026-11-26 21:53 ` Konstantin Khorenko
  2026-12-01  0:50   ` no-reply
  2026-11-27 14:43 ` [Devel] [PATCH hci-8.2 0/7] KVM fixes for the 8.2 kernel Konstantin Khorenko
  7 siblings, 1 reply; 16+ messages in thread
From: Konstantin Khorenko @ 2026-11-26 21:53 UTC (permalink / raw)
  To: Pavel Tikhomirov, Vasileios Almpanis; +Cc: devel

From: Yosry Ahmed <yosry.ahmed@linux.dev>

Add a test that verifies KVM's newly introduced behavior of synthesizing
a triple fault in L1 if L2 clears EFER.SVME without an L1 interception
(which is architecturally undefined).

Signed-off-by: Yosry Ahmed <yosry.ahmed@linux.dev>
Link: https://patch.msgid.link/20260209195142.2554532-3-yosry.ahmed@linux.dev
Signed-off-by: Sean Christopherson <seanjc@google.com>
[khorenko@: Makefile.kvm context: 26.x has no svm_nested_invalid_vmcb12_gpa
 test]
(cherry picked from commit 3900e56eb184abcc8a16ab52af24ea255589acc2)

https://virtuozzo.atlassian.net/browse/VSTOR-157390
Feature: fix ms/kvm
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 tools/testing/selftests/kvm/Makefile.kvm           |  1 +
 .../selftests/kvm/x86/svm_nested_clear_efer_svme.c | 55 ++++++++++++++++++++++
 2 files changed, 56 insertions(+)

diff --git a/tools/testing/selftests/kvm/Makefile.kvm b/tools/testing/selftests/kvm/Makefile.kvm
index 9d41f0d045ab0..a5d4d6a784ce7 100644
--- a/tools/testing/selftests/kvm/Makefile.kvm
+++ b/tools/testing/selftests/kvm/Makefile.kvm
@@ -97,6 +97,7 @@ TEST_GEN_PROGS_x86 += x86/state_test
 TEST_GEN_PROGS_x86 += x86/vmx_preemption_timer_test
 TEST_GEN_PROGS_x86 += x86/svm_vmcall_test
 TEST_GEN_PROGS_x86 += x86/svm_int_ctl_test
+TEST_GEN_PROGS_x86 += x86/svm_nested_clear_efer_svme
 TEST_GEN_PROGS_x86 += x86/svm_nested_shutdown_test
 TEST_GEN_PROGS_x86 += x86/svm_nested_soft_inject_test
 TEST_GEN_PROGS_x86 += x86/tsc_scaling_sync
diff --git a/tools/testing/selftests/kvm/x86/svm_nested_clear_efer_svme.c b/tools/testing/selftests/kvm/x86/svm_nested_clear_efer_svme.c
new file mode 100644
index 0000000000000..a521a9eed0613
--- /dev/null
+++ b/tools/testing/selftests/kvm/x86/svm_nested_clear_efer_svme.c
@@ -0,0 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2026, Google LLC.
+ */
+#include "kvm_util.h"
+#include "vmx.h"
+#include "svm_util.h"
+#include "kselftest.h"
+
+
+#define L2_GUEST_STACK_SIZE 64
+
+static void l2_guest_code(void)
+{
+	unsigned long efer = rdmsr(MSR_EFER);
+
+	/* generic_svm_setup() initializes EFER_SVME set for L2 */
+	GUEST_ASSERT(efer & EFER_SVME);
+	wrmsr(MSR_EFER, efer & ~EFER_SVME);
+
+	/* Unreachable, L1 should be shutdown */
+	GUEST_ASSERT(0);
+}
+
+static void l1_guest_code(struct svm_test_data *svm)
+{
+	unsigned long l2_guest_stack[L2_GUEST_STACK_SIZE];
+
+	generic_svm_setup(svm, l2_guest_code,
+			  &l2_guest_stack[L2_GUEST_STACK_SIZE]);
+	run_guest(svm->vmcb, svm->vmcb_gpa);
+
+	/* Unreachable, L1 should be shutdown */
+	GUEST_ASSERT(0);
+}
+
+int main(int argc, char *argv[])
+{
+	struct kvm_vcpu *vcpu;
+	struct kvm_vm *vm;
+	vm_vaddr_t nested_gva = 0;
+
+	TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SVM));
+
+	vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code);
+
+	vcpu_alloc_svm(vm, &nested_gva);
+	vcpu_args_set(vcpu, 1, nested_gva);
+
+	vcpu_run(vcpu);
+	TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_SHUTDOWN);
+
+	kvm_vm_free(vm);
+	return 0;
+}

-- 
2.43.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Devel] [PATCH hci-8.2 0/7] KVM fixes for the 8.2 kernel
  2026-11-26 21:52 [Devel] [PATCH hci-8.2 0/7] KVM fixes for the 8.2 kernel Konstantin Khorenko
                   ` (6 preceding siblings ...)
  2026-11-26 21:53 ` [Devel] [PATCH hci-8.2 7/7] ms/KVM: selftests: Add a test for L2 clearing EFER.SVME without intercept Konstantin Khorenko
@ 2026-11-27 14:43 ` Konstantin Khorenko
  7 siblings, 0 replies; 16+ messages in thread
From: Konstantin Khorenko @ 2026-11-27 14:43 UTC (permalink / raw)
  To: Pavel Tikhomirov, Vasileios Almpanis, Konstantin Khorenko; +Cc: devel

On Thu, 26 Nov 2026 22:52:58 +0100, Konstantin Khorenko wrote:
> KVM fixes for the 8.2 kernel
> 
> The KVM fixes the 8.1 kernel got in 24.4, for the 26.x branch: from
> 6.12.y stable where it has them, patches 6-7 from mainline.
> 
> - Patches 1-4 (VSTOR-157287): a guest can lock up or exhaust the host.
>   - Patch 1: CVE-2026-99713.
>   - Patch 2: CVE-2026-99712.
>   - Patch 3: nVMX MSR unwind on a failed VM-Entry.
>   - Patch 4: CVE-2026-99710.
> - Patch 5 (VSTOR-157390): CVE-2026-99312, a stale L2 MMU root after
>   INIT.
> - Patches 6-7 (VSTOR-157390): L2 clearing EFER.SVME without an L1
>   intercept now triple-faults L1, with a selftest.
> 
> [...]

Applied to branch-rh10-6.12.0-211.75.1.26.x.vz10-ovz, will be released in rh10-6.12.0-211.75.1.26.5.vz10, thanks!

[1/7] ms/KVM: x86/mmu: Conditionally resched when retrying gPTE walk on A/D update failure
      https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/2a4b769f1bc7
[2/7] ms/KVM: x86: Conditionally resched when restarting REP string emulation
      https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/67ea65424008
[3/7] ms/KVM: nVMX: Process each host MSR entry at most once when unwinding failed VM-Entry
      https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/dad94d8f9f85
[4/7] ms/KVM: x86/mmu: Cap number of parent PTEs per SP at 1000 (the arbitrary rmap limit)
      https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/2fe843c31933
[5/7] ms/KVM: x86: Unconditionally reset MMU context when emulating INIT
      https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/b2300c4cb8e8
[6/7] ms/KVM: SVM: Triple fault L1 on unintercepted EFER.SVME clear by L2
      https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/e3e6028574f8
[7/7] ms/KVM: selftests: Add a test for L2 clearing EFER.SVME without intercept
      https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/68d7c50146a2

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team


_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Devel] [PATCH hci-8.2 1/7] ms/KVM: x86/mmu: Conditionally resched when retrying gPTE walk on A/D update failure
  2026-11-26 21:52 ` [Devel] [PATCH hci-8.2 1/7] ms/KVM: x86/mmu: Conditionally resched when retrying gPTE walk on A/D update failure Konstantin Khorenko
@ 2026-12-01  0:44   ` no-reply
  0 siblings, 0 replies; 16+ messages in thread
From: no-reply @ 2026-12-01  0:44 UTC (permalink / raw)
  To: Konstantin Khorenko, Pavel Tikhomirov, Vasileios Almpanis; +Cc: devel

> From: Sean Christopherson <seanjc@google.com>
> 
> [ Upstream commit b2691b3a6cd230209736c89684dab90d939aa56b ]
> 
> Conditionally reschedule when retrying a guest PTE walk because the CMPXCHG
> to update A/D bits failed, e.g. because a different task/vCPU modified the
> relevant gPTEs.  On kernels without involuntary preemption of some kind, a
> misbehaving guest can "capture" a pCPU effectively indefinitely and trigger
> soft lockups by continuously modifying its gPTEs such that the result of
> the walk is remains valid.
> 
> Fixes: b3e4e63fd9ee ("KVM: MMU: Use cmpxchg for pte updates on walk_addr()")
> Cc: stable@vger.kernel.org
> Reported-by: Stefan Teodorescu <fane@google.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> Message-ID: <20261022015903.282261-1-seanjc@google.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> (cherry picked from commit 399c8c1e2ea42018960a31ef3a2e93554e50f606)
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-157287
> Feature: fix ms/kvm
> Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>

Sashiko has reviewed this patch and found no issues.

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261126-khorenko-vstor-157390-kvm-fixes-v1-0-ea4024e03c63@virtuozzo.com?part=1


_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Devel] [PATCH hci-8.2 2/7] ms/KVM: x86: Conditionally resched when restarting REP string emulation
  2026-11-26 21:53 ` [Devel] [PATCH hci-8.2 2/7] ms/KVM: x86: Conditionally resched when restarting REP string emulation Konstantin Khorenko
@ 2026-12-01  0:45   ` no-reply
  0 siblings, 0 replies; 16+ messages in thread
From: no-reply @ 2026-12-01  0:45 UTC (permalink / raw)
  To: Konstantin Khorenko, Pavel Tikhomirov, Vasileios Almpanis; +Cc: devel

> From: Sean Christopherson <seanjc@google.com>
> 
> [ Upstream commit ae85ac25eb671d174811cc3101549448671fd505 ]
> 
> When restarting emulation, e.g. of a REP-prefixed string instruction,
> conditionally reschedule as emulating guest writes can be deceptively slow
> and expensive, e.g. when shadow paging is in use and each write can trigger
> write tracking.
> 
> In a perfect world, restarting emulation (or not) would be less arbitrary,
> e.g. would honor not only host events (NEED_RESCHED, signals, etc.) but
> also guest events (e.g. by checking kvm_vcpu_has_events()).  Unfortunately,
> as pointed out by Sashiko, pio_in_emulated()'s read-ahead logic is baked
> into the restart logic, as KVM relies on restarting emulation to drain the
> cache and avoid duplicate reads from the I/O port.  I.e. re-entering the
> [ ... ]
> (cherry picked from commit c1293d2134c2d63741b197a1e5a6363894ed4bce)
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-157287
> Feature: fix ms/kvm
> Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>

Sashiko has reviewed this patch and found no issues.

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261126-khorenko-vstor-157390-kvm-fixes-v1-0-ea4024e03c63@virtuozzo.com?part=2


_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Devel] [PATCH hci-8.2 3/7] ms/KVM: nVMX: Process each host MSR entry at most once when unwinding failed VM-Entry
  2026-11-26 21:53 ` [Devel] [PATCH hci-8.2 3/7] ms/KVM: nVMX: Process each host MSR entry at most once when unwinding failed VM-Entry Konstantin Khorenko
@ 2026-12-01  0:45   ` no-reply
  0 siblings, 0 replies; 16+ messages in thread
From: no-reply @ 2026-12-01  0:45 UTC (permalink / raw)
  To: Konstantin Khorenko, Pavel Tikhomirov, Vasileios Almpanis; +Cc: devel

> From: Sean Christopherson <seanjc@google.com>
> 
> [ Upstream commit c33ef9d334059f7cb167569ed7b4779752fe4425 ]
> 
> Add a missing "break" in the inner for-loop of the open coded mess that
> unwinds MSRs back to the pre-VM-Enter state when VMLAUNCH/VMRESUME VM-Fails
> due to a consistency check that is caught by hardware but missed by KVM.
> I.e. move on to the next MSR in the VM-Entry load list after performing a
> write using a value found in the VM-Exit load list.  Processing *every*
> matching entry in the VM-Exit load list makes the processing quadratic,
> which is problematic if the load lists are full of MSRs that are expensive
> to emulate.  E.g. writing APIC_BASE triggers kvm_recalculate_apic_map() and
> a whole pile of unnecessary work.
> 
> Functionally, arbitrarily restoring the value of the first matching entry
> [ ... ]
> (cherry picked from commit 05fae367c6878d08f54a7c5bb6986a5e57e9bd1c)
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-157287
> Feature: fix ms/kvm
> Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>

Sashiko has reviewed this patch and found no issues.

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261126-khorenko-vstor-157390-kvm-fixes-v1-0-ea4024e03c63@virtuozzo.com?part=3


_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Devel] [PATCH hci-8.2 4/7] ms/KVM: x86/mmu: Cap number of parent PTEs per SP at 1000 (the arbitrary rmap limit)
  2026-11-26 21:53 ` [Devel] [PATCH hci-8.2 4/7] ms/KVM: x86/mmu: Cap number of parent PTEs per SP at 1000 (the arbitrary rmap limit) Konstantin Khorenko
@ 2026-12-01  0:46   ` no-reply
  0 siblings, 0 replies; 16+ messages in thread
From: no-reply @ 2026-12-01  0:46 UTC (permalink / raw)
  To: Konstantin Khorenko, Pavel Tikhomirov, Vasileios Almpanis; +Cc: devel

> From: Sean Christopherson <seanjc@google.com>
> 
> [ Upstream commit e4558c3d7198ed9a0adc3304681f561f4e4d80e1 ]
> 
> When potentially reusing a shadow page, zap the shadow page if its number
> of parent PTEs exceeds KVM's (mostly) arbitrary rmap recycling threshold.
> Letting the guest create a (mostly) unbounded number of parent PTEs allows
> the guest to coerce KVM into creating lists containing millions of PTEs,
> effectively bounded only by the maximum number of shadow pages.
> 
> Because PTE lists are simple singly linked lists, removal is O(n).  Even
> worse, if a list is constructed just so, teardown can be O(n^2), e.g. if
> SPTEs are built such that zapping child SPTEs always zaps the last entry
> in the list.  To cap things off, all paths that walk PTE lists do so
> while holding mmu_lock, without conditionally rescheduling.
> [ ... ]
> (cherry picked from commit edf87e07376054eedcd5306e0794a26e3004d97b)
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-157287
> Feature: fix ms/kvm
> Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>

Sashiko has reviewed this patch and found no issues.

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261126-khorenko-vstor-157390-kvm-fixes-v1-0-ea4024e03c63@virtuozzo.com?part=4


_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Devel] [PATCH hci-8.2 5/7] ms/KVM: x86: Unconditionally reset MMU context when emulating INIT
  2026-11-26 21:53 ` [Devel] [PATCH hci-8.2 5/7] ms/KVM: x86: Unconditionally reset MMU context when emulating INIT Konstantin Khorenko
@ 2026-12-01  0:47   ` no-reply
  0 siblings, 0 replies; 16+ messages in thread
From: no-reply @ 2026-12-01  0:47 UTC (permalink / raw)
  To: Konstantin Khorenko, Pavel Tikhomirov, Vasileios Almpanis; +Cc: devel

> From: Sean Christopherson <seanjc@google.com>
> 
> [ Upstream commit c7c288d178cb0b78d3464a616b16b1aa0b316049 ]
> 
> Force an MMU reset when emulating an INIT even if paging was already
> disabled, as the MMU page role includes guest_mode (L2), i.e. an INIT while
> L2 is running with CR0.PG=0 will result in KVM running L1 with a stale MMU
> context.
> 
> Alternatively, the reset could be scoped strictly to paging being enabled
> or L2 being active, but SMM is also encoded in the page role.  Even though
> it _should_ be impossible for the vCPU to be INIT'd while SMM is active,
> there's zero value in not handling SMM.  At that point, the only scenario
> where KVM _doesn't_ need to reset the MMU context is on an INIT with the
> vCPU running in Real Mode or Unpaged Protect Mode, and while INIT in those
> [ ... ]
> (cherry picked from commit f55a3e4e08dc004b4bab7c1e9323d7e7e96e266a)
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-157390
> Feature: fix ms/kvm
> Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>

Sashiko has reviewed this patch and found no issues.

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261126-khorenko-vstor-157390-kvm-fixes-v1-0-ea4024e03c63@virtuozzo.com?part=5


_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Devel] [PATCH hci-8.2 6/7] ms/KVM: SVM: Triple fault L1 on unintercepted EFER.SVME clear by L2
  2026-11-26 21:53 ` [Devel] [PATCH hci-8.2 6/7] ms/KVM: SVM: Triple fault L1 on unintercepted EFER.SVME clear by L2 Konstantin Khorenko
@ 2026-12-01  0:49   ` no-reply
  0 siblings, 0 replies; 16+ messages in thread
From: no-reply @ 2026-12-01  0:49 UTC (permalink / raw)
  To: Konstantin Khorenko, Pavel Tikhomirov, Vasileios Almpanis; +Cc: devel

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] kvm/svm: comment typo and commit message omits wants_to_run
  gating
--

commit 241f9fb2c8d3d5ea8f0d77081ce249af0f7abd5b
Author: Yosry Ahmed <yosry.ahmed@linux.dev>

ms/KVM: SVM: Triple fault L1 on unintercepted EFER.SVME clear by L2

When L2 clears EFER.SVME and L1 does not intercept the write, svm_set_efer() now requests a triple fault for L1 before tearing down the nested state. Previously KVM left guest mode and kept running L1 without injecting a #VMEXIT.

Link: https://patch.msgid.link/20260209195142.2554532-2-yosry.ahmed@linux.dev

> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index 385b6db1698af..f4e581d35c88b 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -222,6 +222,19 @@ int svm_set_efer(struct kvm_vcpu *vcpu, u64 efer)
>
>  	if ((old_efer & EFER_SVME) != (efer & EFER_SVME)) {
>  		if (!(efer & EFER_SVME)) {
> +			/*
> +			 * Architecturally, clearing EFER.SVME while a guest is
> +			 * running yields undefined behavior, i.e. KVM can do
> +			 * literally anything.  Force the vCPU back into L1 as
> +			 * that is the safest option for KVM, but synthesize a
> +			 * triple fault (for L1!) so that KVM at least doesn't
> +			 * run random L2 code in the context of L1.  Do so if
> +			 * and only if the vCPU is actively running, e.g. to
> +			 * avoid positives if userspace is stuffing state.
> +			 */
> +			if (is_guest_mode(vcpu) && vcpu->wants_to_run)
> +				kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu);

[Severity: Low]
This isn't a bug, but the comment says "to avoid positives" where it
presumably means "to avoid false positives".

Also, the commit message does not mention the vcpu->wants_to_run condition.
Because wants_to_run is only set inside KVM_RUN, host-initiated EFER writes
outside KVM_RUN (KVM_SET_SREGS, KVM_SET_NESTED_STATE) do not trigger the
triple fault. Could the changelog say so?

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261126-khorenko-vstor-157390-kvm-fixes-v1-0-ea4024e03c63@virtuozzo.com?part=6

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Devel] [PATCH hci-8.2 7/7] ms/KVM: selftests: Add a test for L2 clearing EFER.SVME without intercept
  2026-11-26 21:53 ` [Devel] [PATCH hci-8.2 7/7] ms/KVM: selftests: Add a test for L2 clearing EFER.SVME without intercept Konstantin Khorenko
@ 2026-12-01  0:50   ` no-reply
  0 siblings, 0 replies; 16+ messages in thread
From: no-reply @ 2026-12-01  0:50 UTC (permalink / raw)
  To: Konstantin Khorenko, Pavel Tikhomirov, Vasileios Almpanis; +Cc: devel

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] selftests/kvm: svm_nested_clear_efer_svme.c has unused includes
--

commit e7569dc074d050f2541b7f7d0c986006bb7ed5e1
Author: Yosry Ahmed <yosry.ahmed@linux.dev>

ms/KVM: selftests: Add a test for L2 clearing EFER.SVME without intercept

This adds a selftest that checks KVM synthesizes a triple fault in L1 when
L2 clears EFER.SVME without an L1 intercept.

Link: https://patch.msgid.link/20260209195142.2554532-3-yosry.ahmed@linux.dev

> diff --git a/tools/testing/selftests/kvm/x86/svm_nested_clear_efer_svme.c b/tools/testing/selftests/kvm/x86/svm_nested_clear_efer_svme.c
> new file mode 100644
> index 0000000000000..a521a9eed0613
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/x86/svm_nested_clear_efer_svme.c
> @@ -0,0 +1,55 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (C) 2026, Google LLC.
> + */
> +#include "kvm_util.h"
> +#include "vmx.h"
> +#include "svm_util.h"
> +#include "kselftest.h"
> +
> +

[Severity: Low]
This isn't a bug, but are the vmx.h and kselftest.h includes needed? This is
an SVM-only test, and it calls no ksft_* helper. The symbols it does use
come in indirectly through svm_util.h and kvm_util.h. There is also a
stray double blank line after the includes.

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261126-khorenko-vstor-157390-kvm-fixes-v1-0-ea4024e03c63@virtuozzo.com?part=7

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2026-12-01  0:51 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-26 21:52 [Devel] [PATCH hci-8.2 0/7] KVM fixes for the 8.2 kernel Konstantin Khorenko
2026-11-26 21:52 ` [Devel] [PATCH hci-8.2 1/7] ms/KVM: x86/mmu: Conditionally resched when retrying gPTE walk on A/D update failure Konstantin Khorenko
2026-12-01  0:44   ` no-reply
2026-11-26 21:53 ` [Devel] [PATCH hci-8.2 2/7] ms/KVM: x86: Conditionally resched when restarting REP string emulation Konstantin Khorenko
2026-12-01  0:45   ` no-reply
2026-11-26 21:53 ` [Devel] [PATCH hci-8.2 3/7] ms/KVM: nVMX: Process each host MSR entry at most once when unwinding failed VM-Entry Konstantin Khorenko
2026-12-01  0:45   ` no-reply
2026-11-26 21:53 ` [Devel] [PATCH hci-8.2 4/7] ms/KVM: x86/mmu: Cap number of parent PTEs per SP at 1000 (the arbitrary rmap limit) Konstantin Khorenko
2026-12-01  0:46   ` no-reply
2026-11-26 21:53 ` [Devel] [PATCH hci-8.2 5/7] ms/KVM: x86: Unconditionally reset MMU context when emulating INIT Konstantin Khorenko
2026-12-01  0:47   ` no-reply
2026-11-26 21:53 ` [Devel] [PATCH hci-8.2 6/7] ms/KVM: SVM: Triple fault L1 on unintercepted EFER.SVME clear by L2 Konstantin Khorenko
2026-12-01  0:49   ` no-reply
2026-11-26 21:53 ` [Devel] [PATCH hci-8.2 7/7] ms/KVM: selftests: Add a test for L2 clearing EFER.SVME without intercept Konstantin Khorenko
2026-12-01  0:50   ` no-reply
2026-11-27 14:43 ` [Devel] [PATCH hci-8.2 0/7] KVM fixes for the 8.2 kernel Konstantin Khorenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox