Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6689060pxv; Thu, 29 Jul 2021 23:10:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFxRLWPtf6egZrM7Lj/fgHM5jaBNYgPdDO1omywfd1rfn4wYIeM/0SD2CdACDfxiBIESAk X-Received: by 2002:a05:6602:2406:: with SMTP id s6mr286554ioa.159.1627625402317; Thu, 29 Jul 2021 23:10:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627625402; cv=none; d=google.com; s=arc-20160816; b=hKmWaUW5bGPr1/B4D4gHcpHdkxIoNOXBpgB+uM497jZceAa4m/iICuZmkd6s1ydXOB XvbzYfeUlNygtxkD2LCeHkDGPVYeI5NQRACtOBJRqLXmGt+9QUVIiAw+vjGrWd0kNiqh kzZzhKyqsJhnYjMT5j7SOuCad8pHkhILBQ1JCxmOm/Zeiz4IGkWtwKh/0iklzMQ1hIAd OHnZQk/ZX6TYba4vGtuq2wzD/P5euhDjikY+yy3SOQloSz1WGV5JF59e+mxWeFtN0LZo T3WnpFR+9e6OcYhz6lcqilX9C8vdre6vYw30rzj/6GRPLvouG7LDyIDzHuSRyCsCLXLA chEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :to:subject:cc; bh=EVnEyDHV3qbx67/lopXosIAXmTGo2Hq5xZ3rPFIR3iY=; b=sSXNlbXgXB2iZ1jrEVOrgtXkvWmt0MThDKwPsutHMDRJcHOHL2eq2RP14/ZPVzhr6e Dj24xGdb/eHtCdSG2GWVzY+YqcX7p7Qoc4NDPPnNoVVlegfZJiN9jm0PD2qyY6N5xdNT 0VLVHanQNjopiBZqhHrUsWNL0Qn6c/XHV03NWaT3Qd6Ezis0Tfwi7jbIvCVnS0pr4PJN qrdqNz0YyVnpS77oB/HCFcCfA7sXfwBYjR+9nusJNnVzhJTpFd9tYnGmKn+607Bc3jjH fgFyr48XkNmEljOCp+OuzI7A3M8NCztrhxkBlNAuI0pppeso4ZWzxHweSu53ij7i6j6O hJ5g== 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 d16si782902ilf.64.2021.07.29.23.09.50; Thu, 29 Jul 2021 23:10:02 -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 S237268AbhG3GJJ (ORCPT + 99 others); Fri, 30 Jul 2021 02:09:09 -0400 Received: from mga06.intel.com ([134.134.136.31]:19454 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236641AbhG3GJF (ORCPT ); Fri, 30 Jul 2021 02:09:05 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10060"; a="274111036" X-IronPort-AV: E=Sophos;i="5.84,281,1620716400"; d="scan'208";a="274111036" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jul 2021 23:09:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,281,1620716400"; d="scan'208";a="465344710" Received: from allen-box.sh.intel.com (HELO [10.239.159.118]) ([10.239.159.118]) by orsmga008.jf.intel.com with ESMTP; 29 Jul 2021 23:08:57 -0700 Cc: baolu.lu@linux.intel.com, iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, suravee.suthikulpanit@amd.com, john.garry@huawei.com, dianders@chromium.org, Marek Szyprowski , Yoshihiro Shimoda , Geert Uytterhoeven , Yong Wu , Heiko Stuebner , Chunyan Zhang , Maxime Ripard , Jean-Philippe Brucker Subject: Re: [PATCH v2 01/24] iommu: Pull IOVA cookie management into the core To: Robin Murphy , joro@8bytes.org, will@kernel.org References: From: Lu Baolu Message-ID: <19face6d-daae-fe36-5154-a1f6e409064d@linux.intel.com> Date: Fri, 30 Jul 2021 14:06:38 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/28/21 11:58 PM, Robin Murphy wrote: > Now that everyone has converged on iommu-dma for IOMMU_DOMAIN_DMA > support, we can abandon the notion of drivers being responsible for the > cookie type, and consolidate all the management into the core code. > > CC: Marek Szyprowski > CC: Yoshihiro Shimoda > CC: Geert Uytterhoeven > CC: Yong Wu > CC: Heiko Stuebner > CC: Chunyan Zhang > CC: Chunyan Zhang > CC: Maxime Ripard > CC: Jean-Philippe Brucker > Signed-off-by: Robin Murphy > --- > drivers/iommu/iommu.c | 7 +++++++ > include/linux/iommu.h | 3 ++- > 2 files changed, 9 insertions(+), 1 deletion(-) > > diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c > index f2cda9950bd5..ea5a9ea8d431 100644 > --- a/drivers/iommu/iommu.c > +++ b/drivers/iommu/iommu.c > @@ -7,6 +7,7 @@ > #define pr_fmt(fmt) "iommu: " fmt > > #include > +#include > #include > #include > #include > @@ -1946,6 +1947,11 @@ static struct iommu_domain *__iommu_domain_alloc(struct bus_type *bus, > /* Assume all sizes by default; the driver may override this later */ > domain->pgsize_bitmap = bus->iommu_ops->pgsize_bitmap; > > + /* Temporarily ignore -EEXIST while drivers still get their own cookies */ > + if (type == IOMMU_DOMAIN_DMA && iommu_get_dma_cookie(domain) == -ENOMEM) { > + iommu_domain_free(domain); > + domain = NULL; > + } > return domain; > } > > @@ -1957,6 +1963,7 @@ EXPORT_SYMBOL_GPL(iommu_domain_alloc); > > void iommu_domain_free(struct iommu_domain *domain) > { > + iommu_put_dma_cookie(domain); > domain->ops->domain_free(domain); > } > EXPORT_SYMBOL_GPL(iommu_domain_free); > diff --git a/include/linux/iommu.h b/include/linux/iommu.h > index 4997c78e2670..141779d76035 100644 > --- a/include/linux/iommu.h > +++ b/include/linux/iommu.h > @@ -40,6 +40,7 @@ struct iommu_domain; > struct notifier_block; > struct iommu_sva; > struct iommu_fault_event; > +struct iommu_dma_cookie; > > /* iommu fault flags */ > #define IOMMU_FAULT_READ 0x0 > @@ -86,7 +87,7 @@ struct iommu_domain { > iommu_fault_handler_t handler; > void *handler_token; > struct iommu_domain_geometry geometry; > - void *iova_cookie; > + struct iommu_dma_cookie *iova_cookie; > }; > > enum iommu_cap { > Reviewed-by: Lu Baolu Best regards, baolu