Skip to contentSkip to conversation

xen/types: Cleanup

PATCH In review Andrew Cooper 5 participants 13 messages Jun 27, 2023 – Jul 5, 2023 RISC-V

lore
Share & tools
lore
#0 lore raw

v2 cover xen/types: Cleanup

v2, adjusted per the discussion at XenSummit

https://cirrus-ci.com/build/6611877547999232
https://gitlab.com/xen-project/people/andyhhp/xen/-/pipelines/912782128

Andrew Cooper (3):
xen/types: Drop #ifdefary for __{SIZE,PTRDIFF}_TYPE__
treewide: Avoid including asm/types.h xen/types: Rework stdint vs __{u,s}$N types

 xen/arch/arm/arm64/lib/find_next_bit.c      |  2 +-
 xen/arch/arm/include/asm/types.h            | 19 ------------
 xen/arch/riscv/include/asm/types.h          | 19 ------------
 xen/arch/x86/cpu/mcheck/mce.h               |  1 -
 xen/arch/x86/cpu/vpmu.c                     |  1 -
 xen/arch/x86/cpu/vpmu_intel.c               |  1 -
 xen/arch/x86/hvm/hvm.c                      |  1 -
 xen/arch/x86/hvm/vmx/vvmx.c                 |  1 -
 xen/arch/x86/include/asm/byteorder.h        |  2 +-
 xen/arch/x86/include/asm/hvm/svm/svmdebug.h |  2 +-
 xen/arch/x86/include/asm/hvm/vmx/vmx.h      |  3 +-
 xen/arch/x86/include/asm/io_apic.h          |  3 +-
 xen/arch/x86/include/asm/page.h             |  2 +-
 xen/arch/x86/include/asm/processor.h        |  1 -
 xen/arch/x86/include/asm/types.h            | 14 ---------
 xen/arch/x86/include/asm/x86_64/page.h      |  2 +-
 xen/arch/x86/mm/p2m-ept.c                   |  1 -
 xen/common/trace.c                          |  1 -
 xen/drivers/char/arm-uart.c                 |  2 +-
 xen/include/xen/bitops.h                    |  2 +-
 xen/include/xen/spinlock.h                  |  3 +-
 xen/include/xen/stdint.h                    | 33 +++++++++++++++++++++
 xen/include/xen/types.h                     | 29 +++++++-----------
 23 files changed, 56 insertions(+), 89 deletions(-)
 create mode 100644 xen/include/xen/stdint.h
Signature · 1 line
2.30.2
#1 lore raw

PATCH v2 1/3 xen/types: Drop #ifdefary for __{SIZE,PTRDIFF}_TYPE__

All supported compilers have these types.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Bob Eshleman <[email protected]>
CC: Alistair Francis <[email protected]>
CC: Connor Davis <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Shawn Anastasio <[email protected]>
CC: Timothy Pearson <[email protected]>

https://godbolt.org/z/Y6PWcd6js

---
 xen/include/xen/types.h | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
xen/include/xen/types.h +1 -8
index 6aba80500aaf..8b22a02eeaa4 100644
@@ -5,18 +5,11 @@
 
 #include <asm/types.h>
 
-#if defined(__SIZE_TYPE__)
 typedef __SIZE_TYPE__ size_t;
-#else
-typedef unsigned long size_t;
-#endif
+
 typedef signed long ssize_t;
 
-#if defined(__PTRDIFF_TYPE__)
 typedef __PTRDIFF_TYPE__ ptrdiff_t;
-#else
-typedef signed long ptrdiff_t;
-#endif
 
 #define BITS_TO_LONGS(bits) \
     (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG)
Signature · 1 line
2.30.2
Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] xen/types: Drop #ifdefary for __{SIZE,PTRDIFF}_TYPE__

Quoted 51 lines · Andrew Cooper

All supported compilers have these types.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Bob Eshleman <[email protected]>
CC: Alistair Francis <[email protected]>
CC: Connor Davis <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Shawn Anastasio <[email protected]>
CC: Timothy Pearson <[email protected]>

https://godbolt.org/z/Y6PWcd6js
---
 xen/include/xen/types.h | 9 +--------

 1 file changed, 1 insertion(+), 8 deletions(-)
xen/include/xen/types.h +0 -0
index 6aba80500aaf..8b22a02eeaa4 100644
@@ -5,18 +5,11 @@


 #include <asm/types.h>

-#if defined(__SIZE_TYPE__)
 typedef __SIZE_TYPE__ size_t;

xen/include/xen/types.h +1 -3
-#else
-typedef unsigned long size_t;
-#endif
+

 typedef signed long ssize_t;

-#if defined(__PTRDIFF_TYPE__)
 typedef __PTRDIFF_TYPE__ ptrdiff_t;

xen/include/xen/types.h +0 -3
-#else
-typedef signed long ptrdiff_t;
-#endif


 #define BITS_TO_LONGS(bits) \
     (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG)

#3 lore raw

PATCH v2 2/3 treewide: Avoid including asm/types.h

