tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

rfc: fix double locking in the pool cache subroutines



Hello.

I'm using the NetBSD-current (yesterday snapshot) on OMAP/H4.
When I try to start one of the libMicro (0.4.0) test called close_tcp
I've got the locking panic (I've switched on the LOCKDEBUG option).

# tcc -p -e $PWD close_tcp
tcc: journal file is /root/micro/results/0010e/journal
07:50:48  Execute /ts/close_tcp/close_tcp-tc
Mutex error: lockdebug_wantlock: locking against myself

lock address : 0x0000000081ca9a00 type     :     sleep/adaptive
initialized  : 0x0000000080410264
shared holds :                  0 exclusive:                  1
shares wanted:                  0 exclusive:                  1
current cpu  :                  0 last held:                  0
current lwp  : 0x0000000081cad4c0 last held: 0x0000000081cad4c0
last locked  : 0x000000008040f660 unlocked : 0x000000008040f704
owner field  : 0x0000000081cad4c0 wait/spin:                0/0

Turnstile chain at 0x80550f20.
=> No active turnstile for this lock.

panic: LOCKDEBUG
Stopped in pid 0.5 (system) at  netbsd:cpu_Debugger+0x4:        bx      r14


Some investigations lead to following quick fix:

diff --git a/sys/kern/subr_pool.c b/sys/kern/subr_pool.c
index 32547e7..6ad1a09 100644
--- a/sys/kern/subr_pool.c
+++ b/sys/kern/subr_pool.c
@@ -2541,7 +2541,9 @@ pool_cache_put_slow(pool_cache_cpu_t *cc, int s,
void *object)
        /* If there are no empty groups in the cache then allocate one. */
        if (__predict_false((pcg = pc->pc_emptygroups) == NULL)) {
                if (__predict_true(!pool_cache_disable)) {
+                       mutex_exit(&pc->pc_lock);
                        pcg = pool_get(pc->pc_pcgpool, PR_NOWAIT);
+                       mutex_enter(&pc->pc_lock);
                }
                if (__predict_true(pcg != NULL)) {
                        pcg->pcg_avail = 0;



-- 
With Best Regards,
Andy Shevchenko


Home | Main Index | Thread Index | Old Index