Blame SOURCES/0001-Add-a-helper-function-to-verify-64-bit-comp-mask.patch

95af3a
From abb3bf03bcb543915852204b4fdaf6a88873b51a Mon Sep 17 00:00:00 2001
95af3a
From: Noa Osherovich <noaos@mellanox.com>
95af3a
Date: Wed, 22 Nov 2017 11:11:21 +0200
95af3a
Subject: [PATCH rdma-core 1/3] Add a helper function to verify 64 bit comp
95af3a
 mask
95af3a
95af3a
The common check for a mask is as follows:
95af3a
if (comp_mask & ~COMP_MASK_SUPPORTED_VALUES)
95af3a
	return EINVAL
95af3a
95af3a
This can cause an issue when using 64 bit mask if the supported variable
95af3a
is signed 32 bit: It will be bitwise inverted and then zeroed to 64
95af3a
bits. This way wrong bits in the mask that exceed 32 bits will not raise
95af3a
an error but will be ignored.
95af3a
95af3a
Add a helper function in driver.h to be used by providers code and fix
95af3a
wrong mask checks where the above was found to be applicable.
95af3a
95af3a
Signed-off-by: Noa Osherovich <noaos@mellanox.com>
95af3a
Reviewed-by: Yishai Hadas <yishaih@mellanox.com>
95af3a
(cherry picked from commit ad4419019a006938731035a766b67838678e6048)
95af3a
---
95af3a
 libibverbs/driver.h    | 5 +++++
95af3a
 providers/mlx4/verbs.c | 4 ++--
95af3a
 providers/mlx5/verbs.c | 3 ++-
95af3a
 3 files changed, 9 insertions(+), 3 deletions(-)
95af3a
95af3a
diff --git a/libibverbs/driver.h b/libibverbs/driver.h
95af3a
index 887412de..0b2cd089 100644
95af3a
--- a/libibverbs/driver.h
95af3a
+++ b/libibverbs/driver.h
95af3a
@@ -330,6 +330,11 @@ static inline int verbs_get_srq_num(struct ibv_srq *srq, uint32_t *srq_num)
95af3a
 	return ENOSYS;
95af3a
 }
95af3a
 
95af3a
+static inline bool check_comp_mask(uint64_t input, uint64_t supported)
95af3a
+{
95af3a
+	return (input & ~supported) == 0;
95af3a
+}
95af3a
+
95af3a
 int ibv_query_gid_type(struct ibv_context *context, uint8_t port_num,
95af3a
 		       unsigned int index, enum ibv_gid_type *type);
95af3a
 #endif /* INFINIBAND_DRIVER_H */
95af3a
diff --git a/providers/mlx4/verbs.c b/providers/mlx4/verbs.c
95af3a
index b966ef2c..7c8f9da8 100644
95af3a
--- a/providers/mlx4/verbs.c
95af3a
+++ b/providers/mlx4/verbs.c
95af3a
@@ -919,8 +919,8 @@ static struct ibv_qp *create_qp_ex(struct ibv_context *context,
95af3a
 		goto err_free;
95af3a
 
95af3a
 	if (mlx4qp_attr) {
95af3a
-		if (mlx4qp_attr->comp_mask &
95af3a
-		    ~(MLX4DV_QP_INIT_ATTR_MASK_RESERVED - 1)) {
95af3a
+		if (!check_comp_mask(mlx4qp_attr->comp_mask,
95af3a
+		    MLX4DV_QP_INIT_ATTR_MASK_RESERVED - 1)) {
95af3a
 			errno = EINVAL;
95af3a
 			goto err_free;
95af3a
 		}
95af3a
diff --git a/providers/mlx5/verbs.c b/providers/mlx5/verbs.c
95af3a
index 2315a0d9..6506bc36 100644
95af3a
--- a/providers/mlx5/verbs.c
95af3a
+++ b/providers/mlx5/verbs.c
95af3a
@@ -433,7 +433,8 @@ static struct ibv_cq_ex *create_cq(struct ibv_context *context,
95af3a
 	cmd.cqe_size = cqe_sz;
95af3a
 
95af3a
 	if (mlx5cq_attr) {
95af3a
-		if (mlx5cq_attr->comp_mask & ~(MLX5DV_CQ_INIT_ATTR_MASK_RESERVED - 1)) {
95af3a
+		if (!check_comp_mask(mlx5cq_attr->comp_mask,
95af3a
+				     MLX5DV_CQ_INIT_ATTR_MASK_RESERVED - 1)) {
95af3a
 			mlx5_dbg(fp, MLX5_DBG_CQ,
95af3a
 				   "Unsupported vendor comp_mask for create_cq\n");
95af3a
 			errno = EINVAL;
95af3a
-- 
95af3a
2.12.1
95af3a