From: Paul Durrant <Paul.Durrant@citrix.com>
To: Anthony Perard <anthony.perard@citrix.com>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Cc: Anthony Perard <anthony.perard@citrix.com>,
"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
Stefano Stabellini <sstabellini@kernel.org>
Subject: Re: [Xen-devel] [PATCH 4/4] xen: Avoid VLA
Date: Mon, 17 Jun 2019 16:39:09 +0000 [thread overview]
Message-ID: <a3843cb971bc4fa8886170d0b2461a44@AMSPEX02CL03.citrite.net> (raw)
In-Reply-To: <20190617154105.32323-5-anthony.perard@citrix.com>
> -----Original Message-----
> From: Anthony PERARD [mailto:anthony.perard@citrix.com]
> Sent: 17 June 2019 16:41
> To: qemu-devel@nongnu.org
> Cc: xen-devel@lists.xenproject.org; Anthony Perard <anthony.perard@citrix.com>; Stefano Stabellini
> <sstabellini@kernel.org>; Paul Durrant <Paul.Durrant@citrix.com>
> Subject: [PATCH 4/4] xen: Avoid VLA
>
> Avoid using a variable length array.
>
> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
> ---
>
> Notes:
> Was suggested by Peter here:
> <CAFEAcA88+A2oCkQnxKDEdpmfCZSmPzWMBg01wDDV68bMZoY5Jg@mail.gmail.com>
> "should we try to stop using variable length arrays?"
>
> hw/i386/xen/xen-hvm.c | 11 ++++++++---
> 1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c
> index 725f9c2278..10d73b55b4 100644
> --- a/hw/i386/xen/xen-hvm.c
> +++ b/hw/i386/xen/xen-hvm.c
> @@ -615,7 +615,8 @@ static void xen_sync_dirty_bitmap(XenIOState *state,
> {
> hwaddr npages = size >> TARGET_PAGE_BITS;
> const int width = sizeof(unsigned long) * 8;
> - unsigned long bitmap[DIV_ROUND_UP(npages, width)];
> + unsigned long *bitmap = NULL;
> + size_t bitmap_size = DIV_ROUND_UP(npages, width);
> int rc, i, j;
> const XenPhysmap *physmap = NULL;
>
> @@ -632,6 +633,8 @@ static void xen_sync_dirty_bitmap(XenIOState *state,
> return;
> }
>
> + bitmap = g_new0(unsigned long, bitmap_size);
> +
How hot is this function? It looks (unsurprisingly) like the section size determines the map size so I wonder whether it can instead be allocated once when the section is added?
Paul
> rc = xen_track_dirty_vram(xen_domid, start_addr >> TARGET_PAGE_BITS,
> npages, bitmap);
> if (rc < 0) {
> @@ -644,10 +647,10 @@ static void xen_sync_dirty_bitmap(XenIOState *state,
> ", 0x" TARGET_FMT_plx "): %s\n",
> start_addr, start_addr + size, strerror(errno));
> }
> - return;
> + goto out;
> }
>
> - for (i = 0; i < ARRAY_SIZE(bitmap); i++) {
> + for (i = 0; i < bitmap_size; i++) {
> unsigned long map = bitmap[i];
> while (map != 0) {
> j = ctzl(map);
> @@ -657,6 +660,8 @@ static void xen_sync_dirty_bitmap(XenIOState *state,
> TARGET_PAGE_SIZE);
> };
> }
> +out:
> + g_free(bitmap);
> }
>
> static void xen_log_start(MemoryListener *listener,
> --
> Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2019-06-17 16:39 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-17 15:41 [Xen-devel] [PATCH 0/4] Fix build of Xen support + cleanup Anthony PERARD
2019-06-17 15:41 ` [Xen-devel] [PATCH 1/4] xen: Fix build with public headers Anthony PERARD
2019-06-17 16:05 ` Paul Durrant
2019-06-17 15:41 ` [Xen-devel] [PATCH 2/4] xen: Import other xen/io/*.h Anthony PERARD
2019-06-17 16:09 ` Paul Durrant
2019-06-17 15:41 ` [Xen-devel] [PATCH 3/4] xen: Import Xen public headers used by xen-hvm.c Anthony PERARD
2019-06-17 16:15 ` Paul Durrant
2019-06-17 16:45 ` Anthony PERARD
2019-06-17 16:54 ` Paul Durrant
2019-06-17 17:19 ` Anthony PERARD
2019-06-18 7:55 ` Paul Durrant
2019-06-18 11:05 ` Anthony PERARD
2019-06-17 15:41 ` [Xen-devel] [PATCH 4/4] xen: Avoid VLA Anthony PERARD
2019-06-17 16:39 ` Paul Durrant [this message]
2019-06-17 17:36 ` Anthony PERARD
2019-06-18 7:50 ` Paul Durrant
2019-06-17 18:09 ` [Xen-devel] [PATCH 0/4] Fix build of Xen support + cleanup no-reply
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=a3843cb971bc4fa8886170d0b2461a44@AMSPEX02CL03.citrite.net \
--to=paul.durrant@citrix.com \
--cc=anthony.perard@citrix.com \
--cc=qemu-devel@nongnu.org \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).