From patchwork Thu Jul 31 15:00:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 34667 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5C96F20540 for ; Thu, 31 Jul 2014 15:02:44 +0000 (UTC) Received: by mail-lb0-f199.google.com with SMTP id 10sf1910498lbg.10 for ; Thu, 31 Jul 2014 08:02:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe:list-post :list-help:list-subscribe:mime-version:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :list-archive:content-type:content-transfer-encoding; bh=Td5PJZ5+yzeh5xTySLXiw6CEn3pK23mJdBuT2BQRKKQ=; b=mboJXi7GECYaz/RBjLMxvgQCXUz6/bi460bBTqkdfyK1ZoJ9P4qQ7fQc3BKYJCOfOu pfYQmaQj1W5CiCt++pbyIliSR3lt69jm1zwwkYzasdvNBuj38hfIbMOvDaz9GAduuJgb HgOri3Kt4Awhrn26SNgTgjUrl4Jax47+1lqfcHgae//hF14M4+FXdZzgnjv3dIYYDQ19 0D4lUPR8D8OVNCrtR5nk3xCgCo/PUcwUFvyulAF97PI+nrMr8rfkHRdcuJAWSYvruWbH 2EyqgdaQg2GahdbkgRsqmH3Pk6dk3yCcL541lFSHOVJc2QNhUc29lT/m9vQvTt5MnWey E9Lw== X-Gm-Message-State: ALoCoQmNgtN7l4pMHPVj1KGFgUt+PYl1C2DlJx6k+MxcPPAmJO7vRAB8ByslNyccVJ3+XTsCgg+p X-Received: by 10.112.33.116 with SMTP id q20mr930210lbi.6.1406818963077; Thu, 31 Jul 2014 08:02:43 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.95.68 with SMTP id h62ls948241qge.52.gmail; Thu, 31 Jul 2014 08:02:42 -0700 (PDT) X-Received: by 10.52.64.140 with SMTP id o12mr9794603vds.70.1406818962903; Thu, 31 Jul 2014 08:02:42 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id cu9si4635415vec.14.2014.07.31.08.02.40 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 31 Jul 2014 08:02:40 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id la4so4457146vcb.9 for ; Thu, 31 Jul 2014 08:02:40 -0700 (PDT) X-Received: by 10.52.120.38 with SMTP id kz6mr2540390vdb.86.1406818960594; Thu, 31 Jul 2014 08:02:40 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp25099vcb; Thu, 31 Jul 2014 08:02:40 -0700 (PDT) X-Received: by 10.70.124.234 with SMTP id ml10mr12972659pdb.106.1406818959568; Thu, 31 Jul 2014 08:02:39 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id tr4si41197841igb.7.2014.07.31.08.02.39 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 31 Jul 2014 08:02:39 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XCrrM-00014M-I4; Thu, 31 Jul 2014 15:01:36 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XCrrF-0000tU-Hx for xen-devel@lists.xenproject.org; Thu, 31 Jul 2014 15:01:29 +0000 Received: from [85.158.139.211:25002] by server-3.bemta-5.messagelabs.com id 65/B3-13873-84A5AD35; Thu, 31 Jul 2014 15:01:28 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-8.tower-206.messagelabs.com!1406818886!11119152!1 X-Originating-IP: [74.125.82.44] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 21824 invoked from network); 31 Jul 2014 15:01:26 -0000 Received: from mail-wg0-f44.google.com (HELO mail-wg0-f44.google.com) (74.125.82.44) by server-8.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 31 Jul 2014 15:01:26 -0000 Received: by mail-wg0-f44.google.com with SMTP id m15so2841580wgh.3 for ; Thu, 31 Jul 2014 08:01:25 -0700 (PDT) X-Received: by 10.180.88.167 with SMTP id bh7mr18447902wib.12.1406818885663; Thu, 31 Jul 2014 08:01:25 -0700 (PDT) Received: from belegaer.uk.xensource.com ([185.25.64.249]) by mx.google.com with ESMTPSA id r20sm67128337wik.0.2014.07.31.08.01.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 Jul 2014 08:01:24 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 31 Jul 2014 16:00:49 +0100 Message-Id: <1406818852-31856-19-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1406818852-31856-1-git-send-email-julien.grall@linaro.org> References: <1406818852-31856-1-git-send-email-julien.grall@linaro.org> Cc: ian.campbell@citrix.com, Stefano Stabellini , tim@xen.org, Julien Grall , Ian Jackson , stefano.stabellini@citrix.com Subject: [Xen-devel] [PATCH v2 18/21] xen/passthrough: dt: Add new domctl XEN_DOMCTL_assign_dt_device X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: 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 Cc: Ian Jackson Cc: Stefano Stabellini Cc: Ian Campbell --- 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 * Copyright (c) 2014 Linaro Limited. * @@ -20,6 +17,7 @@ #include #include +#include #include #include @@ -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;