poll/select: initialize triggered field of struct poll_wqueues
PATCH 1/1 poll/select: initialize triggered field of struct poll_wqueues
Hi,
That's only the second time I read fs/select.c so this has to be reviewed carefully.
It has been quickly tested on my Debian Lenny x86_32 box and everything seems to works fine on the surface.
Cheers,
Guillaume Knispel
poll/select: initialize triggered field of struct poll_wqueues
The triggered field of struct poll_wqueues introduced in commit 5f820f648c92a5ecc771a96b3c29aa6e90013bba "poll: allow f_op->poll to sleep" was set to 1 in pollwake() (now __pollwake() ), tested and later set to 0 in poll_schedule_timeout(), but not initialized before. As a result when the process needs to sleep, triggered was likely to be non-zero even if pollwake() is not called before the first poll_schedule_timeout(), meaning schedule_hrtimeout_range() would not be called and an extra loop calling all ->poll() would be done.
This patch initialize triggered to 0 in poll_initwait() so the ->poll() are not called twice before the process goes to sleep when it needs to.
--- fs/select.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
fs/select.c +1 -0
@@ -110,6 +110,7 @@ void poll_initwait(struct poll_wqueues *pwq) {init_poll_funcptr (&pwq->pt, __pollwait); pwq->polling_task = current; + pwq->triggered =0 ; pwq->error =0 ; pwq->table =NULL ; pwq->inline_index =0 ;
Guillaume,
Quoted 11 lines · Guillaume Knispel
poll/select: initialize triggered field of struct
poll_wqueuesThe triggered field of struct
poll_wqueuesintroduced in commit5f820f648c92a5ecc771a96b3c29aa6e90013bba"poll: allowf_op->pollto sleep" was set to 1 inpollwake()(now__pollwake()), tested and later set to 0 inpoll_schedule_timeout(), but not initialized before. As a result when the process needs to sleep, triggered was likely to be non-zero even ifpollwake()is not called before the firstpoll_schedule_timeout(), meaningschedule_hrtimeout_range()would not be called and an extra loop calling all ->poll() would be done.
Quoted 2 lines
This patch initialize triggered to 0 in
poll_initwait()so the ->poll() are not called twice before the process goes to sleep when it needs to.
Indeed, triggered is random stack content, so it needs to be initialized.
Quoted 1 line
Signed-off-by Guillaume Knispel <[email protected]>
Quoted 17 lines
--- fs/select.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)fs/select.c +1
-0@@ -110,6 +110,7 @@ void poll_initwait(struct poll_wqueues *pwq) {init_poll_funcptr (&pwq->pt, __pollwait); pwq->polling_task = current; + pwq->triggered =0 ; pwq->error =0 ; pwq->table =NULL ; pwq->inline_index =0 ;
Quoted 11 lines · Guillaume Knispel
poll/select: initialize triggered field of struct
poll_wqueuesThe triggered field of struct
poll_wqueuesintroduced in commit5f820f648c92a5ecc771a96b3c29aa6e90013bba"poll: allowf_op->pollto sleep" was set to 1 inpollwake()(now__pollwake()), tested and later set to 0 inpoll_schedule_timeout(), but not initialized before. As a result when the process needs to sleep, triggered was likely to be non-zero even ifpollwake()is not called before the firstpoll_schedule_timeout(), meaningschedule_hrtimeout_range()would not be called and an extra loop calling all ->poll() would be done.
Quoted 4 lines
This patch initialize triggered to 0 in
poll_initwait()so the ->poll() are not called twice before the process goes to sleep when it needs to.Signed-off-by Guillaume Knispel <[email protected]>
Ah... nice spotting.
Thanks.
Signature · 1 line
tejun
Quoted 12 lines · On Sun, 16 Aug 2009 09:53:08 +0900 Tejun Heo <[email protected]> wrote:
Quoted 11 lines · Guillaume Knispel
poll/select: initialize triggered field of struct
poll_wqueuesThe triggered field of struct
poll_wqueuesintroduced in commit5f820f648c92a5ecc771a96b3c29aa6e90013bba"poll: allowf_op->pollto sleep" was set to 1 inpollwake()(now__pollwake()), tested and later set to 0 inpoll_schedule_timeout(), but not initialized before. As a result when the process needs to sleep, triggered was likely to be non-zero even ifpollwake()is not called before the firstpoll_schedule_timeout(), meaningschedule_hrtimeout_range()would not be called and an extra loop calling all ->poll() would be done.
Quoted 9 lines
Quoted 4 lines
This patch initialize triggered to 0 in
poll_initwait()so the ->poll() are not called twice before the process goes to sleep when it needs to.Signed-off-by Guillaume Knispel <[email protected]>Ah... nice spotting.
Acked-by Tejun Heo <[email protected]>
OK, thanks.
I tagged this for -stable backporting. That isn't strictly needed, as there's no particular harm caused here. But using an uninitialised variable in the core poll/select code is pretty gross.
Hello,
Quoted 5 lines · Andrew Morton
OK, thanks.
I tagged this for -stable backporting. That isn't strictly needed, as there's no particular harm caused here. But using an uninitialised variable in the core poll/select code is pretty gross.
Yes, I was thinking about putting this for -stable too. It's not critical but still.
Thanks.
Signature · 1 line
tejun
Quoted 4 lines · Andrew Morton
I tagged this for -stable backporting. That isn't strictly needed, as there's no particular harm caused here. But using an uninitialised variable in the core poll/select code is pretty gross.
Hmm. I committed it when Tejun's ack came in, but I didn't tag it for stable. Oh well.
Linus
Quoted 3 lines · Linus Torvalds
Hmm. I committed it when Tejun's ack came in, but I didn't tag it for stable. Oh well.
Oh, actually, I noticed that I hadn't pushed it out yet. So I added the stable tag and did so.
Linus