* [Qemu-devel] [PATCH] kvm: workaround build break on gcc-7.1.1 / fedora26
@ 2017-08-02 14:47 Greg Kurz
2017-08-03 13:34 ` Philippe Mathieu-Daudé
2017-08-03 13:46 ` Philippe Mathieu-Daudé
0 siblings, 2 replies; 13+ messages in thread
From: Greg Kurz @ 2017-08-02 14:47 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini
Building QEMU on fedora26 with the latest gcc package fails:
CC ppc64-softmmu/target/ppc/kvm.o
In file included from include/sysemu/hw_accel.h:16:0,
from target/ppc/kvm.c:31:
target/ppc/kvm.c: In function ‘kvmppc_booke_watchdog_enable’:
include/sysemu/kvm.h:449:35: error: ‘args_tmp[i]’ may be used uninitialized
in this function [-Werror=maybe-uninitialized]
cap.args[i] = args_tmp[i]; \
^
target/ppc/kvm.c: In function ‘kvmppc_set_papr’:
include/sysemu/kvm.h:449:35: error: ‘args_tmp[i]’ may be used uninitialized
in this function [-Werror=maybe-uninitialized]
cc1: all warnings being treated as errors
$ rpm -q gcc
gcc-7.1.1-3.fc26.ppc64le
Testing the size of args_tmp seems to be enough to prevent the warning
to pop up.
Signed-off-by: Greg Kurz <groug@kaod.org>
---
include/sysemu/kvm.h | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 91fc07ee9afe..41fc1005a9ea 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -429,9 +429,11 @@ int kvm_vm_check_extension(KVMState *s, unsigned int extension);
}; \
uint64_t args_tmp[] = { __VA_ARGS__ }; \
int i; \
- for (i = 0; i < (int)ARRAY_SIZE(args_tmp) && \
+ if (sizeof(args_tmp)) { \
+ for (i = 0; i < (int)ARRAY_SIZE(args_tmp) && \
i < ARRAY_SIZE(cap.args); i++) { \
- cap.args[i] = args_tmp[i]; \
+ cap.args[i] = args_tmp[i]; \
+ } \
} \
kvm_vm_ioctl(s, KVM_ENABLE_CAP, &cap); \
})
@@ -444,9 +446,11 @@ int kvm_vm_check_extension(KVMState *s, unsigned int extension);
}; \
uint64_t args_tmp[] = { __VA_ARGS__ }; \
int i; \
- for (i = 0; i < (int)ARRAY_SIZE(args_tmp) && \
+ if (sizeof(args_tmp)) { \
+ for (i = 0; i < (int)ARRAY_SIZE(args_tmp) && \
i < ARRAY_SIZE(cap.args); i++) { \
- cap.args[i] = args_tmp[i]; \
+ cap.args[i] = args_tmp[i]; \
+ } \
} \
kvm_vcpu_ioctl(cpu, KVM_ENABLE_CAP, &cap); \
})
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [Qemu-devel] [PATCH] kvm: workaround build break on gcc-7.1.1 / fedora26
2017-08-02 14:47 [Qemu-devel] [PATCH] kvm: workaround build break on gcc-7.1.1 / fedora26 Greg Kurz
@ 2017-08-03 13:34 ` Philippe Mathieu-Daudé
2017-08-03 13:55 ` Eric Blake
2017-08-03 14:31 ` Greg Kurz
2017-08-03 13:46 ` Philippe Mathieu-Daudé
1 sibling, 2 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-08-03 13:34 UTC (permalink / raw)
To: Greg Kurz, qemu-devel; +Cc: Paolo Bonzini, Eric Blake
Hi Greg,
On 08/02/2017 11:47 AM, Greg Kurz wrote:
> Building QEMU on fedora26 with the latest gcc package fails:
>
> CC ppc64-softmmu/target/ppc/kvm.o
> In file included from include/sysemu/hw_accel.h:16:0,
> from target/ppc/kvm.c:31:
> target/ppc/kvm.c: In function ‘kvmppc_booke_watchdog_enable’:
> include/sysemu/kvm.h:449:35: error: ‘args_tmp[i]’ may be used uninitialized
> in this function [-Werror=maybe-uninitialized]
> cap.args[i] = args_tmp[i]; \
> ^
> target/ppc/kvm.c: In function ‘kvmppc_set_papr’:
> include/sysemu/kvm.h:449:35: error: ‘args_tmp[i]’ may be used uninitialized
> in this function [-Werror=maybe-uninitialized]
> cc1: all warnings being treated as errors
>
> $ rpm -q gcc
> gcc-7.1.1-3.fc26.ppc64le
>
> Testing the size of args_tmp seems to be enough to prevent the warning
> to pop up.
This sizeof() use looks unnatural to me. I wonder why not use size_t,
since this is about sizeof()/ARRAY_SIZE(). The problem seems to come
from the commit this cast was introduced (61c7bbd236):
target-ppc/kvm.c:1302:21: error: comparison of unsigned expression < 0
is always false [-Werror=type-limits]
So I'd rather suggest this code, which looks more natural to read to me:
if (ARRAY_SIZE(args_tmp)) {
for (i = 0; i < ARRAY_SIZE(args_tmp) && ...
I Cc'ed Eric :)
Regards,
Phil.
>
> Signed-off-by: Greg Kurz <groug@kaod.org>
> ---
> include/sysemu/kvm.h | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
> index 91fc07ee9afe..41fc1005a9ea 100644
> --- a/include/sysemu/kvm.h
> +++ b/include/sysemu/kvm.h
> @@ -429,9 +429,11 @@ int kvm_vm_check_extension(KVMState *s, unsigned int extension);
> }; \
> uint64_t args_tmp[] = { __VA_ARGS__ }; \
> int i; \
> - for (i = 0; i < (int)ARRAY_SIZE(args_tmp) && \
> + if (sizeof(args_tmp)) { \
> + for (i = 0; i < (int)ARRAY_SIZE(args_tmp) && \
> i < ARRAY_SIZE(cap.args); i++) { \
> - cap.args[i] = args_tmp[i]; \
> + cap.args[i] = args_tmp[i]; \
> + } \
> } \
> kvm_vm_ioctl(s, KVM_ENABLE_CAP, &cap); \
> })
> @@ -444,9 +446,11 @@ int kvm_vm_check_extension(KVMState *s, unsigned int extension);
> }; \
> uint64_t args_tmp[] = { __VA_ARGS__ }; \
> int i; \
> - for (i = 0; i < (int)ARRAY_SIZE(args_tmp) && \
> + if (sizeof(args_tmp)) { \
> + for (i = 0; i < (int)ARRAY_SIZE(args_tmp) && \
> i < ARRAY_SIZE(cap.args); i++) { \
> - cap.args[i] = args_tmp[i]; \
> + cap.args[i] = args_tmp[i]; \
> + } \
> } \
> kvm_vcpu_ioctl(cpu, KVM_ENABLE_CAP, &cap); \
> })
>
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Qemu-devel] [PATCH] kvm: workaround build break on gcc-7.1.1 / fedora26
2017-08-02 14:47 [Qemu-devel] [PATCH] kvm: workaround build break on gcc-7.1.1 / fedora26 Greg Kurz
2017-08-03 13:34 ` Philippe Mathieu-Daudé
@ 2017-08-03 13:46 ` Philippe Mathieu-Daudé
2017-08-03 14:10 ` Eric Blake
2017-08-03 14:36 ` Greg Kurz
1 sibling, 2 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-08-03 13:46 UTC (permalink / raw)
To: Greg Kurz, qemu-devel
Cc: Paolo Bonzini, Eric Blake, Fam Zheng, Alex Bennée
Hi Greg,
On 08/02/2017 11:47 AM, Greg Kurz wrote:
> Building QEMU on fedora26 with the latest gcc package fails:
>
> CC ppc64-softmmu/target/ppc/kvm.o
> In file included from include/sysemu/hw_accel.h:16:0,
> from target/ppc/kvm.c:31:
> target/ppc/kvm.c: In function ‘kvmppc_booke_watchdog_enable’:
> include/sysemu/kvm.h:449:35: error: ‘args_tmp[i]’ may be used uninitialized
> in this function [-Werror=maybe-uninitialized]
> cap.args[i] = args_tmp[i]; \
> ^
> target/ppc/kvm.c: In function ‘kvmppc_set_papr’:
> include/sysemu/kvm.h:449:35: error: ‘args_tmp[i]’ may be used uninitialized
> in this function [-Werror=maybe-uninitialized]
> cc1: all warnings being treated as errors
I'm trying to reproduce this in our docker images (all x86_64 based) but
can't reproduce.
./configure shows:
KVM support yes
but in "sysemu/kvm.h" CONFIG_KVM_IS_POSSIBLE is not defined
I can see CONFIG_KVM defined, but no NEED_CPU_H.
>
> $ rpm -q gcc
> gcc-7.1.1-3.fc26.ppc64le
I don't have native ppc64le to build, do you know if it is possible to
cross-compile enabling kvm? It seems I have the correct Linux headers, I
wonder if this isn't a ./configure test which disable the kvm cross-build.
Regards,
Phil.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Qemu-devel] [PATCH] kvm: workaround build break on gcc-7.1.1 / fedora26
2017-08-03 13:34 ` Philippe Mathieu-Daudé
@ 2017-08-03 13:55 ` Eric Blake
2017-08-03 14:07 ` Philippe Mathieu-Daudé
2017-08-03 14:31 ` Greg Kurz
1 sibling, 1 reply; 13+ messages in thread
From: Eric Blake @ 2017-08-03 13:55 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, Greg Kurz, qemu-devel; +Cc: Paolo Bonzini
[-- Attachment #1: Type: text/plain, Size: 1498 bytes --]
On 08/03/2017 08:34 AM, Philippe Mathieu-Daudé wrote:
> Hi Greg,
>
> On 08/02/2017 11:47 AM, Greg Kurz wrote:
>> Building QEMU on fedora26 with the latest gcc package fails:
>>
>> CC ppc64-softmmu/target/ppc/kvm.o
>> In file included from include/sysemu/hw_accel.h:16:0,
>> from target/ppc/kvm.c:31:
>> target/ppc/kvm.c: In function ‘kvmppc_booke_watchdog_enable’:
>> include/sysemu/kvm.h:449:35: error: ‘args_tmp[i]’ may be used
>> uninitialized
>
> This sizeof() use looks unnatural to me. I wonder why not use size_t,
> since this is about sizeof()/ARRAY_SIZE(). The problem seems to come
> from the commit this cast was introduced (61c7bbd236):
>
> target-ppc/kvm.c:1302:21: error: comparison of unsigned expression < 0
> is always false [-Werror=type-limits]
>
> So I'd rather suggest this code, which looks more natural to read to me:
>
> if (ARRAY_SIZE(args_tmp)) {
> for (i = 0; i < ARRAY_SIZE(args_tmp) && ...
For that matter, the existing code is doing:
int i;
i < (int)ARRAY_SIZE(args_tmp)
but wouldn't that be better as:
size_t i;
i < ARRAY_SIZE(args_temp)
I guess we have both the old compilers (per commit 61c7bbd2) and the new
to worry about; although I was unable to reproduce it on Fedora 26 on
x86_64 (is this an architecture-dependent compiler bug?)
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Qemu-devel] [PATCH] kvm: workaround build break on gcc-7.1.1 / fedora26
2017-08-03 13:55 ` Eric Blake
@ 2017-08-03 14:07 ` Philippe Mathieu-Daudé
2017-08-03 18:38 ` Greg Kurz
0 siblings, 1 reply; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-08-03 14:07 UTC (permalink / raw)
To: Eric Blake, Greg Kurz, qemu-devel; +Cc: Paolo Bonzini
On 08/03/2017 10:55 AM, Eric Blake wrote:
> On 08/03/2017 08:34 AM, Philippe Mathieu-Daudé wrote:
>> Hi Greg,
>>
>> On 08/02/2017 11:47 AM, Greg Kurz wrote:
>>> Building QEMU on fedora26 with the latest gcc package fails:
>>>
>>> CC ppc64-softmmu/target/ppc/kvm.o
>>> In file included from include/sysemu/hw_accel.h:16:0,
>>> from target/ppc/kvm.c:31:
>>> target/ppc/kvm.c: In function ‘kvmppc_booke_watchdog_enable’:
>>> include/sysemu/kvm.h:449:35: error: ‘args_tmp[i]’ may be used
>>> uninitialized
>
>>
>> This sizeof() use looks unnatural to me. I wonder why not use size_t,
>> since this is about sizeof()/ARRAY_SIZE(). The problem seems to come
>> from the commit this cast was introduced (61c7bbd236):
>>
>> target-ppc/kvm.c:1302:21: error: comparison of unsigned expression < 0
>> is always false [-Werror=type-limits]
>>
>> So I'd rather suggest this code, which looks more natural to read to me:
>>
>> if (ARRAY_SIZE(args_tmp)) {
>> for (i = 0; i < ARRAY_SIZE(args_tmp) && ...
Oops I forgot to suggest size_t i.
>
> For that matter, the existing code is doing:
>
> int i;
> i < (int)ARRAY_SIZE(args_tmp)
>
> but wouldn't that be better as:
>
> size_t i;
> i < ARRAY_SIZE(args_temp)
>
> I guess we have both the old compilers (per commit 61c7bbd2) and the new
> to worry about; although I was unable to reproduce it on Fedora 26 on
> x86_64 (is this an architecture-dependent compiler bug?)
>
Ok so let's stop losing time about compiler incoherent warnings, using
-Wno-type-limits for GCC < 5...
So we can keep a sane/understandable codebase, using size_t and no (int)
cast.
Phil.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Qemu-devel] [PATCH] kvm: workaround build break on gcc-7.1.1 / fedora26
2017-08-03 13:46 ` Philippe Mathieu-Daudé
@ 2017-08-03 14:10 ` Eric Blake
2017-08-03 14:24 ` Cornelia Huck
2017-08-03 14:36 ` Greg Kurz
1 sibling, 1 reply; 13+ messages in thread
From: Eric Blake @ 2017-08-03 14:10 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, Greg Kurz, qemu-devel
Cc: Paolo Bonzini, Fam Zheng, Alex Bennée
[-- Attachment #1: Type: text/plain, Size: 2030 bytes --]
On 08/03/2017 08:46 AM, Philippe Mathieu-Daudé wrote:
> Hi Greg,
>
> On 08/02/2017 11:47 AM, Greg Kurz wrote:
>> Building QEMU on fedora26 with the latest gcc package fails:
>>
>> CC ppc64-softmmu/target/ppc/kvm.o
>> In file included from include/sysemu/hw_accel.h:16:0,
>> from target/ppc/kvm.c:31:
>> target/ppc/kvm.c: In function ‘kvmppc_booke_watchdog_enable’:
>> include/sysemu/kvm.h:449:35: error: ‘args_tmp[i]’ may be used
>> uninitialized
>> in this function [-Werror=maybe-uninitialized]
>> cap.args[i] = args_tmp[i]; \
>> ^
>> target/ppc/kvm.c: In function ‘kvmppc_set_papr’:
>> include/sysemu/kvm.h:449:35: error: ‘args_tmp[i]’ may be used
>> uninitialized
>> in this function [-Werror=maybe-uninitialized]
>> cc1: all warnings being treated as errors
>
> I'm trying to reproduce this in our docker images (all x86_64 based) but
> can't reproduce.
That's because x86_64 hosts only call kvm_vm_enable_cap() with non-empty
varargs. But we have:
accel/kvm/kvm-all.c: ret = kvm_vm_enable_cap(s, KVM_CAP_S390_IRQCHIP, 0);
which is only compiled on s390 hosts (or, at least that's my guess,
based on the cap name) - and THAT code is passing empty varargs, which
explains args_tmp[] being a 0-length array, and getting the compiler to
complain about i < 0 always being false.
So my question on IRC was whether we can stack the decks, and force a
non-empty args_tmp = { 0, __VA_ARGS__} coupled by skipping the first
iteration in the for loop. Or, since cap.args[] is already being
zero-initialized, args_tmp = { __VA_ARGS__, 0 } means the last iteration
of the for loop is a no-op (assigning 0 to something that is already 0)
- although that may be harder to correctly account for both empty and
non-empty __VA_ARGS__.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Qemu-devel] [PATCH] kvm: workaround build break on gcc-7.1.1 / fedora26
2017-08-03 14:10 ` Eric Blake
@ 2017-08-03 14:24 ` Cornelia Huck
2017-08-04 16:54 ` Paolo Bonzini
0 siblings, 1 reply; 13+ messages in thread
From: Cornelia Huck @ 2017-08-03 14:24 UTC (permalink / raw)
To: Eric Blake
Cc: Philippe Mathieu-Daudé,
Greg Kurz, qemu-devel, Alex Bennée, Paolo Bonzini,
Fam Zheng
On Thu, 3 Aug 2017 09:10:29 -0500
Eric Blake <eblake@redhat.com> wrote:
> On 08/03/2017 08:46 AM, Philippe Mathieu-Daudé wrote:
> > Hi Greg,
> >
> > On 08/02/2017 11:47 AM, Greg Kurz wrote:
> >> Building QEMU on fedora26 with the latest gcc package fails:
> >>
> >> CC ppc64-softmmu/target/ppc/kvm.o
> >> In file included from include/sysemu/hw_accel.h:16:0,
> >> from target/ppc/kvm.c:31:
> >> target/ppc/kvm.c: In function ‘kvmppc_booke_watchdog_enable’:
> >> include/sysemu/kvm.h:449:35: error: ‘args_tmp[i]’ may be used
> >> uninitialized
> >> in this function [-Werror=maybe-uninitialized]
> >> cap.args[i] = args_tmp[i]; \
> >> ^
> >> target/ppc/kvm.c: In function ‘kvmppc_set_papr’:
> >> include/sysemu/kvm.h:449:35: error: ‘args_tmp[i]’ may be used
> >> uninitialized
> >> in this function [-Werror=maybe-uninitialized]
> >> cc1: all warnings being treated as errors
> >
> > I'm trying to reproduce this in our docker images (all x86_64 based) but
> > can't reproduce.
>
> That's because x86_64 hosts only call kvm_vm_enable_cap() with non-empty
> varargs.
There's
target/i386/kvm.c: kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_SYNIC, 0)) {
> But we have:
>
> accel/kvm/kvm-all.c: ret = kvm_vm_enable_cap(s, KVM_CAP_S390_IRQCHIP, 0);
>
> which is only compiled on s390 hosts (or, at least that's my guess,
> based on the cap name)
I don't see how the compiler can optimize this away, as the check for
this cap is an ioctl...
> - and THAT code is passing empty varargs, which
> explains args_tmp[] being a 0-length array, and getting the compiler to
> complain about i < 0 always being false.
[I don't have any s390x system with gcc7 yet, or I'd test this.]
>
> So my question on IRC was whether we can stack the decks, and force a
> non-empty args_tmp = { 0, __VA_ARGS__} coupled by skipping the first
> iteration in the for loop. Or, since cap.args[] is already being
> zero-initialized, args_tmp = { __VA_ARGS__, 0 } means the last iteration
> of the for loop is a no-op (assigning 0 to something that is already 0)
> - although that may be harder to correctly account for both empty and
> non-empty __VA_ARGS__.
This seems a bit ugly. And I still don't understand why this only seems
to hit on ppc...
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Qemu-devel] [PATCH] kvm: workaround build break on gcc-7.1.1 / fedora26
2017-08-03 13:34 ` Philippe Mathieu-Daudé
2017-08-03 13:55 ` Eric Blake
@ 2017-08-03 14:31 ` Greg Kurz
1 sibling, 0 replies; 13+ messages in thread
From: Greg Kurz @ 2017-08-03 14:31 UTC (permalink / raw)
To: Philippe Mathieu-Daudé; +Cc: qemu-devel, Paolo Bonzini, Eric Blake
[-- Attachment #1: Type: text/plain, Size: 4334 bytes --]
On Thu, 3 Aug 2017 10:34:45 -0300
Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> Hi Greg,
>
> On 08/02/2017 11:47 AM, Greg Kurz wrote:
> > Building QEMU on fedora26 with the latest gcc package fails:
> >
> > CC ppc64-softmmu/target/ppc/kvm.o
> > In file included from include/sysemu/hw_accel.h:16:0,
> > from target/ppc/kvm.c:31:
> > target/ppc/kvm.c: In function ‘kvmppc_booke_watchdog_enable’:
> > include/sysemu/kvm.h:449:35: error: ‘args_tmp[i]’ may be used uninitialized
> > in this function [-Werror=maybe-uninitialized]
> > cap.args[i] = args_tmp[i]; \
> > ^
> > target/ppc/kvm.c: In function ‘kvmppc_set_papr’:
> > include/sysemu/kvm.h:449:35: error: ‘args_tmp[i]’ may be used uninitialized
> > in this function [-Werror=maybe-uninitialized]
> > cc1: all warnings being treated as errors
> >
> > $ rpm -q gcc
> > gcc-7.1.1-3.fc26.ppc64le
> >
> > Testing the size of args_tmp seems to be enough to prevent the warning
> > to pop up.
>
> This sizeof() use looks unnatural to me. I wonder why not use size_t,
> since this is about sizeof()/ARRAY_SIZE(). The problem seems to come
> from the commit this cast was introduced (61c7bbd236):
>
> target-ppc/kvm.c:1302:21: error: comparison of unsigned expression < 0
> is always false [-Werror=type-limits]
>
Switching from int to size_t causes this error ^^ to show up again.
> So I'd rather suggest this code, which looks more natural to read to me:
>
> if (ARRAY_SIZE(args_tmp)) {
Yeah, it's maybe more in phase with the context but anyway, the truly
unnatural thing is to be forced to do:
if (foo) {
for (i = 0; i < foo; ...
> for (i = 0; i < ARRAY_SIZE(args_tmp) && ...
>
> I Cc'ed Eric :)
>
> Regards,
>
> Phil.
>
> >
> > Signed-off-by: Greg Kurz <groug@kaod.org>
> > ---
> > include/sysemu/kvm.h | 12 ++++++++----
> > 1 file changed, 8 insertions(+), 4 deletions(-)
> >
> > diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
> > index 91fc07ee9afe..41fc1005a9ea 100644
> > --- a/include/sysemu/kvm.h
> > +++ b/include/sysemu/kvm.h
> > @@ -429,9 +429,11 @@ int kvm_vm_check_extension(KVMState *s, unsigned int extension);
> > }; \
> > uint64_t args_tmp[] = { __VA_ARGS__ }; \
> > int i; \
> > - for (i = 0; i < (int)ARRAY_SIZE(args_tmp) && \
> > + if (sizeof(args_tmp)) { \
> > + for (i = 0; i < (int)ARRAY_SIZE(args_tmp) && \
> > i < ARRAY_SIZE(cap.args); i++) { \
> > - cap.args[i] = args_tmp[i]; \
> > + cap.args[i] = args_tmp[i]; \
> > + } \
> > } \
> > kvm_vm_ioctl(s, KVM_ENABLE_CAP, &cap); \
> > })
> > @@ -444,9 +446,11 @@ int kvm_vm_check_extension(KVMState *s, unsigned int extension);
> > }; \
> > uint64_t args_tmp[] = { __VA_ARGS__ }; \
> > int i; \
> > - for (i = 0; i < (int)ARRAY_SIZE(args_tmp) && \
> > + if (sizeof(args_tmp)) { \
> > + for (i = 0; i < (int)ARRAY_SIZE(args_tmp) && \
> > i < ARRAY_SIZE(cap.args); i++) { \
> > - cap.args[i] = args_tmp[i]; \
> > + cap.args[i] = args_tmp[i]; \
> > + } \
> > } \
> > kvm_vcpu_ioctl(cpu, KVM_ENABLE_CAP, &cap); \
> > })
> >
> >
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Qemu-devel] [PATCH] kvm: workaround build break on gcc-7.1.1 / fedora26
2017-08-03 13:46 ` Philippe Mathieu-Daudé
2017-08-03 14:10 ` Eric Blake
@ 2017-08-03 14:36 ` Greg Kurz
1 sibling, 0 replies; 13+ messages in thread
From: Greg Kurz @ 2017-08-03 14:36 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: qemu-devel, Paolo Bonzini, Eric Blake, Fam Zheng, Alex Bennée
[-- Attachment #1: Type: text/plain, Size: 1717 bytes --]
On Thu, 3 Aug 2017 10:46:47 -0300
Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> Hi Greg,
>
> On 08/02/2017 11:47 AM, Greg Kurz wrote:
> > Building QEMU on fedora26 with the latest gcc package fails:
> >
> > CC ppc64-softmmu/target/ppc/kvm.o
> > In file included from include/sysemu/hw_accel.h:16:0,
> > from target/ppc/kvm.c:31:
> > target/ppc/kvm.c: In function ‘kvmppc_booke_watchdog_enable’:
> > include/sysemu/kvm.h:449:35: error: ‘args_tmp[i]’ may be used uninitialized
> > in this function [-Werror=maybe-uninitialized]
> > cap.args[i] = args_tmp[i]; \
> > ^
> > target/ppc/kvm.c: In function ‘kvmppc_set_papr’:
> > include/sysemu/kvm.h:449:35: error: ‘args_tmp[i]’ may be used uninitialized
> > in this function [-Werror=maybe-uninitialized]
> > cc1: all warnings being treated as errors
>
> I'm trying to reproduce this in our docker images (all x86_64 based) but
> can't reproduce.
>
> ./configure shows:
>
> KVM support yes
>
> but in "sysemu/kvm.h" CONFIG_KVM_IS_POSSIBLE is not defined
>
> I can see CONFIG_KVM defined, but no NEED_CPU_H.
>
> >
> > $ rpm -q gcc
> > gcc-7.1.1-3.fc26.ppc64le
>
> I don't have native ppc64le to build, do you know if it is possible to
> cross-compile enabling kvm? It seems I have the correct Linux headers, I
> wonder if this isn't a ./configure test which disable the kvm cross-build.
>
I don't cross-compile personally but I see no reasons why it wouldn't be
possible. I'd say the biggest churn is to setup the cross-compile environment :)
> Regards,
>
> Phil.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Qemu-devel] [PATCH] kvm: workaround build break on gcc-7.1.1 / fedora26
2017-08-03 14:07 ` Philippe Mathieu-Daudé
@ 2017-08-03 18:38 ` Greg Kurz
2017-08-03 18:56 ` Eric Blake
0 siblings, 1 reply; 13+ messages in thread
From: Greg Kurz @ 2017-08-03 18:38 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: Eric Blake, qemu-devel, Paolo Bonzini, Cornelia Huck
[-- Attachment #1: Type: text/plain, Size: 2633 bytes --]
On Thu, 3 Aug 2017 11:07:13 -0300
Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> On 08/03/2017 10:55 AM, Eric Blake wrote:
> > On 08/03/2017 08:34 AM, Philippe Mathieu-Daudé wrote:
> >> Hi Greg,
> >>
> >> On 08/02/2017 11:47 AM, Greg Kurz wrote:
> >>> Building QEMU on fedora26 with the latest gcc package fails:
> >>>
> >>> CC ppc64-softmmu/target/ppc/kvm.o
> >>> In file included from include/sysemu/hw_accel.h:16:0,
> >>> from target/ppc/kvm.c:31:
> >>> target/ppc/kvm.c: In function ‘kvmppc_booke_watchdog_enable’:
> >>> include/sysemu/kvm.h:449:35: error: ‘args_tmp[i]’ may be used
> >>> uninitialized
> >
> >>
> >> This sizeof() use looks unnatural to me. I wonder why not use size_t,
> >> since this is about sizeof()/ARRAY_SIZE(). The problem seems to come
> >> from the commit this cast was introduced (61c7bbd236):
> >>
> >> target-ppc/kvm.c:1302:21: error: comparison of unsigned expression < 0
> >> is always false [-Werror=type-limits]
> >>
> >> So I'd rather suggest this code, which looks more natural to read to me:
> >>
> >> if (ARRAY_SIZE(args_tmp)) {
> >> for (i = 0; i < ARRAY_SIZE(args_tmp) && ...
>
> Oops I forgot to suggest size_t i.
>
> >
> > For that matter, the existing code is doing:
> >
> > int i;
> > i < (int)ARRAY_SIZE(args_tmp)
> >
> > but wouldn't that be better as:
> >
> > size_t i;
> > i < ARRAY_SIZE(args_temp)
> >
> > I guess we have both the old compilers (per commit 61c7bbd2) and the new
> > to worry about; although I was unable to reproduce it on Fedora 26 on
> > x86_64 (is this an architecture-dependent compiler bug?)
> >
>
The following code snippet spits a warning with gcc-7.1.1-3.fc26 and -Wall on
ppc64le AND x86_64:
int foo(void)
{
char empty_array[] = { };
int i, ret = 0;
for (i = 0; i < (int) (sizeof(empty_array) / sizeof(empty_array[0])); i++) {
ret = empty_array[i];
}
return ret;
}
If I drop the (int), the warning goes away... and so does the build break
of qemu-system-ppc64 on my ppc64le host.
I don't have 4.7.1 or 4.6 compilers around but I could check 4.8.5
is okay with that change FWIW.
> Ok so let's stop losing time about compiler incoherent warnings, using
> -Wno-type-limits for GCC < 5...
> So we can keep a sane/understandable codebase, using size_t and no (int)
> cast.
>
If I also convert 'int i' to 'size_t i' then I get the same error as
in commit 61c7bbd2:
error: comparison of unsigned expression < 0 is always
false [-Werror=type-limits]
> Phil.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Qemu-devel] [PATCH] kvm: workaround build break on gcc-7.1.1 / fedora26
2017-08-03 18:38 ` Greg Kurz
@ 2017-08-03 18:56 ` Eric Blake
2017-08-07 11:13 ` Greg Kurz
0 siblings, 1 reply; 13+ messages in thread
From: Eric Blake @ 2017-08-03 18:56 UTC (permalink / raw)
To: Greg Kurz, Philippe Mathieu-Daudé
Cc: qemu-devel, Paolo Bonzini, Cornelia Huck
[-- Attachment #1: Type: text/plain, Size: 1597 bytes --]
On 08/03/2017 01:38 PM, Greg Kurz wrote:
> The following code snippet spits a warning with gcc-7.1.1-3.fc26 and -Wall on
> ppc64le AND x86_64:
>
> int foo(void)
> {
> char empty_array[] = { };
> int i, ret = 0;
>
> for (i = 0; i < (int) (sizeof(empty_array) / sizeof(empty_array[0])); i++) {
> ret = empty_array[i];
> }
>
> return ret;
> }
Confirmed. No idea why the cast makes gcc think i is uninitialized.
>
> If I drop the (int), the warning goes away... and so does the build break
> of qemu-system-ppc64 on my ppc64le host.
>
> I don't have 4.7.1 or 4.6 compilers around but I could check 4.8.5
> is okay with that change FWIW.
I tested with gcc 4.4.7 on RHEL 6, but -Wtype-limits there didn't warn
whether or not the (int) was present; it's possible that we still need
to test with 4.6 or 4.7.1 to see whether it makes a difference.
>
>> Ok so let's stop losing time about compiler incoherent warnings, using
>> -Wno-type-limits for GCC < 5...
>> So we can keep a sane/understandable codebase, using size_t and no (int)
>> cast.
That's also a possibility, if we still hit old compilers that require
the (int).
>>
>
> If I also convert 'int i' to 'size_t i' then I get the same error as
> in commit 61c7bbd2:
>
> error: comparison of unsigned expression < 0 is always
> false [-Werror=type-limits]
Confirmed with newer gcc, whether or not the (int) cast is present.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Qemu-devel] [PATCH] kvm: workaround build break on gcc-7.1.1 / fedora26
2017-08-03 14:24 ` Cornelia Huck
@ 2017-08-04 16:54 ` Paolo Bonzini
0 siblings, 0 replies; 13+ messages in thread
From: Paolo Bonzini @ 2017-08-04 16:54 UTC (permalink / raw)
To: Cornelia Huck, Eric Blake
Cc: Philippe Mathieu-Daudé,
Greg Kurz, qemu-devel, Alex Bennée, Fam Zheng
On 03/08/2017 16:24, Cornelia Huck wrote:
> On Thu, 3 Aug 2017 09:10:29 -0500
> Eric Blake <eblake@redhat.com> wrote:
>
>> On 08/03/2017 08:46 AM, Philippe Mathieu-Daudé wrote:
>>> Hi Greg,
>>>
>>> On 08/02/2017 11:47 AM, Greg Kurz wrote:
>>>> Building QEMU on fedora26 with the latest gcc package fails:
>>>>
>>>> CC ppc64-softmmu/target/ppc/kvm.o
>>>> In file included from include/sysemu/hw_accel.h:16:0,
>>>> from target/ppc/kvm.c:31:
>>>> target/ppc/kvm.c: In function ‘kvmppc_booke_watchdog_enable’:
>>>> include/sysemu/kvm.h:449:35: error: ‘args_tmp[i]’ may be used
>>>> uninitialized
>>>> in this function [-Werror=maybe-uninitialized]
>>>> cap.args[i] = args_tmp[i]; \
>>>> ^
>>>> target/ppc/kvm.c: In function ‘kvmppc_set_papr’:
>>>> include/sysemu/kvm.h:449:35: error: ‘args_tmp[i]’ may be used
>>>> uninitialized
>>>> in this function [-Werror=maybe-uninitialized]
>>>> cc1: all warnings being treated as errors
>>>
>>> I'm trying to reproduce this in our docker images (all x86_64 based) but
>>> can't reproduce.
>>
>> That's because x86_64 hosts only call kvm_vm_enable_cap() with non-empty
>> varargs.
>
> There's
>
> target/i386/kvm.c: kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_SYNIC, 0)) {
>
>> But we have:
>>
>> accel/kvm/kvm-all.c: ret = kvm_vm_enable_cap(s, KVM_CAP_S390_IRQCHIP, 0);
>>
>> which is only compiled on s390 hosts (or, at least that's my guess,
>> based on the cap name)
>
> I don't see how the compiler can optimize this away, as the check for
> this cap is an ioctl...
Indeed. This is a compiler bug and it only provides a warning (meaning
--disable-werror silences it). I don't think it's a good idea to uglify
the code for something that the compiler should easily optimize away...
Paolo
> This seems a bit ugly. And I still don't understand why this only seems
> to hit on ppc...
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Qemu-devel] [PATCH] kvm: workaround build break on gcc-7.1.1 / fedora26
2017-08-03 18:56 ` Eric Blake
@ 2017-08-07 11:13 ` Greg Kurz
0 siblings, 0 replies; 13+ messages in thread
From: Greg Kurz @ 2017-08-07 11:13 UTC (permalink / raw)
To: Eric Blake
Cc: Philippe Mathieu-Daudé, qemu-devel, Paolo Bonzini, Cornelia Huck
[-- Attachment #1: Type: text/plain, Size: 1764 bytes --]
On Thu, 3 Aug 2017 13:56:45 -0500
Eric Blake <eblake@redhat.com> wrote:
> On 08/03/2017 01:38 PM, Greg Kurz wrote:
> > The following code snippet spits a warning with gcc-7.1.1-3.fc26 and -Wall on
> > ppc64le AND x86_64:
> >
> > int foo(void)
> > {
> > char empty_array[] = { };
> > int i, ret = 0;
> >
> > for (i = 0; i < (int) (sizeof(empty_array) / sizeof(empty_array[0])); i++) {
> > ret = empty_array[i];
> > }
> >
> > return ret;
> > }
>
> Confirmed. No idea why the cast makes gcc think i is uninitialized.
>
FYI, I've created a BZ to track this issue in gcc:
https://bugzilla.redhat.com/show_bug.cgi?id=1478864
> >
> > If I drop the (int), the warning goes away... and so does the build break
> > of qemu-system-ppc64 on my ppc64le host.
> >
> > I don't have 4.7.1 or 4.6 compilers around but I could check 4.8.5
> > is okay with that change FWIW.
>
> I tested with gcc 4.4.7 on RHEL 6, but -Wtype-limits there didn't warn
> whether or not the (int) was present; it's possible that we still need
> to test with 4.6 or 4.7.1 to see whether it makes a difference.
>
> >
> >> Ok so let's stop losing time about compiler incoherent warnings, using
> >> -Wno-type-limits for GCC < 5...
> >> So we can keep a sane/understandable codebase, using size_t and no (int)
> >> cast.
>
> That's also a possibility, if we still hit old compilers that require
> the (int).
>
> >>
> >
> > If I also convert 'int i' to 'size_t i' then I get the same error as
> > in commit 61c7bbd2:
> >
> > error: comparison of unsigned expression < 0 is always
> > false [-Werror=type-limits]
>
> Confirmed with newer gcc, whether or not the (int) cast is present.
>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2017-08-07 11:13 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-02 14:47 [Qemu-devel] [PATCH] kvm: workaround build break on gcc-7.1.1 / fedora26 Greg Kurz
2017-08-03 13:34 ` Philippe Mathieu-Daudé
2017-08-03 13:55 ` Eric Blake
2017-08-03 14:07 ` Philippe Mathieu-Daudé
2017-08-03 18:38 ` Greg Kurz
2017-08-03 18:56 ` Eric Blake
2017-08-07 11:13 ` Greg Kurz
2017-08-03 14:31 ` Greg Kurz
2017-08-03 13:46 ` Philippe Mathieu-Daudé
2017-08-03 14:10 ` Eric Blake
2017-08-03 14:24 ` Cornelia Huck
2017-08-04 16:54 ` Paolo Bonzini
2017-08-03 14:36 ` Greg Kurz
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.