From patchwork Wed Nov 22 12:11:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 10070357 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BE80F603FA for ; Wed, 22 Nov 2017 12:11:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA10D29C2D for ; Wed, 22 Nov 2017 12:11:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E70029C34; Wed, 22 Nov 2017 12:11:53 +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=-6.9 required=2.0 tests=BAYES_00, 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 2C8A629C2D for ; Wed, 22 Nov 2017 12:11:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752556AbdKVMLv (ORCPT ); Wed, 22 Nov 2017 07:11:51 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:47128 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752322AbdKVMLu (ORCPT ); Wed, 22 Nov 2017 07:11:50 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from yishaih@mellanox.com) with ESMTPS (AES256-SHA encrypted); 22 Nov 2017 14:11:45 +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 vAMCBj8m029427; Wed, 22 Nov 2017 14:11:45 +0200 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 vAMCBjXm001683; Wed, 22 Nov 2017 14:11:45 +0200 Received: (from yishaih@localhost) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8/Submit) id vAMCBjdY001678; Wed, 22 Nov 2017 14:11:45 +0200 From: Yishai Hadas To: linux-rdma@vger.kernel.org Cc: yishaih@mellanox.com, noaos@mellanox.com, majd@mellanox.com Subject: [PATCH V1 rdma-core 1/3] Add a helper function to verify 64 bit comp mask Date: Wed, 22 Nov 2017 14:11:06 +0200 Message-Id: <1511352668-1441-2-git-send-email-yishaih@mellanox.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1511352668-1441-1-git-send-email-yishaih@mellanox.com> References: <1511352668-1441-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: Noa Osherovich The common check for a mask is as follows: if (comp_mask & ~COMP_MASK_SUPPORTED_VALUES) return EINVAL This can cause an issue when using 64 bit mask if the supported variable is signed 32 bit: It will be bitwise inverted and then zeroed to 64 bits. This way wrong bits in the mask that exceed 32 bits will not raise an error but will be ignored. Add a helper function in driver.h to be used by providers code and fix wrong mask checks where the above was found to be applicable. Signed-off-by: Noa Osherovich Reviewed-by: Yishai Hadas --- libibverbs/driver.h | 5 +++++ providers/mlx4/verbs.c | 4 ++-- providers/mlx5/verbs.c | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/libibverbs/driver.h b/libibverbs/driver.h index 4b1e5dd..24b087a 100644 --- a/libibverbs/driver.h +++ b/libibverbs/driver.h @@ -400,6 +400,11 @@ static inline int verbs_get_srq_num(struct ibv_srq *srq, uint32_t *srq_num) return ENOSYS; } +static inline bool check_comp_mask(uint64_t input, uint64_t supported) +{ + return (input & ~supported) == 0; +} + int ibv_query_gid_type(struct ibv_context *context, uint8_t port_num, unsigned int index, enum ibv_gid_type *type); #endif /* INFINIBAND_DRIVER_H */ diff --git a/providers/mlx4/verbs.c b/providers/mlx4/verbs.c index 8a2773f..ec02bd4 100644 --- a/providers/mlx4/verbs.c +++ b/providers/mlx4/verbs.c @@ -922,8 +922,8 @@ static struct ibv_qp *create_qp_ex(struct ibv_context *context, goto err_free; if (mlx4qp_attr) { - if (mlx4qp_attr->comp_mask & - ~(MLX4DV_QP_INIT_ATTR_MASK_RESERVED - 1)) { + if (!check_comp_mask(mlx4qp_attr->comp_mask, + MLX4DV_QP_INIT_ATTR_MASK_RESERVED - 1)) { errno = EINVAL; goto err_free; } diff --git a/providers/mlx5/verbs.c b/providers/mlx5/verbs.c index 19fc947..9187119 100644 --- a/providers/mlx5/verbs.c +++ b/providers/mlx5/verbs.c @@ -434,7 +434,8 @@ static struct ibv_cq_ex *create_cq(struct ibv_context *context, cmd.cqe_size = cqe_sz; if (mlx5cq_attr) { - if (mlx5cq_attr->comp_mask & ~(MLX5DV_CQ_INIT_ATTR_MASK_RESERVED - 1)) { + if (!check_comp_mask(mlx5cq_attr->comp_mask, + MLX5DV_CQ_INIT_ATTR_MASK_RESERVED - 1)) { mlx5_dbg(fp, MLX5_DBG_CQ, "Unsupported vendor comp_mask for create_cq\n"); errno = EINVAL;