public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Osipenko <digetx@gmail.com>
To: Nicolin Chen <nicolinc@nvidia.com>,
	thierry.reding@gmail.com, joro@8bytes.org, will@kernel.org
Cc: vdumpa@nvidia.com, jonathanh@nvidia.com,
	linux-tegra@vger.kernel.org, iommu@lists.linux-foundation.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v7 6/6] iommu/tegra-smmu: Add pagetable mappings to debugfs
Date: Wed, 8 Dec 2021 17:37:34 +0300	[thread overview]
Message-ID: <085d4e6a-31b1-37c8-fe31-fb15119affc6@gmail.com> (raw)
In-Reply-To: <20211208084732.23363-7-nicolinc@nvidia.com>

Hi,

08.12.2021 11:47, Nicolin Chen пишет:
> This patch dumps all active mapping entries from pagetable to a
> debugfs directory named "mappings".
> 
> Attaching an example:
> 
> [SWGROUP: xusb_host] [as: (id: 5), (attr: R|W|-), (pd_dma: 0x0000000080005000)]
> {
>         [index: 1023] 0xf0080040 (count: 52)
>         {
>                 PTE RANGE      | ATTR | PHYS               | IOVA               | SIZE
>                 [#913 , #913 ] | 0x7  | 0x0000000102674000 | 0x00000000fff91000 | 0x1000
>                 [#914 , #914 ] | 0x7  | 0x0000000102672000 | 0x00000000fff92000 | 0x1000
>                 [#915 , #915 ] | 0x7  | 0x0000000102671000 | 0x00000000fff93000 | 0x1000
>                 [#916 , #916 ] | 0x7  | 0x0000000102670000 | 0x00000000fff94000 | 0x1000
>                 [#921 , #921 ] | 0x7  | 0x00000000fcc00000 | 0x00000000fff99000 | 0x1000
>                 [#922 , #922 ] | 0x7  | 0x000000010266d000 | 0x00000000fff9a000 | 0x1000
>                 [#923 , #923 ] | 0x7  | 0x000000010266c000 | 0x00000000fff9b000 | 0x1000
>                 [#948 , #948 ] | 0x7  | 0x0000000102668000 | 0x00000000fffb4000 | 0x1000
>                 [#949 , #949 ] | 0x7  | 0x0000000102667000 | 0x00000000fffb5000 | 0x1000
>                 [#950 , #950 ] | 0x7  | 0x0000000102666000 | 0x00000000fffb6000 | 0x1000
>                 [#951 , #951 ] | 0x7  | 0x0000000102665000 | 0x00000000fffb7000 | 0x1000
>                 [#952 , #952 ] | 0x7  | 0x000000010264b000 | 0x00000000fffb8000 | 0x1000
>                 [#953 , #953 ] | 0x7  | 0x000000010264a000 | 0x00000000fffb9000 | 0x1000
>                 [#954 , #954 ] | 0x7  | 0x0000000102649000 | 0x00000000fffba000 | 0x1000
>                 [#955 , #955 ] | 0x7  | 0x0000000102648000 | 0x00000000fffbb000 | 0x1000
>                 [#956 , #956 ] | 0x7  | 0x000000010260f000 | 0x00000000fffbc000 | 0x1000
>                 [#957 , #957 ] | 0x7  | 0x000000010260e000 | 0x00000000fffbd000 | 0x1000
>                 [#958 , #958 ] | 0x7  | 0x000000010260d000 | 0x00000000fffbe000 | 0x1000
>                 [#959 , #959 ] | 0x7  | 0x000000010260b000 | 0x00000000fffbf000 | 0x1000
>                 [#960 , #992 ] | 0x7  | 0x00000001025ea000 | 0x00000000fffc0000 | 0x21000
>         }
> }
> Total PDEs: 1, total PTEs: 52

The patch is almost good to me, there is one nit.

On older SoCs we put multiple devices into the same shared group and the debugfs shows it as the first member of the group.

This is what we get on T30 using this v7:

# ls/sys/kernel/debug/smmu/mappings
g2  hc  vde

# cat /sys/kernel/debug/smmu/mappings/g2 
[SWGROUP: g2] [as: (id: 2), (attr: R|W|-), (pd_dma: 0x834a6000)]
{
        [index: 0] 0xf0083494 (count: 1000)
        {
                PTE RANGE      | ATTR | PHYS       | IOVA       | SIZE       
                [#0   , #15  ] | 0x7  | 0xbfde0000 | 0x00000000 | 0x10000    
                [#16  , #47  ] | 0x7  | 0xbfdc0000 | 0x00010000 | 0x20000    
                [#48  , #111 ] | 0x7  | 0xbfd80000 | 0x00030000 | 0x40000    
                [#112 , #239 ] | 0x7  | 0xbfd00000 | 0x00070000 | 0x80000    
                [#240 , #495 ] | 0x7  | 0xbfc00000 | 0x000f0000 | 0x100000   
                [#496 , #999 ] | 0x7  | 0xbf400000 | 0x001f0000 | 0x1f8000   
        }
}
Total PDEs: 1, total PTEs: 1000

See that name is "g2", meanwhile these mappings are made by display client driver.

I changed your patch to use the proper group name and to show all members of the group, see that change in the end of this email.

With my change applied, we get:

# ls/sys/kernel/debug/smmu/mappings
drm  hc  vde

# cat /sys/kernel/debug/smmu/mappings/drm 
[SWGROUP: dc, dcb, g2, nv, nv2] [as: (id: 2), (attr: R|W|-), (pd_dma: 0x82480000)]
{
        [index: 0] 0xf0083583 (count: 1000)
        {
                PTE RANGE      | ATTR | PHYS       | IOVA       | SIZE       
                [#0   , #15  ] | 0x7  | 0xbfde0000 | 0x00000000 | 0x10000    
                [#16  , #47  ] | 0x7  | 0xbfdc0000 | 0x00010000 | 0x20000    
                [#48  , #111 ] | 0x7  | 0xbfd80000 | 0x00030000 | 0x40000    
                [#112 , #239 ] | 0x7  | 0xbfd00000 | 0x00070000 | 0x80000    
                [#240 , #495 ] | 0x7  | 0xbfc00000 | 0x000f0000 | 0x100000   
                [#496 , #999 ] | 0x7  | 0xbf400000 | 0x001f0000 | 0x1f8000   
        }
}
Total PDEs: 1, total PTEs: 1000

--- >8 ---

diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c
index 575e82076270..fb1326a72038 100644
--- a/drivers/iommu/tegra-smmu.c
+++ b/drivers/iommu/tegra-smmu.c
@@ -509,6 +509,7 @@ static void tegra_smmu_as_unprepare(struct tegra_smmu *smmu,
 static int tegra_smmu_debugfs_mappings_show(struct seq_file *s, void *data)
 {
 	struct tegra_smmu_group *group = s->private;
+	const struct tegra_smmu_group_soc *soc;
 	const struct tegra_smmu_swgroup *swgrp;
 	struct tegra_smmu_as *as;
 	struct tegra_smmu *smmu;
@@ -524,6 +525,7 @@ static int tegra_smmu_debugfs_mappings_show(struct seq_file *s, void *data)
 
 	swgrp = group->swgrp;
 	smmu = group->smmu;
+	soc = group->soc;
 	as = group->as;
 
 	mutex_lock(&smmu->lock);
@@ -536,7 +538,38 @@ static int tegra_smmu_debugfs_mappings_show(struct seq_file *s, void *data)
 	if (!pd)
 		goto unlock;
 
-	seq_printf(s, "[SWGROUP: %s] ", swgrp->name);
+	seq_puts(s, "[SWGROUP: ");
+	if (soc) {
+		bool first_swgroup = true;
+		unsigned int i;
+
+		for (i = 0; i < soc->num_swgroups; i++) {
+			swgrp = tegra_smmu_find_swgrp(smmu, soc->swgroups[i]);
+
+			if (WARN_ON(!swgrp))
+				goto unlock;
+
+			val = smmu_readl(smmu, swgrp->reg);
+
+			if (!(val & SMMU_ASID_ENABLE))
+				continue;
+
+			if (WARN_ON((val & SMMU_ASID_MASK) != as->id))
+				continue;
+
+			if (first_swgroup)
+				first_swgroup = false;
+			else
+				seq_puts(s, ", ");
+
+			seq_printf(s, "%s", swgrp->name);
+		}
+	} else {
+		WARN_ON((val & SMMU_ASID_MASK) != as->id);
+		seq_printf(s, "%s", swgrp->name);
+	}
+	seq_puts(s, "] ");
+
 	seq_printf(s, "[as: (id: %d), ", as->id);
 	seq_printf(s, "(attr: %c|%c|%c), ",
 		   as->attr & SMMU_PD_READABLE ? 'R' : '-',
@@ -631,6 +664,7 @@ static void tegra_smmu_attach_as(struct tegra_smmu *smmu,
 {
 	const struct tegra_smmu_swgroup *swgrp;
 	struct tegra_smmu_group *group;
+	const char *name;
 
 	/* Find swgrp according to the swgroup id */
 	swgrp = tegra_smmu_find_swgrp(smmu, swgroup);
@@ -647,10 +681,16 @@ static void tegra_smmu_attach_as(struct tegra_smmu *smmu,
 				 "overwriting group->as for swgroup: %s\n", swgrp->name);
 		group->as = as;
 
-		if (smmu->debugfs_mappings)
-			debugfs_create_file(group->swgrp->name, 0444,
+		if (smmu->debugfs_mappings) {
+			if (group->soc)
+				name = group->soc->name;
+			else
+				name = group->swgrp->name;
+
+			debugfs_create_file(name, 0444,
 					    smmu->debugfs_mappings, group,
 					    &tegra_smmu_debugfs_mappings_fops);
+		}
 
 		break;
 	}

  reply	other threads:[~2021-12-08 14:37 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-08  8:47 [PATCH v7 0/6] iommu/tegra-smmu: Add pagetable mappings to debugfs Nicolin Chen
2021-12-08  8:47 ` [PATCH v7 1/6] iommu/tegra-smmu: Rename struct iommu_group *group to *grp Nicolin Chen
2021-12-08  8:47 ` [PATCH v7 2/6] iommu/tegra-smmu: Rename tegra_smmu_find_group to tegra_smmu_find_group_soc Nicolin Chen
2021-12-08  8:47 ` [PATCH v7 3/6] iommu/tegra-smmu: Rename struct tegra_smmu_swgroup *group to *swgrp Nicolin Chen
2021-12-08  8:47 ` [PATCH v7 4/6] iommu/tegra-smmu: Use swgrp pointer instead of swgroup id Nicolin Chen
2021-12-08  8:47 ` [PATCH v7 5/6] iommu/tegra-smmu: Attach as pointer to tegra_smmu_group Nicolin Chen
2021-12-08  8:47 ` [PATCH v7 6/6] iommu/tegra-smmu: Add pagetable mappings to debugfs Nicolin Chen
2021-12-08 14:37   ` Dmitry Osipenko [this message]
2021-12-08 14:49   ` Dmitry Osipenko
2021-12-08 16:09   ` Dmitry Osipenko
2021-12-08 20:58     ` Nicolin Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=085d4e6a-31b1-37c8-fe31-fb15119affc6@gmail.com \
    --to=digetx@gmail.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=jonathanh@nvidia.com \
    --cc=joro@8bytes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=nicolinc@nvidia.com \
    --cc=thierry.reding@gmail.com \
    --cc=vdumpa@nvidia.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox