From patchwork Fri Aug 10 13:11:45 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Borntraeger X-Patchwork-Id: 176491 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 08D882C00D1 for ; Fri, 10 Aug 2012 23:12:07 +1000 (EST) Received: from localhost ([::1]:43273 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Szp0X-0003P9-2h for incoming@patchwork.ozlabs.org; Fri, 10 Aug 2012 09:12:05 -0400 Received: from eggs.gnu.org ([208.118.235.92]:40959) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Szp0M-0003P0-8I for qemu-devel@nongnu.org; Fri, 10 Aug 2012 09:11:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Szp0L-0000WW-6D for qemu-devel@nongnu.org; Fri, 10 Aug 2012 09:11:54 -0400 Received: from e06smtp16.uk.ibm.com ([195.75.94.112]:32945) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Szp0K-0000W8-UA for qemu-devel@nongnu.org; Fri, 10 Aug 2012 09:11:53 -0400 Received: from /spool/local by e06smtp16.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 10 Aug 2012 14:11:51 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp16.uk.ibm.com (192.168.101.146) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 10 Aug 2012 14:11:49 +0100 Received: from d06av05.portsmouth.uk.ibm.com (d06av05.portsmouth.uk.ibm.com [9.149.37.229]) by b06cxnps3075.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q7ADBgPG20578332 for ; Fri, 10 Aug 2012 13:11:42 GMT Received: from d06av05.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q7ADBmD3007968 for ; Fri, 10 Aug 2012 07:11:48 -0600 Received: from localhost.localdomain (dyn-9-152-224-85.boeblingen.de.ibm.com [9.152.224.85]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q7ADBmIb007958; Fri, 10 Aug 2012 07:11:48 -0600 From: Christian Borntraeger To: Avi Kivity , Marcelo Tosatti , Anthony Liguori Date: Fri, 10 Aug 2012 15:11:45 +0200 Message-Id: <1344604305-25312-1-git-send-email-borntraeger@de.ibm.com> X-Mailer: git-send-email 1.7.0.4 x-cbid: 12081013-3548-0000-0000-000002CAEF8D X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.75.94.112 Cc: Christian Borntraeger , qemu-devel@nongnu.org Subject: [Qemu-devel] [RFC/PATCH] qemu: Use valgrind annotations to mark kvm guest memory as defined X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org valgrind with kvm produces a big amount of false positives regarding "Conditional jump or move depends on uninitialised value(s)". This happens because the guest memory is allocated with qemu_vmalloc which boils down posix_memalign etc. This function is (correctly) considered by valgrind as returning undefined memory. Since valgrind is based on jitting code, it will not be able to see changes made by the guest to guest memory if this is done by KVM_RUN, thus keeping most of the guest memory undefined. Now lots of places in qemu will then use guest memory to change behaviour. To avoid the flood of these messages, lets declare the whole guest memory as defined. This will reduce the noise and allows us to see real problems. In the future we might want to make this conditional, since there is actually something that we can use those false positives for: These messages will point to code that depends on guest memory, so we can use these backtraces to actually make an audit that is focussed only at those code places. For normal development we dont want to see those messages, though. Signed-off-by: Christian Borntraeger --- configure | 3 ++- kvm-all.c | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletions(-) diff --git a/configure b/configure index 280726c..90df0d8 100755 --- a/configure +++ b/configure @@ -2900,11 +2900,12 @@ if compile_prog "-Werror" "" ; then fi ######################################## -# check if we have valgrind/valgrind.h +# check if we have valgrind/valgrind.h and valgrind/memcheck.h valgrind_h=no cat > $TMPC << EOF #include +#include int main(void) { return 0; } diff --git a/kvm-all.c b/kvm-all.c index 2148b20..33d16cf 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -39,6 +39,10 @@ #include #endif +#ifdef CONFIG_VALGRIND_H +#include +#endif + /* KVM uses PAGE_SIZE in its definition of COALESCED_MMIO_MAX */ #define PAGE_SIZE TARGET_PAGE_SIZE @@ -1687,6 +1691,9 @@ void *kvm_vmalloc(ram_addr_t size) void kvm_setup_guest_memory(void *start, size_t size) { +#ifdef CONFIG_VALGRIND_H + VALGRIND_MAKE_MEM_DEFINED(start, size); +#endif if (!kvm_has_sync_mmu()) { int ret = qemu_madvise(start, size, QEMU_MADV_DONTFORK);