render / rpms / qemu

Forked from rpms/qemu 9 months ago
Clone

Blame 0120-qemu-Use-valgrind-annotations-to-mark-kvm-guest-memo.patch

5544c1
From e688bfbda0f6893b08d1e51f4fb26d4b38e922d4 Mon Sep 17 00:00:00 2001
5544c1
From: Christian Borntraeger <borntraeger@de.ibm.com>
5544c1
Date: Fri, 10 Aug 2012 15:11:45 +0200
5544c1
Subject: [PATCH] qemu: Use valgrind annotations to mark kvm guest memory as
5544c1
 defined
5544c1
5544c1
valgrind with kvm produces a big amount of false positives regarding
5544c1
"Conditional jump or move depends on uninitialised value(s)". This
5544c1
happens because the guest memory is allocated with qemu_vmalloc which
5544c1
boils down posix_memalign etc. This function is (correctly) considered
5544c1
by valgrind as returning undefined memory.
5544c1
5544c1
Since valgrind is based on jitting code, it will not be able to see
5544c1
changes made by the guest to guest memory if this is done by KVM_RUN,
5544c1
thus keeping most of the guest memory undefined.
5544c1
5544c1
Now lots of places in qemu will then use guest memory to change behaviour.
5544c1
To avoid the flood of these messages, lets declare the whole guest
5544c1
memory as defined. This will reduce the noise and allows us to see real
5544c1
problems.
5544c1
5544c1
In the future we might want to make this conditional, since there
5544c1
is actually something that we can use those false positives for:
5544c1
These messages will point to code that depends on guest memory, so
5544c1
we can use these backtraces to actually make an audit that is focussed
5544c1
only at those code places. For normal development we dont want to
5544c1
see those messages, though.
5544c1
5544c1
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
5544c1
Signed-off-by: Avi Kivity <avi@redhat.com>
5544c1
(cherry picked from commit 62fe83318d2fc5b31f473d66326910d94c1c4907)
5544c1
5544c1
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
5544c1
---
5544c1
 configure | 3 ++-
5544c1
 kvm-all.c | 7 +++++++
5544c1
 2 files changed, 9 insertions(+), 1 deletion(-)
5544c1
5544c1
diff --git a/configure b/configure
5544c1
index d7a948f..8874eff 100755
5544c1
--- a/configure
5544c1
+++ b/configure
5544c1
@@ -2937,11 +2937,12 @@ if compile_prog "-Werror" "" ; then
5544c1
 fi
5544c1
 
5544c1
 ########################################
5544c1
-# check if we have valgrind/valgrind.h
5544c1
+# check if we have valgrind/valgrind.h and valgrind/memcheck.h
5544c1
 
5544c1
 valgrind_h=no
5544c1
 cat > $TMPC << EOF
5544c1
 #include <valgrind/valgrind.h>
5544c1
+#include <valgrind/memcheck.h>
5544c1
 int main(void) {
5544c1
   return 0;
5544c1
 }
5544c1
diff --git a/kvm-all.c b/kvm-all.c
5544c1
index badf1d8..90c71f9 100644
5544c1
--- a/kvm-all.c
5544c1
+++ b/kvm-all.c
5544c1
@@ -39,6 +39,10 @@
5544c1
 #include <sys/eventfd.h>
5544c1
 #endif
5544c1
 
5544c1
+#ifdef CONFIG_VALGRIND_H
5544c1
+#include <valgrind/memcheck.h>
5544c1
+#endif
5544c1
+
5544c1
 /* KVM uses PAGE_SIZE in its definition of COALESCED_MMIO_MAX */
5544c1
 #define PAGE_SIZE TARGET_PAGE_SIZE
5544c1
 
5544c1
@@ -1769,6 +1773,9 @@ void *kvm_vmalloc(ram_addr_t size)
5544c1
 
5544c1
 void kvm_setup_guest_memory(void *start, size_t size)
5544c1
 {
5544c1
+#ifdef CONFIG_VALGRIND_H
5544c1
+    VALGRIND_MAKE_MEM_DEFINED(start, size);
5544c1
+#endif
5544c1
     if (!kvm_has_sync_mmu()) {
5544c1
         int ret = qemu_madvise(start, size, QEMU_MADV_DONTFORK);
5544c1
 
5544c1
-- 
5544c1
1.7.12.1
5544c1