linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC v2 0/6] guest_memfd: Track amount of memory allocated on inode
@ 2026-02-25  7:20 Ackerley Tng
  2026-02-25  7:20 ` [PATCH RFC v2 1/6] KVM: guest_memfd: Don't set FGP_ACCESSED when getting folios Ackerley Tng
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Ackerley Tng @ 2026-02-25  7:20 UTC (permalink / raw)
  To: Paolo Bonzini, Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Matthew Wilcox (Oracle),
	Shuah Khan, Jonathan Corbet, Alexander Viro, Christian Brauner,
	Jan Kara, seanjc, rientjes, rick.p.edgecombe, yan.y.zhao, fvdl,
	jthoughton, vannapurve, shivankg, michael.roth, pratyush,
	pasha.tatashin, kalyazin, tabba
  Cc: kvm, linux-kernel, linux-mm, linux-fsdevel, linux-kselftest,
	linux-doc, Ackerley Tng

Hi,

Currently, guest_memfd doesn't update inode's i_blocks or i_bytes at
all. Hence, st_blocks in the struct populated by a userspace fstat()
call on a guest_memfd will always be 0. This patch series makes
guest_memfd track the amount of memory allocated on an inode, which
allows fstat() to accurately report that on requests from userspace.

The inode's i_blocks and i_bytes fields are updated when the folio is
associated or disassociated from the guest_memfd inode, which are at
allocation and truncation times respectively.

In RFC v2, to update inode fields at truncation time, this series adds a
new .unaccount_folio callback to struct address_space_operations, which
guest_memfd uses to deduct the folio's size at truncation time.

The second patch, to use filemap_alloc_folio() during allocation of
guest_memfd folios, was written as a debugging step to resolve a bug
found by syzbot [1], but turned out to not be the fix. I include it
here because it cleans up the allocation process and provides a nice
foundation for updating inode fields during allocations.

The first patch was separately submitted [2], and provided here since
it is a prerequisite simplication before application of the second
patch.

Changes from RFC v1:

+ Removed a full custom implementation of .evict_inode for guest_memfd
  in favor of adding .unaccount_folio callback.

RFC v1: https://lore.kernel.org/all/cover.1771826352.git.ackerleytng@google.com/T/

[1] https://lore.kernel.org/all/29c347bde68ec027259654e8e85371307edf7058.1770148108.git.ackerleytng@google.com/
[2] https://lore.kernel.org/all/20260129172646.2361462-1-ackerleytng@google.com/

Signed-off-by: Ackerley Tng <ackerleytng@google.com>
---
Ackerley Tng (6):
      KVM: guest_memfd: Don't set FGP_ACCESSED when getting folios
      KVM: guest_memfd: Directly allocate folios with filemap_alloc_folio()
      fs: Add .unaccount_folio callback
      KVM: guest_memfd: Track amount of memory allocated on inode
      KVM: selftests: Wrap fstat() to assert success
      KVM: selftests: Test that st_blocks is updated on allocation

 Documentation/filesystems/vfs.rst                  |  8 +++
 include/linux/fs.h                                 |  1 +
 mm/filemap.c                                       |  3 ++
 tools/testing/selftests/kvm/guest_memfd_test.c     | 32 ++++++++----
 tools/testing/selftests/kvm/include/kvm_syscalls.h |  2 +
 virt/kvm/guest_memfd.c                             | 60 ++++++++++++++++------
 6 files changed, 80 insertions(+), 26 deletions(-)
---
base-commit: b1195183ed42f1522fae3fe44ebee3af437aa000
change-id: 20260225-gmem-st-blocks-733f35d10211

Best regards,
--
Ackerley Tng <ackerleytng@google.com>



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-02-25  7:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-25  7:20 [PATCH RFC v2 0/6] guest_memfd: Track amount of memory allocated on inode Ackerley Tng
2026-02-25  7:20 ` [PATCH RFC v2 1/6] KVM: guest_memfd: Don't set FGP_ACCESSED when getting folios Ackerley Tng
2026-02-25  7:20 ` [PATCH RFC v2 2/6] KVM: guest_memfd: Directly allocate folios with filemap_alloc_folio() Ackerley Tng
2026-02-25  7:20 ` [PATCH RFC v2 3/6] fs: Add .unaccount_folio callback Ackerley Tng
2026-02-25  7:20 ` [PATCH RFC v2 4/6] KVM: guest_memfd: Track amount of memory allocated on inode Ackerley Tng
2026-02-25  7:20 ` [PATCH RFC v2 5/6] KVM: selftests: Wrap fstat() to assert success Ackerley Tng
2026-02-25  7:20 ` [PATCH RFC v2 6/6] KVM: selftests: Test that st_blocks is updated on allocation Ackerley Tng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox