Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp365971ybk; Fri, 15 May 2020 02:49:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHxIQUNcApOLxlNcrYJ/187icl4zpSfMz8qHMo/+E8RdfAhhhdozc47oYdu/Kag964Icl2 X-Received: by 2002:a05:6402:7ca:: with SMTP id u10mr1861454edy.322.1589536178786; Fri, 15 May 2020 02:49:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589536178; cv=none; d=google.com; s=arc-20160816; b=mk1iyU7j2bUoYb0z0DJAnl/KTFV92sMf0hlG7fyU7eD5kDXiJ/l72WjUkVApZG+0ie ITmp8or9vdFJ9ZMNfDxhBMlOXppDOPu27dbjI/tmYaMLlfQ/qo5YoL3dJKXfX4YC/5ju kAdHabkNSyqN8FVoXtAdg/TIw8lSp6GC2UHSh1pYubUeq/fkxGR1Orjj0NcnFEFcPR7g gMb4Dq5waFWtjXuhK2cRM+Q2RfsJ6ixgEOx2kZi59pF09i3+rPVDZ1ye+NWMKk5D0b10 orRn1SYyj+oA6YjHQchkx4b1Kz5gkitwlVsud5GZmLv4Q3rJE4U0GbI6UjYzuVJKrwsI Llgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=TYarkoCdFFwPv8alZGVJCxrDqnth307FABgMpM9wmN0=; b=bNj0+a4zSg/CSHmgVgxUAWOnujTtV5K497evekp4jxZ9W/Hiy2jjNN1YmwGeXhFT0Z mOzw1keczyBMoa+sVR6mWBQAP6eyZPEVtrkqJe9Ody7x2+Mlz7CKMErQGy6GmfqoglN9 EvOXEwZgwriyH3/Fi6lOoGFSrJaBwfmi2TO6nR1jKA5uL0eLnCb5U79y4qz3zRxFC0V8 N+TsmKOnd6s1KlCO+AsEuzMRLJfYaJ0KveEtz2QyY9usU8+vKl4IkDDOlqjmQDQPOXbI HjFDm+MuzqW8399it4aYTcewfSS1oNBHr9zHZF8D8Hdo7/oO1SIbmtNuV9NY7pQ76r3K IuHw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r21si896525ejb.162.2020.05.15.02.49.13; Fri, 15 May 2020 02:49:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727999AbgEOJpW (ORCPT + 99 others); Fri, 15 May 2020 05:45:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727116AbgEOJpW (ORCPT ); Fri, 15 May 2020 05:45:22 -0400 Received: from theia.8bytes.org (8bytes.org [IPv6:2a01:238:4383:600:38bc:a715:4b6d:a889]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BFF6C061A0C for ; Fri, 15 May 2020 02:45:22 -0700 (PDT) Received: by theia.8bytes.org (Postfix, from userid 1000) id 428AA379; Fri, 15 May 2020 11:45:20 +0200 (CEST) From: Joerg Roedel To: Joerg Roedel Cc: Tom Murphy , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, jroedel@suse.de, Jerry Snitselaar Subject: [PATCH] iommu: Implement deferred domain attachment Date: Fri, 15 May 2020 11:45:19 +0200 Message-Id: <20200515094519.20338-1-joro@8bytes.org> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel The IOMMU core code has support for deferring the attachment of a domain to a device. This is needed in kdump kernels where the new domain must not be attached to a device before the device driver takes it over. But this needs support from the dma-ops code too, to actually do the late attachment when there are DMA-API calls for the device. This got lost in the AMD IOMMU driver after converting it to the dma-iommu code. Do the late attachment in the dma-iommu code-path to fix the issue. Cc: Jerry Snitselaar Cc: Tom Murphy Reported-by: Jerry Snitselaar Tested-by: Jerry Snitselaar Fixes: be62dbf554c5 ("iommu/amd: Convert AMD iommu driver to the dma-iommu api") Signed-off-by: Joerg Roedel --- drivers/iommu/iommu.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 4050569188be..f54ebb964271 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1889,13 +1889,19 @@ void iommu_domain_free(struct iommu_domain *domain) } EXPORT_SYMBOL_GPL(iommu_domain_free); -static int __iommu_attach_device(struct iommu_domain *domain, - struct device *dev) +static bool __iommu_is_attach_deferred(struct iommu_domain *domain, + struct device *dev) +{ + if (!domain->ops->is_attach_deferred) + return false; + + return domain->ops->is_attach_deferred(domain, dev); +} + +static int __iommu_attach_device_no_defer(struct iommu_domain *domain, + struct device *dev) { int ret; - if ((domain->ops->is_attach_deferred != NULL) && - domain->ops->is_attach_deferred(domain, dev)) - return 0; if (unlikely(domain->ops->attach_dev == NULL)) return -ENODEV; @@ -1903,9 +1909,19 @@ static int __iommu_attach_device(struct iommu_domain *domain, ret = domain->ops->attach_dev(domain, dev); if (!ret) trace_attach_device_to_domain(dev); + return ret; } +static int __iommu_attach_device(struct iommu_domain *domain, + struct device *dev) +{ + if (__iommu_is_attach_deferred(domain, dev)) + return 0; + + return __iommu_attach_device_no_defer(domain, dev); +} + int iommu_attach_device(struct iommu_domain *domain, struct device *dev) { struct iommu_group *group; @@ -2023,7 +2039,12 @@ EXPORT_SYMBOL_GPL(iommu_get_domain_for_dev); */ struct iommu_domain *iommu_get_dma_domain(struct device *dev) { - return dev->iommu_group->default_domain; + struct iommu_domain *domain = dev->iommu_group->default_domain; + + if (__iommu_is_attach_deferred(domain, dev)) + __iommu_attach_device_no_defer(domain, dev); + + return domain; } /* -- 2.25.1