Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp14817pxv; Wed, 21 Jul 2021 14:08:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx30ddWaRDcpPzM34Qbh9Kn1ilLX0f69bzTP+xIqacj3FBhjWpmcz9pbtiEc9JpznTfSo/C X-Received: by 2002:a5e:c803:: with SMTP id y3mr27475041iol.107.1626901578308; Wed, 21 Jul 2021 14:06:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626901578; cv=none; d=google.com; s=arc-20160816; b=KyKS26OWRDZ1B/HFZVwF4Yjbcp8doPjvhsfEsqYUo+v+0Ux0ezfv5zAG+0QZcec8G/ odLodnikVCCsF+tsURB+kG4+pbauk544Zb0BCzywh0tA/zoKNfNYaODXqX2rRIwXnYKz xwOztSX/T7iW40nNQQLtnobLxlIfZcjybbZTTaOId9Rvc8X8qgm/nNsus9VsLlRXy4uS Qxb4xB+JqdkWp2fZVzkql7dYoBGs4ZmwsqcalrAETS/wxmejoxhOT9kkNTOMvkRmD2xC mO/nVg7KoQRK5LomGiKq4BtCJ9u5Nit/jvbFxfW9rTrz5XTT287dD3ywqvUDcprzB2iJ Kkxg== 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=ZWKDT0wDjBN0Gaukd+uVYDSmb7Im1BuNj2O4GLEAHpI=; b=ltfq+ICYs5EIys+nWwnvmHaBgvU6nrg4kqLAR0w7sGHxtuyhU8FvcFApN3Yuk2ngRO Cb+sffN1pVPzYhNR5HuQYqhzQ3QOLnrLhcedNSvlLddmKAaS1i7R5P7opEhsrkqpRtf3 QHIaPsHrFDI9bPLwdsptDqZadnV68hbBY0zNmKbk3ND7eHmqiVNoum4J7aKAJ3YM9DVx lGg9DVj8M9fcVDkR8/2OCjATa5iV0F1QR3dGHIU2UL0h/ZpIMLC3eegCXR3pESY4H9U1 4kQVo0AKKmr++XJm2DpEiizpcaKv5oHYYbN0T6+MAIUDtawp6p0md5fuAl5jxa+zISuh tWuQ== 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 y1si29429022jab.59.2021.07.21.14.06.06; Wed, 21 Jul 2021 14:06:18 -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 S231320AbhGURkL (ORCPT + 99 others); Wed, 21 Jul 2021 13:40:11 -0400 Received: from foss.arm.com ([217.140.110.172]:33114 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231192AbhGURkK (ORCPT ); Wed, 21 Jul 2021 13:40:10 -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 1F2F4113E; Wed, 21 Jul 2021 11:20:47 -0700 (PDT) Received: from 010265703453.arm.com (unknown [10.57.36.146]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9CAE33F694; Wed, 21 Jul 2021 11:20:45 -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 Subject: [PATCH 01/23] iommu: Pull IOVA cookie management into the core Date: Wed, 21 Jul 2021 19:20:12 +0100 Message-Id: <86f8bd2a3e78766b60270d70490f0275706b7525.1626888444.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. 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 5419c4b9f27a..0952de57c466 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 @@ -1941,6 +1942,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; } @@ -1952,6 +1958,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 32d448050bf7..007662b65474 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