Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp173883rdh; Tue, 13 Feb 2024 13:06:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW4F0JjD265mxAKDmDANuzUw6fQiHIWdKuP+vMmARo0LcRpfcLbspYXRMj/XvBpMED0aP6UdtEfg0qwXokzztM/X7vCUn7pHh3mYfPdzw== X-Google-Smtp-Source: AGHT+IGXJhWrrYJLARei7fPKLqUD9bAb2o/+eW6a7TMcBrlocscmOw/XD1iXkbMJsK8czcRGWlHL X-Received: by 2002:a17:907:378:b0:a3b:aa21:a801 with SMTP id rs24-20020a170907037800b00a3baa21a801mr351718ejb.53.1707858412549; Tue, 13 Feb 2024 13:06:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707858412; cv=pass; d=google.com; s=arc-20160816; b=HsNRUxNbt/m7d6B3IhJ4MBYWmvyn+KyVPYbjO1+dBf+e2DlhSfg/9oQCPxT5mwnZsO hXL1/9i3PJEYByzrzU+w5v4qOXMX9UwPRutBXZE9PRXuQA2WWHy1v2epU9Vpg78ZFJB5 OYXQ9oL575Egb2P9CXKl26bw/VA9pEQB5Kn6rMzb2EN+PaVfTnw8wn0Lcnzk5YF9rvHJ iZHkrJtOACFSR7PY1aO6q1WjsG/9BHdjJsPNK2ihyBAK3EjzJ/F9FPMuAvDkYPLT9OM3 fQgqmTRlVPe2ii8AAfqBXqgFaTssGT1kY9kxJWaiHIYxOFteFAKlBkUNCPCNJWfRFLr0 OcwA== 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=6b2NH0+77mUe86DUwaZRXaWed3MppHmNM5Y+tgRpkxU=; b=vVLZ0fTQqtSGPCOoSPpnTJVK6kSyUIYNuwLVpIi2psez63RAAp9gCY0RqAVV+Kfhum UP0gMMdylcRB2totUYg0rgb/uXkBGQnuut+RSs8mUniJWL0DZhF8qMeML65kdWn9sB0r csYHWEjbDTTm4z47t1HKB0nYfmPyBib4DDuQI41aAsTVnjt59FGuXSmhHXCNORvn75fF N/P7mpts/alBt2ftGKaNp3SbyFN3zSgA+RjjcgajtGHiLihTsT/06oNfvHsOe9s0gSoC uMg1RECgk/JkVzXw9Ket6Me+lNIctsnMWGxnaNGy4HDyWeWiGkwLBg3ED1N92fBZ6Yb2 k05w==; 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 header.b=audm8sAo; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64252-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCXACLqJX+nSBV63uwhDcrePDD6bFzCSAYKiR/KWD2Zpz6oXaZYgLNuLBD9LYo7U6V7oP7pE/lzYMLhhhrcY6Kks6s5t1okAHRYv3m6I2w== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id qb35-20020a1709077ea300b00a3cae7aae94si1763471ejc.121.2024.02.13.13.06.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 13:06:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64252-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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 header.b=audm8sAo; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64252-linux.lists.archive=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 26CA71F212B4 for ; Tue, 13 Feb 2024 21:06:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 74236633F9; Tue, 13 Feb 2024 21:04:21 +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 Content-Type: text/plain; charset=UTF-8 Date: Tue, 13 Feb 2024 22:04:17 +0100 (CET) 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; }