All of lore.kernel.org
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Daniel Mack <daniel@caiaq.de>
Cc: Clemens Ladisch <clemens@ladisch.de>,
	alsa-devel@alsa-project.org, USB list <linux-usb@vger.kernel.org>,
	Takashi Iwai <tiwai@suse.de>, Greg KH <gregkh@suse.de>,
	Kernel development list <linux-kernel@vger.kernel.org>,
	Chris Wright <chrisw@sous-sol.org>,
	iommu@lists.linux-foundation.org,
	Andi Kleen <andi@firstfloor.org>,
	Alan Stern <stern@rowland.harvard.edu>,
	Pedro Ribeiro <pedrib@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	David Woodhouse <dwmw2@infradead.org>
Subject: Re: [alsa-devel] USB transfer_buffer allocations on 64bit systems
Date: Mon, 10 May 2010 10:31:32 -0400	[thread overview]
Message-ID: <20100510143132.GB29517@phenom.dumpdata.com> (raw)
In-Reply-To: <20100507102408.GM30801@buzzloop.caiaq.de>

On Fri, May 07, 2010 at 12:24:08PM +0200, Daniel Mack wrote:
> On Fri, May 07, 2010 at 11:47:37AM +0200, Clemens Ladisch wrote:
> > Daniel Mack wrote:
> > > The problem is again (summarized):
> > > 
> > > On 64bit machines, with 4GB or more, the allocated buffers for USB
> > > transfers might be beyond the 32bit boundary. In this case, the IOMMU
> > > should take care and install DMA bounce buffer to copy over the buffer
> > > before the transfer actually happens. The problem is, however, that this
> > > copy mechanism takes place when the URB with its associated buffer is
> > > submitted, not when the EHCI will actually do the transfer.
> > > 
> > > In the particular case of audio drivers, though, the contents of the
> > > buffers are likely to change after the submission. What we do here
> > > is that we map the audio stream buffers which are used by ALSA to
> > > the output URBs, so they're filled asychronously. Once the buffer is
> > > actually sent out on the bus, it is believed to contain proper audio
> > > date. If it doesn't, that's due to too tight audio timing or other
> > > problems. This breaks once buffers are magically bounced in the
> > > background.
> > 
> > At least the audio class and ua101 drivers don't do this and fill the
> > buffers before they are submitted.
> 
> Gnaa, you're right. I _thought_ my code does it the way I described, but
> what I wrote is how I _wanted_ to do it, not how it's currently done. I
> have a plan to change this in the future.
> 
> So unfortunately, that doesn't explain it either. Sorry for the noise.

Well, you might be on the right track. You see, when you do any DMA API
operation (say pci_map_page), you might end up with _two_ DMA addresses.
One that you get from doing 'virt_to_phys' for your buffer (which might
be above the 4GB mark), and another from the 'pci_map_page' (which can
be the virt_to_phys of your buffer or it can be the DMA address of the
SWIOTLB). If you don't submit the _right_ DMA address or sync after the
DMA transfer (so the SWIOTLB would do its memcpy to your allocated
buffer DMA address), you could end up having the data it the SWIOTLB buffer,
and check data in your kzalloc buffer and notice that nothing is there
(and if it hadn't called pci_dma_sync.. before the check).

But this obviously would not happen if you buffer is allocated with the
GFP_DMA32.

I am not familiar with the USB stack so it might be doing this correctly
already...

WARNING: multiple messages have this Message-ID (diff)
From: Konrad Rzeszutek Wilk <konrad.wilk-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
To: Daniel Mack <daniel-rDUAYElUppE@public.gmane.org>
Cc: Clemens Ladisch <clemens-P6GI/4k7KOmELgA04lAiVw@public.gmane.org>,
	alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw@public.gmane.org,
	USB list <linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Takashi Iwai <tiwai-l3A5Bk7waGM@public.gmane.org>,
	Greg KH <gregkh-l3A5Bk7waGM@public.gmane.org>,
	Kernel development list
	<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Chris Wright <chrisw-69jw2NvuJkxg9hUCZPvPmw@public.gmane.org>,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	Andi Kleen <andi-Vw/NltI1exuRpAAqCnN02g@public.gmane.org>,
	Alan Stern
	<stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org>,
	Pedro Ribeiro <pedrib-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Andrew Morton
	<akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>,
	David Woodhouse <dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
Subject: Re: [alsa-devel] USB transfer_buffer allocations on 64bit systems
Date: Mon, 10 May 2010 10:31:32 -0400	[thread overview]
Message-ID: <20100510143132.GB29517@phenom.dumpdata.com> (raw)
In-Reply-To: <20100507102408.GM30801-ahpEBR4enfnCULTFXS99ULNAH6kLmebB@public.gmane.org>

On Fri, May 07, 2010 at 12:24:08PM +0200, Daniel Mack wrote:
> On Fri, May 07, 2010 at 11:47:37AM +0200, Clemens Ladisch wrote:
> > Daniel Mack wrote:
> > > The problem is again (summarized):
> > > 
> > > On 64bit machines, with 4GB or more, the allocated buffers for USB
> > > transfers might be beyond the 32bit boundary. In this case, the IOMMU
> > > should take care and install DMA bounce buffer to copy over the buffer
> > > before the transfer actually happens. The problem is, however, that this
> > > copy mechanism takes place when the URB with its associated buffer is
> > > submitted, not when the EHCI will actually do the transfer.
> > > 
> > > In the particular case of audio drivers, though, the contents of the
> > > buffers are likely to change after the submission. What we do here
> > > is that we map the audio stream buffers which are used by ALSA to
> > > the output URBs, so they're filled asychronously. Once the buffer is
> > > actually sent out on the bus, it is believed to contain proper audio
> > > date. If it doesn't, that's due to too tight audio timing or other
> > > problems. This breaks once buffers are magically bounced in the
> > > background.
> > 
> > At least the audio class and ua101 drivers don't do this and fill the
> > buffers before they are submitted.
> 
> Gnaa, you're right. I _thought_ my code does it the way I described, but
> what I wrote is how I _wanted_ to do it, not how it's currently done. I
> have a plan to change this in the future.
> 
> So unfortunately, that doesn't explain it either. Sorry for the noise.

Well, you might be on the right track. You see, when you do any DMA API
operation (say pci_map_page), you might end up with _two_ DMA addresses.
One that you get from doing 'virt_to_phys' for your buffer (which might
be above the 4GB mark), and another from the 'pci_map_page' (which can
be the virt_to_phys of your buffer or it can be the DMA address of the
SWIOTLB). If you don't submit the _right_ DMA address or sync after the
DMA transfer (so the SWIOTLB would do its memcpy to your allocated
buffer DMA address), you could end up having the data it the SWIOTLB buffer,
and check data in your kzalloc buffer and notice that nothing is there
(and if it hadn't called pci_dma_sync.. before the check).

But this obviously would not happen if you buffer is allocated with the
GFP_DMA32.

I am not familiar with the USB stack so it might be doing this correctly
already...
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2010-05-10 14:34 UTC|newest]

Thread overview: 221+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-07  9:06 USB transfer_buffer allocations on 64bit systems Daniel Mack
2010-04-07  9:06 ` Daniel Mack
     [not found] ` <p2g581ef6d61004070220z1153d40ez955b356e01220848@mail.gmail.com>
2010-04-07  9:26   ` USB HID gadget driver (was: Re: USB transfer_buffer allocations on 64bit systems) Daniel Mack
2010-04-07  9:26     ` Daniel Mack
2010-04-07 14:59 ` USB transfer_buffer allocations on 64bit systems Alan Stern
2010-04-07 14:59   ` Alan Stern
2010-04-07 15:11   ` Daniel Mack
2010-04-07 15:11     ` Daniel Mack
2010-04-07 15:31     ` Greg KH
2010-04-07 15:31       ` Greg KH
2010-04-07 15:35       ` Daniel Mack
2010-04-07 15:35         ` Daniel Mack
2010-04-07 15:51         ` Greg KH
2010-04-07 15:51           ` Greg KH
2010-04-07 16:04           ` Alan Stern
2010-04-07 16:04             ` Alan Stern
2010-04-08  6:09         ` Oliver Neukum
2010-04-08 11:07           ` Daniel Mack
2010-04-08 11:07             ` Daniel Mack
2010-04-07 15:55       ` Alan Stern
2010-04-07 15:55         ` Alan Stern
2010-04-07 16:16         ` Daniel Mack
2010-04-07 16:16           ` Daniel Mack
2010-04-07 16:47           ` Alan Stern
2010-04-07 16:47             ` Alan Stern
2010-04-07 17:55           ` Takashi Iwai
2010-04-07 17:55             ` Takashi Iwai
2010-04-07 17:59             ` Daniel Mack
2010-04-07 17:59               ` Daniel Mack
2010-04-07 18:06               ` Takashi Iwai
2010-04-07 18:06                 ` Takashi Iwai
2010-04-07 19:13             ` Alan Stern
2010-04-07 19:13               ` Alan Stern
2010-04-07 23:59               ` Robert Hancock
2010-04-07 23:59                 ` Robert Hancock
2010-04-08  0:33               ` Greg KH
2010-04-08  0:33                 ` Greg KH
2010-04-09  0:01                 ` Robert Hancock
2010-04-09 16:50                   ` Sarah Sharp
2010-04-09 16:50                     ` Sarah Sharp
2010-04-09 23:38                     ` Robert Hancock
2010-04-09 23:38                       ` Robert Hancock
2010-04-10  8:34                       ` [alsa-devel] " Daniel Mack
2010-04-10  8:34                         ` Daniel Mack
2010-04-10 17:02                         ` [alsa-devel] " Robert Hancock
2010-04-12 18:56                           ` Sarah Sharp
2010-04-12 20:39                             ` Robert Hancock
2010-04-12 20:39                               ` Robert Hancock
2010-04-12 20:58                               ` Sarah Sharp
2010-04-12 11:17               ` [PATCH] USB: rename usb_buffer_alloc() and usb_buffer_free() Daniel Mack
2010-04-12 11:17                 ` Daniel Mack
2010-04-13 18:16                 ` Daniel Mack
2010-04-13 18:16                   ` Daniel Mack
2010-04-13 19:27                   ` Alan Stern
2010-04-13 19:27                     ` Alan Stern
2010-04-13 20:26                     ` Greg KH
2010-04-13 21:47                       ` Daniel Mack
2010-04-13 21:47                         ` Daniel Mack
2010-04-07 17:52         ` USB transfer_buffer allocations on 64bit systems Takashi Iwai
2010-04-07 17:52           ` Takashi Iwai
2010-04-07 15:46     ` Alan Stern
2010-04-07 15:46       ` Alan Stern
2010-04-08  6:12       ` Oliver Neukum
2010-04-08 16:59         ` Alan Stern
2010-04-08 16:59           ` Alan Stern
2010-04-08 21:24           ` Oliver Neukum
2010-04-08 22:20             ` Alan Stern
2010-04-08 22:20               ` Alan Stern
2010-04-09  6:04               ` Oliver Neukum
2010-04-09 14:41                 ` Alan Stern
2010-04-09 14:41                   ` Alan Stern
2010-04-09 14:50                   ` Oliver Neukum
2010-04-09 14:50                     ` Oliver Neukum
2010-04-09 15:15                     ` Alan Stern
2010-04-09 15:15                       ` Alan Stern
2010-04-09 20:51                       ` Oliver Neukum
2010-04-09 20:51                         ` Oliver Neukum
2010-04-09 21:21                         ` Alan Stern
2010-04-09 21:21                           ` Alan Stern
2010-04-07 16:54   ` Oliver Neukum
2010-04-07 16:54     ` Oliver Neukum
2010-04-07 17:00     ` Daniel Mack
2010-04-07 17:00       ` Daniel Mack
2010-04-07 23:55   ` Robert Hancock
2010-04-07 23:55     ` Robert Hancock
2010-04-08  2:10     ` Alan Stern
2010-04-08  2:10       ` Alan Stern
2010-04-08  7:30       ` Daniel Mack
2010-04-08  7:30         ` Daniel Mack
2010-04-08 16:57         ` Alan Stern
2010-04-08 16:57           ` Alan Stern
2010-04-08 17:17           ` Pedro Ribeiro
2010-04-08 18:17             ` Alan Stern
2010-04-08 23:13           ` Pedro Ribeiro
2010-04-08 23:13             ` Pedro Ribeiro
2010-04-09 16:01             ` Alan Stern
2010-04-09 16:01               ` Alan Stern
2010-04-09 18:09               ` Daniel Mack
2010-04-09 18:19                 ` Pedro Ribeiro
2010-04-09 18:19                   ` Pedro Ribeiro
2010-04-09 19:34                   ` Alan Stern
2010-04-09 19:34                     ` Alan Stern
2010-04-09 20:14                     ` Daniel Mack
2010-04-09 20:14                       ` Daniel Mack
2010-04-09 20:25                     ` [LKML] " Konrad Rzeszutek Wilk
2010-04-09 20:25                       ` Konrad Rzeszutek Wilk
2010-04-09 21:23                       ` Alan Stern
2010-04-09 21:23                         ` Alan Stern
2010-04-09 22:11                         ` Robert Hancock
2010-04-12 10:48                           ` Daniel Mack
2010-04-12 10:48                             ` Daniel Mack
2010-04-12 12:06                             ` Pedro Ribeiro
2010-04-10 12:49                   ` Daniel Mack
2010-04-10 12:49                     ` Daniel Mack
2010-04-10 13:21                     ` Pedro Ribeiro
2010-04-10 13:21                       ` Pedro Ribeiro
2010-04-12  8:59   ` Andi Kleen
2010-04-12  8:59     ` Andi Kleen
2010-04-12 11:14     ` Daniel Mack
2010-04-12 11:14       ` Daniel Mack
2010-04-12 11:53       ` Andi Kleen
2010-04-12 11:53         ` Andi Kleen
2010-04-12 12:11         ` Pedro Ribeiro
2010-04-12 12:12           ` Andi Kleen
2010-04-12 12:12             ` Andi Kleen
2010-04-12 12:32             ` Daniel Mack
2010-04-12 12:47               ` Andi Kleen
2010-04-12 12:54                 ` Daniel Mack
2010-04-12 12:54                   ` Daniel Mack
2010-04-12 15:43                   ` Andi Kleen
2010-04-12 16:17                     ` Alan Stern
2010-04-12 16:17                       ` Alan Stern
2010-04-12 16:29                       ` Andi Kleen
2010-04-12 16:57                         ` Alan Stern
2010-04-12 16:57                           ` Alan Stern
2010-04-12 17:15                           ` Daniel Mack
2010-04-12 17:15                             ` Daniel Mack
2010-04-12 17:22                             ` Andi Kleen
2010-04-12 17:22                               ` Andi Kleen
2010-04-12 17:56                               ` Daniel Mack
2010-04-12 17:56                                 ` Daniel Mack
2010-04-12 17:52                             ` [LKML] " Konrad Rzeszutek Wilk
2010-04-12 17:52                               ` Konrad Rzeszutek Wilk
2010-04-13 18:22                           ` Daniel Mack
2010-04-13 18:22                             ` Daniel Mack
2010-04-13 23:46                             ` Pedro Ribeiro
2010-04-13 23:46                               ` Pedro Ribeiro
2010-04-14 10:09                               ` Daniel Mack
2010-04-14 10:09                                 ` Daniel Mack
2010-04-14 10:47                                 ` Pedro Ribeiro
2010-04-14 11:02                                   ` Pedro Ribeiro
2010-04-14 13:18                                   ` [LKML] " Konrad Rzeszutek Wilk
2010-04-14 14:08                                   ` Alan Stern
2010-04-14 14:08                                     ` Alan Stern
2010-04-14 16:36                                     ` Daniel Mack
2010-04-14 16:36                                       ` Daniel Mack
2010-04-14 17:21                                       ` Pedro Ribeiro
2010-04-14 17:21                                         ` Pedro Ribeiro
2010-04-14 18:23                                         ` Alan Stern
2010-04-14 18:27                                           ` Pedro Ribeiro
2010-04-14 18:53                                             ` Alan Stern
2010-04-15  7:35                                         ` Daniel Mack
2010-04-15  7:35                                           ` Daniel Mack
2010-04-14 18:15                                       ` Alan Stern
2010-04-14 18:36                                         ` David Woodhouse
2010-04-14 21:12                                           ` Pedro Ribeiro
2010-04-14 22:25                                             ` Chris Wright
2010-04-14 22:56                                               ` Pedro Ribeiro
2010-04-14 23:37                                                 ` Chris Wright
2010-04-15  1:20                                                   ` Pedro Ribeiro
2010-04-15 15:20                                                     ` Alan Stern
2010-04-20  0:16                                                       ` Pedro Ribeiro
2010-05-07  7:48                                                         ` Daniel Mack
2010-05-07  7:48                                                           ` Daniel Mack
2010-05-07  9:47                                                           ` [alsa-devel] " Clemens Ladisch
2010-05-07  9:47                                                             ` Clemens Ladisch
2010-05-07 10:24                                                             ` [alsa-devel] " Daniel Mack
2010-05-07 10:24                                                               ` Daniel Mack
2010-05-07 14:51                                                               ` [alsa-devel] " Alan Stern
2010-05-07 14:51                                                                 ` Alan Stern
2010-05-10  2:50                                                                 ` FUJITA Tomonori
2010-05-10  9:21                                                                   ` David Woodhouse
2010-05-10  9:21                                                                     ` David Woodhouse
2010-05-10 14:58                                                                     ` [alsa-devel] " Alan Stern
2010-05-10 14:58                                                                       ` Alan Stern
2010-05-11  1:06                                                                       ` FUJITA Tomonori
2010-05-11  1:06                                                                         ` FUJITA Tomonori
2010-05-11 14:00                                                                         ` Alan Stern
2010-05-11 14:00                                                                           ` Alan Stern
2010-05-11 14:22                                                                           ` FUJITA Tomonori
2010-05-11 14:24                                                                           ` Konrad Rzeszutek Wilk
2010-05-11 14:38                                                                             ` FUJITA Tomonori
2010-05-11 15:04                                                                               ` Alan Stern
2010-05-11 15:04                                                                                 ` Alan Stern
2010-05-11 15:34                                                                                 ` FUJITA Tomonori
2010-05-11 16:06                                                                                   ` Alan Stern
2010-05-11 16:09                                                                                     ` Daniel Mack
2010-05-11 16:48                                                                                     ` Pedro Ribeiro
2010-05-11 17:10                                                                                       ` Daniel Mack
2010-05-11 17:32                                                                                         ` Pedro Ribeiro
2010-05-11 17:38                                                                                           ` Daniel Mack
2010-05-12 23:50                                                                                             ` Pedro Ribeiro
2010-05-13  9:36                                                                                               ` Daniel Mack
2010-05-14  0:17                                                                                                 ` Pedro Ribeiro
2010-05-11 14:57                                                                             ` Alan Stern
2010-05-11 15:05                                                                               ` Daniel Mack
2010-05-10 14:31                                                               ` Konrad Rzeszutek Wilk [this message]
2010-05-10 14:31                                                                 ` Konrad Rzeszutek Wilk
2010-05-07 11:42                                                             ` Oliver Neukum
2010-05-07 11:42                                                               ` Oliver Neukum
2010-05-07 11:47                                                               ` Oliver Neukum
2010-05-07 11:47                                                                 ` Oliver Neukum
2010-05-07 11:58                                                                 ` Daniel Mack
2010-05-07 11:58                                                                   ` Daniel Mack
2010-05-07 14:45                                                                   ` [alsa-devel] " Alan Stern
2010-05-07 14:45                                                                     ` Alan Stern
2010-04-14 18:38                                         ` Chris Wright
2010-04-14 20:29                                           ` Alan Stern
2010-04-14 21:01                                             ` Konrad Rzeszutek Wilk
2010-04-14 21:12                                               ` Pedro Ribeiro
2010-04-15  1:50                                                 ` Alan Stern

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=20100510143132.GB29517@phenom.dumpdata.com \
    --to=konrad.wilk@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=andi@firstfloor.org \
    --cc=chrisw@sous-sol.org \
    --cc=clemens@ladisch.de \
    --cc=daniel@caiaq.de \
    --cc=dwmw2@infradead.org \
    --cc=gregkh@suse.de \
    --cc=iommu@lists.linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=pedrib@gmail.com \
    --cc=stern@rowland.harvard.edu \
    --cc=tiwai@suse.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.