History

net/sched: pass netlink extack to mqprio and taprio offload

With the multiplexed ndo_setup_tc() model which lacks a first-class struct netlink_ext_ack * argument, the only way to pass the netlink extended ACK message down to the device driver is to embed it within the offload structure. Do this for struct tc_mqprio_qopt_offload and struct tc_taprio_qopt_offload. Since struct tc_taprio_qopt_offload also contains a tc_mqprio_qopt_offload structure, and since device drivers might effectively reuse their mqprio implementation for the mqprio portion of taprio, we make taprio set the extack in both offload structures to point at the same netlink extack message. In fact, the taprio handling is a bit more tricky, for 2 reasons. First is because the offload structure has a longer lifetime than the extack structure. The driver is supposed to populate the extack synchronously from ndo_setup_tc() and leave it alone afterwards. To not have any use-after-free surprises, we zero out the extack pointer when we leave taprio_enable_offload(). The second reason is because taprio does overwrite the extack message on ndo_setup_tc() error. We need to switch to the weak form of setting an extack message, which preserves a potential message set by the driver.

Vladimir Oltean committed 3 years ago

Commit c54876c1 parent ab277d23 files · +16 −3Browse files

Unified · Split

3 files
  1. include/net/pkt_sched.h +2 −0
  2. net/sched/sch_mqprio.c +4 −1
  3. net/sched/sch_taprio.c +10 −2
include/net/pkt_sched.h+2−0
@@ -166,6 +166,7 @@ struct tc_mqprio_caps { · 165 unmodified lines
166struct tc_mqprio_qopt_offload {166struct tc_mqprio_qopt_offload {
167 /* struct tc_mqprio_qopt must always be the first element */167 /* struct tc_mqprio_qopt must always be the first element */
168 struct tc_mqprio_qopt qopt;168 struct tc_mqprio_qopt qopt;
169 struct netlink_ext_ack *extack;
169 u16 mode;170 u16 mode;
170 u16 shaper;171 u16 shaper;
171 u32 flags;172 u32 flags;
@@ -193,6 +194,7 @@ struct tc_taprio_sched_entry { · 21 unmodified lines
193 194
194struct tc_taprio_qopt_offload {195struct tc_taprio_qopt_offload {
195 struct tc_mqprio_qopt_offload mqprio;196 struct tc_mqprio_qopt_offload mqprio;
197 struct netlink_ext_ack *extack;
196 u8 enable;198 u8 enable;
197 ktime_t base_time;199 ktime_t base_time;
198 u64 cycle_time;200 u64 cycle_time;
net/sched/sch_mqprio.c+4−1
@@ -33,9 +33,12 @@ static int mqprio_enable_offload(struct Qdisc *sch, · 32 unmodified lines
33 const struct tc_mqprio_qopt *qopt,33 const struct tc_mqprio_qopt *qopt,
34 struct netlink_ext_ack *extack)34 struct netlink_ext_ack *extack)
35{35{
36 struct tc_mqprio_qopt_offload mqprio = {.qopt = *qopt};
37 struct mqprio_sched *priv = qdisc_priv(sch);36 struct mqprio_sched *priv = qdisc_priv(sch);
38 struct net_device *dev = qdisc_dev(sch);37 struct net_device *dev = qdisc_dev(sch);
38 struct tc_mqprio_qopt_offload mqprio = {
39 .qopt = *qopt,
40 .extack = extack,
41 };
39 int err, i;42 int err, i;
40 43
41 switch (priv->mode) {44 switch (priv->mode) {
net/sched/sch_taprio.c+10−2
@@ -1520,7 +1520,9 @@ static int taprio_enable_offload(struct net_device *dev, · 1519 unmodified lines
1520 return -ENOMEM;1520 return -ENOMEM;
1521 }1521 }
1522 offload->enable = 1;1522 offload->enable = 1;
1523 offload->extack = extack;
1523 mqprio_qopt_reconstruct(dev, &offload->mqprio.qopt);1524 mqprio_qopt_reconstruct(dev, &offload->mqprio.qopt);
1525 offload->mqprio.extack = extack;
1524 taprio_sched_to_offload(dev, sched, offload, &caps);1526 taprio_sched_to_offload(dev, sched, offload, &caps);
1525 1527
1526 for (tc = 0; tc < TC_MAX_QUEUE; tc++)1528 for (tc = 0; tc < TC_MAX_QUEUE; tc++)
@@ -1528,14 +1530,20 @@ static int taprio_enable_offload(struct net_device *dev, · 1 unmodified line
1528 1530
1529 err = ops->ndo_setup_tc(dev, TC_SETUP_QDISC_TAPRIO, offload);1531 err = ops->ndo_setup_tc(dev, TC_SETUP_QDISC_TAPRIO, offload);
1530 if (err < 0) {1532 if (err < 0) {
1531 NL_SET_ERR_MSG(extack,1533 NL_SET_ERR_MSG_WEAK(extack,
1532 "Device failed to setup taprio offload");1534 "Device failed to setup taprio offload");
1533 goto done;1535 goto done;
1534 }1536 }
1535 1537
1536 q->offloaded = true;1538 q->offloaded = true;
1537 1539
1538done:1540done:
1541 /* The offload structure may linger around via a reference taken by the
1542 * device driver, so clear up the netlink extack pointer so that the
1543 * driver isn't tempted to dereference data which stopped being valid
1544 */
1545 offload->extack = NULL;
1546 offload->mqprio.extack = NULL;
1539 taprio_offload_free(offload);1547 taprio_offload_free(offload);
1540 1548
1541 return err;1549 return err;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t