[PATCH 0/4] microblaze: KUnit support

0 views
Skip to first unread message

Thomas Weißschuh

unread,
Aug 4, 2026, 1:32:38 AM (12 days ago) Aug 4
to Michal Simek, Brendan Higgins, David Gow, Rae Moar, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Thomas Weißschuh
Add the necessary prerequisites and configuration to run KUnit on
microblaze.

Please note that various KUnit tests will fail with the default
configuration as the memmove() implementation from
arch/microblaze/lib/memmove.c seems to be broken.

Signed-off-by: Thomas Weißschuh <li...@weissschuh.net>
---
Thomas Weißschuh (4):
microblaze: uaccess: Zero out destination on failed get_user()
microblaze: reset: Call POWER_OFF handlers
microblaze: reset: Provide a power off handler through an unaligned PC
kunit: qemu_configs: Add microblaze configuration

arch/microblaze/Kconfig | 9 +++++++++
arch/microblaze/include/asm/uaccess.h | 3 ++-
arch/microblaze/kernel/reset.c | 22 ++++++++++++++++++++++
tools/testing/kunit/qemu_configs/microblaze.py | 17 +++++++++++++++++
4 files changed, 50 insertions(+), 1 deletion(-)
---
base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482
change-id: 20260802-kunit-microblaze-7a3f6ac88b4d

Best regards,
--
Thomas Weißschuh <li...@weissschuh.net>

Thomas Weißschuh

unread,
Aug 4, 2026, 1:32:39 AM (12 days ago) Aug 4
to Michal Simek, Brendan Higgins, David Gow, Rae Moar, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Thomas Weißschuh
Add a basic configuration to run kunit tests on microblaze.

Signed-off-by: Thomas Weißschuh <li...@weissschuh.net>
---
tools/testing/kunit/qemu_configs/microblaze.py | 17 +++++++++++++++++
1 file changed, 17 insertions(+)

diff --git a/tools/testing/kunit/qemu_configs/microblaze.py b/tools/testing/kunit/qemu_configs/microblaze.py
new file mode 100644
index 000000000000..ff012095e77d
--- /dev/null
+++ b/tools/testing/kunit/qemu_configs/microblaze.py
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0-only
+from ..qemu_config import QemuArchParams
+
+QEMU_ARCH = QemuArchParams(linux_arch='microblaze',
+ kconfig='''
+CONFIG_CPU_BIG_ENDIAN=y
+CONFIG_SERIAL_UARTLITE=y
+CONFIG_SERIAL_UARTLITE_CONSOLE=y
+CONFIG_MB_POWER_OFF_THROUGH_UNALIGNED_PC=y
+''',
+ qemu_arch='microblaze',
+ kernel_path='arch/microblaze/boot/linux.bin',
+ kernel_command_line='kunit_shutdown=poweroff',
+ extra_qemu_params=[
+ '-M', 'petalogix-s3adsp1800',
+ ],
+)

--
2.55.0

Thomas Weißschuh

unread,
Aug 4, 2026, 1:32:39 AM (12 days ago) Aug 4
to Michal Simek, Brendan Higgins, David Gow, Rae Moar, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Thomas Weißschuh
On failure get_user() is supposed to zero out the destination variable.
This is documented in the kdoc of the microblaze get_user()
implementation and validated in lib/tests/usercopy_kunit.c.

Currently that zeroing is missing.

Add it.

Fixes: 0d6de9532663 ("microblaze_mmu_v2: uaccess MMU update")
Signed-off-by: Thomas Weißschuh <li...@weissschuh.net>
---
arch/microblaze/include/asm/uaccess.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/microblaze/include/asm/uaccess.h b/arch/microblaze/include/asm/uaccess.h
index afa0dd8d013f..77203af255e5 100644
--- a/arch/microblaze/include/asm/uaccess.h
+++ b/arch/microblaze/include/asm/uaccess.h
@@ -95,7 +95,8 @@ extern long __user_bad(void);
#define get_user(x, ptr) ({ \
const typeof(*(ptr)) __user *__gu_ptr = (ptr); \
access_ok(__gu_ptr, sizeof(*__gu_ptr)) ? \
- __get_user(x, __gu_ptr) : -EFAULT; \
+ __get_user(x, __gu_ptr) : \
+ ((x) = 0, -EFAULT); \
})

#define __get_user(x, ptr) \

--
2.55.0

Thomas Weißschuh

unread,
Aug 4, 2026, 1:32:39 AM (12 days ago) Aug 4
to Michal Simek, Brendan Higgins, David Gow, Rae Moar, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Thomas Weißschuh
microblaze is missing a generic architecture-wide power off mechanism.

To enable KUnit for microblaze it is necessary for KUnit to shut down
the machine in a way that QEMU will recognize. The machines emulated by
QEMU do not provide machine-specific power off functionality which could
be used.
However at least the petalogix-s3adsp1800 machine will abort if an
unaligned instruction is executed. An ugly message will be printed but
that is not an issue for KUnit.

Make use of this to provide a power off handler.

Signed-off-by: Thomas Weißschuh <li...@weissschuh.net>

---
This is quite hacky. But I didn't find a better solution.
---
arch/microblaze/Kconfig | 9 +++++++++
arch/microblaze/kernel/reset.c | 21 +++++++++++++++++++++
2 files changed, 30 insertions(+)

diff --git a/arch/microblaze/Kconfig b/arch/microblaze/Kconfig
index 484ebb3baedf..0ca8999dd770 100644
--- a/arch/microblaze/Kconfig
+++ b/arch/microblaze/Kconfig
@@ -216,3 +216,12 @@ config MB_MANAGER
Say N here unless you know what you are doing.

