diff mbox series

[v2,4/4] xen/public: replace remaining int and long

Message ID 20240410234740.994001-4-stefano.stabellini@amd.com (mailing list archive)
State New, archived
Headers show
Series xen/public: use fixed-size integers | expand

Commit Message

Stefano Stabellini April 10, 2024, 11:47 p.m. UTC
Replace all int and long in few remaining x86-specific headers and
x86-specific hypercalls.

Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
---
 xen/include/public/arch-x86/hvm/save.h   |  4 +-
 xen/include/public/arch-x86/xen-x86_32.h | 10 ++---
 xen/include/public/arch-x86/xen-x86_64.h | 10 ++---
 xen/include/public/arch-x86/xen.h        | 50 ++++++++++++------------
 xen/include/public/xen.h                 | 24 ++++++------
 5 files changed, 49 insertions(+), 49 deletions(-)

Comments

Jan Beulich April 18, 2024, 7:04 a.m. UTC | #1
On 11.04.2024 01:47, Stefano Stabellini wrote:
> --- a/xen/include/public/arch-x86/hvm/save.h
> +++ b/xen/include/public/arch-x86/hvm/save.h
> @@ -415,7 +415,7 @@ struct hvm_hw_pci_irqs {
>       * Indexed by: device*4 + INTx#.
>       */
>      union {
> -        unsigned long i[16 / sizeof (unsigned long)]; /* DECLARE_BITMAP(i, 32*4); */
> +        xen_ulong_t i[16 / sizeof (xen_ulong_t)]; /* DECLARE_BITMAP(i, 32*4); */
>          uint64_t pad[2];
>      };
>  };
> @@ -428,7 +428,7 @@ struct hvm_hw_isa_irqs {
>       * Indexed by ISA IRQ (assumes no ISA-device IRQ sharing).
>       */
>      union {
> -        unsigned long i[1];  /* DECLARE_BITMAP(i, 16); */
> +        xen_ulong_t i[1];  /* DECLARE_BITMAP(i, 16); */
>          uint64_t pad[1];
>      };
>  };

Taking just this as example: Why is this not part of patch 3? If there was
"x86" somewhere in the title, I could probably see a reason for such
separation.

> --- a/xen/include/public/arch-x86/xen-x86_32.h
> +++ b/xen/include/public/arch-x86/xen-x86_32.h
> @@ -68,7 +68,7 @@
>  #define MACH2PHYS_VIRT_END    xen_mk_ulong(__MACH2PHYS_VIRT_END)
>  #define MACH2PHYS_NR_ENTRIES  ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>2)
>  #ifndef machine_to_phys_mapping
> -#define machine_to_phys_mapping ((unsigned long *)MACH2PHYS_VIRT_START)
> +#define machine_to_phys_mapping ((xen_ulong_t *)MACH2PHYS_VIRT_START)

While making this (and the corresponding 64-bit) adjustment, we ought to
at least consider to also add const. The overall change is at risk of being
disruptive to consumers anyway, in case they use less lax compilers than
e.g. gcc and Clang are: "unsigned int" and "uint32_t", even if both 32 bits
wide, don't necessarily need to be treated as the same type by the compiler.
In fact portability of code would be increased if compilers insisted on
clearly distinguishing the two.

In fact because of this it may want considering to split the conversions of
"long" from those of "int", just to cover the remote possibility of the
latter needing reverting from some reason.

> --- a/xen/include/public/arch-x86/xen.h
> +++ b/xen/include/public/arch-x86/xen.h
> @@ -141,7 +141,7 @@ struct trap_info {
>      uint8_t       vector;  /* exception vector                              */
>      uint8_t       flags;   /* 0-3: privilege level; 4: clear event enable?  */
>      uint16_t      cs;      /* code selector                                 */
> -    unsigned long address; /* code offset                                   */
> +    xen_ulong_t address;   /* code offset                                   */
>  };

Nit: Please add two padding blanks to retain columnar arrangement of field
names.

