81 lines
3.2 KiB
Diff
81 lines
3.2 KiB
Diff
From 73f85b945f09ae118f2c1479110f2e34906e084b Mon Sep 17 00:00:00 2001
|
|
From: Stefan Hajnoczi <stefanha@redhat.com>
|
|
Date: Tue, 10 Jun 2025 13:36:39 +0100
|
|
Subject: [PATCH 02/31] include/qemu/compiler: add QEMU_UNINITIALIZED attribute
|
|
macro
|
|
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: [1/30] 6b6151625fdf6636cbf352731906f643e2fbfd35
|
|
|
|
The QEMU_UNINITIALIZED macro is to be used to skip the default compiler
|
|
variable initialization done by -ftrivial-auto-var-init=zero.
|
|
|
|
Use this in cases where there a method in the device I/O path (or other
|
|
important hot paths), that has large variables on the stack. A rule of
|
|
thumb is that "large" means a method with 4kb data in the local stack
|
|
frame. Any variables which are KB in size, should be annotated with this
|
|
attribute, to pre-emptively eliminate any potential overhead from the
|
|
compiler zero'ing memory.
|
|
|
|
Given that this turns off a security hardening feature, when using this
|
|
to flag variables, it is important that the code is double-checked to
|
|
ensure there is no possible use of uninitialized data in the method.
|
|
|
|
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
|
|
Message-id: 20250610123709.835102-2-berrange@redhat.com
|
|
[DB: split off patch & rewrite guidance on when to use the annotation]
|
|
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
|
|
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
(cherry picked from commit c653b67d1863b7ebfa67f7c9f4aec209d7b5ced5)
|
|
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
|
Conflicts:
|
|
include/qemu/compiler.h
|
|
Context conflict due to clang Thread Safety Analysis macros.
|
|
---
|
|
include/qemu/compiler.h | 20 ++++++++++++++++++++
|
|
1 file changed, 20 insertions(+)
|
|
|
|
diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
|
|
index c06954ccb4..cc193d5b82 100644
|
|
--- a/include/qemu/compiler.h
|
|
+++ b/include/qemu/compiler.h
|
|
@@ -212,6 +212,26 @@
|
|
# define QEMU_USED
|
|
#endif
|
|
|
|
+/*
|
|
+ * Disable -ftrivial-auto-var-init on a local variable.
|
|
+ *
|
|
+ * Use this in cases where there a method in the device I/O path (or other
|
|
+ * important hot paths), that has large variables on the stack. A rule of
|
|
+ * thumb is that "large" means a method with 4kb data in the local stack
|
|
+ * frame. Any variables which are KB in size, should be annotated with this
|
|
+ * attribute, to pre-emptively eliminate any potential overhead from the
|
|
+ * compiler's implicit zero'ing of memory.
|
|
+ *
|
|
+ * Given that this turns off a security hardening feature, when using this
|
|
+ * to flag variables, it is important that the code is double-checked to
|
|
+ * ensure there is no possible use of uninitialized data in the method.
|
|
+ */
|
|
+#if __has_attribute(uninitialized)
|
|
+# define QEMU_UNINITIALIZED __attribute__((uninitialized))
|
|
+#else
|
|
+# define QEMU_UNINITIALIZED
|
|
+#endif
|
|
+
|
|
/*
|
|
* Ugly CPP trick that is like "defined FOO", but also works in C
|
|
* code. Useful to replace #ifdef with "if" statements; assumes
|
|
--
|
|
2.39.3
|
|
|