[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v3 4/6] xen/x86: use arch_get_ram_range to get information from E820 map


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Wei Chen <wei.chen@xxxxxxx>
  • Date: Mon, 22 Aug 2022 10:58:08 +0800
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none
  • Arc-message-signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hEp02Pxymk3veSHxg4lI7WcmCBI/fVSPn+8BlOkU1Dg=; b=JTfQZh8qvnncODRNTWIiWXLvuOQf09patZrABFlR3yrB7qbmxCJSEZY/+BFeOoO0Tbbb+m/VTcKl+21QUUVkDojj7pQX7CwcJBhLqtQ66UFvLjLo+aDRMDGDVlGCYHvaHidZQKyaC6lZMZA8Zx7e2Jl7JMeB+LmJUun9flyrUAKFSBrsebvKbvaZx8eXvWDex+laCiQXmtD02kSK+JtEiN002DxWPfylmnhgDnyrz+JgZTHAiH1hdeEiOvBLK8yfG7OOOa+m3U+yTPnQib6wmJULsNDUHPIA5R1CEeiaLeTFQcxpplF9bDRvuRiCfAkEOvfBo0YwnXg1Vs0a3/pvcQ==
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hEp02Pxymk3veSHxg4lI7WcmCBI/fVSPn+8BlOkU1Dg=; b=aBC8j3tA8klF8/3b2CyL/LECzBPPDsZCDRY6jwR0Vhji0jztrkXcarPACIFG1uH9biRY8v6V3tljKbPqcPTaBjgHyMqk7+DZsqa46IAdYdyINm5FtfFD1UiJ/Nh5DZmY5RJMHwkCi3EKMPPRhMqObyv5Uo+XUydTtiUdUg6dgf2/lYyGpSDWfeoISlvMCCCDSWujhIZysWwjz11+yVuCl+b5iGCp1VwKMxUiOA3j4z+b2x+j9gxQTpORoCHfiLdsVre4pkgGeXOpSI1NuUZMAWO0mTwvCIjTxP3XeVQq1KO8sXzA3TTWmxpB/b5xgizE7gd/5icULdth4tzwMzvu8w==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=nQ38jlpXVX2Kl44PyhfXzx9OnsxPcHf/e07sdnn2BmNi7q8SR5QL9nD5rvGaLdek9VpRDjjQ9TSM0QBRHsPChvuig22plC2W1JVX4OG1gs/SJbLHbMriDIgoCC6t/uwSiuUjZvlikMdnjxk/T9dza4FagyE2pcxMot1mL1dLt0IXwsb6pT60ADOMnJGcnh3MsaeFVhXFFKZFdtbjByTtmvWnv7937AidmWvlxJP2xaKYDhfZsYmR/UYeTLmXiJbR4ngQQN8okztjrOWqqRacY8o1R+ZzN0uCjd5BWi5IboAX+cu0Xz3yKF2zsgu2jo8tIM4/ndKIpt4df0C4vC6O1w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jzg6ZSM3G1DoNYyZbYQ3zgWNeXVQ0OruKCEWKAYqE4AL0TSuVGeALo7krtbhbYt9H4GaFIofyaefGZjgGrF8IofBoJS0bpyxTkE4qeK1/TB8kYbHfMrzT1m3YRJ0MY2tP1mUjv18JRII2JrKd4k91K5gt1dekQL5RgwLaR6948gtTQG+uJ2bXxtul19dHB8tHYxNk/pqQdmhNpXr0ZX8vqxoFaaAFVQwMZptrqVFArq04SJdiflI/821FVrBkFkZ4w56xlOL+9q5Z0zrQOSvqij412fMukyv4vfD1sU4BiCh50WDyG92KrLVFKsXqXMfyC7UQLlGH9VC19Pjog8m+w==
  • Cc: <nd@xxxxxxx>, Wei Chen <wei.chen@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • Delivery-date: Mon, 22 Aug 2022 02:59:41 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true

The sanity check of nodes_cover_memory is also a requirement of
other architectures that support NUMA. But now, the code of
nodes_cover_memory is tied to the x86 E820. In this case, we
introduce arch_get_ram_range to decouple architecture specific
memory map from this function. This means, other architectures
like Arm can also use it to check its node and memory coverage
from bootmem info.

Depends arch_get_ram_range, we make nodes_cover_memory become
architecture independent. We also use neutral words to replace
SRAT and E820 in the print message of this function. This will
to make the massage seems more common.

As arch_get_ram_range use unsigned int for index, we also adjust
the index in nodes_cover_memory from int to unsigned int.

Signed-off-by: Wei Chen <wei.chen@xxxxxxx>
---
v2 -> v3:
1. Rename arch_get_memory_map to arch_get_ram_range.
2. Use -ENOENT instead of -ENODEV to indicate end of memory map.
3. Add description to code comment that arch_get_ram_range returns
   RAM range in [start, end) format.
v1 -> v2:
1. Use arch_get_memory_map to replace arch_get_memory_bank_range
   and arch_get_memory_bank_number.
2. Remove the !start || !end check, because caller guarantee
   these two pointers will not be NULL.
---
 xen/arch/x86/numa.c    | 25 +++++++++++++++++++++++++
 xen/arch/x86/srat.c    | 18 +++++++++++-------
 xen/include/xen/numa.h |  3 +++
 3 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/xen/arch/x86/numa.c b/xen/arch/x86/numa.c
index 9a9090e99a..c28c7388e4 100644
--- a/xen/arch/x86/numa.c
+++ b/xen/arch/x86/numa.c
@@ -9,6 +9,7 @@
 #include <xen/nodemask.h>
 #include <xen/numa.h>
 #include <asm/acpi.h>
+#include <asm/e820.h>
 
 #ifndef Dprintk
 #define Dprintk(x...)
@@ -96,3 +97,27 @@ unsigned int __init arch_get_dma_bitsize(void)
                  flsl(node_start_pfn(node) + node_spanned_pages(node) / 4 - 1)
                  + PAGE_SHIFT, 32);
 }
+
+/*
+ * This function provides the ability for caller to get one RAM entry
+ * from architectural memory map by index.
+ *
+ * This function will return zero if it can return a proper RAM entry.
+ * otherwise it will return -ENOENT for out of scope index, or return
+ * -EINVAL for non-RAM type memory entry.
+ *
+ * Note: the range is exclusive at the end, e.g. [start, end).
+ */
+int __init arch_get_ram_range(unsigned int idx, paddr_t *start, paddr_t *end)
+{
+    if ( idx >= e820.nr_map )
+        return -ENOENT;
+
+    if ( e820.map[idx].type != E820_RAM )
+        return -EINVAL;
+
+    *start = e820.map[idx].addr;
+    *end = *start + e820.map[idx].size;
+
+    return 0;
+}
diff --git a/xen/arch/x86/srat.c b/xen/arch/x86/srat.c
index 4c7f0c547e..6bebfb344f 100644
--- a/xen/arch/x86/srat.c
+++ b/xen/arch/x86/srat.c
@@ -428,18 +428,22 @@ acpi_numa_memory_affinity_init(const struct 
acpi_srat_mem_affinity *ma)
    Make sure the PXMs cover all memory. */
 static int __init nodes_cover_memory(void)
 {
-       int i;
+       unsigned int i;
 
-       for (i = 0; i < e820.nr_map; i++) {
+       for (i = 0; ; i++) {
                int j, found;
                paddr_t start, end;
 
-               if (e820.map[i].type != E820_RAM) {
+               /* Try to loop memory map from index 0 to end to get RAM 
ranges. */
+               found = arch_get_ram_range(i, &start, &end);
+
+               /* Index relate entry is not RAM, skip it. */
+               if (found == -EINVAL)
                        continue;
-               }
 
-               start = e820.map[i].addr;
-               end = e820.map[i].addr + e820.map[i].size;
+               /* Reach the end of arch's memory map */
+               if (found == -ENOENT)
+                       break;
 
                do {
                        found = 0;
@@ -458,7 +462,7 @@ static int __init nodes_cover_memory(void)
                } while (found && start < end);
 
                if (start < end) {
-                       printk(KERN_ERR "SRAT: No PXM for e820 range: "
+                       printk(KERN_ERR "NUMA: No NODE for RAM range: "
                                "[%"PRIpaddr", %"PRIpaddr"]\n", start, end - 1);
                        return 0;
                }
diff --git a/xen/include/xen/numa.h b/xen/include/xen/numa.h
index b779e68787..d64006483a 100644
--- a/xen/include/xen/numa.h
+++ b/xen/include/xen/numa.h
@@ -80,6 +80,9 @@ static inline __attribute_pure__ nodeid_t phys_to_nid(paddr_t 
addr)
 #define node_end_pfn(nid)       (NODE_DATA(nid)->node_start_pfn + \
                                 NODE_DATA(nid)->node_spanned_pages)
 
+extern int arch_get_ram_range(unsigned int idx,
+                              paddr_t *start, paddr_t *end);
+
 #endif
 
 #endif /* _XEN_NUMA_H */
-- 
2.25.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.