NetBSD-Bugs archive

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

Re: kern/56592 - sys: dev: sysmon: possible ABBA deadlock in sme_events_worker() and sme_events_check()



The following reply was made to PR kern/56592; it has been noted by GNATS.

From: Paul Goyette <paul%whooppee.com@localhost>
To: gnats%netbsd.org@localhost
Cc: baijiaju1990%gmail.com@localhost
Subject: Re: kern/56592 - sys: dev: sysmon: possible ABBA deadlock in
 sme_events_worker() and sme_events_check()
Date: Thu, 30 Dec 2021 19:37:30 -0800 (PST)

 Yeah, that looks like a possible deadlock.  The following patch to
 sme_events_check() should re-order the mutex_enter() calls to avoid
 this.  (Note, I have not actually confirmed that the deadlock will
 ever occur, and the patch has only been compile-tested!)
 
 
 Index: sysmon_envsys_events.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/sysmon/sysmon_envsys_events.c,v
 retrieving revision 1.121
 diff -u -p -r1.121 sysmon_envsys_events.c
 --- sysmon_envsys_events.c	11 Sep 2017 06:02:09 -0000	1.121
 +++ sysmon_envsys_events.c	31 Dec 2021 03:32:31 -0000
 @@ -736,14 +736,15 @@ sme_events_check(void *arg)
 
   	KASSERT(sme != NULL);
 
 +	mutex_enter(&sme->sme_mtx);
   	mutex_enter(&sme->sme_work_mtx);
   	if (sme->sme_busy > 0) {
   		log(LOG_WARNING, "%s: workqueue busy: updates stopped\n",
   		    sme->sme_name);
   		mutex_exit(&sme->sme_work_mtx);
 +		mutex_exit(&sme->sme_mtx);
   		return;
   	}
 -	mutex_enter(&sme->sme_mtx);
   	LIST_FOREACH(see, &sme->sme_events_list, see_list) {
   		workqueue_enqueue(sme->sme_wq, &see->see_wk, NULL);
   		see->see_edata->flags |= ENVSYS_FNEED_REFRESH;
 @@ -751,8 +752,8 @@ sme_events_check(void *arg)
   	}
   	if (!sysmon_low_power)
   		sme_schedule_callout(sme);
 -	mutex_exit(&sme->sme_mtx);
   	mutex_exit(&sme->sme_work_mtx);
 +	mutex_exit(&sme->sme_mtx);
   }
 
   /*
 
 
 
 +--------------------+--------------------------+----------------------+
 | Paul Goyette       | PGP Key fingerprint:     | E-mail addresses:    |
 | (Retired)          | FA29 0E3B 35AF E8AE 6651 | paul%whooppee.com@localhost    |
 | Software Developer | 0786 F758 55DE 53BA 7731 | pgoyette%netbsd.org@localhost  |
 | & Network Engineer |                          | pgoyette99%gmail.com@localhost |
 +--------------------+--------------------------+----------------------+
 


Home | Main Index | Thread Index | Old Index