All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [rfc] new poll callback'd wake up hell ...
@ 2002-11-25 22:05 John Myers
  2002-11-25 22:36 ` Davide Libenzi
  0 siblings, 1 reply; 9+ messages in thread
From: John Myers @ 2002-11-25 22:05 UTC (permalink / raw)
  To: linux-kernel; +Cc: Davide Libenzi

Davide Libenzi writes:
 > 1) Move the wake_up() call done inside the poll callback outside the lock

You can't.  You need to hold the lock over the callback or your callback 
could end up accessing a freed epitem.



^ permalink raw reply	[flat|nested] 9+ messages in thread
* [rfc] new poll callback'd wake up hell ...
@ 2002-11-20 22:34 Davide Libenzi
  2002-11-21  0:20 ` Mark Mielke
  0 siblings, 1 reply; 9+ messages in thread
From: Davide Libenzi @ 2002-11-20 22:34 UTC (permalink / raw)
  To: Linux Kernel Mailing List; +Cc: Andrew Morton


With the new wake_up() mechanism and wait queue that supports callbacks, a
wake_up() function call might end up calling another function. This
function might be the poll callback that someone else installed on the
first device. The callback invocation will make the one that installed the
callback on the first device to think that events are avalable, and it'll
very likely go ahead and wake_up() its own poll wait queue. See the
problem ? We can cycle through and we can either have a deadlock or a
stack blow up. An easy like ineffective solution would be to avoid the
insertion inside an epoll fd on other epoll fds. But this won't prevent
that another device that will use a similar technique will born tomorrow.
This is waht I was thinking to solve those problems :

1) Move the wake_up() call done inside the poll callback outside the lock

void poll_cb(xxx *data)
{
	int pwake = 0;

	lock(data);
	...
	if (wait_queue_active(&data->poll_wait))
		pwake++;
	unlock(data)
	if (pwake)
		ep_poll_safe_wakeup(&data->psw, &data->poll_wait)
}



2) Use this infrastructure to perform safe poll wakeups

/*
 * This is used to implement the safe poll wake up avoiding to reenter
 * the poll callback from inside wake_up().
 */
struct poll_safewake {
        int wakedoor;	/* Init = 1, can do wake up */
        atomic_t count;	/* Init = 0, wake up count */
};

/* Perform a safe wake up of the poll wait list */
static void ep_poll_safe_wakeup(struct poll_safewake *psw, wait_queue_head_t *wq)
{
        atomic_inc(&psw->count);
        do {
                if (!xchg(&psw->wakedoor, 0))
                        break;
                wake_up(wq);
                xchg(&psw->wakedoor, 1);
        } while (!atomic_dec_and_test(&psw->count));
}



Does anyone foresee problem in this implementation ?
Another ( crappy ) solution might be to avoid the epoll fd to drop inside
its poll wait queue head, wait queues that has the function pointer != NULL




- Davide




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

end of thread, other threads:[~2002-11-25 23:11 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-11-25 22:05 [rfc] new poll callback'd wake up hell John Myers
2002-11-25 22:36 ` Davide Libenzi
2002-11-25 22:52   ` Davide Libenzi
2002-11-25 23:01     ` Davide Libenzi
2002-11-25 23:12   ` John Myers
2002-11-25 23:19     ` Davide Libenzi
  -- strict thread matches above, loose matches on Subject: below --
2002-11-20 22:34 Davide Libenzi
2002-11-21  0:20 ` Mark Mielke
2002-11-21  1:09   ` Davide Libenzi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.