Skip to content

Commit 6c1b980

Browse files
committed
Merge tag 'dma-mapping-6.6-2023-08-29' of git://git.infradead.org/users/hch/dma-mapping
Pull dma-maping updates from Christoph Hellwig: - allow dynamic sizing of the swiotlb buffer, to cater for secure virtualization workloads that require all I/O to be bounce buffered (Petr Tesarik) - move a declaration to a header (Arnd Bergmann) - check for memory region overlap in dma-contiguous (Binglei Wang) - remove the somewhat dangerous runtime swiotlb-xen enablement and unexport is_swiotlb_active (Christoph Hellwig, Juergen Gross) - per-node CMA improvements (Yajun Deng) * tag 'dma-mapping-6.6-2023-08-29' of git://git.infradead.org/users/hch/dma-mapping: swiotlb: optimize get_max_slots() swiotlb: move slot allocation explanation comment where it belongs swiotlb: search the software IO TLB only if the device makes use of it swiotlb: allocate a new memory pool when existing pools are full swiotlb: determine potential physical address limit swiotlb: if swiotlb is full, fall back to a transient memory pool swiotlb: add a flag whether SWIOTLB is allowed to grow swiotlb: separate memory pool data from other allocator data swiotlb: add documentation and rename swiotlb_do_find_slots() swiotlb: make io_tlb_default_mem local to swiotlb.c swiotlb: bail out of swiotlb_init_late() if swiotlb is already allocated dma-contiguous: check for memory region overlap dma-contiguous: support numa CMA for specified node dma-contiguous: support per-numa CMA for all architectures dma-mapping: move arch_dma_set_mask() declaration to header swiotlb: unexport is_swiotlb_active x86: always initialize xen-swiotlb when xen-pcifront is enabling xen/pci: add flag for PCI passthrough being possible
2 parents 3d3dfeb + d069ed2 commit 6c1b980

File tree

23 files changed

+910
-187
lines changed

23 files changed

+910
-187
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@
696696
kernel/dma/contiguous.c
697697

698698
cma_pernuma=nn[MG]
699-
[ARM64,KNL,CMA]
699+
[KNL,CMA]
700700
Sets the size of kernel per-numa memory area for
701701
contiguous memory allocations. A value of 0 disables
702702
per-numa CMA altogether. And If this option is not
@@ -706,6 +706,17 @@
706706
which is located in node nid, if the allocation fails,
707707
they will fallback to the global default memory area.
708708

709+
numa_cma=<node>:nn[MG][,<node>:nn[MG]]
710+
[KNL,CMA]
711+
Sets the size of kernel numa memory area for
712+
contiguous memory allocations. It will reserve CMA
713+
area for the specified node.
714+
715+
With numa CMA enabled, DMA users on node nid will
716+
first try to allocate buffer from the numa area
717+
which is located in node nid, if the allocation fails,
718+
they will fallback to the global default memory area.
719+
709720
cmo_free_hint= [PPC] Format: { yes | no }
710721
Specify whether pages are marked as being inactive
711722
when they are freed. This is used in CMO environments

arch/arm/xen/mm.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,10 @@ static int __init xen_mm_init(void)
125125
return 0;
126126

127127
/* we can work with the default swiotlb */
128-
if (!io_tlb_default_mem.nslabs) {
129-
rc = swiotlb_init_late(swiotlb_size_or_default(),
130-
xen_swiotlb_gfp(), NULL);
131-
if (rc < 0)
132-
return rc;
133-
}
128+
rc = swiotlb_init_late(swiotlb_size_or_default(),
129+
xen_swiotlb_gfp(), NULL);
130+
if (rc < 0)
131+
return rc;
134132

135133
cflush.op = 0;
136134
cflush.a.dev_bus_addr = 0;

arch/arm64/mm/init.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,6 @@ void __init bootmem_init(void)
461461
arm64_hugetlb_cma_reserve();
462462
#endif
463463

464-
dma_pernuma_cma_reserve();
465-
466464
kvm_hyp_reserve();
467465

468466
/*

arch/mips/pci/pci-octeon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ static int __init octeon_pci_setup(void)
664664

665665
/* BAR1 movable regions contiguous to cover the swiotlb */
666666
octeon_bar1_pci_phys =
667-
io_tlb_default_mem.start & ~((1ull << 22) - 1);
667+
default_swiotlb_base() & ~((1ull << 22) - 1);
668668

