Skip to content

Commit 85ceaf8

Browse files
committed
Merge tag 'rolling-lts/wsl/6.18.26.2' into linux-msft-wsl-6.18.y
Linux rolling-lts/wsl/6.18.26.2 Signed-off-by: Mitchell Levy <levymitchell0@gmail.com>
2 parents f15bfa1 + eeff7e3 commit 85ceaf8

5 files changed

Lines changed: 118 additions & 1 deletion

File tree

MSFT-Merge/log

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ feature/arm64-hyperv-hypercall-interface/6.18 712c88941ba7cfd3c9eec3a58eef4
55
feature/arm64-hyperv-synthetic-clocks-timers/6.18 ea0cd9a5b6202ef81b45f137c37b17478a54f382
66
feature/wsl-module-script/6.18 9c6d7c0a3fadd2ce32c90dad74429ed7e463ad4a
77
feature/dxgkrnl/6.18 7645bb43d045d813c5a11a5746c28bd763868b28
8+
feature/swiotlb-pool/6.18 8e58006b40f811c1611a0edd7f8ac4f518baf1dd
89
product/wsl/readme/6.18 bbf044c25e1203bed3182cedae466235420e7e96
910
product/wsl/security/6.18 20778f3fd73f259549f66a8bea0227dbdfe3e170
1011
fix/virtiofs-dax-hang/6.18 668def1339349ba0ff85f22b6244066a8369b022

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
VERSION = 6
33
PATCHLEVEL = 18
44
SUBLEVEL = 26
5-
EXTRAVERSION = .1
5+
EXTRAVERSION = .2
66
NAME = Baby Opossum Posse
77

88
# *DOCUMENTATION*

drivers/pci/controller/pci-hyperv.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
#include <linux/acpi.h>
5353
#include <linux/sizes.h>
5454
#include <linux/of_irq.h>
55+
#include <linux/swiotlb.h>
56+
#include <linux/memblock.h>
5557
#include <asm/mshyperv.h>
5658

5759
/*
@@ -468,6 +470,22 @@ struct pci_eject_response {
468470

469471
static int pci_ring_size = VMBUS_RING_SIZE(SZ_16K);
470472

473+
static phys_addr_t hv_pci_swiotlb_base;
474+
static size_t hv_pci_swiotlb_size;
475+
476+
static int __init early_hv_pci_swiotlb(char *p)
477+
{
478+
hv_pci_swiotlb_base = memparse(p, &p);
479+
if (*p == ',')
480+
hv_pci_swiotlb_size = memparse(p + 1, NULL);
481+
if (hv_pci_swiotlb_base && hv_pci_swiotlb_size)
482+
memblock_reserve(hv_pci_swiotlb_base, hv_pci_swiotlb_size);
483+
return 0;
484+
}
485+
early_param("hv_pci_swiotlb", early_hv_pci_swiotlb);
486+
487+
static struct io_tlb_mem *hv_pci_swiotlb_pool;
488+
471489
/*
472490
* Driver specific state.
473491
*/
@@ -2510,6 +2528,25 @@ static void hv_pci_assign_numa_node(struct hv_pcibus_device *hbus)
25102528
}
25112529
}
25122530

