[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v2 18/21] xen/passthrough: dt: Add new domctl XEN_DOMCTL_assign_dt_device
A device node is described by a path. It will be used to retrieved the node in the device tree and assign the related device to the domain. Only device protected by an IOMMU can be assigned to a guest. Signed-off-by: Julien Grall <julien.grall@xxxxxxxxxx> Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> Cc: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx> Cc: Ian Campbell <ian.campbell@xxxxxxxxxx> --- Changes in v2: - Use a different number for XEN_DOMCTL_assign_dt_device --- tools/libxc/xc_domain.c | 29 +++++++++++++++++++++ tools/libxc/xenctrl.h | 4 +++ xen/drivers/passthrough/device_tree.c | 45 ++++++++++++++++++++++++++++++--- xen/drivers/passthrough/iommu.c | 7 +++++ xen/include/public/domctl.h | 10 ++++++++ xen/include/xen/iommu.h | 3 +++ 6 files changed, 95 insertions(+), 3 deletions(-) diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c index 4cc0474..08b6f02 100644 --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -1677,6 +1677,35 @@ int xc_deassign_device( return do_domctl(xch, &domctl); } +int xc_assign_dt_device( + xc_interface *xch, + uint32_t domid, + char *path) +{ + int rc; + size_t size = strlen(path); + xen_domctl_assign_dt_device_t *assign_dt_device; + DECLARE_DOMCTL; + DECLARE_HYPERCALL_BOUNCE(path, size, XC_HYPERCALL_BUFFER_BOUNCE_IN); + + if ( xc_hypercall_bounce_pre(xch, path) ) + return -1; + + domctl.cmd = XEN_DOMCTL_assign_dt_device; + domctl.domain = (domid_t)domid; + + assign_dt_device = &domctl.u.assign_dt_device; + + assign_dt_device->size = size; + set_xen_guest_handle(assign_dt_device->path, path); + + rc = do_domctl(xch, &domctl); + + xc_hypercall_bounce_post(xch, path); + + return rc; +} + int xc_domain_update_msi_irq( xc_interface *xch, uint32_t domid, diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h index c549753..bd24e1d 100644 --- a/tools/libxc/xenctrl.h +++ b/tools/libxc/xenctrl.h @@ -2071,6 +2071,10 @@ int xc_deassign_device(xc_interface *xch, uint32_t domid, uint32_t machine_bdf); +int xc_assign_dt_device(xc_interface *xch, + uint32_t domid, + char *path); + int xc_domain_memory_mapping(xc_interface *xch, uint32_t domid, unsigned long first_gfn, diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index f8affa0..232159a 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -1,9 +1,6 @@ /* * Code to passthrough a device tree node to a guest * - * TODO: This contains only the necessary code to protected device passed to - * dom0. It will need some updates when device passthrough will is added. - * * Julien Grall <julien.grall@xxxxxxxxxx> * Copyright (c) 2014 Linaro Limited. * @@ -20,6 +17,7 @@ #include <xen/lib.h> #include <xen/sched.h> +#include <xen/guest_access.h> #include <xen/iommu.h> #include <xen/device_tree.h> @@ -111,3 +109,44 @@ void iommu_dt_domain_destroy(struct domain *d) dt_node_full_name(dev), d->domain_id); } } + +int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, + XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) +{ + int ret; + + /* TODO: How to deal with XSM? */ + + switch ( domctl->cmd ) + { + case XEN_DOMCTL_assign_dt_device: + { + struct dt_device_node *dev; + + + /* TODO: Do we need to check is_dying? Mostly to protect against + * hypercall trying to passthrough a device while we are + * dying. + */ + + ret = dt_find_node_by_gpath(domctl->u.assign_dt_device.path, + domctl->u.assign_dt_device.size, + &dev); + if ( ret ) + break; + + ret = iommu_assign_dt_device(d, dev); + + if ( ret ) + printk(XENLOG_G_ERR "XEN_DOMCTL_assign_dt_device: assign \"%s\"" + " to dom%u failed (%d)\n", + dt_node_full_name(dev), d->domain_id, ret); + } + break; + default: + ret = -ENOSYS; + break; + } + + return ret; +} diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c index 2953ede..5507c93 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -343,6 +343,13 @@ int iommu_do_domctl( ret = iommu_do_pci_domctl(domctl, d, u_domctl); #endif + if ( ret != -ENOSYS ) + return ret; + +#ifdef HAS_DEVICE_TREE + ret = iommu_do_dt_domctl(domctl, d, u_domctl); +#endif + return ret; } diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index f7bad9b..8c4d4c5 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -984,6 +984,14 @@ struct xen_domctl_dtdev_op { typedef struct xen_domctl_dtdev_op xen_domctl_dtdev_op_t; DEFINE_XEN_GUEST_HANDLE(xen_domctl_dtdev_op_t); +/* Device Tree: Assign a non-PCI device to a guest */ +struct xen_domctl_assign_dt_device { + uint32_t size; /* IN: Length of the path */ + XEN_GUEST_HANDLE_64(char) path; /* IN: path to the device tree node */ +}; +typedef struct xen_domctl_assign_dt_device xen_domctl_assign_dt_device_t; +DEFINE_XEN_GUEST_HANDLE(xen_domctl_assign_dt_device_t); + struct xen_domctl { uint32_t cmd; #define XEN_DOMCTL_createdomain 1 @@ -1058,6 +1066,7 @@ struct xen_domctl { #define XEN_DOMCTL_set_vcpu_msrs 73 #define XEN_DOMCTL_configure_domain 74 #define XEN_DOMCTL_dtdev_op 75 +#define XEN_DOMCTL_assign_dt_device 76 #define XEN_DOMCTL_gdbsx_guestmemio 1000 #define XEN_DOMCTL_gdbsx_pausevcpu 1001 #define XEN_DOMCTL_gdbsx_unpausevcpu 1002 @@ -1097,6 +1106,7 @@ struct xen_domctl { struct xen_domctl_sendtrigger sendtrigger; struct xen_domctl_get_device_group get_device_group; struct xen_domctl_assign_device assign_device; + struct xen_domctl_assign_dt_device assign_dt_device; struct xen_domctl_bind_pt_irq bind_pt_irq; struct xen_domctl_memory_mapping memory_mapping; struct xen_domctl_ioport_mapping ioport_mapping; diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 8dc7bd2..6dd2670 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -118,6 +118,9 @@ int iommu_deassign_dt_device(struct domain *d, struct dt_device_node *dev); int iommu_dt_domain_init(struct domain *d); void iommu_dt_domain_destroy(struct domain *d); +int iommu_do_dt_domctl(struct xen_domctl *, struct domain *, + XEN_GUEST_HANDLE_PARAM(xen_domctl_t)); + #endif /* HAS_DEVICE_TREE */ struct page_info; -- 1.7.10.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |