linux-parisc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Russell King - ARM Linux <linux@armlinux.org.uk>
To: Joerg Roedel <joro@8bytes.org>
Cc: Robin Murphy <robin.murphy@arm.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Christoph Hellwig <hch@lst.de>,
	linux-arch@vger.kernel.org, linux-alpha@vger.kernel.org,
	linux-ia64@vger.kernel.org, linux-parisc@vger.kernel.org,
	David Woodhouse <dwmw2@infradead.org>,
	the arch/x86 maintainers <x86@kernel.org>,
	Linux List Kernel Mailing <linux-kernel@vger.kernel.org>,
	iommu@lists.linux-foundation.org, jdmason@kudzu.us,
	xen-devel@lists.xenproject.org,
	linux-arm-kernel@lists.infradead.org, m.szyprowski@samsung.com
Subject: Re: remove the ->mapping_error method from dma_map_ops V2
Date: Fri, 23 Nov 2018 13:20:38 +0000	[thread overview]
Message-ID: <20181123132038.GT30658@n2100.armlinux.org.uk> (raw)
In-Reply-To: <20181123130313.GI1586@8bytes.org>

On Fri, Nov 23, 2018 at 02:03:13PM +0100, Joerg Roedel wrote:
> On Fri, Nov 23, 2018 at 11:01:55AM +0000, Russell King - ARM Linux wrote:
> > Yuck.  So, if we have a 4GB non-PAE 32-bit system, or a PAE system
> > where we have valid memory across the 4GB boundary and no IOMMU,
> > we have to reserve the top 4K page in the first 4GB of RAM?
> 
> But that is only needed when dma_addr_t is 32bit anyway, no?

You said:

  But we can easily work around that by reserving the top 4k of the first
  4GB of IOVA address space in the allocator, no? Then these values are
  never returned as valid DMA handles.

To me, your proposal equates to this in code:

int dma_error(dma_addr_t addr)
{
	return (addr & ~(dma_addr_t)0xfff) == 0xfffff000 ? (s32)addr : 0; 
}

Hence, the size of dma_addr_t would be entirely irrelevant.  This
makes dma_addr_t values in the range of 0xfffff000 to 0xffffffff special,
irrespective of whether dma_addr_t is 32-bit or 64-bit.

If that's not what you meant, then I'm afraid your statement wasn't
worded very well - so please can you re-word to state more precisely
what your proposal is?

> > Rather than inventing magic cookies like this, I'd much rather we
> > sanitised the API so that we have functions that return success or
> > an error code, rather than trying to shoe-horn some kind of magic
> > error codes into dma_addr_t and subtly break systems in the process.
> 
> Sure, but is has the obvious downside that we need to touch every driver
> that uses these functions, and that are probably a lot of drivers.

So we have two options:
- change the interface
- subtly break drivers

In any case, I disagree that we need to touch every driver.  Today,
drivers just do:

	if (dma_mapping_error(dev, addr))

and, because dma_mapping_error() returns a boolean, they only care about
the true/falseness.  If we're going to start returning error codes, then
there's no point just returning error codes unless we have some way for
drivers to use them.  Yes, the simple way would be to make
dma_mapping_error() translate addr to an error code, and that maintains
compatibility with existing drivers.

If, instead, we revamped the DMA API, and had the *new* mapping functions
which returned an error code, then the existing mapping functions can be
implemented as part of compatibility rather trivially:

dma_addr_t dma_map_single(...)
{
	dma_addr_t addr;
	int error;

	error = dma_map_single_error(..., &addr);
	if (error)
		addr = DMA_MAPPING_ERROR;
	return addr;
}

which means that if drivers want access to the error code, they use
dma_map_single_error(), meanwhile existing drivers just get on with life
as it _currently_ is, with the cookie-based all-ones error code - without
introducing any of this potential breakage.

Remember, existing drivers would need modification in _any_ case to make
use of a returned error code, so the argument that we'd need to touch
every driver doesn't really stand up.

