From: Matan Barak <matanb@xxxxxxxxxxxx> Certain mlx5 based hardware require special data parsing when working with packets which went through ESP action. We would like to avoid unaware applications from mistakenly mishandling the data, skipping the required parsing. In order to do that, we add a new direct verb. This direct verb is identical to the ibv_create_flow_action_esp, but sets a vendor specific flag that means "I expect the data to come with special metadata". In turn, the kernel would verify that the data would indeed be returned as expected and would fail this command otherwise. Signed-off-by: Matan Barak <matanb@xxxxxxxxxxxx> Signed-off-by: Boris Pismenny <borisp@xxxxxxxxxxxx> Signed-off-by: Yishai Hadas <yishaih@xxxxxxxxxxxx> --- debian/ibverbs-providers.symbols | 1 + debian/libibverbs-dev.install | 2 + kernel-headers/CMakeLists.txt | 2 + kernel-headers/rdma/mlx5_user_ioctl_cmds.h | 44 +++++++++++++++++++ kernel-headers/rdma/mlx5_user_ioctl_verbs.h | 43 ++++++++++++++++++ providers/mlx5/CMakeLists.txt | 3 +- providers/mlx5/libmlx5.map | 5 +++ providers/mlx5/man/CMakeLists.txt | 1 + providers/mlx5/man/mlx5dv_flow_action_esp.3.md | 60 ++++++++++++++++++++++++++ providers/mlx5/mlx5_api.h | 41 ++++++++++++++++++ providers/mlx5/mlx5dv.h | 15 +++++++ providers/mlx5/verbs.c | 29 +++++++++++++ 12 files changed, 245 insertions(+), 1 deletion(-) create mode 100644 kernel-headers/rdma/mlx5_user_ioctl_cmds.h create mode 100644 kernel-headers/rdma/mlx5_user_ioctl_verbs.h create mode 100644 providers/mlx5/man/mlx5dv_flow_action_esp.3.md create mode 100644 providers/mlx5/mlx5_api.h diff --git a/debian/ibverbs-providers.symbols b/debian/ibverbs-providers.symbols index dc87c07..33e83cd 100644 --- a/debian/ibverbs-providers.symbols +++ b/debian/ibverbs-providers.symbols @@ -18,3 +18,4 @@ libmlx5.so.1 ibverbs-providers #MINVER# mlx5dv_create_qp@MLX5_1.3 16 mlx5dv_create_wq@MLX5_1.3 16 mlx5dv_get_clock_info@MLX5_1.4 17 + mlx5dv_create_flow_action_esp@MLX5_1.5 18 diff --git a/debian/libibverbs-dev.install b/debian/libibverbs-dev.install index 2fd279c..cabadf8 100644 --- a/debian/libibverbs-dev.install +++ b/debian/libibverbs-dev.install @@ -1,5 +1,7 @@ usr/include/infiniband/arch.h usr/include/infiniband/ib_user_ioctl_verbs.h +usr/include/infiniband/mlx5_api.h +usr/include/infiniband/mlx5_user_ioctl_verbs.h usr/include/infiniband/mlx4dv.h usr/include/infiniband/mlx5dv.h usr/include/infiniband/opcode.h diff --git a/kernel-headers/CMakeLists.txt b/kernel-headers/CMakeLists.txt index 011c66b..1ea9da2 100644 --- a/kernel-headers/CMakeLists.txt +++ b/kernel-headers/CMakeLists.txt @@ -11,6 +11,7 @@ publish_internal_headers(rdma rdma/ib_user_verbs.h rdma/mlx4-abi.h rdma/mlx5-abi.h + rdma/mlx5_user_ioctl_cmds.h rdma/mthca-abi.h rdma/nes-abi.h rdma/ocrdma-abi.h @@ -59,5 +60,6 @@ rdma_kernel_provider_abi( publish_headers(infiniband rdma/ib_user_ioctl_verbs.h + rdma/mlx5_user_ioctl_verbs.h ) diff --git a/kernel-headers/rdma/mlx5_user_ioctl_cmds.h b/kernel-headers/rdma/mlx5_user_ioctl_cmds.h new file mode 100644 index 0000000..69d1200 --- /dev/null +++ b/kernel-headers/rdma/mlx5_user_ioctl_cmds.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017, Mellanox Technologies inc. All rights reserved. + * + * This software is available to you under a choice of one of two + * licenses. You may choose to be licensed under the terms of the GNU + * General Public License (GPL) Version 2, available from the file + * COPYING in the main directory of this source tree, or the + * OpenIB.org BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef MLX5_USER_IOCTL_CMDS_H +#define MLX5_USER_IOCTL_CMDS_H + +#include <rdma/ib_user_ioctl_cmds.h> + +enum mlx5_ib_create_flow_action_attrs { + /* This attribute belong to the driver namespace */ + MLX5_IB_ATTR_CREATE_FLOW_ACTION_FLAGS = (1U << UVERBS_ID_NS_SHIFT), +}; + +#endif + diff --git a/kernel-headers/rdma/mlx5_user_ioctl_verbs.h b/kernel-headers/rdma/mlx5_user_ioctl_verbs.h new file mode 100644 index 0000000..fbb8bad --- /dev/null +++ b/kernel-headers/rdma/mlx5_user_ioctl_verbs.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017, Mellanox Technologies inc. All rights reserved. + * + * This software is available to you under a choice of one of two + * licenses. You may choose to be licensed under the terms of the GNU + * General Public License (GPL) Version 2, available from the file + * COPYING in the main directory of this source tree, or the + * OpenIB.org BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef MLX5_USER_IOCTL_VERBS_H +#define MLX5_USER_IOCTL_VERBS_H + +#include <linux/types.h> + +enum mlx5_ib_uapi_flow_action_flags { + MLX5_IB_UAPI_FLOW_ACTION_FLAGS_REQUIRE_METADATA = 1 << 0, +}; + +#endif + diff --git a/providers/mlx5/CMakeLists.txt b/providers/mlx5/CMakeLists.txt index a8db43d..17ccd08 100644 --- a/providers/mlx5/CMakeLists.txt +++ b/providers/mlx5/CMakeLists.txt @@ -11,7 +11,7 @@ if (MLX5_MW_DEBUG) endif() rdma_shared_provider(mlx5 libmlx5.map - 1 1.4.${PACKAGE_VERSION} + 1 1.5.${PACKAGE_VERSION} buf.c cq.c dbrec.c @@ -23,4 +23,5 @@ rdma_shared_provider(mlx5 libmlx5.map publish_headers(infiniband mlx5dv.h + mlx5_api.h ) diff --git a/providers/mlx5/libmlx5.map b/providers/mlx5/libmlx5.map index 01fb983..410cc0e 100644 --- a/providers/mlx5/libmlx5.map +++ b/providers/mlx5/libmlx5.map @@ -28,3 +28,8 @@ MLX5_1.4 { global: mlx5dv_get_clock_info; } MLX5_1.3; + +MLX5_1.5 { + global: + mlx5dv_create_flow_action_esp; +} MLX5_1.4; diff --git a/providers/mlx5/man/CMakeLists.txt b/providers/mlx5/man/CMakeLists.txt index 876b6fc..cdc7115 100644 --- a/providers/mlx5/man/CMakeLists.txt +++ b/providers/mlx5/man/CMakeLists.txt @@ -1,4 +1,5 @@ rdma_man_pages( + mlx5dv_flow_action_esp.3.md mlx5dv_get_clock_info.3 mlx5dv_init_obj.3 mlx5dv_query_device.3 diff --git a/providers/mlx5/man/mlx5dv_flow_action_esp.3.md b/providers/mlx5/man/mlx5dv_flow_action_esp.3.md new file mode 100644 index 0000000..e2e223b --- /dev/null +++ b/providers/mlx5/man/mlx5dv_flow_action_esp.3.md @@ -0,0 +1,60 @@ +--- +layout: page +title: mlx5dv_flow_action_esp(3) +section: 3 +tagline: Verbs +--- + +# NAME + +mlx5dv_flow_action_esp(3) -- Flow action esp for mlx5 provider(3) + +# SYNOPSIS + +```c +#include <infiniband/mlx5/mlx5dv.h> + +struct ibv_flow_action * +mlx5dv_create_flow_action_esp(struct ibv_context *ctx, + struct ibv_flow_action_esp_attr *esp, + struct mlx5dv_flow_action_esp *mlx5_attr); +``` + +# DESCRIPTION + +Create an IPSEC ESP flow steering action. +This verb is identical to *ibv_create_flow_action_esp* verb, but allows mlx5 specific flags. + +# ARGUMENTS + +Please see *ibv_flow_action_esp(3)* man page for *ctx* and *esp*. + +## *mlx5_attr* argument + +```c +struct mlx5dv_flow_action_esp { + uint64_t comp_mask; /* Use enum mlx5dv_flow_action_esp_mask */ + uint32_t action_flags; /* Use enum mlx5dv_flow_action_flags */ +}; +``` + +*comp_mask* +: Bitmask specifying what fields in the structure are valid (*enum mlx5dv_flow_action_esp_mask*). + +*action_flags* +: A bitwise OR of the various values described below. + + *MLX5DV_FLOW_ACTION_FLAGS_REQUIRE_METADATA*: + Each received and transmitted packet using offload is expected to carry metadata in the form of a L2 header + with ethernet type 0x8CE4, followed by 6 bytes of data and the original packet ethertype. + +# NOTE + +The ESN is expected to be placed in the IV field for egress packets. +The 64 bit sequence number is written in big-endian over the 64 bit IV field. +There is no need to call modify to update the ESN window on egress when this DV is used. + +# SEE ALSO + +*ibv_flow_action_esp(3)*, *RFC 4106* + diff --git a/providers/mlx5/mlx5_api.h b/providers/mlx5/mlx5_api.h new file mode 100644 index 0000000..b87f897 --- /dev/null +++ b/providers/mlx5/mlx5_api.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017, Mellanox Technologies inc. All rights reserved. + * + * This software is available to you under a choice of one of two + * licenses. You may choose to be licensed under the terms of the GNU + * General Public License (GPL) Version 2, available from the file + * COPYING in the main directory of this source tree, or the + * OpenIB.org BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef MLX5_API_H +#define MLX5_API_H + +#include <infiniband/mlx5_user_ioctl_verbs.h> + +#define mlx5dv_flow_action_flags mlx5_ib_uapi_flow_action_flags +#define MLX5DV_FLOW_ACTION_FLAGS_REQUIRE_METADATA MLX5_IB_UAPI_FLOW_ACTION_FLAGS_REQUIRE_METADATA + +#endif diff --git a/providers/mlx5/mlx5dv.h b/providers/mlx5/mlx5dv.h index 6a7e1d1..37aee18 100644 --- a/providers/mlx5/mlx5dv.h +++ b/providers/mlx5/mlx5dv.h @@ -45,6 +45,7 @@ #include <infiniband/verbs.h> #include <infiniband/tm_types.h> +#include <infiniband/mlx5_api.h> #ifdef __cplusplus extern "C" { @@ -171,6 +172,20 @@ struct mlx5dv_qp_init_attr { struct ibv_qp *mlx5dv_create_qp(struct ibv_context *context, struct ibv_qp_init_attr_ex *qp_attr, struct mlx5dv_qp_init_attr *mlx5_qp_attr); + +enum mlx5dv_flow_action_esp_mask { + MLX5DV_FLOW_ACTION_ESP_MASK_FLAGS = 1 << 0, +}; + +struct mlx5dv_flow_action_esp { + uint64_t comp_mask; /* Use enum mlx5dv_flow_action_esp_mask */ + uint32_t action_flags; /* Use enum mlx5dv_flow_action_flags */ +}; + +struct ibv_flow_action *mlx5dv_create_flow_action_esp(struct ibv_context *ctx, + struct ibv_flow_action_esp_attr *esp, + struct mlx5dv_flow_action_esp *mlx5_attr); + /* * Most device capabilities are exported by ibv_query_device(...), * but there is HW device-specific information which is important diff --git a/providers/mlx5/verbs.c b/providers/mlx5/verbs.c index 06f6408..99b30e8 100644 --- a/providers/mlx5/verbs.c +++ b/providers/mlx5/verbs.c @@ -46,6 +46,8 @@ #include <util/compiler.h> #include <util/mmio.h> +#include <rdma/ib_user_ioctl_cmds.h> +#include <rdma/mlx5_user_ioctl_cmds.h> #include "mlx5.h" #include "mlx5-abi.h" @@ -2998,6 +3000,33 @@ struct ibv_flow_action *mlx5_create_flow_action_esp(struct ibv_context *ctx, return _mlx5_create_flow_action_esp(ctx, attr, NULL); } +struct ibv_flow_action *mlx5dv_create_flow_action_esp(struct ibv_context *ctx, + struct ibv_flow_action_esp_attr *esp, + struct mlx5dv_flow_action_esp *mlx5_attr) +{ + DECLARE_COMMAND_BUFFER_LINK(driver_attr, UVERBS_OBJECT_FLOW_ACTION, + UVERBS_METHOD_FLOW_ACTION_ESP_CREATE, 1, + NULL); + + if (!check_comp_mask(mlx5_attr->comp_mask, + MLX5DV_FLOW_ACTION_ESP_MASK_FLAGS)) { + errno = EOPNOTSUPP; + return NULL; + } + + if (mlx5_attr->comp_mask & MLX5DV_FLOW_ACTION_ESP_MASK_FLAGS) { + if (!check_comp_mask(mlx5_attr->action_flags, + MLX5_IB_UAPI_FLOW_ACTION_FLAGS_REQUIRE_METADATA)) { + errno = EOPNOTSUPP; + return NULL; + } + fill_attr_in_uint64(driver_attr, MLX5_IB_ATTR_CREATE_FLOW_ACTION_FLAGS, + mlx5_attr->action_flags); + } + + return _mlx5_create_flow_action_esp(ctx, esp, driver_attr); +} + int mlx5_modify_flow_action_esp(struct ibv_flow_action *action, struct ibv_flow_action_esp_attr *attr) { -- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html