Merge branch 'ethtool-rss-track-rss-ctx-busy-from-core'

Daniel Zahka says:

====================
ethtool: rss: track rss ctx busy from core

This series prevents deletion of rss contexts that are
in use by ntuple filters from ethtool core.
====================

Link: https://patch.msgid.link/20241011183549.1581021-1-daniel.zahka@gmail.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
Paolo Abeni
2024-10-17 10:22:03 +02:00
4 changed files with 86 additions and 2 deletions
+48
View File
@@ -684,6 +684,54 @@ int ethtool_check_max_channel(struct net_device *dev,
return 0;
}
int ethtool_check_rss_ctx_busy(struct net_device *dev, u32 rss_context)
{
const struct ethtool_ops *ops = dev->ethtool_ops;
struct ethtool_rxnfc *info;
int rc, i, rule_cnt;
if (!ops->get_rxnfc)
return 0;
rule_cnt = ethtool_get_rxnfc_rule_count(dev);
if (!rule_cnt)
return 0;
if (rule_cnt < 0)
return -EINVAL;
info = kvzalloc(struct_size(info, rule_locs, rule_cnt), GFP_KERNEL);
if (!info)
return -ENOMEM;
info->cmd = ETHTOOL_GRXCLSRLALL;
info->rule_cnt = rule_cnt;
rc = ops->get_rxnfc(dev, info, info->rule_locs);
if (rc)
goto out_free;
for (i = 0; i < rule_cnt; i++) {
struct ethtool_rxnfc rule_info = {
.cmd = ETHTOOL_GRXCLSRULE,
.fs.location = info->rule_locs[i],
};
rc = ops->get_rxnfc(dev, &rule_info, NULL);
if (rc)
goto out_free;
if (rule_info.fs.flow_type & FLOW_RSS &&
rule_info.rss_context == rss_context) {
rc = -EBUSY;
goto out_free;
}
}
out_free:
kvfree(info);
return rc;
}
int ethtool_check_ops(const struct ethtool_ops *ops)
{
if (WARN_ON(ops->set_coalesce && !ops->supported_coalesce_params))
+1
View File
@@ -47,6 +47,7 @@ bool convert_legacy_settings_to_link_ksettings(
int ethtool_check_max_channel(struct net_device *dev,
struct ethtool_channels channels,
struct genl_info *info);
int ethtool_check_rss_ctx_busy(struct net_device *dev, u32 rss_context);
int __ethtool_get_ts_info(struct net_device *dev, struct kernel_ethtool_ts_info *info);
extern const struct ethtool_phy_ops *ethtool_phy_ops;
+7
View File
@@ -1462,6 +1462,13 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev,
mutex_lock(&dev->ethtool->rss_lock);
locked = true;
}
if (rxfh.rss_context && rxfh_dev.rss_delete) {
ret = ethtool_check_rss_ctx_busy(dev, rxfh.rss_context);
if (ret)
goto out;
}
if (create) {
if (rxfh_dev.rss_delete) {
ret = -EINVAL;
@@ -6,7 +6,7 @@ import random
from lib.py import ksft_run, ksft_pr, ksft_exit, ksft_eq, ksft_ne, ksft_ge, ksft_lt
from lib.py import NetDrvEpEnv
from lib.py import EthtoolFamily, NetdevFamily
from lib.py import KsftSkipEx
from lib.py import KsftSkipEx, KsftFailEx
from lib.py import rand_port
from lib.py import ethtool, ip, defer, GenerateTraffic, CmdExitFailure
@@ -606,6 +606,33 @@ def test_rss_context_overlap2(cfg):
test_rss_context_overlap(cfg, True)
def test_delete_rss_context_busy(cfg):
"""
Test that deletion returns -EBUSY when an rss context is being used
by an ntuple filter.
"""
require_ntuple(cfg)
# create additional rss context
ctx_id = ethtool_create(cfg, "-X", "context new")
ctx_deleter = defer(ethtool, f"-X {cfg.ifname} context {ctx_id} delete")
# utilize context from ntuple filter
port = rand_port()
flow = f"flow-type tcp{cfg.addr_ipver} dst-port {port} context {ctx_id}"
ntuple_id = ethtool_create(cfg, "-N", flow)
defer(ethtool, f"-N {cfg.ifname} delete {ntuple_id}")
# attempt to delete in-use context
try:
ctx_deleter.exec_only()
ctx_deleter.cancel()
raise KsftFailEx(f"deleted context {ctx_id} used by rule {ntuple_id}")
except CmdExitFailure:
pass
def main() -> None:
with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
cfg.ethnl = EthtoolFamily()
@@ -616,7 +643,8 @@ def main() -> None:
test_rss_context, test_rss_context4, test_rss_context32,
test_rss_context_dump, test_rss_context_queue_reconfigure,
test_rss_context_overlap, test_rss_context_overlap2,
test_rss_context_out_of_order, test_rss_context4_create_with_cfg],
test_rss_context_out_of_order, test_rss_context4_create_with_cfg,
test_delete_rss_context_busy],
args=(cfg, ))
ksft_exit()