From: sashiko-bot@kernel.org
To: "Hemanth Selam" <hemanth.selam@gmail.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v2 1/2] KVM: selftests: Add a helper to read a vCPU's APIC ID
Date: Wed, 26 Aug 2026 12:11:59 +0000 [thread overview]
Message-ID: <20260826121200.79E7A1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260826115915.2882221-2-hemanth.selam@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] vcpu_get_apic_id() incorrectly computes the APIC ID for x2APIC vCPUs, particularly when KVM_X2APIC_API_USE_32BIT_IDS is enabled, returning 0 for typical APIC IDs and truncating IDs > 255.
--
commit dd16ed0d3dc6ed699be3a1e4ae7b88bd360cc286
Author: Hemanth Selam <hemanth.selam@gmail.com>
KVM: selftests: Add a helper to read a vCPU's APIC ID
This commit adds a helper function to read a vCPU's APIC ID directly from
the host. This prevents tests from having to open code the KVM_GET_LAPIC
ioctl when targeting a vCPU with an IPI.
> diff --git a/tools/testing/selftests/kvm/include/x86/apic.h b/tools/testing/selftests/kvm/include/x86/apic.h
> index 31887bdc3d6c4..293044c81228d 100644
> --- a/tools/testing/selftests/kvm/include/x86/apic.h
> +++ b/tools/testing/selftests/kvm/include/x86/apic.h
> @@ -79,6 +79,15 @@ void apic_disable(void);
> void xapic_enable(void);
> void x2apic_enable(void);
>
> +/* Reads the APIC ID of a vCPU from the host, e.g. to target an IPI at it. */
> +static inline u32 vcpu_get_apic_id(struct kvm_vcpu *vcpu)
> +{
> + struct kvm_lapic_state lapic;
> +
> + vcpu_ioctl(vcpu, KVM_GET_LAPIC, &lapic);
> + return GET_APIC_ID_FIELD(*(u32 *)&lapic.regs[APIC_ID]);
[Severity: Medium]
Does this unconditionally apply xAPIC bitwise extraction, failing to account
for the x2APIC format where the ID may be stored unshifted or exceed 8 bits?
If a test invokes vcpu_get_apic_id() on an x2APIC vCPU and the VM has
KVM_X2APIC_API_USE_32BIT_IDS enabled, KVM stores the unshifted 32-bit ID in
the APIC_ID register, but GET_APIC_ID_FIELD shifts it by 24.
If not enabled, KVM shifts the ID by 24, but GET_APIC_ID_FIELD applies an
8-bit mask (0xFF), silently truncating any x2APIC ID > 255.
This incorrect APIC ID computation could cause tests that rely on this
helper for cross-vCPU IPIs to target the wrong vCPU (often ID 0), leading
to test failures or false passes.
> +}
> +
> static inline u32 get_bsp_flag(void)
> {
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260826115915.2882221-1-hemanth.selam@gmail.com?part=1
next prev parent reply other threads:[~2026-08-26 12:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-26 11:59 [PATCH v2 0/2] KVM: selftests: Actually test PV_UNHALT Hemanth Selam
2026-08-26 11:59 ` [PATCH v2 1/2] KVM: selftests: Add a helper to read a vCPU's APIC ID Hemanth Selam
2026-08-26 12:11 ` sashiko-bot [this message]
2026-08-26 11:59 ` [PATCH v2 2/2] KVM: selftests: Test the PV_UNHALT feature, not just its CPUID bit Hemanth Selam
2026-08-27 4:48 ` [PATCH v2 1/2] KVM: selftests: Add a helper to read a vCPU's APIC ID Hemanth Selam
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=20260826121200.79E7A1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=hemanth.selam@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 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.