public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Wu Fengguang <fengguang.wu@intel.com>
To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Greg KH <greg@kroah.com>, Andi Kleen <andi@firstfloor.org>,
	Wu Fengguang <fengguang.wu@intel.com>
Cc: Christoph Lameter <clameter@sgi.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Tejun Heo <tj@kernel.org>
Cc: Nick Piggin <npiggin@suse.de>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH 2/3] devmem: handle partial kmem write/read
Date: Tue, 15 Sep 2009 10:18:53 +0800	[thread overview]
Message-ID: <20090915022328.460943370@intel.com> (raw)
In-Reply-To: 20090915021851.168285585@intel.com

[-- Attachment #1: kmem-vwrite-ret.patch --]
[-- Type: text/plain, Size: 1579 bytes --]

Return early on partial read/write, which may happen in future.
(eg. hit hwpoison pages)

CC: Greg KH <greg@kroah.com>
CC: Andi Kleen <andi@firstfloor.org>
CC: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
---
 drivers/char/mem.c |   30 ++++++++++++++++++------------
 mm/vmalloc.c       |   10 +---------
 2 files changed, 19 insertions(+), 21 deletions(-)

--- linux-mm.orig/drivers/char/mem.c	2009-09-15 09:44:49.000000000 +0800
+++ linux-mm/drivers/char/mem.c	2009-09-15 09:44:55.000000000 +0800
@@ -444,18 +444,22 @@ static ssize_t read_kmem(struct file *fi
 		if (!kbuf)
 			return -ENOMEM;
 		while (count > 0) {
+			unsigned long n;
+
 			sz = size_inside_page(p, count);
-			sz = vread(kbuf, (char *)p, sz);
-			if (!sz)
+			n = vread(kbuf, (char *)p, sz);
+			if (!n)
 				break;
-			if (copy_to_user(buf, kbuf, sz)) {
+			if (copy_to_user(buf, kbuf, n)) {
 				free_page((unsigned long)kbuf);
 				return -EFAULT;
 			}
-			count -= sz;
-			buf += sz;
-			read += sz;
-			p += sz;
+			count -= n;
+			buf += n;
+			read += n;
+			p += n;
+			if (n < sz)
+				break;
 		}
 		free_page((unsigned long)kbuf);
 	}
@@ -551,11 +555,13 @@ static ssize_t write_kmem(struct file * 
 				free_page((unsigned long)kbuf);
 				return -EFAULT;
 			}
-			sz = vwrite(kbuf, (char *)p, sz);
-			count -= sz;
-			buf += sz;
-			virtr += sz;
-			p += sz;
+			n = vwrite(kbuf, (char *)p, sz);
+			count -= n;
+			buf += n;
+			virtr += n;
+			p += n;
+			if (n < sz)
+				break;
 		}
 		free_page((unsigned long)kbuf);
 	}

-- 


  parent reply	other threads:[~2009-09-15  2:25 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-15  2:18 [PATCH 0/3] /proc/kmem cleanups and hwpoison bits Wu Fengguang
2009-09-15  2:18 ` [PATCH 1/3] vmalloc: ignore vmalloc area holes in vwrite() Wu Fengguang
2009-09-15  2:34   ` KAMEZAWA Hiroyuki
2009-09-15  3:15     ` Wu Fengguang
2009-09-15  3:18       ` KAMEZAWA Hiroyuki
2009-09-15  5:21         ` Wu Fengguang
2009-09-15  2:18 ` Wu Fengguang [this message]
2009-09-15  2:38   ` [PATCH 2/3] devmem: handle partial kmem write/read KAMEZAWA Hiroyuki
2009-09-15  9:01     ` Wu Fengguang
2009-09-15  9:03       ` Wu Fengguang
2009-09-15  2:18 ` [PATCH 3/3] HWPOISON: prevent /dev/kmem users from accessing hwpoison pages Wu Fengguang
2009-09-15  2:45   ` KAMEZAWA Hiroyuki
2009-09-15  3:09 ` [PATCH 0/3] /proc/kmem cleanups and hwpoison bits KAMEZAWA Hiroyuki
2009-09-15  8:22   ` Wu Fengguang
2009-09-15 10:16     ` Hugh Dickins
2009-09-16  0:39       ` KAMEZAWA Hiroyuki
2009-09-16  0:39       ` Wu Fengguang
2009-09-16  9:01       ` Geert Uytterhoeven
2009-09-16 11:26         ` Hugh Dickins
2009-09-16 11:42           ` Geert Uytterhoeven

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=20090915022328.460943370@intel.com \
    --to=fengguang.wu@intel.com \
    --cc=andi@firstfloor.org \
    --cc=benh@kernel.crashing.org \
    --cc=greg@kroah.com \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    /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