xen: add new hypercall buffer mapping device
Juergen Gross
maintainerPATCH v2 1/1 xen: add new hypercall buffer mapping device
For passing arbitrary data from user land to the Xen hypervisor the Xen tools today are using mlock()ed buffers. Unfortunately the kernel might change access rights of such buffers for brief periods of time e.g. for page migration or compaction, leading to access faults in the hypervisor, as the hypervisor can't use the locks of the kernel.
In order to solve this problem add a new device node to the Xen privcmd driver to easily allocate hypercall buffers via mmap(). The memory is allocated in the kernel and just mapped into user space. Marked as VM_IO the user mapping will not be subject to page migration et al.
---
V2:
- don't add new node to xenfs (Andrew Cooper)
- use unsigned long for page count (Andrew Cooper)
- drop DONTDUMP flag from vma (Andrew Cooper)
- rename node to "xen/hypercall" (Andrew Cooper)
- modify limit to unsigned int (Jan Beulich)
- drop error messages (Jan Beulich)
- change errno returned (Boris Ostrovsky)
--- drivers/xen/Makefile | 2 +- drivers/xen/privcmd-buf.c | 210 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/xen/privcmd.c | 9 ++ drivers/xen/privcmd.h | 3 + 4 files changed, 223 insertions(+), 1 deletion(-) create mode 100644 drivers/xen/privcmd-buf.c
drivers/xen/Makefile +1 -1
@@ -41,4 +41,4 @@ obj-$(CONFIG_XEN_PVCALLS_FRONTEND) += pvcalls-front.o xen-evtchn-y := evtchn.o xen-gntdev-y := gntdev.o xen-gntalloc-y := gntalloc.o -xen-privcmd-y := privcmd.o +xen-privcmd-y := privcmd.o privcmd-buf.o
drivers/xen/privcmd-buf.c new file +210 -0
210 lines not on this page · raw message
drivers/xen/privcmd.c +9 -0
@@ -1007,12 +1007,21 @@ static int __init privcmd_init(void)pr_err ("Could not register Xen privcmd device\n" );return err; } + + err =misc_register (&xen_privcmdbuf_dev); +if (err !=0 ) { +pr_err ("Could not register Xen hypercall-buf device\n" ); +misc_deregister (&privcmd_dev); +return err; + } +return 0 ; } static void __exit privcmd_exit(void) {misc_deregister (&privcmd_dev); +misc_deregister (&xen_privcmdbuf_dev); }module_init (privcmd_init);
drivers/xen/privcmd.h +3 -0
@@ -1,3 +1,6 @@#include <linux/fs.h> extern const struct file_operations xen_privcmd_fops; +extern const struct file_operations xen_privcmdbuf_fops; + +extern struct miscdevice xen_privcmdbuf_dev;
Signature · 1 line
2.13.7
drivers/xen/privcmd-buf.c line 149
Quoted 9 lines · Juergen Gross
drivers/xen/privcmd-buf.c new file +9
-0+static int privcmd_buf_mmap (struct file *file,struct vm_area_struct *vma) +{ +struct privcmd_buf_private *file_priv = file->private_data; +struct privcmd_buf_vma_private *vma_priv; +unsigned long count =vma_pages (vma); +unsigned int i; +int ret =0 ; + + if (!(vma->vm_flags & VM_SHARED) || count > (unsigned long)limit ||
You don't need the unsigned long cast, as limit will be promoted automatically.
Otherwise, LGTM.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 6 lines · Juergen Gross
For passing arbitrary data from user land to the Xen hypervisor the Xen tools today are using mlock()ed buffers. Unfortunately the kernel might change access rights of such buffers for brief periods of time e.g. for page migration or compaction, leading to access faults in the hypervisor, as the hypervisor can't use the locks of the kernel.
Quoted 6 lines
In order to solve this problem add a new device node to the Xen privcmd driver to easily allocate hypercall buffers via
mmap(). The memory is allocated in the kernel and just mapped into user space. Marked asVM_IOthe user mapping will not be subject to page migration et al.Signed-off-by Juergen Gross <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 6 lines · Juergen Gross
For passing arbitrary data from user land to the Xen hypervisor the Xen tools today are using mlock()ed buffers. Unfortunately the kernel might change access rights of such buffers for brief periods of time e.g. for page migration or compaction, leading to access faults in the hypervisor, as the hypervisor can't use the locks of the kernel.
Quoted 6 lines
In order to solve this problem add a new device node to the Xen privcmd driver to easily allocate hypercall buffers via
mmap(). The memory is allocated in the kernel and just mapped into user space. Marked asVM_IOthe user mapping will not be subject to page migration et al.Signed-off-by Juergen Gross <[email protected]>