From: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
Christophe de Dinechin <dinechin@redhat.com>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Cc: "Vladimir Sementsov-Ogievskiy" <vsementsov@virtuozzo.com>,
"berto@igalia.com" <berto@igalia.com>,
"ehabkost@redhat.com" <ehabkost@redhat.com>,
"qemu-block@nongnu.org" <qemu-block@nongnu.org>,
"mtosatti@redhat.com" <mtosatti@redhat.com>,
"mdroth@linux.vnet.ibm.com" <mdroth@linux.vnet.ibm.com>,
"armbru@redhat.com" <armbru@redhat.com>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"rth@twiddle.net" <rth@twiddle.net>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>,
"Denis Lunev" <den@virtuozzo.com>
Subject: Re: [Qemu-devel] [PATCH 3/3] i386/kvm: initialize struct at full before ioctl call
Date: Wed, 31 Jul 2019 14:10:50 +0000 [thread overview]
Message-ID: <cb3960b5-2ebe-ddeb-b4e6-4e085ecb5020@virtuozzo.com> (raw)
In-Reply-To: <038487b3-0b39-0695-7ef7-ede1b3143ad1@redhat.com>
On 31/07/2019 15:32, Paolo Bonzini wrote:
> On 31/07/19 11:05, Christophe de Dinechin wrote:
>>
>> Christian Borntraeger writes:
>>
>>> On 30.07.19 18:44, Philippe Mathieu-Daudé wrote:
>>>> On 7/30/19 6:01 PM, Andrey Shinkevich wrote:
>>>>> Not the whole structure is initialized before passing it to the KVM.
>>>>> Reduce the number of Valgrind reports.
>>>>>
>>>>> Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
>>>>> ---
>>>>> target/i386/kvm.c | 3 +++
>>>>> 1 file changed, 3 insertions(+)
>>>>>
>>>>> diff --git a/target/i386/kvm.c b/target/i386/kvm.c
>>>>> index dbbb137..ed57e31 100644
>>>>> --- a/target/i386/kvm.c
>>>>> +++ b/target/i386/kvm.c
>>>>> @@ -190,6 +190,7 @@ static int kvm_get_tsc(CPUState *cs)
>>>>> return 0;
>>>>> }
>>>>>
>>>>> + memset(&msr_data, 0, sizeof(msr_data));
>>>>
>>>> I wonder the overhead of this one...
>>>
>>> Cant we use designated initializers like in
>>>
>>> commit bdfc8480c50a53d91aa9a513d23a84de0d5fbc86
>>> Author: Christian Borntraeger <borntraeger@de.ibm.com>
>>> AuthorDate: Thu Oct 30 09:23:41 2014 +0100
>>> Commit: Paolo Bonzini <pbonzini@redhat.com>
>>> CommitDate: Mon Dec 15 12:21:01 2014 +0100
>>>
>>> valgrind/i386: avoid false positives on KVM_SET_XCRS ioctl
>>>
>>> and others?
>>>
>>> This should minimize the impact.
>>
>> Oh, when you talked about using designated initializers, I thought you
>> were talking about fully initializing the struct, like so:
>
> Yeah, that would be good too. For now I'm applying Andrey's series though.
>
> Paolo
>
Thank you.
As Philippe wrote, 'dbgregs.flags = 0;' is unnecessary with 'memset(0)'.
Andrey
>> diff --git a/target/i386/kvm.c b/target/i386/kvm.c
>> index dbbb13772a..3533870c43 100644
>> --- a/target/i386/kvm.c
>> +++ b/target/i386/kvm.c
>> @@ -180,19 +180,20 @@ static int kvm_get_tsc(CPUState *cs)
>> {
>> X86CPU *cpu = X86_CPU(cs);
>> CPUX86State *env = &cpu->env;
>> - struct {
>> - struct kvm_msrs info;
>> - struct kvm_msr_entry entries[1];
>> - } msr_data;
>> int ret;
>>
>> if (env->tsc_valid) {
>> return 0;
>> }
>>
>> - msr_data.info.nmsrs = 1;
>> - msr_data.entries[0].index = MSR_IA32_TSC;
>> - env->tsc_valid = !runstate_is_running();
>> + struct {
>> + struct kvm_msrs info;
>> + struct kvm_msr_entry entries[1];
>> + } msr_data = {
>> + .info = { .nmsrs = 1 },
>> + .entries = { [0] = { .index = MSR_IA32_TSC } }
>> + };
>> + env->tsc_valid = !runstate_is_running();
>>
>> ret = kvm_vcpu_ioctl(CPU(cpu), KVM_GET_MSRS, &msr_data);
>> if (ret < 0) {
>>
>>
>> This gives the compiler maximum opportunities to flag mistakes like
>> initializing the same thing twice, and make it easier (read no smart
>> optimizations) to initialize in one go. Moving the declaration past the
>> 'if' also addresses Philippe's concern.
>>
>>>>
>>>>> msr_data.info.nmsrs = 1;
>>>>> msr_data.entries[0].index = MSR_IA32_TSC;
>>>>> env->tsc_valid = !runstate_is_running();
>>>>> @@ -1706,6 +1707,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
>>>>>
>>>>> if (has_xsave) {
>>>>> env->xsave_buf = qemu_memalign(4096, sizeof(struct kvm_xsave));
>>>>> + memset(env->xsave_buf, 0, sizeof(struct kvm_xsave));
>>>>
>>>> OK
>>>>
>>>>> }
>>>>>
>>>>> max_nested_state_len = kvm_max_nested_state_length();
>>>>> @@ -3477,6 +3479,7 @@ static int kvm_put_debugregs(X86CPU *cpu)
>>>>> return 0;
>>>>> }
>>>>>
>>>>> + memset(&dbgregs, 0, sizeof(dbgregs));
>>>>
>>>> OK
>>>>
>>>>> for (i = 0; i < 4; i++) {
>>>>> dbgregs.db[i] = env->dr[i];
>>>>> }
>>>>
>>>> We could remove 'dbgregs.flags = 0;'
>>>>
>>>> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>>>>
>>
>>
>> --
>> Cheers,
>> Christophe de Dinechin (IRC c3d)
>>
>
--
With the best regards,
Andrey Shinkevich
next prev parent reply other threads:[~2019-07-31 14:11 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-30 16:01 [Qemu-devel] [PATCH 0/3] Reduce the number of Valgrind reports in unit tests Andrey Shinkevich
2019-07-30 16:01 ` [Qemu-devel] [PATCH 1/3] test-throttle: Fix uninitialized use of burst_length Andrey Shinkevich
2019-08-13 12:19 ` Alberto Garcia
2019-07-30 16:01 ` [Qemu-devel] [PATCH 2/3] tests: Fix uninitialized byte in test_visitor_in_fuzz Andrey Shinkevich
2019-07-30 16:01 ` [Qemu-devel] [PATCH 3/3] i386/kvm: initialize struct at full before ioctl call Andrey Shinkevich
2019-07-30 16:44 ` Philippe Mathieu-Daudé
2019-07-30 17:05 ` Christian Borntraeger
2019-07-30 17:14 ` Philippe Mathieu-Daudé
2019-07-30 17:47 ` Christian Borntraeger
2019-07-31 9:05 ` Christophe de Dinechin
2019-07-31 12:32 ` Paolo Bonzini
2019-07-31 14:10 ` Andrey Shinkevich [this message]
2019-07-30 19:22 ` Paolo Bonzini
2019-07-30 16:46 ` Peter Maydell
2019-07-30 17:09 ` Christian Borntraeger
2019-07-30 19:20 ` Paolo Bonzini
2019-07-31 7:24 ` Christian Borntraeger
2019-07-31 12:04 ` Andrey Shinkevich
2019-07-31 12:28 ` Christian Borntraeger
2019-07-31 12:43 ` Christian Borntraeger
2019-07-31 13:03 ` Paolo Bonzini
2019-07-31 14:11 ` Andrey Shinkevich
2019-08-13 12:02 ` [Qemu-devel] [PATCH 0/3] Reduce the number of Valgrind reports in unit tests Andrey Shinkevich
2019-08-13 12:05 ` Paolo Bonzini
2019-08-13 12:08 ` Andrey Shinkevich
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=cb3960b5-2ebe-ddeb-b4e6-4e085ecb5020@virtuozzo.com \
--to=andrey.shinkevich@virtuozzo.com \
--cc=armbru@redhat.com \
--cc=berto@igalia.com \
--cc=den@virtuozzo.com \
--cc=dinechin@redhat.com \
--cc=ehabkost@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mdroth@linux.vnet.ibm.com \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
--cc=vsementsov@virtuozzo.com \
/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).