All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: Understanding osdep_xenforeignmemory_map mmap behaviour
@ 2022-03-24  1:42 Stefano Stabellini
  2022-03-24  5:12 ` Juergen Gross
  0 siblings, 1 reply; 15+ messages in thread
From: Stefano Stabellini @ 2022-03-24  1:42 UTC (permalink / raw)
  To: alex.bennee
  Cc: xen-devel, Stratos-dev, viresh.kumar, mathieu.poirier,
	christopher.w.clark, jgross, boris.ostrovsky

I am pretty sure the reasons have to do with old x86 PV guests, so I am
CCing Juergen and Boris.


> Hi,
> 
> While we've been working on the rust-vmm virtio backends on Xen we
> obviously have to map guest memory info the userspace of the daemon.
> However following the logic of what is going on is a little confusing.
> For example in the Linux backend we have this:
> 
>   void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
>                                    uint32_t dom, void *addr,
>                                    int prot, int flags, size_t num,
>                                    const xen_pfn_t arr[/*num*/], int err[/*num*/])
>   {
>       int fd = fmem->fd;
>       privcmd_mmapbatch_v2_t ioctlx;
>       size_t i;
>       int rc;
> 
>       addr = mmap(addr, num << XC_PAGE_SHIFT, prot, flags | MAP_SHARED,
>                   fd, 0);
>       if ( addr == MAP_FAILED )
>           return NULL;
> 
>       ioctlx.num = num;
>       ioctlx.dom = dom;
>       ioctlx.addr = (unsigned long)addr;
>       ioctlx.arr = arr;
>       ioctlx.err = err;
> 
>       rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx);
> 
> Where the fd passed down is associated with the /dev/xen/privcmd device
> for issuing hypercalls on userspaces behalf. What is confusing is why
> the function does it's own mmap - one would assume the passed addr would
> be associated with a anonymous or file backed mmap region already that
> the calling code has setup. Applying a mmap to a special device seems a
> little odd.
> 
> Looking at the implementation on the kernel side it seems the mmap
> handler only sets a few flags:
> 
>   static int privcmd_mmap(struct file *file, struct vm_area_struct *vma)
>   {
>           /* DONTCOPY is essential for Xen because copy_page_range doesn't know
>            * how to recreate these mappings */
>           vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTCOPY |
>                            VM_DONTEXPAND | VM_DONTDUMP;
>           vma->vm_ops = &privcmd_vm_ops;
>           vma->vm_private_data = NULL;
> 
>           return 0;
>   }
> 
> So can I confirm that the mmap of /dev/xen/privcmd is being called for
> side effects? Is it so when the actual ioctl is called the correct flags
> are set of the pages associated with the user space virtual address
> range?
> 
> Can I confirm there shouldn't be any limitation on where and how the
> userspace virtual address space is setup for the mapping in the guest
> memory?
> 
> Is there a reason why this isn't done in the ioctl path itself?
> 
> I'm trying to understand the differences between Xen and KVM in the API
> choices here. I think the equivalent is the KVM_SET_USER_MEMORY_REGION
> ioctl for KVM which brings a section of the guest physical address space
> into the userspaces vaddr range.


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2022-09-01  6:29 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-24  1:42 Understanding osdep_xenforeignmemory_map mmap behaviour Stefano Stabellini
2022-03-24  5:12 ` Juergen Gross
2022-03-25 16:07   ` Alex Bennée
2022-03-28  6:26     ` Juergen Gross
2022-08-24  9:19   ` Viresh Kumar
2022-08-24  9:44     ` Andrew Cooper
2022-08-24 11:22       ` Alex Bennée
2022-08-24 13:07         ` Juergen Gross
2022-08-24 15:58           ` Alex Bennée
2022-08-25  6:02             ` Juergen Gross
2022-08-31 16:02               ` Alex Bennée
2022-09-01  6:28                 ` Juergen Gross
2022-08-24 10:09     ` Juergen Gross
2022-08-24 11:47       ` Alex Bennée
2022-08-24 13:14         ` Juergen Gross

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.