[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 5 of 5] Add support for mapping grant references in HVM domains to unmodified_drivers/linux-2.6
# HG changeset patch # User Steven Smith <steven.smith@xxxxxxxxxxxxx> # Date 1242731493 -3600 # Node ID db464ab112d4b6095a966c09c7065c91f2d6930e # Parent c6126a51b5094529933790ba166778bfb8c3d9de Add support for mapping grant references in HVM domains to unmodified_drivers/linux-2.6. I've not tried to give it the same API as the PV grant map interface, because the underlying mechanism is too different for that to be very comfortable. Also add a couple of very simple modules to unmodified_drivers/linux-2.6 which can be used to test mapping grants into HVM domains. These are about as brain-dead as it's possible to be, but they do demonstrate the basic functionality. Signed-off-by: Steven Smith <steven.smith@xxxxxxxxxx> diff -r c6126a51b509 -r db464ab112d4 unmodified_drivers/linux-2.6/Makefile --- a/unmodified_drivers/linux-2.6/Makefile Tue May 19 12:11:33 2009 +0100 +++ b/unmodified_drivers/linux-2.6/Makefile Tue May 19 12:11:33 2009 +0100 @@ -5,3 +5,5 @@ obj-m += blkfront/ obj-m += netfront/ obj-m += scsifront/ + +obj-m += test-gntmap.o test-gntoffer.o diff -r c6126a51b509 -r db464ab112d4 unmodified_drivers/linux-2.6/platform-pci/Kbuild --- a/unmodified_drivers/linux-2.6/platform-pci/Kbuild Tue May 19 12:11:33 2009 +0100 +++ b/unmodified_drivers/linux-2.6/platform-pci/Kbuild Tue May 19 12:11:33 2009 +0100 @@ -7,7 +7,7 @@ xen-platform-pci-objs := evtchn.o platform-pci.o gnttab.o xen_support.o xen-platform-pci-objs += features.o platform-compat.o xen-platform-pci-objs += reboot.o machine_reboot.o -xen-platform-pci-objs += panic-handler.o +xen-platform-pci-objs += panic-handler.o gntmap.o xen-platform-pci-objs += ../xenbus/xenbus_comms.o xen-platform-pci-objs += ../xenbus/xenbus_xs.o diff -r c6126a51b509 -r db464ab112d4 unmodified_drivers/linux-2.6/platform-pci/gntmap.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/unmodified_drivers/linux-2.6/platform-pci/gntmap.c Tue May 19 12:11:33 2009 +0100 @@ -0,0 +1,56 @@ +#include <linux/module.h> +#include <linux/kernel.h> +#include <xen/interface/xen.h> +#include <xen/interface/grant_table.h> +#include <xen/interface/hvm/hvm_op.h> +#include <asm/hypervisor.h> + +#include "platform-pci.h" +#include "gntmap.h" + +int gntmap_map_grant(struct gntmap_detail *res, + domid_t domid, + grant_ref_t gref, + int readonly) +{ + unsigned long pa; + struct xen_hvm_map_grant_ref op; + int rc; + void *va; + + memset(res, 0, sizeof(*res)); + + pa = alloc_xen_mmio(PAGE_SIZE); + + va = ioremap(pa, PAGE_SIZE); + if (!va) + return -ENOMEM; + + op.domid = domid; + op.gref = gref; + op.pfn = pa >> PAGE_SHIFT; + op.flags = GNTMAP_host_map | (readonly ? GNTMAP_readonly : 0); + rc = HYPERVISOR_hvm_op(HVMOP_map_grant_ref, &op); + if (rc < 0) { + iounmap(va); + return rc; + } + res->phys_addr = pa; + res->handle = op.handle; + res->va = va; + return 0; +} + +void gntmap_unmap_grant(struct gntmap_detail *detail) +{ + struct xen_hvm_unmap_grant_ref op; + int rc; + + iounmap(detail->va); + op.handle = detail->handle; + rc = HYPERVISOR_hvm_op(HVMOP_unmap_grant_ref, &op); + BUG_ON(rc); +} + +EXPORT_SYMBOL_GPL(gntmap_map_grant); +EXPORT_SYMBOL_GPL(gntmap_unmap_grant); diff -r c6126a51b509 -r db464ab112d4 unmodified_drivers/linux-2.6/platform-pci/gntmap.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/unmodified_drivers/linux-2.6/platform-pci/gntmap.h Tue May 19 12:11:33 2009 +0100 @@ -0,0 +1,20 @@ +#ifndef GNTMAP_H__ +#define GNTMAP_H__ + +#include <xen/interface/xen.h> +#include <xen/interface/grant_table.h> + +struct gntmap_detail { + unsigned long phys_addr; + void *va; + grant_handle_t handle; +}; + +int gntmap_map_grant(struct gntmap_detail *res, + domid_t domid, + grant_ref_t gref, + int readonly); + +void gntmap_unmap_grant(struct gntmap_detail *detail); + +#endif /* !GNTMAP_H__ */ diff -r c6126a51b509 -r db464ab112d4 unmodified_drivers/linux-2.6/platform-pci/platform-pci.c --- a/unmodified_drivers/linux-2.6/platform-pci/platform-pci.c Tue May 19 12:11:33 2009 +0100 +++ b/unmodified_drivers/linux-2.6/platform-pci/platform-pci.c Tue May 19 12:11:33 2009 +0100 @@ -36,7 +36,9 @@ #include <asm/uaccess.h> #include <asm/hypervisor.h> #include <asm/pgtable.h> +#include <xen/interface/xen.h> #include <xen/interface/memory.h> +#include <xen/interface/grant_table.h> #include <xen/interface/hvm/params.h> #include <xen/features.h> #include <xen/evtchn.h> diff -r c6126a51b509 -r db464ab112d4 unmodified_drivers/linux-2.6/test-gntmap.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/unmodified_drivers/linux-2.6/test-gntmap.c Tue May 19 12:11:33 2009 +0100 @@ -0,0 +1,59 @@ +#include <linux/kernel.h> +#include <linux/module.h> +#include "platform-pci/gntmap.h" + +static int remote_domid; +static int remote_gref; +static int readonly; + +module_param(remote_domid, int, S_IRUGO); +module_param(remote_gref, int, S_IRUGO); +module_param(readonly, int, S_IRUGO); + +int +main(void) +{ + struct gntmap_detail detail; + int rc; + unsigned long *ptr; + unsigned x; + + rc = gntmap_map_grant(&detail, remote_domid, remote_gref, readonly); + if (rc < 0) { + printk(KERN_ERR "cannot map %d::%d, readonly %d\n", + remote_domid, remote_gref, readonly); + return rc; + } + ptr = detail.va; + for (x = 0; x < PAGE_SIZE / sizeof(unsigned long);) { +#if BITS_PER_LONG == 32 + printk(KERN_INFO + "%08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n", + ptr[x], + ptr[x+1], + ptr[x+2], + ptr[x+3], + ptr[x+4], + ptr[x+5], + ptr[x+6], + ptr[x+7]); + x += 8; +#else + printk(KERN_INFO + "%016lx %016lx %016lx %016lx\n", + ptr[x], + ptr[x+1], + ptr[x+2], + ptr[x+3]); + x += 4; +#endif + } + gntmap_unmap_grant(&detail); + + /* Make the load fail */ + return -EINVAL; +} + +module_init(main); + +MODULE_LICENSE("GPL"); diff -r c6126a51b509 -r db464ab112d4 unmodified_drivers/linux-2.6/test-gntoffer.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/unmodified_drivers/linux-2.6/test-gntoffer.c Tue May 19 12:11:33 2009 +0100 @@ -0,0 +1,36 @@ +#include <linux/kernel.h> +#include <linux/module.h> + +#include <xen/interface/xen.h> +#include <xen/interface/grant_table.h> +#include <xen/gnttab.h> + +static int remote_domid; +module_param(remote_domid, int, S_IRUGO); + +static int gref; +static void *buf; + +int main(void) +{ + buf = (void *)get_zeroed_page(GFP_KERNEL); + if (!buf) { + printk(KERN_ERR "can't get a free page\n"); + return -ENOMEM; + } + memset(buf, 0x92, PAGE_SIZE); + gref = gnttab_grant_foreign_access(remote_domid, virt_to_mfn(buf), 0); + printk(KERN_INFO "gref is %d\n", gref); + return 0; +} + +void finish(void) +{ + gnttab_end_foreign_access(gref, 0); + free_page((unsigned long)buf); +} + +module_init(main); +module_exit(finish); + +MODULE_LICENSE("GPL"); _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |