Skip to content

Commit 8280674

Browse files
Tianyu LanChristoph Hellwig
authored andcommitted
swiotlb: max mapping size takes min align mask into account
swiotlb_find_slots() skips slots according to io tlb aligned mask calculated from min aligned mask and original physical address offset. This affects max mapping size. The mapping size can't achieve the IO_TLB_SEGSIZE * IO_TLB_SIZE when original offset is non-zero. This will cause system boot up failure in Hyper-V Isolation VM where swiotlb force is enabled. Scsi layer use return value of dma_max_mapping_size() to set max segment size and it finally calls swiotlb_max_mapping_size(). Hyper-V storage driver sets min align mask to 4k - 1. Scsi layer may pass 256k length of request buffer with 0~4k offset and Hyper-V storage driver can't get swiotlb bounce buffer via DMA API. Swiotlb_find_slots() can't find 256k length bounce buffer with offset. Make swiotlb_max_mapping _size() take min align mask into account. Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent 1b8e5d1 commit 8280674

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

kernel/dma/swiotlb.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,18 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t paddr, size_t size,
736736

737737
size_t swiotlb_max_mapping_size(struct device *dev)
738738
{
739-
return ((size_t)IO_TLB_SIZE) * IO_TLB_SEGSIZE;
739+
int min_align_mask = dma_get_min_align_mask(dev);
740+
int min_align = 0;
741+
742+
/*
743+
* swiotlb_find_slots() skips slots according to
744+
* min align mask. This affects max mapping size.
745+
* Take it into acount here.
746+
*/
747+
if (min_align_mask)
748+
min_align = roundup(min_align_mask, IO_TLB_SIZE);
749+
750+
return ((size_t)IO_TLB_SIZE) * IO_TLB_SEGSIZE - min_align;
740751
}
741752

742753
bool is_swiotlb_active(struct device *dev)

0 commit comments

Comments
 (0)