Date: Thu, 31 Jan 2008 06:31:54 -0500 From: John Baldwin <jhb@freebsd.org> To: John Birrell <jb@what-creek.com> Cc: Perforce Change Reviews <perforce@freebsd.org> Subject: Re: PERFORCE change 134245 for review Message-ID: <200801310631.54935.jhb@freebsd.org> In-Reply-To: <20080130205204.GA68541@what-creek.com> References: <200801272148.m0RLmWdF053919@repoman.freebsd.org> <200801300913.03782.jhb@freebsd.org> <20080130205204.GA68541@what-creek.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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@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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200801310631.54935.jhb>