valgrind fallout for s390x/kvm
cover valgrind fallout for s390x/kvm
I need these patches below to run valgrind on s390x/kvm without a lot of false positives.
Christian Borntraeger (2):
s390x/migration: use zero flag parameter
s390x/kvm: use valgrind annotations for kvm device attributes
hw/s390x/s390-skeys-kvm.c | 12 ++++++++- hw/s390x/s390-stattrib-kvm.c | 7 ++++++ target/s390x/kvm.c | 59 ++++++++++++++++++++++++++++++++++++++------ 3 files changed, 69 insertions(+), 9 deletions(-)
Signature · 1 line
2.9.4
PATCH 1/2 s390x/migration: use zero flag parameter
valgrind pointed out that we call KVM_S390_GET_IRQ_STATE with an undefined value for flags. Right now this is unused, but we better play safe.
--- target/s390x/kvm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
target/s390x/kvm.c +4 -4
@@ -2069,7 +2069,10 @@ int kvm_s390_set_cpu_state(S390CPU *cpu, uint8_t cpu_state)void kvm_s390_vcpu_interrupt_pre_save (S390CPU *cpu) { -struct kvm_s390_irq_state irq_state; +struct kvm_s390_irq_state irq_state = { + .buf = (uint64_t ) cpu->irqstate, + .len =VCPU_IRQ_BUF_SIZE , + };CPUState *cs =CPU (cpu);int32_t bytes;
@@ -2077,9 +2080,6 @@ void kvm_s390_vcpu_interrupt_pre_save(S390CPU *cpu)return ; } - irq_state.buf = (uint64_t ) cpu->irqstate; - irq_state.len =VCPU_IRQ_BUF_SIZE ; - bytes =kvm_vcpu_ioctl (cs,KVM_S390_GET_IRQ_STATE , &irq_state);if (bytes <0 ) { cpu->irqstate_saved_size =0 ;
Signature · 1 line
2.9.4
Re: [Qemu-devel] [PATCH 1/2] s390x/migration: use zero flag parameter
Quoted 26 lines · On Mon, 20 Nov 2017 13:35:24 +0100 Christian Borntraeger…
valgrind pointed out that we call
KVM_S390_GET_IRQ_STATEwith an undefined value for flags. Right now this is unused, but we better play safe.Signed-off-by Christian Borntraeger <[email protected]>--- target/s390x/kvm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)target/s390x/kvm.c +4
-1@@ -2069,7 +2069,10 @@ int kvm_s390_set_cpu_state(S390CPU *cpu, uint8_t cpu_state)void kvm_s390_vcpu_interrupt_pre_save (S390CPU *cpu) { -struct kvm_s390_irq_state irq_state; +struct kvm_s390_irq_state irq_state = { + .buf = (uint64_t ) cpu->irqstate, + .len =VCPU_IRQ_BUF_SIZE , + };CPUState *cs =CPU (cpu);int32_t bytes;
target/s390x/kvm.c void kvm_s390_vcpu_interrupt_pre_save(S390CPU *cpu) · line 2085
Quoted 9 lines
target/s390x/kvm.c +0
-3@@ -2077,9 +2080,6 @@ void kvm_s390_vcpu_interrupt_pre_save(S390CPU *cpu)return ; } - irq_state.buf = (uint64_t ) cpu->irqstate; - irq_state.len =VCPU_IRQ_BUF_SIZE ; - bytes =kvm_vcpu_ioctl (cs,KVM_S390_GET_IRQ_STATE , &irq_state);if (bytes <0 ) { cpu->irqstate_saved_size =0 ;
I'm wondering why it does not also complain for KVM_S390_SET_IRQ_STATE? It would make sense to use a struct initializer there as well.
Re: [Qemu-devel] [PATCH 1/2] s390x/migration: use zero flag parameter
Quoted 32 lines · Cornelia Huck
Quoted 29 lines · On Mon, 20 Nov 2017 13:35:24 +0100 Christian Borntraeger…
valgrind pointed out that we call
KVM_S390_GET_IRQ_STATEwith an undefined value for flags. Right now this is unused, but we better play safe.Signed-off-by Christian Borntraeger <[email protected]>--- target/s390x/kvm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)target/s390x/kvm.c +4
-1@@ -2069,7 +2069,10 @@ int kvm_s390_set_cpu_state(S390CPU *cpu, uint8_t cpu_state)void kvm_s390_vcpu_interrupt_pre_save (S390CPU *cpu) { -struct kvm_s390_irq_state irq_state; +struct kvm_s390_irq_state irq_state = { + .buf = (uint64_t ) cpu->irqstate, + .len =VCPU_IRQ_BUF_SIZE , + };CPUState *cs =CPU (cpu);int32_t bytes;@@ -2077,9 +2080,6 @@ void kvm_s390_vcpu_interrupt_pre_save(S390CPU *cpu)return ; }
Quoted 8 lines
target/s390x/kvm.c void kvm_s390_vcpu_interrupt_pre_save(S390CPU *cpu) · line 2085
Quoted 6 lines
target/s390x/kvm.c +0
-3- irq_state.buf = (uint64_t ) cpu->irqstate; - irq_state.len =VCPU_IRQ_BUF_SIZE ; - bytes =kvm_vcpu_ioctl (cs,KVM_S390_GET_IRQ_STATE , &irq_state);if (bytes <0 ) { cpu->irqstate_saved_size =0 ;I'm wondering why it does not also complain for
KVM_S390_SET_IRQ_STATE?
I guess that my tests do not having peding interrupts during migration and we exit early in
int kvm_s390_vcpu_interrupt_post_load(S390CPU *cpu)
{
CPUState *cs = CPU(cpu);
struct kvm_s390_irq_state irq_state;
int r;--> if (cpu->irqstate_saved_size == 0) {
--> return 0;
}Quoted 1 line
It would make sense to use a struct initializer there as well.
Yes, I think you are right.
Quoted 1 line
Re: [Qemu-devel] [PATCH 1/2] s390x/migration: use zero flag parameter
In reply to Christian BorntraegerQuoted 27 lines · Christian Borntraeger
valgrind pointed out that we call
KVM_S390_GET_IRQ_STATEwith an undefined value for flags. Right now this is unused, but we better play safe.Signed-off-by Christian Borntraeger <[email protected]>--- target/s390x/kvm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)target/s390x/kvm.c +4
-1@@ -2069,7 +2069,10 @@ int kvm_s390_set_cpu_state(S390CPU *cpu, uint8_t cpu_state)void kvm_s390_vcpu_interrupt_pre_save (S390CPU *cpu) { -struct kvm_s390_irq_state irq_state; +struct kvm_s390_irq_state irq_state = { + .buf = (uint64_t ) cpu->irqstate, + .len =VCPU_IRQ_BUF_SIZE , + };CPUState *cs =CPU (cpu);int32_t bytes;
target/s390x/kvm.c void kvm_s390_vcpu_interrupt_pre_save(S390CPU *cpu) · line 2085
Quoted 9 lines
target/s390x/kvm.c +0
-3@@ -2077,9 +2080,6 @@ void kvm_s390_vcpu_interrupt_pre_save(S390CPU *cpu)return ; } - irq_state.buf = (uint64_t ) cpu->irqstate; - irq_state.len =VCPU_IRQ_BUF_SIZE ; - bytes =kvm_vcpu_ioctl (cs,KVM_S390_GET_IRQ_STATE , &irq_state);if (bytes <0 ) { cpu->irqstate_saved_size =0 ;
BTW, should we have a check in the kernel that flags is properly set to zero?
Thomas
Re: [Qemu-devel] [PATCH 1/2] s390x/migration: use zero flag parameter
Quoted 40 lines · Thomas Huth
Quoted 27 lines · Christian Borntraeger
valgrind pointed out that we call
KVM_S390_GET_IRQ_STATEwith an undefined value for flags. Right now this is unused, but we better play safe.Signed-off-by Christian Borntraeger <[email protected]>--- target/s390x/kvm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)target/s390x/kvm.c +4
-1@@ -2069,7 +2069,10 @@ int kvm_s390_set_cpu_state(S390CPU *cpu, uint8_t cpu_state)void kvm_s390_vcpu_interrupt_pre_save (S390CPU *cpu) { -struct kvm_s390_irq_state irq_state; +struct kvm_s390_irq_state irq_state = { + .buf = (uint64_t ) cpu->irqstate, + .len =VCPU_IRQ_BUF_SIZE , + };CPUState *cs =CPU (cpu);int32_t bytes;target/s390x/kvm.c void kvm_s390_vcpu_interrupt_pre_save(S390CPU *cpu) · line 2085
Quoted 9 lines
target/s390x/kvm.c +0
-3@@ -2077,9 +2080,6 @@ void kvm_s390_vcpu_interrupt_pre_save(S390CPU *cpu)return ; } - irq_state.buf = (uint64_t ) cpu->irqstate; - irq_state.len =VCPU_IRQ_BUF_SIZE ; - bytes =kvm_vcpu_ioctl (cs,KVM_S390_GET_IRQ_STATE , &irq_state);if (bytes <0 ) { cpu->irqstate_saved_size =0 ;Reviewed-by Thomas Huth <[email protected]>
Quoted 2 lines
BTW, should we have a check in the kernel that flags is properly set to zero?
We should have one. Doing that now will break old QEMUs :-/
PATCH 2/2 s390x/kvm: use valgrind annotations for kvm device attributes
In reply to Christian Borntraegerthe KVM_GET/SET_DEVICE_ATTR calls have non-self-describing side effects. Use valgrind annotations to properly mark all storage changes instead of using memset or designated initializers.
--- hw/s390x/s390-skeys-kvm.c | 12 ++++++++++- hw/s390x/s390-stattrib-kvm.c | 7 ++++++ target/s390x/kvm.c | 51 ++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 65 insertions(+), 5 deletions(-)
hw/s390x/s390-skeys-kvm.c +11 -1
@@ -13,6 +13,9 @@#include "hw/s390x/storage-keys.h" #include "sysemu/kvm.h" #include "qemu/error-report.h" +#ifdef CONFIG_VALGRIND_H +#include <valgrind/memcheck.h> +#endif static int kvm_s390_skeys_enabled (S390SKeysState *ss) {
@@ -35,8 +38,15 @@ static int kvm_s390_skeys_get(S390SKeysState *ss, uint64_t start_gfn, .count = count, .skeydata_addr = (__u64)keys }; +int ret; -return kvm_vm_ioctl (kvm_state,KVM_S390_GET_SKEYS , &args); + ret =kvm_vm_ioctl (kvm_state,KVM_S390_GET_SKEYS , &args); +if (!ret) { +#ifdef CONFIG_VALGRIND_H +VALGRIND_MAKE_MEM_DEFINED (keys, count); +#endif + } +return ret; } static int kvm_s390_skeys_set(S390SKeysState *ss, uint64_t start_gfn,
hw/s390x/s390-stattrib-kvm.c +7 -0
@@ -18,6 +18,9 @@#include "exec/ram_addr.h" #include "cpu.h" #include "kvm_s390x.h" +#ifdef CONFIG_VALGRIND_H +#include <valgrind/memcheck.h> +#endif Object *kvm_s390_stattrib_create (void ) {
@@ -54,6 +57,10 @@ static int kvm_s390_stattrib_read_helper(S390StAttribState *sa,if (r <0 ) {error_report ("KVM_S390_GET_CMMA_BITS failed: %s" ,strerror (-r));return r; + }else { +#ifdef CONFIG_VALGRIND_H +VALGRIND_MAKE_MEM_DEFINED (values, clog.count); +#endif } *start_gfn = clog.start_gfn;
target/s390x/kvm.c +47 -4
115 lines not on this page · raw message
Signature · 1 line
2.9.4
Re: [Qemu-devel] [PATCH 2/2] s390x/kvm: use valgrind annotations for kvm device attributes
Quoted 28 lines · On Mon, 20 Nov 2017 13:35:25 +0100 Christian Borntraeger…
the KVM_GET/SET_DEVICE_ATTR calls have non-self-describing side effects. Use valgrind annotations to properly mark all storage changes instead of using memset or designated initializers.
Signed-off-by Christian Borntraeger <[email protected]>--- hw/s390x/s390-skeys-kvm.c | 12 ++++++++++- hw/s390x/s390-stattrib-kvm.c | 7 ++++++ target/s390x/kvm.c | 51 ++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 65 insertions(+), 5 deletions(-)hw/s390x/s390-skeys-kvm.c +3
-0@@ -13,6 +13,9 @@#include "hw/s390x/storage-keys.h" #include "sysemu/kvm.h" #include "qemu/error-report.h" +#ifdef CONFIG_VALGRIND_H +#include <valgrind/memcheck.h> +#endif static int kvm_s390_skeys_enabled (S390SKeysState *ss) {@@ -35,8 +38,15 @@ static int kvm_s390_skeys_get(S390SKeysState *ss, uint64_t start_gfn, .count = count,
hw/s390x/s390-skeys-kvm.c static int kvm_s390_skeys_get(S390SKeysState *ss, uint64_t start_gfn, · line 47
Quoted 10 lines
hw/s390x/s390-skeys-kvm.c +6
-1.skeydata_addr = (__u64)keys }; +int ret; -return kvm_vm_ioctl (kvm_state,KVM_S390_GET_SKEYS , &args); + ret =kvm_vm_ioctl (kvm_state,KVM_S390_GET_SKEYS , &args); +if (!ret) { +#ifdef CONFIG_VALGRIND_H +VALGRIND_MAKE_MEM_DEFINED (keys, count); +#endif
This looks ugly :(
Is s390x the only one hitting those side effects? If we need to sprinkle those all over the source code, it improves valgrind results but makes the code harder to read...
(And no, I don't have a better idea.)
Quoted 3 lines
hw/s390x/s390-skeys-kvm.c +2
-0+ } +return ret; }
Re: [Qemu-devel] [PATCH 2/2] s390x/kvm: use valgrind annotations for kvm device attributes
Quoted 44 lines · Cornelia Huck
Quoted 28 lines · On Mon, 20 Nov 2017 13:35:25 +0100 Christian Borntraeger…
the KVM_GET/SET_DEVICE_ATTR calls have non-self-describing side effects. Use valgrind annotations to properly mark all storage changes instead of using memset or designated initializers.
Signed-off-by Christian Borntraeger <[email protected]>--- hw/s390x/s390-skeys-kvm.c | 12 ++++++++++- hw/s390x/s390-stattrib-kvm.c | 7 ++++++ target/s390x/kvm.c | 51 ++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 65 insertions(+), 5 deletions(-)hw/s390x/s390-skeys-kvm.c +3
-0@@ -13,6 +13,9 @@#include "hw/s390x/storage-keys.h" #include "sysemu/kvm.h" #include "qemu/error-report.h" +#ifdef CONFIG_VALGRIND_H +#include <valgrind/memcheck.h> +#endif static int kvm_s390_skeys_enabled (S390SKeysState *ss) {@@ -35,8 +38,15 @@ static int kvm_s390_skeys_get(S390SKeysState *ss, uint64_t start_gfn, .count = count,hw/s390x/s390-skeys-kvm.c static int kvm_s390_skeys_get(S390SKeysState *ss, uint64_t start_gfn, · line 47
Quoted 10 lines
hw/s390x/s390-skeys-kvm.c +6
-1.skeydata_addr = (__u64)keys }; +int ret; -return kvm_vm_ioctl (kvm_state,KVM_S390_GET_SKEYS , &args); + ret =kvm_vm_ioctl (kvm_state,KVM_S390_GET_SKEYS , &args); +if (!ret) { +#ifdef CONFIG_VALGRIND_H +VALGRIND_MAKE_MEM_DEFINED (keys, count); +#endif This looks ugly :(
Quoted 5 lines
Is s390x the only one hitting those side effects? If we need to sprinkle those all over the source code, it improves valgrind results but makes the code harder to read...
(And no, I don't have a better idea.)
We could provide a wrapper?
Quoted 5 lines
Quoted 4 lines
hw/s390x/s390-skeys-kvm.c +2
-0+ } +return ret; }
Re: [Qemu-devel] [PATCH 2/2] s390x/kvm: use valgrind annotations for kvm device attributes
In reply to Cornelia HuckQuoted 44 lines · Cornelia Huck
Quoted 28 lines · On Mon, 20 Nov 2017 13:35:25 +0100 Christian Borntraeger…
the KVM_GET/SET_DEVICE_ATTR calls have non-self-describing side effects. Use valgrind annotations to properly mark all storage changes instead of using memset or designated initializers.
Signed-off-by Christian Borntraeger <[email protected]>--- hw/s390x/s390-skeys-kvm.c | 12 ++++++++++- hw/s390x/s390-stattrib-kvm.c | 7 ++++++ target/s390x/kvm.c | 51 ++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 65 insertions(+), 5 deletions(-)hw/s390x/s390-skeys-kvm.c +3
-0@@ -13,6 +13,9 @@#include "hw/s390x/storage-keys.h" #include "sysemu/kvm.h" #include "qemu/error-report.h" +#ifdef CONFIG_VALGRIND_H +#include <valgrind/memcheck.h> +#endif static int kvm_s390_skeys_enabled (S390SKeysState *ss) {@@ -35,8 +38,15 @@ static int kvm_s390_skeys_get(S390SKeysState *ss, uint64_t start_gfn, .count = count,hw/s390x/s390-skeys-kvm.c static int kvm_s390_skeys_get(S390SKeysState *ss, uint64_t start_gfn, · line 47
Quoted 10 lines
hw/s390x/s390-skeys-kvm.c +6
-1.skeydata_addr = (__u64)keys }; +int ret; -return kvm_vm_ioctl (kvm_state,KVM_S390_GET_SKEYS , &args); + ret =kvm_vm_ioctl (kvm_state,KVM_S390_GET_SKEYS , &args); +if (!ret) { +#ifdef CONFIG_VALGRIND_H +VALGRIND_MAKE_MEM_DEFINED (keys, count); +#endif This looks ugly :(
Quoted 1 line
Is s390x the only one hitting those side effects?
Almost nobody else uses the device attributes. And when they use it they have the same problem
We papered over some bugs by zero-initializing structs but I think marking only the really changed memory will help to detect real bugs (e.g. if code reads ioctl data but the ioctl fails we will not detect this when pre-zeroing.
If we need to
Quoted 9 lines
sprinkle those all over the source code, it improves valgrind results but makes the code harder to read...
(And no, I don't have a better idea.)
Quoted 3 lines
hw/s390x/s390-skeys-kvm.c +2
-0+ } +return ret; }
Re: [Qemu-devel] [PATCH 2/2] s390x/kvm: use valgrind annotations for kvm device attributes
Quoted 45 lines · On Mon, 20 Nov 2017 14:11:03 +0100 Christian Borntraeger…
Quoted 44 lines · Cornelia Huck
Quoted 28 lines · On Mon, 20 Nov 2017 13:35:25 +0100 Christian Borntraeger…
the KVM_GET/SET_DEVICE_ATTR calls have non-self-describing side effects. Use valgrind annotations to properly mark all storage changes instead of using memset or designated initializers.
Signed-off-by Christian Borntraeger <[email protected]>--- hw/s390x/s390-skeys-kvm.c | 12 ++++++++++- hw/s390x/s390-stattrib-kvm.c | 7 ++++++ target/s390x/kvm.c | 51 ++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 65 insertions(+), 5 deletions(-)hw/s390x/s390-skeys-kvm.c +3
-0@@ -13,6 +13,9 @@#include "hw/s390x/storage-keys.h" #include "sysemu/kvm.h" #include "qemu/error-report.h" +#ifdef CONFIG_VALGRIND_H +#include <valgrind/memcheck.h> +#endif static int kvm_s390_skeys_enabled (S390SKeysState *ss) {@@ -35,8 +38,15 @@ static int kvm_s390_skeys_get(S390SKeysState *ss, uint64_t start_gfn, .count = count,hw/s390x/s390-skeys-kvm.c static int kvm_s390_skeys_get(S390SKeysState *ss, uint64_t start_gfn, · line 47
Quoted 10 lines
hw/s390x/s390-skeys-kvm.c +6
-1.skeydata_addr = (__u64)keys }; +int ret; -return kvm_vm_ioctl (kvm_state,KVM_S390_GET_SKEYS , &args); + ret =kvm_vm_ioctl (kvm_state,KVM_S390_GET_SKEYS , &args); +if (!ret) { +#ifdef CONFIG_VALGRIND_H +VALGRIND_MAKE_MEM_DEFINED (keys, count); +#endif This looks ugly :(
Quoted 4 lines
Quoted 1 line
Is s390x the only one hitting those side effects?
Almost nobody else uses the device attributes. And when they use it they have the same problem
Makes sense.
Quoted 3 lines
We papered over some bugs by zero-initializing structs but I think marking only the really changed memory will help to detect real bugs (e.g. if code reads ioctl data but the ioctl fails we will not detect this when pre-zeroing.
Yes, from a "finding bugs" standpoint that's definitely an improvement. Maybe a wrapper would improve the readability.