Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5360832pxv; Wed, 28 Jul 2021 09:00:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbMQ3HdSpZletT0G09trCPWGEMUWKTiAWBY6MWXKWrQBX/KlugooBVFe2kjjx6d2+omCJ0 X-Received: by 2002:a92:7a12:: with SMTP id v18mr355712ilc.27.1627488008677; Wed, 28 Jul 2021 09:00:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627488008; cv=none; d=google.com; s=arc-20160816; b=vw7tjYZpowYGE4lHdHR+1i/wrB3bnKhXgfa6jL7gGNslfFzhTrh8Yz2VD6yzD2Jkpo P7cedbdSQIdfDN8+2ntM9/TJAX2xazPSTshKICI0yLs7XhYZxJHJpiQFseyUsR5wShpb 6HgUCNLBxbDzczWBNdmo+rO35cZkZquwu6snqATz7K0tj5evaS2MTe+av9dGQuAwuZGp /XqUBFrTajwn90qpP/ah2LvG1XN1aCHSk5aeIyCApOaff5djD1hrgdNeOmQ1EjHrWD9C PW+6mP+rFYPISN6+KhjQayl6ZzK7fU4k1UQFEnqv1B3m3HmZ+Y7pCFwKohgApFKIHbNa PmPA== 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=4F9fSKHthhSevNPgkZSLBR4SD2ZMlxI/8eXDBoHtubQ=; b=HyBO0bQXefn/ndUql8Z9I5lBIByPVK1s4tqaUsyBbGQABnjgCmajBrR0WTI5XWtM5W FJ1jUWVrOpUu0sGXvIZrJ3A969H1XEN8Ry9Mv8/IBo4Kq4bX4mOd7vWb3oQ9AgcXAez5 ByEIRj5UhbGeEdcxXhU9hwtMCyxv/LmwlJN63CdPgWaqXSTu9MC7IJ3+Be3CHoDkiJ6/ 5uNO5NmREvTsBaUb/p4rV17H3Tv1NFWRytc1ItgBcdI8T7w65DAXuMs1MjBC9YejnWk/ PSEzaJW+iXjKw6zG9fovSALedOggwEed7AH3+51tx65YTfcNQ6Gl8NQmp3qf566AV1qc 0iqQ== 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 x17si301522jat.44.2021.07.28.08.59.57; Wed, 28 Jul 2021 09:00:08 -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 S237172AbhG1P7J (ORCPT + 99 others); Wed, 28 Jul 2021 11:59:09 -0400 Received: from foss.arm.com ([217.140.110.172]:59162 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229880AbhG1P7H (ORCPT ); Wed, 28 Jul 2021 11:59:07 -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 2C123D6E; Wed, 28 Jul 2021 08:59:06 -0700 (PDT) Received: from 010265703453.arm.com (unknown [10.57.36.146]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A5E4F3F70D; Wed, 28 Jul 2021 08:59:03 -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, Marek Szyprowski , Yoshihiro Shimoda , Geert Uytterhoeven , Yong Wu , Heiko Stuebner , Chunyan Zhang , Maxime Ripard , Jean-Philippe Brucker Subject: [PATCH v2 01/24] iommu: Pull IOVA cookie management into the core Date: Wed, 28 Jul 2021 16:58:22 +0100 Message-Id: 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: 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 { -- 2.25.1