Skip to content

Commit 33cb624

Browse files
Jianbo Liujfvogel
authored andcommitted
net/mlx5e: Add correct match to check IPSec syndromes for switchdev mode
[ Upstream commit 85e4a808af2545fefaf18c8fe50071b06fcbdabc ] In commit dddb49b ("net/mlx5e: Add IPsec and ASO syndromes check in HW"), IPSec and ASO syndromes checks after decryption for the specified ASO object were added. But they are correct only for eswith in legacy mode. For switchdev mode, metadata register c1 is used to save the mapped id (not ASO object id). So, need to change the match accordingly for the check rules in status table. Signed-off-by: Jianbo Liu <[email protected]> Reviewed-by: Leon Romanovsky <[email protected]> Reviewed-by: Patrisious Haddad <[email protected]> Signed-off-by: Tariq Toukan <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit a68686c08b70bdad0b1a406bcfe7e07f3bdc5da2) Signed-off-by: Jack Vogel <[email protected]>
1 parent 412cf1c commit 33cb624

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,25 @@ static void ipsec_rx_status_pass_destroy(struct mlx5e_ipsec *ipsec,
165165
#endif
166166
}
167167

168+
static void ipsec_rx_rule_add_match_obj(struct mlx5e_ipsec_sa_entry *sa_entry,
169+
struct mlx5e_ipsec_rx *rx,
170+
struct mlx5_flow_spec *spec)
171+
{
172+
struct mlx5e_ipsec *ipsec = sa_entry->ipsec;
173+
174+
if (rx == ipsec->rx_esw) {
175+
mlx5_esw_ipsec_rx_rule_add_match_obj(sa_entry, spec);
176+
} else {
177+
MLX5_SET_TO_ONES(fte_match_param, spec->match_criteria,
178+
misc_parameters_2.metadata_reg_c_2);
179+
MLX5_SET(fte_match_param, spec->match_value,
180+
misc_parameters_2.metadata_reg_c_2,
181+
sa_entry->ipsec_obj_id | BIT(31));
182+
183+
spec->match_criteria_enable |= MLX5_MATCH_MISC_PARAMETERS_2;
184+
}
185+
}
186+
168187
static int rx_add_rule_drop_auth_trailer(struct mlx5e_ipsec_sa_entry *sa_entry,
169188
struct mlx5e_ipsec_rx *rx)
170189
{
@@ -200,11 +219,8 @@ static int rx_add_rule_drop_auth_trailer(struct mlx5e_ipsec_sa_entry *sa_entry,
200219

201220
MLX5_SET_TO_ONES(fte_match_param, spec->match_criteria, misc_parameters_2.ipsec_syndrome);
202221
MLX5_SET(fte_match_param, spec->match_value, misc_parameters_2.ipsec_syndrome, 1);
203-
MLX5_SET_TO_ONES(fte_match_param, spec->match_criteria, misc_parameters_2.metadata_reg_c_2);
204-
MLX5_SET(fte_match_param, spec->match_value,
205-
misc_parameters_2.metadata_reg_c_2,
206-
sa_entry->ipsec_obj_id | BIT(31));
207222
spec->match_criteria_enable = MLX5_MATCH_MISC_PARAMETERS_2;
223+
ipsec_rx_rule_add_match_obj(sa_entry, rx, spec);
208224
rule = mlx5_add_flow_rules(ft, spec, &flow_act, &dest, 1);
209225
if (IS_ERR(rule)) {
210226
err = PTR_ERR(rule);
@@ -281,10 +297,8 @@ static int rx_add_rule_drop_replay(struct mlx5e_ipsec_sa_entry *sa_entry, struct
281297

282298
MLX5_SET_TO_ONES(fte_match_param, spec->match_criteria, misc_parameters_2.metadata_reg_c_4);
283299
MLX5_SET(fte_match_param, spec->match_value, misc_parameters_2.metadata_reg_c_4, 1);
284-
MLX5_SET_TO_ONES(fte_match_param, spec->match_criteria, misc_parameters_2.metadata_reg_c_2);
285-
MLX5_SET(fte_match_param, spec->match_value, misc_parameters_2.metadata_reg_c_2,
286-
sa_entry->ipsec_obj_id | BIT(31));
287300
spec->match_criteria_enable = MLX5_MATCH_MISC_PARAMETERS_2;
301+
ipsec_rx_rule_add_match_obj(sa_entry, rx, spec);
288302
rule = mlx5_add_flow_rules(ft, spec, &flow_act, &dest, 1);
289303
if (IS_ERR(rule)) {
290304
err = PTR_ERR(rule);

drivers/net/ethernet/mellanox/mlx5/core/esw/ipsec_fs.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,19 @@ int mlx5_esw_ipsec_rx_setup_modify_header(struct mlx5e_ipsec_sa_entry *sa_entry,
8585
return err;
8686
}
8787

88+
void mlx5_esw_ipsec_rx_rule_add_match_obj(struct mlx5e_ipsec_sa_entry *sa_entry,
89+
struct mlx5_flow_spec *spec)
90+
{
91+
MLX5_SET(fte_match_param, spec->match_criteria,
92+
misc_parameters_2.metadata_reg_c_1,
93+
ESW_IPSEC_RX_MAPPED_ID_MATCH_MASK);
94+
MLX5_SET(fte_match_param, spec->match_value,
95+
misc_parameters_2.metadata_reg_c_1,
96+
sa_entry->rx_mapped_id << ESW_ZONE_ID_BITS);
97+
98+
spec->match_criteria_enable |= MLX5_MATCH_MISC_PARAMETERS_2;
99+
}
100+
88101
void mlx5_esw_ipsec_rx_id_mapping_remove(struct mlx5e_ipsec_sa_entry *sa_entry)
89102
{
90103
struct mlx5e_ipsec *ipsec = sa_entry->ipsec;

drivers/net/ethernet/mellanox/mlx5/core/esw/ipsec_fs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ int mlx5_esw_ipsec_rx_ipsec_obj_id_search(struct mlx5e_priv *priv, u32 id,
2020
void mlx5_esw_ipsec_tx_create_attr_set(struct mlx5e_ipsec *ipsec,
2121
struct mlx5e_ipsec_tx_create_attr *attr);
2222
void mlx5_esw_ipsec_restore_dest_uplink(struct mlx5_core_dev *mdev);
23+
void mlx5_esw_ipsec_rx_rule_add_match_obj(struct mlx5e_ipsec_sa_entry *sa_entry,
24+
struct mlx5_flow_spec *spec);
2325
#else
2426
static inline void mlx5_esw_ipsec_rx_create_attr_set(struct mlx5e_ipsec *ipsec,
2527
struct mlx5e_ipsec_rx_create_attr *attr) {}
@@ -48,5 +50,8 @@ static inline void mlx5_esw_ipsec_tx_create_attr_set(struct mlx5e_ipsec *ipsec,
4850
struct mlx5e_ipsec_tx_create_attr *attr) {}
4951

5052
static inline void mlx5_esw_ipsec_restore_dest_uplink(struct mlx5_core_dev *mdev) {}
53+
static inline void
54+
mlx5_esw_ipsec_rx_rule_add_match_obj(struct mlx5e_ipsec_sa_entry *sa_entry,
55+
struct mlx5_flow_spec *spec) {}
5156
#endif /* CONFIG_MLX5_ESWITCH */
5257
#endif /* __MLX5_ESW_IPSEC_FS_H__ */

include/linux/mlx5/eswitch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ u32 mlx5_eswitch_get_vport_metadata_for_set(struct mlx5_eswitch *esw,
147147

148148
/* reuse tun_opts for the mapped ipsec obj id when tun_id is 0 (invalid) */
149149
#define ESW_IPSEC_RX_MAPPED_ID_MASK GENMASK(ESW_TUN_OPTS_BITS - 1, 0)
150+
#define ESW_IPSEC_RX_MAPPED_ID_MATCH_MASK \
151+
GENMASK(31 - ESW_RESERVED_BITS, ESW_ZONE_ID_BITS)
150152

151153
u8 mlx5_eswitch_mode(const struct mlx5_core_dev *dev);
152154
u16 mlx5_eswitch_get_total_vports(const struct mlx5_core_dev *dev);

0 commit comments

Comments
 (0)