From: Roland Dreier <roland@topspin.com>
To: David Brownell <david-b@pacbell.net>
Cc: linuxppc-embedded@lists.linuxppc.org,
linux-usb-devel@lists.sourceforge.net
Subject: Re: [linux-usb-devel] USB on PPC440GP (cache incoherent)
Date: 07 Jun 2002 20:43:20 -0700 [thread overview]
Message-ID: <528z5qbfl3.fsf@topspin.com> (raw)
In-Reply-To: <3D0171F2.4080602@pacbell.net>
>>>>> "David" == David Brownell <david-b@pacbell.net> writes:
Roland> Note that this might not work perfectly on all
Roland> cache-incoherent processors, since kmalloc could
Roland> potentially allocate a chunk of memory that is smaller
Roland> than the processor's cache line size. However it is safe
Roland> on the 440GP since the 440GP's cache line size is 32
Roland> bytes.
David> Could you elaborate? Documentation/DMA-mapping.txt says
David> that kmalloc returns data suitable for DMA, you are saying
David> otherwise. The DMA mapping calls are supposed to handle
David> cache flushing as needed. If they don't, a lot of code
David> will be breaking ...
I don't know for a fact that there is an architecture where it breaks,
but the idea is that for the 440GP, pci_map_single() with
PCI_DMA_FROMDEVICE invalidates the cache for the memory it is
mapping. At least on the 440GP, you can only invalidate entire cache
lines, which means that if the buffer you are using is smaller than a
cache line then you can get memory corruption. The 440GP does not
flush the cache for PCI_DMA_FROMDEVICE, and even if it did, you could
still have problems if you access the same cache line as the buffer is
in before the DMA completes.
The smallest buffer that kmalloc() will give you is 32 bytes. If
there is an architecture with cache lines bigger than 32 bytes that is
not cache coherent for DMA and only allows entire cache lines to be
invalidated, then using a kmalloc'ed buffer for DMA could cause
problems if it smaller than a cache line.
David> This hub.h change (and its follow-ons) should not be
David> necessary since the struct usb_hub is already allocated
David> using kmalloc() in hub_probe(), and so it's DMA-ready.
David> (Modulo the spec issue noted above for DMA-mapping.txt of
David> course!)
The hub.h change moved the buffer member out of struct usb_hub into
its own kmalloc'ed buffer. I don't know that having buffer be part of
usb_hub was actually causing problems, but I don't think it was safe
for the reasons I described above: buffer was not cache line aligned
and was smaller than a cache line, so mixing DMA access into buffer
and access to other members of struct usb_hub could cause corruption.
Thanks,
Roland
** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/
next prev parent reply other threads:[~2002-06-08 3:43 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-06-07 23:57 USB on PPC440GP (cache incoherent) Roland Dreier
2002-06-08 2:54 ` [linux-usb-devel] " David Brownell
2002-06-08 3:43 ` Roland Dreier [this message]
2002-06-08 5:18 ` David Brownell
2002-06-08 8:47 ` Oliver Neukum
2002-06-08 20:43 ` Roland Dreier
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=528z5qbfl3.fsf@topspin.com \
--to=roland@topspin.com \
--cc=david-b@pacbell.net \
--cc=linux-usb-devel@lists.sourceforge.net \
--cc=linuxppc-embedded@lists.linuxppc.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).