Skip to content

Commit d32ae76

Browse files
Eric Dumazetdavem330
authored andcommitted
sch_qfq: accurate wsum handling
We can underestimate q->wsum in case of "tc class replace ... qfq" and/or qdisc_create_dflt() error. wsum is not really used in fast path, only at qfq qdisc/class setup, to catch user error. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> CC: Stephen Hemminger <shemminger@vyatta.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent d47a0ac commit d32ae76

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

‎net/sched/sch_qfq.c‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ static int qfq_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
211211
struct nlattr *tb[TCA_QFQ_MAX + 1];
212212
u32 weight, lmax, inv_w;
213213
int i, err;
214+
int delta_w;
214215

215216
if (tca[TCA_OPTIONS] == NULL) {
216217
pr_notice("qfq: no options\n");
@@ -232,9 +233,10 @@ static int qfq_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
232233

233234
inv_w = ONE_FP / weight;
234235
weight = ONE_FP / inv_w;
235-
if (q->wsum + weight > QFQ_MAX_WSUM) {
236+
delta_w = weight - (cl ? ONE_FP / cl->inv_w : 0);
237+
if (q->wsum + delta_w > QFQ_MAX_WSUM) {
236238
pr_notice("qfq: total weight out of range (%u + %u)\n",
237-
weight, q->wsum);
239+
delta_w, q->wsum);
238240
return -EINVAL;
239241
}
240242

@@ -256,13 +258,12 @@ static int qfq_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
256258
return err;
257259
}
258260

259-
sch_tree_lock(sch);
260-
if (tb[TCA_QFQ_WEIGHT]) {
261-
q->wsum = weight - ONE_FP / cl->inv_w;
261+
if (inv_w != cl->inv_w) {
262+
sch_tree_lock(sch);
263+
q->wsum += delta_w;
262264
cl->inv_w = inv_w;
265+
sch_tree_unlock(sch);
263266
}
264-
sch_tree_unlock(sch);
265-
266267
return 0;
267268
}
268269

@@ -277,7 +278,6 @@ static int qfq_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
277278
i = qfq_calc_index(cl->inv_w, cl->lmax);
278279

279280
cl->grp = &q->groups[i];
280-
q->wsum += weight;
281281

282282
cl->qdisc = qdisc_create_dflt(sch->dev_queue,
283283
&pfifo_qdisc_ops, classid);
@@ -294,6 +294,7 @@ static int qfq_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
294294
return err;
295295
}
296296
}
297+
q->wsum += weight;
297298

298299
sch_tree_lock(sch);
299300
qdisc_class_hash_insert(&q->clhash, &cl->common);

0 commit comments

Comments
 (0)