pagemap: Make pagemap_read enforce reading in multiples of 8
Subsystems (2)
PATCH 3/5 pagemap: Make pagemap_read enforce reading in multiples of 8
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 <[email protected]>
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.
--- fs/proc/task_mmu.c | 18 ++++-------------- 1 files changed, 4 insertions(+), 14 deletions(-)
fs/proc/task_mmu.c +4 -14
@@ -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 ;
Signature · 1 line
1.5.3.6
Quoted 3 lines · Thomas Tuttle
Since kpagecount and kpageflags require reads in multiples of 8, and it simplifies
add_to_pagemapsignificantly, I added the same requirement to/proc/pid/pagemap.
I'm generally fine with this. Another approach that's perhaps more friendly is when someone tries to do a 24-byte read, do a 16-byte read, leaving the file pointer aligned. Not sure if that's completely kosher though.
Signature · 1 line
Mathematics is the supreme nostalgia of our time.
Quoted 10 lines · Matt Mackall
Quoted 3 lines · Thomas Tuttle
Since kpagecount and kpageflags require reads in multiples of 8, and it simplifies
add_to_pagemapsignificantly, I added the same requirement to/proc/pid/pagemap.I'm generally fine with this. Another approach that's perhaps more friendly is when someone tries to do a 24-byte read, do a 16-byte read, leaving the file pointer aligned. Not sure if that's completely kosher though.
This doesn't require that they read exactly 8 bytes, just that they read some multiple of 8 bytes. (They can read 8, 16, 24, etc..., just not something like 12.)
--ttuttle
Quoted 7 lines · Thomas Tuttle
Quoted 6 lines · Matt Mackall
Quoted 3 lines · Thomas Tuttle
Since kpagecount and kpageflags require reads in multiples of 8, and it simplifies
add_to_pagemapsignificantly, I added the same requirement to/proc/pid/pagemap.
Quoted 8 lines
Quoted 4 lines
I'm generally fine with this. Another approach that's perhaps more friendly is when someone tries to do a 24-byte read, do a 16-byte read, leaving the file pointer aligned. Not sure if that's completely kosher though.
This doesn't require that they read exactly 8 bytes, just that they read some multiple of 8 bytes. (They can read 8, 16, 24, etc..., just not something like 12.)
Yes, I got that, I'm just mathematically impaired this morning. Read that as "when someone tries to do a *20* byte read, do a 16-byte read.." In other words, round down to the nearest multiple of 8.
Signature · 1 line
Mathematics is the supreme nostalgia of our time.
Quoted 3 lines · Matt Mackall
Yes, I got that, I'm just mathematically impaired this morning. Read that as "when someone tries to do a *20* byte read, do a 16-byte read.." In other words, round down to the nearest multiple of 8.
Oh. I would seriously question doing that, because it would allow reads that are improperly split up to fail silently. What happens if someone tries to read 40 bytes, and (for some reason) it gets split into two 20-byte reads? Instead of "12345" they'll get "12.34." (where . is 4 zero or garbage bytes). I'd rather they get an error.
--ttuttle
Quoted 10 lines · Thomas Tuttle
Quoted 3 lines · Matt Mackall
Yes, I got that, I'm just mathematically impaired this morning. Read that as "when someone tries to do a *20* byte read, do a 16-byte read.." In other words, round down to the nearest multiple of 8.
Oh. I would seriously question doing that, because it would allow reads that are improperly split up to fail silently. What happens if someone tries to read 40 bytes, and (for some reason) it gets split into two 20-byte reads? Instead of "12345" they'll get "12.34." (where . is 4 zero or garbage bytes). I'd rather they get an error.
I suppose you're right, people usually don't check those return codes.
Signature · 1 line
Mathematics is the supreme nostalgia of our time.