Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/compat/linux32/common Always clear FUTEX_PRIVATE_FLAG fo...



details:   https://anonhg.NetBSD.org/src/rev/42253ff10ca6
branches:  trunk
changeset: 932238:42253ff10ca6
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sun May 03 01:06:55 2020 +0000

description:
Always clear FUTEX_PRIVATE_FLAG for Linux processes.  NetBSD-native futexes
exist in different namespace depending on FUTEX_PRIVATE_FLAG.  This appears
not to be the case in Linux, and some futex users will mix private and non-
private ops on the same futex object.  Provide a convenience wrapper that
puts this logic in one place witn a comment explaining why.

While here, move the Linux futex wrapper out of its own file and plop
it in linux_misc.c, which is where it lives in the linux32 module.

diffstat:

 sys/compat/linux/arch/alpha/files.linux_alpha     |   3 +-
 sys/compat/linux/arch/amd64/linux_commons.c       |   5 +-
 sys/compat/linux/arch/arm/linux_commons.c         |   5 +-
 sys/compat/linux/arch/i386/linux_commons.c        |   5 +-
 sys/compat/linux/arch/m68k/files.linux_m68k       |   3 +-
 sys/compat/linux/arch/mips/files.linux_mips       |   3 +-
 sys/compat/linux/arch/powerpc/files.linux_powerpc |   3 +-
 sys/compat/linux/common/linux_exec.c              |   7 +-
 sys/compat/linux/common/linux_futex.c             |  87 -----------------------
 sys/compat/linux/common/linux_misc.c              |  61 +++++++++++++++-
 sys/compat/linux/common/linux_misc.h              |   4 +-
 sys/compat/linux32/common/linux32_misc.c          |   6 +-
 12 files changed, 79 insertions(+), 113 deletions(-)

diffs (truncated from 395 to 300 lines):

diff -r c737f64a9e17 -r 42253ff10ca6 sys/compat/linux/arch/alpha/files.linux_alpha
--- a/sys/compat/linux/arch/alpha/files.linux_alpha     Sat May 02 22:19:47 2020 +0000
+++ b/sys/compat/linux/arch/alpha/files.linux_alpha     Sun May 03 01:06:55 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.linux_alpha,v 1.10 2019/03/24 16:24:19 maxv Exp $
+#      $NetBSD: files.linux_alpha,v 1.11 2020/05/03 01:06:55 thorpej Exp $
 #
 # Config file description for alpha-dependent Linux compat code.
 
@@ -9,6 +9,5 @@
 file   compat/linux/arch/alpha/linux_sysent.c          compat_linux
 file   compat/linux/common/linux_fadvise64.c           compat_linux
 file   compat/linux/common/linux_file64.c              compat_linux
-file   compat/linux/common/linux_futex.c               compat_linux
 file   compat/linux/common/linux_olduname.c            compat_linux
 file   compat/linux/common/linux_sigaction.c           compat_linux
