From patchwork Tue Apr 28 14:32:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 47671 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4B78B2121F for ; Tue, 28 Apr 2015 14:34:46 +0000 (UTC) Received: by wicmx19 with SMTP id mx19sf6306461wic.3 for ; Tue, 28 Apr 2015 07:34:45 -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=X790znZuu+37aSYucph+cU6fChaVHWq0jTehiNsihz8=; b=lrJ205wkATHjkWdoOVZQ6tE+dScUoGI9RMQDP7Yk+6AiJAIuRFd/ublDHLc7eCgVMx eMaN7V2MlQKsXFCClPp5oKch+p/Rr4RURCkC9um0MCbVoMS52AGKlfAwG9NA+PSHalTA l7gqZW5Dt1LZHSmSLvBPkWn4FjqxSAWNW0K4TX1ZV/a5+KoFj2u9f5h7nJUAJ0w+dDhn ZbOnOUmwVikqQhI7IrQsoMy49SPVn7boCNwTPxxydFs4D03XtoW9m5rI/VgpOWkqYoHX i0Zwzgy2BvmUv1Hrbgs262VEGldTJ0MrmJfEpi/RQuIRrvcpUyJWUliXULKVoZLmF7j9 GV3g== X-Gm-Message-State: ALoCoQmCz5tMfycxlmu+Z/6GSQ80rrottZblawtnCZ3DuZIfMHW3VPNgBaJ4W9ohSy4laQLKvVgP X-Received: by 10.112.28.111 with SMTP id a15mr10403730lbh.21.1430231685520; Tue, 28 Apr 2015 07:34:45 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.225.134 with SMTP id rk6ls84268lac.83.gmail; Tue, 28 Apr 2015 07:34:45 -0700 (PDT) X-Received: by 10.152.20.39 with SMTP id k7mr14790846lae.3.1430231685318; Tue, 28 Apr 2015 07:34:45 -0700 (PDT) Received: from mail-lb0-f175.google.com (mail-lb0-f175.google.com. [209.85.217.175]) by mx.google.com with ESMTPS id ll7si11667251lac.46.2015.04.28.07.34.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Apr 2015 07:34:45 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.175 as permitted sender) client-ip=209.85.217.175; Received: by lbcga7 with SMTP id ga7so108940396lbc.1 for ; Tue, 28 Apr 2015 07:34:45 -0700 (PDT) X-Received: by 10.112.150.100 with SMTP id uh4mr14544400lbb.112.1430231684419; Tue, 28 Apr 2015 07:34:44 -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 l1csp1924051lbt; Tue, 28 Apr 2015 07:34:43 -0700 (PDT) X-Received: by 10.236.198.237 with SMTP id v73mr23362481yhn.54.1430231679650; Tue, 28 Apr 2015 07:34:39 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id z4si35242932vdh.68.2015.04.28.07.34.38 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 28 Apr 2015 07:34: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 1Yn6Zo-0007mN-W3; Tue, 28 Apr 2015 14:33:32 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Yn6Zn-0007lX-GN for xen-devel@lists.xenproject.org; Tue, 28 Apr 2015 14:33:31 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id 8D/4C-26324-A3A9F355; Tue, 28 Apr 2015 14:33:30 +0000 X-Env-Sender: julien.grall@citrix.com X-Msg-Ref: server-8.tower-31.messagelabs.com!1430231608!20720319!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 10560 invoked from network); 28 Apr 2015 14:33:29 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-8.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 28 Apr 2015 14:33:29 -0000 X-IronPort-AV: E=Sophos;i="5.11,663,1422921600"; d="scan'208";a="257345547" From: Julien Grall To: Date: Tue, 28 Apr 2015 15:32:32 +0100 Message-ID: <1430231563-25648-9-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: ian.campbell@citrix.com, Julien Grall , tim@xen.org, Robert VanVossen , stefano.stabellini@citrix.com, Jan Beulich Subject: [Xen-devel] [PATCH v6 08/19] xen/passthrough: arm: release the DT devices assigned to a guest earlier 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.175 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 The toolstack may not have deassigned every device used by a guest. Therefore we have to go through the device list and remove them before asking the IOMMU drivers to release memory for this domain. This can be done by moving the call to the release function when we relinquish the resources. The IOMMU part will be destroyed later when the domain is freed. Signed-off-by: Julien Grall Signed-off-by: Robert VanVossen Acked-by: Jan Beulich Acked-by: Ian Campbell --- Changes in v5: - Add Ian's ack Changes in v4: - Typoes in commit message - Add Jan's ack - iommu_release_dt_devices was only release the first device by mistake. Thanks for Robert VanVossen for spotting it. Changes in v3: - Patch added. Superseed the patch "xen/passthrough: call arch_iommu_domain_destroy before calling iommu teardown" in the previous patch series. --- xen/arch/arm/domain.c | 4 ++++ xen/drivers/passthrough/arm/iommu.c | 1 - xen/drivers/passthrough/device_tree.c | 7 ++++++- xen/include/xen/iommu.h | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 180bccc..24b8938 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -795,6 +795,10 @@ int domain_relinquish_resources(struct domain *d) switch ( d->arch.relmem ) { case RELMEM_not_started: + ret = iommu_release_dt_devices(d); + if ( ret ) + return ret; + d->arch.relmem = RELMEM_xen; /* Fallthrough */ diff --git a/xen/drivers/passthrough/arm/iommu.c b/xen/drivers/passthrough/arm/iommu.c index 9234657..95b1abb 100644 --- a/xen/drivers/passthrough/arm/iommu.c +++ b/xen/drivers/passthrough/arm/iommu.c @@ -66,7 +66,6 @@ int arch_iommu_domain_init(struct domain *d) void arch_iommu_domain_destroy(struct domain *d) { - iommu_dt_domain_destroy(d); } int arch_iommu_populate_page_table(struct domain *d) diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index 4d82a09..05ab274 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -105,7 +105,7 @@ int iommu_dt_domain_init(struct domain *d) return 0; } -void iommu_dt_domain_destroy(struct domain *d) +int iommu_release_dt_devices(struct domain *d) { struct hvm_iommu *hd = domain_hvm_iommu(d); struct dt_device_node *dev, *_dev; @@ -115,7 +115,12 @@ void iommu_dt_domain_destroy(struct domain *d) { rc = iommu_deassign_dt_device(d, dev); if ( rc ) + { dprintk(XENLOG_ERR, "Failed to deassign %s in domain %u\n", dt_node_full_name(dev), d->domain_id); + return rc; + } } + + return 0; } diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index e9d2d5c..d9c9ede 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -117,7 +117,7 @@ void iommu_read_msi_from_ire(struct msi_desc *msi_desc, struct msi_msg *msg); int iommu_assign_dt_device(struct domain *d, struct dt_device_node *dev); 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_release_dt_devices(struct domain *d); #endif /* HAS_DEVICE_TREE */