Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp522826ybk; Fri, 15 May 2020 06:56:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7JGh+ktheOAh7nH+Up+pjLZCSNrWuTHkOI2q8Cmyv7ghKbDv/M+nOUGZwnRfcFWUbOeXu X-Received: by 2002:a50:b044:: with SMTP id i62mr3065652edd.214.1589550960199; Fri, 15 May 2020 06:56:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589550960; cv=none; d=google.com; s=arc-20160816; b=XYiUmf6+6L39ifzw9RQ75IeeOyuhd9se98FUhq6UunIHZ9+XI99RCIgcWFI2dVY/II EjGAkPUT8r7GGiXxxEoY4d0kyAS6NZYlBfiFJjZHMCZTQ9V+CGzzv2M6cWrdNKYbI91B 2xSyWJiBIvn5zOQhwLae1J4bQpkFmzUmVwg6kEXB6ECT/2Rm+r+GND6vJURgsER9iZqL 5/Rzxk1mp7nQIe/04GJf4wMAbjILDNAutDYuJkajn8OqCOexOnnIGefRYHnPuRqS1DBt qjMClv7XTmZJPlSm+oXBoIdT6CXHYzvI++p+5bPDGjc5vm+YHnzvIwtxatTJJKyJuSkf D/5Q== 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:to:subject:cc:ironport-sdr:ironport-sdr; bh=PrRmKb3UeIAaAMrSexOqqn1uJ4cbfvMylqmob2J9uXA=; b=vl7/QobFfT62jxbvpdKngPVqZ/kTHo8wLVOppIE53ydqd8hPgca7W83el7za2r9HGj 1OlLTcAu2lYOhqpPRHfyOJ2bjIFHlabKhTcMzvLOfk3QERRjO6pJbbYkU8jTeYpS5VQP I/k9BE3IKqGoHSwzCLmZvYDs8C6QBjIrggUwW3UWX7BzKIS2LkrfrvWhZFZ9+OUGJ8Hz L5+2si6GNbJI3mtc5qjWvYkoyumYC+iry/ol8Gb5xiLxjieRZG/zz2YMgzA0390r5Jtt WWw+o9pmexutOwrtqf7Jdx06VgOrsDSdbvjIpnK6fx/xJ+UqoHTfbXVwUEsNM/r3FXHG qD2A== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a24si1361092ejg.46.2020.05.15.06.55.36; Fri, 15 May 2020 06:56:00 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726231AbgEONvF (ORCPT + 99 others); Fri, 15 May 2020 09:51:05 -0400 Received: from mga01.intel.com ([192.55.52.88]:31614 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726160AbgEONvF (ORCPT ); Fri, 15 May 2020 09:51:05 -0400 IronPort-SDR: yYWVSlOq3ZkEdRJl3wwscNCbm5hTnwumSYwJvrlwecQpH6jBelMhmvIoLHQhCtTU28F4fK7gHl wSV2Kwu8/OmQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2020 06:51:05 -0700 IronPort-SDR: HiRFDcklPJUOEKtJdITP/v5pcs/FB32XD6WuiHt534hfwqBnP30FDEEowsD0xUZlBDceKdBcVC 8Rtsgl1YWUfQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,395,1583222400"; d="scan'208";a="252383003" Received: from blu2-mobl3.ccr.corp.intel.com (HELO [10.249.171.19]) ([10.249.171.19]) by fmsmga007.fm.intel.com with ESMTP; 15 May 2020 06:51:03 -0700 Cc: baolu.lu@linux.intel.com, iommu@lists.linux-foundation.org, jroedel@suse.de, linux-kernel@vger.kernel.org, Tom Murphy Subject: Re: [PATCH] iommu: Implement deferred domain attachment To: Joerg Roedel References: <20200515094519.20338-1-joro@8bytes.org> From: Lu Baolu Message-ID: <8ce93a10-2ce0-e5a0-88a0-5d21d7003c0f@linux.intel.com> Date: Fri, 15 May 2020 21:51:03 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; 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-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Joerg, On 2020/5/15 17: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); It seems that the return value needs to be checked. The default domain is invalid if attach() failed. Best regards, baolu