Skip to contentSkip to conversation

cpu/a9mpcore: Set number of GIC priority bits to 5

PATCH Superseded Sai Pavan Boddu 3 participants 7 messages Feb 21, 2020 – Feb 24, 2020 1 message not in the archive

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v2 1/3 arm_gic: Mask the un-supported priority bits

Priority bits implemented in arm-gic can be 8 to 4, un-implemented bits are read as zeros(RAZ).

---
 hw/intc/arm_gic.c                | 26 ++++++++++++++++++++++++--
 hw/intc/arm_gic_common.c         |  1 +
 include/hw/intc/arm_gic_common.h |  1 +
 3 files changed, 26 insertions(+), 2 deletions(-)
hw/intc/arm_gic.c +24 -2
index 1d7da7b..dec8767 100644
@@ -641,6 +641,23 @@ uint32_t gic_acknowledge_irq(GICState *s, int cpu, MemTxAttrs attrs)
     return ret;
 }
 
+static uint32_t gic_fullprio_mask(GICState *s, int cpu)
+{
+    /*
+     * Return a mask word which clears the unimplemented priority
+     * bits from a priority value for an interrupt. (Not to be
+     * confused with the group priority, whose mask depends on BPR.)
+     */
+    int unimpBits;
+
+    if (gic_is_vcpu(cpu)) {
+        unimpBits = GIC_VIRT_MAX_GROUP_PRIO_BITS;
+    } else {
+        unimpBits = 8 - s->n_prio_bits;
+    }
+    return ~0U << unimpBits;
+}
+
 void gic_dist_set_priority(GICState *s, int cpu, int irq, uint8_t val,
                       MemTxAttrs attrs)
 {
@@ -669,7 +686,7 @@ static uint32_t gic_dist_get_priority(GICState *s, int cpu, int irq,
         }
         prio = (prio << 1) & 0xff; /* Non-secure view */
     }
-    return prio;
+    return prio & gic_fullprio_mask(s, cpu);
 }
 
 static void gic_set_priority_mask(GICState *s, int cpu, uint8_t pmask,
@@ -684,7 +701,7 @@ static void gic_set_priority_mask(GICState *s, int cpu, uint8_t pmask,
             return;
         }
     }
-    s->priority_mask[cpu] = pmask;
+    s->priority_mask[cpu] = pmask & gic_fullprio_mask(s, cpu);
 }
 
 static uint32_t gic_get_priority_mask(GICState *s, int cpu, MemTxAttrs attrs)
@@ -2055,6 +2072,11 @@ static void arm_gic_realize(DeviceState *dev, Error **errp)
         return;
     }
 
+    if (s->n_prio_bits > 8) {
+        error_setg(errp, "num-priority-bits cannot be greater than 8");
+        return;
+    }
+
     /* This creates distributor, main CPU interface (s->cpuiomem[0]) and if
      * enabled, virtualization extensions related interfaces (main virtual
      * interface (s->vifaceiomem[0]) and virtual CPU interface).
hw/intc/arm_gic_common.c +1 -0
index e6c4fe7..7b44d56 100644
@@ -357,6 +357,7 @@ static Property arm_gic_common_properties[] = {
     DEFINE_PROP_BOOL("has-security-extensions", GICState, security_extn, 0),
     /* True if the GIC should implement the virtualization extensions */
     DEFINE_PROP_BOOL("has-virtualization-extensions", GICState, virt_extn, 0),
+    DEFINE_PROP_UINT32("num-priority-bits", GICState, n_prio_bits, 8),
     DEFINE_PROP_END_OF_LIST(),
 };
 
