# HG changeset patch # User Taylor R Campbell # Date 1588599693 0 # Mon May 04 13:41:33 2020 +0000 # Branch trunk # Node ID 1a3123a0eccca17da2e90a931aabe01a5601924a # Parent 4d90033727a1bbba57854aaf5ac2d4f675184468 Release the collision if we find one. Candidate fix for: panic: lock error: Mutex: mutex_vector_enter,542: locking against myself: lock 0xffff8f611abd37e0 cpu 8 lwp 0xffff8f60a3c6a040 cpu8: Begin traceback... vpanic() at netbsd:vpanic+0x178 snprintf() at netbsd:snprintf lockdebug_abort() at netbsd:lockdebug_abort+0xe6 mutex_vector_enter() at netbsd:mutex_vector_enter+0x3c1 ksem_close_fop() at netbsd:ksem_close_fop+0x17 closef() at netbsd:closef+0x69 fd_free() at netbsd:fd_free+0x101 exit1() at netbsd:exit1+0x118 sys_exit() at netbsd:sys_exit+0x3d syscall() at netbsd:syscall+0x299 diff -r 4d90033727a1 -r 1a3123a0eccc sys/kern/uipc_sem.c --- a/sys/kern/uipc_sem.c Mon May 04 00:18:34 2020 +0000 +++ b/sys/kern/uipc_sem.c Mon May 04 13:41:33 2020 +0000 @@ -110,6 +110,7 @@ static kauth_listener_t ksem_listener; static int ksem_sysinit(void); static int ksem_sysfini(bool); static int ksem_modcmd(modcmd_t, void *); +static void ksem_release(ksem_t *, int); static int ksem_close_fop(file_t *); static int ksem_stat_fop(file_t *, struct stat *); static int ksem_read_fop(file_t *, off_t *, struct uio *, @@ -365,6 +366,7 @@ ksem_lookup_pshared(intptr_t id) static void ksem_alloc_pshared_id(ksem_t *ksem) { + ksem_t *ksem0; uint32_t try; KASSERT(ksem->ks_pshared_proc != NULL); @@ -374,10 +376,11 @@ ksem_alloc_pshared_id(ksem_t *ksem) try = (cprng_fast32() & ~KSEM_MARKER_MASK) | KSEM_PSHARED_MARKER; - if (ksem_lookup_pshared_locked(try) == NULL) { + if ((ksem0 = ksem_lookup_pshared_locked(try)) == NULL) { /* Got it! */ break; } + ksem_release(ksem0, -1); } ksem->ks_pshared_id = try; u_long bucket = KSEM_PSHARED_HASH(ksem->ks_pshared_id);