All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] um: Assorted console related fixes
@ 2022-01-01 21:58 ` Richard Weinberger
  0 siblings, 0 replies; 27+ messages in thread
From: Richard Weinberger @ 2022-01-01 21:58 UTC (permalink / raw)
  To: linux-um; +Cc: linux-kernel, johannes.berg, anton.ivanov, Richard Weinberger

When UML terminates (gracefully or panic) it does not always
cleanup on the host side.
Especially when fd:0,fd:1 is used as console it can leave a misconfigured
stdin/out on the host side.
Also stale processes such as port-helper can left behind.

This series fixes the console exit code to make sure UML
undoes everything it changed on the host side.

Richard Weinberger (4):
  um: Run console exit code also upon kernel panic
  um: os_set_fd_block: Return old blocking mode
  um: chan: Restore blocking mode upon exit
  um: irq: Restore O_ASYNC upon exit

 arch/um/drivers/chan.h               |  1 +
 arch/um/drivers/chan_kern.c          | 11 +++++++----
 arch/um/drivers/chan_user.c          |  2 +-
 arch/um/drivers/mconsole_kern.c      |  2 +-
 arch/um/drivers/stdio_console.c      |  4 ++--
 arch/um/drivers/ubd_user.c           |  2 +-
 arch/um/drivers/xterm.c              |  2 +-
 arch/um/include/shared/uml_console.h | 11 +++++++++++
 arch/um/kernel/irq.c                 |  5 ++++-
 arch/um/kernel/um_arch.c             |  8 +++++---
 arch/um/os-Linux/file.c              |  5 ++++-
 11 files changed, 38 insertions(+), 15 deletions(-)
 create mode 100644 arch/um/include/shared/uml_console.h

-- 
2.26.2


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 0/4] um: Assorted console related fixes
@ 2022-01-01 21:58 ` Richard Weinberger
  0 siblings, 0 replies; 27+ messages in thread
From: Richard Weinberger @ 2022-01-01 21:58 UTC (permalink / raw)
  To: linux-um; +Cc: linux-kernel, johannes.berg, anton.ivanov, Richard Weinberger

When UML terminates (gracefully or panic) it does not always
cleanup on the host side.
Especially when fd:0,fd:1 is used as console it can leave a misconfigured
stdin/out on the host side.
Also stale processes such as port-helper can left behind.

This series fixes the console exit code to make sure UML
undoes everything it changed on the host side.

Richard Weinberger (4):
  um: Run console exit code also upon kernel panic
  um: os_set_fd_block: Return old blocking mode
  um: chan: Restore blocking mode upon exit
  um: irq: Restore O_ASYNC upon exit

 arch/um/drivers/chan.h               |  1 +
 arch/um/drivers/chan_kern.c          | 11 +++++++----
 arch/um/drivers/chan_user.c          |  2 +-
 arch/um/drivers/mconsole_kern.c      |  2 +-
 arch/um/drivers/stdio_console.c      |  4 ++--
 arch/um/drivers/ubd_user.c           |  2 +-
 arch/um/drivers/xterm.c              |  2 +-
 arch/um/include/shared/uml_console.h | 11 +++++++++++
 arch/um/kernel/irq.c                 |  5 ++++-
 arch/um/kernel/um_arch.c             |  8 +++++---
 arch/um/os-Linux/file.c              |  5 ++++-
 11 files changed, 38 insertions(+), 15 deletions(-)
 create mode 100644 arch/um/include/shared/uml_console.h

-- 
2.26.2


_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 1/4] um: Run console exit code also upon kernel panic
  2022-01-01 21:58 ` Richard Weinberger
@ 2022-01-01 21:58   ` Richard Weinberger
  -1 siblings, 0 replies; 27+ messages in thread
From: Richard Weinberger @ 2022-01-01 21:58 UTC (permalink / raw)
  To: linux-um; +Cc: linux-kernel, johannes.berg, anton.ivanov, Richard Weinberger

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 <richard@nod.at>
---
 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 <richard@nod.at>
+ */
+
+#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


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 1/4] um: Run console exit code also upon kernel panic
@ 2022-01-01 21:58   ` Richard Weinberger
  0 siblings, 0 replies; 27+ messages in thread
From: Richard Weinberger @ 2022-01-01 21:58 UTC (permalink / raw)
  To: linux-um; +Cc: linux-kernel, johannes.berg, anton.ivanov, Richard Weinberger

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 <richard@nod.at>
---
 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 <richard@nod.at>
+ */
+
+#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


_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 2/4] um: os_set_fd_block: Return old blocking mode
  2022-01-01 21:58 ` Richard Weinberger
@ 2022-01-01 21:58   ` Richard Weinberger
  -1 siblings, 0 replies; 27+ messages in thread
From: Richard Weinberger @ 2022-01-01 21:58 UTC (permalink / raw)
  To: linux-um; +Cc: linux-kernel, johannes.berg, anton.ivanov, Richard Weinberger

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 <richard@nod.at>
---
 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 = {
 
 static int open_one_chan(struct chan *chan)
 {
-	int fd, err;
+	int fd, ret;
 
 	if (chan->opened)
 		return 0;
@@ -95,10 +95,10 @@ static int open_one_chan(struct chan *chan)
 	if (fd < 0)
 		return fd;
 
-	err = os_set_fd_block(fd, 0);
-	if (err) {
+	ret = os_set_fd_block(fd, 0);
+	if (ret < 0) {
 		(*chan->ops->close)(fd, chan->data);
-		return err;
+		return ret;
 	}
 
 	chan->fd = 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, int *fd_out,
 	}
 
 	err = 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_kern.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;
 
 	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)
 
 	err = os_set_fd_block(*fd_out, 0);
 	err = 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 primary, void *d,
 	}
 
 	err = 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 = %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;
 
 	flags = fcntl(fd, F_GETFL);
 	if (flags < 0)
 		return -errno;
 
+	oldmode = !!(flags & O_NONBLOCK);
+
 	if (blocking)
 		flags &= ~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;
 
-	return 0;
+	return oldmode;
 }
 
 int os_accept_connection(int fd)
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 2/4] um: os_set_fd_block: Return old blocking mode
@ 2022-01-01 21:58   ` Richard Weinberger
  0 siblings, 0 replies; 27+ messages in thread
From: Richard Weinberger @ 2022-01-01 21:58 UTC (permalink / raw)
  To: linux-um; +Cc: linux-kernel, johannes.berg, anton.ivanov, Richard Weinberger

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 <richard@nod.at>
---
 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 = {
 
 static int open_one_chan(struct chan *chan)
 {
-	int fd, err;
+	int fd, ret;
 
 	if (chan->opened)
 		return 0;
@@ -95,10 +95,10 @@ static int open_one_chan(struct chan *chan)
 	if (fd < 0)
 		return fd;
 
-	err = os_set_fd_block(fd, 0);
-	if (err) {
+	ret = os_set_fd_block(fd, 0);
+	if (ret < 0) {
 		(*chan->ops->close)(fd, chan->data);
-		return err;
+		return ret;
 	}
 
 	chan->fd = 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, int *fd_out,
 	}
 
 	err = 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_kern.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;
 
 	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)
 
 	err = os_set_fd_block(*fd_out, 0);
 	err = 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 primary, void *d,
 	}
 
 	err = 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 = %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;
 
 	flags = fcntl(fd, F_GETFL);
 	if (flags < 0)
 		return -errno;
 
+	oldmode = !!(flags & O_NONBLOCK);
+
 	if (blocking)
 		flags &= ~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;
 
-	return 0;
+	return oldmode;
 }
 
 int os_accept_connection(int fd)
-- 
2.26.2


_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 3/4] um: chan: Restore blocking mode upon exit
  2022-01-01 21:58 ` Richard Weinberger
@ 2022-01-01 21:58   ` Richard Weinberger
  -1 siblings, 0 replies; 27+ messages in thread
From: Richard Weinberger @ 2022-01-01 21:58 UTC (permalink / raw)
  To: linux-um; +Cc: linux-kernel, johannes.berg, anton.ivanov, Richard Weinberger

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 <richard@nod.at>
---
 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)
 	}
 
 	chan->fd = fd;
+	chan->fd_blocking = ret;
 
 	chan->opened = 1;
 	return 0;
@@ -223,6 +224,8 @@ static void close_one_chan(struct chan *chan, int delay_free_irq)
 	if (chan->ops->close != NULL)
 		(*chan->ops->close)(chan->fd, chan->data);
 
+	os_set_fd_block(chan->fd, chan->fd_blocking);
+
 	chan->opened = 0;
 	chan->fd = -1;
 }
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 3/4] um: chan: Restore blocking mode upon exit
@ 2022-01-01 21:58   ` Richard Weinberger
  0 siblings, 0 replies; 27+ messages in thread
From: Richard Weinberger @ 2022-01-01 21:58 UTC (permalink / raw)
  To: linux-um; +Cc: linux-kernel, johannes.berg, anton.ivanov, Richard Weinberger

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 <richard@nod.at>
---
 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)
 	}
 
 	chan->fd = fd;
+	chan->fd_blocking = ret;
 
 	chan->opened = 1;
 	return 0;
@@ -223,6 +224,8 @@ static void close_one_chan(struct chan *chan, int delay_free_irq)
 	if (chan->ops->close != NULL)
 		(*chan->ops->close)(chan->fd, chan->data);
 
+	os_set_fd_block(chan->fd, chan->fd_blocking);
+
 	chan->opened = 0;
 	chan->fd = -1;
 }
-- 
2.26.2


_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 4/4] um: irq: Restore O_ASYNC upon exit
  2022-01-01 21:58 ` Richard Weinberger
@ 2022-01-01 21:58   ` Richard Weinberger
  -1 siblings, 0 replies; 27+ messages in thread
From: Richard Weinberger @ 2022-01-01 21:58 UTC (permalink / raw)
  To: linux-um; +Cc: linux-kernel, johannes.berg, anton.ivanov, Richard Weinberger

Just like with O_NONBLOCK, make sure UML clears O_ASYNC
upon exit when it set it.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 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, void *dev)
 				continue;
 
 			os_del_epoll_fd(entry->fd);
+			os_clear_fd_async(entry->fd);
 			reg->events = 0;
 			update_or_free_irq_entry(entry);
 			goto out;
@@ -396,8 +397,10 @@ int deactivate_all_fds(void)
 	os_set_ioignore();
 
 	/* 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;
 }
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 4/4] um: irq: Restore O_ASYNC upon exit
@ 2022-01-01 21:58   ` Richard Weinberger
  0 siblings, 0 replies; 27+ messages in thread
From: Richard Weinberger @ 2022-01-01 21:58 UTC (permalink / raw)
  To: linux-um; +Cc: linux-kernel, johannes.berg, anton.ivanov, Richard Weinberger

Just like with O_NONBLOCK, make sure UML clears O_ASYNC
upon exit when it set it.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 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, void *dev)
 				continue;
 
 			os_del_epoll_fd(entry->fd);
+			os_clear_fd_async(entry->fd);
 			reg->events = 0;
 			update_or_free_irq_entry(entry);
 			goto out;
@@ -396,8 +397,10 @@ int deactivate_all_fds(void)
 	os_set_ioignore();
 
 	/* 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;
 }
-- 
2.26.2


_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/4] um: Run console exit code also upon kernel panic
  2022-01-01 21:58   ` Richard Weinberger
  (?)
@ 2022-01-04  5:58   ` kernel test robot
  -1 siblings, 0 replies; 27+ messages in thread
From: kernel test robot @ 2022-01-04  5:58 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 2006 bytes --]

Hi Richard,

I love your patch! Perhaps something to improve:

[auto build test WARNING on rw-uml/linux-next]
[also build test WARNING on linux/master linus/master v5.16-rc8 next-20211224]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Richard-Weinberger/um-Assorted-console-related-fixes/20220102-055954
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rw/uml.git linux-next
config: um-i386_defconfig (https://download.01.org/0day-ci/archive/20220104/202201041330.hsCRX4ov-lkp(a)intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/8ed1e739d9071fbe06c0e6ff91eeb065afd18953
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Richard-Weinberger/um-Assorted-console-related-fixes/20220102-055954
        git checkout 8ed1e739d9071fbe06c0e6ff91eeb065afd18953
        # save the config file to linux build tree
        mkdir build_dir
        make W=1 O=build_dir ARCH=um SUBARCH=i386 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> arch/um/drivers/stdio_console.c:183:6: warning: no previous prototype for 'uml_console_exit' [-Wmissing-prototypes]
     183 | void uml_console_exit(void)
         |      ^~~~~~~~~~~~~~~~


vim +/uml_console_exit +183 arch/um/drivers/stdio_console.c

   182	
 > 183	void uml_console_exit(void)
   184	{
   185		if (!con_init_done)
   186			return;
   187		close_lines(vts, ARRAY_SIZE(vts));
   188	}
   189	__uml_exitcall(uml_console_exit);
   190	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/4] um: Run console exit code also upon kernel panic
  2022-01-01 21:58   ` Richard Weinberger
@ 2022-01-04  8:56     ` Johannes Berg
  -1 siblings, 0 replies; 27+ messages in thread
From: Johannes Berg @ 2022-01-04  8:56 UTC (permalink / raw)
  To: Richard Weinberger, linux-um; +Cc: linux-kernel, anton.ivanov

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 <richard@nod.at>
> + */
> +
> +#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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/4] um: Run console exit code also upon kernel panic
@ 2022-01-04  8:56     ` Johannes Berg
  0 siblings, 0 replies; 27+ messages in thread
From: Johannes Berg @ 2022-01-04  8:56 UTC (permalink / raw)
  To: Richard Weinberger, linux-um; +Cc: linux-kernel, anton.ivanov

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 <richard@nod.at>
> + */
> +
> +#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

_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 2/4] um: os_set_fd_block: Return old blocking mode
  2022-01-01 21:58   ` Richard Weinberger
@ 2022-01-04  9:00     ` Johannes Berg
  -1 siblings, 0 replies; 27+ messages in thread
From: Johannes Berg @ 2022-01-04  9:00 UTC (permalink / raw)
  To: Richard Weinberger, linux-um; +Cc: linux-kernel, anton.ivanov

On Sat, 2022-01-01 at 22:58 +0100, Richard Weinberger wrote:
> 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.
> 
> +++ b/arch/um/drivers/chan_user.c
> @@ -257,7 +257,7 @@ static int winch_tramp(int fd, struct tty_port *port, int *fd_out,
>  	}
>  
>  	err = 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;

This does 'return err' afterwards, which then changes the logic from 0
to 1, which seems wrong - especially given that it gets passed further
elsewhere as a pid, which seems very questionable in the first place,
but at least 1 would be valid pid unlike 0?

IOW, I think you need

-	return err;
+	return 0;

a couple of lines later.

johannes

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 2/4] um: os_set_fd_block: Return old blocking mode
@ 2022-01-04  9:00     ` Johannes Berg
  0 siblings, 0 replies; 27+ messages in thread
From: Johannes Berg @ 2022-01-04  9:00 UTC (permalink / raw)
  To: Richard Weinberger, linux-um; +Cc: linux-kernel, anton.ivanov

On Sat, 2022-01-01 at 22:58 +0100, Richard Weinberger wrote:
> 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.
> 
> +++ b/arch/um/drivers/chan_user.c
> @@ -257,7 +257,7 @@ static int winch_tramp(int fd, struct tty_port *port, int *fd_out,
>  	}
>  
>  	err = 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;

This does 'return err' afterwards, which then changes the logic from 0
to 1, which seems wrong - especially given that it gets passed further
elsewhere as a pid, which seems very questionable in the first place,
but at least 1 would be valid pid unlike 0?

IOW, I think you need

-	return err;
+	return 0;

a couple of lines later.

johannes

_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 4/4] um: irq: Restore O_ASYNC upon exit
  2022-01-01 21:58   ` Richard Weinberger
@ 2022-01-04  9:02     ` Johannes Berg
  -1 siblings, 0 replies; 27+ messages in thread
From: Johannes Berg @ 2022-01-04  9:02 UTC (permalink / raw)
  To: Richard Weinberger, linux-um; +Cc: linux-kernel, anton.ivanov

On Sat, 2022-01-01 at 22:58 +0100, Richard Weinberger wrote:
> Just like with O_NONBLOCK, make sure UML clears O_ASYNC
> upon exit when it set it.
> 

"when it set it" isn't really quite true - you always clear it, should
it be similar to the O_NONBLOCK version to see the old mode?

johannes

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 4/4] um: irq: Restore O_ASYNC upon exit
@ 2022-01-04  9:02     ` Johannes Berg
  0 siblings, 0 replies; 27+ messages in thread
From: Johannes Berg @ 2022-01-04  9:02 UTC (permalink / raw)
  To: Richard Weinberger, linux-um; +Cc: linux-kernel, anton.ivanov

On Sat, 2022-01-01 at 22:58 +0100, Richard Weinberger wrote:
> Just like with O_NONBLOCK, make sure UML clears O_ASYNC
> upon exit when it set it.
> 

"when it set it" isn't really quite true - you always clear it, should
it be similar to the O_NONBLOCK version to see the old mode?

johannes

_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 0/4] um: Assorted console related fixes
  2022-01-01 21:58 ` Richard Weinberger
                   ` (4 preceding siblings ...)
  (?)
@ 2022-03-09  5:29 ` Glenn Washburn
  2022-03-09  8:35   ` Richard Weinberger
  -1 siblings, 1 reply; 27+ messages in thread
From: Glenn Washburn @ 2022-03-09  5:29 UTC (permalink / raw)
  To: Richard Weinberger, linux-um; +Cc: Johannes Berg, Glenn Washburn

On Sat, 2022-01-01 at 22:58 +0100, Richard Weinberger wrote:
> When UML terminates (gracefully or panic) it does not always
> cleanup on the host side.
> Especially when fd:0,fd:1 is used as console it can leave a misconfigured
> stdin/out on the host side.
> Also stale processes such as port-helper can left behind.

> This series fixes the console exit code to make sure UML
> undoes everything it changed on the host side.

I gave this a run hoping it would fix the issues I'm seeing with the console
getting messed up when UML exits via halt in the guest. Echo is turned off
and looks like carriage return doesn't work either. I'm using "reset" to get
the terminal back to its previous state. Unfortunately this patch series did
not fix this issue.

I'm not saying that these aren't valid fixes. But it does appear that these
changes don't make sure that "everything" changed on the host side is undone.

Glenn


_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 0/4] um: Assorted console related fixes
  2022-03-09  5:29 ` [PATCH 0/4] um: Assorted console related fixes Glenn Washburn
@ 2022-03-09  8:35   ` Richard Weinberger
  2022-03-09 16:13     ` Randy Dunlap
  2022-03-10 18:21     ` Glenn Washburn
  0 siblings, 2 replies; 27+ messages in thread
From: Richard Weinberger @ 2022-03-09  8:35 UTC (permalink / raw)
  To: Glenn Washburn; +Cc: linux-um, Johannes Berg

----- Ursprüngliche Mail -----
>> This series fixes the console exit code to make sure UML
>> undoes everything it changed on the host side.
> 
> I gave this a run hoping it would fix the issues I'm seeing with the console
> getting messed up when UML exits via halt in the guest. Echo is turned off
> and looks like carriage return doesn't work either. I'm using "reset" to get
> the terminal back to its previous state. Unfortunately this patch series did
> not fix this issue.
> 
> I'm not saying that these aren't valid fixes. But it does appear that these
> changes don't make sure that "everything" changed on the host side is undone.

So when you compare "stty -a" before and after the damange you still see differences?
Please also compare the flags of /proc/$$/fdinfo/{0,1,2}

Thanks,
//richard

_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 0/4] um: Assorted console related fixes
  2022-03-09  8:35   ` Richard Weinberger
@ 2022-03-09 16:13     ` Randy Dunlap
  2022-03-09 16:21       ` Richard Weinberger
  2022-03-10 18:21     ` Glenn Washburn
  1 sibling, 1 reply; 27+ messages in thread
From: Randy Dunlap @ 2022-03-09 16:13 UTC (permalink / raw)
  To: Richard Weinberger, Glenn Washburn; +Cc: linux-um, Johannes Berg



On 3/9/22 00:35, Richard Weinberger wrote:
> ----- Ursprüngliche Mail -----
>>> This series fixes the console exit code to make sure UML
>>> undoes everything it changed on the host side.
>>
>> I gave this a run hoping it would fix the issues I'm seeing with the console
>> getting messed up when UML exits via halt in the guest. Echo is turned off
>> and looks like carriage return doesn't work either. I'm using "reset" to get
>> the terminal back to its previous state. Unfortunately this patch series did
>> not fix this issue.
>>
>> I'm not saying that these aren't valid fixes. But it does appear that these
>> changes don't make sure that "everything" changed on the host side is undone.
> 
> So when you compare "stty -a" before and after the damange you still see differences?
> Please also compare the flags of /proc/$$/fdinfo/{0,1,2}

Uh, where are the patches?

> http://lists.infradead.org/mailman/listinfo/linux-um

not in that archive ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

-- 
~Randy

_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 0/4] um: Assorted console related fixes
  2022-03-09 16:13     ` Randy Dunlap
@ 2022-03-09 16:21       ` Richard Weinberger
  2022-03-09 16:48         ` Randy Dunlap
  0 siblings, 1 reply; 27+ messages in thread
From: Richard Weinberger @ 2022-03-09 16:21 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: Glenn Washburn, linux-um, Johannes Berg

Randy,

----- Ursprüngliche Mail -----
> Von: "Randy Dunlap" <rdunlap@infradead.org>
> Uh, where are the patches?
> 
>> http://lists.infradead.org/mailman/listinfo/linux-um
> 
> not in that archive ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

https://lore.kernel.org/lkml/20220101215810.13260-1-richard@nod.at/T/

Thanks,
//richard

_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 0/4] um: Assorted console related fixes
  2022-03-09 16:21       ` Richard Weinberger
@ 2022-03-09 16:48         ` Randy Dunlap
  0 siblings, 0 replies; 27+ messages in thread
From: Randy Dunlap @ 2022-03-09 16:48 UTC (permalink / raw)
  To: Richard Weinberger; +Cc: Glenn Washburn, linux-um, Johannes Berg



On 3/9/22 08:21, Richard Weinberger wrote:
> Randy,
> 
> ----- Ursprüngliche Mail -----
>> Von: "Randy Dunlap" <rdunlap@infradead.org>
>> Uh, where are the patches?
>>
>>> http://lists.infradead.org/mailman/listinfo/linux-um
>>
>> not in that archive ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> https://lore.kernel.org/lkml/20220101215810.13260-1-richard@nod.at/T/

Thanks.

-- 
~Randy

_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 0/4] um: Assorted console related fixes
  2022-03-09  8:35   ` Richard Weinberger
  2022-03-09 16:13     ` Randy Dunlap
@ 2022-03-10 18:21     ` Glenn Washburn
  2022-04-04 21:41       ` Richard Weinberger
  1 sibling, 1 reply; 27+ messages in thread
From: Glenn Washburn @ 2022-03-10 18:21 UTC (permalink / raw)
  To: Richard Weinberger; +Cc: linux-um, Johannes Berg

On Wed, 9 Mar 2022 09:35:02 +0100 (CET)
Richard Weinberger <richard@nod.at> wrote:

> ----- Ursprüngliche Mail -----
> >> This series fixes the console exit code to make sure UML
> >> undoes everything it changed on the host side.
> > 
> > I gave this a run hoping it would fix the issues I'm seeing with the console
> > getting messed up when UML exits via halt in the guest. Echo is turned off
> > and looks like carriage return doesn't work either. I'm using "reset" to get
> > the terminal back to its previous state. Unfortunately this patch series did
> > not fix this issue.
> > 
> > I'm not saying that these aren't valid fixes. But it does appear that these
> > changes don't make sure that "everything" changed on the host side is undone.
> 
> So when you compare "stty -a" before and after the damange you still see differences?
> Please also compare the flags of /proc/$$/fdinfo/{0,1,2}

Here's a diff of the before and after:
-- /tmp/uml-console.before.out 2022-03-10 18:12:54.049171650 +0000
+++ /tmp/uml-console.after.out  2022-03-10 18:13:20.711630281 +0000
@@ -3,20 +3,20 @@
 eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
 werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
 -parenb -parodd -cmspar cs8 hupcl -cstopb cread -clocal -crtscts
--ignbrk brkint ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
+-ignbrk -brkint ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff
 -iuclc -ixany imaxbel -iutf8
-opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig icanon -iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
+-opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
+-isig -icanon -iexten -echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
 echoctl echoke -flusho -extproc
 /proc/3383323/fdinfo/0:1:pos:  0
-/proc/3383323/fdinfo/0:2:flags:        0120002
+/proc/3383323/fdinfo/0:2:flags:        0124002
 /proc/3383323/fdinfo/0:3:mnt_id:       6104
 /proc/3383323/fdinfo/0:4:ino:  24
 /proc/3383323/fdinfo/1:1:pos:  0
-/proc/3383323/fdinfo/1:2:flags:        0120002
+/proc/3383323/fdinfo/1:2:flags:        0124002
 /proc/3383323/fdinfo/1:3:mnt_id:       6104
 /proc/3383323/fdinfo/1:4:ino:  24
 /proc/3383323/fdinfo/2:1:pos:  0
-/proc/3383323/fdinfo/2:2:flags:        0120002
+/proc/3383323/fdinfo/2:2:flags:        0124002
 /proc/3383323/fdinfo/2:3:mnt_id:       6104
 /proc/3383323/fdinfo/2:4:ino:  24

It looks like these were not reset: brkin icrnl ixon opost isig icanon echo

Originally I was applying this patch series to 5.16.12 and seeing this issue.
But I this output is from applying the patch series to 5.17-rc7, if that matters. Thanks for looking t this.

Glenn

> 
> Thanks,
> //richard

_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 0/4] um: Assorted console related fixes
  2022-03-10 18:21     ` Glenn Washburn
@ 2022-04-04 21:41       ` Richard Weinberger
  2022-06-06 23:16         ` Glenn Washburn
  0 siblings, 1 reply; 27+ messages in thread
From: Richard Weinberger @ 2022-04-04 21:41 UTC (permalink / raw)
  To: development; +Cc: Richard Weinberger, linux-um, Johannes Berg

Glenn,

On Thu, Mar 10, 2022 at 7:22 PM Glenn Washburn
<development@efficientek.com> wrote:
>
> On Wed, 9 Mar 2022 09:35:02 +0100 (CET)
> Richard Weinberger <richard@nod.at> wrote:
>
> > ----- Ursprüngliche Mail -----
> > >> This series fixes the console exit code to make sure UML
> > >> undoes everything it changed on the host side.
> > >
> > > I gave this a run hoping it would fix the issues I'm seeing with the console
> > > getting messed up when UML exits via halt in the guest. Echo is turned off
> > > and looks like carriage return doesn't work either. I'm using "reset" to get
> > > the terminal back to its previous state. Unfortunately this patch series did
> > > not fix this issue.
> > >
> > > I'm not saying that these aren't valid fixes. But it does appear that these
> > > changes don't make sure that "everything" changed on the host side is undone.
> >
> > So when you compare "stty -a" before and after the damange you still see differences?
> > Please also compare the flags of /proc/$$/fdinfo/{0,1,2}
>
> Here's a diff of the before and after:
> -- /tmp/uml-console.before.out 2022-03-10 18:12:54.049171650 +0000
> +++ /tmp/uml-console.after.out  2022-03-10 18:13:20.711630281 +0000
> @@ -3,20 +3,20 @@
>  eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
>  werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
>  -parenb -parodd -cmspar cs8 hupcl -cstopb cread -clocal -crtscts
> --ignbrk brkint ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
> +-ignbrk -brkint ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff
>  -iuclc -ixany imaxbel -iutf8
> -opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
> -isig icanon -iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
> +-opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
> +-isig -icanon -iexten -echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
>  echoctl echoke -flusho -extproc
>  /proc/3383323/fdinfo/0:1:pos:  0
> -/proc/3383323/fdinfo/0:2:flags:        0120002
> +/proc/3383323/fdinfo/0:2:flags:        0124002
>  /proc/3383323/fdinfo/0:3:mnt_id:       6104
>  /proc/3383323/fdinfo/0:4:ino:  24
>  /proc/3383323/fdinfo/1:1:pos:  0
> -/proc/3383323/fdinfo/1:2:flags:        0120002
> +/proc/3383323/fdinfo/1:2:flags:        0124002
>  /proc/3383323/fdinfo/1:3:mnt_id:       6104
>  /proc/3383323/fdinfo/1:4:ino:  24
>  /proc/3383323/fdinfo/2:1:pos:  0
> -/proc/3383323/fdinfo/2:2:flags:        0120002
> +/proc/3383323/fdinfo/2:2:flags:        0124002
>  /proc/3383323/fdinfo/2:3:mnt_id:       6104
>  /proc/3383323/fdinfo/2:4:ino:  24
>
> It looks like these were not reset: brkin icrnl ixon opost isig icanon echo
>
> Originally I was applying this patch series to 5.16.12 and seeing this issue.
> But I this output is from applying the patch series to 5.17-rc7, if that matters. Thanks for looking t this.

Hmm. Looks like the cleanup function is never called.
Can you verify whether uml_console_exit() runs at exit time?

-- 
Thanks,
//richard

_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 0/4] um: Assorted console related fixes
  2022-04-04 21:41       ` Richard Weinberger
@ 2022-06-06 23:16         ` Glenn Washburn
  2022-06-07  8:22           ` Johannes Berg
  0 siblings, 1 reply; 27+ messages in thread
From: Glenn Washburn @ 2022-06-06 23:16 UTC (permalink / raw)
  To: Richard Weinberger; +Cc: Richard Weinberger, linux-um, Johannes Berg

On Mon, 4 Apr 2022 23:41:29 +0200
Richard Weinberger <richard.weinberger@gmail.com> wrote:

> Glenn,
> 
> On Thu, Mar 10, 2022 at 7:22 PM Glenn Washburn
> <development@efficientek.com> wrote:
> >
> > On Wed, 9 Mar 2022 09:35:02 +0100 (CET)
> > Richard Weinberger <richard@nod.at> wrote:
> >
> > > ----- Ursprüngliche Mail -----
> > > >> This series fixes the console exit code to make sure UML
> > > >> undoes everything it changed on the host side.
> > > >
> > > > I gave this a run hoping it would fix the issues I'm seeing with the console
> > > > getting messed up when UML exits via halt in the guest. Echo is turned off
> > > > and looks like carriage return doesn't work either. I'm using "reset" to get
> > > > the terminal back to its previous state. Unfortunately this patch series did
> > > > not fix this issue.
> > > >
> > > > I'm not saying that these aren't valid fixes. But it does appear that these
> > > > changes don't make sure that "everything" changed on the host side is undone.
> > >
> > > So when you compare "stty -a" before and after the damange you still see differences?
> > > Please also compare the flags of /proc/$$/fdinfo/{0,1,2}
> >
> > Here's a diff of the before and after:
> > -- /tmp/uml-console.before.out 2022-03-10 18:12:54.049171650 +0000
> > +++ /tmp/uml-console.after.out  2022-03-10 18:13:20.711630281 +0000
> > @@ -3,20 +3,20 @@
> >  eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
> >  werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
> >  -parenb -parodd -cmspar cs8 hupcl -cstopb cread -clocal -crtscts
> > --ignbrk brkint ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
> > +-ignbrk -brkint ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff
> >  -iuclc -ixany imaxbel -iutf8
> > -opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
> > -isig icanon -iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
> > +-opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
> > +-isig -icanon -iexten -echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
> >  echoctl echoke -flusho -extproc
> >  /proc/3383323/fdinfo/0:1:pos:  0
> > -/proc/3383323/fdinfo/0:2:flags:        0120002
> > +/proc/3383323/fdinfo/0:2:flags:        0124002
> >  /proc/3383323/fdinfo/0:3:mnt_id:       6104
> >  /proc/3383323/fdinfo/0:4:ino:  24
> >  /proc/3383323/fdinfo/1:1:pos:  0
> > -/proc/3383323/fdinfo/1:2:flags:        0120002
> > +/proc/3383323/fdinfo/1:2:flags:        0124002
> >  /proc/3383323/fdinfo/1:3:mnt_id:       6104
> >  /proc/3383323/fdinfo/1:4:ino:  24
> >  /proc/3383323/fdinfo/2:1:pos:  0
> > -/proc/3383323/fdinfo/2:2:flags:        0120002
> > +/proc/3383323/fdinfo/2:2:flags:        0124002
> >  /proc/3383323/fdinfo/2:3:mnt_id:       6104
> >  /proc/3383323/fdinfo/2:4:ino:  24
> >
> > It looks like these were not reset: brkin icrnl ixon opost isig icanon echo
> >
> > Originally I was applying this patch series to 5.16.12 and seeing this issue.
> > But I this output is from applying the patch series to 5.17-rc7, if that matters. Thanks for looking t this.
> 
> Hmm. Looks like the cleanup function is never called.
> Can you verify whether uml_console_exit() runs at exit time?