> @@ -174,36 +174,36 @@ struct vcpu_guest_context {
>  #define VGCF_syscall_disables_events   (1<<_VGCF_syscall_disables_events)
>  #define _VGCF_online                   5
>  #define VGCF_online                    (1<<_VGCF_online)
> -    unsigned long flags;                    /* VGCF_* flags                 */
> -    struct cpu_user_regs user_regs;         /* User-level CPU registers     */
> -    struct trap_info trap_ctxt[256];        /* Virtual IDT                  */
> -    unsigned long ldt_base, ldt_ents;       /* LDT (linear address, # ents) */
> -    unsigned long gdt_frames[16], gdt_ents; /* GDT (machine frames, # ents) */
> -    unsigned long kernel_ss, kernel_sp;     /* Virtual TSS (only SS1/SP1)   */
> +    xen_ulong_t flags;                    /* VGCF_* flags                 */
> +    struct cpu_user_regs user_regs;       /* User-level CPU registers     */
> +    struct trap_info trap_ctxt[256];      /* Virtual IDT                  */

Please can these two lines remain untouched, and other lines instead have
padding blanks added to keep comments aligned?

> @@ -228,7 +228,7 @@ struct arch_shared_info {
>       * is to be used.
>       */
>      xen_pfn_t     pfn_to_mfn_frame_list_list;
> -    unsigned long nmi_reason;
> +    xen_ulong_t nmi_reason;

Nit: Here there again want to be two padding blanks.

Jan
diff mbox series

Patch

diff --git a/xen/include/public/arch-x86/hvm/save.h b/xen/include/public/arch-x86/hvm/save.h
index 7ecacadde1..8e3dfcf439 100644
--- a/xen/include/public/arch-x86/hvm/save.h
+++ b/xen/include/public/arch-x86/hvm/save.h
@@ -415,7 +415,7 @@  struct hvm_hw_pci_irqs {
      * Indexed by: device*4 + INTx#.
      */
     union {
-        unsigned long i[16 / sizeof (unsigned long)]; /* DECLARE_BITMAP(i, 32*4); */
+        xen_ulong_t i[16 / sizeof (xen_ulong_t)]; /* DECLARE_BITMAP(i, 32*4); */
         uint64_t pad[2];
     };
 };
@@ -428,7 +428,7 @@  struct hvm_hw_isa_irqs {
      * Indexed by ISA IRQ (assumes no ISA-device IRQ sharing).
      */
     union {
-        unsigned long i[1];  /* DECLARE_BITMAP(i, 16); */
+        xen_ulong_t i[1];  /* DECLARE_BITMAP(i, 16); */
         uint64_t pad[1];
     };
 };
diff --git a/xen/include/public/arch-x86/xen-x86_32.h b/xen/include/public/arch-x86/xen-x86_32.h
index 9e3bf06b12..0b2671ab65 100644
--- a/xen/include/public/arch-x86/xen-x86_32.h
+++ b/xen/include/public/arch-x86/xen-x86_32.h
@@ -68,7 +68,7 @@ 
 #define MACH2PHYS_VIRT_END    xen_mk_ulong(__MACH2PHYS_VIRT_END)
 #define MACH2PHYS_NR_ENTRIES  ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>2)
 #ifndef machine_to_phys_mapping
-#define machine_to_phys_mapping ((unsigned long *)MACH2PHYS_VIRT_START)
+#define machine_to_phys_mapping ((xen_ulong_t *)MACH2PHYS_VIRT_START)
 #endif
 
 /* 32-/64-bit invariability for control interfaces (domctl/sysctl). */
@@ -151,14 +151,14 @@  DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t);
 #define xen_cr3_to_pfn(cr3) (((unsigned)(cr3) >> 12) | ((unsigned)(cr3) << 20))
 
 struct arch_vcpu_info {
-    unsigned long cr2;
-    unsigned long pad[5]; /* sizeof(vcpu_info_t) == 64 */
+    xen_ulong_t cr2;
+    xen_ulong_t pad[5]; /* sizeof(vcpu_info_t) == 64 */
 };
 typedef struct arch_vcpu_info arch_vcpu_info_t;
 
 struct xen_callback {
-    unsigned long cs;
-    unsigned long eip;
+    xen_ulong_t cs;
+    xen_ulong_t eip;
 };
 typedef struct xen_callback xen_callback_t;
 
diff --git a/xen/include/public/arch-x86/xen-x86_64.h b/xen/include/public/arch-x86/xen-x86_64.h
index 43f6e3d220..bd27fc59fe 100644
--- a/xen/include/public/arch-x86/xen-x86_64.h
+++ b/xen/include/public/arch-x86/xen-x86_64.h
@@ -67,7 +67,7 @@ 
 #define MACH2PHYS_VIRT_END    xen_mk_ulong(__MACH2PHYS_VIRT_END)
 #define MACH2PHYS_NR_ENTRIES  ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>3)
 #ifndef machine_to_phys_mapping
-#define machine_to_phys_mapping ((unsigned long *)HYPERVISOR_VIRT_START)
+#define machine_to_phys_mapping ((xen_ulong_t *)HYPERVISOR_VIRT_START)
 #endif
 
 /*
@@ -198,12 +198,12 @@  DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t);
 #undef __DECL_REG_LO16
 #undef __DECL_REG_HI
 
-#define xen_pfn_to_cr3(pfn) ((unsigned long)(pfn) << 12)
-#define xen_cr3_to_pfn(cr3) ((unsigned long)(cr3) >> 12)
+#define xen_pfn_to_cr3(pfn) ((xen_ulong_t)(pfn) << 12)
+#define xen_cr3_to_pfn(cr3) ((xen_ulong_t)(cr3) >> 12)
 
 struct arch_vcpu_info {
-    unsigned long cr2;
-    unsigned long pad; /* sizeof(vcpu_info_t) == 64 */
+    xen_ulong_t cr2;
+    xen_ulong_t pad; /* sizeof(vcpu_info_t) == 64 */
 };
 typedef struct arch_vcpu_info arch_vcpu_info_t;
 
diff --git a/xen/include/public/arch-x86/xen.h b/xen/include/public/arch-x86/xen.h
index a9a87d9b50..90710c1230 100644
--- a/xen/include/public/arch-x86/xen.h
+++ b/xen/include/public/arch-x86/xen.h
@@ -141,7 +141,7 @@  struct trap_info {
     uint8_t       vector;  /* exception vector                              */
     uint8_t       flags;   /* 0-3: privilege level; 4: clear event enable?  */
     uint16_t      cs;      /* code selector                                 */
-    unsigned long address; /* code offset                                   */
+    xen_ulong_t address;   /* code offset                                   */
 };
 typedef struct trap_info trap_info_t;
 DEFINE_XEN_GUEST_HANDLE(trap_info_t);
@@ -174,36 +174,36 @@  struct vcpu_guest_context {
 #define VGCF_syscall_disables_events   (1<<_VGCF_syscall_disables_events)
 #define _VGCF_online                   5
 #define VGCF_online                    (1<<_VGCF_online)
-    unsigned long flags;                    /* VGCF_* flags                 */
-    struct cpu_user_regs user_regs;         /* User-level CPU registers     */
-    struct trap_info trap_ctxt[256];        /* Virtual IDT                  */
-    unsigned long ldt_base, ldt_ents;       /* LDT (linear address, # ents) */
-    unsigned long gdt_frames[16], gdt_ents; /* GDT (machine frames, # ents) */
-    unsigned long kernel_ss, kernel_sp;     /* Virtual TSS (only SS1/SP1)   */
+    xen_ulong_t flags;                    /* VGCF_* flags                 */
+    struct cpu_user_regs user_regs;       /* User-level CPU registers     */
+    struct trap_info trap_ctxt[256];      /* Virtual IDT                  */
+    xen_ulong_t ldt_base, ldt_ents;       /* LDT (linear address, # ents) */
+    xen_ulong_t gdt_frames[16], gdt_ents; /* GDT (machine frames, # ents) */
+    xen_ulong_t kernel_ss, kernel_sp;     /* Virtual TSS (only SS1/SP1)   */
     /* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */
-    unsigned long ctrlreg[8];               /* CR0-CR7 (control registers)  */
-    unsigned long debugreg[8];              /* DB0-DB7 (debug registers)    */
+    xen_ulong_t ctrlreg[8];               /* CR0-CR7 (control registers)  */
+    xen_ulong_t debugreg[8];              /* DB0-DB7 (debug registers)    */
 #ifdef __i386__
-    unsigned long event_callback_cs;        /* CS:EIP of event callback     */
-    unsigned long event_callback_eip;
-    unsigned long failsafe_callback_cs;     /* CS:EIP of failsafe callback  */
-    unsigned long failsafe_callback_eip;
+    xen_ulong_t event_callback_cs;        /* CS:EIP of event callback     */
+    xen_ulong_t event_callback_eip;
+    xen_ulong_t failsafe_callback_cs;     /* CS:EIP of failsafe callback  */
+    xen_ulong_t failsafe_callback_eip;
 #else
-    unsigned long event_callback_eip;
-    unsigned long failsafe_callback_eip;
+    xen_ulong_t event_callback_eip;
+    xen_ulong_t failsafe_callback_eip;
 #ifdef __XEN__
     union {
-        unsigned long syscall_callback_eip;
+        xen_ulong_t syscall_callback_eip;
         struct {
-            unsigned int event_callback_cs;    /* compat CS of event cb     */
-            unsigned int failsafe_callback_cs; /* compat CS of failsafe cb  */
+            uint32_t event_callback_cs;    /* compat CS of event cb     */
+            uint32_t failsafe_callback_cs; /* compat CS of failsafe cb  */
         };
     };
 #else
-    unsigned long syscall_callback_eip;
+    xen_ulong_t syscall_callback_eip;
 #endif
 #endif
-    unsigned long vm_assist;                /* VMASST_TYPE_* bitmap */
+    xen_ulong_t vm_assist;                /* VMASST_TYPE_* bitmap */
 #ifdef __x86_64__
     /* Segment base addresses. */
     uint64_t      fs_base;
@@ -219,7 +219,7 @@  struct arch_shared_info {
      * Number of valid entries in the p2m table(s) anchored at
      * pfn_to_mfn_frame_list_list and/or p2m_vaddr.
      */
-    unsigned long max_pfn;
+    xen_ulong_t max_pfn;
     /*
      * Frame containing list of mfns containing list of mfns containing p2m.
      * A value of 0 indicates it has not yet been set up, ~0 indicates it has
@@ -228,7 +228,7 @@  struct arch_shared_info {
      * is to be used.
      */
     xen_pfn_t     pfn_to_mfn_frame_list_list;
-    unsigned long nmi_reason;
+    xen_ulong_t nmi_reason;
     /*
      * Following three fields are valid if p2m_cr3 contains a value different
      * from 0.
@@ -247,9 +247,9 @@  struct arch_shared_info {
      * Modifying a p2m element in the linear p2m list is allowed via an atomic
      * write only.
      */
-    unsigned long p2m_cr3;         /* cr3 value of the p2m address space */
-    unsigned long p2m_vaddr;       /* virtual address of the p2m list */
-    unsigned long p2m_generation;  /* generation count of p2m mapping */
+    xen_ulong_t p2m_cr3;         /* cr3 value of the p2m address space */
+    xen_ulong_t p2m_vaddr;       /* virtual address of the p2m list */
+    xen_ulong_t p2m_generation;  /* generation count of p2m mapping */
 #ifdef __i386__
     /* There's no room for this field in the generic structure. */
     uint32_t wc_sec_hi;
diff --git a/xen/include/public/xen.h b/xen/include/public/xen.h
index b47d48d0e2..2444e752ab 100644
--- a/xen/include/public/xen.h
+++ b/xen/include/public/xen.h
@@ -430,17 +430,17 @@  DEFINE_XEN_GUEST_HANDLE(xen_ulong_t);
 
 #ifndef __ASSEMBLY__
 struct mmuext_op {
-    unsigned int cmd; /* => enum mmuext_cmd */
+    uint32_t cmd; /* => enum mmuext_cmd */
     union {
         /* [UN]PIN_TABLE, NEW_BASEPTR, NEW_USER_BASEPTR
          * CLEAR_PAGE, COPY_PAGE, [UN]MARK_SUPER */
         xen_pfn_t     mfn;
         /* INVLPG_LOCAL, INVLPG_ALL, SET_LDT */
-        unsigned long linear_addr;
+        xen_ulong_t linear_addr;
     } arg1;
     union {
         /* SET_LDT */
-        unsigned int nr_ents;
+        uint32_t nr_ents;
         /* TLB_FLUSH_MULTI, INVLPG_MULTI */
 #if __XEN_INTERFACE_VERSION__ >= 0x00030205
         XEN_GUEST_HANDLE(const_void) vcpumask;
@@ -832,8 +832,8 @@  typedef struct shared_info shared_info_t;
 struct start_info {
     /* THE FOLLOWING ARE FILLED IN BOTH ON INITIAL BOOT AND ON RESUME.    */
     char magic[32];             /* "xen-<version>-<platform>".            */
-    unsigned long nr_pages;     /* Total pages allocated to this domain.  */
-    unsigned long shared_info;  /* MACHINE address of shared info struct. */
+    xen_ulong_t nr_pages;     /* Total pages allocated to this domain.  */
+    xen_ulong_t shared_info;  /* MACHINE address of shared info struct. */
     uint32_t flags;             /* SIF_xxx flags.                         */
     xen_pfn_t store_mfn;        /* MACHINE page number of shared page.    */
     uint32_t store_evtchn;      /* Event channel for store communication. */
@@ -848,18 +848,18 @@  struct start_info {
         } dom0;
     } console;
     /* THE FOLLOWING ARE ONLY FILLED IN ON INITIAL BOOT (NOT RESUME).     */
-    unsigned long pt_base;      /* VIRTUAL address of page directory.     */
-    unsigned long nr_pt_frames; /* Number of bootstrap p.t. frames.       */
-    unsigned long mfn_list;     /* VIRTUAL address of page-frame list.    */
-    unsigned long mod_start;    /* VIRTUAL address of pre-loaded module   */
+    xen_ulong_t pt_base;      /* VIRTUAL address of page directory.     */
+    xen_ulong_t nr_pt_frames; /* Number of bootstrap p.t. frames.       */
+    xen_ulong_t mfn_list;     /* VIRTUAL address of page-frame list.    */
+    xen_ulong_t mod_start;    /* VIRTUAL address of pre-loaded module   */
                                 /* (PFN of pre-loaded module if           */
                                 /*  SIF_MOD_START_PFN set in flags).      */
-    unsigned long mod_len;      /* Size (bytes) of pre-loaded module.     */
+    xen_ulong_t mod_len;      /* Size (bytes) of pre-loaded module.     */
 #define MAX_GUEST_CMDLINE 1024
     int8_t cmd_line[MAX_GUEST_CMDLINE];
     /* The pfn range here covers both page table and p->m table frames.   */
-    unsigned long first_p2m_pfn;/* 1st pfn forming initial P->M table.    */
-    unsigned long nr_p2m_frames;/* # of pfns forming initial P->M table.  */
+    xen_ulong_t first_p2m_pfn;/* 1st pfn forming initial P->M table.    */
+    xen_ulong_t nr_p2m_frames;/* # of pfns forming initial P->M table.  */
 };
 typedef struct start_info start_info_t;