tech-kern archive

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

racy acccess in kern_runq.c



Hi,

There are some racy accesses in kern_runq.c detected by KCSAN.  Those
racy access messages is so frequency that they cover other messages,
so I want to fix them.  They can be fixed by the following patch.

====================
diff --git a/sys/kern/kern_runq.c b/sys/kern/kern_runq.c
index 04ff1732016..bb0815689cd 100644
--- a/sys/kern/kern_runq.c
+++ b/sys/kern/kern_runq.c
@@ -627,7 +627,7 @@ sched_balance(void *nocallout)
 	/* Make lockless countings */
 	for (CPU_INFO_FOREACH(cii, ci)) {
 		spc = &ci->ci_schedstate;
-
+		spc_lock(ci);
 		/*
 		 * Average count of the threads
 		 *
@@ -643,10 +643,11 @@ sched_balance(void *nocallout)
 			hci = ci;
 			highest = spc->spc_avgcount;
 		}
+		spc_unlock(ci);
 	}
/* Update the worker */
-	worker_ci = hci;
+	atomic_swap_ptr(&worker_ci, hci);
if (nocallout == NULL)
 		callout_schedule(&balance_ch, balance_period);
@@ -734,12 +735,15 @@ sched_idle(void)
 	spc_unlock(ci);
no_migration:
+	spc_lock(ci);
 	if ((spc->spc_flags & SPCF_OFFLINE) != 0 || spc->spc_count != 0) {
+		spc_unlock(ci);
 		return;
 	}
/* Reset the counter, and call the balancer */
 	spc->spc_avgcount = 0;
+	spc_unlock(ci);
 	sched_balance(ci);
 	tci = worker_ci;
 	tspc = &tci->ci_schedstate;
====================

Can I commit this patch?


Thanks,

--
//////////////////////////////////////////////////////////////////////
Internet Initiative Japan Inc.

Device Engineering Section,
Product Development Department,
Product Division,
Technology Unit

Kengo NAKAHARA <k-nakahara%iij.ad.jp@localhost>


Home | Main Index | Thread Index | Old Index