Re: [PATCH v5 02/10] iommu/vt-d: Use per-device dma_ops

From: Lu Baolu
Date: Thu Jul 25 2019 - 14:03:54 EST

Hi Christoph,

On 7/25/19 1:44 PM, Christoph Hellwig wrote:
/* Check if the dev needs to go through non-identity map and unmap process.*/
static bool iommu_need_mapping(struct device *dev)
- int ret;
if (iommu_dummy(dev))
return false;
- ret = identity_mapping(dev);
- if (ret) {
- u64 dma_mask = *dev->dma_mask;
- if (dev->coherent_dma_mask && dev->coherent_dma_mask < dma_mask)
- dma_mask = dev->coherent_dma_mask;
- if (dma_mask >= dma_get_required_mask(dev))
- return false;

Don't we need to keep this bit so that we still allow the IOMMU
to act if the device has a too small DMA mask to address all memory in
the system, even if if it should otherwise be identity mapped?

This checking happens only when device is using an identity mapped
domain. If the device has a small DMA mask, swiotlb will be used for
high memory access.

This is supposed to be handled in dma_direct_map_page():

if (unlikely(!dma_direct_possible(dev, dma_addr, size)) &&
!swiotlb_map(dev, &phys, &dma_addr, size, dir, attrs)) {
report_addr(dev, dma_addr, size);

Best regards,