Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D75B5C433EF for ; Wed, 30 Mar 2022 18:13:34 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A3F8A840EC; Wed, 30 Mar 2022 20:13:31 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="KmfgVdJL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9D012840EC; Wed, 30 Mar 2022 20:13:29 +0200 (CEST) Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id EC324840FC for ; Wed, 30 Mar 2022 20:13:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qv1-xf2f.google.com with SMTP id e22so17486927qvf.9 for ; Wed, 30 Mar 2022 11:13:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=fDDgxVVStNmSUi6LODriiAN48R825FXzL6JGXDtt4jk=; b=KmfgVdJLxJVsmdMVtyk1/so1YWoQm3m2Zh8jxqqEkWhDO/v94psdg4NAqdrNpbvO/M FpoYxdtV7bxz/rzUUBbHu+2sowc8WGhAUQcQgV4ThuVG86pTrfgpudWTDLBqRQQujmgB DooWWs+98EDRpIECVWrJE+hNWAC4AfNc9oHuEBOIFF3hdF0GFbxPte5uytRzMvJAQIyR zig6LYLRIN3K2Mw3/0460IkL6QTtxZNaTMazi+unW54lo/QLqtg1Zq7BigEAa1tXRk12 mXIeSi4kXlxbrEE+CtpMQRMoP9w4vIGotGSY9CemNQw/3CcPAo9CDAGKzkgUd/Gqxn+w ce+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=fDDgxVVStNmSUi6LODriiAN48R825FXzL6JGXDtt4jk=; b=JQEc9BzdwaE3/eTtDoa3Lm8CLKCKVCwywfA2zUg8GanLgot4bRPFlTNw8movEKghjT LpJ9iTITI5WUgMHVgfIYRuFsRDLssDE0HOQMC9N5hQri3dRH0WcrqfOWbpfotwJWbRbr +2pc8BqTzahR8AluNqnzAJWBHgVzXtB2clNzp0+kV6lHye6wXuDi8BiAywttIFeE5ZiD aW/8BPBfrWiloKUqoMFWDxHIywZsL1hLoXVLqsawWcQb+fhwbcJk/0MnWmVHyf54tXuS Ihj3EMgq5if3PHI9Df45TDUpGnuzRe0ZTWBs9Rc7aNndpRv1f9eaVWb4QSgW//auTeRJ owxA== X-Gm-Message-State: AOAM531Uq12evvUhVK/WhEFwfPBqFrPCvXInYhaKLyR17QHLl0hQTcxk zMBzou4jQSpYU7Ei/JDhDw0= X-Google-Smtp-Source: ABdhPJxz2en/dCM+WCr+cvfAld77hTxzCwr56QRwIpv+0bu7PZ6HMKg5CDULklX0M9tm9T4XgWFljQ== X-Received: by 2002:a05:6214:c21:b0:440:c80f:17a8 with SMTP id a1-20020a0562140c2100b00440c80f17a8mr32609041qvd.24.1648663992615; Wed, 30 Mar 2022 11:13:12 -0700 (PDT) Received: from [192.168.1.201] (pool-108-18-137-133.washdc.fios.verizon.net. [108.18.137.133]) by smtp.googlemail.com with ESMTPSA id r12-20020a05620a03cc00b0067d370e414esm11103540qkm.15.2022.03.30.11.13.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 30 Mar 2022 11:13:12 -0700 (PDT) Subject: Re: [PATCH v3 0/3] malloc: Enable profiling dlmalloc with valgrind To: Tom Rini , u-boot@lists.denx.de Cc: Heinrich Schuchardt , Simon Glass References: <20220323180451.48950-1-seanga2@gmail.com> From: Sean Anderson Message-ID: <57cb4b49-fa30-1194-9ac3-faa53e8033bd@gmail.com> Date: Wed, 30 Mar 2022 14:13:11 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <20220323180451.48950-1-seanga2@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Hi all, On 3/23/22 2:04 PM, Sean Anderson wrote: > This series adds support for running valgrind against U-Boot's internal > malloc. This allows for much more useful reports to be generated. > > Some example output of valgrind run against u-boot/master with this branch > applied may be found at [1]. Note that valgrind gives up around acpi. This > feature still needs a lot of work on suppressions/hints to filter out the noise > properly. > > [1] https://gist.githubusercontent.com/Forty-Bot/199bf06f9cdd6871e54f8f484c16e111/raw/2a2f99108eef84b48e27a54332f3f71f4e2e5342/gistfile1.txt This is a bit of a follow up to the above. Over the past week I've sent a few patches [1-4] with various bugs found with valgrind. Hopefully this gives a good idea of the kind of problems valgrind is equipped to find. In particular, it is good at determining where we go past the end of buffers or otherwise read uninitialized memory. I've also discovered why I originally stopped working on this series: supressions don't "un-taint" uninitialized memory accesses. Currently, I have dlmalloc's reads its bookkeeping information marked as a "red zone." This means that all reads to it are marked as illegal by valgrind. This is fine for regular code, but dlmalloc really does need to access this area, so we suppress its violations. However, if dlmalloc then passes a result calculated from a "tainted" access, that result is still tainted. So the first accessor will raise a warning. This means that every construct like foo = malloc(sizeof(*foo)); if (!foo) return -ENOMEM; will raise a warning when we check the result of malloc. Whoops. There are three ways (as I see it) to address this: - Don't mark dlmalloc bookkeeping information as a red zone. This is the simplest solution, but reduces the power of valgrind immensely, since we can no longer determine that (e.g.) access past the end of an array is undefined. - Implement red zones properly. This would involve growing every allocation by a fixed amount (16 bytes or so) and then using that extra space for a real red zone that neither regular code nor dlmalloc needs to access. Unfortunately, this would probably some fairly intensive surgery to dlmalloc to add/remove the offset appropriately. - Mark bookkeeping information as valid before we use it in dlmalloc, and then mark it invalid before returning. This would be the most correct, but it would be very tricky to implement since there are so many code paths to mark. I think it would be the most effort out of the three options here. Until one of the above options are implemented, it will remain difficult to sift through the massive amount of spurious warnings. That said, if anyone wants to play around with this a bit, I have some additional invocation suggestions which I have been using, but which are not documented - "--error-limit=no" will enable printing more than 1000 errors in a single session. - "--vgdb=yes --vgdb-error=0" will let you use gdb to attach like gdb -ex "target remote | vgdb" u-boot This is very helpful for inspecting the program state when there is an error. - "t cooked" to U-Boot will keep the console in a sane state if you terminate it early (instead of having to run tset). The above should probably be documented in patch 3. I will add it if I do a v4 (or I will send a follow-up). --Sean [1] https://patchwork.ozlabs.org/project/uboot/list/?series=291719 [2] https://patchwork.ozlabs.org/project/uboot/list/?series=291739 [3] https://patchwork.ozlabs.org/project/uboot/list/?series=292710 [4] https://patchwork.ozlabs.org/project/uboot/list/?series=292712