Skip to contentSkip to conversation

Fixing several GCC 11 warnings

PATCH Superseded [email protected] 5 participants 17 messages Jan 11, 2021 Networking

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Fixing several GCC 11 warnings

From: Miroslav Rezanina <[email protected]>

Compiling qemu using GCC 11 we got several new warnings. To allow build with --enable-werror, we need to solve issues generating these warnings.

Miroslav Rezanina (3):
Fix net.c warning on GCC 11
s390x: Fix vm name copy length
Fix tcg_out_op argument mismatch warning

 net/eth.c                    | 3 +++
 target/s390x/kvm.c           | 2 +-
 target/s390x/misc_helper.c   | 4 +++-
 tcg/aarch64/tcg-target.c.inc | 3 +--
 tcg/sparc/tcg-target.c.inc   | 3 +--
 5 files changed, 9 insertions(+), 6 deletions(-)
Signature · 1 line
2.18.4
#1 lore raw

PATCH 1/3 Fix net.c warning on GCC 11

From: Miroslav Rezanina <[email protected]>

When building qemu with GCC 11, compiling eth.c file produce following warning:

warning: array subscript 'struct ip6_ext_hdr_routing[0]' is partly outside array bounds of 'struct ip6_ext_hdr[1]' [-Warray-bounds]

This caused by retyping from ip6_ext_hdr to ip6_ext_hdr_routing that has more attributes.

As this usage is expected, suppress the warning temporarily through the function using this retyping.

---
 net/eth.c | 3 +++
 1 file changed, 3 insertions(+)
net/eth.c +3 -0
index 1e0821c5f8..b9bdd0435c 100644
@@ -405,6 +405,8 @@ _eth_get_rss_ex_dst_addr(const struct iovec *pkt, int pkt_frags,
                         struct ip6_ext_hdr *ext_hdr,
                         struct in6_address *dst_addr)
 {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Warray-bounds"
     struct ip6_ext_hdr_routing *rthdr = (struct ip6_ext_hdr_routing *) ext_hdr;
 
     if ((rthdr->rtype == 2) &&
@@ -426,6 +428,7 @@ _eth_get_rss_ex_dst_addr(const struct iovec *pkt, int pkt_frags,
     }
 
     return false;
+#pragma GCC diagnostic pop
 }
 
 static bool
Signature · 1 line
2.18.4
#2 lore raw

PATCH 2/3 s390x: Fix vm name copy length

In reply to [email protected]

From: Miroslav Rezanina <[email protected]>

There are two cases when vm name is copied but closing \0 can be lost in case name is too long (>=256 characters).

Updating length to copy so there is space for closing \0.

---
 target/s390x/kvm.c         | 2 +-
 target/s390x/misc_helper.c | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)
target/s390x/kvm.c +1 -1
index b8385e6b95..2313b5727e 100644
@@ -1918,7 +1918,7 @@ static void insert_stsi_3_2_2(S390CPU *cpu, __u64 addr, uint8_t ar)
      */
     if (qemu_name) {
         strncpy((char *)sysib.ext_names[0], qemu_name,
-                sizeof(sysib.ext_names[0]));
+                sizeof(sysib.ext_names[0]) - 1);
     } else {
         strcpy((char *)sysib.ext_names[0], "KVMguest");
     }
target/s390x/misc_helper.c +3 -1
index 58dbc023eb..7c478b9e58 100644
@@ -369,8 +369,10 @@ uint32_t HELPER(stsi)(CPUS390XState *env, uint64_t a0, uint64_t r0, uint64_t r1)
                 ebcdic_put(sysib.sysib_322.vm[0].name, qemu_name,
                            MIN(sizeof(sysib.sysib_322.vm[0].name),
                                strlen(qemu_name)));
+		memset((char *)sysib.sysib_322.ext_names[0], 0, 
+		       sizeof(sysib.sysib_322.ext_names[0]));
                 strncpy((char *)sysib.sysib_322.ext_names[0], qemu_name,
-                        sizeof(sysib.sysib_322.ext_names[0]));
+                        sizeof(sysib.sysib_322.ext_names[0]) - 1);
             } else {
                 ebcdic_put(sysib.sysib_322.vm[0].name, "TCGguest", 8);
                 strcpy((char *)sysib.sysib_322.ext_names[0], "TCGguest");
Signature · 1 line
2.18.4
#3 lore raw

Re: [RHEL7 qemu-kvm PATCH 2/3] s390x: Fix vm name copy length

Hi Miroslav,

Quoted 18 lines · On 1/11/21 12:30 PM, [email protected] wrote:

From: Miroslav Rezanina <[email protected]>

There are two cases when vm name is copied but closing \0 can be lost in case name is too long (>=256 characters).

Updating length to copy so there is space for closing \0.

---
 target/s390x/kvm.c         | 2 +-
 target/s390x/misc_helper.c | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)
target/s390x/kvm.c +0 -0
index b8385e6b95..2313b5727e 100644

target/s390x/kvm.c static void insert_stsi_3_2_2(S390CPU *cpu, __u64 addr, uint8_t ar) · line 1924

