Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp258033pxt; Wed, 4 Aug 2021 10:20:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoJ5zuwv0WQoOLL07WIkTBt5USz98mko5xsdbuRsmoKf2Ra9ox572npHwCY00sdKH9Z5PR X-Received: by 2002:a5d:984d:: with SMTP id p13mr347660ios.182.1628097600400; Wed, 04 Aug 2021 10:20:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628097600; cv=none; d=google.com; s=arc-20160816; b=sU6kAFqyI0pMLArvzO5Q0oAdzRwpBcmQB4bsg8HIAq2dIIJ9YaaXiRxuA4Jo4WwjEP kk3h/cTilq8rTi1UBooTDieekeY/3IXGvzL5g6aMaNgXr9pbh0SWaDcp3f2XUC1NPdJ8 mWS/fB5j7X8VnmkA+v+XmyQLxZWMghPEe7C7Z8IPueChZOTzYxVU3rfpe4TpsOYYGRkB /KAONnNinXx6UcAzo9dpOk3/HG+oHKcBu2HvNEJawNHTOsg/2sEATjS+T/2NTNOcBWrs RIiiTO6uKigvd5JeMySfWJ3YLqroaEHAuSHU1ENVrv+BzmmtN5WPgBF8AeoIAxn9A0A3 IrjA== 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=dikVk/ouPrdUlJmr/Gb5QBcjrPN91U8PUVqqo8BovXA=; b=n43pkQizxoIs/3ENSztYjqxhU9aG1JXkvDzH9AK54O+RlYsUG/dn8zvk2gu6jj8Wgs bYvqLPMaffHZnaNTwIAW1jMFN3Ixdku4GDEtqDvv3VqyIO88TvuyR+iqKVneuI/J/h4K 3ZSH4DV7g8JP9rZBfm2pRDCoOaY+/OfRk0JkUH16EFm2fM7gaO2L6O0dtFqp2W6gVF6O LgNZe6WalG2qOccbzqbq0/eS/zlB2ToOZoR7VzLlU2SOiy0Fmiz0Wq80zHIQRolONPib gFNm1Y2wOlXtHqDEjR5RtpGldbBTqBIMcIQb639WFMm/DemLXdMzspXdT2rLPXLM+zzU c2dA== 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 s12si2608900ild.148.2021.08.04.10.19.42; Wed, 04 Aug 2021 10:20:00 -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 S239872AbhHDRRY (ORCPT + 99 others); Wed, 4 Aug 2021 13:17:24 -0400 Received: from foss.arm.com ([217.140.110.172]:35224 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239990AbhHDRRC (ORCPT ); Wed, 4 Aug 2021 13:17:02 -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 00DDE142F; Wed, 4 Aug 2021 10:16:50 -0700 (PDT) Received: from 010265703453.arm.com (unknown [10.57.36.146]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 33D2D3F66F; Wed, 4 Aug 2021 10:16:48 -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 Subject: [PATCH v3 20/25] iommu: Express DMA strictness via the domain type Date: Wed, 4 Aug 2021 18:15:48 +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 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. Reviewed-by: Lu Baolu Signed-off-by: Robin Murphy --- v3: Remember to update iommu_def_domain_type accordingly from iommu_set_dma_strict() too --- drivers/iommu/dma-iommu.c | 9 +++++---- drivers/iommu/iommu.c | 14 +++++--------- include/linux/iommu.h | 1 - 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 207c8febdac9..2e19505dddf9 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..55ca5bf3cafc 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) ? @@ -355,17 +358,10 @@ early_param("iommu.strict", iommu_dma_setup); void iommu_set_dma_strict(void) { iommu_dma_strict = true; + if (iommu_def_domain_type == IOMMU_DOMAIN_DMA_FQ) + iommu_def_domain_type = IOMMU_DOMAIN_DMA; } -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 5629ae42951f..923a8d1c5e39 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -504,7 +504,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