From: Jianbo Liu mlx5e_accel_ipsec_fs_modify() rule update races with mlx5e_xfrm_update_stats(): The former removes and recreates steering counters while the latter reads them. Fix that by: - moving the eswitch RX mapped id into struct mlx5e_ipsec_rule so everything related to rule creation is in the same struct. - swap the pointer to it under x->lock to avoid the race. Discovered by Sashiko. Not reproduced. Tested on ConnectX-7 (fw 28.48.1000) under KASAN and lockdep: 10k neighbour updates, each one rebuilding the rules, with concurrent SA dumps and traffic. No splat, no packet loss. Fixes: b2f7b01d36a9 ("net/mlx5e: Simulate missing IPsec TX limits hardware functionality") Signed-off-by: Jianbo Liu Reviewed-by: Cosmin Ratiu Signed-off-by: Tariq Toukan --- drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h | 2 +- .../net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c | 7 +++++-- drivers/net/ethernet/mellanox/mlx5/core/esw/ipsec_fs.c | 8 ++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h index f4b2d7b950c0..9bbcd9e4c319 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h @@ -215,6 +215,7 @@ struct mlx5e_ipsec_rule { struct mlx5e_ipsec_drop replay; struct mlx5e_ipsec_drop auth; struct mlx5e_ipsec_drop trailer; + u32 rx_mapped_id; }; struct mlx5e_ipsec_miss { @@ -286,7 +287,6 @@ struct mlx5e_ipsec_sa_entry { struct mlx5e_ipsec_work *work; struct mlx5e_ipsec_dwork *dwork; struct mlx5e_ipsec_limits limits; - u32 rx_mapped_id; u8 ctx[MLX5_ST_SZ_BYTES(ipsec_aso)]; }; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c index 0facc5477155..d0f738fdeff3 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c @@ -2845,8 +2845,11 @@ void mlx5e_accel_ipsec_fs_modify(struct mlx5e_ipsec_sa_entry *sa_entry) if (err) return; - mlx5e_accel_ipsec_fs_del_rule(sa_entry); - memcpy(sa_entry, &sa_entry_shadow, sizeof(*sa_entry)); + spin_lock_bh(&sa_entry->x->lock); + swap(sa_entry->ipsec_rule, sa_entry_shadow.ipsec_rule); + spin_unlock_bh(&sa_entry->x->lock); + + mlx5e_accel_ipsec_fs_del_rule(&sa_entry_shadow); } int mlx5e_ipsec_fs_tunnel_allowed(struct mlx5e_ipsec_sa_entry *sa_entry) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/esw/ipsec_fs.c b/drivers/net/ethernet/mellanox/mlx5/core/esw/ipsec_fs.c index f8c97954b6ea..2615bbc89a16 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/esw/ipsec_fs.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/esw/ipsec_fs.c @@ -85,7 +85,7 @@ int mlx5_esw_ipsec_rx_setup_modify_header(struct mlx5e_ipsec_sa_entry *sa_entry, goto err_header_alloc; } - sa_entry->rx_mapped_id = mapped_id; + sa_entry->ipsec_rule.rx_mapped_id = mapped_id; flow_act->modify_hdr = modify_hdr; flow_act->action |= MLX5_FLOW_CONTEXT_ACTION_MOD_HDR; @@ -104,7 +104,7 @@ void mlx5_esw_ipsec_rx_rule_add_match_obj(struct mlx5e_ipsec_sa_entry *sa_entry, ESW_IPSEC_RX_MAPPED_ID_MATCH_MASK); MLX5_SET(fte_match_param, spec->match_value, misc_parameters_2.metadata_reg_c_1, - sa_entry->rx_mapped_id << ESW_ZONE_ID_BITS); + sa_entry->ipsec_rule.rx_mapped_id << ESW_ZONE_ID_BITS); spec->match_criteria_enable |= MLX5_MATCH_MISC_PARAMETERS_2; } @@ -113,9 +113,9 @@ void mlx5_esw_ipsec_rx_id_mapping_remove(struct mlx5e_ipsec_sa_entry *sa_entry) { struct mlx5e_ipsec *ipsec = sa_entry->ipsec; - if (sa_entry->rx_mapped_id) + if (sa_entry->ipsec_rule.rx_mapped_id) xa_erase_bh(&ipsec->ipsec_obj_id_map, - sa_entry->rx_mapped_id); + sa_entry->ipsec_rule.rx_mapped_id); } int mlx5_esw_ipsec_rx_ipsec_obj_id_search(struct mlx5e_priv *priv, u32 id, -- 2.44.0