valgrind/i386/s390x: memcheck false positives
cover valgrind/i386/s390x: memcheck false positives
This series avoids most memcheck false positives in KVM ioctls on s390x and x86_64.
Please review and consider for 2.2 or later. Some of these things could also be fixed in valgrind, but it will take a while until these changes hit a release or distros.
The series is also available via signed tag:
The following changes since commit 3e9418e160cd8901c83a3c88967158084f5b5c03:
Revert "main-loop.c: Handle SIGINT, SIGHUP and SIGTERM synchronously" (2014-10-27 15:05:09 +0000)
are available in the git repository at:
git://github.com/borntraeger/qemu.git tags/memcheck
for you to fetch changes up to e5bcf96f709e57a54188ffa6a988b6acb603df7a:
valgrind/s390x: avoid false positives on KVM_SET_FPU ioctl (2014-10-30 10:08:49 +0100)
----------------------------------------------------------------
valgrind/i386/s390x: memcheck false positives
Let's avoid most memcheck false positives in KVM ioctls.
----------------------------------------------------------------
Christian Borntraeger (9):
valgrind: avoid false positives in KVM_GET_DIRTY_LOG ioctl valgrind/i386: avoid false positives on KVM_SET_CLOCK ioctl valgrind/i386: avoid false positives on KVM_SET_PIT ioctl valgrind/i386: avoid false positives on KVM_SET_XCRS ioctl valgrind/i386: avoid false positives on KVM_SET_MSRS ioctl valgrind/i386: avoid false positives on KVM_SET_MSRS(TSC) ioctl valgrind/i386: avoid false positives on KVM_GET_MSRS ioctl valgrind/i386: avoid false positives on KVM_SET_VCPU_EVENTS ioctl valgrind/s390x: avoid false positives on KVM_SET_FPU ioctl
hw/i386/kvm/clock.c | 3 +-- hw/i386/kvm/i8254.c | 2 +- kvm-all.c | 2 +- target-i386/kvm.c | 9 +++++---- target-s390x/kvm.c | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-)
PATCH 1/9 valgrind: avoid false positives in KVM_GET_DIRTY_LOG ioctl
struct kvm_dirty_log contains padding fields that trigger false positives in valgrind. Let's use a designated initializer to avoid false positives from valgrind/memcheck.
--- kvm-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kvm-all.c +1 -1
@@ -400,7 +400,7 @@ static int kvm_physical_sync_dirty_bitmap(MemoryRegionSection *section) {KVMState *s = kvm_state;unsigned long size, allocated_size =0 ; -KVMDirtyLog d; +KVMDirtyLog d = {};KVMSlot *mem;int ret =0 ;hwaddr start_addr = section->offset_within_address_space;
Signature · 1 line
1.9.3
PATCH 2/9 valgrind/i386: avoid false positives on KVM_SET_CLOCK ioctl
In reply to Christian Borntraegerkvm_clock_data contains pad fields. Let's use a designated initializer to avoid false positives from valgrind/memcheck.
--- hw/i386/kvm/clock.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
hw/i386/kvm/clock.c +1 -2
@@ -88,7 +88,7 @@ static void kvmclock_vm_state_change(void *opaque, int running,int ret;if (running) { -struct kvm_clock_data data; +struct kvm_clock_data data = {};uint64_t time_at_migration =kvmclock_current_nsec (s); s->clock_valid = false;
@@ -99,7 +99,6 @@ static void kvmclock_vm_state_change(void *opaque, int running, } data.clock = s->clock; - data.flags =0 ; ret =kvm_vm_ioctl (kvm_state,KVM_SET_CLOCK , &data);if (ret <0 ) {fprintf (stderr,"KVM_SET_CLOCK failed: %s\n" ,strerror (ret));
Signature · 1 line
1.9.3
PATCH 3/9 valgrind/i386: avoid false positives on KVM_SET_PIT ioctl
In reply to Christian Borntraegerstruct kvm_pit_state2 contains pad fields. Let's use a designated initializer to avoid false positives from valgrind/memcheck.
--- hw/i386/kvm/i8254.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/kvm/i8254.c +1 -1
@@ -138,7 +138,7 @@ static void kvm_pit_get(PITCommonState *pit)static void kvm_pit_put (PITCommonState *pit) {KVMPITState *s =KVM_PIT (pit); -struct kvm_pit_state2 kpit; +struct kvm_pit_state2 kpit = {};struct kvm_pit_channel_state *kchan;struct PITChannelState *sc;int i, ret;
Signature · 1 line
1.9.3
PATCH 4/9 valgrind/i386: avoid false positives on KVM_SET_XCRS ioctl
In reply to Christian Borntraegerstruct kvm_xcrs contains padding bytes. Let's use a designated initializer to avoid false positives from valgrind/memcheck.
--- target-i386/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target-i386/kvm.c +1 -1
@@ -1074,7 +1074,7 @@ static int kvm_put_xsave(X86CPU *cpu)static int kvm_put_xcrs (X86CPU *cpu) {CPUX86State *env = &cpu->env; -struct kvm_xcrs xcrs; +struct kvm_xcrs xcrs = {};if (!kvm_has_xcrs ()) {return 0 ;
Signature · 1 line
1.9.3
PATCH 5/9 valgrind/i386: avoid false positives on KVM_SET_MSRS ioctl
In reply to Christian Borntraegerstruct kvm_msrs contains padding bytes. Let's use a designated initializer to avoid false positives from valgrind/memcheck.
--- target-i386/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target-i386/kvm.c +1 -1
@@ -1189,7 +1189,7 @@ static int kvm_put_msrs(X86CPU *cpu, int level)struct {struct kvm_msrs info;struct kvm_msr_entry entries[150 ]; - } msr_data; + } msr_data = {};struct kvm_msr_entry *msrs = msr_data.entries;int n =0 , i;
Signature · 1 line
1.9.3
PATCH 6/9 valgrind/i386: avoid false positives on KVM_SET_MSRS(TSC) ioctl
In reply to Christian Borntraegerstruct kvm_msrs contains pad fields. Let's use a designated initializer to avoid false positives from valgrind/memcheck.
--- target-i386/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target-i386/kvm.c +1 -1
@@ -1150,7 +1150,7 @@ static int kvm_put_tscdeadline_msr(X86CPU *cpu)struct {struct kvm_msrs info;struct kvm_msr_entry entries[1 ]; - } msr_data; + } msr_data = {};struct kvm_msr_entry *msrs = msr_data.entries;if (!has_msr_tsc_deadline) {
Signature · 1 line
1.9.3
PATCH 7/9 valgrind/i386: avoid false positives on KVM_GET_MSRS ioctl
In reply to Christian Borntraegerstruct 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.
--- target-i386/kvm.c | 1 + 1 file changed, 1 insertion(+)
target-i386/kvm.c +1 -0
@@ -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;
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH 7/9] valgrind/i386: avoid false positives on KVM_GET_MSRS ioctl
Quoted 5 lines · Christian Borntraeger
struct
kvm_msrscontains a pad field. Lets initialize this pad field. A designated initializer seems not appropriate here, as structkvm_msrsis embedded in themsr_datastructure.Signed-off-by Christian Borntraeger <[email protected]>
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
Re: [Qemu-devel] [PATCH 7/9] valgrind/i386: avoid false positives on KVM_GET_MSRS ioctl
Quoted 7 lines · Paolo Bonzini
Quoted 5 lines · Christian Borntraeger
struct
kvm_msrscontains a pad field. Lets initialize this pad field. A designated initializer seems not appropriate here, as structkvm_msrsis embedded in themsr_datastructure.Signed-off-by Christian Borntraeger <[email protected]>
Quoted 7 lines
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
Quoted 1 line
Also, you're missing one occurrence in
kvm_put_msr_feature_control.
PATCH 8/9 valgrind/i386: avoid false positives on KVM_SET_VCPU_EVENTS ioctl
In reply to Christian Borntraegerstruct kvm_vcpu_events contains reserved fields. Let's use a designated initializer to avoid false positives in valgrind.
--- target-i386/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target-i386/kvm.c +1 -1
@@ -1854,7 +1854,7 @@ static int kvm_put_apic(X86CPU *cpu)static int kvm_put_vcpu_events (X86CPU *cpu,int level) {CPUX86State *env = &cpu->env; -struct kvm_vcpu_events events; +struct kvm_vcpu_events events= {};if (!kvm_has_vcpu_events ()) {return 0 ;
Signature · 1 line
1.9.3
PATCH 9/9 valgrind/s390x: avoid false positives on KVM_SET_FPU ioctl
In reply to Christian Borntraegerstruct kvm_fpu contains an alignment padding on s390x. Let's use a designated initializer to avoid false positives from valgrind/memcheck.
--- target-s390x/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target-s390x/kvm.c +1 -1
@@ -208,7 +208,7 @@ int kvm_arch_put_registers(CPUState *cs, int level)CPUS390XState *env = &cpu->env;struct kvm_sregs sregs;struct kvm_regs regs; -struct kvm_fpu fpu; +struct kvm_fpu fpu = {};int r;int i;
Signature · 1 line
1.9.3
Quoted 6 lines · Christian Borntraeger
This series avoids most memcheck false positives in KVM ioctls on s390x and
x86_64.Please review and consider for 2.2 or later. Some of these things could also be fixed in valgrind, but it will take a while until these changes hit a release or distros.
Are you planning to submit the valgrind fixes as well? These definitely seem like valgrind bugs that we're having to work around here (though the workarounds are pretty simple so they're not a huge deal).
thanks
-- PMM
Am 30.10.2014 10:46, schrieb Peter Maydell:
Quoted 11 lines · Christian Borntraeger
Quoted 6 lines
This series avoids most memcheck false positives in KVM ioctls on s390x and
x86_64.Please review and consider for 2.2 or later. Some of these things could also be fixed in valgrind, but it will take a while until these changes hit a release or distros.
Are you planning to submit the valgrind fixes as well? These definitely seem like valgrind bugs that we're having to work around here (though the workarounds are pretty simple so they're not a huge deal).
Yes, I will try to get some of this fixed in valgrind as well. This will take a little longer though because the code changes are bigger than just 1 line of code. Given that valgrind has around 1 release/year, this patch set is certainly a nice band-aid that is useful for todays development.
Christian
Quoted 4 lines · Christian Borntraeger
Yes, I will try to get some of this fixed in valgrind as well. This will take a little longer though because the code changes are bigger than just 1 line of code. Given that valgrind has around 1 release/year, this patch set is certainly a nice band-aid that is useful for todays development.
I guess these patches also mean we're not going to get valgrind warnings if we forget to initialize a necessary field in the struct, but I suppose we can live with that.
-- PMM
Am 30.10.2014 10:58, schrieb Peter Maydell:
Quoted 8 lines · Christian Borntraeger
Quoted 4 lines
Yes, I will try to get some of this fixed in valgrind as well. This will take a little longer though because the code changes are bigger than just 1 line of code. Given that valgrind has around 1 release/year, this patch set is certainly a nice band-aid that is useful for todays development.
I guess these patches also mean we're not going to get valgrind warnings if we forget to initialize a necessary field in the struct.
Yes, thats correct. The alternative would be to not use an designated initializer and instead memset reserved and pad field.
Quoted 4 lines
but I suppose we can live with that.
-- PMM
Quoted 3 lines · Christian Borntraeger
Some of these things could
also be fixed in valgrind, but it will take a while until these changes hit a release or distros.
Ok, it's sensible to have it fixed in QEMU if it's temporary. Which could not be fixed in valgrind?
Paolo
Am 30.10.2014 14:03, schrieb Paolo Bonzini:
Quoted 7 lines · Christian Borntraeger
Quoted 3 lines
Some of these things could
also be fixed in valgrind, but it will take a while until these changes hit a release or distros.Ok, it's sensible to have it fixed in QEMU if it's temporary. Which could not be fixed in valgrind?
This is a tricky question. A typical annotation in valgrind for an more complex ioctl looks like
case VKI_SIOCGMIIREG: /* get hardware entry registers */
PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMIIREG)",
(Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name );
PRE_MEM_READ( "ioctl(SIOCGIFMIIREG)",
(Addr)&((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->phy_id,
sizeof(((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->phy_id) );
PRE_MEM_READ( "ioctl(SIOCGIFMIIREG)",
(Addr)&((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->reg_num,
sizeof(((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->reg_num) );
PRE_MEM_WRITE( "ioctl(SIOCGIFMIIREG)", ARG3,
sizeof(struct vki_ifreq));
break;This scheme works fine as long as the ioctl is unchanged. So any ioctl that has padding and no flags this should be doable.
For all KVM ioctls with reserved fields that might become used on certain flags, we have two options:
a: we would instruct valgrind to not check the reserved fields Whenever we start using them, we would still not check those field
b: we would instruct valgrind to not check the reserved fields if flags has a certain value (e.g. 0), otherwise all reserved fields would be checked. Whenever we start using the reserved fields, valgrind would complain unless we write all. So in that case we have to modify valgrind again
In essence a will cause false negatives, b will cause false positives
I think b is preferred
Christian
Quoted 32 lines · Christian Borntraeger
Am 30.10.2014 14:03, schrieb Paolo Bonzini:
Quoted 7 lines · Christian Borntraeger
Quoted 3 lines
Some of these things could
also be fixed in valgrind, but it will take a while until these changes hit a release or distros.Ok, it's sensible to have it fixed in QEMU if it's temporary. Which could not be fixed in valgrind?
This is a tricky question. A typical annotation in valgrind for an more complex ioctl looks like
case VKI_SIOCGMIIREG: /* get hardware entry registers */ PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMIIREG)", (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); PRE_MEM_READ( "ioctl(SIOCGIFMIIREG)", (Addr)&((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->phy_id, sizeof(((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->phy_id) ); PRE_MEM_READ( "ioctl(SIOCGIFMIIREG)", (Addr)&((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->reg_num, sizeof(((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->reg_num) ); PRE_MEM_WRITE( "ioctl(SIOCGIFMIIREG)", ARG3, sizeof(struct vki_ifreq)); break;This scheme works fine as long as the ioctl is unchanged. So any ioctl that has padding and no flags this should be doable.
For all KVM ioctls with reserved fields that might become used on certain flags, we have two options:
a: we would instruct valgrind to not check the reserved fields Whenever we start using them, we would still not check those field
Quoted 6 lines
b: we would instruct valgrind to not check the reserved fields if flags has a certain value (e.g. 0), otherwise all reserved fields would be checked. Whenever we start using the reserved fields, valgrind would complain unless we write all. So in that case we have to modify valgrind again
In essence a will cause false negatives, b will cause false positives
I think b is preferred
I agree.
Paolo
Quoted 38 lines · Christian Borntraeger
This series avoids most memcheck false positives in KVM ioctls on s390x and
x86_64.Please review and consider for 2.2 or later. Some of these things could also be fixed in valgrind, but it will take a while until these changes hit a release or distros.
The series is also available via signed tag:
The following changes since commit
3e9418e160cd8901c83a3c88967158084f5b5c03:Revert "
main-loop.c: Handle SIGINT, SIGHUP and SIGTERM synchronously" (2014-10-27 15:05:09 +0000)are available in the git repository at:
git://github.com/borntraeger/qemu.gittags/memcheckfor you to fetch changes up to
e5bcf96f709e57a54188ffa6a988b6acb603df7a:valgrind/s390x: avoid false positives on
KVM_SET_FPUioctl (2014-10-30 10:08:49 +0100)----------------------------------------------------------------
valgrind/i386/s390x: memcheck false positivesLet's avoid most memcheck false positives in KVM ioctls.
----------------------------------------------------------------
Christian Borntraeger (9):
valgrind: avoid false positives inKVM_GET_DIRTY_LOGioctl valgrind/i386: avoid false positives onKVM_SET_CLOCKioctl valgrind/i386: avoid false positives onKVM_SET_PITioctl valgrind/i386: avoid false positives onKVM_SET_XCRSioctl valgrind/i386: avoid false positives onKVM_SET_MSRSioctl valgrind/i386: avoid false positives onKVM_SET_MSRS(TSC)ioctl valgrind/i386: avoid false positives onKVM_GET_MSRSioctl valgrind/i386: avoid false positives onKVM_SET_VCPU_EVENTSioctl valgrind/s390x: avoid false positives onKVM_SET_FPUioctl
Quoted 9 lines
hw/i386/kvm/clock.c | 3 +-- hw/i386/kvm/i8254.c | 2 +- kvm-all.c | 2 +- target-i386/kvm.c | 9 +++++---- target-s390x/kvm.c | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-)
Christian, when you respin can you add another one in kvm_irqchip_add_adapter_route? Coverity reports kroute.pad as uninitialized.
Paolo
Am 13.11.2014 um 15:34 schrieb Paolo Bonzini:
Quoted 49 lines · Christian Borntraeger
Quoted 38 lines
This series avoids most memcheck false positives in KVM ioctls on s390x and
x86_64.Please review and consider for 2.2 or later. Some of these things could also be fixed in valgrind, but it will take a while until these changes hit a release or distros.
The series is also available via signed tag:
The following changes since commit
3e9418e160cd8901c83a3c88967158084f5b5c03:Revert "
main-loop.c: Handle SIGINT, SIGHUP and SIGTERM synchronously" (2014-10-27 15:05:09 +0000)are available in the git repository at:
git://github.com/borntraeger/qemu.gittags/memcheckfor you to fetch changes up to
e5bcf96f709e57a54188ffa6a988b6acb603df7a:valgrind/s390x: avoid false positives on
KVM_SET_FPUioctl (2014-10-30 10:08:49 +0100)----------------------------------------------------------------
valgrind/i386/s390x: memcheck false positivesLet's avoid most memcheck false positives in KVM ioctls.
----------------------------------------------------------------
Christian Borntraeger (9):
valgrind: avoid false positives inKVM_GET_DIRTY_LOGioctl valgrind/i386: avoid false positives onKVM_SET_CLOCKioctl valgrind/i386: avoid false positives onKVM_SET_PITioctl valgrind/i386: avoid false positives onKVM_SET_XCRSioctl valgrind/i386: avoid false positives onKVM_SET_MSRSioctl valgrind/i386: avoid false positives onKVM_SET_MSRS(TSC)ioctl valgrind/i386: avoid false positives onKVM_GET_MSRSioctl valgrind/i386: avoid false positives onKVM_SET_VCPU_EVENTSioctl valgrind/s390x: avoid false positives onKVM_SET_FPUioctlQuoted 9 lines
hw/i386/kvm/clock.c | 3 +-- hw/i386/kvm/i8254.c | 2 +- kvm-all.c | 2 +- target-i386/kvm.c | 9 +++++---- target-s390x/kvm.c | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-)
Quoted 3 lines
Christian, when you respin can you add another one in
kvm_irqchip_add_adapter_route? Coverity reports kroute.pad as uninitialized.
OK, will do. It will take probably some more days, but it will happen :-)