From patchwork Mon Jul 17 23:15:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 121692 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp1411070vqt; Mon, 17 Jul 2023 16:54:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlG6uq7l5tMbwWJS/fkclEUFLOIXTE+XHVWLiXcr9BL7JvhEnsmv5+rPxHadWjqKEuDlE/3m X-Received: by 2002:a17:907:6da2:b0:991:b292:695 with SMTP id sb34-20020a1709076da200b00991b2920695mr13370333ejc.55.1689638051920; Mon, 17 Jul 2023 16:54:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689638051; cv=none; d=google.com; s=arc-20160816; b=hiwXcsNcqfpLl77UHVlWS6dGeNsej0RdOfwycYL78zPc1VKHyU8B2z1OsEvdT71eX3 hL9lFZ3f3pnjQIx19adpTDVX91Pf+tR4truFO2OBeXuRuhvvuRQ3OXFIxE0b2Q9hJ+SB x6oRLjgPj0S9zVzRDbi8UDEY8oWjD+iZkuei9V6llyCCHmAajBc0jmldAAPhABf2X8lj ZATLi9AHjBxrO3UqMJOLXsZZJNu5EHHCm6uQ1dtSx2kp1g14IjNmOxKkAIw5rvEVH/UJ rxe3eSF1x1IbNn5XtAgxmBMFGk8w+WxGqPfoTd5rDRAj9GxKqM+SSC6Evb9lh9tMhbtA OVZA== 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=zCuopdE3RQFCHCsf4zrOItotVQ+TGysIbFJ/I2GYtw8=; fh=MJzvnywV9/WrN/ASipmGkNx/7jKFHnq83nsgXe/obdc=; b=DPwTHBdGVDvh1m2q0v7M33hXaYUtpmHwElKZx7SSh931Je1z2/PWMvMQIaykqpBPKe PGUMy53zM73nrfZmUYc3eIfyIxdQMs92Y9hYqz0ZlHwtQep+V9aGftc4was+2Qh+M9WE 0IbRC3JefDwh/mSFutxK294o9m2FwSuG5JPZUmf2HIo74FdgOw6ff2j8Img8HrsP4Be1 OQyO8uuFjd27v56eXU9GtANwDWoOvXmiEEEOnjKYUeLvznOqm1M2OPEnb/q0TDpImEcw u7Y/kA+shtZX58Oz9/vE11qeXvqyRNFno4x7oO7GrFUrkxOQRzQBQdWqgS61LyZM4Qnt 0ZkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=dppNph2l; 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 bv21-20020a170906b1d500b0099290e2c162si293017ejb.444.2023.07.17.16.53.48; Mon, 17 Jul 2023 16:54:11 -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=dppNph2l; 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 S231621AbjGQXYq (ORCPT + 99 others); Mon, 17 Jul 2023 19:24:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230183AbjGQXYp (ORCPT ); Mon, 17 Jul 2023 19:24:45 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83227173D for ; Mon, 17 Jul 2023 16:24:07 -0700 (PDT) Message-ID: <20230717223225.634205045@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1689635742; 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=zCuopdE3RQFCHCsf4zrOItotVQ+TGysIbFJ/I2GYtw8=; b=dppNph2lvl/AOCMRGkW5+6iP+zBV6T6fhualr5yM3nTvvGsVHRkvAczwnO5iChrUEZTBLr MPzxLG322AeGzqsLHIL4lC77BEWkGJt0evtw7wNvM39/0e9r3ULKKR7Zit9hFaUE1uj8Ys D//L5k0w6q8X4zMFjlVdWr8AhneziF8A2VOYgW6vRHH6H3uV6JQDO+1p9kX8jabWS+JGdG Q+Sn/dd8s8F4QKFSAZHe7Kf9G4wCTmahDZtMHlQM78GGnRnHIRHj0cfVyEOUlH8kF4WfKi YGMkvlg7YcxM9HqhFrXUKnyQZoItU3nMPjRw+jS2TME8KfxqdewJMzSu+ngFNQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1689635742; 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=zCuopdE3RQFCHCsf4zrOItotVQ+TGysIbFJ/I2GYtw8=; b=X3TZmsQ1KOmKrkLjA6RX6lbC27nGCSpGt7+z4PlXHaB7WPz4d7khssHbEuHP3Mrf/F6XmQ gx147IAen5VtsuDw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Linus Torvalds , Andrew Cooper , Tom Lendacky , Paolo Bonzini , Wei Liu , Arjan van de Ven , Juergen Gross Subject: [patch 43/58] x86/apic: Prepare x2APIC for using apic::max_apic_id References: <20230717223049.327865981@linutronix.de> MIME-Version: 1.0 Date: Tue, 18 Jul 2023 01:15:41 +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: 1771713910206738589 X-GMAIL-MSGID: 1771713910206738589 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 --- 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,