]> git.itanic.dy.fi Git - linux-stable/commit
wireguard: ratelimiter: use hrtimer in selftest
authorJason A. Donenfeld <Jason@zx2c4.com>
Tue, 2 Aug 2022 12:56:10 +0000 (14:56 +0200)
committerJakub Kicinski <kuba@kernel.org>
Tue, 2 Aug 2022 20:47:50 +0000 (13:47 -0700)
commit151c8e499f4705010780189377f85b57400ccbf5
tree3e3ec1c005739bac3193c85bf05e696ba10baae4
parent1995943c3f2a59d73efe8bf9b33a92d0f1812af3
wireguard: ratelimiter: use hrtimer in selftest

Using msleep() is problematic because it's compared against
ratelimiter.c's ktime_get_coarse_boottime_ns(), which means on systems
with slow jiffies (such as UML's forced HZ=100), the result is
inaccurate. So switch to using schedule_hrtimeout().

However, hrtimer gives us access only to the traditional posix timers,
and none of the _COARSE variants. So now, rather than being too
imprecise like jiffies, it's too precise.

One solution would be to give it a large "range" value, but this will
still fire early on a loaded system. A better solution is to align the
timeout to the actual coarse timer, and then round up to the nearest
tick, plus change.

So add the timeout to the current coarse time, and then
schedule_hrtimer() until the absolute computed time.

This should hopefully reduce flakes in CI as well. Note that we keep the
retry loop in case the entire function is running behind, because the
test could still be scheduled out, by either the kernel or by the
hypervisor's kernel, in which case restarting the test and hoping to not
be scheduled out still helps.

Fixes: e7096c131e51 ("net: WireGuard secure network tunnel")
Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/wireguard/selftest/ratelimiter.c
kernel/time/hrtimer.c