All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: selftests: kvm_binary_stats_test: Fix index expressions
@ 2022-06-14  8:10 Andrew Jones
  2022-06-14 14:43 ` Sean Christopherson
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Jones @ 2022-06-14  8:10 UTC (permalink / raw)
  To: kvm; +Cc: seanjc, pbonzini

kvm_binary_stats_test accepts two arguments, the number of vms
and number of vcpus. If these inputs are not equal then the
test would likely crash for one reason or another due to using
miscalculated indices for the vcpus array. Fix the index
expressions by swapping the use of i and j.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---

Applies to kvm/queue

 tools/testing/selftests/kvm/kvm_binary_stats_test.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/kvm/kvm_binary_stats_test.c b/tools/testing/selftests/kvm/kvm_binary_stats_test.c
index 1baabf955d63..3c2d06b61442 100644
--- a/tools/testing/selftests/kvm/kvm_binary_stats_test.c
+++ b/tools/testing/selftests/kvm/kvm_binary_stats_test.c
@@ -225,14 +225,14 @@ int main(int argc, char *argv[])
 	for (i = 0; i < max_vm; ++i) {
 		vms[i] = vm_create_barebones();
 		for (j = 0; j < max_vcpu; ++j)
-			vcpus[j * max_vcpu + i] = __vm_vcpu_add(vms[i], j);
+			vcpus[i * max_vcpu + j] = __vm_vcpu_add(vms[i], j);
 	}
 
 	/* Check stats read for every VM and VCPU */
 	for (i = 0; i < max_vm; ++i) {
 		vm_stats_test(vms[i]);
 		for (j = 0; j < max_vcpu; ++j)
-			vcpu_stats_test(vcpus[j * max_vcpu + i]);
+			vcpu_stats_test(vcpus[i * max_vcpu + j]);
 	}
 
 	for (i = 0; i < max_vm; ++i)
-- 
2.34.3


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

* Re: [PATCH] KVM: selftests: kvm_binary_stats_test: Fix index expressions
  2022-06-14  8:10 [PATCH] KVM: selftests: kvm_binary_stats_test: Fix index expressions Andrew Jones
@ 2022-06-14 14:43 ` Sean Christopherson
  0 siblings, 0 replies; 2+ messages in thread
From: Sean Christopherson @ 2022-06-14 14:43 UTC (permalink / raw)
  To: Andrew Jones; +Cc: kvm, pbonzini

On Tue, Jun 14, 2022, Andrew Jones wrote:
> kvm_binary_stats_test accepts two arguments, the number of vms
> and number of vcpus. If these inputs are not equal then the
> test would likely crash for one reason or another due to using
> miscalculated indices for the vcpus array. Fix the index
> expressions by swapping the use of i and j.
> 
> Signed-off-by: Andrew Jones <drjones@redhat.com>
> ---

Thanks!  I had done this locally but lost track of it when updating kvm/queue.

Reviewed-by: Sean Christopherson <seanjc@google.com>

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

end of thread, other threads:[~2022-06-14 14:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-14  8:10 [PATCH] KVM: selftests: kvm_binary_stats_test: Fix index expressions Andrew Jones
2022-06-14 14:43 ` 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.