From patchwork Thu Apr 9 15:09:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 46957 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C1A3021416 for ; Thu, 9 Apr 2015 15:15:34 +0000 (UTC) Received: by wixv7 with SMTP id v7sf18213574wix.0 for ; Thu, 09 Apr 2015 08:15:34 -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=ky0i1sJ12m9Gib+u+3RePfwCcspM8Jbu2CS1LA1hlDyx6ad1tER6CU6iHRZoy6aZMG yucUr0QpZhUBps+VdFICvCHEJNmC+1KH22ZzCm5QURxeBmItCFFMBe/+xsB16khIZFPZ 4p6+GmwQ5WNSi15jX+6FwIgw4LVX691N0iI/F3JbcPrW1UIBQ0Hexe3thofAdqq+7Tl4 1Ba7sCNXfgppX1PuSbO7P2fQWAE2niq5zoiK4URy+TIwENWIQHzJyquDvshp/1Kdd9jO nYZ5A8dXWFJNgqYdIfsB+oi/tZ8moeFaIDRsSpxWYqt0a2ZVV8DYXXNDcbUz8c+1pTd3 NWZQ== X-Gm-Message-State: ALoCoQmNXUp0d1vOIK/6gaYMVny50xS+wcpWccNxqEy/6dtpd8eMmaTmhfMvy4b9djo9Yf30iriX X-Received: by 10.113.11.3 with SMTP id ee3mr3887634lbd.9.1428592534068; Thu, 09 Apr 2015 08:15:34 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.181.5 with SMTP id ds5ls356935lac.20.gmail; Thu, 09 Apr 2015 08:15:33 -0700 (PDT) X-Received: by 10.112.90.201 with SMTP id by9mr27888766lbb.30.1428592533961; Thu, 09 Apr 2015 08:15:33 -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 k3si8643401laf.146.2015.04.09.08.15.33 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Apr 2015 08:15:33 -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 lbcga7 with SMTP id ga7so43982721lbc.1 for ; Thu, 09 Apr 2015 08:15:33 -0700 (PDT) X-Received: by 10.152.234.169 with SMTP id uf9mr4908053lac.88.1428592533866; Thu, 09 Apr 2015 08:15:33 -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 l1csp533528lbt; Thu, 9 Apr 2015 08:15:32 -0700 (PDT) X-Received: by 10.55.56.20 with SMTP id f20mr59712259qka.100.1428592530895; Thu, 09 Apr 2015 08:15:30 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id f53si7488563qge.68.2015.04.09.08.15.30 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 09 Apr 2015 08:15:30 -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 1YgE9j-0000JH-5W; Thu, 09 Apr 2015 15:14:11 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YgE9i-0000Ii-2m for xen-devel@lists.xenproject.org; Thu, 09 Apr 2015 15:14:10 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id 31/EC-26324-14796255; Thu, 09 Apr 2015 15:14:09 +0000 X-Env-Sender: julien.grall@citrix.com X-Msg-Ref: server-11.tower-31.messagelabs.com!1428592446!15086826!1 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 28348 invoked from network); 9 Apr 2015 15:14:08 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-11.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 9 Apr 2015 15:14:08 -0000 X-IronPort-AV: E=Sophos;i="5.11,550,1422921600"; d="scan'208";a="253565305" From: Julien Grall To: Date: Thu, 9 Apr 2015 16:09:34 +0100 Message-ID: <1428592185-18581-9-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: MIA2 Cc: ian.campbell@citrix.com, Julien Grall , tim@xen.org, Robert VanVossen , stefano.stabellini@citrix.com, Jan Beulich Subject: [Xen-devel] [PATCH v5 p2 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.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 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 */