File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -249,10 +249,11 @@ bool icmp_global_allow(void)
249
249
bool rc = false;
250
250
251
251
/* Check if token bucket is empty and cannot be refilled
252
- * without taking the spinlock.
252
+ * without taking the spinlock. The READ_ONCE() are paired
253
+ * with the following WRITE_ONCE() in this same function.
253
254
*/
254
- if (!icmp_global .credit ) {
255
- delta = min_t (u32 , now - icmp_global .stamp , HZ );
255
+ if (!READ_ONCE ( icmp_global .credit ) ) {
256
+ delta = min_t (u32 , now - READ_ONCE ( icmp_global .stamp ) , HZ );
256
257
if (delta < HZ / 50 )
257
258
return false;
258
259
}
@@ -262,14 +263,14 @@ bool icmp_global_allow(void)
262
263
if (delta >= HZ / 50 ) {
263
264
incr = sysctl_icmp_msgs_per_sec * delta / HZ ;
264
265
if (incr )
265
- icmp_global .stamp = now ;
266
+ WRITE_ONCE ( icmp_global .stamp , now ) ;
266
267
}
267
268
credit = min_t (u32 , icmp_global .credit + incr , sysctl_icmp_msgs_burst );
268
269
if (credit ) {
269
270
credit -- ;
270
271
rc = true;
271
272
}
272
- icmp_global .credit = credit ;
273
+ WRITE_ONCE ( icmp_global .credit , credit ) ;
273
274
spin_unlock (& icmp_global .lock );
274
275
return rc ;
275
276
}
You can’t perform that action at this time.
0 commit comments