In reply to Andrew Cooper

We're about to rearrange the common and arch types.h split. While most users already include <xen/types.h>, a few do not and some files fail to compile as a result.

Almost all logic is going to have types very early in the include chain. Drop the include entirely from C files, and swap to the common types.h in headers.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Bob Eshleman <[email protected]>
CC: Alistair Francis <[email protected]>
CC: Connor Davis <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Shawn Anastasio <[email protected]>
CC: Timothy Pearson <[email protected]>
---

v2: New

 xen/arch/arm/arm64/lib/find_next_bit.c      | 2 +-
 xen/arch/x86/cpu/mcheck/mce.h               | 1 -
 xen/arch/x86/cpu/vpmu.c                     | 1 -
 xen/arch/x86/cpu/vpmu_intel.c               | 1 -
 xen/arch/x86/hvm/hvm.c                      | 1 -
 xen/arch/x86/hvm/vmx/vvmx.c                 | 1 -
 xen/arch/x86/include/asm/byteorder.h        | 2 +-
 xen/arch/x86/include/asm/hvm/svm/svmdebug.h | 2 +-
 xen/arch/x86/include/asm/hvm/vmx/vmx.h      | 3 ++-
 xen/arch/x86/include/asm/io_apic.h          | 3 ++-
 xen/arch/x86/include/asm/page.h             | 2 +-
 xen/arch/x86/include/asm/processor.h        | 1 -
 xen/arch/x86/include/asm/x86_64/page.h      | 2 +-
 xen/arch/x86/mm/p2m-ept.c                   | 1 -
 xen/common/trace.c                          | 1 -
 xen/drivers/char/arm-uart.c                 | 2 +-
 xen/include/xen/bitops.h                    | 2 +-
 xen/include/xen/spinlock.h                  | 3 ++-
 18 files changed, 13 insertions(+), 18 deletions(-)
xen/arch/arm/arm64/lib/find_next_bit.c +1 -1
index 8ebf8bfe973c..ca6f82277e77 100644
@@ -9,7 +9,7 @@
  * 2 of the License, or (at your option) any later version.
  */
 #include <xen/bitops.h>
-#include <asm/types.h>
+
 #include <asm/byteorder.h>
 
 #ifndef find_next_bit
xen/arch/x86/cpu/mcheck/mce.h +0 -1
index bea08bdc7464..dd5d258362e6 100644
@@ -7,7 +7,6 @@
 #include <xen/sched.h>
 #include <xen/smp.h>
 
-#include <asm/types.h>
 #include <asm/traps.h>
 #include <asm/atomic.h>
 
xen/arch/x86/cpu/vpmu.c +0 -1
index f31c32bcf3a6..a022126f18fd 100644
@@ -14,7 +14,6 @@
 #include <xen/hypercall.h>
 #include <xen/sched.h>
 #include <asm/regs.h>
-#include <asm/types.h>
 #include <asm/msr.h>
 #include <asm/nmi.h>
 #include <asm/p2m.h>
xen/arch/x86/cpu/vpmu_intel.c +0 -1
index 35e350578b84..ab122b22f3ac 100644
@@ -12,7 +12,6 @@
 #include <xen/xenoprof.h>
 #include <asm/system.h>
 #include <asm/regs.h>
-#include <asm/types.h>
 #include <asm/apic.h>
 #include <asm/traps.h>
 #include <asm/msr.h>
xen/arch/x86/hvm/hvm.c +0 -1
index a67ef79dc003..57363c2ae124 100644
@@ -38,7 +38,6 @@
 #include <asm/regs.h>
 #include <asm/cpufeature.h>
 #include <asm/processor.h>
-#include <asm/types.h>
 #include <asm/msr.h>
 #include <asm/i387.h>
 #include <asm/xstate.h>
xen/arch/x86/hvm/vmx/vvmx.c +0 -1
index 1034534c977b..16b0ef82b6c8 100644
@@ -10,7 +10,6 @@
 
 #include <xen/ioreq.h>
 
-#include <asm/types.h>
 #include <asm/mtrr.h>
 #include <asm/p2m.h>
 #include <asm/hvm/support.h>
xen/arch/x86/include/asm/byteorder.h +1 -1
index 1f77e502a528..e935f7b2b03b 100644
@@ -1,7 +1,7 @@
 #ifndef __ASM_X86_BYTEORDER_H__
 #define __ASM_X86_BYTEORDER_H__
 
-#include <asm/types.h>
+#include <xen/types.h>
 #include <xen/compiler.h>
 
 static inline __attribute_const__ __u32 ___arch__swab32(__u32 x)
xen/arch/x86/include/asm/hvm/svm/svmdebug.h +1 -1
index f1cde676dca1..2fb76ec24c76 100644
@@ -8,7 +8,7 @@
 #ifndef __ASM_X86_HVM_SVM_SVMDEBUG_H__
 #define __ASM_X86_HVM_SVM_SVMDEBUG_H__
 
