[00/28] More Linux syscall refactor

Message ID 20201118195552.2687336-1-adhemerval.zanella@linaro.org
Headers
Series More Linux syscall refactor |

Message

Adhemerval Zanella Nov. 18, 2020, 7:55 p.m. UTC
  This is second part of Linux syscall refactor (the first one [1] focused
on simplify the internal mechanism).  Although this patchset is
independent from first part, some code do intersect (such the ones that
might use the syscall return value), however they are easily fixed
whether one is pushed first.

This part remove ununsed code, consolidate implementation, simplify the
auto-generation syscall list, move some auto-generation to C, and move
some assembly implementation to C.

The idea is to 1. remove implementations from auto-generation which
require either arch-specific knowledge or can't be implemented easily
on C (such as 64-bit variable on 32-bit architecture) and 2. minimize the
assembly implementation that issues syscalls to a bare minimum (only the
ones that are not easily implemented in C, such as clone or vfork).

The long goal with this refactor is to replace the auto-generation
using assembly macros to a auto-generation using C code, thus removing
the requirement of each architecture to provide the ASM assembly macros
(all syscall will be done through proper inline functions).  The
subsequent part to implement it relies on this patchset and the previous
one [1].

[1] https://sourceware.org/pipermail/libc-alpha/2020-November/119456.html

Adhemerval Zanella (28):
  Remove generic pthread linuxism on POSIX timer_routine
  Removed ununsed pthread implementations
  Remove local-setxid.h
  Remove HAVE_INLINED_SYSCALLS usage on generic implementations
  linux: Consolidate and cleanup personality syscall
  x32: Remove syscalls.list
  linux: Assume bind support
  linux: Assume getpeername support
  linux: Assume getsockname support
  linux: Assume getsockopt support
  linux: Assume listen support
  linux: Assume setsockopt support
  linux: Assume shutdown support
  linux: Assume socket support
  linux: Assume socketpair support
  linux: Remove superflous __ASSUME_CONNECT_SYSCALL definitions
  x86_64: Remove ununsed syscalls.list entry
  nptl: Add futex_trylock_pi
  linux: Add fanotify_mark C implementation
  linux: Add prlimit64 C implementation
  linux: Implement mremap in C
  Linux: implement ioctl in C
  mips: Implement n32 lseek64 in C
  x32: Implement lseek64 in C
  linux: Implement pipe in terms of __NR_pipe2
  linux: Consolidate brk implementation
  linux: Add generic C syscall implementation
  alpha: Move implementations to C

 debug/read_chk.c                              |   9 --
 debug/readlink_chk.c                          |   5 -
 nptl/Makefile                                 |   4 -
 nptl/pthread_mutex_trylock.c                  |   9 +-
 nptl/pthread_setegid.c                        |   3 -
 nptl/pthread_seteuid.c                        |   3 -
 nptl/pthread_setgid.c                         |   3 -
 nptl/pthread_setregid.c                       |   3 -
 nptl/pthread_setresgid.c                      |   3 -
 nptl/pthread_setresuid.c                      |   3 -
 nptl/pthread_setreuid.c                       |   3 -
 nptl/pthread_setuid.c                         |   3 -
 sysdeps/generic/local-setxid.h                |   4 -
 sysdeps/nptl/futex-internal.h                 |  36 ++++++
 sysdeps/nptl/lowlevellock-futex.h             |   5 +
 sysdeps/posix/spawni.c                        |   5 +-
 sysdeps/pthread/timer_routines.c              |  19 ----
 sysdeps/unix/syscalls.list                    |   2 -
 sysdeps/unix/sysv/linux/Makefile              |   4 +-
 sysdeps/unix/sysv/linux/aarch64/sysdep.h      |   3 +
 sysdeps/unix/sysv/linux/alpha/brk.S           |  83 --------------
 sysdeps/unix/sysv/linux/{arm => alpha}/brk.c  |  13 +--
 sysdeps/unix/sysv/linux/alpha/dl-brk.S        |   1 -
 .../alpha/{fraiseexcpt.S => fraiseexcpt.c}    |  37 ++-----
 .../sysv/linux/alpha/{getegid.S => getegid.c} |  15 +--
 .../sysv/linux/alpha/{geteuid.S => geteuid.c} |  15 +--
 .../sysv/linux/alpha/{getppid.S => getppid.c} |  15 +--
 .../sysv/linux/alpha/ieee_get_fp_control.S    |  50 ---------
 .../linux/alpha/ieee_get_fp_control.c}        |  29 ++---
 .../sysv/linux/alpha/ieee_set_fp_control.S    |  46 --------
 .../linux/alpha/ieee_set_fp_control.c}        |  24 ++--
 sysdeps/unix/sysv/linux/alpha/pipe.S          |   1 -
 .../alpha/{setcontext.S => setcontext.c}      |  27 ++---
 sysdeps/unix/sysv/linux/alpha/syscalls.list   |  11 --
 sysdeps/unix/sysv/linux/alpha/sysdep.h        |  21 ++++
 sysdeps/unix/sysv/linux/arc/sysdep.h          |   3 +
 sysdeps/unix/sysv/linux/arm/syscalls.list     |  17 ---
 .../unix/sysv/linux/{microblaze => }/brk.c    |   5 +-
 sysdeps/unix/sysv/linux/csky/sysdep.h         |   3 +
 sysdeps/unix/sysv/linux/dl-brk.c              |   5 -
 .../sysv/linux/{sh/pipe.S => fanotify_mark.c} |  42 +++----
 sysdeps/unix/sysv/linux/generic/brk.c         |  43 --------
 sysdeps/unix/sysv/linux/generic/syscalls.list |  12 --
 .../linux/generic/wordsize-32/syscalls.list   |   5 -
 sysdeps/unix/sysv/linux/hppa/brk.c            |  41 -------
 sysdeps/unix/sysv/linux/hppa/fanotify_mark.c  |   2 +
 sysdeps/unix/sysv/linux/hppa/prlimit64.c      |   2 +
 sysdeps/unix/sysv/linux/hppa/syscall.c        |  65 -----------
 sysdeps/unix/sysv/linux/hppa/syscalls.list    |  16 ---
 sysdeps/unix/sysv/linux/i386/brk.c            |  45 --------
 .../unix/sysv/linux/i386/kernel-features.h    |  23 ++--
 sysdeps/unix/sysv/linux/i386/syscalls.list    |   6 -
 sysdeps/unix/sysv/linux/i386/sysdep.h         |   3 +
 sysdeps/unix/sysv/linux/ia64/brk.S            |  50 ---------
 sysdeps/unix/sysv/linux/ia64/dl-brk.S         |   1 -
 sysdeps/unix/sysv/linux/ia64/pipe.S           |  37 -------
 sysdeps/unix/sysv/linux/ia64/syscalls.list    |  11 --
 sysdeps/unix/sysv/linux/ia64/sysdep.h         |   3 +
 .../unix/sysv/linux/{x86_64/brk.c => ioctl.c} |  31 +++---
 sysdeps/unix/sysv/linux/kernel-features.h     |   9 ++
 sysdeps/unix/sysv/linux/local-setxid.h        |  16 ---
 .../unix/sysv/linux/m68k/kernel-features.h    |  23 ++--
 sysdeps/unix/sysv/linux/m68k/syscalls.list    |   3 -
 sysdeps/unix/sysv/linux/m68k/sysdep.h         |   3 +
 .../sysv/linux/microblaze/kernel-features.h   |  10 --
 .../unix/sysv/linux/microblaze/syscalls.list  |   4 -
 sysdeps/unix/sysv/linux/microblaze/sysdep.h   |   3 +
 sysdeps/unix/sysv/linux/mips/brk.c            |  46 --------
 .../unix/sysv/linux/mips/mips32/syscalls.list |   5 -
 sysdeps/unix/sysv/linux/mips/mips32/sysdep.h  |   3 +
 .../unix/sysv/linux/mips/mips64/n32/lseek64.c |  47 ++++++++
 .../sysv/linux/mips/mips64/n32/syscalls.list  |  11 --
 .../sysv/linux/mips/mips64/n64/syscalls.list  |   4 -
 sysdeps/unix/sysv/linux/mips/mips64/sysdep.h  |   3 +
 sysdeps/unix/sysv/linux/mips/pipe.S           |   1 -
 sysdeps/unix/sysv/linux/mips/syscalls.list    |  14 ---
 .../unix/sysv/linux/{sh/brk.c => mremap.c}    |  40 +++----
 sysdeps/unix/sysv/linux/nios2/sysdep.h        |   3 +
 sysdeps/unix/sysv/linux/personality.c         |  24 +---
 sysdeps/unix/sysv/linux/{generic => }/pipe.c  |   6 +-
 sysdeps/unix/sysv/linux/powerpc/dl-brk.S      |   1 -
 .../unix/sysv/linux/powerpc/kernel-features.h |  10 --
 .../linux/powerpc/powerpc32/syscalls.list     |   3 -
 .../unix/sysv/linux/powerpc/powerpc64/brk.S   |  43 --------
 sysdeps/unix/sysv/linux/prlimit.c             |   2 +
 .../{powerpc/powerpc32/brk.S => prlimit64.c}  |  51 ++++-----
 sysdeps/unix/sysv/linux/riscv/sysdep.h        |   3 +
 sysdeps/unix/sysv/linux/s390/brk.c            |  55 ---------
 .../unix/sysv/linux/s390/kernel-features.h    |  22 ++--
 .../sysv/linux/s390/s390-32/syscalls.list     |   4 -
 sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h |   5 +
 sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h |   5 +
 sysdeps/unix/sysv/linux/sh/fanotify_mark.c    |   2 +
 sysdeps/unix/sysv/linux/sh/kernel-features.h  |  10 --
 sysdeps/unix/sysv/linux/sh/syscalls.list      |   6 -
 .../unix/sysv/linux/sparc/kernel-features.h   |  17 ++-
 sysdeps/unix/sysv/linux/sparc/sparc32/brk.c   |  54 ---------
 sysdeps/unix/sysv/linux/sparc/sparc32/pipe.S  |  39 -------
 .../sysv/linux/sparc/sparc32/syscalls.list    |   3 -
 .../unix/sysv/linux/sparc/sparc32/sysdep.h    |   3 +
 sysdeps/unix/sysv/linux/sparc/sparc64/brk.S   | 104 ------------------
 .../unix/sysv/linux/sparc/sparc64/dl-brk.S    |   1 -
 .../sysv/linux/sparc/sparc64/personality.c    |   3 -
 sysdeps/unix/sysv/linux/sparc/sparc64/pipe.S  |  40 -------
 .../sysv/linux/sparc/sparc64/syscalls.list    |   7 --
 sysdeps/unix/sysv/linux/spawni.c              |  19 +++-
 sysdeps/unix/sysv/linux/{riscv => }/syscall.c |  33 +++---
 sysdeps/unix/sysv/linux/syscalls.list         |   2 -
 sysdeps/unix/sysv/linux/sysdep.h              |   4 +
 .../unix/sysv/linux/wordsize-64/syscalls.list |   4 -
 sysdeps/unix/sysv/linux/x86_64/syscalls.list  |  13 ---
 sysdeps/unix/sysv/linux/x86_64/x32/lseek.S    |  43 --------
 sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S  |   1 -
 .../{m68k/brk.c => x86_64/x32/lseek64.c}      |  44 ++++----
 .../unix/sysv/linux/x86_64/x32/syscalls.list  |   4 -
 115 files changed, 429 insertions(+), 1497 deletions(-)
 delete mode 100644 nptl/pthread_setegid.c
 delete mode 100644 nptl/pthread_seteuid.c
 delete mode 100644 nptl/pthread_setgid.c
 delete mode 100644 nptl/pthread_setregid.c
 delete mode 100644 nptl/pthread_setresgid.c
 delete mode 100644 nptl/pthread_setresuid.c
 delete mode 100644 nptl/pthread_setreuid.c
 delete mode 100644 nptl/pthread_setuid.c
 delete mode 100644 sysdeps/generic/local-setxid.h
 delete mode 100644 sysdeps/unix/sysv/linux/alpha/brk.S
 rename sysdeps/unix/sysv/linux/{arm => alpha}/brk.c (77%)
 delete mode 100644 sysdeps/unix/sysv/linux/alpha/dl-brk.S
 rename sysdeps/unix/sysv/linux/alpha/{fraiseexcpt.S => fraiseexcpt.c} (66%)
 rename sysdeps/unix/sysv/linux/alpha/{getegid.S => getegid.c} (79%)
 rename sysdeps/unix/sysv/linux/alpha/{geteuid.S => geteuid.c} (79%)
 rename sysdeps/unix/sysv/linux/alpha/{getppid.S => getppid.c} (79%)
 delete mode 100644 sysdeps/unix/sysv/linux/alpha/ieee_get_fp_control.S
 rename sysdeps/unix/{mips/pipe.S => sysv/linux/alpha/ieee_get_fp_control.c} (64%)
 delete mode 100644 sysdeps/unix/sysv/linux/alpha/ieee_set_fp_control.S
 rename sysdeps/unix/{alpha/pipe.S => sysv/linux/alpha/ieee_set_fp_control.c} (68%)
 delete mode 100644 sysdeps/unix/sysv/linux/alpha/pipe.S
 rename sysdeps/unix/sysv/linux/alpha/{setcontext.S => setcontext.c} (62%)
 rename sysdeps/unix/sysv/linux/{microblaze => }/brk.c (90%)
 delete mode 100644 sysdeps/unix/sysv/linux/dl-brk.c
 rename sysdeps/unix/sysv/linux/{sh/pipe.S => fanotify_mark.c} (56%)
 delete mode 100644 sysdeps/unix/sysv/linux/generic/brk.c
 delete mode 100644 sysdeps/unix/sysv/linux/generic/syscalls.list
 delete mode 100644 sysdeps/unix/sysv/linux/generic/wordsize-32/syscalls.list
 delete mode 100644 sysdeps/unix/sysv/linux/hppa/brk.c
 create mode 100644 sysdeps/unix/sysv/linux/hppa/fanotify_mark.c
 create mode 100644 sysdeps/unix/sysv/linux/hppa/prlimit64.c
 delete mode 100644 sysdeps/unix/sysv/linux/hppa/syscall.c
 delete mode 100644 sysdeps/unix/sysv/linux/hppa/syscalls.list
 delete mode 100644 sysdeps/unix/sysv/linux/i386/brk.c
 delete mode 100644 sysdeps/unix/sysv/linux/ia64/brk.S
 delete mode 100644 sysdeps/unix/sysv/linux/ia64/dl-brk.S
 delete mode 100644 sysdeps/unix/sysv/linux/ia64/pipe.S
 rename sysdeps/unix/sysv/linux/{x86_64/brk.c => ioctl.c} (63%)
 delete mode 100644 sysdeps/unix/sysv/linux/local-setxid.h
 delete mode 100644 sysdeps/unix/sysv/linux/mips/brk.c
 delete mode 100644 sysdeps/unix/sysv/linux/mips/mips32/syscalls.list
 create mode 100644 sysdeps/unix/sysv/linux/mips/mips64/n32/lseek64.c
 delete mode 100644 sysdeps/unix/sysv/linux/mips/mips64/n32/syscalls.list
 delete mode 100644 sysdeps/unix/sysv/linux/mips/pipe.S
 rename sysdeps/unix/sysv/linux/{sh/brk.c => mremap.c} (57%)
 rename sysdeps/unix/sysv/linux/{generic => }/pipe.c (86%)
 delete mode 100644 sysdeps/unix/sysv/linux/powerpc/dl-brk.S
 delete mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc64/brk.S
 rename sysdeps/unix/sysv/linux/{powerpc/powerpc32/brk.S => prlimit64.c} (54%)
 delete mode 100644 sysdeps/unix/sysv/linux/s390/brk.c
 create mode 100644 sysdeps/unix/sysv/linux/sh/fanotify_mark.c
 delete mode 100644 sysdeps/unix/sysv/linux/sparc/sparc32/brk.c
 delete mode 100644 sysdeps/unix/sysv/linux/sparc/sparc32/pipe.S
 delete mode 100644 sysdeps/unix/sysv/linux/sparc/sparc64/brk.S
 delete mode 100644 sysdeps/unix/sysv/linux/sparc/sparc64/dl-brk.S
 delete mode 100644 sysdeps/unix/sysv/linux/sparc/sparc64/personality.c
 delete mode 100644 sysdeps/unix/sysv/linux/sparc/sparc64/pipe.S
 delete mode 100644 sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list
 rename sysdeps/unix/sysv/linux/{riscv => }/syscall.c (53%)
 delete mode 100644 sysdeps/unix/sysv/linux/x86_64/x32/lseek.S
 delete mode 100644 sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S
 rename sysdeps/unix/sysv/linux/{m68k/brk.c => x86_64/x32/lseek64.c} (51%)
 delete mode 100644 sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list
  

