All of lore.kernel.org
 help / color / mirror / Atom feed
From: Robert Hancock <hancockr@shaw.ca>
To: linux-kernel@vger.kernel.org
Subject: Memory vs. MMIO ordering, again
Date: Wed, 24 Dec 2008 12:06:54 -0600	[thread overview]
Message-ID: <gittnv$2qj$1@ger.gmane.org> (raw)

A question came up recently about memory ordering in libata. Essentially 
we have the classic case (ata_bmdma_setup in drivers/ata/libata-sff.c) 
where we do some writes to memory (specifically the PRD table) and want 
to make sure the device will see those writes before we poke it to go 
and use that memory. Right now this is using an mb() (which seems like 
overkill, even in the worst case it seems like only a wmb() should be 
needed).

I just finished digging through the 2006 LKML discussion "Opinion on 
ordering of writel vs. stores to RAM" which ironically failed to clearly 
answer the question asked in its subject.

Documentation/memory-barriers.txt does not answer this question either. 
The only thing it contains that seems to pertain to this question is the 
following:

"Memory mapped I/O usually takes place through memory locations that are 
part of a window in the CPU's memory space that has different properties 
assigned than the usual RAM directed window.

Amongst these properties is usually the fact that such accesses bypass 
the caching entirely and go directly to the device buses.  This means 
MMIO accesses may, in effect, overtake accesses to cached memory that 
were emitted earlier. A memory barrier isn't sufficient in such a case, 
but rather the cache must be flushed between the cached memory write and 
the MMIO access if the two are in any way dependent."

This seems like BS to me.. Flush the cache? How is a driver supposed to 
know how to do that? Furthermore, why should it need to worry about this 
  kind of detail? This seems wrong or at least a low-level detail that 
normal code should not have to be concerned with.

 From what I can vaguely infer from that 2006 discussion it seems like 
powerpc was going to be fixed so that writel, etc. would provide the 
expected ordering with respect to memory writes, however I don't know if 
this is actually the case. The documentation that driver writers would 
rely on should be updated to be explicit on this question...


             reply	other threads:[~2008-12-24 18:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-24 18:06 Robert Hancock [this message]
2008-12-24 18:32 ` Memory vs. MMIO ordering, again Alan Cox
2008-12-24 21:15   ` Robert Hancock
2008-12-25  0:11     ` Alan Cox

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='gittnv$2qj$1@ger.gmane.org' \
    --to=hancockr@shaw.ca \
    --cc=linux-kernel@vger.kernel.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 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.