linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] cache flush bug in mm/filemap.c (all kernels >= 2.5.30(at least))
@ 2003-05-22 12:34 LW
  2003-05-22 14:03 ` Russell King
  2003-05-22 14:11 ` Russell King
  0 siblings, 2 replies; 45+ messages in thread
From: LW @ 2003-05-22 12:34 UTC (permalink / raw)
  To: linux-kernel; +Cc: Linus Torvalds, linux-arm-kernel

[-- Attachment #1: message body text --]
[-- Type: text/plain, Size: 616 bytes --]

Hi,

in file 'mm/filemap.c' a call to 'flush_dcache_page' is missing as a
replacement for the obsoleted 'flush_page_to_ram' call that was
present there in older kernels.

This missing macro call produces data errors when randomly reading an
'mmap'ed file (e.g. leading to segfaults, when a program is executed).

In kernels < 2.5.46 the deprecated macro call was still present
(defined to do nothing), while in later kernels the call has been
removed.

Below are two patches generated against kernel versions 2.5.30 and
2.5.68 which should also be applicable to other kernels (with a hunk
offset).


Lothar Wassmann

[-- Attachment #2: patch for kernel 2.5.30 --]
[-- Type: text/plain, Size: 331 bytes --]

--- linux-2.5.30/mm/filemap.c	2002-08-14 19:04:09.000000000 +0200
+++ work-2.5.30_config/mm/filemap.c	2003-05-22 12:50:14.000000000 +0200
@@ -1260,7 +1260,7 @@
 	 * and possibly copy it over to another page..
 	 */
 	mark_page_accessed(page);
-	flush_page_to_ram(page);
+	flush_dcache_page(page);
 	return page;
 
 no_cached_page:

[-- Attachment #3: patch for kernels >= 2.5.46 --]
[-- Type: text/plain, Size: 298 bytes --]

--- linux-2.5.68/mm/filemap.c	2003-04-29 11:39:40.000000000 +0200
+++ work-2.5.68/mm/filemap.c	2003-05-22 12:22:31.000000000 +0200
@@ -1011,6 +1011,7 @@
 	 * Found the page and have a reference on it.
 	 */
 	mark_page_accessed(page);
+	//flush_dcache_page(page);
 	return page;
 
 no_cached_page:

[-- Attachment #4: Readme --]
[-- Type: text/plain, Size: 1575 bytes --]

In older kernels (< 2.5.46) used to be a call to 'flush_page_to_ram'
in the function 'filemap_nopage()' in 'mm/filemap.c'. This macro has
been obsoleted and has been replaced in other places by appropriate
'flush_dcache_page', 'flush_icache_page', 'copy_user_page', or
'clear_user_page' calls.

But in 'mm/filemap.c' it has been removed without replacement.
In fact a call to 'flush_dcache_page' should be in place there.

This missing macro call produces data errors when randomly reading an
'mmap'ed file (like it happens, when a program is executed).

I stumbled over this bug when I tried to execute a program from a
freshly mounted IDE CF card. The first call would segfault while
subsequent calls worked. This behaviour recurred when the disk was
unmounted between calls.

It also helped to copy the file (to /dev/null) before executing it
(from CF disk).
Digging into the problem I wrote a simple program that created a large
file (e.g. 1 MiB size), umounted and remounted the disk where it had
been created to flush all buffers and subsequently 'mmap'ed the file
and checked the contents from the file end to the start.
Upon error the program simply read the same word over and over again
until the correct data appeared after some time.


In kernels < 2.5.46 the deprecated macro call was still present in
filemap.c (though the macro was defined to do nothing), while in later
kernel versions that call was removed.

The accompanied patches are generated against kernel versions 2.5.30
and 2.5.68 but should also be applicable to other kernels (with a hunk
offset).

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

end of thread, other threads:[~2003-05-29 20:59 UTC | newest]

Thread overview: 45+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-22 12:34 [patch] cache flush bug in mm/filemap.c (all kernels >= 2.5.30(at least)) LW
2003-05-22 14:03 ` Russell King
2003-05-22 14:11 ` Russell King
2003-05-23  8:02   ` David S. Miller
2003-05-23  9:12     ` Andrew Morton
2003-05-23  9:49       ` David S. Miller
2003-05-23 10:04         ` Andrew Morton
2003-05-23 10:15           ` David S. Miller
2003-05-23  8:20   ` Lothar Wassmann
2003-05-23  9:24     ` Andrew Morton
2003-05-23 10:04       ` Lothar Wassmann
2003-05-23 10:45         ` Andrew Morton
2003-05-23 11:22           ` Paul Mackerras
2003-05-23 16:54           ` Russell King
2003-05-23 17:31             ` Hugh Dickins
2003-05-23 18:29               ` Andrew Morton
2003-05-23 18:34                 ` Russell King
2003-05-26  3:19                   ` David S. Miller
2003-05-26  5:07                     ` Mika Penttilä
2003-05-26  5:08                       ` David S. Miller
2003-05-26  5:36                         ` Mika Penttilä
2003-05-26  5:36                           ` David S. Miller
2003-05-26 13:18                             ` Roman Zippel
2003-05-26 22:34                               ` David S. Miller
2003-05-27 10:53                                 ` Roman Zippel
2003-05-27 21:22                                   ` David S. Miller
2003-05-28 16:35                                     ` Roman Zippel
2003-05-28 22:47                                       ` David S. Miller
2003-05-29  0:12                                         ` Roman Zippel
2003-05-29  1:37                                           ` David S. Miller
2003-05-29  7:13                                             ` Russell King
2003-05-29  7:15                                               ` David S. Miller
2003-05-29 17:49                                             ` Roman Zippel
2003-05-29 21:09                                               ` David S. Miller
2003-05-26  8:55                     ` Russell King
2003-05-26 13:08                       ` Lothar Wassmann
2003-05-26 22:19                         ` Russell King
2003-05-26 13:25                       ` Jens Axboe
2003-05-26 22:35                       ` David S. Miller
2003-05-26  3:20                   ` David S. Miller
2003-05-23 11:13         ` Russell King
2003-05-23 12:46           ` Lothar Wassmann
2003-05-23 15:42             ` Hugh Dickins
2003-05-25 17:10               ` David Woodhouse
2003-05-26 11:44               ` Lothar Wassmann

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