public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jun Sun <jsun@mvista.com>
To: linux-kernel@vger.kernel.org
Cc: jsun@mvista.com, Marcelo Tosatti <marcelo@conectiva.com.br>
Subject: [PATCH] [2.4] kiobuf flush dcache properly
Date: Tue, 1 Apr 2003 17:03:07 -0800	[thread overview]
Message-ID: <20030401170307.A29837@mvista.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 516 bytes --]

Some CPUs have cache aliasing problem, where the same physical
memory could appear in more than one places in data cache
(such as those found in MIPS and Sparc).  For those CPUs, kiobuf
is not flushing cache properly.

The symptom can be easily found if you open files with O_DIRECT
flag and do file copies on those CPUs.

This patch fixes the problem.

Basically if it is a WRITE (from user to disk), we need to flush
cache before the IO.  If it is a READ, we need to flush cache after 
the IO.

Please apply.

Jun

[-- Attachment #2: 030401-2.4-kiobuf-flush-dcache.patch --]
[-- Type: text/plain, Size: 1633 bytes --]

diff -Nru linux-2.4.20/mm/memory.c.orig linux-2.4.20/mm/memory.c
--- linux-2.4.20/mm/memory.c.orig	2003-04-01 16:33:48.000000000 -0800
+++ linux-2.4.20/mm/memory.c	2003-04-01 16:41:34.000000000 -0800
@@ -553,6 +553,7 @@
 	if (err)
 		return err;
 
+	iobuf->rw = rw;
 	iobuf->locked = 0;
 	iobuf->offset = va & (PAGE_SIZE-1);
 	iobuf->length = len;
@@ -569,11 +570,10 @@
 		return err;
 	}
 	iobuf->nr_pages = err;
-	while (pgcount--) {
-		/* FIXME: flush superflous for rw==READ,
-		 * probably wrong function for rw==WRITE
-		 */
-		flush_dcache_page(iobuf->maplist[pgcount]);
+	/* if rw==WRITE, get updated data before writing them to disk */
+	if (rw==WRITE) {
+		while (pgcount--) 
+			flush_dcache_page(iobuf->maplist[pgcount]);
 	}
 	dprintk ("map_user_kiobuf: end OK\n");
 	return 0;
@@ -628,9 +628,10 @@
 		if (map) {
 			if (iobuf->locked)
 				UnlockPage(map);
-			/* FIXME: cache flush missing for rw==READ
-			 * FIXME: call the correct reference counting function
-			 */
+			/* if rw==READ, flush dcache before user uses data */
+			if (iobuf->rw==READ) {
+				flush_dcache_page(iobuf->maplist[i]);
+			}
 			page_cache_release(map);
 		}
 	}
diff -Nru linux-2.4.20/include/linux/iobuf.h.orig linux-2.4.20/include/linux/iobuf.h
--- linux-2.4.20/include/linux/iobuf.h.orig	2002-11-28 15:53:15.000000000 -0800
+++ linux-2.4.20/include/linux/iobuf.h	2003-04-01 16:34:16.000000000 -0800
@@ -32,6 +32,7 @@
 
 struct kiobuf 
 {
+	int		rw;		/* mapped for READ or WRITE */
 	int		nr_pages;	/* Pages actually referenced */
 	int		array_len;	/* Space in the allocated lists */
 	int		offset;		/* Offset to start of valid data */

                 reply	other threads:[~2003-04-02  0:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20030401170307.A29837@mvista.com \
    --to=jsun@mvista.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcelo@conectiva.com.br \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox