linux/virt/kvm
David Ballesteros 382e5d514b KVM: Ensure memory attributes xarray nodes are accounted to the caller's memcg
Explicitly instantiate the memory attributes xarray with XA_FLAGS_ACCOUNT
to ensure that all allocations are accounted to the memcg.  Frustratingly,
memory allocations done in the "fastpath" do not honor the passed in gfp,
even for an explicit xa_reserve().  Only the rare, slow path __xas_nomem()
honors the original gfp.  E.g.

  xa_reserve(..., GFP_KERNEL_ACCOUNT)
  |
  -> ...
     |
     -> __xa_cmpxchg_raw()
        |
        -> xas_store()  <== does not take @gfp
           |
           -> xas_create()
              |
              -> xas_alloc()

The bug was confirmed by observing that a process in a cgroup limited to
256 MiB grew radix_tree_node slab by ~512 MiB while its memory.current
stayed near 0.

Fixes: 5a475554db ("KVM: Introduce per-page memory attributes")
Cc: stable@vger.kernel.org
Assisted-by: Claude-Code:claude-opus-5
Signed-off-by: David Ballesteros <davimaba.v@proton.me>
Link: https://patch.msgid.link/20260915175335.138547-4-davimaba.v@proton.me
[sean: rewrite changelog, tag for stable]
Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-09-22 08:36:06 -07:00
..
async_pf.c KVM: remove redundant __GFP_NOWARN 2025-08-19 11:51:13 -07:00
async_pf.h
binary_stats.c KVM: Remove subtle "struct kvm_stats_desc" pseudo-overlay 2026-01-08 10:40:48 -08:00
coalesced_mmio.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
coalesced_mmio.h
dirty_ring.c KVM: Reject wrapped offset in kvm_reset_dirty_gfn() 2026-05-12 22:16:16 +02:00
eventfd.c KVM: Replace guest-triggerable BUG_ON() in ioeventfd datamatch with get_unaligned() 2026-06-24 11:25:14 +02:00
guest_memfd.c Arm: 2026-08-25 11:48:04 -07:00
guest_memfd.h KVM: guest_memfd: Move gmem function declarations to dedicated guest_memfd.h 2026-08-05 10:00:53 -07:00
irqchip.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
Kconfig KVM: guest_memfd: Rename prepare() hook and Kconfig to make_private() / CONVERT 2026-07-27 09:42:42 -07:00
kvm_main.c KVM: Ensure memory attributes xarray nodes are accounted to the caller's memcg 2026-09-22 08:36:06 -07:00
kvm_mm.h KVM: guest_memfd: Move gmem function declarations to dedicated guest_memfd.h 2026-08-05 10:00:53 -07:00
Makefile.kvm KVM: Rename CONFIG_KVM_PRIVATE_MEM to CONFIG_KVM_GUEST_MEMFD 2025-08-27 04:34:59 -04:00
pfncache.c KVM: pfncache: Precisely track refcounted pages 2024-10-25 12:57:59 -04:00
vfio.c KVM: VFIO: update coherency only if file was deleted 2026-05-13 11:12:40 -07:00
vfio.h