Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next v3 0/3] net: qualcomm: rmnet: fix TX aggregation bugs
@ 2026-11-30 22:01 Antonio Quartulli
  2026-11-30 22:01 ` [PATCH net-next v3 1/3] net: qualcomm: rmnet: recheck the aggregate after flushing it Antonio Quartulli
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Antonio Quartulli @ 2026-11-30 22:01 UTC (permalink / raw)
  To: netdev
  Cc: Subash Abhinov Kasiviswanathan, Sean Tranchetti, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Daniele Palmas, Koen Vandeputte, Jérémy Jean,
	Antonio Quartulli

Fixes for rmnet TX aggregation bugs still present in net-next. Each
commit message includes a reproducer; all three were reproduced in a VM
(KASAN, kmemleak, DEBUG_OBJECTS) before the fix and are gone after it.
Patch 2 needs a debug udelay() to widen the race window, patch 3 a
32-bit kernel. The bugs were found while reviewing [1] and reproduced
with AI assistance.

Patches 1 and 2 build on 7bcccc40cdb5 ("net: qualcomm: rmnet: bound TX
aggregates on byte-limit update"), which touches the same lines.

Changes in v3:
- patch 1: refresh the timestamps on retry and flush at most once per
  skb (Sashiko)

Changes in v2:
- drop patches 4-6, already fixed in net-next by 0af0e210b5bd and
  4f89bcfa1e16
- rebase on net-next, retarget to net-next like the related fixes

[1] https://lore.kernel.org/netdev/20261002143529.3217189-1-koen.vandeputte@citymesh.com/

v2: https://lore.kernel.org/netdev/20261127150827.785753-1-antonio@mandelbit.com/
v1: https://lore.kernel.org/netdev/20261126163219.1744750-1-antonio@mandelbit.com/

Antonio Quartulli (3):
  net: qualcomm: rmnet: recheck the aggregate after flushing it
  net: qualcomm: rmnet: always arm the flush timer for a new aggregate
  net: qualcomm: rmnet: fix TX aggregation timeout overflow on 32-bit

 .../ethernet/qualcomm/rmnet/rmnet_map_data.c  | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)


base-commit: 02e8a63b4685a4321c60d562edabecc097f4a0d9
-- 
2.56.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net-next v3 1/3] net: qualcomm: rmnet: recheck the aggregate after flushing it
  2026-11-30 22:01 [PATCH net-next v3 0/3] net: qualcomm: rmnet: fix TX aggregation bugs Antonio Quartulli
@ 2026-11-30 22:01 ` Antonio Quartulli
  2026-11-30 22:01 ` [PATCH net-next v3 2/3] net: qualcomm: rmnet: always arm the flush timer for a new aggregate Antonio Quartulli
  2026-11-30 22:02 ` [PATCH net-next v3 3/3] net: qualcomm: rmnet: fix TX aggregation timeout overflow on 32-bit Antonio Quartulli
  2 siblings, 0 replies; 4+ messages in thread
From: Antonio Quartulli @ 2026-11-30 22:01 UTC (permalink / raw)
  To: netdev
  Cc: Subash Abhinov Kasiviswanathan, Sean Tranchetti, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Daniele Palmas, Koen Vandeputte, Jérémy Jean,
	Antonio Quartulli

When an skb does not fit in the pending aggregate,
rmnet_map_tx_aggregate() flushes it with agg_lock dropped, then jumps
back past the skbagg_head check. rmnet vnds are lltx and can share a
port, so another CPU may start an aggregate meanwhile: it is then
overwritten and leaked along with the packets chained to it.

Reproducer, with UDP sent through both vnds from several CPUs:

  ip link add v0 mtu 9000 type veth peer name v1 mtu 9000
  ip link set v0 up; ip link set v1 up
  ip link add link v0 name rmnet1 type rmnet mux_id 1
  ip link add link v0 name rmnet2 type rmnet mux_id 2
  ethtool -C rmnet1 tx-aggr-max-frames 64 tx-aggr-max-bytes 4096 \
          tx-aggr-time-usecs 2000

The sum of the tx_bytes of rmnet1 and rmnet2 stays above that of v0
after the flush timeout, and kmemleak reports skbs allocated by
skb_copy_expand() in rmnet_map_tx_aggregate().

