Index: kern/kern_sysctl.c =================================================================== --- kern/kern_sysctl.c (revision 249327) +++ kern/kern_sysctl.c (working copy) @@ -1406,7 +1406,7 @@ static int sysctl_root(SYSCTL_HANDLER_ARGS) { struct sysctl_oid *oid; - int error, indx, lvl; + int error, indx, lvl, giantlocked; SYSCTL_ASSERT_XLOCKED(); @@ -1488,10 +1488,13 @@ sysctl_root(SYSCTL_HANDLER_ARGS) oid->oid_running++; SYSCTL_XUNLOCK(); - if (!(oid->oid_kind & CTLFLAG_MPSAFE)) + if (!(oid->oid_kind & CTLFLAG_MPSAFE)) { + giantlocked = 1; mtx_lock(&Giant); + } else + giantlocked = 0; error = oid->oid_handler(oid, arg1, arg2, req); - if (!(oid->oid_kind & CTLFLAG_MPSAFE)) + if (giantlocked) mtx_unlock(&Giant); KFAIL_POINT_ERROR(_debug_fail_point, sysctl_running, error);