net: airoha: Fix skb->priority underflow in airoha_dev_select_queue()
Subsystems (4)
PATCH v3 1/1 net: airoha: Fix skb->priority underflow in airoha_dev_select_queue()
In airoha_dev_select_queue(), the expression:
queue = (skb->priority - 1) % AIROHA_NUM_QOS_QUEUES;
implicitly converts to unsigned arithmetic: when skb->priority is 0 (the default for unclassified traffic), (0u - 1u) wraps to UINT_MAX, and UINT_MAX % 8 = 7, routing default best-effort packets to the highest-priority QoS queue. This causes QoS inversion where the majority of traffic on a PON gateway starves actual high-priority flows (VoIP, gaming, etc.).
Fix by guarding the subtraction: when priority is 0, map to queue 0 (lowest priority), otherwise apply the original (priority - 1) % 8 mapping.
--- drivers/net/ethernet/airoha/airoha_eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/airoha/airoha_eth.c +1 -1
@@ -1933,7 +1933,7 @@ static u16 airoha_dev_select_queue(struct net_device *dev, struct sk_buff *skb,*/ channel =netdev_uses_dsa (dev) ?skb_get_queue_mapping (skb) : port->id; channel = channel %AIROHA_NUM_QOS_CHANNELS ; - queue = (skb->priority -1 ) %AIROHA_NUM_QOS_QUEUES ;/* QoS queue */ + queue = skb->priority ? (skb->priority -1 ) %AIROHA_NUM_QOS_QUEUES :0 ; queue = channel *AIROHA_NUM_QOS_QUEUES + queue;return queue < dev->num_tx_queues ? queue :0 ;
Signature · 1 line
2.51.0
Jakub Kicinski
maintainerQuoted 28 lines · On Sun, 14 Jun 2026 07:30:54 +0800 Wayen Yan wrote:
In
airoha_dev_select_queue(), the expression:queue = (skb->priority - 1) % AIROHA_NUM_QOS_QUEUES;implicitly converts to unsigned arithmetic: when
skb->priorityis 0 (the default for unclassified traffic), (0u - 1u) wraps toUINT_MAX, andUINT_MAX% 8 = 7, routing default best-effort packets to the highest-priority QoS queue. This causes QoS inversion where the majority of traffic on a PON gateway starves actual high-priority flows (VoIP, gaming, etc.).Fix by guarding the subtraction: when priority is 0, map to queue 0 (lowest priority), otherwise apply the original (priority - 1) % 8 mapping.
Fixes 2b288b81560b ("net: airoha: Introduce ndo_select_queue callback")Acked-by Lorenzo Bianconi <[email protected]>Reviewed-by Joe Damato <[email protected]>Signed-off-by Wayen Yan <[email protected]>--- drivers/net/ethernet/airoha/airoha_eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ethernet/airoha/airoha_eth.c +0
-0
drivers/net/ethernet/airoha/airoha_eth.c static u16 airoha_dev_select_queue(struct net_device *dev, struct sk_buff *skb, · line 1936
Quoted 5 lines
drivers/net/ethernet/airoha/airoha_eth.c +1
-1@@ -1933,7 +1933,7 @@ static u16 airoha_dev_select_queue(struct net_device *dev, struct sk_buff *skb,*/ channel =netdev_uses_dsa (dev) ?skb_get_queue_mapping (skb) : port->id; channel = channel %AIROHA_NUM_QOS_CHANNELS ; - queue = (skb->priority -1 ) %AIROHA_NUM_QOS_QUEUES ;/* QoS queue */ + queue = skb->priority ? (skb->priority -1 ) %AIROHA_NUM_QOS_QUEUES :0 ;
Hi Lorenzo, is there a reason we're subtracting 1 here in the first place? Could be just me, but may be worth adding a comment here.
Intuitively if we are "narrowing" 16 prios to 8 queues it'd make most sense to group the adjacent ones -- divide by two.
Please respin with some sort of an explanation..
Quoted 3 lines
drivers/net/ethernet/airoha/airoha_eth.c +0
-0queue = channel *AIROHA_NUM_QOS_QUEUES + queue;return queue < dev->num_tx_queues ? queue :0 ;
Signature · 1 line
pw-bot: cr
Quoted 38 lines · On Sun, 14 Jun 2026 07:30:54 +0800 Wayen Yan wrote:
Quoted 28 lines
In
airoha_dev_select_queue(), the expression:queue = (skb->priority - 1) % AIROHA_NUM_QOS_QUEUES;implicitly converts to unsigned arithmetic: when
skb->priorityis 0 (the default for unclassified traffic), (0u - 1u) wraps toUINT_MAX, andUINT_MAX% 8 = 7, routing default best-effort packets to the highest-priority QoS queue. This causes QoS inversion where the majority of traffic on a PON gateway starves actual high-priority flows (VoIP, gaming, etc.).Fix by guarding the subtraction: when priority is 0, map to queue 0 (lowest priority), otherwise apply the original (priority - 1) % 8 mapping.
Fixes 2b288b81560b ("net: airoha: Introduce ndo_select_queue callback")Acked-by Lorenzo Bianconi <[email protected]>Reviewed-by Joe Damato <[email protected]>Signed-off-by Wayen Yan <[email protected]>--- drivers/net/ethernet/airoha/airoha_eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ethernet/airoha/airoha_eth.c +0
-0drivers/net/ethernet/airoha/airoha_eth.c static u16 airoha_dev_select_queue(struct net_device *dev, struct sk_buff *skb, · line 1936
Quoted 5 lines
drivers/net/ethernet/airoha/airoha_eth.c +1
-1@@ -1933,7 +1933,7 @@ static u16 airoha_dev_select_queue(struct net_device *dev, struct sk_buff *skb,*/ channel =netdev_uses_dsa (dev) ?skb_get_queue_mapping (skb) : port->id; channel = channel %AIROHA_NUM_QOS_CHANNELS ; - queue = (skb->priority -1 ) %AIROHA_NUM_QOS_QUEUES ;/* QoS queue */ + queue = skb->priority ? (skb->priority -1 ) %AIROHA_NUM_QOS_QUEUES :0 ;Hi Lorenzo, is there a reason we're subtracting 1 here in the first place? Could be just me, but may be worth adding a comment here.
Quoted 4 lines
Intuitively if we are "narrowing" 16 prios to 8 queues it'd make most sense to group the adjacent ones -- divide by two.
Please respin with some sort of an explanation..
IIRC this is a leftover of the ETS offload support. I agree it is righ to just do:
queue = skb->priority % AIROHA_NUM_QOS_QUEUES; /* QoS queue */
@Wayen: can you please respin fixing the issue? Please add even my Acked-by:
Regards,
Lorenzo
Quoted 6 lines
Quoted 4 lines
drivers/net/ethernet/airoha/airoha_eth.c +0
-0queue = channel *AIROHA_NUM_QOS_QUEUES + queue;return queue < dev->num_tx_queues ? queue :0 ;Signature · 1 line
pw-bot: cr
Quoted 4 lines · Jakub Kicinski
Hi Lorenzo, is there a reason we're subtracting 1 here in the first place? Could be just me, but may be worth adding a comment here.
Please respin with some sort of an explanation..
Hi Jakub,
The (priority - 1) mapping predates my involvement — I only addressed the underflow bug when skb->priority is 0, where the unsigned subtraction wraps and routes best-effort packets to the highest-priority queue.
Lorenzo, could you clarify the intended priority-to-queue mapping so I can add a proper comment in the respin?
Regards,
Wayen