From: Anthony PERARD <anthony.perard@citrix.com>
To: <qemu-devel@nongnu.org>
Cc: Anthony PERARD <anthony.perard@citrix.com>,
xen-devel@lists.xenproject.org,
Paul Durrant <paul.durrant@citrix.com>,
Stefano Stabellini <sstabellini@kernel.org>
Subject: [Xen-devel] [PATCH v2 4/4] xen: Avoid VLA
Date: Tue, 18 Jun 2019 12:23:41 +0100 [thread overview]
Message-ID: <20190618112341.513-5-anthony.perard@citrix.com> (raw)
In-Reply-To: <20190618112341.513-1-anthony.perard@citrix.com>
Avoid using a variable length array.
We allocate the `dirty_bitmap' buffer only once when we start tracking
for dirty bits.
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
Notes:
v2:
- Allocate the bitmap buffer only once when we start tracking dirty bits.
(instead of at every function call)
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 | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c
index ae3deb4ef3..469f1260a4 100644
--- a/hw/i386/xen/xen-hvm.c
+++ b/hw/i386/xen/xen-hvm.c
@@ -119,6 +119,8 @@ typedef struct XenIOState {
DeviceListener device_listener;
hwaddr free_phys_offset;
const XenPhysmap *log_for_dirtybit;
+ /* Buffer used by xen_sync_dirty_bitmap */
+ unsigned long *dirty_bitmap;
Notifier exit;
Notifier suspend;
@@ -464,6 +466,8 @@ static int xen_remove_from_physmap(XenIOState *state,
QLIST_REMOVE(physmap, list);
if (state->log_for_dirtybit == physmap) {
state->log_for_dirtybit = NULL;
+ g_free(state->dirty_bitmap);
+ state->dirty_bitmap = NULL;
}
g_free(physmap);
@@ -614,7 +618,7 @@ 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)];
+ size_t bitmap_size = DIV_ROUND_UP(npages, width);
int rc, i, j;
const XenPhysmap *physmap = NULL;
@@ -626,13 +630,14 @@ static void xen_sync_dirty_bitmap(XenIOState *state,
if (state->log_for_dirtybit == NULL) {
state->log_for_dirtybit = physmap;
+ state->dirty_bitmap = g_new(unsigned long, bitmap_size);
} else if (state->log_for_dirtybit != physmap) {
/* Only one range for dirty bitmap can be tracked. */
return;
}
rc = xen_track_dirty_vram(xen_domid, start_addr >> TARGET_PAGE_BITS,
- npages, bitmap);
+ npages, state->dirty_bitmap);
if (rc < 0) {
#ifndef ENODATA
#define ENODATA ENOENT
@@ -646,8 +651,8 @@ static void xen_sync_dirty_bitmap(XenIOState *state,
return;
}
- for (i = 0; i < ARRAY_SIZE(bitmap); i++) {
- unsigned long map = bitmap[i];
+ for (i = 0; i < bitmap_size; i++) {
+ unsigned long map = state->dirty_bitmap[i];
while (map != 0) {
j = ctzl(map);
map &= ~(1ul << j);
@@ -677,6 +682,8 @@ static void xen_log_stop(MemoryListener *listener, MemoryRegionSection *section,
if (old & ~new & (1 << DIRTY_MEMORY_VGA)) {
state->log_for_dirtybit = NULL;
+ g_free(state->dirty_bitmap);
+ state->dirty_bitmap = NULL;
/* Disable dirty bit tracking */
xen_track_dirty_vram(xen_domid, 0, 0, NULL);
}
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
WARNING: multiple messages have this Message-ID (diff)
From: Anthony PERARD <anthony.perard@citrix.com>
To: <qemu-devel@nongnu.org>
Cc: Anthony PERARD <anthony.perard@citrix.com>,
xen-devel@lists.xenproject.org,
Paul Durrant <paul.durrant@citrix.com>,
Stefano Stabellini <sstabellini@kernel.org>
Subject: [Qemu-devel] [PATCH v2 4/4] xen: Avoid VLA
Date: Tue, 18 Jun 2019 12:23:41 +0100 [thread overview]
Message-ID: <20190618112341.513-5-anthony.perard@citrix.com> (raw)
In-Reply-To: <20190618112341.513-1-anthony.perard@citrix.com>
Avoid using a variable length array.
We allocate the `dirty_bitmap' buffer only once when we start tracking
for dirty bits.
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
Notes:
v2:
- Allocate the bitmap buffer only once when we start tracking dirty bits.
(instead of at every function call)
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 | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c
index ae3deb4ef3..469f1260a4 100644
--- a/hw/i386/xen/xen-hvm.c
+++ b/hw/i386/xen/xen-hvm.c
@@ -119,6 +119,8 @@ typedef struct XenIOState {
DeviceListener device_listener;
hwaddr free_phys_offset;
const XenPhysmap *log_for_dirtybit;
+ /* Buffer used by xen_sync_dirty_bitmap */
+ unsigned long *dirty_bitmap;
Notifier exit;
Notifier suspend;
@@ -464,6 +466,8 @@ static int xen_remove_from_physmap(XenIOState *state,
QLIST_REMOVE(physmap, list);
if (state->log_for_dirtybit == physmap) {
state->log_for_dirtybit = NULL;
+ g_free(state->dirty_bitmap);
+ state->dirty_bitmap = NULL;
}
g_free(physmap);
@@ -614,7 +618,7 @@ 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)];
+ size_t bitmap_size = DIV_ROUND_UP(npages, width);
int rc, i, j;
const XenPhysmap *physmap = NULL;
@@ -626,13 +630,14 @@ static void xen_sync_dirty_bitmap(XenIOState *state,
if (state->log_for_dirtybit == NULL) {
state->log_for_dirtybit = physmap;
+ state->dirty_bitmap = g_new(unsigned long, bitmap_size);
} else if (state->log_for_dirtybit != physmap) {
/* Only one range for dirty bitmap can be tracked. */
return;
}
rc = xen_track_dirty_vram(xen_domid, start_addr >> TARGET_PAGE_BITS,
- npages, bitmap);
+ npages, state->dirty_bitmap);
if (rc < 0) {
#ifndef ENODATA
#define ENODATA ENOENT
@@ -646,8 +651,8 @@ static void xen_sync_dirty_bitmap(XenIOState *state,
return;
}
- for (i = 0; i < ARRAY_SIZE(bitmap); i++) {
- unsigned long map = bitmap[i];
+ for (i = 0; i < bitmap_size; i++) {
+ unsigned long map = state->dirty_bitmap[i];
while (map != 0) {
j = ctzl(map);
map &= ~(1ul << j);
@@ -677,6 +682,8 @@ static void xen_log_stop(MemoryListener *listener, MemoryRegionSection *section,
if (old & ~new & (1 << DIRTY_MEMORY_VGA)) {
state->log_for_dirtybit = NULL;
+ g_free(state->dirty_bitmap);
+ state->dirty_bitmap = NULL;
/* Disable dirty bit tracking */
xen_track_dirty_vram(xen_domid, 0, 0, NULL);
}
--
Anthony PERARD
next prev parent reply other threads:[~2019-06-18 11:24 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-18 11:23 [Xen-devel] [PATCH v2 0/4] Fix build of Xen support + cleanup Anthony PERARD
2019-06-18 11:23 ` [Qemu-devel] " Anthony PERARD
2019-06-18 11:23 ` [Xen-devel] [PATCH v2 1/4] xen: Fix build with public headers Anthony PERARD
2019-06-18 11:23 ` [Qemu-devel] " Anthony PERARD
2019-06-18 12:14 ` [Xen-devel] " Daniel P. Berrangé
2019-06-18 12:14 ` Daniel P. Berrangé
2019-06-20 14:44 ` [Xen-devel] " Anthony PERARD
2019-06-20 14:44 ` Anthony PERARD
2019-06-18 11:23 ` [Xen-devel] [PATCH v2 2/4] xen: Import other xen/io/*.h Anthony PERARD
2019-06-18 11:23 ` [Qemu-devel] " Anthony PERARD
2019-06-18 11:23 ` [Xen-devel] [PATCH v2 3/4] xen: Drop includes of xen/hvm/params.h Anthony PERARD
2019-06-18 11:23 ` [Qemu-devel] " Anthony PERARD
2019-06-18 11:51 ` [Xen-devel] " Paul Durrant
2019-06-18 11:51 ` [Qemu-devel] " Paul Durrant
2019-06-18 11:23 ` Anthony PERARD [this message]
2019-06-18 11:23 ` [Qemu-devel] [PATCH v2 4/4] xen: Avoid VLA Anthony PERARD
2019-06-18 11:35 ` [Xen-devel] " Philippe Mathieu-Daudé
2019-06-18 11:35 ` Philippe Mathieu-Daudé
2019-06-18 11:52 ` [Xen-devel] " Paul Durrant
2019-06-18 11:52 ` [Qemu-devel] " Paul Durrant
2019-06-18 12:00 ` [Xen-devel] [PATCH v2 0/4] Fix build of Xen support + cleanup no-reply
2019-06-18 12:00 ` [Qemu-devel] " 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=20190618112341.513-5-anthony.perard@citrix.com \
--to=anthony.perard@citrix.com \
--cc=paul.durrant@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 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.