[RFC PATCH 08/55] KVM: selftests: Cover plane run-state ioctls in planes_test

From: David Woodhouse

Date: Sat Oct 17 2026 - 08:37:07 EST


From: David Woodhouse <dwmw@xxxxxxxxxxxx>

Assert the initial stopped state of a new plane-1 vCPU, a runnable and
back-to-stopped round trip, and rejection of out-of-range states.

The tools copy of linux/kvm.h picks up the plane run-state ioctl
definitions.

Signed-off-by: David Woodhouse <dwmw@xxxxxxxxxxxx>
Assisted-by: LLM
---
tools/include/uapi/linux/kvm.h | 4 ++++
tools/testing/selftests/kvm/x86/planes_test.c | 22 +++++++++++++++++++
2 files changed, 26 insertions(+)

diff --git a/tools/include/uapi/linux/kvm.h b/tools/include/uapi/linux/kvm.h
index 586c0d6c168c..8d9f7e6bba19 100644
--- a/tools/include/uapi/linux/kvm.h
+++ b/tools/include/uapi/linux/kvm.h
@@ -1370,6 +1370,10 @@ struct kvm_s390_keyop {
#define KVM_HAS_DEVICE_ATTR _IOW(KVMIO, 0xe3, struct kvm_device_attr)

#define KVM_CREATE_PLANE _IO(KVMIO, 0xe4)
+#define KVM_GET_PLANE_RUN_STATE _IOR(KVMIO, 0xe5, __u32)
+#define KVM_SET_PLANE_RUN_STATE _IOW(KVMIO, 0xe6, __u32)
+#define KVM_PLANE_RUN_STATE_STOPPED 0
+#define KVM_PLANE_RUN_STATE_RUNNABLE 1

/*
* ioctls for vcpu fds
diff --git a/tools/testing/selftests/kvm/x86/planes_test.c b/tools/testing/selftests/kvm/x86/planes_test.c
index 3517175580d3..b28ed4077715 100644
--- a/tools/testing/selftests/kvm/x86/planes_test.c
+++ b/tools/testing/selftests/kvm/x86/planes_test.c
@@ -89,6 +89,28 @@ static void test_plane_lifecycle(void)
TEST_ASSERT(vcpu1_fd >= 0,
"KVM_CREATE_VCPU on plane 1 failed: errno %d", errno);

+ /* Plane 1 starts stopped; run state is readable and writable. */
+ {
+ u32 state = 0xff;
+
+ kvm_ioctl(vcpu1_fd, KVM_GET_PLANE_RUN_STATE, &state);
+ TEST_ASSERT_EQ(state, KVM_PLANE_RUN_STATE_STOPPED);
+
+ state = KVM_PLANE_RUN_STATE_RUNNABLE;
+ kvm_ioctl(vcpu1_fd, KVM_SET_PLANE_RUN_STATE, &state);
+ state = 0xff;
+ kvm_ioctl(vcpu1_fd, KVM_GET_PLANE_RUN_STATE, &state);
+ TEST_ASSERT_EQ(state, KVM_PLANE_RUN_STATE_RUNNABLE);
+
+ state = KVM_PLANE_RUN_STATE_STOPPED;
+ kvm_ioctl(vcpu1_fd, KVM_SET_PLANE_RUN_STATE, &state);
+
+ state = 2;
+ TEST_ASSERT_EQ(__kvm_ioctl(vcpu1_fd, KVM_SET_PLANE_RUN_STATE,
+ &state), -1);
+ TEST_ASSERT_EQ(errno, EINVAL);
+ }
+
/* Register state is per plane: write plane 1, plane 0 unaffected. */
kvm_ioctl(vcpu1_fd, KVM_GET_REGS, &regs1);
regs1.rbx = 0x5157ca11; /* arbitrary marker */
--
2.50.1