Thread (10 messages) 10 messages, 3 authors, 2026-08-24

Re: [PATCH v3 2/2] KVM: arm64: nv: Delay freeing of shadow S2 structures until VM destruction

flat view

From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
Date: 2026-08-24 11:18:23
Also in: kvmarm, stable

On Sat, Aug 22, 2026 at 09:12:32AM +0100, Marc Zyngier wrote:
On Fri, 21 Aug 2026 19:15:45 +0100,
"Lorenzo Stoakes (ARM)" [off-list ref] wrote:
quoted
quoted
@@ -1310,16 +1319,12 @@ void kvm_nested_s2_flush(struct kvm *kvm)

 void kvm_arch_flush_shadow_all(struct kvm *kvm)
 {
-	for (int i = kvm->arch.nested_mmus_size - 1; i >= 0; i--) {
+	for (int i = 0; i < kvm->arch.nested_mmus_size; i++) {
Hmm why this was in reverse before? :) I guess some product of the
kvfree() bit or maybe something else?
We allocate s2_mmus in S2_MMU_PER_VCPU chunks. Which means that it
complicates the freeing of the these structures, as they can only be
freed once all S2 PTs of that chunk have been freed. We have three
options:

- scan forward, and use complicated logic to work out that you have
  freed the last PTs of a chunk, freeing with a negative offset from
  the current point in the loop. Works, but hard to reason about in
  fewer than 3 seconds.

- scan backward, use simpler logic to ensure you have reached the
  beginning of a chunk, nuke it.

- have two loops, one for the PTs, one for the MMUs. That's what we
  end-up with due to the different garbage collection phases.
Ah I see, so tear down page tables of the 2nd of the pair, then after doing it
for the 1st of the pair free the chunk, makes sense.
Cheers,

	M.

--
Without deviation from the norm, progress is not possible.
--
Cheers, Lorenzo
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help