From: Nicolin Chen <nicolinc@nvidia.com>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: <iommu@lists.linux.dev>, "Joerg Roedel (AMD)" <joro@8bytes.org>,
Jean-Philippe Brucker <jpb@kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
Robin Murphy <robin.murphy@arm.com>,
Will Deacon <will@kernel.org>,
David Matlack <dmatlack@google.com>,
"John Garry" <john.garry@arm.com>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
<patches@lists.linux.dev>, Pranjal Shrivastava <praan@google.com>,
"Samiullah Khawaja" <skhawaja@google.com>,
Mostafa Saleh <smostafa@google.com>
Subject: Re: [PATCH v3 05/13] iommupt/kunit: Skip test configs without supported features
Date: Mon, 23 Nov 2026 21:29:52 -0800 [thread overview]
Message-ID: <awUg0O0WQUBcuUvC@nvidia.com> (raw)
In-Reply-To: <5-v3-97feb2edfbab+748d0a-iommupt_armv8_jgg@nvidia.com>
On Sun, Nov 15, 2026 at 07:30:35PM -0400, Jason Gunthorpe wrote:
> Some of the tests configs can test features we don't currently enable,
> like TTBR1 on ARMv8. Instead of blowing up, skip the test. When
> CONFIG_DEBUG_GENERIC_PT is set all features are force enabled during
> the build so everything can be tested. That is the normal mode for the
> kunit.py runner.
>
> Reviewed-by: Pranjal Shrivastava <praan@google.com>
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
> drivers/iommu/generic_pt/kunit_iommu.h | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/drivers/iommu/generic_pt/kunit_iommu.h b/drivers/iommu/generic_pt/kunit_iommu.h
> index 79d7f9c8e7868f..558e161eacb05f 100644
> --- a/drivers/iommu/generic_pt/kunit_iommu.h
> +++ b/drivers/iommu/generic_pt/kunit_iommu.h
> @@ -134,6 +134,16 @@ static int pt_kunit_priv_init(struct kunit *test, struct kunit_iommu_priv *priv)
>
> #ifdef kunit_fmt_cfgs
> priv->cfg = kunit_fmt_cfgs[((uintptr_t)test->param_value) - 1];
> + /*
> + * Without CONFIG_DEBUG_GENERIC_PT only the format's compiled-in
> + * PT_SUPPORTED_FEATURES are available, so cfgs requesting bits outside
> + * that set cannot be tested.
> + */
> + if (priv->cfg.common.features & ~KUNIT_PT_SUPPORTED_FEATURES)
> + kunit_skip(
> + test,
> + "cfg requires features not built into this format (enable CONFIG_DEBUG_GENERIC_PT)");
The patch looks fine.
But I tried iommu_pt_kunit_test on Grace with CONFIG_PAGE_SIZE_64KB
and got this assertion:
------------------------------------------------------------
KTAP version 1
1..6
KTAP version 1
# Subtest: amdv1_mock_iommu_test
# module: kunit_iommu_mock
1..7
KTAP version 1
# Subtest: test_increase_level
ok 1 amdv1_mock_cfg_0
ok 2 amdv1_mock_cfg_1 # SKIP max_vasz_lg2 fits in starting level, no growth possible
# test_increase_level: pass:1 fail:0 skip:1 total:2
ok 1 test_increase_level
KTAP version 1
# Subtest: test_map_simple
ok 1 amdv1_mock_cfg_0
ok 2 amdv1_mock_cfg_1
# test_map_simple: pass:2 fail:0 skip:0 total:2
ok 2 test_map_simple
KTAP version 1
# Subtest: test_map_table_to_oa
# test_map_table_to_oa: Test should be marked slow (runtime: 4.997639265s)
# test_map_table_to_oa: ASSERTION FAILED at drivers/iommu/generic_pt/fmt/../kunit_iommu_pt.h:473
Expected priv->orig_nr_secondary_pagetable == global_node_page_state(NR_SECONDARY_PAGETABLE), but
priv->orig_nr_secondary_pagetable == 157 (0x9d)
global_node_page_state(NR_SECONDARY_PAGETABLE) == 174 (0xae)
# test_map_table_to_oa: test aborted during cleanup. continuing without cleaning up
[...and all other tests continued but all failed...]
------------------------------------------------------------
I asked AI to fix the issue, and it came up with a patch (attached).
I wonder if it makes sense to you.
Nicolin
From c7e0332ce5c2854e4ff23ac7cb024ad837d11986 Mon Sep 17 00:00:00 2001
From: Nicolin Chen <nicolinc@nvidia.com>
Date: Tue, 24 Nov 2026 04:41:11 +0000
Subject: [PATCH] iommupt/kunit: Include per-CPU deltas in the leak check
The leak check reads NR_SECONDARY_PAGETABLE with global_node_page_state().
That only returns the global counter. Each CPU also keeps a small delta of
page updates that is folded into the global counter only after it exceeds
a threshold. So the value can be off by a few pages without any leak.
On an arm64 KVM guest with 64 KiB pages, test_map_simple frees every page
but still sees 5 extra pages. The assertion fails in the exit callback and
aborts the cleanup. Then the dummy device stays registered, and every later
test case fails to init with -EBUSY.
Add pt_kunit_nr_secondary_pagetable(). It adds the per-CPU deltas of every
node to the global counter. Use it for both the initial and the final read.
The result is still a best-effort snapshot, because a concurrent fold can
move a delta from a CPU to the global counter between the two reads.
Also change the assertion into an expectation. A mismatch still fails the
test case, but the exit callback now finishes its cleanup. So a mismatch no
longer breaks the test cases that run after it.
Fixes: bc5233c0904e ("iommupt: Add a kunit test for the IOMMU implementation")
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
---
drivers/iommu/generic_pt/kunit_iommu.h | 2 +-
drivers/iommu/generic_pt/kunit_iommu_pt.h | 29 +++++++++++++++++++----
2 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/drivers/iommu/generic_pt/kunit_iommu.h b/drivers/iommu/generic_pt/kunit_iommu.h
index 558e161eacb05..3c098be0d8f3f 100644
--- a/drivers/iommu/generic_pt/kunit_iommu.h
+++ b/drivers/iommu/generic_pt/kunit_iommu.h
@@ -84,7 +84,7 @@ struct kunit_iommu_priv {
unsigned int largest_pgsz_lg2;
pt_oaddr_t test_oa;
pt_vaddr_t safe_pgsize_bitmap;
- unsigned long orig_nr_secondary_pagetable;
+ long orig_nr_secondary_pagetable;
};
PT_IOMMU_CHECK_DOMAIN(struct kunit_iommu_priv, fmt_table.iommu, domain);
diff --git a/drivers/iommu/generic_pt/kunit_iommu_pt.h b/drivers/iommu/generic_pt/kunit_iommu_pt.h
index 9fc71db74234d..29b882dd5b0ed 100644
--- a/drivers/iommu/generic_pt/kunit_iommu_pt.h
+++ b/drivers/iommu/generic_pt/kunit_iommu_pt.h
@@ -438,6 +438,28 @@ static struct kunit_case iommu_test_cases[] = {
{},
};
+/*
+ * global_node_page_state() only reads the global counter. Each CPU also keeps
+ * a small delta that might not be folded into the global counter yet. Add the
+ * deltas of every CPU on every node to get a closer count. This is still just
+ * a best-effort snapshot. A concurrent fold can move a delta between the reads.
+ */
+static long pt_kunit_nr_secondary_pagetable(void)
+{
+ const enum node_stat_item item = NR_SECONDARY_PAGETABLE;
+ long nr = atomic_long_read(&vm_node_stat[item]);
+ int nid, cpu;
+
+ for_each_online_node(nid) {
+ struct per_cpu_nodestat __percpu *stats =
+ NODE_DATA(nid)->per_cpu_nodestats;
+
+ for_each_online_cpu(cpu)
+ nr += per_cpu_ptr(stats, cpu)->vm_node_stat_diff[item];
+ }
+ return nr;
+}
+
static int pt_kunit_iommu_init(struct kunit *test)
{
struct kunit_iommu_priv *priv;
@@ -447,8 +469,7 @@ static int pt_kunit_iommu_init(struct kunit *test)
if (!priv)
return -ENOMEM;
- priv->orig_nr_secondary_pagetable =
- global_node_page_state(NR_SECONDARY_PAGETABLE);
+ priv->orig_nr_secondary_pagetable = pt_kunit_nr_secondary_pagetable();
ret = pt_kunit_priv_init(test, priv);
if (ret) {
kunit_kfree(test, priv);
@@ -470,8 +491,8 @@ static void pt_kunit_iommu_exit(struct kunit *test)
* Look for memory leaks, assumes kunit is running isolated and nothing
* else is using secondary page tables.
*/
- KUNIT_ASSERT_EQ(test, priv->orig_nr_secondary_pagetable,
- global_node_page_state(NR_SECONDARY_PAGETABLE));
+ KUNIT_EXPECT_EQ(test, priv->orig_nr_secondary_pagetable,
+ pt_kunit_nr_secondary_pagetable());
kunit_kfree(test, test->priv);
}
--
2.43.0
next prev parent reply other threads:[~2026-11-24 5:30 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-15 23:30 [PATCH v3 00/13] Use the generic iommu page table for SMMUv3 Jason Gunthorpe
2026-11-15 23:30 ` [PATCH v3 01/13] iommu/arm-smmu-v3: Change how the tlbi describes the invalidation Jason Gunthorpe
2026-11-15 23:30 ` [PATCH v3 02/13] iommu/arm-smmu-v3: Support the DS expansion of range invalidation SCALE Jason Gunthorpe
2026-11-15 23:30 ` [PATCH v3 03/13] iommupt: Remove the sanity check for pt_num_items_lg2() at the top level Jason Gunthorpe
2026-11-24 0:40 ` Nicolin Chen
2026-11-15 23:30 ` [PATCH v3 04/13] iommupt/kunit: Do not test INCOHERENT on anything but x86 Jason Gunthorpe
2026-11-24 0:49 ` Nicolin Chen
2026-11-15 23:30 ` [PATCH v3 05/13] iommupt/kunit: Skip test configs without supported features Jason Gunthorpe
2026-11-24 5:29 ` Nicolin Chen [this message]
2026-11-24 15:08 ` Jason Gunthorpe
2026-11-24 19:08 ` Nicolin Chen
2026-11-24 20:07 ` Jason Gunthorpe
2026-11-26 5:00 ` Nicolin Chen
2026-11-30 22:44 ` Nicolin Chen
2026-11-15 23:30 ` [PATCH v3 06/13] iommupt/armv8: Add the 64 bit ARMv8 page table format Jason Gunthorpe
2026-11-15 23:30 ` [PATCH v3 07/13] iommupt/armv8: Add DBM support Jason Gunthorpe
2026-11-15 23:30 ` [PATCH v3 08/13] iommupt/armv8: Implement the iommu specific components Jason Gunthorpe
2026-11-15 23:30 ` [PATCH v3 09/13] iommu/arm-smmu-v3: Remove io-pgtable-arm from sva.c Jason Gunthorpe
2026-11-15 23:30 ` [PATCH v3 10/13] iommu/arm-smmu-v3: Move the DMA API comment to flush_iotlb_all Jason Gunthorpe
2026-11-15 23:30 ` [PATCH v3 11/13] iommu/arm-smmu-v3: Support CONT in paging domains with errata Jason Gunthorpe
2026-11-15 23:30 ` [PATCH v3 12/13] iommu/arm-smmu-v3: Use the generic iommu page table Jason Gunthorpe
2026-11-15 23:30 ` [PATCH v3 13/13] iommu: Remove pgsize from iommu_iotlb_gather Jason Gunthorpe
2026-11-24 0:04 ` [PATCH v3 00/13] Use the generic iommu page table for SMMUv3 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=awUg0O0WQUBcuUvC@nvidia.com \
--to=nicolinc@nvidia.com \
--cc=dmatlack@google.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=john.garry@arm.com \
--cc=joro@8bytes.org \
--cc=jpb@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=pasha.tatashin@soleen.com \
--cc=patches@lists.linux.dev \
--cc=praan@google.com \
--cc=robin.murphy@arm.com \
--cc=skhawaja@google.com \
--cc=smostafa@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.