Skip to contentSkip to conversation

KVM: selftests: sync_regs_test: use KVM_SYNC_X86_VALID_FIELDS

PATCH In review Piotr Zarycki 2 participants 6 messages May 11 – May 19

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: selftests: sync_regs_test: use KVM_SYNC_X86_VALID_FIELDS

Use KVM_SYNC_X86_VALID_FIELDS instead of open-coding the same three flags, ensuring the test stays in sync with any future additions.

---
 tools/testing/selftests/kvm/x86/sync_regs_test.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/testing/selftests/kvm/x86/sync_regs_test.c +1 -2
index e0c52321f87c..8f9239f9d357 100644
@@ -79,7 +79,7 @@ static void compare_vcpu_events(struct kvm_vcpu_events *left,
 {
 }
 
-#define TEST_SYNC_FIELDS   (KVM_SYNC_X86_REGS|KVM_SYNC_X86_SREGS|KVM_SYNC_X86_EVENTS)
+#define TEST_SYNC_FIELDS   KVM_SYNC_X86_VALID_FIELDS
 #define INVALID_SYNC_FIELD 0x80000000
 
 /*
@@ -255,7 +255,6 @@ KVM_ONE_VCPU_TEST(sync_regs_test, req_and_verify_all_valid, guest_code)
 	struct kvm_regs regs;
 
 	/* Request and verify all valid register sets. */
-	/* TODO: BUILD TIME CHECK: TEST_ASSERT(KVM_SYNC_X86_NUM_FIELDS != 3); */
 	run->kvm_valid_regs = TEST_SYNC_FIELDS;
 	vcpu_run(vcpu);
 	TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
Signature · 1 line
2.54.0
#1 lore raw
Quoted 13 lines · Piotr Zarycki

Use KVM_SYNC_X86_VALID_FIELDS instead of open-coding the same three flags, ensuring the test stays in sync with any future additions.

---
 tools/testing/selftests/kvm/x86/sync_regs_test.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/testing/selftests/kvm/x86/sync_regs_test.c +0 -0
index e0c52321f87c..8f9239f9d357 100644

tools/testing/selftests/kvm/x86/sync_regs_test.c static void compare_vcpu_events(struct kvm_vcpu_events *left, · line 82

Quoted 5 lines
tools/testing/selftests/kvm/x86/sync_regs_test.c +1 -1
@@ -79,7 +79,7 @@ static void compare_vcpu_events(struct kvm_vcpu_events *left,
 {
 }
 
-#define TEST_SYNC_FIELDS   (KVM_SYNC_X86_REGS|KVM_SYNC_X86_SREGS|KVM_SYNC_X86_EVENTS)
+#define TEST_SYNC_FIELDS   KVM_SYNC_X86_VALID_FIELDS

Explicitly defining the set of fields to test is very deliberate. (a) we want to detect ABI breakage, e.g. if KVM removes a valid field. (b) if a field is added in the future, the test likely needs to be updated, i.e. would break if KVM extends KVM_SYNC_X86_VALID_FIELDS. (c) KVM_SYNC_X86_VALID_FIELDS probably shouldn't be defined in a uapi header; for all intents and purposes it's a KVM- internal details.

Quoted 14 lines
tools/testing/selftests/kvm/x86/sync_regs_test.c +0 -1
 #define INVALID_SYNC_FIELD 0x80000000
 
 /*
@@ -255,7 +255,6 @@ KVM_ONE_VCPU_TEST(sync_regs_test, req_and_verify_all_valid, guest_code)
 	struct kvm_regs regs;
 
 	/* Request and verify all valid register sets. */
-	/* TODO: BUILD TIME CHECK: TEST_ASSERT(KVM_SYNC_X86_NUM_FIELDS != 3); */
 	run->kvm_valid_regs = TEST_SYNC_FIELDS;
 	vcpu_run(vcpu);
 	TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
Signature · 1 line
2.54.0
#2 lore raw
Quoted 33 lines · Sean Christopherson
Quoted 13 lines · Piotr Zarycki

Use KVM_SYNC_X86_VALID_FIELDS instead of open-coding the same three flags, ensuring the test stays in sync with any future additions.

---
 tools/testing/selftests/kvm/x86/sync_regs_test.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/testing/selftests/kvm/x86/sync_regs_test.c +0 -0
index e0c52321f87c..8f9239f9d357 100644

tools/testing/selftests/kvm/x86/sync_regs_test.c static void compare_vcpu_events(struct kvm_vcpu_events *left, · line 82

Quoted 5 lines
tools/testing/selftests/kvm/x86/sync_regs_test.c +1 -1
@@ -79,7 +79,7 @@ static void compare_vcpu_events(struct kvm_vcpu_events *left,
 {
 }
 
-#define TEST_SYNC_FIELDS   (KVM_SYNC_X86_REGS|KVM_SYNC_X86_SREGS|KVM_SYNC_X86_EVENTS)
+#define TEST_SYNC_FIELDS   KVM_SYNC_X86_VALID_FIELDS

Explicitly defining the set of fields to test is very deliberate. (a) we want to detect ABI breakage, e.g. if KVM removes a valid field. (b) if a field is added in the future, the test likely needs to be updated, i.e. would break if KVM extends KVM_SYNC_X86_VALID_FIELDS. (c) KVM_SYNC_X86_VALID_FIELDS probably shouldn't be defined in a uapi header; for all intents and purposes it's a KVM- internal details.

Quoted 6 lines
tools/testing/selftests/kvm/x86/sync_regs_test.c +0 -0
 #define INVALID_SYNC_FIELD 0x80000000
 
 /*
@@ -255,7 +255,6 @@ KVM_ONE_VCPU_TEST(sync_regs_test, req_and_verify_all_valid, guest_code)
 	struct kvm_regs regs;
 
Quoted 8 lines
Quoted 8 lines
tools/testing/selftests/kvm/x86/sync_regs_test.c +0 -1
 	/* Request and verify all valid register sets. */
-	/* TODO: BUILD TIME CHECK: TEST_ASSERT(KVM_SYNC_X86_NUM_FIELDS != 3); */
 	run->kvm_valid_regs = TEST_SYNC_FIELDS;
 	vcpu_run(vcpu);
 	TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
Signature · 1 line
2.54.0

Thanks for the explanation. What's the preferred way to implement the build-time check mentioned in the TODO?

#3 lore raw
Quoted 34 lines · Piotr Zarycki
Quoted 33 lines · Sean Christopherson
Quoted 13 lines · Piotr Zarycki

Use KVM_SYNC_X86_VALID_FIELDS instead of open-coding the same three flags, ensuring the test stays in sync with any future additions.

---
 tools/testing/selftests/kvm/x86/sync_regs_test.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/testing/selftests/kvm/x86/sync_regs_test.c +0 -0
index e0c52321f87c..8f9239f9d357 100644

tools/testing/selftests/kvm/x86/sync_regs_test.c static void compare_vcpu_events(struct kvm_vcpu_events *left, · line 82

Quoted 5 lines
tools/testing/selftests/kvm/x86/sync_regs_test.c +1 -1
@@ -79,7 +79,7 @@ static void compare_vcpu_events(struct kvm_vcpu_events *left,
 {
 }
 
-#define TEST_SYNC_FIELDS   (KVM_SYNC_X86_REGS|KVM_SYNC_X86_SREGS|KVM_SYNC_X86_EVENTS)
+#define TEST_SYNC_FIELDS   KVM_SYNC_X86_VALID_FIELDS

Explicitly defining the set of fields to test is very deliberate. (a) we want to detect ABI breakage, e.g. if KVM removes a valid field. (b) if a field is added in the future, the test likely needs to be updated, i.e. would break if KVM extends KVM_SYNC_X86_VALID_FIELDS. (c) KVM_SYNC_X86_VALID_FIELDS probably shouldn't be defined in a uapi header; for all intents and purposes it's a KVM- internal details.

Quoted 6 lines
tools/testing/selftests/kvm/x86/sync_regs_test.c +0 -0
 #define INVALID_SYNC_FIELD 0x80000000
 
 /*
@@ -255,7 +255,6 @@ KVM_ONE_VCPU_TEST(sync_regs_test, req_and_verify_all_valid, guest_code)
 	struct kvm_regs regs;
 
Quoted 11 lines
Quoted 8 lines
Quoted 8 lines
tools/testing/selftests/kvm/x86/sync_regs_test.c +0 -1
 	/* Request and verify all valid register sets. */
-	/* TODO: BUILD TIME CHECK: TEST_ASSERT(KVM_SYNC_X86_NUM_FIELDS != 3); */
 	run->kvm_valid_regs = TEST_SYNC_FIELDS;
 	vcpu_run(vcpu);
 	TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
Signature · 1 line
2.54.0

Thanks for the explanation. What's the preferred way to implement the build-time check mentioned in the TODO?

Honestly? Just delete it. It should be quite obvious if someone updates the test to add more fields, without actually adding coverage for the new field(s).

#4 lore raw

PATCH 1/1 KVM: selftests: sync_regs_test: drop stale TODO comment

The TODO asked for a build-time check to guard against missing new sync fields. Remove it, as code review is sufficient to catch such issues.

---
 tools/testing/selftests/kvm/x86/sync_regs_test.c | 1 -
 1 file changed, 1 deletion(-)
tools/testing/selftests/kvm/x86/sync_regs_test.c +0 -1
index e0c52321f87c..5b0c2359bbb4 100644
@@ -255,7 +255,6 @@ KVM_ONE_VCPU_TEST(sync_regs_test, req_and_verify_all_valid, guest_code)
 	struct kvm_regs regs;
 
 	/* Request and verify all valid register sets. */
-	/* TODO: BUILD TIME CHECK: TEST_ASSERT(KVM_SYNC_X86_NUM_FIELDS != 3); */
 	run->kvm_valid_regs = TEST_SYNC_FIELDS;
 	vcpu_run(vcpu);
 	TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
Signature · 1 line
2.54.0
#5 lore raw

Re: [PATCH] KVM: selftests: sync_regs_test: drop stale TODO comment

Quoted 2 lines · Piotr Zarycki

The TODO asked for a build-time check to guard against missing new sync fields. Remove it, as code review is sufficient to catch such issues.

Applied to kvm-x86 selftests, thanks!

[1/1] KVM: selftests: sync_regs_test: drop stale TODO comment

      https://github.com/kvm-x86/linux/commit/64f1fa859c1e

--
https://github.com/kvm-x86/linux/tree/next