public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] selftests/kvm: Use vcpus count instead of hardcoded 0xff in test_icr
@ 2025-09-06 18:43 Sukrut Heroorkar
  2025-09-08 14:30 ` Sean Christopherson
  0 siblings, 1 reply; 3+ messages in thread
From: Sukrut Heroorkar @ 2025-09-06 18:43 UTC (permalink / raw)
  Cc: skhan, david.hunter.linux, Sukrut Heroorkar, Sean Christopherson,
	Paolo Bonzini, Shuah Khan,
	open list:KERNEL VIRTUAL MACHINE FOR X86 (KVM/x86),
	open list:KERNEL SELFTEST FRAMEWORK, open list

Replace the hardcoded 0xff in test_icr() with the actual number of vcpus
created for the vm. This address the existing TODO and keeps the test
correct if it is ever run with multiple vcpus.

Signed-off-by: Sukrut Heroorkar <hsukrut3@gmail.com>
---
 tools/testing/selftests/kvm/x86/xapic_state_test.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/kvm/x86/xapic_state_test.c b/tools/testing/selftests/kvm/x86/xapic_state_test.c
index fdebff1165c7..4af36682503e 100644
--- a/tools/testing/selftests/kvm/x86/xapic_state_test.c
+++ b/tools/testing/selftests/kvm/x86/xapic_state_test.c
@@ -56,6 +56,17 @@ static void x2apic_guest_code(void)
 	} while (1);
 }
 
+static unsigned int vm_nr_vcpus(struct kvm_vm *vm)
+{
+	struct kvm_vcpu *vcpu;
+	unsigned int count = 0;
+
+	list_for_each_entry(vcpu, &vm->vcpus, list)
+		count++;
+
+	return count;
+}
+
 static void ____test_icr(struct xapic_vcpu *x, uint64_t val)
 {
 	struct kvm_vcpu *vcpu = x->vcpu;
@@ -124,7 +135,7 @@ static void test_icr(struct xapic_vcpu *x)
 	 * vCPUs, not vcpu.id + 1.  Arbitrarily use vector 0xff.
 	 */
 	icr = APIC_INT_ASSERT | 0xff;
-	for (i = 0; i < 0xff; i++) {
+	for (i = 0; i < vm_nr_vcpus(vcpu->vm); i++) {
 		if (i == vcpu->id)
 			continue;
 		for (j = 0; j < 8; j++)
-- 
2.43.0


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

* Re: [PATCH] selftests/kvm: Use vcpus count instead of hardcoded 0xff in test_icr
  2025-09-06 18:43 [PATCH] selftests/kvm: Use vcpus count instead of hardcoded 0xff in test_icr Sukrut Heroorkar
@ 2025-09-08 14:30 ` Sean Christopherson
  2025-09-08 20:23   ` sukrut heroorkar
  0 siblings, 1 reply; 3+ messages in thread
From: Sean Christopherson @ 2025-09-08 14:30 UTC (permalink / raw)
  To: Sukrut Heroorkar
  Cc: skhan, david.hunter.linux, Paolo Bonzini, Shuah Khan,
	open list:KERNEL VIRTUAL MACHINE FOR X86 (KVM/x86),
	open list:KERNEL SELFTEST FRAMEWORK, open list

On Sat, Sep 06, 2025, Sukrut Heroorkar wrote:
> Replace the hardcoded 0xff in test_icr() with the actual number of vcpus
> created for the vm. This address the existing TODO and keeps the test
> correct if it is ever run with multiple vcpus.

The TODO is stale, it was resolved by commit 376bc1b458c9 ("KVM: selftests: Don't
assume vcpu->id is '0' in xAPIC state test"), I/we just forgot to delete the
comment.

> Signed-off-by: Sukrut Heroorkar <hsukrut3@gmail.com>
> ---
>  tools/testing/selftests/kvm/x86/xapic_state_test.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/kvm/x86/xapic_state_test.c b/tools/testing/selftests/kvm/x86/xapic_state_test.c
> index fdebff1165c7..4af36682503e 100644
> --- a/tools/testing/selftests/kvm/x86/xapic_state_test.c
> +++ b/tools/testing/selftests/kvm/x86/xapic_state_test.c
> @@ -56,6 +56,17 @@ static void x2apic_guest_code(void)
>  	} while (1);
>  }
>  
> +static unsigned int vm_nr_vcpus(struct kvm_vm *vm)
> +{
> +	struct kvm_vcpu *vcpu;
> +	unsigned int count = 0;
> +
> +	list_for_each_entry(vcpu, &vm->vcpus, list)
> +		count++;
> +
> +	return count;
> +}
> +
>  static void ____test_icr(struct xapic_vcpu *x, uint64_t val)
>  {
>  	struct kvm_vcpu *vcpu = x->vcpu;
> @@ -124,7 +135,7 @@ static void test_icr(struct xapic_vcpu *x)
>  	 * vCPUs, not vcpu.id + 1.  Arbitrarily use vector 0xff.
>  	 */
>  	icr = APIC_INT_ASSERT | 0xff;
> -	for (i = 0; i < 0xff; i++) {
> +	for (i = 0; i < vm_nr_vcpus(vcpu->vm); i++) {

This is wrong/undesirable.  The original code was:

        for (i = vcpu->id + 1; i < 0xff; i++) {
                for (j = 0; j < 8; j++)
                        __test_icr(vm, vcpu, i << (32 + 24) | APIC_INT_ASSERT | (j << 8));
        }

I.e. the _lower_ bound was nr_vcpus+1.  Regardless, as fixed by the aformentioned
commit, using the number of vCPUs in any capacity is simply wrong.  The stale
comment just needs to be deleted.:

>  		if (i == vcpu->id)
>  			continue;
>  		for (j = 0; j < 8; j++)
> -- 
> 2.43.0
> 

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

* Re: [PATCH] selftests/kvm: Use vcpus count instead of hardcoded 0xff in test_icr
  2025-09-08 14:30 ` Sean Christopherson
