Use a cloned sk_buff for each netlink message sent to multiple listeners.
Earlier, the same skb, representing a netlink message, was being erroneously
reused for doing genetlink_unicast()'s (effectively netlink_unicast()) to
each listener on the per-cpu list of listeners. Since netlink_unicast() frees
up the skb passed to it, regardless of status of the send, reuse is bad.
Thanks to Chandra Seetharaman for discovering this bug.
Signed-Off-By: Shailabh Nagar <redacted>
Signed-Off-By: Chandra Seetharaman <redacted>
kernel/taskstats.c | 13 ++++++++++++-
1 files changed, 12 insertions(+), 1 deletion(-)
Index: linux-2.6.18-rc1/kernel/taskstats.c
===================================================================
If we do a GFP_KERNEL allocation with this semaphore held, and the
oom-killer tries to kill something to satisfy the allocation, and the
killed task gets stuck on that semaphore, I wonder of the box locks up.
Probably it'll work out OK if the semaphore is taken after that task has
had some resources torn down.
If we do a GFP_KERNEL allocation with this semaphore held, and the
oom-killer tries to kill something to satisfy the allocation, and the
killed task gets stuck on that semaphore, I wonder of the box locks up.
If we do a GFP_KERNEL allocation with this semaphore held, and the
oom-killer tries to kill something to satisfy the allocation, and the
killed task gets stuck on that semaphore, I wonder of the box locks up.
We do GFP_KERNEL inside semaphores/mutexes in lots of places. So if this
can deadlock with the oom-killer we probably should fix that, preferably
by having GFP_KERNEL fail in that case.
This lock is special, in that it's taken on the exit() path (I think). So
it can block tasks which are trying to exit.
But yes. Reliable, deadlock-free oom-killing is, err, a matter of ongoing
research.
If we do a GFP_KERNEL allocation with this semaphore held, and the
oom-killer tries to kill something to satisfy the allocation, and the
killed task gets stuck on that semaphore, I wonder of the box locks up.
We do GFP_KERNEL inside semaphores/mutexes in lots of places. So if this
can deadlock with the oom-killer we probably should fix that, preferably
by having GFP_KERNEL fail in that case.
This lock is special, in that it's taken on the exit() path (I think). So
it can block tasks which are trying to exit.
If we do a GFP_KERNEL allocation with this semaphore held, and the
oom-killer tries to kill something to satisfy the allocation, and the
killed task gets stuck on that semaphore, I wonder of the box locks up.
Hmm...doesn't look very safe does it.
There's no real need for us to skb_clone within the sem. Keeping a count of
listeners and doing the clone outside should let us avoid this problem.
I was trying to avoid doing the above because of the potential for
listeners getting added continuously to the list
(and having to repeat the allocation loop outside the down_write).
But on second thoughts, we're under no obligation to send the data to all the
listeners who add themselves in the short time between our taking a snapshot
of the listener count and when the send is done (within the down_write). So
it should be ok.
quoted
quoted
We do GFP_KERNEL inside semaphores/mutexes in lots of places. So if this
can deadlock with the oom-killer we probably should fix that, preferably
by having GFP_KERNEL fail in that case.
This lock is special, in that it's taken on the exit() path (I think). So
it can block tasks which are trying to exit.
Sorry, missed the context.
If there is a deadlock then it's not just this allocation that you
need worry about. There is also an allocation within genlmsg_uniast
that would be GFP_KERNEL.
Thats true. The GFP_KERNEL allocation potentially called in netlink_trim() as part
of the genlmsg/netlink_unicast() is again a problem.
So perhaps we should switch to using RCU for protecting the listener list.
--Shailabh
If we do a GFP_KERNEL allocation with this semaphore held, and the
oom-killer tries to kill something to satisfy the allocation, and the
killed task gets stuck on that semaphore, I wonder of the box locks up.
We do GFP_KERNEL inside semaphores/mutexes in lots of places. So if this
can deadlock with the oom-killer we probably should fix that, preferably
by having GFP_KERNEL fail in that case.
This lock is special, in that it's taken on the exit() path (I think). So
it can block tasks which are trying to exit.
Sorry, missed the context.
If there is a deadlock then it's not just this allocation that you
need worry about. There is also an allocation within genlmsg_uniast
that would be GFP_KERNEL.
Remove down_write() from taskstats code invoked on the exit() path.
In send_cpu_listeners(), which is called on the exit path,
a down_write() was protecting operations like skb_clone() and
genlmsg_unicast() that do GFP_KERNEL allocations. If the oom-killer
decides to kill tasks to satisfy the allocations,the exit of those
tasks could block on the same semphore.
The down_write() was only needed to allow removal of invalid
listeners from the listener list. The patch converts the down_write
to a down_read and defers the removal to a separate critical region.
This ensures that even if the oom-killer is called, no other task's
exit is blocked as it can still acquire another down_read.
Thanks to Andrew Morton & Herbert Xu for pointing out the oom
related pitfalls, and to Chandra Seetharaman for suggesting this
fix instead of using something more complex like RCU.
Signed-Off-By: Chandra Seetharaman <redacted>
Signed-Off-By: Shailabh Nagar <redacted>
---
kernel/taskstats.c | 24 +++++++++++++++++++-----
1 files changed, 19 insertions(+), 5 deletions(-)
Index: linux-2.6.18-rc1/kernel/taskstats.c
===================================================================