From nobody Wed Jul 1 04:16:43 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED052C433F5 for ; Sat, 1 Jan 2022 21:58:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232746AbiAAV6Z (ORCPT ); Sat, 1 Jan 2022 16:58:25 -0500 Received: from lithops.sigma-star.at ([195.201.40.130]:48678 "EHLO lithops.sigma-star.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232719AbiAAV6Z (ORCPT ); Sat, 1 Jan 2022 16:58:25 -0500 Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 739EA614E2CD; Sat, 1 Jan 2022 22:58:23 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id VqnfkIwBPEAg; Sat, 1 Jan 2022 22:58:23 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 0279B614E2EE; Sat, 1 Jan 2022 22:58:23 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id c039Ef3NOiFE; Sat, 1 Jan 2022 22:58:22 +0100 (CET) Received: from blindfold.corp.sigma-star.at (213-47-184-186.cable.dynamic.surfer.at [213.47.184.186]) by lithops.sigma-star.at (Postfix) with ESMTPSA id B2820614E2DB; Sat, 1 Jan 2022 22:58:22 +0100 (CET) From: Richard Weinberger To: linux-um@lists.infradead.org Cc: linux-kernel@vger.kernel.org, johannes.berg@intel.com, anton.ivanov@cambridgegreys.com, Richard Weinberger Subject: [PATCH 1/4] um: Run console exit code also upon kernel panic Date: Sat, 1 Jan 2022 22:58:07 +0100 Message-Id: <20220101215810.13260-2-richard@nod.at> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220101215810.13260-1-richard@nod.at> References: <20220101215810.13260-1-richard@nod.at> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 --- 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_consol= e.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); =20 -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); =20 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 + */ + +#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 #include =20 -#include +#include +#include #include +#include #include #include -#include -#include #include #include #include #include #include +#include =20 #include "um_arch.h" =20 @@ -245,6 +246,7 @@ static int panic_exit(struct notifier_block *self, unsi= gned long unused1, bust_spinlocks(1); bust_spinlocks(0); uml_exitcode =3D 1; + uml_console_exit(); os_dump_core(); return 0; } --=20 2.26.2 From nobody Wed Jul 1 04:16:43 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33224C433EF for ; Sat, 1 Jan 2022 21:58:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232769AbiAAV6a (ORCPT ); Sat, 1 Jan 2022 16:58:30 -0500 Received: from lithops.sigma-star.at ([195.201.40.130]:48700 "EHLO lithops.sigma-star.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232733AbiAAV6Z (ORCPT ); Sat, 1 Jan 2022 16:58:25 -0500 Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id D0019614E2ED; Sat, 1 Jan 2022 22:58:23 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 4wakbcodk5Q1; Sat, 1 Jan 2022 22:58:23 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 4B767614E2F1; Sat, 1 Jan 2022 22:58:23 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id D0uH1gMZpXN6; Sat, 1 Jan 2022 22:58:23 +0100 (CET) Received: from blindfold.corp.sigma-star.at (213-47-184-186.cable.dynamic.surfer.at [213.47.184.186]) by lithops.sigma-star.at (Postfix) with ESMTPSA id F305C614E2CD; Sat, 1 Jan 2022 22:58:22 +0100 (CET) From: Richard Weinberger To: linux-um@lists.infradead.org Cc: linux-kernel@vger.kernel.org, johannes.berg@intel.com, anton.ivanov@cambridgegreys.com, Richard Weinberger Subject: [PATCH 2/4] um: os_set_fd_block: Return old blocking mode Date: Sat, 1 Jan 2022 22:58:08 +0100 Message-Id: <20220101215810.13260-3-richard@nod.at> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220101215810.13260-1-richard@nod.at> References: <20220101215810.13260-1-richard@nod.at> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This will be needed when we restore the old mode upon exit. The function now returns < 0 in case of an error, 1 if O_NONBLOCK was set, 0 otherwise. Signed-off-by: Richard Weinberger --- arch/um/drivers/chan_kern.c | 8 ++++---- arch/um/drivers/chan_user.c | 2 +- arch/um/drivers/mconsole_kern.c | 2 +- arch/um/drivers/ubd_user.c | 2 +- arch/um/drivers/xterm.c | 2 +- arch/um/os-Linux/file.c | 5 ++++- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/arch/um/drivers/chan_kern.c b/arch/um/drivers/chan_kern.c index 62997055c454..86be115b5890 100644 --- a/arch/um/drivers/chan_kern.c +++ b/arch/um/drivers/chan_kern.c @@ -83,7 +83,7 @@ static const struct chan_ops not_configged_ops =3D { =20 static int open_one_chan(struct chan *chan) { - int fd, err; + int fd, ret; =20 if (chan->opened) return 0; @@ -95,10 +95,10 @@ static int open_one_chan(struct chan *chan) if (fd < 0) return fd; =20 - err =3D os_set_fd_block(fd, 0); - if (err) { + ret =3D os_set_fd_block(fd, 0); + if (ret < 0) { (*chan->ops->close)(fd, chan->data); - return err; + return ret; } =20 chan->fd =3D fd; diff --git a/arch/um/drivers/chan_user.c b/arch/um/drivers/chan_user.c index 6040817c036f..b449656cd5f8 100644 --- a/arch/um/drivers/chan_user.c +++ b/arch/um/drivers/chan_user.c @@ -257,7 +257,7 @@ static int winch_tramp(int fd, struct tty_port *port, i= nt *fd_out, } =20 err =3D os_set_fd_block(*fd_out, 0); - if (err) { + if (err < 0) { printk(UM_KERN_ERR "winch_tramp: failed to set thread_fd " "non-blocking.\n"); goto out_close; diff --git a/arch/um/drivers/mconsole_kern.c b/arch/um/drivers/mconsole_ker= n.c index 6ead1e240457..8000914f9cd4 100644 --- a/arch/um/drivers/mconsole_kern.c +++ b/arch/um/drivers/mconsole_kern.c @@ -732,7 +732,7 @@ static int __init mconsole_init(void) printk(KERN_ERR "Failed to initialize management console\n"); return 1; } - if (os_set_fd_block(sock, 0)) + if (os_set_fd_block(sock, 0) < 0) goto out; =20 register_reboot_notifier(&reboot_notifier); diff --git a/arch/um/drivers/ubd_user.c b/arch/um/drivers/ubd_user.c index a1afe414ce48..a930a254826b 100644 --- a/arch/um/drivers/ubd_user.c +++ b/arch/um/drivers/ubd_user.c @@ -42,7 +42,7 @@ int start_io_thread(unsigned long sp, int *fd_out) =20 err =3D os_set_fd_block(*fd_out, 0); err =3D os_set_fd_block(kernel_fd, 0); - if (err) { + if (err < 0) { printk("start_io_thread - failed to set nonblocking I/O.\n"); goto out_close; } diff --git a/arch/um/drivers/xterm.c b/arch/um/drivers/xterm.c index 87ca4a47cd66..01be81c25266 100644 --- a/arch/um/drivers/xterm.c +++ b/arch/um/drivers/xterm.c @@ -161,7 +161,7 @@ static int xterm_open(int input, int output, int primar= y, void *d, } =20 err =3D os_set_fd_block(new, 0); - if (err) { + if (err < 0) { printk(UM_KERN_ERR "xterm_open : failed to set xterm " "descriptor non-blocking, err =3D %d\n", -err); goto out_close2; diff --git a/arch/um/os-Linux/file.c b/arch/um/os-Linux/file.c index e4421dbc4c36..af2b3cba2c93 100644 --- a/arch/um/os-Linux/file.c +++ b/arch/um/os-Linux/file.c @@ -445,11 +445,14 @@ int os_clear_fd_async(int fd) int os_set_fd_block(int fd, int blocking) { int flags; + int oldmode; =20 flags =3D fcntl(fd, F_GETFL); if (flags < 0) return -errno; =20 + oldmode =3D !!(flags & O_NONBLOCK); + if (blocking) flags &=3D ~O_NONBLOCK; else @@ -458,7 +461,7 @@ int os_set_fd_block(int fd, int blocking) if (fcntl(fd, F_SETFL, flags) < 0) return -errno; =20 - return 0; + return oldmode; } =20 int os_accept_connection(int fd) --=20 2.26.2 From nobody Wed Jul 1 04:16:43 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03766C433F5 for ; Sat, 1 Jan 2022 21:58:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232753AbiAAV61 (ORCPT ); Sat, 1 Jan 2022 16:58:27 -0500 Received: from lithops.sigma-star.at ([195.201.40.130]:48712 "EHLO lithops.sigma-star.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232735AbiAAV6Z (ORCPT ); Sat, 1 Jan 2022 16:58:25 -0500 Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 05DD1614E2F2; Sat, 1 Jan 2022 22:58:24 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id s2QX--ih1H1p; Sat, 1 Jan 2022 22:58:23 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id A41F2614E2F0; Sat, 1 Jan 2022 22:58:23 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id GLwt1eU-o2h7; Sat, 1 Jan 2022 22:58:23 +0100 (CET) Received: from blindfold.corp.sigma-star.at (213-47-184-186.cable.dynamic.surfer.at [213.47.184.186]) by lithops.sigma-star.at (Postfix) with ESMTPSA id 45C9C614E2EF; Sat, 1 Jan 2022 22:58:23 +0100 (CET) From: Richard Weinberger To: linux-um@lists.infradead.org Cc: linux-kernel@vger.kernel.org, johannes.berg@intel.com, anton.ivanov@cambridgegreys.com, Richard Weinberger Subject: [PATCH 3/4] um: chan: Restore blocking mode upon exit Date: Sat, 1 Jan 2022 22:58:09 +0100 Message-Id: <20220101215810.13260-4-richard@nod.at> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220101215810.13260-1-richard@nod.at> References: <20220101215810.13260-1-richard@nod.at> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Make sure that O_NONBLOCK is cleared upon exit if UML sets it. Otherwise stdin/out behaves strange after UML terminates. Signed-off-by: Richard Weinberger --- arch/um/drivers/chan.h | 1 + arch/um/drivers/chan_kern.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/arch/um/drivers/chan.h b/arch/um/drivers/chan.h index c37cc4f26f91..6b8c462f146e 100644 --- a/arch/um/drivers/chan.h +++ b/arch/um/drivers/chan.h @@ -22,6 +22,7 @@ struct chan { unsigned int output:1; unsigned int opened:1; unsigned int enabled:1; + unsigned int fd_blocking:1; int fd; const struct chan_ops *ops; void *data; diff --git a/arch/um/drivers/chan_kern.c b/arch/um/drivers/chan_kern.c index 86be115b5890..6d512589fa50 100644 --- a/arch/um/drivers/chan_kern.c +++ b/arch/um/drivers/chan_kern.c @@ -102,6 +102,7 @@ static int open_one_chan(struct chan *chan) } =20 chan->fd =3D fd; + chan->fd_blocking =3D ret; =20 chan->opened =3D 1; return 0; @@ -223,6 +224,8 @@ static void close_one_chan(struct chan *chan, int delay= _free_irq) if (chan->ops->close !=3D NULL) (*chan->ops->close)(chan->fd, chan->data); =20 + os_set_fd_block(chan->fd, chan->fd_blocking); + chan->opened =3D 0; chan->fd =3D -1; } --=20 2.26.2 From nobody Wed Jul 1 04:16:43 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42414C433EF for ; Sat, 1 Jan 2022 21:58:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232782AbiAAV6c (ORCPT ); Sat, 1 Jan 2022 16:58:32 -0500 Received: from lithops.sigma-star.at ([195.201.40.130]:48722 "EHLO lithops.sigma-star.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232736AbiAAV6Z (ORCPT ); Sat, 1 Jan 2022 16:58:25 -0500 Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 44FEB614E2EE; Sat, 1 Jan 2022 22:58:24 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id O1xi_jvJo9ku; Sat, 1 Jan 2022 22:58:24 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id ECF2F614E2F1; Sat, 1 Jan 2022 22:58:23 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 2WzYrs5O1-Md; Sat, 1 Jan 2022 22:58:23 +0100 (CET) Received: from blindfold.corp.sigma-star.at (213-47-184-186.cable.dynamic.surfer.at [213.47.184.186]) by lithops.sigma-star.at (Postfix) with ESMTPSA id 97B18614E2EE; Sat, 1 Jan 2022 22:58:23 +0100 (CET) From: Richard Weinberger To: linux-um@lists.infradead.org Cc: linux-kernel@vger.kernel.org, johannes.berg@intel.com, anton.ivanov@cambridgegreys.com, Richard Weinberger Subject: [PATCH 4/4] um: irq: Restore O_ASYNC upon exit Date: Sat, 1 Jan 2022 22:58:10 +0100 Message-Id: <20220101215810.13260-5-richard@nod.at> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220101215810.13260-1-richard@nod.at> References: <20220101215810.13260-1-richard@nod.at> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Just like with O_NONBLOCK, make sure UML clears O_ASYNC upon exit when it set it. Signed-off-by: Richard Weinberger --- arch/um/kernel/irq.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/um/kernel/irq.c b/arch/um/kernel/irq.c index a8873d9bc28b..e020bdccfa23 100644 --- a/arch/um/kernel/irq.c +++ b/arch/um/kernel/irq.c @@ -342,6 +342,7 @@ static void free_irq_by_irq_and_dev(unsigned int irq, v= oid *dev) continue; =20 os_del_epoll_fd(entry->fd); + os_clear_fd_async(entry->fd); reg->events =3D 0; update_or_free_irq_entry(entry); goto out; @@ -396,8 +397,10 @@ int deactivate_all_fds(void) os_set_ioignore(); =20 /* we can no longer call kfree() here so just deactivate */ - list_for_each_entry(entry, &active_fds, list) + list_for_each_entry(entry, &active_fds, list) { os_del_epoll_fd(entry->fd); + os_clear_fd_async(entry->fd); + } os_close_epoll_fd(); return 0; } --=20 2.26.2