Skip to content

Commit dd8b3a8

Browse files
committed
Merge tag 'ipsec-next-2022-12-09' of git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec-next
Steffen Klassert says: ==================== ipsec-next 2022-12-09 1) Add xfrm packet offload core API. From Leon Romanovsky. 2) Add xfrm packet offload support for mlx5. From Leon Romanovsky and Raed Salem. 3) Fix a typto in a error message. From Colin Ian King. * tag 'ipsec-next-2022-12-09' of git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec-next: (38 commits) xfrm: Fix spelling mistake "oflload" -> "offload" net/mlx5e: Open mlx5 driver to accept IPsec packet offload net/mlx5e: Handle ESN update events net/mlx5e: Handle hardware IPsec limits events net/mlx5e: Update IPsec soft and hard limits net/mlx5e: Store all XFRM SAs in Xarray net/mlx5e: Provide intermediate pointer to access IPsec struct net/mlx5e: Skip IPsec encryption for TX path without matching policy net/mlx5e: Add statistics for Rx/Tx IPsec offloaded flows net/mlx5e: Improve IPsec flow steering autogroup net/mlx5e: Configure IPsec packet offload flow steering net/mlx5e: Use same coding pattern for Rx and Tx flows net/mlx5e: Add XFRM policy offload logic net/mlx5e: Create IPsec policy offload tables net/mlx5e: Generalize creation of default IPsec miss group and rule net/mlx5e: Group IPsec miss handles into separate struct net/mlx5e: Make clear what IPsec rx_err does net/mlx5e: Flatten the IPsec RX add rule path net/mlx5e: Refactor FTE setup code to be more clear net/mlx5e: Move IPsec flow table creation to separate function ... ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 5fc11a4 + abe2343 commit dd8b3a8

File tree

30 files changed

+2141
-512
lines changed

30 files changed

+2141
-512
lines changed

Documentation/networking/xfrm_device.rst

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ XFRM device - offloading the IPsec computations
55
===============================================
66

77
Shannon Nelson <[email protected]>
8+
Leon Romanovsky <[email protected]>
89

910

1011
Overview
@@ -18,17 +19,39 @@ can radically increase throughput and decrease CPU utilization. The XFRM
1819
Device interface allows NIC drivers to offer to the stack access to the
1920
hardware offload.
2021

22+
Right now, there are two types of hardware offload that kernel supports.
23+
* IPsec crypto offload:
24+
* NIC performs encrypt/decrypt
25+
* Kernel does everything else
26+
* IPsec packet offload:
27+
* NIC performs encrypt/decrypt
28+
* NIC does encapsulation
29+
* Kernel and NIC have SA and policy in-sync
30+
* NIC handles the SA and policies states
31+
* The Kernel talks to the keymanager
32+
2133
Userland access to the offload is typically through a system such as
2234
libreswan or KAME/raccoon, but the iproute2 'ip xfrm' command set can
2335
be handy when experimenting. An example command might look something
24-
like this::
36+
like this for crypto offload:
2537

2638
ip x s add proto esp dst 14.0.0.70 src 14.0.0.52 spi 0x07 mode transport \
2739
reqid 0x07 replay-window 32 \
2840
aead 'rfc4106(gcm(aes))' 0x44434241343332312423222114131211f4f3f2f1 128 \
2941
sel src 14.0.0.52/24 dst 14.0.0.70/24 proto tcp \
3042
offload dev eth4 dir in
3143

44+
and for packet offload
45+
46+
ip x s add proto esp dst 14.0.0.70 src 14.0.0.52 spi 0x07 mode transport \
47+
reqid 0x07 replay-window 32 \
48+
aead 'rfc4106(gcm(aes))' 0x44434241343332312423222114131211f4f3f2f1 128 \
49+
sel src 14.0.0.52/24 dst 14.0.0.70/24 proto tcp \
50+
offload packet dev eth4 dir in
51+
52+
ip x p add src 14.0.0.70 dst 14.0.0.52 offload packet dev eth4 dir in
53+
tmpl src 14.0.0.70 dst 14.0.0.52 proto esp reqid 10000 mode transport
54+
3255
Yes, that's ugly, but that's what shell scripts and/or libreswan are for.
3356

3457

@@ -40,17 +63,24 @@ Callbacks to implement
4063

4164
/* from include/linux/netdevice.h */
4265
struct xfrmdev_ops {
66+
/* Crypto and Packet offload callbacks */
4367
int (*xdo_dev_state_add) (struct xfrm_state *x);
4468
void (*xdo_dev_state_delete) (struct xfrm_state *x);
4569
void (*xdo_dev_state_free) (struct xfrm_state *x);
4670
bool (*xdo_dev_offload_ok) (struct sk_buff *skb,
4771
struct xfrm_state *x);
4872
void (*xdo_dev_state_advance_esn) (struct xfrm_state *x);
73+
74+
/* Solely packet offload callbacks */
75+
void (*xdo_dev_state_update_curlft) (struct xfrm_state *x);
76+
int (*xdo_dev_policy_add) (struct xfrm_policy *x);
77+
void (*xdo_dev_policy_delete) (struct xfrm_policy *x);
78+
void (*xdo_dev_policy_free) (struct xfrm_policy *x);
4979
};
5080

51-
The NIC driver offering ipsec offload will need to implement these
52-
callbacks to make the offload available to the network stack's
53-
XFRM subsystem. Additionally, the feature bits NETIF_F_HW_ESP and
81+
The NIC driver offering ipsec offload will need to implement callbacks
82+
relevant to supported offload to make the offload available to the network
83+
stack's XFRM subsystem. Additionally, the feature bits NETIF_F_HW_ESP and
5484
NETIF_F_HW_ESP_TX_CSUM will signal the availability of the offload.
5585

5686

@@ -79,7 +109,8 @@ and an indication of whether it is for Rx or Tx. The driver should
79109

80110
=========== ===================================
81111
0 success
82-
-EOPNETSUPP offload not supported, try SW IPsec
112+
-EOPNETSUPP offload not supported, try SW IPsec,
113+
not applicable for packet offload mode
83114
other fail the request
84115
=========== ===================================
85116

@@ -96,6 +127,7 @@ will serviceable. This can check the packet information to be sure the
96127
offload can be supported (e.g. IPv4 or IPv6, no IPv4 options, etc) and
97128
return true of false to signify its support.
98129

130+
Crypto offload mode:
99131
When ready to send, the driver needs to inspect the Tx packet for the
100132
offload information, including the opaque context, and set up the packet
101133
send accordingly::
@@ -139,13 +171,25 @@ the stack in xfrm_input().
139171
In ESN mode, xdo_dev_state_advance_esn() is called from xfrm_replay_advance_esn().
140172
Driver will check packet seq number and update HW ESN state machine if needed.
141173

174+
Packet offload mode:
175+
HW adds and deletes XFRM headers. So in RX path, XFRM stack is bypassed if HW
176+
reported success. In TX path, the packet lefts kernel without extra header
177+
and not encrypted, the HW is responsible to perform it.
178+
142179
When the SA is removed by the user, the driver's xdo_dev_state_delete()
143-
is asked to disable the offload. Later, xdo_dev_state_free() is called
144-
from a garbage collection routine after all reference counts to the state
180+
and xdo_dev_policy_delete() are asked to disable the offload. Later,
181+
xdo_dev_state_free() and xdo_dev_policy_free() are called from a garbage
182+
collection routine after all reference counts to the state and policy
145183
have been removed and any remaining resources can be cleared for the
146184
offload state. How these are used by the driver will depend on specific
147185
hardware needs.
148186

149187
As a netdev is set to DOWN the XFRM stack's netdev listener will call
150-
xdo_dev_state_delete() and xdo_dev_state_free() on any remaining offloaded
151-
states.
188+
xdo_dev_state_delete(), xdo_dev_policy_delete(), xdo_dev_state_free() and
189+
xdo_dev_policy_free() on any remaining offloaded states.
190+
191+
Outcome of HW handling packets, the XFRM core can't count hard, soft limits.
192+
The HW/driver are responsible to perform it and provide accurate data when
193+
xdo_dev_state_update_curlft() is called. In case of one of these limits
194+
occuried, the driver needs to call to xfrm_state_check_expire() to make sure
195+
that XFRM performs rekeying sequence.

drivers/net/ethernet/chelsio/inline_crypto/ch_ipsec/chcr_ipsec.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ static int ch_ipsec_xfrm_add_state(struct xfrm_state *x)
283283
pr_debug("Cannot offload xfrm states with geniv other than seqiv\n");
284284
return -EINVAL;
285285
}
286+
if (x->xso.type != XFRM_DEV_OFFLOAD_CRYPTO) {
287+
pr_debug("Unsupported xfrm offload\n");
288+
return -EINVAL;
289+
}
286290

287291
sa_entry = kzalloc(sizeof(*sa_entry), GFP_KERNEL);
288292
if (!sa_entry) {

drivers/net/ethernet/intel/ixgbe/ixgbe_ipsec.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,11 @@ static int ixgbe_ipsec_add_sa(struct xfrm_state *xs)
585585
return -EINVAL;
586586
}
587587

588+
if (xs->xso.type != XFRM_DEV_OFFLOAD_CRYPTO) {
589+
netdev_err(dev, "Unsupported ipsec offload type\n");
590+
return -EINVAL;
591+
}
592+
588593
if (xs->xso.dir == XFRM_DEV_OFFLOAD_IN) {
589594
struct rx_sa rsa;
590595

drivers/net/ethernet/intel/ixgbevf/ipsec.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@ static int ixgbevf_ipsec_add_sa(struct xfrm_state *xs)
280280
return -EINVAL;
281281
}
282282

283+
if (xs->xso.type != XFRM_DEV_OFFLOAD_CRYPTO) {
284+
netdev_err(dev, "Unsupported ipsec offload type\n");
285+
return -EINVAL;
286+
}
287+
283288
if (xs->xso.dir == XFRM_DEV_OFFLOAD_IN) {
284289
struct rx_sa rsa;
285290

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,4 +1245,5 @@ int mlx5e_set_vf_rate(struct net_device *dev, int vf, int min_tx_rate, int max_t
12451245
int mlx5e_get_vf_config(struct net_device *dev, int vf, struct ifla_vf_info *ivi);
12461246
int mlx5e_get_vf_stats(struct net_device *dev, int vf, struct ifla_vf_stats *vf_stats);
12471247
#endif
1248+
int mlx5e_create_mkey(struct mlx5_core_dev *mdev, u32 pdn, u32 *mkey);
12481249
#endif /* __MLX5_EN_H__ */

drivers/net/ethernet/mellanox/mlx5/core/en/fs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ enum {
8484
MLX5E_ARFS_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
8585
#endif
8686
#ifdef CONFIG_MLX5_EN_IPSEC
87-
MLX5E_ACCEL_FS_ESP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
87+
MLX5E_ACCEL_FS_POL_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
88+
MLX5E_ACCEL_FS_ESP_FT_LEVEL,
8889
MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL,
8990
#endif
9091
};

drivers/net/ethernet/mellanox/mlx5/core/en/tc/meter.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ mlx5e_tc_meter_modify(struct mlx5_core_dev *mdev,
162162
MLX5_ACCESS_ASO_OPC_MOD_FLOW_METER);
163163

164164
aso_ctrl = &aso_wqe->aso_ctrl;
165-
memset(aso_ctrl, 0, sizeof(*aso_ctrl));
166165
aso_ctrl->data_mask_mode = MLX5_ASO_DATA_MASK_MODE_BYTEWISE_64BYTE << 6;
167166
aso_ctrl->condition_1_0_operand = MLX5_ASO_ALWAYS_TRUE |
168167
MLX5_ASO_ALWAYS_TRUE << 4;

0 commit comments

Comments
 (0)