Skip to contentSkip to conversation

poll/select: initialize triggered field of struct poll_wqueues

PATCH In review Guillaume Knispel 5 participants 7 messages Aug 15, 2009 – Aug 16, 2009 VFS

lore
Share & tools
lore
#0 lore raw

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
index d870237..8084834 100644
@@ -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;
Acked-by on v1 1/1
#1 lore raw

Guillaume,

Quoted 11 lines · 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.

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
Quoted 17 lines
---
 fs/select.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
fs/select.c +1 -0
index d870237..8084834 100644
@@ -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;
Acked-by on v1 1/1
#2 lore raw
In reply to Guillaume Knispel
Quoted 11 lines · 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.

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.

Ah... nice spotting.

Thanks.

Signature · 1 line
tejun
#3 lore raw
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_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.

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.

Ah... nice spotting.

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.

#4 lore raw

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
#5 lore raw
In reply to Andrew Morton
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

#6 lore raw
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