fix nvme performance regression due to dma_max_mapping_size()
Hi all,
the new dma_max_mapping_size function is a little to eager to limit the I/O size if the swiotlb buffer is present, but the device is not addressing limited. Fix this by adding an additional check.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH 1/2 dma-mapping: add a dma_addressing_limited helper
This helper returns if the device has issues addressing all present memory in the system.
Signed-off-by Christoph Hellwig <[email protected]>
--- include/linux/dma-mapping.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
include/linux/dma-mapping.h +14 -0
@@ -679,6 +679,20 @@ static inline int dma_coerce_mask_and_coherent(struct device *dev, u64 mask)return dma_set_mask_and_coherent (dev, mask); } +/** +* dma_addressing_limited - return if the device is addressing limited +* @dev: device to check +* +* Return %true if the devices DMA mask is too small to address all memory in +* the system, else %false. Lack of addressing bits is the prime reason for +* bounce buffering, but might not be the only one. +*/ +static inline bool dma_addressing_limited (struct device *dev) +{ +return min_not_zero (*dev->dma_mask, dev->bus_dma_mask) < +dma_get_required_mask (dev); +} +#ifdef CONFIG_ARCH_HAS_SETUP_DMA_OPS void arch_setup_dma_ops (struct device *dev,u64 dma_base,u64 size,const struct iommu_ops *iommu,bool coherent);
Signature · 6 lines
2.20.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH 2/2 dma-direct: only limit the mapping size if swiotlb could be used
In reply to Christoph HellwigDon't just check for a swiotlb buffer, but also if buffering might be required for this particular device.
Fixes 133d624b1cee ("dma: Introduce dma_max_mapping_size()")
Reported-by Benjamin Herrenschmidt <[email protected]>
Signed-off-by Christoph Hellwig <[email protected]>
--- kernel/dma/direct.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
kernel/dma/direct.c +4 -6
@@ -399,11 +399,9 @@ int dma_direct_supported(struct device *dev, u64 mask)size_t dma_direct_max_mapping_size (struct device *dev) { -size_t size =SIZE_MAX ; -/* If SWIOTLB is active, use its maximum mapping size */ -if (is_swiotlb_active ()) - size =swiotlb_max_mapping_size (dev); - -return size; +if (is_swiotlb_active () && + (dma_addressing_limited (dev) || swiotlb_force ==SWIOTLB_FORCE )) +return swiotlb_max_mapping_size (dev); +return SIZE_MAX ; }
Signature · 6 lines
2.20.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu