Skip to content

Commit 8746515

Browse files
Stefano StabelliniDavid Vrabel
authored andcommitted
xen: Add __GFP_DMA flag when xen_swiotlb_init gets free pages on ARM
Make sure that xen_swiotlb_init allocates buffers that are DMA capable when at least one memblock is available below 4G. Otherwise we assume that all devices on the SoC can cope with >4G addresses. We do this on ARM and ARM64, where dom0 is mapped 1:1, so pfn == mfn in this case. No functional changes on x86. From: Chen Baozi <baozich@gmail.com> Signed-off-by: Chen Baozi <baozich@gmail.com> Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Tested-by: Chen Baozi <baozich@gmail.com> Acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Signed-off-by: David Vrabel <david.vrabel@citrix.com>
1 parent a71dbda commit 8746515

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

arch/arm/include/asm/xen/page.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,6 @@ static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
110110
bool xen_arch_need_swiotlb(struct device *dev,
111111
unsigned long pfn,
112112
unsigned long mfn);
113+
unsigned long xen_get_swiotlb_free_pages(unsigned int order);
113114

114115
#endif /* _ASM_ARM_XEN_PAGE_H */

arch/arm/xen/mm.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <linux/gfp.h>
55
#include <linux/highmem.h>
66
#include <linux/export.h>
7+
#include <linux/memblock.h>
78
#include <linux/of_address.h>
89
#include <linux/slab.h>
910
#include <linux/types.h>
@@ -21,6 +22,20 @@
2122
#include <asm/xen/hypercall.h>
2223
#include <asm/xen/interface.h>
2324

25+
unsigned long xen_get_swiotlb_free_pages(unsigned int order)
26+
{
27+
struct memblock_region *reg;
28+
gfp_t flags = __GFP_NOWARN;
29+
30+
for_each_memblock(memory, reg) {
31+
if (reg->base < (phys_addr_t)0xffffffff) {
32+
flags |= __GFP_DMA;
33+
break;
34+
}
35+
}
36+
return __get_free_pages(flags, order);
37+
}
38+
2439
enum dma_cache_op {
2540
DMA_UNMAP,
2641
DMA_MAP,

arch/x86/include/asm/xen/page.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,4 +269,9 @@ static inline bool xen_arch_need_swiotlb(struct device *dev,
269269
return false;
270270
}
271271

272+
static inline unsigned long xen_get_swiotlb_free_pages(unsigned int order)
273+
{
274+
return __get_free_pages(__GFP_NOWARN, order);
275+
}
276+
272277
#endif /* _ASM_X86_XEN_PAGE_H */

drivers/xen/swiotlb-xen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ int __ref xen_swiotlb_init(int verbose, bool early)
235235
#define SLABS_PER_PAGE (1 << (PAGE_SHIFT - IO_TLB_SHIFT))
236236
#define IO_TLB_MIN_SLABS ((1<<20) >> IO_TLB_SHIFT)
237237
while ((SLABS_PER_PAGE << order) > IO_TLB_MIN_SLABS) {
238-
xen_io_tlb_start = (void *)__get_free_pages(__GFP_NOWARN, order);
238+
xen_io_tlb_start = (void *)xen_get_swiotlb_free_pages(order);
239239
if (xen_io_tlb_start)
240240
break;
241241
order--;

0 commit comments

Comments
 (0)