-#include <asm/types.h>
+#include <xen/types.h>
 #include <asm/hvm/svm/vmcb.h>
 
 void svm_sync_vmcb(struct vcpu *v, enum vmcb_sync_state new_state);
xen/arch/x86/include/asm/hvm/vmx/vmx.h +2 -1
index 36c108d8797d..c84acc221daa 100644
@@ -8,7 +8,8 @@
 #define __ASM_X86_HVM_VMX_VMX_H__
 
 #include <xen/sched.h>
-#include <asm/types.h>
+#include <xen/types.h>
+
 #include <asm/regs.h>
 #include <asm/asm_defns.h>
 #include <asm/processor.h>
xen/arch/x86/include/asm/io_apic.h +2 -1
index ef0878b09e24..bd8cb95f46b1 100644
@@ -1,7 +1,8 @@
 #ifndef __ASM_IO_APIC_H
 #define __ASM_IO_APIC_H
 
-#include <asm/types.h>
+#include <xen/types.h>
+
 #include <asm/mpspec.h>
 #include <asm/apicdef.h>
 #include <asm/fixmap.h>
xen/arch/x86/include/asm/page.h +1 -1
index b585235d064a..3647bb1260c2 100644
@@ -9,7 +9,7 @@
 #define PAGE_ORDER_1G       18
 
 #ifndef __ASSEMBLY__
-# include <asm/types.h>
+# include <xen/types.h>
 # include <xen/lib.h>
 #endif
 
xen/arch/x86/include/asm/processor.h +0 -1
index f983ff501d95..3b3cf51814f8 100644
@@ -9,7 +9,6 @@
 #include <xen/types.h>
 #include <xen/smp.h>
 #include <xen/percpu.h>
-#include <asm/types.h>
 #include <asm/cpufeature.h>
 #include <asm/desc.h>
 #endif
xen/arch/x86/include/asm/x86_64/page.h +1 -1
index 26bdb4b19bb9..53faa7875baf 100644
@@ -19,7 +19,7 @@ static inline unsigned long canonicalise_addr(unsigned long addr)
         return addr & ~CANONICAL_MASK;
 }
 
-#include <asm/types.h>
+#include <xen/types.h>
 
 #include <xen/pdx.h>
 
xen/arch/x86/mm/p2m-ept.c +0 -1
index ffd34a1cc65f..85c4e8e54f66 100644
@@ -11,7 +11,6 @@
 #include <asm/current.h>
 #include <asm/iocap.h>
 #include <asm/paging.h>
-#include <asm/types.h>
 #include <asm/domain.h>
 #include <asm/p2m.h>
 #include <asm/hvm/vmx/vmx.h>
xen/common/trace.c +0 -1
index df4a719e4b43..17d62f70561f 100644
@@ -16,7 +16,6 @@
  * it's possible to reconstruct a chronological record of trace events.
  */
 
-#include <asm/types.h>
 #include <asm/io.h>
 #include <xen/lib.h>
 #include <xen/param.h>
xen/drivers/char/arm-uart.c +1 -1
index eeb9ceefc06a..8098a968c285 100644
@@ -18,7 +18,7 @@
  */
 
 #include <asm/device.h>
-#include <asm/types.h>
+
 #include <xen/console.h>
 #include <xen/device_tree.h>
 #include <xen/param.h>
xen/include/xen/bitops.h +1 -1
index 33619a0873fe..4cd0310789b5 100644
@@ -1,6 +1,6 @@
 #ifndef _LINUX_BITOPS_H
 #define _LINUX_BITOPS_H