@ 2025-09-08 20:23   ` sukrut heroorkar
  0 siblings, 0 replies; 3+ messages in thread
From: sukrut heroorkar @ 2025-09-08 20:23 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: skhan, david.hunter.linux, Paolo Bonzini, Shuah Khan,
	open list:KERNEL VIRTUAL MACHINE FOR X86 (KVM/x86),
	open list:KERNEL SELFTEST FRAMEWORK, open list

Hi Sean,

On Mon, Sep 8, 2025 at 4:30 PM Sean Christopherson <seanjc@google.com> wrote:
>
> On Sat, Sep 06, 2025, Sukrut Heroorkar wrote:
> > Replace the hardcoded 0xff in test_icr() with the actual number of vcpus
> > created for the vm. This address the existing TODO and keeps the test
> > correct if it is ever run with multiple vcpus.
>
> The TODO is stale, it was resolved by commit 376bc1b458c9 ("KVM: selftests: Don't
> assume vcpu->id is '0' in xAPIC state test"), I/we just forgot to delete the
> comment.
>
> > Signed-off-by: Sukrut Heroorkar <hsukrut3@gmail.com>
> > ---
> >  tools/testing/selftests/kvm/x86/xapic_state_test.c | 13 ++++++++++++-
> >  1 file changed, 12 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/testing/selftests/kvm/x86/xapic_state_test.c b/tools/testing/selftests/kvm/x86/xapic_state_test.c
> > index fdebff1165c7..4af36682503e 100644
> > --- a/tools/testing/selftests/kvm/x86/xapic_state_test.c
> > +++ b/tools/testing/selftests/kvm/x86/xapic_state_test.c
> > @@ -56,6 +56,17 @@ static void x2apic_guest_code(void)
> >       } while (1);
> >  }
> >
> > +static unsigned int vm_nr_vcpus(struct kvm_vm *vm)
> > +{
> > +     struct kvm_vcpu *vcpu;
> > +     unsigned int count = 0;
> > +
> > +     list_for_each_entry(vcpu, &vm->vcpus, list)
> > +             count++;
> > +
> > +     return count;
> > +}
> > +
> >  static void ____test_icr(struct xapic_vcpu *x, uint64_t val)
> >  {
> >       struct kvm_vcpu *vcpu = x->vcpu;
> > @@ -124,7 +135,7 @@ static void test_icr(struct xapic_vcpu *x)
> >        * vCPUs, not vcpu.id + 1.  Arbitrarily use vector 0xff.
> >        */
> >       icr = APIC_INT_ASSERT | 0xff;
> > -     for (i = 0; i < 0xff; i++) {
> > +     for (i = 0; i < vm_nr_vcpus(vcpu->vm); i++) {
>
> This is wrong/undesirable.  The original code was:
>
>         for (i = vcpu->id + 1; i < 0xff; i++) {
>                 for (j = 0; j < 8; j++)
>                         __test_icr(vm, vcpu, i << (32 + 24) | APIC_INT_ASSERT | (j << 8));
>         }
>
> I.e. the _lower_ bound was nr_vcpus+1.  Regardless, as fixed by the aformentioned
> commit, using the number of vCPUs in any capacity is simply wrong.  The stale
> comment just needs to be deleted.:

Thanks for the clarification. I will send a patch removing the stale
TODO comment.
>
> >               if (i == vcpu->id)
> >                       continue;
> >               for (j = 0; j < 8; j++)
> > --
> > 2.43.0
> >

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

end of thread, other threads:[~2025-09-08 20:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-06 18:43 [PATCH] selftests/kvm: Use vcpus count instead of hardcoded 0xff in test_icr Sukrut Heroorkar
2025-09-08 14:30 ` Sean Christopherson
2025-09-08 20:23   ` sukrut heroorkar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox