From: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
To: sjur.brandeland@stericsson.com
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
sjurbren@stericsson.com, linux-kernel@vger.kernel.org,
virtualization@lists.linux-foundation.org,
yrl.pp-manager.tt@hitachi.com, Amit Shah <amit.shah@redhat.com>,
Linus Walleij <linus.walleij@linaro.org>
Subject: Re: [PATCH 1/3] virtio_console:Merge struct buffer_token into struct port_buffer
Date: Wed, 26 Sep 2012 11:44:33 +0900 [thread overview]
Message-ID: <50626C11.9040708@hitachi.com> (raw)
In-Reply-To: <1348580837-10919-2-git-send-email-sjur.brandeland@stericsson.com>
(2012/09/25 22:47), sjur.brandeland@stericsson.com wrote:
> From: Sjur Brændeland <sjur.brandeland@stericsson.com>
>
> This merge reduces code size by unifying the approach for
> sending scatter-lists and regular buffers. Any type of
> write operation (splice, write, put_chars) will now allocate
> a port_buffer and send_buf() and free_buf() can always be used.
Thanks!
This looks much nicer and simpler. I just have some comments below.
> Signed-off-by: Sjur Brændeland <sjur.brandeland@stericsson.com>
> cc: Rusty Russell <rusty@rustcorp.com.au>
> cc: Michael S. Tsirkin <mst@redhat.com>
> cc: Amit Shah <amit.shah@redhat.com>
> cc: Linus Walleij <linus.walleij@linaro.org>
> cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
> ---
> drivers/char/virtio_console.c | 141 ++++++++++++++++++-----------------------
> 1 files changed, 62 insertions(+), 79 deletions(-)
>
> diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
> index 8ab9c3d..f4f7b04 100644
> --- a/drivers/char/virtio_console.c
> +++ b/drivers/char/virtio_console.c
> @@ -111,6 +111,11 @@ struct port_buffer {
> size_t len;
> /* offset in the buf from which to consume data */
> size_t offset;
> +
> + /* If sgpages == 0 then buf is used, else sg is used */
> + unsigned int sgpages;
> +
> + struct scatterlist sg[1];
> };
>
> /*
> @@ -338,23 +343,46 @@ static inline bool use_multiport(struct ports_device *portdev)
>
> static void free_buf(struct port_buffer *buf)
> {
> + int i;
> +
> kfree(buf->buf);
this should be done only when !buf->sgpages, or (see below)
> +
> + if (buf->sgpages)
> + for (i = 0; i < buf->sgpages; i++) {
> + struct page *page = sg_page(&buf->sg[i]);
> + if (!page)
> + break;
> + put_page(page);
> + }
> +
> kfree(buf);
> }
>
> -static struct port_buffer *alloc_buf(size_t buf_size)
> +static struct port_buffer *alloc_buf(struct virtqueue *vq, size_t buf_size,
> + int nrbufs)
> {
> struct port_buffer *buf;
> + size_t alloc_size;
>
> - buf = kmalloc(sizeof(*buf), GFP_KERNEL);
> + /* Allocate buffer and the scatter list */
> + alloc_size = sizeof(*buf) + sizeof(struct scatterlist) * nrbufs;
This allocates one redundant sg entry when nrbuf > 0,
but I think it is OK. (just a comment)
> + buf = kmalloc(alloc_size, GFP_ATOMIC);
This should be kzalloc(), or buf->buf and others are not initialized,
which will cause unexpected kfree bug at kfree(buf->buf) in free_buf.
> if (!buf)
> goto fail;
> - buf->buf = kzalloc(buf_size, GFP_KERNEL);
> +
> + buf->sgpages = nrbufs;
> + if (nrbufs > 0)
> + return buf;
> +
> + buf->buf = kmalloc(buf_size, GFP_ATOMIC);
You can also use kzalloc here as previous code does.
But if the reason why using kzalloc comes from the security,
I think kmalloc is enough here, since the host can access
all the guest pages anyway.
> if (!buf->buf)
> goto free_buf;
> buf->len = 0;
> buf->offset = 0;
> buf->size = buf_size;
> +
> + /* Prepare scatter buffer for sending */
> + sg_init_one(buf->sg, buf->buf, buf_size);
> return buf;
>
> free_buf:
Thank you,
--
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
WARNING: multiple messages have this Message-ID (diff)
From: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
To: sjur.brandeland@stericsson.com
Cc: Amit Shah <amit.shah@redhat.com>,
linux-kernel@vger.kernel.org,
virtualization@lists.linux-foundation.org,
sjurbren@stericsson.com, Rusty Russell <rusty@rustcorp.com.au>,
"Michael S. Tsirkin" <mst@redhat.com>,
Linus Walleij <linus.walleij@linaro.org>,
yrl.pp-manager.tt@hitachi.com
Subject: Re: [PATCH 1/3] virtio_console:Merge struct buffer_token into struct port_buffer
Date: Wed, 26 Sep 2012 11:44:33 +0900 [thread overview]
Message-ID: <50626C11.9040708@hitachi.com> (raw)
In-Reply-To: <1348580837-10919-2-git-send-email-sjur.brandeland@stericsson.com>
(2012/09/25 22:47), sjur.brandeland@stericsson.com wrote:
> From: Sjur Brændeland <sjur.brandeland@stericsson.com>
>
> This merge reduces code size by unifying the approach for
> sending scatter-lists and regular buffers. Any type of
> write operation (splice, write, put_chars) will now allocate
> a port_buffer and send_buf() and free_buf() can always be used.
Thanks!
This looks much nicer and simpler. I just have some comments below.
> Signed-off-by: Sjur Brændeland <sjur.brandeland@stericsson.com>
> cc: Rusty Russell <rusty@rustcorp.com.au>
> cc: Michael S. Tsirkin <mst@redhat.com>
> cc: Amit Shah <amit.shah@redhat.com>
> cc: Linus Walleij <linus.walleij@linaro.org>
> cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
> ---
> drivers/char/virtio_console.c | 141 ++++++++++++++++++-----------------------
> 1 files changed, 62 insertions(+), 79 deletions(-)
>
> diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
> index 8ab9c3d..f4f7b04 100644
> --- a/drivers/char/virtio_console.c
> +++ b/drivers/char/virtio_console.c
> @@ -111,6 +111,11 @@ struct port_buffer {
> size_t len;
> /* offset in the buf from which to consume data */
> size_t offset;
> +
> + /* If sgpages == 0 then buf is used, else sg is used */
> + unsigned int sgpages;
> +
> + struct scatterlist sg[1];
> };
>
> /*
> @@ -338,23 +343,46 @@ static inline bool use_multiport(struct ports_device *portdev)
>
> static void free_buf(struct port_buffer *buf)
> {
> + int i;
> +
> kfree(buf->buf);
this should be done only when !buf->sgpages, or (see below)
> +
> + if (buf->sgpages)
> + for (i = 0; i < buf->sgpages; i++) {
> + struct page *page = sg_page(&buf->sg[i]);
> + if (!page)
> + break;
> + put_page(page);
> + }
> +
> kfree(buf);
> }
>
> -static struct port_buffer *alloc_buf(size_t buf_size)
> +static struct port_buffer *alloc_buf(struct virtqueue *vq, size_t buf_size,
> + int nrbufs)
> {
> struct port_buffer *buf;
> + size_t alloc_size;
>
> - buf = kmalloc(sizeof(*buf), GFP_KERNEL);
> + /* Allocate buffer and the scatter list */
> + alloc_size = sizeof(*buf) + sizeof(struct scatterlist) * nrbufs;
This allocates one redundant sg entry when nrbuf > 0,
but I think it is OK. (just a comment)
> + buf = kmalloc(alloc_size, GFP_ATOMIC);
This should be kzalloc(), or buf->buf and others are not initialized,
which will cause unexpected kfree bug at kfree(buf->buf) in free_buf.
> if (!buf)
> goto fail;
> - buf->buf = kzalloc(buf_size, GFP_KERNEL);
> +
> + buf->sgpages = nrbufs;
> + if (nrbufs > 0)
> + return buf;
> +
> + buf->buf = kmalloc(buf_size, GFP_ATOMIC);
You can also use kzalloc here as previous code does.
But if the reason why using kzalloc comes from the security,
I think kmalloc is enough here, since the host can access
all the guest pages anyway.
> if (!buf->buf)
> goto free_buf;
> buf->len = 0;
> buf->offset = 0;
> buf->size = buf_size;
> +
> + /* Prepare scatter buffer for sending */
> + sg_init_one(buf->sg, buf->buf, buf_size);
> return buf;
>
> free_buf:
Thank you,
--
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com
next prev parent reply other threads:[~2012-09-26 2:44 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-25 13:47 [PATCHv6 0/3] virtio_console: Add rproc_serial device sjur.brandeland
2012-09-25 13:47 ` sjur.brandeland
2012-09-25 13:47 ` [PATCH 1/3] virtio_console:Merge struct buffer_token into struct port_buffer sjur.brandeland
2012-09-25 13:47 ` sjur.brandeland
2012-09-26 2:44 ` Masami Hiramatsu [this message]
2012-09-26 2:44 ` Masami Hiramatsu
2012-09-26 7:48 ` Sjur BRENDELAND
2012-09-26 7:48 ` Sjur BRENDELAND
2012-09-26 9:40 ` Masami Hiramatsu
2012-09-26 9:40 ` Masami Hiramatsu
2012-09-26 23:42 ` Rusty Russell
2012-09-26 23:42 ` Rusty Russell
2012-10-01 9:39 ` Amit Shah
2012-10-01 9:39 ` Amit Shah
2012-10-01 9:35 ` Amit Shah
2012-10-01 9:35 ` Amit Shah
2012-09-25 13:47 ` [PATCHv5 2/3] virtio_console: Add support for remoteproc serial sjur.brandeland
2012-09-25 13:47 ` sjur.brandeland
2012-09-26 23:52 ` Rusty Russell
2012-09-26 23:52 ` Rusty Russell
2012-10-01 9:52 ` Amit Shah
2012-10-01 9:52 ` Amit Shah
2012-09-25 13:47 ` [PATCH 3/3] virtio_console: Don't initialize buffers to zero sjur.brandeland
2012-09-25 13:47 ` sjur.brandeland
2012-10-01 8:24 ` Amit Shah
2012-10-01 8:24 ` Amit Shah
2012-09-28 12:48 ` [PATCHv6 0/3] virtio_console: Add rproc_serial device Amit Shah
2012-09-28 12:48 ` Amit Shah
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50626C11.9040708@hitachi.com \
--to=masami.hiramatsu.pt@hitachi.com \
--cc=amit.shah@redhat.com \
--cc=linus.walleij@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=sjur.brandeland@stericsson.com \
--cc=sjurbren@stericsson.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=yrl.pp-manager.tt@hitachi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.