Comments

Joseph Myers Nov. 18, 2020, 9:06 p.m. UTC | #1
This series introduces assumptions that various socket syscalls are 
available.  That's not valid until the minimum Linux kernel version has 
been increased to at least 4.4 (depending on the architecture, but 
probably such a change would be done globally).  In the case of 
getpeername and getsockname, at least, it's not safe (for 32-bit SPARC 
under 64-bit kernels) until Linux 4.20 - in general, before assuming a 
syscall to be present after any increase of the minimum Linux kernel 
version, it's important to review the actual state of support for that 
syscall in the minimum kernel version, including in compat syscall tables.

As I previously noted 
<https://sourceware.org/pipermail/libc-alpha/2020-July/116453.html>, I 
think we ought to implement Carlos's proposal of removing the runtime 
check for old kernel versions before increasing the minimum kernel 
version, given that an increased version allows very little cleanup for 
e.g. x86_64.

I also think that, when assuming presence of a syscall reduces the C 
implementation of a socket function to just calling a single syscall 
unconditionally, having one line for that function in a single 
syscalls.list file is better than having a manually-maintained C 
implementation.
  
Adhemerval Zanella Nov. 19, 2020, 12:21 p.m. UTC | #2
On 18/11/2020 18:06, Joseph Myers wrote:
> This series introduces assumptions that various socket syscalls are 
> available.  That's not valid until the minimum Linux kernel version has 
> been increased to at least 4.4 (depending on the architecture, but 
> probably such a change would be done globally).  In the case of 
> getpeername and getsockname, at least, it's not safe (for 32-bit SPARC 
> under 64-bit kernels) until Linux 4.20 - in general, before assuming a 
> syscall to be present after any increase of the minimum Linux kernel 
> version, it's important to review the actual state of support for that 
> syscall in the minimum kernel version, including in compat syscall tables.

