lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 11 Oct 2021 16:57:53 +0800
From:   Yajun Deng <yajun.deng@...ux.dev>
To:     davem@...emloft.net, kuba@...nel.org
Cc:     netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
        Yajun Deng <yajun.deng@...ux.dev>
Subject: [PATCH net-next] netpoll: Fix carrier_timeout for msleep()

It should be sleep carrier_timeout seconds rather than 4 seconds if
carrier_timeout has been modified.
Add start variable, hence atleast and atmost use the same jiffies, and
use msecs_to_jiffies() and MSEC_PER_SEC match with jiffies.
At the same time, msleep() is not for 1ms - 20ms, use usleep_range()
instead, see Documentation/timers/timers-howto.rst.

Fixes: bff38771e106 ("netpoll: Introduce netpoll_carrier_timeout kernel option")
Signed-off-by: Yajun Deng <yajun.deng@...ux.dev>
---
 net/core/netpoll.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index edfc0f8011f8..88e4ff3b9e95 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -682,7 +682,7 @@ int netpoll_setup(struct netpoll *np)
 	}
 
 	if (!netif_running(ndev)) {
-		unsigned long atmost, atleast;
+		unsigned long atmost, atleast, start;
 
 		np_info(np, "device %s not up yet, forcing it\n", np->dev_name);
 
@@ -694,14 +694,15 @@ int netpoll_setup(struct netpoll *np)
 		}
 
 		rtnl_unlock();
-		atleast = jiffies + HZ/10;
-		atmost = jiffies + carrier_timeout * HZ;
+		start = jiffies;
+		atleast = start + msecs_to_jiffies(MSEC_PER_SEC / 10);
+		atmost = start + msecs_to_jiffies(carrier_timeout * MSEC_PER_SEC);
 		while (!netif_carrier_ok(ndev)) {
 			if (time_after(jiffies, atmost)) {
 				np_notice(np, "timeout waiting for carrier\n");
 				break;
 			}
-			msleep(1);
+			usleep_range(USEC_PER_MSEC, 2 * USEC_PER_MSEC);
 		}
 
 		/* If carrier appears to come up instantly, we don't
@@ -710,8 +711,9 @@ int netpoll_setup(struct netpoll *np)
 		 */
 
 		if (time_before(jiffies, atleast)) {
-			np_notice(np, "carrier detect appears untrustworthy, waiting 4 seconds\n");
-			msleep(4000);
+			np_notice(np, "carrier detect appears untrustworthy, waiting %d seconds\n",
+				  carrier_timeout);
+			msleep(carrier_timeout * MSEC_PER_SEC);
 		}
 		rtnl_lock();
 	}
-- 
2.32.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