include/hw/intc/arm_gic_common.h +1 -0
index b5585fe..6e0d6b8 100644
@@ -96,6 +96,7 @@ typedef struct GICState {
     uint16_t priority_mask[GIC_NCPU_VCPU];
     uint16_t running_priority[GIC_NCPU_VCPU];
     uint16_t current_pending[GIC_NCPU_VCPU];
+    uint32_t n_prio_bits;
 
     /* If we present the GICv2 without security extensions to a guest,
      * the guest can configure the GICC_CTLR to configure group 1 binary point
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH v2 1/3] arm_gic: Mask the un-supported priority bits

Quoted 22 lines · Sai Pavan Boddu

Priority bits implemented in arm-gic can be 8 to 4, un-implemented bits are read as zeros(RAZ).

---
 hw/intc/arm_gic.c                | 26 ++++++++++++++++++++++++--
 hw/intc/arm_gic_common.c         |  1 +
 include/hw/intc/arm_gic_common.h |  1 +
 3 files changed, 26 insertions(+), 2 deletions(-)
hw/intc/arm_gic.c +3 -0
index 1d7da7b..dec8767 100644
@@ -641,6 +641,23 @@ uint32_t gic_acknowledge_irq(GICState *s, int cpu, MemTxAttrs attrs)
     return ret;
 }
 
+static uint32_t gic_fullprio_mask(GICState *s, int cpu)
+{
+    /*

hw/intc/arm_gic.c uint32_t gic_acknowledge_irq(GICState *s, int cpu, MemTxAttrs attrs) · line 656

Quoted 10 lines
hw/intc/arm_gic.c +10 -0
+     * Return a mask word which clears the unimplemented priority
+     * bits from a priority value for an interrupt. (Not to be
+     * confused with the group priority, whose mask depends on BPR.)
+     */
+    int unimpBits;
+
+    if (gic_is_vcpu(cpu)) {
+        unimpBits = GIC_VIRT_MAX_GROUP_PRIO_BITS;
+    } else {
+        unimpBits = 8 - s->n_prio_bits;

This isn't right; GIC_VIRT_MAX_GROUP_PRIO_BITS should be handled the same way as s->n_prio_bits. The expression I suggested in my comment on your v1 should work:

    if (gic_is_vcpu(cpu)) {
        pribits = GIC_VIRT_MAX_GROUP_PRIO_BITS;
    } else {
        pribits = s->n_prio_bits;
    }
    return ~0U << (8 - s->n_prio_bits);

hw/intc/arm_gic.c uint32_t gic_acknowledge_irq(GICState *s, int cpu, MemTxAttrs attrs) · line 663

Quoted 7 lines
hw/intc/arm_gic.c +4 -0
+    }
+    return ~0U << unimpBits;
+}
+
 void gic_dist_set_priority(GICState *s, int cpu, int irq, uint8_t val,
                       MemTxAttrs attrs)
 {

You seem to have lost the part of the patch which applies the mask in gic_dist_set_priority(). If the GIC only has 5 bits of priority we should not allow the guest to set more than that.

Quoted 19 lines
hw/intc/arm_gic.c +2 -2
@@ -669,7 +686,7 @@ static uint32_t gic_dist_get_priority(GICState *s, int cpu, int irq,
         }
         prio = (prio << 1) & 0xff; /* Non-secure view */
     }
-    return prio;
+    return prio & gic_fullprio_mask(s, cpu);
 }
 
 static void gic_set_priority_mask(GICState *s, int cpu, uint8_t pmask,
@@ -684,7 +701,7 @@ static void gic_set_priority_mask(GICState *s, int cpu, uint8_t pmask,
             return;
         }
     }
-    s->priority_mask[cpu] = pmask;
+    s->priority_mask[cpu] = pmask & gic_fullprio_mask(s, cpu);
 }
 
 static uint32_t gic_get_priority_mask(GICState *s, int cpu, MemTxAttrs attrs)

hw/intc/arm_gic.c static void arm_gic_realize(DeviceState *dev, Error **errp) · line 2078

Quoted 7 lines
hw/intc/arm_gic.c +4 -0
@@ -2055,6 +2072,11 @@ static void arm_gic_realize(DeviceState *dev, Error **errp)
         return;
     }
 
+    if (s->n_prio_bits > 8) {
+        error_setg(errp, "num-priority-bits cannot be greater than 8");
+        return;
+    }

You need to also check that the value is at least as large as the lowest permitted value, as I suggested in my v1 comment.

thanks
-- PMM

#3 lore raw

RE: [PATCH v2 1/3] arm_gic: Mask the un-supported priority bits

Hi Peter,

Will send V3 for below comments.
In v2 I may have confused with functionality of group priority interrupt bits. Now things look clear. Thanks.

Regards,
Sai Pavan

Quoted 103 lines

-----Original Message-----
From: Peter Maydell <[email protected]>
Sent: Friday, February 21, 2020 9:00 PM
To: Sai Pavan Boddu <[email protected]>
Cc: Edgar E . Iglesias <[email protected]>; Alistair Francis <[email protected]>; Anthony Liguori <[email protected]>; Andreas Färber <[email protected]>; qemu-arm <[email protected]>; QEMU Developers <[email protected]>
Subject: Re: [PATCH v2 1/3] arm_gic: Mask the un-supported priority bits

hw/intc/arm_gic.c uint32_t gic_acknowledge_irq(GICState *s, int

Quoted 16 lines · Sai Pavan Boddu

Priority bits implemented in arm-gic can be 8 to 4, un-implemented bits are read as zeros(RAZ).

---
 hw/intc/arm_gic.c                | 26 ++++++++++++++++++++++++--
 hw/intc/arm_gic_common.c         |  1 +
 include/hw/intc/arm_gic_common.h |  1 +
 3 files changed, 26 insertions(+), 2 deletions(-)
hw/intc/arm_gic.c index renamed from hw/intc/arm_gic.c +0 -0

1d7da7b..dec8767 100644

hw/intc/arm_gic.c +0 -0
@@ -641,6 +641,23 @@ uint32_t gic_acknowledge_irq(GICState *s, int

cpu, MemTxAttrs attrs)

Quoted 5 lines
hw/intc/arm_gic.c +2 -0
     return ret;
 }
 
+static uint32_t gic_fullprio_mask(GICState *s, int cpu) {
+    /*

hw/intc/arm_gic.c uint32_t gic_acknowledge_irq(GICState *s, int cpu, MemTxAttrs attrs) · line 656

Quoted 10 lines
hw/intc/arm_gic.c +10 -0
+     * Return a mask word which clears the unimplemented priority
+     * bits from a priority value for an interrupt. (Not to be
+     * confused with the group priority, whose mask depends on BPR.)
+     */
+    int unimpBits;
+
+    if (gic_is_vcpu(cpu)) {
+        unimpBits = GIC_VIRT_MAX_GROUP_PRIO_BITS;
+    } else {
+        unimpBits = 8 - s->n_prio_bits;

This isn't right; GIC_VIRT_MAX_GROUP_PRIO_BITS should be handled the same way as s->n_prio_bits. The expression I suggested in my comment on your v1 should work:

    if (gic_is_vcpu(cpu)) {
        pribits = GIC_VIRT_MAX_GROUP_PRIO_BITS;
    } else {
        pribits = s->n_prio_bits;
    }
    return ~0U << (8 - s->n_prio_bits);

hw/intc/arm_gic.c uint32_t gic_acknowledge_irq(GICState *s, int cpu, MemTxAttrs attrs)

Quoted 6 lines
hw/intc/arm_gic.c +4 -0
+    }
+    return ~0U << unimpBits;
+}
+
 void gic_dist_set_priority(GICState *s, int cpu, int irq, uint8_t val,
                       MemTxAttrs attrs)  {

You seem to have lost the part of the patch which applies the mask in gic_dist_set_priority(). If the GIC only has 5 bits of priority we should not allow the guest to set more than that.

hw/intc/arm_gic.c static uint32_t gic_dist_get_priority(GICState *s,

Quoted 1 line
hw/intc/arm_gic.c +0 -0
@@ -669,7 +686,7 @@ static uint32_t gic_dist_get_priority(GICState *s,

int cpu, int irq,

Quoted 9 lines
hw/intc/arm_gic.c +1 -1
         }
         prio = (prio << 1) & 0xff; /* Non-secure view */
     }
-    return prio;
+    return prio & gic_fullprio_mask(s, cpu);
 }
 
 static void gic_set_priority_mask(GICState *s, int cpu, uint8_t

pmask, @@ -684,7 +701,7 @@ static void gic_set_priority_mask(GICState

*s, int cpu, uint8_t pmask,

Quoted 9 lines
             return;
         }
     }
hw/intc/arm_gic.c +1 -1
-    s->priority_mask[cpu] = pmask;
+    s->priority_mask[cpu] = pmask & gic_fullprio_mask(s, cpu);
 }
 
 static uint32_t gic_get_priority_mask(GICState *s, int cpu,

MemTxAttrs attrs) @@ -2055,6 +2072,11 @@ static void

arm_gic_realize(DeviceState *dev, Error **errp)

hw/intc/arm_gic.c static void arm_gic_realize(DeviceState *dev, Error **errp) · line 2078

Quoted 7 lines
         return;
     }
hw/intc/arm_gic.c +4 -0
+    if (s->n_prio_bits > 8) {
+        error_setg(errp, "num-priority-bits cannot be greater than 8");
+        return;
+    }

You need to also check that the value is at least as large as the lowest permitted value, as I suggested in my v1 comment.

thanks
-- PMM

#4 lore raw

PATCH v2 2/3 cpu/a9mpcore: Set number of GIC priority bits to 5

In reply to a message not in the archive

All A9 CPUs have a GIC with 5 bits of priority.

---
 hw/cpu/a9mpcore.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/cpu/a9mpcore.c +4 -0
index 1f8bc8a..b4f6a7e 100644
@@ -16,6 +16,8 @@
 #include "hw/qdev-properties.h"
 #include "hw/core/cpu.h"
 
