linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
To: Christoph Hellwig <hch@infradead.org>
Cc: mbrugger@suse.com, linux-kernel@vger.kernel.org,
	Russell King <linux@armlinux.org.uk>,
	iommu@lists.linux-foundation.org, f.fainelli@gmail.com,
	bcm-kernel-feedback-list@broadcom.com,
	linux-rpi-kernel@lists.infradead.org,
	Robin Murphy <robin.murphy@arm.com>,
	linux-arm-kernel@lists.infradead.org, wahrenst@gmx.net
Subject: Re: [PATCH RFC 4/5] dma/direct: check for overflows in ARM's dma_capable()
Date: Tue, 15 Oct 2019 15:07:08 +0200	[thread overview]
Message-ID: <d57feba7e3956136a5d77cebbbf2807c2950d6df.camel@suse.de> (raw)
In-Reply-To: <20191015102346.GA9071@infradead.org>

[-- Attachment #1: Type: text/plain, Size: 2108 bytes --]

On Tue, 2019-10-15 at 03:23 -0700, Christoph Hellwig wrote:
> On Mon, Oct 14, 2019 at 08:31:06PM +0200, Nicolas Saenz Julienne wrote:
> > The Raspberry Pi 4 has a 1GB ZONE_DMA area starting at address
> > 0x00000000 and a mapping between physical and DMA memory offset by
> > 0xc0000000.  It transpires that, on non LPAE systems, any attempt to
> > translate physical addresses outside of ZONE_DMA will result in an
> > overflow. The resulting DMA addresses will not be detected by arm's
> > dma_capable() as they still fit in the device's DMA mask.
> > 
> > Fix this by failing to validate a DMA address smaller than the lowest
> > possible DMA address.
> 
> I think the main problem here is that arm doesn't respect the
> bus_dma_mask.  If you replace the arm version of dma_capable with
> the generic one, does that fi the issue for you as well?

Yeah, that was my fist thought too, but it doesn't help.

So with RPi4's DMA mapping:

soc {
	dma-ranges = <0xc0000000  0x0 0x00000000  0x3c000000>;
	[...]
};

You'll get a 32bit bus dma map (log2i(0xc0000000 + 0x3c000000) + 1 = 32).

Trouble is, taking into account arm's multi_v7_defconfig uses 32bit addresses,
most phys_to_dma() translations are likely to overflow. For example phys
0x60000000 will be translated to DMA 0x20000000, which is no good.

No mask is going to catch this, and both dma_capable() implementations will
fail.

> We need to untangle the various macros arm uses for the direct mapping
> and eventually we should be able to use the linux/dma-direct.h helpers
> directly.  Here is a branch with some simple preps I had.  Freshly
> rebased, not actually tested:
> 
> 
http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/arm-generic-dma-preps

Noted, looks good to me.

Actually, an alternative to this patch would be to kill all custom
dma_capable() implementations, which are mostly redundant, and add these extra
checks conditional to the DMA address size in the generic version. I'll try to
respin this if I manage to understand what's going on with x86/sta211-fixup.c.


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2019-10-15 13:07 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-14 18:31 [PATCH RFC 0/5] ARM: Raspberry Pi 4 DMA support Nicolas Saenz Julienne
2019-10-14 18:31 ` [PATCH RFC 1/5] dma/direct: turn ARCH_ZONE_DMA_BITS into a variable Nicolas Saenz Julienne
2019-10-30 21:49   ` Christoph Hellwig
2019-10-31 10:30     ` Nicolas Saenz Julienne
2019-10-31 13:38       ` Christoph Hellwig
2019-10-31 17:26         ` Nicolas Saenz Julienne
2019-10-14 18:31 ` [PATCH RFC 2/5] ARM: introduce arm_dma_direct Nicolas Saenz Julienne
2019-10-15 10:04   ` Christoph Hellwig
2019-10-14 18:31 ` [PATCH RFC 3/5] ARM: let machines select dma-direct over arch's DMA implementation Nicolas Saenz Julienne
2019-10-14 18:31 ` [PATCH RFC 4/5] dma/direct: check for overflows in ARM's dma_capable() Nicolas Saenz Julienne
2019-10-15 10:23   ` Christoph Hellwig
2019-10-15 13:07     ` Nicolas Saenz Julienne [this message]
2019-10-14 18:31 ` [PATCH RFC 5/5] ARM: bcm2711: use dma-direct Nicolas Saenz Julienne
2019-10-14 20:59 ` [PATCH RFC 0/5] ARM: Raspberry Pi 4 DMA support Catalin Marinas
2019-10-15  7:48   ` Nicolas Saenz Julienne
2019-10-15 17:46     ` Catalin Marinas

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=d57feba7e3956136a5d77cebbbf2807c2950d6df.camel@suse.de \
    --to=nsaenzjulienne@suse.de \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=f.fainelli@gmail.com \
    --cc=hch@infradead.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=linux@armlinux.org.uk \
    --cc=mbrugger@suse.com \
    --cc=robin.murphy@arm.com \
    --cc=wahrenst@gmx.net \
    /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).