Re: [RFC PATCH v1 06/37] KVM: guest_memfd: Update kvm_gmem_populate() to use gmem attributes

From: Ackerley Tng

Date: Fri Nov 14 2025 - 19:52:57 EST


Yan Zhao <yan.y.zhao@xxxxxxxxx> writes:

>> #ifdef CONFIG_HAVE_KVM_ARCH_GMEM_POPULATE
>> +static bool kvm_gmem_range_is_private(struct gmem_inode *gi, pgoff_t index,
>> + size_t nr_pages, struct kvm *kvm, gfn_t gfn)
>> +{
>> + pgoff_t end = index + nr_pages - 1;
>> + void *entry;
>> +
>> + if (vm_memory_attributes)
>> + return kvm_range_has_vm_memory_attributes(kvm, gfn, gfn + nr_pages,
>> + KVM_MEMORY_ATTRIBUTE_PRIVATE,
>> + KVM_MEMORY_ATTRIBUTE_PRIVATE);
> Can't compile kvm_range_has_vm_memory_attributes() if
> CONFIG_KVM_VM_MEMORY_ATTRIBUTES is not set.

Thanks! I will fix this in the next revision.


We've been discussing HugeTLB support in the guest_memfd upstream calls
and I'd like to add a quick follow up here, with code, for anyone who
might be interested. Here's a WIP tree:

https://github.com/googleprodkernel/linux-cc/tree/wip-gmem-conversions-hugetlb-restructuring

This tree was based off kvm-next (as of 2025-10-08), and includes

+ Mmap fixes from Sean
+ NUMA mempolicy support from Shivank Garg (AMD)
+ Some cleanup patches from Sean
+ Conversion series [1] with some cleanups (Thanks for the comments and
reviews on this series! Haven't had time to figure out all of it,
addressed some first)
+ st_blocks fix for guest_memfd, which was discussed at the guest_memfd
upstream call: slides [2]
+ HugeTLB support without conversion: this stage does not yet take into
account comments from the upstream call. This stage provides support
for HugeTLB to be used through guest_memfd for private memory. This
has to be used with the KVM parameter vm_memory_attributes set to
true. This stage can be used to test Yan's TDX huge page support by
setting up guest_memfd with HugeTLB just for private memory, with
shared memory being taken from elsewhere.
+ HugeTLB support with conversion and folio restructuring: this stage
also does not take into account comments from the upstream call, so it
still disables the INIT_SHARED flag, although HugeTLB can now be used
with in-place conversion for both shared and private memory. This can
be used to test Yan's TDX huge page support.

[1] https://lore.kernel.org/all/cover.1760731772.git.ackerleytng@xxxxxxxxxx/T/
[2] https://lpc.events/event/18/contributions/1764/attachments/1409/3715/2025-10-30%20guest_memfd%20upstream%20call_%20guest_memfd%20HugeTLB%20support%20overview.pdf