All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC][PATCHES] termios.h cleanups
@ 2022-08-20  3:33 Al Viro
  2022-08-20  3:37 ` [PATCH 1/7] loongarch: remove generic-y += termios.h Al Viro
  2022-08-20 18:14 ` [RFC][PATCHES] termios.h cleanups Linus Torvalds
  0 siblings, 2 replies; 36+ 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] 36+ messages in thread
* [RFC][PATCHES] termios.h cleanups
@ 2018-09-10  4:49 Al Viro
  0 siblings, 0 replies; 36+ 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] 36+ messages in thread

end of thread, other threads:[~2022-09-09  8:46 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-20  3:33 [RFC][PATCHES] termios.h cleanups Al Viro
2022-08-20  3:37 ` [PATCH 1/7] loongarch: remove generic-y += termios.h Al Viro
2022-08-20  3:37   ` [PATCH 2/7] termios: get rid of stray asm/termios.h include in n_hdlc.c Al Viro
2022-08-20  3:37   ` [PATCH 3/7] start unifying INIT_C_CC and termios convertors Al Viro
2022-08-20  3:37   ` [PATCH 4/7] termios: consolidate values for VDISCARD in INIT_C_CC Al Viro
2022-08-20 18:01     ` Linus Torvalds
2022-08-20 18:27       ` Al Viro
2022-08-20  3:37   ` [PATCH 5/7] make generic INIT_C_CC a bit more generic Al Viro
2022-08-20  3:37   ` [PATCH 6/7] termios: convert the last (sparc) INIT_C_CC to array Al Viro
2022-08-20  3:37   ` [PATCH 7/7] termios: get rid of non-UAPI asm/termios.h Al Viro
2022-08-20 18:14 ` [RFC][PATCHES] termios.h cleanups Linus Torvalds
2022-08-20 18:43   ` Al Viro
2022-08-20 21:44     ` Linus Torvalds
2022-08-21  0:30       ` Al Viro
2022-08-21  1:02         ` [PATCH v2 1/8] loongarch: remove generic-y += termios.h Al Viro
2022-08-21  1:02           ` [PATCH v2 2/8] termios: get rid of stray asm/termios.h include in n_hdlc.c Al Viro
2022-08-21  1:02           ` [PATCH v2 3/8] termios: uninline conversion helpers Al Viro
2022-08-30 12:26             ` Greg Kroah-Hartman
2022-09-01 17:03               ` Al Viro
2022-09-01 17:06                 ` [PATCH v3 1/6] " Al Viro
2022-09-01 17:06                 ` [PATCH v3 2/6] termios: start unifying non-UAPI parts of asm/termios.h Al Viro
2022-09-01 17:07                 ` [PATCH v3 3/6] termios: consolidate values for VDISCARD in INIT_C_CC Al Viro
2022-09-01 17:07                 ` [PATCH v3 4/6] make generic INIT_C_CC a bit more generic Al Viro
2022-09-01 17:08                 ` [PATCH v3 5/6] termios: convert the last (sparc) INIT_C_CC to array Al Viro
2022-09-01 17:08                 ` [PATCH v3 6/6] termios: get rid of non-UAPI asm/termios.h Al Viro
2022-09-02  5:32                   ` [PATCH v3 7/6] termios: kill uapi termios.h that are identical to generic one Al Viro
2022-09-09  8:45                 ` [PATCH v2 3/8] termios: uninline conversion helpers Greg Kroah-Hartman
2022-08-21  1:02           ` [PATCH v2 4/8] termios: start unifying non-UAPI parts of asm/termios.h Al Viro
2022-08-21  5:13             ` Al Viro
2022-08-21  1:02           ` [PATCH v2 5/8] termios: consolidate values for VDISCARD in INIT_C_CC Al Viro
2022-08-21  1:02           ` [PATCH v2 6/8] make generic INIT_C_CC a bit more generic Al Viro
2022-08-21  1:02           ` [PATCH v2 7/8] termios: convert the last (sparc) INIT_C_CC to array Al Viro
2022-08-21  1:02           ` [PATCH v2 8/8] termios: get rid of non-UAPI asm/termios.h Al Viro
2022-08-21 14:56           ` [PATCH v2 1/8] loongarch: remove generic-y += termios.h Huacai Chen
2022-08-21 14:58             ` Huacai Chen
  -- strict thread matches above, loose matches on Subject: below --
2018-09-10  4:49 [RFC][PATCHES] termios.h cleanups 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.