From: "Jan Beulich" Subject: [PATCH 1/2] page-alloc/x86: don't restrict DMA heap to node 0 Date: Wed, 10 Aug 2016 03:23:26 -0600 Message-ID: <57AB0EAE020000780010494F@prv-mh.provo.novell.com> References: <57AB0D5C020000780010493B@prv-mh.provo.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartF9CF099E.4__=" Return-path: Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bXPjX-0005UX-Fp for xen-devel@lists.xenproject.org; Wed, 10 Aug 2016 09:23:31 +0000 In-Reply-To: <57AB0D5C020000780010493B@prv-mh.provo.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" To: xen-devel Cc: Stefano Stabellini , Wei Liu , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartF9CF099E.4__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline When node zero has no memory, the DMA bit width will end up getting set to 9, which is obviously not helpful to hold back a reasonable amount of low enough memory for Dom0 to use for DMA purposes. Find the lowest node with memory below 4Gb instead. Introduce arch_get_dma_bitsize() to keep this arch-specific logic out of common code. Signed-off-by: Jan Beulich --- a/xen/arch/x86/numa.c +++ b/xen/arch/x86/numa.c @@ -355,11 +355,21 @@ void __init init_cpu_to_node(void) } } =20 -EXPORT_SYMBOL(cpu_to_node); -EXPORT_SYMBOL(node_to_cpumask); -EXPORT_SYMBOL(memnode_shift); -EXPORT_SYMBOL(memnodemap); -EXPORT_SYMBOL(node_data); +unsigned int __init arch_get_dma_bitsize(void) +{ + unsigned int node; + + for_each_online_node(node) + if ( node_spanned_pages(node) && + !(node_start_pfn(node) >> (32 - PAGE_SHIFT)) ) + break; + if ( node >=3D MAX_NUMNODES ) + panic("No node with memory below 4Gb"); + + return min_t(unsigned int, + flsl(node_start_pfn(node) + node_spanned_pages(node) / 4 = - 1) + + PAGE_SHIFT, 32); +} =20 static void dump_numa(unsigned char key) { --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -1368,16 +1368,7 @@ void __init end_boot_allocator(void) init_heap_pages(virt_to_page(bootmem_region_list), 1); =20 if ( !dma_bitsize && (num_online_nodes() > 1) ) - { -#ifdef CONFIG_X86 - dma_bitsize =3D min_t(unsigned int, - flsl(NODE_DATA(0)->node_spanned_pages) - 1 - + PAGE_SHIFT - 2, - 32); -#else - dma_bitsize =3D 32; -#endif - } + dma_bitsize =3D arch_get_dma_bitsize(); =20 printk("Domain heap initialised"); if ( dma_bitsize ) --- a/xen/include/asm-arm/numa.h +++ b/xen/include/asm-arm/numa.h @@ -17,6 +17,11 @@ static inline __attribute__((pure)) node #define node_start_pfn(nid) (pdx_to_pfn(frametable_base_pdx)) #define __node_distance(a, b) (20) =20 +static inline unsigned int arch_get_dma_bitsize(void) +{ + return 32; +} + #endif /* __ARCH_ARM_NUMA_H */ /* * Local variables: --- a/xen/include/asm-x86/numa.h +++ b/xen/include/asm-x86/numa.h @@ -86,5 +86,6 @@ extern int valid_numa_range(u64 start, u =20 void srat_parse_regions(u64 addr); extern u8 __node_distance(nodeid_t a, nodeid_t b); +unsigned int arch_get_dma_bitsize(void); =20 #endif --=__PartF9CF099E.4__= Content-Type: text/plain; name="DMA-heap-fallback.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="DMA-heap-fallback.patch" page-alloc/x86: don't restrict DMA heap to node 0=0A=0AWhen node zero has = no memory, the DMA bit width will end up getting set=0Ato 9, which is = obviously not helpful to hold back a reasonable amount=0Aof low enough = memory for Dom0 to use for DMA purposes. Find the lowest=0Anode with = memory below 4Gb instead.=0A=0AIntroduce arch_get_dma_bitsize() to keep = this arch-specific logic out=0Aof common code.=0A=0ASigned-off-by: Jan = Beulich =0A=0A--- a/xen/arch/x86/numa.c=0A+++ b/xen/arch= /x86/numa.c=0A@@ -355,11 +355,21 @@ void __init init_cpu_to_node(void)=0A = }=0A }=0A =0A-EXPORT_SYMBOL(cpu_to_node);=0A-EXPORT_SYMBOL(node_to_cpuma= sk);=0A-EXPORT_SYMBOL(memnode_shift);=0A-EXPORT_SYMBOL(memnodemap);=0A-EXPO= RT_SYMBOL(node_data);=0A+unsigned int __init arch_get_dma_bitsize(void)=0A+= {=0A+ unsigned int node;=0A+=0A+ for_each_online_node(node)=0A+ = if ( node_spanned_pages(node) &&=0A+ !(node_start_pfn(node) = >> (32 - PAGE_SHIFT)) )=0A+ break;=0A+ if ( node >=3D = MAX_NUMNODES )=0A+ panic("No node with memory below 4Gb");=0A+=0A+ = return min_t(unsigned int,=0A+ flsl(node_start_pfn(node) = + node_spanned_pages(node) / 4 - 1)=0A+ + PAGE_SHIFT, = 32);=0A+}=0A =0A static void dump_numa(unsigned char key)=0A {=0A--- = a/xen/common/page_alloc.c=0A+++ b/xen/common/page_alloc.c=0A@@ -1368,16 = +1368,7 @@ void __init end_boot_allocator(void)=0A init_heap_pages(virt= _to_page(bootmem_region_list), 1);=0A =0A if ( !dma_bitsize && = (num_online_nodes() > 1) )=0A- {=0A-#ifdef CONFIG_X86=0A- = dma_bitsize =3D min_t(unsigned int,=0A- = flsl(NODE_DATA(0)->node_spanned_pages) - 1=0A- = + PAGE_SHIFT - 2,=0A- 32);=0A-#else=0A- = dma_bitsize =3D 32;=0A-#endif=0A- }=0A+ dma_bitsize =3D = arch_get_dma_bitsize();=0A =0A printk("Domain heap initialised");=0A = if ( dma_bitsize )=0A--- a/xen/include/asm-arm/numa.h=0A+++ b/xen/include= /asm-arm/numa.h=0A@@ -17,6 +17,11 @@ static inline __attribute__((pure)) = node=0A #define node_start_pfn(nid) (pdx_to_pfn(frametable_base_pdx))=0A = #define __node_distance(a, b) (20)=0A =0A+static inline unsigned int = arch_get_dma_bitsize(void)=0A+{=0A+ return 32;=0A+}=0A+=0A #endif /* = __ARCH_ARM_NUMA_H */=0A /*=0A * Local variables:=0A--- a/xen/include/asm-x= 86/numa.h=0A+++ b/xen/include/asm-x86/numa.h=0A@@ -86,5 +86,6 @@ extern = int valid_numa_range(u64 start, u=0A =0A void srat_parse_regions(u64 = addr);=0A extern u8 __node_distance(nodeid_t a, nodeid_t b);=0A+unsigned = int arch_get_dma_bitsize(void);=0A =0A #endif=0A --=__PartF9CF099E.4__= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVuLm9yZwpodHRwczovL2xpc3RzLnhlbi5v cmcveGVuLWRldmVsCg== --=__PartF9CF099E.4__=--