Skip to content

Commit

Permalink
Merge branch 'Fix-issues-in-tc-taprio-and-tc-cbs'
Browse files Browse the repository at this point in the history
Vladimir Oltean says:

====================
Fix issues in tc-taprio and tc-cbs

This series fixes one panic and one WARN_ON found in the tc-taprio
qdisc, while trying to apply it:

- On an interface which is not multi-queue
- On an interface which has no carrier

The tc-cbs was also visually found to suffer of the same issue as
tc-taprio, and the fix was only compile-tested in that case.
====================

Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
davem330 committed Sep 1, 2019
2 parents 5f81d54 + 1c6c09a commit 154f4fb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
19 changes: 11 additions & 8 deletions net/sched/sch_cbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,6 @@ static struct sk_buff *cbs_dequeue_soft(struct Qdisc *sch)
s64 credits;
int len;

if (atomic64_read(&q->port_rate) == -1) {
WARN_ONCE(1, "cbs: dequeue() called with unknown port rate.");
return NULL;
}

if (q->credits < 0) {
credits = timediff_to_credits(now - q->last, q->idleslope);

Expand Down Expand Up @@ -303,11 +298,19 @@ static int cbs_enable_offload(struct net_device *dev, struct cbs_sched_data *q,
static void cbs_set_port_rate(struct net_device *dev, struct cbs_sched_data *q)
{
struct ethtool_link_ksettings ecmd;
int speed = SPEED_10;
int port_rate = -1;
int err;

err = __ethtool_get_link_ksettings(dev, &ecmd);
if (err < 0)
goto skip;

if (ecmd.base.speed != SPEED_UNKNOWN)
speed = ecmd.base.speed;

if (!__ethtool_get_link_ksettings(dev, &ecmd) &&
ecmd.base.speed != SPEED_UNKNOWN)
port_rate = ecmd.base.speed * 1000 * BYTES_PER_KBIT;
skip:
port_rate = speed * 1000 * BYTES_PER_KBIT;

atomic64_set(&q->port_rate, port_rate);
netdev_dbg(dev, "cbs: set %s's port_rate to: %lld, linkspeed: %d\n",
Expand Down
31 changes: 17 additions & 14 deletions net/sched/sch_taprio.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,6 @@ static struct sk_buff *taprio_dequeue(struct Qdisc *sch)
u32 gate_mask;
int i;

if (atomic64_read(&q->picos_per_byte) == -1) {
WARN_ONCE(1, "taprio: dequeue() called with unknown picos per byte.");
return NULL;
}

rcu_read_lock();
entry = rcu_dereference(q->current_entry);
/* if there's no entry, it means that the schedule didn't
Expand Down Expand Up @@ -958,12 +953,20 @@ static void taprio_set_picos_per_byte(struct net_device *dev,
struct taprio_sched *q)
{
struct ethtool_link_ksettings ecmd;
int picos_per_byte = -1;
int speed = SPEED_10;
int picos_per_byte;
int err;

if (!__ethtool_get_link_ksettings(dev, &ecmd) &&
ecmd.base.speed != SPEED_UNKNOWN)
picos_per_byte = div64_s64(NSEC_PER_SEC * 1000LL * 8,
ecmd.base.speed * 1000 * 1000);
err = __ethtool_get_link_ksettings(dev, &ecmd);
if (err < 0)
goto skip;

if (ecmd.base.speed != SPEED_UNKNOWN)
speed = ecmd.base.speed;

skip:
picos_per_byte = div64_s64(NSEC_PER_SEC * 1000LL * 8,
speed * 1000 * 1000);

atomic64_set(&q->picos_per_byte, picos_per_byte);
netdev_dbg(dev, "taprio: set %s's picos_per_byte to: %lld, linkspeed: %d\n",
Expand Down Expand Up @@ -1249,6 +1252,10 @@ static int taprio_init(struct Qdisc *sch, struct nlattr *opt,
*/
q->clockid = -1;

spin_lock(&taprio_list_lock);
list_add(&q->taprio_list, &taprio_list);
spin_unlock(&taprio_list_lock);

if (sch->parent != TC_H_ROOT)
return -EOPNOTSUPP;

Expand All @@ -1266,10 +1273,6 @@ static int taprio_init(struct Qdisc *sch, struct nlattr *opt,
if (!opt)
return -EINVAL;

spin_lock(&taprio_list_lock);
list_add(&q->taprio_list, &taprio_list);
spin_unlock(&taprio_list_lock);

for (i = 0; i < dev->num_tx_queues; i++) {
struct netdev_queue *dev_queue;
struct Qdisc *qdisc;
Expand Down

0 comments on commit 154f4fb

Please sign in to comment.