Re: poll() in 2.6 and beyond

From: Linus Torvalds (torvalds_at_osdl.org)
Date: 03/03/04

  • Next message: James Simmons: "New Permedia2 framebuffer driver."
    Date:	Wed, 3 Mar 2004 14:25:52 -0800 (PST)
    To: "Richard B. Johnson" <root@chaos.analogic.com>
    
    

    On Wed, 3 Mar 2004, Richard B. Johnson wrote:
    >
    > are being quashed by those who just like to argue. Therefore,
    > I wrote some code that emulates the environment in which I
    > discovered the poll failure.

    No. I think you wrote some code that shows the bug you have.

    Your "poll()" function IS BUGGY.

    Look at this:

            static size_t poll(struct file *fp, struct poll_table_struct *wait)
            {
                size_t poll_flag;
                size_t flags;
                DEB(printk(KERN_INFO"%s : poll() called\n", devname));
                poll_wait(fp, &pwait, wait);
                DEB(printk(KERN_INFO"%s : poll() returned\n", devname));
                spin_lock_irqsave(&rtc_lock, flags);
                poll_flag = global_poll_flag;
    *** global_poll_flag = 0;
                spin_unlock_irqrestore(&rtc_lock, flags);
                return poll_flag;
            }

    you are clearing your own flag that says "there are events pending", so if
    you call your "poll()" function twice, on the second time it will say
    "there are no events pending".

    You should clear the "events pending" flag only when you literally remove
    the event (ie at "read()" time, not at "poll()" time). Because the
    select() code _will_ call down to the "poll()" functions multiple times if
    it gets woken up for any bogus reason.

    See if that fixes anything.

    It may well be that 2.6.x calls down to the low-level driver "poll()"
    function more than it should. That would be a mis-feature, and worth
    looking at, but I think you should try to fix your test first, since right
    now the bug is questionable.

                            Linus
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/


  • Next message: James Simmons: "New Permedia2 framebuffer driver."

    Relevant Pages

    • Re: 2.4.29-pre2 Oops at find_inode/reiserfs_find_actor
      ... That bug requires the MS_ACTIVE flag to have been cleared. ... IOW, you would have to be in the middle of unmounting the filesystem, ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: [PATCH] break_lock forever broken
      ... in the spinlock fastpath. ... A better solution for the bug you noticed is ... clear the flag if it sees it set, and to make all the other ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)