Sorry about the delay. I don't think that uml_console_exit() is getting
run. I'm testing this by running a UML instance which has been compiled
with -ggdb3. Then attach to the running process via GDB. Set a
breakpoint on uml_console_exit(), then do a shutdown/halt (syscall
reboot(0x4321fedc)). GDB says that the process was terminated with
SIGKILL, which I'm guessing is why uml_console_exit() is not run.

Glenn

_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 0/4] um: Assorted console related fixes
  2022-06-06 23:16         ` Glenn Washburn
@ 2022-06-07  8:22           ` Johannes Berg
  2022-06-07 15:10             ` Glenn Washburn
  0 siblings, 1 reply; 27+ messages in thread
From: Johannes Berg @ 2022-06-07  8:22 UTC (permalink / raw)
  To: development, Richard Weinberger; +Cc: Richard Weinberger, linux-um

On Mon, 2022-06-06 at 18:16 -0500, Glenn Washburn wrote:
>  GDB says that the process was terminated with
> SIGKILL, which I'm guessing is why uml_console_exit() is not run.
> 

https://patchwork.ozlabs.org/project/linux-um/patch/20220520194536.1acbb414a2d1.I1d71bab01d45f7f8e446df6e98547a7989338208@changeid/

johannes

_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 0/4] um: Assorted console related fixes
  2022-06-07  8:22           ` Johannes Berg
@ 2022-06-07 15:10             ` Glenn Washburn
  0 siblings, 0 replies; 27+ messages in thread
From: Glenn Washburn @ 2022-06-07 15:10 UTC (permalink / raw)
  To: Johannes Berg; +Cc: Richard Weinberger, Richard Weinberger, linux-um

On Tue, 07 Jun 2022 10:22:43 +0200
Johannes Berg <johannes@sipsolutions.net> wrote:

> On Mon, 2022-06-06 at 18:16 -0500, Glenn Washburn wrote:
> >  GDB says that the process was terminated with
> > SIGKILL, which I'm guessing is why uml_console_exit() is not run.
> > 
> 
> https://patchwork.ozlabs.org/project/linux-um/patch/20220520194536.1acbb414a2d1.I1d71bab01d45f7f8e446df6e98547a7989338208@changeid/

Great! I've tested that this solves the SIGKILL issue and that stty
reports the same values before and after running a UML instance.

However, the flags re not the same (before 32770 and after 34818, in
decimal). It seems that the O_NONBLOCK flag is not being restored to
its original value (off).

So now the terminal is not messed up, but the flags are still an issue
for me because having stdin/stdout in non-blocking mode breaks some of
my scripts using uml.

Glenn

_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um


^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2022-06-07 15:10 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-01 21:58 [PATCH 0/4] um: Assorted console related fixes Richard Weinberger
2022-01-01 21:58 ` Richard Weinberger
2022-01-01 21:58 ` [PATCH 1/4] um: Run console exit code also upon kernel panic Richard Weinberger
2022-01-01 21:58   ` Richard Weinberger
2022-01-04  5:58   ` kernel test robot
2022-01-04  8:56   ` Johannes Berg
2022-01-04  8:56     ` Johannes Berg
2022-01-01 21:58 ` [PATCH 2/4] um: os_set_fd_block: Return old blocking mode Richard Weinberger
2022-01-01 21:58   ` Richard Weinberger
2022-01-04  9:00   ` Johannes Berg
2022-01-04  9:00     ` Johannes Berg
2022-01-01 21:58 ` [PATCH 3/4] um: chan: Restore blocking mode upon exit Richard Weinberger
2022-01-01 21:58   ` Richard Weinberger
2022-01-01 21:58 ` [PATCH 4/4] um: irq: Restore O_ASYNC " Richard Weinberger
2022-01-01 21:58   ` Richard Weinberger
2022-01-04  9:02   ` Johannes Berg
2022-01-04  9:02     ` Johannes Berg
2022-03-09  5:29 ` [PATCH 0/4] um: Assorted console related fixes Glenn Washburn
2022-03-09  8:35   ` Richard Weinberger
2022-03-09 16:13     ` Randy Dunlap
2022-03-09 16:21       ` Richard Weinberger
2022-03-09 16:48         ` Randy Dunlap
2022-03-10 18:21     ` Glenn Washburn
2022-04-04 21:41       ` Richard Weinberger
2022-06-06 23:16         ` Glenn Washburn
2022-06-07  8:22           ` Johannes Berg
2022-06-07 15:10             ` Glenn Washburn

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.