Date: Fri, 25 Jan 2008 20:00:15 GMT From: John Baldwin <jhb@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 134101 for review Message-ID: <200801252000.m0PK0F1c062328@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=134101 Change 134101 by jhb@jhb_mutex on 2008/01/25 19:59:58 - Add an assert to enforce MTX_RECURSE checking for spin mutexes (previously this was only done with WITNESS, but hardly anyone enables WITNESS on spin locks) - Add test cases for MTX_RECURSE testing for spin locks and a test case for the sleepq chain lock recursing. Affected files ... .. //depot/projects/smpng/sys/kern/kern_mutex.c#150 edit .. //depot/projects/smpng/sys/modules/crash/crash.c#49 edit Differences ... ==== //depot/projects/smpng/sys/kern/kern_mutex.c#150 (text+ko) ==== @@ -216,6 +216,10 @@ KASSERT(LOCK_CLASS(&m->lock_object) == &lock_class_mtx_spin, ("mtx_lock_spin() of sleep mutex %s @ %s:%d", m->lock_object.lo_name, file, line)); + if (mtx_owned(m)) + KASSERT((m->lock_object.lo_flags & LO_RECURSABLE) != 0, + ("mtx_lock_spin: recursed on non-recursive mutex %s @ %s:%d\n", + m->lock_object.lo_name, file, line)); WITNESS_CHECKORDER(&m->lock_object, opts | LOP_NEWORDER | LOP_EXCLUSIVE, file, line); _get_spin_lock(m, curthread, opts, file, line); ==== //depot/projects/smpng/sys/modules/crash/crash.c#49 (text+ko) ==== @@ -100,6 +100,18 @@ } static void +exercise_sc_recurse(void) +{ + struct callout c; + + callout_init(&c, CALLOUT_MPSAFE); + callout_reset(&c, hz, tsleep_race_fallback, NULL); + tsleep(&race_wchan, 0, "race", 5 * hz); + callout_drain(&c); +} +CRASH_EVENT("test recursing on sleepq chain lock", exercise_sc_recurse); + +static void exercise_tsleep_race(void) { struct callout c; @@ -160,6 +172,30 @@ CRASH_EVENT("exercise tsleep() race", exercise_tsleep_race); static void +spin_recurse(void) +{ + + bzero(&test1_mtx, sizeof(test1_mtx)); + mtx_init(&test1_mtx, "test1", NULL, MTX_SPIN | MTX_RECURSE); + mtx_lock_spin(&test1_mtx); + mtx_lock_spin(&test1_mtx); + kdb_enter(KDB_WHY_CRASH, "test1_mtx should be recursed"); + mtx_unlock_spin(&test1_mtx); + mtx_unlock_spin(&test1_mtx); + mtx_destroy(&test1_mtx); + + bzero(&test1_mtx, sizeof(test1_mtx)); + mtx_init(&test1_mtx, "test1", NULL, MTX_SPIN); + printf("recursing on non-recursive spin lock should go boom\n"); + mtx_lock_spin(&test1_mtx); + mtx_lock_spin(&test1_mtx); + mtx_unlock_spin(&test1_mtx); + mtx_unlock_spin(&test1_mtx); + mtx_destroy(&test1_mtx); +} +CRASH_EVENT("test spin lock recurse", spin_recurse); + +static void sx_recurse(void) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200801252000.m0PK0F1c062328>