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

[PATCH v5 3/8] xen: introduce an arch helper for default dma zone status


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Wei Chen <wei.chen@xxxxxxx>
  • Date: Mon, 6 Jun 2022 12:09:11 +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=zV9BPdeAndxQ7scfKxz8oRzzRCdsj7R5+H/m4APAu1s=; b=BSk0r40Ul5Di9UWLMU0mPTASjblIR4xtTM7WXFGafB6NCYka3ZhaSDT+2B3O4liXCADhddupwtOjG2Vl7YpGzRKsvlo0+tk3PGWNiwqpraLe/2JpKr+u9A4NVNPOSajkrv9e6xHrduDuH2AVm9EFpoqAyXCnVHyME1w+LnnCcimgl3vA2KM2bYgwFyyHhr1bDbUB9GQdP2ICJBHUFwWtVf7AZBy44HiZaoEmpMBr1eZWQONCkrxfEzshSfSVvf6R+qcWbFOwuGdfO/lQv1XKE2gOUpgkZDXfup2AULaj9sj/8YoW1IOLntCdPb2kKGB71Z8vzmGr4ocNXalg91v5QA==
  • 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=zV9BPdeAndxQ7scfKxz8oRzzRCdsj7R5+H/m4APAu1s=; b=mKcKsXHA+4sRVb8MJqxmMVdNNk8LqADOh3womIJ63rNs+oAEQFTncDAe+Ka/x1IBDLHvftanIJsyL3ysUFJb+noTzNoypRHlkIrhhrSH9OhPcSL+Jd89ZnZ7xkanwr5Hi1LoLe6ZT0XCNHOqzUCVqeoVjGaMLhxhPvrJVLqQaBFxtySoFR4z0X2nUJmemLIowMzxpRkKN7dmjXKo0ga/Dow5gtXW5F4RJN72XOW2YcOCHKzV0izQJaWq/ljpMYFBpER2gbIbIw0mpYkBDv5jRETTJ1WEXwPH6Ch2QhO657PY0lzITmZrZBPPialskBujGMVtRQHu15QmKe31wt2YRw==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=Rw4YCyc3kplTi0dy0J9sE2MdXGplsaHNaDGQ1DRVaBzbHFTA27zvi6lZvxugqn2WEaR88o2VOd9U2SiCOC2V/PX89LtiNWXGyX+VgcEcLUV2QvyQwWYUbays+kJP3EitWkuqwl+iD/Rd/2hkd4sO/zrFg1LUerfRhQUNLYZgIvy5G2JYZnLh0K33pnsYZ5emmB+MZD3b1v42jmED3G0HwCBrLRJkPpOPUoROndrzUTnLNnGgHtILR6Jwgk3l4Ga+JFSL049yFJ99bU4pHKMT0gxAMB7GjR1Ip7S0I4bcjkwgliHc9XZAnGt5fjWfic3GL4y9erJHPGPa9ATnNU+ePQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c7zrYHEOZWdptqK6uM8V7TGdX5QvWrCeeMU1XVr2edHrFzDm9VG+t2z3Bt2A2UIDYElk/Ptk1cdHtpUNDQRs3x1ejOCOzndQ/K8lgKATwq/FtD831HEcOAawCaRzBlhZgW+WaVJ0zejgYGr9GaPDFoBRQ47ceF/Ui+g0ROZ95QQcOKecX1lpFGdLb86F7Hw1efWChynFhxFNohR5MPP/b11w1uLjiQk/gUg78Vih/ZnfVu8HkUmdVepBrbY4nQ9L0l/oQcQSBxf4fwo2ejGin1X+RL+M3f+nx46Ft5vIRyuricfRlOaPCdtHIWC9ADSI16XENRuU8raG9UfXhf6LGw==
  • Cc: <nd@xxxxxxx>, Wei Chen <wei.chen@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Jiamei Xie <jiamei.xie@xxxxxxx>
  • Delivery-date: Mon, 06 Jun 2022 04:09:51 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true

In current code, when Xen is running in a multiple nodes
NUMA system, it will set dma_bitsize in end_boot_allocator
to reserve some low address memory as DMA zone.

There are some x86 implications in the implementation.
Because on x86, memory starts from 0. On a multiple-nodes
NUMA system, if a single node contains the majority or all
of the DMA memory, x86 prefers to give out memory from
non-local allocations rather than exhausting the DMA memory
ranges. Hence x86 uses dma_bitsize to set aside some largely
arbitrary amount of memory for DMA zone. The allocations
from DMA zone would happen only after exhausting all other
nodes' memory.

But the implications are not shared across all architectures.
For example, Arm cannot guarantee the availability of memory
below a certain boundary for DMA limited-capability devices
either. But currently, Arm doesn't need a reserved DMA zone
in Xen. Because there is no DMA device in Xen. And for guests,
Xen Arm only allows Dom0 to have DMA operations without IOMMU.
Xen will try to allocate memory under 4GB or memory range that
is limited by dma_bitsize for Dom0 in boot time. For DomU, even
Xen can passthrough devices to DomU without IOMMU, but Xen Arm
doesn't guarantee their DMA operations. So, Xen Arm doesn't
need a reserved DMA zone to provide DMA memory for guests.

In this patch, we introduce an arch_want_default_dmazone helper
for different architectures to determine whether they need to
set dma_bitsize for DMA zone reservation or not.

At the same time, when x86 Xen is built with CONFIG_PV=n could
probably leverage this new helper to actually not trigger DMA
zone reservation.

Signed-off-by: Wei Chen <wei.chen@xxxxxxx>
Tested-by: Jiamei Xie <jiamei.xie@xxxxxxx>
Acked-by: Jan Beulich <jbeulich@xxxxxxxx>
---
v3 -> v4:
1. Add Acked-by.
v2 -> v3:
1. Add Tb.
2. Rename arch_have_default_dmazone to arch_want_default_dmazone.
v1 -> v2:
1. Extend the description of Arm's workaround for reserve DMA
   allocations to avoid the same discussion every time.
2. Use a macro to define arch_have_default_dmazone, because
   it's little hard to make x86 version to static inline.
   Use a macro will also avoid add __init for this function.
3. Change arch_have_default_dmazone return value from
   unsigned int to bool.
4. Un-addressed comment: make arch_have_default_dmazone
   of x86 to be static inline. Because, if we move
   arch_have_default_dmazone to x86/asm/numa.h, it depends
   on nodemask.h to provide num_online_nodes. But nodemask.h
   needs numa.h to provide MAX_NUMANODES. This will cause a
   loop dependency. And this function can only be used in
   end_boot_allocator, in Xen initialization. So I think,
   compared to the changes introduced by inline, it doesn't
   mean much.
---
 xen/arch/arm/include/asm/numa.h | 1 +
 xen/arch/x86/include/asm/numa.h | 1 +
 xen/common/page_alloc.c         | 2 +-
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/xen/arch/arm/include/asm/numa.h b/xen/arch/arm/include/asm/numa.h
index 31a6de4e23..e4c4d89192 100644
--- a/xen/arch/arm/include/asm/numa.h
+++ b/xen/arch/arm/include/asm/numa.h
@@ -24,6 +24,7 @@ extern mfn_t first_valid_mfn;
 #define node_spanned_pages(nid) (max_page - mfn_x(first_valid_mfn))
 #define node_start_pfn(nid) (mfn_x(first_valid_mfn))
 #define __node_distance(a, b) (20)
+#define arch_want_default_dmazone() (false)
 
 #endif /* __ARCH_ARM_NUMA_H */
 /*
diff --git a/xen/arch/x86/include/asm/numa.h b/xen/arch/x86/include/asm/numa.h
index bada2c0bb9..5d8385f2e1 100644
--- a/xen/arch/x86/include/asm/numa.h
+++ b/xen/arch/x86/include/asm/numa.h
@@ -74,6 +74,7 @@ static inline __attribute__((pure)) nodeid_t 
phys_to_nid(paddr_t addr)
 #define node_spanned_pages(nid)        (NODE_DATA(nid)->node_spanned_pages)
 #define node_end_pfn(nid)       (NODE_DATA(nid)->node_start_pfn + \
                                 NODE_DATA(nid)->node_spanned_pages)
+#define arch_want_default_dmazone() (num_online_nodes() > 1)
 
 extern int valid_numa_range(u64 start, u64 end, nodeid_t node);
 
diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
index 319029140f..b3bddc719b 100644
--- a/xen/common/page_alloc.c
+++ b/xen/common/page_alloc.c
@@ -1889,7 +1889,7 @@ void __init end_boot_allocator(void)
     }
     nr_bootmem_regions = 0;
 
-    if ( !dma_bitsize && (num_online_nodes() > 1) )
+    if ( !dma_bitsize && arch_want_default_dmazone() )
         dma_bitsize = arch_get_dma_bitsize();
 
     printk("Domain heap initialised");
-- 
2.25.1




 


Rackspace

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