public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH][Bug 5132] fix sys_poll() large timeout handling
@ 2005-08-31 20:01 Nishanth Aravamudan
  2005-09-06 21:25 ` Nishanth Aravamudan
  0 siblings, 1 reply; 11+ messages in thread
From: Nishanth Aravamudan @ 2005-08-31 20:01 UTC (permalink / raw)
  To: akpm; +Cc: dwmw2, bunk, johnstul, drepper, Franz.Fischer, LKML

Sorry everybody, forgot the most important Cc: :)

-Nish

Hi Andrew,

In looking at Bug 5132 and sys_poll(), I think there is a flaw in the
current code.

The @timeout parameter to sys_poll() is in milliseconds but we compare
it to (MAX_SCHEDULE_TIMEOUT / HZ), which is jiffies/jiffies-per-sec or
seconds. That seems blatantly broken. Also, I think we are better served
by converting to jiffies first then comparing, as opposed to converting
our maximum to milliseconds (or seconds, incorrectly) and comparing.

Comments, suggestions for improvement?

Description: The current sys_poll() implementation does not seem to
handle large timeouts correctly. Any value in milliseconds (@timeout)
which exceeds the maximum representable jiffy value
(MAX_SCHEDULE_TIMEOUT) should result in a MAX_SCHEDULE_TIMEOUT
schedule_timeout() call. To achieve this, convert @timeout to jiffies
first, then compare to MAX_SCHEDULE_TIMEOUT.

Signed-off-by: Nishanth Aravamudan <nacc@us.ibm.com>

---

 fs/select.c |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diff -urpN 2.6.13/fs/select.c 2.6.13-dev/fs/select.c
--- 2.6.13/fs/select.c	2005-08-28 17:46:14.000000000 -0700
+++ 2.6.13-dev/fs/select.c	2005-08-31 12:43:52.000000000 -0700
@@ -470,12 +470,16 @@ asmlinkage long sys_poll(struct pollfd _
 		return -EINVAL;
 
 	if (timeout) {
-		/* Careful about overflow in the intermediate values */
-		if ((unsigned long) timeout < MAX_SCHEDULE_TIMEOUT / HZ)
-			timeout = (unsigned long)(timeout*HZ+999)/1000+1;
-		else /* Negative or overflow */
-			timeout = MAX_SCHEDULE_TIMEOUT;
+		/*
+		 * Convert the value from msecs to jiffies - if overflow
+		 * occurs we get a negative value, which gets handled by
+		 * the next block
+		 */
+		timeout = msecs_to_jiffies(timeout) + 1;
 	}
+	if (timeout < 0) /* Negative requests result in infinite timeouts */
+		timeout = MAX_SCHEDULE_TIMEOUT;
+	/* 0 case falls through */
 
 	poll_initwait(&table);
 

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2005-09-12 16:07 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-31 20:01 [PATCH][Bug 5132] fix sys_poll() large timeout handling Nishanth Aravamudan
2005-09-06 21:25 ` Nishanth Aravamudan
2005-09-10  0:35   ` [UPDATE PATCH][Bug " Nishanth Aravamudan
2005-09-10  1:16     ` Andrew Morton
2005-09-10  2:23       ` Nishanth Aravamudan
2005-09-10  2:36         ` Andrew Morton
2005-09-10  2:55           ` Nishanth Aravamudan
2005-09-12 14:30             ` Peter Staubach
2005-09-12 15:05               ` Nishanth Aravamudan
2005-09-12 15:19                 ` Peter Staubach
2005-09-12 16:06                   ` Nishanth Aravamudan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox