Skip to content

Commit 16bb8c6

Browse files
Jianbo Liukuba-moo
authored andcommitted
net/mlx5e: TC, Offload rewrite and mirror on tunnel over ovs internal port
To offload the encap rule when the tunnel IP is configured on an openvswitch internal port, driver need to overwrite vport metadata in reg_c0 to the value assigned to the internal port, then forward packets to root table to be processed again by the rules matching on the metadata for such internal port. When such rule is combined with header rewrite and mirror, openvswitch generates the rule like the following, because it resets mirror after packets are modified. in_port(enp8s0f0npf0sf1),.., actions:enp8s0f0npf0sf2,set(tunnel(...)),set(ipv4(...)),vxlan_sys_4789,enp8s0f0npf0sf2 The split_count was introduced before to support rewrite and mirror. Driver splits the rule into two different hardware rules in order to offload it. But it's not enough to offload the above complicated rule because of the limitations, in both driver and firmware. To resolve this issue, the destination array is split again after the destination indexed by split_count. An extra rule is added for the leftover destinations (in the above example, it is enp8s0f0npf0sf2), and is inserted to post_act table. And the extra destination is added in the original rule to forward to post_act table, so the extra mirror is done there. Signed-off-by: Jianbo Liu <jianbol@nvidia.com> Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com> Signed-off-by: Tariq Toukan <tariqt@nvidia.com> Link: https://patch.msgid.link/20240808055927.2059700-4-tariqt@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 88c46f6 commit 16bb8c6

File tree

4 files changed

+112
-0
lines changed

4 files changed

+112
-0
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en/tc_priv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ struct mlx5e_tc_flow {
109109
struct completion init_done;
110110
struct completion del_hw_done;
111111
struct mlx5_flow_attr *attr;
112+
struct mlx5_flow_attr *extra_split_attr;
112113
struct list_head attrs;
113114
u32 chain_mapping;
114115
};

drivers/net/ethernet/mellanox/mlx5/core/en_tc.c

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,11 +1739,102 @@ has_encap_dests(struct mlx5_flow_attr *attr)
17391739
return false;
17401740
}
17411741

