Commit 1f6da306 authored by Yevgeny Kliteynik's avatar Yevgeny Kliteynik Committed by Saeed Mahameed

net/mlx5e: Geneve, Keep tunnel info as pointer to the original struct

In mlx5e encap entry structure, IP tunnel info data structure is copied
by value. This approach worked till now, but it breaks when there are
encapsulation options, such as in case of Geneve.

These options are stored in the structure that is allocated adjacent to
the IP tunnel info struct, and not pointed at by any field in that struct.
Therefore, when copying the struct by value, we loose the address of the
original struct and can't get to the encapsulation options.

Fix the problem by storing the pointer to the tunnel info data instead.
Reviewed-by: default avatarOz Shlomo <ozsh@mellanox.com>
Signed-off-by: default avatarYevgeny Kliteynik <kliteyn@mellanox.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@mellanox.com>
parent 0ccc171e
...@@ -141,7 +141,8 @@ static int mlx5e_route_lookup_ipv6(struct mlx5e_priv *priv, ...@@ -141,7 +141,8 @@ static int mlx5e_route_lookup_ipv6(struct mlx5e_priv *priv,
return 0; return 0;
} }
static int mlx5e_gen_vxlan_header(char buf[], struct ip_tunnel_key *tun_key) static int mlx5e_gen_vxlan_header(char buf[],
const struct ip_tunnel_key *tun_key)
{ {
__be32 tun_id = tunnel_id_to_key32(tun_key->tun_id); __be32 tun_id = tunnel_id_to_key32(tun_key->tun_id);
struct udphdr *udp = (struct udphdr *)(buf); struct udphdr *udp = (struct udphdr *)(buf);
...@@ -155,7 +156,7 @@ static int mlx5e_gen_vxlan_header(char buf[], struct ip_tunnel_key *tun_key) ...@@ -155,7 +156,7 @@ static int mlx5e_gen_vxlan_header(char buf[], struct ip_tunnel_key *tun_key)
return 0; return 0;
} }
static int mlx5e_gen_gre_header(char buf[], struct ip_tunnel_key *tun_key) static int mlx5e_gen_gre_header(char buf[], const struct ip_tunnel_key *tun_key)
{ {
__be32 tun_id = tunnel_id_to_key32(tun_key->tun_id); __be32 tun_id = tunnel_id_to_key32(tun_key->tun_id);
int hdr_len; int hdr_len;
...@@ -183,7 +184,7 @@ static int mlx5e_gen_ip_tunnel_header(char buf[], __u8 *ip_proto, ...@@ -183,7 +184,7 @@ static int mlx5e_gen_ip_tunnel_header(char buf[], __u8 *ip_proto,
struct mlx5e_encap_entry *e) struct mlx5e_encap_entry *e)
{ {
int err = 0; int err = 0;
struct ip_tunnel_key *key = &e->tun_info.key; const struct ip_tunnel_key *key = &e->tun_info->key;
if (e->tunnel_type == MLX5E_TC_TUNNEL_TYPE_VXLAN) { if (e->tunnel_type == MLX5E_TC_TUNNEL_TYPE_VXLAN) {
*ip_proto = IPPROTO_UDP; *ip_proto = IPPROTO_UDP;
...@@ -229,7 +230,7 @@ int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv, ...@@ -229,7 +230,7 @@ int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv,
struct mlx5e_encap_entry *e) struct mlx5e_encap_entry *e)
{ {
int max_encap_size = MLX5_CAP_ESW(priv->mdev, max_encap_header_size); int max_encap_size = MLX5_CAP_ESW(priv->mdev, max_encap_header_size);
struct ip_tunnel_key *tun_key = &e->tun_info.key; const struct ip_tunnel_key *tun_key = &e->tun_info->key;
struct net_device *out_dev, *route_dev; struct net_device *out_dev, *route_dev;
struct neighbour *n = NULL; struct neighbour *n = NULL;
struct flowi4 fl4 = {}; struct flowi4 fl4 = {};
...@@ -345,7 +346,7 @@ int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv, ...@@ -345,7 +346,7 @@ int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv,
struct mlx5e_encap_entry *e) struct mlx5e_encap_entry *e)
{ {
int max_encap_size = MLX5_CAP_ESW(priv->mdev, max_encap_header_size); int max_encap_size = MLX5_CAP_ESW(priv->mdev, max_encap_header_size);
struct ip_tunnel_key *tun_key = &e->tun_info.key; const struct ip_tunnel_key *tun_key = &e->tun_info->key;
struct net_device *out_dev, *route_dev; struct net_device *out_dev, *route_dev;
struct neighbour *n = NULL; struct neighbour *n = NULL;
struct flowi6 fl6 = {}; struct flowi6 fl6 = {};
...@@ -489,7 +490,7 @@ int mlx5e_tc_tun_init_encap_attr(struct net_device *tunnel_dev, ...@@ -489,7 +490,7 @@ int mlx5e_tc_tun_init_encap_attr(struct net_device *tunnel_dev,
e->tunnel_type = mlx5e_tc_tun_get_type(tunnel_dev); e->tunnel_type = mlx5e_tc_tun_get_type(tunnel_dev);
if (e->tunnel_type == MLX5E_TC_TUNNEL_TYPE_VXLAN) { if (e->tunnel_type == MLX5E_TC_TUNNEL_TYPE_VXLAN) {
int dst_port = be16_to_cpu(e->tun_info.key.tp_dst); int dst_port = be16_to_cpu(e->tun_info->key.tp_dst);
if (!mlx5_vxlan_lookup_port(priv->mdev->vxlan, dst_port)) { if (!mlx5_vxlan_lookup_port(priv->mdev->vxlan, dst_port)) {
NL_SET_ERR_MSG_MOD(extack, NL_SET_ERR_MSG_MOD(extack,
...@@ -503,7 +504,7 @@ int mlx5e_tc_tun_init_encap_attr(struct net_device *tunnel_dev, ...@@ -503,7 +504,7 @@ int mlx5e_tc_tun_init_encap_attr(struct net_device *tunnel_dev,
e->tunnel_hlen = VXLAN_HLEN; e->tunnel_hlen = VXLAN_HLEN;
} else if (e->tunnel_type == MLX5E_TC_TUNNEL_TYPE_GRETAP) { } else if (e->tunnel_type == MLX5E_TC_TUNNEL_TYPE_GRETAP) {
e->reformat_type = MLX5_REFORMAT_TYPE_L2_TO_NVGRE; e->reformat_type = MLX5_REFORMAT_TYPE_L2_TO_NVGRE;
e->tunnel_hlen = gre_calc_hlen(e->tun_info.key.tun_flags); e->tunnel_hlen = gre_calc_hlen(e->tun_info->key.tun_flags);
} else { } else {
e->reformat_type = -1; e->reformat_type = -1;
e->tunnel_hlen = -1; e->tunnel_hlen = -1;
......
...@@ -150,7 +150,7 @@ struct mlx5e_encap_entry { ...@@ -150,7 +150,7 @@ struct mlx5e_encap_entry {
struct hlist_node encap_hlist; struct hlist_node encap_hlist;
struct list_head flows; struct list_head flows;
u32 encap_id; u32 encap_id;
struct ip_tunnel_info tun_info; const struct ip_tunnel_info *tun_info;
unsigned char h_dest[ETH_ALEN]; /* destination eth addr */ unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
struct net_device *out_dev; struct net_device *out_dev;
......
...@@ -126,7 +126,7 @@ struct mlx5e_tc_flow { ...@@ -126,7 +126,7 @@ struct mlx5e_tc_flow {
}; };
struct mlx5e_tc_flow_parse_attr { struct mlx5e_tc_flow_parse_attr {
struct ip_tunnel_info tun_info[MLX5_MAX_FLOW_FWD_VPORTS]; const struct ip_tunnel_info *tun_info[MLX5_MAX_FLOW_FWD_VPORTS];
struct net_device *filter_dev; struct net_device *filter_dev;
struct mlx5_flow_spec spec; struct mlx5_flow_spec spec;
int num_mod_hdr_actions; int num_mod_hdr_actions;
...@@ -2568,7 +2568,7 @@ static int parse_tc_nic_actions(struct mlx5e_priv *priv, ...@@ -2568,7 +2568,7 @@ static int parse_tc_nic_actions(struct mlx5e_priv *priv,
} }
struct encap_key { struct encap_key {
struct ip_tunnel_key *ip_tun_key; const struct ip_tunnel_key *ip_tun_key;
int tunnel_type; int tunnel_type;
}; };
...@@ -2612,7 +2612,7 @@ static int mlx5e_attach_encap(struct mlx5e_priv *priv, ...@@ -2612,7 +2612,7 @@ static int mlx5e_attach_encap(struct mlx5e_priv *priv,
struct mlx5_eswitch *esw = priv->mdev->priv.eswitch; struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
struct mlx5_esw_flow_attr *attr = flow->esw_attr; struct mlx5_esw_flow_attr *attr = flow->esw_attr;
struct mlx5e_tc_flow_parse_attr *parse_attr; struct mlx5e_tc_flow_parse_attr *parse_attr;
struct ip_tunnel_info *tun_info; const struct ip_tunnel_info *tun_info;
struct encap_key key, e_key; struct encap_key key, e_key;
struct mlx5e_encap_entry *e; struct mlx5e_encap_entry *e;
unsigned short family; unsigned short family;
...@@ -2621,7 +2621,7 @@ static int mlx5e_attach_encap(struct mlx5e_priv *priv, ...@@ -2621,7 +2621,7 @@ static int mlx5e_attach_encap(struct mlx5e_priv *priv,
int err = 0; int err = 0;
parse_attr = attr->parse_attr; parse_attr = attr->parse_attr;
tun_info = &parse_attr->tun_info[out_index]; tun_info = parse_attr->tun_info[out_index];
family = ip_tunnel_info_af(tun_info); family = ip_tunnel_info_af(tun_info);
key.ip_tun_key = &tun_info->key; key.ip_tun_key = &tun_info->key;
key.tunnel_type = mlx5e_tc_tun_get_type(mirred_dev); key.tunnel_type = mlx5e_tc_tun_get_type(mirred_dev);
...@@ -2630,7 +2630,7 @@ static int mlx5e_attach_encap(struct mlx5e_priv *priv, ...@@ -2630,7 +2630,7 @@ static int mlx5e_attach_encap(struct mlx5e_priv *priv,
hash_for_each_possible_rcu(esw->offloads.encap_tbl, e, hash_for_each_possible_rcu(esw->offloads.encap_tbl, e,
encap_hlist, hash_key) { encap_hlist, hash_key) {
e_key.ip_tun_key = &e->tun_info.key; e_key.ip_tun_key = &e->tun_info->key;
e_key.tunnel_type = e->tunnel_type; e_key.tunnel_type = e->tunnel_type;
if (!cmp_encap_info(&e_key, &key)) { if (!cmp_encap_info(&e_key, &key)) {
found = true; found = true;
...@@ -2646,7 +2646,7 @@ static int mlx5e_attach_encap(struct mlx5e_priv *priv, ...@@ -2646,7 +2646,7 @@ static int mlx5e_attach_encap(struct mlx5e_priv *priv,
if (!e) if (!e)
return -ENOMEM; return -ENOMEM;
e->tun_info = *tun_info; e->tun_info = tun_info;
err = mlx5e_tc_tun_init_encap_attr(mirred_dev, priv, e, extack); err = mlx5e_tc_tun_init_encap_attr(mirred_dev, priv, e, extack);
if (err) if (err)
goto out_err; goto out_err;
...@@ -2885,7 +2885,7 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, ...@@ -2885,7 +2885,7 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv,
} else if (encap) { } else if (encap) {
parse_attr->mirred_ifindex[attr->out_count] = parse_attr->mirred_ifindex[attr->out_count] =
out_dev->ifindex; out_dev->ifindex;
parse_attr->tun_info[attr->out_count] = *info; parse_attr->tun_info[attr->out_count] = info;
encap = false; encap = false;
attr->dests[attr->out_count].flags |= attr->dests[attr->out_count].flags |=
MLX5_ESW_DEST_ENCAP; MLX5_ESW_DEST_ENCAP;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment