kernel shell, stacks shell commands: iterate unlocked on SMP

call k_thread_foreach_unlocked to avoid assertions caused
by calling shell_print while holding a global lock

Signed-off-by: Maxim Adelman <imax@meta.com>
(cherry picked from commit ecf2cb5932156c889b7886609a652abe79cc16fa)
diff --git a/subsys/shell/modules/kernel_service.c b/subsys/shell/modules/kernel_service.c
index 71ff4ab..94940dd 100644
--- a/subsys/shell/modules/kernel_service.c
+++ b/subsys/shell/modules/kernel_service.c
@@ -140,7 +140,12 @@
 
 	shell_print(shell, "Scheduler: %u since last call", sys_clock_elapsed());
 	shell_print(shell, "Threads:");
+
+#ifdef CONFIG_SMP
+	k_thread_foreach_unlocked(shell_tdata_dump, (void *)shell);
+#else
 	k_thread_foreach(shell_tdata_dump, (void *)shell);
+#endif
 	return 0;
 }
 
@@ -184,7 +189,12 @@
 
 	ARG_UNUSED(argc);
 	ARG_UNUSED(argv);
+
+#ifdef CONFIG_SMP
+	k_thread_foreach_unlocked(shell_stack_dump, (void *)shell);
+#else
 	k_thread_foreach(shell_stack_dump, (void *)shell);
+#endif
 
 	/* Placeholder logic for interrupt stack until we have better
 	 * kernel support, including dumping arch-specific exception-related