1742+
static int
1743+
extra_split_attr_dests_needed(struct mlx5e_tc_flow *flow, struct mlx5_flow_attr *attr)
1744+
{
1745+
struct mlx5_esw_flow_attr *esw_attr;
1746+
1747+
if (flow->attr != attr ||
1748+
!list_is_first(&attr->list, &flow->attrs))
1749+
return 0;
1750+
1751+
esw_attr = attr->esw_attr;
1752+
if (!esw_attr->split_count ||
1753+
esw_attr->split_count == esw_attr->out_count - 1)
1754+
return 0;
1755+
1756+
if (esw_attr->dest_int_port &&
1757+
(esw_attr->dests[esw_attr->split_count].flags &
1758+
MLX5_ESW_DEST_CHAIN_WITH_SRC_PORT_CHANGE))
1759+
return esw_attr->split_count + 1;
1760+
1761+
return 0;
1762+
}
1763+
1764+
static int
1765+
extra_split_attr_dests(struct mlx5e_tc_flow *flow,
1766+
struct mlx5_flow_attr *attr, int split_count)
1767+
{
1768+
struct mlx5e_post_act *post_act = get_post_action(flow->priv);
1769+
struct mlx5e_tc_flow_parse_attr *parse_attr, *parse_attr2;
1770+
struct mlx5_esw_flow_attr *esw_attr, *esw_attr2;
1771+
struct mlx5e_post_act_handle *handle;
1772+
struct mlx5_flow_attr *attr2;
1773+
int i, j, err;
1774+
1775+
if (IS_ERR(post_act))
1776+
return PTR_ERR(post_act);
1777+
1778+
attr2 = mlx5_alloc_flow_attr(mlx5e_get_flow_namespace(flow));
1779+
parse_attr2 = kvzalloc(sizeof(*parse_attr), GFP_KERNEL);
1780+
if (!attr2 || !parse_attr2) {
1781+
err = -ENOMEM;
1782+
goto err_free;
1783+
}
1784+
attr2->parse_attr = parse_attr2;
1785+
1786+
handle = mlx5e_tc_post_act_add(post_act, attr2);
1787+
if (IS_ERR(handle)) {
1788+
err = PTR_ERR(handle);
1789+
goto err_free;
1790+
}
1791+
1792+
esw_attr = attr->esw_attr;
1793+
esw_attr2 = attr2->esw_attr;
1794+
esw_attr2->in_rep = esw_attr->in_rep;
1795+
1796+
parse_attr = attr->parse_attr;
1797+
parse_attr2->filter_dev = parse_attr->filter_dev;
1798+
1799+
for (i = split_count, j = 0; i < esw_attr->out_count; i++, j++)
1800+
esw_attr2->dests[j] = esw_attr->dests[i];
1801+
1802+
esw_attr2->out_count = j;
1803+
attr2->action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
1804+
1805+
err = mlx5e_tc_post_act_offload(post_act, handle);
1806+
if (err)
1807+
goto err_post_act_offload;
1808+
1809+
err = mlx5e_tc_post_act_set_handle(flow->priv->mdev, handle,
1810+
&parse_attr->mod_hdr_acts);
1811+
if (err)
1812+
goto err_post_act_set_handle;
1813+
1814+
esw_attr->out_count = split_count;
1815+
attr->extra_split_ft = mlx5e_tc_post_act_get_ft(post_act);
1816+
flow->extra_split_attr = attr2;
1817+
1818+
attr2->post_act_handle = handle;
1819+
1820+
return 0;
1821+
1822+
err_post_act_set_handle:
1823+
mlx5e_tc_post_act_unoffload(post_act, handle);
1824+
err_post_act_offload:
1825+
mlx5e_tc_post_act_del(post_act, handle);
1826+
err_free:
1827+
kvfree(parse_attr2);
1828+
kfree(attr2);
1829+
return err;
1830+
}
1831+
17421832
static int
17431833
post_process_attr(struct mlx5e_tc_flow *flow,
17441834
struct mlx5_flow_attr *attr,
17451835
struct netlink_ext_ack *extack)
17461836
{
1837+
int extra_split;
17471838
bool vf_tun;
17481839
int err = 0;
17491840

@@ -1757,6 +1848,13 @@ post_process_attr(struct mlx5e_tc_flow *flow,
17571848
goto err_out;
17581849
}
17591850

1851+
extra_split = extra_split_attr_dests_needed(flow, attr);
1852+
if (extra_split > 0) {
1853+
err = extra_split_attr_dests(flow, attr, extra_split);
1854+
if (err)
1855+
goto err_out;
1856+
}
1857+
17601858
if (attr->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR) {
17611859
err = mlx5e_tc_attach_mod_hdr(flow->priv, flow, attr);
17621860
if (err)
@@ -1971,6 +2069,11 @@ static void mlx5e_tc_del_fdb_flow(struct mlx5e_priv *priv,
19712069
mlx5e_tc_act_stats_del_flow(get_act_stats_handle(priv), flow);
19722070

19732071
free_flow_post_acts(flow);
2072+
if (flow->extra_split_attr) {
2073+
mlx5_free_flow_attr_actions(flow, flow->extra_split_attr);
2074+
kvfree(flow->extra_split_attr->parse_attr);
2075+
kfree(flow->extra_split_attr);
2076+
}
19742077
mlx5_free_flow_attr_actions(flow, attr);
19752078

19762079
kvfree(attr->esw_attr->rx_tun_attr);

drivers/net/ethernet/mellanox/mlx5/core/en_tc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ struct mlx5_flow_attr {
8686
u32 dest_chain;
8787
struct mlx5_flow_table *ft;
8888
struct mlx5_flow_table *dest_ft;
89+
struct mlx5_flow_table *extra_split_ft;
8990
u8 inner_match_level;
9091
u8 outer_match_level;
9192
u8 tun_ip_version;

drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,13 @@ esw_setup_dests(struct mlx5_flow_destination *dest,
613613
}
614614
}
615615

616+
if (attr->extra_split_ft) {
617+
flow_act->flags |= FLOW_ACT_IGNORE_FLOW_LEVEL;
618+
dest[*i].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
619+
dest[*i].ft = attr->extra_split_ft;
620+
(*i)++;
621+
}
622+
616623
out:
617624
return err;
618625
}

0 commit comments

Comments
 (0)