From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 631A7C4338F for ; Sat, 24 Jul 2021 05:31:04 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1D5C3601FC for ; Sat, 24 Jul 2021 05:31:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1D5C3601FC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Cc:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=4TArGImI1KsODuYJBlKRS54rRYdVfoBmvWrqh8F5R7E=; b=VSvby5rXXc8PE/K4+4LOA/xzqF wPg359yYwyMuB20CdbCf4C3XZeCEaqJHtGuX5tdd7w8Gh3gy6uxKzEHCkuFMiy+hBFINqXs0MxT6n tkAA7qiAIHFHxCF4MbNgSS5oZUKnOHMAKW4gU8hcaZmI1A6ZLkTXh562JUND7b2yz0shjTD7+fnxc plVYNEzEzIzI4hlbkaSI7tEU6QfWCQaCe1HmaYpcoOivfEMeem8bnSHRUGQm8Lnw212Ta8MEfLyBt 9gYzEywMdmualyYXwONoxRB0L9RwHxLSe5uxSq93uqJQkRQcIswWhCVgfPXkooBdPU45oP/nQmw+C cHcyDMHQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m7AEJ-006k8M-5m; Sat, 24 Jul 2021 05:29:43 +0000 Received: from mga09.intel.com ([134.134.136.24]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m7AEF-006k7q-Ai for linux-arm-kernel@lists.infradead.org; Sat, 24 Jul 2021 05:29:40 +0000 X-IronPort-AV: E=McAfee;i="6200,9189,10054"; a="211996538" X-IronPort-AV: E=Sophos;i="5.84,265,1620716400"; d="scan'208";a="211996538" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jul 2021 22:29:38 -0700 X-IronPort-AV: E=Sophos;i="5.84,265,1620716400"; d="scan'208";a="502966562" Received: from yuhaipen-mobl.ccr.corp.intel.com (HELO [10.254.209.247]) ([10.254.209.247]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jul 2021 22:29:36 -0700 Cc: baolu.lu@linux.intel.com, iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, suravee.suthikulpanit@amd.com, john.garry@huawei.com, dianders@chromium.org Subject: Re: [PATCH 18/23] iommu: Express DMA strictness via the domain type To: Robin Murphy , joro@8bytes.org, will@kernel.org References: <37708e21b55e17eb074ef145afc2157cd0192abe.1626888445.git.robin.murphy@arm.com> From: Lu Baolu Message-ID: Date: Sat, 24 Jul 2021 13:29:34 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <37708e21b55e17eb074ef145afc2157cd0192abe.1626888445.git.robin.murphy@arm.com> Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210723_222939_532222_97856481 X-CRM114-Status: GOOD ( 22.93 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Robin, On 2021/7/22 2:20, Robin Murphy wrote: > 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 ends up using flush queues for drivers > which are aware of them and can actually benefit. Is this expressed by vendor iommu driver has ops->flush_iotlb_all? > - 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 | 10 ++++++---- > drivers/iommu/iommu.c | 14 ++++---------- > include/linux/iommu.h | 1 - > 5 files changed, 12 insertions(+), 17 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 fa41026d272e..260b560d0075 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 dbc14c265b15..2c717f3be056 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 b1af1ff324c5..a114a7ad88ec 100644 > --- a/drivers/iommu/dma-iommu.c > +++ b/drivers/iommu/dma-iommu.c > @@ -363,13 +363,15 @@ 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 && > + domain->ops->flush_iotlb_all) { > 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 8333c334891e..d7eaacae0944 100644 > --- a/drivers/iommu/iommu.c > +++ b/drivers/iommu/iommu.c > @@ -135,6 +135,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) ? > @@ -352,15 +355,6 @@ void iommu_set_dma_strict(bool strict) > iommu_dma_strict = strict; > } > > -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) > { > @@ -764,7 +758,7 @@ static int iommu_create_device_direct_mappings(struct iommu_group *group, > unsigned long pg_size; > int ret = 0; > > - if (!domain || domain->type != IOMMU_DOMAIN_DMA) > + if (!domain || !(domain->type & __IOMMU_DOMAIN_DMA_API)) Nit: probably move above change to patch 14? > return 0; > > BUG_ON(!domain->pgsize_bitmap); > diff --git a/include/linux/iommu.h b/include/linux/iommu.h > index 56519110d43f..557c4c12e2cf 100644 > --- a/include/linux/iommu.h > +++ b/include/linux/iommu.h > @@ -484,7 +484,6 @@ int iommu_set_pgtable_quirks(struct iommu_domain *domain, > unsigned long quirks); > > void iommu_set_dma_strict(bool val); > -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); > Best regards, baolu _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel