Skip to content

Commit

Permalink
Merge branch 'net-qede-convert-filter-code-to-use-extack'
Browse files Browse the repository at this point in the history
Asbjørn Sloth Tønnesen says:

====================
net: qede: convert filter code to use extack

This series converts the filter code in the qede driver
to use NL_SET_ERR_MSG_*(extack, ...) for error handling.

Patch 1-12 converts qede_parse_flow_attr() to use extack,
along with all it's static helper functions.

qede_parse_flow_attr() is used in two places:
- qede_add_tc_flower_fltr()
- qede_flow_spec_to_rule()

In the latter call site extack is faked in the same way as
is done in mlxsw (patch 12).

While the conversion is going on, some error messages are silenced
in between patch 1-12. If wanted could squash patch 1-12 in a v3, but
I felt that it would be easier to review as 12 more trivial patches.

Patch 13 and 14, finishes up by converting qede_parse_actions(),
and ensures that extack is propagated to it, in both call contexts.

v1: https://lore.kernel.org/netdev/[email protected]/
====================

Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
kuba-moo committed May 11, 2024
2 parents d50729f + 8415487 commit 24e28b6
Showing 1 changed file with 63 additions and 51 deletions.
114 changes: 63 additions & 51 deletions drivers/net/ethernet/qlogic/qede/qede_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1520,8 +1520,8 @@ static int qede_flow_spec_validate_unused(struct qede_dev *edev,
return 0;
}

static int qede_set_v4_tuple_to_profile(struct qede_dev *edev,
struct qede_arfs_tuple *t)
static int qede_set_v4_tuple_to_profile(struct qede_arfs_tuple *t,
struct netlink_ext_ack *extack)
{
/* We must have Only 4-tuples/l4 port/src ip/dst ip
* as an input.
Expand All @@ -1538,7 +1538,7 @@ static int qede_set_v4_tuple_to_profile(struct qede_dev *edev,
t->dst_ipv4 && !t->src_ipv4) {
t->mode = QED_FILTER_CONFIG_MODE_IP_DEST;
} else {
DP_INFO(edev, "Invalid N-tuple\n");
NL_SET_ERR_MSG_MOD(extack, "Invalid N-tuple");
return -EOPNOTSUPP;
}

Expand All @@ -1549,9 +1549,9 @@ static int qede_set_v4_tuple_to_profile(struct qede_dev *edev,
return 0;
}

static int qede_set_v6_tuple_to_profile(struct qede_dev *edev,
struct qede_arfs_tuple *t,
struct in6_addr *zaddr)
static int qede_set_v6_tuple_to_profile(struct qede_arfs_tuple *t,
struct in6_addr *zaddr,
struct netlink_ext_ack *extack)
{
/* We must have Only 4-tuples/l4 port/src ip/dst ip
* as an input.
Expand All @@ -1573,7 +1573,7 @@ static int qede_set_v6_tuple_to_profile(struct qede_dev *edev,
!memcmp(&t->src_ipv6, zaddr, sizeof(struct in6_addr))) {
t->mode = QED_FILTER_CONFIG_MODE_IP_DEST;
} else {
DP_INFO(edev, "Invalid N-tuple\n");
NL_SET_ERR_MSG_MOD(extack, "Invalid N-tuple");
return -EOPNOTSUPP;
}

Expand Down Expand Up @@ -1671,7 +1671,7 @@ static int qede_parse_actions(struct qede_dev *edev,
int i;

if (!flow_action_has_entries(flow_action)) {
DP_NOTICE(edev, "No actions received\n");
NL_SET_ERR_MSG_MOD(extack, "No actions received");
return -EINVAL;
}

Expand All @@ -1687,7 +1687,8 @@ static int qede_parse_actions(struct qede_dev *edev,
break;

if (act->queue.index >= QEDE_RSS_COUNT(edev)) {
DP_INFO(edev, "Queue out-of-bounds\n");
NL_SET_ERR_MSG_MOD(extack,
"Queue out-of-bounds");
return -EINVAL;
}
break;
Expand All @@ -1700,16 +1701,17 @@ static int qede_parse_actions(struct qede_dev *edev,
}

static int
qede_flow_parse_ports(struct qede_dev *edev, struct flow_rule *rule,
struct qede_arfs_tuple *t)
qede_flow_parse_ports(struct flow_rule *rule, struct qede_arfs_tuple *t,
struct netlink_ext_ack *extack)
{
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_PORTS)) {
struct flow_match_ports match;

flow_rule_match_ports(rule, &match);
if ((match.key->src && match.mask->src != htons(U16_MAX)) ||
(match.key->dst && match.mask->dst != htons(U16_MAX))) {
DP_NOTICE(edev, "Do not support ports masks\n");
NL_SET_ERR_MSG_MOD(extack,
"Do not support ports masks");
return -EINVAL;
}

Expand All @@ -1721,8 +1723,9 @@ qede_flow_parse_ports(struct qede_dev *edev, struct flow_rule *rule,
}

static int
qede_flow_parse_v6_common(struct qede_dev *edev, struct flow_rule *rule,
struct qede_arfs_tuple *t)
qede_flow_parse_v6_common(struct flow_rule *rule,
struct qede_arfs_tuple *t,
struct netlink_ext_ack *extack)
{
struct in6_addr zero_addr, addr;
int err;
Expand All @@ -1738,25 +1741,26 @@ qede_flow_parse_v6_common(struct qede_dev *edev, struct flow_rule *rule,
memcmp(&match.mask->src, &addr, sizeof(addr))) ||
(memcmp(&match.key->dst, &zero_addr, sizeof(addr)) &&
memcmp(&match.mask->dst, &addr, sizeof(addr)))) {
DP_NOTICE(edev,
"Do not support IPv6 address prefix/mask\n");
NL_SET_ERR_MSG_MOD(extack,
"Do not support IPv6 address prefix/mask");
return -EINVAL;
}

memcpy(&t->src_ipv6, &match.key->src, sizeof(addr));
memcpy(&t->dst_ipv6, &match.key->dst, sizeof(addr));
}

err = qede_flow_parse_ports(edev, rule, t);
err = qede_flow_parse_ports(rule, t, extack);
if (err)
return err;

return qede_set_v6_tuple_to_profile(edev, t, &zero_addr);
return qede_set_v6_tuple_to_profile(t, &zero_addr, extack);
}

static int
qede_flow_parse_v4_common(struct qede_dev *edev, struct flow_rule *rule,
struct qede_arfs_tuple *t)
qede_flow_parse_v4_common(struct flow_rule *rule,
struct qede_arfs_tuple *t,
struct netlink_ext_ack *extack)
{
int err;

Expand All @@ -1766,64 +1770,66 @@ qede_flow_parse_v4_common(struct qede_dev *edev, struct flow_rule *rule,
flow_rule_match_ipv4_addrs(rule, &match);
if ((match.key->src && match.mask->src != htonl(U32_MAX)) ||
(match.key->dst && match.mask->dst != htonl(U32_MAX))) {
DP_NOTICE(edev, "Do not support ipv4 prefix/masks\n");
NL_SET_ERR_MSG_MOD(extack,
"Do not support ipv4 prefix/masks");
return -EINVAL;
}

t->src_ipv4 = match.key->src;
t->dst_ipv4 = match.key->dst;
}

err = qede_flow_parse_ports(edev, rule, t);
err = qede_flow_parse_ports(rule, t, extack);
if (err)
return err;

return qede_set_v4_tuple_to_profile(edev, t);
return qede_set_v4_tuple_to_profile(t, extack);
}

static int
qede_flow_parse_tcp_v6(struct qede_dev *edev, struct flow_rule *rule,
struct qede_arfs_tuple *tuple)
qede_flow_parse_tcp_v6(struct flow_rule *rule, struct qede_arfs_tuple *tuple,
struct netlink_ext_ack *extack)
{
tuple->ip_proto = IPPROTO_TCP;
tuple->eth_proto = htons(ETH_P_IPV6);

return qede_flow_parse_v6_common(edev, rule, tuple);
return qede_flow_parse_v6_common(rule, tuple, extack);
}

static int
qede_flow_parse_tcp_v4(struct qede_dev *edev, struct flow_rule *rule,
struct qede_arfs_tuple *tuple)
qede_flow_parse_tcp_v4(struct flow_rule *rule, struct qede_arfs_tuple *tuple,
struct netlink_ext_ack *extack)
{
tuple->ip_proto = IPPROTO_TCP;
tuple->eth_proto = htons(ETH_P_IP);

return qede_flow_parse_v4_common(edev, rule, tuple);
return qede_flow_parse_v4_common(rule, tuple, extack);
}

static int
qede_flow_parse_udp_v6(struct qede_dev *edev, struct flow_rule *rule,
struct qede_arfs_tuple *tuple)
qede_flow_parse_udp_v6(struct flow_rule *rule, struct qede_arfs_tuple *tuple,
struct netlink_ext_ack *extack)
{
tuple->ip_proto = IPPROTO_UDP;
tuple->eth_proto = htons(ETH_P_IPV6);

return qede_flow_parse_v6_common(edev, rule, tuple);
return qede_flow_parse_v6_common(rule, tuple, extack);
}

static int
qede_flow_parse_udp_v4(struct qede_dev *edev, struct flow_rule *rule,
struct qede_arfs_tuple *tuple)
qede_flow_parse_udp_v4(struct flow_rule *rule, struct qede_arfs_tuple *tuple,
struct netlink_ext_ack *extack)
{
tuple->ip_proto = IPPROTO_UDP;
tuple->eth_proto = htons(ETH_P_IP);

return qede_flow_parse_v4_common(edev, rule, tuple);
return qede_flow_parse_v4_common(rule, tuple, extack);
}

static int
qede_parse_flow_attr(struct qede_dev *edev, __be16 proto,
struct flow_rule *rule, struct qede_arfs_tuple *tuple)
qede_parse_flow_attr(__be16 proto, struct flow_rule *rule,
struct qede_arfs_tuple *tuple,
struct netlink_ext_ack *extack)
{
struct flow_dissector *dissector = rule->match.dissector;
int rc = -EINVAL;
Expand All @@ -1837,14 +1843,15 @@ qede_parse_flow_attr(struct qede_dev *edev, __be16 proto,
BIT_ULL(FLOW_DISSECTOR_KEY_BASIC) |
BIT_ULL(FLOW_DISSECTOR_KEY_IPV6_ADDRS) |
BIT_ULL(FLOW_DISSECTOR_KEY_PORTS))) {
DP_NOTICE(edev, "Unsupported key set:0x%llx\n",
dissector->used_keys);
NL_SET_ERR_MSG_FMT_MOD(extack, "Unsupported key used: 0x%llx",
dissector->used_keys);
return -EOPNOTSUPP;
}

if (proto != htons(ETH_P_IP) &&
proto != htons(ETH_P_IPV6)) {
DP_NOTICE(edev, "Unsupported proto=0x%x\n", proto);
NL_SET_ERR_MSG_FMT_MOD(extack, "Unsupported proto=0x%x",
proto);
return -EPROTONOSUPPORT;
}

Expand All @@ -1856,22 +1863,23 @@ qede_parse_flow_attr(struct qede_dev *edev, __be16 proto,
}

if (ip_proto == IPPROTO_TCP && proto == htons(ETH_P_IP))
rc = qede_flow_parse_tcp_v4(edev, rule, tuple);
rc = qede_flow_parse_tcp_v4(rule, tuple, extack);
else if (ip_proto == IPPROTO_TCP && proto == htons(ETH_P_IPV6))
rc = qede_flow_parse_tcp_v6(edev, rule, tuple);
rc = qede_flow_parse_tcp_v6(rule, tuple, extack);
else if (ip_proto == IPPROTO_UDP && proto == htons(ETH_P_IP))
rc = qede_flow_parse_udp_v4(edev, rule, tuple);
rc = qede_flow_parse_udp_v4(rule, tuple, extack);
else if (ip_proto == IPPROTO_UDP && proto == htons(ETH_P_IPV6))
rc = qede_flow_parse_udp_v6(edev, rule, tuple);
rc = qede_flow_parse_udp_v6(rule, tuple, extack);
else
DP_NOTICE(edev, "Invalid protocol request\n");
NL_SET_ERR_MSG_MOD(extack, "Invalid protocol request");

return rc;
}

int qede_add_tc_flower_fltr(struct qede_dev *edev, __be16 proto,
struct flow_cls_offload *f)
{
struct netlink_ext_ack *extack = f->common.extack;
struct qede_arfs_fltr_node *n;
struct qede_arfs_tuple t;
int min_hlen, rc;
Expand All @@ -1884,7 +1892,7 @@ int qede_add_tc_flower_fltr(struct qede_dev *edev, __be16 proto,
}

/* parse flower attribute and prepare filter */
rc = qede_parse_flow_attr(edev, proto, f->rule, &t);
rc = qede_parse_flow_attr(proto, f->rule, &t, extack);
if (rc)
goto unlock;

Expand All @@ -1899,7 +1907,7 @@ int qede_add_tc_flower_fltr(struct qede_dev *edev, __be16 proto,
}

/* parse tc actions and get the vf_id */
rc = qede_parse_actions(edev, &f->rule->action, f->common.extack);
rc = qede_parse_actions(edev, &f->rule->action, extack);
if (rc)
goto unlock;

Expand Down Expand Up @@ -1946,7 +1954,8 @@ int qede_add_tc_flower_fltr(struct qede_dev *edev, __be16 proto,
static int qede_flow_spec_validate(struct qede_dev *edev,
struct flow_action *flow_action,
struct qede_arfs_tuple *t,
__u32 location)
__u32 location,
struct netlink_ext_ack *extack)
{
int err;

Expand All @@ -1970,7 +1979,7 @@ static int qede_flow_spec_validate(struct qede_dev *edev,
return -EINVAL;
}

err = qede_parse_actions(edev, flow_action, NULL);
err = qede_parse_actions(edev, flow_action, extack);
if (err)
return err;

Expand All @@ -1983,6 +1992,7 @@ static int qede_flow_spec_to_rule(struct qede_dev *edev,
{
struct ethtool_rx_flow_spec_input input = {};
struct ethtool_rx_flow_rule *flow;
struct netlink_ext_ack extack;
__be16 proto;
int err;

Expand Down Expand Up @@ -2010,14 +2020,16 @@ static int qede_flow_spec_to_rule(struct qede_dev *edev,
if (IS_ERR(flow))
return PTR_ERR(flow);

err = qede_parse_flow_attr(edev, proto, flow->rule, t);
err = qede_parse_flow_attr(proto, flow->rule, t, &extack);
if (err)
goto err_out;

/* Make sure location is valid and filter isn't already set */
err = qede_flow_spec_validate(edev, &flow->rule->action, t,
fs->location);
fs->location, &extack);
err_out:
if (extack._msg)
DP_NOTICE(edev, "%s\n", extack._msg);
ethtool_rx_flow_rule_destroy(flow);
return err;

Expand Down

0 comments on commit 24e28b6

Please sign in to comment.