diff --git a/libibverbs/cmd.c b/libibverbs/cmd.c
index d759ec89c843cc..d45082eea0cab3 100644
--- a/libibverbs/cmd.c
+++ b/libibverbs/cmd.c
@@ -135,10 +135,8 @@ int ibv_cmd_query_device_ex(struct ibv_context *context,
 			    struct ibv_device_attr_ex *attr, size_t attr_size,
 			    uint64_t *raw_fw_ver,
 			    struct ibv_query_device_ex *cmd,
-			    size_t cmd_core_size,
 			    size_t cmd_size,
 			    struct ib_uverbs_ex_query_device_resp *resp,
-			    size_t resp_core_size,
 			    size_t resp_size)
 {
 	int err;
@@ -150,23 +148,16 @@ int ibv_cmd_query_device_ex(struct ibv_context *context,
 			sizeof(attr->comp_mask))
 		return EINVAL;
 
-	if (resp_core_size < offsetof(struct ib_uverbs_ex_query_device_resp,
-				      response_length) +
-			     sizeof(resp->response_length))
-		return EINVAL;
-
-	IBV_INIT_CMD_RESP_EX_V(cmd, cmd_core_size, cmd_size,
-			       QUERY_DEVICE, resp, resp_core_size,
-			       resp_size);
 	cmd->comp_mask = 0;
 	cmd->reserved = 0;
 	memset(attr->orig_attr.fw_ver, 0, sizeof(attr->orig_attr.fw_ver));
 	memset(&attr->comp_mask, 0, attr_size - sizeof(attr->orig_attr));
-	err = write(context->cmd_fd, cmd, cmd_size);
-	if (err != cmd_size)
-		return errno;
 
-	(void)VALGRIND_MAKE_MEM_DEFINED(resp, resp_size);
+	err = execute_cmd_write_ex(context, IB_USER_VERBS_EX_CMD_QUERY_DEVICE,
+				   cmd, cmd_size, resp, resp_size);
+	if (err)
+		return err;
+
 	copy_query_dev_fields(&attr->orig_attr, &resp->base, raw_fw_ver);
 	/* Report back supported comp_mask bits. For now no comp_mask bit is
 	 * defined */
@@ -886,10 +877,8 @@ int ibv_cmd_create_qp_ex2(struct ibv_context *context,
 			  struct verbs_qp *qp, int vqp_sz,
 			  struct ibv_qp_init_attr_ex *qp_attr,
 			  struct ibv_create_qp_ex *cmd,
-			  size_t cmd_core_size,
 			  size_t cmd_size,
 			  struct ib_uverbs_ex_create_qp_resp *resp,
-			  size_t resp_core_size,
 			  size_t resp_size)
 {
 	struct verbs_xrcd *vxrcd = NULL;
@@ -898,15 +887,7 @@ int ibv_cmd_create_qp_ex2(struct ibv_context *context,
 	if (qp_attr->comp_mask >= IBV_QP_INIT_ATTR_RESERVED)
 		return EINVAL;
 
-	if (resp_core_size <
-	    offsetof(struct ib_uverbs_ex_create_qp_resp, response_length) +
-	    sizeof(resp->response_length))
-		return EINVAL;
-
-	memset(cmd, 0, cmd_core_size);
-
-	IBV_INIT_CMD_RESP_EX_V(cmd, cmd_core_size, cmd_size, CREATE_QP, resp,
-			       resp_core_size, resp_size);
+	memset(&cmd->core_payload, 0, sizeof(cmd->core_payload));
 
 	err = create_qp_ex_common(qp, qp_attr, vxrcd,
 				  ibv_create_qp_ex_to_reg(cmd));
@@ -916,9 +897,6 @@ int ibv_cmd_create_qp_ex2(struct ibv_context *context,
 	if (qp_attr->comp_mask & IBV_QP_INIT_ATTR_CREATE_FLAGS) {
 		if (qp_attr->create_flags & ~CREATE_QP_EX2_SUP_CREATE_FLAGS)
 			return EINVAL;
-		if (cmd_core_size < offsetof(struct ibv_create_qp_ex, create_flags) +
-				    sizeof(qp_attr->create_flags))
-			return EINVAL;
 		cmd->create_flags = qp_attr->create_flags;
 
 		if (qp_attr->create_flags & IBV_QP_CREATE_SOURCE_QPN)
@@ -926,18 +904,14 @@ int ibv_cmd_create_qp_ex2(struct ibv_context *context,
 	}
 
 	if (qp_attr->comp_mask & IBV_QP_INIT_ATTR_IND_TABLE) {
-		if (cmd_core_size < offsetof(struct ibv_create_qp_ex, rwq_ind_tbl_handle) +
-				    sizeof(cmd->rwq_ind_tbl_handle))
-			return EINVAL;
 		cmd->rwq_ind_tbl_handle = qp_attr->rwq_ind_tbl->ind_tbl_handle;
 		cmd->comp_mask = IB_UVERBS_CREATE_QP_MASK_IND_TABLE;
 	}
 
-	err = write(context->cmd_fd, cmd, cmd_size);
-	if (err != cmd_size)
-		return errno;
-
-	(void)VALGRIND_MAKE_MEM_DEFINED(resp, resp_size);
+	err = execute_cmd_write_ex(context, IB_USER_VERBS_EX_CMD_CREATE_QP,
+				   cmd, cmd_size, resp, resp_size);
+	if (err)
+		return err;
 
 	create_qp_handle_resp_common(context, qp, qp_attr, &resp->base, vxrcd,
 				     vqp_sz);
@@ -1288,17 +1262,10 @@ int ibv_cmd_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr,
 
 int ibv_cmd_modify_qp_ex(struct ibv_qp *qp, struct ibv_qp_attr *attr,
 			 int attr_mask, struct ibv_modify_qp_ex *cmd,
-			 size_t cmd_core_size, size_t cmd_size,
+			 size_t cmd_size,
 			 struct ib_uverbs_ex_modify_qp_resp *resp,
-			 size_t resp_core_size, size_t resp_size)
+			 size_t resp_size)
 {
-	if (resp_core_size < offsetof(struct ib_uverbs_ex_modify_qp_resp,
-			     response_length) + sizeof(resp->response_length))
-		return EINVAL;
-
-	IBV_INIT_CMD_RESP_EX_V(cmd, cmd_core_size, cmd_size, MODIFY_QP,
-			       resp, resp_core_size, resp_size);
-
 	copy_modify_qp_fields(qp, attr, attr_mask, &cmd->base);
 
 	if (attr_mask & IBV_QP_RATE_LIMIT) {
@@ -1309,12 +1276,8 @@ int ibv_cmd_modify_qp_ex(struct ibv_qp *qp, struct ibv_qp_attr *attr,
 			return EINVAL;
 	}
 
-	if (write(qp->context->cmd_fd, cmd, cmd_size) != cmd_size)
-		return errno;
-
-	(void)VALGRIND_MAKE_MEM_DEFINED(resp, resp_size);
-
-	return 0;
+	return execute_cmd_write_ex(qp->context, IB_USER_VERBS_EX_CMD_MODIFY_QP,
+				    cmd, cmd_size, resp, resp_size);
 }
 
 int ibv_cmd_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr,
@@ -1847,7 +1810,7 @@ int ibv_cmd_create_flow(struct ibv_qp *qp,
 		err = ib_spec_to_kern_spec(ib_spec, kern_spec);
 		if (err) {
 			errno = err;
-			goto err;
+			return err;
 		}
 		cmd->flow_attr.size +=
 			((struct ibv_kern_spec *)kern_spec)->hdr.size;
@@ -1861,19 +1824,16 @@ int ibv_cmd_create_flow(struct ibv_qp *qp,
 		written_size += ucmd_size;
 	}
 
-	IBV_INIT_CMD_RESP_EX_VCMD(cmd, written_size - ucmd_size,
-				  written_size, CREATE_FLOW,
-				  &resp, sizeof(resp));
-	if (write(qp->context->cmd_fd, cmd, written_size) != written_size)
-		goto err;
-
-	(void) VALGRIND_MAKE_MEM_DEFINED(&resp, sizeof(resp));
+	err = execute_cmd_write_ex_full(qp->context,
+					IB_USER_VERBS_EX_CMD_CREATE_FLOW, cmd,
+					written_size - ucmd_size, written_size,
+					&resp, sizeof(resp), sizeof(resp));
+	if (err)
+		return err;
 
 	flow_id->context = qp->context;
 	flow_id->handle = resp.flow_handle;
 	return 0;
-err:
-	return errno;
 }
 
 int ibv_cmd_destroy_flow(struct ibv_flow *flow_id)
@@ -1895,10 +1855,8 @@ int ibv_cmd_create_wq(struct ibv_context *context,
 		      struct ibv_wq_init_attr *wq_init_attr,
 		      struct ibv_wq *wq,
 		      struct ibv_create_wq *cmd,
-		      size_t cmd_core_size,
 		      size_t cmd_size,
 		      struct ib_uverbs_ex_create_wq_resp *resp,
-		      size_t resp_core_size,
 		      size_t resp_size)
 {
 	int err;
@@ -1906,10 +1864,6 @@ int ibv_cmd_create_wq(struct ibv_context *context,
 	if (wq_init_attr->comp_mask >= IBV_WQ_INIT_ATTR_RESERVED)
 		return EINVAL;
 
-	IBV_INIT_CMD_RESP_EX_V(cmd, cmd_core_size, cmd_size,
-			       CREATE_WQ, resp,
-			       resp_core_size, resp_size);
-
 	cmd->user_handle   = (uintptr_t)wq;
 	cmd->pd_handle           = wq_init_attr->pd->handle;
 	cmd->cq_handle   = wq_init_attr->cq->handle;
@@ -1918,22 +1872,18 @@ int ibv_cmd_create_wq(struct ibv_context *context,
 	cmd->max_wr = wq_init_attr->max_wr;
 	cmd->comp_mask = 0;
 
-	if (cmd_core_size >= offsetof(struct ibv_create_wq, create_flags) +
-	    sizeof(cmd->create_flags)) {
-		if (wq_init_attr->comp_mask & IBV_WQ_INIT_ATTR_FLAGS) {
-			if (wq_init_attr->create_flags & ~(IBV_WQ_FLAGS_RESERVED - 1))
-				return EOPNOTSUPP;
-			cmd->create_flags = wq_init_attr->create_flags;
-		}
+	if (wq_init_attr->comp_mask & IBV_WQ_INIT_ATTR_FLAGS) {
+		if (wq_init_attr->create_flags & ~(IBV_WQ_FLAGS_RESERVED - 1))
+			return EOPNOTSUPP;
+		cmd->create_flags = wq_init_attr->create_flags;
 	}
 
-	err = write(context->cmd_fd, cmd, cmd_size);
-	if (err != cmd_size)
-		return errno;
-
-	(void) VALGRIND_MAKE_MEM_DEFINED(resp, resp_size);
+	err = execute_cmd_write_ex(context, IB_USER_VERBS_EX_CMD_CREATE_WQ,
+				   cmd, cmd_size, resp, resp_size);
+	if (err)
+		return err;
 
-	if (resp->response_length < resp_core_size)
+	if (resp->response_length < sizeof(*resp))
 		return EINVAL;
 
 	wq->handle  = resp->wq_handle;
@@ -1949,31 +1899,30 @@ int ibv_cmd_create_wq(struct ibv_context *context,
 }
 
 int ibv_cmd_modify_wq(struct ibv_wq *wq, struct ibv_wq_attr *attr,
-		      struct ibv_modify_wq *cmd, size_t cmd_core_size,
-		      size_t cmd_size)
+		      struct ibv_modify_wq *cmd, size_t cmd_size)
 {
+	int err;
+
 	if (attr->attr_mask >= IBV_WQ_ATTR_RESERVED)
 		return EINVAL;
 
-	memset(cmd, 0, cmd_core_size);
-	IBV_INIT_CMD_EX(cmd, cmd_size, MODIFY_WQ);
+	memset(cmd, 0, sizeof(*cmd));
 
 	cmd->curr_wq_state = attr->curr_wq_state;
 	cmd->wq_state = attr->wq_state;
-	if (cmd_core_size >= offsetof(struct ibv_modify_wq, flags_mask) +
-	    sizeof(cmd->flags_mask)) {
-		if (attr->attr_mask & IBV_WQ_ATTR_FLAGS) {
-			if (attr->flags_mask & ~(IBV_WQ_FLAGS_RESERVED - 1))
-				return EOPNOTSUPP;
-			cmd->flags = attr->flags;
-			cmd->flags_mask = attr->flags_mask;
-		}
+	if (attr->attr_mask & IBV_WQ_ATTR_FLAGS) {
+		if (attr->flags_mask & ~(IBV_WQ_FLAGS_RESERVED - 1))
+			return EOPNOTSUPP;
+		cmd->flags = attr->flags;
+		cmd->flags_mask = attr->flags_mask;
 	}
 	cmd->wq_handle = wq->handle;
 	cmd->attr_mask = attr->attr_mask;
 
-	if (write(wq->context->cmd_fd, cmd, cmd_size) != cmd_size)
-		return errno;
+	err = execute_cmd_write_ex_req(
+		wq->context, IB_USER_VERBS_EX_CMD_MODIFY_WQ, cmd, cmd_size);
+	if (err)
+		return err;
 
 	if (attr->attr_mask & IBV_WQ_ATTR_STATE)
 		wq->state = attr->wq_state;
@@ -2030,17 +1979,15 @@ int ibv_cmd_create_rwq_ind_table(struct ibv_context *context,
 	for (i = 0; i < num_tbl_entries; i++)
 		cmd->wq_handles[i] = init_attr->ind_tbl[i]->handle;
 
-	IBV_INIT_CMD_RESP_EX_V(cmd, cmd_size, cmd_size,
-			       CREATE_RWQ_IND_TBL, resp,
-			       sizeof(*resp), resp_size);
 	cmd->log_ind_tbl_size = init_attr->log_ind_tbl_size;
 	cmd->comp_mask = 0;
 
-	err = write(context->cmd_fd, cmd, cmd_size);
-	if (err != cmd_size)
-		return errno;
-
-	(void) VALGRIND_MAKE_MEM_DEFINED(resp, resp_size);
+	err = execute_cmd_write_ex_full(context,
+					IB_USER_VERBS_EX_CMD_CREATE_RWQ_IND_TBL,
+					cmd, cmd_size, cmd_size, resp,
+					sizeof(*resp), resp_size);
+	if (err)
+		return err;
 
 	if (resp->response_length < sizeof(*resp))
 		return EINVAL;
@@ -2076,16 +2023,12 @@ int ibv_cmd_modify_cq(struct ibv_cq *cq,
 	if (attr->attr_mask >= IBV_CQ_ATTR_RESERVED)
 		return EINVAL;
 
-	IBV_INIT_CMD_EX(cmd, cmd_size, MODIFY_CQ);
-
 	cmd->cq_handle = cq->handle;
 	cmd->attr_mask = attr->attr_mask;
 	cmd->attr.cq_count =  attr->moderate.cq_count;
 	cmd->attr.cq_period = attr->moderate.cq_period;
 	cmd->reserved = 0;
 
-	if (write(cq->context->cmd_fd, cmd, cmd_size) != cmd_size)
-		return errno;
-
-	return 0;
+	return execute_cmd_write_ex_req(
+		cq->context, IB_USER_VERBS_EX_CMD_MODIFY_CQ, cmd, cmd_size);
 }
diff --git a/libibverbs/cmd_fallback.c b/libibverbs/cmd_fallback.c
index 3a43a0c569776f..cad8b21756a6a6 100644
--- a/libibverbs/cmd_fallback.c
+++ b/libibverbs/cmd_fallback.c
@@ -38,6 +38,7 @@
 #include <ccan/build_assert.h>
 
 #include <unistd.h>
+#include <valgrind/memcheck.h>
 
 /*
  * Check if the command buffer provided by the driver includes anything that
@@ -285,3 +286,38 @@ int _execute_write_raw_ex(struct ibv_context *ctx, struct ex_hdr *hdr)
 
 	return 0;
 }
+
+/*
+ * req_size is the total length of the ex_hdr, core payload and driver data.
+ * core_req_size is the total length of the ex_hdr and core_payload.
+ */
+int _execute_cmd_write_ex(struct ibv_context *ctx, unsigned int write_method,
+		       struct ex_hdr *req, size_t core_req_size,
+		       size_t req_size, void *resp, size_t core_resp_size,
+		       size_t resp_size)
+{
+	req->hdr.command = IB_USER_VERBS_CMD_FLAG_EXTENDED | write_method;
+	req->hdr.in_words =
+		__check_divide(core_req_size - sizeof(struct ex_hdr), 8);
+	req->hdr.out_words = __check_divide(core_resp_size, 8);
+	req->ex_hdr.provider_in_words =
+		__check_divide(req_size - core_req_size, 8);
+	req->ex_hdr.provider_out_words =
+		__check_divide(resp_size - core_resp_size, 8);
+	req->ex_hdr.response = ioctl_ptr_to_u64(resp);
+	req->ex_hdr.cmd_hdr_reserved = 0;
+
+	/*
+	 * Users assumes the stack buffer is zeroed before passing to the
+	 * kernel for writing.
+	 */
+	if (resp)
+		memset(resp, 0, resp_size);
+
+	if (write(ctx->cmd_fd, req, req_size) != req_size)
+		return errno;
+
+	if (resp)
+		VALGRIND_MAKE_MEM_DEFINED(resp, resp_size);
+	return 0;
+}
diff --git a/libibverbs/cmd_ioctl.c b/libibverbs/cmd_ioctl.c
index c12442f319a570..bb6ab45ebba96e 100644
--- a/libibverbs/cmd_ioctl.c
+++ b/libibverbs/cmd_ioctl.c
@@ -38,6 +38,7 @@
 #include <infiniband/driver.h>
 
 #include <rdma/ib_user_ioctl_cmds.h>
+#include <valgrind/memcheck.h>
 
 /* Number of attrs in this and all the link'd buffers */
 unsigned int __ioctl_final_num_attrs(unsigned int num_attrs,
diff --git a/libibverbs/cmd_write.h b/libibverbs/cmd_write.h
index 7ae26359b25f29..2a3c50aa62015c 100644
--- a/libibverbs/cmd_write.h
+++ b/libibverbs/cmd_write.h
@@ -256,6 +256,36 @@ int _execute_cmd_write(struct ibv_context *ctx, unsigned int write_method,
 			resp_size, resp_size);                                 \
 	})
 
+/*
+ * For write() commands that use the _ex protocol. _full allows the caller to
+ * specify all 4 sizes directly. This version is used when the core structs
+ * end in a flex array. The normal and req versions are similar to write() and
+ * deduce the length of the core struct from the enum.
+ */
+int _execute_cmd_write_ex(struct ibv_context *ctx, unsigned int write_method,
+			  struct ex_hdr *req, size_t core_req_size,
+			  size_t req_size, void *resp, size_t core_resp_size,
+			  size_t resp_size);
+#define execute_cmd_write_ex_full(ctx, enum, cmd, core_cmd_size, cmd_size,     \
+				  resp, core_resp_size, resp_size)             \
+	_execute_cmd_write_ex(                                                 \
+		ctx, enum, &(cmd)->hdr + check_type(cmd, IBV_ABI_REQ(enum) *), \
+		core_cmd_size, cmd_size,                                       \
+		resp + check_type(resp, IBV_KABI_RESP(enum) *),                \
+		core_resp_size, resp_size)
+#define execute_cmd_write_ex(ctx, enum, cmd, cmd_size, resp, resp_size)        \
+	execute_cmd_write_ex_full(ctx, enum, cmd, sizeof(*(cmd)), cmd_size,    \
+				  resp, sizeof(*(resp)), resp_size)
+#define execute_cmd_write_ex_req(ctx, enum, cmd, cmd_size)                     \
+	({                                                                     \
+		static_assert(sizeof(IBV_KABI_RESP(enum)) == 0,                \
+			      "Method has a response!");                       \
+		_execute_cmd_write_ex(                                         \
+			ctx, enum,                                             \
+			&(cmd)->hdr + check_type(cmd, IBV_ABI_REQ(enum) *),    \
+			sizeof(*(cmd)), cmd_size, NULL, 0, 0);                 \
+	})
+
 /*
  * These two macros are used only with execute_ioctl_fallback - they allow the
  * IOCTL code to be elided by the compiler when disabled.
diff --git a/libibverbs/driver.h b/libibverbs/driver.h
index cc879fb61335c7..9030dc81d37ca4 100644
--- a/libibverbs/driver.h
+++ b/libibverbs/driver.h
@@ -413,10 +413,8 @@ int ibv_cmd_query_device_ex(struct ibv_context *context,
 			    struct ibv_device_attr_ex *attr, size_t attr_size,
 			    uint64_t *raw_fw_ver,
 			    struct ibv_query_device_ex *cmd,
-			    size_t cmd_core_size,
 			    size_t cmd_size,
 			    struct ib_uverbs_ex_query_device_resp *resp,
-			    size_t resp_core_size,
 			    size_t resp_size);
 int ibv_cmd_query_port(struct ibv_context *context, uint8_t port_num,
 		       struct ibv_port_attr *port_attr,
@@ -501,10 +499,8 @@ int ibv_cmd_create_qp_ex2(struct ibv_context *context,
 			  struct verbs_qp *qp, int vqp_sz,
 			  struct ibv_qp_init_attr_ex *qp_attr,
 			  struct ibv_create_qp_ex *cmd,
-			  size_t cmd_core_size,
 			  size_t cmd_size,
 			  struct ib_uverbs_ex_create_qp_resp *resp,
-			  size_t resp_core_size,
 			  size_t resp_size);
 int ibv_cmd_open_qp(struct ibv_context *context,
 		    struct verbs_qp *qp,  int vqp_sz,
@@ -520,9 +516,9 @@ int ibv_cmd_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr,
 		      struct ibv_modify_qp *cmd, size_t cmd_size);
 int ibv_cmd_modify_qp_ex(struct ibv_qp *qp, struct ibv_qp_attr *attr,
 			 int attr_mask, struct ibv_modify_qp_ex *cmd,
-			 size_t cmd_core_size, size_t cmd_size,
+			 size_t cmd_size,
 			 struct ib_uverbs_ex_modify_qp_resp *resp,
-			 size_t resp_core_size, size_t resp_size);
+			 size_t resp_size);
 int ibv_cmd_destroy_qp(struct ibv_qp *qp);
 int ibv_cmd_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr,
 		      struct ibv_send_wr **bad_wr);
@@ -548,16 +544,13 @@ int ibv_cmd_create_wq(struct ibv_context *context,
 		      struct ibv_wq_init_attr *wq_init_attr,
 		      struct ibv_wq *wq,
 		      struct ibv_create_wq *cmd,
-		      size_t cmd_core_size,
 		      size_t cmd_size,
 		      struct ib_uverbs_ex_create_wq_resp *resp,
-		      size_t resp_core_size,
 		      size_t resp_size);
 
 int ibv_cmd_destroy_flow_action(struct verbs_flow_action *action);
 int ibv_cmd_modify_wq(struct ibv_wq *wq, struct ibv_wq_attr *attr,
-		      struct ibv_modify_wq *cmd, size_t cmd_core_size,
-		      size_t cmd_size);
+		      struct ibv_modify_wq *cmd, size_t cmd_size);
 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,
diff --git a/libibverbs/ibverbs.h b/libibverbs/ibverbs.h
index c70114f11e9bad..24843b49fdb3c7 100644
--- a/libibverbs/ibverbs.h
+++ b/libibverbs/ibverbs.h
@@ -37,9 +37,6 @@
 #include <pthread.h>
 
 #include <infiniband/driver.h>
-
-#include <valgrind/memcheck.h>
-
 #include <ccan/bitmap.h>
 
 #define INIT		__attribute__((constructor))
@@ -86,35 +83,4 @@ static inline const struct verbs_context_ops *get_ops(struct ibv_context *ctx)
 	return &get_priv(ctx)->ops;
 }
 
-static inline uint32_t _cmd_ex(uint32_t cmd)
-{
-	return IB_USER_VERBS_CMD_FLAG_EXTENDED | cmd;
-}
-
-#define IBV_INIT_CMD_RESP_EX_V(cmd, cmd_size, size, opcode, out, resp_size,\
-		outsize)						   \
-	do {                                                               \
-		size_t c_size = cmd_size - sizeof(struct ex_hdr);	   \
-		(cmd)->hdr.hdr.command =				   \
-			_cmd_ex(IB_USER_VERBS_EX_CMD_##opcode);		   \
-		(cmd)->hdr.hdr.in_words  = ((c_size) / 8);                 \
-		(cmd)->hdr.hdr.out_words = ((resp_size) / 8);              \
-		(cmd)->hdr.ex_hdr.provider_in_words   = (((size) - (cmd_size))/8);\
-		(cmd)->hdr.ex_hdr.provider_out_words  =			   \
-			     (((outsize) - (resp_size)) / 8);              \
-		(cmd)->hdr.ex_hdr.response  = (uintptr_t) (out);           \
-		(cmd)->hdr.ex_hdr.cmd_hdr_reserved = 0;			   \
-	} while (0)
-
-#define IBV_INIT_CMD_RESP_EX_VCMD(cmd, cmd_size, size, opcode, out, outsize) \
-	IBV_INIT_CMD_RESP_EX_V(cmd, cmd_size, size, opcode, out,	     \
-			sizeof(*(out)), outsize)
-
-#define IBV_INIT_CMD_RESP_EX(cmd, size, opcode, out, outsize)		     \
-	IBV_INIT_CMD_RESP_EX_V(cmd, sizeof(*(cmd)), size, opcode, out,    \
-			sizeof(*(out)), outsize)
-
-#define IBV_INIT_CMD_EX(cmd, size, opcode)				     \
-	IBV_INIT_CMD_RESP_EX_V(cmd, sizeof(*(cmd)), size, opcode, NULL, 0, 0)
-
 #endif /* IB_VERBS_H */
diff --git a/providers/mlx4/verbs.c b/providers/mlx4/verbs.c
index a88454e405c717..7a357b5da2759f 100644
--- a/providers/mlx4/verbs.c
+++ b/providers/mlx4/verbs.c
@@ -80,10 +80,8 @@ int mlx4_query_device_ex(struct ibv_context *context,
 	int err;
 
 	err = ibv_cmd_query_device_ex(context, input, attr, attr_size,
-				      &raw_fw_ver,
-				      &cmd.ibv_cmd, sizeof(cmd.ibv_cmd), sizeof(cmd),
-				      &resp.ibv_resp, sizeof(resp.ibv_resp),
-				      sizeof(resp));
+				      &raw_fw_ver, &cmd.ibv_cmd, sizeof(cmd),
+				      &resp.ibv_resp, sizeof(resp));
 	if (err)
 		return err;
 
@@ -785,10 +783,9 @@ static int mlx4_cmd_create_qp_ex_rss(struct ibv_context *context,
 	       sizeof(cmd_ex.rx_hash_key));
 
 	ret = ibv_cmd_create_qp_ex2(context, &qp->verbs_qp,
-				    sizeof(qp->verbs_qp), attr,
-				    &cmd_ex.ibv_cmd, sizeof(cmd_ex.ibv_cmd),
+				    sizeof(qp->verbs_qp), attr, &cmd_ex.ibv_cmd,
 				    sizeof(cmd_ex), &resp.ibv_resp,
-				    sizeof(resp.ibv_resp), sizeof(resp));
+				    sizeof(resp));
 	return ret;
 }
 
@@ -841,10 +838,9 @@ static int mlx4_cmd_create_qp_ex(struct ibv_context *context,
 	cmd_ex.drv_payload = cmd->drv_payload;
 
 	ret = ibv_cmd_create_qp_ex2(context, &qp->verbs_qp,
-				    sizeof(qp->verbs_qp), attr,
-				    &cmd_ex.ibv_cmd, sizeof(cmd_ex.ibv_cmd),
+				    sizeof(qp->verbs_qp), attr, &cmd_ex.ibv_cmd,
 				    sizeof(cmd_ex), &resp.ibv_resp,
-				    sizeof(resp.ibv_resp), sizeof(resp));
+				    sizeof(resp));
 	return ret;
 }
 
@@ -1479,10 +1475,7 @@ struct ibv_wq *mlx4_create_wq(struct ibv_context *context,
 	pthread_mutex_lock(&to_mctx(context)->qp_table_mutex);
 
 	ret = ibv_cmd_create_wq(context, attr, &qp->wq, &cmd.ibv_cmd,
-				sizeof(cmd.ibv_cmd),
-				sizeof(cmd),
-				&resp, sizeof(resp),
-				sizeof(resp));
+				sizeof(cmd), &resp, sizeof(resp));
 	if (ret)
 		goto err_rq_db;
 
@@ -1529,8 +1522,7 @@ int mlx4_modify_wq(struct ibv_wq *ibwq, struct ibv_wq_attr *attr)
 	struct mlx4_modify_wq cmd = {};
 	int ret;
 
-	ret = ibv_cmd_modify_wq(ibwq, attr, &cmd.ibv_cmd,  sizeof(cmd.ibv_cmd),
-				sizeof(cmd));
+	ret = ibv_cmd_modify_wq(ibwq, attr, &cmd.ibv_cmd, sizeof(cmd));
 
 	if (!ret && (attr->attr_mask & IBV_WQ_ATTR_STATE) &&
 	    (ibwq->state == IBV_WQS_RESET)) {
diff --git a/providers/mlx5/verbs.c b/providers/mlx5/verbs.c
index 22a3b9ff23c98c..9378c07e1ee2ba 100644
--- a/providers/mlx5/verbs.c
+++ b/providers/mlx5/verbs.c
@@ -1557,10 +1557,9 @@ static int mlx5_cmd_create_rss_qp(struct ibv_context *context,
 			attr->rx_hash_conf.rx_hash_key_len);
 
 	ret = ibv_cmd_create_qp_ex2(context, &qp->verbs_qp,
-					    sizeof(qp->verbs_qp), attr,
-					    &cmd_ex_rss.ibv_cmd, sizeof(cmd_ex_rss.ibv_cmd),
-					    sizeof(cmd_ex_rss), &resp.ibv_resp,
-					    sizeof(resp.ibv_resp), sizeof(resp));
+				    sizeof(qp->verbs_qp), attr,
+				    &cmd_ex_rss.ibv_cmd, sizeof(cmd_ex_rss),
+				    &resp.ibv_resp, sizeof(resp));
 	if (ret)
 		return ret;
 
@@ -1588,10 +1587,9 @@ static int mlx5_cmd_create_qp_ex(struct ibv_context *context,
 	cmd_ex.drv_payload = cmd->drv_payload;
 
 	ret = ibv_cmd_create_qp_ex2(context, &qp->verbs_qp,
-				    sizeof(qp->verbs_qp), attr,
-				    &cmd_ex.ibv_cmd, sizeof(cmd_ex.ibv_cmd),
+				    sizeof(qp->verbs_qp), attr, &cmd_ex.ibv_cmd,
 				    sizeof(cmd_ex), &resp->ibv_resp,
-				    sizeof(resp->ibv_resp), sizeof(*resp));
+				    sizeof(*resp));
 
 	return ret;
 }
@@ -2154,11 +2152,8 @@ static int modify_dct(struct ibv_qp *qp, struct ibv_qp_attr *attr,
 	bool dct_create;
 	int ret;
 
-	ret = ibv_cmd_modify_qp_ex(qp, attr, attr_mask,
-				   &cmd_ex,
-				   sizeof(cmd_ex), sizeof(cmd_ex),
-				   &resp.ibv_resp,
-				   sizeof(resp.ibv_resp), sizeof(resp));
+	ret = ibv_cmd_modify_qp_ex(qp, attr, attr_mask, &cmd_ex, sizeof(cmd_ex),
+				   &resp.ibv_resp, sizeof(resp));
 	if (ret)
 		return ret;
 
@@ -2249,11 +2244,8 @@ int mlx5_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr,
 	}
 
 	if (attr_mask & MLX5_MODIFY_QP_EX_ATTR_MASK)
-		ret = ibv_cmd_modify_qp_ex(qp, attr, attr_mask,
-					   &cmd_ex,
-					   sizeof(cmd_ex), sizeof(cmd_ex),
-					   &resp,
-					   sizeof(resp), sizeof(resp));
+		ret = ibv_cmd_modify_qp_ex(qp, attr, attr_mask, &cmd_ex,
+					   sizeof(cmd_ex), &resp, sizeof(resp));
 	else
 		ret = ibv_cmd_modify_qp(qp, attr, attr_mask,
 					&cmd, sizeof(cmd));
@@ -2320,10 +2312,8 @@ int mlx5_modify_qp_rate_limit(struct ibv_qp *qp,
 	qp_attr.rate_limit = attr->rate_limit;
 
 	ret = ibv_cmd_modify_qp_ex(qp, &qp_attr, IBV_QP_RATE_LIMIT,
-				   &cmd.ibv_cmd,
-				   sizeof(cmd.ibv_cmd), sizeof(cmd),
-				   &resp,
-				   sizeof(resp), sizeof(resp));
+				   &cmd.ibv_cmd, sizeof(cmd), &resp,
+				   sizeof(resp));
 
 	return ret;
 }
@@ -2816,11 +2806,10 @@ int mlx5_query_device_ex(struct ibv_context *context,
 
 	memset(&cmd, 0, sizeof(cmd));
 	memset(&resp, 0, sizeof(resp));
-	err = ibv_cmd_query_device_ex(context, input, attr, attr_size,
-				      &raw_fw_ver,
-				      &cmd.ibv_cmd, sizeof(cmd.ibv_cmd), sizeof(cmd),
-				      &resp.ibv_resp, sizeof(resp.ibv_resp),
-				      cmd_supp_uhw ? sizeof(resp) : sizeof(resp.ibv_resp));
+	err = ibv_cmd_query_device_ex(
+		context, input, attr, attr_size, &raw_fw_ver, &cmd.ibv_cmd,
+		sizeof(cmd), &resp.ibv_resp,
+		cmd_supp_uhw ? sizeof(resp) : sizeof(resp.ibv_resp));
 	if (err)
 		return err;
 
@@ -3018,10 +3007,7 @@ static struct ibv_wq *create_wq(struct ibv_context *context,
 	}
 
 	err = ibv_cmd_create_wq(context, attr, &rwq->wq, &cmd.ibv_cmd,
-				sizeof(cmd.ibv_cmd),
-				sizeof(cmd),
-				&resp.ibv_resp, sizeof(resp.ibv_resp),
-				sizeof(resp));
+				sizeof(cmd), &resp.ibv_resp, sizeof(resp));
 	if (err)
 		goto err_create;
 
@@ -3077,7 +3063,7 @@ int mlx5_modify_wq(struct ibv_wq *wq, struct ibv_wq_attr *attr)
 		}
 	}
 
-	return ibv_cmd_modify_wq(wq, attr, &cmd.ibv_cmd,  sizeof(cmd.ibv_cmd), sizeof(cmd));
+	return ibv_cmd_modify_wq(wq, attr, &cmd.ibv_cmd, sizeof(cmd));
 }
 
 int mlx5_destroy_wq(struct ibv_wq *wq)
