Re: endianness swapped

2019-04-29 Thread Arnd Bergmann
On Mon, Apr 29, 2019 at 10:44 AM Geert Uytterhoeven
 wrote:
> On Sun, Apr 28, 2019 at 3:59 PM Greg Ungerer  wrote:
> > On 28/4/19 7:21 pm, Arnd Bergmann wrote:
> > > On Sun, Apr 28, 2019 at 10:46 AM Geert Uytterhoeven
> > >  wrote:
> > >>
> > >> Orthogonal to how Coldfire's read[wl]() should be fixed, I find it a bit
> > >> questionable to swap data twice on big endian architectures.
> > >
> > > I would expect that the compiler is capable of detecting a double
> > > swap and optimize it out. Even if it can't, there are not that many
> > > instances of io{read,write}{16,32}be in the kernel, so the increase
> > > in kernel image size from a double swap should be limited to a
> > > few extra instructions, and the runtime overhead should be
> > > negligible compared to the bus access.
>
> Probably the overhead is not negligible on old m68k...

Maybe the I/O devices are faster than I expected then. I was guessing
that there is still a factor of 100x or more between going to an on-chip
bus and single byterev register-to-register instruction.

I did notice that __arch_swab32() is an inline assembly, so the
compiler has no way of eliminating the double swap, but
setting CONFIG_ARCH_USE_BUILTIN_BSWAP makes it
do the right thing.

  Arnd


Re: endianness swapped

2019-04-29 Thread Arnd Bergmann
On Mon, Apr 29, 2019 at 9:04 AM Greg Ungerer  wrote:
> On 29/4/19 4:44 am, Arnd Bergmann wrote:
> > Is there a complete list of coldfire on-chip device drivers?
> >
> > Looking at some of the drivers:
> >
> > - drivers/i2c/busses/i2c-imx.c uses only 8-bit accesses and works either 
> > way,
> >same for drivers/tty/serial/mcf.c
> > - drivers/spi/spi-coldfire-qspi.c is apparently coldfire-only and could use
> >ioread32be for a portable to do big-endian register access.
> > - edma-common has a wrapper to support both big-endian and little-endian
> >configurations in the same kernel image, but the mcf interrupt handler
> >is hardcoded to the (normally) little-endian ioread32 function.
> > - drivers/net/ethernet/freescale/fec_main.c is shared between coldfire
> >and i.MX (but not mpc52xx), and is hardcoded to readl/writel, and
> >would need the same trick as edma to make it portable.
>
> That matches up with what we list out in arch/m68k/coldfire/devices.c.
> I can't think of any other drivers.

Ok

> There is a lot of use readl/writel and friends in the architecture
> specific code too, in arch/m68k/coldfire. At first I used __raw_readl/
> __raw_writel to always get native endianess. But quote a few uses of
> readl/writel have crept in over the years.

I generally recommend avoiding the __raw_ accessors altogether
except for very special cases (e.g. copying from device memory
into main RAM in fixed-size units). On most architectures these
days, MMIO registers require additional properties that are
provided by readl() but not __raw_readl(), in particular atomicity
and ordering against other memory accesses and spinlocks.
Presumably m68k is similar to i386 here in that the __raw_ version
already provides all those guarantees due to the way the architecture
is defined.

What tends to work best in cases like this is to have a bus specific
wrapper around readl/ioread32/ioread32be that does exactly what
is needed for the bus that a device is on. As we concluded earlier,
it's easy enough to define coldfire specific ioread32be etc that
do what we want here, but it also sounds like it would not be hard
to change arch/m68k/coldfire/*.c, drivers/net/ethernet/freescale/fec*
and drivers/dma/*edma*.c to use big-endian accessors, and
then make coldfire use the generic readl/writel and
ioread32be/iowrite32be.

  Arnd


Re: endianness swapped

2019-04-28 Thread Arnd Bergmann
On Sun, Apr 28, 2019 at 3:59 PM Greg Ungerer  wrote:
> On 28/4/19 7:21 pm, Arnd Bergmann wrote:
> > On Sun, Apr 28, 2019 at 10:46 AM Geert Uytterhoeven
> >  wrote:
> >> On Sat, Apr 27, 2019 at 10:22 PM Angelo Dureghello  wrote:
> >>> On Sat, Apr 27, 2019 at 05:32:22PM +0200, Angelo Dureghello wrote:
> >
> > Coldfire makes the behavior of readw()/readl() depend on the
> > MMIO address, presumably since that was the easiest way to
> > get drivers working originally, but it breaks the assumption
> > in the asm-generic code.
>
> Yes, that is right.
>
> There is a number of common hardware modules that Freescale have
> used in the ColdFire SoC parts and in their ARM based parts (iMX
> families). The ARM parts are pretty much always little endian, and
> the ColdFire is always big endian. The hardware registers in those
> hardware blocks are always accessed in native endian of the processor.

In later Freescale/NXP ARM SoCs (i.MX and Layerscape), we
also get a lot of devices pulled over from PowerPC, with random
endianess. In some cases, the same device that had big-endian
registers originally ends up in two different ARM products and one of
them uses big-endian while the other one uses little-endian registers.

> So the address range checks are to deal with those internal
> hardware blocks (i2c, spi, dma, etc), since we know those are
> at fixed addresses. That leaves the usual endian swapping in place for
> other general (ie external) devices (PCI devices, network chips, etc).

Is there a complete list of coldfire on-chip device drivers?

Looking at some of the drivers:

- drivers/i2c/busses/i2c-imx.c uses only 8-bit accesses and works either way,
  same for drivers/tty/serial/mcf.c
- drivers/spi/spi-coldfire-qspi.c is apparently coldfire-only and could use
  ioread32be for a portable to do big-endian register access.
- edma-common has a wrapper to support both big-endian and little-endian
  configurations in the same kernel image, but the mcf interrupt handler
  is hardcoded to the (normally) little-endian ioread32 function.
- drivers/net/ethernet/freescale/fec_main.c is shared between coldfire
  and i.MX (but not mpc52xx), and is hardcoded to readl/writel, and
  would need the same trick as edma to make it portable.

  Arnd


Re: endianness swapped

2019-04-28 Thread Arnd Bergmann
On Sun, Apr 28, 2019 at 10:46 AM Geert Uytterhoeven
 wrote:
> On Sat, Apr 27, 2019 at 10:22 PM Angelo Dureghello  wrote:
> > On Sat, Apr 27, 2019 at 05:32:22PM +0200, Angelo Dureghello wrote:
> > > as you may know, i am working on mcf5441x.
> > > Sorry for not following carefully all the threads, but from a certain
> > > kernel version (likely 4.19 or near there), seems ioread32be
> > > reads the bytes swapped in endianness (mcf-edma dma driver not working
> > > anymore).
> > >
> > > Has there been a change about this in the architecture I/O access ?
> > > How should i proceed now ? Fixing the DMA driver read/write, or what ?
>
> > looks like the reason of my ioread32be now swapped is:
> >
> > https://patchwork.kernel.org/patch/10766673/
> >
> > Trying to figure out what to do now.
>
> This is commit aecc787c06f4300f ("iomap: Use non-raw io functions for
> io{read|write}XXbe"):
>
> --- a/lib/iomap.c
> +++ b/lib/iomap.c
> @@ -65,8 +65,8 @@ static void bad_io_access(unsigned long port, const
> char *access)
>  #endif
>
>  #ifndef mmio_read16be
> -#define mmio_read16be(addr) be16_to_cpu(__raw_readw(addr))
> -#define mmio_read32be(addr) be32_to_cpu(__raw_readl(addr))
> +#define mmio_read16be(addr) swab16(readw(addr))
> +#define mmio_read32be(addr) swab32(readl(addr))
>  #endif
>
>  unsigned int ioread8(void __iomem *addr)
> @@ -106,8 +106,8 @@ EXPORT_SYMBOL(ioread32be);
>  #endif
>
>  #ifndef mmio_write16be
> -#define mmio_write16be(val,port) __raw_writew(be16_to_cpu(val),port)
> -#define mmio_write32be(val,port) __raw_writel(be32_to_cpu(val),port)
> +#define mmio_write16be(val,port) writew(swab16(val),port)
> +#define mmio_write32be(val,port) writel(swab32(val),port)
>
> On big endian, the raw accessors are assumed to be non-swapping,
> while non-raw accessors are assumed to be swapping.
> The latter is not true for Coldfire internal registers, cfr.
> arch/m68k/include/asm/io_no.h:

The raw accessors are always assumed to be non-swapping
in the asm-generic code, while the non-raw ones are assumed to
be little-endian in order for them to work with portable drivers.

We have some other cases of big-endian machines that use
a hardware byteswap on their MMIO buses (iirc some mips
and superh parts), but they then need to swap the __raw_*
accessor data words in software to get back to the normal
behavior, as well as swizzle the address for accesses that are
less than 32 bit wide.

Coldfire makes the behavior of readw()/readl() depend on the
MMIO address, presumably since that was the easiest way to
get drivers working originally, but it breaks the assumption
in the asm-generic code.

> static inline u16 readw(const volatile void __iomem *addr)
> {
> if (cf_internalio(addr))
> return __raw_readw(addr);
> return __le16_to_cpu(__raw_readw(addr));
> }
>
> Orthogonal to how Coldfire's read[wl]() should be fixed, I find it a bit
> questionable to swap data twice on big endian architectures.

I would expect that the compiler is capable of detecting a double
swap and optimize it out. Even if it can't, there are not that many
instances of io{read,write}{16,32}be in the kernel, so the increase
in kernel image size from a double swap should be limited to a
few extra instructions, and the runtime overhead should be
negligible compared to the bus access.

> Fortunately we can avoid that by defining our own
> mmio_{read,write}{16,32}be()...

Yes, that should be the easiest workaround. I doubt that anyone
would want to audit all drivers for internal I/O on coldfire and
convert them to use the big-endian accessors in place of the
readw/readl ones in order to use the asm-generic/io.h conventions.

  Arnd


[PATCH] [v2] arch: add pidfd and io_uring syscalls everywhere

2019-04-15 Thread Arnd Bergmann
Add the io_uring and pidfd_send_signal system calls to all architectures.

These system calls are designed to handle both native and compat tasks,
so all entries are the same across architectures, only arm-compat and
the generic tale still use an old format.

Acked-by: Michael Ellerman  (powerpc)
Acked-by: Heiko Carstens  (s390)
Acked-by: Geert Uytterhoeven 
Signed-off-by: Arnd Bergmann 
---
Changes since v1:
- fix s390 table
- use 'n64' tag in mips-n64 instead of common.
---
 arch/alpha/kernel/syscalls/syscall.tbl  | 4 
 arch/arm/tools/syscall.tbl  | 4 
 arch/arm64/include/asm/unistd.h | 2 +-
 arch/arm64/include/asm/unistd32.h   | 8 
 arch/ia64/kernel/syscalls/syscall.tbl   | 4 
 arch/m68k/kernel/syscalls/syscall.tbl   | 4 
 arch/microblaze/kernel/syscalls/syscall.tbl | 4 
 arch/mips/kernel/syscalls/syscall_n32.tbl   | 4 
 arch/mips/kernel/syscalls/syscall_n64.tbl   | 4 
 arch/mips/kernel/syscalls/syscall_o32.tbl   | 4 
 arch/parisc/kernel/syscalls/syscall.tbl | 4 
 arch/powerpc/kernel/syscalls/syscall.tbl| 4 
 arch/s390/kernel/syscalls/syscall.tbl   | 4 
 arch/sh/kernel/syscalls/syscall.tbl | 4 
 arch/sparc/kernel/syscalls/syscall.tbl  | 4 
 arch/xtensa/kernel/syscalls/syscall.tbl | 4 
 16 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/arch/alpha/kernel/syscalls/syscall.tbl 
b/arch/alpha/kernel/syscalls/syscall.tbl
index 63ed39cbd3bd..165f268beafc 100644
--- a/arch/alpha/kernel/syscalls/syscall.tbl
+++ b/arch/alpha/kernel/syscalls/syscall.tbl
@@ -463,3 +463,7 @@
 532common  getppid sys_getppid
 # all other architectures have common numbers for new syscall, alpha
 # is the exception.
+534common  pidfd_send_signal   sys_pidfd_send_signal
+535common  io_uring_setup  sys_io_uring_setup
+536common  io_uring_enter  sys_io_uring_enter
+537common  io_uring_register   sys_io_uring_register
diff --git a/arch/arm/tools/syscall.tbl b/arch/arm/tools/syscall.tbl
index 9016f4081bb9..0393917eaa57 100644
--- a/arch/arm/tools/syscall.tbl
+++ b/arch/arm/tools/syscall.tbl
@@ -437,3 +437,7 @@
 421common  rt_sigtimedwait_time64  sys_rt_sigtimedwait
 422common  futex_time64sys_futex
 423common  sched_rr_get_interval_time64sys_sched_rr_get_interval
+424common  pidfd_send_signal   sys_pidfd_send_signal
+425common  io_uring_setup  sys_io_uring_setup
+426common  io_uring_enter  sys_io_uring_enter
+427common  io_uring_register   sys_io_uring_register
diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h
index 310d8f1cae7a..c6946fe640e6 100644
--- a/arch/arm64/include/asm/unistd.h
+++ b/arch/arm64/include/asm/unistd.h
@@ -49,7 +49,7 @@
 #define __ARM_NR_compat_set_tls(__ARM_NR_COMPAT_BASE + 5)
 #define __ARM_NR_COMPAT_END(__ARM_NR_COMPAT_BASE + 0x800)
 
-#define __NR_compat_syscalls   424
+#define __NR_compat_syscalls   428
 #endif
 
 #define __ARCH_WANT_SYS_CLONE
diff --git a/arch/arm64/include/asm/unistd32.h 
b/arch/arm64/include/asm/unistd32.h
index 5590f2623690..23f1a44acada 100644
--- a/arch/arm64/include/asm/unistd32.h
+++ b/arch/arm64/include/asm/unistd32.h
@@ -866,6 +866,14 @@ __SYSCALL(__NR_rt_sigtimedwait_time64, 
compat_sys_rt_sigtimedwait_time64)
 __SYSCALL(__NR_futex_time64, sys_futex)
 #define __NR_sched_rr_get_interval_time64 423
 __SYSCALL(__NR_sched_rr_get_interval_time64, sys_sched_rr_get_interval)
+#define __NR_pidfd_send_signal 424
+__SYSCALL(__NR_pidfd_send_signal, sys_pidfd_send_signal)
+#define __NR_io_uring_setup 425
+__SYSCALL(__NR_io_uring_setup, sys_io_uring_setup)
+#define __NR_io_uring_enter 426
+__SYSCALL(__NR_io_uring_enter, sys_io_uring_enter)
+#define __NR_io_uring_register 427
+__SYSCALL(__NR_io_uring_register, sys_io_uring_register)
 
 /*
  * Please add new compat syscalls above this comment and update
diff --git a/arch/ia64/kernel/syscalls/syscall.tbl 
b/arch/ia64/kernel/syscalls/syscall.tbl
index ab9cda5f6136..56e3d0b685e1 100644
--- a/arch/ia64/kernel/syscalls/syscall.tbl
+++ b/arch/ia64/kernel/syscalls/syscall.tbl
@@ -344,3 +344,7 @@
 332common  pkey_free   sys_pkey_free
 333common  rseqsys_rseq
 # 334 through 423 are reserved to sync up with other architectures
+424common  pidfd_send_signal   sys_pidfd_send_signal
+425common  io_uring_setup  sys_io_uring_setup
+426common  io_uring_enter  sys_io_uring_enter
+427common  io_uring_register   sys_io_uring_register
diff --git a/arch/m68k/kernel/syscalls/syscall.tbl 
b/arch/m68k/kernel/syscalls/syscall.tbl
index 125c14178979..df4ec3ec71d1 100644
--- a/arch/m68k/kernel/syscalls/syscall.tbl

Re: [PATCH 2/2] arch: add pidfd and io_uring syscalls everywhere

2019-03-31 Thread Arnd Bergmann
On Sun, Mar 31, 2019 at 5:47 PM Michael Ellerman  wrote:
>
> Arnd Bergmann  writes:
> > Add the io_uring and pidfd_send_signal system calls to all architectures.
> >
> > These system calls are designed to handle both native and compat tasks,
> > so all entries are the same across architectures, only arm-compat and
> > the generic tale still use an old format.
> >
> > Signed-off-by: Arnd Bergmann 
> > ---
> >  arch/alpha/kernel/syscalls/syscall.tbl  | 4 
> >  arch/arm/tools/syscall.tbl  | 4 
> >  arch/arm64/include/asm/unistd.h | 2 +-
> >  arch/arm64/include/asm/unistd32.h   | 8 
> >  arch/ia64/kernel/syscalls/syscall.tbl   | 4 
> >  arch/m68k/kernel/syscalls/syscall.tbl   | 4 
> >  arch/microblaze/kernel/syscalls/syscall.tbl | 4 
> >  arch/mips/kernel/syscalls/syscall_n32.tbl   | 4 
> >  arch/mips/kernel/syscalls/syscall_n64.tbl   | 4 
> >  arch/mips/kernel/syscalls/syscall_o32.tbl   | 4 
> >  arch/parisc/kernel/syscalls/syscall.tbl | 4 
> >  arch/powerpc/kernel/syscalls/syscall.tbl| 4 
>
> Have you done any testing?
>
> I'd rather not wire up syscalls that have never been tested at all on
> powerpc.

No, I have not. I did review the system calls carefully and added the first
patch to fix the bug on x86 compat mode before adding the same bug
on the other compat architectures though ;-)

Generally, my feeling is that adding system calls is not fundamentally
different from adding other ABIs, and we should really do it at
the same time across all architectures, rather than waiting for each
maintainer to get around to reviewing and testing the new calls
first. This is not a problem on powerpc, but a lot of other architectures
are less active, which is how we have always ended up with
different sets of system calls across architectures.

The problem here is that this makes it harder for the C library to
know when a system call is guaranteed to be available. glibc
still needs a feature test for newly added syscalls to see if they
are working (they might be backported to an older kernel, or
disabled), but whenever the minimum kernel version is increased,
it makes sense to drop those checks and assume non-optional
system calls will work if they were part of that minimum version.

In the future, I'd hope that any new system calls get added
right away on all architectures when they land (it was a bit
tricky this time, because I still did a bunch of reworks that
conflicted with the new calls). Bugs will happen of course, but
I think adding them sooner makes it more likely to catch those
bugs early on so we have a chance to fix them properly,
and need fewer arch specific workarounds (ideally none)
for system calls.

   Arnd


Re: [PATCH 2/2] arch: add pidfd and io_uring syscalls everywhere

2019-03-26 Thread Arnd Bergmann
On Mon, Mar 25, 2019 at 6:37 PM Paul Burton  wrote:
> On Mon, Mar 25, 2019 at 03:47:37PM +0100, Arnd Bergmann wrote:
> > Add the io_uring and pidfd_send_signal system calls to all architectures.
> >
> > These system calls are designed to handle both native and compat tasks,
> > so all entries are the same across architectures, only arm-compat and
> > the generic tale still use an old format.
> >
> > Signed-off-by: Arnd Bergmann 
> > ---
> >%
> > diff --git a/arch/mips/kernel/syscalls/syscall_n64.tbl 
> > b/arch/mips/kernel/syscalls/syscall_n64.tbl
> > index c85502e67b44..c4a49f7d57bb 100644
> > --- a/arch/mips/kernel/syscalls/syscall_n64.tbl
> > +++ b/arch/mips/kernel/syscalls/syscall_n64.tbl
> > @@ -338,3 +338,7 @@
> >  327  n64 rseqsys_rseq
> >  328  n64 io_pgetevents   sys_io_pgetevents
> >  # 329 through 423 are reserved to sync up with other architectures
> > +424  common  pidfd_send_signal   sys_pidfd_send_signal
> > +425  common  io_uring_setup  sys_io_uring_setup
> > +426  common  io_uring_enter  sys_io_uring_enter
> > +427  common  io_uring_register   sys_io_uring_register
>
> Shouldn't these declare the ABI as "n64"?
>
> I don't see anywhere that it would actually change the generated code,
> but a comment at the top of the file says that every entry should use
> "n64" and so far they all do. Did you have something else in mind here?

You are right, the use of 'common' here is unintentional but harmless,
and I should have used 'n64' here.

We may decide to do things differently in the future, i.e. we could
have just a single global file for newly added system calls once
it turns out that the tables are consistent across all architectures,
but I'd probably go on with the separate identical entries for a bit
before changing that.

 Arnd


[PATCH 2/2] arch: add pidfd and io_uring syscalls everywhere

2019-03-25 Thread Arnd Bergmann
Add the io_uring and pidfd_send_signal system calls to all architectures.

These system calls are designed to handle both native and compat tasks,
so all entries are the same across architectures, only arm-compat and
the generic tale still use an old format.

Signed-off-by: Arnd Bergmann 
---
 arch/alpha/kernel/syscalls/syscall.tbl  | 4 
 arch/arm/tools/syscall.tbl  | 4 
 arch/arm64/include/asm/unistd.h | 2 +-
 arch/arm64/include/asm/unistd32.h   | 8 
 arch/ia64/kernel/syscalls/syscall.tbl   | 4 
 arch/m68k/kernel/syscalls/syscall.tbl   | 4 
 arch/microblaze/kernel/syscalls/syscall.tbl | 4 
 arch/mips/kernel/syscalls/syscall_n32.tbl   | 4 
 arch/mips/kernel/syscalls/syscall_n64.tbl   | 4 
 arch/mips/kernel/syscalls/syscall_o32.tbl   | 4 
 arch/parisc/kernel/syscalls/syscall.tbl | 4 
 arch/powerpc/kernel/syscalls/syscall.tbl| 4 
 arch/s390/kernel/syscalls/syscall.tbl   | 4 
 arch/sh/kernel/syscalls/syscall.tbl | 4 
 arch/sparc/kernel/syscalls/syscall.tbl  | 4 
 arch/xtensa/kernel/syscalls/syscall.tbl | 4 
 16 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/arch/alpha/kernel/syscalls/syscall.tbl 
b/arch/alpha/kernel/syscalls/syscall.tbl
index 63ed39cbd3bd..165f268beafc 100644
--- a/arch/alpha/kernel/syscalls/syscall.tbl
+++ b/arch/alpha/kernel/syscalls/syscall.tbl
@@ -463,3 +463,7 @@
 532common  getppid sys_getppid
 # all other architectures have common numbers for new syscall, alpha
 # is the exception.
+534common  pidfd_send_signal   sys_pidfd_send_signal
+535common  io_uring_setup  sys_io_uring_setup
+536common  io_uring_enter  sys_io_uring_enter
+537common  io_uring_register   sys_io_uring_register
diff --git a/arch/arm/tools/syscall.tbl b/arch/arm/tools/syscall.tbl
index 9016f4081bb9..0393917eaa57 100644
--- a/arch/arm/tools/syscall.tbl
+++ b/arch/arm/tools/syscall.tbl
@@ -437,3 +437,7 @@
 421common  rt_sigtimedwait_time64  sys_rt_sigtimedwait
 422common  futex_time64sys_futex
 423common  sched_rr_get_interval_time64sys_sched_rr_get_interval
+424common  pidfd_send_signal   sys_pidfd_send_signal
+425common  io_uring_setup  sys_io_uring_setup
+426common  io_uring_enter  sys_io_uring_enter
+427common  io_uring_register   sys_io_uring_register
diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h
index 310d8f1cae7a..c6946fe640e6 100644
--- a/arch/arm64/include/asm/unistd.h
+++ b/arch/arm64/include/asm/unistd.h
@@ -49,7 +49,7 @@
 #define __ARM_NR_compat_set_tls(__ARM_NR_COMPAT_BASE + 5)
 #define __ARM_NR_COMPAT_END(__ARM_NR_COMPAT_BASE + 0x800)
 
-#define __NR_compat_syscalls   424
+#define __NR_compat_syscalls   428
 #endif
 
 #define __ARCH_WANT_SYS_CLONE
diff --git a/arch/arm64/include/asm/unistd32.h 
b/arch/arm64/include/asm/unistd32.h
index 5590f2623690..23f1a44acada 100644
--- a/arch/arm64/include/asm/unistd32.h
+++ b/arch/arm64/include/asm/unistd32.h
@@ -866,6 +866,14 @@ __SYSCALL(__NR_rt_sigtimedwait_time64, 
compat_sys_rt_sigtimedwait_time64)
 __SYSCALL(__NR_futex_time64, sys_futex)
 #define __NR_sched_rr_get_interval_time64 423
 __SYSCALL(__NR_sched_rr_get_interval_time64, sys_sched_rr_get_interval)
+#define __NR_pidfd_send_signal 424
+__SYSCALL(__NR_pidfd_send_signal, sys_pidfd_send_signal)
+#define __NR_io_uring_setup 425
+__SYSCALL(__NR_io_uring_setup, sys_io_uring_setup)
+#define __NR_io_uring_enter 426
+__SYSCALL(__NR_io_uring_enter, sys_io_uring_enter)
+#define __NR_io_uring_register 427
+__SYSCALL(__NR_io_uring_register, sys_io_uring_register)
 
 /*
  * Please add new compat syscalls above this comment and update
diff --git a/arch/ia64/kernel/syscalls/syscall.tbl 
b/arch/ia64/kernel/syscalls/syscall.tbl
index ab9cda5f6136..56e3d0b685e1 100644
--- a/arch/ia64/kernel/syscalls/syscall.tbl
+++ b/arch/ia64/kernel/syscalls/syscall.tbl
@@ -344,3 +344,7 @@
 332common  pkey_free   sys_pkey_free
 333common  rseqsys_rseq
 # 334 through 423 are reserved to sync up with other architectures
+424common  pidfd_send_signal   sys_pidfd_send_signal
+425common  io_uring_setup  sys_io_uring_setup
+426common  io_uring_enter  sys_io_uring_enter
+427common  io_uring_register   sys_io_uring_register
diff --git a/arch/m68k/kernel/syscalls/syscall.tbl 
b/arch/m68k/kernel/syscalls/syscall.tbl
index 125c14178979..df4ec3ec71d1 100644
--- a/arch/m68k/kernel/syscalls/syscall.tbl
+++ b/arch/m68k/kernel/syscalls/syscall.tbl
@@ -423,3 +423,7 @@
 421common  rt_sigtimedwait_time64  sys_rt_sigtimedwait
 422common  futex_time64sys_futex

Re: [PATCH] x86: Deprecate a.out support

2019-03-11 Thread Arnd Bergmann
On Mon, Mar 11, 2019 at 8:47 PM Måns Rullgård  wrote:
> Linus Torvalds  writes:
> > On Mon, Mar 11, 2019 at 11:08 AM Måns Rullgård  wrote:
> >>
> >> The latest version I have is 5.1, and that uses ECOFF.
> >
> > ECOFF _is_ a.out as far as Linux is concerned.
> >
> > So Linux basically treats ECOFF as "regular a.out with just some
> > header extensions".
> >
> > We don't have any specific support for ECOFF.
> >
> > I _think_. Again, it's been years and years.
>
> Right, which is why killing a.out entirely would have the unfortunate
> effect of also removing the OSF/1 compatibility on Alpha.
>
> If we are to support Alpha as an architecture at all, it makes sense to
> support the things people actually use it for.
>
> Now, personally I can live without it.  I just don't like to see
> features removed without due consideration.

The main historic use case I've heard of was running Netscape
Navigator on Alpha Linux, before there was an open source version.
Doing this today to connect to the open internet is probably
a bit pointless, but there may be other use cases.

Looking at the system call table in the kernel
(arch/alpha/kernel/syscalls/syscall.tbl), we seem to support a
specific subset that was required for a set of applications, and
not much more. Old system calls (osf_old_open, osf_execve,
osf_old_sigaction) are listed but not implemented, and the same
is true for most of the later calls (osf_fuser, osf_sigsendset,
osf_waitid, osf_signal, ...), just the ones in the middle are there.
This would also indicate that it never really worked as a
general-purpose emulation layer but was only there for a specific
set of applications.

Another data point I have is that osf1 emulation was broken
between linux-4.13 and linux-4.16 without anyone noticing, see
47669fb6b595 ("alpha: osf_sys.c: fix put_tv32 regression").

  Arnd


Re: [PATCH] x86: Deprecate a.out support

2019-03-11 Thread Arnd Bergmann
On Sun, Mar 10, 2019 at 11:46 PM Linus Torvalds
 wrote:
>
> On Sun, Mar 10, 2019 at 2:37 PM Matt Turner  wrote:
> >
> > I'm not aware of a reason to keep a.out support on alpha.
>
> Hmm. I was looking at removing a.out support entirely, but it's
> actually fairly incestuous on alpha.
>
> For example, arch/alpha/boot/tools/objstrip.c very much has some a.out
> support in it. Maybe it can just be removed entirely.
>
> There's also an a.out.h include in arch/alpha/kernel/binfmt_loader.c.
>
> Finally, note that CONFIG_OSF4_COMPAT also no longer makes sense
> without a.out support.
>
> So this attached patch does not compile on alpha, but it's been many
> many years since I had an alpha to test with, so I'm stuck.
>
> Matt, can you fill in the details and complete this patch?

I wonder if we could remove the osf time32 compat code as well,
this was one of the areas that kept causing problems with the y2038
rework. (I think it's all good now, but it's never been tested as far as I
can tell).

For some syscalls (e.g. brk, mmap, getxuid, ...) we definitely need to
keep the osf1 version, since it is the only supported ABI.

I just looked up some really old source trees and found that glibc-2.1
was the first release to use 64-bit time_t the way we do it today,
as implemented in [1], so all Debian and SuSE releases for alpha
had it, but any ELF binaries built on Red Hat Linux 4.x and 5.x
(released 1996 through 1998) or earlier would use 32-bit time_t
osf1 syscalls. Red Hat 2.x and 3.x were a.out based on alpha.

  Arnd

[1] https://repo.or.cz/glibc/history.git/commitdiff/64819b5c3a94e81e4


Re: [PATCH v2 29/29] y2038: add 64-bit time_t syscalls to all 32-bit architectures

2019-01-21 Thread Arnd Bergmann
On Mon, Jan 21, 2019 at 6:08 PM Arnd Bergmann  wrote:
> On Mon, Jan 21, 2019 at 9:19 AM Geert Uytterhoeven  
> wrote:
> > Regardless, I'm wondering what to do with the holes marked "room for
> > arch specific calls".
> > When is a syscall really arch-specific, and can it be added there, and
> > when does it turn out (later) that it isn't, breaking the
> > synchronization again?
>
> We've had a bit of that already, with cacheflush(), which exists on
> a couple of architectures, including some that use the first
> 'arch specific' slot (244) of the asm-generic table. I think this
> will be rare enough that we can figure out a solution when we
> get there.
>
> > The pkey syscalls may be a bad example, as AFAIU they can be implemented
> > on some architectures, but not on some others.  Still, I had skipped them
> > when adding new syscalls to m68k.
> >
> > Perhaps we should get rid of the notion of "arch-specific syscalls", and
> > reserve a slot everywhere anyway?
>
> I don't mind calling the hole something else if that helps. Out of
> principle I would already assume that anything we add for x86
> or the generic table should be added everywhere, but we can
> make it broader than that.

Applying this fixup below,

 ARnd

diff --git a/arch/x86/entry/syscalls/syscall_32.tbl
b/arch/x86/entry/syscalls/syscall_32.tbl
index d9c2d2eea044..955ab6a3b61f 100644
--- a/arch/x86/entry/syscalls/syscall_32.tbl
+++ b/arch/x86/entry/syscalls/syscall_32.tbl
@@ -398,7 +398,7 @@
 384i386arch_prctl  sys_arch_prctl
 __ia32_compat_sys_arch_prctl
 385i386io_pgetevents   sys_io_pgetevents_time32
 __ia32_compat_sys_io_pgetevents
 386i386rseqsys_rseq
 __ia32_sys_rseq
-# room for arch specific syscalls
+# don't use numbers 387 through 392, add new calls at the end
 393i386semget  sys_semget
 __ia32_sys_semget
 394i386semctl  sys_semctl
 __ia32_compat_sys_semctl
 395i386shmget  sys_shmget
 __ia32_sys_shmget
diff --git a/arch/x86/entry/syscalls/syscall_64.tbl
b/arch/x86/entry/syscalls/syscall_64.tbl
index 43a622aec07e..2ae92fddb6d5 100644
--- a/arch/x86/entry/syscalls/syscall_64.tbl
+++ b/arch/x86/entry/syscalls/syscall_64.tbl
@@ -343,6 +343,8 @@
 332common  statx   __x64_sys_statx
 333common  io_pgetevents   __x64_sys_io_pgetevents
 334common  rseq__x64_sys_rseq
+# don't use numbers 387 through 423, add new calls after the last
+# 'common' entry

 #
 # x32-specific system call numbers start at 512 to avoid cache impact
diff --git a/include/uapi/asm-generic/unistd.h
b/include/uapi/asm-generic/unistd.h
index 53831e4a4c86..acf9a07ab2ff 100644
--- a/include/uapi/asm-generic/unistd.h
+++ b/include/uapi/asm-generic/unistd.h
@@ -740,7 +740,7 @@ __SC_COMP_3264(__NR_io_pgetevents,
sys_io_pgetevents_time32, sys_io_pgetevents,
 __SYSCALL(__NR_rseq, sys_rseq)
 #define __NR_kexec_file_load 294
 __SYSCALL(__NR_kexec_file_load, sys_kexec_file_load)
-/* 295 through 402 are unassigned to sync up with generic numbers */
+/* 295 through 402 are unassigned to sync up with generic numbers, don't use */
 #if __BITS_PER_LONG == 32
 #define __NR_clock_gettime64 403
 __SYSCALL(__NR_clock_gettime64, sys_clock_gettime)


Re: [PATCH v2 14/29] arch: add pkey and rseq syscall numbers everywhere

2019-01-21 Thread Arnd Bergmann
On Mon, Jan 21, 2019 at 9:56 AM Geert Uytterhoeven  wrote:
>
> Note that all architectures that already define pkey syscalls, list
> pkey_mprotect first.

