net/mlx5e: Allow IPsec soft/hard limits in bytes
authorLeon Romanovsky <leonro@nvidia.com>
Thu, 12 Oct 2023 19:27:50 +0000 (12:27 -0700)
committerSaeed Mahameed <saeedm@nvidia.com>
Sat, 14 Oct 2023 17:16:33 +0000 (10:16 -0700)
Actually the mlx5 code already has needed support to allow users
to configure soft/hard limits in bytes. It is possible due to the
situation with TX path, where CX7 devices are missing hardware
implementation to send events to the software, see commit b2f7b01d36a9
("net/mlx5e: Simulate missing IPsec TX limits hardware functionality").

That software workaround is not limited to TX and works for bytes too.
So relax the validation logic to not block soft/hard limits in bytes.

Reviewed-by: Patrisious Haddad <phaddad@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c

index 62f9c19f1028a4e57fc1ab4c85d75d2b91b7a4c7..655496598c688496bb30e14c0a0d6e52e2d93040 100644 (file)
@@ -56,7 +56,7 @@ static struct mlx5e_ipsec_pol_entry *to_ipsec_pol_entry(struct xfrm_policy *x)
        return (struct mlx5e_ipsec_pol_entry *)x->xdo.offload_handle;
 }
 
-static void mlx5e_ipsec_handle_tx_limit(struct work_struct *_work)
+static void mlx5e_ipsec_handle_sw_limits(struct work_struct *_work)
 {
        struct mlx5e_ipsec_dwork *dwork =
                container_of(_work, struct mlx5e_ipsec_dwork, dwork.work);
@@ -486,9 +486,15 @@ static int mlx5e_xfrm_validate_state(struct mlx5_core_dev *mdev,
                        return -EINVAL;
                }
 
-               if (x->lft.hard_byte_limit != XFRM_INF ||
-                   x->lft.soft_byte_limit != XFRM_INF) {
-                       NL_SET_ERR_MSG_MOD(extack, "Device doesn't support limits in bytes");
+               if (x->lft.soft_byte_limit >= x->lft.hard_byte_limit &&
+                   x->lft.hard_byte_limit != XFRM_INF) {
+                       /* XFRM stack doesn't prevent such configuration :(. */
+                       NL_SET_ERR_MSG_MOD(extack, "Hard byte limit must be greater than soft one");
+                       return -EINVAL;
+               }
+
+               if (!x->lft.soft_byte_limit || !x->lft.hard_byte_limit) {
+                       NL_SET_ERR_MSG_MOD(extack, "Soft/hard byte limits can't be 0");
                        return -EINVAL;
                }
 
@@ -624,11 +630,10 @@ static int mlx5e_ipsec_create_dwork(struct mlx5e_ipsec_sa_entry *sa_entry)
        if (x->xso.type != XFRM_DEV_OFFLOAD_PACKET)
                return 0;
 
-       if (x->xso.dir != XFRM_DEV_OFFLOAD_OUT)
-               return 0;
-
        if (x->lft.soft_packet_limit == XFRM_INF &&
-           x->lft.hard_packet_limit == XFRM_INF)
+           x->lft.hard_packet_limit == XFRM_INF &&
+           x->lft.soft_byte_limit == XFRM_INF &&
+           x->lft.hard_byte_limit == XFRM_INF)
                return 0;
 
        dwork = kzalloc(sizeof(*dwork), GFP_KERNEL);
@@ -636,7 +641,7 @@ static int mlx5e_ipsec_create_dwork(struct mlx5e_ipsec_sa_entry *sa_entry)
                return -ENOMEM;
 
        dwork->sa_entry = sa_entry;
-       INIT_DELAYED_WORK(&dwork->dwork, mlx5e_ipsec_handle_tx_limit);
+       INIT_DELAYED_WORK(&dwork->dwork, mlx5e_ipsec_handle_sw_limits);
        sa_entry->dwork = dwork;
        return 0;
 }
index ef4dfc8442a9265c6e33497c0dbf6ca325e1b2ba..f41c976dc33f931eb3ac19431684fbd206a9e413 100644 (file)
@@ -1326,15 +1326,17 @@ static int rx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
        setup_fte_no_frags(spec);
        setup_fte_upper_proto_match(spec, &attrs->upspec);
 
-       if (rx != ipsec->rx_esw)
-               err = setup_modify_header(ipsec, attrs->type,
-                                         sa_entry->ipsec_obj_id | BIT(31),
-                                         XFRM_DEV_OFFLOAD_IN, &flow_act);
-       else
-               err = mlx5_esw_ipsec_rx_setup_modify_header(sa_entry, &flow_act);
+       if (!attrs->drop) {
+               if (rx != ipsec->rx_esw)
+                       err = setup_modify_header(ipsec, attrs->type,
+                                                 sa_entry->ipsec_obj_id | BIT(31),
+                                                 XFRM_DEV_OFFLOAD_IN, &flow_act);
+               else
+                       err = mlx5_esw_ipsec_rx_setup_modify_header(sa_entry, &flow_act);
 
-       if (err)
-               goto err_mod_header;
+               if (err)
+                       goto err_mod_header;
+       }
 
        switch (attrs->type) {
        case XFRM_DEV_OFFLOAD_PACKET:
@@ -1384,7 +1386,8 @@ err_add_cnt:
        if (flow_act.pkt_reformat)
                mlx5_packet_reformat_dealloc(mdev, flow_act.pkt_reformat);
 err_pkt_reformat:
-       mlx5_modify_header_dealloc(mdev, flow_act.modify_hdr);
+       if (flow_act.modify_hdr)
+               mlx5_modify_header_dealloc(mdev, flow_act.modify_hdr);
 err_mod_header:
        kvfree(spec);
 err_alloc:
@@ -1882,7 +1885,8 @@ void mlx5e_accel_ipsec_fs_del_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
                return;
        }
 
-       mlx5_modify_header_dealloc(mdev, ipsec_rule->modify_hdr);
+       if (ipsec_rule->modify_hdr)
+               mlx5_modify_header_dealloc(mdev, ipsec_rule->modify_hdr);
        mlx5_esw_ipsec_rx_id_mapping_remove(sa_entry);
        rx_ft_put(sa_entry->ipsec, sa_entry->attrs.family, sa_entry->attrs.type);
 }