mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-16 18:26:42 +00:00
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:
commit
c8eb0c3ffd
@ -488,24 +488,21 @@ netdev_nl_queue_dump_one(struct net_device *netdev, struct sk_buff *rsp,
|
|||||||
struct netdev_nl_dump_ctx *ctx)
|
struct netdev_nl_dump_ctx *ctx)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
int i;
|
|
||||||
|
|
||||||
if (!(netdev->flags & IFF_UP))
|
if (!(netdev->flags & IFF_UP))
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
for (i = ctx->rxq_idx; i < netdev->real_num_rx_queues;) {
|
for (; ctx->rxq_idx < netdev->real_num_rx_queues; ctx->rxq_idx++) {
|
||||||
err = netdev_nl_queue_fill_one(rsp, netdev, i,
|
err = netdev_nl_queue_fill_one(rsp, netdev, ctx->rxq_idx,
|
||||||
NETDEV_QUEUE_TYPE_RX, info);
|
NETDEV_QUEUE_TYPE_RX, info);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
ctx->rxq_idx = i++;
|
|
||||||
}
|
}
|
||||||
for (i = ctx->txq_idx; i < netdev->real_num_tx_queues;) {
|
for (; ctx->txq_idx < netdev->real_num_tx_queues; ctx->txq_idx++) {
|
||||||
err = netdev_nl_queue_fill_one(rsp, netdev, i,
|
err = netdev_nl_queue_fill_one(rsp, netdev, ctx->txq_idx,
|
||||||
NETDEV_QUEUE_TYPE_TX, info);
|
NETDEV_QUEUE_TYPE_TX, info);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
ctx->txq_idx = i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
@ -671,7 +668,7 @@ netdev_nl_stats_by_queue(struct net_device *netdev, struct sk_buff *rsp,
|
|||||||
i, info);
|
i, info);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
ctx->rxq_idx = i++;
|
ctx->rxq_idx = ++i;
|
||||||
}
|
}
|
||||||
i = ctx->txq_idx;
|
i = ctx->txq_idx;
|
||||||
while (ops->get_queue_stats_tx && i < netdev->real_num_tx_queues) {
|
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);
|
i, info);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
ctx->txq_idx = i++;
|
ctx->txq_idx = ++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->rxq_idx = 0;
|
ctx->rxq_idx = 0;
|
||||||
|
@ -8,25 +8,28 @@ from lib.py import cmd
|
|||||||
import glob
|
import glob
|
||||||
|
|
||||||
|
|
||||||
def sys_get_queues(ifname) -> int:
|
def sys_get_queues(ifname, qtype='rx') -> int:
|
||||||
folders = glob.glob(f'/sys/class/net/{ifname}/queues/rx-*')
|
folders = glob.glob(f'/sys/class/net/{ifname}/queues/{qtype}-*')
|
||||||
return len(folders)
|
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)
|
queues = nl.queue_get({'ifindex': cfg.ifindex}, dump=True)
|
||||||
if queues:
|
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
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_queues(cfg, nl) -> None:
|
def get_queues(cfg, nl) -> None:
|
||||||
queues = nl_get_queues(cfg, nl)
|
snl = NetdevFamily(recv_size=4096)
|
||||||
if not queues:
|
|
||||||
raise KsftSkipEx('queue-get not supported by device')
|
|
||||||
|
|
||||||
expected = sys_get_queues(cfg.dev['ifname'])
|
for qtype in ['rx', 'tx']:
|
||||||
ksft_eq(queues, expected)
|
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'], qtype)
|
||||||
|
ksft_eq(queues, expected)
|
||||||
|
|
||||||
|
|
||||||
def addremove_queues(cfg, nl) -> None:
|
def addremove_queues(cfg, nl) -> None:
|
||||||
@ -57,7 +60,7 @@ def addremove_queues(cfg, nl) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def main() -> 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_run([get_queues, addremove_queues], args=(cfg, NetdevFamily()))
|
||||||
ksft_exit()
|
ksft_exit()
|
||||||
|
|
||||||
|
@ -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[1][key], triple[0][key], comment="bad key: " + key)
|
||||||
ksft_ge(triple[2][key], triple[1][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
|
# Test invalid dumps
|
||||||
# 0 is invalid
|
# 0 is invalid
|
||||||
with ksft_raises(NlError) as cm:
|
with ksft_raises(NlError) as cm:
|
||||||
@ -158,7 +175,7 @@ def check_down(cfg) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def main() -> 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,
|
ksft_run([check_pause, check_fec, pkt_byte_sum, qstat_by_ifindex,
|
||||||
check_down],
|
check_down],
|
||||||
args=(cfg, ))
|
args=(cfg, ))
|
||||||
|
@ -32,23 +32,23 @@ except ModuleNotFoundError as e:
|
|||||||
# Set schema='' to avoid jsonschema validation, it's slow
|
# Set schema='' to avoid jsonschema validation, it's slow
|
||||||
#
|
#
|
||||||
class EthtoolFamily(YnlFamily):
|
class EthtoolFamily(YnlFamily):
|
||||||
def __init__(self):
|
def __init__(self, recv_size=0):
|
||||||
super().__init__((SPEC_PATH / Path('ethtool.yaml')).as_posix(),
|
super().__init__((SPEC_PATH / Path('ethtool.yaml')).as_posix(),
|
||||||
schema='')
|
schema='', recv_size=recv_size)
|
||||||
|
|
||||||
|
|
||||||
class RtnlFamily(YnlFamily):
|
class RtnlFamily(YnlFamily):
|
||||||
def __init__(self):
|
def __init__(self, recv_size=0):
|
||||||
super().__init__((SPEC_PATH / Path('rt_link.yaml')).as_posix(),
|
super().__init__((SPEC_PATH / Path('rt_link.yaml')).as_posix(),
|
||||||
schema='')
|
schema='', recv_size=recv_size)
|
||||||
|
|
||||||
|
|
||||||
class NetdevFamily(YnlFamily):
|
class NetdevFamily(YnlFamily):
|
||||||
def __init__(self):
|
def __init__(self, recv_size=0):
|
||||||
super().__init__((SPEC_PATH / Path('netdev.yaml')).as_posix(),
|
super().__init__((SPEC_PATH / Path('netdev.yaml')).as_posix(),
|
||||||
schema='')
|
schema='', recv_size=recv_size)
|
||||||
|
|
||||||
class NetshaperFamily(YnlFamily):
|
class NetshaperFamily(YnlFamily):
|
||||||
def __init__(self):
|
def __init__(self, recv_size=0):
|
||||||
super().__init__((SPEC_PATH / Path('net_shaper.yaml')).as_posix(),
|
super().__init__((SPEC_PATH / Path('net_shaper.yaml')).as_posix(),
|
||||||
schema='')
|
schema='', recv_size=recv_size)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user