* [PATCH net-next v2 0/2] ipvlan/macvlan: fix local RX byte accounting
@ 2026-11-12 2:56 Xia Yan
2026-11-12 2:56 ` [PATCH net-next v2 1/2] ipvlan: fix RX byte accounting for local traffic Xia Yan
2026-11-12 2:56 ` [PATCH net-next v2 2/2] macvlan: fix RX byte accounting for local broadcast and multicast Xia Yan
0 siblings, 2 replies; 6+ messages in thread
From: Xia Yan @ 2026-11-12 2:56 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, maheshb, arnd,
kaber, dskr99, linux-kernel, yana06070
Both ipvlan and macvlan count the Ethernet header twice for some
traffic between virtual devices sharing one lower device.
Patch 1 fixes ipvlan local unicast, broadcast and multicast RX
accounting. Patch 2 fixes macvlan bridge-mode local broadcast and
multicast RX accounting. The lower-device receive paths retain
their existing Ethernet-header adjustment.
Tested in UML on net-next 368fbf5d82da with IPv4 and IPv6 UDP
traffic: 26 ipvlan cases and 20 macvlan cases. The corrected byte
counts match the received Ethernet frame lengths. The external
RX cases and macvlan local unicast cases retain their counts.
The ipvlan fix was first submitted to net. This v2 targets net-next
and adds the macvlan fix as Eric suggested. Cc: stable is dropped.
Changes since v1:
- Target net-next and drop Cc: stable.
- Add the macvlan local broadcast and multicast accounting fix.
v1: https://lore.kernel.org/netdev/20261025014251.542973-1-yanxia@cmss.chinamobile.com/
Review: https://lore.kernel.org/netdev/CAL4WiioxAR1ZBjVJNgYfLM0hUwyHapRu+TAUzedpOpe0yheH3w@mail.gmail.com/
Xia Yan (2):
ipvlan: fix RX byte accounting for local traffic
macvlan: fix RX byte accounting for local broadcast and multicast
drivers/net/ipvlan/ipvlan_core.c | 4 ++--
drivers/net/macvlan.c | 3 ++-
2 files changed, 4 insertions(+), 3 deletions(-)
base-commit: 368fbf5d82da9ebce309449c74fc0b128f7d0219
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net-next v2 1/2] ipvlan: fix RX byte accounting for local traffic
2026-11-12 2:56 [PATCH net-next v2 0/2] ipvlan/macvlan: fix local RX byte accounting Xia Yan
@ 2026-11-12 2:56 ` Xia Yan
2026-11-18 17:43 ` Simon Horman
2026-11-12 2:56 ` [PATCH net-next v2 2/2] macvlan: fix RX byte accounting for local broadcast and multicast Xia Yan
1 sibling, 1 reply; 6+ messages in thread
From: Xia Yan @ 2026-11-12 2:56 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, maheshb, arnd,
kaber, dskr99, linux-kernel, yana06070
For traffic between ipvlan devices on the same lower device,
skb->len already includes the Ethernet header. Adding ETH_HLEN
again in ipvlan_rcv_frame() overcounts rx_bytes by 14 bytes per
packet. ipvlan_process_multicast() does the same for local broadcast
and multicast traffic.
Packets received from the lower device have had the Ethernet header
pulled by eth_type_trans(), so their counters still need ETH_HLEN.
Use the existing local and tx_pkt flags to distinguish these paths.
Found during a code review of the ipvlan receive paths.
Sending five IPv4 UDP packets with 32-byte payloads between ipvlan
devices in separate network namespaces increases rx_bytes by 440
instead of 370. With this change the count is 370. External RX byte
counts are unchanged in the same tests.
Tested before and after the change with custom IPv4 and IPv6 UDP
tests in UML, covering L2 unicast, broadcast and joined multicast,
and L3 unicast.
Fixes: 2ad7bf363841 ("ipvlan: Initial check-in of the IPVLAN driver.")
Signed-off-by: Xia Yan <yanxia@cmss.chinamobile.com>
---
drivers/net/ipvlan/ipvlan_core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ipvlan/ipvlan_core.c b/drivers/net/ipvlan/ipvlan_core.c
index 7ad12dc78..ba646293a 100644
--- a/drivers/net/ipvlan/ipvlan_core.c
+++ b/drivers/net/ipvlan/ipvlan_core.c
@@ -276,7 +276,7 @@ void ipvlan_process_multicast(struct work_struct *work)
if (!(ipvlan->dev->flags & IFF_UP))
continue;
ret = NET_RX_DROP;
- len = skb->len + ETH_HLEN;
+ len = skb->len + (tx_pkt ? 0 : ETH_HLEN);
nskb = skb_clone(skb, GFP_ATOMIC);
local_bh_disable();
if (nskb) {
@@ -331,7 +331,7 @@ static int ipvlan_rcv_frame(struct ipvl_addr *addr, struct sk_buff **pskb,
bool success = false;
struct sk_buff *skb = *pskb;
- len = skb->len + ETH_HLEN;
+ len = skb->len + (local ? 0 : ETH_HLEN);
/* Only packets exchanged between two local slaves need to have
* device-up check as well as skb-share check.
*/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net-next v2 2/2] macvlan: fix RX byte accounting for local broadcast and multicast
2026-11-12 2:56 [PATCH net-next v2 0/2] ipvlan/macvlan: fix local RX byte accounting Xia Yan
2026-11-12 2:56 ` [PATCH net-next v2 1/2] ipvlan: fix RX byte accounting for local traffic Xia Yan
@ 2026-11-12 2:56 ` Xia Yan
2026-11-18 17:43 ` Simon Horman
2026-11-18 17:48 ` Arnd Bergmann
1 sibling, 2 replies; 6+ messages in thread
From: Xia Yan @ 2026-11-12 2:56 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, maheshb, arnd,
kaber, dskr99, linux-kernel, yana06070
In bridge mode, broadcast and multicast packets sent by one macvlan
are delivered to the other bridge ports by macvlan_broadcast(),
called from macvlan_queue_xmit(). The skb still contains its
Ethernet header there, so adding ETH_HLEN again in the rx_bytes
accounting overcounts by 14 bytes per packet on every receiving
macvlan.
Packets flooded from the receive handler have had the Ethernet
header pulled by eth_type_trans(), so they still need ETH_HLEN.
Use the existing mode argument to skip the extra ETH_HLEN for the
local bridge-mode path.
Noticed in macvlan during review of the ipvlan fix, and confirmed
on a 6.6 distribution kernel: five IPv4 UDP packets with 32-byte
payloads increased rx_bytes by 440 instead of 370.
Tested before and after the change with custom IPv4 and IPv6 UDP
tests in UML. The corrected counters match the received Ethernet
frame lengths. Local unicast and external RX counts are unchanged
in these tests.
Fixes: 618e1b7482f7 ("macvlan: implement bridge, VEPA and private mode")
Signed-off-by: Xia Yan <yanxia@cmss.chinamobile.com>
---
drivers/net/macvlan.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index 4f8416bb5..96ec9bafa 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -290,7 +290,8 @@ static void macvlan_broadcast(struct sk_buff *skb,
err = macvlan_broadcast_one(nskb, vlan, eth,
mode == MACVLAN_MODE_BRIDGE) ?:
netif_rx(nskb);
- macvlan_count_rx(vlan, skb->len + ETH_HLEN,
+ macvlan_count_rx(vlan, skb->len +
+ (mode == MACVLAN_MODE_BRIDGE ? 0 : ETH_HLEN),
err == NET_RX_SUCCESS, true);
}
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v2 1/2] ipvlan: fix RX byte accounting for local traffic
2026-11-12 2:56 ` [PATCH net-next v2 1/2] ipvlan: fix RX byte accounting for local traffic Xia Yan
@ 2026-11-18 17:43 ` Simon Horman
0 siblings, 0 replies; 6+ messages in thread
From: Simon Horman @ 2026-11-18 17:43 UTC (permalink / raw)
To: Xia Yan
Cc: netdev, andrew+netdev, davem, edumazet, kuba, pabeni, maheshb,
arnd, kaber, dskr99, linux-kernel, yana06070
On Thu, Nov 12, 2026 at 10:56:18AM +0800, Xia Yan wrote:
> For traffic between ipvlan devices on the same lower device,
> skb->len already includes the Ethernet header. Adding ETH_HLEN
> again in ipvlan_rcv_frame() overcounts rx_bytes by 14 bytes per
> packet. ipvlan_process_multicast() does the same for local broadcast
> and multicast traffic.
>
> Packets received from the lower device have had the Ethernet header
> pulled by eth_type_trans(), so their counters still need ETH_HLEN.
>
> Use the existing local and tx_pkt flags to distinguish these paths.
>
> Found during a code review of the ipvlan receive paths.
>
> Sending five IPv4 UDP packets with 32-byte payloads between ipvlan
> devices in separate network namespaces increases rx_bytes by 440
> instead of 370. With this change the count is 370. External RX byte
> counts are unchanged in the same tests.
>
> Tested before and after the change with custom IPv4 and IPv6 UDP
> tests in UML, covering L2 unicast, broadcast and joined multicast,
> and L3 unicast.
>
> Fixes: 2ad7bf363841 ("ipvlan: Initial check-in of the IPVLAN driver.")
> Signed-off-by: Xia Yan <yanxia@cmss.chinamobile.com>
I agree that net-next is an appropriate target for this change.
Reviewed-by: Simon Horman <horms@kernel.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v2 2/2] macvlan: fix RX byte accounting for local broadcast and multicast
2026-11-12 2:56 ` [PATCH net-next v2 2/2] macvlan: fix RX byte accounting for local broadcast and multicast Xia Yan
@ 2026-11-18 17:43 ` Simon Horman
2026-11-18 17:48 ` Arnd Bergmann
1 sibling, 0 replies; 6+ messages in thread
From: Simon Horman @ 2026-11-18 17:43 UTC (permalink / raw)
To: Xia Yan
Cc: netdev, andrew+netdev, davem, edumazet, kuba, pabeni, maheshb,
arnd, kaber, dskr99, linux-kernel, yana06070
On Thu, Nov 12, 2026 at 10:56:19AM +0800, Xia Yan wrote:
> In bridge mode, broadcast and multicast packets sent by one macvlan
> are delivered to the other bridge ports by macvlan_broadcast(),
> called from macvlan_queue_xmit(). The skb still contains its
> Ethernet header there, so adding ETH_HLEN again in the rx_bytes
> accounting overcounts by 14 bytes per packet on every receiving
> macvlan.
>
> Packets flooded from the receive handler have had the Ethernet
> header pulled by eth_type_trans(), so they still need ETH_HLEN.
>
> Use the existing mode argument to skip the extra ETH_HLEN for the
> local bridge-mode path.
>
> Noticed in macvlan during review of the ipvlan fix, and confirmed
> on a 6.6 distribution kernel: five IPv4 UDP packets with 32-byte
> payloads increased rx_bytes by 440 instead of 370.
>
> Tested before and after the change with custom IPv4 and IPv6 UDP
> tests in UML. The corrected counters match the received Ethernet
> frame lengths. Local unicast and external RX counts are unchanged
> in these tests.
>
> Fixes: 618e1b7482f7 ("macvlan: implement bridge, VEPA and private mode")
> Signed-off-by: Xia Yan <yanxia@cmss.chinamobile.com>
I agree that net-next is an appropriate target for this change.
Reviewed-by: Simon Horman <horms@kernel.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v2 2/2] macvlan: fix RX byte accounting for local broadcast and multicast
2026-11-12 2:56 ` [PATCH net-next v2 2/2] macvlan: fix RX byte accounting for local broadcast and multicast Xia Yan
2026-11-18 17:43 ` Simon Horman
@ 2026-11-18 17:48 ` Arnd Bergmann
1 sibling, 0 replies; 6+ messages in thread
From: Arnd Bergmann @ 2026-11-18 17:48 UTC (permalink / raw)
To: Xia Yan, Netdev
Cc: andrew+netdev, David S . Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, maheshb, kaber, dskr99, linux-kernel, yana06070
On Thu, Nov 12, 2026, at 03:56, Xia Yan wrote:
> In bridge mode, broadcast and multicast packets sent by one macvlan
> are delivered to the other bridge ports by macvlan_broadcast(),
> called from macvlan_queue_xmit(). The skb still contains its
> Ethernet header there, so adding ETH_HLEN again in the rx_bytes
> accounting overcounts by 14 bytes per packet on every receiving
> macvlan.
>
> Packets flooded from the receive handler have had the Ethernet
> header pulled by eth_type_trans(), so they still need ETH_HLEN.
>
> Use the existing mode argument to skip the extra ETH_HLEN for the
> local bridge-mode path.
>
> Noticed in macvlan during review of the ipvlan fix, and confirmed
> on a 6.6 distribution kernel: five IPv4 UDP packets with 32-byte
> payloads increased rx_bytes by 440 instead of 370.
>
> Tested before and after the change with custom IPv4 and IPv6 UDP
> tests in UML. The corrected counters match the received Ethernet
> frame lengths. Local unicast and external RX counts are unchanged
> in these tests.
>
> Fixes: 618e1b7482f7 ("macvlan: implement bridge, VEPA and private mode")
> Signed-off-by: Xia Yan <yanxia@cmss.chinamobile.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-18 17:48 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-12 2:56 [PATCH net-next v2 0/2] ipvlan/macvlan: fix local RX byte accounting Xia Yan
2026-11-12 2:56 ` [PATCH net-next v2 1/2] ipvlan: fix RX byte accounting for local traffic Xia Yan
2026-11-18 17:43 ` Simon Horman
2026-11-12 2:56 ` [PATCH net-next v2 2/2] macvlan: fix RX byte accounting for local broadcast and multicast Xia Yan
2026-11-18 17:43 ` Simon Horman
2026-11-18 17:48 ` Arnd Bergmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®