From patchwork Mon Jul 24 13:34:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 124993 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp1813294vqg; Mon, 24 Jul 2023 06:51:28 -0700 (PDT) X-Google-Smtp-Source: APBJJlGuR/KIlrPQAZ+h3XAQ3AaXaz0LPghLy/OwPTZhuxIk4OQLOvOWkZ7FaNrjQcr9i+UPAyWy X-Received: by 2002:aa7:c481:0:b0:522:1956:a291 with SMTP id m1-20020aa7c481000000b005221956a291mr5367254edq.8.1690206688110; Mon, 24 Jul 2023 06:51:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690206688; cv=none; d=google.com; s=arc-20160816; b=WSF5MuQLlH65xkF8gegtTIzU246Cp4S1sAbzZC2ehdRvEKO1SHMAhld2+PD2QMKJ4m DWYyjTw5f1oM2fWyQ25zPwW3tQrNrJyHLau0+iV7BPHesJph4IIsev8FhYy8IwVFhAH1 avkHKqUJaGVz4SbtSq4okttT9GXbXnrueSDBYugcWbLncn3GcyVLBh5cCPKHeORf5yPX vecboEF4+DjGNB0K4ZE5ZEZuv3YYWkqkKDnhaXnO7e6tdMet1ByjF7Emq0tbYjy95WuF CPGZ3+CTvO8YQ5wMPxJz+cj5GMgWs8dmUb1CbuLqjlBdO6YQXu4Qx+0LO0vu+fp71BwS Wk6A== 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=szXoVyIugEhLQoBNKHeoJc9xg6are8RXmgk50QQTfEQ=; fh=mE3iieUIZLcDfOLIULj9X6/p0bMDPZGFSVRsnyRUnTc=; b=noIniEXfTpBpiroPGAmAtTx9WXoVKRwk023C6K/pFQEZ8t+iyTfKSrswHOUULPNSgl HRXpFMAMN+2XjRqsTK1NS8c+nQmm/cLxrQ3dLuv9830/U7Q8e82sCOgzensdH2atR/mO Yy/oNKIrDUPhGg783/amIXzAxzjJ9Es6lJ3vwYqss20As71hJLEE9ej750mFgzvcsfr7 qv4RsCMkCKwmqotEqWEFaFqp8IdvumAbQzix7+bUM4LRxOBEZS7WYFaHcXInRNjF00Iv 1wjfKQGOncJdkAr1WsYHkeEyqrHu71L56Z3OkqxCL175mmr0F5No1DlkBg6sZ1PKGhqU 4Fiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=n7uarqd3; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n22-20020a05640206d600b005218239ce10si6678546edy.206.2023.07.24.06.51.03; Mon, 24 Jul 2023 06:51:28 -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=n7uarqd3; 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 S231666AbjGXNiD (ORCPT + 99 others); Mon, 24 Jul 2023 09:38:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231590AbjGXNhe (ORCPT ); Mon, 24 Jul 2023 09:37:34 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E154230ED for ; Mon, 24 Jul 2023 06:36:13 -0700 (PDT) Message-ID: <20230724132047.149054128@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690205699; 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=szXoVyIugEhLQoBNKHeoJc9xg6are8RXmgk50QQTfEQ=; b=n7uarqd3pMzRqJTlxuF5yXK90hit5XxnQykJs8a24A+nlnoQi0N3gkfVjconnL/Sdu0C2G v15Wk4FhYXkJlaKkLMVMV2HK18Do5U6f1D1NjNITNHVAar7gqXfVuOKf2oqGV6g02YScbA G4RLlCeJkFQLmGiAgV3fm+MAyImOCOF8bIVtukwhOpSqpTMr1rS+ZPySumefyi9epw9N2i eI4XiVO/uvFO4wp4hAq2HcjarF3j0t5ZCGktPg1yWxkMxuHDAJu6vqbetSKdxkByk4gyHp 2Q8i51LBvU8ARAVrp6gF4JI3wElYrNlCO1G+BO7CevdN7peyy8MSXkOify4zpg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690205699; 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=szXoVyIugEhLQoBNKHeoJc9xg6are8RXmgk50QQTfEQ=; b=o5eCI97zCcZ87VWWuPVHrr1SAFB0AAZLUdU2CvDZHOj2yu6AOA8CDjKrIPHe0Drvq4kFWY QFxKW1meOXIRfkCQ== 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 43/58] x86/apic: Prepare x2APIC for using apic::max_apic_id References: <20230724131206.500814398@linutronix.de> MIME-Version: 1.0 Date: Mon, 24 Jul 2023 15:34:58 +0200 (CEST) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772310167903674733 X-GMAIL-MSGID: 1772310167903674733 In order to remove the apic::apic_id_valid() callback and switch to checking apic::max_apic_id, it is required to update apic::max_apic_id when the APIC initialization code overrides it via x2apic_set_max_apicid(). Make the existing booleans a bitfield and add a flag which lets the update function and the core code which switches the driver detect whether the apic instance wants to have that update or not and apply it if required. Signed-off-by: Thomas Gleixner Acked-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/apic.h | 7 ++++--- arch/x86/kernel/apic/local.h | 1 + arch/x86/kernel/apic/probe_64.c | 4 ++++ arch/x86/kernel/apic/x2apic_cluster.c | 1 + arch/x86/kernel/apic/x2apic_phys.c | 5 ++++- 5 files changed, 14 insertions(+), 4 deletions(-) --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -266,10 +266,11 @@ struct apic { void (*send_IPI_all)(int vector); void (*send_IPI_self)(int vector); - u32 disable_esr; - enum apic_delivery_modes delivery_mode; - bool dest_mode_logical; + + u32 disable_esr : 1, + dest_mode_logical : 1, + x2apic_set_max_apicid : 1; u32 (*calc_dest_apicid)(unsigned int cpu); --- a/arch/x86/kernel/apic/local.h +++ b/arch/x86/kernel/apic/local.h @@ -23,6 +23,7 @@ int x2apic_phys_pkg_id(int initial_apici void x2apic_send_IPI_all(int vector); void x2apic_send_IPI_allbutself(int vector); void x2apic_send_IPI_self(int vector); +extern u32 x2apic_max_apicid; /* IPI */ --- a/arch/x86/kernel/apic/probe_64.c +++ b/arch/x86/kernel/apic/probe_64.c @@ -19,6 +19,10 @@ static __init void apic_install_driver(s return; apic = driver; + + if (IS_ENABLED(CONFIG_X86_X2APIC) && apic->x2apic_set_max_apicid) + apic->max_apic_id = x2apic_max_apicid; + pr_info("Switched APIC routing to %s:\n", apic->name); } --- a/arch/x86/kernel/apic/x2apic_cluster.c +++ b/arch/x86/kernel/apic/x2apic_cluster.c @@ -240,6 +240,7 @@ static struct apic apic_x2apic_cluster _ .phys_pkg_id = x2apic_phys_pkg_id, .max_apic_id = UINT_MAX, + .x2apic_set_max_apicid = true, .get_apic_id = x2apic_get_apic_id, .set_apic_id = x2apic_set_apic_id, --- a/arch/x86/kernel/apic/x2apic_phys.c +++ b/arch/x86/kernel/apic/x2apic_phys.c @@ -8,11 +8,13 @@ int x2apic_phys; static struct apic apic_x2apic_phys; -static u32 x2apic_max_apicid __ro_after_init = UINT_MAX; +u32 x2apic_max_apicid __ro_after_init = UINT_MAX; void __init x2apic_set_max_apicid(u32 apicid) { x2apic_max_apicid = apicid; + if (apic->x2apic_set_max_apicid) + apic->max_apic_id = apicid; } static int __init set_x2apic_phys_mode(char *arg) @@ -161,6 +163,7 @@ static struct apic apic_x2apic_phys __ro .phys_pkg_id = x2apic_phys_pkg_id, .max_apic_id = UINT_MAX, + .x2apic_set_max_apicid = true, .get_apic_id = x2apic_get_apic_id, .set_apic_id = x2apic_set_apic_id,