endmenu
+
+config MB_POWER_OFF_THROUGH_UNALIGNED_PC
+ bool "Power off through unaligned PC"
+ help
+ This options adds a power off handler which executes an unaligned PC
+ so the machine resets in a generic way. This works for the
+ petalogix-s3adsp1800 QEMU machine.
+
+ Say N here unless you know what you are doing.
diff --git a/arch/microblaze/kernel/reset.c b/arch/microblaze/kernel/reset.c
index 3612a20ca16d..4af660deed3b 100644
--- a/arch/microblaze/kernel/reset.c
+++ b/arch/microblaze/kernel/reset.c
@@ -41,3 +41,24 @@ void machine_restart(char *cmd)
pr_emerg("Reboot failed -- System halted\n");
while (1);
}
+
+#ifdef CONFIG_MB_POWER_OFF_THROUGH_UNALIGNED_PC
+static int unaligned_pc_sys_off(struct sys_off_data *data)
+{
+ __asm__(
+ "bri 1\n"
+ );
+
+ return NOTIFY_DONE;
+}
+
+static int __init register_unaligned_pc_sys_off(void)
+{
+ struct sys_off_handler *sys_off;
+
+ sys_off = register_sys_off_handler(SYS_OFF_MODE_POWER_OFF, SYS_OFF_PRIO_LOW,
+ unaligned_pc_sys_off, NULL);
+ return PTR_ERR_OR_ZERO(sys_off);
+}
+device_initcall(register_unaligned_pc_sys_off);
+#endif /* CONFIG_MB_POWER_OFF_THROUGH_UNALIGNED_PC */

--
2.55.0

David Gow

unread,
Aug 5, 2026, 9:59:09 AM (11 days ago) Aug 5
to Thomas Weißschuh, Michal Simek, Brendan Higgins, Rae Moar, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com
Le 04/08/2026 à 13:32, Thomas Weißschuh a écrit :
> On failure get_user() is supposed to zero out the destination variable.
> This is documented in the kdoc of the microblaze get_user()
> implementation and validated in lib/tests/usercopy_kunit.c.
>
> Currently that zeroing is missing.
>
> Add it.
>
> Fixes: 0d6de9532663 ("microblaze_mmu_v2: uaccess MMU update")
> Signed-off-by: Thomas Weißschuh <li...@weissschuh.net>
> ---

This test seems to be the gift which keeps on giving. Every architecture
seems to have had a buggy get_user() at some point.

Reviewed-by: David Gow <da...@davidgow.net>

Cheers,
-- David

David Gow

unread,
Aug 5, 2026, 9:59:21 AM (11 days ago) Aug 5
to Thomas Weißschuh, Michal Simek, Brendan Higgins, Rae Moar, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com
Le 04/08/2026 à 13:32, Thomas Weißschuh a écrit :
> microblaze is missing a generic architecture-wide power off mechanism.
>
> To enable KUnit for microblaze it is necessary for KUnit to shut down
> the machine in a way that QEMU will recognize. The machines emulated by
> QEMU do not provide machine-specific power off functionality which could
> be used.
> However at least the petalogix-s3adsp1800 machine will abort if an
> unaligned instruction is executed. An ugly message will be printed but
> that is not an issue for KUnit.
>
> Make use of this to provide a power off handler.
>
> Signed-off-by: Thomas Weißschuh <li...@weissschuh.net>
>
> ---
> This is quite hacky. But I didn't find a better solution.

This is hacky. It does work fine here, though, and I also don't have a
better solution. But I'd feel better about it if a Microblaze person has
seen it and at least not complained too loudly.

Tested-by: David Gow <da...@davidgow.net>

David Gow

unread,
Aug 5, 2026, 9:59:22 AM (11 days ago) Aug 5
to Thomas Weißschuh, Michal Simek, Brendan Higgins, Rae Moar, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com
Le 04/08/2026 à 13:32, Thomas Weißschuh a écrit :
> Add a basic configuration to run kunit tests on microblaze.
>
> Signed-off-by: Thomas Weißschuh <li...@weissschuh.net>
> ---

Works well here, though there are still a couple of test failures (and a
longer timeout is needed to get through them all on my machine):

> Testing complete. Ran 965 tests: passed: 866, failed: 3, skipped: 96
> Failures: blake2s.test_hash_alignment_consistency,
memcpy.memmove_overlap_test, printf.dentry


I'm okay with this going in via either the microblaze or KUnit trees.
Any preferences?

Reviewed-by: David Gow <da...@davidgow.net>

Cheers,
-- David

Thomas Weißschuh

unread,
Aug 5, 2026, 3:18:36 PM (11 days ago) Aug 5
to David Gow, Michal Simek, Brendan Higgins, Rae Moar, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com
On 2026-08-05 21:59:16+0800, David Gow wrote:
> Le 04/08/2026 à 13:32, Thomas Weißschuh a écrit :
> > Add a basic configuration to run kunit tests on microblaze.
> >
> > Signed-off-by: Thomas Weißschuh <li...@weissschuh.net>
> > ---
>
> Works well here, though there are still a couple of test failures (and a
> longer timeout is needed to get through them all on my machine):
>
> > Testing complete. Ran 965 tests: passed: 866, failed: 3, skipped: 96
> > Failures: blake2s.test_hash_alignment_consistency,
> memcpy.memmove_overlap_test, printf.dentry

These are all due to the broken memmove() implementation.

It should be fixed by *either*:
- Disabling CONFIG_OPT_LIB_FUNCTION
- Enabling CONFIG_OPT_LIB_ASM

> I'm okay with this going in via either the microblaze or KUnit trees. Any
> preferences?

None from me. I would have expected it to go through microblaze, though.

> Reviewed-by: David Gow <da...@davidgow.net>

Thanks!

(...)
Reply all
Reply to author
Forward
0 new messages