-#include <asm/types.h>
+#include <xen/types.h>
 
 /*
  * Create a contiguous bitmask starting at bit position @l and ending at
xen/include/xen/spinlock.h +2 -1
index ca40c71c88f9..0a02a527dc59 100644
@@ -2,9 +2,10 @@
 #define __SPINLOCK_H__
 
 #include <xen/time.h>
+#include <xen/types.h>
+
 #include <asm/system.h>
 #include <asm/spinlock.h>
-#include <asm/types.h>
 
 #define SPINLOCK_CPU_BITS  12
 
Signature · 1 line
2.30.2
Acked-by on v2 2/3
#4 lore raw

Re: [PATCH v2 2/3] treewide: Avoid including asm/types.h

Quoted 10 lines · Andrew Cooper

We're about to rearrange the common and arch types.h split. While most users already include <xen/types.h>, a few do not and some files fail to compile as a result.

Almost all logic is going to have types very early in the include chain. Drop the include entirely from C files, and swap to the common types.h in headers.

No functional change.

#5 lore raw

PATCH v2 3/3 xen/types: Rework stdint vs __{u,s}$N types

In reply to Andrew Cooper

Xen uses the stdint types. Rearrange the types headers to define the compatibility __{u,s}$N types in terms of the stdint types, not the other way around.

All all supported compilers on architectures other than x86 support the stdint __*_TYPE__ macros. Move these into a new xen/stdint.h to avoid them being duplicated in each architecture.

For the compilers which don't support the __*_TYPE__ macros, synthesize appropriate alternatives.

This cleanup has the side effect of removing all use of the undocumented __signed__ GCC keyword. This is a vestigial remnant of gcc -traditional mode for dialetcs of C prior to the introduction of the signed keyword.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Bob Eshleman <[email protected]>
CC: Alistair Francis <[email protected]>
CC: Connor Davis <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Shawn Anastasio <[email protected]>
CC: Timothy Pearson <[email protected]>
CC: Roberto Bagnara <[email protected]>

v2:
* Introduce xen/stdint.h as discussed at XenSummit

---
 xen/arch/arm/include/asm/types.h   | 19 -----------------
 xen/arch/riscv/include/asm/types.h | 19 -----------------
 xen/arch/x86/include/asm/types.h   | 14 -------------
 xen/include/xen/stdint.h           | 33 ++++++++++++++++++++++++++++++
 xen/include/xen/types.h            | 20 ++++++++----------
 5 files changed, 42 insertions(+), 63 deletions(-)
 create mode 100644 xen/include/xen/stdint.h
xen/arch/arm/include/asm/types.h +0 -19
index fb6618ef247f..545a5e9d1175 100644
@@ -1,25 +1,6 @@
 #ifndef __ARM_TYPES_H__
 #define __ARM_TYPES_H__
 
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-#if defined(CONFIG_ARM_32)
-typedef __signed__ long long __s64;
-typedef unsigned long long __u64;
-#elif defined (CONFIG_ARM_64)
-typedef __signed__ long __s64;
-typedef unsigned long __u64;
-#endif
-#endif
-
 typedef signed char s8;
 typedef unsigned char u8;
 
xen/arch/riscv/include/asm/types.h +0 -19
index 0c0ce78c8f6e..93a680a8f323 100644
@@ -1,25 +1,6 @@
 #ifndef __RISCV_TYPES_H__
 #define __RISCV_TYPES_H__
 
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-#if defined(CONFIG_RISCV_32)
-typedef __signed__ long long __s64;
-typedef unsigned long long __u64;
-#elif defined (CONFIG_RISCV_64)
-typedef __signed__ long __s64;
-typedef unsigned long __u64;
-#endif
-#endif
-
 typedef signed char s8;
 typedef unsigned char u8;
 
xen/arch/x86/include/asm/types.h +0 -14
index 2d56aed66782..c9d257716551 100644
@@ -1,20 +1,6 @@
 #ifndef __X86_TYPES_H__
 #define __X86_TYPES_H__
 
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-typedef __signed__ long __s64;
-typedef unsigned long __u64;
-#endif
-
 typedef signed char s8;
 typedef unsigned char u8;
 
xen/include/xen/stdint.h new file +33 -0
new file mode 100644
index 000000000000..4cf82790f196
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __XEN_STDINT_H__
+#define __XEN_STDINT_H__
+
+#ifndef __INT8_TYPE__ /* GCC <= 4.4 */
+
+typedef __INT8_TYPE__        int8_t;
+typedef __UINT8_TYPE__      uint8_t;
+typedef __INT16_TYPE__      int16_t;
+typedef __UINT16_TYPE__    uint16_t;
+typedef __INT32_TYPE__      int32_t;
+typedef __UINT32_TYPE__    uint32_t;
+typedef __INT64_TYPE__      int64_t;
+typedef __UINT64_TYPE__    uint64_t;
+
+#else
+
+/*
+ * Define the types using GCC internal notation.  Clang understands this too.
+ * https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
+ */
+typedef   signed __attribute__((__mode__(QI)))     int8_t;
+typedef unsigned __attribute__((__mode__(QI)))    uint8_t;
+typedef   signed __attribute__((__mode__(HI)))    int16_t;
+typedef unsigned __attribute__((__mode__(HI)))   uint16_t;
+typedef   signed __attribute__((__mode__(SI)))    int32_t;
+typedef unsigned __attribute__((__mode__(SI)))   uint32_t;
+typedef   signed __attribute__((__mode__(DI)))    int64_t;
+typedef unsigned __attribute__((__mode__(DI)))   uint64_t;
+
+#endif
+
+#endif /* __XEN_STDINT_H__ */
xen/include/xen/types.h +9 -11
index 8b22a02eeaa4..c873c81ccf06 100644
@@ -2,6 +2,7 @@
 #define __TYPES_H__
 
 #include <xen/stdbool.h>
+#include <xen/stdint.h>
 
 #include <asm/types.h>
 
@@ -39,17 +40,14 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t;
 #define LONG_MIN        (-LONG_MAX - 1)
 #define ULONG_MAX       (~0UL)
 
-typedef         __u8            uint8_t;
-typedef         __s8            int8_t;
-
-typedef         __u16           uint16_t;
-typedef         __s16           int16_t;
-
-typedef         __u32           uint32_t;
-typedef         __s32           int32_t;
-
-typedef         __u64           uint64_t;
-typedef         __s64           int64_t;
+typedef uint8_t         __u8;
+typedef int8_t          __s8;
+typedef uint16_t        __u16;
+typedef int16_t         __s16;
+typedef uint32_t        __u32;
+typedef int32_t         __s32;
+typedef uint64_t        __u64;
+typedef int64_t         __s64;
 
 typedef __u16 __le16;
 typedef __u16 __be16;
