Skip to contentSkip to conversation

xen/arm: vgic: Add missing 'U' in VGIC_ICFG_MASK for shifted constant

PATCH In review Henry Wang 4 participants 4 messages Jun 29, 2023 – Jul 4, 2023

lore
Share & tools
lore

Henry Wang

author
#0 lore raw

PATCH 1/1 xen/arm: vgic: Add missing 'U' in VGIC_ICFG_MASK for shifted constant

With UBSAN on some arm64 platforms, e.g. FVP_Base_RevC-2xAEMvA, the following splat will be printed while Dom0 is booting:

```
(XEN) ==================================================================
(XEN) UBSAN: Undefined behaviour in arch/arm/vgic.c:372:15
(XEN) left shift of 1 by 31 places cannot be represented in type 'int'
(XEN) Xen WARN at common/ubsan/ubsan.c:172
(XEN) ----[ Xen-4.18-unstable  arm64  debug=y ubsan=y  Not tainted ]----
```

This is because there is a device node in the device tree with 0xf as the interrupts property. Example of the device tree node is shown below:

```
ethernet@202000000 {
    compatible = "smsc,lan91c111";
    reg = <0x2 0x2000000 0x10000>;
    interrupts = <0xf>;
};
```

and this value is passed to vgic_get_virq_type() as "index" then "intr" in VGIC_ICFG_MASK.

Add the missing 'U' in VGIC_ICFG_MASK as a fix, and this should also addressing MISRA Rule 7.2:

A "u" or "U" suffix shall be applied to all integer constants that are represented in an unsigned type

---
This patch should be based on top of Julien's series "xen/arm: Enable UBSAN support" to test.

---
 xen/arch/arm/vgic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/vgic.c +1 -1
index c61c68870c..97d6f61066 100644
@@ -358,7 +358,7 @@ void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n)
     }
 }
 
-#define VGIC_ICFG_MASK(intr) (1 << ((2 * ((intr) % 16)) + 1))
+#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)
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 23 lines · Henry Wang

With UBSAN on some arm64 platforms, e.g. FVP_Base_RevC-2xAEMvA, the following splat will be printed while Dom0 is booting:

```
(XEN) ==================================================================
(XEN) UBSAN: Undefined behaviour in arch/arm/vgic.c:372:15
(XEN) left shift of 1 by 31 places cannot be represented in type 'int'
(XEN) Xen WARN at common/ubsan/ubsan.c:172
(XEN) ----[ Xen-4.18-unstable  arm64  debug=y ubsan=y  Not tainted ]----
```

This is because there is a device node in the device tree with 0xf as the interrupts property. Example of the device tree node is shown below:

```
ethernet@202000000 {
    compatible = "smsc,lan91c111";
    reg = <0x2 0x2000000 0x10000>;
    interrupts = <0xf>;
};
```

and this value is passed to vgic_get_virq_type() as "index" then "intr" in VGIC_ICFG_MASK.

Quoted 7 lines

Add the missing 'U' in VGIC_ICFG_MASK as a fix, and this should also addressing MISRA Rule 7.2:

A "u" or "U" suffix shall be applied to all integer constants that are represented in an unsigned type

Quoted 23 lines

---
This patch should be based on top of Julien's series "xen/arm: Enable UBSAN support" to test.

---
 xen/arch/arm/vgic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/vgic.c +1 -1
index c61c68870c..97d6f61066 100644
@@ -358,7 +358,7 @@ void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n)
     }
 }
 
-#define VGIC_ICFG_MASK(intr) (1 << ((2 * ((intr) % 16)) + 1))
+#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)
Signature · 1 line
2.25.1
Reviewed-by
#2 lore raw
Quoted 49 lines · Stefano Stabellini
Quoted 23 lines · Henry Wang

With UBSAN on some arm64 platforms, e.g. FVP_Base_RevC-2xAEMvA, the following splat will be printed while Dom0 is booting:

```
(XEN) ==================================================================
(XEN) UBSAN: Undefined behaviour in arch/arm/vgic.c:372:15
(XEN) left shift of 1 by 31 places cannot be represented in type 'int'
(XEN) Xen WARN at common/ubsan/ubsan.c:172
(XEN) ----[ Xen-4.18-unstable  arm64  debug=y ubsan=y  Not tainted ]----
```

This is because there is a device node in the device tree with 0xf as the interrupts property. Example of the device tree node is shown below:

```
ethernet@202000000 {
     compatible = "smsc,lan91c111";
     reg = <0x2 0x2000000 0x10000>;
     interrupts = <0xf>;
};
```

and this value is passed to vgic_get_virq_type() as "index" then "intr" in VGIC_ICFG_MASK.

Quoted 7 lines

Add the missing 'U' in VGIC_ICFG_MASK as a fix, and this should also addressing MISRA Rule 7.2:

A "u" or "U" suffix shall be applied to all integer constants that are represented in an unsigned type

Quoted 15 lines

---
This patch should be based on top of Julien's series "xen/arm: Enable UBSAN support" to test.

---
  xen/arch/arm/vgic.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/vgic.c +0 -0
index c61c68870c..97d6f61066 100644
@@ -358,7 +358,7 @@ void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n)
      }
  }
 
Quoted 8 lines
Quoted 8 lines
xen/arch/arm/vgic.c +1 -1
-#define VGIC_ICFG_MASK(intr) (1 << ((2 * ((intr) % 16)) + 1))
+#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)
Signature · 1 line
2.25.1
#3 lore raw
In reply to Stefano Stabellini

Hi,

Quoted 27 lines · Stefano Stabellini
Quoted 26 lines · Henry Wang

With UBSAN on some arm64 platforms, e.g. FVP_Base_RevC-2xAEMvA, the following splat will be printed while Dom0 is booting:

```
(XEN) ==================================================================
(XEN) UBSAN: Undefined behaviour in arch/arm/vgic.c:372:15
(XEN) left shift of 1 by 31 places cannot be represented in type 'int'
(XEN) Xen WARN at common/ubsan/ubsan.c:172
(XEN) ----[ Xen-4.18-unstable  arm64  debug=y ubsan=y  Not tainted ]----
```

This is because there is a device node in the device tree with 0xf as the interrupts property. Example of the device tree node is shown below:

```
ethernet@202000000 {
     compatible = "smsc,lan91c111";
     reg = <0x2 0x2000000 0x10000>;
     interrupts = <0xf>;
};
```

and this value is passed to vgic_get_virq_type() as "index" then "intr" in VGIC_ICFG_MASK.

Add the missing 'U' in VGIC_ICFG_MASK as a fix, and this should also addressing MISRA Rule 7.2:

Quoted 6 lines
Quoted 4 lines

A "u" or "U" suffix shall be applied to all integer constants that are represented in an unsigned type

It is now committed.

Cheers,

Signature · 1 line
Julien Grall