render / rpms / qemu

Forked from rpms/qemu 10 months ago
Clone

Blame 0001-hw-virtio-fix-crash-in-processing-balloon-stats.patch

Daniel P. Berrangé 737c06
From 231345d9109bcc6601d570e9e04585493b125b67 Mon Sep 17 00:00:00 2001
Daniel P. Berrangé 737c06
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= <berrange@redhat.com>
Daniel P. Berrangé 737c06
Date: Fri, 29 Nov 2024 09:29:23 +0000
Daniel P. Berrangé 737c06
Subject: [PATCH] hw/virtio: fix crash in processing balloon stats
Daniel P. Berrangé 737c06
MIME-Version: 1.0
Daniel P. Berrangé 737c06
Content-Type: text/plain; charset=UTF-8
Daniel P. Berrangé 737c06
Content-Transfer-Encoding: 8bit
Daniel P. Berrangé 737c06
Daniel P. Berrangé 737c06
balloon_stats_get_all will iterate over guest stats upto the max
Daniel P. Berrangé 737c06
VIRTIO_BALLOON_S_NR value, calling visit_type_uint64 to populate
Daniel P. Berrangé 737c06
the QObject dict. The dict keys are obtained from the static
Daniel P. Berrangé 737c06
array balloon_stat_names which is VIRTIO_BALLOON_S_NR in size.
Daniel P. Berrangé 737c06
Daniel P. Berrangé 737c06
Unfortunately the way that array is declared results in any
Daniel P. Berrangé 737c06
unassigned stats getting a NULL name, which will then cause
Daniel P. Berrangé 737c06
visit_type_uint64 to trigger an assert in qobject_output_add_obj.
Daniel P. Berrangé 737c06
Daniel P. Berrangé 737c06
The balloon_stat_names array was fortunately fully populated with
Daniel P. Berrangé 737c06
names until recently:
Daniel P. Berrangé 737c06
Daniel P. Berrangé 737c06
  commit 0d2eeef77a33315187df8519491a900bde4a3d83
Daniel P. Berrangé 737c06
  Author: Bibo Mao <maobibo@loongson.cn>
Daniel P. Berrangé 737c06
  Date:   Mon Oct 28 10:38:09 2024 +0800
Daniel P. Berrangé 737c06
Daniel P. Berrangé 737c06
    linux-headers: Update to Linux v6.12-rc5
Daniel P. Berrangé 737c06
Daniel P. Berrangé 737c06
pulled a change to include/standard-headers/linux/virtio_balloon.h
Daniel P. Berrangé 737c06
which increased VIRTIO_BALLOON_S_NR by 6, and failed to add the new
Daniel P. Berrangé 737c06
names to balloon_stat_names.
Daniel P. Berrangé 737c06
Daniel P. Berrangé 737c06
This commit fills in the missing names, and uses a static assert to
Daniel P. Berrangé 737c06
guarantee that any future changes to VIRTIO_BALLOON_S_NR will cause
Daniel P. Berrangé 737c06
a build failure until balloon_stat_names is updated.
Daniel P. Berrangé 737c06
Daniel P. Berrangé 737c06
This problem was detected by the Cockpit Project's automated
Daniel P. Berrangé 737c06
integration tests on QEMU 9.2.0-rc1.
Daniel P. Berrangé 737c06
Daniel P. Berrangé 737c06
Fixes: 0d2eeef77a33315187df8519491a900bde4a3d83
Daniel P. Berrangé 737c06
Reported-by: Martin Pitt <mpitt@redhat.com>
Daniel P. Berrangé 737c06
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Daniel P. Berrangé 737c06
---
Daniel P. Berrangé 737c06
 hw/virtio/virtio-balloon.c | 16 +++++++++++++++-
Daniel P. Berrangé 737c06
 1 file changed, 15 insertions(+), 1 deletion(-)
Daniel P. Berrangé 737c06
Daniel P. Berrangé 737c06
diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
Daniel P. Berrangé 737c06
index 609e39a821..afd2ad6dd6 100644
Daniel P. Berrangé 737c06
--- a/hw/virtio/virtio-balloon.c
Daniel P. Berrangé 737c06
+++ b/hw/virtio/virtio-balloon.c
Daniel P. Berrangé 737c06
@@ -167,19 +167,33 @@ static void balloon_deflate_page(VirtIOBalloon *balloon,
Daniel P. Berrangé 737c06
     }
Daniel P. Berrangé 737c06
 }
Daniel P. Berrangé 737c06
 
Daniel P. Berrangé 737c06
+/*
Daniel P. Berrangé 737c06
+ * All stats upto VIRTIO_BALLOON_S_NR /must/ have a
Daniel P. Berrangé 737c06
+ * non-NULL name declared here, since these are used
Daniel P. Berrangé 737c06
+ * as keys for populating the QDict with stats
Daniel P. Berrangé 737c06
+ */
Daniel P. Berrangé 737c06
 static const char *balloon_stat_names[] = {
Daniel P. Berrangé 737c06
    [VIRTIO_BALLOON_S_SWAP_IN] = "stat-swap-in",
Daniel P. Berrangé 737c06
    [VIRTIO_BALLOON_S_SWAP_OUT] = "stat-swap-out",
Daniel P. Berrangé 737c06
    [VIRTIO_BALLOON_S_MAJFLT] = "stat-major-faults",
Daniel P. Berrangé 737c06
    [VIRTIO_BALLOON_S_MINFLT] = "stat-minor-faults",
Daniel P. Berrangé 737c06
    [VIRTIO_BALLOON_S_MEMFREE] = "stat-free-memory",
Daniel P. Berrangé 737c06
+
Daniel P. Berrangé 737c06
    [VIRTIO_BALLOON_S_MEMTOT] = "stat-total-memory",
Daniel P. Berrangé 737c06
    [VIRTIO_BALLOON_S_AVAIL] = "stat-available-memory",
Daniel P. Berrangé 737c06
    [VIRTIO_BALLOON_S_CACHES] = "stat-disk-caches",
Daniel P. Berrangé 737c06
    [VIRTIO_BALLOON_S_HTLB_PGALLOC] = "stat-htlb-pgalloc",
Daniel P. Berrangé 737c06
    [VIRTIO_BALLOON_S_HTLB_PGFAIL] = "stat-htlb-pgfail",
Daniel P. Berrangé 737c06
-   [VIRTIO_BALLOON_S_NR] = NULL
Daniel P. Berrangé 737c06
+
Daniel P. Berrangé 737c06
+   [VIRTIO_BALLOON_S_OOM_KILL] = "stat-oom-kills",
Daniel P. Berrangé 737c06
+   [VIRTIO_BALLOON_S_ALLOC_STALL] = "stat-alloc-stalls",
Daniel P. Berrangé 737c06
+   [VIRTIO_BALLOON_S_ASYNC_SCAN] = "stat-async-scans",
Daniel P. Berrangé 737c06
+   [VIRTIO_BALLOON_S_DIRECT_SCAN] = "stat-direct-scans",
Daniel P. Berrangé 737c06
+   [VIRTIO_BALLOON_S_ASYNC_RECLAIM] = "stat-async-reclaims",
Daniel P. Berrangé 737c06
+
Daniel P. Berrangé 737c06
+   [VIRTIO_BALLOON_S_DIRECT_RECLAIM] = "stat-direct-reclaims",
Daniel P. Berrangé 737c06
 };
Daniel P. Berrangé 737c06
+G_STATIC_ASSERT(G_N_ELEMENTS(balloon_stat_names) == VIRTIO_BALLOON_S_NR);
Daniel P. Berrangé 737c06
 
Daniel P. Berrangé 737c06
 /*
Daniel P. Berrangé 737c06
  * reset_stats - Mark all items in the stats array as unset
Daniel P. Berrangé 737c06
-- 
Daniel P. Berrangé 737c06
2.46.0
Daniel P. Berrangé 737c06