* [PATCH] mm/damon/paddr: add KUnit tests for addr_unit conversion
@ 2026-11-08 14:23 Aveline Noir
2026-11-08 18:07 ` SJ Park
0 siblings, 1 reply; 2+ messages in thread
From: Aveline Noir @ 2026-11-08 14:23 UTC (permalink / raw)
To: SJ Park, Andrew Morton; +Cc: linux-kernel, damon, linux-mm
damon_pa_phys_addr() and damon_pa_core_addr() convert between DAMON core
addresses and physical addresses using addr_unit. addr_unit lets 32-bit
kernels with a 64-bit phys_addr_t monitor physical memory above 4 GiB,
but no test covers the conversions.
Add a KUnit suite for both helpers, including a case for addresses above
4 GiB that is skipped when phys_addr_t is 32-bit.
Signed-off-by: Aveline Noir <jm5905938@gmail.com>
---
KUnit passes on x86_64 and i386. Selftests pass on x86_64, except for
damos_quota.py, which is flaky even without this patch.
---
mm/damon/Kconfig | 12 ++++++++++
mm/damon/paddr.c | 2 ++
mm/damon/tests/.kunitconfig | 4 ++++
mm/damon/tests/paddr-kunit.h | 55 ++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 73 insertions(+)
diff --git a/mm/damon/Kconfig b/mm/damon/Kconfig
index 34631a44cdec..6f8722fcf464 100644
--- a/mm/damon/Kconfig
+++ b/mm/damon/Kconfig
@@ -65,6 +65,18 @@ config DAMON_VADDR_KUNIT_TEST
If unsure, say N.
+config DAMON_PADDR_KUNIT_TEST
+ bool "Test for DAMON physical address space operations" if !KUNIT_ALL_TESTS
+ depends on DAMON_PADDR && KUNIT=y
+ default KUNIT_ALL_TESTS
+ help
+ This builds the DAMON physical address operations Kunit test suite.
+
+ For more information on KUnit and unit tests in general, please refer
+ to the KUnit documentation.
+
+ If unsure, say N.
+
config DAMON_SYSFS
bool "DAMON sysfs interface"
depends on DAMON && SYSFS
diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index 5b773012a876..e89cb14ee17b 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -479,3 +479,5 @@ static int __init damon_pa_initcall(void)
}
subsys_initcall(damon_pa_initcall);
+
+#include "tests/paddr-kunit.h"
diff --git a/mm/damon/tests/.kunitconfig b/mm/damon/tests/.kunitconfig
index 144d27e6ecc5..9279f0c82be7 100644
--- a/mm/damon/tests/.kunitconfig
+++ b/mm/damon/tests/.kunitconfig
@@ -9,6 +9,10 @@ CONFIG_PAGE_IDLE_FLAG=y
CONFIG_DAMON_VADDR=y
CONFIG_DAMON_VADDR_KUNIT_TEST=y
+# for DAMON paddr ops
+CONFIG_DAMON_PADDR=y
+CONFIG_DAMON_PADDR_KUNIT_TEST=y
+
# for DAMON sysfs interface
CONFIG_SYSFS=y
CONFIG_DAMON_SYSFS=y
diff --git a/mm/damon/tests/paddr-kunit.h b/mm/damon/tests/paddr-kunit.h
new file mode 100644
index 000000000000..9839cc233071
--- /dev/null
+++ b/mm/damon/tests/paddr-kunit.h
@@ -0,0 +1,55 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Data Access Monitor Unit Tests
+ */
+
+#ifdef CONFIG_DAMON_PADDR_KUNIT_TEST
+
+#ifndef _DAMON_PADDR_TEST_H
+#define _DAMON_PADDR_TEST_H
+
+#include <kunit/test.h>
+
+static void damon_test_pa_phys_addr(struct kunit *test)
+{
+ KUNIT_EXPECT_EQ(test, damon_pa_phys_addr(0x1000, 1), 0x1000);
+ KUNIT_EXPECT_EQ(test, damon_pa_phys_addr(0x40000, 0x1000), 0x40000000);
+}
+
+static void damon_test_pa_core_addr(struct kunit *test)
+{
+ KUNIT_EXPECT_EQ(test, damon_pa_core_addr(0x1000000, 0x1000), 0x1000);
+ /* The conversion rounds down. */
+ KUNIT_EXPECT_EQ(test, damon_pa_core_addr(0x1fff, 0x1000), 1);
+ KUNIT_EXPECT_EQ(test, damon_pa_core_addr(0xfff, 0x1000), 0);
+}
+
+static void damon_test_pa_addr_over_4g(struct kunit *test)
+{
+ unsigned long addr = 0xffffffffUL;
+ unsigned long addr_unit = 0x1000;
+ u64 pa = 0xffffffff000ULL;
+
+ if (!IS_ENABLED(CONFIG_PHYS_ADDR_T_64BIT))
+ kunit_skip(test, "phys_addr_t is 32-bit");
+
+ KUNIT_EXPECT_EQ(test, damon_pa_phys_addr(addr, addr_unit), pa);
+ KUNIT_EXPECT_EQ(test, damon_pa_core_addr(pa, addr_unit), addr);
+}
+
+static struct kunit_case damon_paddr_test_cases[] = {
+ KUNIT_CASE(damon_test_pa_phys_addr),
+ KUNIT_CASE(damon_test_pa_core_addr),
+ KUNIT_CASE(damon_test_pa_addr_over_4g),
+ {},
+};
+
+static struct kunit_suite damon_paddr_test_suite = {
+ .name = "damon-paddr",
+ .test_cases = damon_paddr_test_cases,
+};
+kunit_test_suite(damon_paddr_test_suite);
+
+#endif /* _DAMON_PADDR_TEST_H */
+
+#endif /* CONFIG_DAMON_PADDR_KUNIT_TEST */
---
base-commit: 2c5dafa7f289d760f4492260b0988029aab478b0
change-id: 20261109-test-damon-paddr-addr-unit-kunit-b2f7e2154de8
Best regards,
--
Aveline Noir <jm5905938@gmail.com>
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] mm/damon/paddr: add KUnit tests for addr_unit conversion
2026-11-08 14:23 [PATCH] mm/damon/paddr: add KUnit tests for addr_unit conversion Aveline Noir
@ 2026-11-08 18:07 ` SJ Park
0 siblings, 0 replies; 2+ messages in thread
From: SJ Park @ 2026-11-08 18:07 UTC (permalink / raw)
To: Aveline Noir; +Cc: SJ Park, Andrew Morton, linux-kernel, damon, linux-mm
Hi Aveline,
On Mon, 09 Nov 2026 01:23:46 +1100 Aveline Noir <jm5905938@gmail.com> wrote:
> damon_pa_phys_addr() and damon_pa_core_addr() convert between DAMON core
> addresses and physical addresses using addr_unit. addr_unit lets 32-bit
> kernels with a 64-bit phys_addr_t monitor physical memory above 4 GiB,
> but no test covers the conversions.
>
> Add a KUnit suite for both helpers, including a case for addresses above
> 4 GiB that is skipped when phys_addr_t is 32-bit.
Thank you for this patch!
>
> Signed-off-by: Aveline Noir <jm5905938@gmail.com>
[...]
> --- a/mm/damon/Kconfig
> +++ b/mm/damon/Kconfig
> @@ -65,6 +65,18 @@ config DAMON_VADDR_KUNIT_TEST
>
> If unsure, say N.
>
> +config DAMON_PADDR_KUNIT_TEST
> + bool "Test for DAMON physical address space operations" if !KUNIT_ALL_TESTS
The above line has more than 80 characters. What about removing "space" ?
Other than that,
Reviewed-by: SJ Park <sj@kernel.org>
Assuming you accept my above suggestion, I modified this patch and applied to
damon/next [1] tree. I will repost it soon (~1 week) as an mm.git merge
request. So, no action from your side is needed for now.
[1] https://origin.kernel.org/doc/html/latest/mm/damon/maintainer-profile.html#scm-trees
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-08 18:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-08 14:23 [PATCH] mm/damon/paddr: add KUnit tests for addr_unit conversion Aveline Noir
2026-11-08 18:07 ` SJ Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®