From patchwork Wed Nov 24 22:07:40 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roland Dreier X-Patchwork-Id: 354602 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oAOM2LnH013351 for ; Wed, 24 Nov 2010 22:13:27 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755073Ab0KXWHp (ORCPT ); Wed, 24 Nov 2010 17:07:45 -0500 Received: from sj-iport-6.cisco.com ([171.71.176.117]:1393 "EHLO sj-iport-6.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752602Ab0KXWHo (ORCPT ); Wed, 24 Nov 2010 17:07:44 -0500 Authentication-Results: sj-iport-6.cisco.com; dkim=neutral (message not signed) header.i=none X-IronPort-AV: E=Sophos;i="4.59,250,1288569600"; d="scan'208";a="625505553" Received: from sj-core-5.cisco.com ([171.71.177.238]) by sj-iport-6.cisco.com with ESMTP; 24 Nov 2010 22:07:44 +0000 Received: from roland-alpha.cisco.com (roland-alpha.cisco.com [10.33.42.9]) by sj-core-5.cisco.com (8.13.8/8.14.3) with ESMTP id oAOM7iig020439; Wed, 24 Nov 2010 22:07:44 GMT Received: by roland-alpha.cisco.com (Postfix, from userid 33217) id 61888E0297; Wed, 24 Nov 2010 14:07:40 -0800 (PST) From: Roland Dreier To: Dan Carpenter Cc: Jason Gunthorpe , Roland Dreier , Sean Hefty , Hal Rosenstock , linux-rdma@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [patch v4] infiniband: uverbs: handle large number of entries References: <20101007071610.GC11681@bicker> <20101007161649.GD21206@obsidianresearch.com> <20101007165947.GD11681@bicker> <20101009231607.GA24649@obsidianresearch.com> <20101012113117.GB6742@bicker> <20101012210118.GR24268@obsidianresearch.com> <20101013091312.GB6060@bicker> <20101123071025.GI1522@bicker> X-Message-Flag: Warning: May contain useful information Date: Wed, 24 Nov 2010 14:07:40 -0800 In-Reply-To: <20101123071025.GI1522@bicker> (Dan Carpenter's message of "Tue, 23 Nov 2010 10:10:25 +0300") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Wed, 24 Nov 2010 22:13:27 +0000 (UTC) diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c index b342248..ec6e434 100644 --- a/drivers/infiniband/core/uverbs_cmd.c +++ b/drivers/infiniband/core/uverbs_cmd.c @@ -903,17 +903,17 @@ ssize_t ib_uverbs_poll_cq(struct ib_uverbs_file *file, struct ib_wc *wc; int ret = 0; int i; - int rsize; if (copy_from_user(&cmd, buf, sizeof cmd)) return -EFAULT; + cmd.ne = min_t(u32, cmd.ne, IB_UVERBS_POLL_CQ_MAX_ENTRIES); + 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); + resp = kmalloc(sizeof *resp + cmd.ne * sizeof *resp->wc, GFP_KERNEL); if (!resp) { ret = -ENOMEM; goto out_wc; @@ -925,10 +925,17 @@ ssize_t ib_uverbs_poll_cq(struct ib_uverbs_file *file, goto out; } - resp->count = ib_poll_cq(cq, cmd.ne, wc); + ret = ib_poll_cq(cq, cmd.ne, wc); + if (ret < 0) { + ret = -EIO; + goto out; + } put_cq_read(cq); + resp->count = ret; + resp->reserved = 0; + for (i = 0; i < resp->count; i++) { resp->wc[i].wr_id = wc[i].wr_id; resp->wc[i].status = wc[i].status; @@ -944,9 +951,11 @@ ssize_t ib_uverbs_poll_cq(struct ib_uverbs_file *file, 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; + resp->wc[i].reserved = 0; } - if (copy_to_user((void __user *) (unsigned long) cmd.response, resp, rsize)) + if (copy_to_user((void __user *) (unsigned long) cmd.response, resp, + sizeof *resp + resp->count * sizeof *resp->wc)) ret = -EFAULT; out: diff --git a/include/rdma/ib_user_verbs.h b/include/rdma/ib_user_verbs.h index fe5b051..61b0286 100644 --- a/include/rdma/ib_user_verbs.h +++ b/include/rdma/ib_user_verbs.h @@ -278,6 +278,10 @@ struct ib_uverbs_resize_cq_resp { __u64 driver_data[0]; }; +enum { + IB_UVERBS_POLL_CQ_MAX_ENTRIES = 1000 +}; + struct ib_uverbs_poll_cq { __u64 response; __u32 cq_handle;