net_sched: fix a missing rcu barrier in mini_qdisc_pair_swap()
Subsystems (3)
PATCH 1/1 net_sched: fix a missing rcu barrier in mini_qdisc_pair_swap()
The rcu_barrier_bh() in mini_qdisc_pair_swap() is to wait for flying RCU callback installed by a previous mini_qdisc_pair_swap(), however we miss it on the tp_head==NULL path, which leads to that the RCU callback still uses miniq_old->rcu after it is freed together with qdisc in qdisc_graft(). So just add it on that path too.
--- net/sched/sch_generic.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/sched/sch_generic.c +3 -1
@@ -1040,6 +1040,8 @@ void mini_qdisc_pair_swap(struct mini_Qdisc_pair *miniqp,if (!tp_head) {RCU_INIT_POINTER (*miniqp->p_miniq,NULL ); +/* Wait for flying RCU callback before it is freed. */ +rcu_barrier_bh ();return ; }
@@ -1055,7 +1057,7 @@ void mini_qdisc_pair_swap(struct mini_Qdisc_pair *miniqp,rcu_assign_pointer (*miniqp->p_miniq, miniq);if (miniq_old) -/* This is counterpart of the rcu barrier above. We need to +/* This is counterpart of the rcu barriers above. We need to * block potential new user of miniq_old until all readers * are not seeing it. */
Signature · 1 line
2.13.6
Jiri Pirko
maintainerQuoted 7 lines · Thu, Dec 21, 2017 at 08:26:24AM CET, [email protected] wrote:
The
rcu_barrier_bh()inmini_qdisc_pair_swap()is to wait for flying RCU callback installed by a previousmini_qdisc_pair_swap(), however we miss it on the tp_head==NULL path, which leads to that the RCU callback still usesminiq_old->rcuafter it is freed together with qdisc inqdisc_graft(). So just add it on that path too.Fixes 46209401f8f6 ("net: core: introduce mini_Qdisc and eliminate usage of tp->q for clsact fastpath ")
This fixes:752fbcc33405 ("net_sched: no need to free qdisc in RCU callback")
Before that, the issue was not there as the qdisc struct got removed after a grace period.
Quoted 25 lines
Reported-by Jakub Kicinski <[email protected]>Tested-by Jakub Kicinski <[email protected]>Cc Jiri Pirko <[email protected]>Cc John Fastabend <[email protected]>Signed-off-by Cong Wang <[email protected]>---
net/sched/sch_generic.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)net/sched/sch_generic.c +2
-0@@ -1040,6 +1040,8 @@ void mini_qdisc_pair_swap(struct mini_Qdisc_pair *miniqp,if (!tp_head) {RCU_INIT_POINTER (*miniqp->p_miniq,NULL ); +/* Wait for flying RCU callback before it is freed. */ +rcu_barrier_bh ();return ;}
net/sched/sch_generic.c void mini_qdisc_pair_swap(struct mini_Qdisc_pair *miniqp, · line 1060
Quoted 5 lines
net/sched/sch_generic.c +1
-1@@ -1055,7 +1057,7 @@ void mini_qdisc_pair_swap(struct mini_Qdisc_pair *miniqp,rcu_assign_pointer (*miniqp->p_miniq, miniq);if (miniq_old) -/* This is counterpart of the rcu barrier above. We need to +/* This is counterpart of the rcu barriers above. We need to
This is incorrect. Here we block in order to not use the same miniq again in scenario
miniq1 (X)
miniq2
miniq1 (yet there are reader using X)
This call_rcu has 0 relation to the barrier you are adding.
But again, we don't we just free qdisc in call_rcu and avoid the barrier?
Quoted 7 lines · Jiri Pirko
Quoted 6 lines · Thu, Dec 21, 2017 at 08:26:24AM CET, [email protected] wrote:
The
rcu_barrier_bh()inmini_qdisc_pair_swap()is to wait for flying RCU callback installed by a previousmini_qdisc_pair_swap(), however we miss it on the tp_head==NULL path, which leads to that the RCU callback still usesminiq_old->rcuafter it is freed together with qdisc inqdisc_graft(). So just add it on that path too.
Quoted 7 lines
Quoted 1 line
Fixes 46209401f8f6 ("net: core: introduce mini_Qdisc and eliminate usage of tp->q for clsact fastpath ")This fixes:
752fbcc33405("net_sched: no need to free qdisc in RCU callback")Before that, the issue was not there as the qdisc struct got removed after a grace period.
This is non-sense. You have to read the stack trace from Jakub again and tell me why you keep believing any RCU reader involved.
I am pretty sure no one reported any crash between commit 752fbcc33405 and 46209401f8f6.
Quoted 36 lines
Quoted 27 lines
Reported-by Jakub Kicinski <[email protected]>Tested-by Jakub Kicinski <[email protected]>Cc Jiri Pirko <[email protected]>Cc John Fastabend <[email protected]>Signed-off-by Cong Wang <[email protected]>---
net/sched/sch_generic.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)net/sched/sch_generic.c +2
-0@@ -1040,6 +1040,8 @@ void mini_qdisc_pair_swap(struct mini_Qdisc_pair *miniqp,if (!tp_head) {RCU_INIT_POINTER (*miniqp->p_miniq,NULL ); +/* Wait for flying RCU callback before it is freed. */ +rcu_barrier_bh ();return ;}net/sched/sch_generic.c void mini_qdisc_pair_swap(struct mini_Qdisc_pair *miniqp, · line 1060
Quoted 5 lines
net/sched/sch_generic.c +1
-1@@ -1055,7 +1057,7 @@ void mini_qdisc_pair_swap(struct mini_Qdisc_pair *miniqp,rcu_assign_pointer (*miniqp->p_miniq, miniq);if (miniq_old) -/* This is counterpart of the rcu barrier above. We need to +/* This is counterpart of the rcu barriers above. We need to This is incorrect. Here we block in order to not use the same miniq again in scenario
Quoted 5 lines
miniq1 (X)
miniq2
miniq1 (yet there are reader using X)This
call_rcuhas 0 relation to the barrier you are adding.
Seriously? It is this call_rcu still flying after we free the qdisc. Did you seriously look into the stack trace from Jakub?
Quoted 4 lines
But again, we don't we just free qdisc in
call_rcuand avoid the barrier?
Non-sense again. Why qdisc code should be adjusted for your miniq code? It is your own responsibility to take care of this shit. Don't spread it out of minq.
Quoted 10 lines · Cong Wang
Quoted 4 lines · Jiri Pirko
But again, we don't we just free qdisc in
call_rcuand avoid the barrier?Non-sense again. Why qdisc code should be adjusted for your miniq code? It is your own responsibility to take care of this shit. Don't spread it out of minq.
Also, in case you believe call_rcu to free qdisc is queued after the call_rcu in miniq, you are wrong again:
https://www.kernel.org/pub/linux/kernel/people/paulmck/Answers/RCU/RCUCBordering.html
The rcu callbacks don't guarantee FIFO ordering.
Jiri Pirko
maintainerQuoted 8 lines · Thu, Dec 21, 2017 at 09:54:06PM CET, [email protected] wrote:
Quoted 7 lines · Cong Wang
Quoted 4 lines · Jiri Pirko
But again, we don't we just free qdisc in
call_rcuand avoid the barrier?
Quoted 6 lines
Quoted 3 lines
Non-sense again. Why qdisc code should be adjusted for your miniq code? It is your own responsibility to take care of this shit. Don't spread it out of minq.
Also, in case you believe
call_rcuto free qdisc is queued after thecall_rcuin miniq, you are wrong again:
I certainly don't :) Not sure why you think I do.
Quoted 4 lines
https://www.kernel.org/pub/linux/kernel/people/paulmck/Answers/RCU/RCUCBordering.html
The rcu callbacks don't guarantee FIFO ordering.
Jiri Pirko
maintainerQuoted 2 lines · Thu, Dec 21, 2017 at 08:01:35PM CET, [email protected] wrote:
Quoted 1 line · Jiri Pirko
Thu, Dec 21, 2017 at 08:26:24AM CET, [email protected] wrote:
[...]
Quoted 4 lines
Seriously? It is this
call_rcustill flying after we free the qdisc. Did you seriously look into the stack trace from Jakub?
Got it now. You are right. Thank you for politely helping me to get out of my confusion.
Quoted 6 lines · Thu, Dec 21, 2017 at 08:26:24AM CET, [email protected] wrote:
The
rcu_barrier_bh()inmini_qdisc_pair_swap()is to wait for flying RCU callback installed by a previousmini_qdisc_pair_swap(), however we miss it on the tp_head==NULL path, which leads to that the RCU callback still usesminiq_old->rcuafter it is freed together with qdisc inqdisc_graft(). So just add it on that path too.
Quoted 6 lines
Fixes 46209401f8f6 ("net: core: introduce mini_Qdisc and eliminate usage of tp->q for clsact fastpath ")Reported-by Jakub Kicinski <[email protected]>Tested-by Jakub Kicinski <[email protected]>Cc Jiri Pirko <[email protected]>Cc John Fastabend <[email protected]>Signed-off-by Cong Wang <[email protected]>
From: Cong Wang <[email protected]>
Date: Wed, 20 Dec 2017 23:26:24 -0800
Quoted 6 lines
The
rcu_barrier_bh()inmini_qdisc_pair_swap()is to wait for flying RCU callback installed by a previousmini_qdisc_pair_swap(), however we miss it on the tp_head==NULL path, which leads to that the RCU callback still usesminiq_old->rcuafter it is freed together with qdisc inqdisc_graft(). So just add it on that path too.
Quoted 6 lines
Fixes 46209401f8f6 ("net: core: introduce mini_Qdisc and eliminate usage of tp->q for clsact fastpath ")Reported-by Jakub Kicinski <[email protected]>Tested-by Jakub Kicinski <[email protected]>Cc Jiri Pirko <[email protected]>Cc John Fastabend <[email protected]>Signed-off-by Cong Wang <[email protected]>
Applied.