LOR with sysctl lock

mdf at FreeBSD.org mdf at FreeBSD.org
Wed Nov 24 19:53:59 UTC 2010


The sysctl lock can cause "random" LOR warnings.  These usually show
on reboot/shutdown when sysctl_ctx_free() is called by a kernel
module, since the mod handler is called with the module lock.  The
reason for the LOR is that, at least theoretically, the sysctl lock is
the first lock in any hierarchy, because a SYSCTL_PROC handler can
take any locks it wants, and will be called with the sysctl lock held
shared.

The below patch will fix the problem generically and with no changes
to other code.  I slightly prefer this to an explicit
sysctl_ctx_free_sched(9), because many times code doesn't know if some
caller holds *any* lock at all; this is especially true for mod
handlers who shouldn't be expected to know how FreeBSD locks calls to
the handler.

I also note that the return value from sysctl_ctx_free(9) is almost
never checked on CURRENT, and the only places it is, the value is
merely used to print a warning.  The only exception is canbus_detach()
in pc98/pc98/canbus.c.  So I wonder if sysctl_ctx_free(9) should
return void and print a warning itself.

Patch:
http://people.freebsd.org/~mdf/0001-Proposed-patch-to-fix-LORs-with-sysctl-lock.patch

If there are no objections, I'd like to commit this next week.

Thanks,
matthew


More information about the freebsd-arch mailing list