Skip to content

Commit e253734

Browse files
rleonkuba-moo
authored andcommitted
net/mlx5e: Rewrite IPsec vs. TC block interface
In the commit 366e462 ("net/mlx5e: Make IPsec offload work together with eswitch and TC"), new API to block IPsec vs. TC creation was introduced. Internally, that API used devlink lock to avoid races with userspace, but it is not really needed as dev->priv.eswitch is stable and can't be changed. So remove dependency on devlink lock and move block encap code back to its original place. Signed-off-by: Leon Romanovsky <leonro@nvidia.com> Signed-off-by: Saeed Mahameed <saeedm@nvidia.com> Link: https://lore.kernel.org/r/20230825062836.103744-5-saeed@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent c46fb77 commit e253734

3 files changed

Lines changed: 38 additions & 93 deletions

File tree

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

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ static void rx_destroy(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,
254254
mlx5_del_flow_rules(rx->sa.rule);
255255
mlx5_destroy_flow_group(rx->sa.group);
256256
mlx5_destroy_flow_table(rx->ft.sa);
257+
if (rx->allow_tunnel_mode)
258+
mlx5_eswitch_unblock_encap(mdev);
257259
if (rx == ipsec->rx_esw) {
258260
mlx5_esw_ipsec_rx_status_destroy(ipsec, rx);
259261
} else {
@@ -357,6 +359,8 @@ static int rx_create(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,
357359
goto err_add;
358360

359361
/* Create FT */
362+
if (mlx5_ipsec_device_caps(mdev) & MLX5_IPSEC_CAP_TUNNEL)
363+
rx->allow_tunnel_mode = mlx5_eswitch_block_encap(mdev);
360364
if (rx->allow_tunnel_mode)
361365
flags = MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT;
362366
ft = ipsec_ft_create(attr.ns, attr.sa_level, attr.prio, 2, flags);
@@ -411,6 +415,8 @@ static int rx_create(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,
411415
err_fs:
412416
mlx5_destroy_flow_table(rx->ft.sa);
413417
err_fs_ft:
418+
if (rx->allow_tunnel_mode)
419+
mlx5_eswitch_unblock_encap(mdev);
414420
mlx5_del_flow_rules(rx->status.rule);
415421
mlx5_modify_header_dealloc(mdev, rx->status.modify_hdr);
416422
err_add:
@@ -428,26 +434,19 @@ static int rx_get(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,
428434
if (rx->ft.refcnt)
429435
goto skip;
430436

431-
if (mlx5_ipsec_device_caps(mdev) & MLX5_IPSEC_CAP_TUNNEL)
432-
rx->allow_tunnel_mode = mlx5_eswitch_block_encap(mdev);
433-
434-
err = mlx5_eswitch_block_mode_trylock(mdev);
437+
err = mlx5_eswitch_block_mode(mdev);
435438
if (err)
436-
goto err_out;
439+
return err;
437440

438441
err = rx_create(mdev, ipsec, rx, family);
439-
mlx5_eswitch_block_mode_unlock(mdev, err);
440-
if (err)
441-
goto err_out;
442+
if (err) {
443+
mlx5_eswitch_unblock_mode(mdev);
444+
return err;
445+
}
442446

443447
skip:
444448
rx->ft.refcnt++;
445449
return 0;
446-
447-
err_out:
448-
if (rx->allow_tunnel_mode)
449-
mlx5_eswitch_unblock_encap(mdev);
450-
return err;
451450
}
452451

453452
static void rx_put(struct mlx5e_ipsec *ipsec, struct mlx5e_ipsec_rx *rx,
@@ -456,12 +455,8 @@ static void rx_put(struct mlx5e_ipsec *ipsec, struct mlx5e_ipsec_rx *rx,
456455
if (--rx->ft.refcnt)
457456
return;
458457

459-
mlx5_eswitch_unblock_mode_lock(ipsec->mdev);
460458
rx_destroy(ipsec->mdev, ipsec, rx, family);
461-
mlx5_eswitch_unblock_mode_unlock(ipsec->mdev);
462-
463-
if (rx->allow_tunnel_mode)
464-
mlx5_eswitch_unblock_encap(ipsec->mdev);
459+
mlx5_eswitch_unblock_mode(ipsec->mdev);
465460
}
466461

467462
static struct mlx5e_ipsec_rx *rx_ft_get(struct mlx5_core_dev *mdev,
@@ -581,6 +576,8 @@ static void tx_destroy(struct mlx5e_ipsec *ipsec, struct mlx5e_ipsec_tx *tx,
581576
mlx5_destroy_flow_group(tx->sa.group);
582577
}
583578
mlx5_destroy_flow_table(tx->ft.sa);
579+
if (tx->allow_tunnel_mode)
580+
mlx5_eswitch_unblock_encap(ipsec->mdev);
584581
mlx5_del_flow_rules(tx->status.rule);
585582
mlx5_destroy_flow_table(tx->ft.status);
586583
}
@@ -621,6 +618,8 @@ static int tx_create(struct mlx5e_ipsec *ipsec, struct mlx5e_ipsec_tx *tx,
621618
if (err)
622619
goto err_status_rule;
623620

621+
if (mlx5_ipsec_device_caps(mdev) & MLX5_IPSEC_CAP_TUNNEL)
622+
tx->allow_tunnel_mode = mlx5_eswitch_block_encap(mdev);
624623
if (tx->allow_tunnel_mode)
625624
flags = MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT;
626625
ft = ipsec_ft_create(tx->ns, attr.sa_level, attr.prio, 4, flags);
@@ -687,6 +686,8 @@ static int tx_create(struct mlx5e_ipsec *ipsec, struct mlx5e_ipsec_tx *tx,
687686
err_sa_miss:
688687
mlx5_destroy_flow_table(tx->ft.sa);
689688
err_sa_ft:
689+
if (tx->allow_tunnel_mode)
690+
mlx5_eswitch_unblock_encap(mdev);
690691
mlx5_del_flow_rules(tx->status.rule);
691692
err_status_rule:
692693
mlx5_destroy_flow_table(tx->ft.status);
@@ -720,52 +721,36 @@ static int tx_get(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,
720721
if (tx->ft.refcnt)
721722
goto skip;
722723

723-
if (mlx5_ipsec_device_caps(mdev) & MLX5_IPSEC_CAP_TUNNEL)
724-
tx->allow_tunnel_mode = mlx5_eswitch_block_encap(mdev);
725-
726-
err = mlx5_eswitch_block_mode_trylock(mdev);
724+
err = mlx5_eswitch_block_mode(mdev);
727725
if (err)
728-
goto err_out;
726+
return err;
729727

730728
err = tx_create(ipsec, tx, ipsec->roce);
731729
if (err) {
732-
mlx5_eswitch_block_mode_unlock(mdev, err);
733-
goto err_out;
730+
mlx5_eswitch_unblock_mode(mdev);
731+
return err;
734732
}
735733

736734
if (tx == ipsec->tx_esw)
737735
ipsec_esw_tx_ft_policy_set(mdev, tx->ft.pol);
738736

739-
mlx5_eswitch_block_mode_unlock(mdev, err);
740-
741737
skip:
742738
tx->ft.refcnt++;
743739
return 0;
744-
745-
err_out:
746-
if (tx->allow_tunnel_mode)
747-
mlx5_eswitch_unblock_encap(mdev);
748-
return err;
749740
}
750741

751742
static void tx_put(struct mlx5e_ipsec *ipsec, struct mlx5e_ipsec_tx *tx)
752743
{
753744
if (--tx->ft.refcnt)
754745
return;
755746

756-
mlx5_eswitch_unblock_mode_lock(ipsec->mdev);
757-
758747
if (tx == ipsec->tx_esw) {
759748
mlx5_esw_ipsec_restore_dest_uplink(ipsec->mdev);
760749
ipsec_esw_tx_ft_policy_set(ipsec->mdev, NULL);
761750
}
762751

763752
tx_destroy(ipsec, tx, ipsec->roce);
764-
765-
mlx5_eswitch_unblock_mode_unlock(ipsec->mdev);
766-
767-
if (tx->allow_tunnel_mode)
768-
mlx5_eswitch_unblock_encap(ipsec->mdev);
753+
mlx5_eswitch_unblock_mode(ipsec->mdev);
769754
}
770755

771756
static struct mlx5_flow_table *tx_ft_get_policy(struct mlx5_core_dev *mdev,

drivers/net/ethernet/mellanox/mlx5/core/eswitch.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -829,10 +829,8 @@ int mlx5_eswitch_reload_reps(struct mlx5_eswitch *esw);
829829
bool mlx5_eswitch_block_encap(struct mlx5_core_dev *dev);
830830
void mlx5_eswitch_unblock_encap(struct mlx5_core_dev *dev);
831831

832-
int mlx5_eswitch_block_mode_trylock(struct mlx5_core_dev *dev);
833-
void mlx5_eswitch_block_mode_unlock(struct mlx5_core_dev *dev, int err);
834-
void mlx5_eswitch_unblock_mode_lock(struct mlx5_core_dev *dev);
835-
void mlx5_eswitch_unblock_mode_unlock(struct mlx5_core_dev *dev);
832+
int mlx5_eswitch_block_mode(struct mlx5_core_dev *dev);
833+
void mlx5_eswitch_unblock_mode(struct mlx5_core_dev *dev);
836834

837835
static inline int mlx5_eswitch_num_vfs(struct mlx5_eswitch *esw)
838836
{
@@ -916,13 +914,8 @@ static inline void mlx5_eswitch_unblock_encap(struct mlx5_core_dev *dev)
916914
{
917915
}
918916

919-
static inline int mlx5_eswitch_block_mode_trylock(struct mlx5_core_dev *dev) { return 0; }
920-
921-
static inline void mlx5_eswitch_block_mode_unlock(struct mlx5_core_dev *dev, int err) {}
922-
923-
static inline void mlx5_eswitch_unblock_mode_lock(struct mlx5_core_dev *dev) {}
924-
925-
static inline void mlx5_eswitch_unblock_mode_unlock(struct mlx5_core_dev *dev) {}
917+
static inline int mlx5_eswitch_block_mode(struct mlx5_core_dev *dev) { return 0; }
918+
static inline void mlx5_eswitch_unblock_mode(struct mlx5_core_dev *dev) {}
926919
#endif /* CONFIG_MLX5_ESWITCH */
927920

928921
#endif /* __MLX5_ESWITCH_H__ */

drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3641,65 +3641,32 @@ static bool esw_offloads_devlink_ns_eq_netdev_ns(struct devlink *devlink)
36413641
return net_eq(devl_net, netdev_net);
36423642
}
36433643

3644-
int mlx5_eswitch_block_mode_trylock(struct mlx5_core_dev *dev)
3644+
int mlx5_eswitch_block_mode(struct mlx5_core_dev *dev)
36453645
{
3646-
struct devlink *devlink = priv_to_devlink(dev);
3647-
struct mlx5_eswitch *esw;
3646+
struct mlx5_eswitch *esw = dev->priv.eswitch;
36483647
int err;
36493648

3650-
devl_lock(devlink);
3651-
esw = mlx5_devlink_eswitch_get(devlink);
3652-
if (IS_ERR(esw)) {
3653-
/* Failure means no eswitch => not possible to change eswitch mode */
3654-
devl_unlock(devlink);
3649+
if (!mlx5_esw_allowed(esw))
36553650
return 0;
3656-
}
36573651

3652+
/* Take TC into account */
36583653
err = mlx5_esw_try_lock(esw);
3659-
if (err < 0) {
3660-
devl_unlock(devlink);
3654+
if (err < 0)
36613655
return err;
3662-
}
3663-
3664-
return 0;
3665-
}
3666-
3667-
void mlx5_eswitch_block_mode_unlock(struct mlx5_core_dev *dev, int err)
3668-
{
3669-
struct devlink *devlink = priv_to_devlink(dev);
3670-
struct mlx5_eswitch *esw;
3671-
3672-
esw = mlx5_devlink_eswitch_get(devlink);
3673-
if (IS_ERR(esw))
3674-
return;
36753656

3676-
if (!err)
3677-
esw->offloads.num_block_mode++;
3657+
esw->offloads.num_block_mode++;
36783658
mlx5_esw_unlock(esw);
3679-
devl_unlock(devlink);
3659+
return 0;
36803660
}
36813661

3682-
void mlx5_eswitch_unblock_mode_lock(struct mlx5_core_dev *dev)
3662+
void mlx5_eswitch_unblock_mode(struct mlx5_core_dev *dev)
36833663
{
3684-
struct devlink *devlink = priv_to_devlink(dev);
3685-
struct mlx5_eswitch *esw;
3664+
struct mlx5_eswitch *esw = dev->priv.eswitch;
36863665

3687-
esw = mlx5_devlink_eswitch_get(devlink);
3688-
if (IS_ERR(esw))
3666+
if (!mlx5_esw_allowed(esw))
36893667
return;
36903668

36913669
down_write(&esw->mode_lock);
3692-
}
3693-
3694-
void mlx5_eswitch_unblock_mode_unlock(struct mlx5_core_dev *dev)
3695-
{
3696-
struct devlink *devlink = priv_to_devlink(dev);
3697-
struct mlx5_eswitch *esw;
3698-
3699-
esw = mlx5_devlink_eswitch_get(devlink);
3700-
if (IS_ERR(esw))
3701-
return;
3702-
37033670
esw->offloads.num_block_mode--;
37043671
up_write(&esw->mode_lock);
37053672
}

0 commit comments

Comments
 (0)