From patchwork Thu Oct 4 10:17:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 10625861 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 94A5C15A6 for ; Thu, 4 Oct 2018 10:20:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FACA28C5B for ; Thu, 4 Oct 2018 10:20:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 73F0828C64; Thu, 4 Oct 2018 10:20:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D186128C68 for ; Thu, 4 Oct 2018 10:20:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727109AbeJDRMn (ORCPT ); Thu, 4 Oct 2018 13:12:43 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:48509 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727260AbeJDRMn (ORCPT ); Thu, 4 Oct 2018 13:12:43 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from yishaih@mellanox.com) with ESMTPS (AES256-SHA encrypted); 4 Oct 2018 12:22:31 +0200 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [10.7.2.17]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w94AHnvf007367; Thu, 4 Oct 2018 13:17:49 +0300 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [127.0.0.1]) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8) with ESMTP id w94AHn7m021108; Thu, 4 Oct 2018 13:17:49 +0300 Received: (from yishaih@localhost) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8/Submit) id w94AHn0Z021107; Thu, 4 Oct 2018 13:17:49 +0300 From: Yishai Hadas To: linux-rdma@vger.kernel.org Cc: yishaih@mellanox.com, markb@mellanox.com, jgg@mellanox.com, majd@mellanox.com, guyle@mellanox.com Subject: [PATCH rdma-core 1/5] Update kernel headers Date: Thu, 4 Oct 2018 13:17:23 +0300 Message-Id: <1538648247-21003-2-git-send-email-yishaih@mellanox.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1538648247-21003-1-git-send-email-yishaih@mellanox.com> References: <1538648247-21003-1-git-send-email-yishaih@mellanox.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP To commit a7ee18bdee83 ("RDMA/mlx5: Allow creating a matcher for a NIC TX flow table") Signed-off-by: Yishai Hadas --- kernel-headers/rdma/mlx5_user_ioctl_cmds.h | 2 ++ kernel-headers/rdma/rdma_user_ioctl_cmds.h | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/kernel-headers/rdma/mlx5_user_ioctl_cmds.h b/kernel-headers/rdma/mlx5_user_ioctl_cmds.h index 75c7093..fb4a8b1 100644 --- a/kernel-headers/rdma/mlx5_user_ioctl_cmds.h +++ b/kernel-headers/rdma/mlx5_user_ioctl_cmds.h @@ -125,6 +125,7 @@ enum mlx5_ib_flow_matcher_create_attrs { MLX5_IB_ATTR_FLOW_MATCHER_MATCH_MASK, MLX5_IB_ATTR_FLOW_MATCHER_FLOW_TYPE, MLX5_IB_ATTR_FLOW_MATCHER_MATCH_CRITERIA, + MLX5_IB_ATTR_FLOW_MATCHER_FLOW_FLAGS, }; enum mlx5_ib_flow_matcher_destroy_attrs { @@ -155,6 +156,7 @@ enum mlx5_ib_create_flow_attrs { MLX5_IB_ATTR_CREATE_FLOW_DEST_QP, MLX5_IB_ATTR_CREATE_FLOW_DEST_DEVX, MLX5_IB_ATTR_CREATE_FLOW_MATCHER, + MLX5_IB_ATTR_CREATE_FLOW_ARR_FLOW_ACTIONS, }; enum mlx5_ib_destoy_flow_attrs { diff --git a/kernel-headers/rdma/rdma_user_ioctl_cmds.h b/kernel-headers/rdma/rdma_user_ioctl_cmds.h index 24800c6..06c34d9 100644 --- a/kernel-headers/rdma/rdma_user_ioctl_cmds.h +++ b/kernel-headers/rdma/rdma_user_ioctl_cmds.h @@ -53,7 +53,7 @@ enum { struct ib_uverbs_attr { __u16 attr_id; /* command specific type attribute */ - __u16 len; /* only for pointers */ + __u16 len; /* only for pointers and IDRs array */ __u16 flags; /* combination of UVERBS_ATTR_F_XXXX */ union { struct { @@ -63,7 +63,10 @@ struct ib_uverbs_attr { __u16 reserved; } attr_data; union { - /* Used by PTR_IN/OUT, ENUM_IN and IDR */ + /* + * ptr to command, inline data, idr/fd or + * ptr to __u32 array of IDRs + */ __aligned_u64 data; /* Used by FD_IN and FD_OUT */ __s64 data_s64; From patchwork Thu Oct 4 10:17:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 10625851 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 49BBC1515 for ; Thu, 4 Oct 2018 10:20:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2FAF628C78 for ; Thu, 4 Oct 2018 10:20:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2199528C79; Thu, 4 Oct 2018 10:20:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F54428C5B for ; Thu, 4 Oct 2018 10:20:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727150AbeJDRMl (ORCPT ); Thu, 4 Oct 2018 13:12:41 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:48489 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727109AbeJDRMl (ORCPT ); Thu, 4 Oct 2018 13:12:41 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from yishaih@mellanox.com) with ESMTPS (AES256-SHA encrypted); 4 Oct 2018 12:22:32 +0200 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [10.7.2.17]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w94AHnBc007370; Thu, 4 Oct 2018 13:17:49 +0300 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [127.0.0.1]) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8) with ESMTP id w94AHnPf021112; Thu, 4 Oct 2018 13:17:49 +0300 Received: (from yishaih@localhost) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8/Submit) id w94AHnWV021111; Thu, 4 Oct 2018 13:17:49 +0300 From: Yishai Hadas To: linux-rdma@vger.kernel.org Cc: yishaih@mellanox.com, markb@mellanox.com, jgg@mellanox.com, majd@mellanox.com, guyle@mellanox.com Subject: [PATCH rdma-core 2/5] verbs: Make fill_attr* able to handle invalid input Date: Thu, 4 Oct 2018 13:17:24 +0300 Message-Id: <1538648247-21003-3-git-send-email-yishaih@mellanox.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1538648247-21003-1-git-send-email-yishaih@mellanox.com> References: <1538648247-21003-1-git-send-email-yishaih@mellanox.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jason Gunthorpe There are several cases where input to fill_attr comes from the untrusted libibverbs user, and may not be marshalable to the kernel. We already have a case like this when passing the flow counters array, but there are a few others too. Provide a general way for the fill_attr functions to signal un-marshaled data and cause execute to automatically fail with EINVAL. Signed-off-by: Jason Gunthorpe Signed-off-by: Yishai Hadas --- libibverbs/cmd_counters.c | 7 ++----- libibverbs/cmd_ioctl.c | 11 ++++++++++- libibverbs/cmd_ioctl.h | 28 ++++++++++++++++++++-------- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/libibverbs/cmd_counters.c b/libibverbs/cmd_counters.c index ed57f25..8964fed 100644 --- a/libibverbs/cmd_counters.c +++ b/libibverbs/cmd_counters.c @@ -87,12 +87,9 @@ int ibv_cmd_read_counters(struct verbs_counters *vcounters, 3, link); - if (!is_attr_size_valid(ncounters, sizeof(uint64_t))) - return EINVAL; - fill_attr_in_obj(cmd, UVERBS_ATTR_READ_COUNTERS_HANDLE, vcounters->handle); - fill_attr_out(cmd, UVERBS_ATTR_READ_COUNTERS_BUFF, counters_value, - ncounters * sizeof(uint64_t)); + fill_attr_out_ptr_array(cmd, UVERBS_ATTR_READ_COUNTERS_BUFF, counters_value, + ncounters); fill_attr_in_uint32(cmd, UVERBS_ATTR_READ_COUNTERS_FLAGS, flags); return execute_ioctl(vcounters->counters.context, cmd); diff --git a/libibverbs/cmd_ioctl.c b/libibverbs/cmd_ioctl.c index f53f83a..c12442f 100644 --- a/libibverbs/cmd_ioctl.c +++ b/libibverbs/cmd_ioctl.c @@ -128,6 +128,14 @@ int execute_ioctl(struct ibv_context *context, struct ibv_command_buffer *cmd) { struct verbs_context *vctx = verbs_get_ctx(context); + /* + * One of the fill functions was given input that cannot be marshaled + */ + if (unlikely(cmd->buffer_error)) { + errno = EINVAL; + return errno; + } + prepare_attrs(cmd); cmd->hdr.length = sizeof(cmd->hdr) + sizeof(cmd->hdr.attrs[0]) * cmd->hdr.num_attrs; @@ -154,7 +162,8 @@ _fill_attr_in_uhw(struct ibv_command_buffer *cmd, uint16_t attr_id, { struct ib_uverbs_attr *attr = _ioctl_next_attr(cmd, attr_id); - assert(len <= UINT16_MAX); + if (unlikely(len > UINT16_MAX)) + cmd->buffer_error = 1; attr->len = len; attr->data = ioctl_ptr_to_u64(data); diff --git a/libibverbs/cmd_ioctl.h b/libibverbs/cmd_ioctl.h index 488c9e8..d58d890 100644 --- a/libibverbs/cmd_ioctl.h +++ b/libibverbs/cmd_ioctl.h @@ -40,6 +40,7 @@ #include #include #include +#include static inline uint64_t ioctl_ptr_to_u64(const void *ptr) { @@ -95,6 +96,8 @@ struct ibv_command_buffer { uint8_t uhw_out_idx; uint8_t uhw_in_headroom_dwords; uint8_t uhw_out_headroom_dwords; + + uint8_t buffer_error:1; /* * These flags control what execute_ioctl_fallback does if the kernel * does not support ioctl @@ -268,7 +271,8 @@ fill_attr_in(struct ibv_command_buffer *cmd, uint16_t attr_id, const void *data, { struct ib_uverbs_attr *attr = _ioctl_next_attr(cmd, attr_id); - assert(len <= UINT16_MAX); + if (unlikely(len > UINT16_MAX)) + cmd->buffer_error = 1; attr->len = len; if (len <= sizeof(uint64_t)) @@ -348,7 +352,9 @@ fill_attr_out(struct ibv_command_buffer *cmd, uint16_t attr_id, void *data, { struct ib_uverbs_attr *attr = _ioctl_next_attr(cmd, attr_id); - assert(len <= UINT16_MAX); + if (unlikely(len > UINT16_MAX)) + cmd->buffer_error = 1; + attr->len = len; attr->data = ioctl_ptr_to_u64(data); @@ -358,6 +364,18 @@ fill_attr_out(struct ibv_command_buffer *cmd, uint16_t attr_id, void *data, #define fill_attr_out_ptr(cmd, attr_id, ptr) \ fill_attr_out(cmd, attr_id, ptr, sizeof(*(ptr))) +/* If size*nelems overflows size_t this returns SIZE_MAX */ +static inline size_t _array_len(size_t size, size_t nelems) +{ + if (size != 0 && + SIZE_MAX / size <= nelems) + return SIZE_MAX; + return size * nelems; +} + +#define fill_attr_out_ptr_array(cmd, attr_id, ptr, nelems) \ + fill_attr_out(cmd, attr_id, ptr, _array_len(sizeof(*ptr), nelems)) + static inline size_t __check_divide(size_t val, unsigned int div) { assert(val % div == 0); @@ -376,10 +394,4 @@ fill_attr_in_enum(struct ibv_command_buffer *cmd, uint16_t attr_id, return attr; } -static inline int is_attr_size_valid(size_t num, size_t ent_size) -{ - /* check multiplication overflow */ - return (!ent_size || UINT16_MAX / ent_size >= num); -} - #endif From patchwork Thu Oct 4 10:17:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 10625853 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8D82115E8 for ; Thu, 4 Oct 2018 10:20:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 745B628C30 for ; Thu, 4 Oct 2018 10:20:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 61F3028CD3; Thu, 4 Oct 2018 10:20:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 070DC28C6E for ; Thu, 4 Oct 2018 10:20:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727234AbeJDRMo (ORCPT ); Thu, 4 Oct 2018 13:12:44 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:48517 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727256AbeJDRMo (ORCPT ); Thu, 4 Oct 2018 13:12:44 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from yishaih@mellanox.com) with ESMTPS (AES256-SHA encrypted); 4 Oct 2018 12:22:32 +0200 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [10.7.2.17]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w94AHnE2007373; Thu, 4 Oct 2018 13:17:49 +0300 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [127.0.0.1]) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8) with ESMTP id w94AHnvr021117; Thu, 4 Oct 2018 13:17:49 +0300 Received: (from yishaih@localhost) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8/Submit) id w94AHnsA021116; Thu, 4 Oct 2018 13:17:49 +0300 From: Yishai Hadas To: linux-rdma@vger.kernel.org Cc: yishaih@mellanox.com, markb@mellanox.com, jgg@mellanox.com, majd@mellanox.com, guyle@mellanox.com Subject: [PATCH rdma-core 3/5] verbs: Add IDRs array attribute type to ioctl() interface Date: Thu, 4 Oct 2018 13:17:25 +0300 Message-Id: <1538648247-21003-4-git-send-email-yishaih@mellanox.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1538648247-21003-1-git-send-email-yishaih@mellanox.com> References: <1538648247-21003-1-git-send-email-yishaih@mellanox.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Guy Levi Methods sometimes need to get a flexible set of idrs and not a strict set as can be achieved today by the conventional idr attribute. This is an idrs-array-like behavior. Since this may be popular used, we add a new IDRS_ARRAY attribute to the generic uverbs ioctl layer. This attribute is embedded in methods, like any other attributes we currently have. We align the user-space code with the respected changes in the kernel. Signed-off-by: Guy Levi Signed-off-by: Yishai Hadas --- libibverbs/cmd_ioctl.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libibverbs/cmd_ioctl.h b/libibverbs/cmd_ioctl.h index d58d890..df3dc41 100644 --- a/libibverbs/cmd_ioctl.h +++ b/libibverbs/cmd_ioctl.h @@ -394,4 +394,13 @@ fill_attr_in_enum(struct ibv_command_buffer *cmd, uint16_t attr_id, return attr; } +/* Send attributes of kernel type UVERBS_ATTR_TYPE_IDRS_ARRAY */ +static inline struct ib_uverbs_attr * +fill_attr_in_objs_arr(struct ibv_command_buffer *cmd, uint16_t attr_id, + const uint32_t *idrs_arr, size_t nelems) +{ + return fill_attr_in(cmd, attr_id, idrs_arr, + _array_len(sizeof(*idrs_arr), nelems)); +} + #endif From patchwork Thu Oct 4 10:17:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 10625857 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A33E23B73 for ; Thu, 4 Oct 2018 10:20:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DD6A28C66 for ; Thu, 4 Oct 2018 10:20:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B17E28CAC; Thu, 4 Oct 2018 10:20:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2764C28C5B for ; Thu, 4 Oct 2018 10:20:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727245AbeJDRMp (ORCPT ); Thu, 4 Oct 2018 13:12:45 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:48532 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727183AbeJDRMp (ORCPT ); Thu, 4 Oct 2018 13:12:45 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from yishaih@mellanox.com) with ESMTPS (AES256-SHA encrypted); 4 Oct 2018 12:22:32 +0200 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [10.7.2.17]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w94AHn3P007374; Thu, 4 Oct 2018 13:17:49 +0300 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [127.0.0.1]) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8) with ESMTP id w94AHn1o021121; Thu, 4 Oct 2018 13:17:49 +0300 Received: (from yishaih@localhost) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8/Submit) id w94AHn0R021120; Thu, 4 Oct 2018 13:17:49 +0300 From: Yishai Hadas To: linux-rdma@vger.kernel.org Cc: yishaih@mellanox.com, markb@mellanox.com, jgg@mellanox.com, majd@mellanox.com, guyle@mellanox.com Subject: [PATCH rdma-core 4/5] mlx5: Allow passing flow flags Date: Thu, 4 Oct 2018 13:17:26 +0300 Message-Id: <1538648247-21003-5-git-send-email-yishaih@mellanox.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1538648247-21003-1-git-send-email-yishaih@mellanox.com> References: <1538648247-21003-1-git-send-email-yishaih@mellanox.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Mark Bloch Use flags defined under enum ibv_flow_flags, this will allow creating egress matcher. Signed-off-by: Mark Bloch Signed-off-by: Yishai Hadas --- providers/mlx5/verbs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/providers/mlx5/verbs.c b/providers/mlx5/verbs.c index de731ce..41060bc 100644 --- a/providers/mlx5/verbs.c +++ b/providers/mlx5/verbs.c @@ -3665,7 +3665,7 @@ mlx5dv_create_flow_matcher(struct ibv_context *context, { DECLARE_COMMAND_BUFFER(cmd, MLX5_IB_OBJECT_FLOW_MATCHER, MLX5_IB_METHOD_FLOW_MATCHER_CREATE, - 4); + 5); struct mlx5dv_flow_matcher *flow_matcher; struct ib_uverbs_attr *handle; int ret; @@ -3695,6 +3695,9 @@ mlx5dv_create_flow_matcher(struct ibv_context *context, fill_attr_in_enum(cmd, MLX5_IB_ATTR_FLOW_MATCHER_FLOW_TYPE, IBV_FLOW_ATTR_NORMAL, &attr->priority, sizeof(attr->priority)); + if (attr->flags) + fill_attr_const_in(cmd, MLX5_IB_ATTR_FLOW_MATCHER_FLOW_FLAGS, + attr->flags); ret = execute_ioctl(context, cmd); if (ret) From patchwork Thu Oct 4 10:17:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 10625859 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DAB1C1926 for ; Thu, 4 Oct 2018 10:20:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C766428C30 for ; Thu, 4 Oct 2018 10:20:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2F2928C5B; Thu, 4 Oct 2018 10:20:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8548928C64 for ; Thu, 4 Oct 2018 10:20:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727253AbeJDRMl (ORCPT ); Thu, 4 Oct 2018 13:12:41 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:48481 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727092AbeJDRMl (ORCPT ); Thu, 4 Oct 2018 13:12:41 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from yishaih@mellanox.com) with ESMTPS (AES256-SHA encrypted); 4 Oct 2018 12:22:32 +0200 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [10.7.2.17]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w94AHn76007379; Thu, 4 Oct 2018 13:17:49 +0300 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [127.0.0.1]) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8) with ESMTP id w94AHnY5021125; Thu, 4 Oct 2018 13:17:49 +0300 Received: (from yishaih@localhost) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8/Submit) id w94AHnjQ021124; Thu, 4 Oct 2018 13:17:49 +0300 From: Yishai Hadas To: linux-rdma@vger.kernel.org Cc: yishaih@mellanox.com, markb@mellanox.com, jgg@mellanox.com, majd@mellanox.com, guyle@mellanox.com Subject: [PATCH rdma-core 5/5] mlx5: Allow passing flow action in mlx5dv_create_flow Date: Thu, 4 Oct 2018 13:17:27 +0300 Message-Id: <1538648247-21003-6-git-send-email-yishaih@mellanox.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1538648247-21003-1-git-send-email-yishaih@mellanox.com> References: <1538648247-21003-1-git-send-email-yishaih@mellanox.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Mark Bloch Add support for passing a ibv_flow_action when creating a flow steering rule. Signed-off-by: Mark Bloch Signed-off-by: Yishai Hadas --- providers/mlx5/man/CMakeLists.txt | 2 + providers/mlx5/man/mlx5dv_create_flow.3.md | 76 ++++++++++++++++++ providers/mlx5/man/mlx5dv_create_flow_matcher.3.md | 90 ++++++++++++++++++++++ providers/mlx5/verbs.c | 56 ++++++++++---- 4 files changed, 209 insertions(+), 15 deletions(-) create mode 100644 providers/mlx5/man/mlx5dv_create_flow.3.md create mode 100644 providers/mlx5/man/mlx5dv_create_flow_matcher.3.md diff --git a/providers/mlx5/man/CMakeLists.txt b/providers/mlx5/man/CMakeLists.txt index 502bbd4..5765691 100644 --- a/providers/mlx5/man/CMakeLists.txt +++ b/providers/mlx5/man/CMakeLists.txt @@ -1,6 +1,8 @@ rdma_man_pages( + mlx5dv_create_flow.3.md mlx5dv_create_flow_action_modify_header.3.md mlx5dv_create_flow_action_packet_reformat.3.md + mlx5dv_create_flow_matcher.3.md mlx5dv_flow_action_esp.3.md mlx5dv_get_clock_info.3 mlx5dv_init_obj.3 diff --git a/providers/mlx5/man/mlx5dv_create_flow.3.md b/providers/mlx5/man/mlx5dv_create_flow.3.md new file mode 100644 index 0000000..8d0169a --- /dev/null +++ b/providers/mlx5/man/mlx5dv_create_flow.3.md @@ -0,0 +1,76 @@ +--- +layout: page +title: mlx5dv_create_flow +section: 3 +tagline: Verbs +date: 2018-9-19 +header: "mlx5 Programmer's Manual" +footer: mlx5 +--- + +# NAME +mlx5dv_create_flow - creates a steering flow rule + +# SYNOPSIS + +```c +#include + +struct ibv_flow * +mlx5dv_create_flow(struct mlx5dv_flow_matcher *flow_matcher, + struct mlx5dv_flow_match_parameters *match_value, + size_t num_actions, + struct mlx5dv_flow_action_attr actions_attr[]) +``` + + +# DESCRIPTION +**mlx5dv_create_flow()** creates a steering flow rule with the ability +to specify specific driver properties. + +# ARGUMENTS + +Please see *mlx5dv_create_flow_matcher(3)* for *flow_matcher* and *match_value*. + +## num_actions + Specifies how many actions are passed in *actions_attr* + +## actions_attr +```c +struct mlx5dv_flow_action_attr { + enum mlx5dv_flow_action_type type; + union { + struct ibv_qp *qp; + struct ibv_counters *counter; + struct ibv_flow_action *action; + uint32_t tag_value; + }; +}; +``` + +## type + MLX5DV_FLOW_ACTION_DEST_IBV_QP + The QP passed will receive the matched packets. + MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION + The flow action to be applied. + +## qp + QP passed, to be used with *type* *MLX5DV_FLOW_ACTION_DEST_IBV_QP*. + +## action + Flow action, to be used with *type* *MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION* + see *mlx5dv_create_flow_action_modify_header(3)* and *mlx5dv_create_flow_action_packet_reformat(3)*. + +# RETURN VALUE + +**mlx5dv_create_flow** +returns a pointer to the created flow rule, or NULL on failure. + +# SEE ALSO + +*mlx5dv_create_flow_action_modify_header(3)*, *mlx5dv_create_flow_action_packet_reformat(3)*, +*mlx5dv_create_flow_matcher(3)*, *mlx5dv_create_qp(3)*, *ibv_create_qp_ex(3)* + +# AUTHOR + +Mark Bloch diff --git a/providers/mlx5/man/mlx5dv_create_flow_matcher.3.md b/providers/mlx5/man/mlx5dv_create_flow_matcher.3.md new file mode 100644 index 0000000..3894d01 --- /dev/null +++ b/providers/mlx5/man/mlx5dv_create_flow_matcher.3.md @@ -0,0 +1,90 @@ +--- +layout: page +title: mlx5dv_create_flow_matcher +section: 3 +tagline: Verbs +date: 2018-9-19 +header: "mlx5 Programmer's Manual" +footer: mlx5 +--- + +# NAME +mlx5dv_create_flow_matcher - creates a matcher to be used with *mlx5dv_create_flow(3)* + +# SYNOPSIS + +```c +#include + +struct mlx5dv_flow_matcher * +mlx5dv_create_flow_matcher(struct ibv_context *context, + struct mlx5dv_flow_matcher_attr *attr) +``` + +# DESCRIPTION + +**mlx5dv_create_flow_matcher()** creates a flow matcher (mask) to be used +with *mlx5dv_create_flow(3)*. + +# ARGUMENTS + +Please see *ibv_open_device(3)* for *context*. + +## attr +```c +struct mlx5dv_flow_matcher_attr { + enum ibv_flow_attr_type type; + uint32_t flags; /* From enum ibv_flow_flags */ + uint16_t priority; + uint8_t match_criteria_enable; /* Device spec format */ + struct mlx5dv_flow_match_parameters *match_mask; + uint64_t comp_mask; +}; +``` + +## type + Type of matcher to be created: + IBV_FLOW_ATTR_NORMAL: + Normal rule according to specification. + +## flags + special flags to control rule: + 0: + Nothing or zero value means matcher will store ingress flow rules. + IBV_FLOW_ATTR_FLAGS_EGRESS: + Specified this matcher will store egress flow rules. + +## priority + See *ibv_create_flow(3)*. + +## match_criteria_enable + What match criteria is configured in *match_mask*, passed in + device spec format. + +## match_mask +```c +struct mlx5dv_flow_match_parameters { + size_t match_sz; + uint64_t match_buf[]; /* Device spec format */ +}; +``` + +## match_sz + Size in bytes of *match_buf*. + +## match_buf + Set which mask to be used, passed in + device spec format. + +# RETURN VALUE + +**mlx5dv_create_flow_matcher** +returns a pointer to *mlx5dv_flow_matcher*, or NULL on failure + +# SEE ALSO + +*ibv_open_device(3)*, *ibv_create_flow(3)* + +# AUTHOR + +Mark Bloch diff --git a/providers/mlx5/verbs.c b/providers/mlx5/verbs.c index 41060bc..81e93dd 100644 --- a/providers/mlx5/verbs.c +++ b/providers/mlx5/verbs.c @@ -3731,25 +3731,26 @@ int mlx5dv_destroy_flow_matcher(struct mlx5dv_flow_matcher *flow_matcher) return 0; } +#define CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED 8 struct ibv_flow * mlx5dv_create_flow(struct mlx5dv_flow_matcher *flow_matcher, struct mlx5dv_flow_match_parameters *match_value, size_t num_actions, struct mlx5dv_flow_action_attr actions_attr[]) { + uint32_t flow_actions[CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED]; + struct verbs_flow_action *vaction; + int num_flow_actions = 0; struct mlx5_flow *mflow; + bool have_qp = false; int ret; + int i; DECLARE_COMMAND_BUFFER(cmd, UVERBS_OBJECT_FLOW, MLX5_IB_METHOD_CREATE_FLOW, - 4); + 5); struct ib_uverbs_attr *handle; enum mlx5dv_flow_action_type type; - if (num_actions != 1) { - errno = EOPNOTSUPP; - return NULL; - } - mflow = calloc(1, sizeof(*mflow)); if (!mflow) { errno = ENOMEM; @@ -3762,17 +3763,42 @@ mlx5dv_create_flow(struct mlx5dv_flow_matcher *flow_matcher, match_value->match_sz); fill_attr_in_obj(cmd, MLX5_IB_ATTR_CREATE_FLOW_MATCHER, flow_matcher->handle); - type = actions_attr[0].type; - switch (type) { - case MLX5DV_FLOW_ACTION_DEST_IBV_QP: - fill_attr_in_obj(cmd, MLX5_IB_ATTR_CREATE_FLOW_DEST_QP, - actions_attr[0].qp->handle); - break; - default: - errno = EOPNOTSUPP; - goto err; + for (i = 0; i < num_actions; i++) { + type = actions_attr[i].type; + switch (type) { + case MLX5DV_FLOW_ACTION_DEST_IBV_QP: + if (have_qp) { + errno = EOPNOTSUPP; + goto err; + } + fill_attr_in_obj(cmd, MLX5_IB_ATTR_CREATE_FLOW_DEST_QP, + actions_attr[i].qp->handle); + have_qp = true; + break; + case MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION: + if (num_flow_actions == + CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED) { + errno = EOPNOTSUPP; + goto err; + } + vaction = container_of(actions_attr[i].action, + struct verbs_flow_action, + action); + + flow_actions[num_flow_actions] = vaction->handle; + num_flow_actions++; + break; + default: + errno = EOPNOTSUPP; + goto err; + } } + if (num_flow_actions) + fill_attr_in_objs_arr(cmd, + MLX5_IB_ATTR_CREATE_FLOW_ARR_FLOW_ACTIONS, + flow_actions, + num_flow_actions); ret = execute_ioctl(flow_matcher->context, cmd); if (ret) goto err;