Define and use UINT64_C and INT64_C
PATCH 1/1 mm: Reuse PRI_gfn macro instead of manual specify the format
In reply to Frediano ZiglioMacros are defined to avoid type mismatch in format strings but also to unify format amongst code.
In the meantime expands to 9 hexadecimal digits.
--- xen/common/grant_table.c | 6 +++--- xen/include/xen/mm-frame.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-)
xen/common/grant_table.c +3 -3
@@ -1848,7 +1848,7 @@ gnttab_unpopulate_status_frames(struct domain *d, struct grant_table *gt)if ( rc ) {gprintk (XENLOG_ERR , -"Could not remove status frame %u (GFN %#lx) from P2M\n" , +"Could not remove status frame %u (GFN %" PRI_gfn") from P2M\n" , i,gfn_x (gfn));domain_crash (d);return rc;
@@ -1863,7 +1863,7 @@ gnttab_unpopulate_status_frames(struct domain *d, struct grant_table *gt)if (paging_mode_translate (d) ) {gprintk (XENLOG_ERR , -"Wrong page state %#lx of status frame %u (GFN %#lx)\n" , +"Wrong page state %#lx of status frame %u (GFN %" PRI_gfn")\n" , pg->count_info, i,gfn_x (gfn));domain_crash (d); }
@@ -3981,7 +3981,7 @@ void grant_table_warn_active_grants(struct domain *d)if ( nr_active <=WARN_GRANT_MAX ) printk(XENLOG_G_DEBUG "d%d has active grant %x (" #ifndef NDEBUG - "GFN %lx, " + "GFN %"PRI_gfn", " #endif "MFN: %#"PRI_mfn")\n", d->domain_id, ref,
xen/include/xen/mm-frame.h +2 -2
@@ -5,7 +5,7 @@#include <xen/typesafe.h> TYPE_SAFE(unsigned long, mfn); -#define PRI_mfn "05lx" +#define PRI_mfn "09lx"#define INVALID_MFN_RAW (~0UL)#define INVALID_MFN _mfn(INVALID_MFN_RAW)/*
@@ -41,7 +41,7 @@ static inline bool mfn_eq(mfn_t x, mfn_t y) } TYPE_SAFE(unsigned long, gfn); -#define PRI_gfn "05lx" +#define PRI_gfn "09lx"#define INVALID_GFN_RAW (~0UL)#define INVALID_GFN _gfn(INVALID_GFN_RAW)/*
Signature · 1 line
2.34.1
PATCH 1/1 Define and use UINT64_C and INT64_C
Makes code and constants work on both 32 and 64 bit.
--- xen/arch/x86/include/asm/config.h | 6 +++--- xen/arch/x86/include/asm/mm.h | 12 ++++++------ xen/arch/x86/include/asm/x86_64/page.h | 4 ++-- xen/arch/x86/setup.c | 4 ++-- xen/common/efi/boot.c | 2 +- xen/crypto/vmac.c | 2 ++ xen/include/crypto/vmac.h | 4 ++++ xen/include/xen/const.h | 9 +++++++++ xen/include/xen/stdint.h | 2 ++ 9 files changed, 31 insertions(+), 14 deletions(-)
xen/arch/x86/include/asm/config.h +3 -3
@@ -86,10 +86,10 @@#include <xen/const.h> #define PML4_ENTRY_BITS 39 -#define PML4_ENTRY_BYTES (_AC(1,UL) << PML4_ENTRY_BITS) +#define PML4_ENTRY_BYTES (UINT64_C(1) << PML4_ENTRY_BITS)#define PML4_ADDR (_slot) \ - (((_AC(_slot, UL) >> 8) * _AC(0xffff000000000000,UL)) | \ - (_AC(_slot, UL) << PML4_ENTRY_BITS)) + (((UINT64_C(_slot) >> 8) * UINT64_C(0xffff000000000000)) | \ + (UINT64_C(_slot) << PML4_ENTRY_BITS))/* * Memory layout:
xen/arch/x86/include/asm/mm.h +6 -6
@@ -20,7 +20,7 @@#define PFN_ORDER (_pfn) ((_pfn)->v.free.order)#define PG_shift (idx) (BITS_PER_LONG - (idx)) -#define PG_mask (x, idx) (x ## UL << PG_shift(idx)) +#define PG_mask (x, idx) (UINT64_C(x) << PG_shift(idx))/* The following page types are MUTUALLY EXCLUSIVE. */ #define PGT_none PG_mask(0, 3)/* no special uses of this page */
@@ -59,7 +59,7 @@/* Count of uses of this frame as its current type. */ #define PGT_count_width PG_shift(9) -#define PGT_count_mask ((1UL<<PGT_count_width)-1) +#define PGT_count_mask ((UINT64_C(1)<<PGT_count_width)-1)/* Are the 'type mask' bits identical? */ #define PGT_type_equal (x, y) (!(((x) ^ (y)) & PGT_type_mask))
@@ -97,7 +97,7 @@#else #define PGC_count_width PG_shift(6)#endif -#define PGC_count_mask ((1UL<<PGC_count_width)-1) +#define PGC_count_mask ((UINT64_C(1)<<PGC_count_width)-1)/* * Page needs to be scrubbed. Since this bit can only be set on a page that is
@@ -499,9 +499,9 @@ static inline int get_page_and_type(struct page_info *page,*/ #undef machine_to_phys_mapping#define machine_to_phys_mapping ((unsigned long *)RDWR_MPT_VIRT_START) -#define INVALID_M2P_ENTRY (~0UL) -#define VALID_M2P (_e) (!((_e) & (1UL<<(BITS_PER_LONG-1)))) -#define SHARED_M2P_ENTRY (~0UL - 1UL) +#define INVALID_M2P_ENTRY (~UINT64_C(0)) +#define VALID_M2P (_e) (!((_e) & (UINT64_C(1)<<(BITS_PER_LONG-1)))) +#define SHARED_M2P_ENTRY (~UINT64_C(0) - UINT64_C(1))#define SHARED_M2P (_e) ((_e) == SHARED_M2P_ENTRY)/*
xen/arch/x86/include/asm/x86_64/page.h +2 -2
@@ -4,8 +4,8 @@#define __XEN_VIRT_START XEN_VIRT_START -#define VADDR_TOP_BIT (1UL << (VADDR_BITS - 1)) -#define CANONICAL_MASK (~0UL & ~VADDR_MASK) +#define VADDR_TOP_BIT (UINT64_C(1) << (VADDR_BITS - 1)) +#define CANONICAL_MASK (~UINT64_C(0) & ~VADDR_MASK)#define is_canonical_address (x) (((long)(x) >> 47) == ((long)(x) >> 63))
xen/arch/x86/setup.c +2 -2
@@ -1384,9 +1384,9 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) }if ( e >min (HYPERVISOR_VIRT_END -DIRECTMAP_VIRT_START , -1UL << (PAGE_SHIFT +32 )) ) +UINT64_C (1 ) << (PAGE_SHIFT +32 )) ) e =min (HYPERVISOR_VIRT_END -DIRECTMAP_VIRT_START , -1UL << (PAGE_SHIFT +32 )); +UINT64_C (1 ) << (PAGE_SHIFT +32 ));#define reloc_size ((__pa(__2M_rwdata_end) + mask) & ~mask)/* Is the region suitable for relocating Xen? */ if ( !xen_phys_start && e <= limit )
xen/common/efi/boot.c +1 -1
@@ -770,7 +770,7 @@ static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, what = what ?:L"Seek" ; else { - file->addr =min (1UL << (32 +PAGE_SHIFT ), + file->addr =min (UINT64_C (1 ) << (32 +PAGE_SHIFT ),HYPERVISOR_VIRT_END -DIRECTMAP_VIRT_START ); ret = efi_bs->AllocatePages (AllocateMaxAddress, EfiLoaderData,PFN_UP (size), &file->addr);
xen/crypto/vmac.c +2 -0
@@ -11,7 +11,9 @@#include <xen/types.h> #include <xen/lib.h> #include <crypto/vmac.h> +#ifndef UINT64_C #define UINT64_C (x) x##ULL +#endif /* end for Xen */ /* Enable code tuned for 64-bit registers; otherwise tuned for 32-bit */
xen/include/crypto/vmac.h +4 -0
@@ -51,12 +51,16 @@#elif (_MSC_VER)/* Microsoft C does not have stdint.h */ typedef unsigned __int32 uint32_t ;typedef unsigned __int64 uint64_t ; +#ifndef UINT64_C #define UINT64_C (v) v ## UI64 +#endif #else /* Guess sensibly - may need adaptation */ typedef unsigned int uint32_t ;typedef unsigned long long uint64_t ; +#ifndef UINT64_C #define UINT64_C (v) v ## ULL#endif +#endif /* -------------------------------------------------------------------------- * This implementation supports two free AES implementations: OpenSSL's and
xen/include/xen/const.h +9 -0
@@ -15,10 +15,19 @@#ifdef __ASSEMBLY__#define _AC (X ,Y ) X#define _AT (T ,X ) X +#define UINT64_C (X ) X +#define INT64_C (X ) X#else #define __AC (X ,Y ) (X##Y)#define _AC (X ,Y ) __AC(X,Y)#define _AT (T ,X ) ((T)(X)) +#if __SIZEOF_LONG__ >=8 +#define UINT64_C (X ) X ## UL +#define INT64_C (X ) X ## L +#else +#define UINT64_C (X ) X ## ULL +#define INT64_C (X ) X ## LL +#endif #endif #define BIT (pos, sfx) (_AC(1, sfx) << (pos))
xen/include/xen/stdint.h +2 -0
@@ -30,4 +30,6 @@ typedef __UINT64_TYPE__ uint64_t;#endif +#include <xen/const.h> +#endif /* __XEN_STDINT_H__ */
Signature · 1 line
2.34.1
Quoted 74 lines · Frediano Ziglio
xen/arch/x86/include/asm/config.h +3
-3@@ -86,10 +86,10 @@#include <xen/const.h> #define PML4_ENTRY_BITS 39 -#define PML4_ENTRY_BYTES (_AC(1,UL) << PML4_ENTRY_BITS) +#define PML4_ENTRY_BYTES (UINT64_C(1) << PML4_ENTRY_BITS)#define PML4_ADDR (_slot) \ - (((_AC(_slot, UL) >> 8) * _AC(0xffff000000000000,UL)) | \ - (_AC(_slot, UL) << PML4_ENTRY_BITS)) + (((UINT64_C(_slot) >> 8) * UINT64_C(0xffff000000000000)) | \ + (UINT64_C(_slot) << PML4_ENTRY_BITS))/* * Memory layout: xen/arch/x86/include/asm/mm.h +6
-6@@ -20,7 +20,7 @@#define PFN_ORDER (_pfn) ((_pfn)->v.free.order)#define PG_shift (idx) (BITS_PER_LONG - (idx)) -#define PG_mask (x, idx) (x ## UL << PG_shift(idx)) +#define PG_mask (x, idx) (UINT64_C(x) << PG_shift(idx))/* The following page types are MUTUALLY EXCLUSIVE. */ #define PGT_none PG_mask(0, 3)/* no special uses of this page */ @@ -59,7 +59,7 @@/* Count of uses of this frame as its current type. */ #define PGT_count_width PG_shift(9) -#define PGT_count_mask ((1UL<<PGT_count_width)-1) +#define PGT_count_mask ((UINT64_C(1)<<PGT_count_width)-1)/* Are the 'type mask' bits identical? */ #define PGT_type_equal (x, y) (!(((x) ^ (y)) & PGT_type_mask))@@ -97,7 +97,7 @@#else #define PGC_count_width PG_shift(6)#endif -#define PGC_count_mask ((1UL<<PGC_count_width)-1) +#define PGC_count_mask ((UINT64_C(1)<<PGC_count_width)-1)/* * Page needs to be scrubbed. Since this bit can only be set on a page that is @@ -499,9 +499,9 @@ static inline int get_page_and_type(struct page_info *page,*/ #undef machine_to_phys_mapping#define machine_to_phys_mapping ((unsigned long *)RDWR_MPT_VIRT_START) -#define INVALID_M2P_ENTRY (~0UL) -#define VALID_M2P (_e) (!((_e) & (1UL<<(BITS_PER_LONG-1)))) -#define SHARED_M2P_ENTRY (~0UL - 1UL) +#define INVALID_M2P_ENTRY (~UINT64_C(0)) +#define VALID_M2P (_e) (!((_e) & (UINT64_C(1)<<(BITS_PER_LONG-1)))) +#define SHARED_M2P_ENTRY (~UINT64_C(0) - UINT64_C(1))#define SHARED_M2P (_e) ((_e) == SHARED_M2P_ENTRY)/* xen/arch/x86/include/asm/x86_64/page.h +2
-2@@ -4,8 +4,8 @@#define __XEN_VIRT_START XEN_VIRT_START -#define VADDR_TOP_BIT (1UL << (VADDR_BITS - 1)) -#define CANONICAL_MASK (~0UL & ~VADDR_MASK) +#define VADDR_TOP_BIT (UINT64_C(1) << (VADDR_BITS - 1)) +#define CANONICAL_MASK (~UINT64_C(0) & ~VADDR_MASK)#define is_canonical_address (x) (((long)(x) >> 47) == ((long)(x) >> 63))
xen/arch/x86/setup.c void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) · line 1389
Quoted 8 lines
xen/arch/x86/setup.c +2
-2@@ -1384,9 +1384,9 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) }if ( e >min (HYPERVISOR_VIRT_END -DIRECTMAP_VIRT_START , -1UL << (PAGE_SHIFT +32 )) ) +UINT64_C (1 ) << (PAGE_SHIFT +32 )) ) e =min (HYPERVISOR_VIRT_END -DIRECTMAP_VIRT_START , -1UL << (PAGE_SHIFT +32 )); +UINT64_C (1 ) << (PAGE_SHIFT +32 ));
I disagree - we're dealing with virtual addresses here, which better wouldn't use fixed-width quantities.
While not always virtual addresses, I similarly disagree for most or all I've left in context further up: If the underlying type to deal with is unsigned long, constants should match.
xen/crypto/vmac.c line 17
Quoted 10 lines
xen/crypto/vmac.c +2
-0@@ -11,7 +11,9 @@#include <xen/types.h> #include <xen/lib.h> #include <crypto/vmac.h> +#ifndef UINT64_C #define UINT64_C (x) x##ULL +#endif /* end for Xen */
Here the #define should probably just be dropped?
xen/include/crypto/vmac.h line 56
Quoted 9 lines
xen/include/crypto/vmac.h +2
-0@@ -51,12 +51,16 @@#elif (_MSC_VER)/* Microsoft C does not have stdint.h */ typedef unsigned __int32 uint32_t ;typedef unsigned __int64 uint64_t ; +#ifndef UINT64_C #define UINT64_C (v) v ## UI64 +#endif
This part surely isn't needed?
xen/include/xen/const.h line 24
Quoted 13 lines
xen/include/xen/const.h +3
-0@@ -15,10 +15,19 @@#ifdef __ASSEMBLY__#define _AC (X ,Y ) X#define _AT (T ,X ) X +#define UINT64_C (X ) X +#define INT64_C (X ) X#else #define __AC (X ,Y ) (X##Y)#define _AC (X ,Y ) __AC(X,Y)#define _AT (T ,X ) ((T)(X)) +#if __SIZEOF_LONG__ >=8
This is available with gcc 4.3 and newer, yet for now our docs still specify 4.1.2 as the baseline.
I'm also unconvinced of the >= - we're talking of fixed-width types here, so imo it needs to be == and then also ...
xen/include/xen/const.h line 27
Quoted 3 lines
xen/include/xen/const.h +3
-0+#define UINT64_C (X ) X ## UL +#define INT64_C (X ) X ## L +#else
#elif __SIZEOF_LONG_LONG__ == 8
here.
xen/include/xen/const.h line 31
Quoted 4 lines
xen/include/xen/const.h +3
-0+#define UINT64_C (X ) X ## ULL +#define INT64_C (X ) X ## LL +#endif #endif
Finally if we introduce these, imo we should introduce the other UINT<n>_C() as well, and in a header named after the one mandated by the C library spec.
xen/include/xen/stdint.h typedef __UINT64_TYPE__ uint64_t; · line 33
Quoted 7 lines
xen/include/xen/stdint.h +1
-0@@ -30,4 +30,6 @@ typedef __UINT64_TYPE__ uint64_t;#endif +#include <xen/const.h>
Why's this needed?
Jan
Re: [PATCH] mm: Reuse PRI_gfn macro instead of manual specify the format
In reply to Frediano ZiglioQuoted 2 lines · Frediano Ziglio
Macros are defined to avoid type mismatch in format strings but also to unify format amongst code.
I'm certainly fine with this part.
Quoted 1 line
In the meantime expands to 9 hexadecimal digits.
What makes 9 special? What will the extra padding zeroes buy us?
Quoted 11 lines
Signed-off-by Frediano Ziglio <[email protected]>--- xen/common/grant_table.c | 6 +++--- xen/include/xen/mm-frame.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-)xen/common/grant_table.c +0
-0
xen/common/grant_table.c gnttab_unpopulate_status_frames(struct domain *d, struct grant_table *gt) · line 1851
Quoted 5 lines
xen/common/grant_table.c +1
-1@@ -1848,7 +1848,7 @@ gnttab_unpopulate_status_frames(struct domain *d, struct grant_table *gt)if ( rc ) { gprintk(XENLOG_ERR, - "Could not remove status frame %u (GFN %#lx) from P2M\n", + "Could not remove status frame %u (GFN %"PRI_gfn") from P2M\n",
The lost # means the number won't identify itself as hex anymore. Rather than ...
xen/common/grant_table.c void grant_table_warn_active_grants(struct domain *d) · line 3986
Quoted 8 lines
xen/common/grant_table.c +1
-1@@ -3981,7 +3981,7 @@ void grant_table_warn_active_grants(struct domain *d)if ( nr_active <=WARN_GRANT_MAX ) printk(XENLOG_G_DEBUG "d%d has active grant %x (" #ifndef NDEBUG - "GFN %lx, " + "GFN %"PRI_gfn", " #endif "MFN: %#"PRI_mfn")\n",
(note this for below)
Quoted 12 lines
xen/include/xen/mm-frame.h +1
-1@@ -5,7 +5,7 @@#include <xen/typesafe.h> TYPE_SAFE(unsigned long, mfn); -#define PRI_mfn "05lx" +#define PRI_mfn "09lx"#define INVALID_MFN_RAW (~0UL)#define INVALID_MFN _mfn(INVALID_MFN_RAW)/*
xen/include/xen/mm-frame.h static inline bool mfn_eq(mfn_t x, mfn_t y) · line 44
Quoted 5 lines
xen/include/xen/mm-frame.h +1
-1@@ -41,7 +41,7 @@ static inline bool mfn_eq(mfn_t x, mfn_t y) } TYPE_SAFE(unsigned long, gfn); -#define PRI_gfn "05lx" +#define PRI_gfn "09lx"
... moving to 09 (twice) here, how about we move to #? Requiring, of course, to drop already-questionable hashes like the one pointed out in the middle.
Jan
Quoted 15 lines · Jan Beulich
xen/arch/x86/setup.c void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) · line 1389
Quoted 11 lines · Frediano Ziglio
xen/arch/x86/setup.c +2
-2@@ -1384,9 +1384,9 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) }if ( e >min (HYPERVISOR_VIRT_END -DIRECTMAP_VIRT_START , -1UL << (PAGE_SHIFT +32 )) ) +UINT64_C (1 ) << (PAGE_SHIFT +32 )) ) e =min (HYPERVISOR_VIRT_END -DIRECTMAP_VIRT_START , -1UL << (PAGE_SHIFT +32 )); +UINT64_C (1 ) << (PAGE_SHIFT +32 ));I disagree - we're dealing with virtual addresses here, which better wouldn't use fixed-width quantities.
Quoted 3 lines
While not always virtual addresses, I similarly disagree for most or all I've left in context further up: If the underlying type to deal with is unsigned long, constants should match.
This is the same problem I ran into with fixmap mappings.
GB() and friends used in config.h are ULL constants, and promote the underlying variables from UL.
64bit mostly copes (give or take some printk formatting), but 32bit fails to compile.
~Andrew
Quoted 20 lines · Andrew Cooper
Quoted 15 lines · Jan Beulich
xen/arch/x86/setup.c void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) · line 1389
Quoted 11 lines · Frediano Ziglio
xen/arch/x86/setup.c +2
-2@@ -1384,9 +1384,9 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) }if ( e >min (HYPERVISOR_VIRT_END -DIRECTMAP_VIRT_START , -1UL << (PAGE_SHIFT +32 )) ) +UINT64_C (1 ) << (PAGE_SHIFT +32 )) ) e =min (HYPERVISOR_VIRT_END -DIRECTMAP_VIRT_START , -1UL << (PAGE_SHIFT +32 )); +UINT64_C (1 ) << (PAGE_SHIFT +32 ));I disagree - we're dealing with virtual addresses here, which better wouldn't use fixed-width quantities.
Quoted 3 lines
While not always virtual addresses, I similarly disagree for most or all I've left in context further up: If the underlying type to deal with is unsigned long, constants should match.
Quoted 7 lines
This is the same problem I ran into with fixmap mappings.
GB()and friends used inconfig.hare ULL constants, and promote the underlying variables from UL.64bit mostly copes (give or take some printk formatting), but 32bit fails to compile.
Yet the code above is never built as 32-bit.
Jan
Re: [PATCH] mm: Reuse PRI_gfn macro instead of manual specify the format
In reply to Jan BeulichQuoted 11 lines · Jan Beulich
Quoted 2 lines · Frediano Ziglio
Macros are defined to avoid type mismatch in format strings but also to unify format amongst code.
I'm certainly fine with this part.
Quoted 1 line
In the meantime expands to 9 hexadecimal digits.
What makes 9 special? What will the extra padding zeroes buy us?
I think either we want kind of fixed size or dynamic. 9 == (48 - 12) / 4, although possibly you would prefer 13 == (64 - 12) / 4.
Quoted 49 lines
xen/common/grant_table.c gnttab_unpopulate_status_frames(struct domain *d,
Quoted 11 lines
Signed-off-by Frediano Ziglio <[email protected]>--- xen/common/grant_table.c | 6 +++--- xen/include/xen/mm-frame.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-)xen/common/grant_table.c +0
-0@@ -1848,7 +1848,7 @@ gnttab_unpopulate_status_frames(struct domain *d,struct
grant_table*gt)xen/common/grant_table.c gnttab_unpopulate_status_frames(struct domain *d, struct grant_table *gt)
Quoted 4 lines
xen/common/grant_table.c +0
-1if ( rc ) { gprintk(XENLOG_ERR, - "Could not remove status frame %u (GFN %#lx)from P2M\n",
xen/common/grant_table.c gnttab_unpopulate_status_frames(struct domain *d, · line 1851
Quoted 1 line
xen/common/grant_table.c +1
-0+ "Could not remove status frame %u (GFN%"PRI_gfn") from P2M\n",
The lost # means the number won't identify itself as hex anymore. Rather than ...
xen/common/grant_table.c void grant_table_warn_active_grants(struct domain
Quoted 1 line
xen/common/grant_table.c +0
-0@@ -3981,7 +3981,7 @@ void grant_table_warn_active_grants(struct domain*d)
xen/common/grant_table.c void grant_table_warn_active_grants(struct domain *d) · line 3986
Quoted 7 lines
xen/common/grant_table.c +1
-1if ( nr_active <=WARN_GRANT_MAX ) printk(XENLOG_G_DEBUG "d%d has active grant %x (" #ifndef NDEBUG - "GFN %lx, " + "GFN %"PRI_gfn", " #endif "MFN: %#"PRI_mfn")\n",(note this for below)
Quoted 14 lines
xen/include/xen/mm-frame.h +1
-1@@ -5,7 +5,7 @@#include <xen/typesafe.h> TYPE_SAFE(unsigned long, mfn); -#define PRI_mfn "05lx" +#define PRI_mfn "09lx"#define INVALID_MFN_RAW (~0UL)#define INVALID_MFN _mfn(INVALID_MFN_RAW)/* @@ -41,7 +41,7 @@ static inline bool mfn_eq(mfn_t x, mfn_t y) }
Quoted 9 lines
xen/include/xen/mm-frame.h static inline bool mfn_eq(mfn_t x, mfn_t y) · line 44
Quoted 3 lines
xen/include/xen/mm-frame.h +1
-1TYPE_SAFE(unsigned long, gfn); -#define PRI_gfn "05lx" +#define PRI_gfn "09lx"... moving to 09 (twice) here, how about we move to #? Requiring, of course,
to drop already-questionable hashes like the one pointed out in the middle.
I suppose you are suggesting getting rid of the padding entirely and move to prefix, like "%#lx".
Quoted 2 lines
Jan
I can do it
Frediano
Re: [PATCH] mm: Reuse PRI_gfn macro instead of manual specify the format
Quoted 7 lines · Frediano Ziglio
Quoted 6 lines · Jan Beulich
Quoted 2 lines · Frediano Ziglio
Macros are defined to avoid type mismatch in format strings but also to unify format amongst code.
I'm certainly fine with this part.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
In the meantime expands to 9 hexadecimal digits.
What makes 9 special? What will the extra padding zeroes buy us?
I think either we want kind of fixed size or dynamic. 9 == (48 - 12) / 4, although possibly you would prefer 13 == (64 - 12) / 4.
64 is too much for x86; it would want to be 52 there. The way it is right now this is (imo deliberately) not arch-specific, though.
Quoted 49 lines
Quoted 41 lines
xen/common/grant_table.c gnttab_unpopulate_status_frames(struct domain *d,
Quoted 3 lines
xen/common/grant_table.c +0
-0@@ -1848,7 +1848,7 @@ gnttab_unpopulate_status_frames(struct domain *d,struct
grant_table*gt)xen/common/grant_table.c gnttab_unpopulate_status_frames(struct domain *d, struct grant_table *gt)
Quoted 4 lines
xen/common/grant_table.c +0
-1if ( rc ) { gprintk(XENLOG_ERR, - "Could not remove status frame %u (GFN %#lx)from P2M\n",
xen/common/grant_table.c gnttab_unpopulate_status_frames(struct domain *d, · line 1851
Quoted 1 line
xen/common/grant_table.c +1
-0+ "Could not remove status frame %u (GFN%"PRI_gfn") from P2M\n",
The lost # means the number won't identify itself as hex anymore. Rather than ...
xen/common/grant_table.c void grant_table_warn_active_grants(struct domain
Quoted 1 line
xen/common/grant_table.c +0
-0@@ -3981,7 +3981,7 @@ void grant_table_warn_active_grants(struct domain*d)
xen/common/grant_table.c void grant_table_warn_active_grants(struct domain *d) · line 3986
Quoted 7 lines
xen/common/grant_table.c +1
-1if ( nr_active <=WARN_GRANT_MAX ) printk(XENLOG_G_DEBUG "d%d has active grant %x (" #ifndef NDEBUG - "GFN %lx, " + "GFN %"PRI_gfn", " #endif "MFN: %#"PRI_mfn")\n",(note this for below)
Quoted 14 lines
xen/include/xen/mm-frame.h +1
-1@@ -5,7 +5,7 @@#include <xen/typesafe.h> TYPE_SAFE(unsigned long, mfn); -#define PRI_mfn "05lx" +#define PRI_mfn "09lx"#define INVALID_MFN_RAW (~0UL)#define INVALID_MFN _mfn(INVALID_MFN_RAW)/* @@ -41,7 +41,7 @@ static inline bool mfn_eq(mfn_t x, mfn_t y) }Quoted 8 lines
xen/include/xen/mm-frame.h static inline bool mfn_eq(mfn_t x, mfn_t y) · line 44
Quoted 3 lines
xen/include/xen/mm-frame.h +1
-1TYPE_SAFE(unsigned long, gfn); -#define PRI_gfn "05lx" +#define PRI_gfn "09lx"... moving to 09 (twice) here, how about we move to #? Requiring, of course,
to drop already-questionable hashes like the one pointed out in the middle.
Quoted 2 lines
I suppose you are suggesting getting rid of the padding entirely and move to prefix, like "%#lx".
Yes, i.e.
#define PRI_mfn "#lx"
Then again I don't really know why "05lx" was chosen originally.
Jan
Re: [PATCH] mm: Reuse PRI_gfn macro instead of manual specify the format
Quoted 10 lines · Jan Beulich
Quoted 9 lines · Frediano Ziglio
Quoted 8 lines · Jan Beulich
Quoted 2 lines · Frediano Ziglio
Macros are defined to avoid type mismatch in format strings but also to unify format amongst code.
I'm certainly fine with this part.
Quoted 1 line
In the meantime expands to 9 hexadecimal digits.
Quoted 10 lines
Quoted 5 lines
Quoted 3 lines
What makes 9 special? What will the extra padding zeroes buy us?
I think either we want kind of fixed size or dynamic. 9 == (48 - 12) / 4, although possibly you would prefer 13 == (64 - 12) / 4.
64 is too much for x86; it would want to be 52 there. The way it is right now this is (imo deliberately) not arch-specific, though.
Yes, but still given the canonic form of x64 you would need to use 13 digits to have all the same size.
Quoted 53 lines
Quoted 41 lines
Quoted 41 lines
xen/common/grant_table.c gnttab_unpopulate_status_frames(struct domain *d,
Quoted 3 lines
xen/common/grant_table.c +0
-0@@ -1848,7 +1848,7 @@ gnttab_unpopulate_status_frames(struct domain *d,struct
grant_table*gt)xen/common/grant_table.c gnttab_unpopulate_status_frames(struct domain *d, struct grant_table *gt)
Quoted 4 lines
xen/common/grant_table.c +0
-1if ( rc ) { gprintk(XENLOG_ERR, - "Could not remove status frame %u (GFN %#lx)from P2M\n",
xen/common/grant_table.c gnttab_unpopulate_status_frames(struct domain *d, · line 1851
Quoted 1 line
xen/common/grant_table.c +1
-0+ "Could not remove status frame %u (GFN%"PRI_gfn") from P2M\n",
The lost # means the number won't identify itself as hex anymore. Rather than ...
xen/common/grant_table.c void grant_table_warn_active_grants(struct domain
Quoted 1 line
xen/common/grant_table.c +0
-0@@ -3981,7 +3981,7 @@ void grant_table_warn_active_grants(struct domain*d)
xen/common/grant_table.c void grant_table_warn_active_grants(struct domain *d) · line 3986
Quoted 7 lines
xen/common/grant_table.c +1
-1if ( nr_active <=WARN_GRANT_MAX ) printk(XENLOG_G_DEBUG "d%d has active grant %x (" #ifndef NDEBUG - "GFN %lx, " + "GFN %"PRI_gfn", " #endif "MFN: %#"PRI_mfn")\n",(note this for below)
Quoted 14 lines
xen/include/xen/mm-frame.h +1
-1@@ -5,7 +5,7 @@#include <xen/typesafe.h> TYPE_SAFE(unsigned long, mfn); -#define PRI_mfn "05lx" +#define PRI_mfn "09lx"#define INVALID_MFN_RAW (~0UL)#define INVALID_MFN _mfn(INVALID_MFN_RAW)/* @@ -41,7 +41,7 @@ static inline bool mfn_eq(mfn_t x, mfn_t y) }Quoted 7 lines
Quoted 7 lines
xen/include/xen/mm-frame.h static inline bool mfn_eq(mfn_t x, mfn_t y) · line 44
Quoted 3 lines
xen/include/xen/mm-frame.h +1
-1TYPE_SAFE(unsigned long, gfn); -#define PRI_gfn "05lx" +#define PRI_gfn "09lx"... moving to 09 (twice) here, how about we move to #? Requiring, of course,
to drop already-questionable hashes like the one pointed out in themiddle.
Quoted 3 lines
Quoted 1 line
I suppose you are suggesting getting rid of the padding entirely and move to prefix, like "%#lx".
Quoted 10 lines
Yes, i.e.
#define
PRI_mfn"#lx"Surely more portable amongst different platforms.
Then again I don't really know why "05lx" was chosen originally.
I assume x86 without PAE, 32 bit, so 5 == (32 - 12) / 4.
Quoted 2 lines
Jan
Sent updated one
Frediano
Quoted 89 lines · Jan Beulich
Quoted 19 lines · Frediano Ziglio
xen/arch/x86/include/asm/config.h +3
-3@@ -86,10 +86,10 @@#include <xen/const.h> #define PML4_ENTRY_BITS 39 -#define PML4_ENTRY_BYTES (_AC(1,UL) << PML4_ENTRY_BITS) +#define PML4_ENTRY_BYTES (UINT64_C(1) << PML4_ENTRY_BITS)#define PML4_ADDR (_slot) \ - (((_AC(_slot, UL) >> 8) * _AC(0xffff000000000000,UL)) | \ - (_AC(_slot, UL) << PML4_ENTRY_BITS)) + (((UINT64_C(_slot) >> 8) * UINT64_C(0xffff000000000000)) | \ + (UINT64_C(_slot) << PML4_ENTRY_BITS))/* * Memory layout: xen/arch/x86/include/asm/mm.h line 26
Quoted 8 lines
xen/arch/x86/include/asm/mm.h +1
-1@@ -20,7 +20,7 @@#define PFN_ORDER (_pfn) ((_pfn)->v.free.order)#define PG_shift (idx) (BITS_PER_LONG - (idx)) -#define PG_mask (x, idx) (x ## UL << PG_shift(idx)) +#define PG_mask (x, idx) (UINT64_C(x) << PG_shift(idx))/* The following page types are MUTUALLY EXCLUSIVE. */ #define PGT_none PG_mask(0, 3)/* no special uses of this page */
Quoted 10 lines
xen/arch/x86/include/asm/mm.h +1
-1@@ -59,7 +59,7 @@/* Count of uses of this frame as its current type. */ #define PGT_count_width PG_shift(9) -#define PGT_count_mask ((1UL<<PGT_count_width)-1) +#define PGT_count_mask ((UINT64_C(1)<<PGT_count_width)-1)/* Are the 'type mask' bits identical? */ #define PGT_type_equal (x, y) (!(((x) ^ (y)) & PGT_type_mask))xen/arch/x86/include/asm/mm.h line 103
Quoted 8 lines
xen/arch/x86/include/asm/mm.h +1
-1@@ -97,7 +97,7 @@#else #define PGC_count_width PG_shift(6)#endif -#define PGC_count_mask ((1UL<<PGC_count_width)-1) +#define PGC_count_mask ((UINT64_C(1)<<PGC_count_width)-1)/* * Page needs to be scrubbed. Since this bit can only be set on a page that is
xen/arch/x86/include/asm/mm.h static inline int get_page_and_type(struct page_info
Quoted 1 line
xen/arch/x86/include/asm/mm.h +0
-0@@ -499,9 +499,9 @@ static inline int get_page_and_type(struct page_info*page,
xen/arch/x86/include/asm/mm.h static inline int get_page_and_type(struct page_info *page,
Quoted 8 lines
xen/arch/x86/include/asm/mm.h +2
-3*/ #undef machine_to_phys_mapping#define machine_to_phys_mapping ((unsigned long *)RDWR_MPT_VIRT_START) -#define INVALID_M2P_ENTRY (~0UL) -#define VALID_M2P (_e) (!((_e) & (1UL<<(BITS_PER_LONG-1)))) -#define SHARED_M2P_ENTRY (~0UL - 1UL) +#define INVALID_M2P_ENTRY (~UINT64_C(0)) +#define VALID_M2P (_e) (!((_e) &(UINT64_C(1)<<(BITS_PER_LONG-1))))
xen/arch/x86/setup.c void asmlinkage __init noreturn
Quoted 20 lines
xen/arch/x86/include/asm/mm.h +1
-0+#define SHARED_M2P_ENTRY (~UINT64_C(0) - UINT64_C(1))#define SHARED_M2P (_e) ((_e) == SHARED_M2P_ENTRY)/* xen/arch/x86/include/asm/x86_64/page.h +2
-2@@ -4,8 +4,8 @@#define __XEN_VIRT_START XEN_VIRT_START -#define VADDR_TOP_BIT (1UL << (VADDR_BITS - 1)) -#define CANONICAL_MASK (~0UL & ~VADDR_MASK) +#define VADDR_TOP_BIT (UINT64_C(1) << (VADDR_BITS - 1)) +#define CANONICAL_MASK (~UINT64_C(0) & ~VADDR_MASK)#define is_canonical_address (x) (((long)(x) >> 47) == ((long)(x) >> 63))xen/arch/x86/setup.c +0
-0@@ -1384,9 +1384,9 @@ void asmlinkage __init noreturn
__start_xen(unsigned long mbi_p)xen/arch/x86/setup.c void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) · line 1389
Quoted 8 lines
xen/arch/x86/setup.c +2
-2}if ( e >min (HYPERVISOR_VIRT_END -DIRECTMAP_VIRT_START , -1UL << (PAGE_SHIFT +32 )) ) +UINT64_C (1 ) << (PAGE_SHIFT +32 )) ) e =min (HYPERVISOR_VIRT_END -DIRECTMAP_VIRT_START , -1UL << (PAGE_SHIFT +32 )); +UINT64_C (1 ) << (PAGE_SHIFT +32 ));
Quoted 4 lines
I disagree - we're dealing with virtual addresses here, which better wouldn't use fixed-width quantities.
I suppose you are suggesting type-based macros instead of fixed-type macros, so something like PADDR_C and VADDR_C.
That makes sense.
Quoted 5 lines
While not always virtual addresses, I similarly disagree for most or all I've left in context further up: If the underlying type to deal with is unsigned long, constants should match.
Sure, in this case the underlying type if used as 32 bit cannot be unsigned long but they should be unsigned long long (or any 64 bit type).
Quoted 14 lines
---
a/xen/crypto/vmac.cxen/arch/x86/setup.c line 17
Quoted 9 lines
xen/arch/x86/setup.c +3
-0+++ b/xen/crypto/vmac.c@@ -11,7 +11,9 @@#include <xen/types.h> #include <xen/lib.h> #include <crypto/vmac.h> +#ifndef UINT64_C #define UINT64_C (x) x##ULL +#endif /* end for Xen */ Here the #define should probably just be dropped?
If we go for newer type-base macros, we won't need to change here.
Quoted 5 lines
xen/include/crypto/vmac.h line 51
Quoted 4 lines
xen/include/crypto/vmac.h +0
-0@@ -51,12 +51,16 @@#elif (_MSC_VER)/* Microsoft C does not have
stdint.h*/
Quoted 9 lines
xen/include/crypto/vmac.h line 56
Quoted 5 lines
xen/include/crypto/vmac.h +2
-0typedef unsigned __int32 uint32_t ;typedef unsigned __int64 uint64_t ; +#ifndef UINT64_C #define UINT64_C (v) v ## UI64 +#endif This part surely isn't needed?
Indeed :-)
Quoted 8 lines
Quoted 8 lines
xen/include/xen/const.h +2
-0@@ -15,10 +15,19 @@#ifdef __ASSEMBLY__#define _AC (X ,Y ) X#define _AT (T ,X ) X +#define UINT64_C (X ) X +#define INT64_C (X ) X
Quoted 10 lines
xen/include/xen/const.h line 24
Quoted 5 lines
xen/include/xen/const.h +1
-0#else #define __AC (X ,Y ) (X##Y)#define _AC (X ,Y ) __AC(X,Y)#define _AT (T ,X ) ((T)(X)) +#if __SIZEOF_LONG__ >=8 This is available with gcc 4.3 and newer, yet for now our docs still specify 4.1.2 as the baseline.
Do we have some sort of configure generated macro for this?
Quoted 25 lines
I'm also unconvinced of the >= - we're talking of fixed-width types here, so imo it needs to be == and then also ...
xen/include/xen/const.h line 27
Quoted 3 lines
xen/include/xen/const.h +3
-0+#define UINT64_C (X ) X ## UL +#define INT64_C (X ) X ## L +#else #elif
__SIZEOF_LONG_LONG__== 8here.
xen/include/xen/const.h line 31
Quoted 4 lines
xen/include/xen/const.h +3
-0+#define UINT64_C (X ) X ## ULL +#define INT64_C (X ) X ## LL +#endif #endif Finally if we introduce these, imo we should introduce the other UINT<n>_C()
as well, and in a header named after the one mandated by the C library spec.Quoted 4 lines
xen/include/xen/stdint.h +0
-0@@ -30,4 +30,6 @@ typedef __UINT64_TYPE__ uint64_t;
Quoted 7 lines
xen/include/xen/stdint.h typedef __UINT64_TYPE__ uint64_t; · line 33
Quoted 3 lines
xen/include/xen/stdint.h +1
-0#endif +#include <xen/const.h> Why's this needed?
Not strictly needed, but in the standard headers they are usually defined including stdint.h.
Quoted 2 lines
Jan
Frediano
Quoted 15 lines · Frediano Ziglio
Quoted 14 lines · Jan Beulich
xen/arch/x86/setup.c void asmlinkage __init noreturn
Quoted 3 lines · Frediano Ziglio
xen/arch/x86/setup.c +0
-0@@ -1384,9 +1384,9 @@ void asmlinkage __init noreturn
__start_xen(unsigned long mbi_p)Quoted 8 lines
xen/arch/x86/setup.c +2
-2}if ( e >min (HYPERVISOR_VIRT_END -DIRECTMAP_VIRT_START , -1UL << (PAGE_SHIFT +32 )) ) +UINT64_C (1 ) << (PAGE_SHIFT +32 )) ) e =min (HYPERVISOR_VIRT_END -DIRECTMAP_VIRT_START , -1UL << (PAGE_SHIFT +32 )); +UINT64_C (1 ) << (PAGE_SHIFT +32 ));
Quoted 6 lines
Quoted 3 lines
I disagree - we're dealing with virtual addresses here, which better wouldn't use fixed-width quantities.
I suppose you are suggesting type-based macros instead of fixed-type macros, so something like
PADDR_CandVADDR_C.
That makes sense.
No, I'm suggesting to somply leave this code alone. On x86 we have no vaddr_t, and hence I see no reason to have VADDR_C().
Quoted 6 lines
Quoted 4 lines
While not always virtual addresses, I similarly disagree for most or all I've left in context further up: If the underlying type to deal with is unsigned long, constants should match.
Sure, in this case the underlying type if used as 32 bit cannot be unsigned long but they should be unsigned long long (or any 64 bit type).
My primary request here is: Code that won't be built as 32-bit doesn't need changing if it's not explicitly using {,u}int64_t-type variables / expressions.
Quoted 14 lines
Quoted 14 lines
---
a/xen/crypto/vmac.cxen/arch/x86/setup.c line 17
Quoted 9 lines
xen/arch/x86/setup.c +3
-0+++ b/xen/crypto/vmac.c@@ -11,7 +11,9 @@#include <xen/types.h> #include <xen/lib.h> #include <crypto/vmac.h> +#ifndef UINT64_C #define UINT64_C (x) x##ULL +#endif /* end for Xen */ Here the #define should probably just be dropped?
Quoted 1 line
If we go for newer type-base macros, we won't need to change here.
I'm afraid I don't understand this reply.
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
xen/include/xen/const.h +2
-0@@ -15,10 +15,19 @@#ifdef __ASSEMBLY__#define _AC (X ,Y ) X#define _AT (T ,X ) X +#define UINT64_C (X ) X +#define INT64_C (X ) XQuoted 9 lines
xen/include/xen/const.h line 24
Quoted 5 lines
xen/include/xen/const.h +1
-0#else #define __AC (X ,Y ) (X##Y)#define _AC (X ,Y ) __AC(X,Y)#define _AT (T ,X ) ((T)(X)) +#if __SIZEOF_LONG__ >=8 This is available with gcc 4.3 and newer, yet for now our docs still specify 4.1.2 as the baseline.
Quoted 1 line
Do we have some sort of configure generated macro for this?
I don#t think we do. And I also don't think we need one - we have BITS_PER_LONG, which ought to be sufficient here.
Quoted 11 lines
Quoted 11 lines
I'm also unconvinced of the >= - we're talking of fixed-width types here, so imo it needs to be == and then also ...
xen/include/xen/const.h line 27
Quoted 3 lines
xen/include/xen/const.h +3
-0+#define UINT64_C (X ) X ## UL +#define INT64_C (X ) X ## L +#else #elif
__SIZEOF_LONG_LONG__== 8here.
Quoted 9 lines
Quoted 9 lines
xen/include/xen/const.h line 31
Quoted 4 lines
xen/include/xen/const.h +3
-0+#define UINT64_C (X ) X ## ULL +#define INT64_C (X ) X ## LL +#endif #endif Finally if we introduce these, imo we should introduce the other UINT<n>_C()
as well, and in a header named after the one mandated by the C library spec.
I'm sorry, I was actually wrong here (alluding to inttypes.h), so ...
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
xen/include/xen/stdint.h +0
-0@@ -30,4 +30,6 @@ typedef __UINT64_TYPE__ uint64_t;
Quoted 8 lines
Quoted 6 lines
xen/include/xen/stdint.h typedef __UINT64_TYPE__ uint64_t; · line 33
Quoted 3 lines
xen/include/xen/stdint.h +1
-0#endif +#include <xen/const.h> Why's this needed?
Not strictly needed, but in the standard headers they are usually defined including
stdint.h.
... yes, but imo the definitions then would better live here in the first place.
Jan