Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp7581718pxb; Thu, 18 Feb 2021 14:10:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJzQiTHMpuw78s7a1exhBrT29Gc1vsA3Rt6Q5YMTqa21mwcXFLH74YUdHyzcirTJb2ZazdDy X-Received: by 2002:a17:906:17d5:: with SMTP id u21mr6111090eje.541.1613686224554; Thu, 18 Feb 2021 14:10:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613686224; cv=none; d=google.com; s=arc-20160816; b=Ds6duaWa6/mnB5D5cSJDd25f+H0r6cyhvUXDVlSo4xTDC1MoiHvA/0B21vYMt0cgRF l/RYXsxzB8fUXsf9DHqqEfU6+yYiFKH4UGYTw4oI2tq9F1ufKt7ya0OVdNButPuUSR1P gPlN/hKZxVtOd0buzJ4llwmUMhxbriSigqJXVP0sVB6LQyaSIAVyV1pL4gei93v9+7zR 3gzBvrd9XsXvH4rQ3UbbOSNQpbJp5Z/Z17sxehiTYbxPHiPVw6lAizq/riQJW2lN20vr eC6PuKFGMIKJmERVYgovURX2LqvA+AZkUgGy00F//0wzLKDjqz3Nfs4Pp04yG726NnVc kLDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=GDOrF8R+0kkQi1QXHaOe+2aJ/te9SJscPtuXTt7HTNI=; b=v7IfRO4scBNOZBbLXdAbvP1jzVtOt48CVWjTZIxzfAjjYzK0yB4yRa64uKhhtdff9Y hzUZ/5G2xderFZq7yb7sAQulNkUu1WbksF8VfLrDVhR/btyUl/s/BC15ILlhVGNH5CQX RjX2vd0yObXpVgSg7xbLzPw8oV/d8loaNrzjZIQheGTGk9Tz5iLUgDUgy+BRHxo0ge+A rYzz6U9oJph3KcFvq3WLChTWnP1w4HV4Z+vSRV52wI6nL7R2Y5cW8jydi4MEXAfaaGAZ ANQbbYUWdoiFc4kirydt7XZw8BUXw4GkDkfKptVnwWshOupxDqhoPdN7TMkx4xUlQv7O VJkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=j+EHKboL; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c15si4464391ejr.124.2021.02.18.14.09.58; Thu, 18 Feb 2021 14:10:24 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=j+EHKboL; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229799AbhBRWHF (ORCPT + 99 others); Thu, 18 Feb 2021 17:07:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229480AbhBRWHD (ORCPT ); Thu, 18 Feb 2021 17:07:03 -0500 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAA8BC061574; Thu, 18 Feb 2021 14:06:23 -0800 (PST) Received: by mail-pg1-x532.google.com with SMTP id t11so2065524pgu.8; Thu, 18 Feb 2021 14:06:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=GDOrF8R+0kkQi1QXHaOe+2aJ/te9SJscPtuXTt7HTNI=; b=j+EHKboLuIIXk/dGnc3IYjkffuISWd6xyHYgLGGeaZT/KW/ok8iLYjK8LBU6vJU65f IDR0kHwEJIpBI+fyLV4/r9Q/3st8cesr6nlt4jyuHGDxAdKjUeL5RgOQYe5a6xhdT6Vs R24fA0o64+vg55bl5BomHTpEi0K7jndmfCMBawRSKY615PrT5lAhW9yao+Qe13BBjees 9GBXEd7v2GR3NiGM3nmw+JfvAZgogaEtC/esyivoncZmZ2RVPU37eYeIJdeobhcMrKqd nsgK5Hd5Y4CHBa31x9XSp/5H63vVC372blY2IYuKybJ7hhszV3qaI1Bx9AS0WTCVrpSV wO1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=GDOrF8R+0kkQi1QXHaOe+2aJ/te9SJscPtuXTt7HTNI=; b=a4O9mjEvwJ1uVj/RvCuRS+lXMtYqplr/Pk5P0ajomMpcvsexUei48eEWbKLTC+UTuu CjeE4uEhtD28mIySdg8XGM95onIUsKzq/N3EnLMy0azzqcyb1aIzlK6LjrYKmoGYRkll Jsjm4HPxMyXLfEYGmT8E1fkCKDoANNCxOMBRhvU10CFreccTqC5AbQB8hx15epIdK1yV 4UdLNImNsq3L0h5ZGUhy02U0Dp3nIATl3gwVoTkmBewhNBH3mT/D2bvvBATklCpGrL5u kpzC7cyhlWKpwCWXQCTOKkgCc5j3N/UaJIkMogNncDOeMHDXYtZj+5ZkQRRa0Iglva/0 GQIA== X-Gm-Message-State: AOAM533mT0fobNDMPpxphgp5sl/VKacC7h4N9ojP/MHA8lfdFCaTNjjX 0ZjaTSOx5kM/ibwTRIO7MOo= X-Received: by 2002:a62:e105:0:b029:1db:6f3e:7a56 with SMTP id q5-20020a62e1050000b02901db6f3e7a56mr6421437pfh.62.1613685983339; Thu, 18 Feb 2021 14:06:23 -0800 (PST) Received: from Asurada-Nvidia.nvidia.com (thunderhill.nvidia.com. [216.228.112.22]) by smtp.gmail.com with ESMTPSA id u17sm7443251pgh.72.2021.02.18.14.06.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Feb 2021 14:06:22 -0800 (PST) From: Nicolin Chen To: joro@8bytes.org, thierry.reding@gmail.com, will@kernel.org, guillaume.tucker@collabora.com Cc: vdumpa@nvidia.com, jonathanh@nvidia.com, digetx@gmail.com, linux-tegra@vger.kernel.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH] iommu/tegra-smmu: Fix mc errors on tegra124-nyan Date: Thu, 18 Feb 2021 14:07:02 -0800 Message-Id: <20210218220702.1962-1-nicoleotsuka@gmail.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 25938c73cd79 ("iommu/tegra-smmu: Rework tegra_smmu_probe_device()") removed certain hack in the tegra_smmu_probe() by relying on IOMMU core to of_xlate SMMU's SID per device, so as to get rid of tegra_smmu_find() and tegra_smmu_configure() that are typically done in the IOMMU core also. This approach works for both existing devices that have DT nodes and other devices (like PCI device) that don't exist in DT, on Tegra210 and Tegra3 upon testing. However, Page Fault errors are reported on tegra124-Nyan: tegra-mc 70019000.memory-controller: display0a: read @0xfe056b40: EMEM address decode error (SMMU translation error [--S]) tegra-mc 70019000.memory-controller: display0a: read @0xfe056b40: Page fault (SMMU translation error [--S]) After debugging, I found that the mentioned commit changed some function callback sequence of tegra-smmu's, resulting in enabling SMMU for display client before display driver gets initialized. I couldn't reproduce exact same issue on Tegra210 as Tegra124 (arm-32) differs at arch-level code. Actually this Page Fault is a known issue, as on most of Tegra platforms, display gets enabled by the bootloader for the splash screen feature, so it keeps filling the framebuffer memory. A proper fix to this issue is to 1:1 linear map the framebuffer memory to IOVA space so the SMMU will have the same address as the physical address in its page table. Yet, Thierry has been working on the solution above for a year, and it hasn't merged. Therefore, let's partially revert the mentioned commit to fix the errors. The reason why we do a partial revert here is that we can still set priv in ->of_xlate() callback for PCI devices. Meanwhile, devices existing in DT, like display, will go through tegra_smmu_configure() at the stage of bus_set_iommu() when SMMU gets probed(), as what it did before we merged the mentioned commit. Once we have the linear map solution for framebuffer memory, this change can be cleaned away. [Big thank to Guillaume who reported and helped debugging/verification] Fixes: 25938c73cd79 ("iommu/tegra-smmu: Rework tegra_smmu_probe_device()") Reported-by: Guillaume Tucker Signed-off-by: Nicolin Chen --- Guillaume, would you please give a "Tested-by" to this change? Thanks! drivers/iommu/tegra-smmu.c | 72 +++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c index 4a3f095a1c26..97eb62f667d2 100644 --- a/drivers/iommu/tegra-smmu.c +++ b/drivers/iommu/tegra-smmu.c @@ -798,10 +798,70 @@ static phys_addr_t tegra_smmu_iova_to_phys(struct iommu_domain *domain, return SMMU_PFN_PHYS(pfn) + SMMU_OFFSET_IN_PAGE(iova); } +static struct tegra_smmu *tegra_smmu_find(struct device_node *np) +{ + struct platform_device *pdev; + struct tegra_mc *mc; + + pdev = of_find_device_by_node(np); + if (!pdev) + return NULL; + + mc = platform_get_drvdata(pdev); + if (!mc) + return NULL; + + return mc->smmu; +} + +static int tegra_smmu_configure(struct tegra_smmu *smmu, struct device *dev, + struct of_phandle_args *args) +{ + const struct iommu_ops *ops = smmu->iommu.ops; + int err; + + err = iommu_fwspec_init(dev, &dev->of_node->fwnode, ops); + if (err < 0) { + dev_err(dev, "failed to initialize fwspec: %d\n", err); + return err; + } + + err = ops->of_xlate(dev, args); + if (err < 0) { + dev_err(dev, "failed to parse SW group ID: %d\n", err); + iommu_fwspec_free(dev); + return err; + } + + return 0; +} + static struct iommu_device *tegra_smmu_probe_device(struct device *dev) { - struct tegra_smmu *smmu = dev_iommu_priv_get(dev); + struct device_node *np = dev->of_node; + struct tegra_smmu *smmu = NULL; + struct of_phandle_args args; + unsigned int index = 0; + int err; + + while (of_parse_phandle_with_args(np, "iommus", "#iommu-cells", index, + &args) == 0) { + smmu = tegra_smmu_find(args.np); + if (smmu) { + err = tegra_smmu_configure(smmu, dev, &args); + of_node_put(args.np); + if (err < 0) + return ERR_PTR(err); + + break; + } + + of_node_put(args.np); + index++; + } + + smmu = dev_iommu_priv_get(dev); if (!smmu) return ERR_PTR(-ENODEV); @@ -1028,6 +1088,16 @@ struct tegra_smmu *tegra_smmu_probe(struct device *dev, if (!smmu) return ERR_PTR(-ENOMEM); + /* + * This is a bit of a hack. Ideally we'd want to simply return this + * value. However the IOMMU registration process will attempt to add + * all devices to the IOMMU when bus_set_iommu() is called. In order + * not to rely on global variables to track the IOMMU instance, we + * set it here so that it can be looked up from the .probe_device() + * callback via the IOMMU device's .drvdata field. + */ + mc->smmu = smmu; + size = BITS_TO_LONGS(soc->num_asids) * sizeof(long); smmu->asids = devm_kzalloc(dev, size, GFP_KERNEL); -- 2.17.1