2531+
/**
2532+
* hv_pci_assign_swiotlb() - assign dedicated swiotlb pool to bus devices
2533+
* @bus: PCI bus whose devices should use the pool
2534+
*
2535+
* If a dedicated swiotlb pool was configured via hv_pci_swiotlb=,
2536+
* assign it to every device on the bus so their DMA bounce buffering
2537+
* uses the restricted region.
2538+
*/
2539+
static void hv_pci_assign_swiotlb(struct pci_bus *bus)
2540+
{
2541+
struct pci_dev *dev;
2542+
2543+
if (!hv_pci_swiotlb_pool)
2544+
return;
2545+
2546+
list_for_each_entry(dev, &bus->devices, bus_list)
2547+
dev->dev.dma_io_tlb_mem = hv_pci_swiotlb_pool;
2548+
}
2549+
25132550
/**
25142551
* create_root_hv_pci_bus() - Expose a new root PCI bus
25152552
* @hbus: Root PCI bus, as understood by this driver
@@ -2533,6 +2570,7 @@ static int create_root_hv_pci_bus(struct hv_pcibus_device *hbus)
25332570
hv_pci_assign_numa_node(hbus);
25342571
pci_bus_assign_resources(bridge->bus);
25352572
hv_pci_assign_slots(hbus);
2573+
hv_pci_assign_swiotlb(bridge->bus);
25362574
pci_bus_add_devices(bridge->bus);
25372575
pci_unlock_rescan_remove();
25382576
hbus->state = hv_pcibus_installed;
@@ -2803,6 +2841,7 @@ static void pci_devices_present_work(struct work_struct *work)
28032841
pci_scan_child_bus(hbus->bridge->bus);
28042842
hv_pci_assign_numa_node(hbus);
28052843
hv_pci_assign_slots(hbus);
2844+
hv_pci_assign_swiotlb(hbus->bridge->bus);
28062845
pci_unlock_rescan_remove();
28072846
break;
28082847

@@ -4221,6 +4260,17 @@ static int __init init_hv_pci_drv(void)
42214260
if (hv_root_partition() && !hv_nested)
42224261
return -ENODEV;
42234262

4263+
if (hv_pci_swiotlb_base && hv_pci_swiotlb_size) {
4264+
hv_pci_swiotlb_pool = swiotlb_create_pool(hv_pci_swiotlb_base,
4265+
hv_pci_swiotlb_size,
4266+
"hv-pci-swiotlb");
4267+
if (IS_ERR(hv_pci_swiotlb_pool)) {
4268+
pr_err("hv_pci: failed to create swiotlb pool: %ld\n",
4269+
PTR_ERR(hv_pci_swiotlb_pool));
4270+
hv_pci_swiotlb_pool = NULL;
4271+
}
4272+
}
4273+
42244274
ret = hv_pci_irqchip_init();
42254275
if (ret)
42264276
return ret;

include/linux/swiotlb.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ bool is_swiotlb_active(struct device *dev);
185185
void __init swiotlb_adjust_size(unsigned long size);
186186
phys_addr_t default_swiotlb_base(void);
187187
phys_addr_t default_swiotlb_limit(void);
188+
struct io_tlb_mem *swiotlb_create_pool(phys_addr_t base, size_t size,
189+
const char *name);
188190
#else
189191
static inline void swiotlb_init(bool addressing_limited, unsigned int flags)
190192
{

kernel/dma/swiotlb.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,3 +1898,67 @@ static int __init rmem_swiotlb_setup(struct reserved_mem *rmem)
18981898

18991899
RESERVEDMEM_OF_DECLARE(dma, "restricted-dma-pool", rmem_swiotlb_setup);
19001900
#endif /* CONFIG_DMA_RESTRICTED_POOL */
1901+
1902+
/**
1903+
* swiotlb_create_pool() - create a swiotlb pool from a physical memory region
1904+
* @base: Physical base address of the region.
1905+
* @size: Size of the region in bytes.
1906+
* @name: Name for debugfs (may be NULL).
1907+
*
1908+
* Allocates and initializes an io_tlb_mem with its default pool backed by the
1909+
* caller-provided physical memory. The region must already be reserved (e.g.
1910+
* via memblock_reserve or firmware memory map) and within the linear mapping.
1911+
*
1912+
* The returned pool has force_bounce set so that streaming DMA is bounced
1913+
* through this region. Assign it to dev->dma_io_tlb_mem to direct a device's
1914+
* DMA bounce buffering into this region. Coherent DMA allocations
1915+
* (dma_alloc_coherent) are not affected and will use normal memory.
1916+
*
1917+
* Return: pointer to a new io_tlb_mem on success, ERR_PTR on failure.
1918+
*/
1919+
struct io_tlb_mem *swiotlb_create_pool(phys_addr_t base, size_t size,
1920+
const char *name)
1921+
{
1922+
struct io_tlb_mem *mem;
1923+
struct io_tlb_pool *pool;
1924+
unsigned long nslabs = size >> IO_TLB_SHIFT;
1925+
unsigned int nareas = 1;
1926+
1927+
if (PageHighMem(pfn_to_page(PHYS_PFN(base))))
1928+
return ERR_PTR(-EINVAL);
1929+
1930+
mem = kzalloc(sizeof(*mem), GFP_KERNEL);
1931+
if (!mem)
1932+
return ERR_PTR(-ENOMEM);
1933+
pool = &mem->defpool;
1934+
1935+
pool->slots = kcalloc(nslabs, sizeof(*pool->slots), GFP_KERNEL);
1936+
if (!pool->slots) {
1937+
kfree(mem);
1938+
return ERR_PTR(-ENOMEM);
1939+
}
1940+
1941+
pool->areas = kcalloc(nareas, sizeof(*pool->areas), GFP_KERNEL);
1942+
if (!pool->areas) {
1943+
kfree(pool->slots);
1944+
kfree(mem);
1945+
return ERR_PTR(-ENOMEM);
1946+
}
1947+
1948+
set_memory_decrypted((unsigned long)phys_to_virt(base),
1949+
size >> PAGE_SHIFT);
1950+
swiotlb_init_io_tlb_pool(pool, base, nslabs, false, nareas);
1951+
mem->force_bounce = true;
1952+
mem->for_alloc = false;
1953+
#ifdef CONFIG_SWIOTLB_DYNAMIC
1954+
spin_lock_init(&mem->lock);
1955+
INIT_LIST_HEAD_RCU(&mem->pools);
1956+
#endif
1957+
add_mem_pool(mem, pool);
1958+
swiotlb_create_debugfs_files(mem, name ?: "swiotlb-pool");
1959+
1960+
pr_info("created restricted pool at %pa, size %zuMiB\n",
1961+
&base, size / SZ_1M);
1962+
return mem;
1963+
}
1964+
EXPORT_SYMBOL_GPL(swiotlb_create_pool);

0 commit comments

Comments
 (0)