+#define A9_GIC_NUM_PRIORITY_BITS    5
+
 static void a9mp_priv_set_irq(void *opaque, int irq, int level)
 {
     A9MPPrivState *s = (A9MPPrivState *)opaque;
@@ -68,6 +70,8 @@ static void a9mp_priv_realize(DeviceState *dev, Error **errp)
     gicdev = DEVICE(&s->gic);
     qdev_prop_set_uint32(gicdev, "num-cpu", s->num_cpu);
     qdev_prop_set_uint32(gicdev, "num-irq", s->num_irq);
+    qdev_prop_set_uint32(gicdev, "num-priority-bits",
+                         A9_GIC_NUM_PRIORITY_BITS);
 
     /* Make the GIC's TZ support match the CPUs. We assume that
      * either all the CPUs have TZ, or none do.
Signature · 1 line
2.7.4
Reviewed-by on v2 2/3
#5 lore raw
Quoted 23 lines · Sai Pavan Boddu

All A9 CPUs have a GIC with 5 bits of priority.

---
 hw/cpu/a9mpcore.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/cpu/a9mpcore.c +2 -0
index 1f8bc8a..b4f6a7e 100644
@@ -16,6 +16,8 @@
 #include "hw/qdev-properties.h"
 #include "hw/core/cpu.h"
 
+#define A9_GIC_NUM_PRIORITY_BITS    5
+
 static void a9mp_priv_set_irq(void *opaque, int irq, int level)
 {
     A9MPPrivState *s = (A9MPPrivState *)opaque;

hw/cpu/a9mpcore.c static void a9mp_priv_realize(DeviceState *dev, Error **errp) · line 77

Quoted 8 lines
hw/cpu/a9mpcore.c +2 -0
@@ -68,6 +70,8 @@ static void a9mp_priv_realize(DeviceState *dev, Error **errp)
     gicdev = DEVICE(&s->gic);
     qdev_prop_set_uint32(gicdev, "num-cpu", s->num_cpu);
     qdev_prop_set_uint32(gicdev, "num-irq", s->num_irq);
+    qdev_prop_set_uint32(gicdev, "num-priority-bits",
+                         A9_GIC_NUM_PRIORITY_BITS);
 
     /* Make the GIC's TZ support match the CPUs. We assume that
      * either all the CPUs have TZ, or none do.

thanks
-- PMM

#6 lore raw

PATCH v2 3/3 cpu/arm11mpcore: Set number of GIC priority bits to 4

In reply to a message not in the archive

ARM11MPCore GIC is implemented with 4 priority bits.

---
 hw/cpu/arm11mpcore.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/cpu/arm11mpcore.c +5 -0
index 2e3e87c..ab9fadb 100644
@@ -15,6 +15,7 @@
 #include "hw/irq.h"
 #include "hw/qdev-properties.h"
 
+#define ARM11MPCORE_NUM_GIC_PRIORITY_BITS    4
 
 static void mpcore_priv_set_irq(void *opaque, int irq, int level)
 {
@@ -86,6 +87,10 @@ static void mpcore_priv_realize(DeviceState *dev, Error **errp)
 
     qdev_prop_set_uint32(gicdev, "num-cpu", s->num_cpu);
     qdev_prop_set_uint32(gicdev, "num-irq", s->num_irq);
+    qdev_prop_set_uint32(gicdev, "num-priority-bits",
+                         ARM11MPCORE_NUM_GIC_PRIORITY_BITS);
+
+
     object_property_set_bool(OBJECT(&s->gic), true, "realized", &err);
     if (err != NULL) {
         error_propagate(errp, err);
Signature · 1 line
2.7.4
Reviewed-by on v2 3/3
#7 lore raw

Re: [PATCH v2 3/3] cpu/arm11mpcore: Set number of GIC priority bits to 4

Quoted 22 lines · Sai Pavan Boddu

ARM11MPCore GIC is implemented with 4 priority bits.

---
 hw/cpu/arm11mpcore.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/cpu/arm11mpcore.c +1 -0
index 2e3e87c..ab9fadb 100644
@@ -15,6 +15,7 @@
 #include "hw/irq.h"
 #include "hw/qdev-properties.h"
 
+#define ARM11MPCORE_NUM_GIC_PRIORITY_BITS    4
 
 static void mpcore_priv_set_irq(void *opaque, int irq, int level)
 {

hw/cpu/arm11mpcore.c static void mpcore_priv_realize(DeviceState *dev, Error **errp) · line 96

Quoted 10 lines
hw/cpu/arm11mpcore.c +4 -0
@@ -86,6 +87,10 @@ static void mpcore_priv_realize(DeviceState *dev, Error **errp)
 
     qdev_prop_set_uint32(gicdev, "num-cpu", s->num_cpu);
     qdev_prop_set_uint32(gicdev, "num-irq", s->num_irq);
+    qdev_prop_set_uint32(gicdev, "num-priority-bits",
+                         ARM11MPCORE_NUM_GIC_PRIORITY_BITS);
+
+
     object_property_set_bool(OBJECT(&s->gic), true, "realized", &err);
     if (err != NULL) {
         error_propagate(errp, err);

thanks
-- PMM