Quoted 8 lines
target/s390x/kvm.c +1 -1
@@ -1918,7 +1918,7 @@ static void insert_stsi_3_2_2(S390CPU *cpu, __u64 addr, uint8_t ar)
      */
     if (qemu_name) {
         strncpy((char *)sysib.ext_names[0], qemu_name,
-                sizeof(sysib.ext_names[0]));
+                sizeof(sysib.ext_names[0]) - 1);
     } else {
         strcpy((char *)sysib.ext_names[0], "KVMguest");
     }

What about using strpadcpy() instead?

    strpadcpy((char *)sysib.sysib_322.ext_names[0],
              sizeof(sysib.sysib_322.ext_names[0]),
              qemu_name ?: "KVMguest", '\0');

target/s390x/misc_helper.c uint32_t HELPER(stsi)(CPUS390XState *env, uint64_t a0, uint64_t r0, uint64_t r1) · line 375

Quoted 13 lines
target/s390x/misc_helper.c +3 -1
index 58dbc023eb..7c478b9e58 100644
@@ -369,8 +369,10 @@ uint32_t HELPER(stsi)(CPUS390XState *env, uint64_t a0, uint64_t r0, uint64_t r1)
                 ebcdic_put(sysib.sysib_322.vm[0].name, qemu_name,
                            MIN(sizeof(sysib.sysib_322.vm[0].name),
                                strlen(qemu_name)));
+		memset((char *)sysib.sysib_322.ext_names[0], 0, 
+		       sizeof(sysib.sysib_322.ext_names[0]));
                 strncpy((char *)sysib.sysib_322.ext_names[0], qemu_name,
-                        sizeof(sysib.sysib_322.ext_names[0]));
+                        sizeof(sysib.sysib_322.ext_names[0]) - 1);

And here:

               strpadcpy((char *)sysib.sysib_322.ext_names[0],
                         sizeof(sysib.sysib_322.ext_names[0]),
                         qemu_name, '\0');
Quoted 4 lines
target/s390x/misc_helper.c +0 -0
             } else {
                 ebcdic_put(sysib.sysib_322.vm[0].name, "TCGguest", 8);
                 strcpy((char *)sysib.sysib_322.ext_names[0], "TCGguest");
#4 lore raw

Re: [RHEL7 qemu-kvm PATCH 2/3] s390x: Fix vm name copy length

Quoted 16 lines · Philippe Mathieu-Daudé

Hi Miroslav,

Quoted 13 lines · On 1/11/21 12:30 PM, [email protected] wrote:

From: Miroslav Rezanina <[email protected]>

There are two cases when vm name is copied but closing \0 can be lost in case name is too long (>=256 characters).

Updating length to copy so there is space for closing \0.

---
  target/s390x/kvm.c         | 2 +-
  target/s390x/misc_helper.c | 4 +++-
  2 files changed, 4 insertions(+), 2 deletions(-)
Quoted 15 lines

target/s390x/kvm.c static void insert_stsi_3_2_2(S390CPU *cpu, __u64 addr, uint8_t ar) · line 1924

Quoted 13 lines
target/s390x/kvm.c +1 -1
index b8385e6b95..2313b5727e 100644
@@ -1918,7 +1918,7 @@ static void insert_stsi_3_2_2(S390CPU *cpu, __u64 addr, uint8_t ar)
       */
      if (qemu_name) {
          strncpy((char *)sysib.ext_names[0], qemu_name,
-                sizeof(sysib.ext_names[0]));
+                sizeof(sysib.ext_names[0]) - 1);
      } else {
          strcpy((char *)sysib.ext_names[0], "KVMguest");
      }

What about using strpadcpy() instead?

Yes, strpadcpy is the better way here - this field has to be padded with zeroes, so doing "- 1" is wrong here.

Thomas

#5 lore raw

Re: [RHEL7 qemu-kvm PATCH 2/3] s390x: Fix vm name copy length

----- Original Message -----

Quoted 40 lines

From: "Thomas Huth" <[email protected]>
To: "Philippe Mathieu-Daudé" <[email protected]>, [email protected], [email protected], "qemu-s390x" <[email protected]>
Sent: Monday, January 11, 2021 1:24:57 PM
Subject: Re: [RHEL7 qemu-kvm PATCH 2/3] s390x: Fix vm name copy length

Quoted 16 lines · Philippe Mathieu-Daudé

Hi Miroslav,

Quoted 13 lines · On 1/11/21 12:30 PM, [email protected] wrote:

From: Miroslav Rezanina <[email protected]>

There are two cases when vm name is copied but closing \0 can be lost in case name is too long (>=256 characters).

Updating length to copy so there is space for closing \0.

---
  target/s390x/kvm.c         | 2 +-
  target/s390x/misc_helper.c | 4 +++-
  2 files changed, 4 insertions(+), 2 deletions(-)
Quoted 16 lines
Quoted 13 lines
target/s390x/kvm.c +1 -1
index b8385e6b95..2313b5727e 100644
@@ -1918,7 +1918,7 @@ static void insert_stsi_3_2_2(S390CPU *cpu, __u64
 addr, uint8_t ar)
       */
      if (qemu_name) {
          strncpy((char *)sysib.ext_names[0], qemu_name,
-                sizeof(sysib.ext_names[0]));
+                sizeof(sysib.ext_names[0]) - 1);
      } else {
          strcpy((char *)sysib.ext_names[0], "KVMguest");
Quoted 1 line
      }

What about using strpadcpy() instead?

