qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Henrique Barboza <danielhb413@gmail.com>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: qemu-ppc@nongnu.org, clg@kaod.org,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	qemu-devel@nongnu.org
Subject: Re: [PATCH v2 2/4] target/ppc: init 'lpcr' in kvmppc_enable_cap_large_decr()
Date: Tue, 5 Apr 2022 16:37:11 -0300	[thread overview]
Message-ID: <73b8f910-ada4-b084-1808-588b8747da18@gmail.com> (raw)
In-Reply-To: <YkZ0OGtA8mVk1Q0p@yekko>



On 4/1/22 00:40, David Gibson wrote:
> On Thu, Mar 31, 2022 at 03:46:57PM -0300, Daniel Henrique Barboza wrote:
>>
>>
>> On 3/31/22 14:36, Richard Henderson wrote:
>>> On 3/31/22 11:17, Daniel Henrique Barboza wrote:
>>>>> Hmm... this is seeming a bit like whack-a-mole.  Could we instead use
>>>>> one of the valgrind hinting mechanisms to inform it that
>>>>> kvm_get_one_reg() writes the variable at *target?
>>>>
>>>> I didn't find a way of doing that looking in the memcheck helpers
>>>> (https://valgrind.org/docs/manual/mc-manual.html section 4.7). That would be a
>>>> good way of solving this warning because we would put stuff inside a specific
>>>> function X and all callers of X would be covered by it.
>>>>
>>>> What I did find instead is a memcheck macro called VALGRIND_MAKE_MEM_DEFINED that
>>>> tells Valgrind that the var was initialized.
>>>>
>>>> This patch would then be something as follows:
>>>>
>>>>
>>>> diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
>>>> index dc93b99189..b0e22fa283 100644
>>>> --- a/target/ppc/kvm.c
>>>> +++ b/target/ppc/kvm.c
>>>> @@ -56,6 +56,10 @@
>>>>    #define DEBUG_RETURN_GUEST 0
>>>>    #define DEBUG_RETURN_GDB   1
>>>>
>>>> +#ifdef CONFIG_VALGRIND_H
>>>> +#include <valgrind/memcheck.h>
>>>> +#endif
>>>> +
>>>>    const KVMCapabilityInfo kvm_arch_required_capabilities[] = {
>>>>        KVM_CAP_LAST_INFO
>>>>    };
>>>> @@ -2539,6 +2543,10 @@ int kvmppc_enable_cap_large_decr(PowerPCCPU *cpu, int enable)
>>>>        CPUState *cs = CPU(cpu);
>>>>        uint64_t lpcr;
>>>>
>>>> +#ifdef CONFIG_VALGRIND_H
>>>> +    VALGRIND_MAKE_MEM_DEFINED(lpcr, sizeof(uint64_t));
>>>> +#endif
>>>> +
>>>>        kvm_get_one_reg(cs, KVM_REG_PPC_LPCR_64, &lpcr);
>>>>        /* Do we need to modify the LPCR? */
>>>>
>>>>
>>>> CONFIG_VALGRIND_H needs 'valgrind-devel´ installed.
>>>>
>>>> I agree that this "Valgrind is complaining about variable initialization" is a whack-a-mole
>>>> situation that will keep happening in the future if we keep adding this same code pattern
>>>> (passing as reference an uninitialized var). For now, given that we have only 4 instances
>>>> to fix it in ppc code (as far as I'm aware of), and we don't have a better way of telling
>>>> Valgrind that we know what we're doing, I think we're better of initializing these vars.
>>>
>>> I would instead put this annotation inside kvm_get_one_reg, so that it covers all kvm hosts.  But it's too late to do this for 7.0.
>>
>> I wasn't planning on pushing these changes for 7.0 since they aren't fixing mem
>> leaks or anything really bad. It's more of a quality of life improvement when
>> using Valgrind.
>>
>> I also tried to put this annotation in kvm_get_one_reg() and it didn't solve the
>> warning.
> 
> That's weird, I'm pretty sure that should work.  I'd double check to
> make sure you had all the parameters right (e.g. could you have marked
> the pointer itself as initialized, rather than the memory it points
> to).


You're right. I got confused with different setups here and there and thought that
it didn't work.

I sent a patch to kvm-all.c that tries to do that:


https://lists.gnu.org/archive/html/qemu-devel/2022-04/msg00507.html


As for this series, for now I'm willing to take it since it improves the situation with
simple initializations. We can reconsider it if we make good progress through the common
code. At any rate these are 7.1 patches, so we have time.



Thanks,


Daniel



> 
>> I didn't find a way of telling Valgrind "consider that every time this
>> function is called with parameter X it initializes X". That would be a good solution
>> to put in the common KVM files and fix the problem for everybody.
>>
>>
>> Daniel
>>
>>
>>
>>>
>>>
>>> r~
>>
> 


  reply	other threads:[~2022-04-05 19:38 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-31  0:17 [PATCH v2 0/4] ppc: valgrind "uninitialized values" fixes Daniel Henrique Barboza
2022-03-31  0:17 ` [PATCH v2 1/4] target/ppc: initialize 'val' union in kvm_get_one_spr() Daniel Henrique Barboza
2022-03-31  1:20   ` David Gibson
2022-03-31  0:17 ` [PATCH v2 2/4] target/ppc: init 'lpcr' in kvmppc_enable_cap_large_decr() Daniel Henrique Barboza
2022-03-31  1:25   ` David Gibson
2022-03-31 17:17     ` Daniel Henrique Barboza
2022-03-31 17:36       ` Richard Henderson
2022-03-31 18:46         ` Daniel Henrique Barboza
2022-04-01  3:40           ` David Gibson
2022-04-05 19:37             ` Daniel Henrique Barboza [this message]
2022-04-01  3:38       ` David Gibson
2022-03-31  0:17 ` [PATCH v2 3/4] target/ppc: init 'sregs' in kvmppc_put_books_sregs() Daniel Henrique Barboza
2022-03-31  0:17 ` [PATCH v2 4/4] target/ppc: init 'rmmu_info' in kvm_get_radix_page_info() Daniel Henrique Barboza

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=73b8f910-ada4-b084-1808-588b8747da18@gmail.com \
    --to=danielhb413@gmail.com \
    --cc=clg@kaod.org \
    --cc=david@gibson.dropbear.id.au \
    --cc=f4bug@amsat.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).