Signature · 1 line
2.30.2
Reviewed-by on v2 3/3
#6 lore raw

Re: [PATCH v2 3/3] xen/types: Rework stdint vs __{u,s}$N types

Quoted 220 lines · Andrew Cooper

Xen uses the stdint types.  Rearrange the types headers to define the compatibility __{u,s}$N types in terms of the stdint types, not the other way
around.

All all supported compilers on architectures other than x86 support the stdint
__*_TYPE__ macros.  Move these into a new xen/stdint.h to avoid them being
duplicated in each architecture.

For the compilers which don't support the __*_TYPE__ macros, synthesize
appropriate alternatives.

This cleanup has the side effect of removing all use of the undocumented
__signed__ GCC keyword.  This is a vestigial remnant of gcc - traditional
mode for dialetcs of C prior to the introduction of the signed keyword.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Bob Eshleman <[email protected]>
CC: Alistair Francis <[email protected]>
CC: Connor Davis <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Shawn Anastasio <[email protected]>
CC: Timothy Pearson <[email protected]>
CC: Roberto Bagnara <[email protected]>

v2:
 * Introduce xen/stdint.h as discussed at XenSummit
---
 xen/arch/arm/include/asm/types.h   | 19 ----------------- xen/arch/riscv/include/asm/types.h | 19 ----------------- xen/arch/x86/include/asm/types.h   | 14 ------------- xen/include/xen/stdint.h           | 33
++++++++++++++++++++++++++++++
 xen/include/xen/types.h            | 20 ++++++++----------

 5 files changed, 42 insertions(+), 63 deletions(-)

 create mode 100644 xen/include/xen/stdint.h

xen/arch/arm/include/asm/types.h +0 -0
index fb6618ef247f..545a5e9d1175 100644
@@ -1,25 +1,6 @@
  #ifndef __ARM_TYPES_H__
  #define __ARM_TYPES_H__

xen/arch/arm/include/asm/types.h +0 -19
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-#if defined(CONFIG_ARM_32)
-typedef __signed__ long long __s64;
-typedef unsigned long long __u64;
-#elif defined (CONFIG_ARM_64)
-typedef __signed__ long __s64;
-typedef unsigned long __u64;
-#endif
-#endif
-

 typedef signed char s8;
 typedef unsigned char u8;

xen/arch/riscv/include/asm/types.h +0 -0
index 0c0ce78c8f6e..93a680a8f323 100644
@@ -1,25 +1,6 @@
  #ifndef __RISCV_TYPES_H__
  #define __RISCV_TYPES_H__

xen/arch/riscv/include/asm/types.h +0 -19
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-#if defined(CONFIG_RISCV_32)
-typedef __signed__ long long __s64;
-typedef unsigned long long __u64;
-#elif defined (CONFIG_RISCV_64)
-typedef __signed__ long __s64;
-typedef unsigned long __u64;
-#endif
-#endif
-

 typedef signed char s8;
 typedef unsigned char u8;

xen/arch/x86/include/asm/types.h +0 -0
index 2d56aed66782..c9d257716551 100644
@@ -1,20 +1,6 @@
  #ifndef __X86_TYPES_H__
  #define __X86_TYPES_H__

xen/arch/x86/include/asm/types.h +0 -14
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-typedef __signed__ long __s64;
-typedef unsigned long __u64;
-#endif
-

 typedef signed char s8;
 typedef unsigned char u8;

xen/include/xen/stdint.h new file +19 -0
new file mode 100644
index 000000000000..4cf82790f196
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __XEN_STDINT_H__
+#define __XEN_STDINT_H__
+
+#ifndef __INT8_TYPE__ /* GCC <= 4.4 */
+
+typedef __INT8_TYPE__        int8_t;
+typedef __UINT8_TYPE__      uint8_t;
+typedef __INT16_TYPE__      int16_t;
+typedef __UINT16_TYPE__    uint16_t;
+typedef __INT32_TYPE__      int32_t;
+typedef __UINT32_TYPE__    uint32_t;
+typedef __INT64_TYPE__      int64_t;
+typedef __UINT64_TYPE__    uint64_t;
+
+#else
+
+/*
+ * Define the types using GCC internal notation.  Clang understands

this too.
+ *
https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
+ */

xen/include/xen/stdint.h new file +12 -0
+typedef   signed __attribute__((__mode__(QI)))     int8_t;
+typedef unsigned __attribute__((__mode__(QI)))    uint8_t;
+typedef   signed __attribute__((__mode__(HI)))    int16_t;
+typedef unsigned __attribute__((__mode__(HI)))   uint16_t;
+typedef   signed __attribute__((__mode__(SI)))    int32_t;
+typedef unsigned __attribute__((__mode__(SI)))   uint32_t;
+typedef   signed __attribute__((__mode__(DI)))    int64_t;
+typedef unsigned __attribute__((__mode__(DI)))   uint64_t;
+
+#endif
+
+#endif /* __XEN_STDINT_H__ */
xen/include/xen/types.h +0 -0
index 8b22a02eeaa4..c873c81ccf06 100644
@@ -2,6 +2,7 @@
  #define __TYPES_H__


 #include <xen/stdbool.h>
+#include <xen/stdint.h>

 #include <asm/types.h>

xen/include/xen/types.h +0 -0
@@ -39,17 +40,14 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t;
  #define LONG_MIN        (-LONG_MAX - 1)
  #define ULONG_MAX       (~0UL)

xen/include/xen/types.h +8 -11
-typedef         __u8            uint8_t;
-typedef         __s8            int8_t;
-
-typedef         __u16           uint16_t;
-typedef         __s16           int16_t;
-
-typedef         __u32           uint32_t;
-typedef         __s32           int32_t;
-
-typedef         __u64           uint64_t;
-typedef         __s64           int64_t;
+typedef uint8_t         __u8;
+typedef int8_t          __s8;
+typedef uint16_t        __u16;
+typedef int16_t         __s16;
+typedef uint32_t        __u32;
+typedef int32_t         __s32;
+typedef uint64_t        __u64;
+typedef int64_t         __s64;


 typedef __u16 __le16;
 typedef __u16 __be16;

#7 lore raw

Re: [PATCH v2 3/3] xen/types: Rework stdint vs __{u,s}$N types

In reply to Andrew Cooper
Quoted 5 lines · Andrew Cooper

Xen uses the stdint types. Rearrange the types headers to define the compatibility __{u,s}$N types in terms of the stdint types, not the other way around.

All all supported compilers on architectures other than x86 support the stdint

Duplicated "all".

xen/include/xen/stdint.h line 5

Quoted 11 lines
xen/include/xen/stdint.h new file +5 -0
new file mode 100644
index 000000000000..4cf82790f196
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __XEN_STDINT_H__
+#define __XEN_STDINT_H__
+
+#ifndef __INT8_TYPE__ /* GCC <= 4.4 */

I'm possibly confused, but don't you want to use __INT8_TYPE__ if it's defined, and hence this should be an ifdef instead of an ifndef?

xen/include/xen/stdint.h line 14

Quoted 9 lines
xen/include/xen/stdint.h new file +9 -0
+
+typedef __INT8_TYPE__        int8_t;
+typedef __UINT8_TYPE__      uint8_t;
+typedef __INT16_TYPE__      int16_t;
+typedef __UINT16_TYPE__    uint16_t;
+typedef __INT32_TYPE__      int32_t;
+typedef __UINT32_TYPE__    uint32_t;
+typedef __INT64_TYPE__      int64_t;
+typedef __UINT64_TYPE__    uint64_t;

Thanks, Roger.

#8 lore raw

Re: [PATCH v2 3/3] xen/types: Rework stdint vs __{u,s}$N types

Quoted 7 lines · Roger Pau Monné
Quoted 5 lines · Andrew Cooper

Xen uses the stdint types. Rearrange the types headers to define the compatibility __{u,s}$N types in terms of the stdint types, not the other way around.

All all supported compilers on architectures other than x86 support the stdint

Duplicated "all".

Yeah, already noticed and adjusted.

Quoted 14 lines

xen/include/xen/stdint.h line 5

Quoted 12 lines
xen/include/xen/stdint.h new file +5 -0
new file mode 100644
index 000000000000..4cf82790f196
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __XEN_STDINT_H__
+#define __XEN_STDINT_H__
+
+#ifndef __INT8_TYPE__ /* GCC <= 4.4 */

I'm possibly confused, but don't you want to use __INT8_TYPE__ if it's defined, and hence this should be an ifdef instead of an ifndef?

You're right.  I was too tired while putting this together.

Originally, this was going to be

#ifndef __INT8_TYPE__
#define __INT8_TYPE__ ...
#endif

typedef ...;

but decided to get rid of the intermediate and use a plain if/else. I'll fix.

~Andrew

#9 lore raw

PATCH v2 3/3 xen/types: Rework stdint vs __{u,s}$N types

In reply to Andrew Cooper

Xen uses the stdint types. Rearrange the types headers to define the compatibility __{u,s}$N types in terms of the stdint types, not the other way around.

All supported compilers on architectures other than x86 support the stdint __*_TYPE__ macros. Move these into a new xen/stdint.h to avoid them being duplicated in each architecture. For the very old x86 compilers, synthesize suitable types using GCC internals.

This cleanup has the side effect of removing all use of the undocumented __signed__ GCC keyword. This is a vestigial remnant of gcc -traditional mode for dialetcs of C prior to the introduction of the signed keyword.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Bob Eshleman <[email protected]>
CC: Alistair Francis <[email protected]>
CC: Connor Davis <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Shawn Anastasio <[email protected]>
CC: Timothy Pearson <[email protected]>
CC: Roberto Bagnara <[email protected]>

