[PATCH] net/virtio: fix MAC table update with empty slots
Wenfeng Liu
liuwf at ysxt.com.cn
Wed Nov 18 08:37:24 CET 2026
Removing a MAC address clears its slot without compacting the address
array. When adding another address, stopping at the first empty slot
omits any valid addresses after it from the control MAC table.
For example, add addresses A, B and C, remove A and B, then add D. D fills
the first empty slot, but C is still beyond the remaining empty slot and
is omitted from the table sent to the device. With MAC filtering enabled,
traffic to C can then be dropped even though C remains in the ethdev
address array.
Scan the complete array and only copy nonzero MAC addresses into the
control table, preserving entries after empty slots without sending
zero addresses.
Fixes: 7698e655516c ("net/virtio: fix MAC table update")
Cc: stable at dpdk.org
Signed-off-by: Wenfeng Liu <liuwf at ysxt.com.cn>
---
Validation:
- Replayed the upstream ethdev MAC add/remove and virtio table-building
functions with AddressSanitizer and a mock control-command receiver.
Three sparse-table cases fail before the fix and all four cases pass
after it (dense, sparse unicast, sparse multicast, and last-slot).
- Built the virtio PMD static/shared libraries on x86_64 with GCC 14 in
both debug and release configurations.
- The driver fix applies to 22.11.11 and passes the same replay there.
- No real virtio guest packet-forwarding test has been performed.
.mailmap | 2 +-
drivers/net/virtio/virtio_ethdev.c | 12 +++++++-----
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/.mailmap b/.mailmap
index a7f57978..b645a2b1 100644
--- a/.mailmap
+++ b/.mailmap
@@ -1863,7 +1863,7 @@ Weiyuan Li <weiyuanx.li at intel.com>
Wen Chiu <wchiu at brocade.com>
Wen-Chi Yang <wolkayang at gmail.com>
Wenbo Cao <caowenbo at mucse.com>
-Wenfeng Liu <liuwf at arraynetworks.com.cn>
+Wenfeng Liu <liuwf at ysxt.com.cn> <liuwf at arraynetworks.com.cn>
Wenjie Li <wenjiex.a.li at intel.com>
Wenjie Sun <findtheonlyway at gmail.com>
Wenjing Qiao <wenjing.qiao at intel.com>
diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index f2302089..1e04427b 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -934,12 +934,14 @@ virtio_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
for (i = 0; i < VIRTIO_MAX_MAC_ADDRS; i++) {
const struct rte_ether_addr *addr
= (i == index) ? mac_addr : addrs + i;
- struct virtio_net_ctrl_mac *tbl
- = rte_is_multicast_ether_addr(addr) ? mc : uc;
- if (rte_is_zero_ether_addr(addr))
- break;
- memcpy(&tbl->macs[tbl->entries++], addr, RTE_ETHER_ADDR_LEN);
+ if (!rte_is_zero_ether_addr(addr)) {
+ struct virtio_net_ctrl_mac *tbl =
+ rte_is_multicast_ether_addr(addr) ? mc : uc;
+
+ memcpy(&tbl->macs[tbl->entries++], addr,
+ RTE_ETHER_ADDR_LEN);
+ }
}
return virtio_mac_table_set(hw, uc, mc);
base-commit: c6d273ce156cc48ef90e64e93a2bba80c9d36345
--
2.52.0
More information about the dev
mailing list