Skip to content

Commit 7403060

Browse files
congwangdavem330
authored andcommitted
net_sched: move tcf_lock down after gen_replace_estimator()
Laura reported a sleep-in-atomic kernel warning inside tcf_act_police_init() which calls gen_replace_estimator() with spinlock protection. It is not necessary in this case, we already have RTNL lock here so it is enough to protect concurrent writers. For the reader, i.e. tcf_act_police(), it needs to make decision based on this rate estimator, in the worst case we drop more/less packets than necessary while changing the rate in parallel, it is still acceptable. Reported-by: Laura Abbott <labbott@redhat.com> Reported-by: Nick Huber <nicholashuber@gmail.com> Cc: Jamal Hadi Salim <jhs@mojatatu.com> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Acked-by: Jamal Hadi Salim <jhs@mojatatu.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 20a3d5b commit 7403060

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

net/sched/act_police.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,21 +132,21 @@ static int tcf_act_police_init(struct net *net, struct nlattr *nla,
132132
}
133133
}
134134

135-
spin_lock_bh(&police->tcf_lock);
136135
if (est) {
137136
err = gen_replace_estimator(&police->tcf_bstats, NULL,
138137
&police->tcf_rate_est,
139138
&police->tcf_lock,
140139
NULL, est);
141140
if (err)
142-
goto failure_unlock;
141+
goto failure;
143142
} else if (tb[TCA_POLICE_AVRATE] &&
144143
(ret == ACT_P_CREATED ||
145144
!gen_estimator_active(&police->tcf_rate_est))) {
146145
err = -EINVAL;
147-
goto failure_unlock;
146+
goto failure;
148147
}
149148

149+
spin_lock_bh(&police->tcf_lock);
150150
/* No failure allowed after this point */
151151
police->tcfp_mtu = parm->mtu;
152152
if (police->tcfp_mtu == 0) {
@@ -192,8 +192,6 @@ static int tcf_act_police_init(struct net *net, struct nlattr *nla,
192192

193193
return ret;
194194

195-
failure_unlock:
196-
spin_unlock_bh(&police->tcf_lock);
197195
failure:
198196
qdisc_put_rtab(P_tab);
199197
qdisc_put_rtab(R_tab);

0 commit comments

Comments
 (0)