All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC][PATCHES] termios.h cleanups
@ 2018-09-10  4:49 Al Viro
  2018-09-10  4:52 ` [RFC][PATCH 1/8] start unifying termios convertors Al Viro
  2018-09-10  8:32 ` [RFC][PATCH 1/8] start unifying termios convertors David Howells
  0 siblings, 2 replies; 17+ messages in thread
From: Al Viro @ 2018-09-10  4:49 UTC (permalink / raw)
  To: linux-arch; +Cc: Linus Torvalds, linux-kernel

	asm/termios.h has tons of duplication and rather
convoluted logics re includes.

	First of all, while everyone has uapi asm/termios.h,
some architectures have asm/termios.h and some do not.  So
include of <asm/termios.h> can go either to arch asm/termios.h,
or to uapi/asm/termios.h.
	In the former case asm/termios.h defines a bunch of
helpers (used in just one file) and a constant (3 more users)
and includes uapi/asm/termios.h
	In the latter... uapi/asm/termios.h is in generated-y
or equivalent to it.  Which is to say, it ends up doing
#include <asm-generic/termios.h>.  Userland-side that would
refer to uapi/asm-generic/termios.h, but kernel-side we end
up with plain asm-generic/termios.h.  Which defines the same
set of helpers and a constant and pulls uapi/asm-generic/termios.h

	Helpers in question are heavily shared; there is an attempt
to put them into a common header (termios-base.h), but not all
instances use it.  Another unpleasant thing is that said helpers
tend to be macros, with very little typechecking.  And all of that
is pulled in by a lot more places than those that are actually
interested - 500-odd instead of 4.

	Below is an attempt to untangle that; the branch is vfs.git#work.termios,
patches in followups.  FWIW, diffstat is

 arch/Kconfig                                       |   3 +
 arch/alpha/Kconfig                                 |   1 +
 arch/alpha/include/asm/termios.h                   |  81 ------------
 arch/alpha/include/asm/termios_internal.h          |  72 ++++++++++
 arch/ia64/include/asm/termios.h                    |  58 --------
 arch/mips/include/asm/termios.h                    | 105 ---------------
 arch/parisc/include/asm/termios.h                  |  52 --------
 arch/powerpc/Kconfig                               |   1 +
 .../include/asm/{termios.h => termios_internal.h}  |   7 +-
 arch/riscv/include/asm/Kbuild                      |   1 -
 arch/s390/include/asm/termios.h                    |  26 ----
 arch/sparc/Kconfig                                 |   1 +
 arch/sparc/include/asm/termios.h                   | 147 ---------------------
 arch/sparc/include/asm/termios_internal.h          | 134 +++++++++++++++++++
 arch/x86/include/uapi/asm/Kbuild                   |   1 +
 arch/x86/include/uapi/asm/termios.h                |   1 -
 drivers/tty/hvc/hvcs.c                             |   1 +
 drivers/tty/n_hdlc.c                               |   1 -
 drivers/tty/tty_io.c                               |   1 +
 drivers/tty/tty_ioctl.c                            |   1 +
 drivers/tty/vcc.c                                  |   1 +
 include/asm-generic/termios-base.h                 |  78 -----------
 include/asm-generic/termios.h                      | 108 ---------------
 include/linux/termios_internal.h                   | 137 +++++++++++++++++++
 24 files changed, 355 insertions(+), 664 deletions(-)
 delete mode 100644 arch/alpha/include/asm/termios.h
 create mode 100644 arch/alpha/include/asm/termios_internal.h
 delete mode 100644 arch/ia64/include/asm/termios.h
 delete mode 100644 arch/mips/include/asm/termios.h
 delete mode 100644 arch/parisc/include/asm/termios.h
 rename arch/powerpc/include/asm/{termios.h => termios_internal.h} (70%)
 delete mode 100644 arch/s390/include/asm/termios.h
 delete mode 100644 arch/sparc/include/asm/termios.h
 create mode 100644 arch/sparc/include/asm/termios_internal.h
 delete mode 100644 arch/x86/include/uapi/asm/termios.h
 delete mode 100644 include/asm-generic/termios-base.h
 delete mode 100644 include/asm-generic/termios.h
 create mode 100644 include/linux/termios_internal.h

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

* [RFC][PATCH 1/8] start unifying termios convertors
  2018-09-10  4:49 [RFC][PATCHES] termios.h cleanups Al Viro
@ 2018-09-10  4:52 ` Al Viro
  2018-09-10  4:52   ` [RFC][PATCH 2/8] move user_termio_to_kernel_termios/kernel_termios_to_user_termio Al Viro
                     ` (6 more replies)
  2018-09-10  8:32 ` [RFC][PATCH 1/8] start unifying termios convertors David Howells
  1 sibling, 7 replies; 17+ messages in thread
From: Al Viro @ 2018-09-10  4:52 UTC (permalink / raw)
  To: linux-arch; +Cc: Linus Torvalds, linux-kernel

From: Al Viro <viro@zeniv.linux.org.uk>

* new header (linut/termios_internal.h), pulled by the sole user of those
suckers
* defaults for user_termios_to_kernel_termios{,_1} and
kernel_termios_to_user_termios{,_1} moved over there

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 arch/alpha/include/asm/termios.h   |   6 --
 arch/ia64/include/asm/termios.h    |   5 --
 arch/mips/include/asm/termios.h    |  24 ------
 arch/parisc/include/asm/termios.h  |   5 --
 arch/s390/include/asm/termios.h    |   3 -
 arch/sparc/include/asm/termios.h   | 165 ++++++++++++++++++++-----------------
 drivers/tty/tty_ioctl.c            |   1 +
 include/asm-generic/termios-base.h |  11 ---
 include/asm-generic/termios.h      |  38 ---------
 include/linux/termios_internal.h   |  58 +++++++++++++
 10 files changed, 148 insertions(+), 168 deletions(-)
 create mode 100644 include/linux/termios_internal.h

diff --git a/arch/alpha/include/asm/termios.h b/arch/alpha/include/asm/termios.h
index 6a8c53dec57e..1cd44956ae7b 100644
--- a/arch/alpha/include/asm/termios.h
+++ b/arch/alpha/include/asm/termios.h
@@ -72,10 +72,4 @@
 	copy_to_user(u_termio, &k_termio, sizeof(k_termio));		\
 })
 
-#define user_termios_to_kernel_termios(k, u) \
-	copy_from_user(k, u, sizeof(struct termios))
-
-#define kernel_termios_to_user_termios(u, k) \
-	copy_to_user(u, k, sizeof(struct termios))
-
 #endif	/* _ALPHA_TERMIOS_H */
diff --git a/arch/ia64/include/asm/termios.h b/arch/ia64/include/asm/termios.h
index 589c026444cc..1bd5ff9745e9 100644
--- a/arch/ia64/include/asm/termios.h
+++ b/arch/ia64/include/asm/termios.h
@@ -50,9 +50,4 @@
 	copy_to_user((termio)->c_cc, (termios)->c_cc, NCC);	\
 })
 
-#define user_termios_to_kernel_termios(k, u) copy_from_user(k, u, sizeof(struct termios2))
-#define kernel_termios_to_user_termios(u, k) copy_to_user(u, k, sizeof(struct termios2))
-#define user_termios_to_kernel_termios_1(k, u) copy_from_user(k, u, sizeof(struct termios))
-#define kernel_termios_to_user_termios_1(u, k) copy_to_user(u, k, sizeof(struct termios))
-
 #endif /* _ASM_IA64_TERMIOS_H */
diff --git a/arch/mips/include/asm/termios.h b/arch/mips/include/asm/termios.h
index ce2d72e34274..3bd98a70e1d1 100644
--- a/arch/mips/include/asm/termios.h
+++ b/arch/mips/include/asm/termios.h
@@ -78,28 +78,4 @@ static inline int kernel_termios_to_user_termio(struct termio __user *termio,
 	return 0;
 }
 
-static inline int user_termios_to_kernel_termios(struct ktermios __user *k,
-	struct termios2 *u)
-{
-	return copy_from_user(k, u, sizeof(struct termios2)) ? -EFAULT : 0;
-}
-
-static inline int kernel_termios_to_user_termios(struct termios2 __user *u,
-	struct ktermios *k)
-{
-	return copy_to_user(u, k, sizeof(struct termios2)) ? -EFAULT : 0;
-}
-
-static inline int user_termios_to_kernel_termios_1(struct ktermios *k,
-	struct termios __user *u)
-{
-	return copy_from_user(k, u, sizeof(struct termios)) ? -EFAULT : 0;
-}
-
-static inline int kernel_termios_to_user_termios_1(struct termios __user *u,
-	struct ktermios *k)
-{
-	return copy_to_user(u, k, sizeof(struct termios)) ? -EFAULT : 0;
-}
-
 #endif /* _ASM_TERMIOS_H */
diff --git a/arch/parisc/include/asm/termios.h b/arch/parisc/include/asm/termios.h
index cded9dc90c1b..679d31db8d77 100644
--- a/arch/parisc/include/asm/termios.h
+++ b/arch/parisc/include/asm/termios.h
@@ -44,9 +44,4 @@
 	copy_to_user((termio)->c_cc, (termios)->c_cc, NCC); \
 })
 
-#define user_termios_to_kernel_termios(k, u) copy_from_user(k, u, sizeof(struct termios2))
-#define kernel_termios_to_user_termios(u, k) copy_to_user(u, k, sizeof(struct termios2))
-#define user_termios_to_kernel_termios_1(k, u) copy_from_user(k, u, sizeof(struct termios))
-#define kernel_termios_to_user_termios_1(u, k) copy_to_user(u, k, sizeof(struct termios))
-
 #endif	/* _PARISC_TERMIOS_H */
diff --git a/arch/s390/include/asm/termios.h b/arch/s390/include/asm/termios.h
index 46fa3020b41e..62759ac7a92b 100644
--- a/arch/s390/include/asm/termios.h
+++ b/arch/s390/include/asm/termios.h
@@ -18,9 +18,6 @@
 */
 #define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
 
-#define user_termios_to_kernel_termios(k, u) copy_from_user(k, u, sizeof(struct termios2))
-#define kernel_termios_to_user_termios(u, k) copy_to_user(u, k, sizeof(struct termios2))
-
 #include <asm-generic/termios-base.h>
 
 #endif	/* _S390_TERMIOS_H */
diff --git a/arch/sparc/include/asm/termios.h b/arch/sparc/include/asm/termios.h
index 4a558efdfa93..27a054a99a58 100644
--- a/arch/sparc/include/asm/termios.h
+++ b/arch/sparc/include/asm/termios.h
@@ -3,6 +3,7 @@
 #define _SPARC_TERMIOS_H
 
 #include <uapi/asm/termios.h>
