Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp206683lqd; Tue, 23 Apr 2024 22:30:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXGYNkd1ypsLwwvcpzXX6pBpFNXhtyu0JGfLgvSmBAUq/fD29oHe0qKQZc5OLeK6fwC0ksZLYP1EO837RWWHyKbqGO1xusPOf53yHCBdw== X-Google-Smtp-Source: AGHT+IGVsiWigbXT8n2axP4/vLXcFH+IcxKz86DvXdA07lJBooICvyCTVxFll42UJn1XLui83OH6 X-Received: by 2002:a17:906:97d1:b0:a55:a8a6:a0c9 with SMTP id ef17-20020a17090697d100b00a55a8a6a0c9mr812535ejb.51.1713936616217; Tue, 23 Apr 2024 22:30:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713936616; cv=pass; d=google.com; s=arc-20160816; b=jVFwGPbuk7dthOjWa9yZdWVMzpYGBWMa+dgOLYWx61KSiAGXq39ADmfnUlpYuDP2NM HrrAU9jxzFnV1yDomlBunAJUq1ckq8U8ud0De3l7ozwMhy3zIr/hUkbgEQ0HdRiFqjUF eSwO/IGgzHfdGkxa/n0rn3rkwzE0QnRqTNER3fWYIqR2QIib5/hoiqiqONXt/6ycAIce Y9kWnHUs9hljzwnPwd86/x84W8vP3+uvdsQLmdi1l4s/jmpEsoRFdAaexz8VhSUD5FPT yEE8T7jnfseQCRPG2BtSRXMAbKTaJxrDg04kKHmbTAWAsTlia+FWr1ehmTC5FgBd//cY b3Jg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=3HQOtAqmMfeeWKw4Xse5Gl774cHgIj/tMaOtn/pLxZc=; fh=AS6bAnUC3rjyOTff0trsaHvXDM/24y7a5/RmLUh9xms=; b=aq6Pi+OzzBxW9L3ScHq/ysqpzmtkPFHkcxxGDQq/aCMNKsNmiuT3eZhRqnHduQCpQ2 z1l45mWKNW++LHESzdYb3ZM+rbA+KEhiC3UqD2sS2KiWxPsUW9t+fAzzs0TIU1ToXAgK C3COAXOdAqhAYKqBRpJqTQoDaIH44a+llpBbuC5jjxXcmWXC8CW/bvIw+HaXBuRvj+ZY g70oCCzfSfROzWEHS69mVeNV3lGTvHbfnWJXZxdIywHuMwjAXlznL8Sc3vEDBxvneMKQ g81/g2TgtqdW+cmgRBbKI3e/W05gRjXx4WM4uc5SkM9iuVWkJLLfSGqRTa7xnudjDW5/ lKkg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WM9LYHzy; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-156303-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156303-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id n16-20020a170906165000b00a4e05accf57si7542154ejd.789.2024.04.23.22.30.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 22:30:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-156303-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WM9LYHzy; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-156303-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156303-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 C347A1F238C2 for ; Wed, 24 Apr 2024 05:30:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 79E8F156652; Wed, 24 Apr 2024 05:30:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="WM9LYHzy" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 B28221552F8; Wed, 24 Apr 2024 05:30:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713936607; cv=none; b=UGJGYdnArk2WkUhmAQXcTAyZgQmAp5xR8kaPrOIgyiCitwho7NGb8i97f9kAe6EG/plf9AnPzS57DdSIbNgAUmJWHwBkw11Ue56+HPNEW7vohpToxnNKea4C1FrWiXqdxG0AF+xVKb7YushVhpCzG00vfAi5ppBhvVYH17DILz8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713936607; c=relaxed/simple; bh=m94xgFiC9Egx8aA5jSWnNCr+cu96SO8oXS5hvtC918o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=u8gaXFcO/t+fB/KyKcNvsWjZXtg9zVFJGIhVR2jeAw5T6W821y+6EywyPTUyLfMXfNOuWq+rhq5riM1L0FZwbb6VNIRjGcJ7xfNOPHzPfMeuMWzec1T7XNGt05/DrJGyiEk2joJJmO9v02kAgqCpYsNNF0wFVw6MXj+VfYI31w0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=WM9LYHzy; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1713936606; x=1745472606; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=m94xgFiC9Egx8aA5jSWnNCr+cu96SO8oXS5hvtC918o=; b=WM9LYHzyRtKnvUnGZA80OE5K2mnOUcijTUjPJfckH7k87gJRJ7wrw+D/ zw+9QlQu20KlWVbGIlBHkdT6z3ssImVJSpI7gRNpNnek90gOZhbiLwSYt 2zEgGVs0BavfbWa6siXYZ0Zaacu4njSnnfZk/tq3+zuk09oknN4KYvv2a FDGPNBTI4wpR25AvsWbvWvJRUQoh80vYanepyVi2MWx6971E5DUPKgGx4 mHFVU+XcNKU/qh76QKnM8y0+xOBwr+kAivN2hjb7hJwRUkKKeo97uVQoi sNiC+8Yd1NCmAQ6IAeOgZDXdenrODtwpeelsXgXQRiuGCdexuYLIQpuWG Q==; X-CSE-ConnectionGUID: xkmE01ruSYCONVNW3UL2MQ== X-CSE-MsgGUID: tyeGDtz5Q8meSfeP3EeHCg== X-IronPort-AV: E=McAfee;i="6600,9927,11053"; a="27004267" X-IronPort-AV: E=Sophos;i="6.07,225,1708416000"; d="scan'208";a="27004267" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Apr 2024 22:30:06 -0700 X-CSE-ConnectionGUID: TV3x9Wh/SXakiir18y3vQA== X-CSE-MsgGUID: lbzoQyNzTZ++rY75L2VhXA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,225,1708416000"; d="scan'208";a="62049888" Received: from unknown (HELO haibo-OptiPlex-7090.sh.intel.com) ([10.239.159.132]) by orviesa001.jf.intel.com with ESMTP; 23 Apr 2024 22:29:55 -0700 From: Haibo Xu To: sunilvl@ventanamicro.com, arnd@arndb.de Cc: xiaobo55x@gmail.com, ajones@ventanamicro.com, Haibo Xu , Catalin Marinas , Will Deacon , Huacai Chen , WANG Xuerui , Paul Walmsley , Palmer Dabbelt , Albert Ou , "Rafael J. Wysocki" , Len Brown , Greg Kroah-Hartman , Robert Moore , Conor Dooley , Alexandre Ghiti , Guo Ren , Charlie Jenkins , Baoquan He , Greentime Hu , Zong Li , Sami Tolvanen , =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , Chen Jiahao , Jisheng Zhang , Samuel Holland , James Morse , "Russell King (Oracle)" , Evan Green , Thomas Gleixner , Tony Luck , Ard Biesheuvel , Yuntao Wang , Dan Williams , Alison Schofield , Dave Jiang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, linux-riscv@lists.infradead.org, linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev Subject: [PATCH v3 2/6] ACPI: RISCV: Add NUMA support based on SRAT and SLIT Date: Wed, 24 Apr 2024 13:46:22 +0800 Message-Id: <060957b1c052a97eced29a5f85f647e95ddb91e9.1713778236.git.haibo1.xu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add acpi_numa.c file to enable parse NUMA information from ACPI SRAT and SLIT tables. SRAT table provide CPUs(Hart) and memory nodes to proximity domain mapping, while SLIT table provide the distance metrics between proximity domains. Signed-off-by: Haibo Xu Reviewed-by: Sunil V L --- arch/riscv/include/asm/acpi.h | 15 +++- arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/acpi.c | 5 -- arch/riscv/kernel/acpi_numa.c | 131 ++++++++++++++++++++++++++++++++++ arch/riscv/kernel/setup.c | 4 +- arch/riscv/kernel/smpboot.c | 2 - include/linux/acpi.h | 6 ++ 7 files changed, 154 insertions(+), 10 deletions(-) create mode 100644 arch/riscv/kernel/acpi_numa.c diff --git a/arch/riscv/include/asm/acpi.h b/arch/riscv/include/asm/acpi.h index 7dad0cf9d701..e0a1f84404f3 100644 --- a/arch/riscv/include/asm/acpi.h +++ b/arch/riscv/include/asm/acpi.h @@ -61,11 +61,14 @@ static inline void arch_fix_phys_package_id(int num, u32 slot) { } void acpi_init_rintc_map(void); struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu); -u32 get_acpi_id_for_cpu(int cpu); +static inline u32 get_acpi_id_for_cpu(int cpu) +{ + return acpi_cpu_get_madt_rintc(cpu)->uid; +} + int acpi_get_riscv_isa(struct acpi_table_header *table, unsigned int cpu, const char **isa); -static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; } void acpi_get_cbo_block_size(struct acpi_table_header *table, u32 *cbom_size, u32 *cboz_size, u32 *cbop_size); #else @@ -87,4 +90,12 @@ static inline void acpi_get_cbo_block_size(struct acpi_table_header *table, #endif /* CONFIG_ACPI */ +#ifdef CONFIG_ACPI_NUMA +int acpi_numa_get_nid(unsigned int cpu); +void acpi_map_cpus_to_nodes(void); +#else +static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; } +static inline void acpi_map_cpus_to_nodes(void) { } +#endif /* CONFIG_ACPI_NUMA */ + #endif /*_ASM_ACPI_H*/ diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile index 81d94a8ee10f..960e627d2ad1 100644 --- a/arch/riscv/kernel/Makefile +++ b/arch/riscv/kernel/Makefile @@ -109,3 +109,4 @@ obj-$(CONFIG_COMPAT) += compat_vdso/ obj-$(CONFIG_64BIT) += pi/ obj-$(CONFIG_ACPI) += acpi.o +obj-$(CONFIG_ACPI_NUMA) += acpi_numa.o diff --git a/arch/riscv/kernel/acpi.c b/arch/riscv/kernel/acpi.c index e619edc8b0cc..040bdbfea2b4 100644 --- a/arch/riscv/kernel/acpi.c +++ b/arch/riscv/kernel/acpi.c @@ -191,11 +191,6 @@ struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu) return &cpu_madt_rintc[cpu]; } -u32 get_acpi_id_for_cpu(int cpu) -{ - return acpi_cpu_get_madt_rintc(cpu)->uid; -} - /* * __acpi_map_table() will be called before paging_init(), so early_ioremap() * or early_memremap() should be called here to for ACPI table mapping. diff --git a/arch/riscv/kernel/acpi_numa.c b/arch/riscv/kernel/acpi_numa.c new file mode 100644 index 000000000000..0231482d6946 --- /dev/null +++ b/arch/riscv/kernel/acpi_numa.c @@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * ACPI 6.6 based NUMA setup for RISCV + * Lots of code was borrowed from arch/arm64/kernel/acpi_numa.c + * + * Copyright 2004 Andi Kleen, SuSE Labs. + * Copyright (C) 2013-2016, Linaro Ltd. + * Author: Hanjun Guo + * Copyright (C) 2024 Intel Corporation. + * + * Reads the ACPI SRAT table to figure out what memory belongs to which CPUs. + * + * Called from acpi_numa_init while reading the SRAT and SLIT tables. + * Assumes all memory regions belonging to a single proximity domain + * are in one chunk. Holes between them will be included in the node. + */ + +#define pr_fmt(fmt) "ACPI: NUMA: " fmt + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +static int acpi_early_node_map[NR_CPUS] __initdata = { NUMA_NO_NODE }; + +int __init acpi_numa_get_nid(unsigned int cpu) +{ + return acpi_early_node_map[cpu]; +} + +static inline int get_cpu_for_acpi_id(u32 uid) +{ + int cpu; + + for (cpu = 0; cpu < nr_cpu_ids; cpu++) + if (uid == get_acpi_id_for_cpu(cpu)) + return cpu; + + return -EINVAL; +} + +static int __init acpi_parse_rintc_pxm(union acpi_subtable_headers *header, + const unsigned long end) +{ + struct acpi_srat_rintc_affinity *pa; + int cpu, pxm, node; + + if (srat_disabled()) + return -EINVAL; + + pa = (struct acpi_srat_rintc_affinity *)header; + if (!pa) + return -EINVAL; + + if (!(pa->flags & ACPI_SRAT_RINTC_ENABLED)) + return 0; + + pxm = pa->proximity_domain; + node = pxm_to_node(pxm); + + /* + * If we can't map the UID to a logical cpu this + * means that the UID is not part of possible cpus + * so we do not need a NUMA mapping for it, skip + * the SRAT entry and keep parsing. + */ + cpu = get_cpu_for_acpi_id(pa->acpi_processor_uid); + if (cpu < 0) + return 0; + + acpi_early_node_map[cpu] = node; + pr_info("SRAT: PXM %d -> HARTID 0x%lx -> Node %d\n", pxm, + cpuid_to_hartid_map(cpu), node); + + return 0; +} + +void __init acpi_map_cpus_to_nodes(void) +{ + int i; + + /* + * In ACPI, SMP and CPU NUMA information is provided in separate + * static tables, namely the MADT and the SRAT. + * + * Thus, it is simpler to first create the cpu logical map through + * an MADT walk and then map the logical cpus to their node ids + * as separate steps. + */ + acpi_table_parse_entries(ACPI_SIG_SRAT, sizeof(struct acpi_table_srat), + ACPI_SRAT_TYPE_RINTC_AFFINITY, acpi_parse_rintc_pxm, 0); + + for (i = 0; i < nr_cpu_ids; i++) + early_map_cpu_to_node(i, acpi_numa_get_nid(i)); +} + +/* Callback for Proximity Domain -> logical node ID mapping */ +void __init acpi_numa_rintc_affinity_init(struct acpi_srat_rintc_affinity *pa) +{ + int pxm, node; + + if (srat_disabled()) + return; + + if (pa->header.length < sizeof(struct acpi_srat_rintc_affinity)) { + pr_err("SRAT: Invalid SRAT header length: %d\n", pa->header.length); + bad_srat(); + return; + } + + if (!(pa->flags & ACPI_SRAT_RINTC_ENABLED)) + return; + + pxm = pa->proximity_domain; + node = acpi_map_pxm_to_node(pxm); + + if (node == NUMA_NO_NODE) { + pr_err("SRAT: Too many proximity domains %d\n", pxm); + bad_srat(); + return; + } + + node_set(node, numa_nodes_parsed); +} diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index 4f73c0ae44b2..a2cde65b69e9 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -281,8 +281,10 @@ void __init setup_arch(char **cmdline_p) setup_smp(); #endif - if (!acpi_disabled) + if (!acpi_disabled) { acpi_init_rintc_map(); + acpi_map_cpus_to_nodes(); + } riscv_init_cbo_blocksizes(); riscv_fill_hwcap(); diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c index d41090fc3203..7b63149128e7 100644 --- a/arch/riscv/kernel/smpboot.c +++ b/arch/riscv/kernel/smpboot.c @@ -96,7 +96,6 @@ static int __init acpi_parse_rintc(union acpi_subtable_headers *header, const un if (hart == cpuid_to_hartid_map(0)) { BUG_ON(found_boot_cpu); found_boot_cpu = true; - early_map_cpu_to_node(0, acpi_numa_get_nid(cpu_count)); return 0; } @@ -106,7 +105,6 @@ static int __init acpi_parse_rintc(union acpi_subtable_headers *header, const un } cpuid_to_hartid_map(cpu_count) = hart; - early_map_cpu_to_node(cpu_count, acpi_numa_get_nid(cpu_count)); cpu_count++; return 0; diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 34829f2c517a..bba6d6b35f68 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -269,6 +269,12 @@ acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa) { } int acpi_numa_memory_affinity_init (struct acpi_srat_mem_affinity *ma); +#ifdef CONFIG_RISCV +void acpi_numa_rintc_affinity_init(struct acpi_srat_rintc_affinity *pa); +#else +static inline void acpi_numa_rintc_affinity_init(struct acpi_srat_rintc_affinity *pa) { } +#endif + #ifndef PHYS_CPUID_INVALID typedef u32 phys_cpuid_t; #define PHYS_CPUID_INVALID (phys_cpuid_t)(-1) -- 2.34.1