[PATCH rdma-core 04/10] verbs: Consolidate duplicate code in create_rwq_ind_table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Jason Gunthorpe <jgg@xxxxxxxxxxxx>

The usual pattern for an _ex API with a core flex array is to have the
core code allocate the variable length command buffer and memcpy the udata
into the end of it. Tidy this up to follow the usual pattern.

Since no drivers have udata here don't bother passing anything from the
driver.

Also update the PABI to v22.

Signed-off-by: Jason Gunthorpe <jgg@xxxxxxxxxxxx>
---
 CMakeLists.txt             |  3 ++-
 debian/control             |  2 +-
 debian/libibverbs1.symbols |  2 +-
 libibverbs/cmd.c           | 33 +++++++++++++--------------------
 libibverbs/driver.h        |  4 ----
 providers/mlx4/verbs.c     | 25 +++----------------------
 providers/mlx5/verbs.c     | 24 +++---------------------
 7 files changed, 23 insertions(+), 70 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index ca5d49d7301cd2..09cf3a123feb48 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -59,8 +59,9 @@ set(PACKAGE_NAME "RDMA")
 # See Documentation/versioning.md
 set(PACKAGE_VERSION "22.0")
 # When this is changed the values in these files need changing too:
+#   debian/control
 #   debian/libibverbs1.symbols
-set(IBVERBS_PABI_VERSION "21")
+set(IBVERBS_PABI_VERSION "22")
 set(IBVERBS_PROVIDER_SUFFIX "-rdmav${IBVERBS_PABI_VERSION}.so")
 
 #-------------------------
diff --git a/debian/control b/debian/control
index 92888f9aeb2cab..4debe4e961e812 100644
--- a/debian/control
+++ b/debian/control
@@ -151,7 +151,7 @@ Section: libs
 Pre-Depends: ${misc:Pre-Depends}
 Depends: adduser, ${misc:Depends}, ${shlibs:Depends}
 Recommends: ibverbs-providers
-Breaks: ibverbs-providers (<< 21~)
+Breaks: ibverbs-providers (<< 22~)
 Description: Library for direct userspace use of RDMA (InfiniBand/iWARP)
  libibverbs is a library that allows userspace processes to use RDMA
  "verbs" as described in the InfiniBand Architecture Specification and
diff --git a/debian/libibverbs1.symbols b/debian/libibverbs1.symbols
index 643435ad146097..774862e63751ae 100644
--- a/debian/libibverbs1.symbols
+++ b/debian/libibverbs1.symbols
@@ -3,7 +3,7 @@ libibverbs.so.1 libibverbs1 #MINVER#
  IBVERBS_1.0@IBVERBS_1.0 1.1.6
  IBVERBS_1.1@IBVERBS_1.1 1.1.6
  IBVERBS_1.5@IBVERBS_1.5 20
- (symver)IBVERBS_PRIVATE_21 21
+ (symver)IBVERBS_PRIVATE_22 22
  ibv_ack_async_event@IBVERBS_1.0 1.1.6
  ibv_ack_async_event@IBVERBS_1.1 1.1.6
  ibv_ack_cq_events@IBVERBS_1.0 1.1.6
