Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp4261274pxb; Tue, 19 Apr 2022 22:15:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTBFd9JHt0TwYDfqUsv+KePD5hgR0fjwO3bJ78r/IAuEN3pXk+BPXp3DCj1wJ+h3QkqUYz X-Received: by 2002:a17:907:8a11:b0:6df:db0a:e5ab with SMTP id sc17-20020a1709078a1100b006dfdb0ae5abmr16693518ejc.528.1650431721668; Tue, 19 Apr 2022 22:15:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650431721; cv=none; d=google.com; s=arc-20160816; b=0E55uIU3FsvYcMHIsvfTfhjvea01nOXGz7GhDH6tgUWh9Gc3YV7WQ0TJ6JaMQl5Y3q ypaCY2EAaj688zrTt3g1dePoMxHzm7V+mAX8RRGoDEByQaxDQ10oYR90SWGbsVkEv/o7 SK0IeZTy0xQF0uA9vehsDgjrhMF4jHB9XXvYQl+Tu739Rz6iFOE61oKWNtBizU5yk2KA eYwnVum/jGo0nLUJg1w1kWfGWZoruPBDsna4PW9wbHVxB9u+lHbwnH7/mYO8ylmZO934 wgw/iEtnOmCVfEU5ozR6RxhV3Drz8UCnjMP3rLim8rZThkn03Cq1x0DiNyez2XpWvISw JnMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=6+ob4e9hBP3/yWDt+2iRA0cNPFIdUpT8rlALcVYUKH4=; b=VPXtPsDNpcrKzRjZOV0VoZBBqldz1qAYF6IYy1rVZIeTcdc6/QMSWd/gGWY0B2OoJ3 lbkeAp0/KixaVi5yhbKJFGfbHxgr98uO3hVK0M1nB/w/hY8Ack0a70LJIaz/OXFkUeXz 5dvkfGKqDhuNIRJnynX3bgVBIPjRUsik88MtRlvMXtubIorJzeYGbn/QsUEONF5fqb3o mcKrMAEeW24tnMZNAmig5tnauKjZZizOcLV/2ntIbaj7rKz2xcG2fZFjU0pCEXfv5m1t ew+VYOaOED1N7E57AVvQqlzy8ni99SqRu+qrxb/dsowugTxWIcmtQvHc+sIbDLCNS2+/ M96g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v7-20020a1709060b4700b006eff03031a0si960821ejg.100.2022.04.19.22.14.31; Tue, 19 Apr 2022 22:15:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1346191AbiDSUas (ORCPT + 99 others); Tue, 19 Apr 2022 16:30:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241331AbiDSUaq (ORCPT ); Tue, 19 Apr 2022 16:30:46 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F239B3AA4D; Tue, 19 Apr 2022 13:28:02 -0700 (PDT) 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 B5F0E106F; Tue, 19 Apr 2022 13:28:02 -0700 (PDT) Received: from [10.57.41.251] (unknown [10.57.41.251]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 495383F73B; Tue, 19 Apr 2022 13:28:00 -0700 (PDT) Message-ID: <52df6c79-3ee7-35e2-b72a-44ee9cb48c34@arm.com> Date: Tue, 19 Apr 2022 21:27:54 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [Patch v1] iommu: arm-smmu: disable large page mappings for Nvidia arm-smmu Content-Language: en-GB To: Ashish Mhetre , thierry.reding@gmail.com, vdumpa@nvidia.com, will@kernel.org, joro@8bytes.org, jonathanh@nvidia.com, linux-tegra@vger.kernel.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: nicolinc@nvidia.com, Snikam@nvidia.com, Pritesh Raithatha References: <20220417090432.21110-1-amhetre@nvidia.com> From: Robin Murphy In-Reply-To: <20220417090432.21110-1-amhetre@nvidia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022-04-17 10:04, Ashish Mhetre wrote: > Tegra194 and Tegra234 SoCs have the erratum that causes walk cache > entries to not be invalidated correctly. The problem is that the walk > cache index generated for IOVA is not same across translation and > invalidation requests. This is leading to page faults when PMD entry is > released during unmap and populated with new PTE table during subsequent > map request. Disabling large page mappings avoids the release of PMD > entry and avoid translations seeing stale PMD entry in walk cache. > Fix this by limiting the page mappings to PAGE_SIZE for Tegra194 and > Tegra234 devices. This is recommended fix from Tegra hardware design > team. Is this related to any of the several known MMU-500 invalidation errata, or is it definitely specific to something NVIDIA have done with their integration? > Co-developed-by: Pritesh Raithatha > Signed-off-by: Pritesh Raithatha > Signed-off-by: Ashish Mhetre > --- > drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c | 23 ++++++++++++++++++++ > drivers/iommu/arm/arm-smmu/arm-smmu.c | 3 +++ > drivers/iommu/arm/arm-smmu/arm-smmu.h | 1 + > 3 files changed, 27 insertions(+) > > diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c b/drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c > index 01e9b50b10a1..b7a3d06da2f4 100644 > --- a/drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c > +++ b/drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c > @@ -258,6 +258,27 @@ static void nvidia_smmu_probe_finalize(struct arm_smmu_device *smmu, struct devi > dev_name(dev), err); > } > > +static void nvidia_smmu_cfg_pgsize_bitmap(struct arm_smmu_device *smmu) > +{ > + const struct device_node *np = smmu->dev->of_node; > + > + /* > + * Tegra194 and Tegra234 SoCs have the erratum that causes walk cache > + * entries to not be invalidated correctly. The problem is that the walk > + * cache index generated for IOVA is not same across translation and > + * invalidation requests. This is leading to page faults when PMD entry > + * is released during unmap and populated with new PTE table during > + * subsequent map request. Disabling large page mappings avoids the > + * release of PMD entry and avoid translations seeing stale PMD entry in > + * walk cache. > + * Fix this by limiting the page mappings to PAGE_SIZE on Tegra194 and > + * Tegra234. > + */ > + if (of_device_is_compatible(np, "nvidia,tegra234-smmu") || > + of_device_is_compatible(np, "nvidia,tegra194-smmu")) > + smmu->pgsize_bitmap = PAGE_SIZE; > +} > + > static const struct arm_smmu_impl nvidia_smmu_impl = { > .read_reg = nvidia_smmu_read_reg, > .write_reg = nvidia_smmu_write_reg, > @@ -268,10 +289,12 @@ static const struct arm_smmu_impl nvidia_smmu_impl = { > .global_fault = nvidia_smmu_global_fault, > .context_fault = nvidia_smmu_context_fault, > .probe_finalize = nvidia_smmu_probe_finalize, > + .cfg_pgsize_bitmap = nvidia_smmu_cfg_pgsize_bitmap, > }; > > static const struct arm_smmu_impl nvidia_smmu_single_impl = { > .probe_finalize = nvidia_smmu_probe_finalize, > + .cfg_pgsize_bitmap = nvidia_smmu_cfg_pgsize_bitmap, > }; > > struct arm_smmu_device *nvidia_smmu_impl_init(struct arm_smmu_device *smmu) > diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c > index 568cce590ccc..3692a19a588a 100644 > --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c > +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c > @@ -1872,6 +1872,9 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu) > if (smmu->features & ARM_SMMU_FEAT_FMT_AARCH64_64K) > smmu->pgsize_bitmap |= SZ_64K | SZ_512M; > > + if (smmu->impl && smmu->impl->cfg_pgsize_bitmap) > + smmu->impl->cfg_pgsize_bitmap(smmu); I'm not the biggest fan of adding a super-specific hook for this, when it seems like it could just as easily be handled in the init_context hook, which is where it is precisely for the purpose of mangling the pgtable_cfg to influence io-pgtable's behaviour. Thanks, Robin. > + > if (arm_smmu_ops.pgsize_bitmap == -1UL) > arm_smmu_ops.pgsize_bitmap = smmu->pgsize_bitmap; > else > diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.h b/drivers/iommu/arm/arm-smmu/arm-smmu.h > index 2b9b42fb6f30..5d9b03024969 100644 > --- a/drivers/iommu/arm/arm-smmu/arm-smmu.h > +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.h > @@ -442,6 +442,7 @@ struct arm_smmu_impl { > void (*write_s2cr)(struct arm_smmu_device *smmu, int idx); > void (*write_sctlr)(struct arm_smmu_device *smmu, int idx, u32 reg); > void (*probe_finalize)(struct arm_smmu_device *smmu, struct device *dev); > + void (*cfg_pgsize_bitmap)(struct arm_smmu_device *smmu); > }; > > #define INVALID_SMENDX -1