+#include <linux/uaccess.h>
 
 
 /*
@@ -64,84 +65,96 @@
 	err; \
 })
 
-#define user_termios_to_kernel_termios(k, u) \
-({ \
-	int err; \
-	err  = get_user((k)->c_iflag, &(u)->c_iflag); \
-	err |= get_user((k)->c_oflag, &(u)->c_oflag); \
-	err |= get_user((k)->c_cflag, &(u)->c_cflag); \
-	err |= get_user((k)->c_lflag, &(u)->c_lflag); \
-	err |= get_user((k)->c_line,  &(u)->c_line); \
-	err |= copy_from_user((k)->c_cc, (u)->c_cc, NCCS); \
-	if ((k)->c_lflag & ICANON) { \
-		err |= get_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \
-		err |= get_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \
-	} else { \
-		err |= get_user((k)->c_cc[VMIN],  &(u)->c_cc[_VMIN]); \
-		err |= get_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \
-	} \
-	err |= get_user((k)->c_ispeed,  &(u)->c_ispeed); \
-	err |= get_user((k)->c_ospeed,  &(u)->c_ospeed); \
-	err; \
-})
+static inline int user_termios_to_kernel_termios(struct ktermios *k,
+						 struct termios2 __user *u)
+{
+	int err;
+	err  = get_user(k->c_iflag, &u->c_iflag);
+	err |= get_user(k->c_oflag, &u->c_oflag);
+	err |= get_user(k->c_cflag, &u->c_cflag);
+	err |= get_user(k->c_lflag, &u->c_lflag);
+	err |= get_user(k->c_line,  &u->c_line);
+	err |= copy_from_user(k->c_cc, u->c_cc, NCCS);
+	if (k->c_lflag & ICANON) {
+		err |= get_user(k->c_cc[VEOF], &u->c_cc[VEOF]);
+		err |= get_user(k->c_cc[VEOL], &u->c_cc[VEOL]);
+	} else {
+		err |= get_user(k->c_cc[VMIN],  &u->c_cc[_VMIN]);
+		err |= get_user(k->c_cc[VTIME], &u->c_cc[_VTIME]);
+	}
+	err |= get_user(k->c_ispeed,  &u->c_ispeed);
+	err |= get_user(k->c_ospeed,  &u->c_ospeed);
+	return err;
+}
 
-#define kernel_termios_to_user_termios(u, k) \
-({ \
-	int err; \
-	err  = put_user((k)->c_iflag, &(u)->c_iflag); \
-	err |= put_user((k)->c_oflag, &(u)->c_oflag); \
-	err |= put_user((k)->c_cflag, &(u)->c_cflag); \
-	err |= put_user((k)->c_lflag, &(u)->c_lflag); \
-	err |= put_user((k)->c_line, &(u)->c_line); \
-	err |= copy_to_user((u)->c_cc, (k)->c_cc, NCCS); \
-	if (!((k)->c_lflag & ICANON)) { \
-		err |= put_user((k)->c_cc[VMIN],  &(u)->c_cc[_VMIN]); \
-		err |= put_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \
-	} else { \
-		err |= put_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \
-		err |= put_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \
-	} \
-	err |= put_user((k)->c_ispeed, &(u)->c_ispeed); \
-	err |= put_user((k)->c_ospeed, &(u)->c_ospeed); \
-	err; \
-})
+#define user_termios_to_kernel_termios user_termios_to_kernel_termios
 
-#define user_termios_to_kernel_termios_1(k, u) \
-({ \
-	int err; \
-	err  = get_user((k)->c_iflag, &(u)->c_iflag); \
-	err |= get_user((k)->c_oflag, &(u)->c_oflag); \
-	err |= get_user((k)->c_cflag, &(u)->c_cflag); \
-	err |= get_user((k)->c_lflag, &(u)->c_lflag); \
-	err |= get_user((k)->c_line,  &(u)->c_line); \
-	err |= copy_from_user((k)->c_cc, (u)->c_cc, NCCS); \
-	if ((k)->c_lflag & ICANON) { \
-		err |= get_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \
-		err |= get_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \
-	} else { \
-		err |= get_user((k)->c_cc[VMIN],  &(u)->c_cc[_VMIN]); \
-		err |= get_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \
-	} \
-	err; \
-})
+static inline int kernel_termios_to_user_termios(struct termios2 __user *u,
+						 struct ktermios *k)
+{
+	int err;
+	err  = put_user(k->c_iflag, &u->c_iflag);
+	err |= put_user(k->c_oflag, &u->c_oflag);
+	err |= put_user(k->c_cflag, &u->c_cflag);
+	err |= put_user(k->c_lflag, &u->c_lflag);
+	err |= put_user(k->c_line, &u->c_line);
+	err |= copy_to_user(u->c_cc, k->c_cc, NCCS);
+	if (!(k->c_lflag & ICANON)) {
+		err |= put_user(k->c_cc[VMIN],  &u->c_cc[_VMIN]);
+		err |= put_user(k->c_cc[VTIME], &u->c_cc[_VTIME]);
+	} else {
+		err |= put_user(k->c_cc[VEOF], &u->c_cc[VEOF]);
+		err |= put_user(k->c_cc[VEOL], &u->c_cc[VEOL]);
+	}
+	err |= put_user(k->c_ispeed, &u->c_ispeed);
+	err |= put_user(k->c_ospeed, &u->c_ospeed);
+	return err;
+}
 
-#define kernel_termios_to_user_termios_1(u, k) \
-({ \
-	int err; \
-	err  = put_user((k)->c_iflag, &(u)->c_iflag); \
-	err |= put_user((k)->c_oflag, &(u)->c_oflag); \
-	err |= put_user((k)->c_cflag, &(u)->c_cflag); \
-	err |= put_user((k)->c_lflag, &(u)->c_lflag); \
-	err |= put_user((k)->c_line, &(u)->c_line); \
-	err |= copy_to_user((u)->c_cc, (k)->c_cc, NCCS); \
-	if (!((k)->c_lflag & ICANON)) { \
-		err |= put_user((k)->c_cc[VMIN],  &(u)->c_cc[_VMIN]); \
-		err |= put_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \
-	} else { \
-		err |= put_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \
-		err |= put_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \
-	} \
-	err; \
-})
+#define kernel_termios_to_user_termios kernel_termios_to_user_termios
+
+static inline int user_termios_to_kernel_termios_1(struct ktermios *k,
+						 struct termios __user *u)
+{
+	int err;
+	err  = get_user(k->c_iflag, &u->c_iflag);
+	err |= get_user(k->c_oflag, &u->c_oflag);
+	err |= get_user(k->c_cflag, &u->c_cflag);
+	err |= get_user(k->c_lflag, &u->c_lflag);
+	err |= get_user(k->c_line,  &u->c_line);
+	err |= copy_from_user(k->c_cc, u->c_cc, NCCS);
+	if (k->c_lflag & ICANON) {
+		err |= get_user(k->c_cc[VEOF], &u->c_cc[VEOF]);
+		err |= get_user(k->c_cc[VEOL], &u->c_cc[VEOL]);
+	} else {
+		err |= get_user(k->c_cc[VMIN],  &u->c_cc[_VMIN]);
+		err |= get_user(k->c_cc[VTIME], &u->c_cc[_VTIME]);
+	}
+	return err;
+}
+
+#define user_termios_to_kernel_termios_1 user_termios_to_kernel_termios_1
+
+static inline int kernel_termios_to_user_termios_1(struct termios __user *u,
+						 struct ktermios *k)
+{
+	int err;
+	err  = put_user(k->c_iflag, &u->c_iflag);
+	err |= put_user(k->c_oflag, &u->c_oflag);
+	err |= put_user(k->c_cflag, &u->c_cflag);
+	err |= put_user(k->c_lflag, &u->c_lflag);
+	err |= put_user(k->c_line, &u->c_line);
+	err |= copy_to_user(u->c_cc, k->c_cc, NCCS);
+	if (!(k->c_lflag & ICANON)) {
+		err |= put_user(k->c_cc[VMIN],  &u->c_cc[_VMIN]);
+		err |= put_user(k->c_cc[VTIME], &u->c_cc[_VTIME]);
+	} else {
+		err |= put_user(k->c_cc[VEOF], &u->c_cc[VEOF]);
+		err |= put_user(k->c_cc[VEOL], &u->c_cc[VEOL]);
+	}
+	return err;
+}
+
+#define kernel_termios_to_user_termios_1 kernel_termios_to_user_termios_1
 
 #endif /* _SPARC_TERMIOS_H */
diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
index d99fec44036c..65410d87786a 100644
--- a/drivers/tty/tty_ioctl.c
+++ b/drivers/tty/tty_ioctl.c
@@ -21,6 +21,7 @@
 #include <linux/bitops.h>
 #include <linux/mutex.h>
 #include <linux/compat.h>
+#include <linux/termios_internal.h>
 
 #include <asm/io.h>
 #include <linux/uaccess.h>
diff --git a/include/asm-generic/termios-base.h b/include/asm-generic/termios-base.h
index 59c5a3bd4a6e..f5f65eb75340 100644
--- a/include/asm-generic/termios-base.h
+++ b/include/asm-generic/termios-base.h
@@ -62,17 +62,6 @@ static inline int kernel_termios_to_user_termio(struct termio __user *termio,
 	return 0;
 }
 
-#ifndef user_termios_to_kernel_termios
-#define user_termios_to_kernel_termios(k, u) copy_from_user(k, u, sizeof(struct termios))
-#endif
-
-#ifndef kernel_termios_to_user_termios
-#define kernel_termios_to_user_termios(u, k) copy_to_user(u, k, sizeof(struct termios))
-#endif
-
-#define user_termios_to_kernel_termios_1(k, u) copy_from_user(k, u, sizeof(struct termios))
-#define kernel_termios_to_user_termios_1(u, k) copy_to_user(u, k, sizeof(struct termios))
-
 #endif	/* __ARCH_TERMIO_GETPUT */
 
 #endif /* _ASM_GENERIC_TERMIOS_BASE_H */
diff --git a/include/asm-generic/termios.h b/include/asm-generic/termios.h
index b1398d0d4a1d..aa897f807ae6 100644
--- a/include/asm-generic/termios.h
+++ b/include/asm-generic/termios.h
@@ -67,42 +67,4 @@ static inline int kernel_termios_to_user_termio(struct termio __user *termio,
 	return 0;
 }
 
-#ifdef TCGETS2
-static inline int user_termios_to_kernel_termios(struct ktermios *k,
-						 struct termios2 __user *u)
-{
-	return copy_from_user(k, u, sizeof(struct termios2));
-}
-
-static inline int kernel_termios_to_user_termios(struct termios2 __user *u,
-						 struct ktermios *k)
-{
-	return copy_to_user(u, k, sizeof(struct termios2));
-}
-
-static inline int user_termios_to_kernel_termios_1(struct ktermios *k,
-						   struct termios __user *u)
-{
-	return copy_from_user(k, u, sizeof(struct termios));
-}
-
-static inline int kernel_termios_to_user_termios_1(struct termios __user *u,
-						   struct ktermios *k)
-{
-	return copy_to_user(u, k, sizeof(struct termios));
-}
-#else /* TCGETS2 */
-static inline int user_termios_to_kernel_termios(struct ktermios *k,
-						 struct termios __user *u)
-{
-	return copy_from_user(k, u, sizeof(struct termios));
-}
-
-static inline int kernel_termios_to_user_termios(struct termios __user *u,
-						 struct ktermios *k)
-{
-	return copy_to_user(u, k, sizeof(struct termios));
-}
-#endif /* TCGETS2 */
-
 #endif /* _ASM_GENERIC_TERMIOS_H */
diff --git a/include/linux/termios_internal.h b/include/linux/termios_internal.h
new file mode 100644
index 000000000000..3beb0595fd54
--- /dev/null
+++ b/include/linux/termios_internal.h
@@ -0,0 +1,58 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_TERMIOS_CONV_H
+#define _LINUX_TERMIOS_CONV_H
+
+#include <linux/uaccess.h>
+#include <asm/termios.h>
+
+#ifdef TCGETS2
+#ifndef user_termios_to_kernel_termios
+static inline int user_termios_to_kernel_termios(struct ktermios *k,
+						 struct termios2 __user *u)
+{
+	return copy_from_user(k, u, sizeof(struct termios2));
+}
+#endif
+#ifndef kernel_termios_to_user_termios
+static inline int kernel_termios_to_user_termios(struct termios2 __user *u,
+						 struct ktermios *k)
+{
+	return copy_to_user(u, k, sizeof(struct termios2));
+}
+#endif
+#ifndef user_termios_to_kernel_termios_1
+static inline int user_termios_to_kernel_termios_1(struct ktermios *k,
+						   struct termios __user *u)
+{
+	return copy_from_user(k, u, sizeof(struct termios));
+}
+#endif
+
+#ifndef kernel_termios_to_user_termios_1
+static inline int kernel_termios_to_user_termios_1(struct termios __user *u,
+						   struct ktermios *k)
+{
+	return copy_to_user(u, k, sizeof(struct termios));
+}
+#endif
+
+#else
+
+#ifndef user_termios_to_kernel_termios
+static inline int user_termios_to_kernel_termios(struct ktermios *k,
+						 struct termios __user *u)
+{
+	return copy_from_user(k, u, sizeof(struct termios));
+}
+#endif
+#ifndef kernel_termios_to_user_termios
+static inline int kernel_termios_to_user_termios(struct termios __user *u,
+						 struct ktermios *k)
+{
+	return copy_to_user(u, k, sizeof(struct termios));
+}
+#endif
+
+#endif /* TCGETS2 */
+
+#endif /* _LINUX_TERMIOS_CONV_H */
-- 
2.11.0


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

* [RFC][PATCH 2/8] move user_termio_to_kernel_termios/kernel_termios_to_user_termio
  2018-09-10  4:52 ` [RFC][PATCH 1/8] start unifying termios convertors Al Viro
@ 2018-09-10  4:52   ` Al Viro
  2018-09-10  4:52   ` [RFC][PATCH 3/8] remove termios-base.h Al Viro
                     ` (5 subsequent siblings)
  6 siblings, 0 replies; 17+ messages in thread
From: Al Viro @ 2018-09-10  4:52 UTC (permalink / raw)
  To: linux-arch; +Cc: Linus Torvalds, linux-kernel

From: Al Viro <viro@zeniv.linux.org.uk>

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 arch/alpha/include/asm/termios.h   | 104 ++++++++++++++++++++-----------------
 arch/ia64/include/asm/termios.h    |  31 -----------
 arch/mips/include/asm/termios.h    |  57 --------------------
 arch/parisc/include/asm/termios.h  |  31 -----------
 arch/sparc/include/asm/termios.h   |  52 +++++++------------
 include/asm-generic/termios-base.h |  57 --------------------
 include/asm-generic/termios.h      |  53 -------------------
 include/linux/termios_internal.h   |  41 +++++++++++++++
 8 files changed, 114 insertions(+), 312 deletions(-)

