From 0210029b617674d420e55dba5931baf0ea7b0e93 Mon Sep 17 00:00:00 2001 From: Martin Pieuchot Date: Tue, 20 Mar 2018 15:45:33 +0000 Subject: Do not panic from ddb(4) when a lock requirement isn't fulfilled. Extend the logic already present for panic() to any DDB-related operation such that if ddb(4) is entered because of a fault or other trap it is still possible to call 'boot reboot'. While here stop printing splassert() messages as well, to not fill the buffer. ok visa@, deraadt@ --- sys/arch/alpha/alpha/db_interface.c | 4 +--- sys/arch/amd64/amd64/db_interface.c | 3 +-- sys/arch/arm/arm/db_interface.c | 4 +--- sys/arch/arm64/arm64/db_interface.c | 4 +--- sys/arch/hppa/hppa/db_interface.c | 3 +-- sys/arch/i386/i386/db_interface.c | 3 +-- sys/arch/mips64/mips64/db_machdep.c | 3 +-- sys/arch/powerpc/ddb/db_interface.c | 5 +---- sys/arch/sh/sh/db_interface.c | 4 +--- sys/arch/sparc64/sparc64/db_interface.c | 4 +--- sys/kern/init_main.c | 3 ++- sys/kern/kern_lock.c | 4 ++-- sys/kern/kern_rwlock.c | 10 +++++----- sys/kern/subr_prf.c | 4 +++- sys/sys/systm.h | 3 ++- 15 files changed, 24 insertions(+), 37 deletions(-) diff --git a/sys/arch/alpha/alpha/db_interface.c b/sys/arch/alpha/alpha/db_interface.c index 9249bf3a9a3..a91a63bbabd 100644 --- a/sys/arch/alpha/alpha/db_interface.c +++ b/sys/arch/alpha/alpha/db_interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_interface.c,v 1.23 2017/04/30 16:45:45 mpi Exp $ */ +/* $OpenBSD: db_interface.c,v 1.24 2018/03/20 15:45:32 mpi Exp $ */ /* $NetBSD: db_interface.c,v 1.8 1999/10/12 17:08:57 jdolecek Exp $ */ /* @@ -92,8 +92,6 @@ struct db_command db_machine_command_table[] = { { NULL, NULL, 0, NULL } }; -int db_active = 0; - struct db_variable db_regs[] = { { "v0", &ddb_regs.tf_regs[FRAME_V0], FCN_NULL }, { "t0", &ddb_regs.tf_regs[FRAME_T0], FCN_NULL }, diff --git a/sys/arch/amd64/amd64/db_interface.c b/sys/arch/amd64/amd64/db_interface.c index a8931294d51..70e7ac718dd 100644 --- a/sys/arch/amd64/amd64/db_interface.c +++ b/sys/arch/amd64/amd64/db_interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_interface.c,v 1.29 2017/07/19 14:34:10 kettenis Exp $ */ +/* $OpenBSD: db_interface.c,v 1.30 2018/03/20 15:45:32 mpi Exp $ */ /* $NetBSD: db_interface.c,v 1.1 2003/04/26 18:39:27 fvdl Exp $ */ /* @@ -78,7 +78,6 @@ boolean_t db_switch_cpu; long db_switch_to_cpu; #endif -int db_active; db_regs_t ddb_regs; void db_printtrap(int, int); diff --git a/sys/arch/arm/arm/db_interface.c b/sys/arch/arm/arm/db_interface.c index 322eb123bf6..8534dda55c4 100644 --- a/sys/arch/arm/arm/db_interface.c +++ b/sys/arch/arm/arm/db_interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_interface.c,v 1.12 2017/04/30 16:45:45 mpi Exp $ */ +/* $OpenBSD: db_interface.c,v 1.13 2018/03/20 15:45:32 mpi Exp $ */ /* $NetBSD: db_interface.c,v 1.34 2003/10/26 23:11:15 chris Exp $ */ /* @@ -92,8 +92,6 @@ extern label_t *db_recover; struct db_variable * db_eregs = db_regs + nitems(db_regs); -int db_active = 0; - int db_access_und_sp(struct db_variable *vp, db_expr_t *valp, int rw) { diff --git a/sys/arch/arm64/arm64/db_interface.c b/sys/arch/arm64/arm64/db_interface.c index 64675c08f8b..d615be12497 100644 --- a/sys/arch/arm64/arm64/db_interface.c +++ b/sys/arch/arm64/arm64/db_interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_interface.c,v 1.4 2018/01/30 15:46:12 kettenis Exp $ */ +/* $OpenBSD: db_interface.c,v 1.5 2018/03/20 15:45:32 mpi Exp $ */ /* $NetBSD: db_interface.c,v 1.34 2003/10/26 23:11:15 chris Exp $ */ /* @@ -122,8 +122,6 @@ extern label_t *db_recover; struct db_variable * db_eregs = db_regs + nitems(db_regs); -int db_active = 0; - #ifdef DDB /* * kdb_trap - field a TRACE or BPT trap diff --git a/sys/arch/hppa/hppa/db_interface.c b/sys/arch/hppa/hppa/db_interface.c index 89c03345f90..33c3bf093fc 100644 --- a/sys/arch/hppa/hppa/db_interface.c +++ b/sys/arch/hppa/hppa/db_interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_interface.c,v 1.42 2017/11/03 11:29:46 jasper Exp $ */ +/* $OpenBSD: db_interface.c,v 1.43 2018/03/20 15:45:32 mpi Exp $ */ /* * Copyright (c) 1999-2003 Michael Shalayeff @@ -122,7 +122,6 @@ struct db_variable db_regs[] = { { "cr30", (long *)&ddb_regs.tf_cr30, FCN_NULL }, }; struct db_variable *db_eregs = db_regs + nitems(db_regs); -int db_active = 0; void db_enter(void) diff --git a/sys/arch/i386/i386/db_interface.c b/sys/arch/i386/i386/db_interface.c index 8de52b0fc68..5791d6a69e6 100644 --- a/sys/arch/i386/i386/db_interface.c +++ b/sys/arch/i386/i386/db_interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_interface.c,v 1.37 2018/03/13 13:51:05 bluhm Exp $ */ +/* $OpenBSD: db_interface.c,v 1.38 2018/03/20 15:45:32 mpi Exp $ */ /* $NetBSD: db_interface.c,v 1.22 1996/05/03 19:42:00 christos Exp $ */ /* @@ -72,7 +72,6 @@ long db_switch_to_cpu; #endif db_regs_t ddb_regs; -int db_active = 0; void kdbprinttrap(int, int); void db_sysregs_cmd(db_expr_t, int, db_expr_t, char *); diff --git a/sys/arch/mips64/mips64/db_machdep.c b/sys/arch/mips64/mips64/db_machdep.c index 1c620160023..91f479b99b7 100644 --- a/sys/arch/mips64/mips64/db_machdep.c +++ b/sys/arch/mips64/mips64/db_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_machdep.c,v 1.48 2017/08/26 15:21:48 visa Exp $ */ +/* $OpenBSD: db_machdep.c,v 1.49 2018/03/20 15:45:32 mpi Exp $ */ /* * Copyright (c) 1998-2003 Opsycon AB (www.opsycon.se) @@ -76,7 +76,6 @@ boolean_t db_switch_cpu; long db_switch_to_cpu; #endif -int db_active = 0; db_regs_t ddb_regs; #ifdef MULTIPROCESSOR diff --git a/sys/arch/powerpc/ddb/db_interface.c b/sys/arch/powerpc/ddb/db_interface.c index e00cf2a8b86..6440539219e 100644 --- a/sys/arch/powerpc/ddb/db_interface.c +++ b/sys/arch/powerpc/ddb/db_interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_interface.c,v 1.3 2017/04/30 16:45:45 mpi Exp $ */ +/* $OpenBSD: db_interface.c,v 1.4 2018/03/20 15:45:32 mpi Exp $ */ /* $NetBSD: db_interface.c,v 1.12 2001/07/22 11:29:46 wiz Exp $ */ /* @@ -50,7 +50,6 @@ boolean_t db_switch_cpu; long db_switch_to_cpu; #endif -int db_active; extern db_regs_t ddb_regs; #ifdef MULTIPROCESSOR @@ -60,8 +59,6 @@ void db_stopproc_cmd(db_expr_t, int, db_expr_t, char *); void db_ddbproc_cmd(db_expr_t, int, db_expr_t, char *); #endif -int db_active = 0; - int db_trap_glue(struct trapframe *frame); /* called from locore */ void diff --git a/sys/arch/sh/sh/db_interface.c b/sys/arch/sh/sh/db_interface.c index ca60506f1a8..423259dd046 100644 --- a/sys/arch/sh/sh/db_interface.c +++ b/sys/arch/sh/sh/db_interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_interface.c,v 1.10 2017/04/30 16:45:45 mpi Exp $ */ +/* $OpenBSD: db_interface.c,v 1.11 2018/03/20 15:45:32 mpi Exp $ */ /* $NetBSD: db_interface.c,v 1.37 2006/09/06 00:11:49 uwe Exp $ */ /*- @@ -83,8 +83,6 @@ struct db_command db_machine_command_table[] = { { NULL } }; -int db_active; - void db_machine_init(void) { diff --git a/sys/arch/sparc64/sparc64/db_interface.c b/sys/arch/sparc64/sparc64/db_interface.c index c62b7c330ea..9c8a91149a4 100644 --- a/sys/arch/sparc64/sparc64/db_interface.c +++ b/sys/arch/sparc64/sparc64/db_interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_interface.c,v 1.49 2017/12/03 10:55:50 mpi Exp $ */ +/* $OpenBSD: db_interface.c,v 1.50 2018/03/20 15:45:32 mpi Exp $ */ /* $NetBSD: db_interface.c,v 1.61 2001/07/31 06:55:47 eeh Exp $ */ /* @@ -197,8 +197,6 @@ struct db_variable *db_eregs = db_regs + nitems(db_regs); extern label_t *db_recover; -int db_active = 0; - extern char *trap_type[]; void kdb_kbd_trap(struct trapframe64 *); diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index 29cd5b2f661..17bff8830fb 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init_main.c,v 1.274 2018/02/28 18:47:33 patrick Exp $ */ +/* $OpenBSD: init_main.c,v 1.275 2018/03/20 15:45:32 mpi Exp $ */ /* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */ /* @@ -124,6 +124,7 @@ extern struct user *proc0paddr; struct vnode *rootvp, *swapdev_vp; int boothowto; struct timespec boottime; +int db_active = 0; int ncpus = 1; int ncpusfound = 1; /* number of cpus we find */ volatile int start_init_exec; /* semaphore for start_init() */ diff --git a/sys/kern/kern_lock.c b/sys/kern/kern_lock.c index 2d79db04ed7..f108c7393e9 100644 --- a/sys/kern/kern_lock.c +++ b/sys/kern/kern_lock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_lock.c,v 1.59 2018/02/19 09:18:00 mpi Exp $ */ +/* $OpenBSD: kern_lock.c,v 1.60 2018/03/20 15:45:32 mpi Exp $ */ /* * Copyright (c) 2017 Visa Hankala @@ -79,7 +79,7 @@ _kernel_unlock(void) int _kernel_lock_held(void) { - if (panicstr) + if (panicstr || db_active) return 1; return (__mp_lock_held(&kernel_lock, curcpu())); } diff --git a/sys/kern/kern_rwlock.c b/sys/kern/kern_rwlock.c index 88228a224a1..1bde7064757 100644 --- a/sys/kern/kern_rwlock.c +++ b/sys/kern/kern_rwlock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_rwlock.c,v 1.33 2017/12/18 10:05:43 mpi Exp $ */ +/* $OpenBSD: kern_rwlock.c,v 1.34 2018/03/20 15:45:32 mpi Exp $ */ /* * Copyright (c) 2002, 2003 Artur Grabowski @@ -236,8 +236,8 @@ retry: unsigned long set = o | op->wait_set; int do_sleep; - /* Avoid deadlocks after panic */ - if (panicstr) + /* Avoid deadlocks after panic or in DDB */ + if (panicstr || db_active) return (0); rw_enter_diag(rwl, flags); @@ -287,8 +287,8 @@ _rw_exit(struct rwlock *rwl LOCK_FL_VARS) int wrlock = owner & RWLOCK_WRLOCK; unsigned long set; - /* Avoid deadlocks after panic */ - if (panicstr) + /* Avoid deadlocks after panic or in DDB */ + if (panicstr || db_active) return; if (wrlock) diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c index 3572e809d09..c75e2a88769 100644 --- a/sys/kern/subr_prf.c +++ b/sys/kern/subr_prf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_prf.c,v 1.93 2018/01/05 11:10:25 pirofti Exp $ */ +/* $OpenBSD: subr_prf.c,v 1.94 2018/03/20 15:45:32 mpi Exp $ */ /* $NetBSD: subr_prf.c,v 1.45 1997/10/24 18:14:25 chuck Exp $ */ /*- @@ -216,6 +216,8 @@ panic(const char *fmt, ...) void splassert_fail(int wantipl, int haveipl, const char *func) { + if (panicstr || db_active) + return; printf("splassert: %s: want %d have %d\n", func, wantipl, haveipl); switch (splassert_ctl) { diff --git a/sys/sys/systm.h b/sys/sys/systm.h index 93ddae25307..7c14c9bd5f3 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -1,4 +1,4 @@ -/* $OpenBSD: systm.h,v 1.138 2018/02/08 09:27:44 mortimer Exp $ */ +/* $OpenBSD: systm.h,v 1.139 2018/03/20 15:45:32 mpi Exp $ */ /* $NetBSD: systm.h,v 1.50 1996/06/09 04:55:09 briggs Exp $ */ /*- @@ -79,6 +79,7 @@ extern const char ostype[]; extern const char osversion[]; extern const char osrelease[]; extern int cold; /* cold start flag initialized in locore */ +extern int db_active; /* running currently inside ddb(4) */ extern int ncpus; /* number of CPUs used */ extern int ncpusfound; /* number of CPUs found */ -- cgit v1.2.3