um: Improve panic notifiers consistency and ordering
authorGuilherme G. Piccoli <gpiccoli@igalia.com>
Fri, 19 Aug 2022 22:17:24 +0000 (19:17 -0300)
committerRichard Weinberger <richard@nod.at>
Mon, 19 Sep 2022 21:04:54 +0000 (23:04 +0200)
Currently the panic notifiers from user mode linux don't follow
the convention for most of the other notifiers present in the
kernel (indentation, priority setting, numeric return).
More important, the priorities could be improved, since it's a
special case (userspace), hence we could run the notifiers earlier;
user mode linux shouldn't care much with other panic notifiers but
the ordering among the mconsole and arch notifier is important,
given that the arch one effectively triggers a core dump.

Fix that by running the mconsole notifier as the first panic
notifier, followed by the architecture one (that coredumps).

Cc: Anton Ivanov <anton.ivanov@cambridgegreys.com>
Cc: Johannes Berg <johannes@sipsolutions.net>
Cc: Richard Weinberger <richard@nod.at>
Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
V3:
- No changes.

V2:
- Kept the notifier header to avoid implicit usage - thanks
Johannes for the suggestion!

Signed-off-by: Richard Weinberger <richard@nod.at>
arch/um/drivers/mconsole_kern.c
arch/um/kernel/um_arch.c

index 8ca67a69268306c8c3ca17857d5efcd9c380e0e6..69af3ce8407af1bc6b53a654148eea0e2820a667 100644 (file)
@@ -846,13 +846,12 @@ static int notify_panic(struct notifier_block *self, unsigned long unused1,
 
        mconsole_notify(notify_socket, MCONSOLE_PANIC, message,
                        strlen(message) + 1);
-       return 0;
+       return NOTIFY_DONE;
 }
 
 static struct notifier_block panic_exit_notifier = {
-       .notifier_call          = notify_panic,
-       .next                   = NULL,
-       .priority               = 1
+       .notifier_call  = notify_panic,
+       .priority       = INT_MAX, /* run as soon as possible */
 };
 
 static int add_notifier(void)
index 0f2adc9a95a2a1db4b723f3b1a8c933a9b5bb200..754d29a387a8190b9447fdc87b4c8d08ab122ec1 100644 (file)
@@ -247,13 +247,13 @@ static int panic_exit(struct notifier_block *self, unsigned long unused1,
        bust_spinlocks(0);
        uml_exitcode = 1;
        os_dump_core();
-       return 0;
+
+       return NOTIFY_DONE;
 }
 
 static struct notifier_block panic_exit_notifier = {
-       .notifier_call          = panic_exit,
-       .next                   = NULL,
-       .priority               = 0
+       .notifier_call  = panic_exit,
+       .priority       = INT_MAX - 1, /* run as 2nd notifier, won't return */
 };
 
 void uml_finishsetup(void)