From: Alejandro Vallejo <alejandro.vallejo@cloud.com>
To: xen-devel@lists.xenproject.org
Cc: "Alejandro Vallejo" <alejandro.vallejo@cloud.com>,
"Jan Beulich" <jbeulich@suse.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Roger Pau Monné" <roger.pau@citrix.com>,
"Anthony PERARD" <anthony.perard@vates.tech>
Subject: [PATCH 3/3] tools/hvmloader: Skip writing MP tables if any CPU has an APIC ID >= 255
Date: Tue, 28 Jan 2025 16:33:42 +0000 [thread overview]
Message-ID: <20250128163342.1491-4-alejandro.vallejo@cloud.com> (raw)
In-Reply-To: <20250128163342.1491-1-alejandro.vallejo@cloud.com>
MP Tables have no means of representing APIC IDs wider than 255. At the
moment the effect is wrapping around which would give a corrupted table
with duplicate APIC IDs (some of them possibly the broadcast 255).
Skip writing it altogether. While it would be possible to restrict the
APs shown it's just not worth the work. Any OS that needs such
adjustments should not have been booted with that many vCPUs to begin
with.
Signed-off-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
---
Changes with respect to v7 in the longer topology series:
* This patch replaces the previous assert in hvmloader/mp_tables.c
---
tools/firmware/hvmloader/config.h | 1 +
tools/firmware/hvmloader/hvmloader.c | 6 +++++-
tools/firmware/hvmloader/smp.c | 4 ++++
3 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/tools/firmware/hvmloader/config.h b/tools/firmware/hvmloader/config.h
index 6e1da137d779..53be34e48a02 100644
--- a/tools/firmware/hvmloader/config.h
+++ b/tools/firmware/hvmloader/config.h
@@ -49,6 +49,7 @@ extern uint8_t ioapic_version;
#define IOAPIC_ID 0x01
extern uint32_t *cpu_to_apicid;
+extern uint32_t max_apicid;
#define LAPIC_BASE_ADDRESS 0xfee00000
diff --git a/tools/firmware/hvmloader/hvmloader.c b/tools/firmware/hvmloader/hvmloader.c
index 4e330fc1e241..54299e27364d 100644
--- a/tools/firmware/hvmloader/hvmloader.c
+++ b/tools/firmware/hvmloader/hvmloader.c
@@ -389,7 +389,11 @@ int main(void)
if ( (hvm_info->nr_vcpus > 1) || hvm_info->apic_mode )
{
- if ( bios->create_mp_tables )
+ /*
+ * Legacy MP tables hold strictly xAPIC IDs. Skip writing
+ * the tables altogether if we have IDs wider than 8bits.
+ */
+ if ( max_apicid < 0xFF && bios->create_mp_tables )
bios->create_mp_tables();
if ( bios->create_pir_tables )
bios->create_pir_tables();
diff --git a/tools/firmware/hvmloader/smp.c b/tools/firmware/hvmloader/smp.c
index c61ed524f947..0a01cdc18caa 100644
--- a/tools/firmware/hvmloader/smp.c
+++ b/tools/firmware/hvmloader/smp.c
@@ -34,6 +34,9 @@ static int ap_callin;
/** True if x2apic support is exposed to the guest. */
static bool has_x2apic;
+/** Highest entry in `cpu_to_apicid`. */
+uint32_t max_apicid;
+
/**
* Lookup table of (x2)APIC IDs.
*
@@ -61,6 +64,7 @@ static uint32_t read_apic_id(void)
static void cpu_setup(unsigned int cpu)
{
uint32_t apicid = cpu_to_apicid[cpu] = read_apic_id();
+ max_apicid = max(max_apicid, apicid);
printf(" - CPU%u[%u] ... ", cpu, apicid);
cacheattr_init();
--
2.48.1
next prev parent reply other threads:[~2025-01-28 16:34 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-28 16:33 [PATCH 0/3] tools/hvmloader: Decouple APIC IDs from vCPU IDs Alejandro Vallejo
2025-01-28 16:33 ` [PATCH 1/3] tools/hvmloader: Retrieve (x2)APIC IDs from the APs themselves Alejandro Vallejo
2025-01-28 17:59 ` Roger Pau Monné
2025-01-28 18:45 ` Alejandro Vallejo
2025-01-28 16:33 ` [PATCH 2/3] tools/hvmloader: Replace LAPIC_ID() with cpu_to_apicid[] Alejandro Vallejo
2025-01-30 12:59 ` Jan Beulich
2025-01-28 16:33 ` Alejandro Vallejo [this message]
2025-01-30 13:02 ` [PATCH 3/3] tools/hvmloader: Skip writing MP tables if any CPU has an APIC ID >= 255 Jan Beulich
2025-01-28 17:45 ` [PATCH 0/3] tools/hvmloader: Decouple APIC IDs from vCPU IDs Roger Pau Monné
2025-01-28 18:42 ` Alejandro Vallejo
2025-01-29 16:25 ` Roger Pau Monné
2025-01-30 9:17 ` Jan Beulich
2025-02-04 14:26 ` Alejandro Vallejo
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=20250128163342.1491-4-alejandro.vallejo@cloud.com \
--to=alejandro.vallejo@cloud.com \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=jbeulich@suse.com \
--cc=roger.pau@citrix.com \
--cc=xen-devel@lists.xenproject.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 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.