From: Willy Tarreau <willy@w.ods.org>
To: Davide Libenzi <davidel@xmailserver.org>, Andrew Morton <akpm@osdl.org>
Cc: Nishanth Aravamudan <nacc@us.ibm.com>,
Nish Aravamudan <nish.aravamudan@gmail.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 3/3] 2.6.14-rc2-mm1 : fixes for overflow in sys_poll()
Date: Sat, 1 Oct 2005 22:39:03 +0200 [thread overview]
Message-ID: <20051001203903.GB28113@alpha.home.local> (raw)
In-Reply-To: <20050924195205.GE26197@alpha.home.local>
Hi,
On Sat, Sep 24, 2005 at 09:52:05PM +0200, Willy Tarreau wrote:
> This patch simplifies the overflow fix which was applied to sys_poll() in
> 2.6.14-rc2-mm1 by relying on the overflow detection code added to jiffies.h
> by patch 1/3. This also removes a useless divide for HZ <= 1000.
>
> It might be worth applying too. It's only for -mm1, and does *not* apply
> to 2.6.14-rc2 because this code has already received patches in -mm1.
I noticed that the overflow check in the original code is either useless or
buggy, so this patch is even more worth applying. Look below at original
code : if HZ <= 1000, the overflow is set only when
msecs_to_jiffies() >= MAX_SCHEDULE_TIMEOUT.
But the maximal value that msecs_to_jiffies() can return is MAX_JIFFY_OFFSET.
Guess what ?
include/linux/jiffies.h:#define MAX_JIFFY_OFFSET ((~0UL >> 1)-1)
include/linux/sched.h:#define MAX_SCHEDULE_TIMEOUT LONG_MAX
include/linux/kernel.h:#define LONG_MAX ((long)(~0UL>>1))
=> MAX_JIFFY_OFFSET == (MAX_SCHEDULE_TIMEOUT - 1)
=> So msecs_to_jiffies() cannot be >= MAX_SCHEDULE_TIMEOUT, and 'overflow'
can never be set for HZ <= 1000.
Given how msecs_to_jiffies() is used everywhere, I wonder if we should not
provide a separate overflow detection function which would be used where
needed, and possibly remove the test from msecs_to_jiffies() which is mostly
called with constants or small delays which will never overflow.
Has anyone an opinion on this ?
Regards,
Willy
> diff -purN linux-2.6.14-rc2-mm1/fs/select.c linux-2.6.14-rc2-mm1-poll/fs/select.c
> --- linux-2.6.14-rc2-mm1/fs/select.c Sat Sep 24 21:12:36 2005
> +++ linux-2.6.14-rc2-mm1-poll/fs/select.c Sat Sep 24 21:23:21 2005
> @@ -469,7 +469,6 @@ asmlinkage long sys_poll(struct pollfd _
> {
> struct poll_wqueues table;
> int fdcount, err;
> - int overflow;
> unsigned int i;
> struct poll_list *head;
> struct poll_list *walk;
> @@ -486,22 +485,11 @@ asmlinkage long sys_poll(struct pollfd _
> return -EINVAL;
>
> /*
> - * We compare HZ with 1000 to work out which side of the
> - * expression needs conversion. Because we want to avoid
> - * converting any value to a numerically higher value, which
> - * could overflow.
> - */
> -#if HZ > 1000
> - overflow = timeout_msecs >= jiffies_to_msecs(MAX_SCHEDULE_TIMEOUT);
> -#else
> - overflow = msecs_to_jiffies(timeout_msecs) >= MAX_SCHEDULE_TIMEOUT;
> -#endif
> -
> - /*
> * If we would overflow in the conversion or a negative timeout
> - * is requested, sleep indefinitely.
> + * is requested, sleep indefinitely. Note: msecs_to_jiffies checks
> + * for the overflow.
> */
> - if (overflow || timeout_msecs < 0)
> + if (timeout_msecs < 0)
> timeout_jiffies = MAX_SCHEDULE_TIMEOUT;
> else
> timeout_jiffies = msecs_to_jiffies(timeout_msecs) + 1;
>
>
next prev parent reply other threads:[~2005-10-01 20:45 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-09-23 18:13 [patch] sys_epoll_wait() timeout saga Davide Libenzi
2005-09-23 18:24 ` Nish Aravamudan
2005-09-24 4:05 ` Willy Tarreau
2005-09-24 4:44 ` Nish Aravamudan
2005-09-24 6:15 ` Willy Tarreau
2005-09-24 7:33 ` Vadim Lobanov
2005-09-24 7:51 ` Willy Tarreau
2005-09-24 15:10 ` Davide Libenzi
2005-09-24 17:20 ` Willy Tarreau
2005-09-24 18:19 ` Davide Libenzi
2005-09-25 6:05 ` Andrew Morton
2005-09-25 6:20 ` Willy Tarreau
2005-09-25 6:32 ` Andrew Morton
2005-09-25 7:08 ` Vadim Lobanov
2005-09-25 8:03 ` Willy Tarreau
2005-09-24 17:19 ` Nishanth Aravamudan
2005-09-24 18:25 ` Davide Libenzi
2005-09-24 19:38 ` [PATCH 0/3] fixes for overflow in poll(), epoll(), and msec_to_jiffies() Willy Tarreau
2005-09-24 19:44 ` [PATCH 1/3] 2.6.14-rc2-mm1: fixes for overflow msec_to_jiffies() Willy Tarreau
2005-09-29 9:43 ` Andrew Morton
2005-09-29 19:41 ` Willy Tarreau
2005-09-29 19:52 ` Andrew Morton
2005-09-29 20:55 ` Willy Tarreau
2005-10-01 17:39 ` Willy Tarreau
2005-09-24 19:47 ` [PATCH 2/3] 2.6.14-rc2-mm1: fixes for overflow in epoll() Willy Tarreau
2005-09-24 19:52 ` [PATCH 3/3] 2.6.14-rc2-mm1 : fixes for overflow in sys_poll() Willy Tarreau
2005-10-01 20:39 ` Willy Tarreau [this message]
2005-09-24 20:08 ` [PATCH 0/3] fixes for overflow in poll(), epoll(), and msec_to_jiffies() Davide Libenzi
2005-09-24 20:21 ` Willy TARREAU
2005-09-25 20:55 ` Nishanth Aravamudan
2005-09-25 22:06 ` Willy Tarreau
2005-09-24 21:25 ` [patch] sys_epoll_wait() timeout saga Vadim Lobanov
2005-09-24 18:30 ` Willy Tarreau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20051001203903.GB28113@alpha.home.local \
--to=willy@w.ods.org \
--cc=akpm@osdl.org \
--cc=davidel@xmailserver.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nacc@us.ibm.com \
--cc=nish.aravamudan@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®