From nobody Fri Dec 19 07:47:58 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01DC0C001DF for ; Mon, 24 Jul 2023 13:36:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230051AbjGXNgG (ORCPT ); Mon, 24 Jul 2023 09:36:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231695AbjGXNf3 (ORCPT ); Mon, 24 Jul 2023 09:35:29 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 996D61BCE for ; Mon, 24 Jul 2023 06:34:58 -0700 (PDT) Message-ID: <20230724132046.448154478@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690205678; 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=KMlJ8GHAqxlGy3Usfux4GuD7eAy2oZuqB8vi82Tf9K0=; b=yWnMQAro+CFUoyVtTEmMGHg7CafNx2W9/24/zHzKBTmHnKlYDSv3pLnPaLQbGjH03m88EX DTQRunwiSXfj33cvwYg07RFKyyY98LZk88gQcoAQxNtR9lP+nPpQdUujiDJtni00az0F15 1EnybptNTnt0h7b5mJqaLL0AN/XyE6VcAmSA/Bz6+hnm9HlpL8dSU+jQ+mPdAgoo+vP/eV WoK24kWI2jQXwrNm25jba0mR6Bi1nmIIU0ED6nxil7P5BUC8S5lLV7/NSlHzotnxJsaSj3 msbisRlK9c45al3UkyCLuOaS1ZKZhEg2mX4iy0xAzVwBLp1Mhbrpj1NDYX+tPQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690205678; 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=KMlJ8GHAqxlGy3Usfux4GuD7eAy2oZuqB8vi82Tf9K0=; b=YILlrcWDt/VbFma6qdluJkCjAZkz1Hibb+i6PwQXwnmGw5qGg0iccLM56FGyRipuQ0e2D0 reXxcqIk2niISdDg== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Andrew Cooper , Tom Lendacky , Paolo Bonzini , Wei Liu , Arjan van de Ven , Juergen Gross , Michael Kelley , Peter Keresztes Schmidt , "Peter Zijlstra (Intel)" Subject: [patch V2 31/58] x86/apic: Mop up apic::apic_id_registered() References: <20230724131206.500814398@linutronix.de> MIME-Version: 1.0 Date: Mon, 24 Jul 2023 15:34:37 +0200 (CEST) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Really not a hotpath and again no reason for having a gazillion of empty callbacks returning 1. Make it return bool and provide one shared implementation for the remaining users. Signed-off-by: Thomas Gleixner Acked-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/apic.h | 2 +- arch/x86/kernel/apic/apic.c | 7 ++----- arch/x86/kernel/apic/apic_common.c | 5 +++++ arch/x86/kernel/apic/apic_flat_64.c | 14 ++------------ arch/x86/kernel/apic/apic_noop.c | 12 ------------ arch/x86/kernel/apic/apic_numachip.c | 7 ------- arch/x86/kernel/apic/bigsmp_32.c | 6 ------ arch/x86/kernel/apic/local.h | 3 ++- arch/x86/kernel/apic/probe_32.c | 5 ----- arch/x86/kernel/apic/x2apic_cluster.c | 1 - arch/x86/kernel/apic/x2apic_phys.c | 6 ------ arch/x86/kernel/apic/x2apic_uv_x.c | 6 ------ arch/x86/xen/apic.c | 6 ------ 13 files changed, 12 insertions(+), 68 deletions(-) --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -295,7 +295,7 @@ struct apic { int (*probe)(void); int (*acpi_madt_oem_check)(char *oem_id, char *oem_table_id); int (*apic_id_valid)(u32 apicid); - int (*apic_id_registered)(void); + bool (*apic_id_registered)(void); =20 bool (*check_apicid_used)(physid_mask_t *map, int apicid); void (*init_apic_ldr)(void); --- a/arch/x86/kernel/apic/apic.c +++ b/arch/x86/kernel/apic/apic.c @@ -1571,11 +1571,8 @@ static void setup_local_APIC(void) apic_write(APIC_ESR, 0); } #endif - /* - * Double-check whether this APIC is really registered. - * This is meaningless in clustered apic mode, so we skip it. - */ - BUG_ON(!apic->apic_id_registered()); + /* Validate that the APIC is registered if required */ + BUG_ON(apic->apic_id_registered && !apic->apic_id_registered()); =20 /* * Intel recommends to set DFR, LDR and TPR before enabling --- a/arch/x86/kernel/apic/apic_common.c +++ b/arch/x86/kernel/apic/apic_common.c @@ -42,6 +42,11 @@ int default_apic_id_valid(u32 apicid) return (apicid < 255); } =20 +bool default_apic_id_registered(void) +{ + return physid_isset(read_apic_id(), phys_cpu_present_map); +} + /* * Set up the logical destination ID when the APIC operates in logical * destination mode. --- a/arch/x86/kernel/apic/apic_flat_64.c +++ b/arch/x86/kernel/apic/apic_flat_64.c @@ -66,16 +66,6 @@ static u32 set_apic_id(unsigned int id) return (id & 0xFF) << 24; } =20 -static unsigned int read_xapic_id(void) -{ - return flat_get_apic_id(apic_read(APIC_ID)); -} - -static int flat_apic_id_registered(void) -{ - return physid_isset(read_xapic_id(), phys_cpu_present_map); -} - static int flat_phys_pkg_id(int initial_apic_id, int index_msb) { return initial_apic_id >> index_msb; @@ -91,7 +81,7 @@ static struct apic apic_flat __ro_after_ .probe =3D flat_probe, .acpi_madt_oem_check =3D flat_acpi_madt_oem_check, .apic_id_valid =3D default_apic_id_valid, - .apic_id_registered =3D flat_apic_id_registered, + .apic_id_registered =3D default_apic_id_registered, =20 .delivery_mode =3D APIC_DELIVERY_MODE_FIXED, .dest_mode_logical =3D true, @@ -168,7 +158,7 @@ static struct apic apic_physflat __ro_af .probe =3D physflat_probe, .acpi_madt_oem_check =3D physflat_acpi_madt_oem_check, .apic_id_valid =3D default_apic_id_valid, - .apic_id_registered =3D flat_apic_id_registered, + .apic_id_registered =3D default_apic_id_registered, =20 .delivery_mode =3D APIC_DELIVERY_MODE_FIXED, .dest_mode_logical =3D false, --- a/arch/x86/kernel/apic/apic_noop.c +++ b/arch/x86/kernel/apic/apic_noop.c @@ -57,17 +57,6 @@ static int noop_probe(void) return 0; } =20 -static int noop_apic_id_registered(void) -{ - /* - * if we would be really "pedantic" - * we should pass read_apic_id() here - * but since NOOP suppose APIC ID =3D 0 - * lets save a few cycles - */ - return physid_isset(0, phys_cpu_present_map); -} - static u32 noop_apic_read(u32 reg) { WARN_ON_ONCE(boot_cpu_has(X86_FEATURE_APIC) && !apic_is_disabled); @@ -85,7 +74,6 @@ struct apic apic_noop __ro_after_init =3D .acpi_madt_oem_check =3D NULL, =20 .apic_id_valid =3D default_apic_id_valid, - .apic_id_registered =3D noop_apic_id_registered, =20 .delivery_mode =3D APIC_DELIVERY_MODE_FIXED, .dest_mode_logical =3D true, --- a/arch/x86/kernel/apic/apic_numachip.c +++ b/arch/x86/kernel/apic/apic_numachip.c @@ -62,11 +62,6 @@ static int numachip_apic_id_valid(u32 ap return 1; } =20 -static int numachip_apic_id_registered(void) -{ - return 1; -} - static int numachip_phys_pkg_id(int initial_apic_id, int index_msb) { return initial_apic_id >> index_msb; @@ -244,7 +239,6 @@ static const struct apic apic_numachip1 .probe =3D numachip1_probe, .acpi_madt_oem_check =3D numachip1_acpi_madt_oem_check, .apic_id_valid =3D numachip_apic_id_valid, - .apic_id_registered =3D numachip_apic_id_registered, =20 .delivery_mode =3D APIC_DELIVERY_MODE_FIXED, .dest_mode_logical =3D false, @@ -286,7 +280,6 @@ static const struct apic apic_numachip2 .probe =3D numachip2_probe, .acpi_madt_oem_check =3D numachip2_acpi_madt_oem_check, .apic_id_valid =3D numachip_apic_id_valid, - .apic_id_registered =3D numachip_apic_id_registered, =20 .delivery_mode =3D APIC_DELIVERY_MODE_FIXED, .dest_mode_logical =3D false, --- a/arch/x86/kernel/apic/bigsmp_32.c +++ b/arch/x86/kernel/apic/bigsmp_32.c @@ -18,11 +18,6 @@ static unsigned bigsmp_get_apic_id(unsig return (x >> 24) & 0xFF; } =20 -static int bigsmp_apic_id_registered(void) -{ - return 1; -} - static bool bigsmp_check_apicid_used(physid_mask_t *map, int apicid) { return false; @@ -85,7 +80,6 @@ static struct apic apic_bigsmp __ro_afte .name =3D "bigsmp", .probe =3D probe_bigsmp, .apic_id_valid =3D default_apic_id_valid, - .apic_id_registered =3D bigsmp_apic_id_registered, =20 .delivery_mode =3D APIC_DELIVERY_MODE_FIXED, .dest_mode_logical =3D false, --- a/arch/x86/kernel/apic/local.h +++ b/arch/x86/kernel/apic/local.h @@ -15,7 +15,6 @@ =20 /* X2APIC */ int x2apic_apic_id_valid(u32 apicid); -int x2apic_apic_id_registered(void); void __x2apic_send_IPI_dest(unsigned int apicid, int vector, unsigned int = dest); unsigned int x2apic_get_apic_id(unsigned long id); u32 x2apic_set_apic_id(unsigned int id); @@ -61,6 +60,8 @@ void default_send_IPI_allbutself(int vec void default_send_IPI_all(int vector); void default_send_IPI_self(int vector); =20 +bool default_apic_id_registered(void); + #ifdef CONFIG_X86_32 void default_send_IPI_mask_sequence_logical(const struct cpumask *mask, in= t vector); void default_send_IPI_mask_allbutself_logical(const struct cpumask *mask, = int vector); --- a/arch/x86/kernel/apic/probe_32.c +++ b/arch/x86/kernel/apic/probe_32.c @@ -18,11 +18,6 @@ =20 #include "local.h" =20 -static int default_apic_id_registered(void) -{ - return physid_isset(read_apic_id(), phys_cpu_present_map); -} - static int default_phys_pkg_id(int cpuid_apic, int index_msb) { return cpuid_apic >> index_msb; --- a/arch/x86/kernel/apic/x2apic_cluster.c +++ b/arch/x86/kernel/apic/x2apic_cluster.c @@ -237,7 +237,6 @@ static struct apic apic_x2apic_cluster _ .probe =3D x2apic_cluster_probe, .acpi_madt_oem_check =3D x2apic_acpi_madt_oem_check, .apic_id_valid =3D x2apic_apic_id_valid, - .apic_id_registered =3D x2apic_apic_id_registered, =20 .delivery_mode =3D APIC_DELIVERY_MODE_FIXED, .dest_mode_logical =3D true, --- a/arch/x86/kernel/apic/x2apic_phys.c +++ b/arch/x86/kernel/apic/x2apic_phys.c @@ -111,11 +111,6 @@ int x2apic_apic_id_valid(u32 apicid) return 1; } =20 -int x2apic_apic_id_registered(void) -{ - return 1; -} - void __x2apic_send_IPI_dest(unsigned int apicid, int vector, unsigned int = dest) { unsigned long cfg =3D __prepare_ICR(0, vector, dest); @@ -157,7 +152,6 @@ static struct apic apic_x2apic_phys __ro .probe =3D x2apic_phys_probe, .acpi_madt_oem_check =3D x2apic_acpi_madt_oem_check, .apic_id_valid =3D x2apic_apic_id_valid, - .apic_id_registered =3D x2apic_apic_id_registered, =20 .delivery_mode =3D APIC_DELIVERY_MODE_FIXED, .dest_mode_logical =3D false, --- a/arch/x86/kernel/apic/x2apic_uv_x.c +++ b/arch/x86/kernel/apic/x2apic_uv_x.c @@ -783,11 +783,6 @@ static int uv_apic_id_valid(u32 apicid) return 1; } =20 -static int uv_apic_id_registered(void) -{ - return 1; -} - static u32 apic_uv_calc_apicid(unsigned int cpu) { return apic_default_calc_apicid(cpu); @@ -829,7 +824,6 @@ static struct apic apic_x2apic_uv_x __ro .probe =3D uv_probe, .acpi_madt_oem_check =3D uv_acpi_madt_oem_check, .apic_id_valid =3D uv_apic_id_valid, - .apic_id_registered =3D uv_apic_id_registered, =20 .delivery_mode =3D APIC_DELIVERY_MODE_FIXED, .dest_mode_logical =3D false, --- a/arch/x86/xen/apic.c +++ b/arch/x86/xen/apic.c @@ -115,11 +115,6 @@ static int xen_id_always_valid(u32 apici return 1; } =20 -static int xen_id_always_registered(void) -{ - return 1; -} - static int xen_phys_pkg_id(int initial_apic_id, int index_msb) { return initial_apic_id >> index_msb; @@ -142,7 +137,6 @@ static struct apic xen_pv_apic =3D { .probe =3D xen_apic_probe_pv, .acpi_madt_oem_check =3D xen_madt_oem_check, .apic_id_valid =3D xen_id_always_valid, - .apic_id_registered =3D xen_id_always_registered, =20 /* .delivery_mode and .dest_mode_logical not used by XENPV */