All of lore.kernel.org
 help / color / mirror / Atom feed
* Walking a wait_queue_t list of tasks blocked on pipe
@ 2016-01-13  3:13 W. Michael Petullo
  0 siblings, 0 replies; 4+ messages in thread
From: W. Michael Petullo @ 2016-01-13  3:13 UTC (permalink / raw)
  To: kernelnewbies

I am trying to walk a wait_queue_t list as part of a LSM file_permission
function. The purpose is to act on each task which has blocked while
trying to read from a pipe.

I have modeled my code on __wake_up_common() in kernel/sched/core.c,
and it looks something like this:

	if (i_pipe->reader <= 0) {
		return;
	}

	list_for_each_entry_safe(curr, next, &i_pipe->wait.task, task_list) {
		[...]
		struct task_struct *blocked = curr->private;
		[...]
	}

I have tried to wrap this with:

	spin_lock_irqsave(&i_pipe->wait.lock, flags)
	spin_unlock_irqrestore[...]

and also:

	write_lock_irq(&tasklist_lock).
	write_unlock_irq[...]

Despite this, I sometimes find that blocked (AKA curr->private) == NULL
during an iteration of the list_for_each_entry_safe loop, and this
surprises me. Why would there be en entry in the wait_queue_t list which
does not have a process associated with it? Is the data structure moving
out from under me? Is there something else I should lock?

Thank you,

-- 
Mike

:wq

^ permalink raw reply	[flat|nested] 4+ messages in thread
* Walking a wait_queue_t list of tasks blocked on pipe
@ 2016-01-14  3:30 W. Michael Petullo
  2016-01-14  8:33 ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: W. Michael Petullo @ 2016-01-14  3:30 UTC (permalink / raw)
  To: linux-kernel

I am trying to write code to walk a wait_queue_t list as part of a LSM
file_permission function. The purpose is to act on each task which has
blocked while trying to read from a pipe.

I modeled my code on __wake_up_common() in kernel/sched/core.c, and it
looks something like this:

	// i_pipe is a struct pipe_inode_info *

	if (i_pipe->reader <= 0) {
		return;
	}

	list_for_each_entry_safe(curr, next, &i_pipe->wait.task, task_list) {
		[...]
		struct task_struct *blocked = curr->private;
		[...]
	}

I am not updating the list itself. I am merely setting a value within
each task_struct's security object.

I have tried to wrap my code with this:

	pipe_lock(i_pipe)
	pipe_unlock[...]

this:

	write_lock_irq(&tasklist_lock)
	write_unlock_irq[...]

and also this:

	spin_lock_irqsave(&i_pipe->wait.lock, flags)
	spin_unlock_irqrestore[...]

Despite these locks, I sometimes find that blocked (AKA curr->private) ==
NULL during an iteration of the list_for_each_entry_safe loop, and this
surprises me. Somme memory corruption errors also seem to indicate that
sometimes blocked contains an invalid pointer other than NULL. Why would
there be en entry in the wait_queue_t list which does not have a process
associated with it? Is the data structure moving out from under me? Is
there something else I should lock?

Thank you,

--
Mike

:wq

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

end of thread, other threads:[~2016-01-14 21:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-13  3:13 Walking a wait_queue_t list of tasks blocked on pipe W. Michael Petullo
  -- strict thread matches above, loose matches on Subject: below --
2016-01-14  3:30 W. Michael Petullo
2016-01-14  8:33 ` Christoph Hellwig
2016-01-14 21:45   ` W. Michael Petullo

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.