Module Name: src
Committed By: riastradh
Date: Fri Aug 16 21:54:17 UTC 2024
Modified Files:
src/sys/kern: subr_localcount.c
Log Message:
localcount: Update per-CPU total at splhigh.
Otherwise localcount_acquire/release in interrupt context may lose
counts.
Duration spent at splhigh is very short.
PR kern/58610: localcount(9) races with interrupts
To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/kern/subr_localcount.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/subr_localcount.c
diff -u src/sys/kern/subr_localcount.c:1.7 src/sys/kern/subr_localcount.c:1.8
--- src/sys/kern/subr_localcount.c:1.7 Fri Nov 17 09:26:36 2017
+++ src/sys/kern/subr_localcount.c Fri Aug 16 21:54:17 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_localcount.c,v 1.7 2017/11/17 09:26:36 ozaki-r Exp $ */
+/* $NetBSD: subr_localcount.c,v 1.8 2024/08/16 21:54:17 riastradh Exp $ */
/*-
* Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -44,7 +44,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_localcount.c,v 1.7 2017/11/17 09:26:36 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_localcount.c,v 1.8 2024/08/16 21:54:17 riastradh Exp $");
#include <sys/param.h>
#include <sys/localcount.h>
@@ -161,11 +161,14 @@ localcount_xc(void *cookie0, void *cooki
struct localcount *lc = cookie0;
kmutex_t *interlock = cookie1;
int64_t *localp;
+ int s;
mutex_enter(interlock);
localp = percpu_getref(lc->lc_percpu);
+ s = splhigh();
*lc->lc_totalp += *localp;
*localp -= *localp; /* ie, *localp = 0; */
+ splx(s);
percpu_putref(lc->lc_percpu);
mutex_exit(interlock);
}
@@ -180,9 +183,12 @@ static void
localcount_adjust(struct localcount *lc, int delta)
{
int64_t *localp;
+ int s;
localp = percpu_getref(lc->lc_percpu);
+ s = splhigh();
*localp += delta;
+ splx(s);
percpu_putref(lc->lc_percpu);
}