Skip to contentSkip to conversation

tools/libxc: Correct XC_DOM_PAGE_SIZE() to return a long long

PATCH Applied Andrew Cooper 3 participants 5 messages Nov 19, 2015 – Nov 20, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/libxc: Correct XC_DOM_PAGE_SIZE() to return a long long

c/s abdf3c5b "libxc: create p2m list outside of kernel mapping if supported" introduces a use which Coverity objects to; an int used to mask a uint64_t.

The result needs to be signed to allow ~XC_DOM_PAGE_SIZE() to function correctly, and long long to function properly in 32bit builds.

---
CC: Ian Campbell <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>

---
 tools/libxc/include/xc_dom.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxc/include/xc_dom.h +1 -1
index 6f0c6e0..2176216 100644
@@ -249,7 +249,7 @@ struct xc_dom_arch {
 void xc_dom_register_arch_hooks(struct xc_dom_arch *hooks);
 
 #define XC_DOM_PAGE_SHIFT(dom)  ((dom)->arch_hooks->page_shift)
-#define XC_DOM_PAGE_SIZE(dom)   (1 << (dom)->arch_hooks->page_shift)
+#define XC_DOM_PAGE_SIZE(dom)   (1LL << (dom)->arch_hooks->page_shift)
 
 /* --- main functions ---------------------------------------------- */
 
Signature · 1 line
2.1.4
#1 lore raw
Quoted 4 lines · Andrew Cooper

c/s abdf3c5b "libxc: create p2m list outside of kernel mapping if supported" introduces a use which Coverity objects to; an int used to mask a uint64_t.

The result needs to be signed to allow ~XC_DOM_PAGE_SIZE() to function

$ git grep XC_DOM_PAGE_SIZE

tools/libxc/include/xc_dom.h:#define XC_DOM_PAGE_SIZE(dom) (1 << (dom)->arch_hooks

tools/libxc/include/xc_dom.h:    unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
tools/libxc/xc_dom_core.c:    unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
tools/libxc/xc_dom_core.c:    unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
tools/libxc/xc_dom_core.c:    unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
tools/libxc/xc_dom_core.c:    unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
tools/libxc/xc_dom_core.c:    page_size = XC_DOM_PAGE_SIZE(dom);
tools/libxc/xc_dom_core.c:         (dom->parms.p2m_base & (XC_DOM_PAGE_SIZE(dom) - 1
tools/libxc/xc_dom_elfloader.c:    elf->dest_size = pages * XC_DOM_PAGE_SIZE(dom);
tools/libxc/xc_dom_hvmloader.c:    elf->dest_size = pages * XC_DOM_PAGE_SIZE(dom);
tools/libxc/xc_dom_x86.c:    memset(l3tab, 0, XC_DOM_PAGE_SIZE(dom));

There is no use for ~XC_DOM_PAGE_SIZE.

And what is the possible scenario you want that?

Quoted 27 lines

correctly, and long long to function properly in 32bit builds.

---
CC: Ian Campbell <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>

---
 tools/libxc/include/xc_dom.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxc/include/xc_dom.h +1 -1
index 6f0c6e0..2176216 100644
@@ -249,7 +249,7 @@ struct xc_dom_arch {
 void xc_dom_register_arch_hooks(struct xc_dom_arch *hooks);
 
 #define XC_DOM_PAGE_SHIFT(dom)  ((dom)->arch_hooks->page_shift)
-#define XC_DOM_PAGE_SIZE(dom)   (1 << (dom)->arch_hooks->page_shift)
+#define XC_DOM_PAGE_SIZE(dom)   (1LL << (dom)->arch_hooks->page_shift)
 
 /* --- main functions ---------------------------------------------- */
 
Signature · 1 line
2.1.4
#2 lore raw
Quoted 19 lines · Wei Liu
Quoted 4 lines · Andrew Cooper

c/s abdf3c5b "libxc: create p2m list outside of kernel mapping if supported" introduces a use which Coverity objects to; an int used to mask a uint64_t.

The result needs to be signed to allow ~XC_DOM_PAGE_SIZE() to function

$ git grep XC_DOM_PAGE_SIZE

tools/libxc/include/xc_dom.h:#define XC_DOM_PAGE_SIZE(dom) (1 << (dom)->arch_hooks

tools/libxc/include/xc_dom.h:    unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
tools/libxc/xc_dom_core.c:    unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
tools/libxc/xc_dom_core.c:    unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
tools/libxc/xc_dom_core.c:    unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
tools/libxc/xc_dom_core.c:    unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
tools/libxc/xc_dom_core.c:    page_size = XC_DOM_PAGE_SIZE(dom);
tools/libxc/xc_dom_core.c:         (dom->parms.p2m_base & (XC_DOM_PAGE_SIZE(dom) - 1
tools/libxc/xc_dom_elfloader.c:    elf->dest_size = pages * XC_DOM_PAGE_SIZE(dom);
tools/libxc/xc_dom_hvmloader.c:    elf->dest_size = pages * XC_DOM_PAGE_SIZE(dom);
tools/libxc/xc_dom_x86.c:    memset(l3tab, 0, XC_DOM_PAGE_SIZE(dom));
Quoted 3 lines

There is no use for ~XC_DOM_PAGE_SIZE.

And what is the possible scenario you want that?

There might not be a current user of this in libxc, but it is a common bug.

Quoted 1 line

From xen/include/asm-x86/page.h

/*

* It is important that the masks are signed quantities. This ensures
that

* the compiler sign-extends a 32-bit mask to 64 bits if that is
required.

*/

#define PAGE_SIZE           (_AC(1,L) << PAGE_SHIFT)
#define PAGE_MASK           (~(PAGE_SIZE-1))
#define PAGE_FLAG_MASK      (~0)
#define PAGE_ORDER_4K       0
#define PAGE_ORDER_2M       9
#define PAGE_ORDER_1G       18

~Andrew

Acked-by
#3 lore raw
Quoted 36 lines · Andrew Cooper
Quoted 19 lines · Wei Liu
Quoted 4 lines · Andrew Cooper

c/s abdf3c5b "libxc: create p2m list outside of kernel mapping if supported" introduces a use which Coverity objects to; an int used to mask a uint64_t.

The result needs to be signed to allow ~XC_DOM_PAGE_SIZE() to function

$ git grep XC_DOM_PAGE_SIZE

tools/libxc/include/xc_dom.h:#define XC_DOM_PAGE_SIZE(dom) (1 << (dom)->arch_hooks

tools/libxc/include/xc_dom.h:    unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
tools/libxc/xc_dom_core.c:    unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
tools/libxc/xc_dom_core.c:    unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
tools/libxc/xc_dom_core.c:    unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
tools/libxc/xc_dom_core.c:    unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
tools/libxc/xc_dom_core.c:    page_size = XC_DOM_PAGE_SIZE(dom);
tools/libxc/xc_dom_core.c:         (dom->parms.p2m_base & (XC_DOM_PAGE_SIZE(dom) - 1
tools/libxc/xc_dom_elfloader.c:    elf->dest_size = pages * XC_DOM_PAGE_SIZE(dom);
tools/libxc/xc_dom_hvmloader.c:    elf->dest_size = pages * XC_DOM_PAGE_SIZE(dom);
tools/libxc/xc_dom_x86.c:    memset(l3tab, 0, XC_DOM_PAGE_SIZE(dom));
Quoted 3 lines

There is no use for ~XC_DOM_PAGE_SIZE.

And what is the possible scenario you want that?

There might not be a current user of this in libxc, but it is a common bug.

From xen/include/asm-x86/page.h

/*

* It is important that the masks are signed quantities. This ensures
that

* the compiler sign-extends a 32-bit mask to 64 bits if that is
required.

Quoted 9 lines

*/

#define PAGE_SIZE           (_AC(1,L) << PAGE_SHIFT)
#define PAGE_MASK           (~(PAGE_SIZE-1))
#define PAGE_FLAG_MASK      (~0)
#define PAGE_ORDER_4K       0
#define PAGE_ORDER_2M       9
#define PAGE_ORDER_1G       18

Good to know.

Quoted 1 line

~Andrew