From: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
To: Christoph Hellwig <hch@infradead.org>
Cc: rubini@gnudd.com, linux-kernel@vger.kernel.org,
Marek Szyprowski <m.szyprowski@samsung.com>,
Robin Murphy <robin.murphy@arm.com>,
helgaas@kernel.org, iommu@lists.linux-foundation.org
Subject: Re: [PATCH v2 1/2] dma-direct: check for overflows on 32 bit DMA addresses
Date: Thu, 31 Oct 2019 11:44:50 +0100 [thread overview]
Message-ID: <cc8dd3f3261c75db44ebe991212b2b501b95fe5f.camel@suse.de> (raw)
In-Reply-To: <20191030214140.GB25515@infradead.org>
[-- Attachment #1: Type: text/plain, Size: 1099 bytes --]
On Wed, 2019-10-30 at 14:41 -0700, Christoph Hellwig wrote:
> On Fri, Oct 18, 2019 at 01:00:43PM +0200, Nicolas Saenz Julienne wrote:
> > +#ifndef CONFIG_ARCH_DMA_ADDR_T_64BIT
> > + /* Check if DMA address overflowed */
> > + if (min(addr, addr + size - 1) <
> > + __phys_to_dma(dev, (phys_addr_t)(min_low_pfn << PAGE_SHIFT)))
> > + return false;
> > +#endif
>
> Would be nice to use IS_ENABLED and PFN_PHYS here, and I also think we
> need to use phys_to_dma to take care of the encryption bit. If you then
> also introduce an end variable we can make the whole thing actually look
> nice:
>
> static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t
> size)
> {
> dma_addr_t end = addr + size - 1;
>
> if (!dev->dma_mask)
> return false;
>
> if (!IS_ENABLED(CONFIG_ARCH_DMA_ADDR_T_64BIT) &&
> min(addr, end) < phys_to_dma(dev, PFN_PHYS(min_low_pfn)))
> return false;
>
> return end <= min_not_zero(*dev->dma_mask, dev->bus_dma_mask);
> }
>
> Otherwise this looks sensible to me.
Thanks, noted.
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2019-10-31 10:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-18 11:00 [PATCH v2 0/2] x86: Get rid of custom DMA functions Nicolas Saenz Julienne
2019-10-18 11:00 ` [PATCH v2 1/2] dma-direct: check for overflows on 32 bit DMA addresses Nicolas Saenz Julienne
2019-10-30 21:41 ` Christoph Hellwig
2019-10-31 10:44 ` Nicolas Saenz Julienne [this message]
2019-10-18 11:00 ` [PATCH v2 2/2] x86/PCI: sta2x11: use default DMA address translation Nicolas Saenz Julienne
2019-10-30 21:45 ` Christoph Hellwig
2019-10-31 10:43 ` Nicolas Saenz Julienne
2019-10-31 13:59 ` Alessandro Rubini
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=cc8dd3f3261c75db44ebe991212b2b501b95fe5f.camel@suse.de \
--to=nsaenzjulienne@suse.de \
--cc=hch@infradead.org \
--cc=helgaas@kernel.org \
--cc=iommu@lists.linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=robin.murphy@arm.com \
--cc=rubini@gnudd.com \
/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).