Quoted 2 lines

Yes, strpadcpy is the better way here - this field has to be padded with zeroes, so doing "- 1" is wrong here.

Hi Thomas,

as I wrote in reply to Phillipe - the array is memset to zeroes before the if so we are sure it's padded with zeroes (in this occurrence, not true for second one).

Mirek

Quoted 3 lines

Thomas

Signature · 2 lines
Miroslav Rezanina
Software Engineer - Virtualization Team Maintainer
#6 lore raw

Re: [RHEL7 qemu-kvm PATCH 2/3] s390x: Fix vm name copy length

Quoted 43 lines · Miroslav Rezanina

----- Original Message -----

Quoted 40 lines

From: "Thomas Huth" <[email protected]>
To: "Philippe Mathieu-Daudé" <[email protected]>, [email protected], [email protected], "qemu-s390x" <[email protected]>
Sent: Monday, January 11, 2021 1:24:57 PM
Subject: Re: [RHEL7 qemu-kvm PATCH 2/3] s390x: Fix vm name copy length

Quoted 32 lines · Philippe Mathieu-Daudé

Hi Miroslav,

Quoted 26 lines · On 1/11/21 12:30 PM, [email protected] wrote:

From: Miroslav Rezanina <[email protected]>

There are two cases when vm name is copied but closing \0 can be lost in case name is too long (>=256 characters).

Updating length to copy so there is space for closing \0.

---
   target/s390x/kvm.c         | 2 +-
   target/s390x/misc_helper.c | 4 +++-
   2 files changed, 4 insertions(+), 2 deletions(-)
target/s390x/kvm.c +1 -1
index b8385e6b95..2313b5727e 100644
@@ -1918,7 +1918,7 @@ static void insert_stsi_3_2_2(S390CPU *cpu, __u64
 addr, uint8_t ar)
        */
       if (qemu_name) {
           strncpy((char *)sysib.ext_names[0], qemu_name,
-                sizeof(sysib.ext_names[0]));
+                sizeof(sysib.ext_names[0]) - 1);
       } else {
           strcpy((char *)sysib.ext_names[0], "KVMguest");
Quoted 1 line
       }

What about using strpadcpy() instead?

Quoted 7 lines
Quoted 2 lines

Yes, strpadcpy is the better way here - this field has to be padded with zeroes, so doing "- 1" is wrong here.

Hi Thomas,

as I wrote in reply to Phillipe - the array is memset to zeroes before the if so we are sure it's padded with zeroes (in this occurrence, not true for second one).

Ok, but dropping the last character is still wrong here. The ext_names do not need to be terminated with a \0 if they have the full length.

Thomas

#7 lore raw

Re: [RHEL7 qemu-kvm PATCH 2/3] s390x: Fix vm name copy length

----- Original Message -----

Quoted 56 lines

From: "Thomas Huth" <[email protected]>
To: "Miroslav Rezanina" <[email protected]>
Cc: "qemu-s390x" <[email protected]>, "Philippe Mathieu-Daudé" <[email protected]>, [email protected]
Sent: Monday, January 11, 2021 1:54:06 PM
Subject: Re: [RHEL7 qemu-kvm PATCH 2/3] s390x: Fix vm name copy length

Quoted 49 lines · Miroslav Rezanina

----- Original Message -----

Quoted 41 lines

From: "Thomas Huth" <[email protected]>
To: "Philippe Mathieu-Daudé" <[email protected]>, [email protected], [email protected], "qemu-s390x"
<[email protected]>
Sent: Monday, January 11, 2021 1:24:57 PM
Subject: Re: [RHEL7 qemu-kvm PATCH 2/3] s390x: Fix vm name copy length

Quoted 16 lines · Philippe Mathieu-Daudé

Hi Miroslav,

Quoted 13 lines · On 1/11/21 12:30 PM, [email protected] wrote:

From: Miroslav Rezanina <[email protected]>

There are two cases when vm name is copied but closing \0 can be lost in case name is too long (>=256 characters).

Updating length to copy so there is space for closing \0.

---
   target/s390x/kvm.c         | 2 +-
   target/s390x/misc_helper.c | 4 +++-
   2 files changed, 4 insertions(+), 2 deletions(-)
Quoted 16 lines
Quoted 13 lines
target/s390x/kvm.c +1 -1
index b8385e6b95..2313b5727e 100644
@@ -1918,7 +1918,7 @@ static void insert_stsi_3_2_2(S390CPU *cpu, __u64
 addr, uint8_t ar)
        */
       if (qemu_name) {
           strncpy((char *)sysib.ext_names[0], qemu_name,
-                sizeof(sysib.ext_names[0]));
+                sizeof(sysib.ext_names[0]) - 1);
       } else {
           strcpy((char *)sysib.ext_names[0], "KVMguest");
Quoted 1 line
       }

What about using strpadcpy() instead?

Quoted 2 lines

Yes, strpadcpy is the better way here - this field has to be padded with zeroes, so doing "- 1" is wrong here.

Hi Thomas,

Quoted 7 lines
Quoted 4 lines

as I wrote in reply to Phillipe - the array is memset to zeroes before the if so we
are sure it's padded with zeroes (in this occurrence, not true for second one).

Ok, but dropping the last character is still wrong here. The ext_names do not need to be terminated with a \0 if they have the full length.

