net/sched: taprio: enforce minimum value for picos_per_byte
Subsystems (4)
PATCH v2 1/1 net/sched: taprio: enforce minimum value for picos_per_byte
Syzbot reported a WARNING in taprio_get_start_time().
When link speed is 470,589 or greater, q->picos_per_byte becomes too small, causing length_to_duration(q, ETH_ZLEN) to return zero.
This zero value leads to validation failures in fill_sched_entry() and parse_taprio_schedule(), allowing arbitrary values to be assigned to entry->interval and cycle_time. As a result, sched->cycle can become zero.
Since SPEED_800000 is the largest defined speed in include/uapi/linux/ethtool.h, this issue can occur in realistic scenarios.
To ensure length_to_duration() returns a non-zero value for minimum-sized Ethernet frames (ETH_ZLEN = 60), picos_per_byte must be at least 17 (60 * 17 > PSEC_PER_NSEC which is 1000).
This patch enforces a minimum value of 17 for picos_per_byte when the calculated value would be lower, and adds a warning message to inform users that scheduling accuracy may be affected at very high link speeds.
---
Changes:
v2:
- Add warning for users to inform link speed is too high for scheduling.
- Correct fixes tag to indicate appropriate commit.
v1: https://lore.kernel.org/all/[email protected]/
net/sched/sch_taprio.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
net/sched/sch_taprio.c +11 -0
@@ -43,6 +43,12 @@ static struct static_key_false taprio_have_working_mqprio;#define TAPRIO_SUPPORTED_FLAGS \ (TCA_TAPRIO_ATTR_FLAG_TXTIME_ASSIST | TCA_TAPRIO_ATTR_FLAG_FULL_OFFLOAD)#define TAPRIO_FLAGS_INVALID U32_MAX +/* Minimum value for picos_per_byte to ensure non-zero duration +* for minimum-sized Ethernet frames (ETH_ZLEN = 60). +* 60 * 17 > PSEC_PER_NSEC (1000) +*/ +#define TAPRIO_PICOS_PER_BYTE_MIN 17 +struct sched_entry {/* Durations between this GCL entry and the GCL entry where the
@@ -1300,6 +1306,11 @@ static void taprio_set_picos_per_byte(struct net_device *dev, skip: picos_per_byte = (USEC_PER_SEC *8 ) / speed; +if (picos_per_byte <TAPRIO_PICOS_PER_BYTE_MIN ) { +pr_warn ("Link speed %d is too high. Schedule may be inaccurate.\n" , + speed); + picos_per_byte =TAPRIO_PICOS_PER_BYTE_MIN ; + }atomic64_set (&q->picos_per_byte, picos_per_byte); netdev_dbg(dev, "taprio: set %s's picos_per_byte to: %lld, linkspeed: %d\n",
Signature · 1 line
2.39.5 (Apple Git-154)
Jakub Kicinski
maintainernet/sched/sch_taprio.c static struct static_key_false taprio_have_working_mqprio; · line 51
Quoted 7 lines · On Sat, 26 Jul 2025 10:08:15 +0900 Takamitsu Iwai wrote:
#define
TAPRIO_FLAGS_INVALIDU32_MAXnet/sched/sch_taprio.c +6
-0+/* Minimum value for picos_per_byte to ensure non-zero duration +* for minimum-sized Ethernet frames (ETH_ZLEN = 60). +* 60 * 17 > PSEC_PER_NSEC (1000) +*/ +#define TAPRIO_PICOS_PER_BYTE_MIN 17 +
unnecessary new line
net/sched/sch_taprio.c static void taprio_set_picos_per_byte(struct net_device *dev, · line 1312
Quoted 10 lines
struct
sched_entry{net/sched/sch_taprio.c +4
-0/* Durations between this GCL entry and the GCL entry where the @@ -1300,6 +1306,11 @@ static void taprio_set_picos_per_byte(struct net_device *dev, skip: picos_per_byte = (USEC_PER_SEC *8 ) / speed; +if (picos_per_byte <TAPRIO_PICOS_PER_BYTE_MIN ) { +pr_warn ("Link speed %d is too high. Schedule may be inaccurate.\n" , + speed); + picos_per_byte =TAPRIO_PICOS_PER_BYTE_MIN ;
for the path coming in from taprio_change() you should use the extack to report the warning (if return value is 0 but extack was set CLIs will print that message as a warning directly to the user)
Signature · 1 line
pw-bot: cr
Quoted 6 lines · On 2025/07/27, 3:38, "Jakub Kicinski" <[email protected]…
Quoted 4 lines
struct sched_entry { /* Durations between this GCL entry and the GCL entry where the(quoted diff) +0
-0@@ -1300,6 +1306,11 @@ static void taprio_set_picos_per_byte(struct net_device *dev,
Quoted 10 lines
net/sched/sch_taprio.c static void taprio_set_picos_per_byte(struct net_device *dev, · line 1312
Quoted 6 lines
net/sched/sch_taprio.c +4
-0skip: picos_per_byte = (USEC_PER_SEC *8 ) / speed; +if (picos_per_byte <TAPRIO_PICOS_PER_BYTE_MIN ) { +pr_warn ("Link speed %d is too high. Schedule may be inaccurate.\n" , + speed); + picos_per_byte =TAPRIO_PICOS_PER_BYTE_MIN ;for the path coming in from
taprio_change()you should use the extack to report the warning (if return value is 0 but extack was set CLIs will print that message as a warning directly to the user)
Thank you for your review.
I decided to use pr_warn() only because taprio_set_picos_per_byte() is called from two different paths:
1. From taprio_change() where extack is available
2. From taprio_dev_notifier() where extack is not available
I plan to modify the patch to handle both cases by:
1. Adding an optional extack parameter to taprio_set_picos_per_byte()
2. Using NL_SET_ERR_MSG_FMT_MOD when extack is provided
3. Falling back to pr_warn() only when extack is NULL
I'll submit an updated version with these changes.
Thanks,
Takamitsu