Skip to content

Commit fc0021a

Browse files
Christoph Hellwigkonradwilk
authored andcommitted
swiotlb: remove the tbl_dma_addr argument to swiotlb_tbl_map_single
The tbl_dma_addr argument is used to check the DMA boundary for the allocations, and thus needs to be a dma_addr_t. swiotlb-xen instead passed a physical address, which could lead to incorrect results for strange offsets. Fix this by removing the parameter entirely and hard code the DMA address for io_tlb_start instead. Fixes: 91ffe4a ("swiotlb-xen: introduce phys_to_dma/dma_to_phys translations") Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Stefano Stabellini <[email protected]> Signed-off-by: Konrad Rzeszutek Wilk <[email protected]>
1 parent e9696d2 commit fc0021a

File tree

4 files changed

+12
-22
lines changed

4 files changed

+12
-22
lines changed

drivers/iommu/intel/iommu.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3815,9 +3815,8 @@ bounce_map_single(struct device *dev, phys_addr_t paddr, size_t size,
38153815
* page aligned, we don't need to use a bounce page.
38163816
*/
38173817
if (!IS_ALIGNED(paddr | size, VTD_PAGE_SIZE)) {
3818-
tlb_addr = swiotlb_tbl_map_single(dev,
3819-
phys_to_dma_unencrypted(dev, io_tlb_start),
3820-
paddr, size, aligned_size, dir, attrs);
3818+
tlb_addr = swiotlb_tbl_map_single(dev, paddr, size,
3819+
aligned_size, dir, attrs);
38213820
if (tlb_addr == DMA_MAPPING_ERROR) {
38223821
goto swiotlb_error;
38233822
} else {

drivers/xen/swiotlb-xen.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
395395
*/
396396
trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force);
397397

398-
map = swiotlb_tbl_map_single(dev, virt_to_phys(xen_io_tlb_start),
399-
phys, size, size, dir, attrs);
398+
map = swiotlb_tbl_map_single(dev, phys, size, size, dir, attrs);
400399
if (map == (phys_addr_t)DMA_MAPPING_ERROR)
401400
return DMA_MAPPING_ERROR;
402401

include/linux/swiotlb.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,9 @@ enum dma_sync_target {
4545
SYNC_FOR_DEVICE = 1,
4646
};
4747

48-
extern phys_addr_t swiotlb_tbl_map_single(struct device *hwdev,
49-
dma_addr_t tbl_dma_addr,
50-
phys_addr_t phys,
51-
size_t mapping_size,
52-
size_t alloc_size,
53-
enum dma_data_direction dir,
54-
unsigned long attrs);
48+
phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
49+
size_t mapping_size, size_t alloc_size,
50+
enum dma_data_direction dir, unsigned long attrs);
5551

5652
extern void swiotlb_tbl_unmap_single(struct device *hwdev,
5753
phys_addr_t tlb_addr,

kernel/dma/swiotlb.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -445,14 +445,11 @@ static void swiotlb_bounce(phys_addr_t orig_addr, phys_addr_t tlb_addr,
445445
}
446446
}
447447

448-
phys_addr_t swiotlb_tbl_map_single(struct device *hwdev,
449-
dma_addr_t tbl_dma_addr,
450-
phys_addr_t orig_addr,
451-
size_t mapping_size,
452-
size_t alloc_size,
453-
enum dma_data_direction dir,
454-
unsigned long attrs)
448+
phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t orig_addr,
449+
size_t mapping_size, size_t alloc_size,
450+
enum dma_data_direction dir, unsigned long attrs)
455451
{
452+
dma_addr_t tbl_dma_addr = phys_to_dma_unencrypted(hwdev, io_tlb_start);
456453
unsigned long flags;
457454
phys_addr_t tlb_addr;
458455
unsigned int nslots, stride, index, wrap;
@@ -671,9 +668,8 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t paddr, size_t size,
671668
trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size,
672669
swiotlb_force);
673670

674-
swiotlb_addr = swiotlb_tbl_map_single(dev,
675-
phys_to_dma_unencrypted(dev, io_tlb_start),
676-
paddr, size, size, dir, attrs);
671+
swiotlb_addr = swiotlb_tbl_map_single(dev, paddr, size, size, dir,
672+
attrs);
677673
if (swiotlb_addr == (phys_addr_t)DMA_MAPPING_ERROR)
678674
return DMA_MAPPING_ERROR;
679675

0 commit comments

Comments
 (0)