It's easy enough to change, so I've reordered them for consistency now.

> Regardless, for m68k:
> Acked-by: Geert Uytterhoeven 

Thanks,

 Arnd


Re: [PATCH v2 29/29] y2038: add 64-bit time_t syscalls to all 32-bit architectures

2019-01-21 Thread Arnd Bergmann
On Mon, Jan 21, 2019 at 9:19 AM Geert Uytterhoeven  wrote:
> On Sat, Jan 19, 2019 at 3:29 PM Russell King - ARM Linux admin
>  wrote:
> > On Fri, Jan 18, 2019 at 11:53:25AM -0800, Andy Lutomirski wrote:
> > > On Fri, Jan 18, 2019 at 11:33 AM Arnd Bergmann  wrote:
> > > > On Fri, Jan 18, 2019 at 7:50 PM Andy Lutomirski  wrote:
> > >
> > > Can we perhaps just start the consistent numbers above 547 or maybe
> > > block out 512..547 in the new regime?
> >
> > I don't think you gain much with that kind of scheme - it won't take
> > very long before an architecture misses having a syscall added, and
> > then someone else adds their own.  Been there with ARM - I was keeping
> > the syscall table in the same order as x86 for new syscalls, but now
>
> Same for m68k, and probably other architectures.
>
> > that others have been adding syscalls to the table since I converted
> > ARM to the tabular form, that's now gone out the window.
> >
> > So, I think it's completely pointless to do what you're suggesting.
> > We'll just end up with a big hole in the middle of the syscall table
> > and then revert back to random numbering of syscalls thereafter again.
>
> I believe the plan is to add future syscalls for all architectures in a
> single commit, to keep everything in sync.

Yes, that is the idea. This was not realistic before, since each one
of the old architectures had its own way of describing the system call
tables, and many needed a different set of quirks.

Since (almost) everything is now converted to the syscall.tbl format,
we have removed all obsolete architectures, and a lot of the quirks
(x32, spu, s390-31) won't matter as much in the future, I think it is
now possible to do it.

We could even extend scripts/checksyscalls.sh to warn if a new
syscall above 423 is not added to all 16 tables at the same time.

> Regardless, I'm wondering what to do with the holes marked "room for
> arch specific calls".
> When is a syscall really arch-specific, and can it be added there, and
> when does it turn out (later) that it isn't, breaking the
> synchronization again?

We've had a bit of that already, with cacheflush(), which exists on
a couple of architectures, including some that use the first
'arch specific' slot (244) of the asm-generic table. I think this
will be rare enough that we can figure out a solution when we
get there.

> The pkey syscalls may be a bad example, as AFAIU they can be implemented
> on some architectures, but not on some others.  Still, I had skipped them
> when adding new syscalls to m68k.
>
> Perhaps we should get rid of the notion of "arch-specific syscalls", and
> reserve a slot everywhere anyway?

I don't mind calling the hole something else if that helps. Out of
principle I would already assume that anything we add for x86
or the generic table should be added everywhere, but we can
make it broader than that.

  Arnd


Re: [PATCH v2 29/29] y2038: add 64-bit time_t syscalls to all 32-bit architectures

2019-01-21 Thread Arnd Bergmann
On Fri, Jan 18, 2019 at 5:25 PM Arnd Bergmann  wrote:
>
> This adds 21 new system calls on each ABI that has 32-bit time_t
> today. All of these have the exact same semantics as their existing
> counterparts, and the new ones all have macro names that end in 'time64'
> for clarification.
>
> This gets us to the point of being able to safely use a C library
> that has 64-bit time_t in user space. There are still a couple of
> loose ends to tie up in various areas of the code, but this is the
> big one, and should be entirely uncontroversial at this point.

I've successfully tested this with musl and LTP now, using an
i386 kernel. The musl port I used is at
https://git.linaro.org/people/arnd.bergmann/musl-y2038.git/
This is just an updated version of what I used for testing last
year, using the current syscall assignment, and going back
to the time32 versions of getitimer/setitimer and
wait4/waitid/getusage.

It's certainly not intended for merging like this, but a proper
musl port is under discussion now, and this should be
sufficient if anyone else wants to try out the new syscall
ABI before we merge it.

The LTP I have is heavily hacked, and has a number of
failures resulting from differences between musl and glibc,
or from the way we convert between the kernel types and
the user space types.

The testing found one minor bug in all the kernel syscall tables:

> +418common  mq_timedsend_time64 sys_mq_timedsend
> +419common  mq_timedreceiv_time64   sys_mq_timedreceive

While this would have fit in with umount(), creat() and mknod(),
it was unintentional, and I've changed it back to
mq_timedreceive_time64 (with an added 'e').

   Arnd


Re: [PATCH v2 29/29] y2038: add 64-bit time_t syscalls to all 32-bit architectures

2019-01-18 Thread Arnd Bergmann
On Fri, Jan 18, 2019 at 8:53 PM Andy Lutomirski  wrote:
> I think we have two issues if we reuse those numbers for new syscalls.
> First, I'd really like to see new syscalls be numbered consistently
> everywhere, or at least on all x86 variants, and we can't on x32
> because they mean something else.  Perhaps more importantly, due to
> what is arguably a rather severe bug, issuing a native x86_64 syscall
> (x32 bit clear) with nr in the range 512..547 does *not* return
> -ENOSYS on a kernel with x32 enabled.  Instead it does something that
> is somewhat arbitrary.  With my patch applied, it will return -ENOSYS,
> but old kernels will still exist, and this will break syscall probing.
>
> Can we perhaps just start the consistent numbers above 547 or maybe
> block out 512..547 in the new regime?

I'm definitely fine with not reusing them ever, and jumping from 511 to
548 when we get there on all architectures, if you think that helps.

While we could also jump to 548 *now*, I think that would be a
bit wasteful. Syscall numbers are fairly cheap, but not entirely
free, especially when you consider architectures like mips that
have an upper bound of 1000 syscalls before they have to get
inventive.

 Arnd


Re: [PATCH v2 29/29] y2038: add 64-bit time_t syscalls to all 32-bit architectures

2019-01-18 Thread Arnd Bergmann
On Fri, Jan 18, 2019 at 7:50 PM Andy Lutomirski  wrote:
> On Fri, Jan 18, 2019 at 8:25 AM Arnd Bergmann  wrote:
> > - Once we get to 512, we clash with the x32 numbers (unless
> >   we remove x32 support first), and probably have to skip
> >   a few more. I also considered using the 512..547 space
> >   for 32-bit-only calls (which never clash with x32), but
> >   that also seems to add a bit of complexity.
>
> I have a patch that I'll send soon to make x32 use its own table.  As
> far as I'm concerned, 547 is *it*.  548 is just a normal number and is
> not special.  But let's please not reuse 512..547 for other purposes
> on x86 variants -- that way lies even more confusion, IMO.

Fair enough, the space for those numbers is cheap enough here.
I take it you mean we also should not reuse that number space if
we were to decide to remove x32 soon, but you are not worried
about clashing with arch/alpha when everything else uses consistent
numbers?

   Arnd


Re: [PATCH v2 13/29] arch: add split IPC system calls where needed

2019-01-18 Thread Arnd Bergmann
On Fri, Jan 18, 2019 at 6:20 PM Gabriel Paubert  wrote:
>
> On Fri, Jan 18, 2019 at 05:18:19PM +0100, Arnd Bergmann wrote:
> > The IPC system call handling is highly inconsistent across architectures,
> > some use sys_ipc, some use separate calls, and some use both.  We also
> > have some architectures that require passing IPC_64 in the flags, and
> > others that set it implicitly.
> >
> > For the additon of a y2083 safe semtimedop() system call, I chose to only
>
> It's not critical, but there are two typos in that line:
> additon -> addition
> 2083 -> 2038

Fixed both, thanks!

 Arnd


Re: [PATCH v2 00/29] y2038: add time64 syscalls

2019-01-18 Thread Arnd Bergmann
On Fri, Jan 18, 2019 at 5:57 PM Dennis Clarke  wrote:
>
> On 1/18/19 11:18 AM, Arnd Bergmann wrote:
> > This is a minor update of the patches I posted last week, I
> > would like to add this into linux-next now, but would still do
> > changes if there are concerns about the contents. The first
> > version did not see a lot of replies, which could mean that
> > either everyone is happy with it, or that it was largely ignored.
> >
> > See also the article at https://lwn.net/Articles/776435/.
>
> I would be happy to read "Approaching the kernel year-2038 end game"
> however it is behind a pay wall.  Perhaps it may be best to just
> host interesting articles about open source idea elsewhere.

It's a short summary of the current state. You can also find a
video and slides from my ELC presentation online for a little more
context.

Generally speaking, I'd recommend paying for the subscription to
lwn.net to anyone interested in the kernel, but it should become
visible to everyone with the next day (a week after the initial
publication). In the meantime, you can find the article at
https://lwn.net/SubscriberLink/776435/a59d93d01d1addfc/.

Finally, I've made a list of the remaining work that Deepa
and I are planning to still continue (this should be mostly
complete but may be missing a few things):

syscalls
 - merge big series for 5.1, to allow time64 syscalls
 - waitid/wait4/getrusage should get a replacement based on __kernel_timespec
 - getitimer/setitimer should probably follow getrusage
 - vdso, waiting for consolidation series from Vincenzo Frascino before
   adding time64 entry points

file systems
 - range checks on timestamps
 - xfs
 - NFS
 - hfs/hfsplus
 - coda
 - hostfs
 - relatime_need_update

drivers
 - media
 - alsa
 - sockets
 - af_packet
 - ppp ioctl
 - rtc ioctl
 - omap3isp

core kernel
 - fix ELF core files (elfcore.h)
 - syscall Audit code (kernel/audit.c, kernel/auditsc.c)
 - make all time32 code conditional
 - remove include/linux/timekeeping32.h
 - remove compat_time* from time32.h
 - remove timeval
 - remove timespec
 - remove time_t

 Arnd


[PATCH v2 28/29] y2038: rename old time and utime syscalls

2019-01-18 Thread Arnd Bergmann
The time, stime, utime, utimes, and futimesat system calls are only
used on older architectures, and we do not provide y2038 safe variants
of them, as they are replaced by clock_gettime64, clock_settime64,
and utimensat_time64.

However, for consistency it seems better to have the 32-bit architectures
that still use them call the "time32" entry points (leaving the
traditional handlers for the 64-bit architectures), like we do for system
calls that now require two versions.

Note: We used to always define __ARCH_WANT_SYS_TIME and
__ARCH_WANT_SYS_UTIME and only set __ARCH_WANT_COMPAT_SYS_TIME and
__ARCH_WANT_SYS_UTIME32 for compat mode on 64-bit kernels. Now this is
reversed: only 64-bit architectures set __ARCH_WANT_SYS_TIME/UTIME, while
we need __ARCH_WANT_SYS_TIME32/UTIME32 for 32-bit architectures and compat
mode. The resulting asm/unistd.h changes look a bit counterintuitive.

This is only a cleanup patch and it should not change any behavior.

Signed-off-by: Arnd Bergmann 
---
 arch/arm/include/asm/unistd.h   |  4 ++--
 arch/arm/tools/syscall.tbl  | 10 +-
 arch/m68k/include/asm/unistd.h  |  4 ++--
 arch/m68k/kernel/syscalls/syscall.tbl   | 10 +-
 arch/microblaze/include/asm/unistd.h|  4 ++--
 arch/microblaze/kernel/syscalls/syscall.tbl | 10 +-
 arch/mips/include/asm/unistd.h  |  4 ++--
 arch/mips/kernel/syscalls/syscall_o32.tbl   | 10 +-
 arch/parisc/include/asm/unistd.h|  9 ++---
 arch/parisc/kernel/syscalls/syscall.tbl | 15 ++-
 arch/powerpc/include/asm/unistd.h   |  8 
 arch/powerpc/kernel/syscalls/syscall.tbl| 19 ++-
 arch/s390/include/asm/unistd.h  |  2 +-
 arch/sh/include/asm/unistd.h|  4 ++--
 arch/sh/kernel/syscalls/syscall.tbl | 10 +-
 arch/sparc/include/asm/unistd.h |  8 
 arch/sparc/kernel/syscalls/syscall.tbl  | 14 +-
 arch/x86/entry/syscalls/syscall_32.tbl  | 10 +-
 arch/x86/include/asm/unistd.h   |  8 
 arch/xtensa/include/asm/unistd.h|  2 +-
 arch/xtensa/kernel/syscalls/syscall.tbl |  6 +++---
 kernel/time/time.c  |  4 ++--
 22 files changed, 98 insertions(+), 77 deletions(-)

diff --git a/arch/arm/include/asm/unistd.h b/arch/arm/include/asm/unistd.h
index d713587dfcf4..7a39e77984ef 100644
--- a/arch/arm/include/asm/unistd.h
+++ b/arch/arm/include/asm/unistd.h
@@ -26,10 +26,10 @@
 #define __ARCH_WANT_SYS_SIGPROCMASK
 #define __ARCH_WANT_SYS_OLD_MMAP
 #define __ARCH_WANT_SYS_OLD_SELECT
-#define __ARCH_WANT_SYS_UTIME
+#define __ARCH_WANT_SYS_UTIME32
 
 #if !defined(CONFIG_AEABI) || defined(CONFIG_OABI_COMPAT)
-#define __ARCH_WANT_SYS_TIME
+#define __ARCH_WANT_SYS_TIME32
 #define __ARCH_WANT_SYS_IPC
 #define __ARCH_WANT_SYS_OLDUMOUNT
 #define __ARCH_WANT_SYS_ALARM
diff --git a/arch/arm/tools/syscall.tbl b/arch/arm/tools/syscall.tbl
index 200f4b878a46..a96d9b5ee04e 100644
--- a/arch/arm/tools/syscall.tbl
+++ b/arch/arm/tools/syscall.tbl
@@ -24,7 +24,7 @@
 10 common  unlink  sys_unlink
 11 common  execve  sys_execve
 12 common  chdir   sys_chdir
-13 oabitimesys_time
+13 oabitimesys_time32
 14 common  mknod   sys_mknod
 15 common  chmod   sys_chmod
 16 common  lchown  sys_lchown16
@@ -36,12 +36,12 @@
 22 oabiumount  sys_oldumount
 23 common  setuid  sys_setuid16
 24 common  getuid  sys_getuid16
-25 oabistime   sys_stime
+25 oabistime   sys_stime32
 26 common  ptrace  sys_ptrace
 27 oabialarm   sys_alarm
 # 28 was sys_fstat
 29 common  pause   sys_pause
-30 oabiutime   sys_utime
+30 oabiutime   sys_utime32
 # 31 was sys_stty
 # 32 was sys_gtty
 33 common  access  sys_access
@@ -283,7 +283,7 @@
 266common  statfs64sys_statfs64_wrapper
 267common  fstatfs64   sys_fstatfs64_wrapper
 268common  tgkill  sys_tgkill
-269common  utimes  sys_utimes
+269common  utimes  sys_utimes_time32
 270common  arm_fadvise64_64sys_arm_fadvise64_64
 271common  pciconfig_iobasesys_pciconfig_iobase
 272common  pciconfig_read  sys_pciconfig_read
@@ -340,7 +340,7 @@
 323common  mkdirat sys_mkdirat
 324common  mknodat sys_mknodat
 325common  fchownatsys_fchownat
-326common  futimesat   sys_futimesat
+326common  futimesat   sys_futimesat_time32
 327common 

[PATCH v2 23/29] timex: change syscalls to use struct __kernel_timex

2019-01-18 Thread Arnd Bergmann
From: Deepa Dinamani 

struct timex is not y2038 safe.
Switch all the syscall apis to use y2038 safe __kernel_timex.

Note that sys_adjtimex() does not have a y2038 safe solution.  C libraries
can implement it by calling clock_adjtime(CLOCK_REALTIME, ...).

Signed-off-by: Deepa Dinamani 
Signed-off-by: Arnd Bergmann 
---
 include/linux/syscalls.h   | 6 +++---
 kernel/time/posix-timers.c | 2 +-
 kernel/time/time.c | 4 +++-
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index baa4b70b02d3..09330d5bda0c 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -54,7 +54,7 @@ struct __sysctl_args;
 struct sysinfo;
 struct timespec;
 struct timeval;
-struct timex;
+struct __kernel_timex;
 struct timezone;
 struct tms;
 struct utimbuf;
@@ -695,7 +695,7 @@ asmlinkage long sys_gettimeofday(struct timeval __user *tv,
struct timezone __user *tz);
 asmlinkage long sys_settimeofday(struct timeval __user *tv,
struct timezone __user *tz);
-asmlinkage long sys_adjtimex(struct timex __user *txc_p);
+asmlinkage long sys_adjtimex(struct __kernel_timex __user *txc_p);
 
 /* kernel/timer.c */
 asmlinkage long sys_getpid(void);
@@ -870,7 +870,7 @@ asmlinkage long sys_open_by_handle_at(int mountdirfd,
  struct file_handle __user *handle,
  int flags);
 asmlinkage long sys_clock_adjtime(clockid_t which_clock,
-   struct timex __user *tx);
+   struct __kernel_timex __user *tx);
 asmlinkage long sys_syncfs(int fd);
 asmlinkage long sys_setns(int fd, int nstype);
 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 2d84b3db1ade..de79f85ae14f 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -1060,7 +1060,7 @@ int do_clock_adjtime(const clockid_t which_clock, struct 
__kernel_timex * ktx)
 }
 
 SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock,
-   struct timex __user *, utx)
+   struct __kernel_timex __user *, utx)
 {
struct __kernel_timex ktx;
int err;
diff --git a/kernel/time/time.c b/kernel/time/time.c
index d179d33f639a..78b5c8f1495a 100644
--- a/kernel/time/time.c
+++ b/kernel/time/time.c
@@ -263,7 +263,8 @@ COMPAT_SYSCALL_DEFINE2(settimeofday, struct old_timeval32 
__user *, tv,
 }
 #endif
 
-SYSCALL_DEFINE1(adjtimex, struct timex __user *, txc_p)
+#if !defined(CONFIG_64BIT_TIME) || defined(CONFIG_64BIT)
+SYSCALL_DEFINE1(adjtimex, struct __kernel_timex __user *, txc_p)
 {
struct __kernel_timex txc;  /* Local copy of parameter */
int ret;
@@ -277,6 +278,7 @@ SYSCALL_DEFINE1(adjtimex, struct timex __user *, txc_p)
ret = do_adjtimex();
return copy_to_user(txc_p, , sizeof(struct __kernel_timex)) ? 
-EFAULT : ret;
 }
+#endif
 
 #ifdef CONFIG_COMPAT_32BIT_TIME
 int get_old_timex32(struct __kernel_timex *txc, const struct old_timex32 
__user *utp)
-- 
2.20.0



[PATCH v2 03/29] ia64: assign syscall numbers for perf and seccomp

2019-01-18 Thread Arnd Bergmann
Most architectures have assigned numbers for both seccomp and
perf_event_open, even when they do not implement either.

ia64 is an exception here, so for consistency lets add numbers for both
of them. Unless CONFIG_PERF_EVENTS and CONFIG_SECCOMP are implemented,
the system calls just return -ENOSYS.

Signed-off-by: Arnd Bergmann 
---
 arch/ia64/kernel/syscalls/syscall.tbl | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/ia64/kernel/syscalls/syscall.tbl 
b/arch/ia64/kernel/syscalls/syscall.tbl
index 52585281205b..2e93dbdcdb80 100644
--- a/arch/ia64/kernel/syscalls/syscall.tbl
+++ b/arch/ia64/kernel/syscalls/syscall.tbl
@@ -337,3 +337,5 @@
 325common  pwritev2sys_pwritev2
 326common  statx   sys_statx
 327common  io_pgetevents   sys_io_pgetevents
+328common  perf_event_open sys_perf_event_open
+329common  seccomp sys_seccomp
-- 
2.20.0



[PATCH v2 21/29] sparc64: add custom adjtimex/clock_adjtime functions

2019-01-18 Thread Arnd Bergmann
sparc64 is the only architecture on Linux that has a 'timeval'
definition with a 32-bit tv_usec but a 64-bit tv_sec. This causes
problems for sparc32 compat mode when we convert it to use the
new __kernel_timex type that has the same layout as all other
64-bit architectures.

To avoid adding sparc64 specific code into the generic adjtimex
implementation, this adds a wrapper in the sparc64 system call handling
that converts the sparc64 'timex' into the new '__kernel_timex'.

At this point, the two structures are defined to be identical,
but that will change in the next step once we convert sparc32.

Signed-off-by: Arnd Bergmann 
---
 arch/sparc/kernel/sys_sparc_64.c   | 59 +-
 arch/sparc/kernel/syscalls/syscall.tbl |  6 ++-
 include/linux/timex.h  |  2 +
 kernel/time/posix-timers.c | 24 +--
 4 files changed, 76 insertions(+), 15 deletions(-)

diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
index 1c079e7bab09..37de18a11207 100644
--- a/arch/sparc/kernel/sys_sparc_64.c
+++ b/arch/sparc/kernel/sys_sparc_64.c
@@ -28,8 +28,9 @@
 #include 
 #include 
 #include 
-
+#include 
 #include 
+
 #include 
 #include 
 
@@ -544,6 +545,62 @@ SYSCALL_DEFINE2(getdomainname, char __user *, name, int, 
len)
return err;
 }
 
+SYSCALL_DEFINE1(sparc_adjtimex, struct timex __user *, txc_p)
+{
+   struct timex txc;   /* Local copy of parameter */
+   struct timex *kt = (void *)
+   int ret;
+
+   /* Copy the user data space into the kernel copy
+* structure. But bear in mind that the structures
+* may change
+*/
+   if (copy_from_user(, txc_p, sizeof(struct timex)))
+   return -EFAULT;
+
+   /*
+* override for sparc64 specific timeval type: tv_usec
+* is 32 bit wide instead of 64-bit in __kernel_timex
+*/
+   kt->time.tv_usec = txc.time.tv_usec;
+   ret = do_adjtimex(kt);
+   txc.time.tv_usec = kt->time.tv_usec;
+
+   return copy_to_user(txc_p, , sizeof(struct timex)) ? -EFAULT : ret;
+}
+
+SYSCALL_DEFINE2(sparc_clock_adjtime, const clockid_t, which_clock,struct timex 
__user *, txc_p)
+{
+   struct timex txc;   /* Local copy of parameter */
+   struct timex *kt = (void *)
+   int ret;
+
+   if (!IS_ENABLED(CONFIG_POSIX_TIMERS)) {
+   pr_err_once("process %d (%s) attempted a POSIX timer syscall "
+   "while CONFIG_POSIX_TIMERS is not set\n",
+   current->pid, current->comm);
+
+   return -ENOSYS;
+   }
+
+   /* Copy the user data space into the kernel copy
+* structure. But bear in mind that the structures
+* may change
+*/
+   if (copy_from_user(, txc_p, sizeof(struct timex)))
+   return -EFAULT;
+
+   /*
+* override for sparc64 specific timeval type: tv_usec
+* is 32 bit wide instead of 64-bit in __kernel_timex
+*/
+   kt->time.tv_usec = txc.time.tv_usec;
+   ret = do_clock_adjtime(which_clock, kt);
+   txc.time.tv_usec = kt->time.tv_usec;
+
+   return copy_to_user(txc_p, , sizeof(struct timex)) ? -EFAULT : ret;
+}
+
 SYSCALL_DEFINE5(utrap_install, utrap_entry_t, type,
utrap_handler_t, new_p, utrap_handler_t, new_d,
utrap_handler_t __user *, old_p,
diff --git a/arch/sparc/kernel/syscalls/syscall.tbl 
b/arch/sparc/kernel/syscalls/syscall.tbl
index 24ebef675184..e70110375399 100644
--- a/arch/sparc/kernel/syscalls/syscall.tbl
+++ b/arch/sparc/kernel/syscalls/syscall.tbl
@@ -258,7 +258,8 @@
 21664  sigreturn   sys_nis_syscall
 217common  clone   sys_clone
 218common  ioprio_get  sys_ioprio_get
-219common  adjtimexsys_adjtimex
compat_sys_adjtimex
+21932  adjtimexsys_adjtimex
compat_sys_adjtimex
+21964  adjtimexsys_sparc_adjtimex
 22032  sigprocmask sys_sigprocmask 
compat_sys_sigprocmask
 22064  sigprocmask sys_nis_syscall
 221common  create_module   sys_ni_syscall
@@ -377,7 +378,8 @@
 331common  prlimit64   sys_prlimit64
 332common  name_to_handle_at   sys_name_to_handle_at
 333common  open_by_handle_at   sys_open_by_handle_at   
compat_sys_open_by_handle_at
-334common  clock_adjtime   sys_clock_adjtime   
compat_sys_clock_adjtime
+33432  clock_adjtime   sys_clock_adjtime   
compat_sys_clock_adjtime
+33464  clock_adjtime   sys_sparc_clock_adjtime
 335common  syncfs  sys_syncfs
 336common  sendmmsgsys_sendmmsg
compat_sys_sendmmsg
 337common  setns   sys_setns
diff -

[PATCH v2 02/29] ia64: add statx and io_pgetevents syscalls

2019-01-18 Thread Arnd Bergmann
All architectures should implement these two, so assign numbers
and hook them up on ia64.

Signed-off-by: Arnd Bergmann 
---
 arch/ia64/kernel/syscalls/syscall.tbl | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/ia64/kernel/syscalls/syscall.tbl 
b/arch/ia64/kernel/syscalls/syscall.tbl
index e97caf51be42..52585281205b 100644
--- a/arch/ia64/kernel/syscalls/syscall.tbl
+++ b/arch/ia64/kernel/syscalls/syscall.tbl
@@ -335,3 +335,5 @@
 323common  copy_file_range sys_copy_file_range
 324common  preadv2 sys_preadv2
 325common  pwritev2sys_pwritev2
+326common  statx   sys_statx
+327common  io_pgetevents   sys_io_pgetevents
-- 
2.20.0



[PATCH v2 10/29] sh: add statx system call

2019-01-18 Thread Arnd Bergmann
statx is available on almost all other architectures but
got missed on sh, so add it now.

Signed-off-by: Arnd Bergmann 
---
 arch/sh/kernel/syscalls/syscall.tbl | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/sh/kernel/syscalls/syscall.tbl 
b/arch/sh/kernel/syscalls/syscall.tbl
index 21ec75288562..a70db013dbc7 100644
--- a/arch/sh/kernel/syscalls/syscall.tbl
+++ b/arch/sh/kernel/syscalls/syscall.tbl
@@ -390,3 +390,4 @@
 380common  copy_file_range sys_copy_file_range
 381common  preadv2 sys_preadv2
 382common  pwritev2sys_pwritev2
+383common  statx   sys_statx
-- 
2.20.0



[PATCH v2 04/29] alpha: wire up io_pgetevents system call

2019-01-18 Thread Arnd Bergmann
The io_pgetevents system call was added in linux-4.18 but has
no entry for alpha:

warning: #warning syscall io_pgetevents not implemented [-Wcpp]

Assign a the next system call number here.

Cc: sta...@vger.kernel.org
Signed-off-by: Arnd Bergmann 
---
 arch/alpha/kernel/syscalls/syscall.tbl | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/alpha/kernel/syscalls/syscall.tbl 
b/arch/alpha/kernel/syscalls/syscall.tbl
index 7b56a53be5e3..e09558edae73 100644
--- a/arch/alpha/kernel/syscalls/syscall.tbl
+++ b/arch/alpha/kernel/syscalls/syscall.tbl
@@ -451,3 +451,4 @@
 520common  preadv2 sys_preadv2
 521common  pwritev2sys_pwritev2
 522common  statx   sys_statx
+523common  io_pgetevents   sys_io_pgetevents
-- 
2.20.0



[PATCH v2 29/29] y2038: add 64-bit time_t syscalls to all 32-bit architectures

2019-01-18 Thread Arnd Bergmann
This adds 21 new system calls on each ABI that has 32-bit time_t
today. All of these have the exact same semantics as their existing
counterparts, and the new ones all have macro names that end in 'time64'
for clarification.

This gets us to the point of being able to safely use a C library
that has 64-bit time_t in user space. There are still a couple of
loose ends to tie up in various areas of the code, but this is the
big one, and should be entirely uncontroversial at this point.

In particular, there are four system calls (getitimer, setitimer,
waitid, and getrusage) that don't have a 64-bit counterpart yet,
but these can all be safely implemented in the C library by wrapping
around the existing system calls because the 32-bit time_t they
pass only counts elapsed time, not time since the epoch. They
will be dealt with later.

Signed-off-by: Arnd Bergmann 
---
The one point that still needs to be agreed on is the actual
number assignment. Following the earlier patch that added
the sysv IPC calls with common numbers where possible, I also
tried the same here, using consistent numbers on all 32-bit
architectures.

There are a couple of minor issues with this:

- On asm-generic, we now leave the numbers from 295 to 402
  unassigned, which wastes a small amount of kernel .data
  segment. Originally I had asm-generic start at 300 and
  everyone else start at 400 here, which was also not
  perfect, and we have gone beyond 400 already, so I ended
  up just using the same numbers as the rest here.

- Once we get to 512, we clash with the x32 numbers (unless
  we remove x32 support first), and probably have to skip
  a few more. I also considered using the 512..547 space
  for 32-bit-only calls (which never clash with x32), but
  that also seems to add a bit of complexity.

- On alpha, we have already used up the space up to 527
  (with a small hole between 261 and 299). We could sync
  up with that as well, but my feeling was that alpha syscalls
  are already special enough that I don't care.

Let me know if you have other ideas.
---
 arch/alpha/kernel/syscalls/syscall.tbl  |  2 +
 arch/arm/tools/syscall.tbl  | 21 ++
 arch/arm64/include/asm/unistd.h |  2 +-
 arch/arm64/include/asm/unistd32.h   | 41 +++
 arch/ia64/kernel/syscalls/syscall.tbl   |  1 +
 arch/m68k/kernel/syscalls/syscall.tbl   | 20 +
 arch/microblaze/kernel/syscalls/syscall.tbl | 21 ++
 arch/mips/kernel/syscalls/syscall_n32.tbl   | 21 ++
 arch/mips/kernel/syscalls/syscall_n64.tbl   |  1 +
 arch/mips/kernel/syscalls/syscall_o32.tbl   | 20 +
 arch/parisc/kernel/syscalls/syscall.tbl | 21 ++
 arch/powerpc/kernel/syscalls/syscall.tbl| 20 +
 arch/s390/kernel/syscalls/syscall.tbl   | 20 +
 arch/sh/kernel/syscalls/syscall.tbl | 20 +
 arch/sparc/kernel/syscalls/syscall.tbl  | 20 +
 arch/x86/entry/syscalls/syscall_32.tbl  | 20 +
 arch/xtensa/kernel/syscalls/syscall.tbl | 21 ++
 include/uapi/asm-generic/unistd.h   | 45 -
 scripts/checksyscalls.sh| 40 ++
 19 files changed, 375 insertions(+), 2 deletions(-)

diff --git a/arch/alpha/kernel/syscalls/syscall.tbl 
b/arch/alpha/kernel/syscalls/syscall.tbl
index 337b8108771a..936a33fae3c9 100644
--- a/arch/alpha/kernel/syscalls/syscall.tbl
+++ b/arch/alpha/kernel/syscalls/syscall.tbl
@@ -461,3 +461,5 @@
 530common  getegid sys_getegid
 531common  geteuid sys_geteuid
 532common  getppid sys_getppid
+# all other architectures have common numbers for new syscall, alpha
+# is the exception.
diff --git a/arch/arm/tools/syscall.tbl b/arch/arm/tools/syscall.tbl
index a96d9b5ee04e..286afdc43283 100644
--- a/arch/arm/tools/syscall.tbl
+++ b/arch/arm/tools/syscall.tbl
@@ -416,3 +416,24 @@
 399common  io_pgetevents   sys_io_pgetevents_time32
 400common  migrate_pages   sys_migrate_pages
 401common  kexec_file_load sys_kexec_file_load
+# 402 is unused
+403common  clock_gettime64 sys_clock_gettime
+404common  clock_settime64 sys_clock_settime
+405common  clock_adjtime64 sys_clock_adjtime
+406common  clock_getres_time64 sys_clock_getres
+407common  clock_nanosleep_time64  sys_clock_nanosleep
+408common  timer_gettime64 sys_timer_gettime
+409common  timer_settime64 sys_timer_settime
+410common  timerfd_gettime64   sys_timerfd_gettime
+411common  timerfd_settime64   sys_timerfd_settime
+412common  utimensat_time64sys_utimensat
+413common  pselect6_time64 sys_pselect6
+414common  ppoll_time64sys_ppoll
+416common  io_pgetevents_time64

[PATCH v2 07/29] ARM: add kexec_file_load system call number

2019-01-18 Thread Arnd Bergmann
A couple of architectures including arm64 already implement the
kexec_file_load system call, on many others we have assigned a system
call number for it, but not implemented it yet.

Adding the number in arch/arm/ lets us use the system call on arm64
systems in compat mode, and also reduces the number of differences
between architectures. If we want to implement kexec_file_load on ARM
in the future, the number assignment means that kexec tools can already
be built with the now current set of kernel headers.

Signed-off-by: Arnd Bergmann 
---
 arch/arm/tools/syscall.tbl| 1 +
 arch/arm64/include/asm/unistd.h   | 2 +-
 arch/arm64/include/asm/unistd32.h | 2 ++
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/arm/tools/syscall.tbl b/arch/arm/tools/syscall.tbl
index 86de9eb34296..20ed7e026723 100644
--- a/arch/arm/tools/syscall.tbl
+++ b/arch/arm/tools/syscall.tbl
@@ -415,3 +415,4 @@
 398common  rseqsys_rseq
 399common  io_pgetevents   sys_io_pgetevents
 400common  migrate_pages   sys_migrate_pages
+401common  kexec_file_load sys_kexec_file_load
diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h
index 261216c3336e..2c30e6f145ff 100644
--- a/arch/arm64/include/asm/unistd.h
+++ b/arch/arm64/include/asm/unistd.h
@@ -44,7 +44,7 @@
 #define __ARM_NR_compat_set_tls(__ARM_NR_COMPAT_BASE + 5)
 #define __ARM_NR_COMPAT_END(__ARM_NR_COMPAT_BASE + 0x800)
 
-#define __NR_compat_syscalls   401
+#define __NR_compat_syscalls   402
 #endif
 
 #define __ARCH_WANT_SYS_CLONE
diff --git a/arch/arm64/include/asm/unistd32.h 
b/arch/arm64/include/asm/unistd32.h
index f15bcbacb8f6..8ca1d4c304f4 100644
--- a/arch/arm64/include/asm/unistd32.h
+++ b/arch/arm64/include/asm/unistd32.h
@@ -823,6 +823,8 @@ __SYSCALL(__NR_rseq, sys_rseq)
 __SYSCALL(__NR_io_pgetevents, compat_sys_io_pgetevents)
 #define __NR_migrate_pages 400
 __SYSCALL(__NR_migrate_pages, compat_sys_migrate_pages)
+#define __NR_kexec_file_load 401
+__SYSCALL(__NR_kexec_file_load, sys_kexec_file_load)
 
 /*
  * Please add new compat syscalls above this comment and update
-- 
2.20.0



[PATCH v2 11/29] sparc64: fix sparc_ipc type conversion

2019-01-18 Thread Arnd Bergmann
__kernel_timespec and timespec are currently the same type, but once
they are different, the type cast has to be changed here.

Signed-off-by: Arnd Bergmann 
---
 arch/sparc/kernel/sys_sparc_64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
index 274ed0b9b3e0..1c079e7bab09 100644
--- a/arch/sparc/kernel/sys_sparc_64.c
+++ b/arch/sparc/kernel/sys_sparc_64.c
@@ -344,7 +344,7 @@ SYSCALL_DEFINE6(sparc_ipc, unsigned int, call, int, first, 
unsigned long, second
goto out;
case SEMTIMEDOP:
err = sys_semtimedop(first, ptr, (unsigned int)second,
-   (const struct timespec __user *)
+   (const struct __kernel_timespec __user *)
 (unsigned long) fifth);
goto out;
case SEMGET:
-- 
2.20.0



[PATCH v2 01/29] ia64: add __NR_umount2 definition

2019-01-18 Thread Arnd Bergmann
Other architectures commonly use __NR_umount2 for sys_umount,
only ia64 and alpha use __NR_umount here. In order to synchronize
the generated tables, use umount2 like everyone else, and add back
the old name from asm/unistd.h for compatibility.

The __IGNORE_* lines are now all obsolete and can be removed as
a side-effect.

Signed-off-by: Arnd Bergmann 
---
 arch/ia64/include/asm/unistd.h| 14 --
 arch/ia64/include/uapi/asm/unistd.h   |  2 ++
 arch/ia64/kernel/syscalls/syscall.tbl |  2 +-
 3 files changed, 3 insertions(+), 15 deletions(-)

diff --git a/arch/ia64/include/asm/unistd.h b/arch/ia64/include/asm/unistd.h
index 0b08ebd2dfde..9ba6110b10b9 100644
--- a/arch/ia64/include/asm/unistd.h
+++ b/arch/ia64/include/asm/unistd.h
@@ -12,20 +12,6 @@
 
 #define NR_syscalls__NR_syscalls /* length of syscall table */
 
-/*
- * The following defines stop scripts/checksyscalls.sh from complaining about
- * unimplemented system calls.  Glibc provides for each of these by using
- * more modern equivalent system calls.
- */
-#define __IGNORE_fork  /* clone() */
-#define __IGNORE_time  /* gettimeofday() */
-#define __IGNORE_alarm /* setitimer(ITIMER_REAL, ... */
-#define __IGNORE_pause /* rt_sigprocmask(), rt_sigsuspend() */
-#define __IGNORE_utime /* utimes() */
-#define __IGNORE_getpgrp   /* getpgid() */
-#define __IGNORE_vfork /* clone() */
-#define __IGNORE_umount2   /* umount() */
-
 #define __ARCH_WANT_NEW_STAT
 #define __ARCH_WANT_SYS_UTIME
 
diff --git a/arch/ia64/include/uapi/asm/unistd.h 
b/arch/ia64/include/uapi/asm/unistd.h
index b2513922dcb5..013e0bcacc39 100644
--- a/arch/ia64/include/uapi/asm/unistd.h
+++ b/arch/ia64/include/uapi/asm/unistd.h
@@ -15,6 +15,8 @@
 
 #define __NR_Linux  1024
 
+#define __NR_umount __NR_umount2
+
 #include 
 
 #endif /* _UAPI_ASM_IA64_UNISTD_H */
diff --git a/arch/ia64/kernel/syscalls/syscall.tbl 
b/arch/ia64/kernel/syscalls/syscall.tbl
index b22203b40bfe..e97caf51be42 100644
--- a/arch/ia64/kernel/syscalls/syscall.tbl
+++ b/arch/ia64/kernel/syscalls/syscall.tbl
@@ -29,7 +29,7 @@
 17 common  getpid  sys_getpid
 18 common  getppid sys_getppid
 19 common  mount   sys_mount
-20 common  umount  sys_umount
+20 common  umount2 sys_umount
 21 common  setuid  sys_setuid
 22 common  getuid  sys_getuid
 23 common  geteuid sys_geteuid
-- 
2.20.0



[PATCH v2 14/29] arch: add pkey and rseq syscall numbers everywhere

2019-01-18 Thread Arnd Bergmann
Most architectures define system call numbers for the rseq and pkey system
calls, even when they don't support the features, and perhaps never will.

Only a few architectures are missing these, so just define them anyway
for consistency. If we decide to add them later to one of these, the
system call numbers won't get out of sync then.

Signed-off-by: Arnd Bergmann 
---
 arch/alpha/include/asm/unistd.h | 4 
 arch/alpha/kernel/syscalls/syscall.tbl  | 4 
 arch/ia64/kernel/syscalls/syscall.tbl   | 4 
 arch/m68k/kernel/syscalls/syscall.tbl   | 4 
 arch/parisc/include/asm/unistd.h| 3 ---
 arch/parisc/kernel/syscalls/syscall.tbl | 4 
 arch/s390/include/asm/unistd.h  | 3 ---
 arch/s390/kernel/syscalls/syscall.tbl   | 3 +++
 arch/sh/kernel/syscalls/syscall.tbl | 4 
 arch/sparc/include/asm/unistd.h | 5 -
 arch/sparc/kernel/syscalls/syscall.tbl  | 4 
 arch/xtensa/kernel/syscalls/syscall.tbl | 1 +
 12 files changed, 28 insertions(+), 15 deletions(-)

diff --git a/arch/alpha/include/asm/unistd.h b/arch/alpha/include/asm/unistd.h
index 564ba87bdc38..31ad350b58a0 100644
--- a/arch/alpha/include/asm/unistd.h
+++ b/arch/alpha/include/asm/unistd.h
@@ -29,9 +29,5 @@
 #define __IGNORE_getppid
 #define __IGNORE_getuid
 
-/* Alpha doesn't have protection keys. */
-#define __IGNORE_pkey_mprotect
-#define __IGNORE_pkey_alloc
-#define __IGNORE_pkey_free
 
 #endif /* _ALPHA_UNISTD_H */
diff --git a/arch/alpha/kernel/syscalls/syscall.tbl 
b/arch/alpha/kernel/syscalls/syscall.tbl
index b0e247287908..25b4a7e76943 100644
--- a/arch/alpha/kernel/syscalls/syscall.tbl
+++ b/arch/alpha/kernel/syscalls/syscall.tbl
@@ -452,3 +452,7 @@
 521common  pwritev2sys_pwritev2
 522common  statx   sys_statx
 523common  io_pgetevents   sys_io_pgetevents
+524common  pkey_alloc  sys_pkey_alloc
+525common  pkey_free   sys_pkey_free
+526common  pkey_mprotect   sys_pkey_mprotect
+527common  rseqsys_rseq
diff --git a/arch/ia64/kernel/syscalls/syscall.tbl 
b/arch/ia64/kernel/syscalls/syscall.tbl
index 2e93dbdcdb80..84e03de00177 100644
--- a/arch/ia64/kernel/syscalls/syscall.tbl
+++ b/arch/ia64/kernel/syscalls/syscall.tbl
@@ -339,3 +339,7 @@
 327common  io_pgetevents   sys_io_pgetevents
 328common  perf_event_open sys_perf_event_open
 329common  seccomp sys_seccomp
+330common  pkey_alloc  sys_pkey_alloc
+331common  pkey_free   sys_pkey_free
+332common  pkey_mprotect   sys_pkey_mprotect
+333common  rseqsys_rseq
diff --git a/arch/m68k/kernel/syscalls/syscall.tbl 
b/arch/m68k/kernel/syscalls/syscall.tbl
index 5354ba02eed2..ae88b85d068e 100644
--- a/arch/m68k/kernel/syscalls/syscall.tbl
+++ b/arch/m68k/kernel/syscalls/syscall.tbl
@@ -388,6 +388,10 @@
 378common  pwritev2sys_pwritev2
 379common  statx   sys_statx
 380common  seccomp sys_seccomp
+381common  pkey_alloc  sys_pkey_alloc
+382common  pkey_free   sys_pkey_free
+383common  pkey_mprotect   sys_pkey_mprotect
+384common  rseqsys_rseq
 # room for arch specific calls
 393common  semget  sys_semget
 394common  semctl  sys_semctl
diff --git a/arch/parisc/include/asm/unistd.h b/arch/parisc/include/asm/unistd.h
index c2c2afb28941..9ec1026af877 100644
--- a/arch/parisc/include/asm/unistd.h
+++ b/arch/parisc/include/asm/unistd.h
@@ -12,9 +12,6 @@
 
 #define __IGNORE_select/* newselect */
 #define __IGNORE_fadvise64 /* fadvise64_64 */
-#define __IGNORE_pkey_mprotect
-#define __IGNORE_pkey_alloc
-#define __IGNORE_pkey_free
 
 #ifndef ASM_LINE_SEP
 # define ASM_LINE_SEP ;
diff --git a/arch/parisc/kernel/syscalls/syscall.tbl 
b/arch/parisc/kernel/syscalls/syscall.tbl
index 9bbd2f9f56c8..e07231de3597 100644
--- a/arch/parisc/kernel/syscalls/syscall.tbl
+++ b/arch/parisc/kernel/syscalls/syscall.tbl
@@ -367,3 +367,7 @@
 348common  pwritev2sys_pwritev2
compat_sys_pwritev2
 349common  statx   sys_statx
 350common  io_pgetevents   sys_io_pgetevents   
compat_sys_io_pgetevents
+351common  pkey_alloc  sys_pkey_alloc
+352common  pkey_free   sys_pkey_free
+353common  pkey_mprotect   sys_pkey_mprotect
+354common  rseqsys_rseq
diff --git a/arch/s390/include/asm/unistd.h b/arch/s390/include/asm/unistd.h
index a1fbf15d53aa..ed08f114ee91 100644
--- a/arch/s390/include/asm/unistd.h
+++ b/arch/s390/include/asm

[PATCH v2 08/29] m68k: assign syscall number for seccomp

2019-01-18 Thread Arnd Bergmann
Most architectures have assigned a numbers for the seccomp syscall
even when they do not implement it.

m68k is an exception here, so for consistency lets add the number.
Unless CONFIG_SECCOMP is implemented, the system call just
returns -ENOSYS.

Signed-off-by: Arnd Bergmann 
---
 arch/m68k/kernel/syscalls/syscall.tbl | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/m68k/kernel/syscalls/syscall.tbl 
b/arch/m68k/kernel/syscalls/syscall.tbl
index 1a95c4a1bc0d..85779d6ef935 100644
--- a/arch/m68k/kernel/syscalls/syscall.tbl
+++ b/arch/m68k/kernel/syscalls/syscall.tbl
@@ -387,3 +387,4 @@
 377common  preadv2 sys_preadv2
 378common  pwritev2sys_pwritev2
 379common  statx   sys_statx
+380common  seccomp sys_seccomp
-- 
2.20.0



[PATCH v2 15/29] alpha: add standard statfs64/fstatfs64 syscalls

2019-01-18 Thread Arnd Bergmann
As Joseph Myers points out, alpha has never had a standard statfs64
interface and instead returns only 32-bit numbers here.

While there is an old osf_statfs64 system call that returns additional
data, this has some other quirks and does not get used in glibc.

I considered making the stat64 structure layout compatible with
with the one used by the kernel on most other 64 bit architecture that
implement it (ia64, parisc, powerpc, and sparc), but in the end
decided to stay with the one that was traditionally defined in
the alpha headers but not used, since this is also what glibc
exposes to user space.

Signed-off-by: Arnd Bergmann 
---
 arch/alpha/kernel/syscalls/syscall.tbl | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/alpha/kernel/syscalls/syscall.tbl 
b/arch/alpha/kernel/syscalls/syscall.tbl
index 25b4a7e76943..0ebd59fdcb8b 100644
--- a/arch/alpha/kernel/syscalls/syscall.tbl
+++ b/arch/alpha/kernel/syscalls/syscall.tbl
@@ -456,3 +456,5 @@
 525common  pkey_free   sys_pkey_free
 526common  pkey_mprotect   sys_pkey_mprotect
 527common  rseqsys_rseq
+528common  statfs64sys_statfs64
+529common  fstatfs64   sys_fstatfs64
-- 
2.20.0



[PATCH v2 16/29] alpha: add generic get{eg,eu,g,p,u,pp}id() syscalls

2019-01-18 Thread Arnd Bergmann
Alpha has traditionally followed the OSF1 calling conventions
here, with its getxpid, getxuid, getxgid system calls returning
two different values in separate registers.

Following what glibc has done here, we can define getpid,
getuid and getgid to be aliases for getxpid, getxuid and getxgid
respectively, and add new system call numbers for getppid, geteuid
and getegid.

Signed-off-by: Arnd Bergmann 
---
 arch/alpha/include/asm/unistd.h| 11 ---
 arch/alpha/include/uapi/asm/unistd.h   |  5 +
 arch/alpha/kernel/syscalls/syscall.tbl |  3 +++
 3 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/arch/alpha/include/asm/unistd.h b/arch/alpha/include/asm/unistd.h
index 31ad350b58a0..986f5da9b7d8 100644
--- a/arch/alpha/include/asm/unistd.h
+++ b/arch/alpha/include/asm/unistd.h
@@ -19,15 +19,4 @@
 #define __ARCH_WANT_SYS_VFORK
 #define __ARCH_WANT_SYS_CLONE
 
-/*
- * Ignore legacy syscalls that we don't use.
- */
-#define __IGNORE_getegid
-#define __IGNORE_geteuid
-#define __IGNORE_getgid
-#define __IGNORE_getpid
-#define __IGNORE_getppid
-#define __IGNORE_getuid
-
-
 #endif /* _ALPHA_UNISTD_H */
diff --git a/arch/alpha/include/uapi/asm/unistd.h 
b/arch/alpha/include/uapi/asm/unistd.h
index 4507071f995f..71fd5db06866 100644
--- a/arch/alpha/include/uapi/asm/unistd.h
+++ b/arch/alpha/include/uapi/asm/unistd.h
@@ -7,6 +7,11 @@
 #define __NR_umount__NR_umount2
 #define __NR_osf_shmat __NR_shmat
 
+/* These return an extra value but can be used as aliases */
+#define __NR_getpid__NR_getxpid
+#define __NR_getuid__NR_getxuid
+#define __NR_getgid__NR_getxgid
+
 #include 
 
 #endif /* _UAPI_ALPHA_UNISTD_H */
diff --git a/arch/alpha/kernel/syscalls/syscall.tbl 
b/arch/alpha/kernel/syscalls/syscall.tbl
index 0ebd59fdcb8b..337b8108771a 100644
--- a/arch/alpha/kernel/syscalls/syscall.tbl
+++ b/arch/alpha/kernel/syscalls/syscall.tbl
@@ -458,3 +458,6 @@
 527common  rseqsys_rseq
 528common  statfs64sys_statfs64
 529common  fstatfs64   sys_fstatfs64
+530common  getegid sys_getegid
+531common  geteuid sys_geteuid
+532common  getppid sys_getppid
-- 
2.20.0



[PATCH v2 26/29] y2038: use time32 syscall names on 32-bit

2019-01-18 Thread Arnd Bergmann
This is the big flip, where all 32-bit architectures set COMPAT_32BIT_TIME
abd use the _time32 system calls from the former compat layer instead
of the system calls that take __kernel_timespec and similar arguments.

The temporary redirects for __kernel_timespec, __kernel_itimerspec
and __kernel_timex can get removed with this.

It would be easy to split this commit by architecture, but with the new
generated system call tables, it's easy enough to do it all at once,
which makes it a little easier to check that the changes are the same
in each table.

Signed-off-by: Arnd Bergmann 
---
 arch/Kconfig|  2 +-
 arch/arm/kernel/sys_oabi-compat.c   |  8 +-
 arch/arm/tools/syscall.tbl  | 46 ++--
 arch/m68k/kernel/syscalls/syscall.tbl   | 42 +--
 arch/microblaze/kernel/syscalls/syscall.tbl | 46 ++--
 arch/mips/kernel/syscalls/syscall_o32.tbl   | 44 +--
 arch/parisc/kernel/syscalls/syscall.tbl | 69 +++--
 arch/powerpc/kernel/syscalls/syscall.tbl| 82 +++--
 arch/sh/kernel/syscalls/syscall.tbl | 42 +--
 arch/sparc/kernel/syscalls/syscall.tbl  | 64 ++--
 arch/x86/entry/syscalls/syscall_32.tbl  | 44 +--
 arch/xtensa/kernel/syscalls/syscall.tbl | 44 +--
 include/uapi/asm-generic/unistd.h   | 56 +++---
 13 files changed, 335 insertions(+), 254 deletions(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index 4cfb6de48f79..46db715a7f42 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -759,7 +759,7 @@ config 64BIT_TIME
  handling.
 
 config COMPAT_32BIT_TIME
-   def_bool (!64BIT && 64BIT_TIME) || COMPAT
+   def_bool !64BIT || COMPAT
help
  This enables 32 bit time_t support in addition to 64 bit time_t 
support.
  This is relevant on all 32-bit architectures, and 64-bit architectures
diff --git a/arch/arm/kernel/sys_oabi-compat.c 
b/arch/arm/kernel/sys_oabi-compat.c
index 92ab36f38795..acd054a42ba2 100644
--- a/arch/arm/kernel/sys_oabi-compat.c
+++ b/arch/arm/kernel/sys_oabi-compat.c
@@ -317,10 +317,10 @@ struct oabi_sembuf {
 asmlinkage long sys_oabi_semtimedop(int semid,
struct oabi_sembuf __user *tsops,
unsigned nsops,
-   const struct timespec __user *timeout)
+   const struct old_timespec32 __user *timeout)
 {
struct sembuf *sops;
-   struct timespec local_timeout;
+   struct old_timespec32 local_timeout;
long err;
int i;
 
@@ -350,7 +350,7 @@ asmlinkage long sys_oabi_semtimedop(int semid,
} else {
mm_segment_t fs = get_fs();
set_fs(KERNEL_DS);
-   err = sys_semtimedop(semid, sops, nsops, timeout);
+   err = sys_semtimedop_time32(semid, sops, nsops, timeout);
set_fs(fs);
}
kfree(sops);
@@ -375,7 +375,7 @@ asmlinkage int sys_oabi_ipc(uint call, int first, int 
second, int third,
return  sys_oabi_semtimedop(first,
(struct oabi_sembuf __user *)ptr,
second,
-   (const struct timespec __user 
*)fifth);
+   (const struct old_timespec32 __user 
*)fifth);
default:
return sys_ipc(call, first, second, third, ptr, fifth);
}
diff --git a/arch/arm/tools/syscall.tbl b/arch/arm/tools/syscall.tbl
index b54b7f2bc24a..200f4b878a46 100644
--- a/arch/arm/tools/syscall.tbl
+++ b/arch/arm/tools/syscall.tbl
@@ -137,7 +137,7 @@
 121common  setdomainname   sys_setdomainname
 122common  uname   sys_newuname
 # 123 was sys_modify_ldt
-124common  adjtimexsys_adjtimex
+124common  adjtimexsys_adjtimex_time32
 125common  mprotectsys_mprotect
 126common  sigprocmask sys_sigprocmask
 # 127 was sys_create_module
@@ -174,8 +174,8 @@
 158common  sched_yield sys_sched_yield
 159common  sched_get_priority_max  sys_sched_get_priority_max
 160common  sched_get_priority_min  sys_sched_get_priority_min
-161common  sched_rr_get_interval   sys_sched_rr_get_interval
-162common  nanosleep   sys_nanosleep
+161common  sched_rr_get_interval   sys_sched_rr_get_interval_time32
+162common  nanosleep   sys_nanosleep_time32
 163common  mremap  sys_mremap
 164common  setresuid   sys_setresuid16
 165common  getresuid   sys_getresuid16
@@ -190,7 +190,7 @@
 174common  rt_sigactionsys_rt_sigaction
 175common  rt_sigprocmask  sys_rt_sigprocmask
 176common  rt_sigpending   sys_rt_sigpending
-177  

[PATCH v2 17/29] syscalls: remove obsolete __IGNORE_ macros

2019-01-18 Thread Arnd Bergmann
These are all for ignoring the lack of obsolete system calls,
which have been marked the same way in scripts/checksyscall.sh,
so these can be removed.

Signed-off-by: Arnd Bergmann 
---
 arch/mips/include/asm/unistd.h   | 16 
 arch/parisc/include/asm/unistd.h |  3 ---
 arch/s390/include/asm/unistd.h   |  2 --
 arch/xtensa/include/asm/unistd.h | 12 
 4 files changed, 33 deletions(-)

diff --git a/arch/mips/include/asm/unistd.h b/arch/mips/include/asm/unistd.h
index b23d74a601b3..5e9eeb83d8d4 100644
--- a/arch/mips/include/asm/unistd.h
+++ b/arch/mips/include/asm/unistd.h
@@ -53,22 +53,6 @@
 #define __ARCH_WANT_SYS_FORK
 #define __ARCH_WANT_SYS_CLONE
 
-/* whitelists for checksyscalls */
-#define __IGNORE_select
-#define __IGNORE_vfork
-#define __IGNORE_time
-#define __IGNORE_uselib
-#define __IGNORE_fadvise64_64
-#define __IGNORE_getdents64
-#if _MIPS_SIM == _MIPS_SIM_NABI32
-#define __IGNORE_truncate64
-#define __IGNORE_ftruncate64
-#define __IGNORE_stat64
-#define __IGNORE_lstat64
-#define __IGNORE_fstat64
-#define __IGNORE_fstatat64
-#endif
-
 #endif /* !__ASSEMBLY__ */
 
 #endif /* _ASM_UNISTD_H */
diff --git a/arch/parisc/include/asm/unistd.h b/arch/parisc/include/asm/unistd.h
index 9ec1026af877..385eae49ed02 100644
--- a/arch/parisc/include/asm/unistd.h
+++ b/arch/parisc/include/asm/unistd.h
@@ -10,9 +10,6 @@
 
 #define SYS_ify(syscall_name)   __NR_##syscall_name
 
-#define __IGNORE_select/* newselect */
-#define __IGNORE_fadvise64 /* fadvise64_64 */
-
 #ifndef ASM_LINE_SEP
 # define ASM_LINE_SEP ;
 #endif
diff --git a/arch/s390/include/asm/unistd.h b/arch/s390/include/asm/unistd.h
index ed08f114ee91..59202ceea1f6 100644
--- a/arch/s390/include/asm/unistd.h
+++ b/arch/s390/include/asm/unistd.h
@@ -10,8 +10,6 @@
 #include 
 #include 
 
-#define __IGNORE_time
-
 #define __ARCH_WANT_NEW_STAT
 #define __ARCH_WANT_OLD_READDIR
 #define __ARCH_WANT_SYS_ALARM
diff --git a/arch/xtensa/include/asm/unistd.h b/arch/xtensa/include/asm/unistd.h
index 0d34629dafc5..81cc52ea1bd5 100644
--- a/arch/xtensa/include/asm/unistd.h
+++ b/arch/xtensa/include/asm/unistd.h
@@ -10,18 +10,6 @@
 #define __ARCH_WANT_SYS_UTIME
 #define __ARCH_WANT_SYS_GETPGRP
 
-/* 
- * Ignore legacy system calls in the checksyscalls.sh script
- */
-
-#define __IGNORE_fork  /* use clone */
-#define __IGNORE_time
-#define __IGNORE_alarm /* use setitimer */
-#define __IGNORE_pause
-#define __IGNORE_mmap  /* use mmap2 */
-#define __IGNORE_vfork /* use clone */
-#define __IGNORE_fadvise64 /* use fadvise64_64 */
-
 #define NR_syscalls__NR_syscalls
 
 #endif /* _XTENSA_UNISTD_H */
-- 
2.20.0



[PATCH v2 18/29] time: make adjtime compat handling available for 32 bit

2019-01-18 Thread Arnd Bergmann
We want to reuse the compat_timex handling on 32-bit architectures the
same way we are using the compat handling for timespec when moving to
64-bit time_t.

Move all definitions related to compat_timex out of the compat code
into the normal timekeeping code, along with a rename to old_timex32,
corresponding to the timespec/timeval structures, and make it controlled
by CONFIG_COMPAT_32BIT_TIME, which 32-bit architectures will then select.

Signed-off-by: Arnd Bergmann 
---
 include/linux/compat.h | 35 ++-
 include/linux/time32.h | 32 -
 kernel/compat.c| 64 --
 kernel/time/posix-timers.c | 14 ++--
 kernel/time/time.c | 70 +++---
 5 files changed, 102 insertions(+), 113 deletions(-)

diff --git a/include/linux/compat.h b/include/linux/compat.h
index 056be0d03722..657ca6abd855 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -132,37 +132,6 @@ struct compat_tms {
compat_clock_t  tms_cstime;
 };
 
-struct compat_timex {
-   compat_uint_t modes;
-   compat_long_t offset;
-   compat_long_t freq;
-   compat_long_t maxerror;
-   compat_long_t esterror;
-   compat_int_t status;
-   compat_long_t constant;
-   compat_long_t precision;
-   compat_long_t tolerance;
-   struct old_timeval32 time;
-   compat_long_t tick;
-   compat_long_t ppsfreq;
-   compat_long_t jitter;
-   compat_int_t shift;
-   compat_long_t stabil;
-   compat_long_t jitcnt;
-   compat_long_t calcnt;
-   compat_long_t errcnt;
-   compat_long_t stbcnt;
-   compat_int_t tai;
-
-   compat_int_t:32; compat_int_t:32; compat_int_t:32; compat_int_t:32;
-   compat_int_t:32; compat_int_t:32; compat_int_t:32; compat_int_t:32;
-   compat_int_t:32; compat_int_t:32; compat_int_t:32;
-};
-
-struct timex;
-int compat_get_timex(struct timex *, const struct compat_timex __user *);
-int compat_put_timex(struct compat_timex __user *, const struct timex *);
-
 #define _COMPAT_NSIG_WORDS (_COMPAT_NSIG / _COMPAT_NSIG_BPW)
 
 typedef struct {
@@ -808,7 +777,7 @@ asmlinkage long compat_sys_gettimeofday(struct 
old_timeval32 __user *tv,
struct timezone __user *tz);
 asmlinkage long compat_sys_settimeofday(struct old_timeval32 __user *tv,
struct timezone __user *tz);
-asmlinkage long compat_sys_adjtimex(struct compat_timex __user *utp);
+asmlinkage long compat_sys_adjtimex(struct old_timex32 __user *utp);
 
 /* kernel/timer.c */
 asmlinkage long compat_sys_sysinfo(struct compat_sysinfo __user *info);
@@ -911,7 +880,7 @@ asmlinkage long compat_sys_open_by_handle_at(int mountdirfd,
 struct file_handle __user *handle,
 int flags);
 asmlinkage long compat_sys_clock_adjtime(clockid_t which_clock,
-struct compat_timex __user *tp);
+struct old_timex32 __user *tp);
 asmlinkage long compat_sys_sendmmsg(int fd, struct compat_mmsghdr __user *mmsg,
unsigned vlen, unsigned int flags);
 asmlinkage ssize_t compat_sys_process_vm_readv(compat_pid_t pid,
diff --git a/include/linux/time32.h b/include/linux/time32.h
index 118b9977080c..820a22e2b98b 100644
--- a/include/linux/time32.h
+++ b/include/linux/time32.h
@@ -10,6 +10,7 @@
  */
 
 #include 
+#include 
 
 #define TIME_T_MAX (time_t)((1UL << ((sizeof(time_t) << 3) - 1)) - 1)
 
@@ -35,13 +36,42 @@ struct old_utimbuf32 {
old_time32_tmodtime;
 };
 
+struct old_timex32 {
+   u32 modes;
+   s32 offset;
+   s32 freq;
+   s32 maxerror;
+   s32 esterror;
+   s32 status;
+   s32 constant;
+   s32 precision;
+   s32 tolerance;
+   struct old_timeval32 time;
+   s32 tick;
+   s32 ppsfreq;
+   s32 jitter;
+   s32 shift;
+   s32 stabil;
+   s32 jitcnt;
+   s32 calcnt;
+   s32 errcnt;
+   s32 stbcnt;
+   s32 tai;
+
+   s32:32; s32:32; s32:32; s32:32;
+   s32:32; s32:32; s32:32; s32:32;
+   s32:32; s32:32; s32:32;
+};
+
 extern int get_old_timespec32(struct timespec64 *, const void __user *);
 extern int put_old_timespec32(const struct timespec64 *, void __user *);
 extern int get_old_itimerspec32(struct itimerspec64 *its,
const struct old_itimerspec32 __user *uits);
 extern int put_old_itimerspec32(const struct itimerspec64 *its,
struct old_itimerspec32 __user *uits);
-
+struct timex;
+int get_old_timex32(struct timex *, const struct old_timex32 __user *);
+int put_old_timex32(struct old_timex32 __user *, const struct timex *);
 
 #if __BITS_PER_LONG == 64
 
diff --git a/kernel/compat.c b/kernel/compat.c
index f01affa17e22..d8a36c6ad7c9 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -20,7 +20,6 

[PATCH v2 19/29] time: Add struct __kernel_timex

2019-01-18 Thread Arnd Bergmann
From: Deepa Dinamani 

struct timex uses struct timeval internally.
struct timeval is not y2038 safe.
Introduce a new UAPI type struct __kernel_timex
that is y2038 safe.

struct __kernel_timex uses a timeval type that is
similar to struct __kernel_timespec which preserves the
same structure size across 32 bit and 64 bit ABIs.
struct __kernel_timex also restructures other members of the
structure to make the structure the same on 64 bit and 32 bit
architectures.
Note that struct __kernel_timex is the same as struct timex
on a 64 bit architecture.

The above solution is similar to other new y2038 syscalls
that are being introduced: both 32 bit and 64 bit ABIs
have a common entry, and the compat entry supports the old 32 bit
syscall interface.

Alternatives considered were:
1. Add new time type to struct timex that makes use of padded
   bits. This time type could be based on the struct __kernel_timespec.
   modes will use a flag to notify which time structure should be
   used internally.
   This needs some application level changes on both 64 bit and 32 bit
   architectures. Although 64 bit machines could continue to use the
   older timeval structure without any changes.

2. Add a new u8 type to struct timex that makes use of padded bits. This
   can be used to save higher order tv_sec bits. modes will use a flag to
   notify presence of such a type.
   This will need some application level changes on 32 bit architectures.

3. Add a new compat_timex structure that differs in only the size of the
   time type; keep rest of struct timex the same.
   This requires extra syscalls to manage all 3 cases on 64 bit
   architectures. This will not need any application level changes but will
   add more complexity from kernel side.

Signed-off-by: Deepa Dinamani 
---
 include/linux/timex.h  |  7 +++
 include/uapi/linux/timex.h | 41 ++
 2 files changed, 48 insertions(+)

diff --git a/include/linux/timex.h b/include/linux/timex.h
index 39c25dbebfe8..7f40e9e42ecc 100644
--- a/include/linux/timex.h
+++ b/include/linux/timex.h
@@ -53,6 +53,13 @@
 #ifndef _LINUX_TIMEX_H
 #define _LINUX_TIMEX_H
 
+/* CONFIG_64BIT_TIME enables new 64 bit time_t syscalls in the compat path
+ * and 32-bit emulation.
+ */
+#ifndef CONFIG_64BIT_TIME
+#define __kernel_timex timex
+#endif
+
 #include 
 
 #define ADJ_ADJTIME0x8000  /* switch between adjtime/adjtimex 
modes */
diff --git a/include/uapi/linux/timex.h b/include/uapi/linux/timex.h
index 92685d826444..a1c6b73016a5 100644
--- a/include/uapi/linux/timex.h
+++ b/include/uapi/linux/timex.h
@@ -92,6 +92,47 @@ struct timex {
int  :32; int  :32; int  :32;
 };
 
+struct __kernel_timex_timeval {
+   __kernel_time64_t   tv_sec;
+   long long   tv_usec;
+};
+
+#ifndef __kernel_timex
+struct __kernel_timex {
+   unsigned int modes; /* mode selector */
+   int :32;/* pad */
+   long long offset;   /* time offset (usec) */
+   long long freq; /* frequency offset (scaled ppm) */
+   long long maxerror;/* maximum error (usec) */
+   long long esterror;/* estimated error (usec) */
+   int status; /* clock command/status */
+   int :32;/* pad */
+   long long constant;/* pll time constant */
+   long long precision;/* clock precision (usec) (read only) */
+   long long tolerance;/* clock frequency tolerance (ppm)
+  * (read only)
+  */
+   struct __kernel_timex_timeval time; /* (read only, except for 
ADJ_SETOFFSET) */
+   long long tick; /* (modified) usecs between clock ticks */
+
+   long long ppsfreq;/* pps frequency (scaled ppm) (ro) */
+   long long jitter; /* pps jitter (us) (ro) */
+   int shift;  /* interval duration (s) (shift) (ro) */
+   int :32;/* pad */
+   long long stabil;/* pps stability (scaled ppm) (ro) */
+   long long jitcnt; /* jitter limit exceeded (ro) */
+   long long calcnt; /* calibration intervals (ro) */
+   long long errcnt; /* calibration errors (ro) */
+   long long stbcnt; /* stability limit exceeded (ro) */
+
+   int tai;/* TAI offset (ro) */
+
+   int  :32; int  :32; int  :32; int  :32;
+   int  :32; int  :32; int  :32; int  :32;
+   int  :32; int  :32; int  :32;
+};
+#endif
+
 /*
  * Mode codes (timex.mode)
  */
-- 
2.20.0



[PATCH v2 12/29] ipc: rename old-style shmctl/semctl/msgctl syscalls

2019-01-18 Thread Arnd Bergmann
The behavior of these system calls is slightly different between
architectures, as determined by the CONFIG_ARCH_WANT_IPC_PARSE_VERSION
symbol. Most architectures that implement the split IPC syscalls don't set
that symbol and only get the modern version, but alpha, arm, microblaze,
mips-n32, mips-n64 and xtensa expect the caller to pass the IPC_64 flag.

For the architectures that so far only implement sys_ipc(), i.e. m68k,
mips-o32, powerpc, s390, sh, sparc, and x86-32, we want the new behavior
when adding the split syscalls, so we need to distinguish between the
two groups of architectures.

The method I picked for this distinction is to have a separate system call
entry point: sys_old_*ctl() now uses ipc_parse_version, while sys_*ctl()
does not. The system call tables of the five architectures are changed
accordingly.

As an additional benefit, we no longer need the configuration specific
definition for ipc_parse_version(), it always does the same thing now,
but simply won't get called on architectures with the modern interface.

A small downside is that on architectures that do set
ARCH_WANT_IPC_PARSE_VERSION, we now have an extra set of entry points
that are never called. They only add a few bytes of bloat, so it seems
better to keep them compared to adding yet another Kconfig symbol.
I considered adding new syscall numbers for the IPC_64 variants for
consistency, but decided against that for now.

Signed-off-by: Arnd Bergmann 
---
 arch/alpha/kernel/syscalls/syscall.tbl  |  6 ++--
 arch/arm/tools/syscall.tbl  |  6 ++--
 arch/arm64/include/asm/unistd32.h   |  6 ++--
 arch/microblaze/kernel/syscalls/syscall.tbl |  6 ++--
 arch/mips/kernel/syscalls/syscall_n32.tbl   |  6 ++--
 arch/mips/kernel/syscalls/syscall_n64.tbl   |  6 ++--
 arch/xtensa/kernel/syscalls/syscall.tbl |  6 ++--
 include/linux/syscalls.h|  3 ++
 ipc/msg.c   | 39 
 ipc/sem.c   | 39 
 ipc/shm.c   | 40 +
 ipc/syscall.c   | 12 +++
 ipc/util.h  | 21 ---
 kernel/sys_ni.c |  3 ++
 14 files changed, 137 insertions(+), 62 deletions(-)

diff --git a/arch/alpha/kernel/syscalls/syscall.tbl 
b/arch/alpha/kernel/syscalls/syscall.tbl
index f920b65e8c49..b0e247287908 100644
--- a/arch/alpha/kernel/syscalls/syscall.tbl
+++ b/arch/alpha/kernel/syscalls/syscall.tbl
@@ -174,17 +174,17 @@
 187common  osf_alt_sigpending  sys_ni_syscall
 188common  osf_alt_setsid  sys_ni_syscall
 199common  osf_swapon  sys_swapon
-200common  msgctl  sys_msgctl
+200common  msgctl  sys_old_msgctl
 201common  msgget  sys_msgget
 202common  msgrcv  sys_msgrcv
 203common  msgsnd  sys_msgsnd
-204common  semctl  sys_semctl
+204common  semctl  sys_old_semctl
 205common  semget  sys_semget
 206common  semop   sys_semop
 207common  osf_utsname sys_osf_utsname
 208common  lchown  sys_lchown
 209common  shmat   sys_shmat
-210common  shmctl  sys_shmctl
+210common  shmctl  sys_old_shmctl
 211common  shmdt   sys_shmdt
 212common  shmget  sys_shmget
 213common  osf_mvalid  sys_ni_syscall
diff --git a/arch/arm/tools/syscall.tbl b/arch/arm/tools/syscall.tbl
index 20ed7e026723..b54b7f2bc24a 100644
--- a/arch/arm/tools/syscall.tbl
+++ b/arch/arm/tools/syscall.tbl
@@ -314,15 +314,15 @@
 297common  recvmsg sys_recvmsg
 298common  semop   sys_semop   sys_oabi_semop
 299common  semget  sys_semget
-300common  semctl  sys_semctl
+300common  semctl  sys_old_semctl
 301common  msgsnd  sys_msgsnd
 302common  msgrcv  sys_msgrcv
 303common  msgget  sys_msgget
-304common  msgctl  sys_msgctl
+304common  msgctl  sys_old_msgctl
 305common  shmat   sys_shmat
 306common  shmdt   sys_shmdt
 307common  shmget  sys_shmget
-308common  shmctl  sys_shmctl
+308common  shmctl  sys_old_shmctl
 309common  add_key sys_add_key
 310common  request_key sys_request_key
 311common  keyctl  sys_keyctl
diff --git a/arch/arm64/include/asm/unistd32

[PATCH v2 27/29] y2038: remove struct definition redirects

2019-01-18 Thread Arnd Bergmann
We now use 64-bit time_t on all architectures, so the __kernel_timex,
__kernel_timeval and __kernel_timespec redirects can be removed
after having served their purpose.

This makes it all much less confusing, as the __kernel_* types
now always refer to the same layout based on 64-bit time_t across
all 32-bit and 64-bit architectures.

Signed-off-by: Arnd Bergmann 
---
 include/linux/time64.h | 8 
 include/linux/timex.h  | 7 ---
 include/uapi/linux/time.h  | 4 
 include/uapi/linux/timex.h | 2 --
 4 files changed, 21 deletions(-)

diff --git a/include/linux/time64.h b/include/linux/time64.h
index 05634afba0db..f38d382ffec1 100644
--- a/include/linux/time64.h
+++ b/include/linux/time64.h
@@ -7,14 +7,6 @@
 typedef __s64 time64_t;
 typedef __u64 timeu64_t;
 
-/* CONFIG_64BIT_TIME enables new 64 bit time_t syscalls in the compat path
- * and 32-bit emulation.
- */
-#ifndef CONFIG_64BIT_TIME
-#define __kernel_timespec timespec
-#define __kernel_itimerspec itimerspec
-#endif
-
 #include 
 
 struct timespec64 {
diff --git a/include/linux/timex.h b/include/linux/timex.h
index 4aff9f0d1367..ce0859763670 100644
--- a/include/linux/timex.h
+++ b/include/linux/timex.h
@@ -53,13 +53,6 @@
 #ifndef _LINUX_TIMEX_H
 #define _LINUX_TIMEX_H
 
-/* CONFIG_64BIT_TIME enables new 64 bit time_t syscalls in the compat path
- * and 32-bit emulation.
- */
-#ifndef CONFIG_64BIT_TIME
-#define __kernel_timex timex
-#endif
-
 #include 
 
 #define ADJ_ADJTIME0x8000  /* switch between adjtime/adjtimex 
modes */
diff --git a/include/uapi/linux/time.h b/include/uapi/linux/time.h
index 6b56a2208be7..b03f8717c312 100644
--- a/include/uapi/linux/time.h
+++ b/include/uapi/linux/time.h
@@ -42,19 +42,15 @@ struct itimerval {
struct timeval it_value;/* current value */
 };
 
-#ifndef __kernel_timespec
 struct __kernel_timespec {
__kernel_time64_t   tv_sec; /* seconds */
long long   tv_nsec;/* nanoseconds */
 };
-#endif
 
-#ifndef __kernel_itimerspec
 struct __kernel_itimerspec {
struct __kernel_timespec it_interval;/* timer period */
struct __kernel_timespec it_value;   /* timer expiration */
 };
-#endif
 
 /*
  * legacy timeval structure, only embedded in structures that
diff --git a/include/uapi/linux/timex.h b/include/uapi/linux/timex.h
index a1c6b73016a5..9f517f9010bb 100644
--- a/include/uapi/linux/timex.h
+++ b/include/uapi/linux/timex.h
@@ -97,7 +97,6 @@ struct __kernel_timex_timeval {
long long   tv_usec;
 };
 
-#ifndef __kernel_timex
 struct __kernel_timex {
unsigned int modes; /* mode selector */
int :32;/* pad */
@@ -131,7 +130,6 @@ struct __kernel_timex {
int  :32; int  :32; int  :32; int  :32;
int  :32; int  :32; int  :32;
 };
-#endif
 
 /*
  * Mode codes (timex.mode)
-- 
2.20.0



[PATCH v2 05/29] alpha: update syscall macro definitions

2019-01-18 Thread Arnd Bergmann
Other architectures commonly use __NR_umount2 for sys_umount,
only ia64 and alpha use __NR_umount here. In order to synchronize
the generated tables, use umount2 like everyone else, and add back
the old name from asm/unistd.h for compatibility.

For shmat, alpha uses the osf_shmat name, we can do the same thing
here, which means we don't have to add an entry in the __IGNORE
list now that shmat is mandatory everywhere

alarm, creat, pause, time, and utime are optional everywhere
these days, no need to list them here any more.

I considered also adding the regular versions of the get*id system
calls that have different names and calling conventions on alpha,
which would further help unify the syscall ABI, but for now
I decided against that.

Signed-off-by: Arnd Bergmann 
---
 arch/alpha/include/asm/unistd.h| 6 --
 arch/alpha/include/uapi/asm/unistd.h   | 5 +
 arch/alpha/kernel/syscalls/syscall.tbl | 4 ++--
 3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/arch/alpha/include/asm/unistd.h b/arch/alpha/include/asm/unistd.h
index 21b706a5b772..564ba87bdc38 100644
--- a/arch/alpha/include/asm/unistd.h
+++ b/arch/alpha/include/asm/unistd.h
@@ -22,18 +22,12 @@
 /*
  * Ignore legacy syscalls that we don't use.
  */
-#define __IGNORE_alarm
-#define __IGNORE_creat
 #define __IGNORE_getegid
 #define __IGNORE_geteuid
 #define __IGNORE_getgid
 #define __IGNORE_getpid
 #define __IGNORE_getppid
 #define __IGNORE_getuid
-#define __IGNORE_pause
-#define __IGNORE_time
-#define __IGNORE_utime
-#define __IGNORE_umount2
 
 /* Alpha doesn't have protection keys. */
 #define __IGNORE_pkey_mprotect
diff --git a/arch/alpha/include/uapi/asm/unistd.h 
b/arch/alpha/include/uapi/asm/unistd.h
index 9ba724f116f1..4507071f995f 100644
--- a/arch/alpha/include/uapi/asm/unistd.h
+++ b/arch/alpha/include/uapi/asm/unistd.h
@@ -2,6 +2,11 @@
 #ifndef _UAPI_ALPHA_UNISTD_H
 #define _UAPI_ALPHA_UNISTD_H
 
+/* These are traditionally the names linux-alpha uses for
+ * the two otherwise generic system calls */
+#define __NR_umount__NR_umount2
+#define __NR_osf_shmat __NR_shmat
+
 #include 
 
 #endif /* _UAPI_ALPHA_UNISTD_H */
diff --git a/arch/alpha/kernel/syscalls/syscall.tbl 
b/arch/alpha/kernel/syscalls/syscall.tbl
index e09558edae73..f920b65e8c49 100644
--- a/arch/alpha/kernel/syscalls/syscall.tbl
+++ b/arch/alpha/kernel/syscalls/syscall.tbl
@@ -29,7 +29,7 @@
 19 common  lseek   sys_lseek
 20 common  getxpid sys_getxpid
 21 common  osf_mount   sys_osf_mount
-22 common  umount  sys_umount
+22 common  umount2 sys_umount
 23 common  setuid  sys_setuid
 24 common  getxuid sys_getxuid
 25 common  exec_with_loadersys_ni_syscall
@@ -183,7 +183,7 @@
 206common  semop   sys_semop
 207common  osf_utsname sys_osf_utsname
 208common  lchown  sys_lchown
-209common  osf_shmat   sys_shmat
+209common  shmat   sys_shmat
 210common  shmctl  sys_shmctl
 211common  shmdt   sys_shmdt
 212common  shmget  sys_shmget
-- 
2.20.0



[PATCH v2 20/29] time: fix sys_timer_settime prototype

2019-01-18 Thread Arnd Bergmann
A small typo has crept into the y2038 conversion of the timer_settime
system call. So far this was completely harmless, but once we start
using the new version, this has to be fixed.

Fixes: 6ff847350702 ("time: Change types to new y2038 safe __kernel_itimerspec")
Signed-off-by: Arnd Bergmann 
---
 include/linux/syscalls.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 938d8908b9e0..baa4b70b02d3 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -591,7 +591,7 @@ asmlinkage long sys_timer_gettime(timer_t timer_id,
 asmlinkage long sys_timer_getoverrun(timer_t timer_id);
 asmlinkage long sys_timer_settime(timer_t timer_id, int flags,
const struct __kernel_itimerspec __user 
*new_setting,
-   struct itimerspec __user *old_setting);
+   struct __kernel_itimerspec __user *old_setting);
 asmlinkage long sys_timer_delete(timer_t timer_id);
 asmlinkage long sys_clock_settime(clockid_t which_clock,
const struct __kernel_timespec __user *tp);
-- 
2.20.0



[PATCH v2 24/29] x86/x32: use time64 versions of sigtimedwait and recvmmsg

2019-01-18 Thread Arnd Bergmann
x32 has always followed the time64 calling conventions of these
syscalls, which required a special hack in compat_get_timespec
aka get_old_timespec32 to continue working.

Since we now have the time64 syscalls, use those explicitly.

Signed-off-by: Arnd Bergmann 
---
 arch/x86/entry/syscalls/syscall_64.tbl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/entry/syscalls/syscall_64.tbl 
b/arch/x86/entry/syscalls/syscall_64.tbl
index f0b1709a5ffb..43a622aec07e 100644
--- a/arch/x86/entry/syscalls/syscall_64.tbl
+++ b/arch/x86/entry/syscalls/syscall_64.tbl
@@ -361,7 +361,7 @@
 520x32 execve  __x32_compat_sys_execve/ptregs
 521x32 ptrace  __x32_compat_sys_ptrace
 522x32 rt_sigpending   __x32_compat_sys_rt_sigpending
-523x32 rt_sigtimedwait __x32_compat_sys_rt_sigtimedwait
+523x32 rt_sigtimedwait __x32_compat_sys_rt_sigtimedwait_time64
 524x32 rt_sigqueueinfo __x32_compat_sys_rt_sigqueueinfo
 525x32 sigaltstack __x32_compat_sys_sigaltstack
 526x32 timer_create__x32_compat_sys_timer_create
@@ -375,7 +375,7 @@
 534x32 preadv  __x32_compat_sys_preadv64
 535x32 pwritev __x32_compat_sys_pwritev64
 536x32 rt_tgsigqueueinfo   __x32_compat_sys_rt_tgsigqueueinfo
-537x32 recvmmsg__x32_compat_sys_recvmmsg
+537x32 recvmmsg__x32_compat_sys_recvmmsg_time64
 538x32 sendmmsg__x32_compat_sys_sendmmsg
 539x32 process_vm_readv__x32_compat_sys_process_vm_readv
 540x32 process_vm_writev   __x32_compat_sys_process_vm_writev
-- 
2.20.0



[PATCH v2 00/29] y2038: add time64 syscalls

2019-01-18 Thread Arnd Bergmann
This is a minor update of the patches I posted last week, I
would like to add this into linux-next now, but would still do
changes if there are concerns about the contents. The first
version did not see a lot of replies, which could mean that
either everyone is happy with it, or that it was largely ignored.

See also the article at https://lwn.net/Articles/776435/.

Changes since v1:

- posting as a combined series for simplicity
- dropped one mips patch that was merged as a 5.0 fix
- reworked s390 compat syscall handling (posted separately)
  and rebased on top of that series
- minor fixes for arm64 and powerpc
- added alpha statfs64 interfaces
- added alpha get{eg,eu,g,p,u,pp}id()

 Arnd


v1 description for cleanup:
The system call tables have diverged a bit over the years, and a number
of the recent additions never made it into all architectures, for one
reason or another.

This is an attempt to clean it up as far as we can without breaking
compatibility, doing a number of steps:

- Add system calls that have not yet been integrated into all
  architectures but that we definitely want there.

- Add the separate ipc syscalls on all architectures that
  traditionally only had sys_ipc(). This version is done without
  support for IPC_OLD that is we have in sys_ipc. The
  new semtimedop_time64 syscall will only be added here, not
  in sys_ipc

- Add syscall numbers for a couple of syscalls that we probably
  don't need everywhere, in particular pkey_* and rseq,
  for the purpose of symmetry: if it's in asm-generic/unistd.h,
  it makes sense to have it everywhere.

- Prepare for having the same system call numbers for any future
  calls. In combination with the generated tables, this hopefully
  makes it easier to add new calls across all architectures
  together.

Most of the contents of this series are unrelated to the actual
y2038 work, but for the moment, that second series is based on
this one. If there are any concerns about changes here, I
can drop or rewrite any individual patch in this series.

My plan is to merge any patches in this series that are found
to be good together with the y2038 patches for linux-5.1, so
please review and provide Acks for merging through my tree,
or pick them up for 5.0 if they seem urgent enough.

v1 description for y2038 patches:

This series finally gets us to the point of having system calls with
64-bit time_t on all architectures, after a long time of incremental
preparation patches.

There was actually one conversion that I missed during the summer,
i.e. Deepa's timex series, which I now updated based the 5.0-rc1 changes
and review comments.

I hope that the actual conversion should be uncontroversial by now,
even if some of the patches are rather large.

The one area that may need a little discussion is for the system call
numbers assigned in the final patch: Can we get consensus on whether
the idea of using the same numbers on all architectures, as well as my
choice of numbers makes sense here?

So far, I have done a lot of build testing across most architectures,
which has found a number of bugs. I have also done an LTP run on arm32
with existing user space, but not on the other architectures. I did LTP
tests with a modified musl libc[2] last summer on an older version of
this series to make sure that the new 64-bit time_t interfaces work.
The version there will need updates for testing with this new kernel
patch series; I plan to do that next.

For testing, the series plus the preparatory patches is available at
[3].  Once there is a general agreement on this series and I have done
more tests for the new system calls, I plan to add this to linux-next
through my asm-generic tree or Thomas' timers tree.

Please review and test!

  Arnd

[1] https://lore.kernel.org/lkml/20190110162435.309262-1-a...@arndb.de/T/
[2] https://git.linaro.org/people/arnd/musl-y2038.git/
[3] https://git.kernel.org/pub/scm/linux/kernel/git/arnd/playground.git 
y2038-5.0-rc1

Arnd Bergmann (26):
  ia64: add __NR_umount2 definition
  ia64: add statx and io_pgetevents syscalls
  ia64: assign syscall numbers for perf and seccomp
  alpha: wire up io_pgetevents system call
  alpha: update syscall macro definitions
  ARM: add migrate_pages() system call
  ARM: add kexec_file_load system call number
  m68k: assign syscall number for seccomp
  sh: remove duplicate unistd_32.h file
  sh: add statx system call
  sparc64: fix sparc_ipc type conversion
  ipc: rename old-style shmctl/semctl/msgctl syscalls
  arch: add split IPC system calls where needed
  arch: add pkey and rseq syscall numbers everywhere
  alpha: add standard statfs64/fstatfs64 syscalls
  alpha: add generic get{eg,eu,g,p,u,pp}id() syscalls
  syscalls: remove obsolete __IGNORE_ macros
  time: make adjtime compat handling available for 32 bit
  time: fix sys_timer_settime prototype
  sparc64: add custom adjtimex/clock_adjtime functions
  x86/x32: use time64 versions of sigtimedwait and recvmmsg
  y2038: syscalls: rename

[PATCH v2 22/29] timex: use __kernel_timex internally

2019-01-18 Thread Arnd Bergmann
From: Deepa Dinamani 

struct timex is not y2038 safe.
Replace all uses of timex with y2038 safe __kernel_timex.

Note that struct __kernel_timex is an ABI interface definition.
We could define a new structure based on __kernel_timex that
is only available internally instead. Right now, there isn't
a strong motivation for this as the structure is isolated to
a few defined struct timex interfaces and such a structure would
be exactly the same as struct timex.

The patch was generated by the following coccinelle script:

virtual patch

@depends on patch forall@
identifier ts;
expression e;
@@
(
- struct timex ts;
+ struct __kernel_timex ts;
|
- struct timex ts = {};
+ struct __kernel_timex ts = {};
|
- struct timex ts = e;
+ struct __kernel_timex ts = e;
|
- struct timex *ts;
+ struct __kernel_timex *ts;
|
(memset \| copy_from_user \| copy_to_user \)(...,
- sizeof(struct timex))
+ sizeof(struct __kernel_timex))
)

@depends on patch forall@
identifier ts;
identifier fn;
@@
fn(...,
- struct timex *ts,
+ struct __kernel_timex *ts,
...) {
...
}

@depends on patch forall@
identifier ts;
identifier fn;
@@
fn(...,
- struct timex *ts) {
+ struct __kernel_timex *ts) {
...
}

Signed-off-by: Deepa Dinamani 
Cc: linux-al...@vger.kernel.org
Cc: net...@vger.kernel.org
---
 arch/alpha/kernel/osf_sys.c  |  5 +++--
 arch/sparc/kernel/sys_sparc_64.c |  4 ++--
 drivers/ptp/ptp_clock.c  |  2 +-
 include/linux/posix-clock.h  |  2 +-
 include/linux/time32.h   |  6 +++---
 include/linux/timex.h|  4 ++--
 kernel/time/ntp.c| 18 ++
 kernel/time/ntp_internal.h   |  2 +-
 kernel/time/posix-clock.c|  2 +-
 kernel/time/posix-timers.c   |  8 
 kernel/time/posix-timers.h   |  2 +-
 kernel/time/time.c   | 14 +++---
 kernel/time/timekeeping.c|  4 ++--
 13 files changed, 38 insertions(+), 35 deletions(-)

diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
index 792586038808..bf497b8b0ec6 100644
--- a/arch/alpha/kernel/osf_sys.c
+++ b/arch/alpha/kernel/osf_sys.c
@@ -1253,7 +1253,7 @@ struct timex32 {
 
 SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
 {
-struct timex txc;
+   struct __kernel_timex txc;
int ret;
 
/* copy relevant bits of struct timex. */
@@ -1270,7 +1270,8 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, 
txc_p)
if (copy_to_user(txc_p, , offsetof(struct timex32, time)) ||
(copy_to_user(_p->tick, , sizeof(struct timex32) - 
  offsetof(struct timex32, tick))) ||
-   (put_tv_to_tv32(_p->time, )))
+   (put_user(txc.time.tv_sec, _p->time.tv_sec)) ||
+   (put_user(txc.time.tv_usec, _p->time.tv_usec)))
  return -EFAULT;
 
return ret;
diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
index 37de18a11207..9825ca6a6020 100644
--- a/arch/sparc/kernel/sys_sparc_64.c
+++ b/arch/sparc/kernel/sys_sparc_64.c
@@ -548,7 +548,7 @@ SYSCALL_DEFINE2(getdomainname, char __user *, name, int, 
len)
 SYSCALL_DEFINE1(sparc_adjtimex, struct timex __user *, txc_p)
 {
struct timex txc;   /* Local copy of parameter */
-   struct timex *kt = (void *)
+   struct __kernel_timex *kt = (void *)
int ret;
 
/* Copy the user data space into the kernel copy
@@ -572,7 +572,7 @@ SYSCALL_DEFINE1(sparc_adjtimex, struct timex __user *, 
txc_p)
 SYSCALL_DEFINE2(sparc_clock_adjtime, const clockid_t, which_clock,struct timex 
__user *, txc_p)
 {
struct timex txc;   /* Local copy of parameter */
-   struct timex *kt = (void *)
+   struct __kernel_timex *kt = (void *)
int ret;
 
if (!IS_ENABLED(CONFIG_POSIX_TIMERS)) {
diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
index 48f3594a7458..79bd102c9bbc 100644
--- a/drivers/ptp/ptp_clock.c
+++ b/drivers/ptp/ptp_clock.c
@@ -124,7 +124,7 @@ static int ptp_clock_gettime(struct posix_clock *pc, struct 
timespec64 *tp)
return err;
 }
 
-static int ptp_clock_adjtime(struct posix_clock *pc, struct timex *tx)
+static int ptp_clock_adjtime(struct posix_clock *pc, struct __kernel_timex *tx)
 {
struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock);
struct ptp_clock_info *ops;
diff --git a/include/linux/posix-clock.h b/include/linux/posix-clock.h
index 3a3bc71017d5..18674d7d5b1c 100644
--- a/include/linux/posix-clock.h
+++ b/include/linux/posix-clock.h
@@ -51,7 +51,7 @@ struct posix_clock;
 struct posix_clock_operations {
struct module *owner;
 
-   int  (*clock_adjtime)(struct posix_clock *pc, struct timex *tx);
+   int  (*clock_adjtime)(struct posix_clock *pc, struct __kernel_timex 
*tx);
 
int  (*clock_gettime)(struct posix_clock *pc, struct timespec64 *ts);
 
diff --git a/include/linux/time32.h b/include/linux/time32.h
index 820a22e2b98b..0a1f302a1753 100644
--- 

[PATCH v2 06/29] ARM: add migrate_pages() system call

2019-01-18 Thread Arnd Bergmann
The migrate_pages system call has an assigned number on all architectures
except ARM. When it got added initially in commit d80ade7b3231 ("ARM:
Fix warning: #warning syscall migrate_pages not implemented"), it was
intentionally left out based on the observation that there are no 32-bit
ARM NUMA systems.

However, there are now arm64 NUMA machines that can in theory run 32-bit
kernels (actually enabling NUMA there would require additional work)
as well as 32-bit user space on 64-bit kernels, so that argument is no
longer very strong.

Assigning the number lets us use the system call on 64-bit kernels as well
as providing a more consistent set of syscalls across architectures.

Signed-off-by: Arnd Bergmann 
---
 arch/arm/include/asm/unistd.h | 1 -
 arch/arm/tools/syscall.tbl| 1 +
 arch/arm64/include/asm/unistd.h   | 2 +-
 arch/arm64/include/asm/unistd32.h | 2 ++
 4 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/arm/include/asm/unistd.h b/arch/arm/include/asm/unistd.h
index 88ef2ce1f69a..d713587dfcf4 100644
--- a/arch/arm/include/asm/unistd.h
+++ b/arch/arm/include/asm/unistd.h
@@ -45,7 +45,6 @@
  * Unimplemented (or alternatively implemented) syscalls
  */
 #define __IGNORE_fadvise64_64
-#define __IGNORE_migrate_pages
 
 #ifdef __ARM_EABI__
 /*
diff --git a/arch/arm/tools/syscall.tbl b/arch/arm/tools/syscall.tbl
index 8edf93b4490f..86de9eb34296 100644
--- a/arch/arm/tools/syscall.tbl
+++ b/arch/arm/tools/syscall.tbl
@@ -414,3 +414,4 @@
 397common  statx   sys_statx
 398common  rseqsys_rseq
 399common  io_pgetevents   sys_io_pgetevents
+400common  migrate_pages   sys_migrate_pages
diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h
index a7b1fc58ffdf..261216c3336e 100644
--- a/arch/arm64/include/asm/unistd.h
+++ b/arch/arm64/include/asm/unistd.h
@@ -44,7 +44,7 @@
 #define __ARM_NR_compat_set_tls(__ARM_NR_COMPAT_BASE + 5)
 #define __ARM_NR_COMPAT_END(__ARM_NR_COMPAT_BASE + 0x800)
 
-#define __NR_compat_syscalls   400
+#define __NR_compat_syscalls   401
 #endif
 
 #define __ARCH_WANT_SYS_CLONE
diff --git a/arch/arm64/include/asm/unistd32.h 
b/arch/arm64/include/asm/unistd32.h
index 04ee190b90fe..f15bcbacb8f6 100644
--- a/arch/arm64/include/asm/unistd32.h
+++ b/arch/arm64/include/asm/unistd32.h
@@ -821,6 +821,8 @@ __SYSCALL(__NR_statx, sys_statx)
 __SYSCALL(__NR_rseq, sys_rseq)
 #define __NR_io_pgetevents 399
 __SYSCALL(__NR_io_pgetevents, compat_sys_io_pgetevents)
+#define __NR_migrate_pages 400
+__SYSCALL(__NR_migrate_pages, compat_sys_migrate_pages)
 
 /*
  * Please add new compat syscalls above this comment and update
-- 
2.20.0



Re: [PATCH 14/15] arch: add split IPC system calls where needed

2019-01-15 Thread Arnd Bergmann
On Tue, Jan 15, 2019 at 5:36 PM Geert Uytterhoeven  wrote:
> On Tue, Jan 15, 2019 at 4:19 PM Arnd Bergmann  wrote:
> > On Tue, Jan 15, 2019 at 4:01 PM Arnd Bergmann  wrote:
> > > On Mon, Jan 14, 2019 at 4:59 AM Michael Ellerman  
> > > wrote:
> > > > Arnd Bergmann  writes:
> > > > >  arch/m68k/kernel/syscalls/syscall.tbl | 11 +++
> > > > >  arch/mips/kernel/syscalls/syscall_o32.tbl | 11 +++
> > > > >  arch/powerpc/kernel/syscalls/syscall.tbl  | 12 
> > > >
> > > > I have some changes I'd like to make to our syscall table that will
> > > > clash with this.
> > > >
> > > > I'll try and send them today.
> > >
> > > Ok. Are those for 5.0 or 5.1? If they are intended for 5.0, it would be
> > > nice for me to have a branch based on 5.0-rc1 that I can put
> > > the other patches on top of.
> >
> > There is also another change that I considered:
> >
> > At the end of my series, we have a lot of entries like
> >
> > 245 32  clock_settime   sys_clock_settime32
> > 245 64  clock_settime   sys_clock_settime
> > 245 spu clock_settime   sys_clock_settime
> >
> > which could be folded into
> >
> > 245 32  clock_settime   sys_clock_settime32
> > 245 spu64 clock_settime   sys_clock_settime
> >
> > if we just add another option to the ABI field. Any thoughts on
> > that?
>
> So "spu64" would mean "spu + 64"?
> That makes it more difficult to read, and to grep.
> What about allowing multiple ABIs, separated by commas?
> So that line would become:
>
> 245 spu,64 clock_settime   sys_clock_settime

I agree that would be a nice representation, but doing this would
again require changing the script, which then in turn clashes with
Firoz' patches to unify it under the scripts/ directory.

   Arnd


Re: [PATCH 14/15] arch: add split IPC system calls where needed

2019-01-15 Thread Arnd Bergmann
On Tue, Jan 15, 2019 at 4:01 PM Arnd Bergmann  wrote:
>
> On Mon, Jan 14, 2019 at 4:59 AM Michael Ellerman  wrote:
> > Arnd Bergmann  writes:
> > >  arch/m68k/kernel/syscalls/syscall.tbl | 11 +++
> > >  arch/mips/kernel/syscalls/syscall_o32.tbl | 11 +++
> > >  arch/powerpc/kernel/syscalls/syscall.tbl  | 12 
> >
> > I have some changes I'd like to make to our syscall table that will
> > clash with this.
> >
> > I'll try and send them today.
>
> Ok. Are those for 5.0 or 5.1? If they are intended for 5.0, it would be
> nice for me to have a branch based on 5.0-rc1 that I can put
> the other patches on top of.

There is also another change that I considered:

At the end of my series, we have a lot of entries like

245 32  clock_settime   sys_clock_settime32
245 64  clock_settime   sys_clock_settime
245 spu clock_settime   sys_clock_settime

which could be folded into

245 32  clock_settime   sys_clock_settime32
245 spu64 clock_settime   sys_clock_settime

if we just add another option to the ABI field. Any thoughts on
that?

  Arnd


Re: [PATCH 14/15] arch: add split IPC system calls where needed

2019-01-15 Thread Arnd Bergmann
On Mon, Jan 14, 2019 at 4:59 AM Michael Ellerman  wrote:
> Arnd Bergmann  writes:
> >  arch/m68k/kernel/syscalls/syscall.tbl | 11 +++
> >  arch/mips/kernel/syscalls/syscall_o32.tbl | 11 +++
> >  arch/powerpc/kernel/syscalls/syscall.tbl  | 12 
>
> I have some changes I'd like to make to our syscall table that will
> clash with this.
>
> I'll try and send them today.

Ok. Are those for 5.0 or 5.1? If they are intended for 5.0, it would be
nice for me to have a branch based on 5.0-rc1 that I can put
the other patches on top of.

> > diff --git a/arch/powerpc/kernel/syscalls/syscall.tbl 
> > b/arch/powerpc/kernel/syscalls/syscall.tbl
> > index db3bbb8744af..1bffab54ff35 100644
> > --- a/arch/powerpc/kernel/syscalls/syscall.tbl
> > +++ b/arch/powerpc/kernel/syscalls/syscall.tbl
> > @@ -425,3 +425,15 @@
> >  386  nospu   pkey_mprotect   sys_pkey_mprotect
> >  387  nospu   rseqsys_rseq
> >  388  nospu   io_pgetevents   sys_io_pgetevents 
> >   compat_sys_io_pgetevents
> > +# room for arch specific syscalls
> > +392  64  semtimedop  sys_semtimedop
> > +393  common  semget  sys_semget
> > +394  common  semctl  sys_semctl
> >   compat_sys_semctl
> > +395  common  shmget  sys_shmget
> > +396  common  shmctl  sys_shmctl
> >   compat_sys_shmctl
> > +397  common  shmat   sys_shmat 
> >   compat_sys_shmat
> > +398  common  shmdt   sys_shmdt
> > +399  common  msgget  sys_msgget
> > +400  common  msgsnd  sys_msgsnd
> >   compat_sys_msgsnd
> > +401  common  msgrcv  sys_msgrcv
> >   compat_sys_msgrcv
> > +402  common  msgctl  sys_msgctl
> >   compat_sys_msgctl
>
> We already have a gap at 366-377 from when we tried to add the split IPC
> calls a few years back.
>
> I guess I don't mind leaving that gap and using the common numbers as
> you've done here.
>
> But it would be good to add a comment pointing out that we have room
> at 366 for more arch specific syscalls as well.

Ah, I missed that. I've added this to my patch now:

index 5c0936d862fc..2ddfba536d5f 100644
--- a/arch/powerpc/kernel/syscalls/syscall.tbl
+++ b/arch/powerpc/kernel/syscalls/syscall.tbl
@@ -460,6 +460,7 @@
 363spu switch_endian   sys_ni_syscall
 364common  userfaultfd sys_userfaultfd
 365common  membarrier  sys_membarrier
+# 366-377 originally left for IPC, now unused
 378nospu   mlock2  sys_mlock2
 379nospu   copy_file_range sys_copy_file_range
 380common  preadv2 sys_preadv2
 compat_sys_preadv2

   Arnd


Re: [PATCH 15/15] arch: add pkey and rseq syscall numbers everywhere

2019-01-15 Thread Arnd Bergmann
On Tue, Jan 15, 2019 at 12:52 PM Russell King - ARM Linux admin
 wrote:
>
> On Thu, Jan 10, 2019 at 05:24:35PM +0100, Arnd Bergmann wrote:
> > Most architectures define system call numbers for the rseq and pkey system
> > calls, even when they don't support the features, and perhaps never will.
> >
> > Only a few architectures are missing these, so just define them anyway
> > for consistency. If we decide to add them later to one of these, the
> > system call numbers won't get out of sync then.
>
> I was lambasted for adding the pkey syscalls for 32-bit ARM in 2016,
> which will probably never support it.  Why has the attitude towards
> this kind of thing now apparently become acceptable?

I was (and still am) a bit unsure about this one. A number of architectures
added the numbers that won't ever support them, but I wasn't sure if
any of those that didn't add them might need it later.

I tried to just go by the rule that anything that we list in
asm-generic/unistd.h
is probably important enough that we want to list it everywhere, even if
that includes a couple that we end up being rather architecture specific.

I'm happy to drop this patch if you or others feel that we're better off
without it though.

  Arnd


Re: [PATCH 14/15] arch: add split IPC system calls where needed

2019-01-11 Thread Arnd Bergmann
On Thu, Jan 10, 2019 at 9:33 PM Heiko Carstens
 wrote:
> On Thu, Jan 10, 2019 at 05:24:34PM +0100, Arnd Bergmann wrote:

> > diff --git a/arch/s390/kernel/syscalls/syscall.tbl 
> > b/arch/s390/kernel/syscalls/syscall.tbl
> > index 022fc099b628..428cf512a757 100644
> > --- a/arch/s390/kernel/syscalls/syscall.tbl
> > +++ b/arch/s390/kernel/syscalls/syscall.tbl
> > @@ -391,3 +391,15 @@
> >  381  common  kexec_file_load sys_kexec_file_load 
> > compat_sys_kexec_file_load
> >  382  common  io_pgetevents   sys_io_pgetevents   
> > compat_sys_io_pgetevents
> >  383  common  rseqsys_rseq
> > compat_sys_rseq
> > +# room for arch specific syscalls
> > +392  64  semtimedop  sys_semtimedop  -
> > +393  common  semget  sys_semget  
> > sys_semget
> ...
> > +395  common  shmget  sys_shmget  
> > sys_shmget
> ...
> > +398  common  shmdt   sys_shmdt   
> > sys_shmdt
> > +399  common  msgget  sys_msgget  
> > sys_msgget
>
> These four need compat system call wrappers, unfortunately... (well,
> actually only shmget and shmdt require them, but let's add them for
> all four). See arch/s390/kernel/compat_wrapper.c
>
> I'm afraid this compat special handling will be even more annoying in
> the future, since s390 will be the only architecture which requires
> this special handling.
>
> _Maybe_ it would make sense to automatically generate a weak compat
> system call wrapper for s390 with the SYSCALL_DEFINE macros, but that
> probably won't work in all cases.

For some reason I was under the impression that s390 already did that.
However, it seems that x86 does, so I'll try to convert the x86 version
for s390, and see if I can get rid of all the wrappers that way.

It would certainly be safer to have the wrappers always present,
especially if we expect future system calls to be added to the
s390 table by whoever implements the syscall itself.

  Arnd


Re: [PATCH 15/15] arch: add pkey and rseq syscall numbers everywhere

2019-01-11 Thread Arnd Bergmann
On Thu, Jan 10, 2019 at 9:36 PM Heiko Carstens
 wrote:
> On Thu, Jan 10, 2019 at 05:24:35PM +0100, Arnd Bergmann wrote:

> Since you only need/want the system call numbers, could you please
> change these lines to:
>
> > +384  common  pkey_alloc  -   -
> > +385  common  pkey_free   -   -
> > +386  common  pkey_mprotect   -   -
>
> Otherwise it _looks_ like we would need compat wrappers here as well,
> even though all of them would just jump to sys_ni_syscall() in this
> case. Making this explicit seems to better.

Ok, fair enough. I considered doing this originally and then
decided against it for consistency with the asm-generic file,
but I don't care much either way.

Is this something you may want to add later? I'm not sure exactly
how pkey compares to s390 storage keys, or if this is something
completely unrelated.

 Arnd


[PATCH 10/11] y2038: rename old time and utime syscalls

2019-01-10 Thread Arnd Bergmann
The time, stime, utime, utimes, and futimesat system calls are only
used on older architectures, and we do not provide y2038 safe variants
of them, as they are replaced by clock_gettime64, clock_settime64,
and utimensat_time64.

However, for consistency it seems better to have the 32-bit architectures
that still use them call the "time32" entry points (leaving the
traditional handlers for the 64-bit architectures), like we do for system
calls that now require two versions.

Note: We used to always define __ARCH_WANT_SYS_TIME and
__ARCH_WANT_SYS_UTIME and only set __ARCH_WANT_COMPAT_SYS_TIME and
__ARCH_WANT_SYS_UTIME32 for compat mode on 64-bit kernels. Now this is
reversed: only 64-bit architectures set __ARCH_WANT_SYS_TIME/UTIME, while
we need __ARCH_WANT_SYS_TIME32/UTIME32 for 32-bit architectures and compat
mode. The resulting asm/unistd.h changes look a bit counterintuitive.

This is only a cleanup patch and it should not change any behavior.

Signed-off-by: Arnd Bergmann 
---
 arch/arm/include/asm/unistd.h   |  4 ++--
 arch/arm/tools/syscall.tbl  | 10 +-
 arch/m68k/include/asm/unistd.h  |  4 ++--
 arch/m68k/kernel/syscalls/syscall.tbl   | 10 +-
 arch/microblaze/include/asm/unistd.h|  4 ++--
 arch/microblaze/kernel/syscalls/syscall.tbl | 10 +-
 arch/mips/include/asm/unistd.h  |  4 ++--
 arch/mips/kernel/syscalls/syscall_o32.tbl   | 10 +-
 arch/parisc/include/asm/unistd.h|  9 ++---
 arch/parisc/kernel/syscalls/syscall.tbl | 15 ++-
 arch/powerpc/include/asm/unistd.h   |  8 
 arch/powerpc/kernel/syscalls/syscall.tbl| 19 ++-
 arch/s390/include/asm/unistd.h  |  2 +-
 arch/sh/include/asm/unistd.h|  4 ++--
 arch/sh/kernel/syscalls/syscall.tbl | 10 +-
 arch/sparc/include/asm/unistd.h |  8 
 arch/sparc/kernel/syscalls/syscall.tbl  | 14 +-
 arch/x86/entry/syscalls/syscall_32.tbl  | 10 +-
 arch/x86/include/asm/unistd.h   |  8 
 arch/xtensa/include/asm/unistd.h|  2 +-
 arch/xtensa/kernel/syscalls/syscall.tbl |  6 +++---
 kernel/time/time.c  |  4 ++--
 22 files changed, 98 insertions(+), 77 deletions(-)

diff --git a/arch/arm/include/asm/unistd.h b/arch/arm/include/asm/unistd.h
index d713587dfcf4..7a39e77984ef 100644
--- a/arch/arm/include/asm/unistd.h
+++ b/arch/arm/include/asm/unistd.h
@@ -26,10 +26,10 @@
 #define __ARCH_WANT_SYS_SIGPROCMASK
 #define __ARCH_WANT_SYS_OLD_MMAP
 #define __ARCH_WANT_SYS_OLD_SELECT
-#define __ARCH_WANT_SYS_UTIME
+#define __ARCH_WANT_SYS_UTIME32
 
 #if !defined(CONFIG_AEABI) || defined(CONFIG_OABI_COMPAT)
-#define __ARCH_WANT_SYS_TIME
+#define __ARCH_WANT_SYS_TIME32
 #define __ARCH_WANT_SYS_IPC
 #define __ARCH_WANT_SYS_OLDUMOUNT
 #define __ARCH_WANT_SYS_ALARM
diff --git a/arch/arm/tools/syscall.tbl b/arch/arm/tools/syscall.tbl
index 200f4b878a46..a96d9b5ee04e 100644
--- a/arch/arm/tools/syscall.tbl
+++ b/arch/arm/tools/syscall.tbl
@@ -24,7 +24,7 @@
 10 common  unlink  sys_unlink
 11 common  execve  sys_execve
 12 common  chdir   sys_chdir
-13 oabitimesys_time
+13 oabitimesys_time32
 14 common  mknod   sys_mknod
 15 common  chmod   sys_chmod
 16 common  lchown  sys_lchown16
@@ -36,12 +36,12 @@
 22 oabiumount  sys_oldumount
 23 common  setuid  sys_setuid16
 24 common  getuid  sys_getuid16
-25 oabistime   sys_stime
+25 oabistime   sys_stime32
 26 common  ptrace  sys_ptrace
 27 oabialarm   sys_alarm
 # 28 was sys_fstat
 29 common  pause   sys_pause
-30 oabiutime   sys_utime
+30 oabiutime   sys_utime32
 # 31 was sys_stty
 # 32 was sys_gtty
 33 common  access  sys_access
@@ -283,7 +283,7 @@
 266common  statfs64sys_statfs64_wrapper
 267common  fstatfs64   sys_fstatfs64_wrapper
 268common  tgkill  sys_tgkill
-269common  utimes  sys_utimes
+269common  utimes  sys_utimes_time32
 270common  arm_fadvise64_64sys_arm_fadvise64_64
 271common  pciconfig_iobasesys_pciconfig_iobase
 272common  pciconfig_read  sys_pciconfig_read
@@ -340,7 +340,7 @@
 323common  mkdirat sys_mkdirat
 324common  mknodat sys_mknodat
 325common  fchownatsys_fchownat
-326common  futimesat   sys_futimesat
+326common  futimesat   sys_futimesat_time32
 327common 

[PATCH 06/11] timex: change syscalls to use struct __kernel_timex

2019-01-10 Thread Arnd Bergmann
From: Deepa Dinamani 

struct timex is not y2038 safe.
Switch all the syscall apis to use y2038 safe __kernel_timex.

Note that sys_adjtimex() does not have a y2038 safe solution.  C libraries
can implement it by calling clock_adjtime(CLOCK_REALTIME, ...).

Signed-off-by: Deepa Dinamani 
Signed-off-by: Arnd Bergmann 
---
 include/linux/syscalls.h   | 6 +++---
 kernel/time/posix-timers.c | 2 +-
 kernel/time/time.c | 4 +++-
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 8e86d9623d4e..394e8db7e57e 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -54,7 +54,7 @@ struct __sysctl_args;
 struct sysinfo;
 struct timespec;
 struct timeval;
-struct timex;
+struct __kernel_timex;
 struct timezone;
 struct tms;
 struct utimbuf;
@@ -695,7 +695,7 @@ asmlinkage long sys_gettimeofday(struct timeval __user *tv,
struct timezone __user *tz);
 asmlinkage long sys_settimeofday(struct timeval __user *tv,
struct timezone __user *tz);
-asmlinkage long sys_adjtimex(struct timex __user *txc_p);
+asmlinkage long sys_adjtimex(struct __kernel_timex __user *txc_p);
 
 /* kernel/timer.c */
 asmlinkage long sys_getpid(void);
@@ -870,7 +870,7 @@ asmlinkage long sys_open_by_handle_at(int mountdirfd,
  struct file_handle __user *handle,
  int flags);
 asmlinkage long sys_clock_adjtime(clockid_t which_clock,
-   struct timex __user *tx);
+   struct __kernel_timex __user *tx);
 asmlinkage long sys_syncfs(int fd);
 asmlinkage long sys_setns(int fd, int nstype);
 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 2d84b3db1ade..de79f85ae14f 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -1060,7 +1060,7 @@ int do_clock_adjtime(const clockid_t which_clock, struct 
__kernel_timex * ktx)
 }
 
 SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock,
-   struct timex __user *, utx)
+   struct __kernel_timex __user *, utx)
 {
struct __kernel_timex ktx;
int err;
diff --git a/kernel/time/time.c b/kernel/time/time.c
index d179d33f639a..78b5c8f1495a 100644
--- a/kernel/time/time.c
+++ b/kernel/time/time.c
@@ -263,7 +263,8 @@ COMPAT_SYSCALL_DEFINE2(settimeofday, struct old_timeval32 
__user *, tv,
 }
 #endif
 
-SYSCALL_DEFINE1(adjtimex, struct timex __user *, txc_p)
+#if !defined(CONFIG_64BIT_TIME) || defined(CONFIG_64BIT)
+SYSCALL_DEFINE1(adjtimex, struct __kernel_timex __user *, txc_p)
 {
struct __kernel_timex txc;  /* Local copy of parameter */
int ret;
@@ -277,6 +278,7 @@ SYSCALL_DEFINE1(adjtimex, struct timex __user *, txc_p)
ret = do_adjtimex();
return copy_to_user(txc_p, , sizeof(struct __kernel_timex)) ? 
-EFAULT : ret;
 }
+#endif
 
 #ifdef CONFIG_COMPAT_32BIT_TIME
 int get_old_timex32(struct __kernel_timex *txc, const struct old_timex32 
__user *utp)
-- 
2.20.0



[PATCH 00/11] y2038: add time64 syscalls

2019-01-10 Thread Arnd Bergmann
This series finally gets us to the point of having system calls with
64-bit time_t on all architectures, after a long time of incremental
preparation patches.

There was actually one conversion that I missed during the summer,
i.e. Deepa's timex series, which I now updated based the 5.0-rc1 changes
and review comments.

I hope that the actual conversion should be uncontroversial by now,
even if some of the patches are rather large.

The one area that may need a little discussion is for the system call
numbers assigned in the final patch: Can we get consensus on whether
the idea of using the same numbers on all architectures, as well as my
choice of numbers makes sense here?

So far, I have done a lot of build testing across most architectures,
which has found a number of bugs. I have also done an LTP run on arm32
with existing user space, but not on the other architectures. I did LTP
tests with a modified musl libc[2] last summer on an older version of
this series to make sure that the new 64-bit time_t interfaces work.
The version there will need updates for testing with this new kernel
patch series; I plan to do that next.

For testing, the series plus the preparatory patches is available at
[3].  Once there is a general agreement on this series and I have done
more tests for the new system calls, I plan to add this to linux-next
through my asm-generic tree or Thomas' timers tree.

Please review and test!

  Arnd

[1] https://lore.kernel.org/lkml/20190110162435.309262-1-a...@arndb.de/T/
[2] https://git.linaro.org/people/arnd/musl-y2038.git/
[3] https://git.kernel.org/pub/scm/linux/kernel/git/arnd/playground.git 
y2038-5.0-rc1

Arnd Bergmann (8):
  time: make adjtime compat handling available for 32 bit
  time: fix sys_timer_settime prototype
  sparc64: add custom adjtimex/clock_adjtime functions
  y2038: syscalls: rename y2038 compat syscalls
  y2038: use time32 syscall names on 32-bit
  y2038: remove struct definition redirects
  y2038: rename old time and utime syscalls
  y2038: add 64-bit time_t syscalls to all 32-bit architectures

Deepa Dinamani (3):
  time: Add struct __kernel_timex
  timex: use __kernel_timex internally
  timex: change syscalls to use struct __kernel_timex

 arch/Kconfig|   2 +-
 arch/alpha/kernel/osf_sys.c |   5 +-
 arch/alpha/kernel/syscalls/syscall.tbl  |   2 +
 arch/arm/include/asm/unistd.h   |   4 +-
 arch/arm/kernel/sys_oabi-compat.c   |   8 +-
 arch/arm/tools/syscall.tbl  |  77 -
 arch/arm64/include/asm/unistd.h |   2 +-
 arch/arm64/include/asm/unistd32.h   |  89 ++
 arch/ia64/kernel/syscalls/syscall.tbl   |   1 +
 arch/m68k/include/asm/unistd.h  |   4 +-
 arch/m68k/kernel/syscalls/syscall.tbl   |  72 +++-
 arch/microblaze/include/asm/unistd.h|   4 +-
 arch/microblaze/kernel/syscalls/syscall.tbl |  77 -
 arch/mips/include/asm/unistd.h  |   4 +-
 arch/mips/kernel/syscalls/syscall_n32.tbl   |  71 
 arch/mips/kernel/syscalls/syscall_n64.tbl   |   1 +
 arch/mips/kernel/syscalls/syscall_o32.tbl   |  74 +++-
 arch/parisc/include/asm/unistd.h|   9 +-
 arch/parisc/kernel/syscalls/syscall.tbl | 105 -
 arch/powerpc/include/asm/unistd.h   |   8 +-
 arch/powerpc/kernel/syscalls/syscall.tbl| 121 +++-
 arch/s390/include/asm/unistd.h  |   2 +-
 arch/s390/kernel/syscalls/syscall.tbl   |  72 +++-
 arch/sh/include/asm/unistd.h|   4 +-
 arch/sh/kernel/syscalls/syscall.tbl |  72 +++-
 arch/sparc/include/asm/unistd.h |   8 +-
 arch/sparc/kernel/sys_sparc_64.c|  59 +-
 arch/sparc/kernel/syscalls/syscall.tbl  | 100 +++-
 arch/x86/entry/syscalls/syscall_32.tbl  |  74 +++-
 arch/x86/entry/syscalls/syscall_64.tbl  |   4 +-
 arch/x86/include/asm/unistd.h   |   8 +-
 arch/xtensa/include/asm/unistd.h|   2 +-
 arch/xtensa/kernel/syscalls/syscall.tbl |  71 
 drivers/ptp/ptp_clock.c |   2 +-
 fs/aio.c|  10 +-
 fs/select.c |   4 +-
 fs/timerfd.c|   4 +-
 fs/utimes.c |  10 +-
 include/linux/compat.h  | 104 +
 include/linux/posix-clock.h |   2 +-
 include/linux/syscalls.h|  65 ++-
 include/linux/time32.h  |  32 +-
 include/linux/time64.h  |   8 --
 include/linux/timex.h   |   4 +-
 include/uapi/asm-generic/unistd.h   | 103 -
 include/uapi/linux/time.h   |   4 -
 include/uapi/linux/timex.h  |  39 +++
 ipc/mqueue.c

[PATCH 11/11] y2038: add 64-bit time_t syscalls to all 32-bit architectures

2019-01-10 Thread Arnd Bergmann
This adds 21 new system calls on each ABI that has 32-bit time_t
today. All of these have the exact same semantics as their existing
counterparts, and the new ones all have macro names that end in 'time64'
for clarification.

This gets us to the point of being able to safely use a C library
that has 64-bit time_t in user space. There are still a couple of
loose ends to tie up in various areas of the code, but this is the
big one, and should be entirely uncontroversial at this point.

In particular, there are four system calls (getitimer, setitimer,
waitid, and getrusage) that don't have a 64-bit counterpart yet,
but these can all be safely implemented in the C library by wrapping
around the existing system calls because the 32-bit time_t they
pass only counts elapsed time, not time since the epoch. They
will be dealt with later.

Signed-off-by: Arnd Bergmann 
---
The one point that still needs to be agreed on is the actual
number assignment. Following the earlier patch that added
the sysv IPC calls with common numbers where possible, I also
tried the same here, using consistent numbers on all 32-bit
architectures.

There are a couple of minor issues with this:

- On asm-generic, we now leave the numbers from 295 to 402
  unassigned, which wastes a small amount of kernel .data
  segment. Originally I had asm-generic start at 300 and
  everyone else start at 400 here, which was also not
  perfect, and we have gone beyond 400 already, so I ended
  up just using the same numbers as the rest here.

- Once we get to 512, we clash with the x32 numbers (unless
  we remove x32 support first), and probably have to skip
  a few more. I also considered using the 512..547 space
  for 32-bit-only calls (which never clash with x32), but
  that also seems to add a bit of complexity.

- On alpha, we have already used up the space up to 527
  (with a small hole between 261 and 299). We could sync
  up with that as well, but my feeling was that alpha syscalls
  are already special enough that I don't care.

Let me know if you have other ideas.
---
 arch/alpha/kernel/syscalls/syscall.tbl  |  2 +
 arch/arm/tools/syscall.tbl  | 21 ++
 arch/arm64/include/asm/unistd.h |  2 +-
 arch/arm64/include/asm/unistd32.h   | 41 +++
 arch/ia64/kernel/syscalls/syscall.tbl   |  1 +
 arch/m68k/kernel/syscalls/syscall.tbl   | 20 +
 arch/microblaze/kernel/syscalls/syscall.tbl | 21 ++
 arch/mips/kernel/syscalls/syscall_n32.tbl   | 21 ++
 arch/mips/kernel/syscalls/syscall_n64.tbl   |  1 +
 arch/mips/kernel/syscalls/syscall_o32.tbl   | 20 +
 arch/parisc/kernel/syscalls/syscall.tbl | 21 ++
 arch/powerpc/kernel/syscalls/syscall.tbl| 20 +
 arch/s390/kernel/syscalls/syscall.tbl   | 20 +
 arch/sh/kernel/syscalls/syscall.tbl | 20 +
 arch/sparc/kernel/syscalls/syscall.tbl  | 20 +
 arch/x86/entry/syscalls/syscall_32.tbl  | 20 +
 arch/xtensa/kernel/syscalls/syscall.tbl | 21 ++
 include/uapi/asm-generic/unistd.h   | 45 -
 scripts/checksyscalls.sh| 40 ++
 19 files changed, 375 insertions(+), 2 deletions(-)

diff --git a/arch/alpha/kernel/syscalls/syscall.tbl 
b/arch/alpha/kernel/syscalls/syscall.tbl
index 25b4a7e76943..04d96d042180 100644
--- a/arch/alpha/kernel/syscalls/syscall.tbl
+++ b/arch/alpha/kernel/syscalls/syscall.tbl
@@ -456,3 +456,5 @@
 525common  pkey_free   sys_pkey_free
 526common  pkey_mprotect   sys_pkey_mprotect
 527common  rseqsys_rseq
+# all other architectures have common numbers for new syscall, alpha
+# is the exception.
diff --git a/arch/arm/tools/syscall.tbl b/arch/arm/tools/syscall.tbl
index a96d9b5ee04e..286afdc43283 100644
--- a/arch/arm/tools/syscall.tbl
+++ b/arch/arm/tools/syscall.tbl
@@ -416,3 +416,24 @@
 399common  io_pgetevents   sys_io_pgetevents_time32
 400common  migrate_pages   sys_migrate_pages
 401common  kexec_file_load sys_kexec_file_load
+# 402 is unused
+403common  clock_gettime64 sys_clock_gettime
+404common  clock_settime64 sys_clock_settime
+405common  clock_adjtime64 sys_clock_adjtime
+406common  clock_getres_time64 sys_clock_getres
+407common  clock_nanosleep_time64  sys_clock_nanosleep
+408common  timer_gettime64 sys_timer_gettime
+409common  timer_settime64 sys_timer_settime
+410common  timerfd_gettime64   sys_timerfd_gettime
+411common  timerfd_settime64   sys_timerfd_settime
+412common  utimensat_time64sys_utimensat
+413common  pselect6_time64 sys_pselect6
+414common  ppoll_time64sys_ppoll
+416common  io_pgetevents_time64

[PATCH 03/11] time: fix sys_timer_settime prototype

2019-01-10 Thread Arnd Bergmann
A small typo has crept into the y2038 conversion of the timer_settime
system call. So far this was completely harmless, but once we start
using the new version, this has to be fixed.

Fixes: 6ff847350702 ("time: Change types to new y2038 safe __kernel_itimerspec")
Signed-off-by: Arnd Bergmann 
---
 include/linux/syscalls.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 0296772e8fe5..8e86d9623d4e 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -591,7 +591,7 @@ asmlinkage long sys_timer_gettime(timer_t timer_id,
 asmlinkage long sys_timer_getoverrun(timer_t timer_id);
 asmlinkage long sys_timer_settime(timer_t timer_id, int flags,
const struct __kernel_itimerspec __user 
*new_setting,
-   struct itimerspec __user *old_setting);
+   struct __kernel_itimerspec __user *old_setting);
 asmlinkage long sys_timer_delete(timer_t timer_id);
 asmlinkage long sys_clock_settime(clockid_t which_clock,
const struct __kernel_timespec __user *tp);
-- 
2.20.0



[PATCH 01/11] time: make adjtime compat handling available for 32 bit

2019-01-10 Thread Arnd Bergmann
We want to reuse the compat_timex handling on 32-bit architectures the
same way we are using the compat handling for timespec when moving to
64-bit time_t.

Move all definitions related to compat_timex out of the compat code
into the normal timekeeping code, along with a rename to old_timex32,
corresponding to the timespec/timeval structures, and make it controlled
by CONFIG_COMPAT_32BIT_TIME, which 32-bit architectures will then select.

Signed-off-by: Arnd Bergmann 
---
 include/linux/compat.h | 35 ++-
 include/linux/time32.h | 32 -
 kernel/compat.c| 64 --
 kernel/time/posix-timers.c | 14 ++--
 kernel/time/time.c | 70 +++---
 5 files changed, 102 insertions(+), 113 deletions(-)

diff --git a/include/linux/compat.h b/include/linux/compat.h
index 056be0d03722..657ca6abd855 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -132,37 +132,6 @@ struct compat_tms {
compat_clock_t  tms_cstime;
 };
 
-struct compat_timex {
-   compat_uint_t modes;
-   compat_long_t offset;
-   compat_long_t freq;
-   compat_long_t maxerror;
-   compat_long_t esterror;
-   compat_int_t status;
-   compat_long_t constant;
-   compat_long_t precision;
-   compat_long_t tolerance;
-   struct old_timeval32 time;
-   compat_long_t tick;
-   compat_long_t ppsfreq;
-   compat_long_t jitter;
-   compat_int_t shift;
-   compat_long_t stabil;
-   compat_long_t jitcnt;
-   compat_long_t calcnt;
-   compat_long_t errcnt;
-   compat_long_t stbcnt;
-   compat_int_t tai;
-
-   compat_int_t:32; compat_int_t:32; compat_int_t:32; compat_int_t:32;
-   compat_int_t:32; compat_int_t:32; compat_int_t:32; compat_int_t:32;
-   compat_int_t:32; compat_int_t:32; compat_int_t:32;
-};
-
-struct timex;
-int compat_get_timex(struct timex *, const struct compat_timex __user *);
-int compat_put_timex(struct compat_timex __user *, const struct timex *);
-
 #define _COMPAT_NSIG_WORDS (_COMPAT_NSIG / _COMPAT_NSIG_BPW)
 
 typedef struct {
@@ -808,7 +777,7 @@ asmlinkage long compat_sys_gettimeofday(struct 
old_timeval32 __user *tv,
struct timezone __user *tz);
 asmlinkage long compat_sys_settimeofday(struct old_timeval32 __user *tv,
struct timezone __user *tz);
-asmlinkage long compat_sys_adjtimex(struct compat_timex __user *utp);
+asmlinkage long compat_sys_adjtimex(struct old_timex32 __user *utp);
 
 /* kernel/timer.c */
 asmlinkage long compat_sys_sysinfo(struct compat_sysinfo __user *info);
@@ -911,7 +880,7 @@ asmlinkage long compat_sys_open_by_handle_at(int mountdirfd,
 struct file_handle __user *handle,
 int flags);
 asmlinkage long compat_sys_clock_adjtime(clockid_t which_clock,
-struct compat_timex __user *tp);
+struct old_timex32 __user *tp);
 asmlinkage long compat_sys_sendmmsg(int fd, struct compat_mmsghdr __user *mmsg,
unsigned vlen, unsigned int flags);
 asmlinkage ssize_t compat_sys_process_vm_readv(compat_pid_t pid,
diff --git a/include/linux/time32.h b/include/linux/time32.h
index 118b9977080c..820a22e2b98b 100644
--- a/include/linux/time32.h
+++ b/include/linux/time32.h
@@ -10,6 +10,7 @@
  */
 
 #include 
+#include 
 
 #define TIME_T_MAX (time_t)((1UL << ((sizeof(time_t) << 3) - 1)) - 1)
 
@@ -35,13 +36,42 @@ struct old_utimbuf32 {
old_time32_tmodtime;
 };
 
+struct old_timex32 {
+   u32 modes;
+   s32 offset;
+   s32 freq;
+   s32 maxerror;
+   s32 esterror;
+   s32 status;
+   s32 constant;
+   s32 precision;
+   s32 tolerance;
+   struct old_timeval32 time;
+   s32 tick;
+   s32 ppsfreq;
+   s32 jitter;
+   s32 shift;
+   s32 stabil;
+   s32 jitcnt;
+   s32 calcnt;
+   s32 errcnt;
+   s32 stbcnt;
+   s32 tai;
+
+   s32:32; s32:32; s32:32; s32:32;
+   s32:32; s32:32; s32:32; s32:32;
+   s32:32; s32:32; s32:32;
+};
+
 extern int get_old_timespec32(struct timespec64 *, const void __user *);
 extern int put_old_timespec32(const struct timespec64 *, void __user *);
 extern int get_old_itimerspec32(struct itimerspec64 *its,
const struct old_itimerspec32 __user *uits);
 extern int put_old_itimerspec32(const struct itimerspec64 *its,
struct old_itimerspec32 __user *uits);
-
+struct timex;
+int get_old_timex32(struct timex *, const struct old_timex32 __user *);
+int put_old_timex32(struct old_timex32 __user *, const struct timex *);
 
 #if __BITS_PER_LONG == 64
 
diff --git a/kernel/compat.c b/kernel/compat.c
index f01affa17e22..d8a36c6ad7c9 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -20,7 +20,6 

[PATCH 04/11] sparc64: add custom adjtimex/clock_adjtime functions

2019-01-10 Thread Arnd Bergmann
sparc64 is the only architecture on Linux that has a 'timeval'
definition with a 32-bit tv_usec but a 64-bit tv_sec. This causes
problems for sparc32 compat mode when we convert it to use the
new __kernel_timex type that has the same layout as all other
64-bit architectures.

To avoid adding sparc64 specific code into the generic adjtimex
implementation, this adds a wrapper in the sparc64 system call handling
that converts the sparc64 'timex' into the new '__kernel_timex'.

At this point, the two structures are defined to be identical,
but that will change in the next step once we convert sparc32.

Signed-off-by: Arnd Bergmann 
---
 arch/sparc/kernel/sys_sparc_64.c   | 59 +-
 arch/sparc/kernel/syscalls/syscall.tbl |  6 ++-
 include/linux/timex.h  |  2 +
 kernel/time/posix-timers.c | 24 +--
 4 files changed, 76 insertions(+), 15 deletions(-)

diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
index 1c079e7bab09..37de18a11207 100644
--- a/arch/sparc/kernel/sys_sparc_64.c
+++ b/arch/sparc/kernel/sys_sparc_64.c
@@ -28,8 +28,9 @@
 #include 
 #include 
 #include 
-
+#include 
 #include 
+
 #include 
 #include 
 
@@ -544,6 +545,62 @@ SYSCALL_DEFINE2(getdomainname, char __user *, name, int, 
len)
return err;
 }
 
+SYSCALL_DEFINE1(sparc_adjtimex, struct timex __user *, txc_p)
+{
+   struct timex txc;   /* Local copy of parameter */
+   struct timex *kt = (void *)
+   int ret;
+
+   /* Copy the user data space into the kernel copy
+* structure. But bear in mind that the structures
+* may change
+*/
+   if (copy_from_user(, txc_p, sizeof(struct timex)))
+   return -EFAULT;
+
+   /*
+* override for sparc64 specific timeval type: tv_usec
+* is 32 bit wide instead of 64-bit in __kernel_timex
+*/
+   kt->time.tv_usec = txc.time.tv_usec;
+   ret = do_adjtimex(kt);
+   txc.time.tv_usec = kt->time.tv_usec;
+
+   return copy_to_user(txc_p, , sizeof(struct timex)) ? -EFAULT : ret;
+}
+
+SYSCALL_DEFINE2(sparc_clock_adjtime, const clockid_t, which_clock,struct timex 
__user *, txc_p)
+{
+   struct timex txc;   /* Local copy of parameter */
+   struct timex *kt = (void *)
+   int ret;
+
+   if (!IS_ENABLED(CONFIG_POSIX_TIMERS)) {
+   pr_err_once("process %d (%s) attempted a POSIX timer syscall "
+   "while CONFIG_POSIX_TIMERS is not set\n",
+   current->pid, current->comm);
+
+   return -ENOSYS;
+   }
+
+   /* Copy the user data space into the kernel copy
+* structure. But bear in mind that the structures
+* may change
+*/
+   if (copy_from_user(, txc_p, sizeof(struct timex)))
+   return -EFAULT;
+
+   /*
+* override for sparc64 specific timeval type: tv_usec
+* is 32 bit wide instead of 64-bit in __kernel_timex
+*/
+   kt->time.tv_usec = txc.time.tv_usec;
+   ret = do_clock_adjtime(which_clock, kt);
+   txc.time.tv_usec = kt->time.tv_usec;
+
+   return copy_to_user(txc_p, , sizeof(struct timex)) ? -EFAULT : ret;
+}
+
 SYSCALL_DEFINE5(utrap_install, utrap_entry_t, type,
utrap_handler_t, new_p, utrap_handler_t, new_d,
utrap_handler_t __user *, old_p,
diff --git a/arch/sparc/kernel/syscalls/syscall.tbl 
b/arch/sparc/kernel/syscalls/syscall.tbl
index 24ebef675184..e70110375399 100644
--- a/arch/sparc/kernel/syscalls/syscall.tbl
+++ b/arch/sparc/kernel/syscalls/syscall.tbl
@@ -258,7 +258,8 @@
 21664  sigreturn   sys_nis_syscall
 217common  clone   sys_clone
 218common  ioprio_get  sys_ioprio_get
-219common  adjtimexsys_adjtimex
compat_sys_adjtimex
+21932  adjtimexsys_adjtimex
compat_sys_adjtimex
+21964  adjtimexsys_sparc_adjtimex
 22032  sigprocmask sys_sigprocmask 
compat_sys_sigprocmask
 22064  sigprocmask sys_nis_syscall
 221common  create_module   sys_ni_syscall
@@ -377,7 +378,8 @@
 331common  prlimit64   sys_prlimit64
 332common  name_to_handle_at   sys_name_to_handle_at
 333common  open_by_handle_at   sys_open_by_handle_at   
compat_sys_open_by_handle_at
-334common  clock_adjtime   sys_clock_adjtime   
compat_sys_clock_adjtime
+33432  clock_adjtime   sys_clock_adjtime   
compat_sys_clock_adjtime
+33464  clock_adjtime   sys_sparc_clock_adjtime
 335common  syncfs  sys_syncfs
 336common  sendmmsgsys_sendmmsg
compat_sys_sendmmsg
 337common  setns   sys_setns
diff -

[PATCH 05/11] timex: use __kernel_timex internally

2019-01-10 Thread Arnd Bergmann
From: Deepa Dinamani 

struct timex is not y2038 safe.
Replace all uses of timex with y2038 safe __kernel_timex.

Note that struct __kernel_timex is an ABI interface definition.
We could define a new structure based on __kernel_timex that
is only available internally instead. Right now, there isn't
a strong motivation for this as the structure is isolated to
a few defined struct timex interfaces and such a structure would
be exactly the same as struct timex.

The patch was generated by the following coccinelle script:

virtual patch

@depends on patch forall@
identifier ts;
expression e;
@@
(
- struct timex ts;
+ struct __kernel_timex ts;
|
- struct timex ts = {};
+ struct __kernel_timex ts = {};
|
- struct timex ts = e;
+ struct __kernel_timex ts = e;
|
- struct timex *ts;
+ struct __kernel_timex *ts;
|
(memset \| copy_from_user \| copy_to_user \)(...,
- sizeof(struct timex))
+ sizeof(struct __kernel_timex))
)

@depends on patch forall@
identifier ts;
identifier fn;
@@
fn(...,
- struct timex *ts,
+ struct __kernel_timex *ts,
...) {
...
}

@depends on patch forall@
identifier ts;
identifier fn;
@@
fn(...,
- struct timex *ts) {
+ struct __kernel_timex *ts) {
...
}

Signed-off-by: Deepa Dinamani 
Cc: linux-al...@vger.kernel.org
Cc: net...@vger.kernel.org
---
 arch/alpha/kernel/osf_sys.c  |  5 +++--
 arch/sparc/kernel/sys_sparc_64.c |  4 ++--
 drivers/ptp/ptp_clock.c  |  2 +-
 include/linux/posix-clock.h  |  2 +-
 include/linux/time32.h   |  6 +++---
 include/linux/timex.h|  4 ++--
 kernel/time/ntp.c| 18 ++
 kernel/time/ntp_internal.h   |  2 +-
 kernel/time/posix-clock.c|  2 +-
 kernel/time/posix-timers.c   |  8 
 kernel/time/posix-timers.h   |  2 +-
 kernel/time/time.c   | 14 +++---
 kernel/time/timekeeping.c|  4 ++--
 13 files changed, 38 insertions(+), 35 deletions(-)

diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
index 792586038808..bf497b8b0ec6 100644
--- a/arch/alpha/kernel/osf_sys.c
+++ b/arch/alpha/kernel/osf_sys.c
@@ -1253,7 +1253,7 @@ struct timex32 {
 
 SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
 {
-struct timex txc;
+   struct __kernel_timex txc;
int ret;
 
/* copy relevant bits of struct timex. */
@@ -1270,7 +1270,8 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, 
txc_p)
if (copy_to_user(txc_p, , offsetof(struct timex32, time)) ||
(copy_to_user(_p->tick, , sizeof(struct timex32) - 
  offsetof(struct timex32, tick))) ||
-   (put_tv_to_tv32(_p->time, )))
+   (put_user(txc.time.tv_sec, _p->time.tv_sec)) ||
+   (put_user(txc.time.tv_usec, _p->time.tv_usec)))
  return -EFAULT;
 
return ret;
diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
index 37de18a11207..9825ca6a6020 100644
--- a/arch/sparc/kernel/sys_sparc_64.c
+++ b/arch/sparc/kernel/sys_sparc_64.c
@@ -548,7 +548,7 @@ SYSCALL_DEFINE2(getdomainname, char __user *, name, int, 
len)
 SYSCALL_DEFINE1(sparc_adjtimex, struct timex __user *, txc_p)
 {
struct timex txc;   /* Local copy of parameter */
-   struct timex *kt = (void *)
+   struct __kernel_timex *kt = (void *)
int ret;
 
/* Copy the user data space into the kernel copy
@@ -572,7 +572,7 @@ SYSCALL_DEFINE1(sparc_adjtimex, struct timex __user *, 
txc_p)
 SYSCALL_DEFINE2(sparc_clock_adjtime, const clockid_t, which_clock,struct timex 
__user *, txc_p)
 {
struct timex txc;   /* Local copy of parameter */
-   struct timex *kt = (void *)
+   struct __kernel_timex *kt = (void *)
int ret;
 
if (!IS_ENABLED(CONFIG_POSIX_TIMERS)) {
diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
index 48f3594a7458..79bd102c9bbc 100644
--- a/drivers/ptp/ptp_clock.c
+++ b/drivers/ptp/ptp_clock.c
@@ -124,7 +124,7 @@ static int ptp_clock_gettime(struct posix_clock *pc, struct 
timespec64 *tp)
return err;
 }
 
-static int ptp_clock_adjtime(struct posix_clock *pc, struct timex *tx)
+static int ptp_clock_adjtime(struct posix_clock *pc, struct __kernel_timex *tx)
 {
struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock);
struct ptp_clock_info *ops;
diff --git a/include/linux/posix-clock.h b/include/linux/posix-clock.h
index 3a3bc71017d5..18674d7d5b1c 100644
--- a/include/linux/posix-clock.h
+++ b/include/linux/posix-clock.h
@@ -51,7 +51,7 @@ struct posix_clock;
 struct posix_clock_operations {
struct module *owner;
 
-   int  (*clock_adjtime)(struct posix_clock *pc, struct timex *tx);
+   int  (*clock_adjtime)(struct posix_clock *pc, struct __kernel_timex 
*tx);
 
int  (*clock_gettime)(struct posix_clock *pc, struct timespec64 *ts);
 
diff --git a/include/linux/time32.h b/include/linux/time32.h
index 820a22e2b98b..0a1f302a1753 100644
--- 

Re: [PATCH 07/15] ARM: add kexec_file_load system call number

2019-01-10 Thread Arnd Bergmann
On Thu, Jan 10, 2019 at 5:39 PM Will Deacon  wrote:
>
> > diff --git a/arch/arm64/include/asm/unistd32.h 
> > b/arch/arm64/include/asm/unistd32.h
> > index 355fe2bc035b..19f3f58b6146 100644
> > --- a/arch/arm64/include/asm/unistd32.h
> > +++ b/arch/arm64/include/asm/unistd32.h
> > @@ -823,6 +823,8 @@ __SYSCALL(__NR_rseq, sys_rseq)
> >  __SYSCALL(__NR_io_pgetevents, compat_sys_io_pgetevents)
> >  #define __NR_migrate_pages 400
> >  __SYSCALL(__NR_migrate_pages, sys_migrate_pages)
> > +#define __NR_kexec_file_load 401
> > +__SYSCALL(__NR_kexec_file_load, sys_kexec_file_load)
>
> Hmm, I wonder if we need a compat wrapper for this, or are we assuming
> that the early entry code has already zero-extended the long and pointer
> arguments?

Yes, that is generally the assumption for compat syscalls.

s390 needs some extra magic to do a 31-to-64 extension on pointer
arguments, and I think sometimes we need a special wrapper to
do sign-extension of 32-bit arguments into 64-bit, but the arguments
here should not need that.

 Arnd


[PATCH 02/11] time: Add struct __kernel_timex

2019-01-10 Thread Arnd Bergmann
From: Deepa Dinamani 

struct timex uses struct timeval internally.
struct timeval is not y2038 safe.
Introduce a new UAPI type struct __kernel_timex
that is y2038 safe.

struct __kernel_timex uses a timeval type that is
similar to struct __kernel_timespec which preserves the
same structure size across 32 bit and 64 bit ABIs.
struct __kernel_timex also restructures other members of the
structure to make the structure the same on 64 bit and 32 bit
architectures.
Note that struct __kernel_timex is the same as struct timex
on a 64 bit architecture.

The above solution is similar to other new y2038 syscalls
that are being introduced: both 32 bit and 64 bit ABIs
have a common entry, and the compat entry supports the old 32 bit
syscall interface.

Alternatives considered were:
1. Add new time type to struct timex that makes use of padded
   bits. This time type could be based on the struct __kernel_timespec.
   modes will use a flag to notify which time structure should be
   used internally.
   This needs some application level changes on both 64 bit and 32 bit
   architectures. Although 64 bit machines could continue to use the
   older timeval structure without any changes.

2. Add a new u8 type to struct timex that makes use of padded bits. This
   can be used to save higher order tv_sec bits. modes will use a flag to
   notify presence of such a type.
   This will need some application level changes on 32 bit architectures.

3. Add a new compat_timex structure that differs in only the size of the
   time type; keep rest of struct timex the same.
   This requires extra syscalls to manage all 3 cases on 64 bit
   architectures. This will not need any application level changes but will
   add more complexity from kernel side.

Signed-off-by: Deepa Dinamani 
---
 include/linux/timex.h  |  7 +++
 include/uapi/linux/timex.h | 41 ++
 2 files changed, 48 insertions(+)

diff --git a/include/linux/timex.h b/include/linux/timex.h
index 39c25dbebfe8..7f40e9e42ecc 100644
--- a/include/linux/timex.h
+++ b/include/linux/timex.h
@@ -53,6 +53,13 @@
 #ifndef _LINUX_TIMEX_H
 #define _LINUX_TIMEX_H
 
+/* CONFIG_64BIT_TIME enables new 64 bit time_t syscalls in the compat path
+ * and 32-bit emulation.
+ */
+#ifndef CONFIG_64BIT_TIME
+#define __kernel_timex timex
+#endif
+
 #include 
 
 #define ADJ_ADJTIME0x8000  /* switch between adjtime/adjtimex 
modes */
diff --git a/include/uapi/linux/timex.h b/include/uapi/linux/timex.h
index 92685d826444..a1c6b73016a5 100644
--- a/include/uapi/linux/timex.h
+++ b/include/uapi/linux/timex.h
@@ -92,6 +92,47 @@ struct timex {
int  :32; int  :32; int  :32;
 };
 
+struct __kernel_timex_timeval {
+   __kernel_time64_t   tv_sec;
+   long long   tv_usec;
+};
+
+#ifndef __kernel_timex
+struct __kernel_timex {
+   unsigned int modes; /* mode selector */
+   int :32;/* pad */
+   long long offset;   /* time offset (usec) */
+   long long freq; /* frequency offset (scaled ppm) */
+   long long maxerror;/* maximum error (usec) */
+   long long esterror;/* estimated error (usec) */
+   int status; /* clock command/status */
+   int :32;/* pad */
+   long long constant;/* pll time constant */
+   long long precision;/* clock precision (usec) (read only) */
+   long long tolerance;/* clock frequency tolerance (ppm)
+  * (read only)
+  */
+   struct __kernel_timex_timeval time; /* (read only, except for 
ADJ_SETOFFSET) */
+   long long tick; /* (modified) usecs between clock ticks */
+
+   long long ppsfreq;/* pps frequency (scaled ppm) (ro) */
+   long long jitter; /* pps jitter (us) (ro) */
+   int shift;  /* interval duration (s) (shift) (ro) */
+   int :32;/* pad */
+   long long stabil;/* pps stability (scaled ppm) (ro) */
+   long long jitcnt; /* jitter limit exceeded (ro) */
+   long long calcnt; /* calibration intervals (ro) */
+   long long errcnt; /* calibration errors (ro) */
+   long long stbcnt; /* stability limit exceeded (ro) */
+
+   int tai;/* TAI offset (ro) */
+
+   int  :32; int  :32; int  :32; int  :32;
+   int  :32; int  :32; int  :32; int  :32;
+   int  :32; int  :32; int  :32;
+};
+#endif
+
 /*
  * Mode codes (timex.mode)
  */
-- 
2.20.0



Re: [PATCH 06/15] ARM: add migrate_pages() system call

2019-01-10 Thread Arnd Bergmann
On Thu, Jan 10, 2019 at 5:32 PM Will Deacon  wrote:

> > diff --git a/arch/arm64/include/asm/unistd32.h 
> > b/arch/arm64/include/asm/unistd32.h
> > index 04ee190b90fe..355fe2bc035b 100644
> > --- a/arch/arm64/include/asm/unistd32.h
> > +++ b/arch/arm64/include/asm/unistd32.h
> > @@ -821,6 +821,8 @@ __SYSCALL(__NR_statx, sys_statx)
> >  __SYSCALL(__NR_rseq, sys_rseq)
> >  #define __NR_io_pgetevents 399
> >  __SYSCALL(__NR_io_pgetevents, compat_sys_io_pgetevents)
> > +#define __NR_migrate_pages 400
> > +__SYSCALL(__NR_migrate_pages, sys_migrate_pages)
>
> Should be compat_sys_migrate_pages instead?

Yes, good catch! Fixed now.

Thanks,

Arnd


Re: [PATCH 00/15] arch: synchronize syscall tables in preparation for y2038

2019-01-10 Thread Arnd Bergmann
On Thu, Jan 10, 2019 at 5:59 PM Geert Uytterhoeven  wrote:
>
> Hi Arnd,
>
> On Thu, Jan 10, 2019 at 5:26 PM Arnd Bergmann  wrote:
> > The system call tables have diverged a bit over the years, and a number
> > of the recent additions never made it into all architectures, for one
> > reason or another.
> >
> > This is an attempt to clean it up as far as we can without breaking
> > compatibility, doing a number of steps:
>
> Thanks a lot!
>
> > - Add system calls that have not yet been integrated into all
> >   architectures but that we definitely want there.
>
> It looks like you missed wiring up io_pgetevents() on m68k.
> Is that intentional?

Yes, I thought I had described that somewhere but maybe I
forgot: semtimedop() and io_pgetevents() get replaced with
time64 versions in the follow-up, so I only added them in
64-bit architectures. If you think we should have both
io_pgetevents() and io_pgetevents_time32() on all 32-bit
architectures, I can add that as well.

  Arnd


[PATCH 11/15] mips: fix n32 compat_ipc_parse_version

2019-01-10 Thread Arnd Bergmann
While reading through the sysvipc implementation, I noticed that the n32
semctl/shmctl/msgctl system calls behave differently based on whether
o32 support is enabled or not: Without o32, the IPC_64 flag passed by
user space is rejected but calls without that flag get IPC_64 behavior.

As far as I can tell, this was inadvertently changed by a cleanup patch
but never noticed by anyone, possibly nobody has tried using sysvipc
on n32 after linux-3.19.

Change it back to the old behavior now.

Fixes: 78aaf956ba3a ("MIPS: Compat: Fix build error if CONFIG_MIPS32_COMPAT but 
no compat ABI.")
Cc: sta...@vger.kernel.org
Signed-off-by: Arnd Bergmann 
---
As stated above, this was only found by inspection, the patch is not
tested. Please review accordingly.
---
 arch/mips/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 787290781b8c..0d14f51d0002 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -3155,6 +3155,7 @@ config MIPS32_O32
 config MIPS32_N32
bool "Kernel support for n32 binaries"
depends on 64BIT
+   select ARCH_WANT_COMPAT_IPC_PARSE_VERSION
select COMPAT
select MIPS32_COMPAT
select SYSVIPC_COMPAT if SYSVIPC
-- 
2.20.0



[PATCH 05/15] alpha: update syscall macro definitions

2019-01-10 Thread Arnd Bergmann
Other architectures commonly use __NR_umount2 for sys_umount,
only ia64 and alpha use __NR_umount here. In order to synchronize
the generated tables, use umount2 like everyone else, and add back
the old name from asm/unistd.h for compatibility.

For shmat, alpha uses the osf_shmat name, we can do the same thing
here, which means we don't have to add an entry in the __IGNORE
list now that shmat is mandatory everywhere

alarm, creat, pause, time, and utime are optional everywhere
these days, no need to list them here any more.

I considered also adding the regular versions of the get*id system
calls that have different names and calling conventions on alpha,
which would further help unify the syscall ABI, but for now
I decided against that.

Signed-off-by: Arnd Bergmann 
---
 arch/alpha/include/asm/unistd.h| 6 --
 arch/alpha/include/uapi/asm/unistd.h   | 5 +
 arch/alpha/kernel/syscalls/syscall.tbl | 4 ++--
 3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/arch/alpha/include/asm/unistd.h b/arch/alpha/include/asm/unistd.h
index 21b706a5b772..564ba87bdc38 100644
--- a/arch/alpha/include/asm/unistd.h
+++ b/arch/alpha/include/asm/unistd.h
@@ -22,18 +22,12 @@
 /*
  * Ignore legacy syscalls that we don't use.
  */
-#define __IGNORE_alarm
-#define __IGNORE_creat
 #define __IGNORE_getegid
 #define __IGNORE_geteuid
 #define __IGNORE_getgid
 #define __IGNORE_getpid
 #define __IGNORE_getppid
 #define __IGNORE_getuid
-#define __IGNORE_pause
-#define __IGNORE_time
-#define __IGNORE_utime
-#define __IGNORE_umount2
 
 /* Alpha doesn't have protection keys. */
 #define __IGNORE_pkey_mprotect
diff --git a/arch/alpha/include/uapi/asm/unistd.h 
b/arch/alpha/include/uapi/asm/unistd.h
index 9ba724f116f1..4507071f995f 100644
--- a/arch/alpha/include/uapi/asm/unistd.h
+++ b/arch/alpha/include/uapi/asm/unistd.h
@@ -2,6 +2,11 @@
 #ifndef _UAPI_ALPHA_UNISTD_H
 #define _UAPI_ALPHA_UNISTD_H
 
+/* These are traditionally the names linux-alpha uses for
+ * the two otherwise generic system calls */
+#define __NR_umount__NR_umount2
+#define __NR_osf_shmat __NR_shmat
+
 #include 
 
 #endif /* _UAPI_ALPHA_UNISTD_H */
diff --git a/arch/alpha/kernel/syscalls/syscall.tbl 
b/arch/alpha/kernel/syscalls/syscall.tbl
index e09558edae73..f920b65e8c49 100644
--- a/arch/alpha/kernel/syscalls/syscall.tbl
+++ b/arch/alpha/kernel/syscalls/syscall.tbl
@@ -29,7 +29,7 @@
 19 common  lseek   sys_lseek
 20 common  getxpid sys_getxpid
 21 common  osf_mount   sys_osf_mount
-22 common  umount  sys_umount
+22 common  umount2 sys_umount
 23 common  setuid  sys_setuid
 24 common  getxuid sys_getxuid
 25 common  exec_with_loadersys_ni_syscall
@@ -183,7 +183,7 @@
 206common  semop   sys_semop
 207common  osf_utsname sys_osf_utsname
 208common  lchown  sys_lchown
-209common  osf_shmat   sys_shmat
+209common  shmat   sys_shmat
 210common  shmctl  sys_shmctl
 211common  shmdt   sys_shmdt
 212common  shmget  sys_shmget
-- 
2.20.0



[PATCH 12/15] sparc64: fix sparc_ipc type conversion

2019-01-10 Thread Arnd Bergmann
__kernel_timespec and timespec are currently the same type, but once
they are different, the type cast has to be changed here.

Signed-off-by: Arnd Bergmann 
---
 arch/sparc/kernel/sys_sparc_64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
index 274ed0b9b3e0..1c079e7bab09 100644
--- a/arch/sparc/kernel/sys_sparc_64.c
+++ b/arch/sparc/kernel/sys_sparc_64.c
@@ -344,7 +344,7 @@ SYSCALL_DEFINE6(sparc_ipc, unsigned int, call, int, first, 
unsigned long, second
goto out;
case SEMTIMEDOP:
err = sys_semtimedop(first, ptr, (unsigned int)second,
-   (const struct timespec __user *)
+   (const struct __kernel_timespec __user *)
 (unsigned long) fifth);
goto out;
case SEMGET:
-- 
2.20.0



[PATCH 03/15] ia64: assign syscall numbers for perf and seccomp

2019-01-10 Thread Arnd Bergmann
Most architectures have assigned numbers for both seccomp and
perf_event_open, even when they do not implement either.

ia64 is an exception here, so for consistency lets add numbers for both
of them. Unless CONFIG_PERF_EVENTS and CONFIG_SECCOMP are implemented,
the system calls just return -ENOSYS.

Signed-off-by: Arnd Bergmann 
---
 arch/ia64/kernel/syscalls/syscall.tbl | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/ia64/kernel/syscalls/syscall.tbl 
b/arch/ia64/kernel/syscalls/syscall.tbl
index 52585281205b..2e93dbdcdb80 100644
--- a/arch/ia64/kernel/syscalls/syscall.tbl
+++ b/arch/ia64/kernel/syscalls/syscall.tbl
@@ -337,3 +337,5 @@
 325common  pwritev2sys_pwritev2
 326common  statx   sys_statx
 327common  io_pgetevents   sys_io_pgetevents
+328common  perf_event_open sys_perf_event_open
+329common  seccomp sys_seccomp
-- 
2.20.0



[PATCH 06/15] ARM: add migrate_pages() system call

2019-01-10 Thread Arnd Bergmann
The migrate_pages system call has an assigned number on all architectures
except ARM. When it got added initially in commit d80ade7b3231 ("ARM:
Fix warning: #warning syscall migrate_pages not implemented"), it was
intentionally left out based on the observation that there are no 32-bit
ARM NUMA systems.

However, there are now arm64 NUMA machines that can in theory run 32-bit
kernels (actually enabling NUMA there would require additional work)
as well as 32-bit user space on 64-bit kernels, so that argument is no
longer very strong.

Assigning the number lets us use the system call on 64-bit kernels as well
as providing a more consistent set of syscalls across architectures.

Signed-off-by: Arnd Bergmann 
---
 arch/arm/include/asm/unistd.h | 1 -
 arch/arm/tools/syscall.tbl| 1 +
 arch/arm64/include/asm/unistd.h   | 2 +-
 arch/arm64/include/asm/unistd32.h | 2 ++
 4 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/arm/include/asm/unistd.h b/arch/arm/include/asm/unistd.h
index 88ef2ce1f69a..d713587dfcf4 100644
--- a/arch/arm/include/asm/unistd.h
+++ b/arch/arm/include/asm/unistd.h
@@ -45,7 +45,6 @@
  * Unimplemented (or alternatively implemented) syscalls
  */
 #define __IGNORE_fadvise64_64
-#define __IGNORE_migrate_pages
 
 #ifdef __ARM_EABI__
 /*
diff --git a/arch/arm/tools/syscall.tbl b/arch/arm/tools/syscall.tbl
index 8edf93b4490f..86de9eb34296 100644
--- a/arch/arm/tools/syscall.tbl
+++ b/arch/arm/tools/syscall.tbl
@@ -414,3 +414,4 @@
 397common  statx   sys_statx
 398common  rseqsys_rseq
 399common  io_pgetevents   sys_io_pgetevents
+400common  migrate_pages   sys_migrate_pages
diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h
index a7b1fc58ffdf..261216c3336e 100644
--- a/arch/arm64/include/asm/unistd.h
+++ b/arch/arm64/include/asm/unistd.h
@@ -44,7 +44,7 @@
 #define __ARM_NR_compat_set_tls(__ARM_NR_COMPAT_BASE + 5)
 #define __ARM_NR_COMPAT_END(__ARM_NR_COMPAT_BASE + 0x800)
 
-#define __NR_compat_syscalls   400
+#define __NR_compat_syscalls   401
 #endif
 
 #define __ARCH_WANT_SYS_CLONE
diff --git a/arch/arm64/include/asm/unistd32.h 
b/arch/arm64/include/asm/unistd32.h
index 04ee190b90fe..355fe2bc035b 100644
--- a/arch/arm64/include/asm/unistd32.h
+++ b/arch/arm64/include/asm/unistd32.h
@@ -821,6 +821,8 @@ __SYSCALL(__NR_statx, sys_statx)
 __SYSCALL(__NR_rseq, sys_rseq)
 #define __NR_io_pgetevents 399
 __SYSCALL(__NR_io_pgetevents, compat_sys_io_pgetevents)
+#define __NR_migrate_pages 400
+__SYSCALL(__NR_migrate_pages, sys_migrate_pages)
 
 /*
  * Please add new compat syscalls above this comment and update
-- 
2.20.0



[PATCH 07/15] ARM: add kexec_file_load system call number

2019-01-10 Thread Arnd Bergmann
A couple of architectures including arm64 already implement the
kexec_file_load system call, on many others we have assigned a system
call number for it, but not implemented it yet.

Adding the number in arch/arm/ lets us use the system call on arm64
systems in compat mode, and also reduces the number of differences
between architectures. If we want to implement kexec_file_load on ARM
in the future, the number assignment means that kexec tools can already
be built with the now current set of kernel headers.

Signed-off-by: Arnd Bergmann 
---
 arch/arm/tools/syscall.tbl| 1 +
 arch/arm64/include/asm/unistd.h   | 2 +-
 arch/arm64/include/asm/unistd32.h | 2 ++
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/arm/tools/syscall.tbl b/arch/arm/tools/syscall.tbl
index 86de9eb34296..20ed7e026723 100644
--- a/arch/arm/tools/syscall.tbl
+++ b/arch/arm/tools/syscall.tbl
@@ -415,3 +415,4 @@
 398common  rseqsys_rseq
 399common  io_pgetevents   sys_io_pgetevents
 400common  migrate_pages   sys_migrate_pages
+401common  kexec_file_load sys_kexec_file_load
diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h
index 261216c3336e..2c30e6f145ff 100644
--- a/arch/arm64/include/asm/unistd.h
+++ b/arch/arm64/include/asm/unistd.h
@@ -44,7 +44,7 @@
 #define __ARM_NR_compat_set_tls(__ARM_NR_COMPAT_BASE + 5)
 #define __ARM_NR_COMPAT_END(__ARM_NR_COMPAT_BASE + 0x800)
 
-#define __NR_compat_syscalls   401
+#define __NR_compat_syscalls   402
 #endif
 
 #define __ARCH_WANT_SYS_CLONE
diff --git a/arch/arm64/include/asm/unistd32.h 
b/arch/arm64/include/asm/unistd32.h
index 355fe2bc035b..19f3f58b6146 100644
--- a/arch/arm64/include/asm/unistd32.h
+++ b/arch/arm64/include/asm/unistd32.h
@@ -823,6 +823,8 @@ __SYSCALL(__NR_rseq, sys_rseq)
 __SYSCALL(__NR_io_pgetevents, compat_sys_io_pgetevents)
 #define __NR_migrate_pages 400
 __SYSCALL(__NR_migrate_pages, sys_migrate_pages)
+#define __NR_kexec_file_load 401
+__SYSCALL(__NR_kexec_file_load, sys_kexec_file_load)
 
 /*
  * Please add new compat syscalls above this comment and update
-- 
2.20.0



[PATCH 02/15] ia64: add statx and io_pgetevents syscalls

2019-01-10 Thread Arnd Bergmann
All architectures should implement these two, so assign numbers
and hook them up on ia64.

Signed-off-by: Arnd Bergmann 
---
 arch/ia64/kernel/syscalls/syscall.tbl | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/ia64/kernel/syscalls/syscall.tbl 
b/arch/ia64/kernel/syscalls/syscall.tbl
index e97caf51be42..52585281205b 100644
--- a/arch/ia64/kernel/syscalls/syscall.tbl
+++ b/arch/ia64/kernel/syscalls/syscall.tbl
@@ -335,3 +335,5 @@
 323common  copy_file_range sys_copy_file_range
 324common  preadv2 sys_preadv2
 325common  pwritev2sys_pwritev2
+326common  statx   sys_statx
+327common  io_pgetevents   sys_io_pgetevents
-- 
2.20.0



[PATCH 08/15] m68k: assign syscall number for seccomp

2019-01-10 Thread Arnd Bergmann
Most architectures have assigned a numbers for the seccomp syscall
even when they do not implement it.

m68k is an exception here, so for consistency lets add the number.
Unless CONFIG_SECCOMP is implemented, the system call just
returns -ENOSYS.

Signed-off-by: Arnd Bergmann 
---
 arch/m68k/kernel/syscalls/syscall.tbl | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/m68k/kernel/syscalls/syscall.tbl 
b/arch/m68k/kernel/syscalls/syscall.tbl
index 1a95c4a1bc0d..85779d6ef935 100644
--- a/arch/m68k/kernel/syscalls/syscall.tbl
+++ b/arch/m68k/kernel/syscalls/syscall.tbl
@@ -387,3 +387,4 @@
 377common  preadv2 sys_preadv2
 378common  pwritev2sys_pwritev2
 379common  statx   sys_statx
+380common  seccomp sys_seccomp
-- 
2.20.0



[PATCH 15/15] arch: add pkey and rseq syscall numbers everywhere

2019-01-10 Thread Arnd Bergmann
Most architectures define system call numbers for the rseq and pkey system
calls, even when they don't support the features, and perhaps never will.

Only a few architectures are missing these, so just define them anyway
for consistency. If we decide to add them later to one of these, the
system call numbers won't get out of sync then.

Signed-off-by: Arnd Bergmann 
---
 arch/alpha/include/asm/unistd.h | 4 
 arch/alpha/kernel/syscalls/syscall.tbl  | 4 
 arch/ia64/kernel/syscalls/syscall.tbl   | 4 
 arch/m68k/kernel/syscalls/syscall.tbl   | 4 
 arch/parisc/include/asm/unistd.h| 3 ---
 arch/parisc/kernel/syscalls/syscall.tbl | 4 
 arch/s390/include/asm/unistd.h  | 3 ---
 arch/s390/kernel/syscalls/syscall.tbl   | 3 +++
 arch/sh/kernel/syscalls/syscall.tbl | 4 
 arch/sparc/include/asm/unistd.h | 5 -
 arch/sparc/kernel/syscalls/syscall.tbl  | 4 
 arch/xtensa/kernel/syscalls/syscall.tbl | 1 +
 12 files changed, 28 insertions(+), 15 deletions(-)

diff --git a/arch/alpha/include/asm/unistd.h b/arch/alpha/include/asm/unistd.h
index 564ba87bdc38..31ad350b58a0 100644
--- a/arch/alpha/include/asm/unistd.h
+++ b/arch/alpha/include/asm/unistd.h
@@ -29,9 +29,5 @@
 #define __IGNORE_getppid
 #define __IGNORE_getuid
 
-/* Alpha doesn't have protection keys. */
-#define __IGNORE_pkey_mprotect
-#define __IGNORE_pkey_alloc
-#define __IGNORE_pkey_free
 
 #endif /* _ALPHA_UNISTD_H */
diff --git a/arch/alpha/kernel/syscalls/syscall.tbl 
b/arch/alpha/kernel/syscalls/syscall.tbl
index b0e247287908..25b4a7e76943 100644
--- a/arch/alpha/kernel/syscalls/syscall.tbl
+++ b/arch/alpha/kernel/syscalls/syscall.tbl
@@ -452,3 +452,7 @@
 521common  pwritev2sys_pwritev2
 522common  statx   sys_statx
 523common  io_pgetevents   sys_io_pgetevents
+524common  pkey_alloc  sys_pkey_alloc
+525common  pkey_free   sys_pkey_free
+526common  pkey_mprotect   sys_pkey_mprotect
+527common  rseqsys_rseq
diff --git a/arch/ia64/kernel/syscalls/syscall.tbl 
b/arch/ia64/kernel/syscalls/syscall.tbl
index 2e93dbdcdb80..84e03de00177 100644
--- a/arch/ia64/kernel/syscalls/syscall.tbl
+++ b/arch/ia64/kernel/syscalls/syscall.tbl
@@ -339,3 +339,7 @@
 327common  io_pgetevents   sys_io_pgetevents
 328common  perf_event_open sys_perf_event_open
 329common  seccomp sys_seccomp
+330common  pkey_alloc  sys_pkey_alloc
+331common  pkey_free   sys_pkey_free
+332common  pkey_mprotect   sys_pkey_mprotect
+333common  rseqsys_rseq
diff --git a/arch/m68k/kernel/syscalls/syscall.tbl 
b/arch/m68k/kernel/syscalls/syscall.tbl
index 5354ba02eed2..ae88b85d068e 100644
--- a/arch/m68k/kernel/syscalls/syscall.tbl
+++ b/arch/m68k/kernel/syscalls/syscall.tbl
@@ -388,6 +388,10 @@
 378common  pwritev2sys_pwritev2
 379common  statx   sys_statx
 380common  seccomp sys_seccomp
+381common  pkey_alloc  sys_pkey_alloc
+382common  pkey_free   sys_pkey_free
+383common  pkey_mprotect   sys_pkey_mprotect
+384common  rseqsys_rseq
 # room for arch specific calls
 393common  semget  sys_semget
 394common  semctl  sys_semctl
diff --git a/arch/parisc/include/asm/unistd.h b/arch/parisc/include/asm/unistd.h
index c2c2afb28941..9ec1026af877 100644
--- a/arch/parisc/include/asm/unistd.h
+++ b/arch/parisc/include/asm/unistd.h
@@ -12,9 +12,6 @@
 
 #define __IGNORE_select/* newselect */
 #define __IGNORE_fadvise64 /* fadvise64_64 */
-#define __IGNORE_pkey_mprotect
-#define __IGNORE_pkey_alloc
-#define __IGNORE_pkey_free
 
 #ifndef ASM_LINE_SEP
 # define ASM_LINE_SEP ;
diff --git a/arch/parisc/kernel/syscalls/syscall.tbl 
b/arch/parisc/kernel/syscalls/syscall.tbl
index 9bbd2f9f56c8..e07231de3597 100644
--- a/arch/parisc/kernel/syscalls/syscall.tbl
+++ b/arch/parisc/kernel/syscalls/syscall.tbl
@@ -367,3 +367,7 @@
 348common  pwritev2sys_pwritev2
compat_sys_pwritev2
 349common  statx   sys_statx
 350common  io_pgetevents   sys_io_pgetevents   
compat_sys_io_pgetevents
+351common  pkey_alloc  sys_pkey_alloc
+352common  pkey_free   sys_pkey_free
+353common  pkey_mprotect   sys_pkey_mprotect
+354common  rseqsys_rseq
diff --git a/arch/s390/include/asm/unistd.h b/arch/s390/include/asm/unistd.h
index a1fbf15d53aa..ed08f114ee91 100644
--- a/arch/s390/include/asm/unistd.h
+++ b/arch/s390/include/asm

[PATCH 13/15] ipc: rename old-style shmctl/semctl/msgctl syscalls

2019-01-10 Thread Arnd Bergmann
The behavior of these system calls is slightly different between
architectures, as determined by the CONFIG_ARCH_WANT_IPC_PARSE_VERSION
symbol. Most architectures that implement the split IPC syscalls don't set
that symbol and only get the modern version, but alpha, arm, microblaze,
mips-n32, mips-n64 and xtensa expect the caller to pass the IPC_64 flag.

For the architectures that so far only implement sys_ipc(), i.e. m68k,
mips-o32, powerpc, s390, sh, sparc, and x86-32, we want the new behavior
when adding the split syscalls, so we need to distinguish between the
two groups of architectures.

The method I picked for this distinction is to have a separate system call
entry point: sys_old_*ctl() now uses ipc_parse_version, while sys_*ctl()
does not. The system call tables of the five architectures are changed
accordingly.

As an additional benefit, we no longer need the configuration specific
definition for ipc_parse_version(), it always does the same thing now,
but simply won't get called on architectures with the modern interface.

A small downside is that on architectures that do set
ARCH_WANT_IPC_PARSE_VERSION, we now have an extra set of entry points
that are never called. They only add a few bytes of bloat, so it seems
better to keep them compared to adding yet another Kconfig symbol.
I considered adding new syscall numbers for the IPC_64 variants for
consistency, but decided against that for now.

Signed-off-by: Arnd Bergmann 
---
 arch/alpha/kernel/syscalls/syscall.tbl  |  6 ++--
 arch/arm/tools/syscall.tbl  |  6 ++--
 arch/arm64/include/asm/unistd32.h   |  6 ++--
 arch/microblaze/kernel/syscalls/syscall.tbl |  6 ++--
 arch/mips/kernel/syscalls/syscall_n32.tbl   |  6 ++--
 arch/mips/kernel/syscalls/syscall_n64.tbl   |  6 ++--
 arch/xtensa/kernel/syscalls/syscall.tbl |  6 ++--
 include/linux/syscalls.h|  3 ++
 ipc/msg.c   | 39 
 ipc/sem.c   | 39 
 ipc/shm.c   | 40 +
 ipc/syscall.c   | 12 +++
 ipc/util.h  | 21 ---
 kernel/sys_ni.c |  3 ++
 14 files changed, 137 insertions(+), 62 deletions(-)

diff --git a/arch/alpha/kernel/syscalls/syscall.tbl 
b/arch/alpha/kernel/syscalls/syscall.tbl
index f920b65e8c49..b0e247287908 100644
--- a/arch/alpha/kernel/syscalls/syscall.tbl
+++ b/arch/alpha/kernel/syscalls/syscall.tbl
@@ -174,17 +174,17 @@
 187common  osf_alt_sigpending  sys_ni_syscall
 188common  osf_alt_setsid  sys_ni_syscall
 199common  osf_swapon  sys_swapon
-200common  msgctl  sys_msgctl
+200common  msgctl  sys_old_msgctl
 201common  msgget  sys_msgget
 202common  msgrcv  sys_msgrcv
 203common  msgsnd  sys_msgsnd
-204common  semctl  sys_semctl
+204common  semctl  sys_old_semctl
 205common  semget  sys_semget
 206common  semop   sys_semop
 207common  osf_utsname sys_osf_utsname
 208common  lchown  sys_lchown
 209common  shmat   sys_shmat
-210common  shmctl  sys_shmctl
+210common  shmctl  sys_old_shmctl
 211common  shmdt   sys_shmdt
 212common  shmget  sys_shmget
 213common  osf_mvalid  sys_ni_syscall
diff --git a/arch/arm/tools/syscall.tbl b/arch/arm/tools/syscall.tbl
index 20ed7e026723..b54b7f2bc24a 100644
--- a/arch/arm/tools/syscall.tbl
+++ b/arch/arm/tools/syscall.tbl
@@ -314,15 +314,15 @@
 297common  recvmsg sys_recvmsg
 298common  semop   sys_semop   sys_oabi_semop
 299common  semget  sys_semget
-300common  semctl  sys_semctl
+300common  semctl  sys_old_semctl
 301common  msgsnd  sys_msgsnd
 302common  msgrcv  sys_msgrcv
 303common  msgget  sys_msgget
-304common  msgctl  sys_msgctl
+304common  msgctl  sys_old_msgctl
 305common  shmat   sys_shmat
 306common  shmdt   sys_shmdt
 307common  shmget  sys_shmget
-308common  shmctl  sys_shmctl
+308common  shmctl  sys_old_shmctl
 309common  add_key sys_add_key
 310common  request_key sys_request_key
 311common  keyctl  sys_keyctl
diff --git a/arch/arm64/include/asm/unistd32

[PATCH 00/15] arch: synchronize syscall tables in preparation for y2038

2019-01-10 Thread Arnd Bergmann
The system call tables have diverged a bit over the years, and a number
of the recent additions never made it into all architectures, for one
reason or another.

This is an attempt to clean it up as far as we can without breaking
compatibility, doing a number of steps:

- Add system calls that have not yet been integrated into all
  architectures but that we definitely want there.

- Add the separate ipc syscalls on all architectures that
  traditionally only had sys_ipc(). This version is done without
  support for IPC_OLD that is we have in sys_ipc. The
  new semtimedop_time64 syscall will only be added here, not
  in sys_ipc

- Add syscall numbers for a couple of syscalls that we probably
  don't need everywhere, in particular pkey_* and rseq,
  for the purpose of symmetry: if it's in asm-generic/unistd.h,
  it makes sense to have it everywhere.

- Prepare for having the same system call numbers for any future
  calls. In combination with the generated tables, this hopefully
  makes it easier to add new calls across all architectures
  together.

Most of the contents of this series are unrelated to the actual
y2038 work, but for the moment, that second series is based on
this one. If there are any concerns about changes here, I
can drop or rewrite any individual patch in this series.

My plan is to merge any patches in this series that are found
to be good together with the y2038 patches for linux-5.1, so
please review and provide Acks for merging through my tree,
or pick them up for 5.0 if they seem urgent enough.

  Arnd

Arnd Bergmann (15):
  ia64: add __NR_umount2 definition
  ia64: add statx and io_pgetevents syscalls
  ia64: assign syscall numbers for perf and seccomp
  alpha: wire up io_pgetevents system call
  alpha: update syscall macro definitions
  ARM: add migrate_pages() system call
  ARM: add kexec_file_load system call number
  m68k: assign syscall number for seccomp
  sh: remove duplicate unistd_32.h file
  sh: add statx system call
  mips: fix n32 compat_ipc_parse_version
  sparc64: fix sparc_ipc type conversion
  ipc: rename old-style shmctl/semctl/msgctl syscalls
  arch: add split IPC system calls where needed
  arch: add pkey and rseq syscall numbers everywhere

 arch/alpha/include/asm/unistd.h |  10 -
 arch/alpha/include/uapi/asm/unistd.h|   5 +
 arch/alpha/kernel/syscalls/syscall.tbl  |  15 +-
 arch/arm/include/asm/unistd.h   |   1 -
 arch/arm/tools/syscall.tbl  |   8 +-
 arch/arm64/include/asm/unistd.h |   2 +-
 arch/arm64/include/asm/unistd32.h   |  10 +-
 arch/ia64/include/asm/unistd.h  |  14 -
 arch/ia64/include/uapi/asm/unistd.h |   2 +
 arch/ia64/kernel/syscalls/syscall.tbl   |  10 +-
 arch/m68k/kernel/syscalls/syscall.tbl   |  16 +
 arch/microblaze/kernel/syscalls/syscall.tbl |   6 +-
 arch/mips/Kconfig   |   1 +
 arch/mips/kernel/syscalls/syscall_n32.tbl   |   6 +-
 arch/mips/kernel/syscalls/syscall_n64.tbl   |   6 +-
 arch/mips/kernel/syscalls/syscall_o32.tbl   |  11 +
 arch/parisc/include/asm/unistd.h|   3 -
 arch/parisc/kernel/syscalls/syscall.tbl |   4 +
 arch/powerpc/kernel/syscalls/syscall.tbl|  12 +
 arch/s390/include/asm/unistd.h  |   3 -
 arch/s390/kernel/syscalls/syscall.tbl   |  15 +
 arch/sh/include/uapi/asm/unistd_32.h| 403 
 arch/sh/kernel/syscalls/syscall.tbl |  16 +
 arch/sparc/include/asm/unistd.h |   5 -
 arch/sparc/kernel/sys_sparc_64.c|   2 +-
 arch/sparc/kernel/syscalls/syscall.tbl  |  16 +
 arch/x86/entry/syscalls/syscall_32.tbl  |  11 +
 arch/xtensa/kernel/syscalls/syscall.tbl |   7 +-
 include/linux/syscalls.h|   3 +
 ipc/msg.c   |  39 +-
 ipc/sem.c   |  39 +-
 ipc/shm.c   |  40 +-
 ipc/syscall.c   |  12 +-
 ipc/util.h  |  21 +-
 kernel/sys_ni.c |   3 +
 35 files changed, 271 insertions(+), 506 deletions(-)
 delete mode 100644 arch/sh/include/uapi/asm/unistd_32.h

-- 
2.20.0
Cc: i...@jurassic.park.msu.ru
Cc: matts...@gmail.com
Cc: li...@armlinux.org.uk
Cc: catalin.mari...@arm.com
Cc: will.dea...@arm.com
Cc: tony.l...@intel.com
Cc: fenghua...@intel.com
Cc: ge...@linux-m68k.org
Cc: mon...@monstr.eu
Cc: paul.bur...@mips.com
Cc: del...@gmx.de
Cc: m...@ellerman.id.au
Cc: schwidef...@de.ibm.com
Cc: heiko.carst...@de.ibm.com
Cc: dal...@libc.org
Cc: da...@davemloft.net
Cc: l...@kernel.org
Cc: t...@linutronix.de
Cc: mi...@redhat.com
Cc: h...@zytor.com
Cc: x...@kernel.org
Cc: jcmvb...@gmail.com
Cc: a...@arndb.de
Cc: firoz.k...@linaro.org
Cc: ebied...@xmission.com
Cc: deepa.ker...@gmail.com
Cc: li...@dominikbrodowski.net
Cc: a...@linux-foundation.org
Cc: d...@stgolabs.net
Cc: linux-al...@vger.kernel.org
Cc: linux-ker

[PATCH 10/15] sh: add statx system call

2019-01-10 Thread Arnd Bergmann
statx is available on almost all other architectures but
got missed on sh, so add it now.

Signed-off-by: Arnd Bergmann 
---
 arch/sh/kernel/syscalls/syscall.tbl | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/sh/kernel/syscalls/syscall.tbl 
b/arch/sh/kernel/syscalls/syscall.tbl
index 21ec75288562..a70db013dbc7 100644
--- a/arch/sh/kernel/syscalls/syscall.tbl
+++ b/arch/sh/kernel/syscalls/syscall.tbl
@@ -390,3 +390,4 @@
 380common  copy_file_range sys_copy_file_range
 381common  preadv2 sys_preadv2
 382common  pwritev2sys_pwritev2
+383common  statx   sys_statx
-- 
2.20.0



[PATCH 14/15] arch: add split IPC system calls where needed

2019-01-10 Thread Arnd Bergmann
The IPC system call handling is highly inconsistent across architectures,
some use sys_ipc, some use separate calls, and some use both.  We also
have some architectures that require passing IPC_64 in the flags, and
others that set it implicitly.

For the additon of a y2083 safe semtimedop() system call, I chose to only
support the separate entry points, but that requires first supporting
the regular ones with their own syscall numbers.

The IPC_64 is now implied by the new semctl/shmctl/msgctl system
calls even on the architectures that require passing it with the ipc()
multiplexer.

I'm not adding the new semtimedop() or semop() on 32-bit architectures,
those will get implemented using the new semtimedop_time64() version
that gets added along with the other time64 calls.
Three 64-bit architectures (powerpc, s390 and sparc) get semtimedop().

Signed-off-by: Arnd Bergmann 
---
One aspect here that might be a bit controversial is the use of
the same system call numbers across all architectures, synchronizing
all of them with the x86-32 numbers. With the new syscall.tbl
files, I hope we can just keep doing that in the future, and no
longer require the architecture maintainers to assign a number.

This is mainly useful for implementers of the C libraries: if
we can add future system calls everywhere at the same time, using
a particular version of the kernel headers also guarantees that
the system call number macro is visible.
---
 arch/m68k/kernel/syscalls/syscall.tbl | 11 +++
 arch/mips/kernel/syscalls/syscall_o32.tbl | 11 +++
 arch/powerpc/kernel/syscalls/syscall.tbl  | 12 
 arch/s390/kernel/syscalls/syscall.tbl | 12 
 arch/sh/kernel/syscalls/syscall.tbl   | 11 +++
 arch/sparc/kernel/syscalls/syscall.tbl| 12 
 arch/x86/entry/syscalls/syscall_32.tbl| 11 +++
 7 files changed, 80 insertions(+)

diff --git a/arch/m68k/kernel/syscalls/syscall.tbl 
b/arch/m68k/kernel/syscalls/syscall.tbl
index 85779d6ef935..5354ba02eed2 100644
--- a/arch/m68k/kernel/syscalls/syscall.tbl
+++ b/arch/m68k/kernel/syscalls/syscall.tbl
@@ -388,3 +388,14 @@
 378common  pwritev2sys_pwritev2
 379common  statx   sys_statx
 380common  seccomp sys_seccomp
+# room for arch specific calls
+393common  semget  sys_semget
+394common  semctl  sys_semctl
+395common  shmget  sys_shmget
+396common  shmctl  sys_shmctl
+397common  shmat   sys_shmat
+398common  shmdt   sys_shmdt
+399common  msgget  sys_msgget
+400common  msgsnd  sys_msgsnd
+401common  msgrcv  sys_msgrcv
+402common  msgctl  sys_msgctl
diff --git a/arch/mips/kernel/syscalls/syscall_o32.tbl 
b/arch/mips/kernel/syscalls/syscall_o32.tbl
index 3d5a47b80d2b..fa47ea8cc6ef 100644
--- a/arch/mips/kernel/syscalls/syscall_o32.tbl
+++ b/arch/mips/kernel/syscalls/syscall_o32.tbl
@@ -380,3 +380,14 @@
 366o32 statx   sys_statx
 367o32 rseqsys_rseq
 368o32 io_pgetevents   sys_io_pgetevents   
compat_sys_io_pgetevents
+# room for arch specific calls
+393o32 semget  sys_semget
+394o32 semctl  sys_semctl  
compat_sys_semctl
+395o32 shmget  sys_shmget
+396o32 shmctl  sys_shmctl  
compat_sys_shmctl
+397o32 shmat   sys_shmat   
compat_sys_shmat
+398o32 shmdt   sys_shmdt
+399o32 msgget  sys_msgget
+400o32 msgsnd  sys_msgsnd  
compat_sys_msgsnd
+401o32 msgrcv  sys_msgrcv  
compat_sys_msgrcv
+402o32 msgctl  sys_msgctl  
compat_sys_msgctl
diff --git a/arch/powerpc/kernel/syscalls/syscall.tbl 
b/arch/powerpc/kernel/syscalls/syscall.tbl
index db3bbb8744af..1bffab54ff35 100644
--- a/arch/powerpc/kernel/syscalls/syscall.tbl
+++ b/arch/powerpc/kernel/syscalls/syscall.tbl
@@ -425,3 +425,15 @@
 386nospu   pkey_mprotect   sys_pkey_mprotect
 387nospu   rseqsys_rseq
 388nospu   io_pgetevents   sys_io_pgetevents   
compat_sys_io_pgetevents
+# room for arch specific syscalls
+39264  semtimedop  sys_semtimedop
+393common  semget  sys_semget
+394common  semctl  sys_semctl

[PATCH 09/15] sh: remove duplicate unistd_32.h file

2019-01-10 Thread Arnd Bergmann
When I merged this patch, the file was accidentally left intact
instead of being removed, which means any changes to syscall.tbl
have no effect.

Fixes: 2b3c5a99d5f3 ("sh: generate uapi header and syscall table header files")
Signed-off-by: Arnd Bergmann 
---
 arch/sh/include/uapi/asm/unistd_32.h | 403 ---
 1 file changed, 403 deletions(-)
 delete mode 100644 arch/sh/include/uapi/asm/unistd_32.h

diff --git a/arch/sh/include/uapi/asm/unistd_32.h 
b/arch/sh/include/uapi/asm/unistd_32.h
deleted file mode 100644
index 31c85aa251ab..
--- a/arch/sh/include/uapi/asm/unistd_32.h
+++ /dev/null
@@ -1,403 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef __ASM_SH_UNISTD_32_H
-#define __ASM_SH_UNISTD_32_H
-
-/*
- * Copyright (C) 1999  Niibe Yutaka
- */
-
-/*
- * This file contains the system call numbers.
- */
-
-#define __NR_restart_syscall 0
-#define __NR_exit1
-#define __NR_fork2
-#define __NR_read3
-#define __NR_write   4
-#define __NR_open5
-#define __NR_close   6
-#define __NR_waitpid 7
-#define __NR_creat   8
-#define __NR_link9
-#define __NR_unlink 10
-#define __NR_execve 11
-#define __NR_chdir  12
-#define __NR_time   13
-#define __NR_mknod  14
-#define __NR_chmod  15
-#define __NR_lchown 16
-/* 17 was sys_break */
-#define __NR_oldstat18
-#define __NR_lseek  19
-#define __NR_getpid 20
-#define __NR_mount  21
-#define __NR_umount 22
-#define __NR_setuid 23
-#define __NR_getuid 24
-#define __NR_stime  25
-#define __NR_ptrace 26
-#define __NR_alarm  27
-#define __NR_oldfstat   28
-#define __NR_pause  29
-#define __NR_utime  30
-/* 31 was sys_stty */
-/* 32 was sys_gtty */
-#define __NR_access 33
-#define __NR_nice   34
-/* 35 was sys_ftime */
-#define __NR_sync   36
-#define __NR_kill   37
-#define __NR_rename 38
-#define __NR_mkdir  39
-#define __NR_rmdir  40
-#define __NR_dup41
-#define __NR_pipe   42
-#define __NR_times  43
-/* 44 was sys_prof */
-#define __NR_brk45
-#define __NR_setgid 46
-#define __NR_getgid 47
-#define __NR_signal 48
-#define __NR_geteuid49
-#define __NR_getegid50
-#define __NR_acct   51
-#define __NR_umount252
-/* 53 was sys_lock */
-#define __NR_ioctl  54
-#define __NR_fcntl  55
-/* 56 was sys_mpx */
-#define __NR_setpgid57
-/* 58 was sys_ulimit */
-/* 59 was sys_olduname */
-#define __NR_umask  60
-#define __NR_chroot 61
-#define __NR_ustat  62
-#define __NR_dup2   63
-#define __NR_getppid64
-#define __NR_getpgrp65
-#define __NR_setsid 66
-#define __NR_sigaction  67
-#define __NR_sgetmask   68
-#define __NR_ssetmask   69
-#define __NR_setreuid   70
-#define __NR_setregid   71
-#define __NR_sigsuspend 72
-#define __NR_sigpending 73
-#define __NR_sethostname74
-#define __NR_setrlimit  75
-#define __NR_getrlimit  76 /* Back compatible 2Gig limited rlimit 
*/
-#define __NR_getrusage  77
-#define __NR_gettimeofday   78
-#define __NR_settimeofday   79
-#define __NR_getgroups  80
-#define __NR_setgroups  81
-/* 82 was sys_oldselect */
-#define __NR_symlink83
-#define __NR_oldlstat   84
-#define __NR_readlink   85
-#define __NR_uselib 86
-#define __NR_swapon 87
-#define __NR_reboot 88
-#define __NR_readdir89
-#define __NR_mmap   90
-#define __NR_munmap 91
-#define __NR_truncate   92
-#define __NR_ftruncate  93
-#define __NR_fchmod 94
-#define __NR_fchown 95
-#define __NR_getpriority96
-#define __NR_setpriority97
-/* 98 was sys_profil */
-#define __NR_statfs 99
-#define __NR_fstatfs   100
-   /* 101 was sys_ioperm */
-#define __NR_socketcall102
-#define __NR_syslog103
-#define __NR_setitimer 104
-#define __NR

Re: [PATCH] m68k/atari: Avoid VLA use in atari_switches_setup()

2019-01-08 Thread Arnd Bergmann
On Mon, Jan 7, 2019 at 10:29 AM Geert Uytterhoeven  wrote:
>
> With gcc 7.3.0:
>
> arch/m68k/atari/config.c: In function ‘atari_switches_setup’:
> arch/m68k/atari/config.c:151:2: warning: ISO C90 forbids variable length 
> array ‘switches’ [-Wvla]
>   char switches[strlen(str) + 1];
>   ^~~~
>
> Replace the variable size by the maximum kernel command line size (512
> bytes), which is an upper limit for all suboptions.
>
> Signed-off-by: Geert Uytterhoeven 

Seems fine as long as COMMAND_LINE_SIZE never grows a lot. Some
architectures use 1024 or 2048, but m68k currently has 256 (you write
512 here).

 Arnd


Re: [PATCH v8 20/25] powerpc, fbdev: Use arch_nvram_ops methods instead of nvram_read_byte() and nvram_write_byte()

2018-12-31 Thread Arnd Bergmann
On Sun, Dec 30, 2018 at 12:43 AM Finn Thain  wrote:

>
> Is there some benefit, or is that just personal taste?
>
> Avoiding changes to call sites avoids code review, but I think 1) the
> thinkpad_acpi changes have already been reviewed and 2) the fbdev changes
> need review anyway.
>
> Your suggesion would add several new entities and one extra layer of
> indirection.
>
> I think indirection harms readability because now the reader now has to go
> and look up the meaning of the new entities.
>
> It's not the case that we need to choose between definitions of
> nvram_read_byte() at compile time, or stub them out:
>
> #ifdef CONFIG_FOO
> static inline unsigned char nvram_read_byte(int addr)
> {
> return arch_nvram_ops.read_byte(addr);
> }
> #else
> static inline unsigned char nvram_read_byte(int addr) { }
> #endif
>
> And I don't anticipate a need for a macro here either:
>
> #define nvram_read_byte(a) random_nvram_read_byte_impl(a)
>
> I think I've used the simplest solution.

Having the indirection would help if the inline function can
encapsulate the NULL pointer check, like

static inline unsigned char nvram_read_byte(loff_t addr)
{
   char data;

   if (!IS_ENABLED(CONFIG_NVRAM))
 return 0xff;

   if (arch_nvram_ops.read_byte)
 return arch_nvram_ops.read_byte(addr);

   if (arch_nvram_ops.read)
 return arch_nvram_ops.read(char, 1, );

  return 0xff;
}

(the above assumes no #ifdef in the structure definition, if you
keep the #ifdef there they have to be added here as well).

  Arnd


Re: [PATCH v8 00/25] Re-use nvram module

2018-12-31 Thread Arnd Bergmann
On Sun, Dec 30, 2018 at 5:05 AM Finn Thain  wrote:
>
> On Sun, 30 Dec 2018, I wrote:
>
> >
> > I'm not opposed to exported functions in place of a singleton ops
> > struct. Other things being equal I'm inclined toward the ops struct,
> > perhaps because I like encapsulation or perhaps because I don't like
> > excess generality. (That design decision was made years ago and I don't
> > remember the reasoning.)
>
> The rationale for the ops struct was that it offers introspection.
>
> It turns out that PPC64 device drivers don't care about byte-at-a-time
> accessors and X86 device drivers don't care about checksum validation.
> But that only gets us so far.
>
> We still needed a way to find out whether the arch has provided
> byte-at-a-time accessors (i.e. PPC32 and M68K Mac) or byte range accessors
> (i.e. PPC64 and those platforms with checksummed NVRAM like X86 and M68K
> Atari).
>
> You can't resolve this question at build time for a multi-platform kernel
> binary, so pre-processor tricks don't help.
>
> Device drivers tend to want to access NVRAM one byte at a time. With this
> patch series, those platforms which need checksum validation always set
> byte-at-a-time methods to NULL. (Hence the atari_scsi changes in patch 3.)
>
> The char misc driver is quite different to the usual device drivers,
> because the struct file_operations methods always access a byte range.
>
> The NULL methods in the ops struct allow the nvram.c misc device to avoid
> inefficient byte-at-a-time accessors where possible, just as
> arch/powerpc/kernel/nvram_64.c presently does.


Ok, I see. That sounds absolutely reasonable, so let's stay with
the structure as you proposed.

   Arnd


Re: [PATCH v8 13/25] m68k: Dispatch nvram_ops calls to Atari or Mac functions

2018-12-31 Thread Arnd Bergmann
On Sun, Dec 30, 2018 at 11:12 PM Finn Thain  wrote:
> On Sun, 30 Dec 2018, LEROY Christophe wrote:

> But I'm over-simplifying. Arnd's alternative actually goes like this,
>
> #if defined(CONFIG_MAC) && !defined(CONFIG_ATARI)
> const struct nvram_ops arch_nvram_ops = {
> /* ... */
> }
> #elif !defined(CONFIG_MAC) && defined(CONFIG_ATARI)
> const struct nvram_ops arch_nvram_ops = {
> /* ... */
> }
> #elif defined(CONFIG_MAC) && defined(CONFIG_ATARI)
> const struct nvram_ops arch_nvram_ops = {
> /* ... */
> }
> #endif
>
> So, you're right, this isn't "duplication", it's "triplication".

Ok, I failed to realized that MAC and ATARI are not mutually exclusive.
I agree that your original version is best then.

   Arnd


Re: [PATCH v8 18/25] powerpc: Implement nvram sync ioctl

2018-12-31 Thread Arnd Bergmann
On Sun, Dec 30, 2018 at 8:25 AM Finn Thain  wrote:
>
> On Sat, 29 Dec 2018, Arnd Bergmann wrote:
>
> > > --- a/drivers/char/nvram.c
> > > +++ b/drivers/char/nvram.c
> > > @@ -48,6 +48,10 @@
> > >  #include 
> > >  #include 
> > >
> > > +#ifdef CONFIG_PPC
> > > +#include 
> > > +#include 
> > > +#endif
> > >
> > >  static DEFINE_MUTEX(nvram_mutex);
> > >  static DEFINE_SPINLOCK(nvram_state_lock);
> > > @@ -331,6 +335,37 @@ static long nvram_misc_ioctl(struct file *file, 
> > > unsigned int cmd,
> > > long ret = -ENOTTY;
> > >
> > > switch (cmd) {
> > > +#ifdef CONFIG_PPC
> > > +   case OBSOLETE_PMAC_NVRAM_GET_OFFSET:
> > > +   pr_warn("nvram: Using obsolete PMAC_NVRAM_GET_OFFSET 
> > > ioctl\n");
> > > +   /* fall through */
> > > +   case IOC_NVRAM_GET_OFFSET:
> > > +   ret = -EINVAL;
> > > +#ifdef CONFIG_PPC_PMAC
> >
> > I think it would make be nicer here to keep the ppc bits in arch/ppc,
> > and instead add a .ioctl() callback to nvram_ops.
> >
>
> The problem with having an nvram_ops.ioctl() method is the code in the
> !PPC branch. That code would get duplicated because it's needed by both
> X86 and M68K, to implement the checksum ioctls.

I was thinking you'd just have a common ioctl function that falls
back to the .ioctl callback for any unhandled commands like

switch (cmd) {
case NVRAM_INIT:
 ...
 break;
case ...:
 break;
default:
 if (ops->ioctl)
 return ops->ioctl(...);
 return -EINVAL;
}

Would that work?

   Arnd


Re: [PATCH v8 00/25] Re-use nvram module

2018-12-29 Thread Arnd Bergmann
On Wed, Dec 26, 2018 at 1:43 AM Finn Thain  wrote:

> This allows for removal of drivers/char/generic_nvram.c as well as some
> duplicated code in arch/powerpc/kernel/nvram_64.c. By reducing the number
> of /dev/nvram char misc device implementations, the number of bugs and
> inconsistencies is also reduced.
>
> This patch series reduces inconsistencies between PPC32 and PPC64, and
> between PPC_PMAC and MAC. A uniform API has benefits for userspace.
> For example, some error codes for some ioctl calls become consistent
> across PowerPC platforms. The uniform API can potentially benefit
> bootloaders that work across different platforms which all have XPRAM
> (e.g. Emile).
>
> I think there are two reasonable merge strategies for this patch series.
> The char misc maintainer could take the entire series. Alternatively the
> m68k maintainer could take patches 1 thru 14, and after those patches
> reach mainline the powerpc maintainer could take 15 thru 25 (even though
> patch 21 is not powerpc-related).

I had a look at the complete series now, and I think this is a great cleanup.
I replied with a couple of minor comments that you may or may not want
to address first.

The one thing I would like to see resolved (I hope this doesn't bring
back an old discussion you had already concluded) is regarding
the use of a global exported structure of function pointers, as opposed
to using either directly exported functions (with a consistent interface)
or a boot-time selectable structure like dma_map_ops or ppc_md.

Arnd


Re: [PATCH v8 24/25] powerpc: Adopt nvram module for PPC64

2018-12-29 Thread Arnd Bergmann
On Wed, Dec 26, 2018 at 1:43 AM Finn Thain  wrote:

> +static ssize_t ppc_nvram_get_size(void)
> +{
> +   if (ppc_md.nvram_size)
> +   return ppc_md.nvram_size();
> +   return -ENODEV;
> +}

> +const struct nvram_ops arch_nvram_ops = {
> +   .read   = ppc_nvram_read,
> +   .write  = ppc_nvram_write,
> +   .get_size   = ppc_nvram_get_size,
> +   .sync   = ppc_nvram_sync,
> +};

Coming back to this after my comment on the m68k side, I notice that
there is now a double indirection through function pointers. Have you
considered completely removing the operations from ppc_md instead
by having multiple copies of nvram_ops?

With the current method, it does seem odd to have a single
per-architecture instance of the exported structure containing
function pointers. This doesn't give us the flexibility of having
multiple copies in the kernel the way that ppc_md does, but it adds
overhead compared to simply exporting the functions directly.

   Arnd


Re: [PATCH v8 13/25] m68k: Dispatch nvram_ops calls to Atari or Mac functions

2018-12-29 Thread Arnd Bergmann
On Wed, Dec 26, 2018 at 1:43 AM Finn Thain  wrote:

> +
> +static ssize_t m68k_nvram_get_size(void)
> +{
> +   if (MACH_IS_ATARI)
> +   return atari_nvram_get_size();
> +   else if (MACH_IS_MAC)
> +   return mac_pram_get_size();
> +   return -ENODEV;
> +}
> +
> +/* Atari device drivers call .read (to get checksum validation) whereas
> + * Mac and PowerMac device drivers just use .read_byte.
> + */
> +const struct nvram_ops arch_nvram_ops = {
> +#ifdef CONFIG_MAC
> +   .read_byte  = m68k_nvram_read_byte,
> +   .write_byte = m68k_nvram_write_byte,
> +#endif
> +#ifdef CONFIG_ATARI
> +   .read   = m68k_nvram_read,
> +   .write  = m68k_nvram_write,
> +   .set_checksum   = m68k_nvram_set_checksum,
> +   .initialize = m68k_nvram_initialize,
> +#endif
> +   .get_size   = m68k_nvram_get_size,
> +};
> +EXPORT_SYMBOL(arch_nvram_ops);

Since the operations are almost entirely distinct, why not have two
separate 'nvram_ops' instances here that each refer to just
the set they actually need?

I was actually expecting one more patch here that would make the
arch_nvram_ops a pointer to one of multiple structures, which would
be easier to do with multiple copies, but I suppose there is no need
for that here (there might be on ppc, I have to look again).

   Arnd


Re: [PATCH v8 18/25] powerpc: Implement nvram sync ioctl

2018-12-29 Thread Arnd Bergmann
> --- a/drivers/char/nvram.c
> +++ b/drivers/char/nvram.c
> @@ -48,6 +48,10 @@
>  #include 
>  #include 
>
> +#ifdef CONFIG_PPC
> +#include 
> +#include 
> +#endif
>
>  static DEFINE_MUTEX(nvram_mutex);
>  static DEFINE_SPINLOCK(nvram_state_lock);
> @@ -331,6 +335,37 @@ static long nvram_misc_ioctl(struct file *file, unsigned 
> int cmd,
> long ret = -ENOTTY;
>
> switch (cmd) {
> +#ifdef CONFIG_PPC
> +   case OBSOLETE_PMAC_NVRAM_GET_OFFSET:
> +   pr_warn("nvram: Using obsolete PMAC_NVRAM_GET_OFFSET 
> ioctl\n");
> +   /* fall through */
> +   case IOC_NVRAM_GET_OFFSET:
> +   ret = -EINVAL;
> +#ifdef CONFIG_PPC_PMAC

I think it would make be nicer here to keep the ppc bits in arch/ppc,
and instead add a .ioctl() callback to nvram_ops.

> @@ -369,12 +405,14 @@ static int nvram_misc_open(struct inode *inode, struct 
> file *file)
> return -EBUSY;
> }
>
> +#ifndef CONFIG_PPC
> /* Prevent multiple writers if the set_checksum ioctl is implemented. 
> */
> if ((arch_nvram_ops.set_checksum != NULL) &&
> (file->f_mode & FMODE_WRITE) && (nvram_open_mode & NVRAM_WRITE)) {
> spin_unlock(_state_lock);
> return -EBUSY;
> }
> +#endif
>
> diff --git a/include/linux/nvram.h b/include/linux/nvram.h
> index b7bfaec60a43..24a57675dba1 100644
> --- a/include/linux/nvram.h
> +++ b/include/linux/nvram.h
> @@ -18,8 +18,12 @@ struct nvram_ops {
> unsigned char   (*read_byte)(int);
> void(*write_byte)(unsigned char, int);
> ssize_t (*get_size)(void);
> +#ifdef CONFIG_PPC
> +   long(*sync)(void);
> +#else
> long(*set_checksum)(void);
> long(*initialize)(void);
> +#endif
>  };

Maybe just leave all entries visible here, and avoid the above #ifdef checks.

   Arnd


Re: [PATCH] Raise the minimum required gcc version to 4.6

2018-12-29 Thread Arnd Bergmann
On Sat, Dec 29, 2018 at 3:25 PM Geert Uytterhoeven  wrote:

> On Fri, Aug 24, 2018 at 12:00 AM Joe Perches  wrote:
> > On Thu, 2018-08-23 at 23:52 +0200, Geert Uytterhoeven wrote:
> --- 
> build.log.linux-4.20.0-atari-07795-g835f16c9b68966ff-gcc-4.1.2-20061115-prerelease-Ubuntu-4.1.1-21
> +++ 
> build.log.linux-4.20.0-atari-07767-gc085b9fd60f52a62-gcc-7.3.0-27ubuntu1~18.04
>
> 20 warning regressions:
>   + arch/m68k/atari/config.c: warning: ISO C90 forbids variable length
> array ‘switches’ [-Wvla]:  => 151:2

Ah, so we still have some of these. The warning was only recently added.

>   + arch/m68k/include/asm/cmpxchg.h: warning: value computed is not
> used [-Wunused-value]:  => 79:22, 122:3, 137:3

IIRC this can be avoided using a ({ ... }) type expression.

>   + arch/m68k/include/asm/raw_io.h: warning: cast to pointer from
> integer of different size [-Wint-to-pointer-cast]:  => 20:19, 33:35,
> 26:31, 30:32

The I/O accessors are defined in an unusual way that defeats a lot
of the type checking we normally have. Generally speaking the
memory space operations (readl/ioread32/__raw_readl, ...) should
be inline functions taking a 'const volatile void __iomem *' argument
(non-const for writel), while the I/O space operations should take
an integer port number (16 or 32 bit, depending on how your ISA
or PCI buses work).

Doing that should avoid all the warnings you quote here, but may
introduce warnings about nonportable driver code.

>   + arch/m68k/include/asm/string.h: warning: argument 2 null where
> non-null expected [-Wnonnull]:  => 72:25

This might be a kernel bug.

>   + arch/m68k/kernel/setup_mm.c: warning: #warning Are you building an
> allnoconfig kernel? [-Wcpp]:  => 51:2
>   + arch/m68k/kernel/setup_mm.c: warning: #warning No CPU/platform
> type selected, your kernel will not work! [-Wcpp]:  => 50:2
>   + arch/m68k/mvme147/config.c: warning: #warning check me! [-Wcpp]:  => 150:2
>   + arch/m68k/mvme16x/config.c: warning: #warning check me! [-Wcpp]:  => 397:2

I've removed that kind of warning from other architectures.

>   + arch/m68k/kernel/signal.c: warning: ISO C90 forbids variable
> length array ‘buf’ [-Wvla]:  => 654:3

You can probably pick the maximum here.

>   + drivers/i2c/i2c-core-base.c: warning: ‘ret’ may be used
> uninitialized in this function [-Wmaybe-uninitialized]:  => 235:5

This might come from the new CONFIG_NO_AUTO_INLINE.

>   + drivers/input/joystick/analog.c: warning: #warning Precise timer
> not defined for this architecture. [-Wcpp]:  => 172:2

Maybe add a Kconfig dependency on !M68K?

>   + include/linux/dynamic_debug.h: warning: statement will never be
> executed [-Wswitch-unreachable]:  => 115:19

No idea.

>   + warning: unmet direct dependencies detected for NEED_MULTIPLE_NODES:  => 
> N/A
>   + warning: unmet direct dependencies detected for SND_SOC_QDSP6:  => N/A

Not gcc warnings.

  Arnd


Re: [PATCH v8 01/25] scsi/atari_scsi: Don't select CONFIG_NVRAM

2018-12-29 Thread Arnd Bergmann
On Sat, Dec 29, 2018 at 3:51 AM Michael Schmitz  wrote:
>
> Hi Finn,
>
> Am 29.12.2018 um 15:34 schrieb Finn Thain:
> > On Sat, 29 Dec 2018, Michael Schmitz wrote:
> >
> >>
> >> IS_BUILTIN(CONFIG_NVRAM) is probably what Christophe really meant to 
> >> suggest.
> >>
> >> Or (really going out on a limb here):
> >>
> >> IS_BUILTIN(CONFIG_NVRAM) ||
> >> ( IS_MODULE(CONFIG_ATARI_SCSI) && IS_ENABLED(CONFIG_NVRAM) )
> >>
> >> Not that I'd advocate that, for this series.
> >>
> >
> > Well, you are a maintainer for atari_scsi.c.
> >
> > Are you saying that you want IS_BUILTIN(CONFIG_NVRAM) used here instead of
> > ifdef?
>
> No, just pointing out that there would be a way to avoid the ifdef
> without messing up driver behaviour. I'm fine with the ifdef - not least
> because it clearly eliminates code that would be unreachable.
>
> (On second thought - I don't want to speculate whether there's weird
> compiler options that could result in the nvram_check_checksum and
> nvram_read_bytes symbols to still be referenced in the final link, even
> though IS_BUILTIN(CONFIG_NVRAM) always evaluates to false. Best leave
> this as-is.)

As far as I know, it's totally reliable with the supported compilers (gcc-4.6+).
In the older compilers (e.g. 4.1), there was a corner case, where it could
have failed to eliminate a function that was only referenced through a pointer
from a discarded variable, but a plain IS_ENABLED() check like the one here
was still ok, and lots of code relies on that.

Other than that, I agree either way is totally fine here, so no objections
to using the #ifdef.

  Arnd


Re: Linux 4.19 in Debian FTBFS with "undefined reference to `strcmp'"

2018-12-19 Thread Arnd Bergmann
On Wed, Dec 19, 2018 at 10:37 AM Geert Uytterhoeven
 wrote:
>
> Hi Arnd,
>
> Are you seeing this issue (gcc replacing calls to strncmp() by strcmp() behind
> our back, causing link errors later), too?
>
> See also 
> https://lore.kernel.org/lkml/28ebe45d-3dbd-2a82-f537-b0725f7a2...@infradead.org/

I haven't run into this one I think, but it looks like a bug in the kernel
yo me to only provide an inline version of strcmp() and not an exported symbol.

Arnd

>
> On Wed, Dec 19, 2018 at 10:32 AM Geert Uytterhoeven
>  wrote:
> > On Wed, Dec 19, 2018 at 9:39 AM Finn Thain  
> > wrote:
> > > On Tue, 18 Dec 2018, John Paul Adrian Glaubitz wrote:
> > > > Could someone quickly remind me how to fix the linking issue when 
> > > > building Linux 4.19
> > > > on m68k [1]?
> > > >
> > >
> > > Here's the patch that I use. I don't know what the best fix is.
> > > https://github.com/fthain/linux/commit/8fa8322eb20f8d1fdd4228742e45d0400e1dfa15
> >
> > Porbably the best fix is to follow Andreas' advice, and replace the
> > calls to strncmp() by
> > direct calls to strcmp()?
> >
> > > --
> > >
> > > > + ld -m m68kelf --build-id -X -o .tmp_vmlinux1 -T 
> > > > ./arch/m68k/kernel/vmlinux.lds --whole-archive built-in.a 
> > > > --no-whole-archive --start-group lib/lib.a arch/m68k/lib/lib.a 
> > > > --end-group
> > > > /usr/bin/ld: block/partitions/ldm.o: in function `ldm_parse_tocblock':
> > > > ./debian/build/build_m68k_none_m68k/./block/partitions/ldm.c:153: 
> > > > undefined reference to `strcmp'
> > > > /usr/bin/ld: 
> > > > ./debian/build/build_m68k_none_m68k/./block/partitions/ldm.c:163: 
> > > > undefined reference to `strcmp'
> > > > /usr/bin/ld: drivers/rtc/rtc-proc.o: in function `is_rtc_hctosys':
> > > > ./debian/build/build_m68k_none_m68k/./drivers/rtc/rtc-proc.c:33: 
> > > > undefined reference to `strcmp'


Re: m68k using deprecated internal APIs?

2018-11-10 Thread Arnd Bergmann
On Fri, Nov 9, 2018 at 12:42 AM Finn Thain  wrote:
> On Sun, 28 Oct 2018, Geert Uytterhoeven wrote:
> > > > The example I gave was GENERIC_CLOCKEVENTS on m68, which is
> > > > supported on most but not all machines there.
> > >
> > > That suggests that the removal of just those machines would suffice
> > > (as opposed to the removal of the entire arch).
> > >
> > > Also, Documentation/features/time/clockevents/arch-support.txt says,
> > > |m68k: |  ok  |
> > >
> > > These two observations make me wonder whether the clockevents feature
> > > is related to the discussion quoted above (?)
> >
> > GENERIC_CLOCKEVENTS is selected only for a few Coldfire CPU types.
> >
>
> !GENERIC_CLOCKEVENTS implies PREEMPT_NONE, and disables the "Timers
> subsystem" (i.e. the NO_HZ config options), but it works fine -- I was
> able to convert the Mac port to !ARCH_USES_GETTIMEOFFSET &&
> !GENERIC_CLOCKEVENTS. (Like many of the Coldfire CPU types.)
>
> You can see those patches here,
> https://github.com/fthain/linux/commits/mac68k-queue/
>
> Note that !ARCH_USES_GETTIMEOFFSET is a build-time choice, meaning that
> all platforms need to be converted together.
>
> Also, some platforms will need to adopt the clocksource API, otherwise the
> built-in "jiffies" clocksource will get used, causing a regression in
> timer accuracy.
>
> Conversion to the clocksource API is straight-forward where the platform
> already implements arch_gettimeoffset. The conversion is discussed in
> include/linux/time.h:
>
> /* Some architectures do not supply their own clocksource.
>  * This is mainly the case in architectures that get their
>  * inter-tick times by reading the counter on their interval
>  * timer. Since these timers wrap every tick, they're not really
>  * useful as clocksources. Wrapping them to act like one is possible
>  * but not very efficient. So we provide a callout these arches
>  * can implement for use with the jiffies clocksource to provide
>  * finer then tick granular time.
>  */
>
> (Not sure what is meant by "not very efficient" here.)
>
> Certain 680x0 platforms do not implement arch_gettimeoffset: apollo, q40,
> sun3, sun3x. These platforms can fall back on the "jiffies" clocksource
> with no loss of timer accuracy, so conversion for these platforms is
> trivial.
>
> Should I continue with the clocksource API conversion for the other
> platforms: amiga, atari, bvme6000, hp300, mvme147, mvme16x? This would
> allow for removal of "select ARCH_USES_GETTIMEOFFSET" (and satisfy
> Documentation/features/time/modern-timekeeping) without loss of timer
> accuracy.
>
> Alternatively, we could defer the clocksource API conversion, leaving it
> up to the platform maintainers (who can actually test the driver changes).
> But that would mean that many platforms would suffer a regression in timer
> accuracy upon removal of arch_gettimeoffset.

Adding the timekeeping maintainers and Linus Walleij to Cc. Linus
worked on removing ARCH_USES_GETTIMEOFFSET on ARM
several platforms in the past.

I noticed that the last timer rework involving
CONFIG_ARCH_USES_GETTIMEOFFSET was back in 2012 with
commit 7b1f62076bba ("time: convert arch_gettimeoffset to a pointer").
At the time, we had cris, m32r, blackfin, m68k and lots of ARM
platforms, now it's only two StrongARM platforms (RPC and
ARCH_EBSA110)  and classic m68k.

   Arnd


Re: m68k using deprecated internal APIs?

2018-10-29 Thread Arnd Bergmann
On Mon, Oct 29, 2018 at 2:58 AM Greg Ungerer  wrote:
> I have been working on and maintaining parts of m68k for a long time,
> and I was not aware that there was a number of problem areas that are
> causing real pain. Maybe a friendly email from subsystem maintainers that
> see issues would go a long way. At least if the m68k (and other arch)
> communities know they can work toward solutions sooner rather than later.
>
> Talk of ultimatums seems a bit heavy handed when only one side seems
> to be aware there is a problem.

Adding Ted to Cc, as he was the one that brought up the ultimatum, and
James who raised the broader question of the long-term prospects of
32-bit hardware.

I have to admit that I failed to direct the maintainer summit discussion
the way I had originally intended. I started off with the eight architectures
that got removed, as an example for stuff that was already known to
be basically completely unused (for mainline Linux), and how it took me
a long time to be really sure that we are not hurting any remaining users.

I did not think (and still don't) that we are going to be removing further
CPU architectures any time soon, with the possible exception of those
that no longer have any compiler that can build them (unicore32 only has
a gcc-4.5 binary that no longer works, hexagon has 4.6 sources and binary
that barely work).

The real question that we tried to resolve is how we can more generally
find out whether a driver is still being used or not when it gets in the
way of some API conversion. This most often involves drivers for PC
add-on cards (network, scsi, ide, isdn, ...) and old bus interconnects
(ISA, EISA, previously MCA), but can also affect architectures from those
days (alpha, parisc, m68k). The conflict here is that unmaintained and
unused drivers are a burden for any treewide API changes in
particular because there is nobody who can test or Ack the changes,
but removing those drivers too aggressively is certain to hit some
users that still require the drivers and simply update their kernels
too infrequently to test changes in time.

I brought up m68k in particular as it was used on the oldest machines
I could find, sun3: To my best knowledge, the last working version of
Linux on this hardware was 2.6.26 with the addition of a simple patch that
was (and presumably still is) needed to get access to the serial console.

My guess is that aside from the popular m68k platforms (amiga, atari,
coldfire and mac and a one or two I'm not familiar with), there is a lot of
code that has not been used on many years. The same thing is certainly
true of mips, ppc, sh, and arm, all of which could benefit from having
someone take a critical look at which platforms were actually ever
properly supported at any point. When we did that on ARM a few years
ago, we ended up removing several that seemed promising when they
initially got added but that were not completed before the people working
on them moved on, or that had worked at some point but stopped
compiling several years earlier without anyone noticing.

  Arnd


Re: m68k using deprecated internal APIs?

2018-10-27 Thread Arnd Bergmann
On Sat, Oct 27, 2018 at 5:02 PM Geert Uytterhoeven  wrote:
>
> Hi Arnd,
>
> https://lwn.net/Articles/769468/ wrote:
> >  For example, the m68k architecture uses a number of internal APIs that no 
> > other
> > architecture needs at this point; removing that architecture would enable 
> > removing
> > the APIs as well
>
> and
>
> > Ted Ts'o suggested that an ultimatum could be made: either the m68k 
> > architecture
> > stops using the old, deprecated timer API (for example) within one year or 
> > it is
> > removed from the kernel.
>
> Which APIs are these exactly?

The example I gave was GENERIC_CLOCKEVENTS on m68, which is
supported on most but not all machines there. This is also missing on
a couple of others (ia64 at least, not sure what else). Another one would
be having CLKDEV_LOOKUP without COMMON_CLK. This one is not
a problem for m68k but is for a couple of ARM and MIPS platforms
that have not yet been converted to COMMON_CLK.

There are probably a couple more like this. I don't actually see any that
are /only/ used by m68k, but there are some interfaces that would be
good to stop using overall to keep things simpler.

   Arnd


Re: [PATCH v3 5/5] m68k: add __IGNORE* entries in asm/unistd.h

2018-10-01 Thread Arnd Bergmann
On Mon, Oct 1, 2018 at 2:39 PM Firoz Khan  wrote:
>
> Add __IGNORE* entries for seccomp, pkey_mprotect, pkey_
> alloc, pkey_free, io_pgetevents and rseq in the file
> asm/unistd.h as it is correct to keep __IGNORE* entry in
> non uapi header asm/unistd.h while uapi/asm/unistd.h must
> hold information only useful for user space applications.
>
> Signed-off-by: Firoz Khan 
> ---
>  arch/m68k/include/asm/unistd.h | 7 +++
>  1 file changed, 7 insertions(+)

I think this one needs to be dropped, as I commented on a similar patch for
another architecture (I forget which one). We really should implemente all
the syscalls below, with the possible exception of the pkey calls.

Note that we even list pkey_* in architectures that don't support the feature.
See also the commit text for a60f7b69d92c ("generic syscalls: Wire up
memory protection keys syscalls")

 Arnd


Re: [PATCH] m68k/mac: Rework patch "use time64_t in RTC handling"

2018-07-24 Thread Arnd Bergmann
On Tue, Jul 24, 2018 at 9:07 AM, Finn Thain  wrote:
> This addresses the issues arising from commit 324caa29cd04
> ("m68k: mac: use time64_t in RTC handling").
>
> Adopt __u32 for the union in via_read_time(), consistent with changes
> to via_write_time().
>
> Use low_32_bits() in via_write_time(), consistent with changes to
> pmu_write_time() and cuda_write_time().
>
> Have via_read_time() return a time64_t, consistent with changes to
> pmu_read_time and cuda_read_time().
>
> Drop the pointless wraparound conditional in via_read_time().
>
> Cc: Arnd Bergmann 
> Signed-off-by: Finn Thain 

Reviewed-by: Arnd Bergmann 

Thanks for fixing it up!
--
To unsubscribe from this list: send the line "unsubscribe linux-m68k" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 0/6] Symbol namespaces

2018-07-24 Thread Arnd Bergmann
On Tue, Jul 24, 2018 at 10:09 AM, Martijn Coenen  wrote:
> Hi Arnd,
>
> On Mon, Jul 23, 2018 at 4:28 PM, Arnd Bergmann  wrote:
>> This looks nice. I don't want to overload you with additional
>> requests, but it might be good to think about how this can
>> be taken further, if we want to actually convert large
>> parts of the kernel to it.
>
> No worries about overloading, I'm happy with all feedback to make this better.
>
>> I have two ideas:
>>
>> - It would be nice to have a simple mechanism in Kconfig
>>   to put all symbols in a module into a namespace that is
>>   derived from KBUILD_MODNAME, to avoid having to
>>   annotate every symbol separately. This could be similar
>>   to how we ended up dealing with EXPORT_NO_SYMBOLS
>>   in the linux-2.4 days, with the goal of eventually having
>>   a namespace for each symbol. Similarly, we could pass
>>   a number of default namespaces through the Makefile,
>>   e.g. if we have a directory that has lots of drivers that all
>>   import the symbols from a common subsystem module.
>
> I'm hinging on two thoughts here; I really like it because it
> obviously reduces work and makes this easier to use. On the other
> hand, you now have to look in multiple places to see if a symbol is
> exported to a namespace/imported from a module. Perhaps it depends on
> how coarse-grained the namespaces end up being. Either way, I think it
> would be pretty easy to cook up patches for this.

Ok, maybe try it and see where we get with it?

>> - If this is possible to implement, it would be great to have
>>   a way to limit the globally visible symbols in a module
>>   to the ones that are explicitly exported  even when a that
>>   module is built-in rather than loadable. Not sure how this
>>   is best done though. A couple of things can be done with
>>   objcopy, or possibly by reintroducing partial linking (which
>>   was removed not too long ago).
>
> If I understand you correctly, this is orthogonal to symbol
> namespaces, right?

Right, the only connection here is that both try to limit the
scope of which symbols are available where. This can definitely
be done without symbol namespaces. The implementation I
had in mind with objcopy might end up using the same
KBUILD_MODNAME as a prefix for internal symbols (which
are not exported to modules), but that is a different problem.

Another related area is the question what happens to symbols
that we want to share between two built-in parts of the kernel
without exporting them to modules. E.g. if we might want to
put all of vfs into one built-in module and make its symbols
private to that module, while all of the mm subsystem is in a
separate built-in module. The symbols that are needed for
communicating between the two could simply be exported
with EXPORT_SYMBOL_GPL(), but we that would open the
surface to loadable modules that can't access them today.
Using namespaces could solve that problem by limiting the
scope in another way, or we could come up with a different
method to annotate them, such as using the gcc visibility
 attributes.

> Do you think these things should be a part of these series, or can it
> be a follow-up?

If you think you can do the first thing easily, I'd say we should
try to come up with an idea of where we want to take this in
the long run. For limiting the scope of global symbols, that may
well be a much bigger task to do upfront, so unless you have an
idea for how to do that, maybe keep it in mind but let's not make
it a dependency.

  Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-m68k" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 0/6] Symbol namespaces

2018-07-23 Thread Arnd Bergmann
On Mon, Jul 16, 2018 at 2:21 PM, Martijn Coenen  wrote:
> As of Linux 4.17, there are more than 3 exported symbols
> in the kernel. There seems to be some consensus amongst
> kernel devs that the export surface is too large, and hard
> to reason about.
>
> Generally, these symbols fall in one of these categories:
> 1) Symbols actually meant for drivers
> 2) Symbols that are only exported because functionality is
>split over multiple modules, yet they really shouldn't
>be used by modules outside of their own subsystem
> 3) Symbols really only meant for in-tree use
>
> When module developers try to upstream their code, it
> regularly turns out that they are using exported symbols
> that they really shouldn't be using. This problem is even
> bigger for drivers that are currently out-of-tree, which
> may be using many symbols that they shouldn't be using,
> and that break when those symbols are removed or modified.
>
> This patch allows subsystem maintainers to partition their
> exported symbols into separate namespaces, and module
> authors to import such namespaces only when needed.
>
> This allows subsystem maintainers to more easily limit
> availability of these namespaced symbols to other parts of
> the kernel. It can also be used to partition the set of
> exported symbols for documentation purposes; for example,
> a set of symbols that is really only used for debugging
> could be in a "SUBSYSTEM_DEBUG" namespace.

This looks nice. I don't want to overload you with additional
requests, but it might be good to think about how this can
be taken further, if we want to actually convert large
parts of the kernel to it. I have two ideas:

- It would be nice to have a simple mechanism in Kconfig
  to put all symbols in a module into a namespace that is
  derived from KBUILD_MODNAME, to avoid having to
  annotate every symbol separately. This could be similar
  to how we ended up dealing with EXPORT_NO_SYMBOLS
  in the linux-2.4 days, with the goal of eventually having
  a namespace for each symbol. Similarly, we could pass
  a number of default namespaces through the Makefile,
  e.g. if we have a directory that has lots of drivers that all
  import the symbols from a common subsystem module.

- If this is possible to implement, it would be great to have
  a way to limit the globally visible symbols in a module
  to the ones that are explicitly exported  even when a that
  module is built-in rather than loadable. Not sure how this
  is best done though. A couple of things can be done with
  objcopy, or possibly by reintroducing partial linking (which
  was removed not too long ago).

Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-m68k" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] [v2] m68k: mac: use time64_t in RTC handling

2018-07-18 Thread Arnd Bergmann
On Wed, Jul 18, 2018 at 3:49 PM, Finn Thain  wrote:
> On Wed, 18 Jul 2018, Arnd Bergmann wrote:

>>
>> -static long via_read_time(void)
>> +static time64_t via_read_time(void)
>>  {
>> union {
>> __u8 cdata[4];
>> -   long idata;
>> +   __u32 idata;
>> } result, last_result;
>> +   time64_t ret;
>
> ret isn't used.
>
>> int count = 1;
>>
>> via_pram_command(0x81, _result.cdata[3]);
>> @@ -279,12 +280,8 @@ static long via_read_time(void)
>> via_pram_command(0x89, [1]);
>> via_pram_command(0x8D, [0]);
>>
>> -   if (result.idata == last_result.idata) {
>> -   if (result.idata < RTC_OFFSET)
>> -   result.idata += 0x1ull;
>> -
>> -   return result.idata - RTC_OFFSET;
>> -   }
>> +   if (result.idata == last_result.idata)
>> +   return (time64_t(result.idata) - RTC_OFFSET);
>>
>
> Did you mean to write,
>
> return (time64_t)result.idata - RTC_OFFSET;
>
> ?

Right, I should have at least tried to build it again.

  Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-m68k" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] [v2] m68k: mac: use time64_t in RTC handling

2018-07-18 Thread Arnd Bergmann
On Wed, Jul 18, 2018 at 2:02 PM, Finn Thain  wrote:
> On Wed, 18 Jul 2018, Geert Uytterhoeven wrote:
>
>>
>> Thanks for your patch!
>>
>> Applied and queued for v4.19, with the WARN_ON() dropped.
>>
>
> The patch you've committed to your for-v4.19 branch has this hunk:
>
> @@ -269,8 +275,12 @@ static long via_read_time(void)
> via_pram_command(0x89, [1]);
> via_pram_command(0x8D, [0]);
>
> -   if (result.idata == last_result.idata)
> +   if (result.idata == last_result.idata) {
> +   if (result.idata < RTC_OFFSET)
> +   result.idata += 0x1ull;
> +
> return result.idata - RTC_OFFSET;
> +   }
>
> if (++count > 10)
> break;
>
> That looks bogus to me, since result.idata is a long.



> Also, the following hunk seems a bit pointless (?)
>
> @@ -291,11 +301,11 @@ static long via_read_time(void)
>   * is basically any machine with Mac II-style ADB.
>   */
>
> -static void via_write_time(long time)
> +static void via_write_time(time64_t time)
>  {
> union {
> __u8 cdata[4];
> -   long idata;
> +   __u32 idata;
> } data;
> __u8 temp;
>
>
> But if data.idata needs to be changed to __u32 here, why not change the
> same struct member in via_read_time() also?

Hmm, apparently I forgot to update via_read_time(), that one
is indeed bogus and now inconsistent with the other functions.

The change in via_write_time() seems at least consistent wtih
what we do elsewhere, and using __u32 makes this code
more portable. (yes, I realize that 64-bit powermac doesn't
use the VIA RTC, but it feels better to write code portably
anyway).

I'd suggest we do it like below to make it consistent with the
rest again, using the 1904..2040 range of dates and no warning
for invalid dates.

If you agree, I'll send that as a proper patch.

   Arnd

diff --git a/arch/m68k/mac/misc.c b/arch/m68k/mac/misc.c
index bf8df47a6d09..8335509969f1 100644
--- a/arch/m68k/mac/misc.c
+++ b/arch/m68k/mac/misc.c
@@ -255,12 +255,13 @@ static void via_write_pram(int offset, __u8 data)
  * is basically any machine with Mac II-style ADB.
  */

-static long via_read_time(void)
+static time64_t via_read_time(void)
 {
union {
__u8 cdata[4];
-   long idata;
+   __u32 idata;
} result, last_result;
+   time64_t ret;
int count = 1;

via_pram_command(0x81, _result.cdata[3]);
@@ -279,12 +280,8 @@ static long via_read_time(void)
via_pram_command(0x89, [1]);
via_pram_command(0x8D, [0]);

-   if (result.idata == last_result.idata) {
-   if (result.idata < RTC_OFFSET)
-   result.idata += 0x1ull;
-
-   return result.idata - RTC_OFFSET;
-   }
+   if (result.idata == last_result.idata)
+   return (time64_t(result.idata) - RTC_OFFSET);

if (++count > 10)
break;
--
To unsubscribe from this list: send the line "unsubscribe linux-m68k" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/3] [v2] powerpc: mac: fix rtc read/write functions

2018-07-09 Thread Arnd Bergmann
On Sun, Jul 1, 2018 at 5:47 PM, Meelis Roos  wrote:
> A patch for the subject is now upstream. That made me finally take some
> time to test it on my PowerMac G4. Tha date is OK but I get two warnings
> with backtrace on bootup. Full dmesg below.

Thanks for testing this, and sorry for the slow reply.

> [4.026490] WARNING: CPU: 0 PID: 1 at 
> arch/powerpc/platforms/powermac/time.c:154 pmu_get_time+0x7c/0xc8
> [4.032261] Modules linked in:
> [4.037878] CPU: 0 PID: 1 Comm: swapper Tainted: GW 
> 4.18.0-rc2-00223-g1904148a361a #88
> [4.043750] NIP:  c0021354 LR: c0021308 CTR: 
> [4.049585] REGS: ef047cd0 TRAP: 0700   Tainted: GW  
> (4.18.0-rc2-00223-g1904148a361a)
> [4.055572] MSR:  00029032   CR: 44000222  XER: 2000
> [4.061620]
>GPR00: c0021308 ef047d80 ef048000  00d7029c 0004 
> 0001 009c
>GPR08: 00d7 0001 0200 c06a 24000228  
> c0004c9c 
>GPR16:       
> c067 c0601a38
>GPR24: 0008 c0630f18 c062a40c c05fc10c ef047e50 ef273800 
> ef047e50 ef047e50
> [4.092393] NIP [c0021354] pmu_get_time+0x7c/0xc8
> [4.098596] LR [c0021308] pmu_get_time+0x30/0xc8

I don't see how the WARN_ON() triggered unless the PMU time is
actually before 1970.

> [4.104779] Call Trace:
> [4.110909] [ef047d80] [c0021308] pmu_get_time+0x30/0xc8 (unreliable)
> [4.117209] [ef047df0] [c00213e8] pmac_get_rtc_time+0x28/0x40
> [4.123470] [ef047e00] [c000bc04] rtc_generic_get_time+0x20/0x34
> [4.129770] [ef047e10] [c03aca34] __rtc_read_time+0x5c/0xe0
> [4.136060] [ef047e20] [c03acafc] rtc_read_time+0x44/0x7c
> [4.142356] [ef047e40] [c061e000] rtc_hctosys+0x64/0x11c
> [4.148616] [ef047ea0] [c0004aa4] do_one_initcall+0x4c/0x1a8
> [4.154866] [ef047f00] [c06022f0] kernel_init_freeable+0x12c/0x1f4
> [4.161123] [ef047f30] [c0004cb4] kernel_init+0x18/0x130
> [4.167359] [ef047f40] [c00121c4] ret_from_kernel_thread+0x14/0x1c
> [4.173610] Instruction dump:
> [4.179766] 8941002e 5484c00e 5508801e 88e1002f 7c844214 554a402e 7c845214 
> 7c843a14
> [4.186076] 7d244810 7d294910 7d2948f8 552907fe <0f09> 3d2083da 
> 80010074 38210070
> [4.192388] ---[ end trace 2e01ad9337fe08fd ]---
> [4.198643] rtc-generic rtc-generic: hctosys: unable to read the hardware 
> clock

The last message here happens exactly in that case as well: tm_year is before
1970:

int rtc_valid_tm(struct rtc_time *tm)
{
if (tm->tm_year < 70
|| ((unsigned)tm->tm_mon) >= 12
|| tm->tm_mday < 1
|| tm->tm_mday > rtc_month_days(tm->tm_mon, tm->tm_year + 1900)
|| ((unsigned)tm->tm_hour) >= 24
|| ((unsigned)tm->tm_min) >= 60
|| ((unsigned)tm->tm_sec) >= 60)
return -EINVAL;

return 0;
}

The most likely explanation I have here is that the RTC was indeed set to an
incorrect date, either because of a depleted battery (not unlikely for
a ~15 year
old box) or because it was previously stored incorrectly. You say that the
time is correct, but that could also be the case if the machine is connected to
the network and synchronized using NTP. It should not have gotten the
time from the RTC after that error.

If you have the time to do another test, can you boot the machine with
its network disconnected, see if the warning persists (it may have been
repaired after the correct time got written into the RTC during shutdown),
what the output of 'sudo hwclock' is, and whether anything changes after
you set the correct time using 'hwclock --systohc' and reboot?

 Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-m68k" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/3] [v2] powerpc: mac: fix rtc read/write functions

2018-06-27 Thread Arnd Bergmann
On Wed, Jun 27, 2018 at 6:32 AM, Michael Ellerman  wrote:
>
> So I think I can take this patch in isolation via the powerpc tree as a
> fix for 4.18.
>
> I'll leave the other two alone.
>

Yes, that is what I had intended with this series but should have made
clearer. The two m68k patches are 4.19 material.

  Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-m68k" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


  1   2   3   >