@@ -406,14 +406,16 @@ static int mlx5e_xfrm_validate_state(struct mlx5_core_dev *mdev,
406
406
return 0 ;
407
407
}
408
408
409
- static void _update_xfrm_state (struct work_struct * work )
409
+ static void mlx5e_ipsec_modify_state (struct work_struct * _work )
410
410
{
411
- struct mlx5e_ipsec_modify_state_work * modify_work =
412
- container_of (work , struct mlx5e_ipsec_modify_state_work , work );
413
- struct mlx5e_ipsec_sa_entry * sa_entry = container_of (
414
- modify_work , struct mlx5e_ipsec_sa_entry , modify_work ) ;
411
+ struct mlx5e_ipsec_work * work =
412
+ container_of (_work , struct mlx5e_ipsec_work , work );
413
+ struct mlx5e_ipsec_sa_entry * sa_entry = work -> sa_entry ;
414
+ struct mlx5_accel_esp_xfrm_attrs * attrs ;
415
415
416
- mlx5_accel_esp_modify_xfrm (sa_entry , & modify_work -> attrs );
416
+ attrs = & ((struct mlx5e_ipsec_sa_entry * )work -> data )-> attrs ;
417
+
418
+ mlx5_accel_esp_modify_xfrm (sa_entry , attrs );
417
419
}
418
420
419
421
static void mlx5e_ipsec_set_esn_ops (struct mlx5e_ipsec_sa_entry * sa_entry )
@@ -432,6 +434,36 @@ static void mlx5e_ipsec_set_esn_ops(struct mlx5e_ipsec_sa_entry *sa_entry)
432
434
sa_entry -> set_iv_op = mlx5e_ipsec_set_iv ;
433
435
}
434
436
437
+ static int mlx5_ipsec_create_work (struct mlx5e_ipsec_sa_entry * sa_entry )
438
+ {
439
+ struct xfrm_state * x = sa_entry -> x ;
440
+ struct mlx5e_ipsec_work * work ;
441
+
442
+ switch (x -> xso .type ) {
443
+ case XFRM_DEV_OFFLOAD_CRYPTO :
444
+ if (!(x -> props .flags & XFRM_STATE_ESN ))
445
+ return 0 ;
446
+ break ;
447
+ default :
448
+ return 0 ;
449
+ }
450
+
451
+ work = kzalloc (sizeof (* work ), GFP_KERNEL );
452
+ if (!work )
453
+ return - ENOMEM ;
454
+
455
+ work -> data = kzalloc (sizeof (* sa_entry ), GFP_KERNEL );
456
+ if (!work -> data ) {
457
+ kfree (work );
458
+ return - ENOMEM ;
459
+ }
460
+
461
+ INIT_WORK (& work -> work , mlx5e_ipsec_modify_state );
462
+ work -> sa_entry = sa_entry ;
463
+ sa_entry -> work = work ;
464
+ return 0 ;
465
+ }
466
+
435
467
static int mlx5e_xfrm_add_state (struct xfrm_state * x ,
436
468
struct netlink_ext_ack * extack )
437
469
{
@@ -467,10 +499,15 @@ static int mlx5e_xfrm_add_state(struct xfrm_state *x,
467
499
mlx5e_ipsec_update_esn_state (sa_entry );
468
500
469
501
mlx5e_ipsec_build_accel_xfrm_attrs (sa_entry , & sa_entry -> attrs );
502
+
503
+ err = mlx5_ipsec_create_work (sa_entry );
504
+ if (err )
505
+ goto err_xfrm ;
506
+
470
507
/* create hw context */
471
508
err = mlx5_ipsec_create_sa_ctx (sa_entry );
472
509
if (err )
473
- goto err_xfrm ;
510
+ goto release_work ;
474
511
475
512
err = mlx5e_accel_ipsec_fs_add_rule (sa_entry );
476
513
if (err )
@@ -486,16 +523,6 @@ static int mlx5e_xfrm_add_state(struct xfrm_state *x,
486
523
goto err_add_rule ;
487
524
488
525
mlx5e_ipsec_set_esn_ops (sa_entry );
489
-
490
- switch (x -> xso .type ) {
491
- case XFRM_DEV_OFFLOAD_CRYPTO :
492
- if (x -> props .flags & XFRM_STATE_ESN )
493
- INIT_WORK (& sa_entry -> modify_work .work ,
494
- _update_xfrm_state );
495
- break ;
496
- default :
497
- break ;
498
- }
499
526
out :
500
527
x -> xso .offload_handle = (unsigned long )sa_entry ;
501
528
return 0 ;
@@ -504,6 +531,9 @@ static int mlx5e_xfrm_add_state(struct xfrm_state *x,
504
531
mlx5e_accel_ipsec_fs_del_rule (sa_entry );
505
532
err_hw_ctx :
506
533
mlx5_ipsec_free_sa_ctx (sa_entry );
534
+ release_work :
535
+ kfree (sa_entry -> work -> data );
536
+ kfree (sa_entry -> work );
507
537
err_xfrm :
508
538
kfree (sa_entry );
509
539
NL_SET_ERR_MSG_MOD (extack , "Device failed to offload this policy" );
@@ -530,17 +560,13 @@ static void mlx5e_xfrm_free_state(struct xfrm_state *x)
530
560
if (x -> xso .flags & XFRM_DEV_OFFLOAD_FLAG_ACQ )
531
561
goto sa_entry_free ;
532
562
533
- switch (x -> xso .type ) {
534
- case XFRM_DEV_OFFLOAD_CRYPTO :
535
- if (x -> props .flags & XFRM_STATE_ESN )
536
- cancel_work_sync (& sa_entry -> modify_work .work );
537
- break ;
538
- default :
539
- break ;
540
- }
563
+ if (sa_entry -> work )
564
+ cancel_work_sync (& sa_entry -> work -> work );
541
565
542
566
mlx5e_accel_ipsec_fs_del_rule (sa_entry );
543
567
mlx5_ipsec_free_sa_ctx (sa_entry );
568
+ kfree (sa_entry -> work -> data );
569
+ kfree (sa_entry -> work );
544
570
sa_entry_free :
545
571
kfree (sa_entry );
546
572
}
@@ -626,16 +652,18 @@ static bool mlx5e_ipsec_offload_ok(struct sk_buff *skb, struct xfrm_state *x)
626
652
static void mlx5e_xfrm_advance_esn_state (struct xfrm_state * x )
627
653
{
628
654
struct mlx5e_ipsec_sa_entry * sa_entry = to_ipsec_sa_entry (x );
629
- struct mlx5e_ipsec_modify_state_work * modify_work =
630
- & sa_entry -> modify_work ;
655
+ struct mlx5e_ipsec_work * work = sa_entry -> work ;
656
+ struct mlx5e_ipsec_sa_entry * sa_entry_shadow ;
631
657
bool need_update ;
632
658
633
659
need_update = mlx5e_ipsec_update_esn_state (sa_entry );
634
660
if (!need_update )
635
661
return ;
636
662
637
- mlx5e_ipsec_build_accel_xfrm_attrs (sa_entry , & modify_work -> attrs );
638
- queue_work (sa_entry -> ipsec -> wq , & modify_work -> work );
663
+ sa_entry_shadow = work -> data ;
664
+ memset (sa_entry_shadow , 0x00 , sizeof (* sa_entry_shadow ));
665
+ mlx5e_ipsec_build_accel_xfrm_attrs (sa_entry , & sa_entry_shadow -> attrs );
666
+ queue_work (sa_entry -> ipsec -> wq , & work -> work );
639
667
}
640
668
641
669
static void mlx5e_xfrm_update_curlft (struct xfrm_state * x )
0 commit comments