[openib-general] ibv_cmd_create_qp() question
Roland Dreier
rdreier at cisco.com
Wed Feb 15 15:04:36 PST 2006
As promised, here is a patch that converts ehca to use
ib_copy_to_udata() in the create_qp method in exactly the same way it
is used in the create_cq method.
Please test and commit if it looks OK. (I have an eHCA test machine
that I'll get set up soon so I can test myself, I promise).
As a bonus, this simplifies your code as well:
linux-kernel/infiniband/hw/ehca/ehca_classes.h | 10 +---------
linux-kernel/infiniband/hw/ehca/ehca_qp.c | 15 ++-------------
userspace/libehca/src/ehca_uclasses.h | 13 ++-----------
userspace/libehca/src/ehca_umain.c | 23 ++++++++++-------------
4 files changed, 15 insertions(+), 46 deletions(-)
Thanks,
Roland
Index: userspace/libehca/src/ehca_uclasses.h
===================================================================
--- userspace/libehca/src/ehca_uclasses.h (revision 5421)
+++ userspace/libehca/src/ehca_uclasses.h (working copy)
@@ -142,13 +142,8 @@ int ehcau_attach_mcast(struct ibv_qp *qp
int ehcau_detach_mcast(struct ibv_qp *qp, union ibv_gid *gid, uint16_t lid);
/**
- * cmd and resp structs to pass to kernel space
+ * resp structs from kernel space
*/
-struct ehcau_create_cq {
- struct ibv_create_cq ibv_cmd;
- u64 respbuf;
-};
-
struct ehcau_create_cq_resp {
struct ibv_create_cq_resp ibv_resp;
u32 cq_number;
@@ -156,12 +151,8 @@ struct ehcau_create_cq_resp {
struct ehca_cq_core ehca_cq_core;
};
-struct ehcau_create_qp {
- struct ibv_create_qp ibv_cmd;
- u64 respbuf;
-};
-
struct ehcau_create_qp_resp {
+ struct ibv_create_qp_resp ibv_resp;
u32 qp_num;
u32 token;
struct ehca_qp_core ehca_qp_core;
Index: userspace/libehca/src/ehca_umain.c
===================================================================
--- userspace/libehca/src/ehca_umain.c (revision 5424)
+++ userspace/libehca/src/ehca_umain.c (working copy)
@@ -200,7 +200,7 @@ int ehcau_dealloc_pd(struct ibv_pd *pd)
struct ibv_cq *ehcau_create_cq(struct ibv_context *context, int cqe,
struct ibv_comp_channel *channel, int comp_vector)
{
- struct ehcau_create_cq cmd;
+ struct ibv_create_cq cmd;
struct ehcau_create_cq_resp resp;
struct ehcau_cq *my_cq = NULL;
int ret = 0;
@@ -220,9 +220,9 @@ struct ibv_cq *ehcau_create_cq(struct ib
"context=%p cqe=%x", context, cqe);
goto create_cq_exit0;
}
- cmd.respbuf = (uintptr_t) & resp;
+
ret = ibv_cmd_create_cq(context, cqe, channel, comp_vector, &my_cq->ib_cq,
- &cmd.ibv_cmd, sizeof(cmd),
+ &cmd, sizeof(cmd),
&resp.ibv_resp, sizeof(resp));
if (ret) {
EDEB_ERR(4, "ibv_cmd_create_cq() failed "
@@ -282,9 +282,8 @@ struct ibv_qp *ehcau_create_qp(struct ib
{
int ret = 0;
struct ehcau_qp *my_qp = NULL;
- struct ehcau_create_qp cmd;
- struct ehcau_create_qp_resp ehca_resp;
- struct ibv_create_qp_resp resp;
+ struct ibv_create_qp cmd;
+ struct ehcau_create_qp_resp resp;
struct ibv_context *context = NULL;
int ret2 = 0;
@@ -301,8 +300,6 @@ struct ibv_qp *ehcau_create_qp(struct ib
memset(my_qp, 0, sizeof(*my_qp));
memset(&cmd, 0, sizeof(cmd));
- memset(&ehca_resp, 0, sizeof(ehca_resp));
- cmd.respbuf = (uintptr_t) &ehca_resp; /* TODO: better include resp in ibv_cmd_create_qp call */
if (pthread_spin_init(&my_qp->spinlock_s, PTHREAD_PROCESS_PRIVATE) ||
pthread_spin_init(&my_qp->spinlock_r, PTHREAD_PROCESS_PRIVATE)) {
@@ -310,8 +307,8 @@ struct ibv_qp *ehcau_create_qp(struct ib
}
ret = ibv_cmd_create_qp(pd, &my_qp->ib_qp, attr,
- &cmd.ibv_cmd, sizeof(cmd),
- &resp, sizeof resp);
+ &cmd, sizeof(cmd),
+ &resp.ibv_resp, sizeof resp);
if (ret != 0) {
EDEB_ERR(4, "ibv_cmd_create_qp() failed ret=%x pd=%p",
@@ -319,9 +316,9 @@ struct ibv_qp *ehcau_create_qp(struct ib
goto create_qp_exit0;
}
/* copy data returned from kernel */
- my_qp->qp_num = ehca_resp.qp_num;
- my_qp->token = ehca_resp.token;
- my_qp->ehca_qp_core = ehca_resp.ehca_qp_core;
+ my_qp->qp_num = resp.qp_num;
+ my_qp->token = resp.token;
+ my_qp->ehca_qp_core = resp.ehca_qp_core;
my_qp->ehca_qp_core.ipz_rqueue.current_q_addr =
my_qp->ehca_qp_core.ipz_rqueue.queue;
my_qp->ehca_qp_core.ipz_squeue.current_q_addr =
Index: linux-kernel/infiniband/hw/ehca/ehca_classes.h
===================================================================
--- linux-kernel/infiniband/hw/ehca/ehca_classes.h (revision 5421)
+++ linux-kernel/infiniband/hw/ehca/ehca_classes.h (working copy)
@@ -345,22 +345,14 @@ extern struct idr ehca_qp_idr;
extern struct idr ehca_cq_idr;
/*
- * cmd and resp structs for comm bw user and kernel space
+ * resp structs for comm bw user and kernel space
*/
-struct ehca_create_cq {
- u64 respbuf;
-};
-
struct ehca_create_cq_resp {
u32 cq_number;
u32 token;
struct ehca_cq_core ehca_cq_core;
};
-struct ehca_create_qp {
- u64 respbuf;
-};
-
struct ehca_create_qp_resp {
u32 qp_num;
u32 token;
Index: linux-kernel/infiniband/hw/ehca/ehca_qp.c
===================================================================
--- linux-kernel/infiniband/hw/ehca/ehca_qp.c (revision 5421)
+++ linux-kernel/infiniband/hw/ehca/ehca_qp.c (working copy)
@@ -404,7 +404,6 @@ struct ib_qp *ehca_create_qp(struct ib_p
struct ehca_cq *recv_ehca_cq = NULL;
struct ehca_cq *send_ehca_cq = NULL;
struct ib_ucontext *context = NULL;
- struct ehca_create_qp ucmd;
u64 hipz_rc = H_Parameter;
int max_send_sge;
int max_recv_sge;
@@ -449,13 +448,6 @@ struct ib_qp *ehca_create_qp(struct ib_p
if (pd->uobject && udata != NULL) {
context = pd->uobject->context;
}
- if (context != NULL) {
- if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd)) {
- EDEB_ERR(4, "copy_from_user() failed udata=%p ",
- udata);
- return ERR_PTR(-EFAULT);
- }
- }
my_qp = ehca_qp_new();
if (!my_qp) {
@@ -670,11 +662,8 @@ struct ib_qp *ehca_create_qp(struct ib_p
&vma);
my_qp->uspace_fwh = (u64)resp.ehca_qp_core.galpas.kernel.fw_handle;
-
- if (copy_to_user
- ((u64 __user *) (unsigned long)ucmd.respbuf, &resp,
- sizeof(resp))) {
- EDEB_ERR(4, "copy_to_user() failed");
+ if (ib_copy_to_udata(udata, &resp, sizeof resp) {
+ EDEB_ERR(4, "Copy to udata failed");
ret = -EINVAL;
goto create_qp_exit3;
}
More information about the general
mailing list