From patchwork Tue Apr 28 14:32:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 47673 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8F7B12121F for ; Tue, 28 Apr 2015 14:35:32 +0000 (UTC) Received: by layy10 with SMTP id y10sf34953651lay.0 for ; Tue, 28 Apr 2015 07:35:31 -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:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-post:list-help:list-subscribe:content-type :content-transfer-encoding:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:list-archive; bh=4A3Rawd7MWQMwn1wsXOWw/elHFuPqCSurk/fomGxTmo=; b=UfkfZ9OXvZweyd6J9cFpf4EzS6i4Qbh/ZfEefIqlkrCBbcyyrynFNEEabezZhTe2Rx SjUN3Mou2gti4GjfncdAv2/Ne2GwJFhK0srJk3LGkvEZVyAdJYT76n7OC8aShGUAchg0 wqXNcGPUdRGpC9Jd0vEGdJqa4UKXpzVJN1GfjnGxEYMewN62uAMMebFtdvr8qBtS7sWV tpVqame59GOoaTDVneskFVRVBkmuoERj7Pdg+DNWDYlepcbVVtMU7416g9KAoOxBTHwx 1jwJIUWF5K5xFlhX9v+O6q0+lZsF6TIOFeNBksVbrB3e/LJbmv1wSQxY4P5i20FJIsVp HbQw== X-Gm-Message-State: ALoCoQkDsRjuPmXXKyxI+j2rnfBajnsW89rMRLVe+K3drwbTqS2jTbW9KCcvq9xEO/AtqoS7w8aO X-Received: by 10.112.13.200 with SMTP id j8mr10390818lbc.14.1430231731547; Tue, 28 Apr 2015 07:35:31 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.121.98 with SMTP id lj2ls76960lab.94.gmail; Tue, 28 Apr 2015 07:35:31 -0700 (PDT) X-Received: by 10.152.179.39 with SMTP id dd7mr2523922lac.118.1430231731443; Tue, 28 Apr 2015 07:35:31 -0700 (PDT) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id t5si16622892lbb.35.2015.04.28.07.35.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Apr 2015 07:35:31 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by lbbuc2 with SMTP id uc2so108774288lbb.2 for ; Tue, 28 Apr 2015 07:35:31 -0700 (PDT) X-Received: by 10.152.4.137 with SMTP id k9mr14636499lak.29.1430231731316; Tue, 28 Apr 2015 07:35:31 -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.112.67.65 with SMTP id l1csp1924440lbt; Tue, 28 Apr 2015 07:35:30 -0700 (PDT) X-Received: by 10.52.33.132 with SMTP id r4mr36415760vdi.0.1430231728715; Tue, 28 Apr 2015 07:35:28 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id fn5si35241852vdc.51.2015.04.28.07.35.27 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 28 Apr 2015 07:35:28 -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 1Yn6Zm-0007lD-CI; Tue, 28 Apr 2015 14:33:30 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Yn6Zk-0007kL-Nm for xen-devel@lists.xenproject.org; Tue, 28 Apr 2015 14:33:28 +0000 Received: from [85.158.137.68] by server-10.bemta-3.messagelabs.com id 6D/7E-14673-73A9F355; Tue, 28 Apr 2015 14:33:27 +0000 X-Env-Sender: julien.grall@citrix.com X-Msg-Ref: server-12.tower-31.messagelabs.com!1430231605!20622706!2 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 6.13.6; banners=-,-,- X-VirusChecked: Checked Received: (qmail 14464 invoked from network); 28 Apr 2015 14:33:27 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-12.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 28 Apr 2015 14:33:27 -0000 X-IronPort-AV: E=Sophos;i="5.11,663,1422921600"; d="scan'208";a="259446283" From: Julien Grall To: Date: Tue, 28 Apr 2015 15:32:33 +0100 Message-ID: <1430231563-25648-10-git-send-email-julien.grall@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1430231563-25648-1-git-send-email-julien.grall@citrix.com> References: <1430231563-25648-1-git-send-email-julien.grall@citrix.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: stefano.stabellini@citrix.com, Julien Grall , tim@xen.org, ian.campbell@citrix.com Subject: [Xen-devel] [PATCH v6 09/19] xen/passthrough: iommu_deassign_device_dt: By default reassign device to nobody 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: , 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: patch@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.217.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: 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);