From: Oliver Neukum <oneukum@suse.com>
To: Russell King - ARM Linux admin <linux@armlinux.org.uk>,
Greg KH <gregkh@linuxfoundation.org>
Cc: yvahkhfo.1df7f8c2@hashmail.org, linux-usb@vger.kernel.org,
security@kernel.org, linux-arm-kernel@lists.infradead.org
Subject: Re: usb zero copy dma handling
Date: Thu, 08 Aug 2019 12:02:04 +0200 [thread overview]
Message-ID: <1565258524.3377.5.camel@suse.com> (raw)
In-Reply-To: <20190808095951.GD5193@shell.armlinux.org.uk>
Am Donnerstag, den 08.08.2019, 10:59 +0100 schrieb Russell King - ARM
Linux admin:
> On Thu, Aug 08, 2019 at 10:58:11AM +0200, Greg KH wrote:
> > But the main issue here is what exactly is this "fixing"? What is wrong
> > with the existing code that non-x86 systems have such a problem with?
> > Shouldn't all of these dma issues be handled by the platform with the
> > remap_pfn_range() call itself?
>
> remap_pfn_range() takes a PFN. virt_to_phys() converts a kernel *direct
> mapped* virtual address to a physical address. That much is fine.
>
> The question is - what is usbm->mem? If that is anything other than an
> address returned by kmalloc() or from the normal page allocator, then
> virt_to_phys() will return garbage.
>
> In other words, if it comes from dma_alloc_coherent(), vmalloc() or
> ioremap(), using virt_to_phys() on it results in garbage.
It comes from usb_alloc_coherent() -> hcd_buffer_alloc() ->
hcd_buffer_alloc()
That function is a bit complicated. so I rather quote than explain:
if (hcd->localmem_pool)
return gen_pool_dma_alloc(hcd->localmem_pool, size, dma)
/* some USB hosts just use PIO */
if (!IS_ENABLED(CONFIG_HAS_DMA) ||
!is_device_dma_capable(bus->sysdev)) {
*dma = ~(dma_addr_t) 0;
return kmalloc(size, mem_flags);
}
for (i = 0; i < HCD_BUFFER_POOLS; i++) {
if (size <= pool_max[i])
return dma_pool_alloc(hcd->pool[i], mem_flags, dma);
}
return dma_alloc_coherent(hcd->self.sysdev, size, dma, mem_flags);
Regards
Oliver
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2019-08-08 10:17 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-08 8:46 usb zero copy dma handling yvahkhfo.1df7f8c2
2019-08-08 8:58 ` Greg KH
2019-08-08 9:46 ` Robin Murphy
2019-08-08 10:07 ` Greg KH
2019-08-08 10:43 ` Robin Murphy
2019-08-08 13:05 ` Greg KH
2019-08-08 9:59 ` Russell King - ARM Linux admin
2019-08-08 10:02 ` Oliver Neukum [this message]
2019-08-08 16:10 ` Christoph Hellwig
2019-08-08 16:12 ` Christoph Hellwig
2019-08-08 16:57 ` Russell King - ARM Linux admin
-- strict thread matches above, loose matches on Subject: below --
2019-07-27 13:57 yvahknez.7f7d2ff0
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=1565258524.3377.5.camel@suse.com \
--to=oneukum@suse.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-usb@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=security@kernel.org \
--cc=yvahkhfo.1df7f8c2@hashmail.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).