v2.5:
* Get the #ifdef-ary the right way around
v2:
* Introduce xen/stdint.h as discussed at XenSummit

---
 xen/arch/arm/include/asm/types.h   | 19 -----------------
 xen/arch/riscv/include/asm/types.h | 19 -----------------
 xen/arch/x86/include/asm/types.h   | 14 -------------
 xen/include/xen/stdint.h           | 33 ++++++++++++++++++++++++++++++
 xen/include/xen/types.h            | 20 ++++++++----------
 5 files changed, 42 insertions(+), 63 deletions(-)
 create mode 100644 xen/include/xen/stdint.h
xen/arch/arm/include/asm/types.h +0 -19
index fb6618ef247f..545a5e9d1175 100644
@@ -1,25 +1,6 @@
 #ifndef __ARM_TYPES_H__
 #define __ARM_TYPES_H__
 
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-#if defined(CONFIG_ARM_32)
-typedef __signed__ long long __s64;
-typedef unsigned long long __u64;
-#elif defined (CONFIG_ARM_64)
-typedef __signed__ long __s64;
-typedef unsigned long __u64;
-#endif
-#endif
-
 typedef signed char s8;
 typedef unsigned char u8;
 
xen/arch/riscv/include/asm/types.h +0 -19
index 0c0ce78c8f6e..93a680a8f323 100644
@@ -1,25 +1,6 @@
 #ifndef __RISCV_TYPES_H__
 #define __RISCV_TYPES_H__
 
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-#if defined(CONFIG_RISCV_32)
-typedef __signed__ long long __s64;
-typedef unsigned long long __u64;
-#elif defined (CONFIG_RISCV_64)
-typedef __signed__ long __s64;
-typedef unsigned long __u64;
-#endif
-#endif
-
 typedef signed char s8;
 typedef unsigned char u8;
 
xen/arch/x86/include/asm/types.h +0 -14
index 2d56aed66782..c9d257716551 100644
@@ -1,20 +1,6 @@
 #ifndef __X86_TYPES_H__
 #define __X86_TYPES_H__
 
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-typedef __signed__ long __s64;
-typedef unsigned long __u64;
-#endif
-
 typedef signed char s8;
 typedef unsigned char u8;
 
xen/include/xen/stdint.h new file +33 -0
new file mode 100644
index 000000000000..8c8a5899373a
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __XEN_STDINT_H__
+#define __XEN_STDINT_H__
+
+#ifndef __INT8_TYPE__ /* GCC <= 4.4 */
+
+/*
+ * Define the types using GCC internal notation.  Clang understands this too.
+ * https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
+ */
+typedef   signed __attribute__((__mode__(QI)))     int8_t;
+typedef unsigned __attribute__((__mode__(QI)))    uint8_t;
+typedef   signed __attribute__((__mode__(HI)))    int16_t;
+typedef unsigned __attribute__((__mode__(HI)))   uint16_t;
+typedef   signed __attribute__((__mode__(SI)))    int32_t;
+typedef unsigned __attribute__((__mode__(SI)))   uint32_t;
+typedef   signed __attribute__((__mode__(DI)))    int64_t;
+typedef unsigned __attribute__((__mode__(DI)))   uint64_t;
+
+#else
+
+typedef __INT8_TYPE__        int8_t;
+typedef __UINT8_TYPE__      uint8_t;
+typedef __INT16_TYPE__      int16_t;
+typedef __UINT16_TYPE__    uint16_t;
+typedef __INT32_TYPE__      int32_t;
+typedef __UINT32_TYPE__    uint32_t;
+typedef __INT64_TYPE__      int64_t;
+typedef __UINT64_TYPE__    uint64_t;
+
+#endif
+
+#endif /* __XEN_STDINT_H__ */
xen/include/xen/types.h +9 -11
index 8b22a02eeaa4..c873c81ccf06 100644
@@ -2,6 +2,7 @@
 #define __TYPES_H__
 
 #include <xen/stdbool.h>
+#include <xen/stdint.h>
 
 #include <asm/types.h>
 
@@ -39,17 +40,14 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t;
 #define LONG_MIN        (-LONG_MAX - 1)
 #define ULONG_MAX       (~0UL)
 
-typedef         __u8            uint8_t;
-typedef         __s8            int8_t;
-
-typedef         __u16           uint16_t;
-typedef         __s16           int16_t;
-
-typedef         __u32           uint32_t;
-typedef         __s32           int32_t;
-
-typedef         __u64           uint64_t;
-typedef         __s64           int64_t;
+typedef uint8_t         __u8;
+typedef int8_t          __s8;
+typedef uint16_t        __u16;
+typedef int16_t         __s16;
+typedef uint32_t        __u32;
+typedef int32_t         __s32;
+typedef uint64_t        __u64;
+typedef int64_t         __s64;
 
 typedef __u16 __le16;
 typedef __u16 __be16;
