net/mlx5e: Geneve, Keep tunnel info as pointer to the original struct
authorYevgeny Kliteynik <kliteyn@mellanox.com>
Tue, 12 Feb 2019 11:31:00 +0000 (13:31 +0200)
committerSaeed Mahameed <saeedm@mellanox.com>
Fri, 31 May 2019 20:04:26 +0000 (13:04 -0700)
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: Oz Shlomo <ozsh@mellanox.com>
Signed-off-by: Yevgeny Kliteynik <kliteyn@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c
drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c

index fe5d4d7f15edc80426bed373e2bf646dfd39dde7..2004d04c4c460c42481ccc044e835e788c5f70ad 100644 (file)
@@ -141,7 +141,8 @@ static int mlx5e_route_lookup_ipv6(struct mlx5e_priv *priv,
        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);
        struct udphdr *udp = (struct udphdr *)(buf);
@@ -155,7 +156,7 @@ static int mlx5e_gen_vxlan_header(char buf[], struct ip_tunnel_key *tun_key)
        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);
        int hdr_len;
@@ -183,7 +184,7 @@ static int mlx5e_gen_ip_tunnel_header(char buf[], __u8 *ip_proto,
                                      struct mlx5e_encap_entry *e)
 {
        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) {
                *ip_proto = IPPROTO_UDP;
@@ -229,7 +230,7 @@ int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv,
                                    struct mlx5e_encap_entry *e)
 {
        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 neighbour *n = NULL;
        struct flowi4 fl4 = {};
@@ -345,7 +346,7 @@ int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv,
                                    struct mlx5e_encap_entry *e)
 {
        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 neighbour *n = NULL;
        struct flowi6 fl6 = {};
@@ -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);
 
        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)) {
                        NL_SET_ERR_MSG_MOD(extack,
@@ -503,7 +504,7 @@ int mlx5e_tc_tun_init_encap_attr(struct net_device *tunnel_dev,
                e->tunnel_hlen = VXLAN_HLEN;
        } else if (e->tunnel_type == MLX5E_TC_TUNNEL_TYPE_GRETAP) {
                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 {
                e->reformat_type = -1;
                e->tunnel_hlen = -1;
index e34573fd88c15c337b9dc56e38fc4da77af47948..5472bb4a0b51cc1d97985ef7fc9368b3ceb41392 100644 (file)
@@ -150,7 +150,7 @@ struct mlx5e_encap_entry {
        struct hlist_node encap_hlist;
        struct list_head flows;
        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 */
 
        struct net_device *out_dev;
index 8e2d8e735faa88a377ae9a14d372584f2cc1e68b..8b06c98cd43670e284750fbcdbeb60ff67f2bb79 100644 (file)
@@ -126,7 +126,7 @@ struct mlx5e_tc_flow {
 };
 
 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 mlx5_flow_spec spec;
        int num_mod_hdr_actions;
@@ -2568,7 +2568,7 @@ static int parse_tc_nic_actions(struct mlx5e_priv *priv,
 }
 
 struct encap_key {
-       struct ip_tunnel_key *ip_tun_key;
+       const struct ip_tunnel_key *ip_tun_key;
        int tunnel_type;
 };
 
@@ -2612,7 +2612,7 @@ static int mlx5e_attach_encap(struct mlx5e_priv *priv,
        struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
        struct mlx5_esw_flow_attr *attr = flow->esw_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 mlx5e_encap_entry *e;
        unsigned short family;
@@ -2621,7 +2621,7 @@ static int mlx5e_attach_encap(struct mlx5e_priv *priv,
        int err = 0;
 
        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);
        key.ip_tun_key = &tun_info->key;
        key.tunnel_type = mlx5e_tc_tun_get_type(mirred_dev);
@@ -2630,7 +2630,7 @@ static int mlx5e_attach_encap(struct mlx5e_priv *priv,
 
        hash_for_each_possible_rcu(esw->offloads.encap_tbl, e,
                                   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;
                if (!cmp_encap_info(&e_key, &key)) {
                        found = true;
@@ -2646,7 +2646,7 @@ static int mlx5e_attach_encap(struct mlx5e_priv *priv,
        if (!e)
                return -ENOMEM;
 
-       e->tun_info = *tun_info;
+       e->tun_info = tun_info;
        err = mlx5e_tc_tun_init_encap_attr(mirred_dev, priv, e, extack);
        if (err)
                goto out_err;
@@ -2885,7 +2885,7 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv,
                        } else if (encap) {
                                parse_attr->mirred_ifindex[attr->out_count] =
                                        out_dev->ifindex;
-                               parse_attr->tun_info[attr->out_count] = *info;
+                               parse_attr->tun_info[attr->out_count] = info;
                                encap = false;
                                attr->dests[attr->out_count].flags |=
                                        MLX5_ESW_DEST_ENCAP;