* [PATCH 1/4] microblaze: uaccess: Zero out destination on failed get_user()
2026-08-04 5:32 [PATCH 0/4] microblaze: KUnit support Thomas Weißschuh
@ 2026-08-04 5:32 ` Thomas Weißschuh
2026-08-05 13:59 ` David Gow
2026-08-04 5:32 ` [PATCH 2/4] microblaze: reset: Call POWER_OFF handlers Thomas Weißschuh
` (2 subsequent siblings)
3 siblings, 1 reply; 10+ messages in thread
From: Thomas Weißschuh @ 2026-08-04 5:32 UTC (permalink / raw)
To: Michal Simek, Brendan Higgins, David Gow, Rae Moar
Cc: linux-kernel, linux-kselftest, kunit-dev, 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 <linux@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
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 1/4] microblaze: uaccess: Zero out destination on failed get_user()
2026-08-04 5:32 ` [PATCH 1/4] microblaze: uaccess: Zero out destination on failed get_user() Thomas Weißschuh
@ 2026-08-05 13:59 ` David Gow
0 siblings, 0 replies; 10+ messages in thread
From: David Gow @ 2026-08-05 13:59 UTC (permalink / raw)
To: Thomas Weißschuh, Michal Simek, Brendan Higgins, Rae Moar
Cc: linux-kernel, linux-kselftest, kunit-dev
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 <linux@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 <david@davidgow.net>
Cheers,
-- David
> 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) \
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/4] microblaze: reset: Call POWER_OFF handlers
2026-08-04 5:32 [PATCH 0/4] microblaze: KUnit support Thomas Weißschuh
2026-08-04 5:32 ` [PATCH 1/4] microblaze: uaccess: Zero out destination on failed get_user() Thomas Weißschuh
@ 2026-08-04 5:32 ` Thomas Weißschuh
2026-08-05 13:59 ` David Gow
2026-08-04 5:32 ` [PATCH 3/4] microblaze: reset: Provide a power off handler through an unaligned PC Thomas Weißschuh
2026-08-04 5:32 ` [PATCH 4/4] kunit: qemu_configs: Add microblaze configuration Thomas Weißschuh
3 siblings, 1 reply; 10+ messages in thread
From: Thomas Weißschuh @ 2026-08-04 5:32 UTC (permalink / raw)
To: Michal Simek, Brendan Higgins, David Gow, Rae Moar
Cc: linux-kernel, linux-kselftest, kunit-dev, Thomas Weißschuh
System power off might be implemented through sys_off handlers.
Currently these are not respected on microblaze.
On power_off call into the generic power off function which will execute
all regustered handlers.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
arch/microblaze/kernel/reset.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/microblaze/kernel/reset.c b/arch/microblaze/kernel/reset.c
index 2f66c7963084..3612a20ca16d 100644
--- a/arch/microblaze/kernel/reset.c
+++ b/arch/microblaze/kernel/reset.c
@@ -27,6 +27,7 @@ void machine_halt(void)
void machine_power_off(void)
{
+ do_kernel_power_off();
pr_notice("Machine power off...\n");
while (1)
;
--
2.55.0
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 2/4] microblaze: reset: Call POWER_OFF handlers
2026-08-04 5:32 ` [PATCH 2/4] microblaze: reset: Call POWER_OFF handlers Thomas Weißschuh
@ 2026-08-05 13:59 ` David Gow
0 siblings, 0 replies; 10+ messages in thread
From: David Gow @ 2026-08-05 13:59 UTC (permalink / raw)
To: Thomas Weißschuh, Michal Simek, Brendan Higgins, Rae Moar
Cc: linux-kernel, linux-kselftest, kunit-dev
Le 04/08/2026 à 13:32, Thomas Weißschuh a écrit :
> System power off might be implemented through sys_off handlers.
>
> Currently these are not respected on microblaze.
>
> On power_off call into the generic power off function which will execute
> all regustered handlers.
>
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
Seems sensible enough.
Acked-by: David Gow <david@davidgow.net>
Cheers,
-- David
> arch/microblaze/kernel/reset.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/arch/microblaze/kernel/reset.c b/arch/microblaze/kernel/reset.c
> index 2f66c7963084..3612a20ca16d 100644
> --- a/arch/microblaze/kernel/reset.c
> +++ b/arch/microblaze/kernel/reset.c
> @@ -27,6 +27,7 @@ void machine_halt(void)
>
> void machine_power_off(void)
> {
> + do_kernel_power_off();
> pr_notice("Machine power off...\n");
> while (1)
> ;
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 3/4] microblaze: reset: Provide a power off handler through an unaligned PC
2026-08-04 5:32 [PATCH 0/4] microblaze: KUnit support Thomas Weißschuh
2026-08-04 5:32 ` [PATCH 1/4] microblaze: uaccess: Zero out destination on failed get_user() Thomas Weißschuh
2026-08-04 5:32 ` [PATCH 2/4] microblaze: reset: Call POWER_OFF handlers Thomas Weißschuh
@ 2026-08-04 5:32 ` Thomas Weißschuh
2026-08-05 13:59 ` David Gow
2026-08-04 5:32 ` [PATCH 4/4] kunit: qemu_configs: Add microblaze configuration Thomas Weißschuh
3 siblings, 1 reply; 10+ messages in thread
From: Thomas Weißschuh @ 2026-08-04 5:32 UTC (permalink / raw)
To: Michal Simek, Brendan Higgins, David Gow, Rae Moar
Cc: linux-kernel, linux-kselftest, kunit-dev, 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 <linux@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
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 3/4] microblaze: reset: Provide a power off handler through an unaligned PC
2026-08-04 5:32 ` [PATCH 3/4] microblaze: reset: Provide a power off handler through an unaligned PC Thomas Weißschuh
@ 2026-08-05 13:59 ` David Gow
0 siblings, 0 replies; 10+ messages in thread
From: David Gow @ 2026-08-05 13:59 UTC (permalink / raw)
To: Thomas Weißschuh, Michal Simek, Brendan Higgins, Rae Moar
Cc: linux-kernel, linux-kselftest, kunit-dev
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 <linux@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 <david@davidgow.net>
> ---
> 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 */
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 4/4] kunit: qemu_configs: Add microblaze configuration
2026-08-04 5:32 [PATCH 0/4] microblaze: KUnit support Thomas Weißschuh
` (2 preceding siblings ...)
2026-08-04 5:32 ` [PATCH 3/4] microblaze: reset: Provide a power off handler through an unaligned PC Thomas Weißschuh
@ 2026-08-04 5:32 ` Thomas Weißschuh
2026-08-05 13:59 ` David Gow
3 siblings, 1 reply; 10+ messages in thread
From: Thomas Weißschuh @ 2026-08-04 5:32 UTC (permalink / raw)
To: Michal Simek, Brendan Higgins, David Gow, Rae Moar
Cc: linux-kernel, linux-kselftest, kunit-dev, Thomas Weißschuh
Add a basic configuration to run kunit tests on microblaze.
Signed-off-by: Thomas Weißschuh <linux@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
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 4/4] kunit: qemu_configs: Add microblaze configuration
2026-08-04 5:32 ` [PATCH 4/4] kunit: qemu_configs: Add microblaze configuration Thomas Weißschuh
@ 2026-08-05 13:59 ` David Gow
2026-08-05 19:18 ` Thomas Weißschuh
0 siblings, 1 reply; 10+ messages in thread
From: David Gow @ 2026-08-05 13:59 UTC (permalink / raw)
To: Thomas Weißschuh, Michal Simek, Brendan Higgins, Rae Moar
Cc: linux-kernel, linux-kselftest, kunit-dev
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 <linux@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 <david@davidgow.net>
Cheers,
-- David
> 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',
> + ],
> +)
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 4/4] kunit: qemu_configs: Add microblaze configuration
2026-08-05 13:59 ` David Gow
@ 2026-08-05 19:18 ` Thomas Weißschuh
0 siblings, 0 replies; 10+ messages in thread
From: Thomas Weißschuh @ 2026-08-05 19:18 UTC (permalink / raw)
To: David Gow
Cc: Michal Simek, Brendan Higgins, Rae Moar, linux-kernel,
linux-kselftest, kunit-dev
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 <linux@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 <david@davidgow.net>
Thanks!
(...)
^ permalink raw reply [flat|nested] 10+ messages in thread