From patchwork Thu Apr 9 15:09:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 46956 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4222021416 for ; Thu, 9 Apr 2015 15:14:49 +0000 (UTC) Received: by wgin8 with SMTP id n8sf17238988wgi.0 for ; Thu, 09 Apr 2015 08:14:48 -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=Q15CTzw4O8DcZy6efcGe0YlMUFoTgxdjKS9rxc0FEyHMWfeCqlEjbxIOTyAntpH8lf KDbXD2s7srKiG6m9MgY+3r73nmBauVFCuaCvZtTIho++g3tfrStDlIhfHSsbyGnMtiFv XIjhy8U+kQ2oYPqIGTCB/Ot/vdDkZXFlWwBtzCzyiH4abuCJND3QR9W0R2GImRbn/qvq JauX5oalQXEHbOcN6FeSGRhAsGZzmVDl+00a6M4HB46y52AmFDMuh3xvr8Jk+UVXcWLd qzmuUTszYqV5AmyrrAceJHzFVzi4b5hvQeN3X0A6zsJZmHaNiwMKGBVm+xPZ5TWj+650 NB7A== X-Gm-Message-State: ALoCoQn4ZIMChCaenGedTUzCD9kdTihJP5c6eMVO+s2S8BtsnZWmWQzW3BpQ52cb4y6+gclu+4xX X-Received: by 10.112.29.39 with SMTP id g7mr5904256lbh.1.1428592488552; Thu, 09 Apr 2015 08:14:48 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.8.1 with SMTP id n1ls283828laa.87.gmail; Thu, 09 Apr 2015 08:14:48 -0700 (PDT) X-Received: by 10.152.121.72 with SMTP id li8mr4761124lab.11.1428592488440; Thu, 09 Apr 2015 08:14:48 -0700 (PDT) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id sw10si968469lbb.158.2015.04.09.08.14.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Apr 2015 08:14:48 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by lbcga7 with SMTP id ga7so43965014lbc.1 for ; Thu, 09 Apr 2015 08:14:48 -0700 (PDT) X-Received: by 10.113.10.134 with SMTP id ea6mr23832050lbd.29.1428592488309; Thu, 09 Apr 2015 08:14:48 -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 l1csp533095lbt; Thu, 9 Apr 2015 08:14:47 -0700 (PDT) X-Received: by 10.52.115.132 with SMTP id jo4mr24086932vdb.43.1428592485351; Thu, 09 Apr 2015 08:14:45 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id f4si13293415vdf.7.2015.04.09.08.14.44 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 09 Apr 2015 08:14:45 -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 1YgE8m-00008d-8P; Thu, 09 Apr 2015 15:13:12 +0000 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 Received: from [85.158.139.211] by server-7.bemta-5.messagelabs.com id F6/A5-02028-60796255; Thu, 09 Apr 2015 15:13:10 +0000 X-Env-Sender: julien.grall@citrix.com X-Msg-Ref: server-7.tower-206.messagelabs.com!1428592386!14820383!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 6.13.6; banners=-,-,- X-VirusChecked: Checked Received: (qmail 31719 invoked from network); 9 Apr 2015 15:13:09 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-7.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 9 Apr 2015 15:13:09 -0000 X-IronPort-AV: E=Sophos;i="5.11,550,1422921600"; d="scan'208";a="251719358" From: Julien Grall To: Date: Thu, 9 Apr 2015 16:09:35 +0100 Message-ID: <1428592185-18581-10-git-send-email-julien.grall@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1428592185-18581-1-git-send-email-julien.grall@citrix.com> References: <1428592185-18581-1-git-send-email-julien.grall@citrix.com> MIME-Version: 1.0 X-DLP: MIA1 Cc: stefano.stabellini@citrix.com, Julien Grall , tim@xen.org, ian.campbell@citrix.com Subject: [Xen-devel] [PATCH v5 p2 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.169 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);