Source-Changes-HG archive

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

[src/netbsd-8]: src Pull up following revision(s) (requested by ozaki-r in ti...



details:   https://anonhg.NetBSD.org/src/rev/36a4a32bda72
branches:  netbsd-8
changeset: 434816:36a4a32bda72
user:      martin <martin%NetBSD.org@localhost>
date:      Mon Apr 02 09:07:52 2018 +0000

description:
Pull up following revision(s) (requested by ozaki-r in ticket #687):
        sys/kern/kern_rwlock_obj.c: revision 1.4
        sys/rump/librump/rumpkern/locks.c: revision 1.80
        sys/kern/kern_rwlock.c: revision 1.50
        sys/arch/x86/x86/db_memrw.c: revision 1.5,1.6
        sys/ddb/db_command.c: revision 1.150-1.153
        share/man/man4/ddb.4: revision 1.175 (via patch),1.176-1.178
        sys/kern/kern_mutex_obj.c: revision 1.6
        sys/kern/subr_lockdebug.c: revision 1.61-1.64
        sys/sys/lockdebug.h: revision 1.17
        sys/kern/kern_mutex.c: revision 1.71
        sys/sys/lockdebug.h: revision 1.18,1.19
        sys/kern/subr_xcall.c: revision 1.26

Obtain proper initialized addresses of locks allocated by mutex_obj_alloc or rw_obj_alloc

Initialized addresses of locks allocated by mutex_obj_alloc or rw_obj_alloc
were not useful because the addresses were mutex_obj_alloc or rw_obj_alloc
itself. What we want to know are callers of them.

Spinkle ASSERT_SLEEPABLE to xcall functions

Use db_printf instead of printf in ddb

Add a new command, show lockstat, which shows statistics of locks
Currently the command shows the number of allocated locks.
The command is useful only if LOCKDEBUG is enabled.

Add a new command, show all locks, which shows information of active locks

The command shows information of all active (i.e., being held) locks that are
tracked through either of LWPs or CPUs by the LOCKDEBUG facility.  The /t
modifier additionally shows a backtrace for each LWP additionally.  This
feature is useful for debugging especially to analyze deadlocks.
The command is useful only if LOCKDEBUG is enabled.

Don't pass a unset address to lockdebug_lock_print

x86: avoid accessing invalid addresses in ddb like arm32
This avoids that a command stops in the middle of an execution if
a fault occurs due to an access to an invalid address.

Get rid of a redundant output

Improve wording. Fix a Cm argument.

ddb: rename "show lockstat" to "show lockstats" to avoid conflicting with lockstat(8)
Requested by mrg@

diffstat:

 share/man/man4/ddb.4              |   19 +++-
 sys/arch/x86/x86/db_memrw.c       |   36 ++++++++-
 sys/ddb/db_command.c              |   34 ++++++++-
 sys/kern/kern_mutex.c             |   22 +++-
 sys/kern/kern_mutex_obj.c         |    8 +-
 sys/kern/kern_rwlock.c            |   17 +++-
 sys/kern/kern_rwlock_obj.c        |    7 +-
 sys/kern/subr_lockdebug.c         |  144 +++++++++++++++++++++++++++++++++++++-
 sys/kern/subr_xcall.c             |    7 +-
 sys/rump/librump/rumpkern/locks.c |   36 ++++++--
 sys/sys/lockdebug.h               |    5 +-
 11 files changed, 291 insertions(+), 44 deletions(-)

diffs (truncated from 717 to 300 lines):

diff -r f88cb5590acc -r 36a4a32bda72 share/man/man4/ddb.4
--- a/share/man/man4/ddb.4      Mon Apr 02 08:54:35 2018 +0000
+++ b/share/man/man4/ddb.4      Mon Apr 02 09:07:52 2018 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: ddb.4,v 1.166 2017/01/12 13:14:41 wiz Exp $
+.\"    $NetBSD: ddb.4,v 1.166.6.1 2018/04/02 09:07:52 martin Exp $
 .\"
 .\" Copyright (c) 1997 - 2009 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -56,7 +56,7 @@
 .\" any improvements or extensions that they make and grant Carnegie Mellon
 .\" the rights to redistribute these changes.
 .\"
-.Dd January 12, 2017
+.Dd March 19, 2018
 .Dt DDB 4
 .Os
 .Sh NAME
@@ -258,7 +258,7 @@
 .Pp
 The syntax:
 .Bd -ragged -offset indent
-.Cm , Ns Ar count
+.Cm \&, Ns Ar count
 .Ed
 .Pp
 repeats the previous command, just as a blank line does, but with
@@ -564,6 +564,13 @@
 See
 .Xr callout 9
 for more information on callouts.
+.It Ic show all locks Ns Op Cm /t
+Display details information about all active locks.
+If
+.Cm /t
+is specified, stack traces of LWPs holding locks are also printed.
+This command is only useful if a kernel is compiled with
+.Cd options LOCKDEBUG .
 .It Ic show all pages
 Display basic information about all physical pages managed by the VM system.
 For more detailed information about a single page, use
@@ -656,7 +663,11 @@
 .It Ic show lock Ar address
 Display information about a lock at
 .Ar address .
-This command is useful only if a kernel is compiled with
+This command is only useful if a kernel is compiled with
+.Cd options LOCKDEBUG .
+.It Ic show lockstats
+Display information about lock statistics.
+This command is only useful if a kernel is compiled with
 .Cd options LOCKDEBUG .
 .It Ic show map Ns Oo Cm /f Oc Ar address
 Print the vm_map at
diff -r f88cb5590acc -r 36a4a32bda72 sys/arch/x86/x86/db_memrw.c
--- a/sys/arch/x86/x86/db_memrw.c       Mon Apr 02 08:54:35 2018 +0000
+++ b/sys/arch/x86/x86/db_memrw.c       Mon Apr 02 09:07:52 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: db_memrw.c,v 1.2 2016/05/12 06:45:16 maxv Exp $        */
+/*     $NetBSD: db_memrw.c,v 1.2.10.1 2018/04/02 09:07:52 martin Exp $ */
 
 /*-
  * Copyright (c) 1996, 2000 The NetBSD Foundation, Inc.
@@ -53,7 +53,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_memrw.c,v 1.2 2016/05/12 06:45:16 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_memrw.c,v 1.2.10.1 2018/04/02 09:07:52 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -62,6 +62,23 @@
 #include <machine/db_machdep.h>
 
 #include <ddb/db_access.h>
+#include <ddb/db_output.h>
+
+static int
+db_validate_address(vaddr_t addr)
+{
+       struct proc *p = curproc;
+       struct pmap *pmap;
+
+       if (!p || !p->p_vmspace || !p->p_vmspace->vm_map.pmap ||
+           addr >= VM_MIN_KERNEL_ADDRESS
+          )
+               pmap = pmap_kernel();
+       else
+               pmap = p->p_vmspace->vm_map.pmap;
+
+       return (pmap_extract(pmap, addr, NULL) == false);
+}
 
 /*
  * Read bytes from kernel address space for debugger.
@@ -73,6 +90,11 @@
 
        src = (char *)addr;
 
+       if (db_validate_address((vaddr_t)src)) {
+               db_printf("address %p is invalid\n", src);
+               return;
+       }
+
        if (size == 8) {
                *((long *)data) = *((long *)src);
                return;
@@ -88,8 +110,14 @@
                return;
        }
 
-       while (size-- > 0)
+       while (size-- > 0) {
+               if (db_validate_address((vaddr_t)src)) {
+                       db_printf("address %p is invalid\n", src);
+                       return;
+               }
+
                *data++ = *src++;
+       }
 }
 
 /*
@@ -117,7 +145,7 @@
                pte = *ppte;
 
                if ((pte & PG_V) == 0) {
-                       printf(" address %p not a valid page\n", dst);
+                       db_printf(" address %p not a valid page\n", dst);
                        return;
                }
 
diff -r f88cb5590acc -r 36a4a32bda72 sys/ddb/db_command.c
--- a/sys/ddb/db_command.c      Mon Apr 02 08:54:35 2018 +0000
+++ b/sys/ddb/db_command.c      Mon Apr 02 09:07:52 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: db_command.c,v 1.148 2017/01/11 12:17:34 joerg Exp $   */
+/*     $NetBSD: db_command.c,v 1.148.8.1 2018/04/02 09:07:52 martin Exp $      */
 
 /*
  * Copyright (c) 1996, 1997, 1998, 1999, 2002, 2009 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.148 2017/01/11 12:17:34 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.148.8.1 2018/04/02 09:07:52 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_aio.h"
@@ -190,6 +190,8 @@
 static void    db_fncall(db_expr_t, bool, db_expr_t, const char *);
 static void     db_help_print_cmd(db_expr_t, bool, db_expr_t, const char *);
 static void    db_lock_print_cmd(db_expr_t, bool, db_expr_t, const char *);
+static void    db_show_all_locks(db_expr_t, bool, db_expr_t, const char *);
+static void    db_show_lockstats(db_expr_t, bool, db_expr_t, const char *);
 static void    db_mount_print_cmd(db_expr_t, bool, db_expr_t, const char *);
 static void    db_mbuf_print_cmd(db_expr_t, bool, db_expr_t, const char *);
 static void    db_map_print_cmd(db_expr_t, bool, db_expr_t, const char *);
@@ -225,6 +227,8 @@
            0 ,"List all processes.",NULL,NULL) },
        { DDB_ADD_CMD("pools",  db_show_all_pools,
            0 ,"Show all pools",NULL,NULL) },
+       { DDB_ADD_CMD("locks",  db_show_all_locks,
+           0 ,"Show all held locks", "[/t]", NULL) },
 #ifdef AIO
        /*added from all sub cmds*/
        { DDB_ADD_CMD("aio_jobs",       db_show_aio_jobs,       0,
@@ -247,6 +251,9 @@
            "Print the files open by process at address",
            "[/f] address", NULL) },
        { DDB_ADD_CMD("lock",   db_lock_print_cmd,      0,NULL,NULL,NULL) },
+       { DDB_ADD_CMD("lockstats",
+                               db_show_lockstats,      0,
+           "Print statistics of locks", NULL, NULL) },
        { DDB_ADD_CMD("map",    db_map_print_cmd,       0,
            "Print the vm_map at address.", "[/f] address",NULL) },
        { DDB_ADD_CMD("module", db_show_module_cmd,     0,
@@ -1221,7 +1228,28 @@
 {
 
 #ifdef _KERNEL /* XXX CRASH(8) */
-       lockdebug_lock_print((void *)(uintptr_t)addr, db_printf);
+       lockdebug_lock_print(have_addr ? (void *)(uintptr_t)addr : NULL,
+           db_printf);
+#endif
+}
+
+static void
+db_show_all_locks(db_expr_t addr, bool have_addr,
+    db_expr_t count, const char *modif)
+{
+
+#ifdef _KERNEL /* XXX CRASH(8) */
+       lockdebug_show_all_locks(db_printf, modif);
+#endif
+}
+
+static void
+db_show_lockstats(db_expr_t addr, bool have_addr,
+    db_expr_t count, const char *modif)
+{
+
+#ifdef _KERNEL /* XXX CRASH(8) */
+       lockdebug_show_lockstats(db_printf);
 #endif
 }
 
diff -r f88cb5590acc -r 36a4a32bda72 sys/kern/kern_mutex.c
--- a/sys/kern/kern_mutex.c     Mon Apr 02 08:54:35 2018 +0000
+++ b/sys/kern/kern_mutex.c     Mon Apr 02 09:07:52 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_mutex.c,v 1.65.2.1 2018/01/13 21:57:11 snj Exp $  */
+/*     $NetBSD: kern_mutex.c,v 1.65.2.2 2018/04/02 09:07:52 martin Exp $       */
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -40,7 +40,7 @@
 #define        __MUTEX_PRIVATE
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.65.2.1 2018/01/13 21:57:11 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.65.2.2 2018/04/02 09:07:52 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -326,8 +326,10 @@
  *     sleeps - see comments in mutex_vector_enter() about releasing
  *     mutexes unlocked.
  */
+void _mutex_init(kmutex_t *, kmutex_type_t, int, uintptr_t);
 void
-mutex_init(kmutex_t *mtx, kmutex_type_t type, int ipl)
+_mutex_init(kmutex_t *mtx, kmutex_type_t type, int ipl,
+    uintptr_t return_address)
 {
        bool dodebug;
 
@@ -353,18 +355,17 @@
 
        switch (type) {
        case MUTEX_NODEBUG:
-               dodebug = LOCKDEBUG_ALLOC(mtx, NULL,
-                   (uintptr_t)__builtin_return_address(0));
+               dodebug = LOCKDEBUG_ALLOC(mtx, NULL, return_address);
                MUTEX_INITIALIZE_SPIN(mtx, dodebug, ipl);
                break;
        case MUTEX_ADAPTIVE:
                dodebug = LOCKDEBUG_ALLOC(mtx, &mutex_adaptive_lockops,
-                   (uintptr_t)__builtin_return_address(0));
+                   return_address);
                MUTEX_INITIALIZE_ADAPTIVE(mtx, dodebug);
                break;
        case MUTEX_SPIN:
                dodebug = LOCKDEBUG_ALLOC(mtx, &mutex_spin_lockops,
-                   (uintptr_t)__builtin_return_address(0));
+                   return_address);
                MUTEX_INITIALIZE_SPIN(mtx, dodebug, ipl);
                break;
        default:
@@ -373,6 +374,13 @@
        }
 }
 
+void
+mutex_init(kmutex_t *mtx, kmutex_type_t type, int ipl)
+{
+
+       _mutex_init(mtx, type, ipl, (uintptr_t)__builtin_return_address(0));
+}
+
 /*
  * mutex_destroy:
  *
diff -r f88cb5590acc -r 36a4a32bda72 sys/kern/kern_mutex_obj.c
--- a/sys/kern/kern_mutex_obj.c Mon Apr 02 08:54:35 2018 +0000
+++ b/sys/kern/kern_mutex_obj.c Mon Apr 02 09:07:52 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_mutex_obj.c,v 1.5 2011/09/27 01:02:38 jym Exp $   */
+/*     $NetBSD: kern_mutex_obj.c,v 1.5.46.1 2018/04/02 09:07:52 martin Exp $   */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_mutex_obj.c,v 1.5 2011/09/27 01:02:38 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_mutex_obj.c,v 1.5.46.1 2018/04/02 09:07:52 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -87,9 +87,11 @@
 mutex_obj_alloc(kmutex_type_t type, int ipl)
 {
        struct kmutexobj *mo;
+       extern void _mutex_init(kmutex_t *, kmutex_type_t, int, uintptr_t);
 
        mo = pool_cache_get(mutex_obj_cache, PR_WAITOK);



Home | Main Index | Thread Index | Old Index