diff --git a/libibverbs/cmd.c b/libibverbs/cmd.c
index af6ea5cfe12a0f..d485b934a63818 100644
--- a/libibverbs/cmd.c
+++ b/libibverbs/cmd.c
@@ -2028,38 +2028,31 @@ int ibv_cmd_destroy_wq(struct ibv_wq *wq)
 int ibv_cmd_create_rwq_ind_table(struct ibv_context *context,
 				 struct ibv_rwq_ind_table_init_attr *init_attr,
 				 struct ibv_rwq_ind_table *rwq_ind_table,
-				 struct ibv_create_rwq_ind_table *cmd,
-				 size_t cmd_core_size,
-				 size_t cmd_size,
 				 struct ib_uverbs_ex_create_rwq_ind_table_resp *resp,
-				 size_t resp_core_size,
 				 size_t resp_size)
 {
-	int err, i;
-	uint32_t required_tbl_size, alloc_tbl_size;
-	uint32_t *tbl_start;
-	int num_tbl_entries;
+	struct ibv_create_rwq_ind_table *cmd;
+	int err;
+	unsigned int i;
+	unsigned int num_tbl_entries;
+	size_t cmd_size;
 
 	if (init_attr->comp_mask >= IBV_CREATE_IND_TABLE_RESERVED)
 		return EINVAL;
 
-	alloc_tbl_size = cmd_core_size - sizeof(*cmd);
 	num_tbl_entries = 1 << init_attr->log_ind_tbl_size;
 
-	/* Data must be u64 aligned */
-	required_tbl_size = (num_tbl_entries * sizeof(uint32_t)) < sizeof(uint64_t) ?
-			sizeof(uint64_t) : (num_tbl_entries * sizeof(uint32_t));
-
-	if (alloc_tbl_size < required_tbl_size)
-		return EINVAL;
+	/* The entire message must be size aligned to 8 bytes. */
+	cmd_size = sizeof(*cmd) + num_tbl_entries * sizeof(cmd->wq_handles[0]);
+	cmd_size = (cmd_size + 7) / 8 * 8;
+	cmd = alloca(cmd_size);
 
-	tbl_start = (uint32_t *)((uint8_t *)cmd + sizeof(*cmd));
 	for (i = 0; i < num_tbl_entries; i++)
-		tbl_start[i] = init_attr->ind_tbl[i]->handle;
+		cmd->wq_handles[i] = init_attr->ind_tbl[i]->handle;
 
-	IBV_INIT_CMD_RESP_EX_V(cmd, cmd_core_size, cmd_size,
+	IBV_INIT_CMD_RESP_EX_V(cmd, cmd_size, cmd_size,
 			       CREATE_RWQ_IND_TBL, resp,
-			       resp_core_size, resp_size);
+			       sizeof(*resp), resp_size);
 	cmd->log_ind_tbl_size = init_attr->log_ind_tbl_size;
 	cmd->comp_mask = 0;
 
@@ -2069,7 +2062,7 @@ int ibv_cmd_create_rwq_ind_table(struct ibv_context *context,
 
 	(void) VALGRIND_MAKE_MEM_DEFINED(resp, resp_size);
 
-	if (resp->response_length < resp_core_size)
+	if (resp->response_length < sizeof(*resp))
 		return EINVAL;
 
 	rwq_ind_table->ind_tbl_handle = resp->ind_tbl_handle;
diff --git a/libibverbs/driver.h b/libibverbs/driver.h
index adf46c39e87112..cc879fb61335c7 100644
--- a/libibverbs/driver.h
+++ b/libibverbs/driver.h
@@ -562,11 +562,7 @@ int ibv_cmd_destroy_wq(struct ibv_wq *wq);
 int ibv_cmd_create_rwq_ind_table(struct ibv_context *context,
 				 struct ibv_rwq_ind_table_init_attr *init_attr,
 				 struct ibv_rwq_ind_table *rwq_ind_table,
-				 struct ibv_create_rwq_ind_table *cmd,
-				 size_t cmd_core_size,
-				 size_t cmd_size,
 				 struct ib_uverbs_ex_create_rwq_ind_table_resp *resp,
-				 size_t resp_core_size,
 				 size_t resp_size);
 int ibv_cmd_destroy_rwq_ind_table(struct ibv_rwq_ind_table *rwq_ind_table);
 int ibv_cmd_create_counters(struct ibv_context *context,
diff --git a/providers/mlx4/verbs.c b/providers/mlx4/verbs.c
index 5b32bd5635ee1f..a88454e405c717 100644
--- a/providers/mlx4/verbs.c
+++ b/providers/mlx4/verbs.c
@@ -1613,42 +1613,23 @@ int mlx4_destroy_wq(struct ibv_wq *ibwq)
 struct ibv_rwq_ind_table *mlx4_create_rwq_ind_table(struct ibv_context *context,
 						    struct ibv_rwq_ind_table_init_attr *init_attr)
 {
-	struct ibv_create_rwq_ind_table *cmd;
 	struct ib_uverbs_ex_create_rwq_ind_table_resp resp = {};
 	struct ibv_rwq_ind_table *ind_table;
-	uint32_t required_tbl_size;
-	unsigned int num_tbl_entries;
-	int cmd_size;
 	int err;
 
-	num_tbl_entries = 1 << init_attr->log_ind_tbl_size;
-	/* Data must be u64 aligned */
-	required_tbl_size =
-		(num_tbl_entries * sizeof(uint32_t)) < sizeof(uint64_t) ?
-			sizeof(uint64_t) : (num_tbl_entries * sizeof(uint32_t));
-
-	cmd_size = required_tbl_size + sizeof(*cmd);
-	cmd = calloc(1, cmd_size);
-	if (!cmd)
-		return NULL;
-
 	ind_table = calloc(1, sizeof(*ind_table));
 	if (!ind_table)
-		goto free_cmd;
+		return NULL;
 
-	err = ibv_cmd_create_rwq_ind_table(context, init_attr, ind_table, cmd,
-					   cmd_size, cmd_size, &resp,
-					   sizeof(resp), sizeof(resp));
+	err = ibv_cmd_create_rwq_ind_table(context, init_attr, ind_table, &resp,
+					   sizeof(resp));
 	if (err)
 		goto err;
 
-	free(cmd);
 	return ind_table;
 
 err:
 	free(ind_table);
-free_cmd:
-	free(cmd);
 	return NULL;
 }
 
diff --git a/providers/mlx5/verbs.c b/providers/mlx5/verbs.c
index 46ab8a8935ea70..22a3b9ff23c98c 100644
--- a/providers/mlx5/verbs.c
+++ b/providers/mlx5/verbs.c
@@ -3258,42 +3258,24 @@ int mlx5_destroy_flow(struct ibv_flow *flow_id)
 struct ibv_rwq_ind_table *mlx5_create_rwq_ind_table(struct ibv_context *context,
 						    struct ibv_rwq_ind_table_init_attr *init_attr)
 {
-	struct ibv_create_rwq_ind_table *cmd;
 	struct mlx5_create_rwq_ind_table_resp resp;
 	struct ibv_rwq_ind_table *ind_table;
-	uint32_t required_tbl_size;
-	int num_tbl_entries;
-	int cmd_size;
 	int err;
 
-	num_tbl_entries = 1 << init_attr->log_ind_tbl_size;
-	/* Data must be u64 aligned */
-	required_tbl_size = (num_tbl_entries * sizeof(uint32_t)) < sizeof(uint64_t) ?
-			sizeof(uint64_t) : (num_tbl_entries * sizeof(uint32_t));
-
-	cmd_size = required_tbl_size + sizeof(*cmd);
-	cmd = calloc(1, cmd_size);
-	if (!cmd)
-		return NULL;
-
 	memset(&resp, 0, sizeof(resp));
 	ind_table = calloc(1, sizeof(*ind_table));
 	if (!ind_table)
-		goto free_cmd;
+		return NULL;
 
-	err = ibv_cmd_create_rwq_ind_table(context, init_attr, ind_table, cmd,
-					   cmd_size, cmd_size, &resp.ibv_resp, sizeof(resp.ibv_resp),
-					   sizeof(resp));
+	err = ibv_cmd_create_rwq_ind_table(context, init_attr, ind_table,
+					   &resp.ibv_resp, sizeof(resp));
 	if (err)
 		goto err;
 
-	free(cmd);
 	return ind_table;
 
 err:
 	free(ind_table);
-free_cmd:
-	free(cmd);
 	return NULL;
 }
 
-- 
2.19.1




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux