From patchwork Tue Jan 28 16:33:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13952763 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 99689C0218A for ; Tue, 28 Jan 2025 16:34:21 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.878658.1288852 (Exim 4.92) (envelope-from ) id 1tcoXS-00074A-I1; Tue, 28 Jan 2025 16:34:10 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 878658.1288852; Tue, 28 Jan 2025 16:34:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tcoXS-000740-BQ; Tue, 28 Jan 2025 16:34:10 +0000 Received: by outflank-mailman (input) for mailman id 878658; Tue, 28 Jan 2025 16:34:09 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tcoXR-00070Z-6u for xen-devel@lists.xenproject.org; Tue, 28 Jan 2025 16:34:09 +0000 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [2a00:1450:4864:20::633]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b2371477-dd95-11ef-a0e6-8be0dac302b0; Tue, 28 Jan 2025 17:34:08 +0100 (CET) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-aa68b513abcso1177535766b.0 for ; Tue, 28 Jan 2025 08:34:08 -0800 (PST) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab6973090d0sm534810966b.18.2025.01.28.08.34.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jan 2025 08:34:06 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b2371477-dd95-11ef-a0e6-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1738082047; x=1738686847; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=k2wXYm4vj9zHpf4g1hT+h92PgyCXWbc4DWlhdSJr70A=; b=X5s30jRmyfQdoWdWUozrK1M0qmMXOTKAnhppKtURGyqvSyzZwA8t7DaeQUHk5OE1LL s2ljVLcMoYP8Ju9usGyUb1+tzI6DU+NXsGrRuJiBCGjD3yCCn0xeIJ4B2l4GGmaxaRSb 8vm4Z8+tDyjZMH4ZuI4Ge7TxQDu4yXY6ZC9zw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738082047; x=1738686847; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k2wXYm4vj9zHpf4g1hT+h92PgyCXWbc4DWlhdSJr70A=; b=AAiRs7ioN6fJtnl1g7KqxGuFRXnzwnACU7Yz2x/H/RKPeYifbeobk1oel3yjjvegb4 a0AuAqlEwGcu5DOiZmpVL25NacaxPgE31Q55HJKjw1iu2rRiwbis9+ehZqGbgRf5LB5x uSYE4Dz2zXSeUW1GpxqT/S34yZpN13apC68AgXHfbJzJ2t7G/jlWeIWfYnoB7R0K2wNq S+YQDqLML47PNHV4ANHrFkGiSRQLCfPthbCuDXmGz+ySumUBium/0a7bkRBGhT1UenfU 7ReFDPs/scXVxrTw/IiXLrZAVEf1vB9gM7DSANrEAFY4dnLbp+Fa5FPr7/J+HlvuU0tV 48Jw== X-Gm-Message-State: AOJu0Yx56ZlVY4ACB/55IiSI6BCILig0l9FGpn88vfb65u3BeYasTgm4 DoJT2uCT9kb9WnPH488PJWjU80aqt7IsGwtddgjYWkF2Z8IKO2k7lNheczcogOOzkHJkWJHUWFJ 6LA4= X-Gm-Gg: ASbGnctqDrG7/QCg7k9SK9rL8bvn+MoQPwWvoPkSzVqSb2FqylDDZoHZftzQIW67V+k hl72fhZloT4+fo8sThWBQP3X5IitKB18O7+jGXuw56yPj1ZJh2iWO3mpFj3ETtQdVsd6Jpyo70I eqaoHEmCos6rLHsW0LjT+k8d3eQOysAmyhJHlZM9cIezgZCUP+fOG0l2SFX5ifqDoWZBkYMMWtS x5WnVxV2G+Avk9hQMTnIlr0w/QRoBIQ52kONRWECdUWvig/DFQziNJ4fN/R/rk0WfCUd1v90juU B40dXOXafFnaYEs0XR5zFLkX7sOENCcy8pTgRG6l X-Google-Smtp-Source: AGHT+IEwuL9IleBtGqDhzoL9t0Kye8GCON7QSXArcXKY1+gnfx33mdQmIerjEV/aNAHSm8DDJZDfvA== X-Received: by 2002:a17:907:72c6:b0:ab2:b84b:2dab with SMTP id a640c23a62f3a-ab38b163149mr5052649466b.30.1738082047389; Tue, 28 Jan 2025 08:34:07 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Anthony PERARD Subject: [PATCH 1/3] tools/hvmloader: Retrieve (x2)APIC IDs from the APs themselves Date: Tue, 28 Jan 2025 16:33:40 +0000 Message-ID: <20250128163342.1491-2-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250128163342.1491-1-alejandro.vallejo@cloud.com> References: <20250128163342.1491-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Make it so the APs expose their own APIC IDs in a lookup table (LUT). We can use that LUT to populate the MADT, decoupling the algorithm that relates CPU IDs and APIC IDs from hvmloader. Modified the printf to also print the APIC ID of each CPU, as well as fixing a (benign) wrong specifier being used for the vcpu id. Signed-off-by: Alejandro Vallejo --- Changes from the v7 version of this patch in the longer topology series: * s/cpu_to_x2apicid/cpu_to_apicid/ * Though, as I already stated, I don't think this is a good idea. * Dynamically size cpu_to_apicid rather than using HVM_MAX_VCPUS. * Got rid of the ap_callin removal. It's not as trivial if we don't want to assume cpu0 always has apicid=0. Part of the complaints on the previous versions involved the inability to do that. * For debugging sanity, I've added the apicid to the CPU boot printf. * Later on, toolstack will choose the APIC IDs and it's helpful to know the relationship in the logs. * While at it, fix the vcpu specifier s/%d/%u/ * Check for leaf 0xb while probing for x2apic support. --- tools/firmware/hvmloader/smp.c | 43 +++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/tools/firmware/hvmloader/smp.c b/tools/firmware/hvmloader/smp.c index 1b940cefd071..c61ed524f947 100644 --- a/tools/firmware/hvmloader/smp.c +++ b/tools/firmware/hvmloader/smp.c @@ -31,9 +31,38 @@ static int ap_callin; +/** True if x2apic support is exposed to the guest. */ +static bool has_x2apic; + +/** + * Lookup table of (x2)APIC IDs. + * + * Each entry is populated for its respective CPU as they come online. This is + * required for generating the MADT with minimal assumptions about ID + * relationships. + */ +uint32_t *cpu_to_apicid; + +static uint32_t read_apic_id(void) +{ + uint32_t apic_id; + + if ( has_x2apic ) + cpuid(0xb, NULL, NULL, NULL, &apic_id); + else + { + cpuid(1, NULL, &apic_id, NULL, NULL); + apic_id >>= 24; + } + + return apic_id; +} + static void cpu_setup(unsigned int cpu) { - printf(" - CPU%d ... ", cpu); + uint32_t apicid = cpu_to_apicid[cpu] = read_apic_id(); + + printf(" - CPU%u[%u] ... ", cpu, apicid); cacheattr_init(); printf("done.\n"); @@ -104,8 +133,20 @@ static void boot_cpu(unsigned int cpu) void smp_initialise(void) { unsigned int i, nr_cpus = hvm_info->nr_vcpus; + uint32_t ecx, max_leaf; + + cpuid(0, &max_leaf, NULL, NULL, NULL); + if ( max_leaf >= 0xb ) + { + cpuid(1, NULL, NULL, &ecx, NULL); + has_x2apic = (ecx >> 21) & 1; + if ( has_x2apic ) + printf("x2APIC supported\n"); + } printf("Multiprocessor initialisation:\n"); + cpu_to_apicid = scratch_alloc(sizeof(*cpu_to_apicid) * nr_cpus, + sizeof(*cpu_to_apicid)); cpu_setup(0); for ( i = 1; i < nr_cpus; i++ ) boot_cpu(i); From patchwork Tue Jan 28 16:33:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13952769 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 65B30C02190 for ; Tue, 28 Jan 2025 16:34:22 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.878659.1288865 (Exim 4.92) (envelope-from ) id 1tcoXT-0007TB-O3; Tue, 28 Jan 2025 16:34:11 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 878659.1288865; Tue, 28 Jan 2025 16:34:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tcoXT-0007T4-Iv; Tue, 28 Jan 2025 16:34:11 +0000 Received: by outflank-mailman (input) for mailman id 878659; Tue, 28 Jan 2025 16:34:09 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tcoXR-00070Z-Rf for xen-devel@lists.xenproject.org; Tue, 28 Jan 2025 16:34:09 +0000 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [2a00:1450:4864:20::536]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b2b1284e-dd95-11ef-a0e6-8be0dac302b0; Tue, 28 Jan 2025 17:34:09 +0100 (CET) Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-5d3d14336f0so9948170a12.3 for ; Tue, 28 Jan 2025 08:34:09 -0800 (PST) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab6973090d0sm534810966b.18.2025.01.28.08.34.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jan 2025 08:34:07 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b2b1284e-dd95-11ef-a0e6-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1738082048; x=1738686848; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9PocrDZ9hDRaC7DH9mGBlVuageGkmPBew72m1MalZps=; b=SeDo6HQD43B9Tg2lusAh3ekHc4vMD/5YNWIknrkayvSjS6oakYijT1hiexy5ryRiLv 9aJleiuV/nzBFAvFMIwByYA1sYqTlUVgeq4MRJ3DCBOj/En4+MjBSdaVUSzInMZw5HfL qMvJdYWwdKuUgoVyJHC0+Cn0T9b7XrsjlCzTE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738082048; x=1738686848; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9PocrDZ9hDRaC7DH9mGBlVuageGkmPBew72m1MalZps=; b=jyFdlW1Vpdd3lqVnMOhIBDgsXTMJqiDhxvKrvFa2yGZEtI/cjfE09mZuKvifrpkNFQ B90LHUscZenWefrXdo84B8gIKGMEZdAomuvq7UdLAwmtQ1Fx5MmVYfiSVkWd3hcqT9n6 y22iA8w6/QMZOx8MgpoxPox25uQGjsIdHmsC74exAzGuo65Wh4hgfbXYcQZBUjdqsrf1 /3FI90nUCLeYKJUATb7Xlo1yqTho/Re+mbzXHru+l4W2IRyQOCgIibYpveapbIgbUxnX YzRRnCXMzL9rrcPgHhKI3DiHhps40hrFqT6nteruZSSBfbMA7ms9UcVuy/HomgfCua4J po3Q== X-Gm-Message-State: AOJu0YyXnnDBdiZHS994OaA1epmlN89QKNqd7dQE4Nd/BCg5c6FRmJgX GZjOqbVx1s1qXKxX3A5E/FJvtgPu85nmkcwXz/Na8s7K3ncNl/JZySubE7cctQk3y43QsOTP9SP CYKQ= X-Gm-Gg: ASbGncsi1ZeXEZkONS25SIXnDdHYJFMSwZp9R1IQqSgoYAWgEWztohC7MWdeeHw6RTV LdBqOa23UA3sF6+DFLoKcVr5eK2ToJ2kBkvU5JBc7BgrKP6nG5jeIDwdxwAHj3OPoeuasA9VbEO O5TtsI9es+v0j1bOOVmVVYH4wUE/IiUYOkqdzfJJYw/L7x46YF9RKK5OmPYd+XWoY8yt0tKwmMK sG35PwEGraGBZdLJ5Uvv2vvaLtACXuJHSZJJlro4KNM7dxwLD51dEnXX21g7xas+WgwAIvHg7RS gMn42nzBR8PJk4UB+oQ/B6wP6Y4rrAX0/SNtZCz7cx0qx7EJ+/o= X-Google-Smtp-Source: AGHT+IEHvOHZ3rC79zgZtlrliUBcqHcZd/1yasALjI6l+oiiKoATwG1XM4JqoTd0amr0xZiVHwo+Tg== X-Received: by 2002:a17:906:f598:b0:aa6:7933:8b26 with SMTP id a640c23a62f3a-ab38b1b17ecmr4577230966b.9.1738082048332; Tue, 28 Jan 2025 08:34:08 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Anthony PERARD Subject: [PATCH 2/3] tools/hvmloader: Replace LAPIC_ID() with cpu_to_apicid[] Date: Tue, 28 Jan 2025 16:33:41 +0000 Message-ID: <20250128163342.1491-3-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250128163342.1491-1-alejandro.vallejo@cloud.com> References: <20250128163342.1491-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Replace uses of the LAPIC_ID() macro with accesses to the cpu_to_apicid[] lookup table. This table contains the APIC IDs of each vCPU as probed at runtime rather than assuming a predefined relation. Moved smp_initialise() ahead of apic_setup() in order to initialise cpu_to_apicid ASAP and avoid using it uninitialised. Note that bringing up the APs doesn't need the APIC in hvmloader becasue it always runs virtualized and uses the PV interface. Signed-off-by: Alejandro Vallejo --- Changes from v7 of the longer topology series: * Removed ASSERT() for the MP tables and merely skipped writing them if any vCPU has an APIC ID >=255. --- tools/firmware/hvmloader/config.h | 3 ++- tools/firmware/hvmloader/hvmloader.c | 6 +++--- tools/firmware/hvmloader/mp_tables.c | 2 +- tools/firmware/hvmloader/util.c | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/firmware/hvmloader/config.h b/tools/firmware/hvmloader/config.h index cd716bf39245..6e1da137d779 100644 --- a/tools/firmware/hvmloader/config.h +++ b/tools/firmware/hvmloader/config.h @@ -48,8 +48,9 @@ extern uint8_t ioapic_version; #define IOAPIC_ID 0x01 +extern uint32_t *cpu_to_apicid; + #define LAPIC_BASE_ADDRESS 0xfee00000 -#define LAPIC_ID(vcpu_id) ((vcpu_id) * 2) #define PCI_ISA_DEVFN 0x08 /* dev 1, fn 0 */ #define PCI_ISA_IRQ_MASK 0x0c20U /* ISA IRQs 5,10,11 are PCI connected */ diff --git a/tools/firmware/hvmloader/hvmloader.c b/tools/firmware/hvmloader/hvmloader.c index f8af88fabf24..4e330fc1e241 100644 --- a/tools/firmware/hvmloader/hvmloader.c +++ b/tools/firmware/hvmloader/hvmloader.c @@ -224,7 +224,7 @@ static void apic_setup(void) /* 8259A ExtInts are delivered through IOAPIC pin 0 (Virtual Wire Mode). */ ioapic_write(0x10, APIC_DM_EXTINT); - ioapic_write(0x11, SET_APIC_ID(LAPIC_ID(0))); + ioapic_write(0x11, SET_APIC_ID(cpu_to_apicid[0])); } struct bios_info { @@ -341,11 +341,11 @@ int main(void) printf("CPU speed is %u MHz\n", get_cpu_mhz()); + smp_initialise(); + apic_setup(); pci_setup(); - smp_initialise(); - perform_tests(); if ( bios->bios_info_setup ) diff --git a/tools/firmware/hvmloader/mp_tables.c b/tools/firmware/hvmloader/mp_tables.c index 77d3010406d0..3c93a5c947d9 100644 --- a/tools/firmware/hvmloader/mp_tables.c +++ b/tools/firmware/hvmloader/mp_tables.c @@ -199,7 +199,7 @@ static void fill_mp_config_table(struct mp_config_table *mpct, int length) static void fill_mp_proc_entry(struct mp_proc_entry *mppe, int vcpu_id) { mppe->type = ENTRY_TYPE_PROCESSOR; - mppe->lapic_id = LAPIC_ID(vcpu_id); + mppe->lapic_id = cpu_to_apicid[vcpu_id]; mppe->lapic_version = 0x11; mppe->cpu_flags = CPU_FLAG_ENABLED; if ( vcpu_id == 0 ) diff --git a/tools/firmware/hvmloader/util.c b/tools/firmware/hvmloader/util.c index d3b3f9038e64..2d07ce129013 100644 --- a/tools/firmware/hvmloader/util.c +++ b/tools/firmware/hvmloader/util.c @@ -827,7 +827,7 @@ static void acpi_mem_free(struct acpi_ctxt *ctxt, static uint32_t acpi_lapic_id(unsigned cpu) { - return LAPIC_ID(cpu); + return cpu_to_apicid[cpu]; } void hvmloader_acpi_build_tables(struct acpi_config *config, From patchwork Tue Jan 28 16:33:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13952768 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2886EC02194 for ; Tue, 28 Jan 2025 16:34:23 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.878660.1288872 (Exim 4.92) (envelope-from ) id 1tcoXU-0007ZK-6Q; Tue, 28 Jan 2025 16:34:12 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 878660.1288872; Tue, 28 Jan 2025 16:34:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tcoXU-0007XY-0w; Tue, 28 Jan 2025 16:34:12 +0000 Received: by outflank-mailman (input) for mailman id 878660; Tue, 28 Jan 2025 16:34:10 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tcoXS-00070Z-Rh for xen-devel@lists.xenproject.org; Tue, 28 Jan 2025 16:34:10 +0000 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [2a00:1450:4864:20::634]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b337f96f-dd95-11ef-a0e6-8be0dac302b0; Tue, 28 Jan 2025 17:34:10 +0100 (CET) Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-aaec61d0f65so1272337166b.1 for ; Tue, 28 Jan 2025 08:34:10 -0800 (PST) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab6973090d0sm534810966b.18.2025.01.28.08.34.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jan 2025 08:34:08 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b337f96f-dd95-11ef-a0e6-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1738082049; x=1738686849; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+utsPfRRtrSY+xEHr/3Olh5IQcbAme2skyUQu+gyGyU=; b=lUV2gTfZ4av3fC7ESoExMVIt7cXCnz3uh5zaRe7SNudIqD8kZbYbFJDSU533rt/MLv 9XZ4/8fFTSpvAZAu+MbHUr4AY+Z9+I9MUdKyHkFqQtRS/zCFf+X9zoC+mr8f5JcaFmEG G3iMOQCTz0Y5CxuTGa05eznRL7rIwjSf5kVtg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738082049; x=1738686849; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+utsPfRRtrSY+xEHr/3Olh5IQcbAme2skyUQu+gyGyU=; b=TmfkB30Y8hwAZaiIamgJ4zPxMYteYCYw77zWaE0VdylaGyBQfSmLByDfsJfLF2x+2E wzh2DPIF/8Pmd4H33y2r4Eh9r/7BQdjnWg+IPMy5v40W+3onM9xCkX2OMKcpH3vq055c SDqXct+HXxI28e9+L8/Aq5FkFQkCiXK2uN+cNn8FlkwlyEtOnK9PZO4fNRwgMdvk1c5y SElNfvfo64Tp/movoR8KdYdl1pc2uc566pP81Hk7HDP1KhL9Ii9v0DU/PGnNv8sjGwvi bPJjQrqnNzIgX4x0oS3hFLTEtviszOtPvzklXIkCoCDKYl/kZJ0yU1C+Wflh+Se9l+eT XfhQ== X-Gm-Message-State: AOJu0YzvmpcP2sl8b2E11mgIXDxo9i/WvpNtapjOmEO8YfUOv+KUXqq2 HH+CkH9sK24udjfX4WI9LFkxHKhrMJF6PuIkDCfqGcyt2dJWvXDn8rqtOzmxRPNqhcRtfE7R/1v v4KU= X-Gm-Gg: ASbGnct2IWZ36H0b6msadiCOTW/97Kt+zpH+2CTijTpbGRPQnOl+g1SWMxFYw7UeIm/ HScrduon7uG8G3o+kZyiuFUK9qa74l01yus4VbNe/ggtdN0SfMvEIGK3Ke2S7xo7ZuO338ktpDr 7xHLNPF7g+f084MNqZUHumsK/z6Tojc5uAqH+qWT9IfUTvXKSqYMKGNzn6nuNUnhXikZPc1I+L8 c3CD4QiW9bi6PZvRMHeZj8skiq6TiZSS+x+xvFlVxzYDJe9LmlrMRL/ZnSg6QBpKTo4fehpPisq WmIaDKumTQ8dQPRzEdtarqlMCRNpiF20/CLf5IY5 X-Google-Smtp-Source: AGHT+IGxoRvFXq/AMeIRrnMzVWApvagPN96I0pk458DBuIzbtfqHOiMu1ezo4GIdaBfzCaIuXSTNJQ== X-Received: by 2002:a17:906:f5a3:b0:ab6:8435:20e7 with SMTP id a640c23a62f3a-ab684352150mr1403056366b.15.1738082049108; Tue, 28 Jan 2025 08:34:09 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Anthony PERARD 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 Message-ID: <20250128163342.1491-4-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250128163342.1491-1-alejandro.vallejo@cloud.com> References: <20250128163342.1491-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 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 --- 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();