Re: [PATCH 1/2] dma-mapping: remove ->mapping_error
From: Christoph Hellwig
Date: Mon Nov 19 2018 - 08:52:20 EST
On Fri, Nov 09, 2018 at 02:41:18PM +0000, Robin Murphy wrote:
>> -
>> #define CMD_SET_TYPE(cmd, t) ((cmd)->data[1] |= ((t) << 28))
>> #define LOOP_TIMEOUT 100000
>> @@ -2339,7 +2337,7 @@ static dma_addr_t __map_single(struct device *dev,
>> paddr &= PAGE_MASK;
>> address = dma_ops_alloc_iova(dev, dma_dom, pages, dma_mask);
>> - if (address == AMD_IOMMU_MAPPING_ERROR)
>> + if (address == DMA_MAPPING_ERROR)
>
> This for one is clearly broken, because the IOVA allocator still returns 0
> on failure here...
Indeed. And that shows how the original code was making a mess of these
different constants..
> I very much agree with the concept, but I think the way to go about it is
> to convert the implementations which need it to the standardised
> *_MAPPING_ERROR value one-by-one, and only then then do the big sweep to
> remove them all. That has more of a chance of getting worthwhile review and
> testing from the respective relevant parties (I'll confess I came looking
> for this bug specifically, since I happened to recall amd_iommu having a
> tricky implicit reliance on the old DMA_ERROR_CODE being 0 on x86).
I'll see if I can split this out somehow, but I'm not sure it is going
to be all that much more readable..
> In terms of really minimising the error-checking overhead it's a bit of a
> shame that DMA_MAPPING_ERROR = 0 doesn't seem viable as the thing to
> standardise on, since that has advantages at the micro-optimisation level
> for many ISAs - fixing up the legacy IOMMU code doesn't seem
> insurmountable, but I suspect there may well be non-IOMMU platforms where
> DMA to physical address 0 is a thing :(
Yes, that is what I'm more worried about.
> (yeah, I know saving a couple of instructions and potential register
> allocations is down in the noise when we're already going from an indirect
> call to an inline comparison; I'm mostly just thinking out loud there)
The nice bit of standardizing the value is that we get rid of an
indirect call, which generally is much more of a problem at the
micro-architecture level.