Merge branch 'netdev-fix-repeated-netlink-messages-in-queue-dumps'

Jakub Kicinski says:

====================
netdev: fix repeated netlink messages in queue dumps

Fix dump continuation for queues and queue stats in the netdev family.
Because we used post-increment when saving id of dumped queue next
skb would re-dump the already dumped queue.
====================

Link: https://patch.msgid.link/20241213152244.3080955-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Jakub Kicinski 2024-12-16 17:30:14 -08:00
commit c8eb0c3ffd
4 changed files with 45 additions and 28 deletions

View File

@ -488,24 +488,21 @@ netdev_nl_queue_dump_one(struct net_device *netdev, struct sk_buff *rsp,
struct netdev_nl_dump_ctx *ctx)
{
int err = 0;
int i;
if (!(netdev->flags & IFF_UP))
return err;
for (i = ctx->rxq_idx; i < netdev->real_num_rx_queues;) {
err = netdev_nl_queue_fill_one(rsp, netdev, i,
for (; ctx->rxq_idx < netdev->real_num_rx_queues; ctx->rxq_idx++) {
err = netdev_nl_queue_fill_one(rsp, netdev, ctx->rxq_idx,
NETDEV_QUEUE_TYPE_RX, info);
if (err)
return err;
ctx->rxq_idx = i++;
}
for (i = ctx->txq_idx; i < netdev->real_num_tx_queues;) {
err = netdev_nl_queue_fill_one(rsp, netdev, i,
for (; ctx->txq_idx < netdev->real_num_tx_queues; ctx->txq_idx++) {
err = netdev_nl_queue_fill_one(rsp, netdev, ctx->txq_idx,
NETDEV_QUEUE_TYPE_TX, info);
if (err)
return err;
ctx->txq_idx = i++;
}
return err;
@ -671,7 +668,7 @@ netdev_nl_stats_by_queue(struct net_device *netdev, struct sk_buff *rsp,
i, info);
if (err)
return err;
ctx->rxq_idx = i++;
ctx->rxq_idx = ++i;
}
i = ctx->txq_idx;
while (ops->get_queue_stats_tx && i < netdev->real_num_tx_queues) {
@ -679,7 +676,7 @@ netdev_nl_stats_by_queue(struct net_device *netdev, struct sk_buff *rsp,
i, info);
if (err)
return err;
ctx->txq_idx = i++;
ctx->txq_idx = ++i;
}
ctx->rxq_idx = 0;

View File

@ -8,24 +8,27 @@ from lib.py import cmd
import glob
def sys_get_queues(ifname) -> int:
folders = glob.glob(f'/sys/class/net/{ifname}/queues/rx-*')
def sys_get_queues(ifname, qtype='rx') -> int:
folders = glob.glob(f'/sys/class/net/{ifname}/queues/{qtype}-*')
return len(folders)
def nl_get_queues(cfg, nl):
def nl_get_queues(cfg, nl, qtype='rx'):
queues = nl.queue_get({'ifindex': cfg.ifindex}, dump=True)
if queues:
return len([q for q in queues if q['type'] == 'rx'])
return len([q for q in queues if q['type'] == qtype])
return None
def get_queues(cfg, nl) -> None:
queues = nl_get_queues(cfg, nl)
snl = NetdevFamily(recv_size=4096)
for qtype in ['rx', 'tx']:
queues = nl_get_queues(cfg, snl, qtype)
if not queues:
raise KsftSkipEx('queue-get not supported by device')
expected = sys_get_queues(cfg.dev['ifname'])
expected = sys_get_queues(cfg.dev['ifname'], qtype)
ksft_eq(queues, expected)
@ -57,7 +60,7 @@ def addremove_queues(cfg, nl) -> None:
def main() -> None:
with NetDrvEnv(__file__, queue_count=3) as cfg:
with NetDrvEnv(__file__, queue_count=100) as cfg:
ksft_run([get_queues, addremove_queues], args=(cfg, NetdevFamily()))
ksft_exit()

View File

@ -110,6 +110,23 @@ def qstat_by_ifindex(cfg) -> None:
ksft_ge(triple[1][key], triple[0][key], comment="bad key: " + key)
ksft_ge(triple[2][key], triple[1][key], comment="bad key: " + key)
# Sanity check the dumps
queues = NetdevFamily(recv_size=4096).qstats_get({"scope": "queue"}, dump=True)
# Reformat the output into {ifindex: {rx: [id, id, ...], tx: [id, id, ...]}}
parsed = {}
for entry in queues:
ifindex = entry["ifindex"]
if ifindex not in parsed:
parsed[ifindex] = {"rx":[], "tx": []}
parsed[ifindex][entry["queue-type"]].append(entry['queue-id'])
# Now, validate
for ifindex, queues in parsed.items():
for qtype in ['rx', 'tx']:
ksft_eq(len(queues[qtype]), len(set(queues[qtype])),
comment="repeated queue keys")
ksft_eq(len(queues[qtype]), max(queues[qtype]) + 1,
comment="missing queue keys")
# Test invalid dumps
# 0 is invalid
with ksft_raises(NlError) as cm:
@ -158,7 +175,7 @@ def check_down(cfg) -> None:
def main() -> None:
with NetDrvEnv(__file__) as cfg:
with NetDrvEnv(__file__, queue_count=100) as cfg:
ksft_run([check_pause, check_fec, pkt_byte_sum, qstat_by_ifindex,
check_down],
args=(cfg, ))

View File

@ -32,23 +32,23 @@ except ModuleNotFoundError as e:
# Set schema='' to avoid jsonschema validation, it's slow
#
class EthtoolFamily(YnlFamily):
def __init__(self):
def __init__(self, recv_size=0):
super().__init__((SPEC_PATH / Path('ethtool.yaml')).as_posix(),
schema='')
schema='', recv_size=recv_size)
class RtnlFamily(YnlFamily):
def __init__(self):
def __init__(self, recv_size=0):
super().__init__((SPEC_PATH / Path('rt_link.yaml')).as_posix(),
schema='')
schema='', recv_size=recv_size)
class NetdevFamily(YnlFamily):
def __init__(self):
def __init__(self, recv_size=0):
super().__init__((SPEC_PATH / Path('netdev.yaml')).as_posix(),
schema='')
schema='', recv_size=recv_size)
class NetshaperFamily(YnlFamily):
def __init__(self):
def __init__(self, recv_size=0):
super().__init__((SPEC_PATH / Path('net_shaper.yaml')).as_posix(),
schema='')
schema='', recv_size=recv_size)