linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: David Brownell <david-b@pacbell.net>
To: Roland Dreier <roland@topspin.com>
Cc: linuxppc-embedded@lists.linuxppc.org,
	linux-usb-devel@lists.sourceforge.net
Subject: Re: [linux-usb-devel] USB on PPC440GP (cache incoherent)
Date: Fri, 07 Jun 2002 22:18:48 -0700	[thread overview]
Message-ID: <3D0193B8.9030500@pacbell.net> (raw)
In-Reply-To: 528z5qbfl3.fsf@topspin.com


>     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.

Or more specifically, cache lines can't be shared between DMA and non-DMA
purposes while a DMA mapping is active ... regardless of the size of the
buffer, its start and end could potentially have such cacheline problems.
That makes good sense to me, and I suspect it'd be worth listing the issue
in DMA-mapping.txt. (Assuming the relevant gurus corrroborate... :)

That text might vaguely allude to the issue, it says you can use "the
addresses returned from those routines" (kmalloc and friends) ... but
of course, kmalloc effectively returns a family of addresses (one for
each byte returned).  Docs on "What memory is DMA-able" have slowly
been improving; I can understand why such caching issues might not yet
be well addressed.


> 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.

A simpler alternate fix might have been to declare that field as aligned,
which I think goes more or less like

	char buffer [...] __attribute__ (aligned (L1_CACHE_BYTES));

and size it accordingly, maybe after rearranging fields.  In any case,
given the subtlety of this issue I'd want to see a comment mentioning
the issue, so it stays safe across many generations of maintainers!

- Dave


** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

  reply	other threads:[~2002-06-08  5:18 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
2002-06-08  5:18     ` David Brownell [this message]
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=3D0193B8.9030500@pacbell.net \
    --to=david-b@pacbell.net \
    --cc=linux-usb-devel@lists.sourceforge.net \
    --cc=linuxppc-embedded@lists.linuxppc.org \
    --cc=roland@topspin.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).