diff --git a/arch/alpha/include/asm/termios.h b/arch/alpha/include/asm/termios.h
index 1cd44956ae7b..63e1ffc8f719 100644
--- a/arch/alpha/include/asm/termios.h
+++ b/arch/alpha/include/asm/termios.h
@@ -2,6 +2,7 @@
 #ifndef _ALPHA_TERMIOS_H
 #define _ALPHA_TERMIOS_H
 
+#include <linux/uaccess.h>
 #include <uapi/asm/termios.h>
 
 /*	eof=^D		eol=\0		eol2=\0		erase=del
@@ -16,60 +17,65 @@
  * Translate a "termio" structure into a "termios". Ugh.
  */
 
-#define user_termio_to_kernel_termios(a_termios, u_termio)			\
-({										\
-	struct ktermios *k_termios = (a_termios);				\
-	struct termio k_termio;							\
-	int canon, ret;								\
-										\
-	ret = copy_from_user(&k_termio, u_termio, sizeof(k_termio));		\
-	if (!ret) {								\
-		/* Overwrite only the low bits.  */				\
-		*(unsigned short *)&k_termios->c_iflag = k_termio.c_iflag;	\
-		*(unsigned short *)&k_termios->c_oflag = k_termio.c_oflag;	\
-		*(unsigned short *)&k_termios->c_cflag = k_termio.c_cflag;	\
-		*(unsigned short *)&k_termios->c_lflag = k_termio.c_lflag;	\
-		canon = k_termio.c_lflag & ICANON;				\
-										\
-		k_termios->c_cc[VINTR]  = k_termio.c_cc[_VINTR];		\
-		k_termios->c_cc[VQUIT]  = k_termio.c_cc[_VQUIT];		\
-		k_termios->c_cc[VERASE] = k_termio.c_cc[_VERASE];		\
-		k_termios->c_cc[VKILL]  = k_termio.c_cc[_VKILL];		\
-		k_termios->c_cc[VEOL2]  = k_termio.c_cc[_VEOL2];		\
-		k_termios->c_cc[VSWTC]  = k_termio.c_cc[_VSWTC];		\
-		k_termios->c_cc[canon ? VEOF : VMIN]  = k_termio.c_cc[_VEOF];	\
-		k_termios->c_cc[canon ? VEOL : VTIME] = k_termio.c_cc[_VEOL];	\
-	}									\
-	ret;									\
-})
+static inline int user_termio_to_kernel_termios(struct ktermios *termios,
+						struct termio __user *termio)
+{
+	struct termio v;
+	bool canon;
+
+	if (copy_from_user(&v, termio, sizeof(struct termio)))
+		return -EFAULT;
+
+	termios->c_iflag = (0xffff0000 & termios->c_iflag) | v.c_iflag;
+	termios->c_oflag = (0xffff0000 & termios->c_oflag) | v.c_oflag;
+	termios->c_cflag = (0xffff0000 & termios->c_cflag) | v.c_cflag;
+	termios->c_lflag = (0xffff0000 & termios->c_lflag) | v.c_lflag;
+	termios->c_line = (0xffff0000 & termios->c_lflag) | v.c_line;
+
+	canon = v.c_lflag & ICANON;
+	termios->c_cc[VINTR]  = v.c_cc[_VINTR];
+	termios->c_cc[VQUIT]  = v.c_cc[_VQUIT];
+	termios->c_cc[VERASE] = v.c_cc[_VERASE];
+	termios->c_cc[VKILL]  = v.c_cc[_VKILL];
+	termios->c_cc[VEOL2]  = v.c_cc[_VEOL2];
+	termios->c_cc[VSWTC]  = v.c_cc[_VSWTC];
+	termios->c_cc[canon ? VEOF : VMIN]  = v.c_cc[_VEOF];
+	termios->c_cc[canon ? VEOL : VTIME] = v.c_cc[_VEOL];
+
+	return 0;
+}
+#define user_termio_to_kernel_termios user_termio_to_kernel_termios
 
 /*
  * Translate a "termios" structure into a "termio". Ugh.
  *
  * Note the "fun" _VMIN overloading.
  */
-#define kernel_termios_to_user_termio(u_termio, a_termios)		\
-({									\
-	struct ktermios *k_termios = (a_termios);			\
-	struct termio k_termio;						\
-	int canon;							\
-									\
-	k_termio.c_iflag = k_termios->c_iflag;				\
-	k_termio.c_oflag = k_termios->c_oflag;				\
-	k_termio.c_cflag = k_termios->c_cflag;				\
-	canon = (k_termio.c_lflag = k_termios->c_lflag) & ICANON;	\
-									\
-	k_termio.c_line = k_termios->c_line;				\
-	k_termio.c_cc[_VINTR]  = k_termios->c_cc[VINTR];		\
-	k_termio.c_cc[_VQUIT]  = k_termios->c_cc[VQUIT];		\
-	k_termio.c_cc[_VERASE] = k_termios->c_cc[VERASE];		\
-	k_termio.c_cc[_VKILL]  = k_termios->c_cc[VKILL];		\
-	k_termio.c_cc[_VEOF]   = k_termios->c_cc[canon ? VEOF : VMIN];	\
-	k_termio.c_cc[_VEOL]   = k_termios->c_cc[canon ? VEOL : VTIME];	\
-	k_termio.c_cc[_VEOL2]  = k_termios->c_cc[VEOL2];		\
-	k_termio.c_cc[_VSWTC]  = k_termios->c_cc[VSWTC];		\
-									\
-	copy_to_user(u_termio, &k_termio, sizeof(k_termio));		\
-})
+static inline int kernel_termios_to_user_termio(struct termio __user *termio,
+						struct ktermios *termios)
+{
+	struct termio v;
+	bool canon;
+
+	memset(&v, 0, sizeof(struct termio));
+	v.c_iflag = termios->c_iflag;
+	v.c_oflag = termios->c_oflag;
+	v.c_cflag = termios->c_cflag;
+	v.c_lflag = termios->c_lflag;
+	v.c_line = termios->c_line;
+
+	canon = v.c_lflag & ICANON;
+	v.c_cc[_VINTR]  = termios->c_cc[VINTR];
+	v.c_cc[_VQUIT]  = termios->c_cc[VQUIT];
+	v.c_cc[_VERASE] = termios->c_cc[VERASE];
+	v.c_cc[_VKILL]  = termios->c_cc[VKILL];
+	v.c_cc[_VEOF]   = termios->c_cc[canon ? VEOF : VMIN];
+	v.c_cc[_VEOL]   = termios->c_cc[canon ? VEOL : VTIME];
+	v.c_cc[_VEOL2]  = termios->c_cc[VEOL2];
+	v.c_cc[_VSWTC]  = termios->c_cc[VSWTC];
+
+	return copy_to_user(termio, &v, sizeof(struct termio));
+}
+#define kernel_termios_to_user_termio kernel_termios_to_user_termio
 
 #endif	/* _ALPHA_TERMIOS_H */
diff --git a/arch/ia64/include/asm/termios.h b/arch/ia64/include/asm/termios.h
index 1bd5ff9745e9..66ca23c03f3c 100644
--- a/arch/ia64/include/asm/termios.h
+++ b/arch/ia64/include/asm/termios.h
@@ -19,35 +19,4 @@
 */
 #define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
 
-/*
- * Translate a "termio" structure into a "termios". Ugh.
- */
-#define SET_LOW_TERMIOS_BITS(termios, termio, x) {	\
-	unsigned short __tmp;				\
-	get_user(__tmp,&(termio)->x);			\
-	*(unsigned short *) &(termios)->x = __tmp;	\
-}
-
-#define user_termio_to_kernel_termios(termios, termio)		\
-({								\
-	SET_LOW_TERMIOS_BITS(termios, termio, c_iflag);		\
-	SET_LOW_TERMIOS_BITS(termios, termio, c_oflag);		\
-	SET_LOW_TERMIOS_BITS(termios, termio, c_cflag);		\
-	SET_LOW_TERMIOS_BITS(termios, termio, c_lflag);		\
-	copy_from_user((termios)->c_cc, (termio)->c_cc, NCC);	\
-})
-
-/*
- * Translate a "termios" structure into a "termio". Ugh.
- */
-#define kernel_termios_to_user_termio(termio, termios)		\
-({								\
-	put_user((termios)->c_iflag, &(termio)->c_iflag);	\
-	put_user((termios)->c_oflag, &(termio)->c_oflag);	\
-	put_user((termios)->c_cflag, &(termio)->c_cflag);	\
-	put_user((termios)->c_lflag, &(termio)->c_lflag);	\
-	put_user((termios)->c_line,  &(termio)->c_line);	\
-	copy_to_user((termio)->c_cc, (termios)->c_cc, NCC);	\
-})
-
 #endif /* _ASM_IA64_TERMIOS_H */
diff --git a/arch/mips/include/asm/termios.h b/arch/mips/include/asm/termios.h
index 3bd98a70e1d1..dbb62330b7a4 100644
--- a/arch/mips/include/asm/termios.h
+++ b/arch/mips/include/asm/termios.h
@@ -21,61 +21,4 @@
  */
 #define INIT_C_CC "\003\034\177\025\1\0\0\0\021\023\032\0\022\017\027\026\004\0"
 
-#include <linux/string.h>
-
-/*
- * Translate a "termio" structure into a "termios". Ugh.
- */
-static inline int user_termio_to_kernel_termios(struct ktermios *termios,
-	struct termio __user *termio)
-{
-	unsigned short iflag, oflag, cflag, lflag;
-	unsigned int err;
-
-	if (!access_ok(VERIFY_READ, termio, sizeof(struct termio)))
-		return -EFAULT;
-
-	err = __get_user(iflag, &termio->c_iflag);
-	termios->c_iflag = (termios->c_iflag & 0xffff0000) | iflag;
-	err |=__get_user(oflag, &termio->c_oflag);
-	termios->c_oflag = (termios->c_oflag & 0xffff0000) | oflag;
-	err |=__get_user(cflag, &termio->c_cflag);
-	termios->c_cflag = (termios->c_cflag & 0xffff0000) | cflag;
-	err |=__get_user(lflag, &termio->c_lflag);
-	termios->c_lflag = (termios->c_lflag & 0xffff0000) | lflag;
-	err |=__get_user(termios->c_line, &termio->c_line);
-	if (err)
-		return -EFAULT;
-
-	if (__copy_from_user(termios->c_cc, termio->c_cc, NCC))
-		return -EFAULT;
-
-	return 0;
-}
-
-/*
- * Translate a "termios" structure into a "termio". Ugh.
- */
-static inline int kernel_termios_to_user_termio(struct termio __user *termio,
-	struct ktermios *termios)
-{
-	int err;
-
-	if (!access_ok(VERIFY_WRITE, termio, sizeof(struct termio)))
-		return -EFAULT;
-
-	err = __put_user(termios->c_iflag, &termio->c_iflag);
-	err |= __put_user(termios->c_oflag, &termio->c_oflag);
-	err |= __put_user(termios->c_cflag, &termio->c_cflag);
-	err |= __put_user(termios->c_lflag, &termio->c_lflag);
-	err |= __put_user(termios->c_line, &termio->c_line);
-	if (err)
-		return -EFAULT;
-
-	if (__copy_to_user(termio->c_cc, termios->c_cc, NCC))
-		return -EFAULT;
-
-	return 0;
-}
-
 #endif /* _ASM_TERMIOS_H */
diff --git a/arch/parisc/include/asm/termios.h b/arch/parisc/include/asm/termios.h
index 679d31db8d77..2f5153be531f 100644
--- a/arch/parisc/include/asm/termios.h
+++ b/arch/parisc/include/asm/termios.h
@@ -13,35 +13,4 @@
 */
 #define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
 
-/*
- * Translate a "termio" structure into a "termios". Ugh.
- */
-#define SET_LOW_TERMIOS_BITS(termios, termio, x) { \
-	unsigned short __tmp; \
-	get_user(__tmp,&(termio)->x); \
-	*(unsigned short *) &(termios)->x = __tmp; \
-}
-
-#define user_termio_to_kernel_termios(termios, termio) \
-({ \
-	SET_LOW_TERMIOS_BITS(termios, termio, c_iflag); \
-	SET_LOW_TERMIOS_BITS(termios, termio, c_oflag); \
-	SET_LOW_TERMIOS_BITS(termios, termio, c_cflag); \
-	SET_LOW_TERMIOS_BITS(termios, termio, c_lflag); \
-	copy_from_user((termios)->c_cc, (termio)->c_cc, NCC); \
-})
-
-/*
- * Translate a "termios" structure into a "termio". Ugh.
- */
-#define kernel_termios_to_user_termio(termio, termios) \
-({ \
-	put_user((termios)->c_iflag, &(termio)->c_iflag); \
-	put_user((termios)->c_oflag, &(termio)->c_oflag); \
-	put_user((termios)->c_cflag, &(termio)->c_cflag); \
-	put_user((termios)->c_lflag, &(termio)->c_lflag); \
-	put_user((termios)->c_line,  &(termio)->c_line); \
-	copy_to_user((termio)->c_cc, (termios)->c_cc, NCC); \
-})
-
 #endif	/* _PARISC_TERMIOS_H */
diff --git a/arch/sparc/include/asm/termios.h b/arch/sparc/include/asm/termios.h
index 27a054a99a58..0652f870bb1a 100644
--- a/arch/sparc/include/asm/termios.h
+++ b/arch/sparc/include/asm/termios.h
@@ -26,44 +26,28 @@
 #define INIT_C_CC "\003\034\177\025\004\000\000\000\021\023\032\031\022\025\027\026\001"
 
 /*
- * Translate a "termio" structure into a "termios". Ugh.
- */
-#define user_termio_to_kernel_termios(termios, termio) \
-({ \
-	unsigned short tmp; \
-	int err; \
-	err = get_user(tmp, &(termio)->c_iflag); \
-	(termios)->c_iflag = (0xffff0000 & ((termios)->c_iflag)) | tmp; \
-	err |= get_user(tmp, &(termio)->c_oflag); \
-	(termios)->c_oflag = (0xffff0000 & ((termios)->c_oflag)) | tmp; \
-	err |= get_user(tmp, &(termio)->c_cflag); \
-	(termios)->c_cflag = (0xffff0000 & ((termios)->c_cflag)) | tmp; \
-	err |= get_user(tmp, &(termio)->c_lflag); \
-	(termios)->c_lflag = (0xffff0000 & ((termios)->c_lflag)) | tmp; \
-	err |= copy_from_user((termios)->c_cc, (termio)->c_cc, NCC); \
-	err; \
-})
-
-/*
  * Translate a "termios" structure into a "termio". Ugh.
  *
  * Note the "fun" _VMIN overloading.
  */
-#define kernel_termios_to_user_termio(termio, termios) \
-({ \
-	int err; \
-	err  = put_user((termios)->c_iflag, &(termio)->c_iflag); \
-	err |= put_user((termios)->c_oflag, &(termio)->c_oflag); \
-	err |= put_user((termios)->c_cflag, &(termio)->c_cflag); \
-	err |= put_user((termios)->c_lflag, &(termio)->c_lflag); \
-	err |= put_user((termios)->c_line,  &(termio)->c_line); \
-	err |= copy_to_user((termio)->c_cc, (termios)->c_cc, NCC); \
-	if (!((termios)->c_lflag & ICANON)) { \
-		err |= put_user((termios)->c_cc[VMIN], &(termio)->c_cc[_VMIN]); \
-		err |= put_user((termios)->c_cc[VTIME], &(termio)->c_cc[_VTIME]); \
-	} \
-	err; \
-})
+static inline int kernel_termios_to_user_termio(struct termio __user *termio,
+						struct ktermios *termios)
+{
+	struct termio v;
+	memset(&v, 0, sizeof(struct termio));
+	v.c_iflag = termios->c_iflag;
+	v.c_oflag = termios->c_oflag;
+	v.c_cflag = termios->c_cflag;
+	v.c_lflag = termios->c_lflag;
+	v.c_line = termios->c_line;
+	memcpy(v.c_cc, termios->c_cc, NCC);
+	if (!(v.c_lflag & ICANON)) {
+		v.c_cc[_VMIN] = termios->c_cc[VMIN];
+		v.c_cc[_VTIME] = termios->c_cc[VTIME];
+	}
+	return copy_to_user(termio, &v, sizeof(struct termio));
+}
+#define kernel_termios_to_user_termio kernel_termios_to_user_termio
 
 static inline int user_termios_to_kernel_termios(struct ktermios *k,
 						 struct termios2 __user *u)
diff --git a/include/asm-generic/termios-base.h b/include/asm-generic/termios-base.h
index f5f65eb75340..63d948ab6746 100644
--- a/include/asm-generic/termios-base.h
+++ b/include/asm-generic/termios-base.h
@@ -7,61 +7,4 @@
 
 #include <linux/uaccess.h>
 
-#ifndef __ARCH_TERMIO_GETPUT
-
-/*
- * Translate a "termio" structure into a "termios". Ugh.
- */
-static inline int user_termio_to_kernel_termios(struct ktermios *termios,
-						struct termio __user *termio)
-{
-	unsigned short tmp;
-
-	if (get_user(tmp, &termio->c_iflag) < 0)
-		goto fault;
-	termios->c_iflag = (0xffff0000 & termios->c_iflag) | tmp;
-
-	if (get_user(tmp, &termio->c_oflag) < 0)
-		goto fault;
-	termios->c_oflag = (0xffff0000 & termios->c_oflag) | tmp;
-
-	if (get_user(tmp, &termio->c_cflag) < 0)
-		goto fault;
-	termios->c_cflag = (0xffff0000 & termios->c_cflag) | tmp;
-
-	if (get_user(tmp, &termio->c_lflag) < 0)
-		goto fault;
-	termios->c_lflag = (0xffff0000 & termios->c_lflag) | tmp;
-
-	if (get_user(termios->c_line, &termio->c_line) < 0)
-		goto fault;
-
-	if (copy_from_user(termios->c_cc, termio->c_cc, NCC) != 0)
-		goto fault;
-
-	return 0;
-
- fault:
-	return -EFAULT;
-}
-
-/*
- * Translate a "termios" structure into a "termio". Ugh.
- */
-static inline int kernel_termios_to_user_termio(struct termio __user *termio,
-						struct ktermios *termios)
-{
-	if (put_user(termios->c_iflag, &termio->c_iflag) < 0 ||
-	    put_user(termios->c_oflag, &termio->c_oflag) < 0 ||
-	    put_user(termios->c_cflag, &termio->c_cflag) < 0 ||
-	    put_user(termios->c_lflag, &termio->c_lflag) < 0 ||
-	    put_user(termios->c_line,  &termio->c_line) < 0 ||
-	    copy_to_user(termio->c_cc, termios->c_cc, NCC) != 0)
-		return -EFAULT;
-
-	return 0;
-}
-
-#endif	/* __ARCH_TERMIO_GETPUT */
-
 #endif /* _ASM_GENERIC_TERMIOS_BASE_H */
diff --git a/include/asm-generic/termios.h b/include/asm-generic/termios.h
index aa897f807ae6..3ffed3886ff2 100644
--- a/include/asm-generic/termios.h
+++ b/include/asm-generic/termios.h
@@ -14,57 +14,4 @@
 */
 #define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
 
-/*
- * Translate a "termio" structure into a "termios". Ugh.
- */
-static inline int user_termio_to_kernel_termios(struct ktermios *termios,
-						const struct termio __user *termio)
-{
-	unsigned short tmp;
-
-	if (get_user(tmp, &termio->c_iflag) < 0)
-		goto fault;
-	termios->c_iflag = (0xffff0000 & termios->c_iflag) | tmp;
-
-	if (get_user(tmp, &termio->c_oflag) < 0)
-		goto fault;
-	termios->c_oflag = (0xffff0000 & termios->c_oflag) | tmp;
-
-	if (get_user(tmp, &termio->c_cflag) < 0)
-		goto fault;
-	termios->c_cflag = (0xffff0000 & termios->c_cflag) | tmp;
-
-	if (get_user(tmp, &termio->c_lflag) < 0)
-		goto fault;
-	termios->c_lflag = (0xffff0000 & termios->c_lflag) | tmp;
-
-	if (get_user(termios->c_line, &termio->c_line) < 0)
-		goto fault;
-
-	if (copy_from_user(termios->c_cc, termio->c_cc, NCC) != 0)
-		goto fault;
-
-	return 0;
-
- fault:
-	return -EFAULT;
-}
-
-/*
- * Translate a "termios" structure into a "termio". Ugh.
- */
-static inline int kernel_termios_to_user_termio(struct termio __user *termio,
-						struct ktermios *termios)
-{
-	if (put_user(termios->c_iflag, &termio->c_iflag) < 0 ||
-	    put_user(termios->c_oflag, &termio->c_oflag) < 0 ||
-	    put_user(termios->c_cflag, &termio->c_cflag) < 0 ||
-	    put_user(termios->c_lflag, &termio->c_lflag) < 0 ||
-	    put_user(termios->c_line,  &termio->c_line) < 0 ||
-	    copy_to_user(termio->c_cc, termios->c_cc, NCC) != 0)
-		return -EFAULT;
-
-	return 0;
-}
-
 #endif /* _ASM_GENERIC_TERMIOS_H */
diff --git a/include/linux/termios_internal.h b/include/linux/termios_internal.h
index 3beb0595fd54..894f565ffc5f 100644
--- a/include/linux/termios_internal.h
+++ b/include/linux/termios_internal.h
@@ -5,6 +5,47 @@
 #include <linux/uaccess.h>
 #include <asm/termios.h>
 
+#ifndef user_termio_to_kernel_termios
+/*
+ * Translate a "termio" structure into a "termios". Ugh.
+ */
+static inline int user_termio_to_kernel_termios(struct ktermios *termios,
+						struct termio __user *termio)
+{
+	struct termio v;
+
+	if (copy_from_user(&v, termio, sizeof(struct termio)))
+		return -EFAULT;
+
+	termios->c_iflag = (0xffff0000 & termios->c_iflag) | v.c_iflag;
+	termios->c_oflag = (0xffff0000 & termios->c_oflag) | v.c_oflag;
+	termios->c_cflag = (0xffff0000 & termios->c_cflag) | v.c_cflag;
+	termios->c_lflag = (0xffff0000 & termios->c_lflag) | v.c_lflag;
+	termios->c_line = (0xffff0000 & termios->c_lflag) | v.c_line;
+	memcpy(termios->c_cc, v.c_cc, NCC);
+	return 0;
+}
+#endif
+
+#ifndef kernel_termios_to_user_termio
+/*
+ * Translate a "termios" structure into a "termio". Ugh.
+ */
+static inline int kernel_termios_to_user_termio(struct termio __user *termio,
+						struct ktermios *termios)
+{
+	struct termio v;
+	memset(&v, 0, sizeof(struct termio));
+	v.c_iflag = termios->c_iflag;
+	v.c_oflag = termios->c_oflag;
+	v.c_cflag = termios->c_cflag;
+	v.c_lflag = termios->c_lflag;
+	v.c_line = termios->c_line;
+	memcpy(v.c_cc, termios->c_cc, NCC);
+	return copy_to_user(termio, &v, sizeof(struct termio));
+}
+#endif
+
 #ifdef TCGETS2
 #ifndef user_termios_to_kernel_termios
 static inline int user_termios_to_kernel_termios(struct ktermios *k,
-- 
2.11.0


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

* [RFC][PATCH 3/8] remove termios-base.h
  2018-09-10  4:52 ` [RFC][PATCH 1/8] start unifying termios convertors Al Viro
  2018-09-10  4:52   ` [RFC][PATCH 2/8] move user_termio_to_kernel_termios/kernel_termios_to_user_termio Al Viro
@ 2018-09-10  4:52   ` Al Viro
  2018-09-10  4:52   ` [RFC][PATCH 4/8] make users of INIT_C_CC pull linux/termios_internal.h Al Viro
                     ` (4 subsequent siblings)
  6 siblings, 0 replies; 17+ messages in thread
From: Al Viro @ 2018-09-10  4:52 UTC (permalink / raw)
  To: linux-arch; +Cc: Linus Torvalds, linux-kernel

From: Al Viro <viro@zeniv.linux.org.uk>

empty now

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 arch/powerpc/include/asm/termios.h |  2 --
 arch/s390/include/asm/termios.h    |  2 --
 include/asm-generic/termios-base.h | 10 ----------
 3 files changed, 14 deletions(-)
 delete mode 100644 include/asm-generic/termios-base.h

diff --git a/arch/powerpc/include/asm/termios.h b/arch/powerpc/include/asm/termios.h
index b8353e2032d0..cb1e593e95bf 100644
--- a/arch/powerpc/include/asm/termios.h
+++ b/arch/powerpc/include/asm/termios.h
@@ -17,6 +17,4 @@
 /*                   ^C  ^\ del  ^U  ^D   1   0   0   0   0  ^W  ^R  ^Z  ^Q  ^S  ^V  ^U  */
 #define INIT_C_CC "\003\034\177\025\004\001\000\000\000\000\027\022\032\021\023\026\025" 
 
-#include <asm-generic/termios-base.h>
-
 #endif	/* _ASM_POWERPC_TERMIOS_H */
diff --git a/arch/s390/include/asm/termios.h b/arch/s390/include/asm/termios.h
index 62759ac7a92b..7ee16b5dcb6f 100644
--- a/arch/s390/include/asm/termios.h
+++ b/arch/s390/include/asm/termios.h
@@ -18,6 +18,4 @@
 */
 #define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
 
-#include <asm-generic/termios-base.h>
-
 #endif	/* _S390_TERMIOS_H */
diff --git a/include/asm-generic/termios-base.h b/include/asm-generic/termios-base.h
deleted file mode 100644
index 63d948ab6746..000000000000
--- a/include/asm-generic/termios-base.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/* termios.h: generic termios/termio user copying/translation
- */
-
-#ifndef _ASM_GENERIC_TERMIOS_BASE_H
-#define _ASM_GENERIC_TERMIOS_BASE_H
-
-#include <linux/uaccess.h>
-
-#endif /* _ASM_GENERIC_TERMIOS_BASE_H */
-- 
2.11.0


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

* [RFC][PATCH 4/8] make users of INIT_C_CC pull linux/termios_internal.h
  2018-09-10  4:52 ` [RFC][PATCH 1/8] start unifying termios convertors Al Viro
  2018-09-10  4:52   ` [RFC][PATCH 2/8] move user_termio_to_kernel_termios/kernel_termios_to_user_termio Al Viro
  2018-09-10  4:52   ` [RFC][PATCH 3/8] remove termios-base.h Al Viro
@ 2018-09-10  4:52   ` Al Viro
  2018-09-10  4:52   ` [RFC][PATCH 5/8] make generic INIT_C_CC a bit more generic Al Viro
                     ` (3 subsequent siblings)
  6 siblings, 0 replies; 17+ messages in thread
From: Al Viro @ 2018-09-10  4:52 UTC (permalink / raw)
  To: linux-arch; +Cc: Linus Torvalds, linux-kernel

From: Al Viro <viro@zeniv.linux.org.uk>

... and move the default definition in there

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 arch/ia64/include/asm/termios.h   |  9 ---------
 arch/parisc/include/asm/termios.h |  9 ---------
 arch/s390/include/asm/termios.h   |  9 ---------
 drivers/tty/hvc/hvcs.c            |  1 +
 drivers/tty/tty_io.c              |  1 +
 drivers/tty/vcc.c                 |  1 +
 include/asm-generic/termios.h     |  8 --------
 include/linux/termios_internal.h  | 10 ++++++++++
 8 files changed, 13 insertions(+), 35 deletions(-)

diff --git a/arch/ia64/include/asm/termios.h b/arch/ia64/include/asm/termios.h
index 66ca23c03f3c..1cef02701401 100644
--- a/arch/ia64/include/asm/termios.h
+++ b/arch/ia64/include/asm/termios.h
@@ -10,13 +10,4 @@
 
 #include <uapi/asm/termios.h>
 
-
-/*	intr=^C		quit=^\		erase=del	kill=^U
-	eof=^D		vtime=\0	vmin=\1		sxtc=\0
-	start=^Q	stop=^S		susp=^Z		eol=\0
-	reprint=^R	discard=^U	werase=^W	lnext=^V
-	eol2=\0
-*/
-#define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
-
 #endif /* _ASM_IA64_TERMIOS_H */
diff --git a/arch/parisc/include/asm/termios.h b/arch/parisc/include/asm/termios.h
index 2f5153be531f..1850a90befb3 100644
--- a/arch/parisc/include/asm/termios.h
+++ b/arch/parisc/include/asm/termios.h
@@ -4,13 +4,4 @@
 
 #include <uapi/asm/termios.h>
 
-
-/*	intr=^C		quit=^\		erase=del	kill=^U
-	eof=^D		vtime=\0	vmin=\1		sxtc=\0
-	start=^Q	stop=^S		susp=^Z		eol=\0
-	reprint=^R	discard=^U	werase=^W	lnext=^V
-	eol2=\0
-*/
-#define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
-
 #endif	/* _PARISC_TERMIOS_H */
diff --git a/arch/s390/include/asm/termios.h b/arch/s390/include/asm/termios.h
index 7ee16b5dcb6f..0e26fe97b0d4 100644
--- a/arch/s390/include/asm/termios.h
+++ b/arch/s390/include/asm/termios.h
@@ -9,13 +9,4 @@
 
 #include <uapi/asm/termios.h>
 
-
-/*	intr=^C		quit=^\		erase=del	kill=^U
-	eof=^D		vtime=\0	vmin=\1		sxtc=\0
-	start=^Q	stop=^S		susp=^Z		eol=\0
-	reprint=^R	discard=^U	werase=^W	lnext=^V
-	eol2=\0
-*/
-#define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
-
 #endif	/* _S390_TERMIOS_H */
diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
index cb4db1b3ca3c..f6be8f999026 100644
--- a/drivers/tty/hvc/hvcs.c
+++ b/drivers/tty/hvc/hvcs.c
@@ -69,6 +69,7 @@
 #include <asm/hvconsole.h>
 #include <asm/hvcserver.h>
 #include <linux/uaccess.h>
+#include <linux/termios_internal.h>
 #include <asm/vio.h>
 
 /*
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 32bc3e3fe4d3..9da2bd81e97e 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -97,6 +97,7 @@
 #include <linux/seq_file.h>
 #include <linux/serial.h>
 #include <linux/ratelimit.h>
+#include <linux/termios_internal.h>
 
 #include <linux/uaccess.h>
 
diff --git a/drivers/tty/vcc.c b/drivers/tty/vcc.c
index 58b454c34560..f674306be121 100644
--- a/drivers/tty/vcc.c
+++ b/drivers/tty/vcc.c
@@ -10,6 +10,7 @@
 #include <linux/sysfs.h>
 #include <linux/tty.h>
 #include <linux/tty_flip.h>
+#include <linux/termios_internal.h>
 #include <asm/vio.h>
 #include <asm/ldc.h>
 
diff --git a/include/asm-generic/termios.h b/include/asm-generic/termios.h
index 3ffed3886ff2..da3b0fe25442 100644
--- a/include/asm-generic/termios.h
+++ b/include/asm-generic/termios.h
@@ -6,12 +6,4 @@
 #include <linux/uaccess.h>
 #include <uapi/asm-generic/termios.h>
 
-/*	intr=^C		quit=^\		erase=del	kill=^U
-	eof=^D		vtime=\0	vmin=\1		sxtc=\0
-	start=^Q	stop=^S		susp=^Z		eol=\0
-	reprint=^R	discard=^U	werase=^W	lnext=^V
-	eol2=\0
-*/
-#define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
-
 #endif /* _ASM_GENERIC_TERMIOS_H */
diff --git a/include/linux/termios_internal.h b/include/linux/termios_internal.h
index 894f565ffc5f..a77fd8df783e 100644
--- a/include/linux/termios_internal.h
+++ b/include/linux/termios_internal.h
@@ -5,6 +5,16 @@
 #include <linux/uaccess.h>
 #include <asm/termios.h>
 
+#ifndef INIT_C_CC
+/*	intr=^C		quit=^\		erase=del	kill=^U
+	eof=^D		vtime=\0	vmin=\1		sxtc=\0
+	start=^Q	stop=^S		susp=^Z		eol=\0
+	reprint=^R	discard=^U	werase=^W	lnext=^V
+	eol2=\0
+*/
+#define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
+#endif
+
 #ifndef user_termio_to_kernel_termios
 /*
  * Translate a "termio" structure into a "termios". Ugh.
-- 
2.11.0


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

* [RFC][PATCH 5/8] make generic INIT_C_CC a bit more generic
  2018-09-10  4:52 ` [RFC][PATCH 1/8] start unifying termios convertors Al Viro
                     ` (2 preceding siblings ...)
  2018-09-10  4:52   ` [RFC][PATCH 4/8] make users of INIT_C_CC pull linux/termios_internal.h Al Viro
@ 2018-09-10  4:52   ` Al Viro
  2018-09-10  4:52   ` [RFC][PATCH 6/8] untangle asm/termios.h mess Al Viro
                     ` (2 subsequent siblings)
  6 siblings, 0 replies; 17+ messages in thread
From: Al Viro @ 2018-09-10  4:52 UTC (permalink / raw)
  To: linux-arch; +Cc: Linus Torvalds, linux-kernel

From: Al Viro <viro@zeniv.linux.org.uk>

turn it into an array initializer; then mips variant folds into
it.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 arch/mips/include/asm/termios.h  |  9 ---------
 include/linux/termios_internal.h | 15 ++++++++++++++-
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/arch/mips/include/asm/termios.h b/arch/mips/include/asm/termios.h
index dbb62330b7a4..12bc56857bf1 100644
--- a/arch/mips/include/asm/termios.h
+++ b/arch/mips/include/asm/termios.h
@@ -12,13 +12,4 @@
 #include <linux/uaccess.h>
 #include <uapi/asm/termios.h>
 
-/*
- *	intr=^C		quit=^\		erase=del	kill=^U
- *	vmin=\1		vtime=\0	eol2=\0		swtc=\0
- *	start=^Q	stop=^S		susp=^Z		vdsusp=
- *	reprint=^R	discard=^U	werase=^W	lnext=^V
- *	eof=^D		eol=\0
- */
-#define INIT_C_CC "\003\034\177\025\1\0\0\0\021\023\032\0\022\017\027\026\004\0"
-
 #endif /* _ASM_TERMIOS_H */
diff --git a/include/linux/termios_internal.h b/include/linux/termios_internal.h
index a77fd8df783e..d25b9a9c2faf 100644
--- a/include/linux/termios_internal.h
+++ b/include/linux/termios_internal.h
@@ -12,7 +12,20 @@
 	reprint=^R	discard=^U	werase=^W	lnext=^V
 	eol2=\0
 */
-#define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
+#define INIT_C_CC {		\
+	[VINTR] = 'C'-0x40,	\
+	[VQUIT] = '\\'-0x40,	\
+	[VERASE] = '\177',	\
+	[VKILL] = 'U'-0x40,	\
+	[VEOF] = 'D'-0x40,	\
+	[VSTART] = 'Q'-0x40,	\
+	[VSTOP] = 'S'-0x40,	\
+	[VSUSP] = 'Z'-0x40,	\
+	[VREPRINT] = 'R'-0x40,	\
+	[VDISCARD] = 'O'-0x40,	\
+	[VWERASE] = 'W'-0x40,	\
+	[VLNEXT] = 'V'-0x40,	\
+	[VMIN] = 1 }
 #endif
 
 #ifndef user_termio_to_kernel_termios
-- 
2.11.0


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

* [RFC][PATCH 6/8] untangle asm/termios.h mess
  2018-09-10  4:52 ` [RFC][PATCH 1/8] start unifying termios convertors Al Viro
                     ` (3 preceding siblings ...)
  2018-09-10  4:52   ` [RFC][PATCH 5/8] make generic INIT_C_CC a bit more generic Al Viro
@ 2018-09-10  4:52   ` Al Viro
  2018-09-10  4:52   ` [RFC][PATCH 7/8] switch x86 to generic uapi asm/termios.h Al Viro
  2018-09-10  4:52   ` [RFC][PATCH 8/8] really consolidate INIT_C_CC definitions Al Viro
  6 siblings, 0 replies; 17+ messages in thread
From: Al Viro @ 2018-09-10  4:52 UTC (permalink / raw)
  To: linux-arch; +Cc: Linus Torvalds, linux-kernel

From: Al Viro <viro@zeniv.linux.org.uk>

Currently, asm/termios.h resolves either to uapi/asm/termios.h
(on architectures that don't have it) or to the same plus the
definitions that are only used by those who pull linux/termios_internal.h

That causes tons of inconveniences - e.g. we can't have generic
asm/termios.h with non-generic uapi/asm/termios.h.

Let's do the following:
	* rename asm/termios.h to asm/termios_internal.h and make
linux/termios_internal.h pull that; that way all includes of
<asm/termios.h> will go directly to uapi/asm/termios.h
	* all but 3 architectures actually have asm/termios.h completely
generic.  Make those 3 select a new config symbol (HAVE_TERMIOS_INTERNAL)
and make the include of asm/termios_internal.h conditional upon that.
Remove all generic instances of asm/termios.h (including include/asm-generic
one).
	* get rid of one pointless include of <asm/termios.h> in
drivers/tty.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 arch/Kconfig                                              |  3 +++
 arch/alpha/Kconfig                                        |  1 +
 arch/alpha/include/asm/{termios.h => termios_internal.h}  |  3 ---
 arch/ia64/include/asm/termios.h                           | 13 -------------
 arch/mips/include/asm/termios.h                           | 15 ---------------
 arch/parisc/include/asm/termios.h                         |  7 -------
 arch/powerpc/Kconfig                                      |  1 +
 .../powerpc/include/asm/{termios.h => termios_internal.h} |  2 --
 arch/riscv/include/asm/Kbuild                             |  1 -
 arch/s390/include/asm/termios.h                           | 12 ------------
 arch/sparc/Kconfig                                        |  1 +
 arch/sparc/include/asm/{termios.h => termios_internal.h}  |  4 ----
 drivers/tty/n_hdlc.c                                      |  1 -
 include/asm-generic/termios.h                             |  9 ---------
 include/linux/termios_internal.h                          |  3 +++
 15 files changed, 9 insertions(+), 67 deletions(-)
 rename arch/alpha/include/asm/{termios.h => termios_internal.h} (97%)
 delete mode 100644 arch/ia64/include/asm/termios.h
 delete mode 100644 arch/mips/include/asm/termios.h
 delete mode 100644 arch/parisc/include/asm/termios.h
 rename arch/powerpc/include/asm/{termios.h => termios_internal.h} (96%)
 delete mode 100644 arch/s390/include/asm/termios.h
 rename arch/sparc/include/asm/{termios.h => termios_internal.h} (98%)
 delete mode 100644 include/asm-generic/termios.h

diff --git a/arch/Kconfig b/arch/Kconfig
index 6801123932a5..a36cce432768 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -727,6 +727,9 @@ config OLD_SIGACTION
 config COMPAT_OLD_SIGACTION
 	bool
 
+config HAS_TERMIOS_INTERNAL
+	bool
+
 config 64BIT_TIME
 	def_bool ARCH_HAS_64BIT_TIME
 	help
diff --git a/arch/alpha/Kconfig b/arch/alpha/Kconfig
index 5b4f88363453..85120bbda191 100644
--- a/arch/alpha/Kconfig
+++ b/arch/alpha/Kconfig
@@ -30,6 +30,7 @@ config ALPHA
 	select MODULES_USE_ELF_RELA
 	select ODD_RT_SIGACTION
 	select OLD_SIGSUSPEND
+	select HAS_TERMIOS_INTERNAL
 	select CPU_NO_EFFICIENT_FFS if !ALPHA_EV67
 	help
 	  The Alpha is a 64-bit general-purpose processor designed and
diff --git a/arch/alpha/include/asm/termios.h b/arch/alpha/include/asm/termios_internal.h
similarity index 97%
rename from arch/alpha/include/asm/termios.h
rename to arch/alpha/include/asm/termios_internal.h
index 63e1ffc8f719..6c2a67e65992 100644
--- a/arch/alpha/include/asm/termios.h
+++ b/arch/alpha/include/asm/termios_internal.h
@@ -2,9 +2,6 @@
 #ifndef _ALPHA_TERMIOS_H
 #define _ALPHA_TERMIOS_H
 
-#include <linux/uaccess.h>
-#include <uapi/asm/termios.h>
-
 /*	eof=^D		eol=\0		eol2=\0		erase=del
 	werase=^W	kill=^U		reprint=^R	sxtc=\0
 	intr=^C		quit=^\		susp=^Z		<OSF/1 VDSUSP>
diff --git a/arch/ia64/include/asm/termios.h b/arch/ia64/include/asm/termios.h
deleted file mode 100644
index 1cef02701401..000000000000
--- a/arch/ia64/include/asm/termios.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * Modified 1999
- *	David Mosberger-Tang <davidm@hpl.hp.com>, Hewlett-Packard Co
- *
- * 99/01/28	Added N_IRDA and N_SMSBLOCK
- */
-#ifndef _ASM_IA64_TERMIOS_H
-#define _ASM_IA64_TERMIOS_H
-
-#include <uapi/asm/termios.h>
-
-#endif /* _ASM_IA64_TERMIOS_H */
diff --git a/arch/mips/include/asm/termios.h b/arch/mips/include/asm/termios.h
deleted file mode 100644
index 12bc56857bf1..000000000000
--- a/arch/mips/include/asm/termios.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * This file is subject to the terms and conditions of the GNU General Public
- * License.  See the file "COPYING" in the main directory of this archive
- * for more details.
- *
- * Copyright (C) 1995, 1996, 2000, 2001 by Ralf Baechle
- * Copyright (C) 2000, 2001 Silicon Graphics, Inc.
- */
-#ifndef _ASM_TERMIOS_H
-#define _ASM_TERMIOS_H
-
-#include <linux/uaccess.h>
-#include <uapi/asm/termios.h>
-
-#endif /* _ASM_TERMIOS_H */
diff --git a/arch/parisc/include/asm/termios.h b/arch/parisc/include/asm/termios.h
deleted file mode 100644
index 1850a90befb3..000000000000
--- a/arch/parisc/include/asm/termios.h
+++ /dev/null
@@ -1,7 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _PARISC_TERMIOS_H
-#define _PARISC_TERMIOS_H
-
-#include <uapi/asm/termios.h>
-
-#endif	/* _PARISC_TERMIOS_H */
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index db0b6eebbfa5..b1402b1f1685 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -223,6 +223,7 @@ config PPC
 	select HAVE_VIRT_CPU_ACCOUNTING
 	select HAVE_IRQ_TIME_ACCOUNTING
 	select HAVE_RSEQ
+	select HAS_TERMIOS_INTERNAL
 	select IOMMU_HELPER			if PPC64
 	select IRQ_DOMAIN
 	select IRQ_FORCED_THREADING
diff --git a/arch/powerpc/include/asm/termios.h b/arch/powerpc/include/asm/termios_internal.h
similarity index 96%
rename from arch/powerpc/include/asm/termios.h
rename to arch/powerpc/include/asm/termios_internal.h
index cb1e593e95bf..b93e889342cf 100644
--- a/arch/powerpc/include/asm/termios.h
+++ b/arch/powerpc/include/asm/termios_internal.h
@@ -12,8 +12,6 @@
 #ifndef _ASM_POWERPC_TERMIOS_H
 #define _ASM_POWERPC_TERMIOS_H
 
-#include <uapi/asm/termios.h>
-
 /*                   ^C  ^\ del  ^U  ^D   1   0   0   0   0  ^W  ^R  ^Z  ^Q  ^S  ^V  ^U  */
 #define INIT_C_CC "\003\034\177\025\004\001\000\000\000\000\027\022\032\021\023\026\025" 
 
diff --git a/arch/riscv/include/asm/Kbuild b/arch/riscv/include/asm/Kbuild
index efdbe311e936..f74ea476a932 100644
--- a/arch/riscv/include/asm/Kbuild
+++ b/arch/riscv/include/asm/Kbuild
@@ -52,7 +52,6 @@ generic-y += stat.h
 generic-y += statfs.h
 generic-y += swab.h
 generic-y += termbits.h
-generic-y += termios.h
 generic-y += topology.h
 generic-y += trace_clock.h
 generic-y += types.h
diff --git a/arch/s390/include/asm/termios.h b/arch/s390/include/asm/termios.h
deleted file mode 100644
index 0e26fe97b0d4..000000000000
--- a/arch/s390/include/asm/termios.h
+++ /dev/null
@@ -1,12 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- *  S390 version
- *
- *  Derived from "include/asm-i386/termios.h"
- */
-#ifndef _S390_TERMIOS_H
-#define _S390_TERMIOS_H
-
-#include <uapi/asm/termios.h>
-
-#endif	/* _S390_TERMIOS_H */
diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
index e6f2a38d2e61..ef9fba4a2d0f 100644
--- a/arch/sparc/Kconfig
+++ b/arch/sparc/Kconfig
@@ -33,6 +33,7 @@ config SPARC
 	select HAVE_CBPF_JIT if SPARC32
 	select HAVE_EBPF_JIT if SPARC64
 	select HAVE_DEBUG_BUGVERBOSE
+	select HAS_TERMIOS_INTERNAL
 	select GENERIC_SMP_IDLE_THREAD
 	select GENERIC_CLOCKEVENTS
 	select GENERIC_STRNCPY_FROM_USER
diff --git a/arch/sparc/include/asm/termios.h b/arch/sparc/include/asm/termios_internal.h
similarity index 98%
rename from arch/sparc/include/asm/termios.h
rename to arch/sparc/include/asm/termios_internal.h
index 0652f870bb1a..028c6bd6e0a7 100644
--- a/arch/sparc/include/asm/termios.h
+++ b/arch/sparc/include/asm/termios_internal.h
@@ -2,10 +2,6 @@
 #ifndef _SPARC_TERMIOS_H
 #define _SPARC_TERMIOS_H
 
-#include <uapi/asm/termios.h>
-#include <linux/uaccess.h>
-
-
 /*
  * c_cc characters in the termio structure.  Oh, how I love being
  * backwardly compatible.  Notice that character 4 and 5 are
diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c
index dabb391909aa..ca3395994a43 100644
--- a/drivers/tty/n_hdlc.c
+++ b/drivers/tty/n_hdlc.c
@@ -101,7 +101,6 @@
 #include <linux/if.h>
 #include <linux/bitops.h>
 
-#include <asm/termios.h>
 #include <linux/uaccess.h>
 
 /*
diff --git a/include/asm-generic/termios.h b/include/asm-generic/termios.h
deleted file mode 100644
index da3b0fe25442..000000000000
--- a/include/asm-generic/termios.h
+++ /dev/null
@@ -1,9 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ASM_GENERIC_TERMIOS_H
-#define _ASM_GENERIC_TERMIOS_H
-
-
-#include <linux/uaccess.h>
-#include <uapi/asm-generic/termios.h>
-
-#endif /* _ASM_GENERIC_TERMIOS_H */
diff --git a/include/linux/termios_internal.h b/include/linux/termios_internal.h
index d25b9a9c2faf..343f7868713d 100644
--- a/include/linux/termios_internal.h
+++ b/include/linux/termios_internal.h
@@ -4,6 +4,9 @@
 
 #include <linux/uaccess.h>
 #include <asm/termios.h>
+#ifdef CONFIG_HAS_TERMIOS_INTERNAL
+#include <asm/termios_internal.h>
+#endif
 
 #ifndef INIT_C_CC
 /*	intr=^C		quit=^\		erase=del	kill=^U
-- 
2.11.0


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

* [RFC][PATCH 7/8] switch x86 to generic uapi asm/termios.h
  2018-09-10  4:52 ` [RFC][PATCH 1/8] start unifying termios convertors Al Viro
                     ` (4 preceding siblings ...)
  2018-09-10  4:52   ` [RFC][PATCH 6/8] untangle asm/termios.h mess Al Viro
@ 2018-09-10  4:52   ` Al Viro
  2018-09-10  4:52   ` [RFC][PATCH 8/8] really consolidate INIT_C_CC definitions Al Viro
  6 siblings, 0 replies; 17+ messages in thread
From: Al Viro @ 2018-09-10  4:52 UTC (permalink / raw)
  To: linux-arch; +Cc: Linus Torvalds, linux-kernel

From: Al Viro <viro@zeniv.linux.org.uk>

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 arch/x86/include/uapi/asm/Kbuild    | 1 +
 arch/x86/include/uapi/asm/termios.h | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)
 delete mode 100644 arch/x86/include/uapi/asm/termios.h

diff --git a/arch/x86/include/uapi/asm/Kbuild b/arch/x86/include/uapi/asm/Kbuild
index 322681622d1e..56994b75c491 100644
--- a/arch/x86/include/uapi/asm/Kbuild
+++ b/arch/x86/include/uapi/asm/Kbuild
@@ -2,6 +2,7 @@
 include include/uapi/asm-generic/Kbuild.asm
 
 generic-y += bpf_perf_event.h
+generic-y += termios.h
 generated-y += unistd_32.h
 generated-y += unistd_64.h
 generated-y += unistd_x32.h
diff --git a/arch/x86/include/uapi/asm/termios.h b/arch/x86/include/uapi/asm/termios.h
deleted file mode 100644
index 280d78a9d966..000000000000
--- a/arch/x86/include/uapi/asm/termios.h
+++ /dev/null
@@ -1 +0,0 @@
-#include <asm-generic/termios.h>
-- 
2.11.0


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

* [RFC][PATCH 8/8] really consolidate INIT_C_CC definitions
  2018-09-10  4:52 ` [RFC][PATCH 1/8] start unifying termios convertors Al Viro
                     ` (5 preceding siblings ...)
  2018-09-10  4:52   ` [RFC][PATCH 7/8] switch x86 to generic uapi asm/termios.h Al Viro
@ 2018-09-10  4:52   ` Al Viro
  2018-09-10 13:33     ` Linus Torvalds
  6 siblings, 1 reply; 17+ messages in thread
From: Al Viro @ 2018-09-10  4:52 UTC (permalink / raw)
  To: linux-arch; +Cc: Linus Torvalds, linux-kernel

From: Al Viro <viro@zeniv.linux.org.uk>

they vary in two respects (renumbering of fields aside):
	* sparc (and nobody else) has dsusp; set to ^Y.
	* original (on i386) has discard set to historical
value (^O), mistaken comment nonwithstanding.  alpha, ppc
and sparc have followed the comment.  Not that we'd ever
handled that thing anyway...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 arch/alpha/include/asm/termios_internal.h   |  8 +-------
 arch/powerpc/include/asm/termios_internal.h |  3 +--
 arch/sparc/include/asm/termios_internal.h   |  8 +-------
 include/linux/termios_internal.h            | 16 ++++++++++++++--
 4 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/arch/alpha/include/asm/termios_internal.h b/arch/alpha/include/asm/termios_internal.h
index 6c2a67e65992..07d5c1a6cdf6 100644
--- a/arch/alpha/include/asm/termios_internal.h
+++ b/arch/alpha/include/asm/termios_internal.h
@@ -2,13 +2,7 @@
 #ifndef _ALPHA_TERMIOS_H
 #define _ALPHA_TERMIOS_H
 
-/*	eof=^D		eol=\0		eol2=\0		erase=del
-	werase=^W	kill=^U		reprint=^R	sxtc=\0
-	intr=^C		quit=^\		susp=^Z		<OSF/1 VDSUSP>
-	start=^Q	stop=^S		lnext=^V	discard=^U
-	vmin=\1		vtime=\0
-*/
-#define INIT_C_CC "\004\000\000\177\027\025\022\000\003\034\032\000\021\023\026\025\001\000"
+#define INIT_C_CC_VDISCARD 'U'-0x40
 
 /*
  * Translate a "termio" structure into a "termios". Ugh.
diff --git a/arch/powerpc/include/asm/termios_internal.h b/arch/powerpc/include/asm/termios_internal.h
index b93e889342cf..116b138ea232 100644
--- a/arch/powerpc/include/asm/termios_internal.h
+++ b/arch/powerpc/include/asm/termios_internal.h
@@ -12,7 +12,6 @@
 #ifndef _ASM_POWERPC_TERMIOS_H
 #define _ASM_POWERPC_TERMIOS_H
 
-/*                   ^C  ^\ del  ^U  ^D   1   0   0   0   0  ^W  ^R  ^Z  ^Q  ^S  ^V  ^U  */
-#define INIT_C_CC "\003\034\177\025\004\001\000\000\000\000\027\022\032\021\023\026\025" 
+#define INIT_C_CC_VDISCARD 'U'-0x40
 
 #endif	/* _ASM_POWERPC_TERMIOS_H */
diff --git a/arch/sparc/include/asm/termios_internal.h b/arch/sparc/include/asm/termios_internal.h
index 028c6bd6e0a7..1649a0cecda9 100644
--- a/arch/sparc/include/asm/termios_internal.h
+++ b/arch/sparc/include/asm/termios_internal.h
@@ -13,13 +13,7 @@
 #define _VMIN	4
 #define _VTIME	5
 
-/*	intr=^C		quit=^\		erase=del	kill=^U
-	eof=^D		eol=\0		eol2=\0		sxtc=\0
-	start=^Q	stop=^S		susp=^Z		dsusp=^Y
-	reprint=^R	discard=^U	werase=^W	lnext=^V
-	vmin=\1         vtime=\0
-*/
-#define INIT_C_CC "\003\034\177\025\004\000\000\000\021\023\032\031\022\025\027\026\001"
+#define INIT_C_CC_VDISCARD 'U'-0x40
 
 /*
  * Translate a "termios" structure into a "termio". Ugh.
diff --git a/include/linux/termios_internal.h b/include/linux/termios_internal.h
index 343f7868713d..549715b18d22 100644
--- a/include/linux/termios_internal.h
+++ b/include/linux/termios_internal.h
@@ -8,13 +8,24 @@
 #include <asm/termios_internal.h>
 #endif
 
-#ifndef INIT_C_CC
 /*	intr=^C		quit=^\		erase=del	kill=^U
 	eof=^D		vtime=\0	vmin=\1		sxtc=\0
 	start=^Q	stop=^S		susp=^Z		eol=\0
 	reprint=^R	discard=^U	werase=^W	lnext=^V
 	eol2=\0
+	... except that discard is actually ^O on most of them.
 */
+#ifndef INIT_C_CC_VDISCARD
+#define INIT_C_CC_VDISCARD 'O'-0x40
+#endif
+
+#ifdef VDSUSP
+#define INIT_C_CC_VDSUSP_EXTRA [VDSUSP] = 'Y'-0x40,
+#else
+#define INIT_C_CC_VDSUSP_EXTRA
+#endif
+
+#ifndef INIT_C_CC
 #define INIT_C_CC {		\
 	[VINTR] = 'C'-0x40,	\
 	[VQUIT] = '\\'-0x40,	\
@@ -25,9 +36,10 @@
 	[VSTOP] = 'S'-0x40,	\
 	[VSUSP] = 'Z'-0x40,	\
 	[VREPRINT] = 'R'-0x40,	\
-	[VDISCARD] = 'O'-0x40,	\
+	[VDISCARD] = INIT_C_CC_VDISCARD,	\
 	[VWERASE] = 'W'-0x40,	\
 	[VLNEXT] = 'V'-0x40,	\
+	INIT_C_CC_VDSUSP_EXTRA	\
 	[VMIN] = 1 }
 #endif
 
-- 
2.11.0


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

* Re: [RFC][PATCH 1/8] start unifying termios convertors
  2018-09-10  4:49 [RFC][PATCHES] termios.h cleanups Al Viro
  2018-09-10  4:52 ` [RFC][PATCH 1/8] start unifying termios convertors Al Viro
