2022-01-01 21:58:28

by Richard Weinberger

[permalink] [raw]
Subject: [PATCH 1/4] um: Run console exit code also upon kernel panic

Make sure that UML's console exit handler run also when the kernel
crashes.
That way settings and resources can get restored.

Signed-off-by: Richard Weinberger <[email protected]>
---
arch/um/drivers/stdio_console.c | 4 ++--
arch/um/include/shared/uml_console.h | 11 +++++++++++
arch/um/kernel/um_arch.c | 8 +++++---
3 files changed, 18 insertions(+), 5 deletions(-)
create mode 100644 arch/um/include/shared/uml_console.h

diff --git a/arch/um/drivers/stdio_console.c b/arch/um/drivers/stdio_console.c
index e8b762f4d8c2..06612c3b6240 100644
--- a/arch/um/drivers/stdio_console.c
+++ b/arch/um/drivers/stdio_console.c
@@ -180,13 +180,13 @@ static int stdio_init(void)
}
late_initcall(stdio_init);

-static void console_exit(void)
+void uml_console_exit(void)
{
if (!con_init_done)
return;
close_lines(vts, ARRAY_SIZE(vts));
}
-__uml_exitcall(console_exit);
+__uml_exitcall(uml_console_exit);

static int console_chan_setup(char *str)
{
diff --git a/arch/um/include/shared/uml_console.h b/arch/um/include/shared/uml_console.h
new file mode 100644
index 000000000000..aa8d02fe5e90
--- /dev/null
+++ b/arch/um/include/shared/uml_console.h
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2022 Richard Weinberger <[email protected]>
+ */
+
+#ifndef UML_CONSOLE_H
+#define UML_CONSOLE_H
+
+extern void uml_console_exit(void);
+
+#endif /* UML_CONSOLE_H */
diff --git a/arch/um/kernel/um_arch.c b/arch/um/kernel/um_arch.c
index abceeabe29b9..0bdae61929ef 100644
--- a/arch/um/kernel/um_arch.c
+++ b/arch/um/kernel/um_arch.c
@@ -17,17 +17,18 @@
#include <linux/kmsg_dump.h>
#include <linux/suspend.h>

-#include <asm/processor.h>
+#include <arch.h>
+#include <as-layout.h>
#include <asm/cpufeature.h>
+#include <asm/processor.h>
#include <asm/sections.h>
#include <asm/setup.h>
-#include <as-layout.h>
-#include <arch.h>
#include <init.h>
#include <kern.h>
#include <kern_util.h>
#include <mem_user.h>
#include <os.h>
+#include <uml_console.h>

#include "um_arch.h"

@@ -245,6 +246,7 @@ static int panic_exit(struct notifier_block *self, unsigned long unused1,
bust_spinlocks(1);
bust_spinlocks(0);
uml_exitcode = 1;
+ uml_console_exit();
os_dump_core();
return 0;
}
--
2.26.2



2022-01-04 08:56:13

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH 1/4] um: Run console exit code also upon kernel panic

On Sat, 2022-01-01 at 22:58 +0100, Richard Weinberger wrote:
>
> diff --git a/arch/um/include/shared/uml_console.h b/arch/um/include/shared/uml_console.h
> new file mode 100644
> index 000000000000..aa8d02fe5e90
> --- /dev/null
> +++ b/arch/um/include/shared/uml_console.h
> @@ -0,0 +1,11 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Copyright (C) 2022 Richard Weinberger <[email protected]>
> + */
> +
> +#ifndef UML_CONSOLE_H
> +#define UML_CONSOLE_H
> +
> +extern void uml_console_exit(void);
>

Not sure it's worth adding a whole new file just for this, but also
doesn't really matter :)

johannes