On Fri, 19 Jun 2026 at 01:32, Ackerley Tng via B4 Relay <[email protected]> wrote: > > From: Ackerley Tng <[email protected]> > > Add two test cases to the guest_memfd conversions selftest to cover > the scenario where a conversion is requested before any memory has been > allocated in the guest_memfd region. > > The KVM_SET_MEMORY_ATTRIBUTES2 ioctl can be called on a memory region at > any time. If the guest had not yet faulted in any pages for that region, > the kernel must record the conversion request and apply the requested state > when the pages are eventually allocated. > > The new tests cover both conversion directions. > > Signed-off-by: Ackerley Tng <[email protected]> > Co-developed-by: Sean Christopherson <[email protected]> > Signed-off-by: Sean Christopherson <[email protected]>
Reviewed-by: Fuad Tabba <[email protected]> Cheers, /fuad > --- > .../selftests/kvm/x86/guest_memfd_conversions_test.c | 14 > ++++++++++++++ > 1 file changed, 14 insertions(+) > > diff --git a/tools/testing/selftests/kvm/x86/guest_memfd_conversions_test.c > b/tools/testing/selftests/kvm/x86/guest_memfd_conversions_test.c > index 8e17d5c08aeb8..b43ac196330f1 100644 > --- a/tools/testing/selftests/kvm/x86/guest_memfd_conversions_test.c > +++ b/tools/testing/selftests/kvm/x86/guest_memfd_conversions_test.c > @@ -265,6 +265,20 @@ GMEM_CONVERSION_MULTIPAGE_TEST_INIT_SHARED(indexing, 4) > #undef combine > } > > +/* > + * Test that even if there are no folios yet, conversion requests are > recorded > + * in guest_memfd. > + */ > +GMEM_CONVERSION_TEST_INIT_SHARED(before_allocation_shared) > +{ > + test_convert_to_private(t, 0, 0, 'A'); > +} > + > +GMEM_CONVERSION_TEST_INIT_PRIVATE(before_allocation_private) > +{ > + test_convert_to_shared(t, 0, 0, 'A', 'B'); > +} > + > int main(int argc, char *argv[]) > { > TEST_REQUIRE(kvm_check_cap(KVM_CAP_VM_TYPES) & > BIT(KVM_X86_SW_PROTECTED_VM)); > > -- > 2.55.0.rc0.738.g0c8ab3ebcc-goog > >
