diff mbox

[7/9] valgrind/i386: avoid false positives on KVM_GET_MSRS ioctl

Message ID 1414661809-21383-8-git-send-email-borntraeger@de.ibm.com
State New
Headers show

Commit Message

Christian Borntraeger Oct. 30, 2014, 9:36 a.m. UTC
struct kvm_msrs contains a pad field. Lets initialize this pad
field. A designated initializer seems not appropriate here, as
struct kvm_msrs is embedded in the msr_data structure.

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 target-i386/kvm.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Paolo Bonzini Nov. 5, 2014, 10:33 a.m. UTC | #1
On 30/10/2014 10:36, Christian Borntraeger wrote:
> struct kvm_msrs contains a pad field. Lets initialize this pad
> field. A designated initializer seems not appropriate here, as
> struct kvm_msrs is embedded in the msr_data structure.
> 
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>

What about this:

    msr_data.info = (struct kvm_msrs) {
        .nmsrs = n
    };

?  It would also be applicable to other uses of kvm_msrs.

Also, you're missing one occurrence in kvm_put_msr_feature_control.

Paolo
Paolo Bonzini Nov. 5, 2014, 10:37 a.m. UTC | #2
On 05/11/2014 11:33, Paolo Bonzini wrote:
> On 30/10/2014 10:36, Christian Borntraeger wrote:
>> struct kvm_msrs contains a pad field. Lets initialize this pad
>> field. A designated initializer seems not appropriate here, as
>> struct kvm_msrs is embedded in the msr_data structure.
>>
>> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> 
> What about this:
> 
>     msr_data.info = (struct kvm_msrs) {
>         .nmsrs = n
>     };
> 
> ?  It would also be applicable to other uses of kvm_msrs.

Also, KVM_SET_MSRS has to deal with a reserved field in struct
kvm_msr_entry.  Currently you handle it with a relatively large memset
produced by the designated initializer "= {}" in kvm_put_msrs.  However,
you could set it in kvm_msr_entry_set, and avoid the memset.

Paolo

> Also, you're missing one occurrence in kvm_put_msr_feature_control.
diff mbox

Patch

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 6203634..90020cb 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -1628,6 +1628,7 @@  static int kvm_get_msrs(X86CPU *cpu)
     }
 
     msr_data.info.nmsrs = n;
+    msr_data.info.pad = 0;
     ret = kvm_vcpu_ioctl(CPU(cpu), KVM_GET_MSRS, &msr_data);
     if (ret < 0) {
         return ret;