Skip to content

Commit 6721239

Browse files
rleonklassert
authored andcommitted
net/mlx5e: Skip IPsec encryption for TX path without matching policy
Software implementation of IPsec skips encryption of packets in TX path if no matching policy is found. So align HW implementation to this behavior, by requiring matching reqid for offloaded policy and SA. Reviewed-by: Raed Salem <[email protected]> Reviewed-by: Saeed Mahameed <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent 81f8fba commit 6721239

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ mlx5e_ipsec_build_accel_xfrm_attrs(struct mlx5e_ipsec_sa_entry *sa_entry,
184184
memcpy(&attrs->daddr, x->id.daddr.a6, sizeof(attrs->daddr));
185185
attrs->family = x->props.family;
186186
attrs->type = x->xso.type;
187+
attrs->reqid = x->props.reqid;
187188
}
188189

189190
static inline int mlx5e_xfrm_validate_state(struct xfrm_state *x)
@@ -267,6 +268,11 @@ static inline int mlx5e_xfrm_validate_state(struct xfrm_state *x)
267268
x->replay_esn->replay_window);
268269
return -EINVAL;
269270
}
271+
272+
if (!x->props.reqid) {
273+
netdev_info(netdev, "Cannot offload without reqid\n");
274+
return -EINVAL;
275+
}
270276
}
271277
return 0;
272278
}
@@ -503,6 +509,7 @@ mlx5e_ipsec_build_accel_pol_attrs(struct mlx5e_ipsec_pol_entry *pol_entry,
503509
attrs->dir = x->xdo.dir;
504510
attrs->action = x->action;
505511
attrs->type = XFRM_DEV_OFFLOAD_PACKET;
512+
attrs->reqid = x->xfrm_vec[0].reqid;
506513
}
507514

508515
static int mlx5e_xfrm_add_policy(struct xfrm_policy *x)

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ struct mlx5_accel_esp_xfrm_attrs {
7777
u8 family;
7878
u32 replay_window;
7979
u32 authsize;
80+
u32 reqid;
8081
};
8182

8283
enum mlx5_ipsec_cap {
@@ -178,12 +179,13 @@ struct mlx5_accel_pol_xfrm_attrs {
178179
u8 action;
179180
u8 type : 2;
180181
u8 dir : 2;
182+
u32 reqid;
181183
};
182184

183185
struct mlx5e_ipsec_pol_entry {
184186
struct xfrm_policy *x;
185187
struct mlx5e_ipsec *ipsec;
186-
struct mlx5_flow_handle *rule;
188+
struct mlx5e_ipsec_rule ipsec_rule;
187189
struct mlx5_accel_pol_xfrm_attrs attrs;
188190
};
189191

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

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,17 @@ static void setup_fte_reg_a(struct mlx5_flow_spec *spec)
456456
misc_parameters_2.metadata_reg_a, MLX5_ETH_WQE_FT_META_IPSEC);
457457
}
458458

459+
static void setup_fte_reg_c0(struct mlx5_flow_spec *spec, u32 reqid)
460+
{
461+
/* Pass policy check before choosing this SA */
462+
spec->match_criteria_enable |= MLX5_MATCH_MISC_PARAMETERS_2;
463+
464+
MLX5_SET(fte_match_param, spec->match_criteria,
465+
misc_parameters_2.metadata_reg_c_0, reqid);
466+
MLX5_SET(fte_match_param, spec->match_value,
467+
misc_parameters_2.metadata_reg_c_0, reqid);
468+
}
469+
459470
static int setup_modify_header(struct mlx5_core_dev *mdev, u32 val, u8 dir,
460471
struct mlx5_flow_act *flow_act)
461472
{
@@ -470,6 +481,11 @@ static int setup_modify_header(struct mlx5_core_dev *mdev, u32 val, u8 dir,
470481
MLX5_ACTION_IN_FIELD_METADATA_REG_B);
471482
ns_type = MLX5_FLOW_NAMESPACE_KERNEL;
472483
break;
484+
case XFRM_DEV_OFFLOAD_OUT:
485+
MLX5_SET(set_action_in, action, field,
486+
MLX5_ACTION_IN_FIELD_METADATA_REG_C_0);
487+
ns_type = MLX5_FLOW_NAMESPACE_EGRESS;
488+
break;
473489
default:
474490
return -EINVAL;
475491
}
@@ -646,6 +662,7 @@ static int tx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
646662
setup_fte_reg_a(spec);
647663
break;
648664
case XFRM_DEV_OFFLOAD_PACKET:
665+
setup_fte_reg_c0(spec, attrs->reqid);
649666
err = setup_pkt_reformat(mdev, attrs, &flow_act);
650667
if (err)
651668
goto err_pkt_reformat;
@@ -712,6 +729,11 @@ static int tx_add_policy(struct mlx5e_ipsec_pol_entry *pol_entry)
712729

713730
setup_fte_no_frags(spec);
714731

732+
err = setup_modify_header(mdev, attrs->reqid, XFRM_DEV_OFFLOAD_OUT,
733+
&flow_act);
734+
if (err)
735+
goto err_mod_header;
736+
715737
switch (attrs->action) {
716738
case XFRM_POLICY_ALLOW:
717739
flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
@@ -741,10 +763,13 @@ static int tx_add_policy(struct mlx5e_ipsec_pol_entry *pol_entry)
741763
}
742764

743765
kvfree(spec);
744-
pol_entry->rule = rule;
766+
pol_entry->ipsec_rule.rule = rule;
767+
pol_entry->ipsec_rule.modify_hdr = flow_act.modify_hdr;
745768
return 0;
746769

747770
err_action:
771+
mlx5_modify_header_dealloc(mdev, flow_act.modify_hdr);
772+
err_mod_header:
748773
kvfree(spec);
749774
err_alloc:
750775
tx_ft_put(pol_entry->ipsec);
@@ -807,7 +832,7 @@ static int rx_add_policy(struct mlx5e_ipsec_pol_entry *pol_entry)
807832
}
808833

809834
kvfree(spec);
810-
pol_entry->rule = rule;
835+
pol_entry->ipsec_rule.rule = rule;
811836
return 0;
812837

813838
err_action:
@@ -964,16 +989,18 @@ int mlx5e_accel_ipsec_fs_add_pol(struct mlx5e_ipsec_pol_entry *pol_entry)
964989

965990
void mlx5e_accel_ipsec_fs_del_pol(struct mlx5e_ipsec_pol_entry *pol_entry)
966991
{
992+
struct mlx5e_ipsec_rule *ipsec_rule = &pol_entry->ipsec_rule;
967993
struct mlx5_core_dev *mdev = mlx5e_ipsec_pol2dev(pol_entry);
968994

969-
mlx5_del_flow_rules(pol_entry->rule);
995+
mlx5_del_flow_rules(ipsec_rule->rule);
970996

971-
if (pol_entry->attrs.dir == XFRM_DEV_OFFLOAD_OUT) {
972-
tx_ft_put(pol_entry->ipsec);
997+
if (pol_entry->attrs.dir == XFRM_DEV_OFFLOAD_IN) {
998+
rx_ft_put(mdev, pol_entry->ipsec, pol_entry->attrs.family);
973999
return;
9741000
}
9751001

976-
rx_ft_put(mdev, pol_entry->ipsec, pol_entry->attrs.family);
1002+
mlx5_modify_header_dealloc(mdev, ipsec_rule->modify_hdr);
1003+
tx_ft_put(pol_entry->ipsec);
9771004
}
9781005

9791006
void mlx5e_accel_ipsec_fs_cleanup(struct mlx5e_ipsec *ipsec)

0 commit comments

Comments
 (0)