The idea of this socket changes is to align with default Linux kernel ABI,
to make the outliers to explicit disable the syscall support where 
applicable and simplify the relation netweenn the syscalls.list and the 
required C implementations.

The 'bind', for instance, is not listed on sysdeps/unix/sysv/linux/syscalls.list,
so ports that do not imply on 'generic' will need to explicit disable on
the kernel-features.h.  Another idea of this change it to eventually
remove the sysdeps/unix/sysv/linux/generic/ and make 
sysdeps/unix/sysv/linux the default implementation.

And the idea is not change any current assumption, my goal is just reorganize
the code. For getpeername and getsockname is indeed wrong assumption in my
patch, it should disable both for !__arch64__ && __LINUX_KERNEL_VERSION < 0x040400.

> 
> As I previously noted 
> <https://sourceware.org/pipermail/libc-alpha/2020-July/116453.html>, I 
> think we ought to implement Carlos's proposal of removing the runtime 
> check for old kernel versions before increasing the minimum kernel 
> version, given that an increased version allows very little cleanup for 
> e.g. x86_64.

I thing this change is orthogonal to what I am proposing here.

> 
> I also think that, when assuming presence of a syscall reduces the C 
> implementation of a socket function to just calling a single syscall 
> unconditionally, having one line for that function in a single 
> syscalls.list file is better than having a manually-maintained C 
> implementation.
> 

