Re: [PATCH] mm: extend prefault helpers to fault in more than PAGE_SIZE

From: Hillf Danton
Date: Fri Feb 17 2012 - 08:06:22 EST


On Thu, Feb 16, 2012 at 11:14 PM, Daniel Vetter <daniel@xxxxxxxx> wrote:
> On Thu, Feb 16, 2012 at 09:32:08PM +0800, Hillf Danton wrote:
>> On Thu, Feb 16, 2012 at 8:01 PM, Daniel Vetter <daniel.vetter@xxxxxxxx> wrote:
>> > @@ -416,17 +417,20 @@ static inline int fault_in_pages_writeable(char __user *uaddr, int size)
>> > Â Â Â Â * Writing zeroes into userspace here is OK, because we know that if
>> > Â Â Â Â * the zero gets there, we'll be overwriting it.
>> > Â Â Â Â */
>> > - Â Â Â ret = __put_user(0, uaddr);
>> > + Â Â Â while (uaddr <= end) {
>> > + Â Â Â Â Â Â Â ret = __put_user(0, uaddr);
>> > + Â Â Â Â Â Â Â if (ret != 0)
>> > + Â Â Â Â Â Â Â Â Â Â Â return ret;
>> > + Â Â Â Â Â Â Â uaddr += PAGE_SIZE;
>> > + Â Â Â }
>>
>> What if
>> Â Â Â Â Â Â Âuaddr & ~PAGE_MASK == PAGE_SIZE -3 &&
>> Â Â Â Â Â Â Â Â end & ~PAGE_MASK == 2
>
> I don't quite follow - can you elaborate upon which issue you're seeing?

I concerned that __put_user(0, end) is missed, but it was added below.

And looks good to me.
Hillf

> Â Â Â Âif (ret == 0) {
> - Â Â Â Â Â Â Â char __user *end = uaddr + size - 1;
> -
> Â Â Â Â Â Â Â Â/*
> Â Â Â Â Â Â Â Â * If the page was already mapped, this will get a cache miss
> Â Â Â Â Â Â Â Â * for sure, so try to avoid doing it.
> Â Â Â Â Â Â Â Â */
> - Â Â Â Â Â Â Â if (((unsigned long)uaddr & PAGE_MASK) !=
> + Â Â Â Â Â Â Â if (((unsigned long)uaddr & PAGE_MASK) ==
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â((unsigned long)end & PAGE_MASK))
> - Â Â Â Â Â Â Â Â Â Â Â ret = __put_user(0, end);
> + Â Â Â Â Â Â Â Â Â Â Â ret = __put_user(0, end);
> Â Â Â Â}
> Â Â Â Âreturn ret;
èº{.nÇ+‰·Ÿ®‰­†+%ŠËlzwm…ébëæìr¸›zX§»®w¥Š{ayºÊÚë,j­¢f£¢·hš‹àz¹®w¥¢¸ ¢·¦j:+v‰¨ŠwèjØm¶Ÿÿ¾«‘êçzZ+ƒùšŽŠÝj"ú!¶iO•æ¬z·švØ^¶m§ÿðà nÆàþY&—