“KVM Chainsaw”: Cleaning Up the Kernel's “God Structure” in Linux 7.3

Translated by a model; the original is in Russian.

· Linux and open source
KVM maintainer Paolo Bonzini has merged into the next branch a patch series that splits the overloaded kvm_mmu structure into three parts. The work is slated for the Linux 7.3 development cycle.

cover.svg

A patch series with the colorful name “KVM Chainsaw” is getting ready to land in the Linux 7.3 merge window. Red Hat engineer and KVM maintainer Paolo Bonzini has already merged the kvm-chainsaw branch into the “next” section of the KVM Git repository, which means the changes are set to make their way into the next kernel.

What the problem is

The central object of the rework is the kvm_mmu structure, which Bonzini flatly calls a “god data structure.” Over the years it has taken on three different responsibilities at once: describing the format of the guest's page tables, walking those tables, and building new ones. As a result, the related (and, by the developer's own admission, poorly named) nested_mmu structure is only used partially, and some of the code is either duplicated or, conversely, swapped out for simplified variants.

What the “chainsaw” does

The series saws kvm_mmu apart into three independent pieces:

  • kvm_pagewalk — the page table walker. There are two of them per virtual CPU: gva_walk and ngpa_walk.
  • kvm_mmu — all that's left for it is building page tables; to do so, it reaches out to the appropriate walker.
  • kvm_page_format — makes it possible to work with already existing PTEs and consolidates the logic around permissions and reserved-bit checking.

The benefit is apparent from the cleanup alone. Among other things, it clears up a long-standing confusion between guest_mmu and nested_mmu: the latter appeared earlier and “stole” the obvious name, which is why the code contained comments like “exclude the nested MMU” in places where what was actually excluded was guest_mmu. Renaming guest_mmu could be the next step — though opinions in the RFC discussion diverged on exactly how to do it.

Not just tidying up

The final patch in the series shows that code reuse is good for new capabilities too. By adapting the permission_fault() mechanism to check SPTEs, the developers open the door to supporting entries with mismatched execute permissions for supervisor and user (XS≠XU) — KVM doesn't support them right now, but down the line they could be added via memory attributes.

The Linux 7.3 merge window will open in the second half of August, so the “chainsaw” and a host of other changes should be expected right there.


Source: Phoronix

Comments

Sign in, to comment.

  • No comments yet.