Re: [PATCH] xen/privcmd: Support correctly 64KB page granularity when mapping memory

From: Boris Ostrovsky
Date: Thu Jun 01 2017 - 09:34:19 EST


On 06/01/2017 08:50 AM, Julien Grall wrote:
> Hi Boris,
>
> On 31/05/17 14:54, Boris Ostrovsky wrote:
>> On 05/31/2017 09:03 AM, Julien Grall wrote:
>>> Commit 5995a68 "xen/privcmd: Add support for Linux 64KB page
>>> granularity" did
>>> not go far enough to support 64KB in mmap_batch_fn.
>>>
>>> The variable 'nr' is the number of 4KB chunk to map. However, when
>>> Linux
>>> is using 64KB page granularity the array of pages
>>> (vma->vm_private_data)
>>> contain one page per 64KB. Fix it by incrementing st->index correctly.
>>>
>>> Furthermore, st->va is not correctly incremented as PAGE_SIZE !=
>>> XEN_PAGE_SIZE.
>>>
>>> Fixes: 5995a68 ("xen/privcmd: Add support for Linux 64KB page
>>> granularity")
>>> CC: stable@xxxxxxxxxxxxxxx
>>> Reported-by: Feng Kan <fkan@xxxxxxx>
>>> Signed-off-by: Julien Grall <julien.grall@xxxxxxx>
>>> ---
>>> drivers/xen/privcmd.c | 4 ++--
>>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c
>>> index 7a92a5e1d40c..feca75b07fdd 100644
>>> --- a/drivers/xen/privcmd.c
>>> +++ b/drivers/xen/privcmd.c
>>> @@ -362,8 +362,8 @@ static int mmap_batch_fn(void *data, int nr,
>>> void *state)
>>> st->global_error = 1;
>>> }
>>> }
>>> - st->va += PAGE_SIZE * nr;
>>> - st->index += nr;
>>> + st->va += XEN_PAGE_SIZE * nr;
>>> + st->index += nr / XEN_PFN_PER_PAGE;
>>>
>>> return 0;
>>> }
>>
>>
>> Are we still using PAGE_MASK for xen_remap_domain_gfn_array()?
>
> Do you mean in the xen_xlate_remap_gfn_array implementation? If so
> there are no use of PAGE_MASK as the code has been converted to
> support 64K page granularity.
>
> If you mean the x86 version of xen_remap_domain_gfn_array, then we
> don't really care as x86 only use 4KB page granularity.


I meant right above the change that you made. Should it also be replaced
with XEN_PAGE_MASK? (Sorry for being unclear.)

==> ret = xen_remap_domain_gfn_array(st->vma, st->va & PAGE_MASK,
gfnp, nr,
(int *)gfnp, st->vma->vm_page_prot,
st->domain, cur_pages);

/* Adjust the global_error? */
if (ret != nr) {
if (ret == -ENOENT)
st->global_error = -ENOENT;
else {
/* Record that at least one error has happened. */
if (st->global_error == 0)
st->global_error = 1;
}
}
st->va += PAGE_SIZE * nr;
st->index += nr;