linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Logan Gunthorpe <logang@deltatee.com>,
	Kit Chow <kchow@gigaio.com>, Dave Jiang <dave.jiang@intel.com>,
	Eric Pilmore <epilmore@gigaio.com>,
	Bjorn Helgaas <helgaas@kernel.org>
Cc: "linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
	Alex Williamson <alex.williamson@redhat.com>,
	David Woodhouse <dwmw2@infradead.org>,
	"iommu@lists.linux-foundation.org"
	<iommu@lists.linux-foundation.org>
Subject: Re: IOAT DMA w/IOMMU
Date: Tue, 14 Aug 2018 15:03:42 +0100	[thread overview]
Message-ID: <c6e860a2-a56f-d30a-a994-9e1f1da401c0@arm.com> (raw)
In-Reply-To: <712ecb24-8919-05a5-f64c-6a1faa971edc@deltatee.com>

On 14/08/18 00:50, Logan Gunthorpe wrote:
> On 13/08/18 05:48 PM, Kit Chow wrote:
>> On 08/13/2018 04:39 PM, Logan Gunthorpe wrote:
>>>
>>> On 13/08/18 05:30 PM, Kit Chow wrote:
>>>> In arch/x86/include/asm/page.h, there is the following comment in
>>>> regards to validating the virtual address.
>>>>
>>>> /*
>>>>    * virt_to_page(kaddr) returns a valid pointer if and only if
>>>>    * virt_addr_valid(kaddr) returns true.
>>>>    */
>>>> #define virt_to_page(kaddr)     pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
>>>>
>>>> So it looks like the validation by virt_addr_valid was somehow dropped
>>>> from the virt_to_page code path. Does anyone have any ideas what
>>>> happended to it?
>>> I don't think it was ever validated (though I haven't been around long
>>> enough to say for certain). What the comment is saying is that you
>>> shouldn't rely on virt_to_page() unless you know virt_addr_valid() is
>>> true (which in most cases you can without the extra check). virt_to_page
>>> is meant to be really fast so adding an extra validation would probably
>>> be a significant performance regression for the entire kernel.
>>>
>>> The fact that this can happen through dma_map_single() is non-ideal at
>>> best. It assumes the caller is mapping regular memory and doesn't check
>>> this at all. It may make sense to fix that but I think people expect
>>> dma_map_single() to be as fast as possible as well...

dma_map_single() is already documented as only supporting lowmem (for 
which virt_to_page() can be assumed to be valid). You might get away 
with feeding it bogus addresses on x86, but on non-coherent 
architectures which convert the page back to a virtual address to 
perform cache maintenance you can expect that to crash and burn rapidly.

There may be some minimal-overhead sanity checking of fundamentals, but 
in general it's not really the DMA API's job to police its callers 
exhaustively; consider that the mm layer doesn't go out of its way to 
stop you from doing things like "kfree(kfree);" either.

>>>
>> Perhaps include the validation with some debug turned on?
> 
> The problem is how often do you develop code with any of the debug
> config options turned on?
> 
> There's already a couple of BUG_ONs in dma_map_single so maybe another
> one with virt_addr_valid wouldn't be so bad.

Note that virt_addr_valid() may be pretty heavyweight in itself. For 
example the arm64 implementation involves memblock_search(); that really 
isn't viable in a DMA mapping fastpath.

Robin.

  parent reply	other threads:[~2018-08-14 14:03 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-09 18:14 IOAT DMA w/IOMMU Eric Pilmore
2018-08-09 18:43 ` Bjorn Helgaas
2018-08-09 18:51   ` Eric Pilmore
2018-08-09 19:35     ` Logan Gunthorpe
2018-08-09 19:47       ` Kit Chow
2018-08-09 20:11         ` Logan Gunthorpe
2018-08-09 20:57           ` Kit Chow
2018-08-09 21:11             ` Logan Gunthorpe
2018-08-09 21:47               ` Kit Chow
2018-08-09 22:40                 ` Jiang, Dave
2018-08-09 22:48                   ` Kit Chow
2018-08-09 22:50                     ` Logan Gunthorpe
2018-08-09 23:00                       ` Kit Chow
2018-08-10 16:02                         ` Kit Chow
2018-08-10 16:23                           ` Kit Chow
2018-08-10 16:24                             ` Logan Gunthorpe
2018-08-10 16:24                           ` Logan Gunthorpe
2018-08-10 16:31                             ` Dave Jiang
2018-08-10 16:33                               ` Logan Gunthorpe
2018-08-10 17:01                                 ` Dave Jiang
2018-08-10 17:15                                   ` Logan Gunthorpe
2018-08-10 17:46                                     ` Dave Jiang
2018-08-11  0:53                                       ` Kit Chow
2018-08-11  2:10                                         ` Logan Gunthorpe
2018-08-13 14:23                                           ` Kit Chow
2018-08-13 14:59                                             ` Robin Murphy
2018-08-13 15:21                                               ` Kit Chow
2018-08-13 23:30                                                 ` Kit Chow
2018-08-13 23:39                                                   ` Logan Gunthorpe
2018-08-13 23:48                                                     ` Kit Chow
2018-08-13 23:50                                                       ` Logan Gunthorpe
2018-08-14 13:47                                                         ` Kit Chow
2018-08-14 14:03                                                         ` Robin Murphy [this message]
2018-08-13 23:36                                                 ` Kit Chow
2018-08-09 21:31       ` Eric Pilmore
2018-08-09 21:36         ` Logan Gunthorpe
2018-08-16 17:16           ` Kit Chow
2018-08-16 17:21             ` Logan Gunthorpe
2018-08-16 18:53               ` Kit Chow
2018-08-16 18:56                 ` Logan Gunthorpe
2018-08-21 23:18                   ` Eric Pilmore
2018-08-21 23:20                     ` Logan Gunthorpe
2018-08-21 23:28                       ` Eric Pilmore
2018-08-21 23:35                         ` Logan Gunthorpe
2018-08-21 23:45                           ` Eric Pilmore
2018-08-21 23:53                             ` Logan Gunthorpe
2018-08-21 23:59                               ` Eric Pilmore
2018-08-21 23:30                       ` Eric Pilmore

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=c6e860a2-a56f-d30a-a994-9e1f1da401c0@arm.com \
    --to=robin.murphy@arm.com \
    --cc=alex.williamson@redhat.com \
    --cc=dave.jiang@intel.com \
    --cc=dwmw2@infradead.org \
    --cc=epilmore@gigaio.com \
    --cc=helgaas@kernel.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=kchow@gigaio.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=logang@deltatee.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).