Re: [PATCH v3 09/15] KVM: arm64: Free removed stage-2 tables in RCU callback

Sean Christopherson
2022-11-01T20:29:05Z

On Thu, Oct 27, 2022, Oliver Upton wrote:
> There is no real urgency to free a stage-2 subtree that was pruned.
> Nonetheless, KVM does the tear down in the stage-2 fault path while
> holding the MMU lock.
>
> Free removed stage-2 subtrees after an RCU grace period. To guarantee
> all stage-2 table pages are freed before killing a VM, add an
> rcu_barrier() to the flush path.

This is _very_ misleading. The above paints RCU as an optimization of sorts to
avoid doing work while holding mmu_lock. Freeing page tables in an RCU callback
is _required_ for correctness when allowing parallel page faults to remove page
tables, as holding mmu_lock for read in that case doesn't ensure no other CPU is
accessing and/or holds a reference to the to-be-freed page table.

IMO, this patch should to be squashed with the previous patch, "Protect stage-2
traversal with RCU". One doesn't make any sense without the other.