From patchwork Tue Feb 13 21:04:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 200602 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp808487dyb; Tue, 13 Feb 2024 13:07:15 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXiELwBZ961bBfYVqIZ71Sy4rzKOaskMTBO5wpDIoKJfBAnRNtgYWjY7rzk7U1J0QLyHBTVxNPTsc94u3sSCcJ2Ww8Izg== X-Google-Smtp-Source: AGHT+IFXxenI99c5DxECBVypHWii0M/exQK9VL/kNvTuD66XrgzjnC4Ch5glyjY9gvOJnIROKcjZ X-Received: by 2002:a05:622a:181a:b0:42d:a9e0:52e7 with SMTP id t26-20020a05622a181a00b0042da9e052e7mr589434qtc.36.1707858434794; Tue, 13 Feb 2024 13:07:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707858434; cv=pass; d=google.com; s=arc-20160816; b=0gL4qMVP0BhuNzHqlKNZ8I/WvHzzdaO1VFsl6tcKvNzj0vMg1LfOLSehC8kdnhp4Vk JPTeSBAmRuipSxXGSG8rS2gS+jVnqm0hgfPG28nKfHrk2PQRkEoM4bLbxqqC7trRquSd gxhiNvjI8YB7fKunce1L25XvpQ5ctIPGrMGT/1W1IVnyu6GWjvTVx1TfDBuWBvdigc1m ajSTFgR9ce5mKFy6qu1NgYKNN0P7K7tdH+d2ONSin2qyav6gPwqCXAFVxhBGSlhSgi7/ pNZer0YBl+A2OjSUkzNkF1VWxupaXskLSGOHrIQhLwg/pVORqmFHz0TCJGn9gEAThhTc Z9eg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:subject:cc:to:from:dkim-signature :dkim-signature:message-id; bh=pSlJYF9kIbqsjwORf5ZK3d1sw55cHx4DH1uFUqVsbKs=; fh=ZwxoKDUPJXfe54u4FXqk4Gd8z9YQGSqFn2HaoMc2MRs=; b=AF5fw9XQpybo81UnwAawKrB9tn9TAaml5vpiVpthPqE3Y2/bu4SsI3umEmL4Ov9EYL lG2rekB3fQiPuwymRpOSmmC2d2q7ib0SRIe7epFZjKDBDo8XtvKw5nHg0KxQO3UalZBI DUK6fcqjWb/iWpi9bvHFYD9v8mUmuWeIMcW1JzaFM4T2X+PoTqbNZU6ZM0VO4d365dB9 JNemEXCmDbqzNkwUm8ZT5mZqhXoch8cK6WtWdzoFFOEASfD8wQ8YbfBYLqtuajB+WmB4 pjvrnVzXeVmHUyX/9BkVBPu5pHnsi792re81ZItUYHsDgFjGkrsKQ1Y8EOjLDlmYw24j zRAA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="hzg+UF/G"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-64252-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64252-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCXECDWvt08OnuxY6HRxCMRJkhhQxvyhi5Znec96htxbai6kt4aLYxyGBdAzRxbEYtdx2TqE7fpLVMxQZ08b1iI1AXbtnw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 1-20020a05620a048100b00787167c97cfsi3416522qkr.324.2024.02.13.13.07.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 13:07:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64252-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="hzg+UF/G"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-64252-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64252-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 95F581C22FAF for ; Tue, 13 Feb 2024 21:07:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6700863501; Tue, 13 Feb 2024 21:04:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="hzg+UF/G"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="audm8sAo" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0EFE16311E for ; Tue, 13 Feb 2024 21:04:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707858260; cv=none; b=QmjVkClXn7DgpaBxaYuAeE+IIiilpQfQ0t4FM8WydyZojnbJHnSiGgU8yI8xkLXHGYKX36nQhhhy6AC0EywBYIBVp/vX/CYKYgufmFUvMF6eN+mcGooskY3mgyjt40PGFH6zd+JhU1VBwMT73gkUlPWpS2QvCkcwquOdIALXVzk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707858260; c=relaxed/simple; bh=TUY7y9Rf16ytOoaCVmIdmnZTOSOSu37xEntr/P44zig=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=QxhaDmMtgT2ftcG/WDnI+hLUwJg3cGnVy7L6VRlTiGjgOvaKMY6qOLwKUC9qmanc+UcsL6SJt2qolSTSKPss1VOJypE4zEnNXEg4bPuCdtvraVlmvw+mFRlm2wO/OVX4z/YbEpXNSMrEu41/ixPkNQ50kAMguM7cRnzsoH52/GM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=hzg+UF/G; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=audm8sAo; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Message-ID: <20240212153625.270320718@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1707858257; 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=pSlJYF9kIbqsjwORf5ZK3d1sw55cHx4DH1uFUqVsbKs=; b=hzg+UF/GRSqtafCcRCijXCd6uYk4ktGN8dXeBYxtdTfn7t1ItQPQL6q3b8rJRoX+ar4Van 6u9X+058nW4TKt82sSheBSfzhlVHIIsXRh72u7QW4ixgqKGgMR2shZjD6VZD/eYc5aKNRp VHm3Rrmv2LJeWytPklF3jHZWhx9B0kq0qKpPZYwgB1esD+wpKPjRgKtFjDjQgBFMrT9rx6 5Ers99nekHN8PN/dvDi5TK2juFzyIAmMx73FTKrsucpS37W2UijUCC0ooEkSKMete2xgyo TD3CQAfxifjdNryaSS890tlm80i/QnrT3I5fpRSWCqL8XrQc30Rug5t4qp/9gw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1707858257; 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=pSlJYF9kIbqsjwORf5ZK3d1sw55cHx4DH1uFUqVsbKs=; b=audm8sAo9WTk8OZaxQGVTks51ctgruLA+wn7KCMFQq8JdhQHffPkHtLwYeCaBA7UrlMA2O MLjAuiU/e6MvOmBQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , Huang Rui , Juergen Gross , Dimitri Sivanich , Sohil Mehta , K Prateek Nayak , Kan Liang , Zhang Rui , "Paul E. McKenney" , Feng Tang , Andy Shevchenko , Michael Kelley , "Peter Zijlstra (Intel)" , Wang Wendy Subject: [patch V6 13/19] x86/mm/numa: Use core domain size on AMD References: <20240212153109.330805450@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Tue, 13 Feb 2024 22:04:17 +0100 (CET) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790819365893199103 X-GMAIL-MSGID: 1790819365893199103 From: Thomas Gleixner 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 Tested-by: Juergen Gross Tested-by: Sohil Mehta Tested-by: Michael Kelley Tested-by: Zhang Rui Tested-by: Wang Wendy --- arch/x86/include/asm/topology.h | 5 +++++ arch/x86/mm/amdtopology.c | 35 ++++++++++++++++------------------- 2 files changed, 21 insertions(+), 19 deletions(-) --- --- 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/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; }