From patchwork Thu Aug 9 12:31:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro YUNOMAE X-Patchwork-Id: 176072 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A80FD2C00CE for ; Thu, 9 Aug 2012 22:32:03 +1000 (EST) Received: from localhost ([::1]:35017 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzRuD-00018V-P4 for incoming@patchwork.ozlabs.org; Thu, 09 Aug 2012 08:32:01 -0400 Received: from eggs.gnu.org ([208.118.235.92]:56912) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzRts-0000oQ-NY for qemu-devel@nongnu.org; Thu, 09 Aug 2012 08:31:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SzRtm-00056d-HC for qemu-devel@nongnu.org; Thu, 09 Aug 2012 08:31:40 -0400 Received: from mail4.hitachi.co.jp ([133.145.228.5]:52475) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzRtm-00056O-1G for qemu-devel@nongnu.org; Thu, 09 Aug 2012 08:31:34 -0400 Received: from mlsv1.hitachi.co.jp (unknown [133.144.234.166]) by mail4.hitachi.co.jp (Postfix) with ESMTP id 3F98633CC2; Thu, 9 Aug 2012 21:31:33 +0900 (JST) Received: from mfilter06.hitachi.co.jp by mlsv1.hitachi.co.jp (8.13.1/8.13.1) id q79CVXCG024626; Thu, 9 Aug 2012 21:31:33 +0900 Received: from vshuts2.hitachi.co.jp (vshuts2.hitachi.co.jp [10.201.6.71]) by mfilter06.hitachi.co.jp (Switch-3.3.4/Switch-3.3.4) with ESMTP id q79CVVY5026044; Thu, 9 Aug 2012 21:31:32 +0900 X-AuditID: b753bd60-8ddefba000006b7e-91-5023ada37c34 Received: from hsdlmain.sdl.hitachi.co.jp (unknown [133.144.14.194]) by vshuts2.hitachi.co.jp (Symantec Mail Security) with ESMTP id 757BF8B0376; Thu, 9 Aug 2012 21:31:31 +0900 (JST) Received: from hsdlvgate2.sdl.hitachi.co.jp by hsdlmain.sdl.hitachi.co.jp (8.13.8/3.7W11021512) id q79CVVtN010773; Thu, 9 Aug 2012 21:31:31 +0900 X-AuditID: b753bd60-8ddefba000006b7e-91-5023ada37c34 Received: from sdl99w.sdl.hitachi.co.jp (sdl99w.sdl.hitachi.co.jp [133.144.14.250]) by hsdlvgate2.sdl.hitachi.co.jp (Symantec Mail Security) with ESMTP id E1CE1236561; Thu, 9 Aug 2012 21:31:30 +0900 (JST) Received: from maild.sdl.hitachi.co.jp (sdl99d.sdl.hitachi.co.jp [133.144.14.199]) by sdl99w.sdl.hitachi.co.jp (Postfix) with ESMTP id 7762653C158; Thu, 9 Aug 2012 21:31:31 +0900 (JST) Received: from ltc189.sdl.hitachi.co.jp (unknown [10.232.28.60]) by maild.sdl.hitachi.co.jp (Postfix) with ESMTP id D0FD4495B83; Thu, 9 Aug 2012 21:31:30 +0900 (JST) From: Yoshihiro YUNOMAE To: linux-kernel@vger.kernel.org Date: Thu, 09 Aug 2012 21:31:20 +0900 Message-ID: <20120809123120.8542.10604.stgit@ltc189.sdl.hitachi.co.jp> In-Reply-To: <20120809123029.8542.38311.stgit@ltc189.sdl.hitachi.co.jp> References: <20120809123029.8542.38311.stgit@ltc189.sdl.hitachi.co.jp> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-Brightmail-Tracker: AAAAAA== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 133.145.228.5 Cc: Herbert Xu , Arnd Bergmann , Frederic Weisbecker , Rusty Russell , qemu-devel@nongnu.org, Borislav Petkov , virtualization@lists.linux-foundation.org, Masami Hiramatsu , "Franch Ch. Eigler" , Ingo Molnar , Mathieu Desnoyers , Steven Rostedt , Anthony Liguori , Greg Kroah-Hartman , Amit Shah , yrl.pp-manager.tt@hitachi.com Subject: [Qemu-devel] [PATCH V2 5/6] virtio/console: Allocate scatterlist according to the current pipe size X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Masami Hiramatsu Allocate scatterlist according to the current pipe size. This allows splicing bigger buffer if the pipe size has been changed by fcntl. Changes in v2: - Just a minor fix for avoiding a confliction with previous patch. Signed-off-by: Masami Hiramatsu --- drivers/char/virtio_console.c | 23 ++++++++++++----------- 1 files changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index b2fc2ab..e88f843 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c @@ -229,7 +229,6 @@ struct port { bool guest_connected; }; -#define MAX_SPLICE_PAGES 32 /* This is the very early arch-specified put chars function. */ static int (*early_put_chars)(u32, const char *, int); @@ -482,15 +481,16 @@ struct buffer_token { void *buf; struct scatterlist *sg; } u; - bool sgpages; + /* If sgpages == 0 then buf is used, else sg is used */ + unsigned int sgpages; }; -static void reclaim_sg_pages(struct scatterlist *sg) +static void reclaim_sg_pages(struct scatterlist *sg, unsigned int nrpages) { int i; struct page *page; - for (i = 0; i < MAX_SPLICE_PAGES; i++) { + for (i = 0; i < nrpages; i++) { page = sg_page(&sg[i]); if (!page) break; @@ -511,7 +511,7 @@ static void reclaim_consumed_buffers(struct port *port) } while ((tok = virtqueue_get_buf(port->out_vq, &len))) { if (tok->sgpages) - reclaim_sg_pages(tok->u.sg); + reclaim_sg_pages(tok->u.sg, tok->sgpages); else kfree(tok->u.buf); kfree(tok); @@ -581,7 +581,7 @@ static ssize_t send_buf(struct port *port, void *in_buf, size_t in_count, tok = kmalloc(sizeof(*tok), GFP_ATOMIC); if (!tok) return -ENOMEM; - tok->sgpages = false; + tok->sgpages = 0; tok->u.buf = in_buf; sg_init_one(sg, in_buf, in_count); @@ -597,7 +597,7 @@ static ssize_t send_pages(struct port *port, struct scatterlist *sg, int nents, tok = kmalloc(sizeof(*tok), GFP_ATOMIC); if (!tok) return -ENOMEM; - tok->sgpages = true; + tok->sgpages = nents; tok->u.sg = sg; return __send_to_port(port, sg, nents, in_count, tok, nonblock); @@ -797,6 +797,7 @@ out: struct sg_list { unsigned int n; + unsigned int size; size_t len; struct scatterlist *sg; }; @@ -807,7 +808,7 @@ static int pipe_to_sg(struct pipe_inode_info *pipe, struct pipe_buffer *buf, struct sg_list *sgl = sd->u.data; unsigned int offset, len; - if (sgl->n == MAX_SPLICE_PAGES) + if (sgl->n == sgl->size) return 0; /* Try lock this page */ @@ -868,12 +869,12 @@ static ssize_t port_fops_splice_write(struct pipe_inode_info *pipe, sgl.n = 0; sgl.len = 0; - sgl.sg = kmalloc(sizeof(struct scatterlist) * MAX_SPLICE_PAGES, - GFP_KERNEL); + sgl.size = pipe->nrbufs; + sgl.sg = kmalloc(sizeof(struct scatterlist) * sgl.size, GFP_KERNEL); if (unlikely(!sgl.sg)) return -ENOMEM; - sg_init_table(sgl.sg, MAX_SPLICE_PAGES); + sg_init_table(sgl.sg, sgl.size); ret = __splice_from_pipe(pipe, &sd, pipe_to_sg); if (likely(ret > 0)) ret = send_pages(port, sgl.sg, sgl.n, sgl.len, true);