Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp3055183rwb; Mon, 7 Aug 2023 07:37:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IElDqFqo2C6XOFGW0YEwx/Lx3f5xyrpQIS6DOE3xsfzvYx+5+OoAHEVlp4pmO/SK6KKs5/t X-Received: by 2002:a17:90a:1787:b0:268:2b38:c9b0 with SMTP id q7-20020a17090a178700b002682b38c9b0mr6870173pja.0.1691419061208; Mon, 07 Aug 2023 07:37:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691419061; cv=none; d=google.com; s=arc-20160816; b=rVPN2sNO2/iq129Fyob5smGp4/zEJA2KBe8CiQbxS9ugXmpR1+XFu8sUHmSaUIpHtF 5MMUBSayygBGQkq9OwpkGRYArGv//qKc0RjOQ7kjHJ+cLI4HtAkQusnlZWhawzIM0ggb iZB3yG0ipdZKhnsI+ZpR6yns6W7UVsmSqvGlZtOdX6mCC+CAjBfeOkW/6JnlmflIhnQr Kw3ULW/b+rKYwOGPlnj+hR2Uswnp49K6aAqMrvxlU1N/n9wUIfEZRkN0COXtF27O27X2 tXxQPZUhx+y4U0clVsrDkrn60ck4M6B8EDOyPIIpQ83Q8W2ZlZx3PnFiHby0kYgss7P2 kOvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=1jDy+E2RKdGXAnT2Cl62jdceXo6yFfKHSHoyZ7qBNXo=; fh=/92WVKYrcN3rA268QXyKzVtm/UtxHeI2lnbU295XDiQ=; b=vqMhdX80HrNtYelgMhU/uWfpeaB8D7ILsnfqzEMnGMyZE86jDYItHdrU2FcE5GBi+m yJdXRERcJ4xxz/r7bVA6PUFGpwgF4G+0xyRIrWswnKoRXqCLCt/xfB9a7hl/XpPOCEiH EGssJUYNTOQjVxyotBqp8MIwl7l8MgYH77F3LXvHgkQxvyEqbJT41lMcH9ZKHwZHKrPc WmUnQyJAU9LKqSACNfZbU3ssKhFg8hpJpKNIpF04yb1qyXGjvvtEaqbni/XvR6IUzC+S VgxC5jnj/v+8prlJfZueSjR96wwb3n2xiPT5Hpf+Wmrjhox/YNOdS+gLR+MyKUjuMYml IO5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Vqgls1KG; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a8-20020a17090abe0800b002682c370e32si3896006pjs.188.2023.08.07.07.37.29; Mon, 07 Aug 2023 07:37:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Vqgls1KG; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234633AbjHGNzv (ORCPT + 99 others); Mon, 7 Aug 2023 09:55:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234621AbjHGNyq (ORCPT ); Mon, 7 Aug 2023 09:54:46 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A990F2680 for ; Mon, 7 Aug 2023 06:53:41 -0700 (PDT) Message-ID: <20230807135028.642879580@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1691416419; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=1jDy+E2RKdGXAnT2Cl62jdceXo6yFfKHSHoyZ7qBNXo=; b=Vqgls1KGgbThxa0cPzIzq7xxMdV//XuJ2bdtGlIcyPSeyOdL0fiEtz9nLblciUvbK29I5o qIB5Ijrp5Hfc5mSScEKaxKMNsqVpI/klhiVZS9W2IhBzBlYbHBrmK4UJFv9gTEJavG+gKi Gkibr+qE+rPnZ2wN8yP8Wy/b2ZOPOlhPMHjZehLvrJFBCJSDGKgk+Gae9YSDDTFZz5Ciyp ecYZhOFCOsLhAAUQcn/utmg+jd6YMzXsSbZiyf7Eq0QXVvw8NRBKO/cVplbSEFhqxzzPRg 6bsGI2j0aXC9jj+GJP1wjonFe0pNsp7gcV9plD5lEJCQFnKwe8jPsQ+rVvAvZw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1691416419; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=1jDy+E2RKdGXAnT2Cl62jdceXo6yFfKHSHoyZ7qBNXo=; b=R2Nshg6rJNPWAunJZisyc2+a4VAL3Urp50ajDxoRPL7hMZe7RYJsfKdfPhAu828SU7qWDm qe03HyqNRkviv1Cw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , Huang Rui , Juergen Gross , Dimitri Sivanich , Michael Kelley , Sohil Mehta , K Prateek Nayak , Kan Liang , Zhang Rui , "Paul E. McKenney" , Feng Tang , Andy Shevchenko Subject: [patch 42/53] x86/cpu/topology: Let XEN/PV use topology from CPUID/MADT References: <20230807130108.853357011@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Mon, 7 Aug 2023 15:53:39 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It turns out that XEN/PV Dom0 has halfways usable CPUID/MADT enumeration except that it cannot deal with CPUs which are enumerated as disabled in MADT. DomU has no MADT and provides at least rudimentary topology information in CPUID leaves 1 and 4. For both it's important that there are not more possible Linux CPUs than vCPUs provided by the hypervisor. As this is ensured by counting the vCPUs before enumeration happens: - lift the restrictions in the CPUID evaluation and the MADT parser - Utilize MADT registration for Dom0 - Keep the fake APIC ID registration for DomU - Fix the XEN APIC fake so the readout of the local APIC ID works for Dom0 via the hypercall and for DomU by returning the registered fake APIC IDs. With that the XEN/PV fake approximates usefulness. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/acpi/boot.c | 25 ++++++++----------------- arch/x86/kernel/cpu/topology_common.c | 2 +- arch/x86/xen/apic.c | 14 +++++++------- arch/x86/xen/smp_pv.c | 13 ++++++++----- 4 files changed, 24 insertions(+), 30 deletions(-) --- a/arch/x86/kernel/acpi/boot.c +++ b/arch/x86/kernel/acpi/boot.c @@ -23,8 +23,6 @@ #include #include -#include - #include #include #include @@ -161,12 +159,6 @@ static int __init acpi_parse_madt(struct return 0; } -static __init void acpi_register_lapic(u32 apic_id, u32 acpi_id, bool present) -{ - if (!xen_pv_domain()) - topology_register_apic(apic_id, acpi_id, present); -} - static bool __init acpi_is_processor_usable(u32 lapic_flags) { if (lapic_flags & ACPI_MADT_ENABLED) @@ -220,7 +212,7 @@ acpi_parse_x2apic(union acpi_subtable_he return 0; } - acpi_register_lapic(apic_id, processor->uid, enabled); + topology_register_apic(apic_id, processor->uid, enabled); #else pr_warn("x2apic entry ignored\n"); #endif @@ -255,9 +247,9 @@ acpi_parse_lapic(union acpi_subtable_hea * to not preallocating memory for all NR_CPUS * when we use CPU hotplug. */ - acpi_register_lapic(processor->id, /* APIC ID */ - processor->processor_id, /* ACPI ID */ - processor->lapic_flags & ACPI_MADT_ENABLED); + topology_register_apic(processor->id, /* APIC ID */ + processor->processor_id, /* ACPI ID */ + processor->lapic_flags & ACPI_MADT_ENABLED); return 0; } @@ -274,9 +266,9 @@ acpi_parse_sapic(union acpi_subtable_hea acpi_table_print_madt_entry(&header->common); - acpi_register_lapic((processor->id << 8) | processor->eid,/* APIC ID */ - processor->processor_id, /* ACPI ID */ - processor->lapic_flags & ACPI_MADT_ENABLED); + topology_register_apic((processor->id << 8) | processor->eid,/* APIC ID */ + processor->processor_id, /* ACPI ID */ + processor->lapic_flags & ACPI_MADT_ENABLED); return 0; } @@ -1073,8 +1065,7 @@ static int __init early_acpi_parse_madt_ return count; } - if (!xen_pv_domain()) - register_lapic_address(acpi_lapic_addr); + register_lapic_address(acpi_lapic_addr); return count; } --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -77,7 +77,7 @@ static bool fake_topology(struct topo_sc topology_set_dom(tscan, TOPO_SMT_DOMAIN, 0, 1); topology_set_dom(tscan, TOPO_CORE_DOMAIN, 0, 1); - return tscan->c->cpuid_level < 1 || xen_pv_domain(); + return tscan->c->cpuid_level < 1; } static void parse_topology(struct topo_scan *tscan, bool early) --- a/arch/x86/xen/apic.c +++ b/arch/x86/xen/apic.c @@ -43,20 +43,20 @@ static u32 xen_apic_read(u32 reg) struct xen_platform_op op = { .cmd = XENPF_get_cpuinfo, .interface_version = XENPF_INTERFACE_VERSION, - .u.pcpu_info.xen_cpuid = 0, }; - int ret; - - /* Shouldn't need this as APIC is turned off for PV, and we only - * get called on the bootup processor. But just in case. */ - if (!xen_initial_domain() || smp_processor_id()) - return 0; + int ret, cpu; if (reg == APIC_LVR) return 0x14; if (reg != APIC_ID) return 0; + cpu = smp_processor_id(); + if (!xen_initial_domain()) + return cpu ? cpuid_to_apicid[cpu] << 24 : 0; + + op.u.pcpu_info.xen_cpuid = cpu; + ret = HYPERVISOR_platform_op(&op); if (ret) op.u.pcpu_info.apic_id = BAD_APICID; --- a/arch/x86/xen/smp_pv.c +++ b/arch/x86/xen/smp_pv.c @@ -156,11 +156,9 @@ static void __init xen_pv_smp_config(voi topology_register_boot_apic(apicid++); - for (i = 1; i < nr_cpu_ids; i++) { - if (HYPERVISOR_vcpu_op(VCPUOP_is_up, i, NULL) < 0) - break; + for (i = 1; i < nr_cpu_ids; i++) topology_register_apic(apicid++, CPU_ACPIID_INVALID, true); - } + /* Pretend to be a proper enumerated system */ smp_found_config = 1; } @@ -451,5 +449,10 @@ void __init xen_smp_init(void) /* Avoid searching for BIOS MP tables */ x86_init.mpparse.find_mptable = x86_init_noop; x86_init.mpparse.early_parse_smp_cfg = x86_init_noop; - x86_init.mpparse.parse_smp_cfg = xen_pv_smp_config; + + /* XEN/PV Dom0 has halfways sane topology information via CPUID/MADT */ + if (xen_initial_domain()) + x86_init.mpparse.parse_smp_cfg = x86_init_noop; + else + x86_init.mpparse.parse_smp_cfg = xen_pv_smp_config; }