linux-stable/include
Nick Piggin 0ed361dec3 mm: fix PageUptodate data race
After running SetPageUptodate, preceeding stores to the page contents to
actually bring it uptodate may not be ordered with the store to set the
page uptodate.

Therefore, another CPU which checks PageUptodate is true, then reads the
page contents can get stale data.

Fix this by having an smp_wmb before SetPageUptodate, and smp_rmb after
PageUptodate.

Many places that test PageUptodate, do so with the page locked, and this
would be enough to ensure memory ordering in those places if
SetPageUptodate were only called while the page is locked.  Unfortunately
that is not always the case for some filesystems, but it could be an idea
for the future.

Also bring the handling of anonymous page uptodateness in line with that of
file backed page management, by marking anon pages as uptodate when they
_are_ uptodate, rather than when our implementation requires that they be
marked as such.  Doing allows us to get rid of the smp_wmb's in the page
copying functions, which were especially added for anonymous pages for an
analogous memory ordering problem.  Both file and anonymous pages are
handled with the same barriers.

FAQ:
Q. Why not do this in flush_dcache_page?
A. Firstly, flush_dcache_page handles only one side (the smb side) of the
ordering protocol; we'd still need smp_rmb somewhere. Secondly, hiding away
memory barriers in a completely unrelated function is nasty; at least in the
PageUptodate macros, they are located together with (half) the operations
involved in the ordering. Thirdly, the smp_wmb is only required when first
bringing the page uptodate, wheras flush_dcache_page should be called each time
it is written to through the kernel mapping. It is logically the wrong place to
put it.

Q. Why does this increase my text size / reduce my performance / etc.
A. Because it is adding the necessary instructions to eliminate the data-race.

Q. Can it be improved?
A. Yes, eg. if you were to create a rule that all SetPageUptodate operations
run under the page lock, we could avoid the smp_rmb places where PageUptodate
is queried under the page lock. Requires audit of all filesystems and at least
some would need reworking. That's great you're interested, I'm eagerly awaiting
your patches.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-02-05 09:44:19 -08:00
..
acpi include/acpi/: Spelling fixes 2008-02-03 17:07:16 +02:00
asm-alpha add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
asm-arm add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
asm-avr32 add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
asm-blackfin [NET]: Introducing socket mark socket option. 2008-01-31 19:27:19 -08:00
asm-cris add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
asm-frv add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
asm-generic add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
asm-h8300 [NET]: Introducing socket mark socket option. 2008-01-31 19:27:19 -08:00
asm-ia64 add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
asm-m32r add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
asm-m68k add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
asm-m68knommu include/asm-m68knommu/: Spelling fixes 2008-02-03 17:38:04 +02:00
asm-mips add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
asm-parisc add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
asm-powerpc add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
asm-ppc add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
asm-s390 add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
asm-sh add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
asm-sparc add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
asm-sparc64 add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
asm-um add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
asm-v850 [NET]: Introducing socket mark socket option. 2008-01-31 19:27:19 -08:00
asm-x86 add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
asm-xtensa add mm argument to pte/pmd/pud/pgd_free 2008-02-05 09:44:18 -08:00
crypto
keys
linux mm: fix PageUptodate data race 2008-02-05 09:44:19 -08:00
math-emu
media include/media/: Spelling fixes 2008-02-03 17:19:47 +02:00
mtd
net [IPV6]: Reorg struct ifmcaddr6 to save some bytes 2008-02-03 04:28:54 -08:00
pcmcia pcmcia: replace kio_addr_t with unsigned int everywhere 2008-02-05 09:44:08 -08:00
rdma
rxrpc
scsi include/scsi/: Spelling fixes 2008-02-03 17:47:00 +02:00
sound [ALSA] version 1.0.16rc2 2008-01-31 17:40:18 +01:00
video
xen x86: page.h: make pte_t a union to always include 2008-01-30 13:32:57 +01:00
Kbuild