Skip to contentSkip to conversation

hw/i386/amd_iommu: Fix maybe-uninitialized error with GCC 12

RFC In review Philippe Mathieu-Daudé 2 participants 3 messages Mar 18, 2022 – Mar 22, 2022

lore
Share & tools
lore
#0 lore raw

RFC 1/1 hw/i386/amd_iommu: Fix maybe-uninitialized error with GCC 12

From: Philippe Mathieu-Daudé <[email protected]>

Initialize 'oldlevel' early to avoid on Debian/sid:

FAILED: libqemu-x86_64-softmmu.fa.p/hw_i386_amd_iommu.c.o In function 'pte_get_page_mask',

      inlined from 'amdvi_page_walk' at hw/i386/amd_iommu.c:945:25,
      inlined from 'amdvi_do_translate' at hw/i386/amd_iommu.c:989:5,
      inlined from 'amdvi_translate' at hw/i386/amd_iommu.c:1038:5:
  hw/i386/amd_iommu.c:877:38: error: 'oldlevel' may be used uninitialized [-Werror=maybe-uninitialized]
    877 |     return ~((1UL << ((oldlevel * 9) + 3)) - 1);
        |                      ~~~~~~~~~~~~~~~~^~~~
  hw/i386/amd_iommu.c: In function 'amdvi_translate':
  hw/i386/amd_iommu.c:906:41: note: 'oldlevel' was declared here
    906 |     unsigned level, present, pte_perms, oldlevel;
        |                                         ^~~~~~~~

cc1: all warnings being treated as errors

Having:

  $ gcc --version
  gcc (Debian 12-20220313-1) 12.0.1 20220314 (experimental)
---
 hw/i386/amd_iommu.c | 1 +
 1 file changed, 1 insertion(+)
hw/i386/amd_iommu.c +1 -0
index 4d13d8e697..b6d299f964 100644
@@ -904,6 +904,7 @@ static void amdvi_page_walk(AMDVIAddressSpace *as, uint64_t *dte,
     /* make sure the DTE has TV = 1 */
     if (pte & AMDVI_DEV_TRANSLATION_VALID) {
         level = get_pte_translation_mode(pte);
+        oldlevel = level;
         if (level >= 7) {
             trace_amdvi_mode_invalid(level, addr);
             return;
Signature · 1 line
2.35.1
#1 lore raw

+qemu-trivial@

Quoted 40 lines · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Initialize 'oldlevel' early to avoid on Debian/sid:

   FAILED: libqemu-x86_64-softmmu.fa.p/hw_i386_amd_iommu.c.o
   In function 'pte_get_page_mask',
       inlined from 'amdvi_page_walk' at hw/i386/amd_iommu.c:945:25,
       inlined from 'amdvi_do_translate' at hw/i386/amd_iommu.c:989:5,
       inlined from 'amdvi_translate' at hw/i386/amd_iommu.c:1038:5:
   hw/i386/amd_iommu.c:877:38: error: 'oldlevel' may be used uninitialized [-Werror=maybe-uninitialized]
     877 |     return ~((1UL << ((oldlevel * 9) + 3)) - 1);
         |                      ~~~~~~~~~~~~~~~~^~~~
   hw/i386/amd_iommu.c: In function 'amdvi_translate':
   hw/i386/amd_iommu.c:906:41: note: 'oldlevel' was declared here
     906 |     unsigned level, present, pte_perms, oldlevel;
         |                                         ^~~~~~~~
   cc1: all warnings being treated as errors

Having:

   $ gcc --version
   gcc (Debian 12-20220313-1) 12.0.1 20220314 (experimental)
---
  hw/i386/amd_iommu.c | 1 +
  1 file changed, 1 insertion(+)
hw/i386/amd_iommu.c +1 -0
index 4d13d8e697..b6d299f964 100644
@@ -904,6 +904,7 @@ static void amdvi_page_walk(AMDVIAddressSpace *as, uint64_t *dte,
      /* make sure the DTE has TV = 1 */
      if (pte & AMDVI_DEV_TRANSLATION_VALID) {
          level = get_pte_translation_mode(pte);
+        oldlevel = level;
          if (level >= 7) {
              trace_amdvi_mode_invalid(level, addr);
              return;
#2 lore raw
Quoted 1 line · Philippe Mathieu-Daudé

+qemu-trivial@

Laurent,

please do not merge this patch as I've sent a replacement and I'll take care of merging it.

Paolo

Quoted 44 lines · Philippe Mathieu-Daudé
Quoted 41 lines

From: Philippe Mathieu-Daudé <[email protected]>

Initialize 'oldlevel' early to avoid on Debian/sid:

   FAILED: libqemu-x86_64-softmmu.fa.p/hw_i386_amd_iommu.c.o
   In function 'pte_get_page_mask',
       inlined from 'amdvi_page_walk' at hw/i386/amd_iommu.c:945:25,
       inlined from 'amdvi_do_translate' at hw/i386/amd_iommu.c:989:5,
       inlined from 'amdvi_translate' at hw/i386/amd_iommu.c:1038:5:
   hw/i386/amd_iommu.c:877:38: error: 'oldlevel' may be used uninitialized [-Werror=maybe-uninitialized] 877 |     return ~((1UL << ((oldlevel * 9) + 3)) - 1);
         |                      ~~~~~~~~~~~~~~~~^~~~
   hw/i386/amd_iommu.c: In function 'amdvi_translate':
   hw/i386/amd_iommu.c:906:41: note: 'oldlevel' was declared here
     906 |     unsigned level, present, pte_perms, oldlevel;
         |                                         ^~~~~~~~
   cc1: all warnings being treated as errors

Having:

   $ gcc --version
   gcc (Debian 12-20220313-1) 12.0.1 20220314 (experimental)

---
  hw/i386/amd_iommu.c | 1 +

  1 file changed, 1 insertion(+)
hw/i386/amd_iommu.c +1 -0
index 4d13d8e697..b6d299f964 100644
@@ -904,6 +904,7 @@ static void amdvi_page_walk(AMDVIAddressSpace *as, 
 uint64_t *dte,
       /* make sure the DTE has TV = 1 */
       if (pte & AMDVI_DEV_TRANSLATION_VALID) {
           level = get_pte_translation_mode(pte);
+        oldlevel = level;
           if (level >= 7) {
               trace_amdvi_mode_invalid(level, addr);

              return;