From mboxrd@z Thu Jan 1 00:00:00 1970 From: Julien Grall Subject: [PATCH v5 p2 09/19] xen/passthrough: iommu_deassign_device_dt: By default reassign device to nobody Date: Thu, 9 Apr 2015 16:09:35 +0100 Message-ID: <1428592185-18581-10-git-send-email-julien.grall@citrix.com> References: <1428592185-18581-1-git-send-email-julien.grall@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YgE8k-00008N-PA for xen-devel@lists.xenproject.org; Thu, 09 Apr 2015 15:13:10 +0000 In-Reply-To: <1428592185-18581-1-git-send-email-julien.grall@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: stefano.stabellini@citrix.com, Julien Grall , tim@xen.org, ian.campbell@citrix.com List-Id: xen-devel@lists.xenproject.org From: Julien Grall Currently, when the device is deassigned from a domain, we directly reassign to DOM0. As the device may not have been correctly reset, this may lead to corruption or expose some part of DOM0 memory. Also, we may have no way to reset some platform devices. If Xen reassigns the device to "nobody", it may receive some global/context fault because the transaction has failed (indeed the context has been marked invalid). Unfortunately there is no simple way to quiesce a buggy hardware. I think we could live with that for a first version of platform device passthrough. DOM0 will have to issue an hypercall to assign the device to itself if it wants to use it. Signed-off-by: Julien Grall Acked-by: Stefano Stabellini Acked-by: Ian Campbell --- Note: This behavior is documented in a following patch which extend DOMCT_*assign_device to support non-PCI passthrough. Changes in v5: - Add Ian's ack Changes in v4: - Add Stefano's ack Changes in v3: - Use the coding style of the new SMMU drivers Changes in v2: - Fix typoes in the commit message - Update commit message --- xen/drivers/passthrough/arm/smmu.c | 8 +++++++- xen/drivers/passthrough/device_tree.c | 9 +++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c index 8a9b58b..65de50b 100644 --- a/xen/drivers/passthrough/arm/smmu.c +++ b/xen/drivers/passthrough/arm/smmu.c @@ -2692,7 +2692,7 @@ static int arm_smmu_reassign_dev(struct domain *s, struct domain *t, int ret = 0; /* Don't allow remapping on other domain than hwdom */ - if (t != hardware_domain) + if (t && t != hardware_domain) return -EPERM; if (t == s) @@ -2702,6 +2702,12 @@ static int arm_smmu_reassign_dev(struct domain *s, struct domain *t, if (ret) return ret; + if (t) { + ret = arm_smmu_assign_dev(t, devfn, dev); + if (ret) + return ret; + } + return 0; } diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index 05ab274..0ec4103 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -80,15 +80,12 @@ int iommu_deassign_dt_device(struct domain *d, struct dt_device_node *dev) spin_lock(&dtdevs_lock); - rc = hd->platform_ops->reassign_device(d, hardware_domain, - 0, dt_to_dev(dev)); + rc = hd->platform_ops->reassign_device(d, NULL, 0, dt_to_dev(dev)); if ( rc ) goto fail; - list_del(&dev->domain_list); - - dt_device_set_used_by(dev, hardware_domain->domain_id); - list_add(&dev->domain_list, &domain_hvm_iommu(hardware_domain)->dt_devices); + list_del_init(&dev->domain_list); + dt_device_set_used_by(dev, DOMID_IO); fail: spin_unlock(&dtdevs_lock); -- 2.1.4