@ 2018-09-10  8:32 ` David Howells
  1 sibling, 0 replies; 17+ messages in thread
From: David Howells @ 2018-09-10  8:32 UTC (permalink / raw)
  To: Al Viro; +Cc: dhowells, linux-arch, Linus Torvalds, linux-kernel

Al Viro <viro@ZenIV.linux.org.uk> wrote:

> +static inline int kernel_termios_to_user_termios(struct termios2 __user *u,
> +						 struct ktermios *k)
> +{
> +	int err;
> +	err  = put_user(k->c_iflag, &u->c_iflag);
> +	err |= put_user(k->c_oflag, &u->c_oflag);
> +	err |= put_user(k->c_cflag, &u->c_cflag);
> +	err |= put_user(k->c_lflag, &u->c_lflag);
> +	err |= put_user(k->c_line, &u->c_line);
> +	err |= copy_to_user(u->c_cc, k->c_cc, NCCS);
> +	if (!(k->c_lflag & ICANON)) {
> +		err |= put_user(k->c_cc[VMIN],  &u->c_cc[_VMIN]);
> +		err |= put_user(k->c_cc[VTIME], &u->c_cc[_VTIME]);
> +	} else {
> +		err |= put_user(k->c_cc[VEOF], &u->c_cc[VEOF]);
> +		err |= put_user(k->c_cc[VEOL], &u->c_cc[VEOL]);
> +	}
> +	err |= put_user(k->c_ispeed, &u->c_ispeed);
> +	err |= put_user(k->c_ospeed, &u->c_ospeed);
> +	return err;
> +}

Can you make this use || instead of |= ?  That way if put_user() uses a
goto-out-of-asm it may be a lot more efficient, both in the normal case and
the error case.

David

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

* Re: [RFC][PATCH 8/8] really consolidate INIT_C_CC definitions
  2018-09-10  4:52   ` [RFC][PATCH 8/8] really consolidate INIT_C_CC definitions Al Viro
@ 2018-09-10 13:33     ` Linus Torvalds
  2018-09-10 14:45       ` Al Viro
  0 siblings, 1 reply; 17+ messages in thread
From: Linus Torvalds @ 2018-09-10 13:33 UTC (permalink / raw)
  To: Al Viro; +Cc: linux-arch, Linux Kernel Mailing List

On Sun, Sep 9, 2018 at 6:52 PM Al Viro <viro@zeniv.linux.org.uk> wrote:
>
>  */
> +#ifndef INIT_C_CC_VDISCARD
> +#define INIT_C_CC_VDISCARD 'O'-0x40
> +#endif

Just change everybody to do the same, nobody cares about VDISCARD.

We can change the value of VDISCARD because it doesn't actually have
anything connected to it, so don't worry about "we used to have odd
different values for it".

            Linus

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

* Re: [RFC][PATCH 8/8] really consolidate INIT_C_CC definitions
  2018-09-10 13:33     ` Linus Torvalds
@ 2018-09-10 14:45       ` Al Viro
  0 siblings, 0 replies; 17+ messages in thread
From: Al Viro @ 2018-09-10 14:45 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-arch, Linux Kernel Mailing List

On Mon, Sep 10, 2018 at 03:33:45AM -1000, Linus Torvalds wrote:
> On Sun, Sep 9, 2018 at 6:52 PM Al Viro <viro@zeniv.linux.org.uk> wrote:
> >
> >  */
> > +#ifndef INIT_C_CC_VDISCARD
> > +#define INIT_C_CC_VDISCARD 'O'-0x40
> > +#endif
> 
> Just change everybody to do the same, nobody cares about VDISCARD.
> 
> We can change the value of VDISCARD because it doesn't actually have
> anything connected to it, so don't worry about "we used to have odd
> different values for it".

Point...  The following added and pushed:

commit 96202dddde4673cfd686b9812e5ab0790f907cd0
Author: Al Viro <viro@zeniv.linux.org.uk>
Date:   Mon Sep 10 10:42:59 2018 -0400

    ... and switch alpha/ppc/sparc to ^O for discard
    
    it's
            1) common for all other architectures
            2) historical default for that thing and
            3) ignored by the tty layer anyway.
    
    Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

diff --git a/arch/alpha/include/asm/termios_internal.h b/arch/alpha/include/asm/termios_internal.h
index 07d5c1a6cdf6..c73cc96f96a3 100644
--- a/arch/alpha/include/asm/termios_internal.h
+++ b/arch/alpha/include/asm/termios_internal.h
@@ -2,8 +2,6 @@
 #ifndef _ALPHA_TERMIOS_H
 #define _ALPHA_TERMIOS_H
 
-#define INIT_C_CC_VDISCARD 'U'-0x40
-
 /*
  * Translate a "termio" structure into a "termios". Ugh.
  */
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index b1402b1f1685..db0b6eebbfa5 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -223,7 +223,6 @@ config PPC
 	select HAVE_VIRT_CPU_ACCOUNTING
 	select HAVE_IRQ_TIME_ACCOUNTING
 	select HAVE_RSEQ
-	select HAS_TERMIOS_INTERNAL
 	select IOMMU_HELPER			if PPC64
 	select IRQ_DOMAIN
 	select IRQ_FORCED_THREADING
diff --git a/arch/powerpc/include/asm/termios_internal.h b/arch/powerpc/include/asm/termios_internal.h
deleted file mode 100644
index 116b138ea232..000000000000
--- a/arch/powerpc/include/asm/termios_internal.h
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * Liberally adapted from alpha/termios.h.  In particular, the c_cc[]
- * fields have been reordered so that termio & termios share the
- * common subset in the same order (for brain dead programs that don't
- * know or care about the differences).
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version
- * 2 of the License, or (at your option) any later version.
- */
-#ifndef _ASM_POWERPC_TERMIOS_H
-#define _ASM_POWERPC_TERMIOS_H
-
-#define INIT_C_CC_VDISCARD 'U'-0x40
-
-#endif	/* _ASM_POWERPC_TERMIOS_H */
diff --git a/arch/sparc/include/asm/termios_internal.h b/arch/sparc/include/asm/termios_internal.h
index 1649a0cecda9..9d14a4bc40cf 100644
--- a/arch/sparc/include/asm/termios_internal.h
+++ b/arch/sparc/include/asm/termios_internal.h
@@ -13,8 +13,6 @@
 #define _VMIN	4
 #define _VTIME	5
 
-#define INIT_C_CC_VDISCARD 'U'-0x40
-
 /*
  * Translate a "termios" structure into a "termio". Ugh.
  *
diff --git a/include/linux/termios_internal.h b/include/linux/termios_internal.h
index 549715b18d22..f0bc26812548 100644
--- a/include/linux/termios_internal.h
+++ b/include/linux/termios_internal.h
@@ -11,14 +11,9 @@
 /*	intr=^C		quit=^\		erase=del	kill=^U
 	eof=^D		vtime=\0	vmin=\1		sxtc=\0
 	start=^Q	stop=^S		susp=^Z		eol=\0
-	reprint=^R	discard=^U	werase=^W	lnext=^V
+	reprint=^R	discard=^O	werase=^W	lnext=^V
 	eol2=\0
-	... except that discard is actually ^O on most of them.
 */
-#ifndef INIT_C_CC_VDISCARD
-#define INIT_C_CC_VDISCARD 'O'-0x40
-#endif
-
 #ifdef VDSUSP
 #define INIT_C_CC_VDSUSP_EXTRA [VDSUSP] = 'Y'-0x40,
 #else
