Skip to content

Commit ef9856a

Browse files
committed
Merge branch 'stable/for-linus-5.12' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/swiotlb
Pull swiotlb updates from Konrad Rzeszutek Wilk: "Two memory encryption related patches (SWIOTLB is enabled by default for AMD-SEV): - Add support for alignment so that NVME can properly work - Keep track of requested DMA buffers length, as underlaying hardware devices can trip SWIOTLB to bounce too much and crash the kernel And a tiny fix to use proper APIs in drivers" * 'stable/for-linus-5.12' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/swiotlb: swiotlb: Validate bounce size in the sync/unmap path nvme-pci: set min_align_mask swiotlb: respect min_align_mask swiotlb: don't modify orig_addr in swiotlb_tbl_sync_single swiotlb: refactor swiotlb_tbl_map_single swiotlb: clean up swiotlb_tbl_unmap_single swiotlb: factor out a nr_slots helper swiotlb: factor out an io_tlb_offset helper swiotlb: add a IO_TLB_SIZE define driver core: add a min_align_mask field to struct device_dma_parameters sdhci: stop poking into swiotlb internals
2 parents fecfd01 + daf9514 commit ef9856a

File tree

6 files changed

+215
-123
lines changed

6 files changed

+215
-123
lines changed

drivers/mmc/host/sdhci.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <linux/slab.h>
2121
#include <linux/scatterlist.h>
2222
#include <linux/sizes.h>
23-
#include <linux/swiotlb.h>
2423
#include <linux/regulator/consumer.h>
2524
#include <linux/pm_runtime.h>
2625
#include <linux/of.h>
@@ -4582,12 +4581,8 @@ int sdhci_setup_host(struct sdhci_host *host)
45824581
mmc->max_segs = SDHCI_MAX_SEGS;
45834582
} else if (host->flags & SDHCI_USE_SDMA) {
45844583
mmc->max_segs = 1;
4585-
if (swiotlb_max_segment()) {
4586-
unsigned int max_req_size = (1 << IO_TLB_SHIFT) *
4587-
IO_TLB_SEGSIZE;
4588-
mmc->max_req_size = min(mmc->max_req_size,
4589-
max_req_size);
4590-
}
4584+
mmc->max_req_size = min_t(size_t, mmc->max_req_size,
4585+
dma_max_mapping_size(mmc_dev(mmc)));
45914586
} else { /* PIO */
45924587
mmc->max_segs = SDHCI_MAX_SEGS;
45934588
}

drivers/nvme/host/pci.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,6 +2632,7 @@ static void nvme_reset_work(struct work_struct *work)
26322632
* Don't limit the IOMMU merged segment size.
26332633
*/
26342634
dma_set_max_seg_size(dev->dev, 0xffffffff);
2635+
dma_set_min_align_mask(dev->dev, NVME_CTRL_PAGE_SIZE - 1);
26352636

26362637
mutex_unlock(&dev->shutdown_lock);
26372638

include/linux/device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ struct device_dma_parameters {
291291
* sg limitations.
292292
*/
293293
unsigned int max_segment_size;
294+
unsigned int min_align_mask;
294295
unsigned long segment_boundary_mask;
295296
};
296297

include/linux/dma-mapping.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,22 @@ static inline int dma_set_seg_boundary(struct device *dev, unsigned long mask)
509509
return -EIO;
510510
}
511511

512+
static inline unsigned int dma_get_min_align_mask(struct device *dev)
513+
{
514+
if (dev->dma_parms)
515+
return dev->dma_parms->min_align_mask;
516+
return 0;
517+
}
518+
519+
static inline int dma_set_min_align_mask(struct device *dev,
520+
unsigned int min_align_mask)
521+
{
522+
if (WARN_ON_ONCE(!dev->dma_parms))
523+
return -EIO;
524+
dev->dma_parms->min_align_mask = min_align_mask;
525+
return 0;
526+
}
527+
512528
static inline int dma_get_cache_alignment(void)
513529
{
514530
#ifdef ARCH_DMA_MINALIGN

include/linux/swiotlb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ enum swiotlb_force {
2929
* controllable.
3030
*/
3131
#define IO_TLB_SHIFT 11
32+
#define IO_TLB_SIZE (1 << IO_TLB_SHIFT)
3233

3334
/* default to 64MB */
3435
#define IO_TLB_DEFAULT_SIZE (64UL<<20)

0 commit comments

Comments
 (0)