net/mlx5e: Don't allow forwarding between uplink
authorTonghao Zhang <xiangxia.m.yue@gmail.com>
Mon, 17 Feb 2020 14:08:50 +0000 (22:08 +0800)
committerSaeed Mahameed <saeedm@mellanox.com>
Fri, 28 Feb 2020 00:39:59 +0000 (16:39 -0800)
We can install forwarding packets rule between uplink
in switchdev mode, as show below. But the hardware does
not do that as expected (mlnx_perf -i $PF1, we can't get
the counter of the PF1). By the way, if we add the uplink
PF0, PF1 to Open vSwitch and enable hw-offload, the rules
can be offloaded but not work fine too. This patch add a
check and if so return -EOPNOTSUPP.

$ tc filter add dev $PF0 protocol all parent ffff: prio 1 handle 1 \
    flower skip_sw action mirred egress redirect dev $PF1

$ tc -d -s filter show dev $PF0 ingress
    skip_sw
    in_hw in_hw_count 1
    action order 1: mirred (Egress Redirect to device enp130s0f1) stolen
    ...
    Sent hardware 408954 bytes 4173 pkt
    ...

Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
Reviewed-by: Roi Dayan <roid@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c

index 6be85a6b11d467ce2fd2e2d1c72f5074f853f555..3557f85f611dfe8281cae6b432bb5e5b1abf912f 100644 (file)
@@ -1464,6 +1464,11 @@ static const struct net_device_ops mlx5e_netdev_ops_uplink_rep = {
        .ndo_set_features        = mlx5e_set_features,
 };
 
+bool mlx5e_eswitch_uplink_rep(struct net_device *netdev)
+{
+       return netdev->netdev_ops == &mlx5e_netdev_ops_uplink_rep;
+}
+
 bool mlx5e_eswitch_rep(struct net_device *netdev)
 {
        if (netdev->netdev_ops == &mlx5e_netdev_ops_rep ||
index 3f756d51435f59daa2b8cb8f776d1ebe7122fbd7..8336301476a93963c0f259a04a830512616b0674 100644 (file)
@@ -200,6 +200,7 @@ void mlx5e_rep_encap_entry_detach(struct mlx5e_priv *priv,
 void mlx5e_rep_queue_neigh_stats_work(struct mlx5e_priv *priv);
 
 bool mlx5e_eswitch_rep(struct net_device *netdev);
+bool mlx5e_eswitch_uplink_rep(struct net_device *netdev);
 
 #else /* CONFIG_MLX5_ESWITCH */
 static inline bool mlx5e_is_uplink_rep(struct mlx5e_priv *priv) { return false; }
index 74091f72c9a8ab44ecc9e5b25f9ce63b2919f3e7..290cdf32bc5e73c10d77b46e253de29a5258c871 100644 (file)
@@ -3405,6 +3405,7 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv,
                                struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
                                struct net_device *uplink_dev = mlx5_eswitch_uplink_get_proto_dev(esw, REP_ETH);
                                struct net_device *uplink_upper;
+                               struct mlx5e_rep_priv *rep_priv;
 
                                if (is_duplicated_output_device(priv->netdev,
                                                                out_dev,
@@ -3440,6 +3441,22 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv,
                                                return err;
                                }
 
+                               /* Don't allow forwarding between uplink.
+                                *
+                                * Input vport was stored esw_attr->in_rep.
+                                * In LAG case, *priv* is the private data of
+                                * uplink which may be not the input vport.
+                                */
+                               rep_priv = mlx5e_rep_to_rep_priv(attr->in_rep);
+                               if (mlx5e_eswitch_uplink_rep(rep_priv->netdev) &&
+                                   mlx5e_eswitch_uplink_rep(out_dev)) {
+                                       NL_SET_ERR_MSG_MOD(extack,
+                                                          "devices are both uplink, can't offload forwarding");
+                                       pr_err("devices %s %s are both uplink, can't offload forwarding\n",
+                                              priv->netdev->name, out_dev->name);
+                                       return -EOPNOTSUPP;
+                               }
+
                                if (!mlx5e_is_valid_eswitch_fwd_dev(priv, out_dev)) {
                                        NL_SET_ERR_MSG_MOD(extack,
                                                           "devices are not on same switch HW, can't offload forwarding");