All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: selftests: Stop assuming stats are contiguous in kvm_binary_stats_test
@ 2023-01-17 22:27 David Matlack
  2023-01-19 21:01 ` Sean Christopherson
  0 siblings, 1 reply; 2+ messages in thread
From: David Matlack @ 2023-01-17 22:27 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Ricardo Koller, Krish Sadhukhan, Jing Zhang, David Matlack, kvm

From: Jing Zhang <jingzhangos@google.com>

Remove the assumption from kvm_binary_stats_test that all stats are
laid out contiguously in memory. The current stats in KVM are
contiguously laid out in memory, but that may change in the future and
the ABI specifically allows holes in the stats data (since each stat
exposes its own offset).

While here drop the check that each stats' offset is less than
size_data, as that is now always true by construction.

Link: https://lore.kernel.org/kvm/20221208193857.4090582-9-dmatlack@google.com/
Fixes: 0b45d58738cd ("KVM: selftests: Add selftest for KVM statistics data binary interface")
Signed-off-by: Jing Zhang <jingzhangos@google.com>
Signed-off-by: David Matlack <dmatlack@google.com>
[Re-worded the commit message.]

Signed-off-by: David Matlack <dmatlack@google.com>
---
 tools/testing/selftests/kvm/kvm_binary_stats_test.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/tools/testing/selftests/kvm/kvm_binary_stats_test.c b/tools/testing/selftests/kvm/kvm_binary_stats_test.c
index 894417c96f70..a7001e29dc06 100644
--- a/tools/testing/selftests/kvm/kvm_binary_stats_test.c
+++ b/tools/testing/selftests/kvm/kvm_binary_stats_test.c
@@ -134,7 +134,7 @@ static void stats_test(int stats_fd)
 				    "Bucket size of stats (%s) is not zero",
 				    pdesc->name);
 		}
-		size_data += pdesc->size * sizeof(*stats_data);
+		size_data = max(size_data, pdesc->offset + pdesc->size * sizeof(*stats_data));
 	}
 
 	/*
@@ -149,14 +149,6 @@ static void stats_test(int stats_fd)
 	TEST_ASSERT(size_data >= header.num_desc * sizeof(*stats_data),
 		    "Data size is not correct");
 
-	/* Check stats offset */
-	for (i = 0; i < header.num_desc; ++i) {
-		pdesc = get_stats_descriptor(stats_desc, i, &header);
-		TEST_ASSERT(pdesc->offset < size_data,
-			    "Invalid offset (%u) for stats: %s",
-			    pdesc->offset, pdesc->name);
-	}
-
 	/* Allocate memory for stats data */
 	stats_data = malloc(size_data);
 	TEST_ASSERT(stats_data, "Allocate memory for stats data");

base-commit: de60733246ff4545a0483140c1f21426b8d7cb7f
prerequisite-patch-id: 42a76ce7cec240776c21f674e99e893a3a6bee58
-- 
2.39.0.246.g2a6d74b583-goog


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] KVM: selftests: Stop assuming stats are contiguous in kvm_binary_stats_test
  2023-01-17 22:27 [PATCH] KVM: selftests: Stop assuming stats are contiguous in kvm_binary_stats_test David Matlack
@ 2023-01-19 21:01 ` Sean Christopherson
  0 siblings, 0 replies; 2+ messages in thread
From: Sean Christopherson @ 2023-01-19 21:01 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini, David Matlack
  Cc: Ricardo Koller, Krish Sadhukhan, Jing Zhang, kvm

On Tue, 17 Jan 2023 14:27:07 -0800, David Matlack wrote:
> Remove the assumption from kvm_binary_stats_test that all stats are
> laid out contiguously in memory. The current stats in KVM are
> contiguously laid out in memory, but that may change in the future and
> the ABI specifically allows holes in the stats data (since each stat
> exposes its own offset).
> 
> While here drop the check that each stats' offset is less than
> size_data, as that is now always true by construction.
> 
> [...]

Applied to kvm-x86 selftests, thanks!

[1/1] KVM: selftests: Stop assuming stats are contiguous in kvm_binary_stats_test
      https://github.com/kvm-x86/linux/commit/d9e552858fab

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-01-19 21:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-17 22:27 [PATCH] KVM: selftests: Stop assuming stats are contiguous in kvm_binary_stats_test David Matlack
2023-01-19 21:01 ` Sean Christopherson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.