-- 
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up

      reply	other threads:[~2018-11-23 13:21 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-22 14:02 remove the ->mapping_error method from dma_map_ops V2 Christoph Hellwig
2018-11-22 14:02 ` [PATCH 01/24] dma-direct: Make DIRECT_MAPPING_ERROR viable for SWIOTLB Christoph Hellwig
2018-11-22 14:02 ` [PATCH 02/24] swiotlb: Skip cache maintenance on map error Christoph Hellwig
2018-11-22 14:02 ` [PATCH 03/24] dma-mapping: provide a generic DMA_MAPPING_ERROR Christoph Hellwig
2018-11-22 14:03 ` [PATCH 04/24] dma-direct: remove the mapping_error dma_map_ops method Christoph Hellwig
2018-11-22 14:03 ` [PATCH 05/24] arm: " Christoph Hellwig
2018-11-22 14:03 ` [PATCH 06/24] powerpc/iommu: " Christoph Hellwig
2018-11-22 14:03 ` [PATCH 07/24] mips/jazz: " Christoph Hellwig
2018-11-22 14:03 ` [PATCH 08/24] s390: " Christoph Hellwig
2018-11-22 14:03 ` [PATCH 09/24] sparc: " Christoph Hellwig
2018-11-22 14:03 ` [PATCH 10/24] parisc/ccio: " Christoph Hellwig
2018-11-22 14:03 ` [PATCH 11/24] parisc/sba_iommu: " Christoph Hellwig
2018-11-22 14:03 ` [PATCH 12/24] arm64: remove the dummy_dma_ops mapping_error method Christoph Hellwig
2018-11-22 14:03 ` [PATCH 13/24] alpha: remove the mapping_error dma_map_ops method Christoph Hellwig
2018-11-22 14:03 ` [PATCH 14/24] ia64/sba_iommu: improve internal map_page users Christoph Hellwig
2018-11-22 14:03 ` [PATCH 15/24] ia64/sba_iommu: remove the mapping_error dma_map_ops method Christoph Hellwig
2018-11-22 14:03 ` [PATCH 16/24] ia64/sn: " Christoph Hellwig
2018-11-22 14:03 ` [PATCH 17/24] x86/amd_gart: " Christoph Hellwig
2018-11-22 14:03 ` [PATCH 18/24] x86/calgary: " Christoph Hellwig
2018-11-22 14:03 ` [PATCH 19/24] iommu: " Christoph Hellwig
2018-11-22 14:03 ` [PATCH 20/24] iommu/intel: small map_page cleanup Christoph Hellwig
2018-11-22 14:03 ` [PATCH 21/24] iommu/vt-d: remove the mapping_error dma_map_ops method Christoph Hellwig
2018-11-22 14:03 ` [PATCH 22/24] iommu/dma-iommu: " Christoph Hellwig
2018-11-22 14:03 ` [PATCH 23/24] xen-swiotlb: " Christoph Hellwig
2018-11-22 14:03 ` [PATCH 24/24] dma-mapping: " Christoph Hellwig
2018-11-22 16:50 ` remove the ->mapping_error method from dma_map_ops V2 Linus Torvalds
2018-11-22 17:07   ` Russell King - ARM Linux
2018-11-22 17:09     ` Linus Torvalds
2018-11-22 17:14       ` Russell King - ARM Linux
2018-11-22 17:52       ` Robin Murphy
2018-11-22 17:55         ` Linus Torvalds
2018-11-22 18:05           ` Russell King - ARM Linux
2018-11-23  6:57             ` Christoph Hellwig
2018-11-23  6:55           ` Christoph Hellwig
2018-11-28  7:41             ` Christoph Hellwig
2018-11-28 16:47               ` Linus Torvalds
2018-11-28 17:45                 ` Russell King - ARM Linux
2018-11-28 18:00                   ` Linus Torvalds
2018-11-28 18:08                     ` Russell King - ARM Linux
2018-11-28 19:23                       ` Russell King - ARM Linux
     [not found]                       ` <CAHk-=whcbiSxSUprsKjVPEdN5-+o8WnTGiKxEV-+HbKNDs=iNA@mail.gmail.com>
2018-11-28 19:31                         ` Russell King - ARM Linux
2018-11-29 16:23                         ` Christoph Hellwig
2018-11-29 17:44                           ` Linus Torvalds
2018-11-29 18:31                             ` Christoph Hellwig
2018-11-29 18:53                               ` Linus Torvalds
2018-11-29 18:55                                 ` Christoph Hellwig
2018-11-28 19:27                     ` David Miller
2018-11-28 19:47                       ` Russell King - ARM Linux
2018-11-28 23:01                         ` Shuah Khan
2018-11-23 10:49         ` Joerg Roedel
2018-11-23 11:01           ` Russell King - ARM Linux
2018-11-23 13:03             ` Joerg Roedel
2018-11-23 13:20               ` Russell King - ARM Linux [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181123132038.GT30658@n2100.armlinux.org.uk \
    --to=linux@armlinux.org.uk \
    --cc=dwmw2@infradead.org \
    --cc=hch@lst.de \
    --cc=iommu@lists.linux-foundation.org \
    --cc=jdmason@kudzu.us \
    --cc=joro@8bytes.org \
    --cc=linux-alpha@vger.kernel.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-ia64@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-parisc@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=robin.murphy@arm.com \
    --cc=torvalds@linux-foundation.org \
    --cc=x86@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).