Oh, they do not have to end with \0??? I did not know it. In that case we probably have to use strpadcpy to get rid of the compiler warning.

Mirek

Quoted 3 lines

Thomas

Signature · 2 lines
Miroslav Rezanina
Software Engineer - Virtualization Team Maintainer
#8 lore raw

Re: [RHEL7 qemu-kvm PATCH 2/3] s390x: Fix vm name copy length

In reply to Thomas Huth
Quoted 47 lines · Thomas Huth
Quoted 46 lines · Miroslav Rezanina

----- Original Message -----

Quoted 42 lines

From: "Thomas Huth" <[email protected]>
To: "Philippe Mathieu-Daudé" <[email protected]>, [email protected], [email protected], "qemu-s390x" <[email protected]>
Sent: Monday, January 11, 2021 1:24:57 PM
Subject: Re: [RHEL7 qemu-kvm PATCH 2/3] s390x: Fix vm name copy length

Quoted 16 lines · Philippe Mathieu-Daudé

Hi Miroslav,

Quoted 13 lines · On 1/11/21 12:30 PM, [email protected] wrote:

From: Miroslav Rezanina <[email protected]>

There are two cases when vm name is copied but closing \0 can be lost in case name is too long (>=256 characters).

Updating length to copy so there is space for closing \0.

---
   target/s390x/kvm.c         | 2 +-
   target/s390x/misc_helper.c | 4 +++-

   2 files changed, 4 insertions(+), 2 deletions(-)
Quoted 16 lines
Quoted 13 lines
target/s390x/kvm.c +1 -1
index b8385e6b95..2313b5727e 100644
@@ -1918,7 +1918,7 @@ static void insert_stsi_3_2_2(S390CPU *cpu, __u64
 addr, uint8_t ar)
         */
        if (qemu_name) {
            strncpy((char *)sysib.ext_names[0], qemu_name,
-                sizeof(sysib.ext_names[0]));
+                sizeof(sysib.ext_names[0]) - 1);
        } else {
            strcpy((char *)sysib.ext_names[0], "KVMguest");
Quoted 1 line

       }

What about using strpadcpy() instead?

Yes, strpadcpy is the better way here - this field has to be padded with zeroes, so doing "- 1" is wrong here.

Quoted 6 lines
Quoted 4 lines

Hi Thomas,

as I wrote in reply to Phillipe - the array is memset to zeroes before the if so we are sure it's padded with zeroes (in this occurrence, not true for second one).

Ok, but dropping the last character is still wrong here. The ext_names do not need to be terminated with a \0 if they have the full length.

The current code is actually correct. We are perfectly fine without the final \n if the string is really 256 bytes.

Replacing memset + strncpy with strpadcpy is certainly a good cleanup. Is it necessary? No.

#9 lore raw

Re: [RHEL7 qemu-kvm PATCH 2/3] s390x: Fix vm name copy length

Quoted 52 lines · Christian Borntraeger
Quoted 49 lines · Thomas Huth
Quoted 48 lines · Miroslav Rezanina

----- Original Message -----

Quoted 40 lines

From: "Thomas Huth" <[email protected]>
To: "Philippe Mathieu-Daudé" <[email protected]>, [email protected], [email protected], "qemu-s390x" <[email protected]>
Sent: Monday, January 11, 2021 1:24:57 PM
Subject: Re: [RHEL7 qemu-kvm PATCH 2/3] s390x: Fix vm name copy length

Quoted 16 lines · Philippe Mathieu-Daudé

Hi Miroslav,

Quoted 13 lines · On 1/11/21 12:30 PM, [email protected] wrote:

From: Miroslav Rezanina <[email protected]>

There are two cases when vm name is copied but closing \0 can be lost in case name is too long (>=256 characters).

Updating length to copy so there is space for closing \0.

---
   target/s390x/kvm.c         | 2 +-
   target/s390x/misc_helper.c | 4 +++-

   2 files changed, 4 insertions(+), 2 deletions(-)
Quoted 16 lines
Quoted 13 lines
target/s390x/kvm.c +1 -1
index b8385e6b95..2313b5727e 100644
@@ -1918,7 +1918,7 @@ static void insert_stsi_3_2_2(S390CPU *cpu, __u64
 addr, uint8_t ar)
         */
        if (qemu_name) {
            strncpy((char *)sysib.ext_names[0], qemu_name,
-                sizeof(sysib.ext_names[0]));
+                sizeof(sysib.ext_names[0]) - 1);
        } else {
            strcpy((char *)sysib.ext_names[0], "KVMguest");
Quoted 1 line

       }

What about using strpadcpy() instead?

Quoted 2 lines

Yes, strpadcpy is the better way here - this field has to be padded with zeroes, so doing "- 1" is wrong here.

Hi Thomas,

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

as I wrote in reply to Phillipe - the array is memset to zeroes before the if so we are sure it's padded with zeroes (in this occurrence, not true for second one).

Ok, but dropping the last character is still wrong here. The ext_names do not need to be terminated with a \0 if they have the full length.

The current code is actually correct. We are perfectly fine without the final \n if the string is really 256 bytes.

Replacing memset + strncpy with strpadcpy is certainly a good cleanup. Is it necessary? No.

And yes, Thomas is right. The -1 is wrong.

#10 lore raw

