public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 3/5] pagemap: Make pagemap_read enforce reading in multiples of 8
@ 2008-06-05 15:06 Thomas Tuttle
  2008-06-05 16:03 ` Matt Mackall
  0 siblings, 1 reply; 6+ messages in thread
From: Thomas Tuttle @ 2008-06-05 15:06 UTC (permalink / raw)
  To: mpm, akpm, linux-kernel

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

Since kpagecount and kpageflags require reads in multiples of 8, and
it simplifies add_to_pagemap significantly, I added the same
requirement to /proc/pid/pagemap.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0003-Make-pagemap_read-enforce-reading-in-multiples-of-8.patch --]
[-- Type: text/x-patch; name=0003-Make-pagemap_read-enforce-reading-in-multiples-of-8.patch, Size: 1800 bytes --]

From 25908731b67069d6cf56d8af522b55479ea75736 Mon Sep 17 00:00:00 2001
From: Thomas Tuttle <ttuttle@google.com>
Date: Thu, 5 Jun 2008 10:45:55 -0400
Subject: [PATCH] Make pagemap_read enforce reading in multiples of 8.

Previously, /proc/pid/pagemap would allow reads of lengths that were not
multiples of 8 to succeed (and would return correct data), but had no way
of reading the remainder of the partial value returned.

/proc/kpage{count,flags} are also arrays of u64s, and they require that
reads are a multiple of 8.  This patch makes /proc/pid/pagemap consistent.

Signed-off-by: Thomas Tuttle <ttuttle@google.com>
---
 fs/proc/task_mmu.c |   18 ++++--------------
 1 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 9915202..3f6d680 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -519,21 +519,11 @@ struct pagemapread {
 static int add_to_pagemap(unsigned long addr, u64 pfn,
 			  struct pagemapread *pm)
 {
-	/*
-	 * Make sure there's room in the buffer for an
-	 * entire entry.  Otherwise, only copy part of
-	 * the pfn.
-	 */
-	if (pm->out + PM_ENTRY_BYTES >= pm->end) {
-		if (copy_to_user(pm->out, &pfn, pm->end - pm->out))
-			return -EFAULT;
-		pm->out = pm->end;
-		return PM_END_OF_BUFFER;
-	}
-
 	if (copy_to_user(pm->out, &pfn, PM_ENTRY_BYTES))
 		return -EFAULT;
 	pm->out += PM_ENTRY_BYTES;
+	if (pm->out >= pm->end)
+		return PM_END_OF_BUFFER;
 	return 0;
 }
 
@@ -633,8 +623,8 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
 		goto out_task;
 
 	ret = -EINVAL;
-	/* file position must be aligned */
-	if (*ppos % PM_ENTRY_BYTES)
+	/* file position and count must be aligned */
+	if ((*ppos % PM_ENTRY_BYTES) || (count % PM_ENTRY_BYTES))
 		goto out_task;
 
 	ret = 0;
-- 
1.5.3.6


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

end of thread, other threads:[~2008-06-05 16:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-05 15:06 [PATCH 3/5] pagemap: Make pagemap_read enforce reading in multiples of 8 Thomas Tuttle
2008-06-05 16:03 ` Matt Mackall
2008-06-05 16:05   ` Thomas Tuttle
2008-06-05 16:09     ` Matt Mackall
2008-06-05 16:14       ` Thomas Tuttle
2008-06-05 16:21         ` Matt Mackall

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