Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp256074pxt; Wed, 4 Aug 2021 10:17:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEWKfyDakqzUGUlCKRPl2Pk0qFWetqnZi16kC2IoErIDhc5rpy+/iZelMrNfy8n3MOhD8/ X-Received: by 2002:a05:6602:2245:: with SMTP id o5mr301408ioo.20.1628097433742; Wed, 04 Aug 2021 10:17:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628097433; cv=none; d=google.com; s=arc-20160816; b=PVuO5uAESOtOP4MVrvVresyHH1Stpknx2fz7808i3ozeMLgsjNBqGZbXeChQZvam3C hLJMplr5h96/+bmO42LIwgJ78MEFCkJ2IL0OIJMd155OJXtx1Amj/bsc3zFfU25DSAyM 8Jt/KBY3VL8G8nW223gFcvMu9dv76Eo33siutyWuc4Q4e/l6F/1ddGumHoqm9Lj3nI1L 3dOFUDqplc/vLGW1r3DGPxuxbvHufTxrvgwUPwoFJ/dq7WQH3HSNVbrQfmLA2hhtsa6S +YxnyJUoSQ4HZ1F7jXiDOj9Bu7yM4DNQOFoSdIgqVpuBfArTsdbZTGGsR1NqxfcuWQ4W p3Fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=jrye3xJIwSKyQGc5Mj2s6yPXcmPoCAhy2vY/3c1+Mas=; b=uszLfci41A1tlKaTgd21uq84KlxQGSJh5OMuR2y8aIr+cpWIsVXdaJZTS3M92lw0/D CrSNTSyRuuLz6171H3GVN1KeHnoBJPo8gyVOGmO+feDVDx5mny81FHudQnicUuzyshHi vFLJypb0kWwHEv/hHjn/FKM2+Njrd1KgM3eLZk1qFWBT6/Eg30pWqdCyjVDR4vH/+LE5 z52koq3CQijsTRd5Au4YbM1KQnjd5l665+JnCXcmfKm5yBMI1vVV0b+0w2JJl37zrE+I V05wwRNrV3pjNUpS6GWvCfcpTEwM07KK28wJDu2ESmP2sdNgcFZevsvutF7nFgZ9cHKX iIyw== 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=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s13si3236591ilp.102.2021.08.04.10.17.01; Wed, 04 Aug 2021 10:17:13 -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=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239821AbhHDRQY (ORCPT + 99 others); Wed, 4 Aug 2021 13:16:24 -0400 Received: from foss.arm.com ([217.140.110.172]:34760 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239816AbhHDRQX (ORCPT ); Wed, 4 Aug 2021 13:16:23 -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 EED911063; Wed, 4 Aug 2021 10:16:10 -0700 (PDT) Received: from 010265703453.arm.com (unknown [10.57.36.146]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 33CEF3F66F; Wed, 4 Aug 2021 10:16:08 -0700 (PDT) From: Robin Murphy To: joro@8bytes.org, will@kernel.org Cc: iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, suravee.suthikulpanit@amd.com, baolu.lu@linux.intel.com, john.garry@huawei.com, dianders@chromium.org, rajatja@google.com, chenxiang66@hisilicon.com, Marek Szyprowski , Yoshihiro Shimoda , Geert Uytterhoeven , Yong Wu , Heiko Stuebner , Chunyan Zhang , Maxime Ripard , Jean-Philippe Brucker Subject: [PATCH v3 01/25] iommu: Pull IOVA cookie management into the core Date: Wed, 4 Aug 2021 18:15:29 +0100 Message-Id: <46f4cda8215bd5f8a9f9fd5a4a6451805f75efa3.1628094600.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: Maxime Ripard Reviewed-by: Jean-Philippe Brucker Reviewed-by: Lu Baolu Signed-off-by: Robin Murphy --- v3: Use a simpler temporary check instead of trying to be clever with the error code --- 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..b65fcc66ffa4 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 avoid -EEXIST while drivers still get their own cookies */ + if (type == IOMMU_DOMAIN_DMA && !domain->iova_cookie && iommu_get_dma_cookie(domain)) { + 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 { -- 2.25.1