Re: [RHEL7 qemu-kvm PATCH 2/3] s390x: Fix vm name copy length

In reply to Christian Borntraeger

----- Original Message -----

Quoted 64 lines

From: "Christian Borntraeger" <[email protected]>
To: "Thomas Huth" <[email protected]>, "Miroslav Rezanina" <[email protected]>
Cc: "qemu-s390x" <[email protected]>, "Philippe Mathieu-Daudé" <[email protected]>, [email protected]
Sent: Monday, January 11, 2021 2:02:32 PM
Subject: Re: [RHEL7 qemu-kvm PATCH 2/3] s390x: Fix vm name copy length

Quoted 55 lines · Thomas Huth
Quoted 53 lines · Miroslav Rezanina

----- Original Message -----

Quoted 41 lines

From: "Thomas Huth" <[email protected]>
To: "Philippe Mathieu-Daudé" <[email protected]>, [email protected], [email protected], "qemu-s390x"
<[email protected]>
Sent: Monday, January 11, 2021 1:24:57 PM
Subject: Re: [RHEL7 qemu-kvm PATCH 2/3] s390x: Fix vm name copy length

Quoted 16 lines · Philippe Mathieu-Daudé

Hi Miroslav,

Quoted 13 lines · On 1/11/21 12:30 PM, [email protected] wrote:

From: Miroslav Rezanina <[email protected]>

There are two cases when vm name is copied but closing \0 can be lost in case name is too long (>=256 characters).

Updating length to copy so there is space for closing \0.

---
   target/s390x/kvm.c         | 2 +-
   target/s390x/misc_helper.c | 4 +++-

   2 files changed, 4 insertions(+), 2 deletions(-)
Quoted 16 lines
Quoted 13 lines
target/s390x/kvm.c +1 -1
index b8385e6b95..2313b5727e 100644
@@ -1918,7 +1918,7 @@ static void insert_stsi_3_2_2(S390CPU *cpu, __u64
 addr, uint8_t ar)
         */
        if (qemu_name) {
            strncpy((char *)sysib.ext_names[0], qemu_name,
-                sizeof(sysib.ext_names[0]));
+                sizeof(sysib.ext_names[0]) - 1);
        } else {
            strcpy((char *)sysib.ext_names[0], "KVMguest");
Quoted 1 line

       }

What about using strpadcpy() instead?

Quoted 2 lines

Yes, strpadcpy is the better way here - this field has to be padded with zeroes, so doing "- 1" is wrong here.

Hi Thomas,

as I wrote in reply to Phillipe - the array is memset to zeroes before the if so we
are sure it's padded with zeroes (in this occurrence, not true for second one).

Quoted 7 lines
Quoted 2 lines

Ok, but dropping the last character is still wrong here. The ext_names do not need to be terminated with a \0 if they have the full length.

The current code is actually correct. We are perfectly fine without the final \n if the string is really 256 bytes.

Replacing memset + strncpy with strpadcpy is certainly a good cleanup. Is it necessary? No.

Yes, it is necessary because otherwise compiler (GCC 11) produce warning and so build fail when --enable-werror is used.

Mirek

Quoted 2 lines
Signature · 2 lines
Miroslav Rezanina
Software Engineer - Virtualization Team Maintainer
#11 lore raw

Re: [RHEL7 qemu-kvm PATCH 2/3] s390x: Fix vm name copy length

Quoted 69 lines · Miroslav Rezanina

----- Original Message -----

Quoted 66 lines

From: "Christian Borntraeger" <[email protected]>
To: "Thomas Huth" <[email protected]>, "Miroslav Rezanina" <[email protected]>
Cc: "qemu-s390x" <[email protected]>, "Philippe Mathieu-Daudé" <[email protected]>, [email protected]
Sent: Monday, January 11, 2021 2:02:32 PM
Subject: Re: [RHEL7 qemu-kvm PATCH 2/3] s390x: Fix vm name copy length

Quoted 57 lines · Thomas Huth
Quoted 47 lines · Miroslav Rezanina

----- Original Message -----

Quoted 41 lines

From: "Thomas Huth" <[email protected]>
To: "Philippe Mathieu-Daudé" <[email protected]>, [email protected], [email protected], "qemu-s390x"
<[email protected]>
Sent: Monday, January 11, 2021 1:24:57 PM
Subject: Re: [RHEL7 qemu-kvm PATCH 2/3] s390x: Fix vm name copy length

Quoted 16 lines · Philippe Mathieu-Daudé

Hi Miroslav,

Quoted 13 lines · On 1/11/21 12:30 PM, [email protected] wrote:

From: Miroslav Rezanina <[email protected]>

There are two cases when vm name is copied but closing \0 can be lost in case name is too long (>=256 characters).

Updating length to copy so there is space for closing \0.

---
   target/s390x/kvm.c         | 2 +-
   target/s390x/misc_helper.c | 4 +++-

   2 files changed, 4 insertions(+), 2 deletions(-)
Quoted 16 lines
Quoted 13 lines
target/s390x/kvm.c +1 -1
index b8385e6b95..2313b5727e 100644
@@ -1918,7 +1918,7 @@ static void insert_stsi_3_2_2(S390CPU *cpu, __u64
 addr, uint8_t ar)
         */
        if (qemu_name) {
            strncpy((char *)sysib.ext_names[0], qemu_name,
-                sizeof(sysib.ext_names[0]));
+                sizeof(sysib.ext_names[0]) - 1);
        } else {
            strcpy((char *)sysib.ext_names[0], "KVMguest");
Quoted 1 line

       }

What about using strpadcpy() instead?

Quoted 2 lines

Yes, strpadcpy is the better way here - this field has to be padded with zeroes, so doing "- 1" is wrong here.

Quoted 6 lines

Hi Thomas,

as I wrote in reply to Phillipe - the array is memset to zeroes before the if so we
are sure it's padded with zeroes (in this occurrence, not true for second one).

Ok, but dropping the last character is still wrong here. The ext_names do not need to be terminated with a \0 if they have the full length.

Quoted 8 lines
Quoted 5 lines

The current code is actually correct. We are perfectly fine without the final \n if the string is really 256 bytes.

Replacing memset + strncpy with strpadcpy is certainly a good cleanup. Is it necessary? No.

Yes, it is necessary because otherwise compiler (GCC 11) produce warning and so build fail when --enable-werror is used.

Fair enough. But that actually means that the compiler warning is wrong, because we use strncpy exactly in the way as described (allowing for the final \n to be missing). But let us use strpadcpy then.

#12 lore raw

Re: [RHEL7 qemu-kvm PATCH 2/3] s390x: Fix vm name copy length

In reply to Philippe Mathieu-Daudé

----- Original Message -----

Quoted 38 lines

From: "Philippe Mathieu-Daudé" <[email protected]>
To: [email protected], [email protected]
Sent: Monday, January 11, 2021 1:10:07 PM
Subject: Re: [RHEL7 qemu-kvm PATCH 2/3] s390x: Fix vm name copy length

Hi Miroslav,

Quoted 26 lines · On 1/11/21 12:30 PM, [email protected] wrote:

From: Miroslav Rezanina <[email protected]>

There are two cases when vm name is copied but closing \0 can be lost in case name is too long (>=256 characters).

Updating length to copy so there is space for closing \0.

---
 target/s390x/kvm.c         | 2 +-
 target/s390x/misc_helper.c | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)
target/s390x/kvm.c +1 -1
index b8385e6b95..2313b5727e 100644
@@ -1918,7 +1918,7 @@ static void insert_stsi_3_2_2(S390CPU *cpu, __u64
 addr, uint8_t ar)
      */
     if (qemu_name) {
         strncpy((char *)sysib.ext_names[0], qemu_name,
-                sizeof(sysib.ext_names[0]));
+                sizeof(sysib.ext_names[0]) - 1);
     } else {
         strcpy((char *)sysib.ext_names[0], "KVMguest");
Quoted 1 line
     }

What about using strpadcpy() instead?

Quoted 3 lines
    strpadcpy((char *)sysib.sysib_322.ext_names[0],
              sizeof(sysib.sysib_322.ext_names[0]),
              qemu_name ?: "KVMguest", '\0');

Hi Philippe,

I went with -1 here because code use memset to 0 few lines above this code, so we now there are only zeroes in the array and we do not have to write them again.

Quoted 18 lines
Quoted 6 lines
target/s390x/misc_helper.c +0 -0
index 58dbc023eb..7c478b9e58 100644

target/s390x/misc_helper.c uint32_t HELPER(stsi)(CPUS390XState *env, uint64_t a0, · line 376

Quoted 9 lines
target/s390x/misc_helper.c +3 -1
@@ -369,8 +369,10 @@ uint32_t HELPER(stsi)(CPUS390XState *env, uint64_t a0,
 uint64_t r0, uint64_t r1)
                 ebcdic_put(sysib.sysib_322.vm[0].name, qemu_name,
                            MIN(sizeof(sysib.sysib_322.vm[0].name),
                                strlen(qemu_name)));
+		memset((char *)sysib.sysib_322.ext_names[0], 0,
+		       sizeof(sysib.sysib_322.ext_names[0]));
                 strncpy((char *)sysib.sysib_322.ext_names[0], qemu_name,
-                        sizeof(sysib.sysib_322.ext_names[0]));
+                        sizeof(sysib.sysib_322.ext_names[0]) - 1);

And here:

Quoted 3 lines
               strpadcpy((char *)sysib.sysib_322.ext_names[0],
                         sizeof(sysib.sysib_322.ext_names[0]),
                         qemu_name, '\0');

However, here we are adding memset so using strpadcpy is better choice to ensure we have \0 after name string.

Mirek

Quoted 7 lines
Quoted 5 lines
target/s390x/misc_helper.c +0 -0
             } else {
                 ebcdic_put(sysib.sysib_322.vm[0].name, "TCGguest", 8);
                 strcpy((char *)sysib.sysib_322.ext_names[0], "TCGguest");
Signature · 2 lines
Miroslav Rezanina
Software Engineer - Virtualization Team Maintainer
#13 lore raw

PATCH 3/3 Fix tcg_out_op argument mismatch warning

In reply to [email protected]

From: Miroslav Rezanina <[email protected]>

There's prototype mismatch between tcg/tcg.c and tcg/aarch/tcg-target.c.inc:

tcg.c:

static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args,
const int *const_args);

tcg-target.c.inc:

static void tcg_out_op(TCGContext *s, TCGOpcode opc,
const TCGArg args[TCG_MAX_OP_ARGS], const int const_args[TCG_MAX_OP_ARGS])

This missmatch cause warnings on GCC 11:

tcg/aarch64/tcg-target.c.inc:1855:37: error: argument 3 of type 'const TCGArg[16]' {aka 'const long unsigned int[16]'} with mismatched bound [-Werror=array-parameter=] tcg/aarch64/tcg-target.c.inc:1856:34: error: argument 4 of type 'const int[16]' with mismatched bound [-Werror=array-parameter=]

Only architectures with this definition are aarch and sparc. Fixing both archs to use proper argument type.

---
 tcg/aarch64/tcg-target.c.inc | 3 +--
 tcg/sparc/tcg-target.c.inc   | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
tcg/aarch64/tcg-target.c.inc +1 -2
index 26f71cb599..fe6bdbf721 100644
@@ -1852,8 +1852,7 @@ static void tcg_out_qemu_st(TCGContext *s, TCGReg data_reg, TCGReg addr_reg,
 static tcg_insn_unit *tb_ret_addr;
 
 static void tcg_out_op(TCGContext *s, TCGOpcode opc,
-                       const TCGArg args[TCG_MAX_OP_ARGS],
-                       const int const_args[TCG_MAX_OP_ARGS])
+                       const TCGArg *args, const int *const_args)
 {
     /* 99% of the time, we can signal the use of extension registers
        by looking to see if the opcode handles 64-bit data.  */
tcg/sparc/tcg-target.c.inc +1 -2
index 6775bd30fc..976f0f05af 100644
@@ -1294,8 +1294,7 @@ static void tcg_out_qemu_st(TCGContext *s, TCGReg data, TCGReg addr,
 }
 
 static void tcg_out_op(TCGContext *s, TCGOpcode opc,
-                       const TCGArg args[TCG_MAX_OP_ARGS],
-                       const int const_args[TCG_MAX_OP_ARGS])
+                       const TCGArg *args, const int *const_args)
 {
     TCGArg a0, a1, a2;
     int c, c2;
Signature · 1 line
2.18.4
#14 lore raw

Re: [RHEL7 qemu-kvm PATCH 3/3] Fix tcg_out_op argument mismatch warning

Quoted 11 lines · On 1/11/21 12:30 PM, [email protected] wrote:

From: Miroslav Rezanina <[email protected]>

There's prototype mismatch between tcg/tcg.c and tcg/aarch/tcg-target.c.inc:

tcg.c:

static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args,
const int *const_args);

tcg-target.c.inc:

Quoted 8 lines

static void tcg_out_op(TCGContext *s, TCGOpcode opc,
const TCGArg args[TCG_MAX_OP_ARGS], const int const_args[TCG_MAX_OP_ARGS])

This missmatch cause warnings on GCC 11:

tcg/aarch64/tcg-target.c.inc:1855:37: error: argument 3 of type 'const TCGArg[16]' {aka 'const long unsigned int[16]'} with mismatched bound [-Werror=array-parameter=] tcg/aarch64/tcg-target.c.inc:1856:34: error: argument 4 of type 'const int[16]' with mismatched bound [-Werror=array-parameter=]

TIL. Interesting, compilers are getting smarter :)

Quoted 12 lines

Only architectures with this definition are aarch and sparc. Fixing both archs to use proper argument type.

---
 tcg/aarch64/tcg-target.c.inc | 3 +--
 tcg/sparc/tcg-target.c.inc   | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
tcg/aarch64/tcg-target.c.inc +0 -0
index 26f71cb599..fe6bdbf721 100644

tcg/aarch64/tcg-target.c.inc static void tcg_out_qemu_st(TCGContext *s, TCGReg data_reg, TCGReg addr_reg, · line 1855

Quoted 6 lines
tcg/aarch64/tcg-target.c.inc +1 -2
@@ -1852,8 +1852,7 @@ static void tcg_out_qemu_st(TCGContext *s, TCGReg data_reg, TCGReg addr_reg,
 static tcg_insn_unit *tb_ret_addr;
 
 static void tcg_out_op(TCGContext *s, TCGOpcode opc,
-                       const TCGArg args[TCG_MAX_OP_ARGS],
-                       const int const_args[TCG_MAX_OP_ARGS])
+                       const TCGArg *args, const int *const_args)

Doing this way we loose information (that the array pointed has TCG_MAX_OP_ARGS elements). What about letting this prototype and fix the other uses?

Quoted 18 lines
tcg/aarch64/tcg-target.c.inc +0 -0
 {
     /* 99% of the time, we can signal the use of extension registers
        by looking to see if the opcode handles 64-bit data.  */
tcg/sparc/tcg-target.c.inc +1 -2
index 6775bd30fc..976f0f05af 100644
@@ -1294,8 +1294,7 @@ static void tcg_out_qemu_st(TCGContext *s, TCGReg data, TCGReg addr,
 }
 
 static void tcg_out_op(TCGContext *s, TCGOpcode opc,
-                       const TCGArg args[TCG_MAX_OP_ARGS],
-                       const int const_args[TCG_MAX_OP_ARGS])
+                       const TCGArg *args, const int *const_args)
 {
     TCGArg a0, a1, a2;
     int c, c2;
#15 lore raw

Re: [RHEL7 qemu-kvm PATCH 3/3] Fix tcg_out_op argument mismatch warning

----- Original Message -----

Quoted 50 lines

From: "Philippe Mathieu-Daudé" <[email protected]>
To: [email protected], [email protected]
Cc: "Richard Henderson" <[email protected]>, "Eric Blake" <[email protected]>
Sent: Monday, January 11, 2021 1:15:04 PM
Subject: Re: [RHEL7 qemu-kvm PATCH 3/3] Fix tcg_out_op argument mismatch warning

Quoted 17 lines · On 1/11/21 12:30 PM, [email protected] wrote:

From: Miroslav Rezanina <[email protected]>

There's prototype mismatch between tcg/tcg.c and
tcg/aarch/tcg-target.c.inc:

tcg.c:

    static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg
    *args,
                           const int *const_args);

tcg-target.c.inc:

static void tcg_out_op(TCGContext *s, TCGOpcode opc,
const TCGArg args[TCG_MAX_OP_ARGS], const int const_args[TCG_MAX_OP_ARGS])

Quoted 7 lines

This missmatch cause warnings on GCC 11:

tcg/aarch64/tcg-target.c.inc:1855:37: error: argument 3 of type 'const TCGArg[16]' {aka 'const long unsigned int[16]'} with mismatched bound [-Werror=array-parameter=] tcg/aarch64/tcg-target.c.inc:1856:34: error: argument 4 of type 'const int[16]' with mismatched bound [-Werror=array-parameter=]

TIL. Interesting, compilers are getting smarter :)

Quoted 16 lines

Only architectures with this definition are aarch and sparc. Fixing both archs to use
proper argument type.

---
 tcg/aarch64/tcg-target.c.inc | 3 +--
 tcg/sparc/tcg-target.c.inc   | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
tcg/aarch64/tcg-target.c.inc +0 -0
index 26f71cb599..fe6bdbf721 100644
@@ -1852,8 +1852,7 @@ static void tcg_out_qemu_st(TCGContext *s, TCGReg
 data_reg, TCGReg addr_reg,
 static tcg_insn_unit *tb_ret_addr;
 
Quoted 8 lines

tcg/aarch64/tcg-target.c.inc static void tcg_out_qemu_st(TCGContext *s, TCGReg data_reg, TCGReg addr_reg, · line 1855

Quoted 4 lines
tcg/aarch64/tcg-target.c.inc +1 -2
 static void tcg_out_op(TCGContext *s, TCGOpcode opc,
-                       const TCGArg args[TCG_MAX_OP_ARGS],
-                       const int const_args[TCG_MAX_OP_ARGS])
+                       const TCGArg *args, const int *const_args)

Doing this way we loose information (that the array pointed has TCG_MAX_OP_ARGS elements). What about letting this prototype and fix the other uses?

I'm not author of the code so I went with smaller change - forward definition in tcg.c and most tct-target.c.inc use this form. I would need someone more familiar with this part to clarify whether it's ok to go with opposite change.

Mirek

Quoted 22 lines
Quoted 20 lines
tcg/aarch64/tcg-target.c.inc +0 -0
 {
     /* 99% of the time, we can signal the use of extension registers

by looking to see if the opcode handles 64-bit data. */

tcg/sparc/tcg-target.c.inc +1 -2
index 6775bd30fc..976f0f05af 100644
@@ -1294,8 +1294,7 @@ static void tcg_out_qemu_st(TCGContext *s, TCGReg
 data, TCGReg addr,
 }
 
 static void tcg_out_op(TCGContext *s, TCGOpcode opc,
-                       const TCGArg args[TCG_MAX_OP_ARGS],
-                       const int const_args[TCG_MAX_OP_ARGS])
+                       const TCGArg *args, const int *const_args)
 {
     TCGArg a0, a1, a2;
     int c, c2;
Signature · 2 lines
Miroslav Rezanina
Software Engineer - Virtualization Team Maintainer
#16 lore raw
In reply to [email protected]
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [RHEL7 qemu-kvm PATCH 0/3] Fixing several GCC 11 warnings

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
c05a0c4 Fix tcg_out_op argument mismatch warning
a8b8ace s390x: Fix vm name copy length
b64e754 Fix net.c warning on GCC 11

=== OUTPUT BEGIN ===
1/3 Checking commit b64e754d193f (Fix net.c warning on GCC 11) 2/3 Checking commit a8b8ace484f8 (s390x: Fix vm name copy length)
ERROR: trailing whitespace
#36: FILE: target/s390x/misc_helper.c:372:
+^I^Imemset((char *)sysib.sysib_322.ext_names[0], 0, $

ERROR: code indent should never use tabs
#36: FILE: target/s390x/misc_helper.c:372:
+^I^Imemset((char *)sysib.sysib_322.ext_names[0], 0, $

ERROR: code indent should never use tabs
#37: FILE: target/s390x/misc_helper.c:373:
+^I^I sizeof(sysib.sysib_322.ext_names[0]));$

total: 3 errors, 0 warnings, 19 lines checked

Patch 2/3 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

3/3 Checking commit c05a0c4ed447 (Fix tcg_out_op argument mismatch warning)
ERROR: Missing Signed-off-by: line(s)

total: 1 errors, 0 warnings, 18 lines checked

Patch 3/3 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]