669669
for (index = 0; index < 32; index++) {
670670
union cvmx_pci_bar1_indexx bar1_index;

arch/powerpc/kernel/dma-mask.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0
22

33
#include <linux/dma-mapping.h>
4+
#include <linux/dma-map-ops.h>
45
#include <linux/export.h>
56
#include <asm/machdep.h>
67

arch/x86/include/asm/xen/swiotlb-xen.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
#ifndef _ASM_X86_SWIOTLB_XEN_H
33
#define _ASM_X86_SWIOTLB_XEN_H
44

5-
#ifdef CONFIG_SWIOTLB_XEN
6-
extern int pci_xen_swiotlb_init_late(void);
7-
#else
8-
static inline int pci_xen_swiotlb_init_late(void) { return -ENXIO; }
9-
#endif
10-
115
int xen_swiotlb_fixup(void *buf, unsigned long nslabs);
126
int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order,
137
unsigned int address_bits,

arch/x86/kernel/pci-dma.c

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,15 @@ static inline void __init pci_swiotlb_detect(void)
7272
#endif /* CONFIG_SWIOTLB */
7373

7474
#ifdef CONFIG_SWIOTLB_XEN
75+
static bool xen_swiotlb_enabled(void)
76+
{
77+
return xen_initial_domain() || x86_swiotlb_enable ||
78+
(IS_ENABLED(CONFIG_XEN_PCIDEV_FRONTEND) && xen_pv_pci_possible);
79+
}
80+
7581
static void __init pci_xen_swiotlb_init(void)
7682
{
77-
if (!xen_initial_domain() && !x86_swiotlb_enable)
83+
if (!xen_swiotlb_enabled())
7884
return;
7985
x86_swiotlb_enable = true;
8086
x86_swiotlb_flags |= SWIOTLB_ANY;
@@ -83,27 +89,6 @@ static void __init pci_xen_swiotlb_init(void)
8389
if (IS_ENABLED(CONFIG_PCI))
8490
pci_request_acs();
8591
}
86-
87-
int pci_xen_swiotlb_init_late(void)
88-
{
89-
if (dma_ops == &xen_swiotlb_dma_ops)
90-
return 0;
91-
92-
/* we can work with the default swiotlb */
93-
if (!io_tlb_default_mem.nslabs) {
94-
int rc = swiotlb_init_late(swiotlb_size_or_default(),
95-
GFP_KERNEL, xen_swiotlb_fixup);
96-
if (rc < 0)
97-
return rc;
98-
}
99-
100-
/* XXX: this switches the dma ops under live devices! */
101-
dma_ops = &xen_swiotlb_dma_ops;
102-
if (IS_ENABLED(CONFIG_PCI))
103-
pci_request_acs();
104-
return 0;
105-
}
106-
EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
10792
#else
10893
static inline void __init pci_xen_swiotlb_init(void)
10994
{

arch/x86/xen/setup.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ struct xen_memory_region xen_extra_mem[XEN_EXTRA_MEM_MAX_REGIONS] __initdata;
4444
/* Number of pages released from the initial allocation. */
4545
unsigned long xen_released_pages;
4646

47+
/* Memory map would allow PCI passthrough. */
48+
bool xen_pv_pci_possible;
49+
4750
/* E820 map used during setting up memory. */
4851
static struct e820_table xen_e820_table __initdata;
4952

@@ -814,6 +817,9 @@ char * __init xen_memory_setup(void)
814817
chunk_size = size;
815818
type = xen_e820_table.entries[i].type;
816819

820+
if (type == E820_TYPE_RESERVED)
821+
xen_pv_pci_possible = true;
822+
817823
if (type == E820_TYPE_RAM) {
818824
if (addr < mem_end) {
819825
chunk_size = min(size, mem_end - addr);

drivers/base/core.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3108,9 +3108,7 @@ void device_initialize(struct device *dev)
31083108
defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL)
31093109
dev->dma_coherent = dma_default_coherent;
31103110
#endif
3111-
#ifdef CONFIG_SWIOTLB
3112-
dev->dma_io_tlb_mem = &io_tlb_default_mem;
3113-
#endif
3111+
swiotlb_dev_init(dev);
31143112
}
31153113
EXPORT_SYMBOL_GPL(device_initialize);
31163114

drivers/pci/xen-pcifront.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <linux/bitops.h>
2323
#include <linux/time.h>
2424
#include <linux/ktime.h>
25-
#include <linux/swiotlb.h>
2625
#include <xen/platform_pci.h>
2726

2827
#include <asm/xen/swiotlb-xen.h>
@@ -669,11 +668,6 @@ static int pcifront_connect_and_init_dma(struct pcifront_device *pdev)
669668

670669
spin_unlock(&pcifront_dev_lock);
671670

672-
if (!err && !is_swiotlb_active(&pdev->xdev->dev)) {
673-
err = pci_xen_swiotlb_init_late();
674-
if (err)
675-
dev_err(&pdev->xdev->dev, "Could not setup SWIOTLB!\n");
676-
}
677671
return err;
678672
}
679673

0 commit comments

Comments
 (0)