Signature · 1 line
2.30.2
Reviewed-by on v2 3/3
#10 lore raw

Re: [PATCH v2.5 3/3] xen/types: Rework stdint vs __{u,s}$N types

Quoted 9 lines · Andrew Cooper

Xen uses the stdint types. Rearrange the types headers to define the compatibility __{u,s}$N types in terms of the stdint types, not the other way around.

All supported compilers on architectures other than x86 support the stdint __*_TYPE__ macros. Move these into a new xen/stdint.h to avoid them being duplicated in each architecture. For the very old x86 compilers, synthesize suitable types using GCC internals.

Quoted 7 lines

This cleanup has the side effect of removing all use of the undocumented __signed__ GCC keyword. This is a vestigial remnant of gcc -traditional mode for dialetcs of C prior to the introduction of the signed keyword.

No functional change.

with one further remark:

Quoted 11 lines
xen/include/xen/stdint.h new file +8 -0
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __XEN_STDINT_H__
+#define __XEN_STDINT_H__
+
+#ifndef __INT8_TYPE__ /* GCC <= 4.4 */
+
+/*
+ * Define the types using GCC internal notation.  Clang understands this too.

xen/include/xen/stdint.h line 18

Quoted 10 lines
xen/include/xen/stdint.h new file +10 -0
+ * https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
+ */
+typedef   signed __attribute__((__mode__(QI)))     int8_t;
+typedef unsigned __attribute__((__mode__(QI)))    uint8_t;
+typedef   signed __attribute__((__mode__(HI)))    int16_t;
+typedef unsigned __attribute__((__mode__(HI)))   uint16_t;
+typedef   signed __attribute__((__mode__(SI)))    int32_t;
+typedef unsigned __attribute__((__mode__(SI)))   uint32_t;
+typedef   signed __attribute__((__mode__(DI)))    int64_t;
+typedef unsigned __attribute__((__mode__(DI)))   uint64_t;

Much like you avoid "mode" potentially being the name of a visible macro, the mode identifiers themselves could in principle be, too. Being upper case names, perhaps there the risk is even slightly higher. Hence I'd prefer if you/we could use __QI__ and alike.

Jan

#11 lore raw

Re: [PATCH v2.5 3/3] xen/types: Rework stdint vs __{u,s}$N types

Quoted 10 lines · Jan Beulich
Quoted 9 lines · Andrew Cooper

Xen uses the stdint types. Rearrange the types headers to define the compatibility __{u,s}$N types in terms of the stdint types, not the other way around.

All supported compilers on architectures other than x86 support the stdint __*_TYPE__ macros. Move these into a new xen/stdint.h to avoid them being duplicated in each architecture. For the very old x86 compilers, synthesize suitable types using GCC internals.

Quoted 8 lines
Quoted 7 lines

This cleanup has the side effect of removing all use of the undocumented __signed__ GCC keyword. This is a vestigial remnant of gcc -traditional mode for dialetcs of C prior to the introduction of the signed keyword.

No functional change.

Thanks.

Quoted 19 lines

with one further remark:

Quoted 17 lines
xen/include/xen/stdint.h new file +14 -0
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __XEN_STDINT_H__
+#define __XEN_STDINT_H__
+
+#ifndef __INT8_TYPE__ /* GCC <= 4.4 */
+
+/*
+ * Define the types using GCC internal notation.  Clang understands this too.
+ * https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
+ */
+typedef   signed __attribute__((__mode__(QI)))     int8_t;
+typedef unsigned __attribute__((__mode__(QI)))    uint8_t;
+typedef   signed __attribute__((__mode__(HI)))    int16_t;
+typedef unsigned __attribute__((__mode__(HI)))   uint16_t;
Quoted 8 lines

xen/include/xen/stdint.h line 18

Quoted 4 lines
xen/include/xen/stdint.h new file +4 -0
+typedef   signed __attribute__((__mode__(SI)))    int32_t;
+typedef unsigned __attribute__((__mode__(SI)))   uint32_t;
+typedef   signed __attribute__((__mode__(DI)))    int64_t;
+typedef unsigned __attribute__((__mode__(DI)))   uint64_t;

Much like you avoid "mode" potentially being the name of a visible macro, the mode identifiers themselves could in principle be, too. Being upper case names, perhaps there the risk is even slightly higher. Hence I'd prefer if you/we could use __QI__ and alike.

Fixed locally.  I won't resend for just this.

~Andrew

Acked-by on the v2 series
#12 lore raw
In reply to Andrew Cooper
Quoted 9 lines · Andrew Cooper

v2, adjusted per the discussion at XenSummit

https://cirrus-ci.com/build/6611877547999232
https://gitlab.com/xen-project/people/andyhhp/xen/-/pipelines/912782128

Andrew Cooper (3):
xen/types: Drop #ifdefary for __{SIZE,PTRDIFF}_TYPE__
treewide: Avoid including asm/types.h xen/types: Rework stdint vs __{u,s}$N types

For the series (including v2.5):

Cheers,

Signature · 1 line
Julien Grall