Skip to contentSkip to conversation

libxc/arm: initialise p2m_size to make gcc happy

PATCH In review Wei Liu 4 participants 7 messages Mar 14, 2018 – Mar 22, 2018

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

PATCH 1/1 libxc/arm: initialise p2m_size to make gcc happy

Gcc with -O3 failed to spot the loop to initialise p2m_size runs at least once.

---
 tools/libxc/xc_dom_arm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/libxc/xc_dom_arm.c +2 -1
index 5b9eca6087..97d08f055a 100644
@@ -395,7 +395,7 @@ static int meminit(struct xc_dom_image *dom)
     const uint64_t modsize = dtb_size + ramdisk_size;
     const uint64_t ram128mb = bankbase[0] + (128<<20);
 
-    xen_pfn_t p2m_size;
+    xen_pfn_t p2m_size = 0; /* make gcc -O3 happy */
     uint64_t bank0end;
 
     assert(dom->rambase_pfn << XC_PAGE_SHIFT == bankbase[0]);
@@ -438,6 +438,7 @@ static int meminit(struct xc_dom_image *dom)
 
     assert(dom->rambank_size[0] != 0);
     assert(ramsize == 0); /* Too much RAM is rejected above */
+    assert(p2m_size != 0);
 
     dom->p2m_size = p2m_size;
     dom->p2m_host = xc_dom_malloc(dom, sizeof(xen_pfn_t) * p2m_size);
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 2 lines · Wei Liu

Gcc with -O3 failed to spot the loop to initialise p2m_size runs at least once.

It is -Og in this case, rather than -O3.  My -O3 comment on the thread was for the more generic cases.

~Andrew

Quoted 20 lines
---
 tools/libxc/xc_dom_arm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/libxc/xc_dom_arm.c +1 -1
index 5b9eca6087..97d08f055a 100644
@@ -395,7 +395,7 @@ static int meminit(struct xc_dom_image *dom)
     const uint64_t modsize = dtb_size + ramdisk_size;
     const uint64_t ram128mb = bankbase[0] + (128<<20);
 
-    xen_pfn_t p2m_size;
+    xen_pfn_t p2m_size = 0; /* make gcc -O3 happy */
     uint64_t bank0end;
 
     assert(dom->rambase_pfn << XC_PAGE_SHIFT == bankbase[0]);

tools/libxc/xc_dom_arm.c static int meminit(struct xc_dom_image *dom) · line 444

Quoted 7 lines
tools/libxc/xc_dom_arm.c +1 -0
@@ -438,6 +438,7 @@ static int meminit(struct xc_dom_image *dom)
 
     assert(dom->rambank_size[0] != 0);
     assert(ramsize == 0); /* Too much RAM is rejected above */
+    assert(p2m_size != 0);
 
     dom->p2m_size = p2m_size;
     dom->p2m_host = xc_dom_malloc(dom, sizeof(xen_pfn_t) * p2m_size);

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#2 lore raw
Quoted 6 lines · Andrew Cooper
Quoted 2 lines · Wei Liu

Gcc with -O3 failed to spot the loop to initialise p2m_size runs at least once.

It is -Og in this case, rather than -O3.  My -O3 comment on the thread was for the more generic cases.

OK. I will fix the commit message and code comment.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw
In reply to Wei Liu

Hi,

Quoted 2 lines · Wei Liu

Gcc with -O3 failed to spot the loop to initialise p2m_size runs at least once.

Aside, Andrew's comment the patch looks okay. But I am wondering why we need to allocate p2m_host for Arm?

From a quick look I have seen no real user except xc_dom_update_guest_p2m that can cope with p2m_host = NULL.

Cheers,

Quoted 28 lines
---
  tools/libxc/xc_dom_arm.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
tools/libxc/xc_dom_arm.c +2 -1
index 5b9eca6087..97d08f055a 100644
@@ -395,7 +395,7 @@ static int meminit(struct xc_dom_image *dom)
      const uint64_t modsize = dtb_size + ramdisk_size;
      const uint64_t ram128mb = bankbase[0] + (128<<20);
 
-    xen_pfn_t p2m_size;
+    xen_pfn_t p2m_size = 0; /* make gcc -O3 happy */
      uint64_t bank0end;
 
      assert(dom->rambase_pfn << XC_PAGE_SHIFT == bankbase[0]);
@@ -438,6 +438,7 @@ static int meminit(struct xc_dom_image *dom)
 
      assert(dom->rambank_size[0] != 0);
      assert(ramsize == 0); /* Too much RAM is rejected above */
+    assert(p2m_size != 0);
 
      dom->p2m_size = p2m_size;
      dom->p2m_host = xc_dom_malloc(dom, sizeof(xen_pfn_t) * p2m_size);
Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#3 lore raw
In reply to Andrew Cooper
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 14.03.18 at 13:35, <[email protected]> wrote:
Quoted 2 lines · Wei Liu

Gcc with -O3 failed to spot the loop to initialise p2m_size runs at least once.

It is -Og in this case, rather than -O3. My -O3 comment on the thread was for the more generic cases.

Yeah, it is likely the fact that gcc does _less_ optimization with -Og that makes it no longer spot that the variable can't be used uninitialized.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#5 lore raw
In reply to Julien Grall
Quoted 9 lines · Julien Grall

Hi,

Quoted 2 lines · Wei Liu

Gcc with -O3 failed to spot the loop to initialise p2m_size runs at least once.

Aside, Andrew's comment the patch looks okay. But I am wondering why we need to allocate p2m_host for Arm?

Not sure, really. :-)

Quoted 3 lines

From a quick look I have seen no real user except xc_dom_update_guest_p2m that can cope with p2m_host = NULL.

Maybe it is to work around this limitation in code.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#6 lore raw

Hi,

Quoted 11 lines · Wei Liu
Quoted 9 lines · Julien Grall

Hi,

Quoted 2 lines · Wei Liu

Gcc with -O3 failed to spot the loop to initialise p2m_size runs at least once.

Aside, Andrew's comment the patch looks okay. But I am wondering why we need to allocate p2m_host for Arm?

Quoted 7 lines

Not sure, really. :-)

Quoted 3 lines

From a quick look I have seen no real user except xc_dom_update_guest_p2m
that can cope with p2m_host = NULL.

Maybe it is to work around this limitation in code.

I will have a look at it. Meanwhile, I guess it is better to make GCC happy with that patch.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel