Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5363636pxv; Wed, 28 Jul 2021 09:03:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdop5lNs2dMRgYP4jSQ2xDQkxI4fNIqQLiahfGgaIcqKPjmrFS1R+RAF1kC2Y52GGfPtd9 X-Received: by 2002:a17:907:e8c:: with SMTP id ho12mr189917ejc.552.1627488179626; Wed, 28 Jul 2021 09:02:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627488179; cv=none; d=google.com; s=arc-20160816; b=mFgQZ31zO0jWlrR+zMmR+o2R1rryp7tylrHQMqLLpzdC93oPe+YJ1Wtf2TyyEujENK oElOIzjYRGwP5+LHz25lruW/Ny2VwSdU/U254HmuGecAvO55DEVj1kD03nIvzt4DYV4S PDUq5KpE7XbDdrhkmZ5YDWC+rR1cfbkmEWtftfJAgOtp4iQFupHDh63VJhzeAo6WdJ2w GG9kG9W/1IYKKd7pscSxLyqy8YPxIVCvn5vbpbFxth0bHMkeDWDBsfHPx4Td43+g5wV1 o8CgYlznPLxS1KJAnfne54cAdwvYb3ejuB5zPpNHrYlLWxovgr6aoY1RPOYuDPhzanZK V/Dw== 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=E4CN3o11Y65I4E1L8kc7yS6d9R6S9M4J96cexOiSiew=; b=rRa6QzlWYbA/9DdiWyjs3oCeklVpGAoPtZ4OcH5zxSt3chrCT8XZj/c/dph0YG5qaA 70Z9p64IFeViBze0+S+UON5396alnwghZEkK1BLAN3amggQoWQeJ+wN9+ZUWWBXiXJWZ mbZvo0UgCjkfxfZfCvoMw0ZcCipLqdfkRyDpDdX1JwWFB4+yAxFlHmcE0nvgZ8BZ39gX kftUATGdoHD/V2dQ5HzNjPmckmaDlF8h02DI8AkdUXw/sm870VAei+AmeMEa7lffbJ9g K2D/sb8X/sRwwg5HZgtgVZcFCV5R0O9Mwhv2PQ8e/aRC1M2652FeUAMKdhmwqowxORtp JTGw== 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 p7si34886edq.323.2021.07.28.09.02.35; Wed, 28 Jul 2021 09:02:59 -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 S237548AbhG1QAG (ORCPT + 99 others); Wed, 28 Jul 2021 12:00:06 -0400 Received: from foss.arm.com ([217.140.110.172]:59526 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237442AbhG1P7k (ORCPT ); Wed, 28 Jul 2021 11:59:40 -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 33F89113E; Wed, 28 Jul 2021 08:59:38 -0700 (PDT) Received: from 010265703453.arm.com (unknown [10.57.36.146]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B8C763F70D; Wed, 28 Jul 2021 08:59:36 -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 v2 18/24] iommu: Express DMA strictness via the domain type Date: Wed, 28 Jul 2021 16:58:39 +0100 Message-Id: <50bee17e9248ccfccb33a10238210d4ff4f4cf4d.1627468309.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 Eliminate the iommu_get_dma_strict() indirection and pipe the information through the domain type from the beginning. Besides the flow simplification this also has several nice side-effects: - Automatically implies strict mode for untrusted devices by virtue of their IOMMU_DOMAIN_DMA override. - Ensures that we only end up using flush queues for drivers which are aware of them and can actually benefit. - Allows us to handle flush queue init failure by falling back to strict mode instead of leaving it to possibly blow up later. Signed-off-by: Robin Murphy --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 +- drivers/iommu/arm/arm-smmu/arm-smmu.c | 2 +- drivers/iommu/dma-iommu.c | 9 +++++---- drivers/iommu/iommu.c | 12 +++--------- include/linux/iommu.h | 1 - 5 files changed, 10 insertions(+), 16 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index a1f0d83d1eb5..19400826eba7 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2175,7 +2175,7 @@ static int arm_smmu_domain_finalise(struct iommu_domain *domain, .iommu_dev = smmu->dev, }; - if (!iommu_get_dma_strict(domain)) + if (domain->type == IOMMU_DOMAIN_DMA_FQ) pgtbl_cfg.quirks |= IO_PGTABLE_QUIRK_NON_STRICT; pgtbl_ops = alloc_io_pgtable_ops(fmt, &pgtbl_cfg, smmu_domain); diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c index 936c5e9d5e82..109e4723f9f5 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -765,7 +765,7 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain, .iommu_dev = smmu->dev, }; - if (!iommu_get_dma_strict(domain)) + if (domain->type == IOMMU_DOMAIN_DMA_FQ) pgtbl_cfg.quirks |= IO_PGTABLE_QUIRK_NON_STRICT; if (smmu->impl && smmu->impl->init_context) { diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 8b3545c01077..7f3968865387 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -363,13 +363,14 @@ static int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base, init_iova_domain(iovad, 1UL << order, base_pfn); - if (!cookie->fq_domain && !dev_is_untrusted(dev) && - domain->ops->flush_iotlb_all && !iommu_get_dma_strict(domain)) { + if (domain->type == IOMMU_DOMAIN_DMA_FQ && !cookie->fq_domain) { if (init_iova_flush_queue(iovad, iommu_dma_flush_iotlb_all, - iommu_dma_entry_dtor)) + iommu_dma_entry_dtor)) { pr_warn("iova flush queue initialization failed\n"); - else + domain->type = IOMMU_DOMAIN_DMA; + } else { cookie->fq_domain = domain; + } } return iova_reserve_iommu_regions(dev, domain); diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 982545234cf3..eecb5657de69 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -136,6 +136,9 @@ static int __init iommu_subsys_init(void) } } + if (!iommu_default_passthrough() && !iommu_dma_strict) + iommu_def_domain_type = IOMMU_DOMAIN_DMA_FQ; + pr_info("Default domain type: %s %s\n", iommu_domain_type_str(iommu_def_domain_type), (iommu_cmd_line & IOMMU_CMD_LINE_DMA_API) ? @@ -357,15 +360,6 @@ void iommu_set_dma_strict(void) iommu_dma_strict = true; } -bool iommu_get_dma_strict(struct iommu_domain *domain) -{ - /* only allow lazy flushing for DMA domains */ - if (domain->type == IOMMU_DOMAIN_DMA) - return iommu_dma_strict; - return true; -} -EXPORT_SYMBOL_GPL(iommu_get_dma_strict); - static ssize_t iommu_group_attr_show(struct kobject *kobj, struct attribute *__attr, char *buf) { diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 046ba4d54cd2..edfe2fdb8368 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -498,7 +498,6 @@ int iommu_set_pgtable_quirks(struct iommu_domain *domain, unsigned long quirks); void iommu_set_dma_strict(void); -bool iommu_get_dma_strict(struct iommu_domain *domain); extern int report_iommu_fault(struct iommu_domain *domain, struct device *dev, unsigned long iova, int flags); -- 2.25.1