aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas Schnelle <schnelle@linux.ibm.com>2023-11-02 12:24:45 +0100
committerNiklas Schnelle <schnelle@linux.ibm.com>2023-11-02 18:18:06 +0100
commit8cfc2dc53db5921e1ec417b1d0ae235ee4125cd6 (patch)
treeaa5b85aef44942948896218cb578f7ca3cfa3b93
parentab3949bdb4b0c066153db45aaf44f71c532e69e3 (diff)
downloadlinux-bounce-min.tar.gz
DEBUG-swiotlb/pci: Make all PCI devices untrusted and add overrun testbounce-min
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
-rw-r--r--drivers/pci/probe.c1
-rw-r--r--kernel/dma/swiotlb.c18
2 files changed, 19 insertions, 0 deletions
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 795534589b985..4aebb2e58923b 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -2436,6 +2436,7 @@ static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn)
dev->devfn = devfn;
dev->vendor = l & 0xffff;
dev->device = (l >> 16) & 0xffff;
+ dev->untrusted = 1;
if (pci_setup_device(dev)) {
pci_bus_put(dev->bus);
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index dff067bd56b1e..330b4966d27fb 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -1300,6 +1300,24 @@ phys_addr_t swiotlb_tbl_map_single(struct device *dev, phys_addr_t orig_addr,
for (i = 0; i < nr_slots(alloc_size + offset); i++)
pool->slots[index + i].orig_addr = slot_addr(orig_addr, i);
tlb_addr = slot_addr(pool->start, index) + offset;
+
+ if (tlb_addr + alloc_size > pool->end) {
+ pr_info("\n\ttransient:%i"
+ "\n\tindex:%i"
+ "\n\tdma_get_min_align_mask(dev):%llx"
+ "\n\torig_addr:%llx"
+ "\n\ttlb_addr=%llx"
+ "\n\tstart:%llx"
+ "\n\tend:%llx"
+ "\n\tpool_size:%zu"
+ "\n\talloc_size:%zu"
+ "\n\toffset:%u\n",
+ pool->transient, index, (u64)dma_get_min_align_mask(dev), (u64)orig_addr,
+ (u64)tlb_addr, (u64)pool->start, (u64)pool->end,
+ (size_t)(pool->end - pool->start), alloc_size, offset);
+ return (phys_addr_t)DMA_MAPPING_ERROR;
+ }
+
/*
* When dir == DMA_FROM_DEVICE we could omit the copy from the orig
* to the tlb buffer, if we knew for sure the device will