From patchwork Wed Aug 2 10:20:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129754 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp359156vqx; Wed, 2 Aug 2023 03:40:03 -0700 (PDT) X-Google-Smtp-Source: APBJJlHvDQzIyiz9sMgWkZb1jyWjCyXwkIKTNVK0oOPnTBzPoforON4BRUKyu/nYDr3bCzyi5+oW X-Received: by 2002:a17:906:7385:b0:99c:825:6076 with SMTP id f5-20020a170906738500b0099c08256076mr4273473ejl.35.1690972803350; Wed, 02 Aug 2023 03:40:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690972803; cv=none; d=google.com; s=arc-20160816; b=REEt+8e3FQ0FGL71SRfUSFv747pkJR2MmONpojE8wAw8hIANBwcNYbHGzk+ktMVxPs ok45m1lfZb7dNUeMNsOflTw3dO3TjYOMJhOY4jaAJ+XPJ2heFOTLfubmGl99XyreSnoZ ZJF2NFTi6a7bij3PtboubIZH/z/0RR+REECEbk/XHpqkZftjsb2IwmlLJHHsz4ICSqDL k5c2bXZACL3dRq8NM7TwSj8AYu1xD5Zo44Y80ZR1UjUaFLybwW2tIxmT2vMCbesFdE/N GxBlGMeZIdbJ7PjRETY1yR2HYPn6mtJgdKeLS0zskKVFYWB6w5tgHldaAo/b2HtRZ33R 7atQ== 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=ifKZU+jjVp506gXqEzVY99mBfb+xgbx4G16QrL/5KJI=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=P6Ow9XPeMiMMbsIut7+qdTNiOdbrVaxSTKwrbEVpbP/wCFFdp+OBNIEJ/Uo/Zb16FZ aTsBdRf5mHJtrbRl3AE7uLp62zmHfDl7g2Rj2n5ot8xEdL/rMKK2W0l60Yq7FPsRorGa FcdG+Kj9EJm5btsiE532T0sPzMXxYQpzoRwItcHv0yqBUpoRFQQo8ob9t5RLC55AdCUc M4z6O3bwahyGdTd57nkPN7f4jK7pevmbONQi5qvTbkzQo12/6vfwYubTb9+zNz+F8Ohq yJ4ryQdwMFYNenO7ZGpwNLcr8Dv9NxlpDnSCHvWeorsovwyoaSlBTQewDPxtHjgkAn24 RkjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Bgi3c5jI; 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 k17-20020a1709061c1100b0098885a739f2si7529376ejg.657.2023.08.02.03.39.39; Wed, 02 Aug 2023 03:40:03 -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=Bgi3c5jI; 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 S233160AbjHBKVM (ORCPT + 99 others); Wed, 2 Aug 2023 06:21:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230456AbjHBKVC (ORCPT ); Wed, 2 Aug 2023 06:21:02 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70F5E213D for ; Wed, 2 Aug 2023 03:21:01 -0700 (PDT) Message-ID: <20230802101932.758513086@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971660; 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=ifKZU+jjVp506gXqEzVY99mBfb+xgbx4G16QrL/5KJI=; b=Bgi3c5jIXWreNy1JQ1MW9oDkILk7cgZUTKPxAO8T5MMvnv1n/GW3zEjKiDefWH5acpRFJ7 VrXd5+F/maZKCZcWS9+bjE/LZIrlfkO4cVVrURoQpB+h7ofDPfGhCgpA9TpINiLIFzYfll /Qiho4obvDD73/Bu05lzc7Cw/mkNuwwK7+2b8KD97pZ3Fc70chGo/WXvDjvS0ZEtxNO5Tq VCV4xhMUWq9qhAGAjXch0YicemdBAI9QRTfJX8eHkZh6no/IRsIanCUpIvLMEM+zPNkeTk KLDSJbeGvWYnPkeSIGAwkr5WpY8MaZT5Pa69RV19/RrGQOWAS6KYdrUvaOYcIg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971660; 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=ifKZU+jjVp506gXqEzVY99mBfb+xgbx4G16QrL/5KJI=; b=SbMoLthrNU8kvnS9+wB47EzWogOFxHaYI+rsI/o92tIgkiI6+VdfYFcC/i7ukbdnahT2go Yky/aTE8jn1fIyCw== 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 , Wei Liu Subject: [patch V3 01/40] cpu/SMT: Make SMT control more robust against enumeration failures References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:20:59 +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,URIBL_BLOCKED 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: 1773113497983168292 X-GMAIL-MSGID: 1773113497983168292 The SMT control mechanism got added as speculation attack vector mitigation. The implemented logic relies on the primary thread mask to be set up properly. This turns out to be an issue with XEN/PV guests because their CPU hotplug mechanics do not enumerate APICs and therefore the mask is never correctly populated. This went unnoticed so far because by chance XEN/PV ends up with smp_num_siblings == 2. So smt_hotplug_control stays at its default value CPU_SMT_ENABLED and the primary thread mask is never evaluated in the context of CPU hotplug. This stopped "working" with the upcoming overhaul of the topology evaluation which legitimately provides a fake topology for XEN/PV. That sets smp_num_siblings to 1, which causes the core CPU hot-plug core to refuse to bring up the APs. This happens because smt_hotplug_control is set to CPU_SMT_NOT_SUPPORTED which causes cpu_smt_allowed() to evaluate the unpopulated primary thread mask with the conclusion that all non-boot CPUs are not valid to be plugged. Make cpu_smt_allowed() more robust and take CPU_SMT_NOT_SUPPORTED and CPU_SMT_NOT_IMPLEMENTED into account. The primary mask issue on x86 XEN/PV needs to be addressed separately as there are users outside of the CPU hotplug code too. Fixes: 05736e4ac13c ("cpu/hotplug: Provide knobs to control SMT") Reported-by: Juergen Gross Signed-off-by: Thomas Gleixner --- kernel/cpu.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -630,6 +630,12 @@ static inline bool cpu_smt_allowed(unsig if (cpu_smt_control == CPU_SMT_ENABLED) return true; + if (cpu_smt_control == CPU_SMT_NOT_SUPPORTED) + return true; + + if (cpu_smt_control == CPU_SMT_NOT_IMPLEMENTED) + return true; + if (topology_is_primary_thread(cpu)) return true; From patchwork Wed Aug 2 10:21:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129762 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp364198vqx; Wed, 2 Aug 2023 03:52:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlHXwyZczd4WjbCSP5Si8DnykbMnkoqUtHjAzEXcj4eeQWZUgJ/WosDuvsHc0mpUJb8SfZtk X-Received: by 2002:aa7:c419:0:b0:522:36e8:bc88 with SMTP id j25-20020aa7c419000000b0052236e8bc88mr4323859edq.12.1690973556585; Wed, 02 Aug 2023 03:52:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690973556; cv=none; d=google.com; s=arc-20160816; b=LRft+A2gw/CEgXcvajJNHyh9FqzXdhKZx2hr407m5ALA6/+9SK2ZsS+c8S97h9eOYS wTpOLl/D+pQuOac4biJEh6Gy/eAQgXkDWkFjgdfHle/iHZxDOLCUAh+fpISylUxAFJqP /kzV91gPzdDo1zeSTx1hr1+X8r8trS+DDLHEl6802J5tMfkYivL+Kuy31W3TmcY4WcTA pTeDI+/yeMnwlALFB+hQVM/2Gs46K03pwwl53x7yzP6mgvI1MCmEGHI14ugtzc7OjqNO cpSJoQpTkhJQwXFrN54VrfXbZmtJqqCtl+r0ZFeh02L3znzSecnZ66XddkES1DuQtFtk SOTQ== 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=KworwVT2v0HpqXoPWJdJcjW+bA4KcReILTYRuVf21jU=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=lNuv6vokbnp+10KkhD5f9ShYnYXVD48rlDjjOkWUOtSQay/6LiW8BQmDpXru9CVxDl BmgHSx6/+vnnpPY9i6heS/U42jLPJwFSxqw7XIEMmDc71xalv5E/tyFANId8z+hbAP6q Yylva4Qh2zPBlU4IeHzjU6a3NwH4J2YEgSdIdZ4SFhI0LsvKkg0fmkcbvkpJYsSG3CzI HveZu9ECxtQpoWv51CSyJR1MFwPBL8hndqR0Hhbhz4g1esGQi0FfXRbF4JwmrwaSr/pb 8SQFrr7tNo+h39fQZDPH3Z8gMcOiEfem/+er1VEVLA5i/hJ4NR9nCjlXVhwoOHY10c/E i17g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="p/BKVW6r"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 h9-20020aa7de09000000b005223f8d2a2csi9510302edv.441.2023.08.02.03.52.13; Wed, 02 Aug 2023 03:52:36 -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="p/BKVW6r"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S233413AbjHBKVQ (ORCPT + 99 others); Wed, 2 Aug 2023 06:21:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233212AbjHBKVF (ORCPT ); Wed, 2 Aug 2023 06:21:05 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EB952690 for ; Wed, 2 Aug 2023 03:21:02 -0700 (PDT) Message-ID: <20230802101932.819070039@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971661; 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=KworwVT2v0HpqXoPWJdJcjW+bA4KcReILTYRuVf21jU=; b=p/BKVW6rK2byUO6m6m7keMSO0k6eLcnu+ZVZBAHzwkKkaL3qYNTYBJ3+Xxld6PSFMKwvC3 qWoIjVCE/RY+re/+YUeII8FzRmk2USFYEDcsuoKIo5uXntaTtsq0pFwQzAuJJTkf+ahj7N sBWrYiOuOBsMuCgOjldGH8LtQG1rG/rq/BmFbxGfLXukoH3wm3ei11leQHzIazrDaRU0ez 9F8IdQFefXVgyY4kXQ8W1GMKwal2cCr1teVVwuc8ZLrqlZgn4EtyA821Y3F/1wRqACVv29 7MxNifWr6s8J2FMrTtQxmneu2XfyDhkV0JnXusQ81t/1KIyLZeGPs/1BYxnMyA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971661; 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=KworwVT2v0HpqXoPWJdJcjW+bA4KcReILTYRuVf21jU=; b=gmJPpEGfssLMz9LV7H2vKKjNS/3GGIo7SH/jpzhq9puu8MBthGCUE3NrNk5AhkEU6AGch8 PCOsmBFyD+08lYBw== 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 , Wei Liu Subject: [patch V3 02/40] x86/apic: Fake primary thread mask for XEN/PV References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:01 +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,URIBL_BLOCKED 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: 1773114288076572650 X-GMAIL-MSGID: 1773114288076572650 The SMT control mechanism got added as speculation attack vector mitigation. The implemented logic relies on the primary thread mask to be set up properly. This turns out to be an issue with XEN/PV guests because their CPU hotplug mechanics do not enumerate APICs and therefore the mask is never correctly populated. This went unnoticed so far because by chance XEN/PV ends up with smp_num_siblings == 2. So smt_hot-plug_control stays at its default value CPU_SMT_ENABLED and the primary thread mask is never evaluated in the context of CPU hotplug. This stopped "working" with the upcoming overhaul of the topology evaluation which legitimately provides a fake topology for XEN/PV. That sets smp_num_siblings to 1, which causes the core CPU hot-plug core to refuse to bring up the APs. This happens because smt_hotplug_control is set to CPU_SMT_NOT_SUPPORTED which causes cpu_smt_allowed() to evaluate the unpopulated primary thread mask with the conclusion that all non-boot CPUs are not valid to be plugged. The core code has already been made more robust against this kind of fail, but the primary thread mask really wants to be populated to avoid other issues all over the place. Just fake the mask by pretending that all XEN/PV vCPUs are primary threads, which is consistent because all of XEN/PVs topology is fake or non-existent. Fixes: 6a4d2657e048 ("x86/smp: Provide topology_is_primary_thread()") Fixes: f54d4434c281 ("x86/apic: Provide cpu_primary_thread mask") Reported-by: Juergen Gross Signed-off-by: Thomas Gleixner --- arch/x86/kernel/apic/apic.c | 11 +++++++++++ 1 file changed, 11 insertions(+) --- a/arch/x86/kernel/apic/apic.c +++ b/arch/x86/kernel/apic/apic.c @@ -36,6 +36,8 @@ #include #include +#include + #include #include #include @@ -2344,6 +2346,15 @@ static int __init smp_init_primary_threa { unsigned int cpu; + /* + * XEN/PV provides either none or useless topology information. + * Pretend that all vCPUs are primary threads. + */ + if (xen_pv_domain()) { + cpumask_copy(&__cpu_primary_thread_mask, cpu_possible_mask); + return 0; + } + for (cpu = 0; cpu < nr_logical_cpuids; cpu++) cpu_mark_primary_thread(cpu, cpuid_to_apicid[cpu]); return 0; From patchwork Wed Aug 2 10:21:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129811 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp413861vqx; Wed, 2 Aug 2023 05:20:10 -0700 (PDT) X-Google-Smtp-Source: APBJJlGDnFw0IEpkp70y4vIhve35vEp76jikJrwU0cFoHOsoXkVbG9v3JJR+yXdQeTc6BNvH9Gsb X-Received: by 2002:a17:907:9686:b0:98d:ebb7:a8b0 with SMTP id hd6-20020a170907968600b0098debb7a8b0mr7220235ejc.14.1690978810416; Wed, 02 Aug 2023 05:20:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690978810; cv=none; d=google.com; s=arc-20160816; b=aG7tNFYJXFJeChTexNSZg/yAOisLK2ALq7iGB+a0W8hyaFysrEfmTqFnbF9mm9I44M 7JkasHPLQbkFkUYAkMs29kWaQnr+3oWuIakd2hd1dJiHo95AajdZYDM+h1Eap1uq/QtD 5ewN30GjrXCb6ZwNVQA+5yt7gO7n98qOgJMQkwtv88HEokaUFEa/lkgqDaStBKhf03Rl 1J58RyN5Q3Fy6ZSoN588VcTEuE2rdN9iRZZhIueyr1+vF5yKN0sWv6YorDDJTEsGKZ/R PcqzkbGnTPbFOJGyqi+qkCt9hIdM79OFWpirvPEZitpdu4DNpbCNdlhbLSo2UhOHzt2D V2oA== 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=nJP92ZJMXC8M/YJGPnD+1ew7/OovV6r/sIvEynfyO4k=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=CVFanFGfJu4np8ntKC3SibpstkyMXCqHCUOT6C0y1hKwwjsQnWjBWiNqOXlZvWuQW+ 18EqC9ttG8tb+kROGl4DxoXpCcxxm/ML28upYv+y9U/UDkJ8ddnsu/FL3JL+jhHBEsmf sF8l33LUZj4wVt17usq/nWXY1hZVLx13s0xYRoi5g8S7yft5neAEyZ8dTcE/BzhgmNdy RvcYuIL14lexKlARTfRus8AFZ5Pzm1P83fxKnwFygtpE84sTY+svMPA+HV4i9X/it60B skilpIE89HTj3S7a59l+5MXOpGzMcSnVlEqiXyrsHlWnN4MMt27kOc4wKv+ZQApOEyFS YOEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=gDFcm6wM; 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 y26-20020a170906071a00b0098d6097599esi10334790ejb.872.2023.08.02.05.19.45; Wed, 02 Aug 2023 05:20:10 -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=gDFcm6wM; 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 S233339AbjHBKVT (ORCPT + 99 others); Wed, 2 Aug 2023 06:21:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233272AbjHBKVJ (ORCPT ); Wed, 2 Aug 2023 06:21:09 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 869D22698 for ; Wed, 2 Aug 2023 03:21:04 -0700 (PDT) Message-ID: <20230802101932.876156493@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971663; 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=nJP92ZJMXC8M/YJGPnD+1ew7/OovV6r/sIvEynfyO4k=; b=gDFcm6wMqNxj/7HRJ+xTYd1J1ayejnSpZ8BYUKcdzVPyXccAg3JEpwJ26u8TW1DiYHy1Us mubCmLepW5wPFd66GZ1KqHFb1p4QuXSo3gYMq5Tz8rKGRVbVfuttwC5Cj5a6IrOXPfkI6F GTXtJ2gYNSea4tf5CvxTny7DowL6MT4WSmnSKeSqAu4pCBkS/iP8iGA5sOu0ZiNyV9mzbr uwO9Ecr39dLQ/0nMaOeZ5X17Ko68z9yQy7B+gmy84hVldIRTXfdCKTp+xYZeuaokLl1I6t tpwN57clSkrJFgRYuhu/6++fuXpGATyQOamlFOuPMLPxZndymWX37qUGn0Q7gQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971663; 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=nJP92ZJMXC8M/YJGPnD+1ew7/OovV6r/sIvEynfyO4k=; b=MjYPETlhtQZV/hf5y4YIM2Jauvk3Tb/rwWksSqU4cLizKZ1XYhnkRLhmeXrUUVR2LOjC5t o2Gak0SJyPpdfpCw== 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 , Wei Liu Subject: [patch V3 03/40] x86/cpu: Encapsulate topology information in cpuinfo_x86 References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:02 +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,URIBL_BLOCKED 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: 1773119797258814982 X-GMAIL-MSGID: 1773119797258814982 The topology related information is randomly scattered across cpuinfo_x86. Create a new structure cpuinfo_topo and move in a first step initial_apicid and apicid into it. Aside of being better readable this is in preparation for replacing the horribly fragile CPU topology evaluation code further down the road. Consolidate APIC ID fields to u32 as that represents the hardware type. No functional change. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/processor.h | 14 +++++++++----- arch/x86/kernel/cpu/amd.c | 10 +++++----- arch/x86/kernel/cpu/cacheinfo.c | 20 ++++++++++---------- arch/x86/kernel/cpu/common.c | 18 +++++++++--------- arch/x86/kernel/cpu/hygon.c | 12 ++++++------ arch/x86/kernel/cpu/mce/apei.c | 2 +- arch/x86/kernel/cpu/mce/core.c | 2 +- arch/x86/kernel/cpu/proc.c | 4 ++-- arch/x86/kernel/cpu/topology.c | 12 ++++++------ arch/x86/xen/apic.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 2 +- drivers/virt/acrn/hsm.c | 2 +- 12 files changed, 52 insertions(+), 48 deletions(-) --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -74,11 +74,16 @@ extern u16 __read_mostly tlb_lld_4m[NR_I extern u16 __read_mostly tlb_lld_1g[NR_INFO]; /* - * CPU type and hardware bug flags. Kept separately for each CPU. - * Members of this structure are referenced in head_32.S, so think twice - * before touching them. [mj] + * CPU type and hardware bug flags. Kept separately for each CPU. */ +struct cpuinfo_topology { + // Real APIC ID read from the local APIC + u32 apicid; + // The initial APIC ID provided by CPUID + u32 initial_apicid; +}; + struct cpuinfo_x86 { __u8 x86; /* CPU family */ __u8 x86_vendor; /* CPU vendor */ @@ -111,6 +116,7 @@ struct cpuinfo_x86 { }; char x86_vendor_id[16]; char x86_model_id[64]; + struct cpuinfo_topology topo; /* in KB - valid for CPUS which support this call: */ unsigned int x86_cache_size; int x86_cache_alignment; /* In bytes */ @@ -124,8 +130,6 @@ struct cpuinfo_x86 { u64 ppin; /* cpuid returned max cores value: */ u16 x86_max_cores; - u16 apicid; - u16 initial_apicid; u16 x86_clflush_size; /* number of cores as seen by the OS: */ u16 booted_cores; --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -387,9 +387,9 @@ static void amd_detect_cmp(struct cpuinf bits = c->x86_coreid_bits; /* Low order bits define the core id (index of core in socket) */ - c->cpu_core_id = c->initial_apicid & ((1 << bits)-1); + c->cpu_core_id = c->topo.initial_apicid & ((1 << bits)-1); /* Convert the initial APIC ID into the socket ID */ - c->phys_proc_id = c->initial_apicid >> bits; + c->phys_proc_id = c->topo.initial_apicid >> bits; /* use socket ID also for last level cache */ per_cpu(cpu_llc_id, cpu) = c->cpu_die_id = c->phys_proc_id; } @@ -405,7 +405,7 @@ static void srat_detect_node(struct cpui #ifdef CONFIG_NUMA int cpu = smp_processor_id(); int node; - unsigned apicid = c->apicid; + unsigned apicid = c->topo.apicid; node = numa_cpu_node(cpu); if (node == NUMA_NO_NODE) @@ -439,7 +439,7 @@ static void srat_detect_node(struct cpui * through CPU mapping may alter the outcome, directly * access __apicid_to_node[]. */ - int ht_nodeid = c->initial_apicid; + int ht_nodeid = c->topo.initial_apicid; if (__apicid_to_node[ht_nodeid] != NUMA_NO_NODE) node = __apicid_to_node[ht_nodeid]; @@ -934,7 +934,7 @@ static void init_amd(struct cpuinfo_x86 set_cpu_cap(c, X86_FEATURE_FSRS); /* get apicid instead of initial apic id from cpuid */ - c->apicid = read_apic_id(); + c->topo.apicid = read_apic_id(); /* K6s reports MCEs but don't actually have all the MSRs */ if (c->x86 < 6) --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -678,7 +678,7 @@ void cacheinfo_amd_init_llc_id(struct cp * LLC is at the core complex level. * Core complex ID is ApicId[3] for these processors. */ - per_cpu(cpu_llc_id, cpu) = c->apicid >> 3; + per_cpu(cpu_llc_id, cpu) = c->topo.apicid >> 3; } else { /* * LLC ID is calculated from the number of threads sharing the @@ -694,7 +694,7 @@ void cacheinfo_amd_init_llc_id(struct cp if (num_sharing_cache) { int bits = get_count_order(num_sharing_cache); - per_cpu(cpu_llc_id, cpu) = c->apicid >> bits; + per_cpu(cpu_llc_id, cpu) = c->topo.apicid >> bits; } } } @@ -712,7 +712,7 @@ void cacheinfo_hygon_init_llc_id(struct * LLC is at the core complex level. * Core complex ID is ApicId[3] for these processors. */ - per_cpu(cpu_llc_id, cpu) = c->apicid >> 3; + per_cpu(cpu_llc_id, cpu) = c->topo.apicid >> 3; } void init_amd_cacheinfo(struct cpuinfo_x86 *c) @@ -776,13 +776,13 @@ void init_intel_cacheinfo(struct cpuinfo new_l2 = this_leaf.size/1024; num_threads_sharing = 1 + this_leaf.eax.split.num_threads_sharing; index_msb = get_count_order(num_threads_sharing); - l2_id = c->apicid & ~((1 << index_msb) - 1); + l2_id = c->topo.apicid & ~((1 << index_msb) - 1); break; case 3: new_l3 = this_leaf.size/1024; num_threads_sharing = 1 + this_leaf.eax.split.num_threads_sharing; index_msb = get_count_order(num_threads_sharing); - l3_id = c->apicid & ~((1 << index_msb) - 1); + l3_id = c->topo.apicid & ~((1 << index_msb) - 1); break; default: break; @@ -915,7 +915,7 @@ static int __cache_amd_cpumap_setup(unsi unsigned int apicid, nshared, first, last; nshared = base->eax.split.num_threads_sharing + 1; - apicid = cpu_data(cpu).apicid; + apicid = cpu_data(cpu).topo.apicid; first = apicid - (apicid % nshared); last = first + nshared - 1; @@ -924,14 +924,14 @@ static int __cache_amd_cpumap_setup(unsi if (!this_cpu_ci->info_list) continue; - apicid = cpu_data(i).apicid; + apicid = cpu_data(i).topo.apicid; if ((apicid < first) || (apicid > last)) continue; this_leaf = this_cpu_ci->info_list + index; for_each_online_cpu(sibling) { - apicid = cpu_data(sibling).apicid; + apicid = cpu_data(sibling).topo.apicid; if ((apicid < first) || (apicid > last)) continue; cpumask_set_cpu(sibling, @@ -969,7 +969,7 @@ static void __cache_cpumap_setup(unsigne index_msb = get_count_order(num_threads_sharing); for_each_online_cpu(i) - if (cpu_data(i).apicid >> index_msb == c->apicid >> index_msb) { + if (cpu_data(i).topo.apicid >> index_msb == c->topo.apicid >> index_msb) { struct cpu_cacheinfo *sib_cpu_ci = get_cpu_cacheinfo(i); if (i == cpu || !sib_cpu_ci->info_list) @@ -1024,7 +1024,7 @@ static void get_cache_id(int cpu, struct num_threads_sharing = 1 + id4_regs->eax.split.num_threads_sharing; index_msb = get_count_order(num_threads_sharing); - id4_regs->id = c->apicid >> index_msb; + id4_regs->id = c->topo.apicid >> index_msb; } int populate_cache_leaves(unsigned int cpu) --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -899,7 +899,7 @@ void detect_ht(struct cpuinfo_x86 *c) return; index_msb = get_count_order(smp_num_siblings); - c->phys_proc_id = apic->phys_pkg_id(c->initial_apicid, index_msb); + c->phys_proc_id = apic->phys_pkg_id(c->topo.initial_apicid, index_msb); smp_num_siblings = smp_num_siblings / c->x86_max_cores; @@ -907,7 +907,7 @@ void detect_ht(struct cpuinfo_x86 *c) core_bits = get_count_order(c->x86_max_cores); - c->cpu_core_id = apic->phys_pkg_id(c->initial_apicid, index_msb) & + c->cpu_core_id = apic->phys_pkg_id(c->topo.initial_apicid, index_msb) & ((1 << core_bits) - 1); #endif } @@ -1721,15 +1721,15 @@ static void generic_identify(struct cpui get_cpu_address_sizes(c); if (c->cpuid_level >= 0x00000001) { - c->initial_apicid = (cpuid_ebx(1) >> 24) & 0xFF; + c->topo.initial_apicid = (cpuid_ebx(1) >> 24) & 0xFF; #ifdef CONFIG_X86_32 # ifdef CONFIG_SMP - c->apicid = apic->phys_pkg_id(c->initial_apicid, 0); + c->topo.apicid = apic->phys_pkg_id(c->topo.initial_apicid, 0); # else - c->apicid = c->initial_apicid; + c->topo.apicid = c->topo.initial_apicid; # endif #endif - c->phys_proc_id = c->initial_apicid; + c->phys_proc_id = c->topo.initial_apicid; } get_model_name(c); /* Default name */ @@ -1763,9 +1763,9 @@ static void validate_apic_and_package_id apicid = apic->cpu_present_to_apicid(cpu); - if (apicid != c->apicid) { + if (apicid != c->topo.apicid) { pr_err(FW_BUG "CPU%u: APIC id mismatch. Firmware: %x APIC: %x\n", - cpu, apicid, c->initial_apicid); + cpu, apicid, c->topo.initial_apicid); } BUG_ON(topology_update_package_map(c->phys_proc_id, cpu)); BUG_ON(topology_update_die_map(c->cpu_die_id, cpu)); @@ -1815,7 +1815,7 @@ static void identify_cpu(struct cpuinfo_ apply_forced_caps(c); #ifdef CONFIG_X86_64 - c->apicid = apic->phys_pkg_id(c->initial_apicid, 0); + c->topo.apicid = apic->phys_pkg_id(c->topo.initial_apicid, 0); #endif /* --- a/arch/x86/kernel/cpu/hygon.c +++ b/arch/x86/kernel/cpu/hygon.c @@ -88,7 +88,7 @@ static void hygon_get_topology(struct cp c->x86_coreid_bits = get_count_order(c->x86_max_cores); /* Socket ID is ApicId[6] for these processors. */ - c->phys_proc_id = c->apicid >> APICID_SOCKET_ID_BIT; + c->phys_proc_id = c->topo.apicid >> APICID_SOCKET_ID_BIT; cacheinfo_hygon_init_llc_id(c, cpu); } else if (cpu_has(c, X86_FEATURE_NODEID_MSR)) { @@ -116,9 +116,9 @@ static void hygon_detect_cmp(struct cpui bits = c->x86_coreid_bits; /* Low order bits define the core id (index of core in socket) */ - c->cpu_core_id = c->initial_apicid & ((1 << bits)-1); + c->cpu_core_id = c->topo.initial_apicid & ((1 << bits)-1); /* Convert the initial APIC ID into the socket ID */ - c->phys_proc_id = c->initial_apicid >> bits; + c->phys_proc_id = c->topo.initial_apicid >> bits; /* use socket ID also for last level cache */ per_cpu(cpu_llc_id, cpu) = c->cpu_die_id = c->phys_proc_id; } @@ -128,7 +128,7 @@ static void srat_detect_node(struct cpui #ifdef CONFIG_NUMA int cpu = smp_processor_id(); int node; - unsigned int apicid = c->apicid; + unsigned int apicid = c->topo.apicid; node = numa_cpu_node(cpu); if (node == NUMA_NO_NODE) @@ -161,7 +161,7 @@ static void srat_detect_node(struct cpui * through CPU mapping may alter the outcome, directly * access __apicid_to_node[]. */ - int ht_nodeid = c->initial_apicid; + int ht_nodeid = c->topo.initial_apicid; if (__apicid_to_node[ht_nodeid] != NUMA_NO_NODE) node = __apicid_to_node[ht_nodeid]; @@ -301,7 +301,7 @@ static void init_hygon(struct cpuinfo_x8 set_cpu_cap(c, X86_FEATURE_REP_GOOD); /* get apicid instead of initial apic id from cpuid */ - c->apicid = read_apic_id(); + c->topo.apicid = read_apic_id(); /* * XXX someone from Hygon needs to confirm this DTRT --- a/arch/x86/kernel/cpu/mce/apei.c +++ b/arch/x86/kernel/cpu/mce/apei.c @@ -103,7 +103,7 @@ int apei_smca_report_x86_error(struct cp m.socketid = -1; for_each_possible_cpu(cpu) { - if (cpu_data(cpu).initial_apicid == lapic_id) { + if (cpu_data(cpu).topo.initial_apicid == lapic_id) { m.extcpu = cpu; m.socketid = cpu_data(m.extcpu).phys_proc_id; break; --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -124,7 +124,7 @@ void mce_setup(struct mce *m) m->cpuvendor = boot_cpu_data.x86_vendor; m->cpuid = cpuid_eax(1); m->socketid = cpu_data(m->extcpu).phys_proc_id; - m->apicid = cpu_data(m->extcpu).initial_apicid; + m->apicid = cpu_data(m->extcpu).topo.initial_apicid; m->mcgcap = __rdmsr(MSR_IA32_MCG_CAP); m->ppin = cpu_data(m->extcpu).ppin; m->microcode = boot_cpu_data.microcode; --- a/arch/x86/kernel/cpu/proc.c +++ b/arch/x86/kernel/cpu/proc.c @@ -23,8 +23,8 @@ static void show_cpuinfo_core(struct seq cpumask_weight(topology_core_cpumask(cpu))); seq_printf(m, "core id\t\t: %d\n", c->cpu_core_id); seq_printf(m, "cpu cores\t: %d\n", c->booted_cores); - seq_printf(m, "apicid\t\t: %d\n", c->apicid); - seq_printf(m, "initial apicid\t: %d\n", c->initial_apicid); + seq_printf(m, "apicid\t\t: %d\n", c->topo.apicid); + seq_printf(m, "initial apicid\t: %d\n", c->topo.initial_apicid); #endif } --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -78,7 +78,7 @@ int detect_extended_topology_early(struc /* * initial apic id, which also represents 32-bit extended x2apic id. */ - c->initial_apicid = edx; + c->topo.initial_apicid = edx; smp_num_siblings = max_t(int, smp_num_siblings, LEVEL_MAX_SIBLINGS(ebx)); #endif return 0; @@ -108,7 +108,7 @@ int detect_extended_topology(struct cpui * Populate HT related information from sub-leaf level 0. */ cpuid_count(leaf, SMT_LEVEL, &eax, &ebx, &ecx, &edx); - c->initial_apicid = edx; + c->topo.initial_apicid = edx; core_level_siblings = LEVEL_MAX_SIBLINGS(ebx); smp_num_siblings = max_t(int, smp_num_siblings, LEVEL_MAX_SIBLINGS(ebx)); core_plus_mask_width = ht_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); @@ -146,20 +146,20 @@ int detect_extended_topology(struct cpui die_select_mask = (~(-1 << die_plus_mask_width)) >> core_plus_mask_width; - c->cpu_core_id = apic->phys_pkg_id(c->initial_apicid, + c->cpu_core_id = apic->phys_pkg_id(c->topo.initial_apicid, ht_mask_width) & core_select_mask; if (die_level_present) { - c->cpu_die_id = apic->phys_pkg_id(c->initial_apicid, + c->cpu_die_id = apic->phys_pkg_id(c->topo.initial_apicid, core_plus_mask_width) & die_select_mask; } - c->phys_proc_id = apic->phys_pkg_id(c->initial_apicid, + c->phys_proc_id = apic->phys_pkg_id(c->topo.initial_apicid, pkg_mask_width); /* * Reinit the apicid, now that we have extended initial_apicid. */ - c->apicid = apic->phys_pkg_id(c->initial_apicid, 0); + c->topo.apicid = apic->phys_pkg_id(c->topo.initial_apicid, 0); c->x86_max_cores = (core_level_siblings / smp_num_siblings); __max_die_per_package = (die_level_siblings / core_level_siblings); --- a/arch/x86/xen/apic.c +++ b/arch/x86/xen/apic.c @@ -118,7 +118,7 @@ static int xen_phys_pkg_id(int initial_a static int xen_cpu_present_to_apicid(int cpu) { if (cpu_present(cpu)) - return cpu_data(cpu).apicid; + return cpu_data(cpu).topo.apicid; else return BAD_APICID; } --- a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c @@ -2255,7 +2255,7 @@ static int kfd_cpumask_to_apic_id(const if (first_cpu_of_numa_node >= nr_cpu_ids) return -1; #ifdef CONFIG_X86_64 - return cpu_data(first_cpu_of_numa_node).apicid; + return cpu_data(first_cpu_of_numa_node).topo.apicid; #else return first_cpu_of_numa_node; #endif --- a/drivers/virt/acrn/hsm.c +++ b/drivers/virt/acrn/hsm.c @@ -447,7 +447,7 @@ static ssize_t remove_cpu_store(struct d if (cpu_online(cpu)) remove_cpu(cpu); - lapicid = cpu_data(cpu).apicid; + lapicid = cpu_data(cpu).topo.apicid; dev_dbg(dev, "Try to remove cpu %lld with lapicid %lld\n", cpu, lapicid); ret = hcall_sos_remove_cpu(lapicid); if (ret < 0) { From patchwork Wed Aug 2 10:21:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129784 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp388611vqx; Wed, 2 Aug 2023 04:37:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlGx8D5aHmOehbwNt+CsnEWZDbd7y9oxdbzhpIM3p/R1ESugaHS3lxokhBsqdS29BEsx9qJE X-Received: by 2002:a05:6a00:2294:b0:687:1923:223 with SMTP id f20-20020a056a00229400b0068719230223mr16730839pfe.33.1690976263444; Wed, 02 Aug 2023 04:37:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690976263; cv=none; d=google.com; s=arc-20160816; b=B/irRzt/5SUDGgAa4RmxIxKLQfWda1YYDNuEofej/COFzPKfQpQ7HK4Zp0mnCDCZeY v1evlgg9oS3JVEPRwhatCxseUVU1zrzZI9uAylO0Ve4RsdcJEN8im/l0Y/o2K3V7kP2W C7M07zHSphw7X3XVMgyAZwRZWU8QKNnDCOPTk9X1p1/Q6gsx1bDXS64XRRb4IK4Ms9Hc PUJtgwZV88XTZ+vIO5lV9TV88K49BlxkdXfTIphDYB0OaRUrNQM2aj0O6aDZfjl53SdY lzc4pC1TjsOfSQOb8YShBLBhL86vdrWmXDEE1KdWKOMOHp9rNpT8fbXmW8hWp2VTLdOe 6X9w== 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=I51FvGvV/xruMOQFpSsZxNsz8mCYiGuaQ5bmqM+I82Y=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=tz+F+IZAfElpCUOFg9xmatyr53mwO9Erqb2AcoBujh7o9xJJScGitAQx2WOeapiYeH fbyNJsovLi1MzZDSxFHjaU/GvgviwcTqt4xkedExooo0YBeVRqdLK2NAwpGD6zlyET4h yEheNO7D9lRPaKLOZsTfJtYWENsJ2kv7hea00recZ37V4zlOiVGfYcXVVQ020xOmC31d iUaYyJ4dKVR/ph/sjsXuNWMaOqvW8R/YriJN7rXkq5rC2XX+NoWAT8ZVudL7kpckkxYL H7dqvftMxY8kNj/tnbgAIgctjPhO/EMDvorSDtB8LumazKNisEMsYibE8vJUOMBwzKxT HtmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=QvYmDKoV; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=bAm4oJCY; 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 cv12-20020a056a0044cc00b0068761c460bdsi1272669pfb.32.2023.08.02.04.37.30; Wed, 02 Aug 2023 04:37:43 -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=QvYmDKoV; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=bAm4oJCY; 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 S233352AbjHBKVY (ORCPT + 99 others); Wed, 2 Aug 2023 06:21:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233316AbjHBKVK (ORCPT ); Wed, 2 Aug 2023 06:21:10 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 310DC26AF for ; Wed, 2 Aug 2023 03:21:06 -0700 (PDT) Message-ID: <20230802101932.933829786@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971664; 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=I51FvGvV/xruMOQFpSsZxNsz8mCYiGuaQ5bmqM+I82Y=; b=QvYmDKoVw6k5/JfXVhMQYp0Q6E15hRhfVYjgHZo3gGJN9ZvcL1FKkKCuOUiM0GoHN2wUpw /I99eeBshxAXJb0I8tSCLSzpQLS8x6mt+Pdk0ns2BeRf7d6AcBg0SOo7To+X8ngQa8Pon5 FRrNbnn1YIc2HZ4tgHDQJ2PupoDXrZJH9kT7F90+59/8FpSzbZRPBemAt5xAWeexkPUnMa DAR5VaKDzKt6KdRwbcZNhRv7oy7lUfnaiJ3D1RMCGFtCgoQRWnuozHmgYJF0m/aSP7Jpzt zNLnwV6yHQyNxr9HPed6y3d4gJbe870NHssD9al9zhw5eUnuwDVV/EFIGh2T+Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971664; 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=I51FvGvV/xruMOQFpSsZxNsz8mCYiGuaQ5bmqM+I82Y=; b=bAm4oJCYPcj27sl9xdiXxiUCXuLspZYAy4zrGFvN2VY3ok6ARYwuDzsPKQy4MwJ7waVRE/ ZM6FJXP/d3CJlpAQ== 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 , Wei Liu Subject: [patch V3 04/40] x86/cpu: Move phys_proc_id into topology info References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:04 +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,URIBL_BLOCKED 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: 1773117126506308082 X-GMAIL-MSGID: 1773117126506308082 Rename it to pkg_id which is the terminology used in the kernel. No functional change. Signed-off-by: Thomas Gleixner --- Documentation/arch/x86/topology.rst | 2 +- arch/x86/include/asm/processor.h | 5 +++-- arch/x86/include/asm/topology.h | 2 +- arch/x86/include/asm/x86_init.h | 2 +- arch/x86/kernel/apic/apic_numachip.c | 2 +- arch/x86/kernel/cpu/amd.c | 4 ++-- arch/x86/kernel/cpu/cacheinfo.c | 4 ++-- arch/x86/kernel/cpu/common.c | 6 +++--- arch/x86/kernel/cpu/hygon.c | 6 +++--- arch/x86/kernel/cpu/mce/apei.c | 2 +- arch/x86/kernel/cpu/mce/core.c | 2 +- arch/x86/kernel/cpu/proc.c | 2 +- arch/x86/kernel/cpu/topology.c | 3 +-- arch/x86/kernel/smpboot.c | 16 ++++++++-------- drivers/scsi/lpfc/lpfc_init.c | 6 +----- 15 files changed, 30 insertions(+), 34 deletions(-) --- a/Documentation/arch/x86/topology.rst +++ b/Documentation/arch/x86/topology.rst @@ -59,7 +59,7 @@ AMD nomenclature for package is 'Node'. The physical ID of the die. This information is retrieved via CPUID. - - cpuinfo_x86.phys_proc_id: + - cpuinfo_x86.topo.pkg_id: The physical ID of the package. This information is retrieved via CPUID and deduced from the APIC IDs of the cores in the package. --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -82,6 +82,9 @@ struct cpuinfo_topology { u32 apicid; // The initial APIC ID provided by CPUID u32 initial_apicid; + + // Physical package ID + u32 pkg_id; }; struct cpuinfo_x86 { @@ -133,8 +136,6 @@ struct cpuinfo_x86 { u16 x86_clflush_size; /* number of cores as seen by the OS: */ u16 booted_cores; - /* Physical processor id: */ - u16 phys_proc_id; /* Logical processor id: */ u16 logical_proc_id; /* Core id: */ --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -106,7 +106,7 @@ extern const struct cpumask *cpu_coregro extern const struct cpumask *cpu_clustergroup_mask(int cpu); #define topology_logical_package_id(cpu) (cpu_data(cpu).logical_proc_id) -#define topology_physical_package_id(cpu) (cpu_data(cpu).phys_proc_id) +#define topology_physical_package_id(cpu) (cpu_data(cpu).topo.pkg_id) #define topology_logical_die_id(cpu) (cpu_data(cpu).logical_die_id) #define topology_die_id(cpu) (cpu_data(cpu).cpu_die_id) #define topology_core_id(cpu) (cpu_data(cpu).cpu_core_id) --- a/arch/x86/include/asm/x86_init.h +++ b/arch/x86/include/asm/x86_init.h @@ -177,7 +177,7 @@ struct x86_init_ops { * struct x86_cpuinit_ops - platform specific cpu hotplug setups * @setup_percpu_clockev: set up the per cpu clock event device * @early_percpu_clock_init: early init of the per cpu clock event device - * @fixup_cpu_id: fixup function for cpuinfo_x86::phys_proc_id + * @fixup_cpu_id: fixup function for cpuinfo_x86::topo.pkg_id * @parallel_bringup: Parallel bringup control */ struct x86_cpuinit_ops { --- a/arch/x86/kernel/apic/apic_numachip.c +++ b/arch/x86/kernel/apic/apic_numachip.c @@ -169,7 +169,7 @@ static void fixup_cpu_id(struct cpuinfo_ nodes = ((val >> 3) & 7) + 1; } - c->phys_proc_id = node / nodes; + c->topo.pkg_id = node / nodes; } static int __init numachip_system_init(void) --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -389,9 +389,9 @@ static void amd_detect_cmp(struct cpuinf /* Low order bits define the core id (index of core in socket) */ c->cpu_core_id = c->topo.initial_apicid & ((1 << bits)-1); /* Convert the initial APIC ID into the socket ID */ - c->phys_proc_id = c->topo.initial_apicid >> bits; + c->topo.pkg_id = c->topo.initial_apicid >> bits; /* use socket ID also for last level cache */ - per_cpu(cpu_llc_id, cpu) = c->cpu_die_id = c->phys_proc_id; + per_cpu(cpu_llc_id, cpu) = c->cpu_die_id = c->topo.pkg_id; } u32 amd_get_nodes_per_socket(void) --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -875,10 +875,10 @@ void init_intel_cacheinfo(struct cpuinfo * turns means that the only possibility is SMT (as indicated in * cpuid1). Since cpuid2 doesn't specify shared caches, and we know * that SMT shares all caches, we can unconditionally set cpu_llc_id to - * c->phys_proc_id. + * c->topo.pkg_id. */ if (per_cpu(cpu_llc_id, cpu) == BAD_APICID) - per_cpu(cpu_llc_id, cpu) = c->phys_proc_id; + per_cpu(cpu_llc_id, cpu) = c->topo.pkg_id; #endif c->x86_cache_size = l3 ? l3 : (l2 ? l2 : (l1i+l1d)); --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -899,7 +899,7 @@ void detect_ht(struct cpuinfo_x86 *c) return; index_msb = get_count_order(smp_num_siblings); - c->phys_proc_id = apic->phys_pkg_id(c->topo.initial_apicid, index_msb); + c->topo.pkg_id = apic->phys_pkg_id(c->topo.initial_apicid, index_msb); smp_num_siblings = smp_num_siblings / c->x86_max_cores; @@ -1729,7 +1729,7 @@ static void generic_identify(struct cpui c->topo.apicid = c->topo.initial_apicid; # endif #endif - c->phys_proc_id = c->topo.initial_apicid; + c->topo.pkg_id = c->topo.initial_apicid; } get_model_name(c); /* Default name */ @@ -1767,7 +1767,7 @@ static void validate_apic_and_package_id pr_err(FW_BUG "CPU%u: APIC id mismatch. Firmware: %x APIC: %x\n", cpu, apicid, c->topo.initial_apicid); } - BUG_ON(topology_update_package_map(c->phys_proc_id, cpu)); + BUG_ON(topology_update_package_map(c->topo.pkg_id, cpu)); BUG_ON(topology_update_die_map(c->cpu_die_id, cpu)); #else c->logical_proc_id = 0; --- a/arch/x86/kernel/cpu/hygon.c +++ b/arch/x86/kernel/cpu/hygon.c @@ -88,7 +88,7 @@ static void hygon_get_topology(struct cp c->x86_coreid_bits = get_count_order(c->x86_max_cores); /* Socket ID is ApicId[6] for these processors. */ - c->phys_proc_id = c->topo.apicid >> APICID_SOCKET_ID_BIT; + c->topo.pkg_id = c->topo.apicid >> APICID_SOCKET_ID_BIT; cacheinfo_hygon_init_llc_id(c, cpu); } else if (cpu_has(c, X86_FEATURE_NODEID_MSR)) { @@ -118,9 +118,9 @@ static void hygon_detect_cmp(struct cpui /* Low order bits define the core id (index of core in socket) */ c->cpu_core_id = c->topo.initial_apicid & ((1 << bits)-1); /* Convert the initial APIC ID into the socket ID */ - c->phys_proc_id = c->topo.initial_apicid >> bits; + c->topo.pkg_id = c->topo.initial_apicid >> bits; /* use socket ID also for last level cache */ - per_cpu(cpu_llc_id, cpu) = c->cpu_die_id = c->phys_proc_id; + per_cpu(cpu_llc_id, cpu) = c->cpu_die_id = c->topo.pkg_id; } static void srat_detect_node(struct cpuinfo_x86 *c) --- a/arch/x86/kernel/cpu/mce/apei.c +++ b/arch/x86/kernel/cpu/mce/apei.c @@ -105,7 +105,7 @@ int apei_smca_report_x86_error(struct cp for_each_possible_cpu(cpu) { if (cpu_data(cpu).topo.initial_apicid == lapic_id) { m.extcpu = cpu; - m.socketid = cpu_data(m.extcpu).phys_proc_id; + m.socketid = cpu_data(m.extcpu).topo.pkg_id; break; } } --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -123,7 +123,7 @@ void mce_setup(struct mce *m) m->time = __ktime_get_real_seconds(); m->cpuvendor = boot_cpu_data.x86_vendor; m->cpuid = cpuid_eax(1); - m->socketid = cpu_data(m->extcpu).phys_proc_id; + m->socketid = cpu_data(m->extcpu).topo.pkg_id; m->apicid = cpu_data(m->extcpu).topo.initial_apicid; m->mcgcap = __rdmsr(MSR_IA32_MCG_CAP); m->ppin = cpu_data(m->extcpu).ppin; --- a/arch/x86/kernel/cpu/proc.c +++ b/arch/x86/kernel/cpu/proc.c @@ -18,7 +18,7 @@ static void show_cpuinfo_core(struct seq unsigned int cpu) { #ifdef CONFIG_SMP - seq_printf(m, "physical id\t: %d\n", c->phys_proc_id); + seq_printf(m, "physical id\t: %d\n", c->topo.pkg_id); seq_printf(m, "siblings\t: %d\n", cpumask_weight(topology_core_cpumask(cpu))); seq_printf(m, "core id\t\t: %d\n", c->cpu_core_id); --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -154,8 +154,7 @@ int detect_extended_topology(struct cpui core_plus_mask_width) & die_select_mask; } - c->phys_proc_id = apic->phys_pkg_id(c->topo.initial_apicid, - pkg_mask_width); + c->topo.pkg_id = apic->phys_pkg_id(c->topo.initial_apicid, pkg_mask_width); /* * Reinit the apicid, now that we have extended initial_apicid. */ --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -347,7 +347,7 @@ int topology_phys_to_logical_pkg(unsigne for_each_possible_cpu(cpu) { struct cpuinfo_x86 *c = &cpu_data(cpu); - if (c->initialized && c->phys_proc_id == phys_pkg) + if (c->initialized && c->topo.pkg_id == phys_pkg) return c->logical_proc_id; } return -1; @@ -363,13 +363,13 @@ EXPORT_SYMBOL(topology_phys_to_logical_p */ static int topology_phys_to_logical_die(unsigned int die_id, unsigned int cur_cpu) { - int cpu, proc_id = cpu_data(cur_cpu).phys_proc_id; + int cpu, proc_id = cpu_data(cur_cpu).topo.pkg_id; for_each_possible_cpu(cpu) { struct cpuinfo_x86 *c = &cpu_data(cpu); if (c->initialized && c->cpu_die_id == die_id && - c->phys_proc_id == proc_id) + c->topo.pkg_id == proc_id) return c->logical_die_id; } return -1; @@ -429,7 +429,7 @@ void __init smp_store_boot_cpu_info(void *c = boot_cpu_data; c->cpu_index = id; - topology_update_package_map(c->phys_proc_id, id); + topology_update_package_map(c->topo.pkg_id, id); topology_update_die_map(c->cpu_die_id, id); c->initialized = true; } @@ -484,7 +484,7 @@ static bool match_smt(struct cpuinfo_x86 if (boot_cpu_has(X86_FEATURE_TOPOEXT)) { int cpu1 = c->cpu_index, cpu2 = o->cpu_index; - if (c->phys_proc_id == o->phys_proc_id && + if (c->topo.pkg_id == o->topo.pkg_id && c->cpu_die_id == o->cpu_die_id && per_cpu(cpu_llc_id, cpu1) == per_cpu(cpu_llc_id, cpu2)) { if (c->cpu_core_id == o->cpu_core_id) @@ -496,7 +496,7 @@ static bool match_smt(struct cpuinfo_x86 return topology_sane(c, o, "smt"); } - } else if (c->phys_proc_id == o->phys_proc_id && + } else if (c->topo.pkg_id == o->topo.pkg_id && c->cpu_die_id == o->cpu_die_id && c->cpu_core_id == o->cpu_core_id) { return topology_sane(c, o, "smt"); @@ -507,7 +507,7 @@ static bool match_smt(struct cpuinfo_x86 static bool match_die(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o) { - if (c->phys_proc_id == o->phys_proc_id && + if (c->topo.pkg_id == o->topo.pkg_id && c->cpu_die_id == o->cpu_die_id) return true; return false; @@ -535,7 +535,7 @@ static bool match_l2c(struct cpuinfo_x86 */ static bool match_pkg(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o) { - if (c->phys_proc_id == o->phys_proc_id) + if (c->topo.pkg_id == o->topo.pkg_id) return true; return false; } --- a/drivers/scsi/lpfc/lpfc_init.c +++ b/drivers/scsi/lpfc/lpfc_init.c @@ -12428,9 +12428,6 @@ lpfc_cpu_affinity_check(struct lpfc_hba int max_core_id, min_core_id; struct lpfc_vector_map_info *cpup; struct lpfc_vector_map_info *new_cpup; -#ifdef CONFIG_X86 - struct cpuinfo_x86 *cpuinfo; -#endif #ifdef CONFIG_SCSI_LPFC_DEBUG_FS struct lpfc_hdwq_stat *c_stat; #endif @@ -12444,8 +12441,7 @@ lpfc_cpu_affinity_check(struct lpfc_hba for_each_present_cpu(cpu) { cpup = &phba->sli4_hba.cpu_map[cpu]; #ifdef CONFIG_X86 - cpuinfo = &cpu_data(cpu); - cpup->phys_id = cpuinfo->phys_proc_id; + cpup->phys_id = topology_physical_package_id(cpu); cpup->core_id = cpuinfo->cpu_core_id; if (lpfc_find_hyper(phba, cpu, cpup->phys_id, cpup->core_id)) cpup->flag |= LPFC_CPU_MAP_HYPER; From patchwork Wed Aug 2 10:21:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129759 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp361526vqx; Wed, 2 Aug 2023 03:46:07 -0700 (PDT) X-Google-Smtp-Source: APBJJlFNO/TbzxffDdsV5LJXCzec9IGx4PO00HG0PZwObHuOEPus3CoOnyHOVjWMheE8YDkF/J01 X-Received: by 2002:a17:907:724f:b0:991:f0dc:c930 with SMTP id ds15-20020a170907724f00b00991f0dcc930mr6885477ejc.16.1690973167571; Wed, 02 Aug 2023 03:46:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690973167; cv=none; d=google.com; s=arc-20160816; b=NULcpfSGqGJFc1csapc8VjzaGoulyPAW+k6vV/EcILo+JUaFojt39amh6deDOBq7qi WhhNBHyiSukyZf6V1rOWNaD5uD6CSO3HxJW+Jb331uo3YkKS/pG3QiH9uRYsTIn+0PGi 9F060HHXyaiY+pfcAn2Mz1PT1eCQvyUtNFTEHWxp7tP1jibwI2mvz1EMoM8YvDseWJ3D 9doIEpbyUhRp4yakcCNngBzMp9dTjKe7B5Xd9naX0g1WR0GBvuqdapl/4HsoZOLhsSoc VlQXMFPojrtwsfv4TqUOeSojE6h24zfvYL7N6DcUR1xmmb3xH6M/pnpRckJ/XoWGlPbH r+fw== 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=bc5Q0JSTqg9+ffQ7s8oKfLAz7DN9aGciy8PBD8PIdfE=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=F8kyFwLBFrO4uKDPoS3oFmrfYQD1vQ0XGI2cF6wetKJt+p+syaqTRN37EpM4UpCHaz 1bXlnGznWqbvIGCTazy+eEvX5y+bqn+Cexe6BLJnH7VyicQBuqb+KAuHYOvN3XBaRPEK hTKaE+no4foTw6UJd1x0awdpzUplWfvigCoGYv+f1YtbOF2VbOL3BCdQdCR7/LR4sFXq 1SjLctRqto23MIMArHe4EhyYNyYTXkcr2VgsoGjXBdD/joEHAvgdkJwjjSnIybdLC2Be 3dBR8ZE/OnByVJXplU2m33oi6skDGJqnIngtvmlEzzUMSAQa5wmg1nIBTXsWJuR4Thmw KIpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Tp1YyY0X; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 q22-20020a17090622d600b0099bbcfbd199si6655988eja.988.2023.08.02.03.45.43; Wed, 02 Aug 2023 03:46:07 -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=Tp1YyY0X; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S233316AbjHBKV2 (ORCPT + 99 others); Wed, 2 Aug 2023 06:21:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230456AbjHBKVN (ORCPT ); Wed, 2 Aug 2023 06:21:13 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0D722137 for ; Wed, 2 Aug 2023 03:21:07 -0700 (PDT) Message-ID: <20230802101932.991285236@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971666; 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=bc5Q0JSTqg9+ffQ7s8oKfLAz7DN9aGciy8PBD8PIdfE=; b=Tp1YyY0XMjMjjKqHa4yp1h48wSwgMQC3N6MrKLRbL8srMbfTpdCdKEkydHHqRbJI5NBbJP tKObadhXYQhs/7qDAaLlU2xVYPoJhri902xfYf2/+BbGdcLLVu02TIDz+lbX+VlrFkZonb 8ZgEx04UmeLjFHb+z5O54ik6uS6Bk/9yfQixBqpL+ziuiNc8SZtsW1tbD8E75KCG9pjy+t Bf++9LCtsay7BxOyCDejeb5AthZq64erbQFUWZF9lkug1lczMF3nVYosdKNtCsuLZ/qmwM U+r8VdYJDXEvndBZdyX/jsl40+LiG+YTIec3/7Odm78Ygh6HrGgMGkP8+eBiOw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971666; 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=bc5Q0JSTqg9+ffQ7s8oKfLAz7DN9aGciy8PBD8PIdfE=; b=LmDAacLSzFA5vvTsOFguLNebBU9Su9ghUiGUVfT3yUjdgTmEzEFLnNYbly2dnJXg1U94DQ af2xauM8Jxj+t3Dw== 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 , Wei Liu Subject: [patch V3 05/40] x86/cpu: Move cpu_die_id into topology info References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:05 +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,URIBL_BLOCKED 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: 1773113880095308810 X-GMAIL-MSGID: 1773113880095308810 Move the next member. No functional change. Signed-off-by: Thomas Gleixner --- Documentation/arch/x86/topology.rst | 4 ++-- arch/x86/include/asm/processor.h | 4 +++- arch/x86/include/asm/topology.h | 2 +- arch/x86/kernel/cpu/amd.c | 8 ++++---- arch/x86/kernel/cpu/cacheinfo.c | 2 +- arch/x86/kernel/cpu/common.c | 2 +- arch/x86/kernel/cpu/hygon.c | 8 ++++---- arch/x86/kernel/cpu/topology.c | 2 +- arch/x86/kernel/smpboot.c | 10 +++++----- 9 files changed, 22 insertions(+), 20 deletions(-) --- a/Documentation/arch/x86/topology.rst +++ b/Documentation/arch/x86/topology.rst @@ -55,7 +55,7 @@ AMD nomenclature for package is 'Node'. The number of dies in a package. This information is retrieved via CPUID. - - cpuinfo_x86.cpu_die_id: + - cpuinfo_x86.topo_die_id: The physical ID of the die. This information is retrieved via CPUID. @@ -65,7 +65,7 @@ AMD nomenclature for package is 'Node'. and deduced from the APIC IDs of the cores in the package. Modern systems use this value for the socket. There may be multiple - packages within a socket. This value may differ from cpu_die_id. + packages within a socket. This value may differ from topo.die_id. - cpuinfo_x86.logical_proc_id: --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -85,6 +85,9 @@ struct cpuinfo_topology { // Physical package ID u32 pkg_id; + + // Physical die ID on AMD, Relative on Intel + u32 die_id; }; struct cpuinfo_x86 { @@ -140,7 +143,6 @@ struct cpuinfo_x86 { u16 logical_proc_id; /* Core id: */ u16 cpu_core_id; - u16 cpu_die_id; u16 logical_die_id; /* Index into per_cpu list: */ u16 cpu_index; --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -108,7 +108,7 @@ extern const struct cpumask *cpu_cluster #define topology_logical_package_id(cpu) (cpu_data(cpu).logical_proc_id) #define topology_physical_package_id(cpu) (cpu_data(cpu).topo.pkg_id) #define topology_logical_die_id(cpu) (cpu_data(cpu).logical_die_id) -#define topology_die_id(cpu) (cpu_data(cpu).cpu_die_id) +#define topology_die_id(cpu) (cpu_data(cpu).topo.die_id) #define topology_core_id(cpu) (cpu_data(cpu).cpu_core_id) #define topology_ppin(cpu) (cpu_data(cpu).ppin) --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -338,7 +338,7 @@ static void amd_get_topology(struct cpui cpuid(0x8000001e, &eax, &ebx, &ecx, &edx); - c->cpu_die_id = ecx & 0xff; + c->topo.die_id = ecx & 0xff; if (c->x86 == 0x15) c->cu_id = ebx & 0xff; @@ -364,9 +364,9 @@ static void amd_get_topology(struct cpui u64 value; rdmsrl(MSR_FAM10H_NODE_ID, value); - c->cpu_die_id = value & 7; + c->topo.die_id = value & 7; - per_cpu(cpu_llc_id, cpu) = c->cpu_die_id; + per_cpu(cpu_llc_id, cpu) = c->topo.die_id; } else return; @@ -391,7 +391,7 @@ static void amd_detect_cmp(struct cpuinf /* Convert the initial APIC ID into the socket ID */ c->topo.pkg_id = c->topo.initial_apicid >> bits; /* use socket ID also for last level cache */ - per_cpu(cpu_llc_id, cpu) = c->cpu_die_id = c->topo.pkg_id; + per_cpu(cpu_llc_id, cpu) = c->topo.die_id = c->topo.pkg_id; } u32 amd_get_nodes_per_socket(void) --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -672,7 +672,7 @@ void cacheinfo_amd_init_llc_id(struct cp if (c->x86 < 0x17) { /* LLC is at the node level. */ - per_cpu(cpu_llc_id, cpu) = c->cpu_die_id; + per_cpu(cpu_llc_id, cpu) = c->topo.die_id; } else if (c->x86 == 0x17 && c->x86_model <= 0x1F) { /* * LLC is at the core complex level. --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1768,7 +1768,7 @@ static void validate_apic_and_package_id cpu, apicid, c->topo.initial_apicid); } BUG_ON(topology_update_package_map(c->topo.pkg_id, cpu)); - BUG_ON(topology_update_die_map(c->cpu_die_id, cpu)); + BUG_ON(topology_update_die_map(c->topo.die_id, cpu)); #else c->logical_proc_id = 0; #endif --- a/arch/x86/kernel/cpu/hygon.c +++ b/arch/x86/kernel/cpu/hygon.c @@ -72,7 +72,7 @@ static void hygon_get_topology(struct cp cpuid(0x8000001e, &eax, &ebx, &ecx, &edx); - c->cpu_die_id = ecx & 0xff; + c->topo.die_id = ecx & 0xff; c->cpu_core_id = ebx & 0xff; @@ -95,9 +95,9 @@ static void hygon_get_topology(struct cp u64 value; rdmsrl(MSR_FAM10H_NODE_ID, value); - c->cpu_die_id = value & 7; + c->topo.die_id = value & 7; - per_cpu(cpu_llc_id, cpu) = c->cpu_die_id; + per_cpu(cpu_llc_id, cpu) = c->topo.die_id; } else return; @@ -120,7 +120,7 @@ static void hygon_detect_cmp(struct cpui /* Convert the initial APIC ID into the socket ID */ c->topo.pkg_id = c->topo.initial_apicid >> bits; /* use socket ID also for last level cache */ - per_cpu(cpu_llc_id, cpu) = c->cpu_die_id = c->topo.pkg_id; + per_cpu(cpu_llc_id, cpu) = c->topo.die_id = c->topo.pkg_id; } static void srat_detect_node(struct cpuinfo_x86 *c) --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -150,7 +150,7 @@ int detect_extended_topology(struct cpui ht_mask_width) & core_select_mask; if (die_level_present) { - c->cpu_die_id = apic->phys_pkg_id(c->topo.initial_apicid, + c->topo.die_id = apic->phys_pkg_id(c->topo.initial_apicid, core_plus_mask_width) & die_select_mask; } --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -368,7 +368,7 @@ static int topology_phys_to_logical_die( for_each_possible_cpu(cpu) { struct cpuinfo_x86 *c = &cpu_data(cpu); - if (c->initialized && c->cpu_die_id == die_id && + if (c->initialized && c->topo.die_id == die_id && c->topo.pkg_id == proc_id) return c->logical_die_id; } @@ -430,7 +430,7 @@ void __init smp_store_boot_cpu_info(void *c = boot_cpu_data; c->cpu_index = id; topology_update_package_map(c->topo.pkg_id, id); - topology_update_die_map(c->cpu_die_id, id); + topology_update_die_map(c->topo.die_id, id); c->initialized = true; } @@ -485,7 +485,7 @@ static bool match_smt(struct cpuinfo_x86 int cpu1 = c->cpu_index, cpu2 = o->cpu_index; if (c->topo.pkg_id == o->topo.pkg_id && - c->cpu_die_id == o->cpu_die_id && + c->topo.die_id == o->topo.die_id && per_cpu(cpu_llc_id, cpu1) == per_cpu(cpu_llc_id, cpu2)) { if (c->cpu_core_id == o->cpu_core_id) return topology_sane(c, o, "smt"); @@ -497,7 +497,7 @@ static bool match_smt(struct cpuinfo_x86 } } else if (c->topo.pkg_id == o->topo.pkg_id && - c->cpu_die_id == o->cpu_die_id && + c->topo.die_id == o->topo.die_id && c->cpu_core_id == o->cpu_core_id) { return topology_sane(c, o, "smt"); } @@ -508,7 +508,7 @@ static bool match_smt(struct cpuinfo_x86 static bool match_die(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o) { if (c->topo.pkg_id == o->topo.pkg_id && - c->cpu_die_id == o->cpu_die_id) + c->topo.die_id == o->topo.die_id) return true; return false; } From patchwork Wed Aug 2 10:21:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129780 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp382745vqx; Wed, 2 Aug 2023 04:27:04 -0700 (PDT) X-Google-Smtp-Source: APBJJlFGBRmoD38kOVB0PEh0ePgZFLj0bTN2CWlPq86JZL6liDOyYZigFZHg2hQjBbKxR+saSUWs X-Received: by 2002:aa7:d414:0:b0:522:2aee:682c with SMTP id z20-20020aa7d414000000b005222aee682cmr4533303edq.2.1690975624209; Wed, 02 Aug 2023 04:27:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690975624; cv=none; d=google.com; s=arc-20160816; b=GK9AKcGtVAm/59CFcaw7Vfoy16O3UDeDLivVZZIbCrlkFX7yJARSPjYhBWoxzUlMKJ tVieRmK+ANVslGudXVzCdjP9OfZ5QPmYCVs8j+UVV+95DH5MNC+wdV3ic8/Kkc515Bl3 PJ6rzKd89FDN7m4BXrPsNYWDOTLk/OQRxfNqL1eAfb7mlI3/iBBtxJ66Ls5XAqgYuBJo pzHP68eC5TBqQgetizGOn1EokvWGGgpfmkaalZbVS7j68E1Z2GYkzQRcCAGyuyMg1aXY 3yJqBZvJpC1KLB2FnXUKqsm+bDNMr/6lJeR8IzjLn51hzU0a/QkrMvP9QUf3R0KuQBEm zT7w== 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=+1QBA7VHZ0Y4GyIw3wTYa2EiSrzVOoXvVDOvnVaT6BY=; fh=9gJBcpdT41PPPDvTiD6XMJBUjtkwfyJvE8vA3pOJn8w=; b=n1x39LZ4Hap/Ffz7bM+HovSo8F70zsADIho3Kri2bTNMMw+wC65qX2zYL57BzcseqK 7DjCYK2vdsihD33U0cipvXE18zJ0YFFQSd60wC8lryU/7dUCVLXCYN7Aih8jpMQ26H1z /W0M5gg6gBr/y63oZ7Dj6g933Dh3l3L3AA7LjAPIkKdCCLmXUBroAUOoGYCynOfiQJlO twlFpPDHn/NVDu4Re8EKzrdaPW0zV9j6I4Q5pTZOdPrfqwqvld4EJ/dve7kjhlZZ2JF1 vMF1YumPVTSFQWjIgJte+MkHmglLnBx/c9DK4S/OyiFC1gnoj9cnNZYBR1Hq2E6c/dJK Pt6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="o23LTXt/"; 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 r2-20020aa7cfc2000000b0052245c04c89si1014740edy.164.2023.08.02.04.26.40; Wed, 02 Aug 2023 04:27:04 -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="o23LTXt/"; 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 S233358AbjHBKVb (ORCPT + 99 others); Wed, 2 Aug 2023 06:21:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233191AbjHBKVO (ORCPT ); Wed, 2 Aug 2023 06:21:14 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B3F22685; Wed, 2 Aug 2023 03:21:09 -0700 (PDT) Message-ID: <20230802101933.047746332@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971667; 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=+1QBA7VHZ0Y4GyIw3wTYa2EiSrzVOoXvVDOvnVaT6BY=; b=o23LTXt/iKfOjDUBvrmBvtxEGJNJfGmJ1cM/lvH782Pf+unWosS99etWR4OmllD2ztKJZJ xcKbXrXBGvgrdFCwG2vHRLVapoFFUJPj8doWNbsjJOS5nSg09BuJW0CGViUtef/l1FcdOX BgX1xmmJGw3TR1o0xFtJM8hsddhUgyOgaK9f8uKseyBtIzJWiyaerUfHVTCYVS0ooXpNa9 nHnfXJiUH2vPCKDDMwJMym6VCiXjhE+H2XHUppZivAEKIlIsJyyQAOsRxw2EZ3nVzxSElC +AlBtzrIF6yINo8RiNi3DBTyq7naN+DFZFoP/RLdCOKxoYR4DRXsuTl+22D94g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971667; 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=+1QBA7VHZ0Y4GyIw3wTYa2EiSrzVOoXvVDOvnVaT6BY=; b=6gTSlQoS5p3R70A6Lc7MlXSOgjUe3LsTGCKzSwZpGGmvqqk1CGzDDvhGBbnH/CAcDWSLln HNlWjHVXXN2/S+AQ== 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 , Wei Liu , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org Subject: [patch V3 06/40] scsi: lpfc: Use topology_core_id() References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:07 +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,URIBL_BLOCKED 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: 1773116455920673992 X-GMAIL-MSGID: 1773116455920673992 Use the provided topology helper. Signed-off-by: Thomas Gleixner Cc: "James E.J. Bottomley" Cc: Dick Kennedy Cc: James Smart Cc: "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org --- drivers/scsi/lpfc/lpfc_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/scsi/lpfc/lpfc_init.c +++ b/drivers/scsi/lpfc/lpfc_init.c @@ -12442,7 +12442,7 @@ lpfc_cpu_affinity_check(struct lpfc_hba cpup = &phba->sli4_hba.cpu_map[cpu]; #ifdef CONFIG_X86 cpup->phys_id = topology_physical_package_id(cpu); - cpup->core_id = cpuinfo->cpu_core_id; + cpup->core_id = topology_core_id(cpu); if (lpfc_find_hyper(phba, cpu, cpup->phys_id, cpup->core_id)) cpup->flag |= LPFC_CPU_MAP_HYPER; #else From patchwork Wed Aug 2 10:21:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129778 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp381360vqx; Wed, 2 Aug 2023 04:24:17 -0700 (PDT) X-Google-Smtp-Source: APBJJlEDSrl91K1ZIq0QWL9zAXn9Qeye7w8ANRS9Pa7OtLl2ZeFI478CIGr1C+/uao013gsQEj7v X-Received: by 2002:a17:907:784a:b0:99b:c952:309a with SMTP id lb10-20020a170907784a00b0099bc952309amr4689099ejc.39.1690975457161; Wed, 02 Aug 2023 04:24:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690975457; cv=none; d=google.com; s=arc-20160816; b=h4RWnXE8sZSFcI7V2xeFFjBD/ww64CuqkCW2+Fsjm0XBm7ClH2URE6sWN4IoOCD2yc Np0sq/bkJ+thdJWfIY01b8wzC8Vz9egF9lPus3CL6rJUvszMpnsvdy/55oa8X45a4dnH RLzaF1DVqFs9i2FoyzVFdixws7NkzKceZZNM/kojBB1F2fRaZNb6fTF0SQTBfwBQuxIN D9el+eHlJZJz1+bbtO5WymsxmwsQ34Oo1iAJJQjYb13V8d3Z8x5HbSnMy4mmrbts+3wa 9IEPmQHJRXghYlRtdHuKo7QFkn/9on8SH5TJdDEg04iI+fgZl/giQwyc3oINGx06xH5y e+Qw== 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=W37gGs0lCrcES4uNg1Zl0+g2c0hE6iWg5mZxC7Tosgc=; fh=MnN2MnOA8nDLSq9u+W1PRucOA//pCn2JLDh027elLCk=; b=uU5fuR9FYBfP44R42RN6hfyR+mxXWW4E5pj7EFSe4LHBfMHT4a4lnsTOxsqRFq8/Rg gsM1Emd82Fna6WNxQ8IOLBbfLxN7uzk4eyBhO0RydSlOG/DPHsb2NZQnQn+l/hhxcOKl IO8WV6tOfY4hcpJnRWaqkEs9tuxCYIGBnFoJto0qN0s+MFG8vqnm+KeSsj42r0MxcQul Yy+k4yS2ftlfdow2urd9gdBegLR/yoWMkBg7hKHgW4hlJWLIhiJGokYhJD18P1JZEp76 9lBmwYbNxmEKUiWRwomBtSnRf2VMDhCQr9E8lIDvb8mMhD5nJYVeIPhZ3cVjb3CBjstp kX6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=F+C9H0Dt; 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 b27-20020a170906151b00b0099c518e9e51si131508ejd.127.2023.08.02.04.23.52; Wed, 02 Aug 2023 04:24:17 -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=F+C9H0Dt; 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 S233821AbjHBKVt (ORCPT + 99 others); Wed, 2 Aug 2023 06:21:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232728AbjHBKVR (ORCPT ); Wed, 2 Aug 2023 06:21:17 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33C8A2720; Wed, 2 Aug 2023 03:21:10 -0700 (PDT) Message-ID: <20230802101933.104722355@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971669; 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=W37gGs0lCrcES4uNg1Zl0+g2c0hE6iWg5mZxC7Tosgc=; b=F+C9H0DtgncTnkKKBoGxFVPsR6sHb0qwuu7W+vof+Q/fWU0keEEA+c/rOi4bZSuoDiaiXP oYt/1oPQsa8rXyPAUwBncl1m7T/6ut3RVLIuIxsC2nMsxHJdLdMpz9SCzWoBW9I4rJrjt2 BoBpbBoBA0LSCLnAY+5EX6gNiTiK62C7Drb7EQV+gqf+XYzYr73P6OD1OpTDAygwQBX4cd BFxZi2MYFacfwyZuB3UynU1qPO14p72U2rUpWDBwOL5advuWSVgXeIiBt79x23CEHVDjBD xdjcA6e7bNRdpjwDfHuSacW44OECgcf35t5mYoDfv1Coh3aMgGVSFKYVUm8rKg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971669; 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=W37gGs0lCrcES4uNg1Zl0+g2c0hE6iWg5mZxC7Tosgc=; b=aR/ClK7pK4d9Nw2NUuBu457SIW7LhYP+u61EVLZ0/hmwVXpsc9Nc7pYCjXgLciQPL8W47x UEnwG0GlNyzhmhBA== 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 , Wei Liu , Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare Subject: [patch V3 07/40] hwmon: (fam15h_power) Use topology_core_id() References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:08 +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,URIBL_BLOCKED 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: 1773116280861686836 X-GMAIL-MSGID: 1773116280861686836 Use the provided topology helper function instead of fiddling in cpu_data. Signed-off-by: Thomas Gleixner Acked-by: Guenter Roeck Cc: linux-hwmon@vger.kernel.org Cc: Jean Delvare Cc: Huang Rui --- drivers/hwmon/fam15h_power.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) --- a/drivers/hwmon/fam15h_power.c +++ b/drivers/hwmon/fam15h_power.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -134,15 +135,13 @@ static DEVICE_ATTR_RO(power1_crit); static void do_read_registers_on_cu(void *_data) { struct fam15h_power_data *data = _data; - int cpu, cu; - - cpu = smp_processor_id(); + int cu; /* * With the new x86 topology modelling, cpu core id actually * is compute unit id. */ - cu = cpu_data(cpu).cpu_core_id; + cu = topology_core_id(smp_processor_id()); rdmsrl_safe(MSR_F15H_CU_PWR_ACCUMULATOR, &data->cu_acc_power[cu]); rdmsrl_safe(MSR_F15H_PTSC, &data->cpu_sw_pwr_ptsc[cu]); From patchwork Wed Aug 2 10:21:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129776 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp381236vqx; Wed, 2 Aug 2023 04:24:03 -0700 (PDT) X-Google-Smtp-Source: APBJJlEVqplEpTyevDFtCyTwQJStYh4fa0SMjtL8UBbQpGbgZA1uTOhYR5sFVjCSDL/lG2Y7h+Vl X-Received: by 2002:aa7:d1d0:0:b0:51d:9ddf:f0f3 with SMTP id g16-20020aa7d1d0000000b0051d9ddff0f3mr4525045edp.31.1690975443200; Wed, 02 Aug 2023 04:24:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690975443; cv=none; d=google.com; s=arc-20160816; b=uZZx0Xlr9pbLrG/XLQeoIYSasLDSdS5IoMjyD7Hf/k/OKM5hSVwymVVxn/FRb53AoM HDkF7mfFhTIdh4svrkeog1rhtIIHfhd1U9ipUea28xBmjQOx/nd82HD8ZUnCBtyOO/O7 D4n3bbO4jCK/v/ghBqulvvW+4b3apZIgaM752NQKSptEts5/xHg2eARPUc26Qh9SsXdn XHOU/4mHZk83u96XrqjvJXpodAyCKvCLIOeS2PGE+DjhpCe3h+gTkrxzAqkucad0c2UM Q1wqaQIXsl+/ePQJBon7invy12PfU7n1vnvI2tsBAwThUTSNzytu+dMbIDSS3y2q7hjc OjnA== 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=H/RRg/Ng7gVCWf1JKUraosEsbY2lA8TZJktDOeNxV1s=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=yCRLGZrIa1yaqBsSEBd5cnYoOPldwLN12QpMSMda776GBx90aKihs40s7IxNNPTrNv NTasFt/m5s4jg0i8WfWSM8uNbQjQxxZMm/y4dZimBmLZsctPbYF0SPE5jpbGVRpRGkh3 VJ43a8cGkaD08vN5HS3lvc1rqqvN/rqmSs2W3sXCtGMchej1Fu34KKeR2McBhFtnMeJR TAujYmxjPgRKYVAlwl5ImBnYR9Bksp8sMKxrXZ6W2t6takV+a9T0vW14oKlJTYR/wd4k 2vyPQRqr/JO79pvjPdE5K/bvUpcErjT2cDFP3gFlrb4cjsVpFHDplLCJ+FvJ/29eOWY6 LS7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="TJ/7ZHcO"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 o4-20020aa7c504000000b0051e0cc6d8c2si10462106edq.474.2023.08.02.04.23.35; Wed, 02 Aug 2023 04:24:03 -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="TJ/7ZHcO"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S230489AbjHBKVw (ORCPT + 99 others); Wed, 2 Aug 2023 06:21:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233516AbjHBKVS (ORCPT ); Wed, 2 Aug 2023 06:21:18 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69039272A for ; Wed, 2 Aug 2023 03:21:12 -0700 (PDT) Message-ID: <20230802101933.163405003@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971670; 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=H/RRg/Ng7gVCWf1JKUraosEsbY2lA8TZJktDOeNxV1s=; b=TJ/7ZHcOJFggz3LlpfZbR84BbOJ+23vEoTJLrQ0pJj6Bad+SbDQdQDzyyFENxnkh25tJiJ gZdFgikZ9SAKytBu96q06A/oIc449vqdpphHd7Pd3kGiqwHgQE0hE6bZ8ktkKANRwC6l66 l91c5j7BZUwfFfVhnwOgProJWDtyvNlDtLFZ8laFAa/CiQPiwycZO98TxQflRuVhsOEv9i edqllP4ngIdR3i02YxW4W7VoB5foe4OTaftj9lMpGW/uoLXEmK2rRiMyfwdfkFao49MRvg jfRYn5fC1xxva6TvlrW70SMpMIdRk3mcMEr6p2WGZcZCLZJy4fY+Z7M5eZTxxw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971670; 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=H/RRg/Ng7gVCWf1JKUraosEsbY2lA8TZJktDOeNxV1s=; b=XUh0UjUU+Xcz1r2Wm+ZxALKdd01NqN1Tmln/PQZjplHvxijxoc2W4wXdCI3WRgFdMZ9hZo vRis1BMEHpUV69Cw== 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 , Wei Liu Subject: [patch V3 08/40] x86/cpu: Move cpu_core_id into topology info References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:10 +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,URIBL_BLOCKED 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: 1773116266236686074 X-GMAIL-MSGID: 1773116266236686074 Rename it to core_id and stick it to the other ID fields. No functional change. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/processor.h | 4 +++- arch/x86/include/asm/topology.h | 2 +- arch/x86/kernel/amd_nb.c | 4 ++-- arch/x86/kernel/cpu/amd.c | 8 ++++---- arch/x86/kernel/cpu/common.c | 4 ++-- arch/x86/kernel/cpu/hygon.c | 4 ++-- arch/x86/kernel/cpu/proc.c | 2 +- arch/x86/kernel/cpu/topology.c | 2 +- arch/x86/kernel/smpboot.c | 6 +++--- 9 files changed, 19 insertions(+), 17 deletions(-) --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -88,6 +88,9 @@ struct cpuinfo_topology { // Physical die ID on AMD, Relative on Intel u32 die_id; + + // Core ID relative to the package + u32 core_id; }; struct cpuinfo_x86 { @@ -142,7 +145,6 @@ struct cpuinfo_x86 { /* Logical processor id: */ u16 logical_proc_id; /* Core id: */ - u16 cpu_core_id; u16 logical_die_id; /* Index into per_cpu list: */ u16 cpu_index; --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -109,7 +109,7 @@ extern const struct cpumask *cpu_cluster #define topology_physical_package_id(cpu) (cpu_data(cpu).topo.pkg_id) #define topology_logical_die_id(cpu) (cpu_data(cpu).logical_die_id) #define topology_die_id(cpu) (cpu_data(cpu).topo.die_id) -#define topology_core_id(cpu) (cpu_data(cpu).cpu_core_id) +#define topology_core_id(cpu) (cpu_data(cpu).topo.core_id) #define topology_ppin(cpu) (cpu_data(cpu).ppin) extern unsigned int __max_die_per_package; --- a/arch/x86/kernel/amd_nb.c +++ b/arch/x86/kernel/amd_nb.c @@ -378,7 +378,7 @@ int amd_get_subcaches(int cpu) pci_read_config_dword(link, 0x1d4, &mask); - return (mask >> (4 * cpu_data(cpu).cpu_core_id)) & 0xf; + return (mask >> (4 * cpu_data(cpu).topo.core_id)) & 0xf; } int amd_set_subcaches(int cpu, unsigned long mask) @@ -404,7 +404,7 @@ int amd_set_subcaches(int cpu, unsigned pci_write_config_dword(nb->misc, 0x1b8, reg & ~0x180000); } - cuid = cpu_data(cpu).cpu_core_id; + cuid = cpu_data(cpu).topo.core_id; mask <<= 4 * cuid; mask |= (0xf ^ (1 << cuid)) << 26; --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -306,7 +306,7 @@ static int nearby_node(int apicid) #endif /* - * Fix up cpu_core_id for pre-F17h systems to be in the + * Fix up topo::core_id for pre-F17h systems to be in the * [0 .. cores_per_node - 1] range. Not really needed but * kept so as not to break existing setups. */ @@ -318,7 +318,7 @@ static void legacy_fixup_core_id(struct return; cus_per_node = c->x86_max_cores / nodes_per_socket; - c->cpu_core_id %= cus_per_node; + c->topo.core_id %= cus_per_node; } /* @@ -344,7 +344,7 @@ static void amd_get_topology(struct cpui c->cu_id = ebx & 0xff; if (c->x86 >= 0x17) { - c->cpu_core_id = ebx & 0xff; + c->topo.core_id = ebx & 0xff; if (smp_num_siblings > 1) c->x86_max_cores /= smp_num_siblings; @@ -387,7 +387,7 @@ static void amd_detect_cmp(struct cpuinf bits = c->x86_coreid_bits; /* Low order bits define the core id (index of core in socket) */ - c->cpu_core_id = c->topo.initial_apicid & ((1 << bits)-1); + c->topo.core_id = c->topo.initial_apicid & ((1 << bits)-1); /* Convert the initial APIC ID into the socket ID */ c->topo.pkg_id = c->topo.initial_apicid >> bits; /* use socket ID also for last level cache */ --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -907,8 +907,8 @@ void detect_ht(struct cpuinfo_x86 *c) core_bits = get_count_order(c->x86_max_cores); - c->cpu_core_id = apic->phys_pkg_id(c->topo.initial_apicid, index_msb) & - ((1 << core_bits) - 1); + c->topo.core_id = apic->phys_pkg_id(c->topo.initial_apicid, index_msb) & + ((1 << core_bits) - 1); #endif } --- a/arch/x86/kernel/cpu/hygon.c +++ b/arch/x86/kernel/cpu/hygon.c @@ -74,7 +74,7 @@ static void hygon_get_topology(struct cp c->topo.die_id = ecx & 0xff; - c->cpu_core_id = ebx & 0xff; + c->topo.core_id = ebx & 0xff; if (smp_num_siblings > 1) c->x86_max_cores /= smp_num_siblings; @@ -116,7 +116,7 @@ static void hygon_detect_cmp(struct cpui bits = c->x86_coreid_bits; /* Low order bits define the core id (index of core in socket) */ - c->cpu_core_id = c->topo.initial_apicid & ((1 << bits)-1); + c->topo.core_id = c->topo.initial_apicid & ((1 << bits)-1); /* Convert the initial APIC ID into the socket ID */ c->topo.pkg_id = c->topo.initial_apicid >> bits; /* use socket ID also for last level cache */ --- a/arch/x86/kernel/cpu/proc.c +++ b/arch/x86/kernel/cpu/proc.c @@ -21,7 +21,7 @@ static void show_cpuinfo_core(struct seq seq_printf(m, "physical id\t: %d\n", c->topo.pkg_id); seq_printf(m, "siblings\t: %d\n", cpumask_weight(topology_core_cpumask(cpu))); - seq_printf(m, "core id\t\t: %d\n", c->cpu_core_id); + seq_printf(m, "core id\t\t: %d\n", c->topo.core_id); seq_printf(m, "cpu cores\t: %d\n", c->booted_cores); seq_printf(m, "apicid\t\t: %d\n", c->topo.apicid); seq_printf(m, "initial apicid\t: %d\n", c->topo.initial_apicid); --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -146,7 +146,7 @@ int detect_extended_topology(struct cpui die_select_mask = (~(-1 << die_plus_mask_width)) >> core_plus_mask_width; - c->cpu_core_id = apic->phys_pkg_id(c->topo.initial_apicid, + c->topo.core_id = apic->phys_pkg_id(c->topo.initial_apicid, ht_mask_width) & core_select_mask; if (die_level_present) { --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -487,7 +487,7 @@ static bool match_smt(struct cpuinfo_x86 if (c->topo.pkg_id == o->topo.pkg_id && c->topo.die_id == o->topo.die_id && per_cpu(cpu_llc_id, cpu1) == per_cpu(cpu_llc_id, cpu2)) { - if (c->cpu_core_id == o->cpu_core_id) + if (c->topo.core_id == o->topo.core_id) return topology_sane(c, o, "smt"); if ((c->cu_id != 0xff) && @@ -498,7 +498,7 @@ static bool match_smt(struct cpuinfo_x86 } else if (c->topo.pkg_id == o->topo.pkg_id && c->topo.die_id == o->topo.die_id && - c->cpu_core_id == o->cpu_core_id) { + c->topo.core_id == o->topo.core_id) { return topology_sane(c, o, "smt"); } @@ -1439,7 +1439,7 @@ static void remove_siblinginfo(int cpu) cpumask_clear(topology_sibling_cpumask(cpu)); cpumask_clear(topology_core_cpumask(cpu)); cpumask_clear(topology_die_cpumask(cpu)); - c->cpu_core_id = 0; + c->topo.core_id = 0; c->booted_cores = 0; cpumask_clear_cpu(cpu, cpu_sibling_setup_mask); recompute_smt_state(); From patchwork Wed Aug 2 10:21:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129804 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp410448vqx; Wed, 2 Aug 2023 05:14:46 -0700 (PDT) X-Google-Smtp-Source: APBJJlHO26LVIRuRZFgN7rZgMqiu4910jXiH3CR5dyWOwr9IOPhpxhvfBrBPaxMkNylXbcO3CUGk X-Received: by 2002:a17:90b:603:b0:268:2b38:c9b0 with SMTP id gb3-20020a17090b060300b002682b38c9b0mr13135042pjb.0.1690978486556; Wed, 02 Aug 2023 05:14:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690978486; cv=none; d=google.com; s=arc-20160816; b=QD5n0ljvPo3Pbco1Mm4WPn4InoQ3sdQroGfXMKsE/hp9xqxxc65OMfvf2S9yMGmYyl XA6NSb+nx8AC615dZQ2LY9io/m1RDIUkeH6+8izDsHAwnD9ucl4rNkXfd+CTUSIjiceg lH9zVs7R+o0zF+ZoBnGHuEi94BrdJBOJk0t5SVKMyLZUucDnFs5oYAnt0Gal1MtCtLuA q99CB6NlGmV1Vvda8t9Ez5S8ppUXYTzBVpPqncwErPKWZ25CEfDuCb02Lqr3n9EL/21o 4taRVhySJ7DfGAQ2uNi4UHAEX8q0gvFgsj+VWBUMQEm0PNZIt3WjB54SvZF9Y+Y6tcpj hoSA== 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=WfNPFKAN9GG2GFdyit2jWhoSZIUriu/Y8Ta0CK3Muoc=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=NzJ9F2ttACyDpzZDbXl3uDPrj5D+jCaCAlZHf8Lirfh1TS0YgP1A0M6WeFP5XeNQ4d vN9oGDRTaz3PPZL81EbwrDlIVZ4w87zU2ah0W0iWip6JidLtdUEnm6MeBba7m8VgeDcb hc84Po4RAIYP9VrNf9r5xTVFjmvEtyAlcleCiOblgDDux5uahrkoiLk50cJ3SG50EMXC euAtxvb1CKYsoR3g/g8Dge9VQadjbYRljXD4e/vH3d5cmhdkOGqVvfh8/fo+aFzT3r7d KBqZN31d5MKFBdVr95Kn5TdKaQpzzZK7oFE0pxMGR4GHdOUQXK6WFwnKx7oI8c8FbPKq HrEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=IzjP3wRm; dkim=neutral (no key) header.i=@linutronix.de header.b=Hq6P4Ipe; 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 x9-20020a17090a1f8900b00250ce1755e9si973993pja.14.2023.08.02.05.14.25; Wed, 02 Aug 2023 05:14:46 -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=IzjP3wRm; dkim=neutral (no key) header.i=@linutronix.de header.b=Hq6P4Ipe; 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 S233918AbjHBKV4 (ORCPT + 99 others); Wed, 2 Aug 2023 06:21:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233652AbjHBKVW (ORCPT ); Wed, 2 Aug 2023 06:21:22 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37D4B2690 for ; Wed, 2 Aug 2023 03:21:14 -0700 (PDT) Message-ID: <20230802101933.221483687@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971672; 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=WfNPFKAN9GG2GFdyit2jWhoSZIUriu/Y8Ta0CK3Muoc=; b=IzjP3wRmszXK2hf4LQMcWiAou6gxoPMqSolNZ5BjktBqAP/EAxZqkMJoXQNqh8i1LgDU8j 6/xxQGEyvcDGkq3QkItK0fAfOwVxDJP5Tg4m0cQsmthQhhHBAUs/gXAiSFk8M1wvGHgUSb THcHR7QNkAuhN8EtHUYk5WH9wOICLGXQkG99RfaexRi+xvVW4ubbFJ2h1dAjY7xahGQHfj dsbMxZll1jjyaQec2z94av8eay3D9gra6pUwvQYGRoYFR6iK7rpp5sz568bJ/m+bZ08uLj eVX3u1mKcDRdvE0p3TMiyoeCU9WEvfusyaq8fnvzb/wPDvXX60i4vNnl2lLg+Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971672; 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=WfNPFKAN9GG2GFdyit2jWhoSZIUriu/Y8Ta0CK3Muoc=; b=Hq6P4IpebG0jgbpDPGSdX/GA4v0B94529BGMSaFzFBZ44+JbQ5krNpaxEcKuc+BDx7Ly5E uyPWWtaApZ5rwYBw== 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 , Wei Liu Subject: [patch V3 09/40] x86/cpu: Move cu_id into topology info References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:11 +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,URIBL_BLOCKED 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: 1773119457522008378 X-GMAIL-MSGID: 1773119457522008378 No functional change. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/processor.h | 4 +++- arch/x86/kernel/cpu/amd.c | 2 +- arch/x86/kernel/cpu/common.c | 2 +- arch/x86/kernel/smpboot.c | 6 +++--- 4 files changed, 8 insertions(+), 6 deletions(-) --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -89,6 +89,9 @@ struct cpuinfo_topology { // Physical die ID on AMD, Relative on Intel u32 die_id; + // Compute unit ID - AMD specific + u32 cu_id; + // Core ID relative to the package u32 core_id; }; @@ -109,7 +112,6 @@ struct cpuinfo_x86 { __u8 x86_phys_bits; /* CPUID returned core id bits: */ __u8 x86_coreid_bits; - __u8 cu_id; /* Max extended CPUID function supported: */ __u32 extended_cpuid_level; /* Maximum supported CPUID level, -1=no CPUID: */ --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -341,7 +341,7 @@ static void amd_get_topology(struct cpui c->topo.die_id = ecx & 0xff; if (c->x86 == 0x15) - c->cu_id = ebx & 0xff; + c->topo.cu_id = ebx & 0xff; if (c->x86 >= 0x17) { c->topo.core_id = ebx & 0xff; --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1789,7 +1789,7 @@ static void identify_cpu(struct cpuinfo_ c->x86_model_id[0] = '\0'; /* Unset */ c->x86_max_cores = 1; c->x86_coreid_bits = 0; - c->cu_id = 0xff; + c->topo.cu_id = 0xff; #ifdef CONFIG_X86_64 c->x86_clflush_size = 64; c->x86_phys_bits = 36; --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -490,9 +490,9 @@ static bool match_smt(struct cpuinfo_x86 if (c->topo.core_id == o->topo.core_id) return topology_sane(c, o, "smt"); - if ((c->cu_id != 0xff) && - (o->cu_id != 0xff) && - (c->cu_id == o->cu_id)) + if ((c->topo.cu_id != 0xff) && + (o->topo.cu_id != 0xff) && + (c->topo.cu_id == o->topo.cu_id)) return topology_sane(c, o, "smt"); } From patchwork Wed Aug 2 10:21:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129808 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp412993vqx; Wed, 2 Aug 2023 05:18:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlE2R58vEct6uOemP2ihOK8MsUB9s5jJM7+DAGpQWXC/yPUfy3dQ13YR43J98RTiiM9nqH/B X-Received: by 2002:aa7:d582:0:b0:522:3139:100c with SMTP id r2-20020aa7d582000000b005223139100cmr4568283edq.39.1690978725082; Wed, 02 Aug 2023 05:18:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690978725; cv=none; d=google.com; s=arc-20160816; b=nw/Nf5easRtObsELjnBDmDTlkmm9uUe3gr2xJTSKayjbAXF5hDl84Id6ZdBZ5LmTh9 dY+IpnKYoUhQUUcNSIZ/ZfLS4TpSYFihdfwkh9Fbp6brOLHOQGRKvLeXUES/8KXK7XsH 2WvJsSi6M48kcHnQF04DqCpjtL0awaEVclgJ/WJPk6qi4ge509IyOqmBI15X6pqUFoVN /gbTZtDurwExidbEkFfqYZyGUaO48pw4O0XIaU6OW+8ctxVCaZ/jpgUhD17/cyUn9c0p PiwrhuEHuvvqWCgb/Ny/sxQIHI8YBkoGzHlivqlJmgjiIsiuzVuCLWkL0raZd+GJjKNV oDjQ== 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=yb4tmHWl8yliaQANo7laiWJ0jRDyn2bmk/9yGN0NZ50=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=itph3cha9zTIYqQAnqY/5zu2+XkxKTaRu+KLIQWZ+TQW5c7pzTqusWYVhct+rZU5fj hauDihE8mRwUNrChQHmO4cmTMUsKRBjb180GXQI7q6DVM4NPmgXKTUDPdFPy5QHo90FG xg0DRaymvEubo/KgeSr1zJwJ410b36mEbVnqXAKQNere7zbBUrmh131sA9aSaTTahPLt 1Io3ApPOfe0rTkiOq1hzf+5sXgvwgs+nAYqRPZQpV69Ep1eemWJkLiqf2rawJE5yqezQ 64GCjMlgT9NdapRLrS64pwI0Jv1HY//G9MUMeS2XXBi31TMglDBODfRtMDOiIwM/wxVS +ldg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=lBU8SqV8; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 i25-20020aa7c719000000b005222780b1c4si9936517edq.600.2023.08.02.05.18.19; Wed, 02 Aug 2023 05:18:45 -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=lBU8SqV8; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S233934AbjHBKWB (ORCPT + 99 others); Wed, 2 Aug 2023 06:22:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233357AbjHBKVa (ORCPT ); Wed, 2 Aug 2023 06:21:30 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC50B2D5B for ; Wed, 2 Aug 2023 03:21:15 -0700 (PDT) Message-ID: <20230802101933.280890888@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971674; 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=yb4tmHWl8yliaQANo7laiWJ0jRDyn2bmk/9yGN0NZ50=; b=lBU8SqV8FhKxosSvVbig2gXXNB0Q2vTZvpIBUKk9Ek+eEchzRBVHEVc6czc3mCHMzhm8+M hhtu11FRkm+0oxNNv6ZSXOSVE4iip0OvsdhPoGu8QYs28zws9oDxqq6N3Z2a9fX7Ldq8mI pgIeVMn5pMDf4U65vDZ7n1lMAsHu68owvA7LgBsf1H41WiqwSyOvnLQB4cTPUP4cOsAe67 estRZQnBvvHV3GY82Y87GFlX2t80MEXsEkFhmn1lJz2PyeJ1J0UHCQNKEX4ajUEm8V80RR op5yI5/21cKG2au/JZwCbUMRYRpENyRF9+1i7uFt4IriUBWAHR7IvorToMGvNg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971674; 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=yb4tmHWl8yliaQANo7laiWJ0jRDyn2bmk/9yGN0NZ50=; b=/5svq9QWeZmmXy+t7I4tr1zNmrs9Q+ESc8AmdtY8RD4UXuK34fkNWN5Al7dy459Q2RpK81 HxN3jTLKRlVpuVCA== 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 , Wei Liu Subject: [patch V3 10/40] x86/cpu: Remove pointless evaluation of x86_coreid_bits References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:13 +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,URIBL_BLOCKED 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: 1773119707455880896 X-GMAIL-MSGID: 1773119707455880896 cpuinfo_x86::x86_coreid_bits is only used by the AMD numa topology code. No point in evaluating it on non AMD systems. No functional change. Signed-off-by: Thomas Gleixner Reviewed-by: Arjan van de Ven --- arch/x86/kernel/cpu/intel.c | 13 ------------- arch/x86/kernel/cpu/zhaoxin.c | 14 -------------- 2 files changed, 27 deletions(-) --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -488,19 +488,6 @@ static void early_init_intel(struct cpui setup_clear_cpu_cap(X86_FEATURE_PGE); } - if (c->cpuid_level >= 0x00000001) { - u32 eax, ebx, ecx, edx; - - cpuid(0x00000001, &eax, &ebx, &ecx, &edx); - /* - * If HTT (EDX[28]) is set EBX[16:23] contain the number of - * apicids which are reserved per package. Store the resulting - * shift value for the package management code. - */ - if (edx & (1U << 28)) - c->x86_coreid_bits = get_count_order((ebx >> 16) & 0xff); - } - check_memory_type_self_snoop_errata(c); /* --- a/arch/x86/kernel/cpu/zhaoxin.c +++ b/arch/x86/kernel/cpu/zhaoxin.c @@ -65,20 +65,6 @@ static void early_init_zhaoxin(struct cp set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC); set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC); } - - if (c->cpuid_level >= 0x00000001) { - u32 eax, ebx, ecx, edx; - - cpuid(0x00000001, &eax, &ebx, &ecx, &edx); - /* - * If HTT (EDX[28]) is set EBX[16:23] contain the number of - * apicids which are reserved per package. Store the resulting - * shift value for the package management code. - */ - if (edx & (1U << 28)) - c->x86_coreid_bits = get_count_order((ebx >> 16) & 0xff); - } - } static void init_zhaoxin(struct cpuinfo_x86 *c) From patchwork Wed Aug 2 10:21:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129790 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp397462vqx; Wed, 2 Aug 2023 04:55:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlFaA3FxQVjPBNQLqzD1XYSbcRDL/3B6PjsF12XrzunZf23xxu7TkX4SqsvN+x72Jtzm5A44 X-Received: by 2002:aa7:d1d1:0:b0:520:f5dd:3335 with SMTP id g17-20020aa7d1d1000000b00520f5dd3335mr4439436edp.41.1690977314536; Wed, 02 Aug 2023 04:55:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690977314; cv=none; d=google.com; s=arc-20160816; b=JL3XtggNQ8sgKrsfGKxdttvzDlHKI0F0MePRPf/RxRX6jubpzlWLjABLx9XsFSzb/i aIfZaoDlS0sMnFneqXp5QCCAIOFnFEo2NwZTdUUjnv7BlmzFcvcpUD0C+jznHRKkdePd +ckLwo6K2oB5yvVe9VKpDXDldnL66vKWjSDNs2pyK7HR8MRD0q9ij0ipDzEDYamq45pn sYeOEBlDCDRjB0ckNYwyoo75aAWRkCTj+zYke7o8Me/Yn7T8VC2ALndz+epbTL2RR1Bm m2oQTcY5iigMVvI4toTap/bpQdl4i0eWbgPe5QzdYQISDnurVkDUK2Y9mHiBa6HOoGWN sKEg== 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=2RANHxmSCQq3gd8prDSNXS5TE/ZWoRk9LvjezfySwEw=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=KrCZaSV61Y6szt86u/hiRist4dkP+vZtgEgWFXPaYjGkVO7FU4PaHcrzxnYRREibUd i4KJEpHj1Ee6YHJs3awNFnjezEKn+kLhxSmUbdM/QnG0U12sh4CjM1/GnTLcbeFCSdhp AMXo1op5JhK6t/Rps4QE+nzf29zNad1hrKTByBb4d7aYZoQpsOkXd853ee16n4J7SwZy LbAiXYdPUHcMk0aAlCKBGrQ2Gcw0+0zh1+HBrqrJFTP4FLf8MQ965EV/37+YcEiXqcFN O3r7IeffEI8smEH6kuP8mqOLsXKPi/9n9gDym0WCrh68yrVhF7sHJTl0aDxYc7UxTUFU csew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=g7HOQDFN; dkim=neutral (no key) header.i=@linutronix.de header.b=+EzvJ0bf; 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 b10-20020aa7df8a000000b005228264a70asi1510075edy.43.2023.08.02.04.54.50; Wed, 02 Aug 2023 04:55:14 -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=g7HOQDFN; dkim=neutral (no key) header.i=@linutronix.de header.b=+EzvJ0bf; 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 S232779AbjHBKWN (ORCPT + 99 others); Wed, 2 Aug 2023 06:22:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233834AbjHBKVt (ORCPT ); Wed, 2 Aug 2023 06:21:49 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AC732D71 for ; Wed, 2 Aug 2023 03:21:17 -0700 (PDT) Message-ID: <20230802101933.339179807@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971675; 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=2RANHxmSCQq3gd8prDSNXS5TE/ZWoRk9LvjezfySwEw=; b=g7HOQDFNQt9uVSg3NUYy4wrHHlDJXps4lztAMLeB0Knh5vfM+Dk2mK/YE/LN+XB9UOy5Do oQDIxrxwl5kYvOybYD2Fp+fjR09T60uuzy82wSsRgapbaHSytGeNJE4vWl8YASLoVUtXWd 7KhTubo+bVa/NQ4Pf5XH06xUHQErQ9BcShLzs9nyuChyhW9nJprme7ryeIz9ZpP/etH19r k9vLrNYjTyatIrlpXq4nNzi2qRm81YKLZR1vUwv1vMIvD76jBYIRzmSfdwYaw5Q0cvCU+o wGdcHZilnQ/GHNPGbOTS/PTT5AKzfSa7dpu0+FHbkGdRSeyjHonsu9SuvQl83w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971675; 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=2RANHxmSCQq3gd8prDSNXS5TE/ZWoRk9LvjezfySwEw=; b=+EzvJ0bfOjrvrad2Ul5NKUd5SDErYnJKiVskoAMRV2SqsVBX78qy3vzxT7hez/EBc2Qref shMpCcF2sRm21xBg== 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 , Wei Liu Subject: [patch V3 11/40] x86/cpu: Move logical package and die IDs into topology info References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:15 +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,URIBL_BLOCKED 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: 1773118228424915104 X-GMAIL-MSGID: 1773118228424915104 Yet another topology related data pair. Rename logical_proc_id to logical_pkg_id so it fits the common naming conventions. No functional change. Signed-off-by: Thomas Gleixner --- Documentation/arch/x86/topology.rst | 2 +- arch/x86/events/intel/uncore.c | 2 +- arch/x86/include/asm/processor.h | 8 ++++---- arch/x86/include/asm/topology.h | 4 ++-- arch/x86/kernel/cpu/common.c | 2 +- arch/x86/kernel/smpboot.c | 8 ++++---- 6 files changed, 13 insertions(+), 13 deletions(-) --- a/Documentation/arch/x86/topology.rst +++ b/Documentation/arch/x86/topology.rst @@ -67,7 +67,7 @@ AMD nomenclature for package is 'Node'. Modern systems use this value for the socket. There may be multiple packages within a socket. This value may differ from topo.die_id. - - cpuinfo_x86.logical_proc_id: + - cpuinfo_x86.topo.logical_pkg_id: The logical ID of the package. As we do not trust BIOSes to enumerate the packages in a consistent way, we introduced the concept of logical package --- a/arch/x86/events/intel/uncore.c +++ b/arch/x86/events/intel/uncore.c @@ -74,7 +74,7 @@ int uncore_device_to_die(struct pci_dev struct cpuinfo_x86 *c = &cpu_data(cpu); if (c->initialized && cpu_to_node(cpu) == node) - return c->logical_die_id; + return c->topo.logical_die_id; } return -1; --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -94,6 +94,10 @@ struct cpuinfo_topology { // Core ID relative to the package u32 core_id; + + // Logical ID mappings + u32 logical_pkg_id; + u32 logical_die_id; }; struct cpuinfo_x86 { @@ -144,10 +148,6 @@ struct cpuinfo_x86 { u16 x86_clflush_size; /* number of cores as seen by the OS: */ u16 booted_cores; - /* Logical processor id: */ - u16 logical_proc_id; - /* Core id: */ - u16 logical_die_id; /* Index into per_cpu list: */ u16 cpu_index; /* Is SMT active on this core? */ --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -105,9 +105,9 @@ static inline void setup_node_to_cpumask extern const struct cpumask *cpu_coregroup_mask(int cpu); extern const struct cpumask *cpu_clustergroup_mask(int cpu); -#define topology_logical_package_id(cpu) (cpu_data(cpu).logical_proc_id) +#define topology_logical_package_id(cpu) (cpu_data(cpu).topo.logical_pkg_id) #define topology_physical_package_id(cpu) (cpu_data(cpu).topo.pkg_id) -#define topology_logical_die_id(cpu) (cpu_data(cpu).logical_die_id) +#define topology_logical_die_id(cpu) (cpu_data(cpu).topo.logical_die_id) #define topology_die_id(cpu) (cpu_data(cpu).topo.die_id) #define topology_core_id(cpu) (cpu_data(cpu).topo.core_id) #define topology_ppin(cpu) (cpu_data(cpu).ppin) --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1770,7 +1770,7 @@ static void validate_apic_and_package_id BUG_ON(topology_update_package_map(c->topo.pkg_id, cpu)); BUG_ON(topology_update_die_map(c->topo.die_id, cpu)); #else - c->logical_proc_id = 0; + c->topo.logical_pkg_id = 0; #endif } --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -348,7 +348,7 @@ int topology_phys_to_logical_pkg(unsigne struct cpuinfo_x86 *c = &cpu_data(cpu); if (c->initialized && c->topo.pkg_id == phys_pkg) - return c->logical_proc_id; + return c->topo.logical_pkg_id; } return -1; } @@ -370,7 +370,7 @@ static int topology_phys_to_logical_die( if (c->initialized && c->topo.die_id == die_id && c->topo.pkg_id == proc_id) - return c->logical_die_id; + return c->topo.logical_die_id; } return -1; } @@ -395,7 +395,7 @@ int topology_update_package_map(unsigned cpu, pkg, new); } found: - cpu_data(cpu).logical_proc_id = new; + cpu_data(cpu).topo.logical_pkg_id = new; return 0; } /** @@ -418,7 +418,7 @@ int topology_update_die_map(unsigned int cpu, die, new); } found: - cpu_data(cpu).logical_die_id = new; + cpu_data(cpu).topo.logical_die_id = new; return 0; } From patchwork Wed Aug 2 10:21:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129770 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp374800vqx; Wed, 2 Aug 2023 04:11:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlEotQiIFlV26naMShjtVuJTmGEOh0y3o0Sapv7S6hgJRkcMn1D5XkPJZHgv3ACNQXUEBxgO X-Received: by 2002:a17:902:e5c4:b0:1b8:1c4f:4f8e with SMTP id u4-20020a170902e5c400b001b81c4f4f8emr18597901plf.53.1690974699305; Wed, 02 Aug 2023 04:11:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690974699; cv=none; d=google.com; s=arc-20160816; b=fqTQZvwFZp2ebHojpkAfLRVx5vUe2vtHwWMd6Qh7hIID0QyYXQoXWOKjb5l1OQwJXC N80nb0119494HoC49a0cIegvBc7OGiopSAo1RhInlq/G/MWriE2g5bJugz/L7FKA9zks J//uFZLLmy0aZAse+fwv5Y8CwSdsD/IWQ6R4EO2y96mhSah5t0Kncjfs7qE5zyel8mGN hyABLRuFgadB//Zp9Xjzk2plF5MilHqTyKMuEBvHkrWdVOulTYJbAhvRkeZQ4tR+/h+j s8upI1LOs7diigpjkXptcAtpjp64H+LJ05f59C6vHN8YOi6kgPuS5rcZD3DS/qoIy0bu hLPg== 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=Sdr5xS1xYe7IJRnJDBWuWdgsWBvT7LI1gSqmf/rO0OY=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=WAquhIXcV19+VA4MS0sumBxK0m80FafR43Hwtrzts56MBaYc4ZaDfAxhSarognGXqg mQmKH4mFw+tTa5YTJXNNec6ehKyBgoZtrVr7VaNqXOAow1Q/P3N8OJa9FVvJA6Ku9vzS lFDBFv9i+hnlGQB+ujHqmBg+uPnpLS6EpCXOPYmLNDn5hglHYAWp5Q8nd1TeKnx1k7wq IqzDIjJ076/mxbNBdkJzcv52qYLiLk4IUL+8VnJnI9e1ld2T2gL5UL49ROyq9P4YYFiV OgkQIyNlTN0983bjBGF30xLKaKkdoJBcrfWeoxDi8negRufW1UflJmcrQ7DB0mEuSGuI rXiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=cIOX62md; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="L/wQjoGP"; 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 n3-20020a170902e54300b001b811b9d416si11092180plf.578.2023.08.02.04.11.17; Wed, 02 Aug 2023 04:11:39 -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=cIOX62md; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="L/wQjoGP"; 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 S232757AbjHBKWU (ORCPT + 99 others); Wed, 2 Aug 2023 06:22:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233877AbjHBKVv (ORCPT ); Wed, 2 Aug 2023 06:21:51 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 418B22D79 for ; Wed, 2 Aug 2023 03:21:19 -0700 (PDT) Message-ID: <20230802101933.396536545@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971677; 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=Sdr5xS1xYe7IJRnJDBWuWdgsWBvT7LI1gSqmf/rO0OY=; b=cIOX62md1bsRU9rvT7/Aw64TisWbc3jB0mu8iey4tqO7vL3gj5xmrYfADik5Z2XeXcfvTK 2R29D8AxKKJX5Z27kYvjnGKddwX8DQB5XAeS2a82DkVUVooJnAmggccFZ1QJzT/2HhjOeg BDuEEIDMDDuVzclcfTwd+/lqHo7190bc1/GD5xVYgxzXLaC5kAFkvnqln7AkRYq7Jqz0Et zROFl9eTP/XK5fP6XN+mEsNaE402xjT3IB8A8/JSBkCKMrDyZyx/FQ5LZ+eCXrifsNMdVj ZLRj6t6lbYsZK4pkT+YiDssLHyv5ixV0y9DsBPfJnHKw9RzrbWmV744lXyD5WQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971677; 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=Sdr5xS1xYe7IJRnJDBWuWdgsWBvT7LI1gSqmf/rO0OY=; b=L/wQjoGPfAAx41Xedn/d5b1R95YAtRk0z0Zi3lIL/FXxW0mAoaVlcceYDt7u4kfk4Ge+LL NlX3mrizwmVlcuAQ== 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 , Wei Liu Subject: [patch V3 12/40] x86/cpu: Move cpu_l[l2]c_id into topology info References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:16 +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,URIBL_BLOCKED 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: 1773115486113216235 X-GMAIL-MSGID: 1773115486113216235 The topology IDs which identify the LLC and L2 domains clearly belong to the per CPU topology information. Move them into cpuinfo_x86::cpuinfo_topo and get rid of the extra per CPU data and the related exports. This also paves the way to do proper topology evaluation during early boot because it removes the only per CPU dependency for that. No functional change. Signed-off-by: Thomas Gleixner Reviewed-by: Arjan van de Ven --- Documentation/arch/x86/topology.rst | 4 +--- arch/x86/events/amd/uncore.c | 2 +- arch/x86/include/asm/cacheinfo.h | 3 --- arch/x86/include/asm/processor.h | 14 +++++++++++++- arch/x86/include/asm/smp.h | 2 -- arch/x86/include/asm/topology.h | 2 +- arch/x86/kernel/apic/apic_numachip.c | 2 +- arch/x86/kernel/cpu/amd.c | 12 ++++-------- arch/x86/kernel/cpu/cacheinfo.c | 33 ++++++++++++--------------------- arch/x86/kernel/cpu/common.c | 14 ++------------ arch/x86/kernel/cpu/cpu.h | 3 +++ arch/x86/kernel/cpu/hygon.c | 14 +++++--------- arch/x86/kernel/smpboot.c | 10 +++++----- 13 files changed, 48 insertions(+), 67 deletions(-) --- a/Documentation/arch/x86/topology.rst +++ b/Documentation/arch/x86/topology.rst @@ -79,9 +79,7 @@ AMD nomenclature for package is 'Node'. The maximum possible number of packages in the system. Helpful for per package facilities to preallocate per package information. - - cpu_llc_id: - - A per-CPU variable containing: + - cpuinfo_x86.topo.llc_id: - On Intel, the first APIC ID of the list of CPUs sharing the Last Level Cache --- a/arch/x86/events/amd/uncore.c +++ b/arch/x86/events/amd/uncore.c @@ -537,7 +537,7 @@ static int amd_uncore_cpu_starting(unsig if (amd_uncore_llc) { uncore = *per_cpu_ptr(amd_uncore_llc, cpu); - uncore->id = get_llc_id(cpu); + uncore->id = per_cpu_llc_id(cpu); uncore = amd_uncore_find_online_sibling(uncore, amd_uncore_llc); *per_cpu_ptr(amd_uncore_llc, cpu) = uncore; --- a/arch/x86/include/asm/cacheinfo.h +++ b/arch/x86/include/asm/cacheinfo.h @@ -7,9 +7,6 @@ extern unsigned int memory_caching_contr #define CACHE_MTRR 0x01 #define CACHE_PAT 0x02 -void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, int cpu); -void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c, int cpu); - void cache_disable(void); void cache_enable(void); void set_cache_aps_delayed_init(bool val); --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -98,6 +98,10 @@ struct cpuinfo_topology { // Logical ID mappings u32 logical_pkg_id; u32 logical_die_id; + + // Cache level topology IDs + u32 llc_id; + u32 l2c_id; }; struct cpuinfo_x86 { @@ -687,7 +691,15 @@ extern int set_tsc_mode(unsigned int val DECLARE_PER_CPU(u64, msr_misc_features_shadow); -extern u16 get_llc_id(unsigned int cpu); +static inline u16 per_cpu_llc_id(unsigned int cpu) +{ + return per_cpu(cpu_info.topo.llc_id, cpu); +} + +static inline u16 per_cpu_l2c_id(unsigned int cpu) +{ + return per_cpu(cpu_info.topo.l2c_id, cpu); +} #ifdef CONFIG_CPU_SUP_AMD extern u32 amd_get_nodes_per_socket(void); --- a/arch/x86/include/asm/smp.h +++ b/arch/x86/include/asm/smp.h @@ -17,8 +17,6 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_ /* cpus sharing the last level cache: */ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map); DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_l2c_shared_map); -DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id); -DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_l2c_id); DECLARE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_cpu_to_apicid); DECLARE_EARLY_PER_CPU_READ_MOSTLY(u32, x86_cpu_to_acpiid); --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -115,7 +115,7 @@ extern const struct cpumask *cpu_cluster extern unsigned int __max_die_per_package; #ifdef CONFIG_SMP -#define topology_cluster_id(cpu) (per_cpu(cpu_l2c_id, cpu)) +#define topology_cluster_id(cpu) (cpu_data(cpu).topo.l2c_id) #define topology_die_cpumask(cpu) (per_cpu(cpu_die_map, cpu)) #define topology_cluster_cpumask(cpu) (cpu_clustergroup_mask(cpu)) #define topology_core_cpumask(cpu) (per_cpu(cpu_core_map, cpu)) --- a/arch/x86/kernel/apic/apic_numachip.c +++ b/arch/x86/kernel/apic/apic_numachip.c @@ -161,7 +161,7 @@ static void fixup_cpu_id(struct cpuinfo_ u64 val; u32 nodes = 1; - this_cpu_write(cpu_llc_id, node); + c->topo.llc_id = node; /* Account for nodes per socket in multi-core-module processors */ if (boot_cpu_has(X86_FEATURE_NODEID_MSR)) { --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -329,8 +329,6 @@ static void legacy_fixup_core_id(struct */ static void amd_get_topology(struct cpuinfo_x86 *c) { - int cpu = smp_processor_id(); - /* get information required for multi-node processors */ if (boot_cpu_has(X86_FEATURE_TOPOEXT)) { int err; @@ -358,15 +356,14 @@ static void amd_get_topology(struct cpui if (!err) c->x86_coreid_bits = get_count_order(c->x86_max_cores); - cacheinfo_amd_init_llc_id(c, cpu); + cacheinfo_amd_init_llc_id(c); } else if (cpu_has(c, X86_FEATURE_NODEID_MSR)) { u64 value; rdmsrl(MSR_FAM10H_NODE_ID, value); c->topo.die_id = value & 7; - - per_cpu(cpu_llc_id, cpu) = c->topo.die_id; + c->topo.llc_id = c->topo.die_id; } else return; @@ -383,7 +380,6 @@ static void amd_get_topology(struct cpui static void amd_detect_cmp(struct cpuinfo_x86 *c) { unsigned bits; - int cpu = smp_processor_id(); bits = c->x86_coreid_bits; /* Low order bits define the core id (index of core in socket) */ @@ -391,7 +387,7 @@ static void amd_detect_cmp(struct cpuinf /* Convert the initial APIC ID into the socket ID */ c->topo.pkg_id = c->topo.initial_apicid >> bits; /* use socket ID also for last level cache */ - per_cpu(cpu_llc_id, cpu) = c->topo.die_id = c->topo.pkg_id; + c->topo.llc_id = c->topo.die_id = c->topo.pkg_id; } u32 amd_get_nodes_per_socket(void) @@ -409,7 +405,7 @@ static void srat_detect_node(struct cpui node = numa_cpu_node(cpu); if (node == NUMA_NO_NODE) - node = get_llc_id(cpu); + node = per_cpu_llc_id(cpu); /* * On multi-fabric platform (e.g. Numascale NumaChip) a --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -661,7 +661,7 @@ static int find_num_cache_leaves(struct return i; } -void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, int cpu) +void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c) { /* * We may have multiple LLCs if L3 caches exist, so check if we @@ -672,13 +672,13 @@ void cacheinfo_amd_init_llc_id(struct cp if (c->x86 < 0x17) { /* LLC is at the node level. */ - per_cpu(cpu_llc_id, cpu) = c->topo.die_id; + c->topo.llc_id = c->topo.die_id; } else if (c->x86 == 0x17 && c->x86_model <= 0x1F) { /* * LLC is at the core complex level. * Core complex ID is ApicId[3] for these processors. */ - per_cpu(cpu_llc_id, cpu) = c->topo.apicid >> 3; + c->topo.llc_id = c->topo.apicid >> 3; } else { /* * LLC ID is calculated from the number of threads sharing the @@ -694,12 +694,12 @@ void cacheinfo_amd_init_llc_id(struct cp if (num_sharing_cache) { int bits = get_count_order(num_sharing_cache); - per_cpu(cpu_llc_id, cpu) = c->topo.apicid >> bits; + c->topo.llc_id = c->topo.apicid >> bits; } } } -void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c, int cpu) +void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c) { /* * We may have multiple LLCs if L3 caches exist, so check if we @@ -712,7 +712,7 @@ void cacheinfo_hygon_init_llc_id(struct * LLC is at the core complex level. * Core complex ID is ApicId[3] for these processors. */ - per_cpu(cpu_llc_id, cpu) = c->topo.apicid >> 3; + c->topo.llc_id = c->topo.apicid >> 3; } void init_amd_cacheinfo(struct cpuinfo_x86 *c) @@ -740,9 +740,6 @@ void init_intel_cacheinfo(struct cpuinfo unsigned int new_l1d = 0, new_l1i = 0; /* Cache sizes from cpuid(4) */ unsigned int new_l2 = 0, new_l3 = 0, i; /* Cache sizes from cpuid(4) */ unsigned int l2_id = 0, l3_id = 0, num_threads_sharing, index_msb; -#ifdef CONFIG_SMP - unsigned int cpu = c->cpu_index; -#endif if (c->cpuid_level > 3) { static int is_initialized; @@ -856,30 +853,24 @@ void init_intel_cacheinfo(struct cpuinfo if (new_l2) { l2 = new_l2; -#ifdef CONFIG_SMP - per_cpu(cpu_llc_id, cpu) = l2_id; - per_cpu(cpu_l2c_id, cpu) = l2_id; -#endif + c->topo.llc_id = l2_id; + c->topo.l2c_id = l2_id; } if (new_l3) { l3 = new_l3; -#ifdef CONFIG_SMP - per_cpu(cpu_llc_id, cpu) = l3_id; -#endif + c->topo.llc_id = l3_id; } -#ifdef CONFIG_SMP /* - * If cpu_llc_id is not yet set, this means cpuid_level < 4 which in + * If llc_id is not yet set, this means cpuid_level < 4 which in * turns means that the only possibility is SMT (as indicated in * cpuid1). Since cpuid2 doesn't specify shared caches, and we know * that SMT shares all caches, we can unconditionally set cpu_llc_id to * c->topo.pkg_id. */ - if (per_cpu(cpu_llc_id, cpu) == BAD_APICID) - per_cpu(cpu_llc_id, cpu) = c->topo.pkg_id; -#endif + if (c->topo.llc_id == BAD_APICID) + c->topo.llc_id = c->topo.pkg_id; c->x86_cache_size = l3 ? l3 : (l2 ? l2 : (l1i+l1d)); --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -75,18 +75,6 @@ u32 elf_hwcap2 __read_mostly; int smp_num_siblings = 1; EXPORT_SYMBOL(smp_num_siblings); -/* Last level cache ID of each logical CPU */ -DEFINE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id) = BAD_APICID; - -u16 get_llc_id(unsigned int cpu) -{ - return per_cpu(cpu_llc_id, cpu); -} -EXPORT_SYMBOL_GPL(get_llc_id); - -/* L2 cache ID of each logical CPU */ -DEFINE_PER_CPU_READ_MOSTLY(u16, cpu_l2c_id) = BAD_APICID; - static struct ppin_info { int feature; int msr_ppin_ctl; @@ -1790,6 +1778,8 @@ static void identify_cpu(struct cpuinfo_ c->x86_max_cores = 1; c->x86_coreid_bits = 0; c->topo.cu_id = 0xff; + c->topo.llc_id = BAD_APICID; + c->topo.l2c_id = BAD_APICID; #ifdef CONFIG_X86_64 c->x86_clflush_size = 64; c->x86_phys_bits = 36; --- a/arch/x86/kernel/cpu/cpu.h +++ b/arch/x86/kernel/cpu/cpu.h @@ -78,6 +78,9 @@ extern int detect_ht_early(struct cpuinf extern void detect_ht(struct cpuinfo_x86 *c); extern void check_null_seg_clears_base(struct cpuinfo_x86 *c); +void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c); +void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c); + unsigned int aperfmperf_get_khz(int cpu); void cpu_select_mitigations(void); --- a/arch/x86/kernel/cpu/hygon.c +++ b/arch/x86/kernel/cpu/hygon.c @@ -63,8 +63,6 @@ static void hygon_get_topology_early(str */ static void hygon_get_topology(struct cpuinfo_x86 *c) { - int cpu = smp_processor_id(); - /* get information required for multi-node processors */ if (boot_cpu_has(X86_FEATURE_TOPOEXT)) { int err; @@ -90,14 +88,13 @@ static void hygon_get_topology(struct cp /* Socket ID is ApicId[6] for these processors. */ c->topo.pkg_id = c->topo.apicid >> APICID_SOCKET_ID_BIT; - cacheinfo_hygon_init_llc_id(c, cpu); + cacheinfo_hygon_init_llc_id(c); } else if (cpu_has(c, X86_FEATURE_NODEID_MSR)) { u64 value; rdmsrl(MSR_FAM10H_NODE_ID, value); c->topo.die_id = value & 7; - - per_cpu(cpu_llc_id, cpu) = c->topo.die_id; + c->topo.llc_id = c->topo.die_id; } else return; @@ -112,15 +109,14 @@ static void hygon_get_topology(struct cp static void hygon_detect_cmp(struct cpuinfo_x86 *c) { unsigned int bits; - int cpu = smp_processor_id(); bits = c->x86_coreid_bits; /* Low order bits define the core id (index of core in socket) */ c->topo.core_id = c->topo.initial_apicid & ((1 << bits)-1); /* Convert the initial APIC ID into the socket ID */ c->topo.pkg_id = c->topo.initial_apicid >> bits; - /* use socket ID also for last level cache */ - per_cpu(cpu_llc_id, cpu) = c->topo.die_id = c->topo.pkg_id; + /* Use package ID also for last level cache */ + c->topo.llc_id = c->topo.die_id = c->topo.pkg_id; } static void srat_detect_node(struct cpuinfo_x86 *c) @@ -132,7 +128,7 @@ static void srat_detect_node(struct cpui node = numa_cpu_node(cpu); if (node == NUMA_NO_NODE) - node = per_cpu(cpu_llc_id, cpu); + node = c->topo.llc_id; /* * On multi-fabric platform (e.g. Numascale NumaChip) a --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -486,7 +486,7 @@ static bool match_smt(struct cpuinfo_x86 if (c->topo.pkg_id == o->topo.pkg_id && c->topo.die_id == o->topo.die_id && - per_cpu(cpu_llc_id, cpu1) == per_cpu(cpu_llc_id, cpu2)) { + per_cpu_llc_id(cpu1) == per_cpu_llc_id(cpu2)) { if (c->topo.core_id == o->topo.core_id) return topology_sane(c, o, "smt"); @@ -518,11 +518,11 @@ static bool match_l2c(struct cpuinfo_x86 int cpu1 = c->cpu_index, cpu2 = o->cpu_index; /* If the arch didn't set up l2c_id, fall back to SMT */ - if (per_cpu(cpu_l2c_id, cpu1) == BAD_APICID) + if (per_cpu_l2c_id(cpu1) == BAD_APICID) return match_smt(c, o); /* Do not match if L2 cache id does not match: */ - if (per_cpu(cpu_l2c_id, cpu1) != per_cpu(cpu_l2c_id, cpu2)) + if (per_cpu_l2c_id(cpu1) != per_cpu_l2c_id(cpu2)) return false; return topology_sane(c, o, "l2c"); @@ -568,11 +568,11 @@ static bool match_llc(struct cpuinfo_x86 bool intel_snc = id && id->driver_data; /* Do not match if we do not have a valid APICID for cpu: */ - if (per_cpu(cpu_llc_id, cpu1) == BAD_APICID) + if (per_cpu_llc_id(cpu1) == BAD_APICID) return false; /* Do not match if LLC id does not match: */ - if (per_cpu(cpu_llc_id, cpu1) != per_cpu(cpu_llc_id, cpu2)) + if (per_cpu_llc_id(cpu1) != per_cpu_llc_id(cpu2)) return false; /* From patchwork Wed Aug 2 10:21:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129767 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp373358vqx; Wed, 2 Aug 2023 04:09:07 -0700 (PDT) X-Google-Smtp-Source: APBJJlFFvuvBuX0RsBTgBbEUmEtpQfcVUq8ZxSdwO9cnT7n+YBnwLIZARCNYFMv40N2Nuu1YlWsU X-Received: by 2002:a05:6e02:1a2f:b0:349:2c0b:1bdb with SMTP id g15-20020a056e021a2f00b003492c0b1bdbmr7621987ile.29.1690974546852; Wed, 02 Aug 2023 04:09:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690974546; cv=none; d=google.com; s=arc-20160816; b=utxWgN9p2LKWsbVzikjbkV9x3/a+4ri97/rYeu0thZ43yLTbmIILrPOUqzLZfeQfET ZB/WaXizUJZ6T7eTWA9BRwg0xz8QGFYp9XigtA7GgyT0xkwBDDYQXI/aBZ2j4Kg7KkTX QMAVCDXE+uKTFyEppPXLb/AJyS1o19Spn18ijYDHn+zt3DWUIo0N8eX10BGjkkZNCf+5 u3fmDigxTsLL34C3P+FOaWgPI4eiP+5cNV+ruMj0w4k03QxASJwxuh20Xqr7z564swUy 0FEQ+YeGfv4OLrWzuipwiJTqv+mNZMhRUT4a2A9cHQC6RPLO9l/JdY9HV3WbPgXzOoJ2 9VTg== 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=axWsLWrT43omLwQZ83u4QKHGIXaDqvWCJze4cehqf28=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=GDMFNwfBic2l0xMmqbPu/MYgxd8VF4P8UcXwanMaJiYjycPmpU1+mGBsHagyhMrt9F pYEAscnmCfyNbH3EQQ+Qv5RV2/qiMEpomZcdAa9PubO4zvsI77LEBbp2pJ0dsgdXjNBU UfH4AoyB02nv+Zwbn7zvs54qfkCynBfgZL6UpL4C1azKps5KsVwaTmC399v0aD13NeWV p+l+6hQBwkYwKxZcudYx3K8iDsWQTp94nvH9NBOoRvGwamYxLspLKj9U2gdzkQ1QNYAM SaNqkuZbEO5QSAGRGI1u/3Q7aOGbJvIVWhN9AOD9b89hoUrSXD4HWWSAGof/MWiBvGx2 /gUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=WKlvsn7Z; 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 w13-20020a17090a8a0d00b00262e28866d4si1033210pjn.163.2023.08.02.04.08.45; Wed, 02 Aug 2023 04:09:06 -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=WKlvsn7Z; 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 S234073AbjHBKWR (ORCPT + 99 others); Wed, 2 Aug 2023 06:22:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232356AbjHBKVv (ORCPT ); Wed, 2 Aug 2023 06:21:51 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AC0630D1 for ; Wed, 2 Aug 2023 03:21:20 -0700 (PDT) Message-ID: <20230802101933.453524827@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971678; 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=axWsLWrT43omLwQZ83u4QKHGIXaDqvWCJze4cehqf28=; b=WKlvsn7Z8S7Z569PBt4IzG9+PQese99tsFzpGXySXMQR4ASEQl0I5yylVadRpA2z+UvDkl fvKGXLFgcyeb8FT04A6UCFFVT1cJRoih5Pz8X+T4TLnaxfMy26f1WONnQ3R7Bz6zO06iVx AlKwVDFbplAXgoNKjb0w6vXD3i9ryZ5JJu0X2I+P2RUGWJtNd+/f++w21KrPTR31xn6xYL 9k7mPVu9twSsWkhCa3LII4pIqV77yNMyVUnZy80NKbVqog/qMSG1nwZDD2SbsSrU+oV+8V 1gELZBIceklbCUvR/E/Cwv4wcWfwM1x2jWpAGM55SVt14NLdMDxHkqrj1egb/A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971678; 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=axWsLWrT43omLwQZ83u4QKHGIXaDqvWCJze4cehqf28=; b=VV6pxm4wqevoFpM6kZDiaE79cewcMMMk36+NiNp8Iox5xIYIBHQVHFHGzZ6gpAwhhloH5m +doygJjo+YJ0X2AA== 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 , Wei Liu Subject: [patch V3 13/40] x86/apic: Use BAD_APICID consistently References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:18 +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,URIBL_BLOCKED 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: 1773115326070666348 X-GMAIL-MSGID: 1773115326070666348 APIC ID checks compare with BAD_APICID all over the place, but some initializers and some code which fiddles with global data structure use -1[U] instead. That simply cannot work at all. Fix it up and use BAD_APICID consistently all over the place. Signed-off-by: Thomas Gleixner --- V3: Fixed changelog typos - Sohil --- arch/x86/kernel/acpi/boot.c | 2 +- arch/x86/kernel/apic/apic.c | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) --- a/arch/x86/kernel/acpi/boot.c +++ b/arch/x86/kernel/acpi/boot.c @@ -852,7 +852,7 @@ int acpi_unmap_cpu(int cpu) set_apicid_to_node(per_cpu(x86_cpu_to_apicid, cpu), NUMA_NO_NODE); #endif - per_cpu(x86_cpu_to_apicid, cpu) = -1; + per_cpu(x86_cpu_to_apicid, cpu) = BAD_APICID; set_cpu_present(cpu, false); num_processors--; --- a/arch/x86/kernel/apic/apic.c +++ b/arch/x86/kernel/apic/apic.c @@ -70,7 +70,7 @@ unsigned int num_processors; unsigned disabled_cpus; /* Processor that is doing the boot up */ -unsigned int boot_cpu_physical_apicid __ro_after_init = -1U; +unsigned int boot_cpu_physical_apicid __ro_after_init = BAD_APICID; EXPORT_SYMBOL_GPL(boot_cpu_physical_apicid); u8 boot_cpu_apic_version __ro_after_init; @@ -2316,9 +2316,7 @@ static int nr_logical_cpuids = 1; /* * Used to store mapping between logical CPU IDs and APIC IDs. */ -int cpuid_to_apicid[] = { - [0 ... NR_CPUS - 1] = -1, -}; +int cpuid_to_apicid[] = { [0 ... NR_CPUS - 1] = BAD_APICID, }; bool arch_match_cpu_phys_id(int cpu, u64 phys_id) { From patchwork Wed Aug 2 10:21:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129799 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp409201vqx; Wed, 2 Aug 2023 05:12:50 -0700 (PDT) X-Google-Smtp-Source: APBJJlEcsohx+dETyGD7btEaK63SO8QmPjf0hpIiz4nFRzp10LWXbOC9KbvN7qZjsPjkrLPBxTlu X-Received: by 2002:a17:903:11d0:b0:1b8:c972:606a with SMTP id q16-20020a17090311d000b001b8c972606amr17255175plh.51.1690978370103; Wed, 02 Aug 2023 05:12:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690978370; cv=none; d=google.com; s=arc-20160816; b=qn58kExxkcHiNEPE4bQXV2g8mmzlgKQIZburTDe9mcSEQYQcp59caCVHke++xZu4CN 5NdFxrHSy0PwRcbLOlk42q1w1AHMnMsESvckYAP8i69GzXOdlrOWm7dPg34TJ3+fukV7 17TG722F7SYhTNXbYab/1EAVqr++64Ph0OCtNaAMVCug4bbdPvFBUo10Moryuz+MPaAF n2G8e08xDAIDoTAist1Aq20EmVT9OtzdjJWN5sKaDIXpR6GUoEoJjWht4hVPSSktTWSI aXasU7SOsQgxFR9TI8TCFr/ikYlsSJBeGWFC7mvRslAySIkhLNy0AtN8e2rdgQEDoBrt Yv6A== 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=afHpAHr//TFG66P7AG1QpLzhwZMkB6i18nsMEAsYlTg=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=A0PMYV6XuCgP4s1L1arT4vqy7IO1xvY78Uimsxw5rmpD8q02hL704+qzBxRxOIbfXI hH/jPggKlnrH9Shw5f75Ba4C5OZdLwmF90RM1I1XaSFyj0+Zl5abQ8nl8uNu1lyuWvkC DuMlAtL3jWWDSmh0xQmy139+qU+zCDFIjn2MTHVtENt67eITN721vIFTzgjsMzNHNmNi 5+IR4cn+93ViGx73Q4fqxQZ80WJopRm/Ln+4JL+SKIM0ZZwr1Zjp0rEDvQqoV6YjAeLA QZ65PDM4tPWyaZmUhx/6+bHfaDUn1VXP2maflb1KzxucrfvkyCOQrcjXYil3wKxnQYiA Zcfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ZNOm49bJ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 k15-20020a170902c40f00b001b23d4573b2si767630plk.27.2023.08.02.05.12.31; Wed, 02 Aug 2023 05:12:50 -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=ZNOm49bJ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S233034AbjHBKWY (ORCPT + 99 others); Wed, 2 Aug 2023 06:22:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232564AbjHBKV7 (ORCPT ); Wed, 2 Aug 2023 06:21:59 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99F2E2708 for ; Wed, 2 Aug 2023 03:21:22 -0700 (PDT) Message-ID: <20230802101933.511125514@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971680; 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=afHpAHr//TFG66P7AG1QpLzhwZMkB6i18nsMEAsYlTg=; b=ZNOm49bJtJ8MTjx+yp6edzrRZwohf/Qo0hNiQlbV8rM8/XaPGJMQc62apCBBIFnhrCGFtV cElJA2PXbqrV/JFCx5SiSOdSfrrs5foOcdooxzTZA7qtRtCTTkxIEJayPA7WDpuQ+mAPJ7 d7tfVeVWKe/l9Zxj+Gj2KyrPRdsTZK79fDWwBObJMB14I3HhywxrBHRbl48SZgNl7lzaHn L9Ses/BKlfvIlmV8Zh5O5MGn7wpXO+c3wWKrfJBlnl5YKvC19p/IMcdriJfamENpndr//t cW7HDJ2wuQa17zbzZZROLPmTQFXA6Ykg7pxVfW5gKVfM8BuLQpjXmxNWUTHMGg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971680; 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=afHpAHr//TFG66P7AG1QpLzhwZMkB6i18nsMEAsYlTg=; b=PTlWeUEoglsQxGOnq0N31rhhSZ7zuGm2Jg8YtOceqYXAzhCTPM1Mln2HhVHVwH3K4NIb8b U92qwpldOTFm2ICg== 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 , Wei Liu Subject: [patch V3 14/40] x86/apic: Use u32 for APIC IDs in global data References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:19 +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,URIBL_BLOCKED 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: 1773119335643401316 X-GMAIL-MSGID: 1773119335643401316 APIC IDs are used with random data types u16, u32, int, unsigned int, unsigned long. Make it all consistently use u32 because that reflects the hardware register width and fixup the most obvious usage sites of that. The APIC callbacks will be addressed separately. Signed-off-by: Thomas Gleixner Reviewed-by: Arjan van de Ven --- arch/x86/include/asm/apic.h | 2 +- arch/x86/include/asm/mpspec.h | 2 +- arch/x86/include/asm/processor.h | 4 ++-- arch/x86/include/asm/smp.h | 2 +- arch/x86/kernel/apic/apic.c | 12 ++++++------ arch/x86/kernel/kvm.c | 6 +++--- arch/x86/mm/numa.c | 4 ++-- 7 files changed, 16 insertions(+), 16 deletions(-) --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -54,7 +54,7 @@ extern int local_apic_timer_c2_ok; extern bool apic_is_disabled; extern unsigned int lapic_timer_period; -extern int cpuid_to_apicid[]; +extern u32 cpuid_to_apicid[]; extern enum apic_intr_mode_id apic_intr_mode; enum apic_intr_mode_id { --- a/arch/x86/include/asm/mpspec.h +++ b/arch/x86/include/asm/mpspec.h @@ -37,7 +37,7 @@ extern int mp_bus_id_to_type[MAX_MP_BUSS extern DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES); -extern unsigned int boot_cpu_physical_apicid; +extern u32 boot_cpu_physical_apicid; extern u8 boot_cpu_apic_version; #ifdef CONFIG_X86_LOCAL_APIC --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -691,12 +691,12 @@ extern int set_tsc_mode(unsigned int val DECLARE_PER_CPU(u64, msr_misc_features_shadow); -static inline u16 per_cpu_llc_id(unsigned int cpu) +static inline u32 per_cpu_llc_id(unsigned int cpu) { return per_cpu(cpu_info.topo.llc_id, cpu); } -static inline u16 per_cpu_l2c_id(unsigned int cpu) +static inline u32 per_cpu_l2c_id(unsigned int cpu) { return per_cpu(cpu_info.topo.l2c_id, cpu); } --- a/arch/x86/include/asm/smp.h +++ b/arch/x86/include/asm/smp.h @@ -18,7 +18,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map); DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_l2c_shared_map); -DECLARE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_cpu_to_apicid); +DECLARE_EARLY_PER_CPU_READ_MOSTLY(u32, x86_cpu_to_apicid); DECLARE_EARLY_PER_CPU_READ_MOSTLY(u32, x86_cpu_to_acpiid); struct task_struct; --- a/arch/x86/kernel/apic/apic.c +++ b/arch/x86/kernel/apic/apic.c @@ -70,7 +70,7 @@ unsigned int num_processors; unsigned disabled_cpus; /* Processor that is doing the boot up */ -unsigned int boot_cpu_physical_apicid __ro_after_init = BAD_APICID; +u32 boot_cpu_physical_apicid __ro_after_init = BAD_APICID; EXPORT_SYMBOL_GPL(boot_cpu_physical_apicid); u8 boot_cpu_apic_version __ro_after_init; @@ -85,7 +85,7 @@ physid_mask_t phys_cpu_present_map; * disable_cpu_apicid=, mostly used for the kdump 2nd kernel to * avoid undefined behaviour caused by sending INIT from AP to BSP. */ -static unsigned int disabled_cpu_apicid __ro_after_init = BAD_APICID; +static u32 disabled_cpu_apicid __ro_after_init = BAD_APICID; /* * This variable controls which CPUs receive external NMIs. By default, @@ -109,7 +109,7 @@ static inline bool apic_accessible(void) /* * Map cpu index to physical APIC ID */ -DEFINE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_cpu_to_apicid, BAD_APICID); +DEFINE_EARLY_PER_CPU_READ_MOSTLY(u32, x86_cpu_to_apicid, BAD_APICID); DEFINE_EARLY_PER_CPU_READ_MOSTLY(u32, x86_cpu_to_acpiid, U32_MAX); EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_apicid); EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_acpiid); @@ -2316,11 +2316,11 @@ static int nr_logical_cpuids = 1; /* * Used to store mapping between logical CPU IDs and APIC IDs. */ -int cpuid_to_apicid[] = { [0 ... NR_CPUS - 1] = BAD_APICID, }; +u32 cpuid_to_apicid[] = { [0 ... NR_CPUS - 1] = BAD_APICID, }; bool arch_match_cpu_phys_id(int cpu, u64 phys_id) { - return phys_id == cpuid_to_apicid[cpu]; + return phys_id == (u64)cpuid_to_apicid[cpu]; } #ifdef CONFIG_SMP @@ -2380,7 +2380,7 @@ static int allocate_logical_cpuid(int ap return nr_logical_cpuids++; } -static void cpu_update_apic(int cpu, int apicid) +static void cpu_update_apic(int cpu, u32 apicid) { #if defined(CONFIG_SMP) || defined(CONFIG_X86_64) early_per_cpu(x86_cpu_to_apicid, cpu) = apicid; --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -500,13 +500,13 @@ static bool pv_sched_yield_supported(voi static void __send_ipi_mask(const struct cpumask *mask, int vector) { unsigned long flags; - int cpu, apic_id, icr; - int min = 0, max = 0; + int cpu, min = 0, max = 0; #ifdef CONFIG_X86_64 __uint128_t ipi_bitmap = 0; #else u64 ipi_bitmap = 0; #endif + u32 apic_id, icr; long ret; if (cpumask_empty(mask)) @@ -1030,8 +1030,8 @@ arch_initcall(activate_jump_labels); /* Kick a cpu by its apicid. Used to wake up a halted vcpu */ static void kvm_kick_cpu(int cpu) { - int apicid; unsigned long flags = 0; + u32 apicid; apicid = per_cpu(x86_cpu_to_apicid, cpu); kvm_hypercall2(KVM_HC_KICK_CPU, flags, apicid); --- a/arch/x86/mm/numa.c +++ b/arch/x86/mm/numa.c @@ -56,7 +56,7 @@ s16 __apicid_to_node[MAX_LOCAL_APIC] = { int numa_cpu_node(int cpu) { - int apicid = early_per_cpu(x86_cpu_to_apicid, cpu); + u32 apicid = early_per_cpu(x86_cpu_to_apicid, cpu); if (apicid != BAD_APICID) return __apicid_to_node[apicid]; @@ -786,7 +786,7 @@ void __init init_gi_nodes(void) void __init init_cpu_to_node(void) { int cpu; - u16 *cpu_to_apicid = early_per_cpu_ptr(x86_cpu_to_apicid); + u32 *cpu_to_apicid = early_per_cpu_ptr(x86_cpu_to_apicid); BUG_ON(cpu_to_apicid == NULL); From patchwork Wed Aug 2 10:21:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129791 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp398022vqx; Wed, 2 Aug 2023 04:56:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFNA3T4fe26Fjba2vQ2ZMxFkqBEPamUhaqlzz6tPrjenpyukFuner5jAdauhUyGzmHBmetC X-Received: by 2002:a05:6512:b02:b0:4fe:5051:f253 with SMTP id w2-20020a0565120b0200b004fe5051f253mr111449lfu.9.1690977383113; Wed, 02 Aug 2023 04:56:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690977383; cv=none; d=google.com; s=arc-20160816; b=EdnoZND+ZHkjVdluBHbIr3qtdhEWj/fi546oWcp1WLdfdDAktTVGhBchkf1X+Ju88m USOFzVfYLIq5Cu4aZa+6jg7Bonfl3toxewOzKIKRAIYTlB2PvX4Y/yVn28knc2mtLNRN Ywm7I/S6kUNWlxgIvKT/dHs6IwXy6CHRbLh6k2Q5ACIFsVDSV0rc0YNeZ2aKsWDzrAQJ tgKlOV+n6lMSOHrFq1o5v0/6vMTbVMjEB2oYgw/QJjldp/gES4VhnQucg5AXFb8cHI8c +wAS2+6hyKAi0gzxXUX9G2PvxJfho7HCeMgR7q8/UeykyGGzphNB3pLidoMx/f6h4ovf rTww== 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=YhEanMRg+4kFvHEfTCEvq8URBlfBDUjAuPyT44iGPEI=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=hjAf4m/cVLgGJ2xOqainkdaKfFkQqwK0tOrnGdK0dDYndgbsuJEXPp/oMyBE5tC6O5 tPekGHHaDOYUP6BtaatKNcp4gjG+/HdkRX7cKkwLEZfdOvUhNPnJxn008Kps/FE0thnf hk5Ro6WN+gX5AOFs+8o0urFIbSn9okLOTf87awPQMwSXaUrQ8R+kJB9+fUHRDuGfKSw8 9bDVGQ1+HAgej0M2xiU/AaS52q/9tDLCVuJ0mgn/HVKemJjeQVxXCKN0D7CExxrX1Hxw vcUgGe0/p6NeG5o7ybDRARBQPYg+E2ysZQGohlMgSJ5lvnx6DP3Idn9sN+YkwLYl9VJN hx6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=1WjrgSoX; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=mstaGafi; 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 o23-20020aa7c517000000b0051e1c495a0csi10334489edq.376.2023.08.02.04.55.58; Wed, 02 Aug 2023 04:56:23 -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=1WjrgSoX; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=mstaGafi; 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 S233924AbjHBKWc (ORCPT + 99 others); Wed, 2 Aug 2023 06:22:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233950AbjHBKWG (ORCPT ); Wed, 2 Aug 2023 06:22:06 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2FDA30FD for ; Wed, 2 Aug 2023 03:21:23 -0700 (PDT) Message-ID: <20230802101933.567908704@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971682; 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=YhEanMRg+4kFvHEfTCEvq8URBlfBDUjAuPyT44iGPEI=; b=1WjrgSoXxYRSbq4yzDqY7yGnGhKXyFxecpWRjEqZ9Pia+Q2fcnkX/3Q+LVo+zddNXK1ZBQ GdbgxTfgfQsHbm+3hZBB1AeEGKTAHz2FQd/3Xse1+4KFLicPpZv5EPpAcqqGLg3CV0o1cq /niMEJ6xnvQsbgc3sHwKRDUY8fRApZzEa9eB3K88Q4STWqf8iNOSRO2Fpmpt3iH6cRiVtN 5b/QU+pHSJ1NVTo7ev6SSaqFeaz4JPyLOPKeYraFtxgnKWgiMDyM5YBJb8k+s85xkj9Ezl gZduL8AvGX9hx70BVL7UYjijVL0RcKUU+I57W0QfqOWy48CNFcwvIZN7JuDW5g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971682; 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=YhEanMRg+4kFvHEfTCEvq8URBlfBDUjAuPyT44iGPEI=; b=mstaGafil/UFKsuu/zTLUcuPfS/mRd+SRP9FG2hwiJehcFjrJMbc3aaYhdftEkHPXc2U3u 71zasdQ4n+9TD8DA== 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 , Wei Liu Subject: [patch V3 15/40] x86/apic: Use u32 for check_apicid_used() References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:21 +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,URIBL_BLOCKED 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: 1773118300475631795 X-GMAIL-MSGID: 1773118300475631795 APIC IDs are used with random data types u16, u32, int, unsigned int, unsigned long. Make it all consistently use u32 because that reflects the hardware register width and move the default implementation to local.h as there are no users outside the apic directory. Signed-off-by: Thomas Gleixner Reviewed-by: Arjan van de Ven --- arch/x86/include/asm/apic.h | 3 +-- arch/x86/kernel/apic/apic_common.c | 2 +- arch/x86/kernel/apic/apic_flat_64.c | 2 -- arch/x86/kernel/apic/apic_noop.c | 2 ++ arch/x86/kernel/apic/bigsmp_32.c | 2 +- arch/x86/kernel/apic/local.h | 1 + 6 files changed, 6 insertions(+), 6 deletions(-) --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -292,7 +292,7 @@ struct apic { int (*acpi_madt_oem_check)(char *oem_id, char *oem_table_id); bool (*apic_id_registered)(void); - bool (*check_apicid_used)(physid_mask_t *map, int apicid); + bool (*check_apicid_used)(physid_mask_t *map, u32 apicid); void (*init_apic_ldr)(void); void (*ioapic_phys_id_map)(physid_mask_t *phys_map, physid_mask_t *retmap); int (*cpu_present_to_apicid)(int mps_cpu); @@ -538,7 +538,6 @@ extern int default_apic_id_valid(u32 api extern u32 apic_default_calc_apicid(unsigned int cpu); extern u32 apic_flat_calc_apicid(unsigned int cpu); -extern bool default_check_apicid_used(physid_mask_t *map, int apicid); extern void default_ioapic_phys_id_map(physid_mask_t *phys_map, physid_mask_t *retmap); extern int default_cpu_present_to_apicid(int mps_cpu); --- a/arch/x86/kernel/apic/apic_common.c +++ b/arch/x86/kernel/apic/apic_common.c @@ -18,7 +18,7 @@ u32 apic_flat_calc_apicid(unsigned int c return 1U << cpu; } -bool default_check_apicid_used(physid_mask_t *map, int apicid) +bool default_check_apicid_used(physid_mask_t *map, u32 apicid) { return physid_isset(apicid, *map); } --- a/arch/x86/kernel/apic/apic_flat_64.c +++ b/arch/x86/kernel/apic/apic_flat_64.c @@ -158,8 +158,6 @@ static struct apic apic_physflat __ro_af .disable_esr = 0, - .check_apicid_used = NULL, - .ioapic_phys_id_map = NULL, .cpu_present_to_apicid = default_cpu_present_to_apicid, .phys_pkg_id = flat_phys_pkg_id, --- a/arch/x86/kernel/apic/apic_noop.c +++ b/arch/x86/kernel/apic/apic_noop.c @@ -18,6 +18,8 @@ #include +#include "local.h" + static void noop_send_IPI(int cpu, int vector) { } static void noop_send_IPI_mask(const struct cpumask *cpumask, int vector) { } static void noop_send_IPI_mask_allbutself(const struct cpumask *cpumask, int vector) { } --- a/arch/x86/kernel/apic/bigsmp_32.c +++ b/arch/x86/kernel/apic/bigsmp_32.c @@ -18,7 +18,7 @@ static unsigned bigsmp_get_apic_id(unsig return (x >> 24) & 0xFF; } -static bool bigsmp_check_apicid_used(physid_mask_t *map, int apicid) +static bool bigsmp_check_apicid_used(physid_mask_t *map, u32 apicid) { return false; } --- a/arch/x86/kernel/apic/local.h +++ b/arch/x86/kernel/apic/local.h @@ -64,6 +64,7 @@ void default_send_IPI_all(int vector); void default_send_IPI_self(int vector); bool default_apic_id_registered(void); +bool default_check_apicid_used(physid_mask_t *map, u32 apicid); #ifdef CONFIG_X86_32 void default_send_IPI_mask_sequence_logical(const struct cpumask *mask, int vector); From patchwork Wed Aug 2 10:21:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129761 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp363230vqx; Wed, 2 Aug 2023 03:50:34 -0700 (PDT) X-Google-Smtp-Source: APBJJlGf7ahsC9WBH8I1PN0UcLMszKhg6RD9AMihsnLBEefanuR7MWLNPHVwqgKXeVl/9wzMQURw X-Received: by 2002:a17:906:3f19:b0:99b:48a9:f56d with SMTP id c25-20020a1709063f1900b0099b48a9f56dmr4067180ejj.22.1690973434025; Wed, 02 Aug 2023 03:50:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690973433; cv=none; d=google.com; s=arc-20160816; b=Ly9Mv/6U0Z5uINbkosscenUWzgqZkuJ5QNfG3cxmj3aniz8VF5c43HzpMm4PV9TxQS I2MA9hJzz3zVt75xHcXS40uIhb8bNrsESitojZo5HncFVtm9xqb6Kb/J5lNYLVXtuzLe 9ouNSNwLX72Q8IFgnsHaADz+GgKCqY9OZtw75Y/5+CiHet6x2LaIp/17NDPS2M7m8fua D9wC1McXgn4aaRv8xkvedrsnve5a2a9kGAv5BVpUXi0qMxA4pipbD1zqYHT3p3HZoCdL 8+i2CwJZlzw4t2DpXtWpBS1lUX5V3Gu5VcOu/4FaYpjV1vwCSDEpts2pW6AwDoTS5rSD khaw== 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=35SsYPutHQfrY5WfuShg4nZEs1pqJGB3qfTztkPXMuo=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=NVWZ7p76DGdMyI2dszQFc8j35jNNv42uMIAr3sGpjXINQvZVoLhCpm1RAZpX79G78K KDlFO+z3eAXtsGm40Xu/qmrV8rvEGxIBNeiKsgXUBh/h2Yiwjbw8Fyl+iaoYVhj976HK 3UeUM4OhUD+BzIjQwldvV0M4G1FbPLIVU7OsK8OwmPl0S9HfO+AV1+nhypsADzAhdH6o eUdRRpt8WNxRz6xruTiXzF3B6SRc4sijxRgbirFApsL/I6A3/GPMmOsqvnseudYjIsr5 t71EjAwZ6s9proMgvpJySSfhi79g4ZGSSSgexZYGmR/XPcnZwAtSSMy8RJVL90mjZ7ZO 8LqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="MV/oumQO"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=C4ix81YM; 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 e6-20020a170906374600b0099319803901si9697160ejc.844.2023.08.02.03.50.09; Wed, 02 Aug 2023 03:50:33 -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="MV/oumQO"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=C4ix81YM; 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 S232421AbjHBKWl (ORCPT + 99 others); Wed, 2 Aug 2023 06:22:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233797AbjHBKWH (ORCPT ); Wed, 2 Aug 2023 06:22:07 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9283C3590 for ; Wed, 2 Aug 2023 03:21:25 -0700 (PDT) Message-ID: <20230802101933.624048507@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971683; 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=35SsYPutHQfrY5WfuShg4nZEs1pqJGB3qfTztkPXMuo=; b=MV/oumQO5BoAgtxkGI6en5/fheTy/diEfI9CHqwE8vtC8AgJSLfWJcBT0tDzLGFvK9kgQO M3WG2p4c2+l+oZ7g0UeypljvYTX8Vv/8vBkAA6vFPbh4wMedGs54+9BZx7FwaG3u6ebas0 tkH0kPILO9NRZq4vI/xEHlVGDhEkAhlnHbuvyYKk4v0qxJXqBIckfQPZfSDNS9mmohyMcY qbbBxV/jGFp+b1qkH57cPWEQUl4z0AskkxkZzNcnkhCQjxngGagRmz3Ttfp4z5vAiekHhV o2x8raRxQXoDi/2r62U/eXgyB9DppE0giPM/euDnyAs09O2IC5jXwAiqmKcgrw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971683; 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=35SsYPutHQfrY5WfuShg4nZEs1pqJGB3qfTztkPXMuo=; b=C4ix81YMNoXabjRTYcc9VhOI4k7/i5DPNizvGtFRyCNfbHW0sxU3h7HJuw/yCbbtT4ui+x CUhDGNQTsITboEAg== 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 , Wei Liu Subject: [patch V3 16/40] x86/apic: Use u32 for cpu_present_to_apicid() References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:23 +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,URIBL_BLOCKED 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: 1773114159521671482 X-GMAIL-MSGID: 1773114159521671482 APIC IDs are used with random data types u16, u32, int, unsigned int, unsigned long. Make it all consistently use u32 because that reflects the hardware register width and fixup a few related usage sites for consistency sake. Signed-off-by: Thomas Gleixner Reviewed-by: Arjan van de Ven --- arch/x86/include/asm/apic.h | 4 ++-- arch/x86/kernel/apic/apic_common.c | 2 +- arch/x86/kernel/cpu/common.c | 3 ++- arch/x86/kernel/smpboot.c | 10 +++++----- arch/x86/xen/apic.c | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -295,7 +295,7 @@ struct apic { bool (*check_apicid_used)(physid_mask_t *map, u32 apicid); void (*init_apic_ldr)(void); void (*ioapic_phys_id_map)(physid_mask_t *phys_map, physid_mask_t *retmap); - int (*cpu_present_to_apicid)(int mps_cpu); + u32 (*cpu_present_to_apicid)(int mps_cpu); int (*phys_pkg_id)(int cpuid_apic, int index_msb); u32 (*get_apic_id)(unsigned long x); @@ -539,7 +539,7 @@ extern u32 apic_default_calc_apicid(unsi extern u32 apic_flat_calc_apicid(unsigned int cpu); extern void default_ioapic_phys_id_map(physid_mask_t *phys_map, physid_mask_t *retmap); -extern int default_cpu_present_to_apicid(int mps_cpu); +extern u32 default_cpu_present_to_apicid(int mps_cpu); #else /* CONFIG_X86_LOCAL_APIC */ --- a/arch/x86/kernel/apic/apic_common.c +++ b/arch/x86/kernel/apic/apic_common.c @@ -28,7 +28,7 @@ void default_ioapic_phys_id_map(physid_m *retmap = *phys_map; } -int default_cpu_present_to_apicid(int mps_cpu) +u32 default_cpu_present_to_apicid(int mps_cpu) { if (mps_cpu < nr_cpu_ids && cpu_present(mps_cpu)) return (int)per_cpu(x86_cpu_to_apicid, mps_cpu); --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1747,7 +1747,8 @@ static void generic_identify(struct cpui static void validate_apic_and_package_id(struct cpuinfo_x86 *c) { #ifdef CONFIG_SMP - unsigned int apicid, cpu = smp_processor_id(); + unsigned int cpu = smp_processor_id(); + u32 apicid; apicid = apic->cpu_present_to_apicid(cpu); --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -816,7 +816,7 @@ static void __init smp_quirk_init_udelay /* * Wake up AP by INIT, INIT, STARTUP sequence. */ -static void send_init_sequence(int phys_apicid) +static void send_init_sequence(u32 phys_apicid) { int maxlvt = lapic_get_maxlvt(); @@ -842,7 +842,7 @@ static void send_init_sequence(int phys_ /* * Wake up AP by INIT, INIT, STARTUP sequence. */ -static int wakeup_secondary_cpu_via_init(int phys_apicid, unsigned long start_eip) +static int wakeup_secondary_cpu_via_init(u32 phys_apicid, unsigned long start_eip) { unsigned long send_status = 0, accept_status = 0; int num_starts, j, maxlvt; @@ -989,7 +989,7 @@ int common_cpu_up(unsigned int cpu, stru * Returns zero if startup was successfully sent, else error code from * ->wakeup_secondary_cpu. */ -static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle) +static int do_boot_cpu(u32 apicid, int cpu, struct task_struct *idle) { unsigned long start_ip = real_mode_header->trampoline_start; int ret; @@ -1057,7 +1057,7 @@ static int do_boot_cpu(int apicid, int c int native_kick_ap(unsigned int cpu, struct task_struct *tidle) { - int apicid = apic->cpu_present_to_apicid(cpu); + u32 apicid = apic->cpu_present_to_apicid(cpu); int err; lockdep_assert_irqs_enabled(); @@ -1250,7 +1250,7 @@ void arch_thaw_secondary_cpus_end(void) bool smp_park_other_cpus_in_init(void) { unsigned int cpu, this_cpu = smp_processor_id(); - unsigned int apicid; + u32 apicid; if (apic->wakeup_secondary_cpu_64 || apic->wakeup_secondary_cpu) return false; --- a/arch/x86/xen/apic.c +++ b/arch/x86/xen/apic.c @@ -115,7 +115,7 @@ static int xen_phys_pkg_id(int initial_a return initial_apic_id >> index_msb; } -static int xen_cpu_present_to_apicid(int cpu) +static u32 xen_cpu_present_to_apicid(int cpu) { if (cpu_present(cpu)) return cpu_data(cpu).topo.apicid; From patchwork Wed Aug 2 10:21:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129803 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp410112vqx; Wed, 2 Aug 2023 05:14:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlEe6u8G4bsqLLoLJTJcHmgtLruaz0X/i4S9eGvN0r2BBlcVo5XgWR+fS13nBBaBls4AbN98 X-Received: by 2002:a17:90b:46c8:b0:262:d7db:2520 with SMTP id jx8-20020a17090b46c800b00262d7db2520mr13605906pjb.26.1690978458366; Wed, 02 Aug 2023 05:14:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690978458; cv=none; d=google.com; s=arc-20160816; b=eg8o3ug4bZj/YZfDasCMWbwH6OjOWEOGkW1ts5InDKx+nLWhzKbTWTAXgRu5UWk+Uz sLz1wuzBY/IURUhCm1dYNsW+DaClKtZ/qgijiyzQUjY8bX6qhUni/+ZIBVcsJJ2CPxnZ FrbG0OqQKdmYBrmo5ifpIpG3evWNsC6S9jEhJ1IgNGHIGWMKYAl/qUO6gxacpRaOWnth 4ZfjFi+J1NA9gTpVG5Tz+ei9w/Ydj+z+NZ0XDSh7maUaKsJqdAOeL5dCyUz0nwhm982+ qL+gtOQCSYXLP2fpsJxKJ/VtQ86jh/Q0lS8lcnY8Mzlz011fMXz4FW9WHJ49uoiPSYUL lXRg== 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=AIhdlL5QJjV35PnxoIghFIXyyofouuO6E0SkWJpEcqM=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=i8yucB3xPgfqiNNu88n/Vm/bnoLzlmBv/U4rlF+3db7yJyEOrUb6t9K6U+747n319e WYKRlDLso+Ax6+IcpeivmGhSCAomjTiY/pUXam/6aYThrwyT2CjSKBdzULis5E6ldTte AR3kC8CoZDdLHu3JzjJxI4v3lyh63Py+8NNrjzDk14M+Fa5MXGCXCzm5aPN7ZtkU/AAj zXvBf5c3T9DJmwHWN9Y6kHCsiyPr4AJkpH42/SBCGUPbJE0Fha0Jdoa3rSgDTUsKgtR8 IbO+9Jp9mMgQsoEU8JM1OS2wiY0CxYdN6fUbxAyxdwSduvAfnJX3Pd8c3NngQuR2YYeG DBzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=aqxPZeUt; 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 x9-20020a17090a1f8900b00250ce1755e9si974283pja.14.2023.08.02.05.14.03; Wed, 02 Aug 2023 05:14:18 -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=aqxPZeUt; 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 S234082AbjHBKW4 (ORCPT + 99 others); Wed, 2 Aug 2023 06:22:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234003AbjHBKWJ (ORCPT ); Wed, 2 Aug 2023 06:22:09 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A533335A4 for ; Wed, 2 Aug 2023 03:21:27 -0700 (PDT) Message-ID: <20230802101933.680585936@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971685; 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=AIhdlL5QJjV35PnxoIghFIXyyofouuO6E0SkWJpEcqM=; b=aqxPZeUtOIcxEG7NDIQJTtEer+WE9EcEdWWVLLAuxz9agV9RclW6gLwgTtzFqpJhkbwtVD iU96U+pnK8fhrATM2EN2TqrT1NU6fXwrOVU8Axx8texXMZf+/96A6Ri7ASVohmbVpuqizM mI0g+8HwUS6N099oRAE6volsFz4u1sofYZbiYjqQQJ9dk1Y2JJv+Yyaluik+Jj1567pqp3 G0AwDleSweB9NQL6MASDFmKWyk+Nz4b49wGBDqdY08CPZVokpJ+HJwKm9txl7ruhC5fDQm f4mU3XPnSRQGkpxtTWAdHmUiKomqq0DHO8y3seKilKsr9M7SySN3Bk+Sli3dOQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971685; 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=AIhdlL5QJjV35PnxoIghFIXyyofouuO6E0SkWJpEcqM=; b=pco6E3uNidDN+QQXueKGnmB2p90mj+x2h55HBjfVGWoddYWfvAgXhcXiass+A0wC+MkFv0 YT5JIOLk3fzwo7BA== 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 , Wei Liu Subject: [patch V3 17/40] x86/apic: Use u32 for phys_pkg_id() References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:24 +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,URIBL_BLOCKED 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: 1773119428029241077 X-GMAIL-MSGID: 1773119428029241077 APIC IDs are used with random data types u16, u32, int, unsigned int, unsigned long. Make it all consistently use u32 because that reflects the hardware register width even if that callback going to be removed soonish. Signed-off-by: Thomas Gleixner Reviewed-by: Arjan van de Ven --- arch/x86/include/asm/apic.h | 2 +- arch/x86/kernel/apic/apic_flat_64.c | 2 +- arch/x86/kernel/apic/apic_noop.c | 2 +- arch/x86/kernel/apic/apic_numachip.c | 2 +- arch/x86/kernel/apic/bigsmp_32.c | 2 +- arch/x86/kernel/apic/local.h | 2 +- arch/x86/kernel/apic/probe_32.c | 2 +- arch/x86/kernel/apic/x2apic_phys.c | 2 +- arch/x86/kernel/apic/x2apic_uv_x.c | 2 +- arch/x86/kernel/vsmp_64.c | 2 +- arch/x86/xen/apic.c | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -296,7 +296,7 @@ struct apic { void (*init_apic_ldr)(void); void (*ioapic_phys_id_map)(physid_mask_t *phys_map, physid_mask_t *retmap); u32 (*cpu_present_to_apicid)(int mps_cpu); - int (*phys_pkg_id)(int cpuid_apic, int index_msb); + u32 (*phys_pkg_id)(u32 cpuid_apic, int index_msb); u32 (*get_apic_id)(unsigned long x); u32 (*set_apic_id)(unsigned int id); --- a/arch/x86/kernel/apic/apic_flat_64.c +++ b/arch/x86/kernel/apic/apic_flat_64.c @@ -66,7 +66,7 @@ static u32 set_apic_id(unsigned int id) return (id & 0xFF) << 24; } -static int flat_phys_pkg_id(int initial_apic_id, int index_msb) +static u32 flat_phys_pkg_id(u32 initial_apic_id, int index_msb) { return initial_apic_id >> index_msb; } --- a/arch/x86/kernel/apic/apic_noop.c +++ b/arch/x86/kernel/apic/apic_noop.c @@ -29,7 +29,7 @@ static void noop_send_IPI_self(int vecto static void noop_apic_icr_write(u32 low, u32 id) { } static int noop_wakeup_secondary_cpu(int apicid, unsigned long start_eip) { return -1; } static u64 noop_apic_icr_read(void) { return 0; } -static int noop_phys_pkg_id(int cpuid_apic, int index_msb) { return 0; } +static u32 noop_phys_pkg_id(u32 cpuid_apic, int index_msb) { return 0; } static unsigned int noop_get_apic_id(unsigned long x) { return 0; } static void noop_apic_eoi(void) { } --- a/arch/x86/kernel/apic/apic_numachip.c +++ b/arch/x86/kernel/apic/apic_numachip.c @@ -56,7 +56,7 @@ static u32 numachip2_set_apic_id(unsigne return id << 24; } -static int numachip_phys_pkg_id(int initial_apic_id, int index_msb) +static u32 numachip_phys_pkg_id(u32 initial_apic_id, int index_msb) { return initial_apic_id >> index_msb; } --- a/arch/x86/kernel/apic/bigsmp_32.c +++ b/arch/x86/kernel/apic/bigsmp_32.c @@ -29,7 +29,7 @@ static void bigsmp_ioapic_phys_id_map(ph physids_promote(0xFFL, retmap); } -static int bigsmp_phys_pkg_id(int cpuid_apic, int index_msb) +static u32 bigsmp_phys_pkg_id(u32 cpuid_apic, int index_msb) { return cpuid_apic >> index_msb; } --- a/arch/x86/kernel/apic/local.h +++ b/arch/x86/kernel/apic/local.h @@ -17,7 +17,7 @@ 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); -int x2apic_phys_pkg_id(int initial_apicid, int index_msb); +u32 x2apic_phys_pkg_id(u32 initial_apicid, int index_msb); void x2apic_send_IPI_all(int vector); void x2apic_send_IPI_allbutself(int vector); --- a/arch/x86/kernel/apic/probe_32.c +++ b/arch/x86/kernel/apic/probe_32.c @@ -18,7 +18,7 @@ #include "local.h" -static int default_phys_pkg_id(int cpuid_apic, int index_msb) +static u32 default_phys_pkg_id(u32 cpuid_apic, int index_msb) { return cpuid_apic >> index_msb; } --- a/arch/x86/kernel/apic/x2apic_phys.c +++ b/arch/x86/kernel/apic/x2apic_phys.c @@ -134,7 +134,7 @@ u32 x2apic_set_apic_id(unsigned int id) return id; } -int x2apic_phys_pkg_id(int initial_apicid, int index_msb) +u32 x2apic_phys_pkg_id(u32 initial_apicid, int index_msb) { return initial_apicid >> index_msb; } --- a/arch/x86/kernel/apic/x2apic_uv_x.c +++ b/arch/x86/kernel/apic/x2apic_uv_x.c @@ -790,7 +790,7 @@ static unsigned int uv_read_apic_id(void return x2apic_get_apic_id(apic_read(APIC_ID)); } -static int uv_phys_pkg_id(int initial_apicid, int index_msb) +static u32 uv_phys_pkg_id(u32 initial_apicid, int index_msb) { return uv_read_apic_id() >> index_msb; } --- a/arch/x86/kernel/vsmp_64.c +++ b/arch/x86/kernel/vsmp_64.c @@ -127,7 +127,7 @@ static void __init vsmp_cap_cpus(void) #endif } -static int apicid_phys_pkg_id(int initial_apic_id, int index_msb) +static u32 apicid_phys_pkg_id(u32 initial_apic_id, int index_msb) { return read_apic_id() >> index_msb; } --- a/arch/x86/xen/apic.c +++ b/arch/x86/xen/apic.c @@ -110,7 +110,7 @@ static int xen_madt_oem_check(char *oem_ return xen_pv_domain(); } -static int xen_phys_pkg_id(int initial_apic_id, int index_msb) +static u32 xen_phys_pkg_id(u32 initial_apic_id, int index_msb) { return initial_apic_id >> index_msb; } From patchwork Wed Aug 2 10:21:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129757 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp360875vqx; Wed, 2 Aug 2023 03:44:33 -0700 (PDT) X-Google-Smtp-Source: APBJJlFYnrYFiSHzHZ+f74X6DbXtnasDTDjbJqLwLHFalAnS8WrsMomV/Uz45RAUSgYg+fTxBrjW X-Received: by 2002:a05:6808:f87:b0:3a1:b6de:ed54 with SMTP id o7-20020a0568080f8700b003a1b6deed54mr19284844oiw.32.1690973073289; Wed, 02 Aug 2023 03:44:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690973073; cv=none; d=google.com; s=arc-20160816; b=RF7k8Zv4VW4C1PPVK3qfCsnCsoBIj1714E9r8pbInEoxJBMpQer8mVNGh2aEgpWoPF 2piAdg1FYQAxTEZtpfv2Jd3TU/KPbcJPczuq5kxRmecu//6vDs5+zn33gFiJlFoYC2WU dSdKKnSQtcIlzhgShjFHaoeWnEn9e79/FYdF+6iERx0vxSrY0wj2rB1sEzdQTnH7Vtkr PHERj4IGjZD1Ya9SEs1xjYfHUg6UaOmTK8w5Nn4bKzTGea7qD3nlnim8OzQiEA5yDqH/ blIHBurWWICDra8s1I13qqgg5oz2hIESExm1I8DyLph/XQv4bZYAtXPElp3MCwjvA8uS z8eQ== 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=N1azWL9rFTheZgbP+psN/3Z4a3oFTh1DV0QsrK11aoI=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=jTwm/vxFrdDe4QRQpnsqZMgKPEAbHsn18hY0qI4OFcho7isX1j68gDSwMDKQweYoej EmofmJrkGT5nALPvU5Gt6WDWk+6VWyQ2VgUZKIM5E+8rd7MAdtUleXKPTuYSSWuuJNHP T2hLXlNxRdtPRhwj/vFhdD7j7o9xfD6jjklYXeL8vhKMjOK0zfjAjAi4Kw4xj0kvyYnc Lz/CW0SQOlfeOOSVyqJyKEVKBOiDF2/rqOta0W5BU5s9pYgIKsPv78k32aJD3ACLS9g1 NOWlx3WuzBCF0nqjiDe3iBWZy017ip7oA8L6yJDJ3MyJaLjipE6UX0IbafUkK8K/olQj nvdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yUCFZiwK; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 v10-20020a63f20a000000b0056416c221d1si9250357pgh.581.2023.08.02.03.44.18; Wed, 02 Aug 2023 03:44:33 -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=yUCFZiwK; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S231641AbjHBKXK (ORCPT + 99 others); Wed, 2 Aug 2023 06:23:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233852AbjHBKWN (ORCPT ); Wed, 2 Aug 2023 06:22:13 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D87AE3A90 for ; Wed, 2 Aug 2023 03:21:28 -0700 (PDT) Message-ID: <20230802101933.738430630@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971686; 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=N1azWL9rFTheZgbP+psN/3Z4a3oFTh1DV0QsrK11aoI=; b=yUCFZiwKcPzwtbATJj0UlP7g1OtH6MiLqBUNiN6qAs4wlMP3lL+WJfdzZ2LYXg8WzPdjpu SxNhNdjTieF2ya7jhMX6SbAhzGoO5Tj4iubOcrFjL6CP3JHuZ6P4GSGranMF/OLug+YlcI fNi+3QYhOtfUueExHLJ9SWb23HgheRXBox19ZjH3MGGFdRaLd5jlY+lDH6U39GqfQE4oVV 6APeKinF4GQOgJMNvuaNUAkP05LtAhcd1GNPNxgyuLIWxQo+xEsiV7bg2bSNA8aeTS3+6Y Lno3E1MQYZ+aYpafF/OflWpJeF0Twg0Bl4Yeab4iraR4/9c/LdarHNyPE3O2eA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971686; 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=N1azWL9rFTheZgbP+psN/3Z4a3oFTh1DV0QsrK11aoI=; b=lyCW/RdQsnyo+KeHNp11pcWRzfKvaL1L3VyjR3GWF7Wh0zdHwyQ+rAV0HgG8tZt0Jgc1rl X67euZQmSoXeAMAg== 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 , Wei Liu Subject: [patch V3 18/40] x86/apic: Use u32 for [gs]et_apic_id() References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:26 +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,URIBL_BLOCKED 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: 1773113781219373228 X-GMAIL-MSGID: 1773113781219373228 APIC IDs are used with random data types u16, u32, int, unsigned int, unsigned long. Make it all consistently use u32 because that reflects the hardware register width. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/apic.h | 14 ++------------ arch/x86/kernel/apic/apic_flat_64.c | 4 ++-- arch/x86/kernel/apic/apic_noop.c | 2 +- arch/x86/kernel/apic/apic_numachip.c | 8 ++++---- arch/x86/kernel/apic/bigsmp_32.c | 2 +- arch/x86/kernel/apic/local.h | 4 ++-- arch/x86/kernel/apic/probe_32.c | 10 ++++++++++ arch/x86/kernel/apic/x2apic_phys.c | 4 ++-- arch/x86/kernel/apic/x2apic_uv_x.c | 2 +- arch/x86/xen/apic.c | 4 ++-- 10 files changed, 27 insertions(+), 27 deletions(-) --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -298,8 +298,8 @@ struct apic { u32 (*cpu_present_to_apicid)(int mps_cpu); u32 (*phys_pkg_id)(u32 cpuid_apic, int index_msb); - u32 (*get_apic_id)(unsigned long x); - u32 (*set_apic_id)(unsigned int id); + u32 (*get_apic_id)(u32 id); + u32 (*set_apic_id)(u32 apicid); /* wakeup_secondary_cpu */ int (*wakeup_secondary_cpu)(int apicid, unsigned long start_eip); @@ -493,16 +493,6 @@ static inline bool lapic_vector_set_in_i return !!(irr & (1U << (vector % 32))); } -static inline unsigned default_get_apic_id(unsigned long x) -{ - unsigned int ver = GET_APIC_VERSION(apic_read(APIC_LVR)); - - if (APIC_XAPIC(ver) || boot_cpu_has(X86_FEATURE_EXTD_APICID)) - return (x >> 24) & 0xFF; - else - return (x >> 24) & 0x0F; -} - /* * Warm reset vector position: */ --- a/arch/x86/kernel/apic/apic_flat_64.c +++ b/arch/x86/kernel/apic/apic_flat_64.c @@ -56,12 +56,12 @@ flat_send_IPI_mask_allbutself(const stru _flat_send_IPI_mask(mask, vector); } -static unsigned int flat_get_apic_id(unsigned long x) +static u32 flat_get_apic_id(u32 x) { return (x >> 24) & 0xFF; } -static u32 set_apic_id(unsigned int id) +static u32 set_apic_id(u32 id) { return (id & 0xFF) << 24; } --- a/arch/x86/kernel/apic/apic_noop.c +++ b/arch/x86/kernel/apic/apic_noop.c @@ -30,7 +30,7 @@ static void noop_apic_icr_write(u32 low, static int noop_wakeup_secondary_cpu(int apicid, unsigned long start_eip) { return -1; } static u64 noop_apic_icr_read(void) { return 0; } static u32 noop_phys_pkg_id(u32 cpuid_apic, int index_msb) { return 0; } -static unsigned int noop_get_apic_id(unsigned long x) { return 0; } +static u32 noop_get_apic_id(u32 apicid) { return 0; } static void noop_apic_eoi(void) { } static u32 noop_apic_read(u32 reg) --- a/arch/x86/kernel/apic/apic_numachip.c +++ b/arch/x86/kernel/apic/apic_numachip.c @@ -25,7 +25,7 @@ static const struct apic apic_numachip1; static const struct apic apic_numachip2; static void (*numachip_apic_icr_write)(int apicid, unsigned int val) __read_mostly; -static unsigned int numachip1_get_apic_id(unsigned long x) +static u32 numachip1_get_apic_id(u32 x) { unsigned long value; unsigned int id = (x >> 24) & 0xff; @@ -38,12 +38,12 @@ static unsigned int numachip1_get_apic_i return id; } -static u32 numachip1_set_apic_id(unsigned int id) +static u32 numachip1_set_apic_id(u32 id) { return (id & 0xff) << 24; } -static unsigned int numachip2_get_apic_id(unsigned long x) +static u32 numachip2_get_apic_id(u32 x) { u64 mcfg; @@ -51,7 +51,7 @@ static unsigned int numachip2_get_apic_i return ((mcfg >> (28 - 8)) & 0xfff00) | (x >> 24); } -static u32 numachip2_set_apic_id(unsigned int id) +static u32 numachip2_set_apic_id(u32 id) { return id << 24; } --- a/arch/x86/kernel/apic/bigsmp_32.c +++ b/arch/x86/kernel/apic/bigsmp_32.c @@ -13,7 +13,7 @@ #include "local.h" -static unsigned bigsmp_get_apic_id(unsigned long x) +static u32 bigsmp_get_apic_id(u32 x) { return (x >> 24) & 0xFF; } --- a/arch/x86/kernel/apic/local.h +++ b/arch/x86/kernel/apic/local.h @@ -15,8 +15,8 @@ /* X2APIC */ 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); +u32 x2apic_get_apic_id(u32 id); +u32 x2apic_set_apic_id(u32 id); u32 x2apic_phys_pkg_id(u32 initial_apicid, int index_msb); void x2apic_send_IPI_all(int vector); --- a/arch/x86/kernel/apic/probe_32.c +++ b/arch/x86/kernel/apic/probe_32.c @@ -23,6 +23,16 @@ static u32 default_phys_pkg_id(u32 cpuid return cpuid_apic >> index_msb; } +static u32 default_get_apic_id(u32 x) +{ + unsigned int ver = GET_APIC_VERSION(apic_read(APIC_LVR)); + + if (APIC_XAPIC(ver) || boot_cpu_has(X86_FEATURE_EXTD_APICID)) + return (x >> 24) & 0xFF; + else + return (x >> 24) & 0x0F; +} + /* should be called last. */ static int probe_default(void) { --- a/arch/x86/kernel/apic/x2apic_phys.c +++ b/arch/x86/kernel/apic/x2apic_phys.c @@ -124,12 +124,12 @@ static int x2apic_phys_probe(void) return apic == &apic_x2apic_phys; } -unsigned int x2apic_get_apic_id(unsigned long id) +u32 x2apic_get_apic_id(u32 id) { return id; } -u32 x2apic_set_apic_id(unsigned int id) +u32 x2apic_set_apic_id(u32 id) { return id; } --- a/arch/x86/kernel/apic/x2apic_uv_x.c +++ b/arch/x86/kernel/apic/x2apic_uv_x.c @@ -780,7 +780,7 @@ static void uv_send_IPI_all(int vector) uv_send_IPI_mask(cpu_online_mask, vector); } -static u32 set_apic_id(unsigned int id) +static u32 set_apic_id(u32 id) { return id; } --- a/arch/x86/xen/apic.c +++ b/arch/x86/xen/apic.c @@ -33,13 +33,13 @@ static unsigned int xen_io_apic_read(uns return 0xfd; } -static u32 xen_set_apic_id(unsigned int x) +static u32 xen_set_apic_id(u32 x) { WARN_ON(1); return x; } -static unsigned int xen_get_apic_id(unsigned long x) +static u32 xen_get_apic_id(u32 x) { return ((x)>>24) & 0xFFu; } From patchwork Wed Aug 2 10:21:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129766 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp371461vqx; Wed, 2 Aug 2023 04:06:10 -0700 (PDT) X-Google-Smtp-Source: APBJJlEed7DDrflFp+yKEvlCPGuTF5Gn7cFYlpuHolCiP29UVx1lwobo3K44uG0C/mvlzhpdnTbA X-Received: by 2002:a17:907:75ed:b0:98c:eef2:d0bc with SMTP id jz13-20020a17090775ed00b0098ceef2d0bcmr4718923ejc.12.1690974369770; Wed, 02 Aug 2023 04:06:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690974369; cv=none; d=google.com; s=arc-20160816; b=vpK3r/UBeizcrbd6Inrmk/UTdkyeX2O5qwc7dLP/2RMQxC2AxsdipA0uQTch0kMzO2 sg1LmdhznbZGu0NyuKvSe3nWyMZfxQEY9nTSV5VEp4RvBkU/3JobU9ICqsYCJqT15QBy bOIQ4tyrUIGc0MWfnsE2//BIl5zlTfmvUdwHvgQjlTGvE9O3P1t3fkfPIewKpSIiVtdl jddB8cT0Ma1z1jPl+m/fbpwLFqOIqV+gb59QSlw8+GnVVgTjZjsQ5fqFmN23Wb6KSPGQ AHbclv7D5nwWb3e3+Tw/3RDgvlSCK1vq1AvBAbb5HO2LfIgo7EzOgxBOOEZfvcWH5wYs nesQ== 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=FP9+8UUFC+luO8OcXcamwcORXtn0BV1u0AzA92zNiiM=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=nfWG4tOWGcbuhv6bfn9GUXa4+vpruI3v0dHQAzuUgVgoQSelFFRDz0V66nrdCcwLd6 UmChvmFouRHCYvic54byXmJ8sbbwrRgPwK+OTY2p6S+TboMygttZXVKegsI9LAdgEkYI 9iI+n6CRjZIoh0NNbEPRG7RlPnWlV3qvClccR2kUSJ1x570l+tYu42Hxt28AnpJlZsIT oZaouHZhEyvrIgk+4Drm3O29CD16Km6sIbr2oJiBimNNp7Q4MCyForKZZC5amsWKoLHb 62j2BNOkxp5Y712VNp+HXOrsBsSBdeRwVgYVo382hZrjj3oqrzsd1/7svmpP2sr+CZBC Kn5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=UDCJRsY7; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=LaJQ2tpY; 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 z13-20020a170906240d00b0098e1bbc3db1si1686559eja.791.2023.08.02.04.05.35; Wed, 02 Aug 2023 04:06:09 -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=UDCJRsY7; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=LaJQ2tpY; 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 S233242AbjHBKXN (ORCPT + 99 others); Wed, 2 Aug 2023 06:23:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233853AbjHBKWN (ORCPT ); Wed, 2 Aug 2023 06:22:13 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 822423AAC for ; Wed, 2 Aug 2023 03:21:30 -0700 (PDT) Message-ID: <20230802101933.795537847@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971688; 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=FP9+8UUFC+luO8OcXcamwcORXtn0BV1u0AzA92zNiiM=; b=UDCJRsY7xOVZbTBSPNlunJ//MLMPSDlgWamRSnfet3Ux04wyTu5jssrf8jdkHWYVOgW+rC s2xNNGbbhtGb56yaN5uAu3AfRN6ho5xbtHNRqgbqs7HkSqpuSvmUuE7BuU5QQ4RsXIe+GJ 5arFZ75TVbvINPEo95LUQTOeZ+mxoDKrmY0eKxw6jsW3EOwGrxz+xDl3elvG9YzN2HkSkp IYaLtPdrNBACqRsfLIYoxeGaT1Nb2YCw24yjBI8721mVBFymCfbWnspU3AHhn1VVgYE+Pm j+eKHDpalWZrUMZOnsBQskSgf+94NashZJOLemgzmsXDAJfMIZpkaBNNsSq9/Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971688; 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=FP9+8UUFC+luO8OcXcamwcORXtn0BV1u0AzA92zNiiM=; b=LaJQ2tpYz3IyuBmlFAxSP60yNvYYwbJ9ZgyaRBkkTvTOBCG0Cpk2sBYchDjtCkUITl8+Rc fJ6z2KYt30ISm+CQ== 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 , Wei Liu Subject: [patch V3 19/40] x86/apic: Use u32 for wakeup_secondary_cpu[_64]() References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:27 +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,URIBL_BLOCKED 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: 1773115140286055474 X-GMAIL-MSGID: 1773115140286055474 APIC IDs are used with random data types u16, u32, int, unsigned int, unsigned long. Make it all consistently use u32 because that reflects the hardware register width. Signed-off-by: Thomas Gleixner Reviewed-by: Arjan van de Ven --- arch/x86/hyperv/hv_vtl.c | 2 +- arch/x86/include/asm/apic.h | 8 ++++---- arch/x86/kernel/acpi/boot.c | 2 +- arch/x86/kernel/apic/apic_noop.c | 2 +- arch/x86/kernel/apic/apic_numachip.c | 2 +- arch/x86/kernel/apic/x2apic_uv_x.c | 2 +- arch/x86/kernel/sev.c | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) --- a/arch/x86/hyperv/hv_vtl.c +++ b/arch/x86/hyperv/hv_vtl.c @@ -192,7 +192,7 @@ static int hv_vtl_apicid_to_vp_id(u32 ap return ret; } -static int hv_vtl_wakeup_secondary_cpu(int apicid, unsigned long start_eip) +static int hv_vtl_wakeup_secondary_cpu(u32 apicid, unsigned long start_eip) { int vp_id; --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -302,9 +302,9 @@ struct apic { u32 (*set_apic_id)(u32 apicid); /* wakeup_secondary_cpu */ - int (*wakeup_secondary_cpu)(int apicid, unsigned long start_eip); + int (*wakeup_secondary_cpu)(u32 apicid, unsigned long start_eip); /* wakeup secondary CPU using 64-bit wakeup point */ - int (*wakeup_secondary_cpu_64)(int apicid, unsigned long start_eip); + int (*wakeup_secondary_cpu_64)(u32 apicid, unsigned long start_eip); char *name; }; @@ -322,8 +322,8 @@ struct apic_override { void (*send_IPI_self)(int vector); u64 (*icr_read)(void); void (*icr_write)(u32 low, u32 high); - int (*wakeup_secondary_cpu)(int apicid, unsigned long start_eip); - int (*wakeup_secondary_cpu_64)(int apicid, unsigned long start_eip); + int (*wakeup_secondary_cpu)(u32 apicid, unsigned long start_eip); + int (*wakeup_secondary_cpu_64)(u32 apicid, unsigned long start_eip); }; /* --- a/arch/x86/kernel/acpi/boot.c +++ b/arch/x86/kernel/acpi/boot.c @@ -358,7 +358,7 @@ acpi_parse_lapic_nmi(union acpi_subtable } #ifdef CONFIG_X86_64 -static int acpi_wakeup_cpu(int apicid, unsigned long start_ip) +static int acpi_wakeup_cpu(u32 apicid, unsigned long start_ip) { /* * Remap mailbox memory only for the first call to acpi_wakeup_cpu(). --- a/arch/x86/kernel/apic/apic_noop.c +++ b/arch/x86/kernel/apic/apic_noop.c @@ -27,7 +27,7 @@ static void noop_send_IPI_allbutself(int static void noop_send_IPI_all(int vector) { } static void noop_send_IPI_self(int vector) { } static void noop_apic_icr_write(u32 low, u32 id) { } -static int noop_wakeup_secondary_cpu(int apicid, unsigned long start_eip) { return -1; } +static int noop_wakeup_secondary_cpu(u32 apicid, unsigned long start_eip) { return -1; } static u64 noop_apic_icr_read(void) { return 0; } static u32 noop_phys_pkg_id(u32 cpuid_apic, int index_msb) { return 0; } static u32 noop_get_apic_id(u32 apicid) { return 0; } --- a/arch/x86/kernel/apic/apic_numachip.c +++ b/arch/x86/kernel/apic/apic_numachip.c @@ -71,7 +71,7 @@ static void numachip2_apic_icr_write(int numachip2_write32_lcsr(NUMACHIP2_APIC_ICR, (apicid << 12) | val); } -static int numachip_wakeup_secondary(int phys_apicid, unsigned long start_rip) +static int numachip_wakeup_secondary(u32 phys_apicid, unsigned long start_rip) { numachip_apic_icr_write(phys_apicid, APIC_DM_INIT); numachip_apic_icr_write(phys_apicid, APIC_DM_STARTUP | --- a/arch/x86/kernel/apic/x2apic_uv_x.c +++ b/arch/x86/kernel/apic/x2apic_uv_x.c @@ -702,7 +702,7 @@ static __init void build_uv_gr_table(voi } } -static int uv_wakeup_secondary(int phys_apicid, unsigned long start_rip) +static int uv_wakeup_secondary(u32 phys_apicid, unsigned long start_rip) { unsigned long val; int pnode; --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -940,7 +940,7 @@ static void snp_cleanup_vmsa(struct sev_ free_page((unsigned long)vmsa); } -static int wakeup_cpu_via_vmgexit(int apic_id, unsigned long start_ip) +static int wakeup_cpu_via_vmgexit(u32 apic_id, unsigned long start_ip) { struct sev_es_save_area *cur_vmsa, *vmsa; struct ghcb_state state; From patchwork Wed Aug 2 10:21:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129783 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp387960vqx; Wed, 2 Aug 2023 04:36:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlFFKhfV0U8UFNVe3qnN/MfplIXGyt5JC/UfoPX9mV88I3JyFnYqYBOA0gzerycpKB75d9Ie X-Received: by 2002:a17:90a:600e:b0:263:43c6:69ac with SMTP id y14-20020a17090a600e00b0026343c669acmr12728594pji.44.1690976194776; Wed, 02 Aug 2023 04:36:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690976194; cv=none; d=google.com; s=arc-20160816; b=tT+kVIrLoQLKw//6Fm27mlddswK0SngLQPHYpqKCxsghPCyRoXq3prCHcMR9Z2NyB4 9zSO6HE4TFXSDl2WnCcY3fnjHkq7mj++TIpva8J0J0uqgtN+gF824C43N1bD2xDH3tEI 3UsBE1aSGhbyVhWPzyppOPgVhx+3gumqT152RG2RmXxSnXHO5dA80b+bPQaiNjHqCffe 32Bie8TPSAZKn11Xq5xXngXoEuSWOl22rBbJtzcIcq5H2/D4TMjenovpfItp6E0+2qKH 2G4+SXjqX698ldaCyk/t5EAFP/ZHST3WavIjo2JEf5pZ7sxDII6QwHFvdstlI7cJV96c 56RA== 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=LotaVQs4RlrtT3Fsb/omzWTh9eCCKi/NbM3QS9xGwX0=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=AMWtT0x7I3nDAMRXivA5ljvLlhZLIFoLjPZ3nJ+hXbPMRAAzW/nGZgFcKHsBn2Xex+ c4uDcJ1n5Z2aZpuqnlbDWYPwMIX8ESYDkdyiikhY7Kn3d4p+g9W4ryp1dw2Qh9MoRTQz q1clD+3OQ/qZqUmJzhlPKLhw03x5fZrYKKpC8W1ycItTLYQpLskKEIOa6d+15zTntkQx VMzFe3dhM36cYK1Q7qChWhUbpuXiBgSH+8VVOJQ5tkHp2zSl3j2+2nTNkPlTnhZSAsmL zGKoJQeBcXT3EZVWEbdtVu2+zsBx2X9qEeITvUQDDcggJxwVhTnjho7VKs8Rhqlr28rY wi/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3+1CRZOH; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=TEVcK9WD; 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 z17-20020a17090acb1100b00262ffca5a31si1064149pjt.161.2023.08.02.04.36.20; Wed, 02 Aug 2023 04:36:34 -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=3+1CRZOH; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=TEVcK9WD; 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 S233466AbjHBKXQ (ORCPT + 99 others); Wed, 2 Aug 2023 06:23:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233882AbjHBKWT (ORCPT ); Wed, 2 Aug 2023 06:22:19 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41E183C10 for ; Wed, 2 Aug 2023 03:21:31 -0700 (PDT) Message-ID: <20230802101933.851562883@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971689; 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=LotaVQs4RlrtT3Fsb/omzWTh9eCCKi/NbM3QS9xGwX0=; b=3+1CRZOHLadMK2buL1hvcuEaY0ehlTPlFQhoQDmjk7fQjFMH/6/XumNG6YttAS1sIPZiM5 CdNsecfkWmu7keu+pnwV+H705jVmI0ekSLVJ8CC3H8CN+PDsXCa/gtfjgoNThvwa/ODJnx BgTk3tX3E/2R6XGeE4o7kZB+bNuggNxbwrO2iAx9JyUct/xWf3oA4t7n66/mWc5IaGTtrd ngBZtgRPv0f3nlJcA+qZiyyj07ZG+wv/GtsdUzg7qTnmoOdi0vz4cdWiW/jsBa9T7bYMnC B2Qyc3Vj+u76vvbsov+cHVZ3ATBmWhaGDxunvCOsSJAUDo3JxT15IpIt3Rffqw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971689; 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=LotaVQs4RlrtT3Fsb/omzWTh9eCCKi/NbM3QS9xGwX0=; b=TEVcK9WDKByA+bUuUzKp1CXx7HekO8ho4tpYNxgCmCPdxy1CwTZ0kTBvRszuYS4TjSSpiU tISU80qHRnKedPDg== 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 , Wei Liu Subject: [patch V3 20/40] x86/cpu/topology: Cure the abuse of cpuinfo for persisting logical ids References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:29 +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,URIBL_BLOCKED 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: 1773117054643787418 X-GMAIL-MSGID: 1773117054643787418 Per CPU cpuinfo is used to persist the logical package and die IDs. That's really not the right place simply because cpuinfo is subject to be reinitialized when a CPU goes through an offline/online cycle. This works by chance today, but that's far from correct and neither obvious nor documented. Add a per cpu datastructure which persists those logical IDs, which allows to cleanup the CPUID evaluation code. This is a temporary workaround until the larger topology management is in place, which makes all of this logical management mechanics obsolete. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/smpboot.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -124,7 +124,20 @@ struct mwait_cpu_dead { */ static DEFINE_PER_CPU_ALIGNED(struct mwait_cpu_dead, mwait_cpu_dead); -/* Logical package management. We might want to allocate that dynamically */ +/* Logical package management. */ +struct logical_maps { + u32 phys_pkg_id; + u32 phys_die_id; + u32 logical_pkg_id; + u32 logical_die_id; +}; + +/* Temporary workaround until the full topology mechanics is in place */ +static DEFINE_PER_CPU_READ_MOSTLY(struct logical_maps, logical_maps) = { + .phys_pkg_id = U32_MAX, + .phys_die_id = U32_MAX, +}; + unsigned int __max_logical_packages __read_mostly; EXPORT_SYMBOL(__max_logical_packages); static unsigned int logical_packages __read_mostly; @@ -345,10 +358,8 @@ int topology_phys_to_logical_pkg(unsigne int cpu; for_each_possible_cpu(cpu) { - struct cpuinfo_x86 *c = &cpu_data(cpu); - - if (c->initialized && c->topo.pkg_id == phys_pkg) - return c->topo.logical_pkg_id; + if (per_cpu(logical_maps.phys_pkg_id, cpu) == phys_pkg) + return per_cpu(logical_maps.logical_pkg_id, cpu); } return -1; } @@ -366,11 +377,9 @@ static int topology_phys_to_logical_die( int cpu, proc_id = cpu_data(cur_cpu).topo.pkg_id; for_each_possible_cpu(cpu) { - struct cpuinfo_x86 *c = &cpu_data(cpu); - - if (c->initialized && c->topo.die_id == die_id && - c->topo.pkg_id == proc_id) - return c->topo.logical_die_id; + if (per_cpu(logical_maps.phys_pkg_id, cpu) == proc_id && + per_cpu(logical_maps.phys_die_id, cpu) == die_id) + return per_cpu(logical_maps.logical_die_id, cpu); } return -1; } @@ -395,6 +404,8 @@ int topology_update_package_map(unsigned cpu, pkg, new); } found: + per_cpu(logical_maps.phys_pkg_id, cpu) = pkg; + per_cpu(logical_maps.logical_pkg_id, cpu) = new; cpu_data(cpu).topo.logical_pkg_id = new; return 0; } @@ -418,6 +429,8 @@ int topology_update_die_map(unsigned int cpu, die, new); } found: + per_cpu(logical_maps.phys_die_id, cpu) = die; + per_cpu(logical_maps.logical_die_id, cpu) = new; cpu_data(cpu).topo.logical_die_id = new; return 0; } From patchwork Wed Aug 2 10:21:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129777 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp381268vqx; Wed, 2 Aug 2023 04:24:07 -0700 (PDT) X-Google-Smtp-Source: APBJJlGHXl8z2CXcRi3QtFK+3ltp4y9uAgTjYpTfo7miBtl6D2z/sIY7Uis1aTWGzFMYjj159ilC X-Received: by 2002:a17:90a:108:b0:268:3ae2:410d with SMTP id b8-20020a17090a010800b002683ae2410dmr13095230pjb.19.1690975447191; Wed, 02 Aug 2023 04:24:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690975447; cv=none; d=google.com; s=arc-20160816; b=MopTy46w/QbgVHDh38vFKqQFS+0j2ZdSGLWzmeMKTT9+t4glJUy/PJFVY2G5Rt9x7o Ju+/v7WFFQ0zpjzi8Dyuzxe1JFHoo3DBugNjfK57+2F7m1G/W6y58VS8zZOZdydprjUp LCE8au4zaRJ/RVA+yY7H7j9E80NxE6IlnuHF3U69tUCDdmBWcN/IIKVr/tT/pkrbKiu2 JwpMphUzZ15881sQ8LQ61JUPca8RjxlEog+YauXSdkNpmVJztI6+J9zvF58+7VAcFGLj LjW1tVmlHfVPUm2sIqi/JEuKLJwjyWsN9Txy/W615l4tXKD1zfPv4SjTfaTIKODomvPM aglg== 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=9zBm+dKZt6w5V4gKJ+yewF1N/306E3qiR6jGUmt6Y6U=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=iblnq6e+CAY+OVJrD6RwZvXJUWtqoFEnn9XGCTqmF+Mrear6MGE+r6TJAfs1tT8G/u xxAQndZeJoGE0zS0QbeEA7I2nOIw9OwAlZPz8eWylooOD2V6uSHtlTgpBKstcHXYA2/N lrj5KUVEpTrlyQCSFKgQTnEHfX18EDh0L3Z1TDQD3gu1YD9OoJ0sB0enzyXIE2lzNkIy mMbDIDhVMq/L++cPjvLLn5HVMmC2zLW8MGhaCXcWwB1NqPLgR3ur5wZ0jqX0LOOcq6XJ DDCbiI6RY+ptE3VCqADEJhScEGAbhP3024kBFxowPDLqlV+sb50j7jWgHWbkSXXeQABg ZeuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Pxy0Qvnc; 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 mg12-20020a17090b370c00b0025bdaaf0d17si1072334pjb.33.2023.08.02.04.23.52; Wed, 02 Aug 2023 04:24:07 -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=Pxy0Qvnc; 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 S233737AbjHBKXX (ORCPT + 99 others); Wed, 2 Aug 2023 06:23:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233816AbjHBKWw (ORCPT ); Wed, 2 Aug 2023 06:22:52 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C70C3C34 for ; Wed, 2 Aug 2023 03:21:36 -0700 (PDT) Message-ID: <20230802101933.911894916@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971691; 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=9zBm+dKZt6w5V4gKJ+yewF1N/306E3qiR6jGUmt6Y6U=; b=Pxy0Qvnch1yLs4uL072wfyfwd4yJnHCyyo26DZ12ASdRFYJvzExiQsszIXVz0x1Macf3IC AZk9zUGQbM83niPrtcbk2c65RTnoT+TqrYYDDePoWMsAhNLGjwjw17AYRLMyGqzA78rIv8 DbUCodrnc6jOsJJVwJcu0YIPYeIWxDpBGp+oDgrM7vuAqQaedz2u0aKsePR52Oa2sH3B+s 4JjX4/SM1BDeRfAe3md9xaoT1tE4AwaHGOqjUgYwZy0csaYQhi0DdbVSzw4FuR0ULS3jsI dUepnl0hIe01NNwKSlgtGoOqZ5px61PmIHHDJnve5bEzy78lUr0C8IBeERlu9Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971691; 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=9zBm+dKZt6w5V4gKJ+yewF1N/306E3qiR6jGUmt6Y6U=; b=eH2IHH6qhRiV/Y3LMw2HbRF9VnDUty1uQ6T6yGbslsVvjhX09U/bsQvx+6xAjBHeUlyn2r 4VGnog+JfPt6nUBw== 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 , Wei Liu Subject: [patch V3 21/40] x86/cpu: Provide debug interface References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:30 +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,URIBL_BLOCKED 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: 1773116270356295416 X-GMAIL-MSGID: 1773116270356295416 Provide debug files which dump the topology related information of cpuinfo_x86. This is useful to validate the upcoming conversion of the topology evaluation for correctness or bug compatibility. Signed-off-by: Thomas Gleixner --- V2: Don't return ENODEV when offline and make online a field. --- arch/x86/kernel/cpu/Makefile | 2 + arch/x86/kernel/cpu/debugfs.c | 58 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile @@ -54,6 +54,8 @@ obj-$(CONFIG_X86_LOCAL_APIC) += perfctr obj-$(CONFIG_HYPERVISOR_GUEST) += vmware.o hypervisor.o mshyperv.o obj-$(CONFIG_ACRN_GUEST) += acrn.o +obj-$(CONFIG_DEBUG_FS) += debugfs.o + quiet_cmd_mkcapflags = MKCAP $@ cmd_mkcapflags = $(CONFIG_SHELL) $(srctree)/$(src)/mkcapflags.sh $@ $^ --- /dev/null +++ b/arch/x86/kernel/cpu/debugfs.c @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include + +#include +#include + +static int cpu_debug_show(struct seq_file *m, void *p) +{ + unsigned long cpu = (unsigned long)m->private; + struct cpuinfo_x86 *c = per_cpu_ptr(&cpu_info, cpu); + + seq_printf(m, "online: %d\n", cpu_online(cpu)); + if (!c->initialized) + return 0; + + seq_printf(m, "initial_apicid: %x\n", c->topo.initial_apicid); + seq_printf(m, "apicid: %x\n", c->topo.apicid); + seq_printf(m, "pkg_id: %u\n", c->topo.pkg_id); + seq_printf(m, "die_id: %u\n", c->topo.die_id); + seq_printf(m, "cu_id: %u\n", c->topo.cu_id); + seq_printf(m, "core_id: %u\n", c->topo.core_id); + seq_printf(m, "logical_pkg_id: %u\n", c->topo.logical_pkg_id); + seq_printf(m, "logical_die_id: %u\n", c->topo.logical_die_id); + seq_printf(m, "llc_id: %u\n", c->topo.llc_id); + seq_printf(m, "l2c_id: %u\n", c->topo.l2c_id); + seq_printf(m, "max_cores: %u\n", c->x86_max_cores); + seq_printf(m, "max_die_per_pkg: %u\n", __max_die_per_package); + seq_printf(m, "smp_num_siblings: %u\n", smp_num_siblings); + return 0; +} + +static int cpu_debug_open(struct inode *inode, struct file *file) +{ + return single_open(file, cpu_debug_show, inode->i_private); +} + +static const struct file_operations dfs_cpu_ops = { + .open = cpu_debug_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static __init int cpu_init_debugfs(void) +{ + struct dentry *dir, *base = debugfs_create_dir("topo", arch_debugfs_dir); + unsigned long id; + char name[10]; + + dir = debugfs_create_dir("cpus", base); + for_each_possible_cpu(id) { + sprintf(name, "%lu", id); + debugfs_create_file(name, 0444, dir, (void *)id, &dfs_cpu_ops); + } + return 0; +} +late_initcall(cpu_init_debugfs); From patchwork Wed Aug 2 10:21:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129805 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp410670vqx; Wed, 2 Aug 2023 05:15:06 -0700 (PDT) X-Google-Smtp-Source: APBJJlHZZ5wFrs5RCiOzOb7++Us/aH38YKjfbxnyQsEFIvEBHPIGt6ajxWk9mwzavqRPniZYJ4fQ X-Received: by 2002:a17:902:d4cb:b0:1b3:f5c7:4e75 with SMTP id o11-20020a170902d4cb00b001b3f5c74e75mr16740581plg.58.1690978506334; Wed, 02 Aug 2023 05:15:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690978506; cv=none; d=google.com; s=arc-20160816; b=Puc4TPyyREdma5NHiwcp3EqYn5Qx/BcV6172Ck078Ruovw4MAJGHXuj2CZaos4HF95 V8PrpgeCUVymdx9IzGUnvPTCyTsClEXzoiIiZPBBmP93fWK+rCNQ/xOoY74lMLdNH4uo LjZK8mmwJn1QiCGJB4b9gDey8V5jxZYlZFXtDiOVrrhAsNAcBlI7EsFJR8gJibgwmkp3 kiMXcWECL+p3pM5dLSIi/oAETGBfS4U4YQ/22ekxb4hF+28gB76De2u42Fc87BE4GVIb nkwFnyb5x7Pe1OHQYPWJbNc1aZkeES0lB3SXPBRKDCaAF7qp6Cz/Gq1NmUUc+gWn7duy A8Yg== 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=RMPH9HSrX/vWRmKrh1k0g9K+DpbMWcgkkNBWT1U3b5k=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=v15fc38dxgDez+J7MxtfB/HmEEGlJIwT/008fR5v5yLsVTH5ST3OR4xYN0RzuS534B Cg/L3vUHi1FchtRCWhflHSJFCpBnRa+FgcQBOnCbg/ZT08Rdt7a7kn2/OD28N9v+o87X wBfTF3WEj+pez2kSsHlSteW1mJyh+p83rW0/umeUUjRghLOVJynEIpT3mlSoXiqixRKL vUzgAHcf5wk9Ui2rjKcdAx5ewlg5cgY66pu18ESNYnvDLTIe0wzt7IwOitxK4y1gFvpn 7AlihDzef7PcqwFwJugl/sBZJne7T2Cg3mUMuKY+47ZH4cvTtUiunQBCIO994X0ll8iO x1gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=R9NttLjM; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 p17-20020a170902e35100b001bbcf3bc9d3si10282352plc.384.2023.08.02.05.14.51; Wed, 02 Aug 2023 05:15:06 -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=R9NttLjM; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S233982AbjHBKXi (ORCPT + 99 others); Wed, 2 Aug 2023 06:23:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234218AbjHBKXA (ORCPT ); Wed, 2 Aug 2023 06:23:00 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C098422B for ; Wed, 2 Aug 2023 03:21:45 -0700 (PDT) Message-ID: <20230802101933.968971205@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971692; 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=RMPH9HSrX/vWRmKrh1k0g9K+DpbMWcgkkNBWT1U3b5k=; b=R9NttLjMcnAJ8p2lO24QRYY9kpfuGK/BTdKHAjpxVUzHiuqKFwqWl4QOB6y9PfyRdeQnwI MtEdu4I7E8j4ORYanITmbdi5dU25hNuozYkGReZGEf8qHN5nZ6xy2eUj8ZUVcLhLxRrtZH e9LJoBQYbhRPMMT8HZ+CpQSuWLKaSXRWDUQyghmC7hEJwmqvISjr3j2X76OE79UoInooHI p+74RrhxxZQp9E2ZxKu27JYlwgpTgh3hD8LD5I/5J0fbTwoimW7kksiQnHziQQRgdPwqM9 o5523rpWXSUcWzDFJDQAJIodAICgD9nr4NKwts0zCOz/AdUobvWNiEzoGNkLvA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971692; 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=RMPH9HSrX/vWRmKrh1k0g9K+DpbMWcgkkNBWT1U3b5k=; b=itBmo4u5rRN3f8Sjomd8pTktY24hZ4kn85GxAM7rphcVRzIMNn5WcYkM6xpsINx803Ljld RsbDQK9r8GBa43AA== 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 , Wei Liu Subject: [patch V3 22/40] x86/cpu: Provide cpuid_read() et al. References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:32 +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,URIBL_BLOCKED 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: 1773119478692402009 X-GMAIL-MSGID: 1773119478692402009 Provide a few helper functions to read CPUID leafs or individual registers into a data structure without requiring unions. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/cpuid.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) --- a/arch/x86/include/asm/cpuid.h +++ b/arch/x86/include/asm/cpuid.h @@ -127,6 +127,42 @@ static inline unsigned int cpuid_edx(uns return edx; } +static inline void __cpuid_read(unsigned int leaf, unsigned int subleaf, u32 *regs) +{ + regs[CPUID_EAX] = leaf; + regs[CPUID_ECX] = subleaf; + __cpuid(regs, regs + 1, regs + 2, regs + 3); +} + +#define cpuid_subleaf(leaf, subleaf, regs) { \ + BUILD_BUG_ON(sizeof(*(regs)) != 16); \ + __cpuid_read(leaf, subleaf, (u32 *)(regs)); \ +} + +#define cpuid_leaf(leaf, regs) { \ + BUILD_BUG_ON(sizeof(*(regs)) != 16); \ + __cpuid_read(leaf, 0, (u32 *)(regs)); \ +} + +static inline void __cpuid_read_reg(unsigned int leaf, unsigned int subleaf, + enum cpuid_regs_idx regidx, u32 *reg) +{ + u32 regs[4]; + + __cpuid_read(leaf, subleaf, regs); + *reg = regs[regidx]; +} + +#define cpuid_subleaf_reg(leaf, subleaf, regidx, reg) { \ + BUILD_BUG_ON(sizeof(*(reg)) != 4); \ + __cpuid_read_reg(leaf, subleaf, regidx, (u32 *)(reg)); \ +} + +#define cpuid_leaf_reg(leaf, regidx, reg) { \ + BUILD_BUG_ON(sizeof(*(reg)) != 4); \ + __cpuid_read_reg(leaf, 0, regidx, (u32 *)(reg)); \ +} + static __always_inline bool cpuid_function_is_indexed(u32 function) { switch (function) { From patchwork Wed Aug 2 10:21:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129797 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp408545vqx; Wed, 2 Aug 2023 05:11:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHV1ZEpOdLdW4Dqt5d8OQSiZYd5qPkZQRz2rs9zcUTeSVL+cuybsVMOa8/o1DqM5nryvYwX X-Received: by 2002:a17:902:9b83:b0:1b8:b3f9:58eb with SMTP id y3-20020a1709029b8300b001b8b3f958ebmr10881plp.31.1690978307824; Wed, 02 Aug 2023 05:11:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690978307; cv=none; d=google.com; s=arc-20160816; b=id3cQ+/d/lQIPUCSn1Dn9YqIrzPWiRHvamZWp19PVrcme7hmM6KWXV0zNEUX0kynQO nbA4+p4ScANcuJDV1xPAQSyvK34OH0IWsNCf+pE/G92iyYwOt9OUyFRVRxf328hh/0fB bVyAVb5uxnk+igykUCUzb1YqstDxNGI8OwX+DFNjq8egdjPOfBN3yN1kmmvXCbs/1bqk O/cloodWzsr4UQTZCL8cxVZb1N9WFAa5adAsQGMWH7RG9NRlQdQwbNuePUZJtOXrp9aP soKJ/g22PnroW7QCNGPC0jaajKq8pKV4Wv0oTD9cu8PE0DYgL23Bz8McTKyHFbC1KUdb y9Nw== 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=43zYzwQS69RJaIJar1DaseAOmt2WmHAdS5J/9APpIJI=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=LD3czvXCtmsxKMpeVLKjGIWvJZSWqntUrE3lgjwEHlAzCIK0VIV0ZsLZ6mkOQo88WP rXfixY9vLm76QiLPPOsjtJbK6yZZg1jt7s3JskxIrHOXBkvaEr9BPqB4iSBpG4U5lCf9 wuwBeWIaGn2OVrWrrKXSLqNxkHtWyfka/LRWiEX5T+C+VT7GXBbCtw/t3LWvu43saS84 05oD7cyThhhRhU9tQHMWJhACDZE9QSH7ol4HgHecjHPDi3ImW1r5dsT82rx8lAPSLSII 3p/pj5v26narRikQxu410hNh2II6/P5MdgU1YPmJbwGBI7wmYSLA5NNxKy0FYlBQDe9Y gvsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="F4LqRZp/"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=aZUVSLor; 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 y9-20020a17090322c900b001bc35017804si1052335plg.443.2023.08.02.05.11.09; Wed, 02 Aug 2023 05:11:47 -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="F4LqRZp/"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=aZUVSLor; 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 S233906AbjHBKXd (ORCPT + 99 others); Wed, 2 Aug 2023 06:23:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234007AbjHBKWz (ORCPT ); Wed, 2 Aug 2023 06:22:55 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D2BE420E for ; Wed, 2 Aug 2023 03:21:39 -0700 (PDT) Message-ID: <20230802101934.026097251@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971694; 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=43zYzwQS69RJaIJar1DaseAOmt2WmHAdS5J/9APpIJI=; b=F4LqRZp/A7EIsTeHkloOOHAja3xfQ1m+jmPIAvbG1shkAKDUEYavXoqUjjvDEwscUzYYmi 5K5Bn7I/oNnZer5GeUV2ECdhHrc5mKeqeJMZws/j7ikk1S12AB4Zg9bZcrHgdGd9efRDrQ 0wafnneii58lSTr4c3GDx2Zi4L3fGyBuTRXuNX9eTqYpYlSfcP/xsCNbOzJ57wZaKfPxU0 D5IzkInRVi8tsLRtg12PXz0CCzg7ravfthvHmDWm7DBS5QEodgN+LqaimeSdeVwM3Rqr91 4MChnLLDvB3+w+mdXWTV2gHBuLFg7YUmDHGToEFgLZ65wDE3bfjf45Une9xF+A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971694; 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=43zYzwQS69RJaIJar1DaseAOmt2WmHAdS5J/9APpIJI=; b=aZUVSLorXA79KsVwDqEpgPxSEKh19Dxqb8gk1E4f4JSGL/rffvLkdoUE+Wxmnnr9Mfxu4Q 4kdtM5cCFdOvITBw== 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 , Wei Liu Subject: [patch V3 23/40] x86/cpu: Provide cpu_init/parse_topology() References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:33 +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,URIBL_BLOCKED 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: 1773119270319321275 X-GMAIL-MSGID: 1773119270319321275 Topology evaluation is a complete disaster and impenetrable mess. It's scattered all over the place with some vendor implementations doing early evaluation and some not. The most horrific part is the permanent overwriting of smt_max_siblings and __max_die_per_package, instead of establishing them once on the boot CPU and validating the result on the APs. The goals are: - One topology evaluation entry point - Proper sharing of pointlessly duplicated code - Proper structuring of the evaluation logic and preferences. - Evaluating important system wide information only once on the boot CPU - Making the 0xb/0x1f leaf parsing less convoluted and actually fixing the short comings of leaf 0x1f evaluation. Start to consolidate the topology evaluation code by providing the entry points for the early boot CPU evaluation and for the final parsing on the boot CPU and the APs. Move the trivial pieces into that new code: - The initialization of cpuinfo_x86::topo - The evaluation of CPUID leaf 1, which presets topo::initial_apicid - topo_apicid is set to topo::initial_apicid when invoked from early boot. When invoked for the final evaluation on the boot CPU it reads the actual APIC ID, which makes apic_get_initial_apicid() obsolete once everything is converted over. Provide a temporary helper function topo_converted() which shields off the not yet converted CPU vendors from invoking code which would break them. This shielding covers all vendor CPUs which support SMP, but not the historical pure UP ones as they only need the topology info init and eventually the initial APIC initialization. Provide two new members in cpuinfo_x86::topo to store the maximum number of SMT siblings and the number of dies per package and add them to the debugfs readout. These two members will be used to populate this information on the boot CPU and to validate the APs against it. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/topology.h | 19 +++ arch/x86/kernel/cpu/Makefile | 3 arch/x86/kernel/cpu/common.c | 23 +--- arch/x86/kernel/cpu/cpu.h | 6 + arch/x86/kernel/cpu/debugfs.c | 37 ++++++ arch/x86/kernel/cpu/topology.h | 31 +++++ arch/x86/kernel/cpu/topology_common.c | 187 ++++++++++++++++++++++++++++++++++ 7 files changed, 289 insertions(+), 17 deletions(-) --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -102,6 +102,25 @@ static inline void setup_node_to_cpumask #include +/* Topology information */ +enum x86_topology_domains { + TOPO_SMT_DOMAIN, + TOPO_CORE_DOMAIN, + TOPO_MODULE_DOMAIN, + TOPO_TILE_DOMAIN, + TOPO_DIE_DOMAIN, + TOPO_PKG_DOMAIN, + TOPO_ROOT_DOMAIN, + TOPO_MAX_DOMAIN, +}; + +struct x86_topology_system { + unsigned int dom_shifts[TOPO_MAX_DOMAIN]; + unsigned int dom_size[TOPO_MAX_DOMAIN]; +}; + +extern struct x86_topology_system x86_topo_system; + extern const struct cpumask *cpu_coregroup_mask(int cpu); extern const struct cpumask *cpu_clustergroup_mask(int cpu); --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile @@ -17,7 +17,8 @@ KMSAN_SANITIZE_common.o := n # As above, instrumenting secondary CPU boot code causes boot hangs. KCSAN_SANITIZE_common.o := n -obj-y := cacheinfo.o scattered.o topology.o +obj-y := cacheinfo.o scattered.o +obj-y += topology_common.o topology.o obj-y += common.o obj-y += rdrand.o obj-y += match.o --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1553,6 +1553,8 @@ static void __init early_identify_cpu(st setup_force_cpu_cap(X86_FEATURE_CPUID); cpu_parse_early_param(); + cpu_init_topology(c); + if (this_cpu->c_early_init) this_cpu->c_early_init(c); @@ -1563,6 +1565,7 @@ static void __init early_identify_cpu(st this_cpu->c_bsp_init(c); } else { setup_clear_cpu_cap(X86_FEATURE_CPUID); + cpu_init_topology(c); } setup_force_cpu_cap(X86_FEATURE_ALWAYS); @@ -1708,18 +1711,6 @@ static void generic_identify(struct cpui get_cpu_address_sizes(c); - if (c->cpuid_level >= 0x00000001) { - c->topo.initial_apicid = (cpuid_ebx(1) >> 24) & 0xFF; -#ifdef CONFIG_X86_32 -# ifdef CONFIG_SMP - c->topo.apicid = apic->phys_pkg_id(c->topo.initial_apicid, 0); -# else - c->topo.apicid = c->topo.initial_apicid; -# endif -#endif - c->topo.pkg_id = c->topo.initial_apicid; - } - get_model_name(c); /* Default name */ /* @@ -1778,9 +1769,6 @@ static void identify_cpu(struct cpuinfo_ c->x86_model_id[0] = '\0'; /* Unset */ c->x86_max_cores = 1; c->x86_coreid_bits = 0; - c->topo.cu_id = 0xff; - c->topo.llc_id = BAD_APICID; - c->topo.l2c_id = BAD_APICID; #ifdef CONFIG_X86_64 c->x86_clflush_size = 64; c->x86_phys_bits = 36; @@ -1799,6 +1787,8 @@ static void identify_cpu(struct cpuinfo_ generic_identify(c); + cpu_parse_topology(c); + if (this_cpu->c_identify) this_cpu->c_identify(c); @@ -1806,7 +1796,8 @@ static void identify_cpu(struct cpuinfo_ apply_forced_caps(c); #ifdef CONFIG_X86_64 - c->topo.apicid = apic->phys_pkg_id(c->topo.initial_apicid, 0); + if (!topo_is_converted(c)) + c->topo.apicid = apic->phys_pkg_id(c->topo.initial_apicid, 0); #endif /* --- a/arch/x86/kernel/cpu/cpu.h +++ b/arch/x86/kernel/cpu/cpu.h @@ -2,6 +2,11 @@ #ifndef ARCH_X86_CPU_H #define ARCH_X86_CPU_H +#include +#include + +#include "topology.h" + /* attempt to consolidate cpu attributes */ struct cpu_dev { const char *c_vendor; @@ -95,4 +100,5 @@ static inline bool spectre_v2_in_eibrs_m mode == SPECTRE_V2_EIBRS_RETPOLINE || mode == SPECTRE_V2_EIBRS_LFENCE; } + #endif /* ARCH_X86_CPU_H */ --- a/arch/x86/kernel/cpu/debugfs.c +++ b/arch/x86/kernel/cpu/debugfs.c @@ -5,6 +5,8 @@ #include #include +#include "cpu.h" + static int cpu_debug_show(struct seq_file *m, void *p) { unsigned long cpu = (unsigned long)m->private; @@ -42,12 +44,47 @@ static const struct file_operations dfs_ .release = single_release, }; +static int dom_debug_show(struct seq_file *m, void *p) +{ + static const char *domain_names[TOPO_ROOT_DOMAIN] = { + [TOPO_SMT_DOMAIN] = "Thread", + [TOPO_CORE_DOMAIN] = "Core", + [TOPO_MODULE_DOMAIN] = "Module", + [TOPO_TILE_DOMAIN] = "Tile", + [TOPO_DIE_DOMAIN] = "Die", + [TOPO_PKG_DOMAIN] = "Package", + }; + unsigned int dom, nthreads = 1; + + for (dom = 0; dom < TOPO_ROOT_DOMAIN; dom++) { + nthreads *= x86_topo_system.dom_size[dom]; + seq_printf(m, "domain: %-10s shift: %u dom_size: %5u max_threads: %5u\n", + domain_names[dom], x86_topo_system.dom_shifts[dom], + x86_topo_system.dom_size[dom], nthreads); + } + return 0; +} + +static int dom_debug_open(struct inode *inode, struct file *file) +{ + return single_open(file, dom_debug_show, inode->i_private); +} + +static const struct file_operations dfs_dom_ops = { + .open = dom_debug_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + static __init int cpu_init_debugfs(void) { struct dentry *dir, *base = debugfs_create_dir("topo", arch_debugfs_dir); unsigned long id; char name[10]; + debugfs_create_file("domains", 0444, base, NULL, &dfs_dom_ops); + dir = debugfs_create_dir("cpus", base); for_each_possible_cpu(id) { sprintf(name, "%lu", id); --- /dev/null +++ b/arch/x86/kernel/cpu/topology.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef ARCH_X86_TOPOLOGY_H +#define ARCH_X86_TOPOLOGY_H + +struct topo_scan { + struct cpuinfo_x86 *c; + unsigned int dom_shifts[TOPO_MAX_DOMAIN]; + unsigned int dom_ncpus[TOPO_MAX_DOMAIN]; +}; + +bool topo_is_converted(struct cpuinfo_x86 *c); +void cpu_init_topology(struct cpuinfo_x86 *c); +void cpu_parse_topology(struct cpuinfo_x86 *c); +void topology_set_dom(struct topo_scan *tscan, enum x86_topology_domains dom, + unsigned int shift, unsigned int ncpus); + +static inline u32 topo_shift_apicid(u32 apicid, enum x86_topology_domains dom) +{ + if (dom == TOPO_SMT_DOMAIN) + return apicid; + return apicid >> x86_topo_system.dom_shifts[dom - 1]; +} + +static inline u32 topo_relative_domain_id(u32 apicid, enum x86_topology_domains dom) +{ + if (dom != TOPO_SMT_DOMAIN) + apicid >>= x86_topo_system.dom_shifts[dom - 1]; + return apicid & (x86_topo_system.dom_size[dom] - 1); +} + +#endif /* ARCH_X86_TOPOLOGY_H */ --- /dev/null +++ b/arch/x86/kernel/cpu/topology_common.c @@ -0,0 +1,187 @@ +// SPDX-License-Identifier: GPL-2.0 +#include + +#include + +#include +#include +#include + +#include "cpu.h" + +struct x86_topology_system x86_topo_system __ro_after_init; + +void topology_set_dom(struct topo_scan *tscan, enum x86_topology_domains dom, + unsigned int shift, unsigned int ncpus) +{ + tscan->dom_shifts[dom] = shift; + tscan->dom_ncpus[dom] = ncpus; + + /* Propagate to the upper levels */ + for (dom++; dom < TOPO_MAX_DOMAIN; dom++) { + tscan->dom_shifts[dom] = tscan->dom_shifts[dom - 1]; + tscan->dom_ncpus[dom] = tscan->dom_ncpus[dom - 1]; + } +} + +bool topo_is_converted(struct cpuinfo_x86 *c) +{ + /* Temporary until everything is converted over. */ + switch (boot_cpu_data.x86_vendor) { + case X86_VENDOR_AMD: + case X86_VENDOR_CENTAUR: + case X86_VENDOR_INTEL: + case X86_VENDOR_HYGON: + case X86_VENDOR_ZHAOXIN: + return false; + default: + /* Let all UP systems use the below */ + return true; + } +} + +static bool fake_topology(struct topo_scan *tscan) +{ + /* + * Preset the CORE level shift for CPUID less systems and XEN_PV, + * which has useless CPUID information. + */ + topology_set_dom(tscan, TOPO_SMT_DOMAIN, 0, 1); + topology_set_dom(tscan, TOPO_CORE_DOMAIN, 1, 1); + + return tscan->c->cpuid_level < 1 || xen_pv_domain(); +} + +static void parse_topology(struct topo_scan *tscan, bool early) +{ + const struct cpuinfo_topology topo_defaults = { + .cu_id = 0xff, + .llc_id = BAD_APICID, + .l2c_id = BAD_APICID, + }; + struct cpuinfo_x86 *c = tscan->c; + struct { + u32 unused0 : 16, + nproc : 8, + apicid : 8; + } ebx; + + c->topo = topo_defaults; + + if (fake_topology(tscan)) + return; + + /* Preset Initial APIC ID from CPUID leaf 1 */ + cpuid_leaf_reg(1, CPUID_EBX, &ebx); + c->topo.initial_apicid = ebx.apicid; + + /* + * The initial invocation from early_identify_cpu() happens before + * the APIC is mapped or X2APIC enabled. For establishing the + * topology, that's not required. Use the initial APIC ID. + */ + if (early) + c->topo.apicid = c->topo.initial_apicid; + else + c->topo.apicid = read_apic_id(); + + /* The above is sufficient for UP */ + if (!IS_ENABLED(CONFIG_SMP)) + return; +} + +static void topo_set_ids(struct topo_scan *tscan) +{ + struct cpuinfo_x86 *c = tscan->c; + u32 apicid = c->topo.apicid; + + c->topo.pkg_id = topo_shift_apicid(apicid, TOPO_PKG_DOMAIN); + c->topo.die_id = topo_shift_apicid(apicid, TOPO_DIE_DOMAIN); + + /* Relative core ID */ + c->topo.core_id = topo_relative_domain_id(apicid, TOPO_CORE_DOMAIN); +} + +static void topo_set_max_cores(struct topo_scan *tscan) +{ + /* + * Bug compatible for now. This is broken on hybrid systems: + * 8 cores SMT + 8 cores w/o SMT + * tscan.dom_ncpus[TOPO_CORE_DOMAIN] = 24; 24 / 2 = 12 !! + * + * Cannot be fixed without further topology enumeration changes. + */ + tscan->c->x86_max_cores = tscan->dom_ncpus[TOPO_CORE_DOMAIN] >> + x86_topo_system.dom_shifts[TOPO_SMT_DOMAIN]; +} + +void cpu_parse_topology(struct cpuinfo_x86 *c) +{ + unsigned int dom, cpu = smp_processor_id(); + struct topo_scan tscan = { .c = c, }; + + parse_topology(&tscan, false); + + if (!topo_is_converted(c)) + return; + + for (dom = TOPO_SMT_DOMAIN; dom < TOPO_MAX_DOMAIN; dom++) { + if (tscan.dom_shifts[dom] == x86_topo_system.dom_shifts[dom]) + continue; + pr_err(FW_BUG "CPU%d: Topology domain %u shift %u != %u\n", cpu, dom, + tscan.dom_shifts[dom], x86_topo_system.dom_shifts[dom]); + } + + /* Bug compatible with the existing parsers */ + if (tscan.dom_ncpus[TOPO_SMT_DOMAIN] > smp_num_siblings) { + if (system_state == SYSTEM_BOOTING) { + pr_warn_once("CPU%d: SMT detected and enabled late\n", cpu); + smp_num_siblings = tscan.dom_ncpus[TOPO_SMT_DOMAIN]; + } else { + pr_warn_once("CPU%d: SMT detected after init. Too late!\n", cpu); + } + } + + topo_set_ids(&tscan); + topo_set_max_cores(&tscan); +} + +void __init cpu_init_topology(struct cpuinfo_x86 *c) +{ + struct topo_scan tscan = { .c = c, }; + unsigned int dom, sft; + + parse_topology(&tscan, true); + + if (!topo_is_converted(c)) + return; + + /* Copy the shift values and calculate the unit sizes. */ + memcpy(x86_topo_system.dom_shifts, tscan.dom_shifts, sizeof(x86_topo_system.dom_shifts)); + + dom = TOPO_SMT_DOMAIN; + x86_topo_system.dom_size[dom] = 1U << x86_topo_system.dom_shifts[dom]; + + for (dom++; dom < TOPO_MAX_DOMAIN; dom++) { + sft = x86_topo_system.dom_shifts[dom] - x86_topo_system.dom_shifts[dom - 1]; + x86_topo_system.dom_size[dom] = 1U << sft; + } + + topo_set_ids(&tscan); + topo_set_max_cores(&tscan); + + /* + * Bug compatible with the existing code. If the boot CPU does not + * have SMT this ends up with one sibling. This needs way deeper + * changes further down the road to get it right during early boot. + */ + smp_num_siblings = tscan.dom_ncpus[TOPO_SMT_DOMAIN]; + + /* + * Neither it's clear whether there are as many dies as the APIC + * space indicating die level is. But assume that the actual number + * of CPUs gives a proper indication for now to stay bug compatible. + */ + __max_die_per_package = tscan.dom_ncpus[TOPO_DIE_DOMAIN] / + tscan.dom_ncpus[TOPO_DIE_DOMAIN - 1]; +} From patchwork Wed Aug 2 10:21:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129812 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp414247vqx; Wed, 2 Aug 2023 05:20:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlE6PAPwoYn40DIAKSujr1toaccRZmau+SsRkBgqGRkMS49CZs3pJVZCdlM30wF5pahn1BTM X-Received: by 2002:aa7:ca50:0:b0:522:1956:a29e with SMTP id j16-20020aa7ca50000000b005221956a29emr5519084edt.34.1690978848198; Wed, 02 Aug 2023 05:20:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690978848; cv=none; d=google.com; s=arc-20160816; b=Lw1KD2fwsoHnk0izSqNQIReWd6afLQhEfBODo0emDjaIXrNGAQ8z+kszZXHvQIb+yl JdLIXzP3gXbG/X6ZJEDOpTHNetOoZbMIk2r72n6elIzOQrAEyAGs+sAJqcFxypTkK6Z2 USFxDVWGcwWU/zDGmNS+IoSRsLt4exvUTxN0kMd7o9fzchWsnv8PCLAGzTdOG4BKmclP nJT7Q5FQE/cHbPTJ0hidKVwhKJJCcsdQeW0wOn7XJkVkroMZDaWiFvlMpeOPC3FEsZwd zxaUzfAVrLsDxBt/2YFkQ7jxeSQy8IaNKRWlU6izbM1fPTCVu6Mrxk5ML9LQ+Emt9ylc ZMSg== 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=rZqB67Sk2gUXfKuY71aQHEPAlesadOxF6WZW7Os2C5w=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=017QmVw6EBDBHakQkbiydLOlEBTCTfTeEDivhFk4dgSCHwuANe6eFJkncuPrwLMmvA 2gdXQiEueUyHq2z5GUN7SYY8SMlSnfC50Zxh68ul9Yj2JO4RdfCj58qWjQ//skWDkxfA 6lVyJ+sTKRVTgFtNWjXOJp0xOCjZxk5wSuMXL8KqOMswNTiqrXJ+hQL2ljRLa83Uv3fB uvxkuXqYA7bP4Y2i2nfHMYdvxV5kZ2t/9zcFlAqRScx7djHhQb/FLY4qJF2NyzoxEy5A SIm8Nw66aKde+WEwoB/DutlgPdTJOfy3L3WdO9BUMvZWrTt1neXiadmb3ZPltM//TjCL lfyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=WSHt4yYh; 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 b23-20020aa7c6d7000000b00522d85a7617si1148093eds.244.2023.08.02.05.20.22; Wed, 02 Aug 2023 05:20:48 -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=WSHt4yYh; 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 S231508AbjHBKYL (ORCPT + 99 others); Wed, 2 Aug 2023 06:24:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233750AbjHBKXZ (ORCPT ); Wed, 2 Aug 2023 06:23:25 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 859742D53 for ; Wed, 2 Aug 2023 03:21:59 -0700 (PDT) Message-ID: <20230802101934.082613843@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971696; 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=rZqB67Sk2gUXfKuY71aQHEPAlesadOxF6WZW7Os2C5w=; b=WSHt4yYhmEvIgUgQUcGM0O3kAS+Y23QA7EqWKf4qdV2wOaPu1Fwi/crnkwcTHsqK/LV6E8 pyboGeGhZwYqLgHrEQZF9V0133AJGx40I1zy6U4UllO5WHFosiedc708ITMkKgupvD4pCd InbE3H+xRTF0MtV5ndQlGHA2kodHlnFbFg6+m5RURwcF3e6e5yxJAmjUadBh65EYAV/RD4 QE/s7HkS8qRAT/KLGLqu0fkmtUXGSGSjEXfTrHWjQEIwLmt9mLbcJTAjySHb7fu+TpJrAi NEeFtR5tvAAolXcDZ4WrkXX8Rq9lAVxrLCLth73vPdxZoCZbeOXoQOeIGcfUUA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971696; 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=rZqB67Sk2gUXfKuY71aQHEPAlesadOxF6WZW7Os2C5w=; b=b/5z8nc4c60NqymQzxubjmBcMOzOBeyJepXj1G0UdWCVfxgROJ+c/ZgXnd1KbZgVk/WW/x WsIxjpYXIcGIH8BA== 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 , Wei Liu Subject: [patch V3 24/40] x86/cpu: Add legacy topology parser References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:35 +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,URIBL_BLOCKED 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: 1773119836387905304 X-GMAIL-MSGID: 1773119836387905304 The legacy topology detection via CPUID leaf 4, which provides the number of cores in the package and CPUID leaf 1 which provides the number of logical CPUs in case that FEATURE_HT is enabled and the CMP_LEGACY feature is not set, is shared for Intel, Centaur amd Zhaoxin CPUs. Lift the code from common.c without the early detection hack and provide it as common fallback mechanism. Will be utilized in later changes. Signed-off-by: Thomas Gleixner --- V3: Provide legacy data in leaf 0xb/0x1f format as expected by the rest of the code - Borislav --- arch/x86/kernel/cpu/common.c | 3 ++ arch/x86/kernel/cpu/topology.h | 3 ++ arch/x86/kernel/cpu/topology_common.c | 44 ++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -883,6 +883,9 @@ void detect_ht(struct cpuinfo_x86 *c) #ifdef CONFIG_SMP int index_msb, core_bits; + if (topo_is_converted(c)) + return; + if (detect_ht_early(c) < 0) return; --- a/arch/x86/kernel/cpu/topology.h +++ b/arch/x86/kernel/cpu/topology.h @@ -6,6 +6,9 @@ struct topo_scan { struct cpuinfo_x86 *c; unsigned int dom_shifts[TOPO_MAX_DOMAIN]; unsigned int dom_ncpus[TOPO_MAX_DOMAIN]; + + // Legacy CPUID[1]:EBX[23:16] number of logical processors + unsigned int ebx1_nproc_shift; }; bool topo_is_converted(struct cpuinfo_x86 *c); --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -24,6 +24,48 @@ void topology_set_dom(struct topo_scan * } } +static unsigned int parse_num_cores(struct cpuinfo_x86 *c) +{ + struct { + u32 cache_type : 5, + unused : 21, + ncores : 6; + } eax; + + if (c->cpuid_level < 4) + return 1; + + cpuid_subleaf_reg(4, 0, CPUID_EAX, &eax); + if (!eax.cache_type) + return 1; + + return eax.ncores + 1; +} + +static void __maybe_unused parse_legacy(struct topo_scan *tscan) +{ + unsigned int cores, core_shift, smt_shift = 0; + struct cpuinfo_x86 *c = tscan->c; + + cores = parse_num_cores(c); + core_shift = get_count_order(cores); + + if (cpu_has(c, X86_FEATURE_HT)) { + if (!WARN_ON_ONCE(tscan->ebx1_nproc_shift < core_shift)) + smt_shift = tscan->ebx1_nproc_shift - core_shift; + /* + * The parser expects leaf 0xb/0x1f format, which means + * the number of logical processors at core level is + * counting threads. + */ + core_shift += smt_shift; + cores <<= smt_shift; + } + + topology_set_dom(tscan, TOPO_SMT_DOMAIN, smt_shift, 1U << smt_shift); + topology_set_dom(tscan, TOPO_CORE_DOMAIN, core_shift, cores); +} + bool topo_is_converted(struct cpuinfo_x86 *c) { /* Temporary until everything is converted over. */ @@ -88,6 +130,8 @@ static void parse_topology(struct topo_s /* The above is sufficient for UP */ if (!IS_ENABLED(CONFIG_SMP)) return; + + tscan->ebx1_nproc_shift = get_count_order(ebx.nproc); } static void topo_set_ids(struct topo_scan *tscan) From patchwork Wed Aug 2 10:21:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129769 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp374252vqx; Wed, 2 Aug 2023 04:10:38 -0700 (PDT) X-Google-Smtp-Source: APBJJlHGK+NIdMyJXb1ZzD2aSHuAo3R5uLj0TscEfrg5Yv1Uq8lnrW6Gg909ZPnOcCb68NYx7KBI X-Received: by 2002:a05:6a00:1990:b0:686:5a11:a434 with SMTP id d16-20020a056a00199000b006865a11a434mr18242688pfl.3.1690974638311; Wed, 02 Aug 2023 04:10:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690974638; cv=none; d=google.com; s=arc-20160816; b=dM1/M7BYm+zfnW8oTO2jdS/5Kz0HR8vC+tZalXyvgkvjZ30QY5w5n5gHR1EEg2YtwT rGfUqWuipA+piR7bYfLTcmyIxZ+jYGU2JumQULvPa9J24xCahNs7MoQGBghIfqoqy/OO i2veDusJD+jWW0BSa5k3E+vqLz8+rBpqyj1VIPY+hPe0EwhsZ6CpiGWdKwhyRvZRgsbH M3JZlf9e2pjQgVDKSwP2rQ0cq2XVaRKvOFRd6lUpJdDBHm39jwrgTFNya3WYxIBT32Zo WtSJMNcfL7xYA+I20UMe1oYOG7shYSZ4zOLho2XzCRrXMB/G1FA4UAXo1tAeY97SOH2b yTCQ== 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=YFWH8dTR2xSRS7NPCdsZGcZyQvJ9Kg7XAQ98q63+xHA=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=abdg2jp9QRu49CX6s2tf/4GZK45hMdPrzT2m+ExGKejZ1Z+NfCw8gANUKDRlsB6FEO /HPnDQX8XmK5l9BaLXWMv5LX/FtOWC4C1rmvvtmaw0gcuI/jcUHdF0ldt6yW1SOixCE/ iKnCUsx0YjO54R1PDFkd/bWnUBaRBFWfkof94/N1DI1p7e3FMPhSCPXluIruMvMIrZxF nCteM5/7jitqTH9QUDvB48sq9GSZ3X7SIyOndnO5/A+e4xxCTNuYpD0H497WPMe10D3K kn9n9XnV1SNCuoSvfWbqvZHhG4s/oZxeBD3Gss7aP307JU4row6xPl0YYHmMt97L20gH 3OYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=RHs548FE; 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 z16-20020a634c10000000b005639fa45a28si53788pga.630.2023.08.02.04.10.14; Wed, 02 Aug 2023 04:10:38 -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=RHs548FE; 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 S233157AbjHBKYU (ORCPT + 99 others); Wed, 2 Aug 2023 06:24:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233816AbjHBKXa (ORCPT ); Wed, 2 Aug 2023 06:23:30 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2605F2D59 for ; Wed, 2 Aug 2023 03:22:03 -0700 (PDT) Message-ID: <20230802101934.139170304@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971697; 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=YFWH8dTR2xSRS7NPCdsZGcZyQvJ9Kg7XAQ98q63+xHA=; b=RHs548FElj20FeJnST7hz2P3LyXh35d/aO4izl6/OKISWGkhnSHoMN9ko0e9LkHarxZNgU aHgPCZGtGkPp46CNLzAsuMFkXXu/LbQjUjNMnE9YYt8QRipFCO0fzKOdJ6TnnLPwjxSMms QY4Jfx30TZbIEVT395pgKC/qwGNhwprCVopzbzc/ytVMYAiDAmFYCOPyMbYF+gTLsO0lTl 2ARMXRCxfAXbgP2p0BIi1f0hCAaaVKUR9CFlvSefSsxZS39VY17zdZgSY6nCU8HNufnQYP 6+OoRlf8j/FPFmgSpAJPw4Q184KzxhqCTDXo7QwOABglsbjZVM6lXIGAOjSqBg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971697; 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=YFWH8dTR2xSRS7NPCdsZGcZyQvJ9Kg7XAQ98q63+xHA=; b=CKMMSbJ8bIOizzwn/IPUkFEqMF/9s/x07fVLeLMYGQlevf7hAfCtGMjnhIhEH6OAq6IuW0 mN8IQo1bBvbXK3DQ== 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 , Wei Liu Subject: [patch V3 25/40] x86/cpu: Use common topology code for Centaur and Zhaoxin References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:37 +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,URIBL_BLOCKED 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: 1773115422157005893 X-GMAIL-MSGID: 1773115422157005893 Centaur and Zhaoxin CPUs use only the legacy SMP detection. Remove the invocations from their 32bit path and exempt them from the call 64bit. No functional change intended. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/cpu/centaur.c | 4 ---- arch/x86/kernel/cpu/topology_common.c | 11 ++++++++--- arch/x86/kernel/cpu/zhaoxin.c | 4 ---- 3 files changed, 8 insertions(+), 11 deletions(-) --- a/arch/x86/kernel/cpu/centaur.c +++ b/arch/x86/kernel/cpu/centaur.c @@ -128,10 +128,6 @@ static void init_centaur(struct cpuinfo_ #endif early_init_centaur(c); init_intel_cacheinfo(c); - detect_num_cpu_cores(c); -#ifdef CONFIG_X86_32 - detect_ht(c); -#endif if (c->cpuid_level > 9) { unsigned int eax = cpuid_eax(10); --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -42,7 +42,7 @@ static unsigned int parse_num_cores(stru return eax.ncores + 1; } -static void __maybe_unused parse_legacy(struct topo_scan *tscan) +static void parse_legacy(struct topo_scan *tscan) { unsigned int cores, core_shift, smt_shift = 0; struct cpuinfo_x86 *c = tscan->c; @@ -71,10 +71,8 @@ bool topo_is_converted(struct cpuinfo_x8 /* Temporary until everything is converted over. */ switch (boot_cpu_data.x86_vendor) { case X86_VENDOR_AMD: - case X86_VENDOR_CENTAUR: case X86_VENDOR_INTEL: case X86_VENDOR_HYGON: - case X86_VENDOR_ZHAOXIN: return false; default: /* Let all UP systems use the below */ @@ -132,6 +130,13 @@ static void parse_topology(struct topo_s return; tscan->ebx1_nproc_shift = get_count_order(ebx.nproc); + + switch (c->x86_vendor) { + case X86_VENDOR_CENTAUR: + case X86_VENDOR_ZHAOXIN: + parse_legacy(tscan); + break; + } } static void topo_set_ids(struct topo_scan *tscan) --- a/arch/x86/kernel/cpu/zhaoxin.c +++ b/arch/x86/kernel/cpu/zhaoxin.c @@ -71,10 +71,6 @@ static void init_zhaoxin(struct cpuinfo_ { early_init_zhaoxin(c); init_intel_cacheinfo(c); - detect_num_cpu_cores(c); -#ifdef CONFIG_X86_32 - detect_ht(c); -#endif if (c->cpuid_level > 9) { unsigned int eax = cpuid_eax(10); From patchwork Wed Aug 2 10:21:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129760 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp362476vqx; Wed, 2 Aug 2023 03:48:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlFmkwsl3UQAmjTfZaPIMHaLCKawxUoVFN9CLlH7IN6B5bwd4WeUXpCTrxl0DjFFG9oBAc8j X-Received: by 2002:a17:907:7885:b0:99c:4ea0:ed18 with SMTP id ku5-20020a170907788500b0099c4ea0ed18mr607435ejc.8.1690973322665; Wed, 02 Aug 2023 03:48:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690973322; cv=none; d=google.com; s=arc-20160816; b=a3WM67GLu9f734SF5CL4iRXj9+imQPJrx5Adga1fQOn28cSegp1I0FGSzGDS/eo/4R 7s2Lgh3+PNz3c9vfFIVXB2tkJZZDdxEUzqRHbK+DLL/pYL24PSHhRvCJSsS6Z0gLOLkW fAIPrHOWVAcLngohLf7mloBbFvZfX8meBidX3/849+QzFAObKOhmf5rDDqDQAfahx6ft qiwaLGqNfv/YoKHWTfDoWyQ9TCltJ2B0BkdGS7KhGpUmMxJ+QMEwOsJcch3keFWgELwF lBigPgyCMHai65dqD1+5i5ePAdoN6iR3N63gCXGydAHSiG5o8S6YT0v5WfC0iH7sqci5 tbTw== 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=R30kgmHCGWHq0zLlNoJY82eQjQTUWAtGppL/g8UfpDM=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=LpZBzfaA7P3oDv5+51P8fuu3FVG/J36cK4BAwQXb1AbE79pQq/9yEx68mveYTuxd13 bwPUaVbOT7MD1P1SGydyLmsR+kMGhUsVHVW2y/WviYbBcNjiN6HBPaDFb43RiYk6azWq cybf3upgJ4zEc1mTmcIV4IbmoIuR0ye+m9qhgMhVY37raJsu+sBZlW3BrZ25ZJzU8cdj PcTFLtzM47JPpWTFbhBNZ+nSTfGKpOd6sBvN+OxHwLTgmccT70lBaiFWaurg3BFRPpfe 88ShbOSBN7+Z+6nJIvttGsUdajlub7xQIyh3kJNrSrQ7iZaT7oYHsgrw3feOw1q8coNZ qbPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mZl1oUzD; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 kk20-20020a170907767400b00987dc76f82fsi5560323ejc.285.2023.08.02.03.48.18; Wed, 02 Aug 2023 03:48:42 -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=mZl1oUzD; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S234093AbjHBKXz (ORCPT + 99 others); Wed, 2 Aug 2023 06:23:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234303AbjHBKXE (ORCPT ); Wed, 2 Aug 2023 06:23:04 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 102EF2690 for ; Wed, 2 Aug 2023 03:21:52 -0700 (PDT) Message-ID: <20230802101934.206290194@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971699; 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=R30kgmHCGWHq0zLlNoJY82eQjQTUWAtGppL/g8UfpDM=; b=mZl1oUzDzgeWX3rmxlgRdLTiQDbPFmeO0/A2HrRvkAERAez2aawbNHcoB9IjICYykqsGkJ sURpz8prF17M1VTPJ4WRXF2SbyVBmnlYY7xtiOY5xjwiy8hp2o1iHZdftbxBuH7ML8bbek Zoc8j9gEFHuYzRaemTUQZiC4o624zTtPHxMFJCcGR1AhAWE0et3Q0QYWgmNMFnhKWLQxsO VmjzLLHKKim94T5m6eF6UhswcTkosd4M7Nsxi/vd+7jszUmJt0AS2jKZ0ill/UEjzBNyFR FQsWTUmLXlFkOiEi+BAmi3lwZiH8HuoHpCN3RUi7YaOkKN3r0P9Sx1DLkQFuOA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971699; 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=R30kgmHCGWHq0zLlNoJY82eQjQTUWAtGppL/g8UfpDM=; b=hBkkqc1sMjkOr4/4dzFwd5yWmJS/klD+OeiB/zox0MhLUbSboB2A2tw5Oi2VtfviSCjtaG FeiTZjYsCbv6rTDg== 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 , Wei Liu Subject: [patch V3 26/40] x86/cpu: Move __max_die_per_package to common.c References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:38 +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,URIBL_BLOCKED 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: 1773114042502080378 X-GMAIL-MSGID: 1773114042502080378 In preparation of a complete replacement for the topology leaf 0xb/0x1f evaluation, move __max_die_per_package into the common code. Will be removed once everything is converted over. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/cpu/common.c | 3 +++ arch/x86/kernel/cpu/topology.c | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -75,6 +75,9 @@ u32 elf_hwcap2 __read_mostly; int smp_num_siblings = 1; EXPORT_SYMBOL(smp_num_siblings); +unsigned int __max_die_per_package __read_mostly = 1; +EXPORT_SYMBOL(__max_die_per_package); + static struct ppin_info { int feature; int msr_ppin_ctl; --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -25,9 +25,6 @@ #define BITS_SHIFT_NEXT_LEVEL(eax) ((eax) & 0x1f) #define LEVEL_MAX_SIBLINGS(ebx) ((ebx) & 0xffff) -unsigned int __max_die_per_package __read_mostly = 1; -EXPORT_SYMBOL(__max_die_per_package); - #ifdef CONFIG_SMP /* * Check if given CPUID extended topology "leaf" is implemented From patchwork Wed Aug 2 10:21:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129800 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp409351vqx; Wed, 2 Aug 2023 05:13:08 -0700 (PDT) X-Google-Smtp-Source: APBJJlFA8CDIjf4yOyqhmXctSB8HxWRMWmWxAAfy8GUmuVFNk+7fl+4/hi6KBPROJvet0HiF1fvO X-Received: by 2002:a05:6a20:938b:b0:13e:f5b5:48ee with SMTP id x11-20020a056a20938b00b0013ef5b548eemr2243557pzh.59.1690978388355; Wed, 02 Aug 2023 05:13:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690978388; cv=none; d=google.com; s=arc-20160816; b=0Xw78PW4JDfmpCa1UdpxMKpwzrPsMAfw1OrPe7xsirhvtFqIJmmzGeBzDXck1OdzfI I7TI9H1uG6yKlj5116cwJbRhXTdW/hk5UUYxw8Esg3nkwJDJHCj46FgPxlgVnFtmHFDR RVBAbi0zxsTaXxr4nVuOC8r79d370UV0tXNNbhDlWJ7tMUGMR+hR1K7jMw3Iyz19aS9a Zpv+hgfWwxm3ypM/chbKShxNb65iEZI4ZucyITviIGDWNKgAMoxusVj3mk5ks4v7Tp2u ycCvAPDhS5lyINP+VA7bjY1tzROQDsMY8zg8UVI9zua+Hb5aKBgS+/VywvHXVzswXi9f gycA== 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=K8G3BegNCqpNmXITgAr+wce0GBx04jSPNL1AU9AAQFg=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=bBJQlQzjQNNsRaEl0LZF5xpT3VW4TbHYYSmWcGMrLgnsKyhZels6mEuWb6FIZ/7Bc+ 8Clpj4UnVbGffnUtEwuElzfZUbYvbbvbF2KmyOgtKV4Kin50nyBgaWB1QphL1Rgvk4K7 554Fdf9ssopk96xaXHWAmCFH3/GglrkZPu3Yz2P2R9PYJXHRq33X24BPTxufO0DR+JuK g1M3GM/smHe9xfR6Xu9T2MiaTesPAUR0CDVYYK2Qhdf4DzNeAUIi2nCYP4g7QeCdYa5h Heo9cMZLdqwRWZN3zFPej4eJea3xpwVJ0SrJHgl/ZVs6Ju6gpfy0hpoGCDDnT+REZuby VIDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=w9vxYKjt; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=UJBJjCKc; 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 bs184-20020a6328c1000000b005633d19281bsi10563804pgb.401.2023.08.02.05.12.50; Wed, 02 Aug 2023 05:13:08 -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=w9vxYKjt; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=UJBJjCKc; 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 S233378AbjHBKYA (ORCPT + 99 others); Wed, 2 Aug 2023 06:24:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231612AbjHBKXK (ORCPT ); Wed, 2 Aug 2023 06:23:10 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A83E626B6 for ; Wed, 2 Aug 2023 03:21:55 -0700 (PDT) Message-ID: <20230802101934.258937135@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971700; 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=K8G3BegNCqpNmXITgAr+wce0GBx04jSPNL1AU9AAQFg=; b=w9vxYKjt5/a2EMtxkZ89rejhVCq4lEmr1Uqx3saIIyeVaEx6lADJRztUMpFiP+QSFVHZc9 xU3gg/W3sbt/fqErnHwjPBnrusHmcss9fo9MnMrMgFUJellh9E9DBLRWEyEr0sfC1HK+sb xwgUCnNASFa56bx4zXVscPOS/cBhurD/vxoDLrRjn7KjseFiVJZrKxSLCmSITTvNwLraez GFBPu0zGg/vC5Avoh/UyiSYxObMwqUNfV+YNyltRjAml2rKPzqXRj5J3Hq7KYP3bfrKZ3r Nr/fqNRmwnKoTEn0H6bOWs8JFRRVnE1InsU7eLmabpYOUci8zJcrfigocBBRHg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971700; 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=K8G3BegNCqpNmXITgAr+wce0GBx04jSPNL1AU9AAQFg=; b=UJBJjCKc7jrzSAUdDDRKu85O6xzgoSIADLOth52EW0WhDR13hhHMx2Vp+Erc55z+TJ56mC KmXbVv5Oo2U3b1Bg== 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 , Wei Liu Subject: [patch V3 27/40] x86/cpu: Provide a sane leaf 0xb/0x1f parser References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:40 +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,URIBL_BLOCKED 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: 1773119354595317267 X-GMAIL-MSGID: 1773119354595317267 detect_extended_topology() along with it's early() variant is a classic example for duct tape engineering: - It evaluates an array of subleafs with a boatload of local variables for the relevant topology levels instead of using an array to save the enumerated information and propagate it to the right level - It has no boundary checks for subleafs - It prevents updating the die_id with a crude workaround instead of checking for leaf 0xb which does not provide die information. - It's broken vs. the number of dies evaluation as it uses: num_processors[DIE_LEVEL] / num_processors[CORE_LEVEL] which "works" only correctly if there is none of the intermediate topology levels (MODULE/TILE) enumerated. There is zero value in trying to "fix" that code as the only proper fix is to rewrite it from scratch. Implement a sane parser with proper code documentation, which will be used for the consolidated topology evaluation in the next step. Signed-off-by: Thomas Gleixner --- V2: Fixed up the comment alignment for registers - Peterz --- arch/x86/kernel/cpu/Makefile | 2 arch/x86/kernel/cpu/topology.h | 12 +++ arch/x86/kernel/cpu/topology_ext.c | 136 +++++++++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+), 1 deletion(-) --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile @@ -18,7 +18,7 @@ KMSAN_SANITIZE_common.o := n KCSAN_SANITIZE_common.o := n obj-y := cacheinfo.o scattered.o -obj-y += topology_common.o topology.o +obj-y += topology_common.o topology_ext.o topology.o obj-y += common.o obj-y += rdrand.o obj-y += match.o --- a/arch/x86/kernel/cpu/topology.h +++ b/arch/x86/kernel/cpu/topology.h @@ -16,6 +16,7 @@ void cpu_init_topology(struct cpuinfo_x8 void cpu_parse_topology(struct cpuinfo_x86 *c); void topology_set_dom(struct topo_scan *tscan, enum x86_topology_domains dom, unsigned int shift, unsigned int ncpus); +bool cpu_parse_topology_ext(struct topo_scan *tscan); static inline u32 topo_shift_apicid(u32 apicid, enum x86_topology_domains dom) { @@ -31,4 +32,15 @@ static inline u32 topo_relative_domain_i return apicid & (x86_topo_system.dom_size[dom] - 1); } +/* + * Update a domain level after the fact without propagating. Used to fixup + * broken CPUID enumerations. + */ +static inline void topology_update_dom(struct topo_scan *tscan, enum x86_topology_domains dom, + unsigned int shift, unsigned int ncpus) +{ + tscan->dom_shifts[dom] = shift; + tscan->dom_ncpus[dom] = ncpus; +} + #endif /* ARCH_X86_TOPOLOGY_H */ --- /dev/null +++ b/arch/x86/kernel/cpu/topology_ext.c @@ -0,0 +1,136 @@ +// SPDX-License-Identifier: GPL-2.0 +#include + +#include +#include +#include + +#include "cpu.h" + +enum topo_types { + INVALID_TYPE = 0, + SMT_TYPE = 1, + CORE_TYPE = 2, + MODULE_TYPE = 3, + TILE_TYPE = 4, + DIE_TYPE = 5, + DIEGRP_TYPE = 6, + MAX_TYPE = 7, +}; + +/* + * Use a lookup table for the case that there are future types > 6 which + * describe an intermediate domain level which does not exist today. + * + * A table will also be handy to parse the new AMD 0x80000026 leaf which + * has defined different domain types, but otherwise uses the same layout + * with some of the reserved bits used for new information. + */ +static const unsigned int topo_domain_map[MAX_TYPE] = { + [SMT_TYPE] = TOPO_SMT_DOMAIN, + [CORE_TYPE] = TOPO_CORE_DOMAIN, + [MODULE_TYPE] = TOPO_MODULE_DOMAIN, + [TILE_TYPE] = TOPO_TILE_DOMAIN, + [DIE_TYPE] = TOPO_DIE_DOMAIN, + [DIEGRP_TYPE] = TOPO_PKG_DOMAIN, +}; + +static inline bool topo_subleaf(struct topo_scan *tscan, u32 leaf, u32 subleaf) +{ + unsigned int dom, maxtype = leaf == 0xb ? CORE_TYPE + 1 : MAX_TYPE; + struct { + // eax + u32 x2apic_shift : 5, // Number of bits to shift APIC ID right + // for the topology ID at the next level + __rsvd0 : 27; // Reserved + // ebx + u32 num_processors : 16, // Number of processors at current level + __rsvd1 : 16; // Reserved + // ecx + u32 level : 8, // Current topology level. Same as sub leaf number + type : 8, // Level type. If 0, invalid + __rsvd2 : 16; // Reserved + // edx + u32 x2apic_id : 32; // X2APIC ID of the current logical processor + } sl; + + cpuid_subleaf(leaf, subleaf, &sl); + + if (!sl.num_processors || sl.type == INVALID_TYPE) + return false; + + if (sl.type >= maxtype) { + /* + * As the subleafs are ordered in domain level order, this + * could be recovered in theory by propagating the + * information at the last parsed level. + * + * But if the infinite wisdom of hardware folks decides to + * create a new domain type between CORE and MODULE or DIE + * and DIEGRP, then that would overwrite the CORE or DIE + * information. + * + * It really would have been too obvious to make the domain + * type space sparse and leave a few reserved types between + * the points which might change instead of forcing + * software to either create a monstrosity of workarounds + * or just being up the creek without a paddle. + * + * Refuse to implement monstrosity, emit an error and try + * to survive. + */ + pr_err_once("Topology: leaf 0x%x:%d Unknown domain type %u\n", + leaf, subleaf, sl.type); + return true; + } + + dom = topo_domain_map[sl.type]; + if (!dom) { + tscan->c->topo.initial_apicid = sl.x2apic_id; + } else if (tscan->c->topo.initial_apicid != sl.x2apic_id) { + pr_warn_once(FW_BUG "CPUID leaf 0x%x subleaf %d APIC ID mismatch %x != %x\n", + leaf, subleaf, tscan->c->topo.initial_apicid, sl.x2apic_id); + } + + topology_set_dom(tscan, dom, sl.x2apic_shift, sl.num_processors); + return true; +} + +static bool parse_topology_leaf(struct topo_scan *tscan, u32 leaf) +{ + u32 subleaf; + + if (tscan->c->cpuid_level < leaf) + return false; + + /* Read all available subleafs and populate the levels */ + for (subleaf = 0; topo_subleaf(tscan, leaf, subleaf); subleaf++); + + /* If subleaf 0 failed to parse, give up */ + if (!subleaf) + return false; + + /* + * There are machines in the wild which have shift 0 in the subleaf + * 0, but advertise 2 logical processors at that level. They are + * truly SMT. + */ + if (!tscan->dom_shifts[TOPO_SMT_DOMAIN] && tscan->dom_ncpus[TOPO_SMT_DOMAIN] > 1) { + unsigned int sft = get_count_order(tscan->dom_ncpus[TOPO_SMT_DOMAIN]); + + pr_warn_once(FW_BUG "CPUID leaf 0x%x subleaf 0 has shift level 0 but %u CPUs\n", + leaf, tscan->dom_ncpus[TOPO_SMT_DOMAIN]); + topology_update_dom(tscan, TOPO_SMT_DOMAIN, sft, tscan->dom_ncpus[TOPO_SMT_DOMAIN]); + } + + set_cpu_cap(tscan->c, X86_FEATURE_XTOPOLOGY); + return true; +} + +bool cpu_parse_topology_ext(struct topo_scan *tscan) +{ + /* Try lead 0x1F first. If not available try leaf 0x0b */ + if (parse_topology_leaf(tscan, 0x1f)) + return true; + return parse_topology_leaf(tscan, 0x0b); +} From patchwork Wed Aug 2 10:21: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: 129781 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp384161vqx; Wed, 2 Aug 2023 04:30:03 -0700 (PDT) X-Google-Smtp-Source: APBJJlEZCHLHl10hrJ49Lxwy9BPTzxrokWUN5W6DhUnkhpaYj9kbeJTWks4mEh+b8GOUTMoDKjYe X-Received: by 2002:a17:906:3281:b0:97d:2bcc:47d5 with SMTP id 1-20020a170906328100b0097d2bcc47d5mr4256478ejw.49.1690975803105; Wed, 02 Aug 2023 04:30:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690975803; cv=none; d=google.com; s=arc-20160816; b=Ldf5i1oow1hJH2e811dzhVO1WcLqgngSxmj6YoqGnBYWN+Et3vu4QCSwWKo6A6KHzD 5Op6b8ApIxVOqzuZP7+dvLTpjZp9b6oF6jUyNzitc+3yjYTVROH2U4KQYTC78+dNbCzB E3VU6uRAnIUeoBoEuBefGgRudEbF5ruy978qDGf2dW8pkljZh/IVzRc2ASnYNeBe7baY 2WS91Eg6LR1ygpcHadWGKDR4UUc461myfXEFL5glRY1Tf92hJuTwX884y87mWnHl6yHk a0T/rXcGt3j4j4ihpH0diAArgAvKgGRAaEBlj1N7fIqKkJGPHFGE9mvRPDZR9p/Rm7J7 RL5Q== 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=3BTOZBcdzyy0AoTkbsTzY5XJZ5iS307qvXgzpSumcTA=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=h7jx6XAbU9mi1C+seJaCfA0PWD6HySEzSoaLQ9phRUk3X5OcfDOcQ+IfnZqrfXApFv FKu5MfGE5ToUmNi06n+vnqUKMfuLwcp4dRQ2uCwRYj0VDG4CfOVhKI0Ak0DaQ9bMNoE9 iqmtFqQNgrz+YxnrTeS1PNUyHnfLEOxsJC/I8vp/k4HD7aXh+75nc1vlYUkKKdKP/i+7 ijGa2L2tWAPBPJ3WIm01z/9RZxf7LQVKF05cI+aaA2wn0s/BijVwGbuHXvE01O4Tx+ZD 0h3sOQkODz5SeLF8aeMIKpCxbF0AqfCZSPx1IBtDTqEsXafGEd87AKkXeyFDsLaLUsvg Km+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=hgePEx0f; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 kk20-20020a170907767400b00987dc76f82fsi5608074ejc.285.2023.08.02.04.29.37; Wed, 02 Aug 2023 04:30:03 -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=hgePEx0f; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S233845AbjHBKYP (ORCPT + 99 others); Wed, 2 Aug 2023 06:24:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233780AbjHBKX3 (ORCPT ); Wed, 2 Aug 2023 06:23:29 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29EAC35AA for ; Wed, 2 Aug 2023 03:22:01 -0700 (PDT) Message-ID: <20230802101934.311584554@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971702; 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=3BTOZBcdzyy0AoTkbsTzY5XJZ5iS307qvXgzpSumcTA=; b=hgePEx0fqlWkl+bbz58Z2+KhCVFwEGTrCWxQm9ZtcXGy/RkfsirkvXHW7batWXPsYk8zUg 2k/Cib8P4Dm2cubEUZwFjaqwwpl80UIvFNNeLvmo2ohXU0AZXTDkLU68W9gDr+2f2Pb8HU GJdzEA+VxF6s5uI5hi5s43Rn7S/Mu76o1+DsLWrpzba/g7vEqdk6HS6p/9TAIsomS7SJnz +zfEKZMx72mp1BqhVCvwO4yAvMhgGdje1Sz3YZlm1/6ObcQfkqZqSzeF2ajYmf5ikhmZBM lmFsmpiGeRFoU71Z7ACv94He3Z8uzBlKFw4rxXhy3aYvKZ/W+b2QbJMn++IEFw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971702; 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=3BTOZBcdzyy0AoTkbsTzY5XJZ5iS307qvXgzpSumcTA=; b=DI22VM/MeZUn1U5KkIfqlSZblaAx+wj3RNmmIqsFIMXXWbVtKCuG+znxYdZaURWRN7nXHd CguX6y/z6oaHwtAQ== 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 , Wei Liu Subject: [patch V3 28/40] x86/cpu: Use common topology code for Intel References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21: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,URIBL_BLOCKED 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: 1773116643499242996 X-GMAIL-MSGID: 1773116643499242996 Intel CPUs use either topology leaf 0xb/0x1f evaluation or the legacy SMP/HT evaluation based on CPUID leaf 0x1/0x4. Move it over to the consolidated topology code and remove the random topology hacks which are sprinkled into the Intel and the common code. No functional change intended. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/cpu/common.c | 65 ---------------------------------- arch/x86/kernel/cpu/cpu.h | 4 -- arch/x86/kernel/cpu/intel.c | 25 ------------- arch/x86/kernel/cpu/topology_common.c | 5 ++ 4 files changed, 4 insertions(+), 95 deletions(-) --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -784,19 +784,6 @@ static void get_model_name(struct cpuinf *(s + 1) = '\0'; } -void detect_num_cpu_cores(struct cpuinfo_x86 *c) -{ - unsigned int eax, ebx, ecx, edx; - - c->x86_max_cores = 1; - if (!IS_ENABLED(CONFIG_SMP) || c->cpuid_level < 4) - return; - - cpuid_count(4, 0, &eax, &ebx, &ecx, &edx); - if (eax & 0x1f) - c->x86_max_cores = (eax >> 26) + 1; -} - void cpu_detect_cache_sizes(struct cpuinfo_x86 *c) { unsigned int n, dummy, ebx, ecx, edx, l2size; @@ -858,54 +845,6 @@ static void cpu_detect_tlb(struct cpuinf tlb_lld_4m[ENTRIES], tlb_lld_1g[ENTRIES]); } -int detect_ht_early(struct cpuinfo_x86 *c) -{ -#ifdef CONFIG_SMP - u32 eax, ebx, ecx, edx; - - if (!cpu_has(c, X86_FEATURE_HT)) - return -1; - - if (cpu_has(c, X86_FEATURE_CMP_LEGACY)) - return -1; - - if (cpu_has(c, X86_FEATURE_XTOPOLOGY)) - return -1; - - cpuid(1, &eax, &ebx, &ecx, &edx); - - smp_num_siblings = (ebx & 0xff0000) >> 16; - if (smp_num_siblings == 1) - pr_info_once("CPU0: Hyper-Threading is disabled\n"); -#endif - return 0; -} - -void detect_ht(struct cpuinfo_x86 *c) -{ -#ifdef CONFIG_SMP - int index_msb, core_bits; - - if (topo_is_converted(c)) - return; - - if (detect_ht_early(c) < 0) - return; - - index_msb = get_count_order(smp_num_siblings); - c->topo.pkg_id = apic->phys_pkg_id(c->topo.initial_apicid, index_msb); - - smp_num_siblings = smp_num_siblings / c->x86_max_cores; - - index_msb = get_count_order(smp_num_siblings); - - core_bits = get_count_order(c->x86_max_cores); - - c->topo.core_id = apic->phys_pkg_id(c->topo.initial_apicid, index_msb) & - ((1 << core_bits) - 1); -#endif -} - static void get_cpu_vendor(struct cpuinfo_x86 *c) { char *v = c->x86_vendor_id; @@ -1853,10 +1792,6 @@ static void identify_cpu(struct cpuinfo_ c->x86, c->x86_model); } -#ifdef CONFIG_X86_64 - detect_ht(c); -#endif - x86_init_rdrand(c); setup_pku(c); setup_cet(c); --- a/arch/x86/kernel/cpu/cpu.h +++ b/arch/x86/kernel/cpu/cpu.h @@ -76,11 +76,7 @@ extern void init_intel_cacheinfo(struct extern void init_amd_cacheinfo(struct cpuinfo_x86 *c); extern void init_hygon_cacheinfo(struct cpuinfo_x86 *c); -extern void detect_num_cpu_cores(struct cpuinfo_x86 *c); -extern int detect_extended_topology_early(struct cpuinfo_x86 *c); extern int detect_extended_topology(struct cpuinfo_x86 *c); -extern int detect_ht_early(struct cpuinfo_x86 *c); -extern void detect_ht(struct cpuinfo_x86 *c); extern void check_null_seg_clears_base(struct cpuinfo_x86 *c); void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c); --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -489,13 +489,6 @@ static void early_init_intel(struct cpui } check_memory_type_self_snoop_errata(c); - - /* - * Get the number of SMT siblings early from the extended topology - * leaf, if available. Otherwise try the legacy SMT detection. - */ - if (detect_extended_topology_early(c) < 0) - detect_ht_early(c); } static void bsp_init_intel(struct cpuinfo_x86 *c) @@ -777,24 +770,6 @@ static void init_intel(struct cpuinfo_x8 intel_workarounds(c); - /* - * Detect the extended topology information if available. This - * will reinitialise the initial_apicid which will be used - * in init_intel_cacheinfo() - */ - detect_extended_topology(c); - - if (!cpu_has(c, X86_FEATURE_XTOPOLOGY)) { - /* - * let's use the legacy cpuid vector 0x1 and 0x4 for topology - * detection. - */ - detect_num_cpu_cores(c); -#ifdef CONFIG_X86_32 - detect_ht(c); -#endif - } - init_intel_cacheinfo(c); if (c->cpuid_level > 9) { --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -64,7 +64,6 @@ bool topo_is_converted(struct cpuinfo_x8 /* Temporary until everything is converted over. */ switch (boot_cpu_data.x86_vendor) { case X86_VENDOR_AMD: - case X86_VENDOR_INTEL: case X86_VENDOR_HYGON: return false; default: @@ -129,6 +128,10 @@ static void parse_topology(struct topo_s case X86_VENDOR_ZHAOXIN: parse_legacy(tscan); break; + case X86_VENDOR_INTEL: + if (!IS_ENABLED(CONFIG_CPU_SUP_INTEL) || !cpu_parse_topology_ext(tscan)) + parse_legacy(tscan); + break; } } From patchwork Wed Aug 2 10:21:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129763 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp364409vqx; Wed, 2 Aug 2023 03:53:01 -0700 (PDT) X-Google-Smtp-Source: APBJJlGPvpfvOHTX+NtkQ5xlWg3KALzpdCQc5P3j4yaXUqgONhn9DbVETGItMJ+JiKn7DnFRCt44 X-Received: by 2002:a19:4f1a:0:b0:4fd:c0dd:d54b with SMTP id d26-20020a194f1a000000b004fdc0ddd54bmr4589334lfb.65.1690973581523; Wed, 02 Aug 2023 03:53:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690973581; cv=none; d=google.com; s=arc-20160816; b=bJDQg8omDeHaTpbTJWghMB76h5WsAlHO+PqUaQA0vAm01sNvGM6x4g5Wz+n2D/78WR 1vk2yuJ+ZXfWdHcM9mjv7cvcQicipOUGDfG6H6Gw898HG7f9c1s1ZfdFQiUMGFiug2VB XqV+SU1A5RSsJkIR89sGjVCs8uUGxHaltIQPrhYvkIjHvl3vy3TiPnuCcdMab1o9t5wc SMp/lc4DzPYheYivzEv4SggNZvxc33qpwwyPurRXAD5Ike3mN7+pz4k80y1mirkGDNJX vTwS6WoZF7mctkqlAIL05cSYZjwbObepj/WWsiaOtQCM4U2P4Mjlbg7hCC/XSwDy709I vakg== 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=2HJ6gKC8xKh7ZYiNVCch9OIndLCiZ8cyEEDMpJCZ4Vw=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=n6s81aTrMYlhGLcLvpSzI3wU1Y0bIIfIJb0FLZ/qoLBcyKQQYSYQI2LSfKXRX2J7w9 PdM9N6BBXjMl8nOhz9CgAN4k4pyGfUP8OeBZVRp7RMAQRtnaIb1PvGneWU/DH4oQF1Zj kCJWt6GbqlM5obbVccPhlrP2AYK06eR9Dbx9a+Vf9pqUb4Fvc6F9B2P0WyHM0Eocej4c C9pRWf7L1RJD47OMJ5n+izB3WvPi6FBdLpC2b1HLlyT7Ik+wkxeQGkFxVH6yzlifqzAY JVs6X2PQimW0KzYdlw30ey73YVZUtspuW5WvGKXMksCaiPVK0Eo4nnZ4EAciW9+CDkjw 5SSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=D2ogqaTX; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=AMDX7xS2; 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 r1-20020a056402034100b005224d26ab13si10032480edw.378.2023.08.02.03.52.37; Wed, 02 Aug 2023 03:53:01 -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=D2ogqaTX; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=AMDX7xS2; 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 S233833AbjHBKZV (ORCPT + 99 others); Wed, 2 Aug 2023 06:25:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232784AbjHBKYT (ORCPT ); Wed, 2 Aug 2023 06:24:19 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DE113585 for ; Wed, 2 Aug 2023 03:22:31 -0700 (PDT) Message-ID: <20230802101934.365251186@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971703; 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=2HJ6gKC8xKh7ZYiNVCch9OIndLCiZ8cyEEDMpJCZ4Vw=; b=D2ogqaTXRcxKevHJH7De736AgjuNSAePAHCq/0OuaEiFm4RqbbWDdPS2z3oMrKrPd51uic BmLCB/qmsvJVW54Nj/vgRnAGVRY5skFxVyl3zqRObFpZmBuEqr1JgGDbQZHiit0JR5abgw kCxui0B2GzTU3HUg9C5knU9KPR1lmtBtXnsgJ9D2TrupE+nOEEO0XH+2qpXUs+xycQ4Pio s6IeGX4DzuF8GD71JAGv1E3vMqgDp0sy++1Qv4cQZ8hhpuMWUrZxgVNmjsKwHT3cqFQXzt qfV+fW82/cK7yYk6DWtQHOxfJmt/ngeohvoKS4GEqXX2DGM3y8G4f3UyZz/ONQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971703; 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=2HJ6gKC8xKh7ZYiNVCch9OIndLCiZ8cyEEDMpJCZ4Vw=; b=AMDX7xS2dT7jig1/0/6r7F0DuRvL0lATJxRl3Zn+Lsnf+c0Ndgp4bcnqPXydLDRgr74PER U729KKsXGaNp8tBw== 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 , Wei Liu Subject: [patch V3 29/40] x86/cpu/amd: Provide a separate accessor for Node ID References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:43 +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,URIBL_BLOCKED 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: 1773114314365570134 X-GMAIL-MSGID: 1773114314365570134 AMD (ab)uses topology_die_id() to store the Node ID information and topology_max_dies_per_pkg to store the number of nodes per package. This collides with the proper processor die level enumeration which is coming on AMD with CPUID 8000_0026, unless there is a correlation between the two. There is zero documentation about that. So provide new storage and new accessors which for now still access die_id and topology_max_dies_per_pkg. Will be mopped up after AMD and HYGON are converted over. Signed-off-by: Thomas Gleixner --- arch/x86/events/amd/core.c | 2 +- arch/x86/include/asm/processor.h | 3 +++ arch/x86/include/asm/topology.h | 8 ++++++++ arch/x86/kernel/amd_nb.c | 4 ++-- arch/x86/kernel/cpu/cacheinfo.c | 2 +- arch/x86/kernel/cpu/mce/amd.c | 4 ++-- arch/x86/kernel/cpu/mce/inject.c | 4 ++-- drivers/edac/amd64_edac.c | 4 ++-- drivers/edac/mce_amd.c | 4 ++-- 9 files changed, 23 insertions(+), 12 deletions(-) --- a/arch/x86/events/amd/core.c +++ b/arch/x86/events/amd/core.c @@ -574,7 +574,7 @@ static void amd_pmu_cpu_starting(int cpu if (!x86_pmu.amd_nb_constraints) return; - nb_id = topology_die_id(cpu); + nb_id = topology_amd_node_id(cpu); WARN_ON_ONCE(nb_id == BAD_APICID); for_each_online_cpu(i) { --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -99,6 +99,9 @@ struct cpuinfo_topology { u32 logical_pkg_id; u32 logical_die_id; + // AMD Node ID and Nodes per Package info + u32 amd_node_id; + // Cache level topology IDs u32 llc_id; u32 l2c_id; --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -131,6 +131,8 @@ extern const struct cpumask *cpu_cluster #define topology_core_id(cpu) (cpu_data(cpu).topo.core_id) #define topology_ppin(cpu) (cpu_data(cpu).ppin) +#define topology_amd_node_id(cpu) (cpu_data(cpu).topo.die_id) + extern unsigned int __max_die_per_package; #ifdef CONFIG_SMP @@ -160,6 +162,11 @@ int topology_update_die_map(unsigned int int topology_phys_to_logical_pkg(unsigned int pkg); bool topology_smt_supported(void); +static inline unsigned int topology_amd_nodes_per_pkg(void) +{ + return __max_die_per_package; +} + extern struct cpumask __cpu_primary_thread_mask; #define cpu_primary_thread_mask ((const struct cpumask *)&__cpu_primary_thread_mask) @@ -182,6 +189,7 @@ static inline int topology_max_die_per_p static inline int topology_max_smt_threads(void) { return 1; } static inline bool topology_is_primary_thread(unsigned int cpu) { return true; } static inline bool topology_smt_supported(void) { return false; } +static inline unsigned int topology_amd_nodes_per_pkg(void) { return 0; }; #endif /* !CONFIG_SMP */ static inline void arch_fix_phys_package_id(int num, u32 slot) --- a/arch/x86/kernel/amd_nb.c +++ b/arch/x86/kernel/amd_nb.c @@ -370,7 +370,7 @@ struct resource *amd_get_mmconfig_range( int amd_get_subcaches(int cpu) { - struct pci_dev *link = node_to_amd_nb(topology_die_id(cpu))->link; + struct pci_dev *link = node_to_amd_nb(topology_amd_node_id(cpu))->link; unsigned int mask; if (!amd_nb_has_feature(AMD_NB_L3_PARTITIONING)) @@ -384,7 +384,7 @@ int amd_get_subcaches(int cpu) int amd_set_subcaches(int cpu, unsigned long mask) { static unsigned int reset, ban; - struct amd_northbridge *nb = node_to_amd_nb(topology_die_id(cpu)); + struct amd_northbridge *nb = node_to_amd_nb(topology_amd_node_id(cpu)); unsigned int reg; int cuid; --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -595,7 +595,7 @@ static void amd_init_l3_cache(struct _cp if (index < 3) return; - node = topology_die_id(smp_processor_id()); + node = topology_amd_node_id(smp_processor_id()); this_leaf->nb = node_to_amd_nb(node); if (this_leaf->nb && !this_leaf->nb->l3_cache.indices) amd_calc_l3_indices(this_leaf->nb); --- a/arch/x86/kernel/cpu/mce/amd.c +++ b/arch/x86/kernel/cpu/mce/amd.c @@ -1181,7 +1181,7 @@ static int threshold_create_bank(struct return -ENODEV; if (is_shared_bank(bank)) { - nb = node_to_amd_nb(topology_die_id(cpu)); + nb = node_to_amd_nb(topology_amd_node_id(cpu)); /* threshold descriptor already initialized on this node? */ if (nb && nb->bank4) { @@ -1285,7 +1285,7 @@ static void threshold_remove_bank(struct * The last CPU on this node using the shared bank is going * away, remove that bank now. */ - nb = node_to_amd_nb(topology_die_id(smp_processor_id())); + nb = node_to_amd_nb(topology_amd_node_id(smp_processor_id())); nb->bank4 = NULL; } --- a/arch/x86/kernel/cpu/mce/inject.c +++ b/arch/x86/kernel/cpu/mce/inject.c @@ -543,8 +543,8 @@ static void do_inject(void) if (boot_cpu_has(X86_FEATURE_AMD_DCM) && b == 4 && boot_cpu_data.x86 < 0x17) { - toggle_nb_mca_mst_cpu(topology_die_id(cpu)); - cpu = get_nbc_for_node(topology_die_id(cpu)); + toggle_nb_mca_mst_cpu(topology_amd_node_id(cpu)); + cpu = get_nbc_for_node(topology_amd_node_id(cpu)); } cpus_read_lock(); --- a/drivers/edac/amd64_edac.c +++ b/drivers/edac/amd64_edac.c @@ -1907,7 +1907,7 @@ static void dct_determine_memory_type(st /* On F10h and later ErrAddr is MC4_ADDR[47:1] */ static u64 get_error_address(struct amd64_pvt *pvt, struct mce *m) { - u16 mce_nid = topology_die_id(m->extcpu); + u16 mce_nid = topology_amd_node_id(m->extcpu); struct mem_ctl_info *mci; u8 start_bit = 1; u8 end_bit = 47; @@ -3438,7 +3438,7 @@ static void get_cpus_on_this_dct_cpumask int cpu; for_each_online_cpu(cpu) - if (topology_die_id(cpu) == nid) + if (topology_amd_node_id(cpu) == nid) cpumask_set_cpu(cpu, mask); } --- a/drivers/edac/mce_amd.c +++ b/drivers/edac/mce_amd.c @@ -1060,7 +1060,7 @@ static void decode_mc3_mce(struct mce *m static void decode_mc4_mce(struct mce *m) { unsigned int fam = x86_family(m->cpuid); - int node_id = topology_die_id(m->extcpu); + int node_id = topology_amd_node_id(m->extcpu); u16 ec = EC(m->status); u8 xec = XEC(m->status, 0x1f); u8 offset = 0; @@ -1188,7 +1188,7 @@ static void decode_smca_error(struct mce if ((bank_type == SMCA_UMC || bank_type == SMCA_UMC_V2) && xec == 0 && decode_dram_ecc) - decode_dram_ecc(topology_die_id(m->extcpu), m); + decode_dram_ecc(topology_amd_node_id(m->extcpu), m); } static inline void amd_decode_err_code(u16 ec) From patchwork Wed Aug 2 10:21:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129809 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp413355vqx; Wed, 2 Aug 2023 05:19:21 -0700 (PDT) X-Google-Smtp-Source: APBJJlEo5pAtRChg1Y72u18EOhUjuRapLlkhfPG9HtStAZXS1XsA2akP4S6kPG0qmeqFyiSqY78I X-Received: by 2002:a17:906:cc15:b0:99a:e756:57bf with SMTP id ml21-20020a170906cc1500b0099ae75657bfmr4839273ejb.7.1690978760951; Wed, 02 Aug 2023 05:19:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690978760; cv=none; d=google.com; s=arc-20160816; b=LSQXIT6CVQ7ukNWnPHL0S6vURA4FA6JTNcazAEHk7rx37cMtgLW8aTVXSiYuQ2+99X XtnViUckfSOpPkZc11ggaIgy+Gb44LSWuhszlfTu7BYSm7FoZ3CjsmzGtPUIzHm6ua2b M9UXGJKcN8SQR9m98FAsI3/EgBHB+sZDixapgmuyMrbudUT+Y6nP/ppVVkRlli5vR2j9 tqBSyc4epEBBcUU6RGy44rQ090CvMf5G1YP4DTaidLn220hVGzLQIymvZ1sXi42TGfp9 aCFGJ/LdrdMeapcm1V0bU1+AtekWTJVp3T2o94KSHe3wqv0hx1i7v/fE6kp1GbVQkXOI eSHw== 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=9t5b1tAKz7mmbfIHIDEbxzE13cfvbiCpOdIgppo/h/E=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=xE2744hBMq2TydinE4ebRyJhCJq+pQo4GVWOELtF3T5R2MfDnpUv9+OuJg7no0GV2N 4CrCbN56MP1HG5c/adcuyvFbXRoZ44AOyw/BFaYJRc9txWX2iJ8VSIv7Z6kdsrL284+q 1XqoERMBNl2DxczrNJPb8t8tDbGh6ImOxijuTCp7uJY296bzpzl+lpEBx7Ps0NX3D9gS HrZ6LZZ86iCksyDWSdjdjOpq8ywwbDu43rzF4iZ/EwUvdy+oDCpFVAJ5mpyYWwvie26h Fs1vpMwOkaEeKENb1coFcVxMeVET/SgZwsLV06KmTzSo8Sx3NzsGI4CjP4AGLynzJfz5 WReQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=NZBPsJjK; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=qXSDSrHr; 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 ay21-20020a170906d29500b00993fe9ca8cfsi10364954ejb.766.2023.08.02.05.18.56; Wed, 02 Aug 2023 05:19:20 -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=NZBPsJjK; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=qXSDSrHr; 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 S233953AbjHBKYb (ORCPT + 99 others); Wed, 2 Aug 2023 06:24:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233956AbjHBKXf (ORCPT ); Wed, 2 Aug 2023 06:23:35 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97CDB3C1E for ; Wed, 2 Aug 2023 03:22:06 -0700 (PDT) Message-ID: <20230802101934.418143974@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971705; 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=9t5b1tAKz7mmbfIHIDEbxzE13cfvbiCpOdIgppo/h/E=; b=NZBPsJjKS1PBIJ5Et2PHFr1nPUJVO73p1P8hHqmmaBj1QXIb174ZafkjueEFMKtg8sjztL KROYwxZBqL+ZYzdZQdobuenJo2ijBwiJQc+9f5kngSCyy0rMt96hhXIg6UMEkO13uU+GuK OvwDpDZD07svxcAIRrEIuFXz2vbWS7JvZBQLv9VPvx0uDZr0onTDD8rkE07TJvM1yZJUkL icHBCPvCCk6iq9tmDi81YpOGA0x8B2zJ+conQNOazvf6OAnsutqs7ICvEzy0m5BHMDQvYB KviZ73cjuuhrbZC888HCqdUPQ7IY+JzI4gVu5HRugsr+GcFLt2uiiqBstJXNRA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971705; 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=9t5b1tAKz7mmbfIHIDEbxzE13cfvbiCpOdIgppo/h/E=; b=qXSDSrHriDSSyRteL7mKAxXbi4myDpaQsYG88z2+Q6A/JAJkhIG/Dlqx8Xfmz9JT/jC1wK J3n0OqmFDa7QiACQ== 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 , Wei Liu Subject: [patch V3 30/40] x86/cpu: Provide an AMD/HYGON specific topology parser References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:44 +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,URIBL_BLOCKED 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: 1773119745443671029 X-GMAIL-MSGID: 1773119745443671029 AMD/HYGON uses various methods for topology evaluation: - Leaf 0x80000008 and 0x8000001e based with an optional leaf 0xb, which is the preferred variant for modern CPUs. Leaf 0xb will be superseded by leaf 0x80000026 soon, which is just another variant of the Intel 0x1f leaf for whatever reasons. - Subleaf 0x80000008 and NODEID_MSR base - Legacy fallback That code is following the principle of random bits and pieces all over the place which results in multiple evaluations and impenetrable code flows in the same way as the Intel parsing did. Provide a sane implementation by clearly separating the three variants and bringing them in the proper preference order in one place. This provides the parsing for both AMD and HYGON because there is no point in having a separate HYGON parser which only differs by 3 lines of code. Any further divergence between AMD and HYGON can be handled in different functions, while still sharing the existing parsers. Signed-off-by: Thomas Gleixner --- V3: Fix the off by one with leaf 0x8000001e::ebx::threads_per_cu - Michael --- arch/x86/include/asm/topology.h | 2 arch/x86/kernel/cpu/Makefile | 2 arch/x86/kernel/cpu/amd.c | 2 arch/x86/kernel/cpu/cacheinfo.c | 4 arch/x86/kernel/cpu/cpu.h | 2 arch/x86/kernel/cpu/debugfs.c | 2 arch/x86/kernel/cpu/topology.h | 6 + arch/x86/kernel/cpu/topology_amd.c | 179 ++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/topology_common.c | 19 +++ 9 files changed, 211 insertions(+), 7 deletions(-) --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -162,6 +162,8 @@ int topology_update_die_map(unsigned int int topology_phys_to_logical_pkg(unsigned int pkg); bool topology_smt_supported(void); +extern unsigned int __amd_nodes_per_pkg; + static inline unsigned int topology_amd_nodes_per_pkg(void) { return __max_die_per_package; --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile @@ -18,7 +18,7 @@ KMSAN_SANITIZE_common.o := n KCSAN_SANITIZE_common.o := n obj-y := cacheinfo.o scattered.o -obj-y += topology_common.o topology_ext.o topology.o +obj-y += topology_common.o topology_ext.o topology_amd.o topology.o obj-y += common.o obj-y += rdrand.o obj-y += match.o --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -423,7 +423,7 @@ static void amd_get_topology(struct cpui if (!err) c->x86_coreid_bits = get_count_order(c->x86_max_cores); - cacheinfo_amd_init_llc_id(c); + cacheinfo_amd_init_llc_id(c, c->topo.die_id); } else if (cpu_has(c, X86_FEATURE_NODEID_MSR)) { u64 value; --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -661,7 +661,7 @@ static int find_num_cache_leaves(struct return i; } -void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c) +void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, u16 die_id) { /* * We may have multiple LLCs if L3 caches exist, so check if we @@ -672,7 +672,7 @@ void cacheinfo_amd_init_llc_id(struct cp if (c->x86 < 0x17) { /* LLC is at the node level. */ - c->topo.llc_id = c->topo.die_id; + c->topo.llc_id = die_id; } else if (c->x86 == 0x17 && c->x86_model <= 0x1F) { /* * LLC is at the core complex level. --- a/arch/x86/kernel/cpu/cpu.h +++ b/arch/x86/kernel/cpu/cpu.h @@ -79,7 +79,7 @@ extern void init_hygon_cacheinfo(struct extern int detect_extended_topology(struct cpuinfo_x86 *c); extern void check_null_seg_clears_base(struct cpuinfo_x86 *c); -void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c); +void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, u16 die_id); void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c); unsigned int aperfmperf_get_khz(int cpu); --- a/arch/x86/kernel/cpu/debugfs.c +++ b/arch/x86/kernel/cpu/debugfs.c @@ -26,6 +26,8 @@ static int cpu_debug_show(struct seq_fil seq_printf(m, "logical_die_id: %u\n", c->topo.logical_die_id); seq_printf(m, "llc_id: %u\n", c->topo.llc_id); seq_printf(m, "l2c_id: %u\n", c->topo.l2c_id); + seq_printf(m, "amd_node_id: %u\n", c->topo.amd_node_id); + seq_printf(m, "amd_nodes_per_pkg: %u\n", topology_amd_nodes_per_pkg()); seq_printf(m, "max_cores: %u\n", c->x86_max_cores); seq_printf(m, "max_die_per_pkg: %u\n", __max_die_per_package); seq_printf(m, "smp_num_siblings: %u\n", smp_num_siblings); --- a/arch/x86/kernel/cpu/topology.h +++ b/arch/x86/kernel/cpu/topology.h @@ -9,6 +9,10 @@ struct topo_scan { // Legacy CPUID[1]:EBX[23:16] number of logical processors unsigned int ebx1_nproc_shift; + + // AMD specific node ID which cannot be mapped into APIC space. + u16 amd_nodes_per_pkg; + u16 amd_node_id; }; bool topo_is_converted(struct cpuinfo_x86 *c); @@ -17,6 +21,8 @@ void cpu_parse_topology(struct cpuinfo_x void topology_set_dom(struct topo_scan *tscan, enum x86_topology_domains dom, unsigned int shift, unsigned int ncpus); bool cpu_parse_topology_ext(struct topo_scan *tscan); +void cpu_parse_topology_amd(struct topo_scan *tscan); +void cpu_topology_fixup_amd(struct topo_scan *tscan); static inline u32 topo_shift_apicid(u32 apicid, enum x86_topology_domains dom) { --- /dev/null +++ b/arch/x86/kernel/cpu/topology_amd.c @@ -0,0 +1,179 @@ +// SPDX-License-Identifier: GPL-2.0 +#include + +#include +#include +#include + +#include "cpu.h" + +static bool parse_8000_0008(struct topo_scan *tscan) +{ + struct { + u32 ncores : 8, + __rsvd0 : 4, + apicidsize : 4, + perftscsize : 2, + __rsvd1 : 14; + } ecx; + unsigned int sft; + + if (tscan->c->extended_cpuid_level < 0x80000008) + return false; + + cpuid_leaf_reg(0x80000008, CPUID_ECX, &ecx); + + /* If the APIC ID size is 0, then get the shift value from ecx.ncores */ + sft = ecx.apicidsize; + if (!sft) + sft = get_count_order(ecx.ncores + 1); + + topology_set_dom(tscan, TOPO_CORE_DOMAIN, sft, ecx.ncores + 1); + return true; +} + +static void store_node(struct topo_scan *tscan, unsigned int nr_nodes, u16 node_id) +{ + /* + * Starting with Fam 17h the DIE domain could probably be used to + * retrieve the node info on AMD/HYGON. Analysis of CPUID dumps + * suggests it's the topmost bit(s) of the CPU cores area, but + * that's guess work and neither enumerated nor documented. + * + * Up to Fam 16h this does not work at all and the legacy node ID + * has to be used. + */ + tscan->amd_nodes_per_pkg = nr_nodes; + tscan->amd_node_id = node_id; +} + +static bool parse_8000_001e(struct topo_scan *tscan, bool has_0xb) +{ + struct { + // eax + u32 x2apic_id : 32; + // ebx + u32 cuid : 8, + threads_per_cu : 8, + __rsvd0 : 16; + // ecx + u32 nodeid : 8, + nodes_per_pkg : 3, + __rsvd1 : 21; + // edx + u32 __rsvd2 : 32; + } leaf; + + if (!boot_cpu_has(X86_FEATURE_TOPOEXT)) + return false; + + cpuid_leaf(0x8000001e, &leaf); + + tscan->c->topo.initial_apicid = leaf.x2apic_id; + + /* + * If leaf 0xb is available, then SMT shift is set already. If not + * take it from ecx.threads_per_cu and use topo_update_dom() - + * topology_set_dom() would propagate and overwrite the already + * propagated CORE level. + */ + if (!has_0xb) { + topology_update_dom(tscan, TOPO_SMT_DOMAIN, get_count_order(leaf.threads_per_cu), + leaf.threads_per_cu + 1); + } + + store_node(tscan, leaf.nodes_per_pkg + 1, leaf.nodeid); + + if (tscan->c->x86_vendor == X86_VENDOR_AMD) { + if (tscan->c->x86 == 0x15) + tscan->c->topo.cu_id = leaf.cuid; + + cacheinfo_amd_init_llc_id(tscan->c, leaf.nodeid); + } else { + /* + * Package ID is ApicId[6..] on Hygon CPUs. See commit + * e0ceeae708ce for explanation. The topology info is + * screwed up: The package shift is always 6 and the node + * ID is bit [4:5]. Don't touch the latter without + * confirmation from the Hygon developers. + */ + topology_set_dom(tscan, TOPO_CORE_DOMAIN, 6, tscan->dom_ncpus[TOPO_CORE_DOMAIN]); + cacheinfo_hygon_init_llc_id(tscan->c); + } + return true; +} + +static bool parse_fam10h_node_id(struct topo_scan *tscan) +{ + struct { + union { + u64 node_id : 3, + nodes_per_pkg : 3, + unused : 58; + u64 msr; + }; + } nid; + + if (!boot_cpu_has(X86_FEATURE_NODEID_MSR)) + return false; + + rdmsrl(MSR_FAM10H_NODE_ID, nid.msr); + store_node(tscan, nid.nodes_per_pkg + 1, nid.node_id); + tscan->c->topo.llc_id = nid.node_id; + return true; +} + +static void legacy_set_llc(struct topo_scan *tscan) +{ + unsigned int apicid = tscan->c->topo.initial_apicid; + + /* parse_8000_0008() set everything up except llc_id */ + tscan->c->topo.llc_id = apicid >> tscan->dom_shifts[TOPO_CORE_DOMAIN]; +} + +static void parse_topology_amd(struct topo_scan *tscan) +{ + bool has_0xb = false; + + /* + * If the extended topology leaf 0x8000_001e is available + * try to get SMT and CORE shift from leaf 0xb first, then + * try to get the CORE shift from leaf 0x8000_0008. + */ + if (boot_cpu_has(X86_FEATURE_TOPOEXT)) + has_0xb = cpu_parse_topology_ext(tscan); + + if (!has_0xb && !parse_8000_0008(tscan)) + return; + + /* Prefer leaf 0x8000001e if available */ + if (parse_8000_001e(tscan, has_0xb)) + return; + + /* Try the NODEID MSR */ + if (parse_fam10h_node_id(tscan)) + return; + + legacy_set_llc(tscan); +} + +void cpu_parse_topology_amd(struct topo_scan *tscan) +{ + tscan->amd_nodes_per_pkg = 1; + parse_topology_amd(tscan); + + if (tscan->amd_nodes_per_pkg > 1) + set_cpu_cap(tscan->c, X86_FEATURE_AMD_DCM); +} + +void cpu_topology_fixup_amd(struct topo_scan *tscan) +{ + struct cpuinfo_x86 *c = tscan->c; + + /* + * Adjust the core_id relative to the node when there is more than + * one node. + */ + if (tscan->c->x86 < 0x17 && tscan->amd_nodes_per_pkg > 1) + c->topo.core_id %= tscan->dom_ncpus[TOPO_CORE_DOMAIN] / tscan->amd_nodes_per_pkg; +} --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -11,11 +11,13 @@ struct x86_topology_system x86_topo_system __ro_after_init; +unsigned int __amd_nodes_per_pkg __ro_after_init; +EXPORT_SYMBOL_GPL(__amd_nodes_per_pkg); + void topology_set_dom(struct topo_scan *tscan, enum x86_topology_domains dom, unsigned int shift, unsigned int ncpus) { - tscan->dom_shifts[dom] = shift; - tscan->dom_ncpus[dom] = ncpus; + topology_update_dom(tscan, dom, shift, ncpus); /* Propagate to the upper levels */ for (dom++; dom < TOPO_MAX_DOMAIN; dom++) { @@ -152,6 +154,13 @@ static void topo_set_ids(struct topo_sca /* Relative core ID */ c->topo.core_id = topo_relative_domain_id(apicid, TOPO_CORE_DOMAIN); + + /* Temporary workaround */ + if (tscan->amd_nodes_per_pkg) + c->topo.amd_node_id = c->topo.die_id = tscan->amd_node_id; + + if (c->x86_vendor == X86_VENDOR_AMD) + cpu_topology_fixup_amd(tscan); } static void topo_set_max_cores(struct topo_scan *tscan) @@ -236,4 +245,10 @@ void __init cpu_init_topology(struct cpu */ __max_die_per_package = tscan.dom_ncpus[TOPO_DIE_DOMAIN] / tscan.dom_ncpus[TOPO_DIE_DOMAIN - 1]; + /* + * AMD systems have Nodes per package which cannot be mapped to + * APIC ID (yet). + */ + if (c->x86_vendor == X86_VENDOR_AMD || c->x86_vendor == X86_VENDOR_HYGON) + __amd_nodes_per_pkg = __max_die_per_package = tscan.amd_nodes_per_pkg; } From patchwork Wed Aug 2 10:21:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129756 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp359838vqx; Wed, 2 Aug 2023 03:41:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlEqGgvbLRAJ3xTEgKHKOQj//VTwCnz/zM1dcuNwTXrKpJhHZ29bhdsM0esSOJJjijDqTS1T X-Received: by 2002:a05:6402:1659:b0:522:cb97:f196 with SMTP id s25-20020a056402165900b00522cb97f196mr4806740edx.36.1690972902248; Wed, 02 Aug 2023 03:41:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690972902; cv=none; d=google.com; s=arc-20160816; b=JkX+CJkRPzFnDZ8G755VHsVUYH/+v7KPYRtaoHlMzAhURTWloocZ+We1opHZzM+m+v U2XjMgQV6SO9vxxnSRLxB4bNoWGrGgf17xctXiVWNppIlsrBlRb4HPv+ZKbpRnGfXDXd mHu0oK9CMAKqz2mP03VQDQdAhRZL6V8fU4SPbL6UTNmaL2gSc7qwojKqVtQ6f9u8Nvh1 5R/W7johzeiNP/m2LipiR1ESILA+bwbPY0QdyRt0DxhjlVJ0v//ycY3BTbIEE0bQxtzI dXYC76BxVNBo2wm/yWhITpr0zNmCfH4n62rlJqarAjQPGvAQndBG9lYpw/RPdv88NbA0 q/aA== 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=4pQHURzHcwcFZ9S0vbzPTsi43pbiloyiG3aJ+/xAmII=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=bLysuvzZXfyqjQOjfrJNq7phb8WDWKitn3Yud3CxOR1E5xPiUwqKMleWdl0IxokqOY pjED3EYjflsSLYXVD/+UGocexIvsnz5KdOMyoScIpYzD0BBiFPp2Bbf65B5eIvX3jMBD HzM9KmyfM8thg9J+L2y3ncuMmGuwdWx2KOf9R9kjJY1p9m3MQsmOlBsAD5l5kUynYbe0 YC/Jo7h0nV2d83eO6O6om3jTDaBVw52W8fCLe4hSyNhSqQJhVBfmwmeQzLLxEyq7mdp3 oUZVRMX4QIGEkGjSn7blWsynlWLrZhNLDvSxMccCZHjisKk0/yS6EzQr+EtCTecbiJyP G7bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ZPGr7pYO; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=AkvBRaWY; 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 v15-20020aa7d80f000000b0052275937198si9476427edq.628.2023.08.02.03.41.18; Wed, 02 Aug 2023 03:41:42 -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=ZPGr7pYO; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=AkvBRaWY; 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 S234021AbjHBKZp (ORCPT + 99 others); Wed, 2 Aug 2023 06:25:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232222AbjHBKYw (ORCPT ); Wed, 2 Aug 2023 06:24:52 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 763A546AA for ; Wed, 2 Aug 2023 03:22:40 -0700 (PDT) Message-ID: <20230802101934.472046549@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971706; 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=4pQHURzHcwcFZ9S0vbzPTsi43pbiloyiG3aJ+/xAmII=; b=ZPGr7pYOkLkHbHgU9IHgxAm+F05vXEQiHjAIco+FVcRjUPK2HJ/LW98ZCUcuxyAK10UPH+ vVtO4sRtEuAv0xiJ6cZIKUAwmBJY86yC/KzK0BhtSUAroVZ1f+b4wSQQoSlD9KnrP1SWrN Lnzci1i0P0b8SDkzpzRj42FxNJJpp9ApLhJOSkd2Z6shpahsDbjJTIsBciyH0nJIFkLE2z 4ACOFEctr8v25ODusINbLocH2cjktAtKwz4D7xByY7G3nvOZfnqTxN6s+T7OzoyZqagkYs P9fv0RZRQ86z8yWpYVqdct8HrKDmrGEYpQw4lBD8s83wpy5RA7r1oQ/0medWeg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971706; 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=4pQHURzHcwcFZ9S0vbzPTsi43pbiloyiG3aJ+/xAmII=; b=AkvBRaWYKTLKp73ignhKa8jp2GwMNvjpExIfbxsYcQ0qoWATCdR2LFgwoiqp6sC3v4HMUM SvvAQ2wxCImd+mAg== 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 , Wei Liu Subject: [patch V3 31/40] x86/smpboot: Teach it about topo.amd_node_id References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:46 +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,URIBL_BLOCKED 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: 1773113601595722597 X-GMAIL-MSGID: 1773113601595722597 When switching AMD over to the new topology parser then the match functions need to look for AMD systems with the extended topology feature at the new topo.amd_node_id member which is then holding the node id information. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/smpboot.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -486,6 +486,7 @@ static bool match_smt(struct cpuinfo_x86 if (c->topo.pkg_id == o->topo.pkg_id && c->topo.die_id == o->topo.die_id && + c->topo.amd_node_id == o->topo.amd_node_id && per_cpu_llc_id(cpu1) == per_cpu_llc_id(cpu2)) { if (c->topo.core_id == o->topo.core_id) return topology_sane(c, o, "smt"); @@ -507,10 +508,13 @@ static bool match_smt(struct cpuinfo_x86 static bool match_die(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o) { - if (c->topo.pkg_id == o->topo.pkg_id && - c->topo.die_id == o->topo.die_id) - return true; - return false; + if (c->topo.pkg_id != o->topo.pkg_id || c->topo.die_id != o->topo.die_id) + return false; + + if (boot_cpu_has(X86_FEATURE_TOPOEXT) && topology_amd_nodes_per_pkg() > 1) + return c->topo.amd_node_id == o->topo.amd_node_id; + + return true; } static bool match_l2c(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o) From patchwork Wed Aug 2 10:21:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129775 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp378853vqx; Wed, 2 Aug 2023 04:19:22 -0700 (PDT) X-Google-Smtp-Source: APBJJlEpLPJuRz2H8ksO7BfLFfWx8SoOA9efokP/eQ8njEuwx0qEjSl40ABDT4iaqqvIlfYlerHK X-Received: by 2002:a05:6870:14c1:b0:1b0:3075:2f9d with SMTP id l1-20020a05687014c100b001b030752f9dmr17070917oab.34.1690975161788; Wed, 02 Aug 2023 04:19:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690975161; cv=none; d=google.com; s=arc-20160816; b=n+Bf8BX1Fipw0oMQRQskYMqH8aClKk3/dS1tcm6/ycIwEfO3gRHQLofXs7TvTmCu1N 7aGVWfjTokF/50/je7lyYNcYN/HjfYWwNne3q48nK9U8Pekt64+AwAe93vB4XP/bYHjh FMjvBGOYTNVuJWTRmPVvIlLtwJy97jiOGnI9Ul/pxLQXyTFD3LOT5hEDFtxDBvrOGxwm EtK/IMqXog8uaQh+NGDdXoTZRgsIzibitxqEziGAbxvV53PAAL7n54klsoUNyv3LXYd+ iULopbGOjYHI1wjahUkrwnRbXt44oTg2hBI24o3rB3nom4MFZEFqrrRN6LpuC9zL3KpS h7jg== 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=PHVw76eHVn9i5zyTYY9cldIsdDgruBt9pP2vpfcIs8M=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=MUkWg9Gj6mEDZfhZvWvhsIueLNCMMV1JOZ+sVd4pU+ZjPBSYshCjRn+msMp99wy+b7 wVmdjuXpplATwNsG9EJDfoBs54zVaC8oT3UkSOzbsmv2C2ccfn1KXbKcVyTELfHr/IEl +5M2xXGNrwwjKpndHDVXKP7FsEGOJRyNhzV14xm4gL8rf6xe/Td8C/vO0LxLJ8OHoZow ds7BvBkEuj/zOKQPd7ABBXFuaTb9go/0/iBh6bO8aB4OfwT8+rGvg06QQhnNAVot42rq W0CRk5AyMpQMbmsHXegYoBT0f9F8eOahe/sMX0k7wPTVwqQNp9hMX8K430D4RfKj20UW 8Dgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Yqfy6bNL; dkim=neutral (no key) header.i=@linutronix.de header.b=CnzPbGuZ; 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 e12-20020a17090a77cc00b00263e423753dsi1050356pjs.42.2023.08.02.04.19.06; Wed, 02 Aug 2023 04:19:21 -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=Yqfy6bNL; dkim=neutral (no key) header.i=@linutronix.de header.b=CnzPbGuZ; 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 S232192AbjHBKZu (ORCPT + 99 others); Wed, 2 Aug 2023 06:25:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229664AbjHBKY5 (ORCPT ); Wed, 2 Aug 2023 06:24:57 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBE9A3581 for ; Wed, 2 Aug 2023 03:22:42 -0700 (PDT) Message-ID: <20230802101934.529871761@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971708; 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=PHVw76eHVn9i5zyTYY9cldIsdDgruBt9pP2vpfcIs8M=; b=Yqfy6bNLUAYFZkMIAZI86OKsN4kOD6o88YsahqbeOPhZdOCltOzK9wvmcM2aUYIZfpc6dq PmYg/PFyIcDS2ZvePzLz1WiksSKYichVXzeXESLsKuadgkRVjoMHQ3DK4uO4FlD5p67WKt JQNH+5tEU9ePPRATxBQm5ubANqDsn40LKMrpS5pf2meKa0Q2qKAUqEapexw23amFTqyO1W 85GVW2gHK7V6Keco2ZrOI94uGDi7qOElSNs4Nb2QXy1KM5mxr51VxO+8DPF7s63rQmjPFY 8AxFBtia3Tl5FYe8/Z+c1H8BDG+QNrxx9IhVR9Xr9xqlhRceIvrTi1a7UzgNZA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971708; 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=PHVw76eHVn9i5zyTYY9cldIsdDgruBt9pP2vpfcIs8M=; b=CnzPbGuZKBbAUkjmYrcE54MO8vYV1BQba5ERzS2ubaiwKbHI/WLujMV6f+PIhp/KV6OI6h A+0u6a2wfJmziTAA== 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 , Wei Liu Subject: [patch V3 32/40] x86/cpu: Use common topology code for AMD References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:47 +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,URIBL_BLOCKED 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: 1773115970977411788 X-GMAIL-MSGID: 1773115970977411788 Switch it over to the new topology evaluation mechanism and remove the random bits and pieces which are sprinkled all over the place. No functional change intended. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/processor.h | 2 arch/x86/include/asm/topology.h | 5 + arch/x86/kernel/cpu/amd.c | 146 ---------------------------------- arch/x86/kernel/cpu/mce/inject.c | 3 arch/x86/kernel/cpu/topology_common.c | 5 - 5 files changed, 10 insertions(+), 151 deletions(-) --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -705,10 +705,8 @@ static inline u32 per_cpu_l2c_id(unsigne } #ifdef CONFIG_CPU_SUP_AMD -extern u32 amd_get_nodes_per_socket(void); extern u32 amd_get_highest_perf(void); #else -static inline u32 amd_get_nodes_per_socket(void) { return 0; } static inline u32 amd_get_highest_perf(void) { return 0; } #endif --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -121,6 +121,11 @@ struct x86_topology_system { extern struct x86_topology_system x86_topo_system; +static inline unsigned int topology_get_domain_size(enum x86_topology_domains dom) +{ + return x86_topo_system.dom_size[dom]; +} + extern const struct cpumask *cpu_coregroup_mask(int cpu); extern const struct cpumask *cpu_clustergroup_mask(int cpu); --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -28,13 +28,6 @@ #include "cpu.h" /* - * nodes_per_socket: Stores the number of nodes per socket. - * Refer to Fam15h Models 00-0fh BKDG - CPUID Fn8000_001E_ECX - * Node Identifiers[10:8] - */ -static u32 nodes_per_socket = 1; - -/* * AMD errata checking * * Errata are defined as arrays of ints using the AMD_LEGACY_ERRATUM() or @@ -372,97 +365,6 @@ static int nearby_node(int apicid) } #endif -/* - * Fix up topo::core_id for pre-F17h systems to be in the - * [0 .. cores_per_node - 1] range. Not really needed but - * kept so as not to break existing setups. - */ -static void legacy_fixup_core_id(struct cpuinfo_x86 *c) -{ - u32 cus_per_node; - - if (c->x86 >= 0x17) - return; - - cus_per_node = c->x86_max_cores / nodes_per_socket; - c->topo.core_id %= cus_per_node; -} - -/* - * Fixup core topology information for - * (1) AMD multi-node processors - * Assumption: Number of cores in each internal node is the same. - * (2) AMD processors supporting compute units - */ -static void amd_get_topology(struct cpuinfo_x86 *c) -{ - /* get information required for multi-node processors */ - if (boot_cpu_has(X86_FEATURE_TOPOEXT)) { - int err; - u32 eax, ebx, ecx, edx; - - cpuid(0x8000001e, &eax, &ebx, &ecx, &edx); - - c->topo.die_id = ecx & 0xff; - - if (c->x86 == 0x15) - c->topo.cu_id = ebx & 0xff; - - if (c->x86 >= 0x17) { - c->topo.core_id = ebx & 0xff; - - if (smp_num_siblings > 1) - c->x86_max_cores /= smp_num_siblings; - } - - /* - * In case leaf B is available, use it to derive - * topology information. - */ - err = detect_extended_topology(c); - if (!err) - c->x86_coreid_bits = get_count_order(c->x86_max_cores); - - cacheinfo_amd_init_llc_id(c, c->topo.die_id); - - } else if (cpu_has(c, X86_FEATURE_NODEID_MSR)) { - u64 value; - - rdmsrl(MSR_FAM10H_NODE_ID, value); - c->topo.die_id = value & 7; - c->topo.llc_id = c->topo.die_id; - } else - return; - - if (nodes_per_socket > 1) { - set_cpu_cap(c, X86_FEATURE_AMD_DCM); - legacy_fixup_core_id(c); - } -} - -/* - * On a AMD dual core setup the lower bits of the APIC id distinguish the cores. - * Assumes number of cores is a power of two. - */ -static void amd_detect_cmp(struct cpuinfo_x86 *c) -{ - unsigned bits; - - bits = c->x86_coreid_bits; - /* Low order bits define the core id (index of core in socket) */ - c->topo.core_id = c->topo.initial_apicid & ((1 << bits)-1); - /* Convert the initial APIC ID into the socket ID */ - c->topo.pkg_id = c->topo.initial_apicid >> bits; - /* use socket ID also for last level cache */ - c->topo.llc_id = c->topo.die_id = c->topo.pkg_id; -} - -u32 amd_get_nodes_per_socket(void) -{ - return nodes_per_socket; -} -EXPORT_SYMBOL_GPL(amd_get_nodes_per_socket); - static void srat_detect_node(struct cpuinfo_x86 *c) { #ifdef CONFIG_NUMA @@ -514,32 +416,6 @@ static void srat_detect_node(struct cpui #endif } -static void early_init_amd_mc(struct cpuinfo_x86 *c) -{ -#ifdef CONFIG_SMP - unsigned bits, ecx; - - /* Multi core CPU? */ - if (c->extended_cpuid_level < 0x80000008) - return; - - ecx = cpuid_ecx(0x80000008); - - c->x86_max_cores = (ecx & 0xff) + 1; - - /* CPU telling us the core id bits shift? */ - bits = (ecx >> 12) & 0xF; - - /* Otherwise recompute */ - if (bits == 0) { - while ((1 << bits) < c->x86_max_cores) - bits++; - } - - c->x86_coreid_bits = bits; -#endif -} - static void bsp_init_amd(struct cpuinfo_x86 *c) { if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) { @@ -572,18 +448,6 @@ static void bsp_init_amd(struct cpuinfo_ if (cpu_has(c, X86_FEATURE_MWAITX)) use_mwaitx_delay(); - if (boot_cpu_has(X86_FEATURE_TOPOEXT)) { - u32 ecx; - - ecx = cpuid_ecx(0x8000001e); - __max_die_per_package = nodes_per_socket = ((ecx >> 8) & 7) + 1; - } else if (boot_cpu_has(X86_FEATURE_NODEID_MSR)) { - u64 value; - - rdmsrl(MSR_FAM10H_NODE_ID, value); - __max_die_per_package = nodes_per_socket = ((value >> 3) & 7) + 1; - } - if (!boot_cpu_has(X86_FEATURE_AMD_SSBD) && !boot_cpu_has(X86_FEATURE_VIRT_SSBD) && c->x86 >= 0x15 && c->x86 <= 0x17) { @@ -665,8 +529,6 @@ static void early_init_amd(struct cpuinf u64 value; u32 dummy; - early_init_amd_mc(c); - if (c->x86 >= 0xf) set_cpu_cap(c, X86_FEATURE_K8); @@ -754,9 +616,6 @@ static void early_init_amd(struct cpuinf } } } - - if (cpu_has(c, X86_FEATURE_TOPOEXT)) - smp_num_siblings = ((cpuid_ebx(0x8000001e) >> 8) & 0xff) + 1; } static void init_amd_k8(struct cpuinfo_x86 *c) @@ -1037,9 +896,6 @@ static void init_amd(struct cpuinfo_x86 if (cpu_has(c, X86_FEATURE_FSRM)) set_cpu_cap(c, X86_FEATURE_FSRS); - /* get apicid instead of initial apic id from cpuid */ - c->topo.apicid = read_apic_id(); - /* K6s reports MCEs but don't actually have all the MSRs */ if (c->x86 < 6) clear_cpu_cap(c, X86_FEATURE_MCE); @@ -1067,8 +923,6 @@ static void init_amd(struct cpuinfo_x86 cpu_detect_cache_sizes(c); - amd_detect_cmp(c); - amd_get_topology(c); srat_detect_node(c); init_amd_cacheinfo(c); --- a/arch/x86/kernel/cpu/mce/inject.c +++ b/arch/x86/kernel/cpu/mce/inject.c @@ -433,8 +433,7 @@ static u32 get_nbc_for_node(int node_id) struct cpuinfo_x86 *c = &boot_cpu_data; u32 cores_per_node; - cores_per_node = (c->x86_max_cores * smp_num_siblings) / amd_get_nodes_per_socket(); - + cores_per_node = (c->x86_max_cores * smp_num_siblings) / topology_amd_nodes_per_pkg(); return cores_per_node * node_id; } --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -72,7 +72,6 @@ bool topo_is_converted(struct cpuinfo_x8 { /* Temporary until everything is converted over. */ switch (boot_cpu_data.x86_vendor) { - case X86_VENDOR_AMD: case X86_VENDOR_HYGON: return false; default: @@ -133,6 +132,10 @@ static void parse_topology(struct topo_s tscan->ebx1_nproc_shift = get_count_order(ebx.nproc); switch (c->x86_vendor) { + case X86_VENDOR_AMD: + if (IS_ENABLED(CONFIG_CPU_SUP_AMD)) + cpu_parse_topology_amd(tscan); + break; case X86_VENDOR_CENTAUR: case X86_VENDOR_ZHAOXIN: parse_legacy(tscan); From patchwork Wed Aug 2 10:21:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129786 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp394243vqx; Wed, 2 Aug 2023 04:48:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlGjPwUJDmEEN4rAq9X5BopYWEdP3oVbXjsQYlmjDCi/XAHYm3EQJMbArV7mJ0B+tRGT/Feu X-Received: by 2002:a17:90b:1e49:b0:268:f8c8:bd5c with SMTP id pi9-20020a17090b1e4900b00268f8c8bd5cmr3608573pjb.17.1690976924512; Wed, 02 Aug 2023 04:48:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690976924; cv=none; d=google.com; s=arc-20160816; b=uWv/S3fREMr+hIAl8JXhG/ntqP+YaKk5ispcJbBOKRWidw9+eA542oVZ/PuA2ZNjKI wiu36EJ6g07YO2WZdpxiwvyvVjEOswaF6JrGtB0SPlUvw7aEpKO6Zyn9+l07tqyI89n4 +c1ksakidn0V5FxZ+i8eoHW/T5voGbzNzAUE+B0WXBuA235qOBVA4e5DVd3U/+/t8b+m c0pbtmQMwiA3cgpezPZLtiMKQAa47lwXEcHnznXyklQV2EjoQfAizO26LMSp3frq3OXt wMnELVwB6mpur/1sCso7RZoQBTu7Me6hQ2johUSHLlbl5GEYzDXe7lM+q74u8zhKh/Ij Po1A== 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=TA5kMoANUsWa3Lbd4gTHZqj4kHJyQLmBiDBM+ACDIDw=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=CNPrFgbODMCCR3d/Oyv7hyKTC4gFl4cMJBLA/MQGWUsEkyM2r8yF2mexxC8mCjh1B6 5271n23oQkxDmhx2RXWpLjd5kojye9iuh+8vU//nMUZ54W1G6dvt9YpnY4NqdJPtKLb9 zP21GRPVUoNbGnY3CP5KVD4IZvtLvrRTDSE0RiNiaknM1tKXWRprYrUV8PDzgLEd79uT o/+XUEHgl4HER4D3hGRolXOHwLFMMKPAThOqU3JJuwLaC8brXq8bYKyZk8M00WTa2XqP eCCc8o+3PvYUVAcPTbS0YtxO+wJCSkQHTIgs+qLfGmbKgPclIGqgmm1lIrWncR/5+rJW 43zQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zH8TGtlL; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=n81yfA4I; 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 p7-20020a17090a348700b0026803b4ddfcsi1076932pjb.103.2023.08.02.04.48.30; Wed, 02 Aug 2023 04:48:44 -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=zH8TGtlL; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=n81yfA4I; 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 S234045AbjHBKYi (ORCPT + 99 others); Wed, 2 Aug 2023 06:24:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233968AbjHBKXg (ORCPT ); Wed, 2 Aug 2023 06:23:36 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CDC72D68 for ; Wed, 2 Aug 2023 03:22:08 -0700 (PDT) Message-ID: <20230802101934.585648729@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971710; 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=TA5kMoANUsWa3Lbd4gTHZqj4kHJyQLmBiDBM+ACDIDw=; b=zH8TGtlLIyXduU6/qK7+Uf7xON0IhU/GdhqmvbuR7a1sccPhuWE8DGglG7lhpveNuKMLcn bnjKlno9bwg0zx1UmR3MtE6guaCdSScsnBy+w7xd2a/4QHkcdyCrJzVT/soNLTj6FN2ICI eja/WX5AWV8kMGzy2i1I/OXoU9sYQRpiQZF5MxwHaCLeOIe2Pf5ZL+JwFKhUiLMv8kuf9T T5hN9OBbLctsTbYEFF0cb7/Yixv+n+ooh/3o3Yb0SlawD/fos5kvP7zf9gJH5Ng6azkBSN cUBZUxPuiGnysqCxtpisdsGQcaCOlASfQCjVcj6vxpxxEZTjA6SxRmG2CxnPAg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971710; 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=TA5kMoANUsWa3Lbd4gTHZqj4kHJyQLmBiDBM+ACDIDw=; b=n81yfA4IUX2rFJ2E9DEGiTF3Nv8SuWr6es7I/la7aGngTXmQDOU7d/oAOyXuLYrstQYKAv GeNhR2/cosmGlODw== 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 , Wei Liu Subject: [patch V3 33/40] x86/cpu: Use common topology code for HYGON References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:49 +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,URIBL_BLOCKED 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: 1773117819592654155 X-GMAIL-MSGID: 1773117819592654155 Switch it over to use the consolidated topology evaluation and remove the temporary safe guards which are not longer needed. No functional change intended. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/cpu/common.c | 5 - arch/x86/kernel/cpu/cpu.h | 1 arch/x86/kernel/cpu/hygon.c | 123 ---------------------------------- arch/x86/kernel/cpu/topology.h | 1 arch/x86/kernel/cpu/topology_common.c | 22 +----- 5 files changed, 4 insertions(+), 148 deletions(-) --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1740,11 +1740,6 @@ static void identify_cpu(struct cpuinfo_ /* Clear/Set all flags overridden by options, after probe */ apply_forced_caps(c); -#ifdef CONFIG_X86_64 - if (!topo_is_converted(c)) - c->topo.apicid = apic->phys_pkg_id(c->topo.initial_apicid, 0); -#endif - /* * Vendor-specific initialization. In this section we * canonicalize the feature flags, meaning if there are --- a/arch/x86/kernel/cpu/cpu.h +++ b/arch/x86/kernel/cpu/cpu.h @@ -76,7 +76,6 @@ extern void init_intel_cacheinfo(struct extern void init_amd_cacheinfo(struct cpuinfo_x86 *c); extern void init_hygon_cacheinfo(struct cpuinfo_x86 *c); -extern int detect_extended_topology(struct cpuinfo_x86 *c); extern void check_null_seg_clears_base(struct cpuinfo_x86 *c); void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, u16 die_id); --- a/arch/x86/kernel/cpu/hygon.c +++ b/arch/x86/kernel/cpu/hygon.c @@ -20,12 +20,6 @@ #define APICID_SOCKET_ID_BIT 6 -/* - * nodes_per_socket: Stores the number of nodes per socket. - * Refer to CPUID Fn8000_001E_ECX Node Identifiers[10:8] - */ -static u32 nodes_per_socket = 1; - #ifdef CONFIG_NUMA /* * To workaround broken NUMA config. Read the comment in @@ -49,76 +43,6 @@ static int nearby_node(int apicid) } #endif -static void hygon_get_topology_early(struct cpuinfo_x86 *c) -{ - if (cpu_has(c, X86_FEATURE_TOPOEXT)) - smp_num_siblings = ((cpuid_ebx(0x8000001e) >> 8) & 0xff) + 1; -} - -/* - * Fixup core topology information for - * (1) Hygon multi-node processors - * Assumption: Number of cores in each internal node is the same. - * (2) Hygon processors supporting compute units - */ -static void hygon_get_topology(struct cpuinfo_x86 *c) -{ - /* get information required for multi-node processors */ - if (boot_cpu_has(X86_FEATURE_TOPOEXT)) { - int err; - u32 eax, ebx, ecx, edx; - - cpuid(0x8000001e, &eax, &ebx, &ecx, &edx); - - c->topo.die_id = ecx & 0xff; - - c->topo.core_id = ebx & 0xff; - - if (smp_num_siblings > 1) - c->x86_max_cores /= smp_num_siblings; - - /* - * In case leaf B is available, use it to derive - * topology information. - */ - err = detect_extended_topology(c); - if (!err) - c->x86_coreid_bits = get_count_order(c->x86_max_cores); - - /* Socket ID is ApicId[6] for these processors. */ - c->topo.pkg_id = c->topo.apicid >> APICID_SOCKET_ID_BIT; - - cacheinfo_hygon_init_llc_id(c); - } else if (cpu_has(c, X86_FEATURE_NODEID_MSR)) { - u64 value; - - rdmsrl(MSR_FAM10H_NODE_ID, value); - c->topo.die_id = value & 7; - c->topo.llc_id = c->topo.die_id; - } else - return; - - if (nodes_per_socket > 1) - set_cpu_cap(c, X86_FEATURE_AMD_DCM); -} - -/* - * On Hygon setup the lower bits of the APIC id distinguish the cores. - * Assumes number of cores is a power of two. - */ -static void hygon_detect_cmp(struct cpuinfo_x86 *c) -{ - unsigned int bits; - - bits = c->x86_coreid_bits; - /* Low order bits define the core id (index of core in socket) */ - c->topo.core_id = c->topo.initial_apicid & ((1 << bits)-1); - /* Convert the initial APIC ID into the socket ID */ - c->topo.pkg_id = c->topo.initial_apicid >> bits; - /* Use package ID also for last level cache */ - c->topo.llc_id = c->topo.die_id = c->topo.pkg_id; -} - static void srat_detect_node(struct cpuinfo_x86 *c) { #ifdef CONFIG_NUMA @@ -169,32 +93,6 @@ static void srat_detect_node(struct cpui #endif } -static void early_init_hygon_mc(struct cpuinfo_x86 *c) -{ -#ifdef CONFIG_SMP - unsigned int bits, ecx; - - /* Multi core CPU? */ - if (c->extended_cpuid_level < 0x80000008) - return; - - ecx = cpuid_ecx(0x80000008); - - c->x86_max_cores = (ecx & 0xff) + 1; - - /* CPU telling us the core id bits shift? */ - bits = (ecx >> 12) & 0xF; - - /* Otherwise recompute */ - if (bits == 0) { - while ((1 << bits) < c->x86_max_cores) - bits++; - } - - c->x86_coreid_bits = bits; -#endif -} - static void bsp_init_hygon(struct cpuinfo_x86 *c) { if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) { @@ -208,18 +106,6 @@ static void bsp_init_hygon(struct cpuinf if (cpu_has(c, X86_FEATURE_MWAITX)) use_mwaitx_delay(); - if (boot_cpu_has(X86_FEATURE_TOPOEXT)) { - u32 ecx; - - ecx = cpuid_ecx(0x8000001e); - __max_die_per_package = nodes_per_socket = ((ecx >> 8) & 7) + 1; - } else if (boot_cpu_has(X86_FEATURE_NODEID_MSR)) { - u64 value; - - rdmsrl(MSR_FAM10H_NODE_ID, value); - __max_die_per_package = nodes_per_socket = ((value >> 3) & 7) + 1; - } - if (!boot_cpu_has(X86_FEATURE_AMD_SSBD) && !boot_cpu_has(X86_FEATURE_VIRT_SSBD)) { /* @@ -238,8 +124,6 @@ static void early_init_hygon(struct cpui { u32 dummy; - early_init_hygon_mc(c); - set_cpu_cap(c, X86_FEATURE_K8); rdmsr_safe(MSR_AMD64_PATCH_LEVEL, &c->microcode, &dummy); @@ -280,8 +164,6 @@ static void early_init_hygon(struct cpui * we can set it unconditionally. */ set_cpu_cap(c, X86_FEATURE_VMMCALL); - - hygon_get_topology_early(c); } static void init_hygon(struct cpuinfo_x86 *c) @@ -296,9 +178,6 @@ static void init_hygon(struct cpuinfo_x8 set_cpu_cap(c, X86_FEATURE_REP_GOOD); - /* get apicid instead of initial apic id from cpuid */ - c->topo.apicid = read_apic_id(); - /* * XXX someone from Hygon needs to confirm this DTRT * @@ -310,8 +189,6 @@ static void init_hygon(struct cpuinfo_x8 cpu_detect_cache_sizes(c); - hygon_detect_cmp(c); - hygon_get_topology(c); srat_detect_node(c); init_hygon_cacheinfo(c); --- a/arch/x86/kernel/cpu/topology.h +++ b/arch/x86/kernel/cpu/topology.h @@ -15,7 +15,6 @@ struct topo_scan { u16 amd_node_id; }; -bool topo_is_converted(struct cpuinfo_x86 *c); void cpu_init_topology(struct cpuinfo_x86 *c); void cpu_parse_topology(struct cpuinfo_x86 *c); void topology_set_dom(struct topo_scan *tscan, enum x86_topology_domains dom, --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -68,18 +68,6 @@ static void parse_legacy(struct topo_sca topology_set_dom(tscan, TOPO_CORE_DOMAIN, core_shift, cores); } -bool topo_is_converted(struct cpuinfo_x86 *c) -{ - /* Temporary until everything is converted over. */ - switch (boot_cpu_data.x86_vendor) { - case X86_VENDOR_HYGON: - return false; - default: - /* Let all UP systems use the below */ - return true; - } -} - static bool fake_topology(struct topo_scan *tscan) { /* @@ -144,6 +132,10 @@ static void parse_topology(struct topo_s if (!IS_ENABLED(CONFIG_CPU_SUP_INTEL) || !cpu_parse_topology_ext(tscan)) parse_legacy(tscan); break; + case X86_VENDOR_HYGON: + if (IS_ENABLED(CONFIG_CPU_SUP_HYGON)) + cpu_parse_topology_amd(tscan); + break; } } @@ -186,9 +178,6 @@ void cpu_parse_topology(struct cpuinfo_x parse_topology(&tscan, false); - if (!topo_is_converted(c)) - return; - for (dom = TOPO_SMT_DOMAIN; dom < TOPO_MAX_DOMAIN; dom++) { if (tscan.dom_shifts[dom] == x86_topo_system.dom_shifts[dom]) continue; @@ -217,9 +206,6 @@ void __init cpu_init_topology(struct cpu parse_topology(&tscan, true); - if (!topo_is_converted(c)) - return; - /* Copy the shift values and calculate the unit sizes. */ memcpy(x86_topo_system.dom_shifts, tscan.dom_shifts, sizeof(x86_topo_system.dom_shifts)); From patchwork Wed Aug 2 10:21:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129772 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp375920vqx; Wed, 2 Aug 2023 04:13:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlFwsCaUxKt8HveKGzVOFMy2o3W3tJ6Z3S69dTUKHrkYZfld95yX2WWNCDSjTvclDQ0bY5Kj X-Received: by 2002:a05:6a21:6da1:b0:13d:82eb:795a with SMTP id wl33-20020a056a216da100b0013d82eb795amr9744792pzb.56.1690974824174; Wed, 02 Aug 2023 04:13:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690974824; cv=none; d=google.com; s=arc-20160816; b=zuNCLHzMEIJ8za7yufXBj9HjjUuSkgOhyvrobZsUGoLiTbIz9zu3V4PpexnrChLazr YB2IWBR4RQxTAedCMatySOOcuo5tRg/H5YAJjq6KM1iPKMklSWJ698V28qgq9QQq/eCl B7XRjlYzJMjgiNK2JKoZU4huaGjVzLF+CefxlQpobzDKML2J0eqXML0kbvf/HJGfV1yy GunRmC+rE6ieIicG7ap4Y1Nhd9nrSsGizjoM/btVWLKByZYZrd0lozvqPEBBeLMdevCP YbnVx6+j36fDtd/UiTvGOqcXXmVVjqB8E9UVeq5AaiXG3HNTj0nG96yAN7K501Wg3w4Z ZB1g== 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=v1jagm3qezJbhLi1KwbMq1PXX83lXTZZ+4TGqrP0z90=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=kxO59yMSTNLP1XX2EGJxpDiG2LzY/Hzc1YZ6gErp1f6ysyitrcNznn2iw740mGF4+O yYNeZVaCrvjj1qk4pGvktKyw5ZKlThDqijReESLPO/RH6jR5SXPHS9fq91OYKBDTY0tL Mb36qabkggx3n+JEVCGrELg+Isha0ZmIBvhmxnko1AJ7lM+sl5PGtayC4MdP97zGvBRY YZQMi4WtNACTxuCxWMMm3jPrO5BWpfu5pTFzrfExhZxLV46O4+GQq6wqz84UndYTM5E9 XSgMNUIuuJ34sNfQoIXEzjKEYkQB/J2LYsuwg0OEdArf/G4fB1mMupYo7r3u857HqH7O NjPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=kcLGAGr8; dkim=neutral (no key) header.i=@linutronix.de header.b=Rld9lTpV; 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 z16-20020a656650000000b005646d7e538esi2725473pgv.128.2023.08.02.04.13.28; Wed, 02 Aug 2023 04:13:44 -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=kcLGAGr8; dkim=neutral (no key) header.i=@linutronix.de header.b=Rld9lTpV; 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 S233996AbjHBKYe (ORCPT + 99 others); Wed, 2 Aug 2023 06:24:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233882AbjHBKXg (ORCPT ); Wed, 2 Aug 2023 06:23:36 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DB032698 for ; Wed, 2 Aug 2023 03:22:10 -0700 (PDT) Message-ID: <20230802101934.641924080@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971711; 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=v1jagm3qezJbhLi1KwbMq1PXX83lXTZZ+4TGqrP0z90=; b=kcLGAGr8vM7wxvnJDZAIm84qWUyLQbZ131GYhWR2nUBgH0BXNc6LRZhNc/r/nhMZvhkC7j Er15Y6d7blSR2skuIbHBbCvfp5fXidLCf64XMiEKMBXXEbPyP9oooFaiGhP4eKLie51jAf h/KCzGBHBZ9Jj0Fh6QI3ebmNfejCLflyATl2tyQID9NDC8tCDPVn+EZMcag5IEPeFxiEWW UB2Z0wfmpAxVeBMaDu8W5HvJ8w6Jgb1Ksda7mDKPa4hjvaJ1Y2ixw1yHXW9nl17d/adP7F 2cvFJ5D67t+7WuhCcRmEZbIOOpje8O410+DVWt0vYwBhzM16foHhf+zv5MJTdQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971711; 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=v1jagm3qezJbhLi1KwbMq1PXX83lXTZZ+4TGqrP0z90=; b=Rld9lTpVgQxq7V1PlqmPdI+w4f3FHxOXbaCI/j/VRhw5TtTS+OHW0NxB/T8ZpUPqMrWNFD l95uR0m/lpfAqzBg== 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 , Wei Liu Subject: [patch V3 34/40] x86/mm/numa: Use core domain size on AMD References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:51 +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,URIBL_BLOCKED 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: 1773115617122916389 X-GMAIL-MSGID: 1773115617122916389 cpuinfo::topo::x86_coreid_bits is about to be phased out. Use the core domain size from the topology information. Add a comment why the early MPTABLE parsing is required and decrapify the loop which sets the APIC ID to node map. Signed-off-by: Thomas Gleixner --- arch/x86/mm/amdtopology.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) --- a/arch/x86/mm/amdtopology.c +++ b/arch/x86/mm/amdtopology.c @@ -54,13 +54,11 @@ static __init int find_northbridge(void) int __init amd_numa_init(void) { - u64 start = PFN_PHYS(0); + unsigned int numnodes, cores, apicid; + u64 prevbase, start = PFN_PHYS(0); u64 end = PFN_PHYS(max_pfn); - unsigned numnodes; - u64 prevbase; - int i, j, nb; u32 nodeid, reg; - unsigned int bits, cores, apicid_base; + int i, j, nb; if (!early_pci_allowed()) return -EINVAL; @@ -158,26 +156,25 @@ int __init amd_numa_init(void) return -ENOENT; /* - * We seem to have valid NUMA configuration. Map apicids to nodes - * using the coreid bits from early_identify_cpu. + * We seem to have valid NUMA configuration. Map apicids to nodes + * using the size of the core domain in the APIC space. */ - bits = boot_cpu_data.x86_coreid_bits; - cores = 1 << bits; - apicid_base = 0; + cores = topology_get_domain_size(TOPO_CORE_DOMAIN); /* - * get boot-time SMP configuration: + * Scan MPTABLE to map the local APIC and ensure that the boot CPU + * APIC ID is valid. This is required because on pre ACPI/SRAT + * systems IO-APICs are mapped before the boot CPU. */ early_get_smp_config(); - if (boot_cpu_physical_apicid > 0) { - pr_info("BSP APIC ID: %02x\n", boot_cpu_physical_apicid); - apicid_base = boot_cpu_physical_apicid; + apicid = boot_cpu_physical_apicid; + if (apicid > 0) + pr_info("BSP APIC ID: %02x\n", apicid); + + for_each_node_mask(i, numa_nodes_parsed) { + for (j = 0; j < cores; j++, apicid++) + set_apicid_to_node(apicid, i); } - - for_each_node_mask(i, numa_nodes_parsed) - for (j = apicid_base; j < cores + apicid_base; j++) - set_apicid_to_node((i << bits) + j, i); - return 0; } From patchwork Wed Aug 2 10:21:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129764 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp366367vqx; Wed, 2 Aug 2023 03:57:38 -0700 (PDT) X-Google-Smtp-Source: APBJJlGzyvQwJJDiEw45FIcO6IgxnTJ/ayuEDfWIcnpegDB6IlA1uYaDvLOrBYdbkgi2HWfTasT8 X-Received: by 2002:a17:906:2092:b0:99b:c0f0:77fe with SMTP id 18-20020a170906209200b0099bc0f077femr4825768ejq.69.1690973858015; Wed, 02 Aug 2023 03:57:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690973858; cv=none; d=google.com; s=arc-20160816; b=uc4br4dzkUmDCUl8JWFwuFXLEBPeyjw2EKr5ALYZKlKPsxx04RLWZ5LLbpV0LOOZpK Qm2djV7PW87/6I4aYm8teGDyFmXrh58hgjdO+5ZYStdMYI/g1GRJqpMbzNlx+w5N4rjq Zk3yZlvNE+Yz95+6gHS4IQSMN0i/j8XMOGlnY7+wWDw4ql8vhkaZ61VPDFqXOlPex2sP 8hlsiMPPOkQg+mlR9jgQDBxGMcdL4thFBwK8Kbvn7znJuqH/AOyQvLjhC90zDEzwTY5s rFq4vgyBV8f5AuOgyR5HxB3XYH1ZmqioREORjKsZNoZjklbJl2lM/BaXb7YiDlPhHqXe IZVQ== 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=u2nALLK7m8WtmbLIhAtObAjpwOgRje3zo0FH2XahcbM=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=b8FPsQsGGVT5FPvpoUUMyRR5Dv46nDUhZGKjJ7hZUJEMbmpHZx9ibEwuvR1g71vh89 67GZTdXD0yis9zRh3etL9WJ05PRSIwwMMHTIVcBaA5xYA1HvMVDFbxRE6lpwjpPSkrLr 0L6mgQDb7MoWUjyjxwL8kEAwsdRBlnZHu42VppXWY/aJT6rtpafPwLmsT3CLqLP1BjYt rDlGZvjgwmkoLjeTyZAoKcMa5cidTO9winASDHPuRpTds3/X/IrOgqJP+VseiJJ2MJcC grCdWYroG39/Iw7nAqrYRa+1qu1t7SppQU9xwM1N8A5X4IxQI61alBsMvwnfudgBZhqd Y8tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=V1ZQMVFt; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=KUxFA0xV; 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 rl19-20020a170907217300b00992f309cfe7si9723213ejb.602.2023.08.02.03.57.13; Wed, 02 Aug 2023 03:57:37 -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=V1ZQMVFt; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=KUxFA0xV; 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 S234118AbjHBKYl (ORCPT + 99 others); Wed, 2 Aug 2023 06:24:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233969AbjHBKXg (ORCPT ); Wed, 2 Aug 2023 06:23:36 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 994C42D63 for ; Wed, 2 Aug 2023 03:22:10 -0700 (PDT) Message-ID: <20230802101934.697864803@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971713; 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=u2nALLK7m8WtmbLIhAtObAjpwOgRje3zo0FH2XahcbM=; b=V1ZQMVFtncXtGerj1HgIM1h59JhPlJ0LMTjszh4xqFaJdDWIa3KDngXHayE016EySYRWge z0yPaL8vi07fb/MDCjbhkUOmA2vyOKNyKSPt7o2756Xuy9Q09mu3UfF2SwsQyckj6paJgR Zk9W+eGkBiMI5O+Nj8ryIKn09CI+Px68+no7DEyY8lZtFCiQHWatJu20OKBr9bW4DPc+9o UocJH1Tlus2VgxkqIjnzsbc9tIBvpbAuI3mGBg2P3grBZZFzLxjwck+SgyDDzywF2oLTjO pFrQGYRWrWzM9B7PLmnYwN9f6fDm4YYkeyeDKVXT2I4BB6e/QRmc3+e7ZTi3ng== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971713; 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=u2nALLK7m8WtmbLIhAtObAjpwOgRje3zo0FH2XahcbM=; b=KUxFA0xVZ8ayqRUIOZBP71zhYfRW4LR2h51trRVzZrx4qIYFw/Z5tLHObASu+spzuIj3sz 3p8OYCsXLqQ61BCw== 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 , Wei Liu Subject: [patch V3 35/40] x86/cpu: Make topology_amd_node_id() use the actual node info References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:52 +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,URIBL_BLOCKED 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: 1773114603922659993 X-GMAIL-MSGID: 1773114603922659993 Now that everything is converted switch it over and remove the intermediate operation. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/topology.h | 4 ++-- arch/x86/kernel/cpu/topology_common.c | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -136,7 +136,7 @@ extern const struct cpumask *cpu_cluster #define topology_core_id(cpu) (cpu_data(cpu).topo.core_id) #define topology_ppin(cpu) (cpu_data(cpu).ppin) -#define topology_amd_node_id(cpu) (cpu_data(cpu).topo.die_id) +#define topology_amd_node_id(cpu) (cpu_data(cpu).topo.amd_node_id) extern unsigned int __max_die_per_package; @@ -171,7 +171,7 @@ extern unsigned int __amd_nodes_per_pkg; static inline unsigned int topology_amd_nodes_per_pkg(void) { - return __max_die_per_package; + return __amd_nodes_per_pkg; } extern struct cpumask __cpu_primary_thread_mask; --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -143,9 +143,7 @@ static void topo_set_ids(struct topo_sca /* Relative core ID */ c->topo.core_id = topo_relative_domain_id(apicid, TOPO_CORE_DOMAIN); - /* Temporary workaround */ - if (tscan->amd_nodes_per_pkg) - c->topo.amd_node_id = c->topo.die_id = tscan->amd_node_id; + c->topo.amd_node_id = tscan->amd_node_id; if (c->x86_vendor == X86_VENDOR_AMD) cpu_topology_fixup_amd(tscan); @@ -231,6 +229,5 @@ void __init cpu_init_topology(struct cpu * AMD systems have Nodes per package which cannot be mapped to * APIC ID (yet). */ - if (c->x86_vendor == X86_VENDOR_AMD || c->x86_vendor == X86_VENDOR_HYGON) - __amd_nodes_per_pkg = __max_die_per_package = tscan.amd_nodes_per_pkg; + __amd_nodes_per_pkg = tscan.amd_nodes_per_pkg; } From patchwork Wed Aug 2 10:21:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129820 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp446236vqx; Wed, 2 Aug 2023 06:12:06 -0700 (PDT) X-Google-Smtp-Source: APBJJlGMmMM2tQpb2pGQB3zqz+9NPIBpUda7H3J8xf5wokldY24+50CfJ5CjqmAVSndSr32CnNZb X-Received: by 2002:a05:6a20:440b:b0:13d:7ad5:a1c0 with SMTP id ce11-20020a056a20440b00b0013d7ad5a1c0mr14276259pzb.10.1690981926460; Wed, 02 Aug 2023 06:12:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690981926; cv=none; d=google.com; s=arc-20160816; b=N5r8/y1oqU2+6LqEanbAUfMJR2/tAGLO0f5LpvWP31RYF6gts2jFdzJZYrlAUGMqUw 42SAP74tg00On4GMwr7nFi/ZrazZz0WBUStyBo0FtR9smhB+ETVEcxJhlvobItPfnum/ mg21bTJjXmKrhQ5oyWCrZfQ5YjZ+OOtyfjN0x3/UARK6E9n3HqV7jal6BqarTvNbeNq3 4BJDGJ0iRyMp4wgxcnauQpc1wYIrWFqaK4YzAtYBlNqbRkRVpxx2dzZWvcHGieh3Q/yn 3xdJwnRSUQktoqe6LK0Aq+PyleUiaI0rWQVku9fFq8tqAT2VaPNMMiNLEULmF37dn/1h i4EA== 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=nCoiYGGGz2nXOq7tjWjNlQvkWfPVDpABc4VMP3k40m8=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=sNqVG6VY0pu0VKGPFBvDwDGA7tBTsaEQf+iL/c9U3yLvcJfXW5HxFl00aYanZMkhM/ q/w8leII4miBm4wYinLltzC/ny85qWJP4lXM5BDmbUnmmmuabBmO1YN2d1xDG/johLT0 fXaDMegl3E8JVR/NagjiJNNa1ltXBTfWoPdB1iZJDZHjmWv3q0ceitQR+NQ3OcrM4d1A 4Z9FGFTxe85WW89rFfsnEOxC7QS0aJe8j+S11+/rBO1xlhUte0NbpkiNuP0bsW4cSm7a 2OcKwSJtg3FejX70Y+hSoLrOxX3o35AGS7QKECYqFcG6Z/Ds8+EQhqAtNRuXfsCDFu8D Ak0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="mJdKU1/i"; dkim=neutral (no key) header.i=@linutronix.de header.b=+IHLFYbR; 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 cm5-20020a056a00338500b0067d204bf281si6765313pfb.3.2023.08.02.06.11.44; Wed, 02 Aug 2023 06:12:06 -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="mJdKU1/i"; dkim=neutral (no key) header.i=@linutronix.de header.b=+IHLFYbR; 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 S234105AbjHBK0A (ORCPT + 99 others); Wed, 2 Aug 2023 06:26:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232208AbjHBKZQ (ORCPT ); Wed, 2 Aug 2023 06:25:16 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 674EF49EB for ; Wed, 2 Aug 2023 03:22:48 -0700 (PDT) Message-ID: <20230802101934.754233993@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971715; 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=nCoiYGGGz2nXOq7tjWjNlQvkWfPVDpABc4VMP3k40m8=; b=mJdKU1/i2bGy/P9wcTY2msxEYqB2t7wFaSh2ACCt7KPeMtNSIR02UWGjaSHFUIId+fj+bT Gzjc2/Ix/EOCUdjv6erB4R1LI4POIbkOD9ZBGJkhYTkrU66+80BSrN46OeVS0ESz2Q00jR R9fwZsM+jXj2XNTQEtqKwmBknFEzvDC4YT0767NejkvK+A2wvtJj4+0L6ZheAQ+/yMzSnB d853ssi9pnfu5SuBDFOsdnKcBCXSAeBLwakNfFCEj6bVJG8W1V6aguIKJlyJ9i14UJ56uT 3FK+lfz37bPnyQq6yize+k8sYcn/zajnRdH46T8fRUyqeU4GdAE9hwh509IPVA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971715; 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=nCoiYGGGz2nXOq7tjWjNlQvkWfPVDpABc4VMP3k40m8=; b=+IHLFYbRhJvyGkoEBXzpz9LKREoxjh08+I5nP10aTIlUnyj206KIC05MuMZzakQa5co0qu HJc5LL/K0FNHQVDw== 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 , Wei Liu Subject: [patch V3 36/40] x86/cpu: Remove topology.c References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:54 +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,URIBL_BLOCKED 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: 1773123064654688997 X-GMAIL-MSGID: 1773123064654688997 No more users. Stick it into the ugly code museum. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/cpu/Makefile | 2 arch/x86/kernel/cpu/topology.c | 164 ----------------------------------------- 2 files changed, 1 insertion(+), 165 deletions(-) --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile @@ -18,7 +18,7 @@ KMSAN_SANITIZE_common.o := n KCSAN_SANITIZE_common.o := n obj-y := cacheinfo.o scattered.o -obj-y += topology_common.o topology_ext.o topology_amd.o topology.o +obj-y += topology_common.o topology_ext.o topology_amd.o obj-y += common.o obj-y += rdrand.o obj-y += match.o --- a/arch/x86/kernel/cpu/topology.c +++ /dev/null @@ -1,164 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Check for extended topology enumeration cpuid leaf 0xb and if it - * exists, use it for populating initial_apicid and cpu topology - * detection. - */ - -#include -#include -#include -#include - -#include "cpu.h" - -/* leaf 0xb SMT level */ -#define SMT_LEVEL 0 - -/* extended topology sub-leaf types */ -#define INVALID_TYPE 0 -#define SMT_TYPE 1 -#define CORE_TYPE 2 -#define DIE_TYPE 5 - -#define LEAFB_SUBTYPE(ecx) (((ecx) >> 8) & 0xff) -#define BITS_SHIFT_NEXT_LEVEL(eax) ((eax) & 0x1f) -#define LEVEL_MAX_SIBLINGS(ebx) ((ebx) & 0xffff) - -#ifdef CONFIG_SMP -/* - * Check if given CPUID extended topology "leaf" is implemented - */ -static int check_extended_topology_leaf(int leaf) -{ - unsigned int eax, ebx, ecx, edx; - - cpuid_count(leaf, SMT_LEVEL, &eax, &ebx, &ecx, &edx); - - if (ebx == 0 || (LEAFB_SUBTYPE(ecx) != SMT_TYPE)) - return -1; - - return 0; -} -/* - * Return best CPUID Extended Topology Leaf supported - */ -static int detect_extended_topology_leaf(struct cpuinfo_x86 *c) -{ - if (c->cpuid_level >= 0x1f) { - if (check_extended_topology_leaf(0x1f) == 0) - return 0x1f; - } - - if (c->cpuid_level >= 0xb) { - if (check_extended_topology_leaf(0xb) == 0) - return 0xb; - } - - return -1; -} -#endif - -int detect_extended_topology_early(struct cpuinfo_x86 *c) -{ -#ifdef CONFIG_SMP - unsigned int eax, ebx, ecx, edx; - int leaf; - - leaf = detect_extended_topology_leaf(c); - if (leaf < 0) - return -1; - - set_cpu_cap(c, X86_FEATURE_XTOPOLOGY); - - cpuid_count(leaf, SMT_LEVEL, &eax, &ebx, &ecx, &edx); - /* - * initial apic id, which also represents 32-bit extended x2apic id. - */ - c->topo.initial_apicid = edx; - smp_num_siblings = max_t(int, smp_num_siblings, LEVEL_MAX_SIBLINGS(ebx)); -#endif - return 0; -} - -/* - * Check for extended topology enumeration cpuid leaf, and if it - * exists, use it for populating initial_apicid and cpu topology - * detection. - */ -int detect_extended_topology(struct cpuinfo_x86 *c) -{ -#ifdef CONFIG_SMP - unsigned int eax, ebx, ecx, edx, sub_index; - unsigned int ht_mask_width, core_plus_mask_width, die_plus_mask_width; - unsigned int core_select_mask, core_level_siblings; - unsigned int die_select_mask, die_level_siblings; - unsigned int pkg_mask_width; - bool die_level_present = false; - int leaf; - - leaf = detect_extended_topology_leaf(c); - if (leaf < 0) - return -1; - - /* - * Populate HT related information from sub-leaf level 0. - */ - cpuid_count(leaf, SMT_LEVEL, &eax, &ebx, &ecx, &edx); - c->topo.initial_apicid = edx; - core_level_siblings = LEVEL_MAX_SIBLINGS(ebx); - smp_num_siblings = max_t(int, smp_num_siblings, LEVEL_MAX_SIBLINGS(ebx)); - core_plus_mask_width = ht_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); - die_level_siblings = LEVEL_MAX_SIBLINGS(ebx); - pkg_mask_width = die_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); - - sub_index = 1; - while (true) { - cpuid_count(leaf, sub_index, &eax, &ebx, &ecx, &edx); - - /* - * Check for the Core type in the implemented sub leaves. - */ - if (LEAFB_SUBTYPE(ecx) == CORE_TYPE) { - core_level_siblings = LEVEL_MAX_SIBLINGS(ebx); - core_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); - die_level_siblings = core_level_siblings; - die_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); - } - if (LEAFB_SUBTYPE(ecx) == DIE_TYPE) { - die_level_present = true; - die_level_siblings = LEVEL_MAX_SIBLINGS(ebx); - die_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); - } - - if (LEAFB_SUBTYPE(ecx) != INVALID_TYPE) - pkg_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); - else - break; - - sub_index++; - } - - core_select_mask = (~(-1 << pkg_mask_width)) >> ht_mask_width; - die_select_mask = (~(-1 << die_plus_mask_width)) >> - core_plus_mask_width; - - c->topo.core_id = apic->phys_pkg_id(c->topo.initial_apicid, - ht_mask_width) & core_select_mask; - - if (die_level_present) { - c->topo.die_id = apic->phys_pkg_id(c->topo.initial_apicid, - core_plus_mask_width) & die_select_mask; - } - - c->topo.pkg_id = apic->phys_pkg_id(c->topo.initial_apicid, pkg_mask_width); - /* - * Reinit the apicid, now that we have extended initial_apicid. - */ - c->topo.apicid = apic->phys_pkg_id(c->topo.initial_apicid, 0); - - c->x86_max_cores = (core_level_siblings / smp_num_siblings); - __max_die_per_package = (die_level_siblings / core_level_siblings); -#endif - return 0; -} From patchwork Wed Aug 2 10:21:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129758 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp361528vqx; Wed, 2 Aug 2023 03:46:07 -0700 (PDT) X-Google-Smtp-Source: APBJJlE246qafiAZ6xCciYJwmC6KI0o74SUIo5D8fMzgghnnFvG/p8qY5Wf+89uvh4BxloT967c3 X-Received: by 2002:a17:907:7784:b0:99b:ed8f:551d with SMTP id ky4-20020a170907778400b0099bed8f551dmr4757103ejc.55.1690973167578; Wed, 02 Aug 2023 03:46:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690973167; cv=none; d=google.com; s=arc-20160816; b=h6jU8Wg6+iF9sOVKHEwuspWNtqUYEp8ZvoSAza3NHwbFTMYOmAnOWXLPWtufv2N01m 9emqaJO1oVkDT/DQwbwe1LFh1K1EsLgmZA9X8zJFrvmu5zZWdG++D96ENpQRQ6GzOKHE u9TOdpMrCLkWGnjmxeFCS1alrIhPZtG8W+lUbbuFQlsB4IL2UmdpLTYZqMPawLx8+lW9 ffdozO+W5rfXJgGEENNDZLSWDYWHIsa46F37VaH+YtkzgyHUVuIqqScZS8YNJmdf8MfP qlm12zjl9OjDPqlVWn7jE2kosjo0NWM2yZ7rR7qZUovZI9wVTEdaXWfRzfdm6CLiIjzE AK1g== 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=NtDDi1Qa1O0ardBTEkM6u4SIs1c9Ae4E5SceZDfIb58=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=djQM0a1WHLF7BjVtGUh7gbnjZDCLbyvksCNAShaXatCQB/ASVFp4/Vcspla81xcKtF 2EOF1Lbfm1sz3Zkfl/IjEDQi9/YDesTb5A6qkneSMHGtjRXHMD49WWvpf/fMkDpwH/cJ PRVTKDBPXJEelVO2O6XsEJXQ0wK2dMnOdBx5DsEHHWsLz2qbGjrqnw/Tsqv72VEad6+M 1DgE8nZtg1DsiFqJCvG0g+VQopPnRhmy6ip0TJUSGqvz9l//9tYevMBaff0ANRTr0o36 OSRchkVQr8Fi7HzsXTlhC/XYtr6IL86VOJgrKkvXgfdBFXhZyabxGNq83gXmXU6bAEvK 5hDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3e+x0U8+; 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 l12-20020a1709066b8c00b009927d850155si10390108ejr.892.2023.08.02.03.45.42; Wed, 02 Aug 2023 03:46:07 -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=3e+x0U8+; 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 S233969AbjHBKYo (ORCPT + 99 others); Wed, 2 Aug 2023 06:24:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233997AbjHBKXu (ORCPT ); Wed, 2 Aug 2023 06:23:50 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E416E2D73 for ; Wed, 2 Aug 2023 03:22:12 -0700 (PDT) Message-ID: <20230802101934.810512981@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971716; 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=NtDDi1Qa1O0ardBTEkM6u4SIs1c9Ae4E5SceZDfIb58=; b=3e+x0U8+mzz4mcQM79r+01qP7gcm7nVeAOu1xrduA0PgtwTapDTEguOzDfKBU7+9SUplSb 9METcUgQvpDdx+kltqaJtgtVyN0S3ZXQBXM8U+9aSizfj9z9TabbRHjapnprHa9fffHBfN gUHtoHCKs6h31u7tC/9+FWnH5HismuuNGM05bqimkuLq4grmJdZJw9GUbCUGfe1g0Rh3eO ZU1UzPUL/LCXnmtFIMQvyQQdKL5+JMPDXg3V7TqEidHKuJIfvb6nxLEpfKKFRUKLN+BTOx pswJSO5yQyXZhNuK3bHL2ZCWkYYO/N0o82bPZ2lwAxVv2Fbio2+HxEaDsp6oow== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971716; 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=NtDDi1Qa1O0ardBTEkM6u4SIs1c9Ae4E5SceZDfIb58=; b=yjsJUdnsCFW+SnaGThqE2afePVDQQhkPsVQcCWHFcze+aNR7ovTJXiFXbpPBWbZngvn9Lr 9t6qpUCIRG4MfcDA== 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 , Wei Liu Subject: [patch V3 37/40] x86/cpu: Remove x86_coreid_bits References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:56 +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,URIBL_BLOCKED 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: 1773113879710842774 X-GMAIL-MSGID: 1773113879710842774 No more users. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/processor.h | 2 -- arch/x86/kernel/cpu/common.c | 1 - 2 files changed, 3 deletions(-) --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -119,8 +119,6 @@ struct cpuinfo_x86 { #endif __u8 x86_virt_bits; __u8 x86_phys_bits; - /* CPUID returned core id bits: */ - __u8 x86_coreid_bits; /* Max extended CPUID function supported: */ __u32 extended_cpuid_level; /* Maximum supported CPUID level, -1=no CPUID: */ --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1712,7 +1712,6 @@ static void identify_cpu(struct cpuinfo_ c->x86_vendor_id[0] = '\0'; /* Unset */ c->x86_model_id[0] = '\0'; /* Unset */ c->x86_max_cores = 1; - c->x86_coreid_bits = 0; #ifdef CONFIG_X86_64 c->x86_clflush_size = 64; c->x86_phys_bits = 36; From patchwork Wed Aug 2 10:21:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129773 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp376303vqx; Wed, 2 Aug 2023 04:14:21 -0700 (PDT) X-Google-Smtp-Source: APBJJlEx4Lahf9WnG5/csNXNv2xxfsBx5SwjtaPjkBuOzfmv97OJGr6pBfxURIK7oUXnjCaX5hK3 X-Received: by 2002:a17:902:ea04:b0:1b8:17e8:547e with SMTP id s4-20020a170902ea0400b001b817e8547emr15357325plg.1.1690974860784; Wed, 02 Aug 2023 04:14:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690974860; cv=none; d=google.com; s=arc-20160816; b=YjZHItkCoZ/DHMV+2CHJzLykHBOBtjfQk4ANbsLGOm7YhtEDxcEsXitohS/gyAWgPF ys8D14oVc1ZQzJmwDPb+Ymu3bPilf/LF6SIiMuTYiBDKas6Abmq/7IolhlesRM/fqGAA LjGQkhihqK9trqBauC1wJFmowuNF12YtNog5sa5OYwv8aa6+Slbn6rw2S/SjqzsieKVI h3cKCd7+v4mCYUYZFras5i/2iRVmZNA7snqpyQAAXqbnKFrroP8Ixj+THfoxqo9Kl9JH 6yb3eyfIX2dOmyOHefqQ6Ue+xtUsssPGTdQz+QatoxfY+29Lncok4qDAkKoF207iSyUo rx6A== 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=ERFK+VFh6rECY3YAEH1UcTGlweh3EwxmdvhVGEi5pZg=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=nDPrBbyjpEVX7TP5G2mgHFoK6gSMoiAI8osPV+II2sV2dDHleivTxAyrAIbUX0EFS2 SGrOpBlV6Tdqtn1/d3sCwIjsY+TrV8TfaT8HXrEeaaDzv/wW2HLt3TvVFaLoik4HL9uU Vubz01AAbzEWTpKVvUXj7mxCiwScCRVNExbtTIiP6FYLjF4nts6J4aAvGMdnipAR1MXp WHIcUg2FmvSxz+veDSJEujB2zZH2BT3FbjuDgyb7smTz312E0bSMUxM7aobw2AD6xBGF xhqcnQQaXtkqAMooVXGjyptOsIwX27mUdCiDao4rziisyw/kRMYeAGGWcZtNDKvWv1xT 05Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3O1KayUj; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 u5-20020a17090282c500b001bb3499d8besi72984plz.478.2023.08.02.04.14.07; Wed, 02 Aug 2023 04:14:20 -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=3O1KayUj; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S232299AbjHBK0W (ORCPT + 99 others); Wed, 2 Aug 2023 06:26:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232838AbjHBKZx (ORCPT ); Wed, 2 Aug 2023 06:25:53 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 648593C13 for ; Wed, 2 Aug 2023 03:23:10 -0700 (PDT) Message-ID: <20230802101934.866730450@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971718; 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=ERFK+VFh6rECY3YAEH1UcTGlweh3EwxmdvhVGEi5pZg=; b=3O1KayUjGUHSjzvQwDknGeyZzNYi/sPzwx5f7hOjXDLdyowPNWAM/vOBpMzUca3IQDyXkX ZZzd+pvGqKUAPWqJ1HWQz56HDT50bWDJHutS6dYJNnnEyauNjWTVOUwNq40V7Cu48JvsZg Kv2tJpHsg8mpfpfPwvKlk75biKVQ1YrC9lP3j3wLcWiOucKg20aaUeIZ8Z2x6gceolTSOP Gj/mOnp8OX5L6Mx6SlMofhMjYeiKSbaw6gSI2Vt5wuf6F+elhuBSGwOz42WzZMQ3EOC7jm bU1ZO8ocKCRCYK2yU5PuA3o0gJS1KRAiYApWjdsZAxpu6/+6oLbjRMiCbvPgbQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971718; 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=ERFK+VFh6rECY3YAEH1UcTGlweh3EwxmdvhVGEi5pZg=; b=otWwmwUqUiEFPwWurQur5WmjLd2ylXs7q0z+53PiKIlW3WO9r+k2p1bprDtWim+HsmKZGG UHzQnZbz+G3OuoBQ== 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 , Wei Liu Subject: [patch V3 38/40] x86/apic: Remove unused phys_pkg_id() callback References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:57 +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,URIBL_BLOCKED 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: 1773115655303326006 X-GMAIL-MSGID: 1773115655303326006 Now that the core code does not use this monstrosity anymore, it's time to put it to rest. The only real purpose was to read the APIC ID on UV and VSMP systems for the actual evaluation. That's what the core code does now. For doing the actual shift operation there is truly no APIC callback required. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/apic.h | 1 - arch/x86/kernel/apic/apic_flat_64.c | 7 ------- arch/x86/kernel/apic/apic_noop.c | 3 --- arch/x86/kernel/apic/apic_numachip.c | 7 ------- arch/x86/kernel/apic/bigsmp_32.c | 6 ------ arch/x86/kernel/apic/local.h | 1 - arch/x86/kernel/apic/probe_32.c | 6 ------ arch/x86/kernel/apic/x2apic_cluster.c | 1 - arch/x86/kernel/apic/x2apic_phys.c | 6 ------ arch/x86/kernel/apic/x2apic_uv_x.c | 11 ----------- arch/x86/kernel/vsmp_64.c | 13 ------------- arch/x86/xen/apic.c | 6 ------ 12 files changed, 68 deletions(-) --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -296,7 +296,6 @@ struct apic { void (*init_apic_ldr)(void); void (*ioapic_phys_id_map)(physid_mask_t *phys_map, physid_mask_t *retmap); u32 (*cpu_present_to_apicid)(int mps_cpu); - u32 (*phys_pkg_id)(u32 cpuid_apic, int index_msb); u32 (*get_apic_id)(u32 id); u32 (*set_apic_id)(u32 apicid); --- a/arch/x86/kernel/apic/apic_flat_64.c +++ b/arch/x86/kernel/apic/apic_flat_64.c @@ -66,11 +66,6 @@ static u32 set_apic_id(u32 id) return (id & 0xFF) << 24; } -static u32 flat_phys_pkg_id(u32 initial_apic_id, int index_msb) -{ - return initial_apic_id >> index_msb; -} - static int flat_probe(void) { return 1; @@ -89,7 +84,6 @@ static struct apic apic_flat __ro_after_ .init_apic_ldr = default_init_apic_ldr, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = flat_phys_pkg_id, .max_apic_id = 0xFE, .get_apic_id = flat_get_apic_id, @@ -159,7 +153,6 @@ static struct apic apic_physflat __ro_af .disable_esr = 0, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = flat_phys_pkg_id, .max_apic_id = 0xFE, .get_apic_id = flat_get_apic_id, --- a/arch/x86/kernel/apic/apic_noop.c +++ b/arch/x86/kernel/apic/apic_noop.c @@ -29,7 +29,6 @@ static void noop_send_IPI_self(int vecto static void noop_apic_icr_write(u32 low, u32 id) { } static int noop_wakeup_secondary_cpu(u32 apicid, unsigned long start_eip) { return -1; } static u64 noop_apic_icr_read(void) { return 0; } -static u32 noop_phys_pkg_id(u32 cpuid_apic, int index_msb) { return 0; } static u32 noop_get_apic_id(u32 apicid) { return 0; } static void noop_apic_eoi(void) { } @@ -56,8 +55,6 @@ struct apic apic_noop __ro_after_init = .ioapic_phys_id_map = default_ioapic_phys_id_map, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = noop_phys_pkg_id, - .max_apic_id = 0xFE, .get_apic_id = noop_get_apic_id, --- a/arch/x86/kernel/apic/apic_numachip.c +++ b/arch/x86/kernel/apic/apic_numachip.c @@ -56,11 +56,6 @@ static u32 numachip2_set_apic_id(u32 id) return id << 24; } -static u32 numachip_phys_pkg_id(u32 initial_apic_id, int index_msb) -{ - return initial_apic_id >> index_msb; -} - static void numachip1_apic_icr_write(int apicid, unsigned int val) { write_lcsr(CSR_G3_EXT_IRQ_GEN, (apicid << 16) | val); @@ -228,7 +223,6 @@ static const struct apic apic_numachip1 .disable_esr = 0, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = numachip_phys_pkg_id, .max_apic_id = UINT_MAX, .get_apic_id = numachip1_get_apic_id, @@ -265,7 +259,6 @@ static const struct apic apic_numachip2 .disable_esr = 0, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = numachip_phys_pkg_id, .max_apic_id = UINT_MAX, .get_apic_id = numachip2_get_apic_id, --- a/arch/x86/kernel/apic/bigsmp_32.c +++ b/arch/x86/kernel/apic/bigsmp_32.c @@ -29,11 +29,6 @@ static void bigsmp_ioapic_phys_id_map(ph physids_promote(0xFFL, retmap); } -static u32 bigsmp_phys_pkg_id(u32 cpuid_apic, int index_msb) -{ - return cpuid_apic >> index_msb; -} - static void bigsmp_send_IPI_allbutself(int vector) { default_send_IPI_mask_allbutself_phys(cpu_online_mask, vector); @@ -88,7 +83,6 @@ static struct apic apic_bigsmp __ro_afte .check_apicid_used = bigsmp_check_apicid_used, .ioapic_phys_id_map = bigsmp_ioapic_phys_id_map, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = bigsmp_phys_pkg_id, .max_apic_id = 0xFE, .get_apic_id = bigsmp_get_apic_id, --- a/arch/x86/kernel/apic/local.h +++ b/arch/x86/kernel/apic/local.h @@ -17,7 +17,6 @@ void __x2apic_send_IPI_dest(unsigned int apicid, int vector, unsigned int dest); u32 x2apic_get_apic_id(u32 id); u32 x2apic_set_apic_id(u32 id); -u32 x2apic_phys_pkg_id(u32 initial_apicid, int index_msb); void x2apic_send_IPI_all(int vector); void x2apic_send_IPI_allbutself(int vector); --- a/arch/x86/kernel/apic/probe_32.c +++ b/arch/x86/kernel/apic/probe_32.c @@ -18,11 +18,6 @@ #include "local.h" -static u32 default_phys_pkg_id(u32 cpuid_apic, int index_msb) -{ - return cpuid_apic >> index_msb; -} - static u32 default_get_apic_id(u32 x) { unsigned int ver = GET_APIC_VERSION(apic_read(APIC_LVR)); @@ -54,7 +49,6 @@ static struct apic apic_default __ro_aft .init_apic_ldr = default_init_apic_ldr, .ioapic_phys_id_map = default_ioapic_phys_id_map, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = default_phys_pkg_id, .max_apic_id = 0xFE, .get_apic_id = default_get_apic_id, --- a/arch/x86/kernel/apic/x2apic_cluster.c +++ b/arch/x86/kernel/apic/x2apic_cluster.c @@ -236,7 +236,6 @@ static struct apic apic_x2apic_cluster _ .init_apic_ldr = init_x2apic_ldr, .ioapic_phys_id_map = NULL, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = x2apic_phys_pkg_id, .max_apic_id = UINT_MAX, .x2apic_set_max_apicid = true, --- a/arch/x86/kernel/apic/x2apic_phys.c +++ b/arch/x86/kernel/apic/x2apic_phys.c @@ -134,11 +134,6 @@ u32 x2apic_set_apic_id(u32 id) return id; } -u32 x2apic_phys_pkg_id(u32 initial_apicid, int index_msb) -{ - return initial_apicid >> index_msb; -} - static struct apic apic_x2apic_phys __ro_after_init = { .name = "physical x2apic", @@ -151,7 +146,6 @@ static struct apic apic_x2apic_phys __ro .disable_esr = 0, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = x2apic_phys_pkg_id, .max_apic_id = UINT_MAX, .x2apic_set_max_apicid = true, --- a/arch/x86/kernel/apic/x2apic_uv_x.c +++ b/arch/x86/kernel/apic/x2apic_uv_x.c @@ -785,16 +785,6 @@ static u32 set_apic_id(u32 id) return id; } -static unsigned int uv_read_apic_id(void) -{ - return x2apic_get_apic_id(apic_read(APIC_ID)); -} - -static u32 uv_phys_pkg_id(u32 initial_apicid, int index_msb) -{ - return uv_read_apic_id() >> index_msb; -} - static int uv_probe(void) { return apic == &apic_x2apic_uv_x; @@ -812,7 +802,6 @@ static struct apic apic_x2apic_uv_x __ro .disable_esr = 0, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = uv_phys_pkg_id, .max_apic_id = UINT_MAX, .get_apic_id = x2apic_get_apic_id, --- a/arch/x86/kernel/vsmp_64.c +++ b/arch/x86/kernel/vsmp_64.c @@ -127,25 +127,12 @@ static void __init vsmp_cap_cpus(void) #endif } -static u32 apicid_phys_pkg_id(u32 initial_apic_id, int index_msb) -{ - return read_apic_id() >> index_msb; -} - -static void vsmp_apic_post_init(void) -{ - /* need to update phys_pkg_id */ - apic->phys_pkg_id = apicid_phys_pkg_id; -} - void __init vsmp_init(void) { detect_vsmp_box(); if (!is_vsmp_box()) return; - x86_platform.apic_post_init = vsmp_apic_post_init; - vsmp_cap_cpus(); set_vsmp_ctl(); --- a/arch/x86/xen/apic.c +++ b/arch/x86/xen/apic.c @@ -110,11 +110,6 @@ static int xen_madt_oem_check(char *oem_ return xen_pv_domain(); } -static u32 xen_phys_pkg_id(u32 initial_apic_id, int index_msb) -{ - return initial_apic_id >> index_msb; -} - static u32 xen_cpu_present_to_apicid(int cpu) { if (cpu_present(cpu)) @@ -133,7 +128,6 @@ static struct apic xen_pv_apic __ro_afte .disable_esr = 0, .cpu_present_to_apicid = xen_cpu_present_to_apicid, - .phys_pkg_id = xen_phys_pkg_id, /* detect_ht */ .max_apic_id = UINT_MAX, .get_apic_id = xen_get_apic_id, From patchwork Wed Aug 2 10:21:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129814 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp415165vqx; Wed, 2 Aug 2023 05:22:21 -0700 (PDT) X-Google-Smtp-Source: APBJJlGSRfxJhokitJ6gnIhk0+QiECkTN71gQ6qjUvzc3ABjX229WrLN0c8wyWvDXzQ+dl4KhddE X-Received: by 2002:a05:6402:b11:b0:522:5778:aed9 with SMTP id bm17-20020a0564020b1100b005225778aed9mr5527801edb.19.1690978940907; Wed, 02 Aug 2023 05:22:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690978940; cv=none; d=google.com; s=arc-20160816; b=TRLq25pehu4qMQkFHulbzPfNuEhX7gx6WlHKbuSWmq5JAhVqx/Hxry1l0EjDCAzAXo Er/aBH3QGwOU6rwpBT6TbDBUiMo0KQBCSmSsg5tU/IfVaEmKIdiv/eyrrZVvtjpyGH3B SeN575mf7fAlV+FcBtZwpvUHlTH+9NE506pq777h7rJCopwDGL7tcxDtKOCnGYpUFGMv fdVCPKgbFhj23o3yPhkUMt5tum8Snpclz3Ymz5KYp9mD/U8hGu6nF+MQUVwYosCudE3Y WwmQzRNRjvlnZoMiFSPlD/rd9pzlwpRjKH5sNaFaP1h5eaCcbB1cD5aUsZ88lwWYvJjO qCSA== 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=dCJ675XRBN0nH/FVG6be5pN6/XKm3FLkxuXqtWJHHNE=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=J5t9S/Nxj7jj5GkVmnROeuwpy6O+Pb2sxn8axqthauwz0boDuynh9bF1vk4Gl0PEWJ XmFBx1Uz8hI92HcwDg1QfV6QRFBsYzy7Kn0Pb4TtKxtLpaUMm+YfyxaCAMngXffCYMEf Xu1pVKiDKPK2nfFNiCT38+AKkrtSYz5jWNnOPSON4E7GbaMY+00tr1TVwBX98rmbyYUr RL9zNLDszg499TlXob19aQk0Waf979hCrObo4+Wt+HdK7WdrwvGTpsf6rvdpzYhw84xh 2lwp/pAJvFNATNBH0+xhw8SNvk15Y/ldkXLiEA1Q5KANW6UjOy7dTdcvXH0W8A/7vVNE bd+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=x0T7RwHm; dkim=neutral (no key) header.i=@linutronix.de header.b=ilXXJAbh; 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 e15-20020aa7d7cf000000b0051e0c5c1e93si9776929eds.538.2023.08.02.05.21.54; Wed, 02 Aug 2023 05:22:20 -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=x0T7RwHm; dkim=neutral (no key) header.i=@linutronix.de header.b=ilXXJAbh; 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 S232540AbjHBKZB (ORCPT + 99 others); Wed, 2 Aug 2023 06:25:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232356AbjHBKX6 (ORCPT ); Wed, 2 Aug 2023 06:23:58 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37BD330D1 for ; Wed, 2 Aug 2023 03:22:19 -0700 (PDT) Message-ID: <20230802101934.924770305@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971719; 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=dCJ675XRBN0nH/FVG6be5pN6/XKm3FLkxuXqtWJHHNE=; b=x0T7RwHmn15tm0Bs8ZjDPJLTBGPqVnxETx0F5yv7R4E0JgrRpz7+E7tzWITycUfEu+MWSS ZL8dIL6Kp7stAiWx1i+I3eTrH/ESvYQMaTWpYR+IAUGKTihGsHGAy2Aa0MNyMCajL6Xv2b SAAxQwmUe/r8wO6lD3xc4Vp3q6oenYOgqcJ8jh83r72qpURo7zJ3iufy8Q2m8A+ItxTgUK J0TFlm8yX1A2mH2fGxAu2t38niiSiNKtP0hAdYC/MirH1m4BMJCpE49MyYy+m6Eaw8VzFM dxhA5cf3IMLFteqfBQPtvtNNQey6DnjZl71NH+EBxNV73U0WuvhxJtyrenh82g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971719; 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=dCJ675XRBN0nH/FVG6be5pN6/XKm3FLkxuXqtWJHHNE=; b=ilXXJAbhecQY8Sfrpo02SFMDLMnw8w5lXtXX/19KQ/bCI9mKKqTMlTZxS/4Qnf3umoQ1DB fHitGSthN95zfqCg== 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 , Wei Liu Subject: [patch V3 39/40] x86/xen/smp_pv: Remove cpudata fiddling References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:21:59 +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,URIBL_BLOCKED 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: 1773119933430231520 X-GMAIL-MSGID: 1773119933430231520 The new topology CPUID parser installs already fake topology for XEN/PV, which ends up with cpuinfo::max_cores = 1. Signed-off-by: Thomas Gleixner Cc: Juergen Gross --- V2: New patch --- arch/x86/xen/smp_pv.c | 3 --- 1 file changed, 3 deletions(-) --- a/arch/x86/xen/smp_pv.c +++ b/arch/x86/xen/smp_pv.c @@ -73,7 +73,6 @@ static void cpu_bringup(void) } cpu = smp_processor_id(); smp_store_cpu_info(cpu); - cpu_data(cpu).x86_max_cores = 1; set_cpu_sibling_map(cpu); speculative_store_bypass_ht_init(); @@ -223,8 +222,6 @@ static void __init xen_pv_smp_prepare_cp smp_prepare_cpus_common(); - cpu_data(0).x86_max_cores = 1; - speculative_store_bypass_ht_init(); xen_pmu_init(0); From patchwork Wed Aug 2 10:22:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129787 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp395513vqx; Wed, 2 Aug 2023 04:51:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlEf6dx0VYHqW4Lmildh1YCJG2TXdVqMEpmMgNXksxsJc4qtKvdGHrNknG0upeni/aAqXvuF X-Received: by 2002:a05:6a20:938a:b0:133:8784:15f7 with SMTP id x10-20020a056a20938a00b00133878415f7mr17521908pzh.14.1690977077799; Wed, 02 Aug 2023 04:51:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690977077; cv=none; d=google.com; s=arc-20160816; b=zZgGQ8IhQu9HwUAyuGO7lxl2OTL2dUTI4ynISCa7YsjZLOM24oPP44xPMjkE2TD6Rd 6Vc2ES9pf3puAjA0bks869yIJV3vD5NeIMKpaNCeBm3jpHG2n0LC6/mtMGqdm/3R24pF 11j0je9iaNNegDIQ8YBL/0uB/o1gqKqzpnBOClQ2cNY2NrAG5Kyzn7wk20mPV9VoX56J z4Pk606Yzo1oeiw9sxiPJuQwye7I6kjN+kiH1+fFHw4hvGJWrlEt6NfdYmhfGJXMmTCb fugZLSbQ+DnfR+Q4/EsZWZTKzbBZdIfUpUN1lA7DeP0h/wcFYu0ge98QRIBnByxCahnC LHKg== 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=y/zw4jIEoXHpKelNkwXOESHKGmmFcaqzgwgGslsADMM=; fh=OiHG50eBbNVlA8vQpd2BswzIfIFqJhLXTq7qKMAB1HY=; b=JvoGjCmLfcbMz64HrdkZpxGV3psrr4P/ttWuMmIbmceZvzJcHiV483yvJjgWoLOTMA /2IU4fMvjf9JbCDrn1vkg01pm7uj/mRw3ZO6KimcuLEpHC8kzMhA5cLzSN8BsQ90oBwv HOBX8Z8Dj4gUd1mhHyKtX2KVHrQ7Cj9lplMsADRLy7gmFeXwJFrYh1q39+Azet5CzkY9 wajQ1VkUNLZjnKNSlAU8LzqK2DVRPCo45E6/d5j6EpQ58VsH7iZ28qwGBLdfy3HX0vHp lM5WWfPRnfZHXECIL6XtyXRQQockyr3SQ1H2sDdhpdjchYfRSrSUJ8ANGmygP+UtP6pD 0DTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=RSZtmFFh; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=SXRN6j03; 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 v63-20020a638942000000b00563e1d607bcsi25013pgd.411.2023.08.02.04.51.03; Wed, 02 Aug 2023 04:51:17 -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=RSZtmFFh; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=SXRN6j03; 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 S233417AbjHBKZH (ORCPT + 99 others); Wed, 2 Aug 2023 06:25:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232829AbjHBKYK (ORCPT ); Wed, 2 Aug 2023 06:24:10 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 305FF30EB for ; Wed, 2 Aug 2023 03:22:24 -0700 (PDT) Message-ID: <20230802101934.981826753@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971721; 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=y/zw4jIEoXHpKelNkwXOESHKGmmFcaqzgwgGslsADMM=; b=RSZtmFFhNHNFj1zXzqnUtmaSstQ/ZlnmyJ1H27QGXck6sDA+Y8Q5Ynf+Fn9JR2n7fbvg6R 4XWpQ9wCIgHlq25B8KpYDPAl0P7FSszu/hQF0vEQAhSrHE+/crj68OzkRilSt13Owsq8yq 3Hg/sx60C2/PBPVZqXdBhowN1d+cLrnZu7axIR6f5zuRPfvVC7X7gV01IcbGxev1sxQB2D wDntLXLwkB7OvwUE3rRSKbRresbkveMhW+1zW7o2mwZH5Elx3ITe8FXcwXVOetQA1u8H9H BAF+5JLTl01rbCBRDuD+wmNzW3EUuLaoNhCSKY6EMkX6XDcti0w/yCICZH8RHQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971721; 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=y/zw4jIEoXHpKelNkwXOESHKGmmFcaqzgwgGslsADMM=; b=SXRN6j03xvwSK8gaUFGtwggHDPgt0kdu5OPWLKi5rTi38FJLmHOSCLCVu8/i2jKomGsNgB DXuk6wgnoKISyYCg== 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 , Wei Liu , Steve Wahl , Mike Travis , Russ Anderson Subject: [patch V3 40/40] x86/apic/uv: Remove the private leaf 0xb parser References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Date: Wed, 2 Aug 2023 12:22:00 +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,URIBL_BLOCKED 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: 1773117980468087190 X-GMAIL-MSGID: 1773117980468087190 The package shift has been already evaluated by the early CPU init. Put the mindless copy right next to the original leaf 0xb parser. Signed-off-by: Thomas Gleixner Cc: Steve Wahl Cc: Mike Travis Cc: Dimitri Sivanich Cc: Russ Anderson --- arch/x86/include/asm/topology.h | 5 +++ arch/x86/kernel/apic/x2apic_uv_x.c | 52 ++++++------------------------------- 2 files changed, 14 insertions(+), 43 deletions(-) --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -126,6 +126,11 @@ static inline unsigned int topology_get_ return x86_topo_system.dom_size[dom]; } +static inline unsigned int topology_get_domain_shift(enum x86_topology_domains dom) +{ + return dom == TOPO_SMT_DOMAIN ? 0 : x86_topo_system.dom_shifts[dom - 1]; +} + extern const struct cpumask *cpu_coregroup_mask(int cpu); extern const struct cpumask *cpu_clustergroup_mask(int cpu); --- a/arch/x86/kernel/apic/x2apic_uv_x.c +++ b/arch/x86/kernel/apic/x2apic_uv_x.c @@ -241,54 +241,20 @@ static void __init uv_tsc_check_sync(voi is_uv(UV3) ? sname.s3.field : \ undef) -/* [Copied from arch/x86/kernel/cpu/topology.c:detect_extended_topology()] */ - -#define SMT_LEVEL 0 /* Leaf 0xb SMT level */ -#define INVALID_TYPE 0 /* Leaf 0xb sub-leaf types */ -#define SMT_TYPE 1 -#define CORE_TYPE 2 -#define LEAFB_SUBTYPE(ecx) (((ecx) >> 8) & 0xff) -#define BITS_SHIFT_NEXT_LEVEL(eax) ((eax) & 0x1f) - -static void set_x2apic_bits(void) -{ - unsigned int eax, ebx, ecx, edx, sub_index; - unsigned int sid_shift; - - cpuid(0, &eax, &ebx, &ecx, &edx); - if (eax < 0xb) { - pr_info("UV: CPU does not have CPUID.11\n"); - return; - } - - cpuid_count(0xb, SMT_LEVEL, &eax, &ebx, &ecx, &edx); - if (ebx == 0 || (LEAFB_SUBTYPE(ecx) != SMT_TYPE)) { - pr_info("UV: CPUID.11 not implemented\n"); - return; - } - - sid_shift = BITS_SHIFT_NEXT_LEVEL(eax); - sub_index = 1; - do { - cpuid_count(0xb, sub_index, &eax, &ebx, &ecx, &edx); - if (LEAFB_SUBTYPE(ecx) == CORE_TYPE) { - sid_shift = BITS_SHIFT_NEXT_LEVEL(eax); - break; - } - sub_index++; - } while (LEAFB_SUBTYPE(ecx) != INVALID_TYPE); - - uv_cpuid.apicid_shift = 0; - uv_cpuid.apicid_mask = (~(-1 << sid_shift)); - uv_cpuid.socketid_shift = sid_shift; -} - static void __init early_get_apic_socketid_shift(void) { + unsigned int sid_shift = topology_get_domain_shift(TOPO_ROOT_DOMAIN); + if (is_uv2_hub() || is_uv3_hub()) uvh_apicid.v = uv_early_read_mmr(UVH_APICID); - set_x2apic_bits(); + if (sid_shift) { + uv_cpuid.apicid_shift = 0; + uv_cpuid.apicid_mask = (~(-1 << sid_shift)); + uv_cpuid.socketid_shift = sid_shift; + } else { + pr_info("UV: CPU does not have valid CPUID.11\n"); + } pr_info("UV: apicid_shift:%d apicid_mask:0x%x\n", uv_cpuid.apicid_shift, uv_cpuid.apicid_mask); pr_info("UV: socketid_shift:%d pnode_mask:0x%x\n", uv_cpuid.socketid_shift, uv_cpuid.pnode_mask);