From: David Miller <davem@davemloft.net>
To: hch@lst.de
Cc: iommu@lists.linux-foundation.org, torvalds@linux-foundation.org,
linux-alpha@vger.kernel.org, linux-arch@vger.kernel.org,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC] remove the ->mapping_error method from dma_map_ops
Date: Fri, 09 Nov 2018 15:12:34 -0800 (PST) [thread overview]
Message-ID: <20181109.151234.2231390463846593374.davem@davemloft.net> (raw)
In-Reply-To: <20181109084632.22848-1-hch@lst.de>
From: Christoph Hellwig <hch@lst.de>
Date: Fri, 9 Nov 2018 09:46:30 +0100
> Error reporting for the dma_map_single and dma_map_page operations is
> currently a mess. Both APIs directly return the dma_addr_t to be used for
> the DMA, with a magic error escape that is specific to the instance and
> checked by another method provided. This has a few downsides:
>
> - the error check is easily forgotten and a __must_check marker doesn't
> help as the value always is consumed anyway
> - the error checking requires another indirect call, which have gotten
> incredibly expensive
> - a lot of code is wasted on implementing these methods
>
> The historical reason for this is that people thought DMA mappings would
> not fail when the API was created, which sounds like a really bad
> assumption in retrospective, and then we tried to cram error handling
> onto it later on.
>
> There basically are two variants: the error code is 0 because the
> implementation will never return 0 as a valid DMA address, or the error
> code is all-F as the implementation won't ever return an address that
> high. The old AMD GART is the only one not falling into these two camps
> as it picks sort of a relative zero relative to where it is mapped.
>
> The 0 return doesn't work for a lot of IOMMUs that start allocating
> bus space from address zero, so we can't consolidate on that, but I think
> we can move everyone to all-Fs, which the patch here does. The reason
> for that is that there is only one way to ever get this address: by
> doing a 1-byte long, 1-byte aligned mapping, but all our mappings
> are not only longer but generally aligned, and the mappings have to
> keep at least the basic alignment. Please try to poke holes into this
> idea as it would simplify our logic a lot, and also allow to change
> at least the not so commonly used yet dma_map_single_attrs and
> dma_map_page_attrs to actually return an error code and further improve
> the error handling flow in the drivers.
I have no problem with patch #1, it looks great.
But patch #2 on the other hand, not so much.
I hate seeing values returned by reference, it adds cost especially
on cpus where all argments and return values fit in registers (we end
up forcing a stack slot and memory references).
And we don't need it here.
DMA addresses are like pointers, and therefore we can return errors and
valid success values in the same dma_addr_t just fine. PTR_ERR() --> DMA_ERR(),
IS_PTR_ERR() --> IS_DMA_ERR, etc.
next prev parent reply other threads:[~2018-11-09 23:12 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-09 8:46 [RFC] remove the ->mapping_error method from dma_map_ops Christoph Hellwig
2018-11-09 8:46 ` [PATCH 1/2] dma-mapping: remove ->mapping_error Christoph Hellwig
2018-11-09 14:41 ` Robin Murphy
2018-11-19 13:52 ` Christoph Hellwig
2018-11-09 8:46 ` [PATCH 2/2] dma-mapping: return errors from dma_map_page and dma_map_attrs Christoph Hellwig
2018-11-09 23:12 ` David Miller [this message]
2018-11-19 13:55 ` [RFC] remove the ->mapping_error method from dma_map_ops Christoph Hellwig
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=20181109.151234.2231390463846593374.davem@davemloft.net \
--to=davem@davemloft.net \
--cc=hch@lst.de \
--cc=iommu@lists.linux-foundation.org \
--cc=linux-alpha@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=x86@kernel.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).