Move the label before the skbagg_head check, and before the timestamps
are taken, so that an aggregate found on retry is not aged against a
stale agg_last and flushed early. Flush at most once per skb: if it
still does not fit the aggregate found on retry, send it without
aggregation (or drop it if it exceeds the byte limit) rather than
flushing again, which could otherwise repeat for as long as other CPUs
keep starting aggregates. A retried skb no longer qualifies for the
sparse-traffic bypass, as an aggregate was just sent.

Fixes: 64b5d1f8f2d1 ("net: qualcomm: rmnet: add tx packets aggregation")
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
 drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
index 7ee2bc33433f..f02ea5d728d0 100644
--- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
+++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
@@ -591,9 +591,11 @@ unsigned int rmnet_map_tx_aggregate(struct sk_buff *skb, struct rmnet_port *port
 	struct timespec64 diff, last;
 	unsigned int len = skb->len;
 	struct sk_buff *agg_skb;
+	bool flushed = false;
 	unsigned int size;
 
 	spin_lock_bh(&port->agg_lock);
+new_packet:
 	memcpy(&last, &port->agg_last, sizeof(struct timespec64));
 	ktime_get_real_ts64(&port->agg_last);
 
@@ -601,7 +603,6 @@ unsigned int rmnet_map_tx_aggregate(struct sk_buff *skb, struct rmnet_port *port
 		/* Check to see if we should agg first. If the traffic is very
 		 * sparse, don't aggregate.
 		 */
-new_packet:
 		diff = timespec64_sub(port->agg_last, last);
 		size = port->egress_agg_params.bytes;
 
@@ -630,12 +631,20 @@ unsigned int rmnet_map_tx_aggregate(struct sk_buff *skb, struct rmnet_port *port
 	diff = timespec64_sub(port->agg_last, port->agg_time);
 	if (port->skbagg_head->len >= port->egress_agg_params.bytes ||
 	    skb->len > port->egress_agg_params.bytes - port->skbagg_head->len) {
+		if (flushed) {
+			if (skb->len > port->egress_agg_params.bytes) {
+				spin_unlock_bh(&port->agg_lock);
+				return 0;
+			}
+			goto no_aggr;
+		}
 		agg_skb = port->skbagg_head;
 		reset_aggr_params(port);
 		spin_unlock_bh(&port->agg_lock);
 		hrtimer_cancel(&port->hrtimer);
 		rmnet_send_skb(port, agg_skb);
 		spin_lock_bh(&port->agg_lock);
+		flushed = true;
 		goto new_packet;
 	}
 
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH net-next v3 2/3] net: qualcomm: rmnet: always arm the flush timer for a new aggregate
  2026-11-30 22:01 [PATCH net-next v3 0/3] net: qualcomm: rmnet: fix TX aggregation bugs Antonio Quartulli
  2026-11-30 22:01 ` [PATCH net-next v3 1/3] net: qualcomm: rmnet: recheck the aggregate after flushing it Antonio Quartulli
@ 2026-11-30 22:01 ` Antonio Quartulli
  2026-11-30 22:02 ` [PATCH net-next v3 3/3] net: qualcomm: rmnet: fix TX aggregation timeout overflow on 32-bit Antonio Quartulli
  2 siblings, 0 replies; 4+ messages in thread
From: Antonio Quartulli @ 2026-11-30 22:01 UTC (permalink / raw)
  To: netdev
  Cc: Subash Abhinov Kasiviswanathan, Sean Tranchetti, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Daniele Palmas, Koen Vandeputte, Jérémy Jean,
	Antonio Quartulli

On flush, rmnet_map_tx_aggregate() resets agg_state and drops agg_lock
before cancelling the flush timer. A CPU starting a new aggregate in
that window finds the old timer active, so it neither arms it nor sets
agg_state. Once the old timer is cancelled, the new aggregate waits for
the next packet; if the port is torn down first,
rmnet_map_tx_aggregate_exit() leaks it because agg_state is not
-EINPROGRESS.

To make reproducing this bug easier, a udelay(2000) was added
after agg_lock is dropped in the flush paths. Then, with two vnds on one
port, tx-aggr-max-frames 2 and tx-aggr-time-usecs 100000, one CPU sends
3 packets on the first vnd (bypass, new aggregate, flush) and another
sends 1 packet on the second vnd 0.5 ms later: that packet stays queued
past the timeout.

Cancel the timer under agg_lock, so a timer armed for a newer aggregate
cannot be cancelled, and arm it whenever agg_state is not -EINPROGRESS;
hrtimer_start() copes with a timer that is still enqueued or running.
If the cancel races with a running callback, the flush work it queued
finds either no aggregate or the new one, which it flushes early.

Fixes: 64b5d1f8f2d1 ("net: qualcomm: rmnet: add tx packets aggregation")
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
 drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
index f02ea5d728d0..f862166b0467 100644
--- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
+++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
@@ -640,8 +640,8 @@ unsigned int rmnet_map_tx_aggregate(struct sk_buff *skb, struct rmnet_port *port
 		}
 		agg_skb = port->skbagg_head;
 		reset_aggr_params(port);
+		hrtimer_try_to_cancel(&port->hrtimer);
 		spin_unlock_bh(&port->agg_lock);
-		hrtimer_cancel(&port->hrtimer);
 		rmnet_send_skb(port, agg_skb);
 		spin_lock_bh(&port->agg_lock);
 		flushed = true;
@@ -664,14 +664,14 @@ unsigned int rmnet_map_tx_aggregate(struct sk_buff *skb, struct rmnet_port *port
 	    port->skbagg_head->len == port->egress_agg_params.bytes) {
 		agg_skb = port->skbagg_head;
 		reset_aggr_params(port);
+		hrtimer_try_to_cancel(&port->hrtimer);
 		spin_unlock_bh(&port->agg_lock);
-		hrtimer_cancel(&port->hrtimer);
 		rmnet_send_skb(port, agg_skb);
 		return len;
 	}
 
 schedule:
-	if (!hrtimer_active(&port->hrtimer) && port->agg_state != -EINPROGRESS) {
+	if (port->agg_state != -EINPROGRESS) {
 		port->agg_state = -EINPROGRESS;
 		hrtimer_start(&port->hrtimer,
 			      ns_to_ktime(port->egress_agg_params.time_nsec),
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH net-next v3 3/3] net: qualcomm: rmnet: fix TX aggregation timeout overflow on 32-bit
  2026-11-30 22:01 [PATCH net-next v3 0/3] net: qualcomm: rmnet: fix TX aggregation bugs Antonio Quartulli
  2026-11-30 22:01 ` [PATCH net-next v3 1/3] net: qualcomm: rmnet: recheck the aggregate after flushing it Antonio Quartulli
  2026-11-30 22:01 ` [PATCH net-next v3 2/3] net: qualcomm: rmnet: always arm the flush timer for a new aggregate Antonio Quartulli
@ 2026-11-30 22:02 ` Antonio Quartulli
  2 siblings, 0 replies; 4+ messages in thread
From: Antonio Quartulli @ 2026-11-30 22:02 UTC (permalink / raw)
  To: netdev
  Cc: Subash Abhinov Kasiviswanathan, Sean Tranchetti, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Daniele Palmas, Koen Vandeputte, Jérémy Jean,
	Antonio Quartulli

On 32-bit, time * NSEC_PER_USEC is computed in 32 bits before being
stored in the u64 time_nsec, so a tx-aggr-time-usecs above 4294967
wraps: 5000000 is stored as 705032704 ns and read back as 705032.

Reproducer:

  ethtool -C rmnet0 tx-aggr-max-frames 64 tx-aggr-time-usecs 5000000
  ethtool -c rmnet0

Do the multiplication in 64 bits.

Fixes: 64b5d1f8f2d1 ("net: qualcomm: rmnet: add tx packets aggregation")
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
 drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
index f862166b0467..e4867e5829c0 100644
--- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
+++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
@@ -695,7 +695,7 @@ void rmnet_map_update_ul_agg_config(struct rmnet_port *port, u32 size,
 	spin_lock_bh(&port->agg_lock);
 	port->egress_agg_params.bytes = size;
 	WRITE_ONCE(port->egress_agg_params.count, count);
-	port->egress_agg_params.time_nsec = time * NSEC_PER_USEC;
+	port->egress_agg_params.time_nsec = (u64)time * NSEC_PER_USEC;
 	spin_unlock_bh(&port->agg_lock);
 }
 
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-30 22:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 22:01 [PATCH net-next v3 0/3] net: qualcomm: rmnet: fix TX aggregation bugs Antonio Quartulli
2026-11-30 22:01 ` [PATCH net-next v3 1/3] net: qualcomm: rmnet: recheck the aggregate after flushing it Antonio Quartulli
2026-11-30 22:01 ` [PATCH net-next v3 2/3] net: qualcomm: rmnet: always arm the flush timer for a new aggregate Antonio Quartulli
2026-11-30 22:02 ` [PATCH net-next v3 3/3] net: qualcomm: rmnet: fix TX aggregation timeout overflow on 32-bit Antonio Quartulli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox