Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Jun 2018 21:36:16 +0000 (UTC)
From:      Gleb Smirnoff <glebius@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r335242 - head/sys/kern
Message-ID:  <201806152136.w5FLaGCP074334@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: glebius
Date: Fri Jun 15 21:36:16 2018
New Revision: 335242
URL: https://svnweb.freebsd.org/changeset/base/335242

Log:
  Since 'ticks' is an int, it may wrap around and cr_ticks at a certain
  counter_rate will be greater than ticks, resulting in counter_ratecheck()
  failure. To fix this take an absolute value of the difference between
  ticks and cr_ticks.
  
  Reported by:	jtl
  Sponsored by:	Netflix

Modified:
  head/sys/kern/subr_counter.c

Modified: head/sys/kern/subr_counter.c
==============================================================================
--- head/sys/kern/subr_counter.c	Fri Jun 15 21:23:03 2018	(r335241)
+++ head/sys/kern/subr_counter.c	Fri Jun 15 21:36:16 2018	(r335242)
@@ -140,7 +140,7 @@ counter_ratecheck(struct counter_rate *cr, int64_t lim
 	val = cr->cr_over;
 	now = ticks;
 
-	if (now - cr->cr_ticks >= hz) {
+	if (abs(now - cr->cr_ticks) >= hz) {
 		/*
 		 * Time to clear the structure, we are in the next second.
 		 * First try unlocked read, and then proceed with atomic.
@@ -151,7 +151,7 @@ counter_ratecheck(struct counter_rate *cr, int64_t lim
 			 * Check if other thread has just went through the
 			 * reset sequence before us.
 			 */
-			if (now - cr->cr_ticks >= hz) {
+			if (abs(now - cr->cr_ticks) >= hz) {
 				val = counter_u64_fetch(cr->cr_rate);
 				counter_u64_zero(cr->cr_rate);
 				cr->cr_over = 0;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201806152136.w5FLaGCP074334>