linux-parisc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Russell King - ARM Linux <linux@armlinux.org.uk>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-arch@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, linux-alpha@vger.kernel.org,
	xen-devel@lists.xenproject.org, robin.murphy@arm.com,
	Christoph Hellwig <hch@lst.de>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: remove the ->mapping_error method from dma_map_ops V2
Date: Wed, 28 Nov 2018 19:23:02 +0000	[thread overview]
Message-ID: <20181128192301.GN30658@n2100.armlinux.org.uk> (raw)
In-Reply-To: <20181128180841.GM30658@n2100.armlinux.org.uk>

On Wed, Nov 28, 2018 at 06:08:41PM +0000, Russell King - ARM Linux wrote:
> On Wed, Nov 28, 2018 at 10:00:06AM -0800, Linus Torvalds wrote:
> > On Wed, Nov 28, 2018 at 9:45 AM Russell King - ARM Linux
> > <linux@armlinux.org.uk> wrote:
> > >
> > > > I don't think this is a huge deal, but ERR_PTR() has been hugely
> > > > successful elsewhere. And I'm not hugely convinced about all these
> > > > "any address can be valid" arguments. How the hell do you generate a
> > > > random dma address in the last page that isn't even page-aligned?
> > >
> > > kmalloc() a 64-byte buffer, dma_map_single() that buffer.
> > 
> > No.
> > 
> > You already cannot do that kmalloc(), exactly because of ERR_PTR().
> 
> I'm very sorry, but I think you are confused.
> 
> kmalloc() returns a _virtual_ address, which quite rightly must not be
> in the top 4K of 4GB, exactly due to ERR_PTR().  That is fine.
> 
> However, that is a completely different kettle of fish from a physical
> or DMA address - neither of which are virtual addresses.
> 
> Now, say we have 1GB of RAM which starts at 0xc0000000 _physical_.
> The kernel is configured with a 2GB/2GB user/kernel split, which means
> all 1GB of RAM is mapped as lowmem from 0x80000000 to 0xbfffffff
> inclusive.  This means kmalloc() can return any address in that range.
> 
> ERR_PTR() will work correctly on any of those pointers, meaning that
> none of them will be seen as an error.
> 
> However, map any virtual address in the range of 0xbffff000 to
> 0xbfffffff into DMA space, and the resulting DMA address could well
> be in the range of 0xfffff000 to 0xffffffff - precisely the range
> of addresses that you are advocating to be used for error codes.
> 
> > The whole argument of "every possible piece of memory is DMA'able" is
> > just wrong.
> 
> I'm very sorry, but I do not buy your argument - you are conflating
> virtual addresses which ERR_PTR() deals in with physical and bus
> addresses - and if you persist down this route, you will cause
> regressions.

Here's another case:

i.MX6 with 4GB of RAM.  Devices are mapped to 0-0x0fffffff physical,
RAM is mapped to 0x10000000-0xffffffff physical.  The last 256MB of
RAM is not accessible as this is a 32-bit device.  DMA addresses are
the same as physical addresses.

While the final physical page will be highmem in a normal kernel,
and thus will not be available for kmalloc(), that doesn't mean it
can't happen.  A crashdump kernel loaded high in physical memory
(eg, last 512MB and given the last 512MB to play around in) would
have the top 512MB as lowmem, and therefore available for kmalloc().

If a page is available in lowmem, it's available for kmalloc(), and
we can't say that we will never allocate memory from such a page for
DMA - if we do and we're using an IS_ERR_VALUE() scheme, it _will_
break if that happens as memory will end up being mapped by the DMA
API but dma_mapping_error() will see it as a failure.

It won't be an obvious breakage, because it depends on the right
conditions happening - a kmalloc() from the top page of physical
RAM and that being passed to dma_map_single().  IOW, it's not something
that a quick boot test would find, it's something that is likely to
cause failures after a system has been running for a period of time.

There are other situations where there are possibilities - such as:

	dma_map_page(dev, page, offset, size, direction)

If 'page' is a highmem page which happens to be the top page in the
4GB space, and offset is non-zero, and there's a 1:1 mapping between
physical address and DMA address, the returned value will be
0xfffff000 + offset - within the "last 4095 values are errors"
range.

Networking uses this for fragments - the packet fragment list is
a list of pages, offsets and sizes - we have sendpage() that may
end up finding that last page, and TCP-sized packets may be
generated from it which would certianly result in non-zero offsets
being passed to dma_map_page().

So, whatever way _I_ look at it, I find your proposal to be unsafe
and potentially regression causing, and I *completely* and strongly
oppose it in its current form.

-- 
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-28 19:23 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 [this message]
     [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

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=20181128192301.GN30658@n2100.armlinux.org.uk \
    --to=linux@armlinux.org.uk \
    --cc=dwmw2@infradead.org \
    --cc=hch@lst.de \
    --cc=iommu@lists.linux-foundation.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=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).