Re: Possible memory ordering bug in page reclaim?

From: Nick Piggin
Date: Sat Oct 15 2005 - 03:58:56 EST


Benjamin Herrenschmidt wrote:
On Sat, 2005-10-15 at 07:17 +0100, Hugh Dickins wrote:

On Sat, 15 Oct 2005, Nick Piggin wrote:


1 2
find_get_page();
write to page write_lock(tree_lock);
SetPageDirty(); if (page_count != 2
put_page(); || PageDirty())

Now I'm worried that 2 might see PageDirty *before* SetPageDirty in

page->flags

1, and page_count *after* put_page in 1.

I think you're right. But I'm the last person to ask
barrier/ordering questions of. CC'ed Ben and Andrea.


yup, now the question is wether PG_Dirty will be visible to CPU 2 before
the page count is decremented right ? That depends on put_page, I
suppose. If it's doing a simple atomic, there is an issue. But atomics
with return has been so often abused as locks that they may have been
implemented with a barrier... (On ppc64, it will do an eieio, thus I
think it should be ok).


Well yes, that's on the store side (1, above). However can't a CPU
still speculatively (eg. guess the branch) load the page->flags
cacheline which might be satisfied from memory before the page->count
cacheline loads? Ie. you can still have the correct write ordering
but have incorrect read ordering?

Because neither PageDirty nor page_count is a barrier, and there is
no read barrier between them.

Nick

--
SUSE Labs, Novell Inc.

Send instant messages to your online friends http://au.messenger.yahoo.com -
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/