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

From: Lu Baolu
Date: Thu Jul 25 2019 - 21:57:33 EST


Hi,

On 7/25/19 7:43 PM, Christoph Hellwig wrote:
On Thu, Jul 25, 2019 at 03:18:03PM +0800, Lu Baolu wrote:
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);
return DMA_MAPPING_ERROR;
}

Well, yes. But the point is that the current code uses dynamic iommu
mappings even if the devices is in the identity mapped domain when the
dma mask Ñs too small to map all memory directly. Your change means it
will now use swiotlb which is most likely going to be a lot more

By default, we use DMA domain. The privileged users are able to change
this with global kernel parameter or per-group default domain type under
discussion. In another word, use of identity domain is a choice of the
privileged user who should consider the possible bounce buffer overhead.

I think current code doesn't do the right thing. The user asks the iommu
driver to use identity domain for a device, but the driver force it back
to DMA domain because of the device address capability.

expensive. I don't think that this change is a good idea, and even if
we decide that this is a good idea after all that should be done in a
separate prep patch that explains the rationale.

Yes. Make sense.

Best regards,
Baolu