Module Name: src Committed By: snj Date: Mon Feb 26 00:43:23 UTC 2018
Modified Files: src/sys/kern [netbsd-8]: kern_synch.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #573): sys/kern/kern_synch.c: 1.314 Avoid a race condition between an LWP migration and curlwp_bind curlwp_bind sets the LP_BOUND flag to l_pflags of the current LWP, which prevents it from migrating to another CPU until curlwp_bindx is called. Meanwhile, there are several ways that an LWP is migrated to another CPU and in any cases the scheduler postpones a migration if a target LWP is running. One example of LWP migrations is a load balancing; the scheduler periodically explores CPU-hogging LWPs and schedule them to migrate (see sched_lwp_stats). At that point the scheduler checks the LP_BOUND flag and if it's set to a LWP, the scheduler doesn't schedule the LWP. A scheduled LWP is tried to be migrated when it is leaving a running CPU, i.e., mi_switch. And mi_switch does NOT check the LP_BOUND flag. So if an LWP is scheduled first and then it sets the LP_BOUND flag, the LWP can be migrated regardless of the flag. To avoid this race condition, we need to check the flag in mi_switch too. For more details see https://mail-index.netbsd.org/tech-kern/2018/02/13/msg023079.html To generate a diff of this commit: cvs rdiff -u -r1.311 -r1.311.10.1 src/sys/kern/kern_synch.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/kern_synch.c diff -u src/sys/kern/kern_synch.c:1.311 src/sys/kern/kern_synch.c:1.311.10.1 --- src/sys/kern/kern_synch.c:1.311 Sun Jul 3 14:24:58 2016 +++ src/sys/kern/kern_synch.c Mon Feb 26 00:43:23 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_synch.c,v 1.311 2016/07/03 14:24:58 christos Exp $ */ +/* $NetBSD: kern_synch.c,v 1.311.10.1 2018/02/26 00:43:23 snj Exp $ */ /*- * Copyright (c) 1999, 2000, 2004, 2006, 2007, 2008, 2009 @@ -69,7 +69,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.311 2016/07/03 14:24:58 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.311.10.1 2018/02/26 00:43:23 snj Exp $"); #include "opt_kstack.h" #include "opt_perfctrs.h" @@ -589,7 +589,8 @@ mi_switch(lwp_t *l) * be reset here, if interrupt/preemption happens * early in idle LWP. */ - if (l->l_target_cpu != NULL) { + if (l->l_target_cpu != NULL && + (l->l_pflag & LP_BOUND) == 0) { KASSERT((l->l_pflag & LP_INTR) == 0); spc->spc_migrating = l; }