diff -r c737f64a9e17 -r 42253ff10ca6 sys/compat/linux/arch/amd64/linux_commons.c
--- a/sys/compat/linux/arch/amd64/linux_commons.c       Sat May 02 22:19:47 2020 +0000
+++ b/sys/compat/linux/arch/amd64/linux_commons.c       Sun May 03 01:06:55 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux_commons.c,v 1.11 2011/05/30 17:50:31 alnsn Exp $ */
+/*     $NetBSD: linux_commons.c,v 1.12 2020/05/03 01:06:55 thorpej Exp $ */
 
 /*
  * This file includes C files from the common
@@ -13,7 +13,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: linux_commons.c,v 1.11 2011/05/30 17:50:31 alnsn Exp $");
+__KERNEL_RCSID(1, "$NetBSD: linux_commons.c,v 1.12 2020/05/03 01:06:55 thorpej Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_sysv.h"
@@ -35,5 +35,4 @@
 #include "../../common/linux_file64.c"
 #include "../../common/linux_misc_notalpha.c"
 #include "../../common/linux_sig_notalpha.c"
-#include "../../common/linux_futex.c"
 #include "../../common/linux_fadvise64.c"
diff -r c737f64a9e17 -r 42253ff10ca6 sys/compat/linux/arch/arm/linux_commons.c
--- a/sys/compat/linux/arch/arm/linux_commons.c Sat May 02 22:19:47 2020 +0000
+++ b/sys/compat/linux/arch/arm/linux_commons.c Sun May 03 01:06:55 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux_commons.c,v 1.12 2011/05/31 22:35:22 njoly Exp $ */
+/*     $NetBSD: linux_commons.c,v 1.13 2020/05/03 01:06:55 thorpej Exp $       */
 
 /*
  * This file includes C files from the common
@@ -13,7 +13,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: linux_commons.c,v 1.12 2011/05/31 22:35:22 njoly Exp $");
+__KERNEL_RCSID(1, "$NetBSD: linux_commons.c,v 1.13 2020/05/03 01:06:55 thorpej Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_sysv.h"
@@ -38,5 +38,4 @@
 #include "../../common/linux_olduname.c"
 #include "../../common/linux_oldolduname.c"
 #include "../../common/linux_uid16.c"
-#include "../../common/linux_futex.c"
 #include "../../common/linux_fadvise64_64.c"
diff -r c737f64a9e17 -r 42253ff10ca6 sys/compat/linux/arch/i386/linux_commons.c
--- a/sys/compat/linux/arch/i386/linux_commons.c        Sat May 02 22:19:47 2020 +0000
+++ b/sys/compat/linux/arch/i386/linux_commons.c        Sun May 03 01:06:55 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux_commons.c,v 1.16 2011/05/31 22:35:22 njoly Exp $ */
+/*     $NetBSD: linux_commons.c,v 1.17 2020/05/03 01:06:56 thorpej Exp $       */
 
 /*
  * This file includes C files from the common
@@ -13,7 +13,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: linux_commons.c,v 1.16 2011/05/31 22:35:22 njoly Exp $");
+__KERNEL_RCSID(1, "$NetBSD: linux_commons.c,v 1.17 2020/05/03 01:06:56 thorpej Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_sysv.h"
@@ -25,7 +25,6 @@
 #include <sys/syscallargs.h>
 
 #include "../../common/linux_pipe.c"
-#include "../../common/linux_futex.c"
 #include "../../common/linux_file64.c"
 #include "../../common/linux_fcntl64.c"
 #include "../../common/linux_ipccall.c"
diff -r c737f64a9e17 -r 42253ff10ca6 sys/compat/linux/arch/m68k/files.linux_m68k
--- a/sys/compat/linux/arch/m68k/files.linux_m68k       Sat May 02 22:19:47 2020 +0000
+++ b/sys/compat/linux/arch/m68k/files.linux_m68k       Sun May 03 01:06:55 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.linux_m68k,v 1.7 2013/12/24 13:41:25 njoly Exp $
+#      $NetBSD: files.linux_m68k,v 1.8 2020/05/03 01:06:56 thorpej Exp $
 #
 # Config file description for m68k-dependent Linux compat code.
 
@@ -18,7 +18,6 @@
 file   compat/linux/common/linux_oldmmap.c             compat_linux
 file   compat/linux/common/linux_oldselect.c           compat_linux
 file   compat/linux/common/linux_uid16.c               compat_linux
-file   compat/linux/common/linux_futex.c               compat_linux
 file   compat/linux/common/linux_fadvise64.c           compat_linux
 file   compat/linux/common/linux_fadvise64_64.c        compat_linux
 file   compat/linux/common/linux_fcntl64.c             compat_linux
diff -r c737f64a9e17 -r 42253ff10ca6 sys/compat/linux/arch/mips/files.linux_mips
--- a/sys/compat/linux/arch/mips/files.linux_mips       Sat May 02 22:19:47 2020 +0000
+++ b/sys/compat/linux/arch/mips/files.linux_mips       Sun May 03 01:06:55 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.linux_mips,v 1.7 2011/05/30 17:50:32 alnsn Exp $
+#      $NetBSD: files.linux_mips,v 1.8 2020/05/03 01:06:56 thorpej Exp $
 #
 # Config file description for mips-dependent Linux compat code.
 
@@ -17,5 +17,4 @@
 file   compat/linux/common/linux_olduname.c            compat_linux
 file   compat/linux/common/linux_file64.c              compat_linux
 file   compat/linux/common/linux_fcntl64.c             compat_linux
-file   compat/linux/common/linux_futex.c               compat_linux
 file   compat/linux/common/linux_fadvise64.c           compat_linux
diff -r c737f64a9e17 -r 42253ff10ca6 sys/compat/linux/arch/powerpc/files.linux_powerpc
--- a/sys/compat/linux/arch/powerpc/files.linux_powerpc Sat May 02 22:19:47 2020 +0000
+++ b/sys/compat/linux/arch/powerpc/files.linux_powerpc Sun May 03 01:06:55 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.linux_powerpc,v 1.11 2011/05/30 17:50:32 alnsn Exp $
+#      $NetBSD: files.linux_powerpc,v 1.12 2020/05/03 01:06:56 thorpej Exp $
 #
 # Config file description for powerpc-dependent Linux compat code.
 
@@ -18,6 +18,5 @@
 file   compat/linux/common/linux_olduname.c            compat_linux
 file   compat/linux/common/linux_file64.c              compat_linux
 file   compat/linux/common/linux_fcntl64.c             compat_linux
-file   compat/linux/common/linux_futex.c               compat_linux
 file   compat/linux/common/linux_fadvise64.c           compat_linux
 file   compat/linux/common/linux_fadvise64_64.c        compat_linux
diff -r c737f64a9e17 -r 42253ff10ca6 sys/compat/linux/common/linux_exec.c
--- a/sys/compat/linux/common/linux_exec.c      Sat May 02 22:19:47 2020 +0000
+++ b/sys/compat/linux/common/linux_exec.c      Sun May 03 01:06:55 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux_exec.c,v 1.123 2020/04/26 18:53:33 thorpej Exp $ */
+/*     $NetBSD: linux_exec.c,v 1.124 2020/05/03 01:06:56 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1994, 1995, 1998, 2000, 2007, 2008, 2020
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_exec.c,v 1.123 2020/04/26 18:53:33 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_exec.c,v 1.124 2020/05/03 01:06:56 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -61,6 +61,7 @@
 #include <compat/linux/common/linux_util.h>
 #include <compat/linux/common/linux_sched.h>
 #include <compat/linux/common/linux_machdep.h>
+#include <compat/linux/common/linux_misc.h>
 #include <compat/linux/common/linux_exec.h>
 #include <compat/linux/common/linux_ipc.h>
 #include <compat/linux/common/linux_sem.h>
@@ -181,7 +182,7 @@
                        printf("%s: cannot clear TID\n", __func__);
 #endif
 
-               error = do_futex((int *)led->led_clear_tid, FUTEX_WAKE,
+               error = linux_do_futex((int *)led->led_clear_tid, FUTEX_WAKE,
                    INT_MAX, NULL, NULL, 0, 0, &retval);
                if (error)
                        printf("%s: linux_sys_futex failed\n", __func__);
diff -r c737f64a9e17 -r 42253ff10ca6 sys/compat/linux/common/linux_futex.c
--- a/sys/compat/linux/common/linux_futex.c     Sat May 02 22:19:47 2020 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,87 +0,0 @@
-/*     $NetBSD: linux_futex.c,v 1.40 2020/04/29 01:44:03 thorpej Exp $ */
-
-/*-
- * Copyright (c) 2019 The NetBSD Foundation.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Taylor R. Campbell and Jason R. Thorpe.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: linux_futex.c,v 1.40 2020/04/29 01:44:03 thorpej Exp $");
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/proc.h>
-#include <sys/lwp.h>
-#include <sys/futex.h>
-
-#include <compat/linux/common/linux_types.h>
-#include <compat/linux/common/linux_emuldata.h>
-#include <compat/linux/common/linux_exec.h>
-#include <compat/linux/common/linux_signal.h>
-#include <compat/linux/common/linux_sched.h>
-#include <compat/linux/common/linux_machdep.h>
-#include <compat/linux/linux_syscallargs.h>
-
-int
-linux_sys_futex(struct lwp *l, const struct linux_sys_futex_args *uap,
-       register_t *retval)
-{
-       /* {
-               syscallarg(int *) uaddr;
-               syscallarg(int) op;
-               syscallarg(int) val;
-               syscallarg(const struct linux_timespec *) timeout;
-               syscallarg(int *) uaddr2;
-               syscallarg(int) val3;
-       } */
-       struct linux_timespec lts;
-       struct timespec ts, *tsp = NULL;
-       int val2 = 0;
-       int error;
-
-       /*
-        * Linux overlays the "timeout" field and the "val2" field.
-        * "timeout" is only valid for FUTEX_WAIT and FUTEX_WAIT_BITSET
-        * on Linux.
-        */
-       const int op = (SCARG(uap, op) & FUTEX_CMD_MASK);
-       if ((op == FUTEX_WAIT || op == FUTEX_WAIT_BITSET) &&
-           SCARG(uap, timeout) != NULL) {
-               if ((error = copyin(SCARG(uap, timeout), 
-                   &lts, sizeof(lts))) != 0) {
-                       return error;
-               }
-               linux_to_native_timespec(&ts, &lts);
-               tsp = &ts;
-       } else {
-               val2 = (int)(uintptr_t)SCARG(uap, timeout);
-       }
-
-       return do_futex(SCARG(uap, uaddr), SCARG(uap, op), SCARG(uap, val),
-           tsp, SCARG(uap, uaddr2), val2, SCARG(uap, val3), retval);
-}
diff -r c737f64a9e17 -r 42253ff10ca6 sys/compat/linux/common/linux_misc.c
--- a/sys/compat/linux/common/linux_misc.c      Sat May 02 22:19:47 2020 +0000
+++ b/sys/compat/linux/common/linux_misc.c      Sun May 03 01:06:55 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux_misc.c,v 1.248 2020/04/19 20:31:59 thorpej Exp $ */
+/*     $NetBSD: linux_misc.c,v 1.249 2020/05/03 01:06:56 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1995, 1998, 1999, 2008 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.248 2020/04/19 20:31:59 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.249 2020/05/03 01:06:56 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -93,6 +93,7 @@
 #include <sys/swap.h>          /* for SWAP_ON */
 #include <sys/sysctl.h>                /* for KERN_DOMAINNAME */
 #include <sys/kauth.h>
+#include <sys/futex.h>
 
 #include <sys/ptrace.h>
 #include <machine/ptrace.h>
@@ -1517,3 +1518,59 @@
        return linux_do_sys_utimensat(l, SCARG(uap, fd), SCARG(uap, path),
            tsp, SCARG(uap, flag), retval);
 }
+
+int
+linux_sys_futex(struct lwp *l, const struct linux_sys_futex_args *uap,
+       register_t *retval)
+{
+       /* {



Home | Main Index | Thread Index | Old Index