public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] page->flags corruption fix
@ 2003-10-07 16:26 Rik van Riel
  2003-10-08 14:49 ` Hugh Dickins
  0 siblings, 1 reply; 21+ messages in thread
From: Rik van Riel @ 2003-10-07 16:26 UTC (permalink / raw)
  To: Marcelo Tosatti; +Cc: Matt Domsch, linux-kernel, benh

In the "better safe than sorry" category. Thanks go out to
Matt Domsch and Robert Hentosh. A similar fix went into the
2.6 kernel. Please apply.

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
#	           ChangeSet	1.1192  -> 1.1193 
#	  include/linux/mm.h	1.43    -> 1.44   
#	     mm/page_alloc.c	1.63    -> 1.64   
#	        mm/filemap.c	1.88    -> 1.89   
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/10/07	riel@cessna.boston.redhat.com	1.1193
# fix page->flags corruption due to races between atomic and non-atomic
# accesses, originally found and fixed by Robert Hentosh and Matt Domsch
# --------------------------------------------
#
diff -Nru a/include/linux/mm.h b/include/linux/mm.h
--- a/include/linux/mm.h	Tue Oct  7 12:19:34 2003
+++ b/include/linux/mm.h	Tue Oct  7 12:19:34 2003
@@ -322,9 +322,11 @@
 #define TryLockPage(page)	test_and_set_bit(PG_locked, &(page)->flags)
 #define PageChecked(page)	test_bit(PG_checked, &(page)->flags)
 #define SetPageChecked(page)	set_bit(PG_checked, &(page)->flags)
+#define ClearPageChecked(page)	clear_bit(PG_checked, &(page)->flags)
 #define PageLaunder(page)	test_bit(PG_launder, &(page)->flags)
 #define SetPageLaunder(page)	set_bit(PG_launder, &(page)->flags)
 #define ClearPageLaunder(page)	clear_bit(PG_launder, &(page)->flags)
+#define ClearPageArch1(page)	clear_bit(PG_arch_1, &(page)->flags)
 
 /*
  * The zone field is never updated after free_area_init_core()
diff -Nru a/mm/filemap.c b/mm/filemap.c
--- a/mm/filemap.c	Tue Oct  7 12:19:34 2003
+++ b/mm/filemap.c	Tue Oct  7 12:19:34 2003
@@ -654,10 +654,13 @@
 	struct address_space *mapping, unsigned long offset,
 	struct page **hash)
 {
-	unsigned long flags;
-
-	flags = page->flags & ~(1 << PG_uptodate | 1 << PG_error | 1 << PG_dirty | 1 << PG_referenced | 1 << PG_arch_1 | 1 << PG_checked);
-	page->flags = flags | (1 << PG_locked);
+	ClearPageUptodate(page);
+	ClearPageError(page);
+	ClearPageDirty(page);
+	ClearPageReferenced(page);
+	ClearPageArch1(page);
+	ClearPageChecked(page);
+	LockPage(page);
 	page_cache_get(page);
 	page->index = offset;
 	add_page_to_inode_queue(mapping, page);
diff -Nru a/mm/page_alloc.c b/mm/page_alloc.c
--- a/mm/page_alloc.c	Tue Oct  7 12:19:34 2003
+++ b/mm/page_alloc.c	Tue Oct  7 12:19:34 2003
@@ -109,7 +109,8 @@
 		BUG();
 	if (PageActive(page))
 		BUG();
-	page->flags &= ~((1<<PG_referenced) | (1<<PG_dirty));
+	ClearPageReferenced(page);
+	ClearPageDirty(page);
 
 	if (current->flags & PF_FREE_PAGES)
 		goto local_freelist;


^ permalink raw reply	[flat|nested] 21+ messages in thread
* Re: [PATCH] page->flags corruption fix
@ 2003-10-08 15:31 Matt_Domsch
  2003-10-08 15:53 ` Hugh Dickins
  0 siblings, 1 reply; 21+ messages in thread
From: Matt_Domsch @ 2003-10-08 15:31 UTC (permalink / raw)
  To: hugh; +Cc: riel, marcelo.tosatti, linux-kernel, benh

On Wed, 2003-10-08 at 09:49, Hugh Dickins wrote:
> On Tue, 7 Oct 2003, Rik van Riel wrote:
> 
> > In the "better safe than sorry" category. Thanks go out to
> > Matt Domsch and Robert Hentosh. A similar fix went into the
> > 2.6 kernel. Please apply.
> 
> Seven atomic ops in a row, isn't that rather inefficient?

Not all arches have atomic_set_mask() and atomic_clear_mask().
asm-arm
asm-arm26
asm-h8300
asm-i386
asm-m68k
asm-m68knommu
asm-ppc
asm-s390
asm-sh
asm-v850
asm-x86_64

do.


> The 2.6 version clears those PG_flags all together in one
> non-atomic op - but elsewhere, in prep_new_page.
>
> Is there an actual test case for why 2.4 now needs this change?

There definitely is when RMAP is present - we've reproduced it
repeatedly in our labs.

We've seen a similar failure with the RHEL2.1 kernel w/o RMAP patches
too.  So we fully believe it's possible in stock 2.4.x.

Thanks,
Matt

-- 
Matt Domsch
Sr. Software Engineer, Lead Engineer
Dell Linux Solutions www.dell.com/linux
Linux on Dell mailing lists @ http://lists.us.dell.com


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2003-10-12 20:39 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-10-07 16:26 [PATCH] page->flags corruption fix Rik van Riel
2003-10-08 14:49 ` Hugh Dickins
2003-10-08 14:57   ` David S. Miller
2003-10-08 15:10     ` Rik van Riel
2003-10-08 15:47       ` Hugh Dickins
2003-10-08 15:52         ` Rik van Riel
  -- strict thread matches above, loose matches on Subject: below --
2003-10-08 15:31 Matt_Domsch
2003-10-08 15:53 ` Hugh Dickins
2003-10-08 15:59   ` Rik van Riel
2003-10-08 17:15     ` Hugh Dickins
2003-10-08 17:41       ` Marcelo Tosatti
2003-10-08 17:52         ` Rik van Riel
2003-10-11 13:48     ` Andrea Arcangeli
2003-10-11 16:03       ` Andrea Arcangeli
2003-10-12 11:15         ` Hugh Dickins
2003-10-12 13:21           ` Andrea Arcangeli
2003-10-12 13:35             ` Andrea Arcangeli
2003-10-12 14:11           ` Rik van Riel
2003-10-12 14:36             ` Andrea Arcangeli
2003-10-12 17:20               ` Rik van Riel
2003-10-12 20:40                 ` Andrea Arcangeli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox