From patchwork Mon Jun 16 16:18:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 31980 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f198.google.com (mail-ob0-f198.google.com [209.85.214.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A10A320E7A for ; Mon, 16 Jun 2014 16:20:01 +0000 (UTC) Received: by mail-ob0-f198.google.com with SMTP id uy5sf31911397obc.5 for ; Mon, 16 Jun 2014 09:20:01 -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=NoTBWGGfu7/nJt6JPgKdcgceXKVNIMqHhB8tX1PsRtA=; b=TPAVKVUZFPylHNptcKZCFpPp8hC7yblVNLBvFhCsF/bzpmyaH1Y+bf0z6u+FkcWBKj aWmfa8yF29Fcq9uNkBuznr/Vl0iJlFQszm9vVM7L5MOhlDHxUlJJkXYVqsEphfhoMvBs zB6+BBv6BI4s4SqaUfRM1WrWQT8V2KaA0PgrEPdL85S8SnvfwdxQwPGvKZehrW0O3bzM 3P8QQAbTEBc71xmyjxUHv6wkRse4bE3feNuy6GkRXVF9fwxi7tIZllsECpTNeao/IKFQ E/M9x4hc9PlOQavlaIMDq8/L6yOZcYwYRUcG0t8w+YZADtdgDFmOCmV3WO+zeuoUEsgL cnSg== X-Gm-Message-State: ALoCoQnLSRmn+RahXnt4gT+IAhbxUMvH14bBvAdPiDjzNYcsyl0V65kWS08qJgNsUMmA+UUQ1VAN X-Received: by 10.182.252.166 with SMTP id zt6mr1652325obc.17.1402935601257; Mon, 16 Jun 2014 09:20:01 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.85.138 with SMTP id n10ls4629788qgd.4.gmail; Mon, 16 Jun 2014 09:20:01 -0700 (PDT) X-Received: by 10.221.7.71 with SMTP id on7mr17052764vcb.18.1402935601099; Mon, 16 Jun 2014 09:20:01 -0700 (PDT) Received: from mail-ve0-f182.google.com (mail-ve0-f182.google.com [209.85.128.182]) by mx.google.com with ESMTPS id d9si4283898vcq.66.2014.06.16.09.20.01 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Jun 2014 09:20:01 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.182 as permitted sender) client-ip=209.85.128.182; Received: by mail-ve0-f182.google.com with SMTP id oy12so4407868veb.13 for ; Mon, 16 Jun 2014 09:20:01 -0700 (PDT) X-Received: by 10.220.53.72 with SMTP id l8mr17260690vcg.16.1402935601000; Mon, 16 Jun 2014 09:20:01 -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.54.6 with SMTP id vs6csp146159vcb; Mon, 16 Jun 2014 09:20:00 -0700 (PDT) X-Received: by 10.140.29.11 with SMTP id a11mr5641971qga.95.1402935600163; Mon, 16 Jun 2014 09:20:00 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id l65si10775360qge.91.2014.06.16.09.19.59 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 16 Jun 2014 09:20:00 -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 1WwZcF-0006tf-1M; Mon, 16 Jun 2014 16:18:39 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WwZcC-0006r2-Q5 for xen-devel@lists.xenproject.org; Mon, 16 Jun 2014 16:18:37 +0000 Received: from [193.109.254.147:32999] by server-8.bemta-14.messagelabs.com id E2/47-01877-BD81F935; Mon, 16 Jun 2014 16:18:35 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-14.tower-27.messagelabs.com!1402935514!11597505!1 X-Originating-IP: [209.85.212.171] 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 5642 invoked from network); 16 Jun 2014 16:18:35 -0000 Received: from mail-wi0-f171.google.com (HELO mail-wi0-f171.google.com) (209.85.212.171) by server-14.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 16 Jun 2014 16:18:35 -0000 Received: by mail-wi0-f171.google.com with SMTP id n15so4385982wiw.16 for ; Mon, 16 Jun 2014 09:18:34 -0700 (PDT) X-Received: by 10.180.105.68 with SMTP id gk4mr28961943wib.24.1402935514729; Mon, 16 Jun 2014 09:18:34 -0700 (PDT) Received: from belegaer.uk.xensource.com ([185.25.64.249]) by mx.google.com with ESMTPSA id l45sm34836161eep.25.2014.06.16.09.18.33 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Jun 2014 09:18:34 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 16 Jun 2014 17:18:01 +0100 Message-Id: <1402935486-29136-15-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1402935486-29136-1-git-send-email-julien.grall@linaro.org> References: <1402935486-29136-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] [RFC 14/19] 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.128.182 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 --- 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 7909536..ea8fc0d 100644 --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -1628,6 +1628,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 5ad2d65..07dcadc 100644 --- a/tools/libxc/xenctrl.h +++ b/tools/libxc/xenctrl.h @@ -2010,6 +2010,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 8a4bc69..9df4343 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 d71ab03..8351814 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 5b11bbf..66806d2 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -936,6 +936,14 @@ typedef struct xen_domctl_vcpu_msrs xen_domctl_vcpu_msrs_t; DEFINE_XEN_GUEST_HANDLE(xen_domctl_vcpu_msrs_t); #endif +/* 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 @@ -1008,6 +1016,7 @@ struct xen_domctl { #define XEN_DOMCTL_cacheflush 71 #define XEN_DOMCTL_get_vcpu_msrs 72 #define XEN_DOMCTL_set_vcpu_msrs 73 +#define XEN_DOMCTL_assign_dt_device 74 #define XEN_DOMCTL_gdbsx_guestmemio 1000 #define XEN_DOMCTL_gdbsx_pausevcpu 1001 #define XEN_DOMCTL_gdbsx_unpausevcpu 1002 @@ -1044,6 +1053,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 9b2af51..833baca 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;