Skip to contentSkip to conversation

xen/arm: Some clean-up found with -Wconversion and -Warith-conversion

PATCH In review Julien Grall 6 participants 22 messages Aug 17, 2023 – Aug 21, 2023

lore
Share & tools
lore
#0 lore raw

cover xen/arm: Some clean-up found with -Wconversion and -Warith-conversion

From: Julien Grall <[email protected]>

Hi all,

This is a small series to fix some of the issues found while playing with -Wconversion and -Warith-conversion.

There are a lot more but the bulk are in
- bitmap
- cpumask
- nodemask
- bitops/atomics
- find_*

Some are not too difficult to address but other there are even prototype conflicts between arm x86.

Cheers,

Julien Grall (3):
xen/arm: vmmio: The number of entries cannot be negative xen/arm: vgic: Use 'unsigned int' rather than 'int' whenever it is
possible
xen/public: arch-arm: All PSR_* defines should be unsigned

 xen/arch/arm/domain.c           |  3 +-
 xen/arch/arm/include/asm/mmio.h |  6 ++--
 xen/arch/arm/include/asm/vgic.h | 17 ++++++-----
 xen/arch/arm/io.c               |  2 +-
 xen/arch/arm/vgic-v2.c          | 14 +++++++--
 xen/arch/arm/vgic-v3.c          |  2 +-
 xen/arch/arm/vgic.c             | 23 ++++++++-------
 xen/arch/arm/vgic/vgic-init.c   |  2 +-
 xen/include/public/arch-arm.h   | 52 ++++++++++++++++-----------------
 9 files changed, 68 insertions(+), 53 deletions(-)
Signature · 1 line
2.40.1
#1 lore raw

PATCH 1/3 xen/arm: vmmio: The number of entries cannot be negative

From: Julien Grall <[email protected]>

The number of virtual MMIO regions cannot be negative. So switch the field 'num_entries' and 'max_num_entries' to 'unsigned int'.

The new type is then propagated to the caller and the vGIC code.

---
 xen/arch/arm/domain.c           | 3 ++-
 xen/arch/arm/include/asm/mmio.h | 6 +++---
 xen/arch/arm/include/asm/vgic.h | 6 +++---
 xen/arch/arm/io.c               | 2 +-
 xen/arch/arm/vgic-v2.c          | 2 +-
 xen/arch/arm/vgic-v3.c          | 2 +-
 xen/arch/arm/vgic.c             | 2 +-
 xen/arch/arm/vgic/vgic-init.c   | 2 +-
 8 files changed, 13 insertions(+), 12 deletions(-)
