[PATCH RFC v4 33/44] KVM: selftests: Test that conversion to private does not support ZERO

Ackerley Tng
2026-03-26T22:25:45Z

Test that conversion to private specifying the
KVM_SET_MEMORY_ATTRIBUTES2_ZERO flag returns -1 and sets errno to
EOPNOTSUPP.

Signed-off-by: Ackerley Tng <ackerleytng@google.com>
---
.../testing/selftests/kvm/guest_memfd_conversions_test.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)

diff --git a/tools/testing/selftests/kvm/guest_memfd_conversions_test.c b/tools/testing/selftests/kvm/guest_memfd_conversions_test.c
index 4ccd3d515bb26..c0abc69f15332 100644
--- a/tools/testing/selftests/kvm/guest_memfd_conversions_test.c
+++ b/tools/testing/selftests/kvm/guest_memfd_conversions_test.c
@@ -488,6 +488,21 @@ GMEM_CONVERSION_MULTIPAGE_TEST_INIT_SHARED(elevated_refcount, 4)
}
}

+GMEM_CONVERSION_TEST_INIT_SHARED(convert_to_private_does_not_support_zero)
+{
+ const loff_t start_offset = 0;
+ loff_t error_offset = -1ul;
+ int ret;
+
+ ret = __gmem_set_private(t->gmem_fd, start_offset, nr_pages * page_size,
+ &error_offset,
+ KVM_SET_MEMORY_ATTRIBUTES2_ZERO);
+
+ TEST_ASSERT_EQ(ret, -1);
+ TEST_ASSERT_EQ(errno, EOPNOTSUPP);
+ TEST_ASSERT_EQ(error_offset, start_offset);
+}
+
int main(int argc, char *argv[])
{
TEST_REQUIRE(kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_SW_PROTECTED_VM));

--
2.53.0.1018.g2bb0e51243-goog