[openib-general] Re: [RFC] Kernel uverbs changes for PathScale merge

Michael S. Tsirkin mst at mellanox.co.il
Thu Oct 13 14:35:06 PDT 2005


Quoting r. Roland Dreier <rolandd at cisco.com>:
> Subject: [RFC] Kernel uverbs changes for PathScale merge
> 
> Here are the changes to the kernel part of userspace verbs required to
> support PathScale's driver.  I'm now happy with them and ready to
> commit them to the svn trunk and queue them for 2.6.15.  This will
> allow the PathScale hardware-specific driver to be move to the trunk
> as well, although quite a bit of cleanup is necessary before merging
> the driver upstream.
> 
> Does anyone have any comments on these changes before I commit?

What prevents the user from passing e.g. poll cq command on
mthca device? If that happens, it seems that ib_poll_cq will
then crash.

Is there a mask somewhere that lets the device specify which
uverbs commands are allowed for it?


> --- infiniband/core/uverbs_cmd.c	(revision 3707)
> +++ infiniband/core/uverbs_cmd.c	(working copy)
> @@ -665,6 +665,93 @@ err:
>  	return ret;
>  }
>  
> +ssize_t ib_uverbs_poll_cq(struct ib_uverbs_file *file,
> +			  const char __user *buf, int in_len,
> +			  int out_len)
> +{
> +	struct ib_uverbs_poll_cq       cmd;
> +	struct ib_uverbs_poll_cq_resp *resp;
> +	struct ib_cq                  *cq;
> +	struct ib_wc                  *wc;
> +	int                            ret = 0;
> +	int                            i;
> +	int                            rsize;
> +
> +	if (copy_from_user(&cmd, buf, sizeof cmd))
> +		return -EFAULT;
> +
> +	wc = kmalloc(cmd.ne * sizeof *wc, GFP_KERNEL);
> +	if (!wc)
> +		return -ENOMEM;
> +
> +	rsize = sizeof *resp + cmd.ne * sizeof(struct ib_uverbs_wc);
> +	resp = kmalloc(rsize, GFP_KERNEL);
> +	if (!resp) {
> +		ret = -ENOMEM;
> +		goto out_wc;
> +	}
> +
> +	down(&ib_uverbs_idr_mutex);
> +	cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle);
> +	if (!cq || cq->uobject->context != file->ucontext) {
> +		ret = -EINVAL;
> +		goto out;
> +	}
> +
> +	resp->count = ib_poll_cq(cq, cmd.ne, wc);
> +
> +	for (i = 0; i < resp->count; i++) {
> +		resp->wc[i].wr_id 	   = wc[i].wr_id;
> +		resp->wc[i].status 	   = wc[i].status;
> +		resp->wc[i].opcode 	   = wc[i].opcode;
> +		resp->wc[i].vendor_err 	   = wc[i].vendor_err;
> +		resp->wc[i].byte_len 	   = wc[i].byte_len;
> +		resp->wc[i].imm_data 	   = wc[i].imm_data;
> +		resp->wc[i].qp_num 	   = wc[i].qp_num;
> +		resp->wc[i].src_qp 	   = wc[i].src_qp;
> +		resp->wc[i].wc_flags 	   = wc[i].wc_flags;
> +		resp->wc[i].pkey_index 	   = wc[i].pkey_index;
> +		resp->wc[i].slid 	   = wc[i].slid;
> +		resp->wc[i].sl 		   = wc[i].sl;
> +		resp->wc[i].dlid_path_bits = wc[i].dlid_path_bits;
> +		resp->wc[i].port_num 	   = wc[i].port_num;
> +	}
> +
> +	if (copy_to_user((void __user *) (unsigned long) cmd.response, resp, rsize))
> +		ret = -EFAULT;
> +
> +out:
> +	up(&ib_uverbs_idr_mutex);
> +	kfree(resp);
> +
> +out_wc:
> +	kfree(wc);
> +	return ret ? ret : in_len;
> +}

-- 
MST



More information about the general mailing list