From: Johannes Berg <johannes@sipsolutions.net> Date: 2013-08-21 14:08:10
Here's another attempt at fixing the genetlink locking issue,
hopefully better tested this time. Sorry about the mess the
previous version caused.
I really didn't find a way to "simply" add locking, no matter
which way I turn genetlink is special because it would then use
the same locks "inside" and "outside" the generic netlink family;
"inside" because I'm trying to protect the otherwise unlocked
dump call, and "outside" because it itself is a generic netlink
family so needs to protect things there.
As a result, I've turned to RCU and (hopefully) made it safe.
The unregistration can get fairly expensive with all the calls
to synchronize_rcu(), but I don't see any better way, and it's
hopefully really rare.
The only place that now uses RCU is ctrl_dumpfamily(), but it'd
be possible to use it in other places. I didn't want to do it
in this patch, but I also don't see any candidates where that
would really make sense.
The first patch should obviously go into 3.11, I'll let you
decide about the second. This one might actually be easier to
backport than the original one, but it'd still have to be done
carefully.
johannes
From: Johannes Berg <johannes@sipsolutions.net> Date: 2013-08-21 14:08:10
From: Johannes Berg <redacted>
This reverts commit 58ad436fcf49810aa006016107f494c9ac9013db.
It turns out that the change introduced a potential deadlock
by causing a locking dependency with netlink's cb_mutex. I
can't seem to find a way to resolve this without doing major
changes to the locking, so revert this.
Signed-off-by: Johannes Berg <redacted>
---
net/netlink/genetlink.c | 7 -------
1 file changed, 7 deletions(-)
From: Johannes Berg <johannes@sipsolutions.net> Date: 2013-08-21 14:08:10
From: Johannes Berg <redacted>
In my previous commit 58ad436fcf49810aa006016107f494c9ac9013db
("genetlink: fix family dump race") I attempted to solve an
issue in generic netlink that could lead to crashes, but it
turns out that this introduced a possibility for deadlock. As
I haven't found a way to actually add locking without causing
that, convert the family, family ops/mcast group lists all to
use RCU, so the family dump code can simply use RCU protection
instead of locking.
Signed-off-by: Johannes Berg <redacted>
---
net/netlink/genetlink.c | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
From: Oliver Hartkopp <socketcan@hartkopp.net> Date: 2013-08-21 19:06:13
On 21.08.2013 16:08, Johannes Berg wrote:
Here's another attempt at fixing the genetlink locking issue,
hopefully better tested this time. Sorry about the mess the
previous version caused.
I really didn't find a way to "simply" add locking, no matter
which way I turn genetlink is special because it would then use
the same locks "inside" and "outside" the generic netlink family;
"inside" because I'm trying to protect the otherwise unlocked
dump call, and "outside" because it itself is a generic netlink
family so needs to protect things there.
As a result, I've turned to RCU and (hopefully) made it safe.
The unregistration can get fairly expensive with all the calls
to synchronize_rcu(), but I don't see any better way, and it's
hopefully really rare.
The only place that now uses RCU is ctrl_dumpfamily(), but it'd
be possible to use it in other places. I didn't want to do it
in this patch, but I also don't see any candidates where that
would really make sense.
The first patch should obviously go into 3.11, I'll let you
decide about the second. This one might actually be easier to
backport than the original one, but it'd still have to be done
carefully.
I applied both patches.
The lockdep issue vanished and i still can write emails :-)
Thanks Johannes.
Tested-by: Oliver Hartkopp <socketcan@hartkopp.net>
johannes
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
This looks like more general problem and not specific to genl_ctrl
family. I have couple of fixes for issues you are seeing, I will send
out those patches soon.
On Wed, Aug 21, 2013 at 12:05 PM, Oliver Hartkopp
[off-list ref] wrote:
On 21.08.2013 16:08, Johannes Berg wrote:
quoted
Here's another attempt at fixing the genetlink locking issue,
hopefully better tested this time. Sorry about the mess the
previous version caused.
I really didn't find a way to "simply" add locking, no matter
which way I turn genetlink is special because it would then use
the same locks "inside" and "outside" the generic netlink family;
"inside" because I'm trying to protect the otherwise unlocked
dump call, and "outside" because it itself is a generic netlink
family so needs to protect things there.
As a result, I've turned to RCU and (hopefully) made it safe.
The unregistration can get fairly expensive with all the calls
to synchronize_rcu(), but I don't see any better way, and it's
hopefully really rare.
The only place that now uses RCU is ctrl_dumpfamily(), but it'd
be possible to use it in other places. I didn't want to do it
in this patch, but I also don't see any candidates where that
would really make sense.
The first patch should obviously go into 3.11, I'll let you
decide about the second. This one might actually be easier to
backport than the original one, but it'd still have to be done
carefully.
I applied both patches.
The lockdep issue vanished and i still can write emails :-)
Thanks Johannes.
Tested-by: Oliver Hartkopp <socketcan@hartkopp.net>
quoted
johannes
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, Aug 21, 2013 at 7:08 AM, Johannes Berg
[off-list ref] wrote:
From: Johannes Berg <redacted>
This reverts commit 58ad436fcf49810aa006016107f494c9ac9013db.
It turns out that the change introduced a potential deadlock
by causing a locking dependency with netlink's cb_mutex. I
can't seem to find a way to resolve this without doing major
changes to the locking, so revert this.
Signed-off-by: Johannes Berg <redacted>
1.8.4.rc2
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, Aug 21, 2013 at 7:08 AM, Johannes Berg
[off-list ref] wrote:
From: Johannes Berg <redacted>
In my previous commit 58ad436fcf49810aa006016107f494c9ac9013db
("genetlink: fix family dump race") I attempted to solve an
issue in generic netlink that could lead to crashes, but it
turns out that this introduced a possibility for deadlock. As
I haven't found a way to actually add locking without causing
that, convert the family, family ops/mcast group lists all to
use RCU, so the family dump code can simply use RCU protection
instead of locking.
Signed-off-by: Johannes Berg <redacted>
1.8.4.rc2
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Johannes Berg <johannes@sipsolutions.net> Date: 2013-08-22 06:51:35
On Wed, 2013-08-21 at 15:53 -0700, Pravin Shelar wrote:
This looks like more general problem and not specific to genl_ctrl
family. I have couple of fixes for issues you are seeing, I will send
out those patches soon.
No, it's not a general problem.
You don't _want_ dump generally locked, it's not really useful. Netlink
guarantees with the cb_mutex that it can't go away, so locking dump at
the generic netlink level doesn't buy the average generic netlink user
at all.
I think that the problem is that generic netlink is "inside itself" in a
manner of speaking.
OTOH, I'm not sure I fully understand what would happen if a family is
deleted while something inside of it is dumping. Even the module unload
wouldn't be prevented since netlink_dump_start() uses THIS_MODULE (which
is really NULL since generic netlink is built into the kernel), so maybe
you're right about the locking, but then your patch still wouldn't be
correct because the family might still go away even if you lock the
genl_lock() every round.
I think to fix that additional problem we need something like the
(untested!) patch below (which is missing documentation updates) in
addition to fix that problem.
johannes
In case of genl-family with parallel ops off, dumpif() callback
is expected to run under genl_lock,
But commit def3117493eafd9df
(genl: Allow concurrent genl callbacks.) changed this behaviour
where only first dumpit() op was called under genl-lock.
I don't think either of those statements are true - dump() has alway
taken a shortcut in netlink_recvmsg() and doesn't go into genl_rcv(), so
how could your patch have changed locking? Therefore, it can't have been
expected either.
For subsequent dump, only nlk->cb_lock was taken.
Following patch fixes it by defining locked dumpit() and done()
callback which takes care of genl-locking.
This might help for generic netlink itself, but I'm not convinced that
it's really useful for other families. I've fixed bugs like in commit
3a5a423bb958ad22eeccca66c533e85bf69ba10e, which actually made it in
after your commit, but per above I don't think it was actually a problem
introduced by your commit.
johannes
From: David Miller <davem@davemloft.net> Date: 2013-08-22 20:26:32
From: Johannes Berg <johannes@sipsolutions.net>
Date: Wed, 21 Aug 2013 16:08:02 +0200
From: Johannes Berg <redacted>
This reverts commit 58ad436fcf49810aa006016107f494c9ac9013db.
It turns out that the change introduced a potential deadlock
by causing a locking dependency with netlink's cb_mutex. I
can't seem to find a way to resolve this without doing major
changes to the locking, so revert this.
Signed-off-by: Johannes Berg <redacted>
So I've applied this since everyone agrees that we should revert
this change.
How to deal with the problem we were attempting to solve is still
under discussion. It seems that even if we go to RCU we must also
address to module reference count issue.
I think the existing locking is very messy, and RCU looks a lot
cleaner and has potential for future improvements to the scalability
of dumps.
So I'd like to propose that we combine Johannes's RCU conversion
with some variant of the module reference count fix.
Can you guys work together and come up with something I can apply?
Thanks.
From: Johannes Berg <johannes@sipsolutions.net> Date: 2013-08-22 20:36:16
On Thu, 2013-08-22 at 13:26 -0700, David Miller wrote:
How to deal with the problem we were attempting to solve is still
under discussion. It seems that even if we go to RCU we must also
address to module reference count issue.
Yes, that's a separate issue. However, I think we should also check in
more detail the dumpit locking issue Pravin pointed out - before his
changes there was indeed the genl lock used as the cb_mutex. As I've
said over in the other thread, I'm not sure that change was actually
useful - it sounded like he confused kernel sockets and userland sockets
here? (Or maybe I am?!)
OTOH, we've already fixed the race conditions that resulted from his
patch, at least in nl80211. You might remember the issue Linus ran into
with the attrbuf, it's looking like that issue was because he changed
generic netlink to no longer use the genl_lock as the cb_mutex.
I think the existing locking is very messy, and RCU looks a lot
cleaner and has potential for future improvements to the scalability
of dumps.
I agree, though we're not all that interested in generic netlink family
scalability I think, we have less than a dozen families, so this
shouldn't really be an issue.
So I'd like to propose that we combine Johannes's RCU conversion
with some variant of the module reference count fix.
Can you guys work together and come up with something I can apply?
Sure, that in itself isn't really a problem, but if we don't take
Pravin's patch to "revert" the cb_mutex change in his parallel_ops
changes, then we definitely need to audit all generic netlink dumpit
implementations in all users to see if they have similar races to
nl80211. I originally thought that it was an nl80211 problem, but I'm
now convinced that it wasn't. Still the new code in nl80211 is probably
nicer, and we can probably make it parallel_ops now due to these changes
but I'm not convinced we can audit all genl families.
If it wasn't that so much time has already passed since the parallel_ops
changes I'd almost suggest reverting those altogether and addressing the
locking properly ...
johannes
On Thu, Aug 22, 2013 at 1:36 PM, Johannes Berg
[off-list ref] wrote:
On Thu, 2013-08-22 at 13:26 -0700, David Miller wrote:
quoted
How to deal with the problem we were attempting to solve is still
under discussion. It seems that even if we go to RCU we must also
address to module reference count issue.
Yes, that's a separate issue. However, I think we should also check in
more detail the dumpit locking issue Pravin pointed out - before his
changes there was indeed the genl lock used as the cb_mutex. As I've
said over in the other thread, I'm not sure that change was actually
useful - it sounded like he confused kernel sockets and userland sockets
here? (Or maybe I am?!)
OTOH, we've already fixed the race conditions that resulted from his
patch, at least in nl80211. You might remember the issue Linus ran into
with the attrbuf, it's looking like that issue was because he changed
generic netlink to no longer use the genl_lock as the cb_mutex.
quoted
I think the existing locking is very messy, and RCU looks a lot
cleaner and has potential for future improvements to the scalability
of dumps.
I agree, though we're not all that interested in generic netlink family
scalability I think, we have less than a dozen families, so this
shouldn't really be an issue.
quoted
So I'd like to propose that we combine Johannes's RCU conversion
with some variant of the module reference count fix.
Can you guys work together and come up with something I can apply?
Sure, that in itself isn't really a problem, but if we don't take
Pravin's patch to "revert" the cb_mutex change in his parallel_ops
changes, then we definitely need to audit all generic netlink dumpit
implementations in all users to see if they have similar races to
nl80211. I originally thought that it was an nl80211 problem, but I'm
now convinced that it wasn't. Still the new code in nl80211 is probably
nicer, and we can probably make it parallel_ops now due to these changes
but I'm not convinced we can audit all genl families.
I have sent fixes for genl-locking.
If it wasn't that so much time has already passed since the parallel_ops
changes I'd almost suggest reverting those altogether and addressing the
locking properly ...
I think genl-parallel ops patch decouple genl-locking from netlink
lock which simplifies it. This also allows existing genl-family
gradually converted to parallel-ops. Once all are moved to parallel
ops, we can get rid of genl_mutex completely.
Passing mutex after one module to another is messy and confusing.
After genl-parallel op changes this is done only by rtnl module.
I will try to get rid of this cb_mutex parameter so that each layer
can have independent locks. I need to check rtnl module for that.