public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Sukrut Heroorkar <hsukrut3@gmail.com>
Cc: skhan@linuxfoundation.org, david.hunter.linux@gmail.com,
	 Paolo Bonzini <pbonzini@redhat.com>,
	Shuah Khan <shuah@kernel.org>,
	 "open list:KERNEL VIRTUAL MACHINE FOR X86 (KVM/x86)"
	<kvm@vger.kernel.org>,
	 "open list:KERNEL SELFTEST FRAMEWORK"
	<linux-kselftest@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] selftests/kvm: Use vcpus count instead of hardcoded 0xff in test_icr
Date: Mon, 8 Sep 2025 07:30:24 -0700	[thread overview]
Message-ID: <aL7ogKtOUi2py1jx@google.com> (raw)
In-Reply-To: <20250906184324.89974-1-hsukrut3@gmail.com>

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
> 

  reply	other threads:[~2025-09-08 14:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2025-09-08 20:23   ` sukrut heroorkar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aL7ogKtOUi2py1jx@google.com \
    --to=seanjc@google.com \
    --cc=david.hunter.linux@gmail.com \
    --cc=hsukrut3@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=shuah@kernel.org \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox