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-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20160104222757.GA969@p100.box>
Date:	Mon, 4 Jan 2016 23:27:57 +0100
From:	Helge Deller <deller@....de>
To:	Thomas Gleixner <tglx@...utronix.de>, linux-parisc@...r.kernel.org,
	James Bottomley <James.Bottomley@...senPartnership.com>,
	John David Anglin <dave.anglin@...l.net>
Cc:	Linux Kernel Development <linux-kernel@...r.kernel.org>
Subject: Re: timerfd_settime/timerfd_gettime issue ?

Hi Thomas,

* Thomas Gleixner <tglx@...utronix.de>:
> On Tue, 29 Dec 2015, Helge Deller wrote:
> > No, the patch below doesn't help.
> > 
> > I still see:
> > [  644.916000] timerfd_settime: interval (sec=0, nsec=100000000) it_value (sec=0, nsec=100000000) 
> > [  645.024000] timerfd_gettime: interval (sec=0, nsec=100000000) it_value (sec=0, nsec=103029949) 
> > 
> 
> Right. It can't help. Sorry for the distraction.
> 
> Looking deeper I found the issue. It's caused by CONFIG_TIME_LOW_RES. See the
> comment in hrtimer_start_range_ns(). We round the expiry time to the next
> jiffies period to avoid short timeouts. Assuming you are running with HZ=250
> this is exactly 4ms. So that's where your extra time comes from.

Yes, that seems right.

> Not sure what to do about that.

The patch below seems to solve the issue for me. But I'm not sure if
there might be any side-effects. What do you think? Does the patch
seems correct? It just adjusts to values returned to userspace (and thus
hides the internal roundings).

Thanks,
Helge

diff --git a/fs/timerfd.c b/fs/timerfd.c
index b94fa6c..9b6cc73 100644
--- a/fs/timerfd.c
+++ b/fs/timerfd.c
@@ -152,8 +152,16 @@ static ktime_t timerfd_get_remaining(struct timerfd_ctx *ctx)
 
 	if (isalarm(ctx))
 		remaining = alarm_expires_remaining(&ctx->t.alarm);
-	else
+	else {
 		remaining = hrtimer_expires_remaining(&ctx->t.tmr);
+#ifdef CONFIG_TIME_LOW_RES
+		/* Expiry time was rounded up in hrtimer_start_range_ns()
+		 * to the next jiffies period to avoid short timeouts.
+		 * Subtract it here again to avoid userspace seeing higher
+		 * values than expected. */
+		remaining.tv64 -= hrtimer_resolution;
+#endif
+	}
 
 	return remaining.tv64 < 0 ? ktime_set(0, 0): remaining;
 }
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