From patchwork Thu Mar 19 19:29:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 46110 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B288021515 for ; Thu, 19 Mar 2015 19:32:59 +0000 (UTC) Received: by wggx13 with SMTP id x13sf14064705wgg.0 for ; Thu, 19 Mar 2015 12:32:59 -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:content-type :content-transfer-encoding:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:list-archive; bh=ZU+cOANakEGUla7z+Egeo94O85xQegbqLd6kmGF/NVA=; b=MXRWS/OUSi2ufjClOs/wJil/ik2YEUf13gWeBGFdWuiB05j7GQuvnkIVngWU5pRaHj idcKvRdaPoKbbR5M4AIQLZGtzX1e5HNorDfApbS55MJBzcOm6tI6Tllc39qfgtv+d16Z j4CGcA6CCxXG8Lrtfc8mdzl5deikRza3CtBjGRjKUFh9hGPxzbwpG8KVHts0m84+036V 0IxVHhZsrw2hSHoHYNzj/QerubkgfVvovcNgaDPxHskIIoraALjXqfx9t4UA88VFneyH YUp3gcPGz9NsmoNfUIMsf/slz21kxI/OV1sG8yk5Yhp6lHoaE6TEIM2mTALhfYD0s4hH K3+Q== X-Gm-Message-State: ALoCoQkbEdUK0czj5rpTOB1dKCarhN3kOGeIwgu61kYc8kQkltBkK2cojFSUAmrc9IIAoxKa9oP+ X-Received: by 10.152.45.7 with SMTP id i7mr12364484lam.9.1426793578940; Thu, 19 Mar 2015 12:32:58 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.28.42 with SMTP id y10ls352732lag.71.gmail; Thu, 19 Mar 2015 12:32:58 -0700 (PDT) X-Received: by 10.112.110.231 with SMTP id id7mr70290257lbb.28.1426793578448; Thu, 19 Mar 2015 12:32:58 -0700 (PDT) Received: from mail-la0-f41.google.com (mail-la0-f41.google.com. [209.85.215.41]) by mx.google.com with ESMTPS id ju10si1613637lab.155.2015.03.19.12.32.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 12:32:58 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) client-ip=209.85.215.41; Received: by ladw1 with SMTP id w1so70598868lad.0 for ; Thu, 19 Mar 2015 12:32:58 -0700 (PDT) X-Received: by 10.152.22.67 with SMTP id b3mr68855524laf.117.1426793578196; Thu, 19 Mar 2015 12:32:58 -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.35.133 with SMTP id h5csp597857lbj; Thu, 19 Mar 2015 12:32:57 -0700 (PDT) X-Received: by 10.140.128.73 with SMTP id 70mr100058051qha.75.1426793557159; Thu, 19 Mar 2015 12:32:37 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id f22si2253760qkf.4.2015.03.19.12.32.36 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 19 Mar 2015 12:32:37 -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 1YYg9y-0004y9-PC; Thu, 19 Mar 2015 19:31:14 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YYg9w-0004rl-Im for xen-devel@lists.xenproject.org; Thu, 19 Mar 2015 19:31:12 +0000 Received: from [85.158.137.68] by server-12.bemta-3.messagelabs.com id 23/9B-32472-FF32B055; Thu, 19 Mar 2015 19:31:11 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-14.tower-31.messagelabs.com!1426793470!11395087!1 X-Originating-IP: [209.85.212.181] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.13.4; banners=-,-,- X-VirusChecked: Checked Received: (qmail 14829 invoked from network); 19 Mar 2015 19:31:10 -0000 Received: from mail-wi0-f181.google.com (HELO mail-wi0-f181.google.com) (209.85.212.181) by server-14.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 19 Mar 2015 19:31:10 -0000 Received: by wibg7 with SMTP id g7so15062554wib.1 for ; Thu, 19 Mar 2015 12:31:10 -0700 (PDT) X-Received: by 10.194.174.106 with SMTP id br10mr103985679wjc.21.1426793470636; Thu, 19 Mar 2015 12:31:10 -0700 (PDT) Received: from chilopoda.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id hl8sm3203005wjb.38.2015.03.19.12.31.09 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Mar 2015 12:31:09 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 19 Mar 2015 19:29:48 +0000 Message-Id: <1426793399-6283-23-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1426793399-6283-1-git-send-email-julien.grall@linaro.org> References: <1426793399-6283-1-git-send-email-julien.grall@linaro.org> Cc: ian.campbell@citrix.com, Julien Grall , tim@xen.org, Robert VanVossen , stefano.stabellini@citrix.com, Jan Beulich Subject: [Xen-devel] [PATCH v4 22/33] 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: , 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.215.41 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: 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 --- 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 7c5bf9f..7ebdce3 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -767,6 +767,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; /* Falltrough */ 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 */