Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp600823ybk; Fri, 15 May 2020 08:46:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCI/S+SuVlad7XIGMRb37usu8dixq7yG3eCiNNo+Q20gEv+C1YtPeTtoDiA46ZhwTC5HBf X-Received: by 2002:a17:906:4356:: with SMTP id z22mr3283853ejm.334.1589557579323; Fri, 15 May 2020 08:46:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589557579; cv=none; d=google.com; s=arc-20160816; b=uhUObSy4jXg2RthjKzZDYP8xCNYXTqHI9eVdDpFDS+29nCSSm4j01RK2OIq3CM4lj8 OYerATHBQxynjTHuvwSqC8yAgHecj6/BURDH+5m3DtlNEB7TJRkYtaNtOdjGwFmO9iOl JC3vku1o5qqMowkzwRbo2T1OIUcvSqdtJqcg95Nk21+WQ5GyBimWX0Z7vkp+/HGeleIF oCtLwUCd0+sJP/4ufWOGPHlVgi7h+7/JoZYRXuNQZvs93pYh8M48qxIwHy4c1OianOAf TAC3jdz6fDIo2bOMuhZ0sV1NA7JIEIDUx8xxSDGdAx9iMAICPGmMuy0/ppO3hlB0engR oD8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=N2H4imHqcgwvcmEhBCm3hssQowgSvqeP2QmGJgkWoXY=; b=mZctrPdTJC1Zwu9wxGQRiS0eQYUrZuydkKsKODc/zLtgBQSbclT/2TqUZhJ7nJCauo PFpwY8Oyog0dR38/qDwTaEa0MyglnGS7UCezjR5DjCureX8DOx0Dez4OgXV8idcQT9/F xcFPv0QhV8XPcAM5BlMeYJytIQXpmdaiKZ1s17CEfCAIPNy+I5NXsa9b8uGzltKlOWI6 IWhdL9wsN4E7fL//VswNGKYpNjfM2RzdrRueOjvv+1Oaq3KOuGQcHaWtr3duWke7JfYG ptQJkypOYbANT4nLO92BvGSGCOwQ5Papj6hSqgTNYn7eHsjVshhdHe5I4Re1x+0dSKT/ Ssjw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p92si1337830edd.321.2020.05.15.08.45.55; Fri, 15 May 2020 08:46:19 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726532AbgEOPmZ (ORCPT + 99 others); Fri, 15 May 2020 11:42:25 -0400 Received: from foss.arm.com ([217.140.110.172]:58370 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726188AbgEOPmZ (ORCPT ); Fri, 15 May 2020 11:42:25 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BEA322F; Fri, 15 May 2020 08:42:24 -0700 (PDT) Received: from [10.57.27.64] (unknown [10.57.27.64]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E26903F71E; Fri, 15 May 2020 08:42:23 -0700 (PDT) Subject: Re: [PATCH] iommu: Implement deferred domain attachment To: Joerg Roedel Cc: iommu@lists.linux-foundation.org, jroedel@suse.de, linux-kernel@vger.kernel.org, Tom Murphy References: <20200515094519.20338-1-joro@8bytes.org> From: Robin Murphy Message-ID: Date: Fri, 15 May 2020 16:42:23 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200515094519.20338-1-joro@8bytes.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-05-15 10:45, Joerg Roedel wrote: > 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); This raises a red flag, since iommu-dma already has explicit deferred attach handling where it should need it, immediately after this is called to retrieve the domain. The whole thing smells to me like we should have an explicit special-case in iommu_probe_device() rather than hooking __iommu_attach_device() in general then having to bodge around the fallout elsewhere. Robin. > + > + return domain; > } > > /* >