Port-xen archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Alloc userspace process to access mapped grant memory regions



On 24/11/12 13:16, Manuel Bouyer wrote:
> On Sat, Nov 24, 2012 at 09:35:47AM +0100, Roger Pau Monné wrote:
>> Thanks for the help, I've changed the code a little bit and tried doing
>> something similar to what is done in the mmap function of xenevt:
>>
>> (inside device mmap handler):
>> xen_shm_map(nentries, domid, grefp, &va, handlep, flags);
>> pmap_extract_ma(pmap_kernel(), map->va, &ma)
>> printf("Kernel MA: %p\n", (void *)ma);
>> return x86_btop(xpmap_mtop(ma));
>>
>> This device also has an ioctl where the user-space process can pass a VA
>> (in the user space) and get the grant associated with this VA (basically
>> the passed VA is the return value of mmap(gntdev...)). I do the
>> following in the ioctl handler:
>>
>> (passed_va is the user provided VA through the ioctl)
>>
>> paddr_t u_pa, k_pa;
>> paddr_t u_ma, k_ma;
>> pmap_t user_pmap = vm_map_pmap(&user_lwp->l_proc->p_vmspace->vm_map);
>>
>> pmap_extract(pmap, passed_va, &u_pa);
>> foreach(kernel_va, list_of_mapped_grants) {
>>      /* kernel_va is map->va in the upper example */
>>      pmap_extract(pmap_kernel(), kernel_va, &k_pa);
>>      if (k_pa == u_pa) {
>>              printf("Find matching PA\n");
>>              pmap_extract_ma(pmap, passed_va, &process_ma);
>>              pmap_extract_ma(pmap_kernel(), kernel_va, &kernel_ma);
>>              printf("Kernel MA: %p - Userspace MA: %p\n",
>>                      (void *)k_ma, (void *)u_ma);
>>      }
>> }
>>
>> The output when performing the mmap is the following:
>>
>> Kernel MA: 0xb24c9000
>>
>> And the output when the user performs the ioctl to find the gref of the
>> user-space VA is:
>>
>> Find matching PA
>> Kernel MA: 0xb24c9000 - Userspace MA: 0xbda71000
>>
>> So it seems like I return the correct MA in the mmap handler, but the
>> userspace process gets a wrong MA associated with it's VA?
> 
> Are the p2m and m2p maps consistent ? I suspect they're not ...

I think it will be easier if there was someway to know the va where the
user-space process is going to map the returned pa, but I can't see a
way to get this from the mmap handler.



Home | Main Index | Thread Index | Old Index