Skip to content

Commit c6475a0

Browse files
aviadyejgunthorpe
authored andcommitted
IB/mlx5: Add implementation for create and destroy action_xfrm
Adding implementation in mlx5 driver to create and destroy action_xfrm object. This merely call the accel layer. A user may pass MLX5_IB_XFRM_FLAGS_REQUIRE_METADATA flag which states that [s]he expects a metadata header to be added to the payload. This header represents information regarding the transformation's state. Reviewed-by: Yishai Hadas <yishaih@mellanox.com> Signed-off-by: Matan Barak <matanb@mellanox.com> Signed-off-by: Aviad Yehezkel <aviadye@mellanox.com> Signed-off-by: Leon Romanovsky <leonro@mellanox.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
1 parent 56ab0b3 commit c6475a0

4 files changed

Lines changed: 235 additions & 1 deletion

File tree

‎drivers/infiniband/hw/mlx5/main.c‎

Lines changed: 132 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@
6060
#include "ib_rep.h"
6161
#include "cmd.h"
6262
#include <linux/mlx5/fs_helpers.h>
63+
#include <linux/mlx5/accel.h>
6364
#include <rdma/uverbs_std_types.h>
65+
#include <rdma/mlx5_user_ioctl_verbs.h>
66+
#include <rdma/mlx5_user_ioctl_cmds.h>
6467

6568
#define UVERBS_MODULE_NAME mlx5_ib
6669
#include <rdma/uverbs_named_ioctl.h>
@@ -3103,6 +3106,122 @@ static struct ib_flow *mlx5_ib_create_flow(struct ib_qp *qp,
31033106
return ERR_PTR(err);
31043107
}
31053108

3109+
static u32 mlx5_ib_flow_action_flags_to_accel_xfrm_flags(u32 mlx5_flags)
3110+
{
3111+
u32 flags = 0;
3112+
3113+
if (mlx5_flags & MLX5_IB_UAPI_FLOW_ACTION_FLAGS_REQUIRE_METADATA)
3114+
flags |= MLX5_ACCEL_XFRM_FLAG_REQUIRE_METADATA;
3115+
3116+
return flags;
3117+
}
3118+
3119+
#define MLX5_FLOW_ACTION_ESP_CREATE_LAST_SUPPORTED MLX5_IB_UAPI_FLOW_ACTION_FLAGS_REQUIRE_METADATA
3120+
static struct ib_flow_action *
3121+
mlx5_ib_create_flow_action_esp(struct ib_device *device,
3122+
const struct ib_flow_action_attrs_esp *attr,
3123+
struct uverbs_attr_bundle *attrs)
3124+
{
3125+
struct mlx5_ib_dev *mdev = to_mdev(device);
3126+
struct ib_uverbs_flow_action_esp_keymat_aes_gcm *aes_gcm;
3127+
struct mlx5_accel_esp_xfrm_attrs accel_attrs = {};
3128+
struct mlx5_ib_flow_action *action;
3129+
u64 action_flags;
3130+
u64 flags;
3131+
int err = 0;
3132+
3133+
if (IS_UVERBS_COPY_ERR(uverbs_copy_from(&action_flags, attrs,
3134+
MLX5_IB_ATTR_CREATE_FLOW_ACTION_FLAGS)))
3135+
return ERR_PTR(-EFAULT);
3136+
3137+
if (action_flags >= (MLX5_FLOW_ACTION_ESP_CREATE_LAST_SUPPORTED << 1))
3138+
return ERR_PTR(-EOPNOTSUPP);
3139+
3140+
flags = mlx5_ib_flow_action_flags_to_accel_xfrm_flags(action_flags);
3141+
3142+
/* We current only support a subset of the standard features. Only a
3143+
* keymat of type AES_GCM, with icv_len == 16, iv_algo == SEQ and esn
3144+
* (with overlap). Full offload mode isn't supported.
3145+
*/
3146+
if (!attr->keymat || attr->replay || attr->encap ||
3147+
attr->spi || attr->seq || attr->tfc_pad ||
3148+
attr->hard_limit_pkts ||
3149+
(attr->flags & ~(IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED |
3150+
IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ENCRYPT)))
3151+
return ERR_PTR(-EOPNOTSUPP);
3152+
3153+
if (attr->keymat->protocol !=
3154+
IB_UVERBS_FLOW_ACTION_ESP_KEYMAT_AES_GCM)
3155+
return ERR_PTR(-EOPNOTSUPP);
3156+
3157+
aes_gcm = &attr->keymat->keymat.aes_gcm;
3158+
3159+
if (aes_gcm->icv_len != 16 ||
3160+
aes_gcm->iv_algo != IB_UVERBS_FLOW_ACTION_IV_ALGO_SEQ)
3161+
return ERR_PTR(-EOPNOTSUPP);
3162+
3163+
action = kmalloc(sizeof(*action), GFP_KERNEL);
3164+
if (!action)
3165+
return ERR_PTR(-ENOMEM);
3166+
3167+
action->esp_aes_gcm.ib_flags = attr->flags;
3168+
memcpy(&accel_attrs.keymat.aes_gcm.aes_key, &aes_gcm->aes_key,
3169+
sizeof(accel_attrs.keymat.aes_gcm.aes_key));
3170+
accel_attrs.keymat.aes_gcm.key_len = aes_gcm->key_len * 8;
3171+
memcpy(&accel_attrs.keymat.aes_gcm.salt, &aes_gcm->salt,
3172+
sizeof(accel_attrs.keymat.aes_gcm.salt));
3173+
memcpy(&accel_attrs.keymat.aes_gcm.seq_iv, &aes_gcm->iv,
3174+
sizeof(accel_attrs.keymat.aes_gcm.seq_iv));
3175+
accel_attrs.keymat.aes_gcm.icv_len = aes_gcm->icv_len * 8;
3176+
accel_attrs.keymat.aes_gcm.iv_algo = MLX5_ACCEL_ESP_AES_GCM_IV_ALGO_SEQ;
3177+
accel_attrs.keymat_type = MLX5_ACCEL_ESP_KEYMAT_AES_GCM;
3178+
3179+
accel_attrs.esn = attr->esn;
3180+
if (attr->flags & IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED)
3181+
accel_attrs.flags |= MLX5_ACCEL_ESP_FLAGS_ESN_TRIGGERED;
3182+
if (attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW)
3183+
accel_attrs.flags |= MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP;
3184+
3185+
if (attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ENCRYPT)
3186+
accel_attrs.action |= MLX5_ACCEL_ESP_ACTION_ENCRYPT;
3187+
3188+
action->esp_aes_gcm.ctx =
3189+
mlx5_accel_esp_create_xfrm(mdev->mdev, &accel_attrs, flags);
3190+
if (IS_ERR(action->esp_aes_gcm.ctx)) {
3191+
err = PTR_ERR(action->esp_aes_gcm.ctx);
3192+
goto err_parse;
3193+
}
3194+
3195+
action->esp_aes_gcm.ib_flags = attr->flags;
3196+
3197+
return &action->ib_action;
3198+
3199+
err_parse:
3200+
kfree(action);
3201+
return ERR_PTR(err);
3202+
}
3203+
3204+
static int mlx5_ib_destroy_flow_action(struct ib_flow_action *action)
3205+
{
3206+
struct mlx5_ib_flow_action *maction = to_mflow_act(action);
3207+
3208+
switch (action->type) {
3209+
case IB_FLOW_ACTION_ESP:
3210+
/*
3211+
* We only support aes_gcm by now, so we implicitly know this is
3212+
* the underline crypto.
3213+
*/
3214+
mlx5_accel_esp_destroy_xfrm(maction->esp_aes_gcm.ctx);
3215+
break;
3216+
default:
3217+
WARN_ON(true);
3218+
break;
3219+
}
3220+
3221+
kfree(maction);
3222+
return 0;
3223+
}
3224+
31063225
static int mlx5_ib_mcg_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
31073226
{
31083227
struct mlx5_ib_dev *dev = to_mdev(ibqp->device);
@@ -4548,13 +4667,23 @@ static void mlx5_ib_cleanup_multiport_master(struct mlx5_ib_dev *dev)
45484667
mlx5_nic_vport_disable_roce(dev->mdev);
45494668
}
45504669

4551-
#define NUM_TREES 0
4670+
ADD_UVERBS_ATTRIBUTES_SIMPLE(mlx5_ib_flow_action, UVERBS_OBJECT_FLOW_ACTION,
4671+
UVERBS_METHOD_FLOW_ACTION_ESP_CREATE,
4672+
&UVERBS_ATTR_PTR_IN(MLX5_IB_ATTR_CREATE_FLOW_ACTION_FLAGS,
4673+
UVERBS_ATTR_TYPE(u64),
4674+
UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY)));
4675+
4676+
#define NUM_TREES 1
45524677
static int populate_specs_root(struct mlx5_ib_dev *dev)
45534678
{
45544679
const struct uverbs_object_tree_def *default_root[NUM_TREES + 1] = {
45554680
uverbs_default_get_objects()};
45564681
size_t num_trees = 1;
45574682

4683+
if (mlx5_accel_ipsec_device_caps(dev->mdev) & MLX5_ACCEL_IPSEC_CAP_DEVICE &&
4684+
!WARN_ON(num_trees >= ARRAY_SIZE(default_root)))
4685+
default_root[num_trees++] = &mlx5_ib_flow_action;
4686+
45584687
dev->ib_dev.specs_root =
45594688
uverbs_alloc_spec_tree(num_trees, default_root);
45604689

@@ -4796,6 +4925,8 @@ int mlx5_ib_stage_caps_init(struct mlx5_ib_dev *dev)
47964925
dev->ib_dev.uverbs_ex_cmd_mask |=
47974926
(1ull << IB_USER_VERBS_EX_CMD_CREATE_FLOW) |
47984927
(1ull << IB_USER_VERBS_EX_CMD_DESTROY_FLOW);
4928+
dev->ib_dev.create_flow_action_esp = mlx5_ib_create_flow_action_esp;
4929+
dev->ib_dev.destroy_flow_action = mlx5_ib_destroy_flow_action;
47994930
dev->ib_dev.driver_id = RDMA_DRIVER_MLX5;
48004931

48014932
err = init_node_data(dev);

‎drivers/infiniband/hw/mlx5/mlx5_ib.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,16 @@ struct mlx5_ib_multiport_info {
772772
bool unaffiliate;
773773
};
774774

775+
struct mlx5_ib_flow_action {
776+
struct ib_flow_action ib_action;
777+
union {
778+
struct {
779+
u64 ib_flags;
780+
struct mlx5_accel_esp_xfrm *ctx;
781+
} esp_aes_gcm;
782+
};
783+
};
784+
775785
struct mlx5_ib_dev {
776786
struct ib_device ib_dev;
777787
struct mlx5_core_dev *mdev;
@@ -895,6 +905,12 @@ static inline struct mlx5_ib_mw *to_mmw(struct ib_mw *ibmw)
895905
return container_of(ibmw, struct mlx5_ib_mw, ibmw);
896906
}
897907

908+
static inline struct mlx5_ib_flow_action *
909+
to_mflow_act(struct ib_flow_action *ibact)
910+
{
911+
return container_of(ibact, struct mlx5_ib_flow_action, ib_action);
912+
}
913+
898914
int mlx5_ib_db_map_user(struct mlx5_ib_ucontext *context, unsigned long virt,
899915
struct mlx5_db *db);
900916
void mlx5_ib_db_unmap_user(struct mlx5_ib_ucontext *context, struct mlx5_db *db);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2018, Mellanox Technologies inc. All rights reserved.
3+
*
4+
* This software is available to you under a choice of one of two
5+
* licenses. You may choose to be licensed under the terms of the GNU
6+
* General Public License (GPL) Version 2, available from the file
7+
* COPYING in the main directory of this source tree, or the
8+
* OpenIB.org BSD license below:
9+
*
10+
* Redistribution and use in source and binary forms, with or
11+
* without modification, are permitted provided that the following
12+
* conditions are met:
13+
*
14+
* - Redistributions of source code must retain the above
15+
* copyright notice, this list of conditions and the following
16+
* disclaimer.
17+
*
18+
* - Redistributions in binary form must reproduce the above
19+
* copyright notice, this list of conditions and the following
20+
* disclaimer in the documentation and/or other materials
21+
* provided with the distribution.
22+
*
23+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30+
* SOFTWARE.
31+
*/
32+
33+
#ifndef MLX5_USER_IOCTL_CMDS_H
34+
#define MLX5_USER_IOCTL_CMDS_H
35+
36+
#include <rdma/ib_user_ioctl_cmds.h>
37+
38+
enum mlx5_ib_create_flow_action_attrs {
39+
/* This attribute belong to the driver namespace */
40+
MLX5_IB_ATTR_CREATE_FLOW_ACTION_FLAGS = (1U << UVERBS_ID_NS_SHIFT),
41+
};
42+
43+
#endif
44+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2018, Mellanox Technologies inc. All rights reserved.
3+
*
4+
* This software is available to you under a choice of one of two
5+
* licenses. You may choose to be licensed under the terms of the GNU
6+
* General Public License (GPL) Version 2, available from the file
7+
* COPYING in the main directory of this source tree, or the
8+
* OpenIB.org BSD license below:
9+
*
10+
* Redistribution and use in source and binary forms, with or
11+
* without modification, are permitted provided that the following
12+
* conditions are met:
13+
*
14+
* - Redistributions of source code must retain the above
15+
* copyright notice, this list of conditions and the following
16+
* disclaimer.
17+
*
18+
* - Redistributions in binary form must reproduce the above
19+
* copyright notice, this list of conditions and the following
20+
* disclaimer in the documentation and/or other materials
21+
* provided with the distribution.
22+
*
23+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30+
* SOFTWARE.
31+
*/
32+
33+
#ifndef MLX5_USER_IOCTL_VERBS_H
34+
#define MLX5_USER_IOCTL_VERBS_H
35+
36+
#include <linux/types.h>
37+
38+
enum mlx5_ib_uapi_flow_action_flags {
39+
MLX5_IB_UAPI_FLOW_ACTION_FLAGS_REQUIRE_METADATA = 1 << 0,
40+
};
41+
42+
#endif
43+

0 commit comments

Comments
 (0)