xen/arch/arm/domain.c +2 -1
index 6113ca785c78..28e3aaa5e482 100644
@@ -694,7 +694,8 @@ int arch_domain_create(struct domain *d,
                        struct xen_domctl_createdomain *config,
                        unsigned int flags)
 {
-    int rc, count = 0;
+    unsigned int count = 0;
+    int rc;
 
     BUILD_BUG_ON(GUEST_MAX_VCPUS < MAX_VIRT_CPUS);
 
xen/arch/arm/include/asm/mmio.h +3 -3
index 79e64d9af804..b22cfdac5be9 100644
@@ -75,8 +75,8 @@ struct mmio_handler {
 };
 
 struct vmmio {
-    int num_entries;
-    int max_num_entries;
+    unsigned int num_entries;
+    unsigned int max_num_entries;
     rwlock_t lock;
     struct mmio_handler *handlers;
 };
@@ -86,7 +86,7 @@ enum io_state try_handle_mmio(struct cpu_user_regs *regs,
 void register_mmio_handler(struct domain *d,
                            const struct mmio_handler_ops *ops,
                            paddr_t addr, paddr_t size, void *priv);
-int domain_io_init(struct domain *d, int max_count);
+int domain_io_init(struct domain *d, unsigned int max_count);
 void domain_io_free(struct domain *d);
 
 void try_decode_instruction(const struct cpu_user_regs *regs,
xen/arch/arm/include/asm/vgic.h +3 -3
index aa9f49409edc..6901a05c0669 100644
@@ -304,8 +304,8 @@ extern void vgic_enable_irqs(struct vcpu *v, uint32_t r, int n);
 extern void vgic_set_irqs_pending(struct vcpu *v, uint32_t r,
                                   unsigned int rank);
 extern void register_vgic_ops(struct domain *d, const struct vgic_ops *ops);
-int vgic_v2_init(struct domain *d, int *mmio_count);
-int vgic_v3_init(struct domain *d, int *mmio_count);
+int vgic_v2_init(struct domain *d, unsigned int *mmio_count);
+int vgic_v3_init(struct domain *d, unsigned int *mmio_count);
 
 extern bool vgic_to_sgi(struct vcpu *v, register_t sgir,
                         enum gic_sgi_mode irqmode, int virq,
@@ -352,7 +352,7 @@ int vgic_connect_hw_irq(struct domain *d, struct vcpu *v, unsigned int virq,
 
 bool vgic_evtchn_irq_pending(struct vcpu *v);
 
-int domain_vgic_register(struct domain *d, int *mmio_count);
+int domain_vgic_register(struct domain *d, unsigned int *mmio_count);
 int domain_vgic_init(struct domain *d, unsigned int nr_spis);
 void domain_vgic_free(struct domain *d);
 int vcpu_vgic_init(struct vcpu *v);
xen/arch/arm/io.c +1 -1
index 172583df047f..96c740d5636c 100644
@@ -224,7 +224,7 @@ void register_mmio_handler(struct domain *d,
     write_unlock(&vmmio->lock);
 }
 
-int domain_io_init(struct domain *d, int max_count)
+int domain_io_init(struct domain *d, unsigned int max_count)
 {
     rwlock_init(&d->arch.vmmio.lock);
     d->arch.vmmio.num_entries = 0;
xen/arch/arm/vgic-v2.c +1 -1
index 35363fee098c..2a2eda2e6f4c 100644
@@ -731,7 +731,7 @@ static const struct vgic_ops vgic_v2_ops = {
     .lpi_get_priority = vgic_v2_lpi_get_priority,
 };
 
-int vgic_v2_init(struct domain *d, int *mmio_count)
+int vgic_v2_init(struct domain *d, unsigned int *mmio_count)
 {
     if ( !vgic_v2_hw.enabled )
     {
xen/arch/arm/vgic-v3.c +1 -1
index 1b7173da1e30..05a009409ab8 100644
@@ -1812,7 +1812,7 @@ static const struct vgic_ops v3_ops = {
     .lpi_get_priority = vgic_v3_lpi_get_priority,
 };
 
-int vgic_v3_init(struct domain *d, int *mmio_count)
+int vgic_v3_init(struct domain *d, unsigned int *mmio_count)
 {
     if ( !vgic_v3_hw.enabled )
     {
xen/arch/arm/vgic.c +1 -1
index 97d6f6106638..afcac791fe4b 100644
@@ -85,7 +85,7 @@ static void vgic_rank_init(struct vgic_irq_rank *rank, uint8_t index,
         write_atomic(&rank->vcpu[i], vcpu);
 }
 
-int domain_vgic_register(struct domain *d, int *mmio_count)
+int domain_vgic_register(struct domain *d, unsigned int *mmio_count)
 {
     switch ( d->arch.vgic.version )
     {
xen/arch/arm/vgic/vgic-init.c +1 -1
index 76b85ea8231b..f8d7d3a226d0 100644
@@ -101,7 +101,7 @@ static void vgic_vcpu_early_init(struct vcpu *vcpu)
  *
  * was: kvm_vgic_create
  */
-int domain_vgic_register(struct domain *d, int *mmio_count)
+int domain_vgic_register(struct domain *d, unsigned int *mmio_count)
 {
     switch ( d->arch.vgic.version )
     {
Signature · 1 line
2.40.1
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] xen/arm: vmmio: The number of entries cannot be negative

Quoted 9 lines · Julien Grall

From: Julien Grall <[email protected]>

The number of virtual MMIO regions cannot be negative. So switch the field 'num_entries' and 'max_num_entries' to 'unsigned int'.

The new type is then propagated to the caller and the vGIC code.

Quoted 141 lines
---
 xen/arch/arm/domain.c           | 3 ++-
 xen/arch/arm/include/asm/mmio.h | 6 +++---
 xen/arch/arm/include/asm/vgic.h | 6 +++---
 xen/arch/arm/io.c               | 2 +-
 xen/arch/arm/vgic-v2.c          | 2 +-
 xen/arch/arm/vgic-v3.c          | 2 +-
 xen/arch/arm/vgic.c             | 2 +-
 xen/arch/arm/vgic/vgic-init.c   | 2 +-
 8 files changed, 13 insertions(+), 12 deletions(-)
xen/arch/arm/domain.c +2 -1
index 6113ca785c78..28e3aaa5e482 100644
@@ -694,7 +694,8 @@ int arch_domain_create(struct domain *d,
                        struct xen_domctl_createdomain *config,
                        unsigned int flags)
 {
-    int rc, count = 0;
+    unsigned int count = 0;
+    int rc;
 
     BUILD_BUG_ON(GUEST_MAX_VCPUS < MAX_VIRT_CPUS);
 
xen/arch/arm/include/asm/mmio.h +3 -3
index 79e64d9af804..b22cfdac5be9 100644
@@ -75,8 +75,8 @@ struct mmio_handler {
 };
 
 struct vmmio {
-    int num_entries;
-    int max_num_entries;
+    unsigned int num_entries;
+    unsigned int max_num_entries;
     rwlock_t lock;
     struct mmio_handler *handlers;
 };
@@ -86,7 +86,7 @@ enum io_state try_handle_mmio(struct cpu_user_regs *regs,
 void register_mmio_handler(struct domain *d,
                            const struct mmio_handler_ops *ops,
                            paddr_t addr, paddr_t size, void *priv);
-int domain_io_init(struct domain *d, int max_count);
+int domain_io_init(struct domain *d, unsigned int max_count);
 void domain_io_free(struct domain *d);
 
 void try_decode_instruction(const struct cpu_user_regs *regs,
xen/arch/arm/include/asm/vgic.h +3 -3
index aa9f49409edc..6901a05c0669 100644
@@ -304,8 +304,8 @@ extern void vgic_enable_irqs(struct vcpu *v, uint32_t r, int n);
 extern void vgic_set_irqs_pending(struct vcpu *v, uint32_t r,
                                   unsigned int rank);
 extern void register_vgic_ops(struct domain *d, const struct vgic_ops *ops);
-int vgic_v2_init(struct domain *d, int *mmio_count);
-int vgic_v3_init(struct domain *d, int *mmio_count);
+int vgic_v2_init(struct domain *d, unsigned int *mmio_count);
+int vgic_v3_init(struct domain *d, unsigned int *mmio_count);
 
 extern bool vgic_to_sgi(struct vcpu *v, register_t sgir,
                         enum gic_sgi_mode irqmode, int virq,
@@ -352,7 +352,7 @@ int vgic_connect_hw_irq(struct domain *d, struct vcpu *v, unsigned int virq,
 
 bool vgic_evtchn_irq_pending(struct vcpu *v);
 
-int domain_vgic_register(struct domain *d, int *mmio_count);
+int domain_vgic_register(struct domain *d, unsigned int *mmio_count);
 int domain_vgic_init(struct domain *d, unsigned int nr_spis);
 void domain_vgic_free(struct domain *d);
 int vcpu_vgic_init(struct vcpu *v);
xen/arch/arm/io.c +1 -1
index 172583df047f..96c740d5636c 100644
@@ -224,7 +224,7 @@ void register_mmio_handler(struct domain *d,
     write_unlock(&vmmio->lock);
 }
 
-int domain_io_init(struct domain *d, int max_count)
+int domain_io_init(struct domain *d, unsigned int max_count)
 {
     rwlock_init(&d->arch.vmmio.lock);
     d->arch.vmmio.num_entries = 0;
xen/arch/arm/vgic-v2.c +1 -1
index 35363fee098c..2a2eda2e6f4c 100644
@@ -731,7 +731,7 @@ static const struct vgic_ops vgic_v2_ops = {
     .lpi_get_priority = vgic_v2_lpi_get_priority,
 };
 
-int vgic_v2_init(struct domain *d, int *mmio_count)
+int vgic_v2_init(struct domain *d, unsigned int *mmio_count)
 {
     if ( !vgic_v2_hw.enabled )
     {
xen/arch/arm/vgic-v3.c +1 -1
index 1b7173da1e30..05a009409ab8 100644
@@ -1812,7 +1812,7 @@ static const struct vgic_ops v3_ops = {
     .lpi_get_priority = vgic_v3_lpi_get_priority,
 };
 
-int vgic_v3_init(struct domain *d, int *mmio_count)
+int vgic_v3_init(struct domain *d, unsigned int *mmio_count)
 {
     if ( !vgic_v3_hw.enabled )
     {
xen/arch/arm/vgic.c +1 -1
index 97d6f6106638..afcac791fe4b 100644
@@ -85,7 +85,7 @@ static void vgic_rank_init(struct vgic_irq_rank *rank, uint8_t index,
         write_atomic(&rank->vcpu[i], vcpu);
 }
 
-int domain_vgic_register(struct domain *d, int *mmio_count)
+int domain_vgic_register(struct domain *d, unsigned int *mmio_count)
 {
     switch ( d->arch.vgic.version )
     {
xen/arch/arm/vgic/vgic-init.c +1 -1
index 76b85ea8231b..f8d7d3a226d0 100644
@@ -101,7 +101,7 @@ static void vgic_vcpu_early_init(struct vcpu *vcpu)
  *
  * was: kvm_vgic_create
  */
-int domain_vgic_register(struct domain *d, int *mmio_count)
+int domain_vgic_register(struct domain *d, unsigned int *mmio_count)
 {
     switch ( d->arch.vgic.version )
     {
Signature · 1 line
2.40.1
Reviewed-by Tested-by on v1 1/3
#3 lore raw

Re: [PATCH 1/3] xen/arm: vmmio: The number of entries cannot be negative

In reply to Julien Grall

Hi Julien,

Quoted 12 lines · Julien Grall

From: Julien Grall <[email protected]>

The number of virtual MMIO regions cannot be negative. So switch the field 'num_entries' and 'max_num_entries' to 'unsigned int'.

The new type is then propagated to the caller and the vGIC code.

---

Kind regards,
Henry

#4 lore raw

PATCH 2/3 xen/arm: vgic: Use 'unsigned int' rather than 'int' whenever it is possible

In reply to Julien Grall

From: Julien Grall <[email protected]>

Switch to unsigned int for the return/parameters of the following functions:
* REG_RANK_NR(): 'b' (number of bits) and the return is always positive. 'n' doesn't need to be size specific.
* vgic_rank_offset(): 'b' (number of bits), 'n' (register index), 's' (size of the access) are always positive.
* vgic_{enable, disable}_irqs(): 'n' (rank index) is always positive
* vgic_get_virq_type(): 'n' (rank index) and 'index' (register index) are always positive.

Take the opportunity to propogate the unsignedness to the local variable used for the arguments.

This will remove some of the warning reported by GCC 12.2.1 when passing the flags -Wsign-conversion/-Wconversion.

---
 xen/arch/arm/include/asm/vgic.h | 11 +++++++----
 xen/arch/arm/vgic-v2.c          | 12 ++++++++++--
 xen/arch/arm/vgic.c             | 21 ++++++++++++---------
 3 files changed, 29 insertions(+), 15 deletions(-)
xen/arch/arm/include/asm/vgic.h +7 -4
index 6901a05c0669..922779ce146a 100644
@@ -252,7 +252,7 @@ struct vgic_ops {
  * Rank containing GICD_<FOO><n> for GICD_<FOO> with
  * <b>-bits-per-interrupt
  */
-static inline int REG_RANK_NR(int b, uint32_t n)
+static inline unsigned int REG_RANK_NR(unsigned int b, unsigned int n)
 {
     switch ( b )
     {
@@ -297,10 +297,13 @@ extern void gic_remove_from_lr_pending(struct vcpu *v, struct pending_irq *p);
 extern void vgic_init_pending_irq(struct pending_irq *p, unsigned int virq);
 extern struct pending_irq *irq_to_pending(struct vcpu *v, unsigned int irq);
 extern struct pending_irq *spi_to_pending(struct domain *d, unsigned int irq);
-extern struct vgic_irq_rank *vgic_rank_offset(struct vcpu *v, int b, int n, int s);
+extern struct vgic_irq_rank *vgic_rank_offset(struct vcpu *v,
+                                              unsigned int b,
+                                              unsigned int n,
+                                              unsigned int s);
 extern struct vgic_irq_rank *vgic_rank_irq(struct vcpu *v, unsigned int irq);
-extern void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n);
-extern void vgic_enable_irqs(struct vcpu *v, uint32_t r, int n);
+extern void vgic_disable_irqs(struct vcpu *v, uint32_t r, unsigned int n);
+extern void vgic_enable_irqs(struct vcpu *v, uint32_t r, unsigned int n);
 extern void vgic_set_irqs_pending(struct vcpu *v, uint32_t r,
                                   unsigned int rank);
 extern void register_vgic_ops(struct domain *d, const struct vgic_ops *ops);
xen/arch/arm/vgic-v2.c +10 -2
index 2a2eda2e6f4c..0aa10fff0f10 100644
@@ -161,7 +161,11 @@ static int vgic_v2_distr_mmio_read(struct vcpu *v, mmio_info_t *info,
 {
     struct hsr_dabt dabt = info->dabt;
     struct vgic_irq_rank *rank;
-    int gicd_reg = (int)(info->gpa - v->domain->arch.vgic.dbase);
+    /*
+     * gpa/dbase are paddr_t which size may be higher than 32-bit. Yet
+     * the difference will always be smaller than 32-bit.
+     */
+    unsigned int gicd_reg = info->gpa - v->domain->arch.vgic.dbase;
     unsigned long flags;
 
     perfc_incr(vgicd_reads);
@@ -403,7 +407,11 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info,
 {
     struct hsr_dabt dabt = info->dabt;
     struct vgic_irq_rank *rank;
-    int gicd_reg = (int)(info->gpa - v->domain->arch.vgic.dbase);
+    /*
+     * gpa/dbase are paddr_t which size may be higher than 32-bit. Yet
+     * the difference will always be smaller than 32-bit.
+     */
+    unsigned int gicd_reg = info->gpa - v->domain->arch.vgic.dbase;
     uint32_t tr;
     unsigned long flags;
 
xen/arch/arm/vgic.c +12 -9
index afcac791fe4b..269b804974e0 100644
@@ -24,7 +24,8 @@
 #include <asm/gic.h>
 #include <asm/vgic.h>
 
-static inline struct vgic_irq_rank *vgic_get_rank(struct vcpu *v, int rank)
+static inline struct vgic_irq_rank *vgic_get_rank(struct vcpu *v,
+                                                  unsigned int rank)
 {
     if ( rank == 0 )
         return v->arch.vgic.private_irqs;
@@ -38,17 +39,17 @@ static inline struct vgic_irq_rank *vgic_get_rank(struct vcpu *v, int rank)
  * Returns rank corresponding to a GICD_<FOO><n> register for
  * GICD_<FOO> with <b>-bits-per-interrupt.
  */
-struct vgic_irq_rank *vgic_rank_offset(struct vcpu *v, int b, int n,
-                                              int s)
+struct vgic_irq_rank *vgic_rank_offset(struct vcpu *v, unsigned int b,
+                                       unsigned int n, unsigned int s)
 {
-    int rank = REG_RANK_NR(b, (n >> s));
+    unsigned int rank = REG_RANK_NR(b, (n >> s));
 
     return vgic_get_rank(v, rank);
 }
 
 struct vgic_irq_rank *vgic_rank_irq(struct vcpu *v, unsigned int irq)
 {
-    int rank = irq/32;
+    unsigned int rank = irq / 32;
 
     return vgic_get_rank(v, rank);
 }
@@ -324,14 +325,14 @@ void arch_move_irqs(struct vcpu *v)
     }
 }
 
-void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n)
+void vgic_disable_irqs(struct vcpu *v, uint32_t r, unsigned int n)
 {
     const unsigned long mask = r;
     struct pending_irq *p;
     struct irq_desc *desc;
     unsigned int irq;
     unsigned long flags;
-    int i = 0;
+    unsigned int i = 0;
     struct vcpu *v_target;
 
     /* LPIs will never be disabled via this function. */
@@ -361,7 +362,9 @@ void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n)
 #define VGIC_ICFG_MASK(intr) (1U << ((2 * ((intr) % 16)) + 1))
 
 /* The function should be called with the rank lock taken */
-static inline unsigned int vgic_get_virq_type(struct vcpu *v, int n, int index)
+static inline unsigned int vgic_get_virq_type(struct vcpu *v,
+                                              unsigned int n,
+                                              unsigned int index)
 {
     struct vgic_irq_rank *r = vgic_get_rank(v, n);
     uint32_t tr = r->icfg[index >> 4];
@@ -374,7 +377,7 @@ static inline unsigned int vgic_get_virq_type(struct vcpu *v, int n, int index)
         return IRQ_TYPE_LEVEL_HIGH;
 }
 
-void vgic_enable_irqs(struct vcpu *v, uint32_t r, int n)
+void vgic_enable_irqs(struct vcpu *v, uint32_t r, unsigned int n)
 {
     const unsigned long mask = r;
     struct pending_irq *p;
Signature · 1 line
2.40.1
Reviewed-by on v1 2/3
#5 lore raw

Re: [PATCH 2/3] xen/arm: vgic: Use 'unsigned int' rather than 'int' whenever it is possible

Quoted 150 lines · Julien Grall

From: Julien Grall <[email protected]>

Switch to unsigned int for the return/parameters of the following functions:
* REG_RANK_NR(): 'b' (number of bits) and the return is always positive. 'n' doesn't need to be size specific.
* vgic_rank_offset(): 'b' (number of bits), 'n' (register index), 's' (size of the access) are always positive.
* vgic_{enable, disable}_irqs(): 'n' (rank index) is always positive
* vgic_get_virq_type(): 'n' (rank index) and 'index' (register index) are always positive.

Take the opportunity to propogate the unsignedness to the local variable used for the arguments.

This will remove some of the warning reported by GCC 12.2.1 when passing the flags -Wsign-conversion/-Wconversion.

---
 xen/arch/arm/include/asm/vgic.h | 11 +++++++----
 xen/arch/arm/vgic-v2.c          | 12 ++++++++++--
 xen/arch/arm/vgic.c             | 21 ++++++++++++---------
 3 files changed, 29 insertions(+), 15 deletions(-)
xen/arch/arm/include/asm/vgic.h +7 -4
index 6901a05c0669..922779ce146a 100644
@@ -252,7 +252,7 @@ struct vgic_ops {
  * Rank containing GICD_<FOO><n> for GICD_<FOO> with
  * <b>-bits-per-interrupt
  */
-static inline int REG_RANK_NR(int b, uint32_t n)
+static inline unsigned int REG_RANK_NR(unsigned int b, unsigned int n)
 {
     switch ( b )
     {
@@ -297,10 +297,13 @@ extern void gic_remove_from_lr_pending(struct vcpu *v, struct pending_irq *p);
 extern void vgic_init_pending_irq(struct pending_irq *p, unsigned int virq);
 extern struct pending_irq *irq_to_pending(struct vcpu *v, unsigned int irq);
 extern struct pending_irq *spi_to_pending(struct domain *d, unsigned int irq);
-extern struct vgic_irq_rank *vgic_rank_offset(struct vcpu *v, int b, int n, int s);
+extern struct vgic_irq_rank *vgic_rank_offset(struct vcpu *v,
+                                              unsigned int b,
+                                              unsigned int n,
+                                              unsigned int s);
 extern struct vgic_irq_rank *vgic_rank_irq(struct vcpu *v, unsigned int irq);
-extern void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n);
-extern void vgic_enable_irqs(struct vcpu *v, uint32_t r, int n);
+extern void vgic_disable_irqs(struct vcpu *v, uint32_t r, unsigned int n);
+extern void vgic_enable_irqs(struct vcpu *v, uint32_t r, unsigned int n);
 extern void vgic_set_irqs_pending(struct vcpu *v, uint32_t r,
                                   unsigned int rank);
 extern void register_vgic_ops(struct domain *d, const struct vgic_ops *ops);
xen/arch/arm/vgic-v2.c +10 -2
index 2a2eda2e6f4c..0aa10fff0f10 100644
@@ -161,7 +161,11 @@ static int vgic_v2_distr_mmio_read(struct vcpu *v, mmio_info_t *info,
 {
     struct hsr_dabt dabt = info->dabt;
     struct vgic_irq_rank *rank;
-    int gicd_reg = (int)(info->gpa - v->domain->arch.vgic.dbase);
+    /*
+     * gpa/dbase are paddr_t which size may be higher than 32-bit. Yet
+     * the difference will always be smaller than 32-bit.
+     */
+    unsigned int gicd_reg = info->gpa - v->domain->arch.vgic.dbase;
     unsigned long flags;
 
     perfc_incr(vgicd_reads);
@@ -403,7 +407,11 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info,
 {
     struct hsr_dabt dabt = info->dabt;
     struct vgic_irq_rank *rank;
-    int gicd_reg = (int)(info->gpa - v->domain->arch.vgic.dbase);
+    /*
+     * gpa/dbase are paddr_t which size may be higher than 32-bit. Yet
+     * the difference will always be smaller than 32-bit.
+     */
+    unsigned int gicd_reg = info->gpa - v->domain->arch.vgic.dbase;
     uint32_t tr;
     unsigned long flags;
 
xen/arch/arm/vgic.c +11 -8
index afcac791fe4b..269b804974e0 100644
@@ -24,7 +24,8 @@
 #include <asm/gic.h>
 #include <asm/vgic.h>
 
-static inline struct vgic_irq_rank *vgic_get_rank(struct vcpu *v, int rank)
+static inline struct vgic_irq_rank *vgic_get_rank(struct vcpu *v,
+                                                  unsigned int rank)
 {
     if ( rank == 0 )
         return v->arch.vgic.private_irqs;
@@ -38,17 +39,17 @@ static inline struct vgic_irq_rank *vgic_get_rank(struct vcpu *v, int rank)
  * Returns rank corresponding to a GICD_<FOO><n> register for
  * GICD_<FOO> with <b>-bits-per-interrupt.
  */
-struct vgic_irq_rank *vgic_rank_offset(struct vcpu *v, int b, int n,
-                                              int s)
+struct vgic_irq_rank *vgic_rank_offset(struct vcpu *v, unsigned int b,
+                                       unsigned int n, unsigned int s)
 {
-    int rank = REG_RANK_NR(b, (n >> s));
+    unsigned int rank = REG_RANK_NR(b, (n >> s));
 
     return vgic_get_rank(v, rank);
 }
 
 struct vgic_irq_rank *vgic_rank_irq(struct vcpu *v, unsigned int irq)
 {
-    int rank = irq/32;
+    unsigned int rank = irq / 32;
 
     return vgic_get_rank(v, rank);
 }
@@ -324,14 +325,14 @@ void arch_move_irqs(struct vcpu *v)
     }
 }
 
-void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n)
+void vgic_disable_irqs(struct vcpu *v, uint32_t r, unsigned int n)
 {
     const unsigned long mask = r;
     struct pending_irq *p;
     struct irq_desc *desc;
     unsigned int irq;
     unsigned long flags;
-    int i = 0;
+    unsigned int i = 0;
     struct vcpu *v_target;
 
     /* LPIs will never be disabled via this function. */
@@ -361,7 +362,9 @@ void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n)
 #define VGIC_ICFG_MASK(intr) (1U << ((2 * ((intr) % 16)) + 1))
 
 /* The function should be called with the rank lock taken */
-static inline unsigned int vgic_get_virq_type(struct vcpu *v, int n, int index)
+static inline unsigned int vgic_get_virq_type(struct vcpu *v,
+                                              unsigned int n,
+                                              unsigned int index)
 {
     struct vgic_irq_rank *r = vgic_get_rank(v, n);
     uint32_t tr = r->icfg[index >> 4];

xen/arch/arm/vgic.c static inline unsigned int vgic_get_virq_type(struct vcpu *v, int n, int index) · line 383

Quoted 8 lines
xen/arch/arm/vgic.c +1 -1
@@ -374,7 +377,7 @@ static inline unsigned int vgic_get_virq_type(struct vcpu *v, int n, int index)
         return IRQ_TYPE_LEVEL_HIGH;
 }
 
-void vgic_enable_irqs(struct vcpu *v, uint32_t r, int n)
+void vgic_enable_irqs(struct vcpu *v, uint32_t r, unsigned int n)
 {
     const unsigned long mask = r;
     struct pending_irq *p;

It looks like you could also switch 'i' to unsigned int in vgic_enable_irqs like you did in vgic_disable_irqs

You could do that on commit:

#6 lore raw

Re: [PATCH 2/3] xen/arm: vgic: Use 'unsigned int' rather than 'int' whenever it is possible

Hi Stefano,

Quoted 154 lines · Stefano Stabellini
Quoted 153 lines · Julien Grall

From: Julien Grall <[email protected]>

Switch to unsigned int for the return/parameters of the following functions:
* REG_RANK_NR(): 'b' (number of bits) and the return is always positive. 'n' doesn't need to be size specific.
* vgic_rank_offset(): 'b' (number of bits), 'n' (register index), 's' (size of the access) are always positive.
* vgic_{enable, disable}_irqs(): 'n' (rank index) is always positive
* vgic_get_virq_type(): 'n' (rank index) and 'index' (register index) are always positive.

Take the opportunity to propogate the unsignedness to the local variable used for the arguments.

This will remove some of the warning reported by GCC 12.2.1 when passing the flags -Wsign-conversion/-Wconversion.

---
  xen/arch/arm/include/asm/vgic.h | 11 +++++++----
  xen/arch/arm/vgic-v2.c          | 12 ++++++++++--
  xen/arch/arm/vgic.c             | 21 ++++++++++++---------
  3 files changed, 29 insertions(+), 15 deletions(-)
xen/arch/arm/include/asm/vgic.h +7 -4
index 6901a05c0669..922779ce146a 100644
@@ -252,7 +252,7 @@ struct vgic_ops {
   * Rank containing GICD_<FOO><n> for GICD_<FOO> with
   * <b>-bits-per-interrupt
   */
-static inline int REG_RANK_NR(int b, uint32_t n)
+static inline unsigned int REG_RANK_NR(unsigned int b, unsigned int n)
  {
      switch ( b )
      {
@@ -297,10 +297,13 @@ extern void gic_remove_from_lr_pending(struct vcpu *v, struct pending_irq *p);
  extern void vgic_init_pending_irq(struct pending_irq *p, unsigned int virq);
  extern struct pending_irq *irq_to_pending(struct vcpu *v, unsigned int irq);
  extern struct pending_irq *spi_to_pending(struct domain *d, unsigned int irq);
-extern struct vgic_irq_rank *vgic_rank_offset(struct vcpu *v, int b, int n, int s);
+extern struct vgic_irq_rank *vgic_rank_offset(struct vcpu *v,
+                                              unsigned int b,
+                                              unsigned int n,
+                                              unsigned int s);
  extern struct vgic_irq_rank *vgic_rank_irq(struct vcpu *v, unsigned int irq);
-extern void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n);
-extern void vgic_enable_irqs(struct vcpu *v, uint32_t r, int n);
+extern void vgic_disable_irqs(struct vcpu *v, uint32_t r, unsigned int n);
+extern void vgic_enable_irqs(struct vcpu *v, uint32_t r, unsigned int n);
  extern void vgic_set_irqs_pending(struct vcpu *v, uint32_t r,
                                    unsigned int rank);
  extern void register_vgic_ops(struct domain *d, const struct vgic_ops *ops);
xen/arch/arm/vgic-v2.c +10 -2
index 2a2eda2e6f4c..0aa10fff0f10 100644
@@ -161,7 +161,11 @@ static int vgic_v2_distr_mmio_read(struct vcpu *v, mmio_info_t *info,
  {
      struct hsr_dabt dabt = info->dabt;
      struct vgic_irq_rank *rank;
-    int gicd_reg = (int)(info->gpa - v->domain->arch.vgic.dbase);
+    /*
+     * gpa/dbase are paddr_t which size may be higher than 32-bit. Yet
+     * the difference will always be smaller than 32-bit.
+     */
+    unsigned int gicd_reg = info->gpa - v->domain->arch.vgic.dbase;
      unsigned long flags;
 
      perfc_incr(vgicd_reads);
@@ -403,7 +407,11 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info,
  {
      struct hsr_dabt dabt = info->dabt;
      struct vgic_irq_rank *rank;
-    int gicd_reg = (int)(info->gpa - v->domain->arch.vgic.dbase);
+    /*
+     * gpa/dbase are paddr_t which size may be higher than 32-bit. Yet
+     * the difference will always be smaller than 32-bit.
+     */
+    unsigned int gicd_reg = info->gpa - v->domain->arch.vgic.dbase;
      uint32_t tr;
      unsigned long flags;
 
xen/arch/arm/vgic.c +11 -8
index afcac791fe4b..269b804974e0 100644
@@ -24,7 +24,8 @@
  #include <asm/gic.h>
  #include <asm/vgic.h>
 
-static inline struct vgic_irq_rank *vgic_get_rank(struct vcpu *v, int rank)
+static inline struct vgic_irq_rank *vgic_get_rank(struct vcpu *v,
+                                                  unsigned int rank)
  {
      if ( rank == 0 )
          return v->arch.vgic.private_irqs;
@@ -38,17 +39,17 @@ static inline struct vgic_irq_rank *vgic_get_rank(struct vcpu *v, int rank)
   * Returns rank corresponding to a GICD_<FOO><n> register for
   * GICD_<FOO> with <b>-bits-per-interrupt.
   */
-struct vgic_irq_rank *vgic_rank_offset(struct vcpu *v, int b, int n,
-                                              int s)
+struct vgic_irq_rank *vgic_rank_offset(struct vcpu *v, unsigned int b,
+                                       unsigned int n, unsigned int s)
  {
-    int rank = REG_RANK_NR(b, (n >> s));
+    unsigned int rank = REG_RANK_NR(b, (n >> s));
 
      return vgic_get_rank(v, rank);
  }
 
  struct vgic_irq_rank *vgic_rank_irq(struct vcpu *v, unsigned int irq)
  {
-    int rank = irq/32;
+    unsigned int rank = irq / 32;
 
      return vgic_get_rank(v, rank);
  }
@@ -324,14 +325,14 @@ void arch_move_irqs(struct vcpu *v)
      }
  }
 
-void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n)
+void vgic_disable_irqs(struct vcpu *v, uint32_t r, unsigned int n)
  {
      const unsigned long mask = r;
      struct pending_irq *p;
      struct irq_desc *desc;
      unsigned int irq;
      unsigned long flags;
-    int i = 0;
+    unsigned int i = 0;
      struct vcpu *v_target;
 
      /* LPIs will never be disabled via this function. */
@@ -361,7 +362,9 @@ void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n)
  #define VGIC_ICFG_MASK(intr) (1U << ((2 * ((intr) % 16)) + 1))
 
  /* The function should be called with the rank lock taken */
-static inline unsigned int vgic_get_virq_type(struct vcpu *v, int n, int index)
+static inline unsigned int vgic_get_virq_type(struct vcpu *v,
+                                              unsigned int n,
+                                              unsigned int index)
  {
      struct vgic_irq_rank *r = vgic_get_rank(v, n);
      uint32_t tr = r->icfg[index >> 4];
@@ -374,7 +377,7 @@ static inline unsigned int vgic_get_virq_type(struct vcpu *v, int n, int index)
          return IRQ_TYPE_LEVEL_HIGH;
  }
 
Quoted 8 lines

xen/arch/arm/vgic.c static inline unsigned int vgic_get_virq_type(struct vcpu *v, int n, int index) · line 383

Quoted 5 lines
xen/arch/arm/vgic.c +1 -1
-void vgic_enable_irqs(struct vcpu *v, uint32_t r, int n)
+void vgic_enable_irqs(struct vcpu *v, uint32_t r, unsigned int n)
  {
      const unsigned long mask = r;
      struct pending_irq *p;

It looks like you could also switch 'i' to unsigned int in vgic_enable_irqs like you did in vgic_disable_irqs

Indeed. I have updated the patch.

Quoted 4 lines

You could do that on commit:

Thanks!

Cheers,

Signature · 1 line
Julien Grall
Reviewed-by Tested-by on v1 2/3
#7 lore raw

Re: [PATCH 2/3] xen/arm: vgic: Use 'unsigned int' rather than 'int' whenever it is possible

In reply to Julien Grall

Hi Julien,

Quoted 14 lines · Julien Grall

From: Julien Grall <[email protected]>

Switch to unsigned int for the return/parameters of the following functions:
* REG_RANK_NR(): 'b' (number of bits) and the return is always positive. 'n' doesn't need to be size specific.
* vgic_rank_offset(): 'b' (number of bits), 'n' (register index), 's' (size of the access) are always positive.
* vgic_{enable, disable}_irqs(): 'n' (rank index) is always positive
* vgic_get_virq_type(): 'n' (rank index) and 'index' (register index) are always positive.

Quoted 7 lines

Take the opportunity to propogate the unsignedness to the local variable used for the arguments.

This will remove some of the warning reported by GCC 12.2.1 when passing the flags -Wsign-conversion/-Wconversion.

Kind regards,
Henry

Reviewed-by on v1 2/3
#8 lore raw

Re: [PATCH 2/3] xen/arm: vgic: Use 'unsigned int' rather than 'int' whenever it is possible

In reply to Julien Grall

Hi Julien,

Quoted 4 lines · Julien Grall

From: Julien Grall <[email protected]>

Quoted 9 lines

Switch to unsigned int for the return/parameters of the following functions:
* REG_RANK_NR(): 'b' (number of bits) and the return is always positive. 'n' doesn't need to be size specific.
* vgic_rank_offset(): 'b' (number of bits), 'n' (register index), 's' (size of the access) are always positive.
* vgic_{enable, disable}_irqs(): 'n' (rank index) is always positive
* vgic_get_virq_type(): 'n' (rank index) and 'index' (register index) are always positive.

It looks like you forgot to mention the modification done to 'vgic_get_rank()' With this addressed:

~Michal

#9 lore raw

Re: [PATCH 2/3] xen/arm: vgic: Use 'unsigned int' rather than 'int' whenever it is possible

Hi Michal,

Quoted 14 lines · Michal Orzel
Quoted 4 lines · Julien Grall

From: Julien Grall <[email protected]>

Quoted 9 lines

Switch to unsigned int for the return/parameters of the following functions:
* REG_RANK_NR(): 'b' (number of bits) and the return is always positive. 'n' doesn't need to be size specific.
* vgic_rank_offset(): 'b' (number of bits), 'n' (register index), 's' (size of the access) are always positive.
* vgic_{enable, disable}_irqs(): 'n' (rank index) is always positive
* vgic_get_virq_type(): 'n' (rank index) and 'index' (register index) are always positive.

Quoted 1 line

It looks like you forgot to mention the modification done to 'vgic_get_rank()'

I have added:

* vgic_get_rank(): 'rank' is an index and therefore always
positive.

Quoted 2 lines

With this addressed:

Thanks!

Cheers,

Signature · 1 line
Julien Grall
#10 lore raw

PATCH 3/3 xen/public: arch-arm: All PSR_* defines should be unsigned

In reply to Julien Grall

From: Julien Grall <[email protected]>

The defines PSR_* are field in registers and always unsigned. So add 'U' to clarify.

This should help with MISRA Rule 7.2.

---
 xen/include/public/arch-arm.h | 52 +++++++++++++++++------------------
 1 file changed, 26 insertions(+), 26 deletions(-)
xen/include/public/arch-arm.h +26 -26
index c6449893e493..492819ad22c9 100644
@@ -339,36 +339,36 @@ typedef uint64_t xen_callback_t;
 
 /* PSR bits (CPSR, SPSR) */
 
-#define PSR_THUMB       (1<<5)        /* Thumb Mode enable */
-#define PSR_FIQ_MASK    (1<<6)        /* Fast Interrupt mask */
-#define PSR_IRQ_MASK    (1<<7)        /* Interrupt mask */
-#define PSR_ABT_MASK    (1<<8)        /* Asynchronous Abort mask */
-#define PSR_BIG_ENDIAN  (1<<9)        /* arm32: Big Endian Mode */
-#define PSR_DBG_MASK    (1<<9)        /* arm64: Debug Exception mask */
-#define PSR_IT_MASK     (0x0600fc00)  /* Thumb If-Then Mask */
-#define PSR_JAZELLE     (1<<24)       /* Jazelle Mode */
-#define PSR_Z           (1<<30)       /* Zero condition flag */
+#define PSR_THUMB       (1U <<5)      /* Thumb Mode enable */
+#define PSR_FIQ_MASK    (1U <<6)      /* Fast Interrupt mask */
+#define PSR_IRQ_MASK    (1U <<7)      /* Interrupt mask */
+#define PSR_ABT_MASK    (1U <<8)      /* Asynchronous Abort mask */
+#define PSR_BIG_ENDIAN  (1U << 9)     /* arm32: Big Endian Mode */
+#define PSR_DBG_MASK    (1U << 9)     /* arm64: Debug Exception mask */
+#define PSR_IT_MASK     (0x0600fc00U) /* Thumb If-Then Mask */
+#define PSR_JAZELLE     (1U << 24)    /* Jazelle Mode */
+#define PSR_Z           (1U << 30)    /* Zero condition flag */
 
 /* 32 bit modes */
-#define PSR_MODE_USR 0x10
-#define PSR_MODE_FIQ 0x11
-#define PSR_MODE_IRQ 0x12
-#define PSR_MODE_SVC 0x13
-#define PSR_MODE_MON 0x16
-#define PSR_MODE_ABT 0x17
-#define PSR_MODE_HYP 0x1a
-#define PSR_MODE_UND 0x1b
-#define PSR_MODE_SYS 0x1f
+#define PSR_MODE_USR 0x10U
+#define PSR_MODE_FIQ 0x11U
+#define PSR_MODE_IRQ 0x12U
+#define PSR_MODE_SVC 0x13U
+#define PSR_MODE_MON 0x16U
+#define PSR_MODE_ABT 0x17U
+#define PSR_MODE_HYP 0x1aU
+#define PSR_MODE_UND 0x1bU
+#define PSR_MODE_SYS 0x1fU
 
 /* 64 bit modes */
-#define PSR_MODE_BIT  0x10 /* Set iff AArch32 */
-#define PSR_MODE_EL3h 0x0d
-#define PSR_MODE_EL3t 0x0c
-#define PSR_MODE_EL2h 0x09
-#define PSR_MODE_EL2t 0x08
-#define PSR_MODE_EL1h 0x05
-#define PSR_MODE_EL1t 0x04
-#define PSR_MODE_EL0t 0x00
+#define PSR_MODE_BIT  0x10U /* Set iff AArch32 */
+#define PSR_MODE_EL3h 0x0dU
+#define PSR_MODE_EL3t 0x0cU
+#define PSR_MODE_EL2h 0x09U
+#define PSR_MODE_EL2t 0x08U
+#define PSR_MODE_EL1h 0x05U
+#define PSR_MODE_EL1t 0x04U
+#define PSR_MODE_EL0t 0x00U
 
 /*
  * We set PSR_Z to be able to boot Linux kernel versions with an invalid
Signature · 1 line
2.40.1
Reviewed-by on v1 3/3
#11 lore raw

Re: [PATCH 3/3] xen/public: arch-arm: All PSR_* defines should be unsigned

Quoted 8 lines · Julien Grall

From: Julien Grall <[email protected]>

The defines PSR_* are field in registers and always unsigned. So add 'U' to clarify.

This should help with MISRA Rule 7.2.

Quoted 74 lines
---
 xen/include/public/arch-arm.h | 52 +++++++++++++++++------------------
 1 file changed, 26 insertions(+), 26 deletions(-)
xen/include/public/arch-arm.h +26 -26
index c6449893e493..492819ad22c9 100644
@@ -339,36 +339,36 @@ typedef uint64_t xen_callback_t;
 
 /* PSR bits (CPSR, SPSR) */
 
-#define PSR_THUMB       (1<<5)        /* Thumb Mode enable */
-#define PSR_FIQ_MASK    (1<<6)        /* Fast Interrupt mask */
-#define PSR_IRQ_MASK    (1<<7)        /* Interrupt mask */
-#define PSR_ABT_MASK    (1<<8)        /* Asynchronous Abort mask */
-#define PSR_BIG_ENDIAN  (1<<9)        /* arm32: Big Endian Mode */
-#define PSR_DBG_MASK    (1<<9)        /* arm64: Debug Exception mask */
-#define PSR_IT_MASK     (0x0600fc00)  /* Thumb If-Then Mask */
-#define PSR_JAZELLE     (1<<24)       /* Jazelle Mode */
-#define PSR_Z           (1<<30)       /* Zero condition flag */
+#define PSR_THUMB       (1U <<5)      /* Thumb Mode enable */
+#define PSR_FIQ_MASK    (1U <<6)      /* Fast Interrupt mask */
+#define PSR_IRQ_MASK    (1U <<7)      /* Interrupt mask */
+#define PSR_ABT_MASK    (1U <<8)      /* Asynchronous Abort mask */
+#define PSR_BIG_ENDIAN  (1U << 9)     /* arm32: Big Endian Mode */
+#define PSR_DBG_MASK    (1U << 9)     /* arm64: Debug Exception mask */
+#define PSR_IT_MASK     (0x0600fc00U) /* Thumb If-Then Mask */
+#define PSR_JAZELLE     (1U << 24)    /* Jazelle Mode */
+#define PSR_Z           (1U << 30)    /* Zero condition flag */
 
 /* 32 bit modes */
-#define PSR_MODE_USR 0x10
-#define PSR_MODE_FIQ 0x11
-#define PSR_MODE_IRQ 0x12
-#define PSR_MODE_SVC 0x13
-#define PSR_MODE_MON 0x16
-#define PSR_MODE_ABT 0x17
-#define PSR_MODE_HYP 0x1a
-#define PSR_MODE_UND 0x1b
-#define PSR_MODE_SYS 0x1f
+#define PSR_MODE_USR 0x10U
+#define PSR_MODE_FIQ 0x11U
+#define PSR_MODE_IRQ 0x12U
+#define PSR_MODE_SVC 0x13U
+#define PSR_MODE_MON 0x16U
+#define PSR_MODE_ABT 0x17U
+#define PSR_MODE_HYP 0x1aU
+#define PSR_MODE_UND 0x1bU
+#define PSR_MODE_SYS 0x1fU
 
 /* 64 bit modes */
-#define PSR_MODE_BIT  0x10 /* Set iff AArch32 */
-#define PSR_MODE_EL3h 0x0d
-#define PSR_MODE_EL3t 0x0c
-#define PSR_MODE_EL2h 0x09
-#define PSR_MODE_EL2t 0x08
-#define PSR_MODE_EL1h 0x05
-#define PSR_MODE_EL1t 0x04
-#define PSR_MODE_EL0t 0x00
+#define PSR_MODE_BIT  0x10U /* Set iff AArch32 */
+#define PSR_MODE_EL3h 0x0dU
+#define PSR_MODE_EL3t 0x0cU
+#define PSR_MODE_EL2h 0x09U
+#define PSR_MODE_EL2t 0x08U
+#define PSR_MODE_EL1h 0x05U
+#define PSR_MODE_EL1t 0x04U
+#define PSR_MODE_EL0t 0x00U
 
 /*
  * We set PSR_Z to be able to boot Linux kernel versions with an invalid
Signature · 1 line
2.40.1
Reviewed-by Tested-by on v1 3/3
#12 lore raw

Re: [PATCH 3/3] xen/public: arch-arm: All PSR_* defines should be unsigned

In reply to Julien Grall

Hi Julien,

Quoted 10 lines · Julien Grall

From: Julien Grall <[email protected]>

The defines PSR_* are field in registers and always unsigned. So add 'U' to clarify.

This should help with MISRA Rule 7.2.

Kind regards,
Henry

#13 lore raw

Re: [PATCH 3/3] xen/public: arch-arm: All PSR_* defines should be unsigned

In reply to Julien Grall
Quoted 9 lines · Julien Grall
xen/include/public/arch-arm.h +0 -3
@@ -339,36 +339,36 @@ typedef uint64_t xen_callback_t;
 
 /* PSR bits (CPSR, SPSR) */
 
-#define PSR_THUMB       (1<<5)        /* Thumb Mode enable */
-#define PSR_FIQ_MASK    (1<<6)        /* Fast Interrupt mask */
-#define PSR_IRQ_MASK    (1<<7)        /* Interrupt mask */

xen/include/public/arch-arm.h typedef uint64_t xen_callback_t; · line 345

Quoted 10 lines
xen/include/public/arch-arm.h +4 -6
-#define PSR_ABT_MASK    (1<<8)        /* Asynchronous Abort mask */
-#define PSR_BIG_ENDIAN  (1<<9)        /* arm32: Big Endian Mode */
-#define PSR_DBG_MASK    (1<<9)        /* arm64: Debug Exception mask */
-#define PSR_IT_MASK     (0x0600fc00)  /* Thumb If-Then Mask */
-#define PSR_JAZELLE     (1<<24)       /* Jazelle Mode */
-#define PSR_Z           (1<<30)       /* Zero condition flag */
+#define PSR_THUMB       (1U <<5)      /* Thumb Mode enable */
+#define PSR_FIQ_MASK    (1U <<6)      /* Fast Interrupt mask */
+#define PSR_IRQ_MASK    (1U <<7)      /* Interrupt mask */
+#define PSR_ABT_MASK    (1U <<8)      /* Asynchronous Abort mask */

Nit: Did you mean to insert blanks also on the rhs of the <<, like you ...

xen/include/public/arch-arm.h typedef uint64_t xen_callback_t; · line 350

Quoted 5 lines
xen/include/public/arch-arm.h +5 -0
+#define PSR_BIG_ENDIAN  (1U << 9)     /* arm32: Big Endian Mode */
+#define PSR_DBG_MASK    (1U << 9)     /* arm64: Debug Exception mask */
+#define PSR_IT_MASK     (0x0600fc00U) /* Thumb If-Then Mask */
+#define PSR_JAZELLE     (1U << 24)    /* Jazelle Mode */
+#define PSR_Z           (1U << 30)    /* Zero condition flag */

... did everywhere here?

As an aside I wonder why they're here: They look like definitions of processor registers, which aren't under our (Xen's) control. I ask in part because the presence of such constants may then be taken as justification to add similar things in new ports. Yet such definitions shouldn't be put here.

Jan

#14 lore raw

Re: [PATCH 3/3] xen/public: arch-arm: All PSR_* defines should be unsigned

Hi Jan,

Quoted 23 lines · Jan Beulich
Quoted 9 lines · Julien Grall
xen/include/public/arch-arm.h +0 -3
@@ -339,36 +339,36 @@ typedef uint64_t xen_callback_t;
 
  /* PSR bits (CPSR, SPSR) */
 
-#define PSR_THUMB       (1<<5)        /* Thumb Mode enable */
-#define PSR_FIQ_MASK    (1<<6)        /* Fast Interrupt mask */
-#define PSR_IRQ_MASK    (1<<7)        /* Interrupt mask */

xen/include/public/arch-arm.h typedef uint64_t xen_callback_t; · line 345

Quoted 10 lines
xen/include/public/arch-arm.h +4 -6
-#define PSR_ABT_MASK    (1<<8)        /* Asynchronous Abort mask */
-#define PSR_BIG_ENDIAN  (1<<9)        /* arm32: Big Endian Mode */
-#define PSR_DBG_MASK    (1<<9)        /* arm64: Debug Exception mask */
-#define PSR_IT_MASK     (0x0600fc00)  /* Thumb If-Then Mask */
-#define PSR_JAZELLE     (1<<24)       /* Jazelle Mode */
-#define PSR_Z           (1<<30)       /* Zero condition flag */
+#define PSR_THUMB       (1U <<5)      /* Thumb Mode enable */
+#define PSR_FIQ_MASK    (1U <<6)      /* Fast Interrupt mask */
+#define PSR_IRQ_MASK    (1U <<7)      /* Interrupt mask */
+#define PSR_ABT_MASK    (1U <<8)      /* Asynchronous Abort mask */

Nit: Did you mean to insert blanks also on the rhs of the <<, like you ...

Quoted 7 lines

xen/include/public/arch-arm.h typedef uint64_t xen_callback_t; · line 350

Quoted 5 lines
xen/include/public/arch-arm.h +5 -0
+#define PSR_BIG_ENDIAN  (1U << 9)     /* arm32: Big Endian Mode */
+#define PSR_DBG_MASK    (1U << 9)     /* arm64: Debug Exception mask */
+#define PSR_IT_MASK     (0x0600fc00U) /* Thumb If-Then Mask */
+#define PSR_JAZELLE     (1U << 24)    /* Jazelle Mode */
+#define PSR_Z           (1U << 30)    /* Zero condition flag */

... did everywhere here?

Yes I did. I will update the patch.

Quoted 3 lines

As an aside I wonder why they're here: They look like definitions of processor registers, which aren't under our (Xen's) control.

I agree they are not under Xen's control. However, they are used by the toolstack and IIRC back then they were not available in any other headers.

Note that they are only available by the tools and the hypervisor (see #ifdef above).

Quoted 4 lines

I ask in
part because the presence of such constants may then be taken as justification to add similar things in new ports. Yet such definitions shouldn't be put here.

From my understanding we are using the public headers to provide macros/defines that are used by both the toolstack and the hypervisor. If they are not meant to be exposed to the guest, then they will be protected with "#if defined(__XEN__) || defined(__XEN_TOOLS__)".

I think we are in a similar situation here. So it is not clear where they should be put if we need to share them between the hypervisor and the toolstack.

Cheers,

Signature · 1 line
Julien Grall
#15 lore raw

Re: [PATCH 3/3] xen/public: arch-arm: All PSR_* defines should be unsigned

Quoted 47 lines · Julien Grall

Hi Jan,

Quoted 21 lines · Jan Beulich
Quoted 7 lines · Julien Grall
xen/include/public/arch-arm.h +0 -3
@@ -339,36 +339,36 @@ typedef uint64_t xen_callback_t;
   /* PSR bits (CPSR, SPSR) */
-#define PSR_THUMB       (1<<5)        /* Thumb Mode enable */
-#define PSR_FIQ_MASK    (1<<6)        /* Fast Interrupt mask */
-#define PSR_IRQ_MASK    (1<<7)        /* Interrupt mask */

xen/include/public/arch-arm.h typedef uint64_t xen_callback_t; · line 343

Quoted 10 lines
xen/include/public/arch-arm.h +4 -6
-#define PSR_ABT_MASK    (1<<8)        /* Asynchronous Abort mask */
-#define PSR_BIG_ENDIAN  (1<<9)        /* arm32: Big Endian Mode */
-#define PSR_DBG_MASK    (1<<9)        /* arm64: Debug Exception mask */
-#define PSR_IT_MASK     (0x0600fc00)  /* Thumb If-Then Mask */
-#define PSR_JAZELLE     (1<<24)       /* Jazelle Mode */
-#define PSR_Z           (1<<30)       /* Zero condition flag */
+#define PSR_THUMB       (1U <<5)      /* Thumb Mode enable */
+#define PSR_FIQ_MASK    (1U <<6)      /* Fast Interrupt mask */
+#define PSR_IRQ_MASK    (1U <<7)      /* Interrupt mask */
+#define PSR_ABT_MASK    (1U <<8)      /* Asynchronous Abort mask */

Nit: Did you mean to insert blanks also on the rhs of the <<, like you ...

Quoted 7 lines

xen/include/public/arch-arm.h typedef uint64_t xen_callback_t; · line 350

Quoted 5 lines
xen/include/public/arch-arm.h +5 -0
+#define PSR_BIG_ENDIAN  (1U << 9)     /* arm32: Big Endian Mode */
+#define PSR_DBG_MASK    (1U << 9)     /* arm64: Debug Exception mask */
+#define PSR_IT_MASK     (0x0600fc00U) /* Thumb If-Then Mask */
+#define PSR_JAZELLE     (1U << 24)    /* Jazelle Mode */
+#define PSR_Z           (1U << 30)    /* Zero condition flag */

... did everywhere here?

Yes I did. I will update the patch.

Quoted 3 lines

As an aside I wonder why they're here: They look like definitions of processor registers, which aren't under our (Xen's) control.

I agree they are not under Xen's control. However, they are used by the toolstack and IIRC back then they were not available in any other headers.

Note that they are only available by the tools and the hypervisor (see #ifdef above).

Quoted 4 lines

I ask in
part because the presence of such constants may then be taken as justification to add similar things in new ports. Yet such definitions shouldn't be put here.

Quoted 4 lines

From my understanding we are using the public headers to provide macros/defines
that are used by both the toolstack and the hypervisor. If they are not meant to be exposed to the guest, then they will be protected with "#if defined(__XEN__) || defined(__XEN_TOOLS__)".

I think we are in a similar situation here. So it is not clear where they should be put if we need to share them between the hypervisor and the toolstack.

What about include/xen/lib? There are headers below that linked at build time via tools/include/Makefile to tools/include/xen/lib.

Juergen

#16 lore raw

Re: [PATCH 3/3] xen/public: arch-arm: All PSR_* defines should be unsigned

Hi,

Quoted 50 lines · Juergen Gross
Quoted 49 lines · Julien Grall

Hi Jan,

Quoted 22 lines · Jan Beulich
Quoted 11 lines · Julien Grall
xen/include/public/arch-arm.h +0 -6
@@ -339,36 +339,36 @@ typedef uint64_t xen_callback_t;
   /* PSR bits (CPSR, SPSR) */
-#define PSR_THUMB       (1<<5)        /* Thumb Mode enable */
-#define PSR_FIQ_MASK    (1<<6)        /* Fast Interrupt mask */
-#define PSR_IRQ_MASK    (1<<7)        /* Interrupt mask */
-#define PSR_ABT_MASK    (1<<8)        /* Asynchronous Abort mask */
-#define PSR_BIG_ENDIAN  (1<<9)        /* arm32: Big Endian Mode */
-#define PSR_DBG_MASK    (1<<9)        /* arm64: Debug Exception 

mask */

xen/include/public/arch-arm.h typedef uint64_t xen_callback_t; · line 345

Quoted 7 lines
xen/include/public/arch-arm.h +4 -3
-#define PSR_IT_MASK     (0x0600fc00)  /* Thumb If-Then Mask */
-#define PSR_JAZELLE     (1<<24)       /* Jazelle Mode */
-#define PSR_Z           (1<<30)       /* Zero condition flag */
+#define PSR_THUMB       (1U <<5)      /* Thumb Mode enable */
+#define PSR_FIQ_MASK    (1U <<6)      /* Fast Interrupt mask */
+#define PSR_IRQ_MASK    (1U <<7)      /* Interrupt mask */
+#define PSR_ABT_MASK    (1U <<8)      /* Asynchronous Abort mask */

Nit: Did you mean to insert blanks also on the rhs of the <<, like you ...

Quoted 8 lines

xen/include/public/arch-arm.h typedef uint64_t xen_callback_t; · line 350

Quoted 6 lines
xen/include/public/arch-arm.h +2 -0
+#define PSR_BIG_ENDIAN  (1U << 9)     /* arm32: Big Endian Mode */
+#define PSR_DBG_MASK    (1U << 9)     /* arm64: Debug Exception 

mask */

xen/include/public/arch-arm.h +3 -0
+#define PSR_IT_MASK     (0x0600fc00U) /* Thumb If-Then Mask */
+#define PSR_JAZELLE     (1U << 24)    /* Jazelle Mode */
+#define PSR_Z           (1U << 30)    /* Zero condition flag */

... did everywhere here?

Yes I did. I will update the patch.

Quoted 3 lines

As an aside I wonder why they're here: They look like definitions of processor registers, which aren't under our (Xen's) control.

I agree they are not under Xen's control. However, they are used by the toolstack and IIRC back then they were not available in any other headers.

Note that they are only available by the tools and the hypervisor (see #ifdef above).

Quoted 4 lines

I ask in
part because the presence of such constants may then be taken as justification to add similar things in new ports. Yet such definitions shouldn't be put here.

Quoted 6 lines
Quoted 3 lines

 From my understanding we are using the public headers to provide macros/defines that are used by both the toolstack and the hypervisor. If they are not meant to be exposed to the guest, then they will be protected with "#if defined(__XEN__) || defined(__XEN_TOOLS__)".

I think we are in a similar situation here. So it is not clear where they should be put if we need to share them between the hypervisor and the toolstack.

What about include/xen/lib? There are headers below that linked at build time via tools/include/Makefile to tools/include/xen/lib.

To me, the question is why would we want to move PSR_* in xen/lib (or whatever name we decide) but all the other defines that are only used by the toolstack would still be in public/.

So are you suggesting to move all the tools only information in xen/lib?

Cheers,

Signature · 1 line
Julien Grall
#17 lore raw

Re: [PATCH 3/3] xen/public: arch-arm: All PSR_* defines should be unsigned

Quoted 53 lines · Julien Grall

Hi,

Quoted 50 lines · Juergen Gross
Quoted 49 lines · Julien Grall

Hi Jan,

Quoted 21 lines · Jan Beulich
Quoted 7 lines · Julien Grall
xen/include/public/arch-arm.h +0 -3
@@ -339,36 +339,36 @@ typedef uint64_t xen_callback_t;
   /* PSR bits (CPSR, SPSR) */
-#define PSR_THUMB       (1<<5)        /* Thumb Mode enable */
-#define PSR_FIQ_MASK    (1<<6)        /* Fast Interrupt mask */
-#define PSR_IRQ_MASK    (1<<7)        /* Interrupt mask */

xen/include/public/arch-arm.h typedef uint64_t xen_callback_t; · line 343

Quoted 10 lines
xen/include/public/arch-arm.h +4 -6
-#define PSR_ABT_MASK    (1<<8)        /* Asynchronous Abort mask */
-#define PSR_BIG_ENDIAN  (1<<9)        /* arm32: Big Endian Mode */
-#define PSR_DBG_MASK    (1<<9)        /* arm64: Debug Exception mask */
-#define PSR_IT_MASK     (0x0600fc00)  /* Thumb If-Then Mask */
-#define PSR_JAZELLE     (1<<24)       /* Jazelle Mode */
-#define PSR_Z           (1<<30)       /* Zero condition flag */
+#define PSR_THUMB       (1U <<5)      /* Thumb Mode enable */
+#define PSR_FIQ_MASK    (1U <<6)      /* Fast Interrupt mask */
+#define PSR_IRQ_MASK    (1U <<7)      /* Interrupt mask */
+#define PSR_ABT_MASK    (1U <<8)      /* Asynchronous Abort mask */

Nit: Did you mean to insert blanks also on the rhs of the <<, like you ...

Quoted 7 lines

xen/include/public/arch-arm.h typedef uint64_t xen_callback_t; · line 350

Quoted 5 lines
xen/include/public/arch-arm.h +5 -0
+#define PSR_BIG_ENDIAN  (1U << 9)     /* arm32: Big Endian Mode */
+#define PSR_DBG_MASK    (1U << 9)     /* arm64: Debug Exception mask */
+#define PSR_IT_MASK     (0x0600fc00U) /* Thumb If-Then Mask */
+#define PSR_JAZELLE     (1U << 24)    /* Jazelle Mode */
+#define PSR_Z           (1U << 30)    /* Zero condition flag */

... did everywhere here?

Yes I did. I will update the patch.

Quoted 3 lines

As an aside I wonder why they're here: They look like definitions of processor registers, which aren't under our (Xen's) control.

I agree they are not under Xen's control. However, they are used by the toolstack and IIRC back then they were not available in any other headers.

Note that they are only available by the tools and the hypervisor (see #ifdef above).

Quoted 4 lines

I ask in
part because the presence of such constants may then be taken as justification to add similar things in new ports. Yet such definitions shouldn't be put here.

 From my understanding we are using the public headers to provide macros/defines that are used by both the toolstack and the hypervisor. If they are not meant to be exposed to the guest, then they will be protected with "#if defined(__XEN__) || defined(__XEN_TOOLS__)".

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

I think we are in a similar situation here. So it is not clear where they should be put if we need to share them between the hypervisor and the toolstack.

What about include/xen/lib? There are headers below that linked at build time via tools/include/Makefile to tools/include/xen/lib.

To me, the question is why would we want to move PSR_* in xen/lib (or whatever name we decide) but all the other defines that are only used by the toolstack would still be in public/.

So are you suggesting to move all the tools only information in xen/lib?

I didn't want to suggest that, especially with our general desire to switch the tools' interfaces to stable ones.

I just wanted to point out that there are other locations available already where such information could be shared between hypervisor and tools. Especially information related to hardware (so not an interface we are defining) might be a good candidate for such an alternative location.

But in the end it is not me to decide what to use. I was just giving a hint. :-)

Juergen

#18 lore raw

Re: [PATCH 3/3] xen/public: arch-arm: All PSR_* defines should be unsigned

Hi Juergen,

Quoted 61 lines · Juergen Gross
Quoted 60 lines · Julien Grall

Hi,

Quoted 56 lines · Juergen Gross
Quoted 44 lines · Julien Grall

Hi Jan,

Quoted 22 lines · Jan Beulich
Quoted 11 lines · Julien Grall
xen/include/public/arch-arm.h +0 -6
@@ -339,36 +339,36 @@ typedef uint64_t xen_callback_t;
   /* PSR bits (CPSR, SPSR) */
-#define PSR_THUMB       (1<<5)        /* Thumb Mode enable */
-#define PSR_FIQ_MASK    (1<<6)        /* Fast Interrupt mask */
-#define PSR_IRQ_MASK    (1<<7)        /* Interrupt mask */
-#define PSR_ABT_MASK    (1<<8)        /* Asynchronous Abort mask */
-#define PSR_BIG_ENDIAN  (1<<9)        /* arm32: Big Endian Mode */
-#define PSR_DBG_MASK    (1<<9)        /* arm64: Debug Exception 

mask */

xen/include/public/arch-arm.h typedef uint64_t xen_callback_t; · line 345

Quoted 7 lines
xen/include/public/arch-arm.h +4 -3
-#define PSR_IT_MASK     (0x0600fc00)  /* Thumb If-Then Mask */
-#define PSR_JAZELLE     (1<<24)       /* Jazelle Mode */
-#define PSR_Z           (1<<30)       /* Zero condition flag */
+#define PSR_THUMB       (1U <<5)      /* Thumb Mode enable */
+#define PSR_FIQ_MASK    (1U <<6)      /* Fast Interrupt mask */
+#define PSR_IRQ_MASK    (1U <<7)      /* Interrupt mask */
+#define PSR_ABT_MASK    (1U <<8)      /* Asynchronous Abort mask */

Nit: Did you mean to insert blanks also on the rhs of the <<, like you ...

Quoted 8 lines

xen/include/public/arch-arm.h typedef uint64_t xen_callback_t; · line 350

Quoted 6 lines
xen/include/public/arch-arm.h +2 -0
+#define PSR_BIG_ENDIAN  (1U << 9)     /* arm32: Big Endian Mode */
+#define PSR_DBG_MASK    (1U << 9)     /* arm64: Debug Exception 

mask */

xen/include/public/arch-arm.h +3 -0
+#define PSR_IT_MASK     (0x0600fc00U) /* Thumb If-Then Mask */
+#define PSR_JAZELLE     (1U << 24)    /* Jazelle Mode */
+#define PSR_Z           (1U << 30)    /* Zero condition flag */

... did everywhere here?

Yes I did. I will update the patch.

Quoted 3 lines

As an aside I wonder why they're here: They look like definitions of processor registers, which aren't under our (Xen's) control.

I agree they are not under Xen's control. However, they are used by the toolstack and IIRC back then they were not available in any other headers.

Note that they are only available by the tools and the hypervisor (see #ifdef above).

Quoted 8 lines
Quoted 4 lines

I ask in
part because the presence of such constants may then be taken as justification to add similar things in new ports. Yet such definitions shouldn't be put here.

 From my understanding we are using the public headers to provide macros/defines that are used by both the toolstack and the hypervisor. If they are not meant to be exposed to the guest, then they will be protected with "#if defined(__XEN__) || defined(__XEN_TOOLS__)".

I think we are in a similar situation here. So it is not clear where they should be put if we need to share them between the hypervisor and the toolstack.

What about include/xen/lib? There are headers below that linked at build time via tools/include/Makefile to tools/include/xen/lib.

Quoted 6 lines
Quoted 3 lines

To me, the question is why would we want to move PSR_* in xen/lib (or whatever name we decide) but all the other defines that are only used by the toolstack would still be in public/.

So are you suggesting to move all the tools only information in xen/lib?

I didn't want to suggest that, especially with our general desire to switch the tools' interfaces to stable ones.

Ok. If there are a desire to switch the tools interface to stables one. Then...

Quoted 5 lines

I just wanted to point out that there are other locations available already where such information could be shared between hypervisor and tools. Especially information related to hardware (so not an interface we are defining) might be a good candidate for such an alternative location.

... I disagree with moving PSR_* outside of the public interface because they are those defines are used in hypercalls. So they would be part of the ABI.

Cheers,

Signature · 1 line
Julien Grall
#19 lore raw

Re: [PATCH 3/3] xen/public: arch-arm: All PSR_* defines should be unsigned

In reply to Julien Grall
Quoted 9 lines · Julien Grall
Quoted 2 lines · Jan Beulich

As an aside I wonder why they're here: They look like definitions of processor registers, which aren't under our (Xen's) control.

I agree they are not under Xen's control. However, they are used by the toolstack and IIRC back then they were not available in any other headers.

Note that they are only available by the tools and the hypervisor (see #ifdef above).

Yes, I did notice that (or else I would have used stronger wording).

Quoted 5 lines
Quoted 4 lines

I ask in
part because the presence of such constants may then be taken as justification to add similar things in new ports. Yet such definitions shouldn't be put here.

Quoted 8 lines

From my understanding we are using the public headers to provide
macros/defines that are used by both the toolstack and the hypervisor. If they are not meant to be exposed to the guest, then they will be protected with "#if defined(__XEN__) || defined(__XEN_TOOLS__)".

I think we are in a similar situation here. So it is not clear where they should be put if we need to share them between the hypervisor and the toolstack.

On x86 we simply arrange for certain hypervisor headers to be re-usable from the toolstack. See in particular arch/x86/include/asm/x86-*.h. And of course everything under include/xen/lib/x86/, but those are our own definitions, not ones meant to solely express relevant hw spec aspects.

Jan

#20 lore raw

Re: [PATCH 3/3] xen/public: arch-arm: All PSR_* defines should be unsigned

Hi Jan,

Quoted 23 lines · Jan Beulich
Quoted 9 lines · Julien Grall
Quoted 2 lines · Jan Beulich

As an aside I wonder why they're here: They look like definitions of processor registers, which aren't under our (Xen's) control.

I agree they are not under Xen's control. However, they are used by the toolstack and IIRC back then they were not available in any other headers.

Note that they are only available by the tools and the hypervisor (see #ifdef above).

Yes, I did notice that (or else I would have used stronger wording).

Quoted 10 lines
Quoted 4 lines

I ask in
part because the presence of such constants may then be taken as justification to add similar things in new ports. Yet such definitions shouldn't be put here.

From my understanding we are using the public headers to provide
macros/defines that are used by both the toolstack and the hypervisor. If they are not meant to be exposed to the guest, then they will be protected with "#if defined(__XEN__) || defined(__XEN_TOOLS__)".

Quoted 8 lines
Quoted 3 lines

I think we are in a similar situation here. So it is not clear where they should be put if we need to share them between the hypervisor and the toolstack.

On x86 we simply arrange for certain hypervisor headers to be re-usable from the toolstack. See in particular arch/x86/include/asm/x86-*.h. And of course everything under include/xen/lib/x86/, but those are our own definitions, not ones meant to solely express relevant hw spec aspects.

Even if they are defined by the HW, we still need them to easily create some hypercalls field.

If we are planning to have a stable toolstack ABI (as Juergen suggested), then I would find a bit odd that onewould need to include lib/ (or provide their own header) in order to update the fields.

Anyway, I am not planning to do any re-ordering anytime soon for the public. But I would be happy to take part of the discussion if there are a general agreement to split further and someone wants to write patches.

Cheers,

Signature · 1 line
Julien Grall
#21 lore raw
In reply to Julien Grall

Hi,

Quoted 17 lines · Julien Grall

From: Julien Grall <[email protected]>

Hi all,

This is a small series to fix some of the issues found while playing with -Wconversion and -Warith-conversion.

There are a lot more but the bulk are in
- bitmap
- cpumask
- nodemask
- bitops/atomics
- find_*

Some are not too difficult to address but other there are even prototype conflicts between arm x86.

Quoted 7 lines

Cheers,

Julien Grall (3):
xen/arm: vmmio: The number of entries cannot be negative xen/arm: vgic: Use 'unsigned int' rather than 'int' whenever it is
possible
xen/public: arch-arm: All PSR_* defines should be unsigned

I have committed the series.

Cheers,

Signature · 1 line
Julien Grall