@@ -36,7 +31,7 @@
 	[VSTOP] = 'S'-0x40,	\
 	[VSUSP] = 'Z'-0x40,	\
 	[VREPRINT] = 'R'-0x40,	\
-	[VDISCARD] = INIT_C_CC_VDISCARD,	\
+	[VDISCARD] = 'O'-0x40,	\
 	[VWERASE] = 'W'-0x40,	\
 	[VLNEXT] = 'V'-0x40,	\
 	INIT_C_CC_VDSUSP_EXTRA	\

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

* Re: [RFC][PATCHES] termios.h cleanups
  2022-08-20 21:44     ` Linus Torvalds
@ 2022-08-21  0:30       ` Al Viro
  0 siblings, 0 replies; 17+ messages in thread
From: Al Viro @ 2022-08-21  0:30 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-arch, linux-kernel, Greg Kroah-Hartman

On Sat, Aug 20, 2022 at 02:44:09PM -0700, Linus Torvalds wrote:
> On Sat, Aug 20, 2022 at 11:44 AM Al Viro <viro@zeniv.linux.org.uk> wrote:
> >
> >         Umm...  Might as well, I guess...  Where to put those, though?
> > drivers/tty/tty_ioctl.c is not an option, unfortunately - it'll pick
> > the local definitions, __weak or no __weak.
> 
> IThat bug is ancient history, and tty_ioctl.c is just fine.
> 
> Yes, we used to have the "you can't have __weak function definitions
> in the same file that uses them" rule.
> 
> But it was due to a bug in gcc-4.1, which would inline weak functions.
> 
> But we long since gave up on gcc-4.1, and we have __weak functions
> declarations in the same file as the use in multiple places. See for
> example arch_release_task_struct() in kernel/fork.c.

OK, that allows to reorder the whole thing better...  See #work.termios2
(very lightly tested)

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

* Re: [RFC][PATCHES] termios.h cleanups
  2022-08-20 18:43   ` Al Viro
@ 2022-08-20 21:44     ` Linus Torvalds
  2022-08-21  0:30       ` Al Viro
  0 siblings, 1 reply; 17+ messages in thread
From: Linus Torvalds @ 2022-08-20 21:44 UTC (permalink / raw)
  To: Al Viro; +Cc: linux-arch, linux-kernel, Greg Kroah-Hartman

On Sat, Aug 20, 2022 at 11:44 AM Al Viro <viro@zeniv.linux.org.uk> wrote:
>
>         Umm...  Might as well, I guess...  Where to put those, though?
> drivers/tty/tty_ioctl.c is not an option, unfortunately - it'll pick
> the local definitions, __weak or no __weak.

IThat bug is ancient history, and tty_ioctl.c is just fine.

Yes, we used to have the "you can't have __weak function definitions
in the same file that uses them" rule.

But it was due to a bug in gcc-4.1, which would inline weak functions.

But we long since gave up on gcc-4.1, and we have __weak functions
declarations in the same file as the use in multiple places. See for
example arch_release_task_struct() in kernel/fork.c.

                 Linus

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

* Re: [RFC][PATCHES] termios.h cleanups
  2022-08-20 18:14 ` Linus Torvalds
@ 2022-08-20 18:43   ` Al Viro
  2022-08-20 21:44     ` Linus Torvalds
  0 siblings, 1 reply; 17+ messages in thread
From: Al Viro @ 2022-08-20 18:43 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-arch, linux-kernel, Greg Kroah-Hartman

On Sat, Aug 20, 2022 at 11:14:19AM -0700, Linus Torvalds wrote:
> On Fri, Aug 19, 2022 at 8:34 PM Al Viro <viro@zeniv.linux.org.uk> wrote:
> >
> > It takes the helpers and INIT_C_CC into new header (termios-internal.h),
> > with defaults being in linux/termios-internal.h, unless an arch-specific
> > variant is provided in asm/termios-internal.h (only alpha and sparc end
> > up needing that).  Files that need that stuff (all 4 of them) include
> > linux/termios-internal.h.
> 
> I don't see anything obviously wrong here, and my main reaction is
> actually that I wish this went a bit further, and moved the whole
> kernel_termios_to_user_termios stuff into C code rather than having
> them in headers.
> 
> I don't think it's really worth inlining those things, and I wonder if
> we could just have the default "just copy directly to/from user space"
> as __weak functions, and then allow sparc and alpha to override them?

	Umm...  Might as well, I guess...  Where to put those, though?
drivers/tty/tty_ioctl.c is not an option, unfortunately - it'll pick
the local definitions, __weak or no __weak.  drivers/tty/termios.c
just for those?  Looks just as convoluted as having those as inlines...

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

* Re: [RFC][PATCHES] termios.h cleanups
  2022-08-20  3:33 [RFC][PATCHES] termios.h cleanups Al Viro
@ 2022-08-20 18:14 ` Linus Torvalds
  2022-08-20 18:43   ` Al Viro
  0 siblings, 1 reply; 17+ messages in thread
From: Linus Torvalds @ 2022-08-20 18:14 UTC (permalink / raw)
  To: Al Viro; +Cc: linux-arch, linux-kernel, Greg Kroah-Hartman

On Fri, Aug 19, 2022 at 8:34 PM Al Viro <viro@zeniv.linux.org.uk> wrote:
>
> It takes the helpers and INIT_C_CC into new header (termios-internal.h),
> with defaults being in linux/termios-internal.h, unless an arch-specific
> variant is provided in asm/termios-internal.h (only alpha and sparc end
> up needing that).  Files that need that stuff (all 4 of them) include
> linux/termios-internal.h.

I don't see anything obviously wrong here, and my main reaction is
actually that I wish this went a bit further, and moved the whole
kernel_termios_to_user_termios stuff into C code rather than having
them in headers.

I don't think it's really worth inlining those things, and I wonder if
we could just have the default "just copy directly to/from user space"
as __weak functions, and then allow sparc and alpha to override them?

              Linus

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

* [RFC][PATCHES] termios.h cleanups
@ 2022-08-20  3:33 Al Viro
  2022-08-20 18:14 ` Linus Torvalds
  0 siblings, 1 reply; 17+ messages in thread
From: Al Viro @ 2022-08-20  3:33 UTC (permalink / raw)
  To: linux-arch; +Cc: Linus Torvalds, linux-kernel, Greg Kroah-Hartman

[resurrecting a patchset from back in 2018]

        asm/termios.h has tons of duplication and rather convoluted
logics re includes.

	asm/termios.h has both UAPI and internal variants.  On seven
architectures (alpha, ia64, mips, parisc, powerpc, s390, sparc)
both variants exist and internal one pulls the UAPI one by #include
<uapi/asm/termios.h>.  That is done very early in the internal header.
Everything else has neither UAPI nor internal termios.h.  Due to
mandatory-y += termios.h
in include/uapi/asm-generic/Kbuild they get generated/uapi/asm/termios.h
that consists of #include <asm-generic/termios.h>, which resolves to
include/asm-generic/termios.h.  That header serves as default internal
asm/termios.h and it contains
#include <uapi/asm-generic/termios.h>, resolving to
include/uapi/asm-generic/termios.h - default UAPI asm/termios.h.  As with
other internal asm/termios.h instances, that include happens very early
in the file.

On loongarch there's a generated/asm/termios.h with the contents identical
to what's in generated/uapi/asm/termios.h.  Completely pointless, but it's
hard to blame the loongarch folks here - the situation's much too confusing...

	Besides the include of UAPI asm/termios.h, non-UAPI ones contain
the following:
        * definition of INIT_C_CC
        * definitions of conversion helpers:
                user_termio_to_kernel_termios(),
                kernel_termios_to_user_termio(),
                user_termios_to_kernel_termios(),
                kernel_termios_to_user_termios()
        * (possibly) definitions of more conversion helpers:
                user_termios_to_kernel_termios_1(),
                kernel_termios_to_user_termios_1()
        * (possibly) include of linux/uaccess.h [generic, mips, powerpc, s390]
        * (possibly) include of linux/string.h [mips only]

        The thing is, conversion headers are used only in one file -
drivers/tty/tty_ioctl.c.  INIT_C_CC has more users - all three of them:
drivers/tty/hvc/hvcs.c, drivers/tty/tty_io.c and drivers/tty/vcc.c.
All other users of termios.h (and there's quite a few of them, in
particular due include in linux/tty.h) actually want the UAPI variant and,
perhaps, indirect include of uaccess.h and/or string.h.

        Helpers in question are heavily shared; there is an attempt
to put them into a common header (termios-base.h), but not all
instances use it.  Another unpleasant thing is that said helpers
tend to be macros, with very little typechecking.

	Patchset attempts to untangle that mess.

It takes the helpers and INIT_C_CC into new header (termios-internal.h),
with defaults being in linux/termios-internal.h, unless an arch-specific
variant is provided in asm/termios-internal.h (only alpha and sparc end
up needing that).  Files that need that stuff (all 4 of them) include
linux/termios-internal.h.

asm/termios.h and linux/termios.h become UAPI-only after that.

This stuff lives in
git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs.git work.termios

Individual patches in followups.  Please, review; if nobody yells,
this will go into -next.

Shortlog:
Al Viro (7):
      loongarch: remove generic-y += termios.h
      termios: get rid of stray asm/termios.h include in n_hdlc.c
      start unifying INIT_C_CC and termios convertors
      termios: consolidate values for VDISCARD in INIT_C_CC
      make generic INIT_C_CC a bit more generic
      termios: convert the last (sparc) INIT_C_CC to array
      termios: get rid of non-UAPI asm/termios.h

Diffstat:
 arch/Kconfig                              |   3 +
 arch/alpha/Kconfig                        |   1 +
 arch/alpha/include/asm/termios-internal.h |  70 ++++++++++++++
 arch/alpha/include/asm/termios.h          |  87 ------------------
 arch/arm/mach-ep93xx/core.c               |   1 +
 arch/arm/mach-versatile/integrator_ap.c   |   1 +
 arch/ia64/include/asm/termios.h           |  58 ------------
 arch/loongarch/include/asm/Kbuild         |   1 -
 arch/mips/include/asm/termios.h           | 105 ---------------------
 arch/parisc/include/asm/termios.h         |  52 -----------
 arch/powerpc/include/asm/termios.h        |  18 ----
 arch/s390/include/asm/termios.h           |  26 ------
 arch/sparc/Kconfig                        |   1 +
 arch/sparc/include/asm/termios-internal.h | 132 +++++++++++++++++++++++++++
 arch/sparc/include/asm/termios.h          | 147 ------------------------------
 drivers/net/wwan/wwan_core.c              |   1 +
 drivers/tty/hvc/hvcs.c                    |   1 +
 drivers/tty/n_hdlc.c                      |   1 -
 drivers/tty/tty_io.c                      |   2 +-
 drivers/tty/tty_ioctl.c                   |   1 +
 drivers/tty/vcc.c                         |   1 +
 include/asm-generic/termios-base.h        |  78 ----------------
 include/asm-generic/termios.h             | 108 ----------------------
 include/linux/serdev.h                    |   1 +
 include/linux/termios_internal.h          | 131 ++++++++++++++++++++++++++
 include/linux/tty_driver.h                |   1 +
 26 files changed, 347 insertions(+), 682 deletions(-)


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

end of thread, other threads:[~2022-08-21  0:31 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-10  4:49 [RFC][PATCHES] termios.h cleanups Al Viro
2018-09-10  4:52 ` [RFC][PATCH 1/8] start unifying termios convertors Al Viro
2018-09-10  4:52   ` [RFC][PATCH 2/8] move user_termio_to_kernel_termios/kernel_termios_to_user_termio Al Viro
2018-09-10  4:52   ` [RFC][PATCH 3/8] remove termios-base.h Al Viro
2018-09-10  4:52   ` [RFC][PATCH 4/8] make users of INIT_C_CC pull linux/termios_internal.h Al Viro
2018-09-10  4:52   ` [RFC][PATCH 5/8] make generic INIT_C_CC a bit more generic Al Viro
2018-09-10  4:52   ` [RFC][PATCH 6/8] untangle asm/termios.h mess Al Viro
2018-09-10  4:52   ` [RFC][PATCH 7/8] switch x86 to generic uapi asm/termios.h Al Viro
2018-09-10  4:52   ` [RFC][PATCH 8/8] really consolidate INIT_C_CC definitions Al Viro
2018-09-10 13:33     ` Linus Torvalds
2018-09-10 14:45       ` Al Viro
2018-09-10  8:32 ` [RFC][PATCH 1/8] start unifying termios convertors David Howells
2022-08-20  3:33 [RFC][PATCHES] termios.h cleanups Al Viro
2022-08-20 18:14 ` Linus Torvalds
2022-08-20 18:43   ` Al Viro
2022-08-20 21:44     ` Linus Torvalds
2022-08-21  0:30       ` Al Viro

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.