Skip to content

Commit 62f6eca

Browse files
rleonklassert
authored andcommitted
xfrm: allow state packet offload mode
Allow users to configure xfrm states with packet offload mode. The packet mode must be requested both for policy and state, and such requires us to do not implement fallback. We explicitly return an error if requested packet mode can't be configured. Reviewed-by: Raed Salem <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent d14f28b commit 62f6eca

File tree

7 files changed

+47
-5
lines changed

7 files changed

+47
-5
lines changed

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_accel/ipsec.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ static inline int mlx5e_xfrm_validate_state(struct xfrm_state *x)
253253
netdev_info(netdev, "Cannot offload xfrm states with geniv other than seqiv\n");
254254
return -EINVAL;
255255
}
256+
if (x->xso.type != XFRM_DEV_OFFLOAD_CRYPTO) {
257+
netdev_info(netdev, "Unsupported xfrm offload type\n");
258+
return -EINVAL;
259+
}
256260
return 0;
257261
}
258262

drivers/net/ethernet/netronome/nfp/crypto/ipsec.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@ static int nfp_net_xfrm_add_state(struct xfrm_state *x)
302302
return -EINVAL;
303303
}
304304

305+
if (x->xso.type != XFRM_DEV_OFFLOAD_CRYPTO) {
306+
nn_err(nn, "Unsupported xfrm offload tyoe\n");
307+
return -EINVAL;
308+
}
309+
305310
cfg->spi = ntohl(x->id.spi);
306311

307312
/* Hash/Authentication */

drivers/net/netdevsim/ipsec.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ static int nsim_ipsec_add_sa(struct xfrm_state *xs)
149149
return -EINVAL;
150150
}
151151

152+
if (xs->xso.type != XFRM_DEV_OFFLOAD_CRYPTO) {
153+
netdev_err(dev, "Unsupported ipsec offload type\n");
154+
return -EINVAL;
155+
}
156+
152157
/* find the first unused index */
153158
ret = nsim_ipsec_find_empty_idx(ipsec);
154159
if (ret < 0) {

net/xfrm/xfrm_device.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,
229229
struct xfrm_dev_offload *xso = &x->xso;
230230
xfrm_address_t *saddr;
231231
xfrm_address_t *daddr;
232+
bool is_packet_offload;
232233

233234
if (!x->type_offload) {
234235
NL_SET_ERR_MSG(extack, "Type doesn't support offload");
@@ -241,11 +242,13 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,
241242
return -EINVAL;
242243
}
243244

244-
if (xuo->flags & ~(XFRM_OFFLOAD_IPV6 | XFRM_OFFLOAD_INBOUND)) {
245+
if (xuo->flags &
246+
~(XFRM_OFFLOAD_IPV6 | XFRM_OFFLOAD_INBOUND | XFRM_OFFLOAD_PACKET)) {
245247
NL_SET_ERR_MSG(extack, "Unrecognized flags in offload request");
246248
return -EINVAL;
247249
}
248250

251+
is_packet_offload = xuo->flags & XFRM_OFFLOAD_PACKET;
249252
dev = dev_get_by_index(net, xuo->ifindex);
250253
if (!dev) {
251254
if (!(xuo->flags & XFRM_OFFLOAD_INBOUND)) {
@@ -260,7 +263,7 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,
260263
x->props.family,
261264
xfrm_smark_get(0, x));
262265
if (IS_ERR(dst))
263-
return 0;
266+
return (is_packet_offload) ? -EINVAL : 0;
264267

265268
dev = dst->dev;
266269

@@ -271,7 +274,7 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,
271274
if (!dev->xfrmdev_ops || !dev->xfrmdev_ops->xdo_dev_state_add) {
272275
xso->dev = NULL;
273276
dev_put(dev);
274-
return 0;
277+
return (is_packet_offload) ? -EINVAL : 0;
275278
}
276279

277280
if (x->props.flags & XFRM_STATE_ESN &&
@@ -291,7 +294,10 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,
291294
else
292295
xso->dir = XFRM_DEV_OFFLOAD_OUT;
293296

294-
xso->type = XFRM_DEV_OFFLOAD_CRYPTO;
297+
if (is_packet_offload)
298+
xso->type = XFRM_DEV_OFFLOAD_PACKET;
299+
else
300+
xso->type = XFRM_DEV_OFFLOAD_CRYPTO;
295301

296302
err = dev->xfrmdev_ops->xdo_dev_state_add(x);
297303
if (err) {
@@ -301,7 +307,15 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,
301307
netdev_put(dev, &xso->dev_tracker);
302308
xso->type = XFRM_DEV_OFFLOAD_UNSPECIFIED;
303309

304-
if (err != -EOPNOTSUPP) {
310+
/* User explicitly requested packet offload mode and configured
311+
* policy in addition to the XFRM state. So be civil to users,
312+
* and return an error instead of taking fallback path.
313+
*
314+
* This WARN_ON() can be seen as a documentation for driver
315+
* authors to do not return -EOPNOTSUPP in packet offload mode.
316+
*/
317+
WARN_ON(err == -EOPNOTSUPP && is_packet_offload);
318+
if (err != -EOPNOTSUPP || is_packet_offload) {
305319
NL_SET_ERR_MSG(extack, "Device failed to offload this state");
306320
return err;
307321
}

0 commit comments

Comments
 (0)