From patchwork Fri Mar 8 22:41:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tivy, Robert" X-Patchwork-Id: 2240481 Return-Path: X-Original-To: patchwork-davinci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from comal.ext.ti.com (comal.ext.ti.com [198.47.26.152]) by patchwork2.kernel.org (Postfix) with ESMTP id BD695DF215 for ; Fri, 8 Mar 2013 22:44:02 +0000 (UTC) Received: from dlelxv30.itg.ti.com ([172.17.2.17]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id r28Mi2je003566 for ; Fri, 8 Mar 2013 16:44:02 -0600 Received: from DLEE70.ent.ti.com (dlee70.ent.ti.com [157.170.170.113]) by dlelxv30.itg.ti.com (8.13.8/8.13.8) with ESMTP id r28Mi2jB027069 for ; Fri, 8 Mar 2013 16:44:02 -0600 Received: from dlelxv23.itg.ti.com (172.17.1.198) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.2.342.3; Fri, 8 Mar 2013 16:44:01 -0600 Received: from linux.omap.com (dlelxs01.itg.ti.com [157.170.227.31]) by dlelxv23.itg.ti.com (8.13.8/8.13.8) with ESMTP id r28Mi1Xv016525 for ; Fri, 8 Mar 2013 16:44:01 -0600 Received: from linux.omap.com (localhost [127.0.0.1]) by linux.omap.com (Postfix) with ESMTP id 9398580627 for ; Fri, 8 Mar 2013 16:44:01 -0600 (CST) X-Original-To: davinci-linux-open-source@linux.davincidsp.com Delivered-To: davinci-linux-open-source@linux.davincidsp.com Received: from dlelxv30.itg.ti.com (dlelxv30.itg.ti.com [172.17.2.17]) by linux.omap.com (Postfix) with ESMTP id 3634580626 for ; Fri, 8 Mar 2013 16:43:48 -0600 (CST) Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dlelxv30.itg.ti.com (8.13.8/8.13.8) with ESMTP id r28MhmYB026550; Fri, 8 Mar 2013 16:43:48 -0600 Received: from dlelxv24.itg.ti.com (172.17.1.199) by dfle73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.1.323.3; Fri, 8 Mar 2013 16:43:47 -0600 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dlelxv24.itg.ti.com (8.13.8/8.13.8) with ESMTP id r28MhlMT002889; Fri, 8 Mar 2013 16:43:47 -0600 Received: from sanblnx02.sanb.design.ti.com (sanblnx02.sanb.design.ti.com [146.252.160.81]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id r28MhlV16973; Fri, 8 Mar 2013 16:43:47 -0600 (CST) Received: from sanblnx02.sanb.design.ti.com (localhost [127.0.0.1]) by sanblnx02.sanb.design.ti.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id r28MhjhC004384; Fri, 8 Mar 2013 14:43:45 -0800 Received: (from a0783933@localhost) by sanblnx02.sanb.design.ti.com (8.13.6/8.13.6/Submit) id r28Mhjrk004381; Fri, 8 Mar 2013 14:43:45 -0800 From: Robert Tivy To: , , , , , , , , Subject: [PATCH v8 1/7] Process all available messages in virtqueue callback Date: Fri, 8 Mar 2013 14:41:42 -0800 Message-ID: <1362782508-3166-2-git-send-email-rtivy@ti.com> X-Mailer: git-send-email 1.7.9.4 In-Reply-To: <1362782508-3166-1-git-send-email-rtivy@ti.com> References: <1362782508-3166-1-git-send-email-rtivy@ti.com> MIME-Version: 1.0 X-BeenThere: davinci-linux-open-source@linux.davincidsp.com X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: Errors-To: davinci-linux-open-source-bounces+patchwork-davinci=patchwork.kernel.org@linux.davincidsp.com Change virtqueue callback function rpmsg_recv_done() to process all available messages instead of just one message. Signed-off-by: Robert Tivy --- drivers/rpmsg/virtio_rpmsg_bus.c | 97 +++++++++++++++++++++++--------------- 1 file changed, 58 insertions(+), 39 deletions(-) diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index f1e3239..ae92ae7 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -782,7 +782,7 @@ out: } EXPORT_SYMBOL(rpmsg_send_offchannel_raw); -/* called when an rx buffer is used, and it's time to digest a message */ +/* called when an rx buffer is used, and it's time to digest a message(s) */ static void rpmsg_recv_done(struct virtqueue *rvq) { struct rpmsg_hdr *msg; @@ -791,6 +791,7 @@ static void rpmsg_recv_done(struct virtqueue *rvq) struct scatterlist sg; struct virtproc_info *vrp = rvq->vdev->priv; struct device *dev = &rvq->vdev->dev; + int added_buf = 0; int err; msg = virtqueue_get_buf(rvq, &len); @@ -799,60 +800,78 @@ static void rpmsg_recv_done(struct virtqueue *rvq) return; } - dev_dbg(dev, "From: 0x%x, To: 0x%x, Len: %d, Flags: %d, Reserved: %d\n", + while (msg) { + dev_dbg(dev, "From: 0x%x, To: 0x%x, Len: %d, Flags: %d, Reserved: %d\n", msg->src, msg->dst, msg->len, msg->flags, msg->reserved); - print_hex_dump(KERN_DEBUG, "rpmsg_virtio RX: ", DUMP_PREFIX_NONE, 16, 1, +#ifdef DEBUG_VERBOSE + print_hex_dump(KERN_DEBUG, "rpmsg_virtio RX: ", + DUMP_PREFIX_NONE, 16, 1, msg, sizeof(*msg) + msg->len, true); +#endif - /* - * We currently use fixed-sized buffers, so trivially sanitize - * the reported payload length. - */ - if (len > RPMSG_BUF_SIZE || - msg->len > (len - sizeof(struct rpmsg_hdr))) { - dev_warn(dev, "inbound msg too big: (%d, %d)\n", len, msg->len); - return; - } + /* + * We currently use fixed-sized buffers, so trivially sanitize + * the reported payload length. + */ + if (len > RPMSG_BUF_SIZE || + msg->len > (len - sizeof(struct rpmsg_hdr))) { + dev_warn(dev, "inbound msg too big: (%d, %d)\n", + len, msg->len); + break; + } - /* use the dst addr to fetch the callback of the appropriate user */ - mutex_lock(&vrp->endpoints_lock); + /* + * Use the dst addr to fetch the callback of the appropriate + * user. + */ + mutex_lock(&vrp->endpoints_lock); - ept = idr_find(&vrp->endpoints, msg->dst); + ept = idr_find(&vrp->endpoints, msg->dst); - /* let's make sure no one deallocates ept while we use it */ - if (ept) - kref_get(&ept->refcount); + /* let's make sure no one deallocates ept while we use it */ + if (ept) + kref_get(&ept->refcount); - mutex_unlock(&vrp->endpoints_lock); + mutex_unlock(&vrp->endpoints_lock); - if (ept) { - /* make sure ept->cb doesn't go away while we use it */ - mutex_lock(&ept->cb_lock); + if (ept) { + /* make sure ept->cb doesn't go away while we use it */ + mutex_lock(&ept->cb_lock); - if (ept->cb) - ept->cb(ept->rpdev, msg->data, msg->len, ept->priv, - msg->src); + if (ept->cb) + ept->cb(ept->rpdev, msg->data, msg->len, + ept->priv, msg->src); - mutex_unlock(&ept->cb_lock); + mutex_unlock(&ept->cb_lock); - /* farewell, ept, we don't need you anymore */ - kref_put(&ept->refcount, __ept_release); - } else - dev_warn(dev, "msg received with no recepient\n"); + /* farewell, ept, we don't need you anymore */ + kref_put(&ept->refcount, __ept_release); + } else + dev_warn(dev, "msg received with no recepient\n"); - /* publish the real size of the buffer */ - sg_init_one(&sg, msg, RPMSG_BUF_SIZE); + /* publish the real size of the buffer */ + sg_init_one(&sg, msg, RPMSG_BUF_SIZE); - /* add the buffer back to the remote processor's virtqueue */ - err = virtqueue_add_buf(vrp->rvq, &sg, 0, 1, msg, GFP_KERNEL); - if (err < 0) { - dev_err(dev, "failed to add a virtqueue buffer: %d\n", err); - return; + /* add the buffer back to the remote processor's virtqueue */ + err = virtqueue_add_buf(vrp->rvq, &sg, 0, 1, msg, GFP_KERNEL); + if (err < 0) { + dev_err(dev, "failed to add a virtqueue buffer: %d\n", + err); + break; + } + + added_buf = 1; + + msg = virtqueue_get_buf(rvq, &len); } - /* tell the remote processor we added another available rx buffer */ - virtqueue_kick(vrp->rvq); + if (added_buf) + /* + * Tell the remote processor we added another available rx + * buffer. + */ + virtqueue_kick(vrp->rvq); } /*