Re: [PATCH] KVM: selftests: Test MADV_COLLAPSE on GUEST_MEMFD

From: Ackerley Tng

Date: Fri Feb 20 2026 - 19:00:08 EST


Sean Christopherson <seanjc@xxxxxxxxxx> writes:

> On Tue, Feb 17, 2026, Ackerley Tng wrote:
>>
>> [...snip...]
>>
>> +
>> + /*
>> + * Use aligned address so that MADV_COLLAPSE will not be
>> + * filtered out early in the collapsing routine.
>
> Please elaborate, the value below is way more magical than just being aligned.
>
>> + */
>> +#define ALIGNED_ADDRESS ((void *)0x4000000000UL)
>
> Use a "const void *" instead of #define inside a function. And use one of the
> appropriate size macros, e.g.
>
> const void *ALIGNED_ADDRESS = (void *)(SZ_1G * <some magic value>);
>
> But why hardcode a virtual address in the first place? If you a specific
> alignment, just allocate enough virtual memory to be able to meet those alignment
> requirements.
>
>> + mem = mmap(ALIGNED_ADDRESS, pmd_size, PROT_READ | PROT_WRITE,
>> + MAP_FIXED | MAP_SHARED, fd, 0);
>>
>> [...snip...]
>>
>> @@ -370,6 +441,7 @@ static void __test_guest_memfd(struct kvm_vm *vm, uint64_t flags)
>> gmem_test(mmap_supported, vm, flags);
>> gmem_test(fault_overflow, vm, flags);
>> gmem_test(numa_allocation, vm, flags);
>> + test_collapse(vm, flags);
>
> Why diverge from everything else? Yeah, the size is different, but that's easy
> enough to handle. And presumably the THP query needs to be able to fail gracefully,
> so something like this?
>
>
> [...snip...]
>

Addressed your comments in a v2 [*], thanks for reviewing!

[*] https://lore.kernel.org/all/cover.1771630983.git.ackerleytng@xxxxxxxxxx/T/