[PATCH 3/5] pagemap: Make pagemap_read enforce reading in multiples of 8

From: Thomas Tuttle
Date: Thu Jun 05 2008 - 11:06:20 EST


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.
From 25908731b67069d6cf56d8af522b55479ea75736 Mon Sep 17 00:00:00 2001
From: Thomas Tuttle <ttuttle@xxxxxxxxxx>
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@xxxxxxxxxx>
---
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