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

[PATCH v2 5/9] xen/x86: use arch_get_memory_map to get information from E820 map


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Wei Chen <wei.chen@xxxxxxx>
  • Date: Fri, 8 Jul 2022 22:54:20 +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=d9ZTzLCFsbwcnMhhUkqTjENjME/eU+MsQ1SV7aGwsNU=; b=SetGHbioTzqDcKYyNmDgcTJaek88+mTJjjYDMBG/JdpcLDrGPg2XBRIVsXgsjA7eCRve+bfKWuBbRi4o1FoZ5jT9nQk1sVA0uRlEPL203WlpPOtu3GU8uqucxmIlECwHkYxJW62EofqjdLvXTtTUzbTHAdsQj5lU2aeNLM8BP3+vNm7r0lJoW+rmkeO+Kw3lVyFiL8Qr/19wFf/hr064qGejtZ8Wv4PDpl8g7zxVqyXgfEpbl/S0s1wYpRDChKjqj5gUFsSdw5gTtIBZO0DKToG+Kng0ouVijhO1aB1z8EoHwUwEbqPWAo/ovmygvWzb1ilCp4wwhY+lWldVC4YcWw==
  • 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=d9ZTzLCFsbwcnMhhUkqTjENjME/eU+MsQ1SV7aGwsNU=; b=kjSzMF7GpcPkwtBF5OLqLwb4TbYyOvLUSjwvV6hzlGvWqvnfkdHlvbysR+g1o3AWESq2Pf6vPBRbsUhwN/KO8ZMNyMawRuYWKEffS4TqS5+wTMK6l52UayEkWBL9yC22w26ZGqUB+KWfyUG413szFTCTl/Z1eWFKxU6B70cMmB9XKMeJg3GR+V409FLqUCiwxNdhmwbYhzbwpCp86xP3ck0vbWDTQqxXfJm174wXmxG9mCPy55tNLM9A810k3VwGSd7C4RI5tiInjq3nwbdx2dT9tvUpLp18wnR6NTpdTmvmK4Ff5SH8/tZnd9EdryVJn9oMjdvebfoBGsY3l61zkg==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=bWeQtnwn7vpeYBK9GVTJ5pfyzM2KNiPqjJXFddUeVTs4QS4MXemfL4gH4ONmuKfP0BVQ38mPUqXl7KwEdncpFef5F9MTGLIEn2rq0LQ99vp5hWCDljzZx+DN+gY61S91hilUu6I8jteYGFO8oPNXoNdW6nH+nnVrgeHg/ez4Xg7JWO2LRox0mcs/xpHURGX/Hvxu3Ygk2I2LRu4qCyzec1ZiTKW0iNYVzXvLGyfgHKzkkco4I+r9AlGPY3nvHbrnV+fx21UzcbB4k/HfoiFVA9TrUe69LOP6QnQAV8m2hNJqGJf5GYkkzNB+LZ4sjstZD2O2DgfDREdL7xP/z1EgkA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mC5YUSdxGVt+CAPSNB1J/xpfu4uuMgFdkcIudF1egaAqa3Ti2x+aqu1cwgPq1oAxen6KpiJtxntz7aZPII3o+EAYt0gPVPG/AGAgXDjM3D+Fx40Gk5eUk2TVydVCeJEyahVhEvHAEkj5jvXo1R1ApllvAhC3TrLdrBSXZU4Z33AVYHe1PrpqrWtYnb9y3D9f/R+V/htSVzW01p2jrRr27OoSnUtItMCx/D+8nDek+vZCqlK3Em81nZGStozct28Yq7HghkP9fEmLFAs3C3O8lZB/zRNjnWGndUL+wCQyIslIzowuILi/UAXb57c2EPZ558JJxn0Hz+qxIgArUJVBaA==
  • 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: Fri, 08 Jul 2022 14:55:37 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true

The sanity check performed by the nodes_cover_memory function is
also necessary for other architectures that do not yet support NUMA.
But now, the code of nodes_cover_memory is tied to the x86 E820.
In this case, we introduce arch_get_memory_map to decouple
architecture specific memory map from this function. This means,
other architectures like Arm can also use it to check its bootmem
info.

Depending on arch_get_memory_map, 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
make the message more common.

As arch_get_memory_map 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>
---
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    | 23 +++++++++++++++++++++++
 xen/arch/x86/srat.c    | 18 +++++++++++-------
 xen/include/xen/numa.h |  3 +++
 3 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/xen/arch/x86/numa.c b/xen/arch/x86/numa.c
index 193314dbd9..fb235c07ec 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...)
@@ -82,3 +83,25 @@ 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 -ENODEV for out of scope index, or return
+ * -EINVAL for non-RAM type memory entry.
+ */
+int __init arch_get_memory_map(unsigned int idx, paddr_t *start, paddr_t *end)
+{
+    if ( idx >= e820.nr_map )
+        return -ENODEV;
+
+    if ( e820.map[idx].type != E820_RAM )
+        return -EINVAL;
+
+    *start = e820.map[idx].addr;
+    *end = e820.map[idx].addr + e820.map[idx].size;
+
+    return 0;
+}
diff --git a/xen/arch/x86/srat.c b/xen/arch/x86/srat.c
index 422e4c73e3..5bc9096a15 100644
--- a/xen/arch/x86/srat.c
+++ b/xen/arch/x86/srat.c
@@ -427,18 +427,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. */
+               found = arch_get_memory_map(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 == -ENODEV)
+                       break;
 
                do {
                        found = 0;
@@ -457,7 +461,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 memory map range: "
                                "[%"PRIpaddr", %"PRIpaddr"]\n", start, end - 1);
                        return 0;
                }
diff --git a/xen/include/xen/numa.h b/xen/include/xen/numa.h
index 695ad51df0..6d02204991 100644
--- a/xen/include/xen/numa.h
+++ b/xen/include/xen/numa.h
@@ -88,6 +88,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_memory_map(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®.