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

Lu Baolu
2019-11-14T05:17:15Z

Hi Christoph,

On 11/13/19 5:53 PM, Christoph Hellwig wrote:
> On Wed, Nov 13, 2019 at 08:03:12AM +0100, Christoph Hellwig wrote:
>> Indeed. And one idea would be to lift the code in the powerpc
>> dma_iommu_ops that check a flag and use the direct ops to the generic
>> dma code and a flag in struct device. We can then switch the intel
>> iommu ops (and AMD Gart) over to it.
>
> Let me know what you think of the branch below. Only compile tested
> and booted on qemu with an emulated intel iommu:
>
> http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/dma-bypass
>

I took a quick look at the related patches on the branch. Most of them
look good to me. But I would like to understand more about below logic.

static int intel_dma_supported(struct device *dev, u64 mask)
{
struct device_domain_info *info = dev->archdata.iommu;
int ret;

ret = dma_direct_supported(dev, mask);
if (ret < 0)
return ret;

if (!info || info == DUMMY_DEVICE_DOMAIN_INFO ||
info == DEFER_DEVICE_DOMAIN_INFO) {
dev->dma_ops_bypass = true;
} else if (info->domain == si_domain) {
if (mask < dma_direct_get_required_mask(dev)) {
dev->dma_ops_bypass = false;
intel_iommu_set_dma_domain(dev);
dev_info(dev, "32bit DMA uses non-identity mapping\n");
} else {
dev->dma_ops_bypass = true;
}
} else {
dev->dma_ops_bypass = false;
}

return 0;
}

Could you please educate me what dma_supported() is exactly for? Will
it always get called during boot? When will it be called?

In above implementation, why do we need to check dma_direct_supported()
at the beginning? And why

if (!info || info == DUMMY_DEVICE_DOMAIN_INFO ||
info == DEFER_DEVICE_DOMAIN_INFO) {
dev->dma_ops_bypass = true;

Best regards,
baolu