I do agree, and my proposal here in once we have a proper support
for direct syscall with bump minimal kernel support we can just
remove the C implementation and move it to syscalls.list without
the need to change and rework over various files.
  
Joseph Myers Nov. 19, 2020, 4:38 p.m. UTC | #3
On Thu, 19 Nov 2020, Adhemerval Zanella wrote:

> And the idea is not change any current assumption, my goal is just reorganize
> the code.

Then I think the individual patches need longer descriptions that make 
this clear - that is, that say explicitly that the change is to the 
default, with the final value of the __ASSUME_* macro being unchanged for 
all glibc configurations.  Because that's not what e.g. "Assume bind 
support" suggests to me.

> For getpeername and getsockname is indeed wrong assumption in my
> patch, it should disable both for !__arch64__ && __LINUX_KERNEL_VERSION < 0x040400.

4.20 for those two, I think, because of the compat syscall table.
  
Adhemerval Zanella Nov. 19, 2020, 5:43 p.m. UTC | #4
On 19/11/2020 13:38, Joseph Myers wrote:
> On Thu, 19 Nov 2020, Adhemerval Zanella wrote:
> 
>> And the idea is not change any current assumption, my goal is just reorganize
>> the code.
> 
> Then I think the individual patches need longer descriptions that make 
> this clear - that is, that say explicitly that the change is to the 
> default, with the final value of the __ASSUME_* macro being unchanged for 
> all glibc configurations.  Because that's not what e.g. "Assume bind 
> support" suggests to me.

Fair enough, I will improve the message on the patches.

> 
>> For getpeername and getsockname is indeed wrong assumption in my
>> patch, it should disable both for !__arch64__ && __LINUX_KERNEL_VERSION < 0x040400.
> 
> 4.20 for those two, I think, because of the compat syscall table.
> 

Right, I will fix this also.