74 lines
3.0 KiB
Diff
74 lines
3.0 KiB
Diff
From ea242d728ed1716602b4cdd01d3fabb5ab260781 Mon Sep 17 00:00:00 2001
|
|
From: Stefan Hajnoczi <stefanha@redhat.com>
|
|
Date: Tue, 10 Jun 2025 13:36:40 +0100
|
|
Subject: [PATCH 03/31] hw/virtio/virtio: avoid cost of -ftrivial-auto-var-init
|
|
in hot path
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
RH-Author: Stefan Hajnoczi <stefanha@redhat.com>
|
|
RH-MergeRequest: 461: Solve -ftrivial-auto-var-init performance regression with QEMU_UNINITIALIZED
|
|
RH-Jira: RHEL-99887
|
|
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
RH-Commit: [2/30] a90fb4e14c182ace7a28c8335858895b4257f37b
|
|
|
|
Since commit 7ff9ff039380 ("meson: mitigate against use of uninitialize
|
|
stack for exploits") the -ftrivial-auto-var-init=zero compiler option is
|
|
used to zero local variables. While this reduces security risks
|
|
associated with uninitialized stack data, it introduced a measurable
|
|
bottleneck in the virtqueue_split_pop() and virtqueue_packed_pop()
|
|
functions.
|
|
|
|
These virtqueue functions are in the hot path. They are called for each
|
|
element (request) that is popped from a VIRTIO device's virtqueue. Using
|
|
__attribute__((uninitialized)) on large stack variables in these
|
|
functions improves fio randread bs=4k iodepth=64 performance from 304k
|
|
to 332k IOPS (+9%).
|
|
|
|
This issue was found using perf-top(1). virtqueue_split_pop() was one of
|
|
the top CPU consumers and the "annotate" feature showed that the memory
|
|
zeroing instructions at the beginning of the functions were hot.
|
|
|
|
Fixes: 7ff9ff039380 ("meson: mitigate against use of uninitialize stack for exploits")
|
|
Cc: Daniel P. Berrangé <berrange@redhat.com>
|
|
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
Message-id: 20250610123709.835102-3-berrange@redhat.com
|
|
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
(cherry picked from commit ba2868ce091cd4abe4be6de4b7e44b3be303b352)
|
|
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
---
|
|
hw/virtio/virtio.c | 8 ++++----
|
|
1 file changed, 4 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
|
|
index 10f24a58dd..7f7b178a50 100644
|
|
--- a/hw/virtio/virtio.c
|
|
+++ b/hw/virtio/virtio.c
|
|
@@ -1680,8 +1680,8 @@ static void *virtqueue_split_pop(VirtQueue *vq, size_t sz)
|
|
VirtIODevice *vdev = vq->vdev;
|
|
VirtQueueElement *elem = NULL;
|
|
unsigned out_num, in_num, elem_entries;
|
|
- hwaddr addr[VIRTQUEUE_MAX_SIZE];
|
|
- struct iovec iov[VIRTQUEUE_MAX_SIZE];
|
|
+ hwaddr QEMU_UNINITIALIZED addr[VIRTQUEUE_MAX_SIZE];
|
|
+ struct iovec QEMU_UNINITIALIZED iov[VIRTQUEUE_MAX_SIZE];
|
|
VRingDesc desc;
|
|
int rc;
|
|
|
|
@@ -1826,8 +1826,8 @@ static void *virtqueue_packed_pop(VirtQueue *vq, size_t sz)
|
|
VirtIODevice *vdev = vq->vdev;
|
|
VirtQueueElement *elem = NULL;
|
|
unsigned out_num, in_num, elem_entries;
|
|
- hwaddr addr[VIRTQUEUE_MAX_SIZE];
|
|
- struct iovec iov[VIRTQUEUE_MAX_SIZE];
|
|
+ hwaddr QEMU_UNINITIALIZED addr[VIRTQUEUE_MAX_SIZE];
|
|
+ struct iovec QEMU_UNINITIALIZED iov[VIRTQUEUE_MAX_SIZE];
|
|
VRingPackedDesc desc;
|
|
uint16_t id;
|
|
int rc;
|
|
--
|
|
2.39.3
|
|
|