Re: [PATCH v4 0/3] KVM: Fix and account mem_attr_array reservations abandoned on ENOMEM

From: Sean Christopherson

Date: Thu Sep 24 2026 - 17:55:35 EST


On Tue, 15 Sep 2026 17:53:40 +0000, David Ballesteros wrote:
> Three small fixes to KVM's per-page memory attributes: release the xarray
> reservations that KVM_SET_MEMORY_ATTRIBUTES abandons when it fails partway
> through (1/3), make kvm_range_has_memory_attributes() agree with itself
> about what such a reservation means (2/3), and charge the xa_nodes to the
> caller's memcg as the code already intended (3/3).
>
> 1/3 Release the reservations abandoned on ENOMEM. This is a plain bug:
> xa_reserve() materializes entries GFN-by-GFN before the store phase,
> and on failure the loop bails without releasing what it reserved. A
> later clear covering them does erase them, but nothing obliges
> userspace to issue one; absent that, the reclaim path is
> kvm_destroy_vm(). The retained entries are not inert -- an
> abandoned reservation is an XA_ZERO_ENTRY, which
> kvm_range_has_memory_attributes()'s !attrs fast path counts as
> present (raw xas_find()) while kvm_get_memory_attributes() treats
> it as absent, so a straddling hugepage over such an entry is marked
> mixed and KVM stops using a hugepage for a range whose attributes
> are uniform. xa_release() erases only entries still reserved,
> leaving pre-existing value entries untouched.
>
> [...]

Applied patch 3, with a heavily modified changelog, to kvm-x86 fixes. For the
reservation behavior, I went with Zeng Chi's fix to have KVM treat ZERO values
as "no attributes". Having dangling reservations is a-ok, the memcg accounting
really needs to do the right thing there.

In the future, please don't have AI directly write changelogs. It's fine to
let AI generate a rough draft, for me at least, AI tends to be far too verbose
and uses terminology that isn't common in Linux/upstream. In other words, AI
tends to write changelogs (and bug reports) that require far too much effort
to understand.

I apologize in advance if you wrote the changelogs, i.e. if I am falsely
accusing you of being a robot. If AI didn't write the changelogs, well, you
do one heck of a job of imitating some of my newfound "friends" :-)

Gripes about AI aside, than you very much for the fixes!

[1/3] KVM: Release memory-attribute reservations abandoned on ENOMEM
[SKIP]
[2/3] KVM: Make kvm_range_has_memory_attributes() consistent about reservations
[SKIP]
[3/3] KVM: Account mem_attr_array nodes to the caller's memcg
https://github.com/kvm-x86/linux/commit/382e5d514b6f

--
https://github.com/kvm-x86/linux/tree/next