Re: [PATCH v2] iommupt/kunit: Skip the page-table leak check on SMP
From: desobei
Date: Thu Nov 19 2026 - 00:19:22 EST
On Sat, Oct 31, 2026 at 04:55:36PM +0800, fangyu.yu@xxxxxxxxxxxxxxxxx wrote:
> NR_SECONDARY_PAGETABLE is batched per-CPU on SMP, so the global counter
> can change as pending updates are folded, even when a test has freed all
> its page tables. Comparing the global counter before and after a test
> can therefore report a false leak. A failed teardown assertion also
> aborts cleanup, causing subsequent tests to fail because the test driver
> is still registered.
I hit this independently on next-20261117, with the KUnit tests built
in and booted in x86_64 QEMU/KVM guests with KASAN, lockdep, UBSAN and
kmemleak enabled. The first false report aborted the cleanup, and every
later test case of the amdv1, vtdss and x86_64 iommu_test and fmt_test
suites then failed with "Driver 'pt_kunit_dev' is already registered".
With this patch applied, all six suites pass with 1 and 8 vCPUs, and
there are no KASAN, UBSAN or lockdep reports.
Tested-by: desobei <desobei@xxxxxxxxxxx>
> * 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));
> + /* Per-CPU vmstat batching can cause false leak reports on SMP. */
> + if (!IS_ENABLED(CONFIG_SMP))
> + KUNIT_ASSERT_EQ(test, priv->orig_nr_secondary_pagetable,
> + global_node_page_state(NR_SECONDARY_PAGETABLE));
A small follow-up thought, not a blocker: on !SMP this is still an
assertion in the exit handler, so a real leak there would again skip the
cleanup and break the suites that run afterwards. KUNIT_EXPECT_EQ()
would still fail the test case but let the cleanup finish. In my testing
on SMP, switching the original check to KUNIT_EXPECT_EQ() was enough to
stop the "already registered" failures.
I debugged this with the help of an AI coding assistant
(Claude Opus 5.5).