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
166166 struct tc_mqprio_qopt_offload {
167167 /* struct tc_mqprio_qopt must always be the first element */
168168 struct tc_mqprio_qopt qopt;
169+ struct netlink_ext_ack *extack;
169170 u16 mode;
170171 u16 shaper;
171172 u32 flags;
@@ -193,6 +194,7 @@ struct tc_taprio_sched_entry { · 21 unmodified lines
193194
194195 struct tc_taprio_qopt_offload {
195196 struct tc_mqprio_qopt_offload mqprio;
197+ struct netlink_ext_ack *extack;
196198 u8 enable;
197199 ktime_t base_time;
198200 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
3333 const struct tc_mqprio_qopt *qopt,
3434 struct netlink_ext_ack *extack)
3535 {
36− struct tc_mqprio_qopt_offload mqprio = {.qopt = *qopt};
3736 struct mqprio_sched *priv = qdisc_priv(sch);
3837 struct net_device *dev = qdisc_dev(sch);
38+ struct tc_mqprio_qopt_offload mqprio = {
39+ .qopt = *qopt,
40+ .extack = extack,
41+ };
3942 int err, i;
4043
4144 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
15201520 return -ENOMEM;
15211521 }
15221522 offload->enable = 1;
1523+ offload->extack = extack;
15231524 mqprio_qopt_reconstruct(dev, &offload->mqprio.qopt);
1525+ offload->mqprio.extack = extack;
15241526 taprio_sched_to_offload(dev, sched, offload, &caps);
15251527
15261528 for (tc = 0; tc < TC_MAX_QUEUE; tc++)
@@ -1528,14 +1530,20 @@ static int taprio_enable_offload(struct net_device *dev, · 1 unmodified line
15281530
15291531 err = ops->ndo_setup_tc(dev, TC_SETUP_QDISC_TAPRIO, offload);
15301532 if (err < 0) {
1531− NL_SET_ERR_MSG(extack,
1532− "Device failed to setup taprio offload");
1533+ NL_SET_ERR_MSG_WEAK(extack,
1534+ "Device failed to setup taprio offload");
15331535 goto done;
15341536 }
15351537
15361538 q->offloaded = true;
15371539
15381540 done:
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;
15391547 taprio_offload_free(offload);
15401548
15411549 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