PERFORCE change 134245 for review

John Baldwin jhb at freebsd.org
Thu Jan 31 04:16:29 PST 2008


On Wednesday 30 January 2008 03:52:04 pm John Birrell wrote:
> On Wed, Jan 30, 2008 at 09:13:03AM -0500, John Baldwin wrote:
> > On Sunday 27 January 2008 04:48:32 pm John Birrell wrote:
> > > http://perforce.freebsd.org/chv.cgi?CH=134245
> > > 
> > > Change 134245 by jb at jb_freebsd1 on 2008/01/27 21:47:41
> > > 
> > > 	The linker lock here is private to code in this file. It is
> > > 	never a problem with it being locked when any other combination
> > > 	of locks are already obtained or even if *no* other locks are
> > > 	obtained. Use SX_NOWITNESS to avoid bogus LOR reports.
> > 
> > If witness reports a LOR it is real, it may just not be obvious.
> 
> Here is some code that demonstrates the problem:
> 
> 
> static struct mtx test_mtx;
> MTX_SYSINIT(test, &test_mtx, "Test", MTX_DEF);
> 
> static int
> test_list(linker_file_t lf, void *arg)
> {
> 	printf("Linker file name: '%s'\n", lf->filename);
> 	return (0);
> }
> 
> static void
> test_thread_func(void *arg)
> {
> 	printf("\n\nI'm a big bad thread, but I'm going to wait a bit... stay 
tuned...\n");
> 
> 	pause("Waiting a bit...", 5000);
> 
> 	printf("The big bad thread is awake and he wants to list the linker 
files...\n");
> 
> 	linker_file_foreach(test_list, NULL);
> 
> 	printf("Lock my wide scope mutex because I have stuff to protect...\n");
> 
> 	mtx_lock(&test_mtx);
> 
> 	printf("I've done some stuff that my wide scope lock protected, but now I 
need to list some linker files...\n");
> 
> 	linker_file_foreach(test_list, NULL);

This acquires an sx lock (KLD_LOCK) while holding a mutex which isn't 
permitted as kris@ mentioned in his previous e-mail.  Just make test_mtx an 
sx lock and witness should be fine.  Either that or acquire your mutex in the 
function that linker_file_foreach() invokes rather than holding it while 
calling into the linker.

-- 
John Baldwin


More information about the p4-projects mailing list