Skip to contentSkip to conversation

xen/arm: gic-v3: Implement correctly the callback send_SGI

PATCH In review Julien Grall 4 participants 11 messages Apr 27, 2015 – May 11, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/arm: gic-v3: Implement correctly the callback send_SGI

Currently, the GICv3 drivers is only able to send an SGI when the cpumask is provided. Although with the modes SGI_TARGET_OTHERS and SGI_TARGET_SELF, no cpumask is provided. Any usage of those modes will crash the hypersivor.

Move the rename gicv3_send_sgi to gicv3_send_sgi_list and implement the different modes:
- SGI_TARGET_OTHERS: Set the Interrupt Routing Mode (bit 40) to 1 (see Table 4 on Section 4.2.6 PRD03-GENC-010745 24.0)
- SGI_TARGET_SELF: Contrawise GICv2, the SGI registers doesn't provide a specific field. So use gicv3_send_sgi_list and pass the cpumask of the current CPU
- SGI_TARGET_LIST: Directly call gicv3_send_sgi_list with the given cpumask

---
 xen/arch/arm/gic-v3.c             | 25 +++++++++++++++++++++++--
 xen/include/asm-arm/gic_v3_defs.h |  2 +-
 2 files changed, 24 insertions(+), 3 deletions(-)
xen/arch/arm/gic-v3.c +23 -2
index b0f498e..e1574d8 100644
@@ -808,8 +808,7 @@ out:
     return tlist;
 }
 
-static void gicv3_send_sgi(enum gic_sgi sgi, enum gic_sgi_mode mode,
-                           const cpumask_t *cpumask)
+static void gicv3_send_sgi_list(enum gic_sgi sgi, const cpumask_t *cpumask)
 {
     int cpu = 0;
     uint64_t val;
@@ -839,6 +838,28 @@ static void gicv3_send_sgi(enum gic_sgi sgi, enum gic_sgi_mode mode,
     isb();
 }
 
+static void gicv3_send_sgi(enum gic_sgi sgi, enum gic_sgi_mode mode,
+                           const cpumask_t *cpumask)
+{
+    switch ( mode )
+    {
+    case SGI_TARGET_OTHERS:
+        WRITE_SYSREG(ICH_SGI_TARGET_OTHERS << ICH_SGI_IRQMODE_SHIFT |
+                     (register_t)sgi << ICH_SGI_IRQ_SHIFT,
+                     ICC_SGI1R_EL1);
+        isb();
+        break;
+    case SGI_TARGET_SELF:
+        gicv3_send_sgi_list(sgi, cpumask_of(smp_processor_id()));
+        break;
+    case SGI_TARGET_LIST:
+        gicv3_send_sgi_list(sgi, cpumask);
+        break;
+    default:
+        BUG();
+    }
+}
+
 /* Shut down the per-CPU GIC interface */
 static void gicv3_disable_interface(void)
 {
xen/include/asm-arm/gic_v3_defs.h +1 -1
index b8a1c2e..556f114 100644
@@ -147,7 +147,7 @@
 
 #define ICH_SGI_IRQMODE_SHIFT        40
 #define ICH_SGI_IRQMODE_MASK         0x1
-#define ICH_SGI_TARGET_OTHERS        1
+#define ICH_SGI_TARGET_OTHERS        1UL
 #define ICH_SGI_TARGET_LIST          0
 #define ICH_SGI_IRQ_SHIFT            24
 #define ICH_SGI_IRQ_MASK             0xf
Signature · 1 line
2.1.4
Acked-by on v1 1/1
#1 lore raw
Quoted 69 lines · Julien Grall

Currently, the GICv3 drivers is only able to send an SGI when the cpumask is provided. Although with the modes SGI_TARGET_OTHERS and SGI_TARGET_SELF, no cpumask is provided. Any usage of those modes will crash the hypersivor.

Move the rename gicv3_send_sgi to gicv3_send_sgi_list and implement the different modes:
- SGI_TARGET_OTHERS: Set the Interrupt Routing Mode (bit 40) to 1 (see Table 4 on Section 4.2.6 PRD03-GENC-010745 24.0)
- SGI_TARGET_SELF: Contrawise GICv2, the SGI registers doesn't provide a specific field. So use gicv3_send_sgi_list and pass the cpumask of the current CPU
- SGI_TARGET_LIST: Directly call gicv3_send_sgi_list with the given cpumask

---
 xen/arch/arm/gic-v3.c             | 25 +++++++++++++++++++++++--
 xen/include/asm-arm/gic_v3_defs.h |  2 +-
 2 files changed, 24 insertions(+), 3 deletions(-)
xen/arch/arm/gic-v3.c +23 -2
index b0f498e..e1574d8 100644
@@ -808,8 +808,7 @@ out:
     return tlist;
 }
 
-static void gicv3_send_sgi(enum gic_sgi sgi, enum gic_sgi_mode mode,
-                           const cpumask_t *cpumask)
+static void gicv3_send_sgi_list(enum gic_sgi sgi, const cpumask_t *cpumask)
 {
     int cpu = 0;
     uint64_t val;
@@ -839,6 +838,28 @@ static void gicv3_send_sgi(enum gic_sgi sgi, enum gic_sgi_mode mode,
     isb();
 }
 
+static void gicv3_send_sgi(enum gic_sgi sgi, enum gic_sgi_mode mode,
+                           const cpumask_t *cpumask)
+{
+    switch ( mode )
+    {
+    case SGI_TARGET_OTHERS:
+        WRITE_SYSREG(ICH_SGI_TARGET_OTHERS << ICH_SGI_IRQMODE_SHIFT |
+                     (register_t)sgi << ICH_SGI_IRQ_SHIFT,
+                     ICC_SGI1R_EL1);
+        isb();
+        break;
+    case SGI_TARGET_SELF:
+        gicv3_send_sgi_list(sgi, cpumask_of(smp_processor_id()));
+        break;
+    case SGI_TARGET_LIST:
+        gicv3_send_sgi_list(sgi, cpumask);
+        break;
+    default:
+        BUG();
+    }
+}
+
 /* Shut down the per-CPU GIC interface */
 static void gicv3_disable_interface(void)
 {
xen/include/asm-arm/gic_v3_defs.h +0 -0
index b8a1c2e..556f114 100644

xen/include/asm-arm/gic_v3_defs.h line 150

Quoted 5 lines
xen/include/asm-arm/gic_v3_defs.h +1 -1
@@ -147,7 +147,7 @@
 
 #define ICH_SGI_IRQMODE_SHIFT        40
 #define ICH_SGI_IRQMODE_MASK         0x1
-#define ICH_SGI_TARGET_OTHERS        1
+#define ICH_SGI_TARGET_OTHERS        1UL

Spurious change?

Aside from this:

Quoted 6 lines
xen/include/asm-arm/gic_v3_defs.h +0 -0
 #define ICH_SGI_TARGET_LIST          0
 #define ICH_SGI_IRQ_SHIFT            24
 #define ICH_SGI_IRQ_MASK             0xf
Signature · 1 line
2.1.4
#2 lore raw

Hi Stefano,

Quoted 7 lines · Stefano Stabellini
Quoted 6 lines · Julien Grall
xen/include/asm-arm/gic_v3_defs.h +0 -0
index b8a1c2e..556f114 100644
@@ -147,7 +147,7 @@
 
Quoted 6 lines

xen/include/asm-arm/gic_v3_defs.h line 150

Quoted 4 lines
xen/include/asm-arm/gic_v3_defs.h +1 -1
 #define ICH_SGI_IRQMODE_SHIFT        40
 #define ICH_SGI_IRQMODE_MASK         0x1
-#define ICH_SGI_TARGET_OTHERS        1
+#define ICH_SGI_TARGET_OTHERS        1UL

Spurious change?

No, this was a mistake when the GICv3 driver has been imported. The IRQMODE bit is 40 and 1 << 40 would throw the error:

gic-v3.c:847:9: error: left shift count >= width of type [-Werror]
WRITE_SYSREG(ICH_SGI_TARGET_OTHERS << ICH_SGI_IRQMODE_SHIFT | ^

Quoted 3 lines

Aside from this:

Thanks,

Signature · 1 line
Julien Grall
#3 lore raw
Quoted 17 lines · Julien Grall

Hi Stefano,

Quoted 7 lines · Stefano Stabellini
Quoted 6 lines · Julien Grall
xen/include/asm-arm/gic_v3_defs.h +0 -0
index b8a1c2e..556f114 100644
@@ -147,7 +147,7 @@
 
Quoted 6 lines

xen/include/asm-arm/gic_v3_defs.h line 150

Quoted 4 lines
xen/include/asm-arm/gic_v3_defs.h +1 -1
 #define ICH_SGI_IRQMODE_SHIFT        40
 #define ICH_SGI_IRQMODE_MASK         0x1
-#define ICH_SGI_TARGET_OTHERS        1
+#define ICH_SGI_TARGET_OTHERS        1UL

Spurious change?

Quoted 6 lines

No, this was a mistake when the GICv3 driver has been imported. The IRQMODE bit is 40 and 1 << 40 would throw the error:

gic-v3.c:847:9: error: left shift count >= width of type [-Werror]
WRITE_SYSREG(ICH_SGI_TARGET_OTHERS << ICH_SGI_IRQMODE_SHIFT | ^

I think you want 1ULL then so it is definitely always 64-bit.

#4 lore raw
Quoted 18 lines · Ian Campbell
Quoted 17 lines · Julien Grall

Hi Stefano,

Quoted 13 lines · Stefano Stabellini

xen/include/asm-arm/gic_v3_defs.h line 150

Quoted 10 lines · Julien Grall
xen/include/asm-arm/gic_v3_defs.h +1 -1
index b8a1c2e..556f114 100644
@@ -147,7 +147,7 @@
 
 #define ICH_SGI_IRQMODE_SHIFT        40
 #define ICH_SGI_IRQMODE_MASK         0x1
-#define ICH_SGI_TARGET_OTHERS        1
+#define ICH_SGI_TARGET_OTHERS        1UL

Spurious change?

Quoted 8 lines
Quoted 6 lines

No, this was a mistake when the GICv3 driver has been imported. The IRQMODE bit is 40 and 1 << 40 would throw the error:

gic-v3.c:847:9: error: left shift count >= width of type [-Werror]
WRITE_SYSREG(ICH_SGI_TARGET_OTHERS << ICH_SGI_IRQMODE_SHIFT | ^

I think you want 1ULL then so it is definitely always 64-bit.

This header is using UL for 64-bit. I know that Vijay's is planning to import more define for Linux which use UL for 64-bit.

I'd like to keep 1UL for consistency.
FWIW, GICv3 is only built for ARM64.

Regards,

Signature · 1 line
Julien Grall
#5 lore raw
Quoted 26 lines · Julien Grall
Quoted 25 lines · Ian Campbell
Quoted 23 lines · Julien Grall

Hi Stefano,

Quoted 7 lines · Stefano Stabellini
Quoted 6 lines · Julien Grall
xen/include/asm-arm/gic_v3_defs.h +0 -0
index b8a1c2e..556f114 100644
@@ -147,7 +147,7 @@
 
Quoted 6 lines

xen/include/asm-arm/gic_v3_defs.h line 150

Quoted 4 lines
xen/include/asm-arm/gic_v3_defs.h +1 -1
 #define ICH_SGI_IRQMODE_SHIFT        40
 #define ICH_SGI_IRQMODE_MASK         0x1
-#define ICH_SGI_TARGET_OTHERS        1
+#define ICH_SGI_TARGET_OTHERS        1UL

Spurious change?

No, this was a mistake when the GICv3 driver has been imported. The IRQMODE bit is 40 and 1 << 40 would throw the error:

gic-v3.c:847:9: error: left shift count >= width of type [-Werror]
WRITE_SYSREG(ICH_SGI_TARGET_OTHERS << ICH_SGI_IRQMODE_SHIFT | ^

Quoted 6 lines
Quoted 1 line

I think you want 1ULL then so it is definitely always 64-bit.

This header is using UL for 64-bit. I know that Vijay's is planning to import more define for Linux which use UL for 64-bit.

I'd like to keep 1UL for consistency.

OK.

Quoted 4 lines

FWIW, GICv3 is only built for ARM64.

Regards,

#6 lore raw
In reply to Julien Grall
Quoted 1 line · Julien Grall

Currently, the GICv3 drivers is only able to send an SGI when the cpumask

"driver"

Quoted 4 lines

is provided. Although with the modes SGI_TARGET_OTHERS and SGI_TARGET_SELF, no cpumask is provided. Any usage of those modes will crash the hypersivor.

Move the rename gicv3_send_sgi to gicv3_send_sgi_list and implement the

s/Move the r/R/

Quoted 4 lines

different modes:
- SGI_TARGET_OTHERS: Set the Interrupt Routing Mode (bit 40) to 1 (see Table 4 on Section 4.2.6 PRD03-GENC-010745 24.0)
- SGI_TARGET_SELF: Contrawise GICv2, the SGI registers doesn't provide

"Contrariwise"? But I think you really mean "Unlike". I'd also say "the GICv3 SGI registers" and s/doesn't/don't/.

Quoted 7 lines

a specific field. So use gicv3_send_sgi_list and pass the cpumask of the current CPU
- SGI_TARGET_LIST: Directly call gicv3_send_sgi_list with the given cpumask

Apart from the commit message nits one code comment:

[...]

xen/arch/arm/gic-v3.c static void gicv3_send_sgi(enum gic_sgi sgi, enum gic_sgi_mode mode, · line 848

Quoted 3 lines
xen/arch/arm/gic-v3.c +3 -0
+    case SGI_TARGET_OTHERS:
+        WRITE_SYSREG(ICH_SGI_TARGET_OTHERS << ICH_SGI_IRQMODE_SHIFT |
+                     (register_t)sgi << ICH_SGI_IRQ_SHIFT,

I don't think you want register_t here, unless ICC_SGI1R_EL1 might be a different width on different architectures.

I think you should just cast to uint64_t and WRITE_SYSREG64.

Ian.

#7 lore raw

Hi Ian,

Quoted 11 lines · Ian Campbell
Quoted 1 line · Julien Grall

Currently, the GICv3 drivers is only able to send an SGI when the cpumask

"driver"

Quoted 4 lines

is provided. Although with the modes SGI_TARGET_OTHERS and SGI_TARGET_SELF, no cpumask is provided. Any usage of those modes will crash the hypersivor.

Move the rename gicv3_send_sgi to gicv3_send_sgi_list and implement the

s/Move the r/R/

I missed while reviewing the commit message. I will fix it in the next version.

Quoted 7 lines
Quoted 4 lines

different modes:
- SGI_TARGET_OTHERS: Set the Interrupt Routing Mode (bit 40) to 1 (see Table 4 on Section 4.2.6 PRD03-GENC-010745 24.0)
- SGI_TARGET_SELF: Contrawise GICv2, the SGI registers doesn't provide

"Contrariwise"? But I think you really mean "Unlike". I'd also say "the GICv3 SGI registers" and s/doesn't/don't/.

Yes, "unlike" is better here.

Quoted 11 lines
Quoted 8 lines

a specific field. So use gicv3_send_sgi_list and pass the cpumask of the current CPU
- SGI_TARGET_LIST: Directly call gicv3_send_sgi_list with the given cpumask

Apart from the commit message nits one code comment:

Quoted 7 lines

[...]

xen/arch/arm/gic-v3.c static void gicv3_send_sgi(enum gic_sgi sgi, enum gic_sgi_mode mode, · line 848

Quoted 3 lines
xen/arch/arm/gic-v3.c +3 -0
+    case SGI_TARGET_OTHERS:
+        WRITE_SYSREG(ICH_SGI_TARGET_OTHERS << ICH_SGI_IRQMODE_SHIFT |
+                     (register_t)sgi << ICH_SGI_IRQ_SHIFT,

I don't think you want register_t here, unless ICC_SGI1R_EL1 might be a different width on different architectures.

Yes, ICC_SGIR1_EL1 is always 64-bit.

Quoted 1 line

I think you should just cast to uint64_t and WRITE_SYSREG64.

Right, I blindly re-use the WRITE_SYSREG as it was done on the previous implementation.

Although, the gic-v3 code seems to always use {READ,WRITE}_SYSREG. This seems wrong too. I will send a patch for replace the calls by the the 64-bit version.

Regards,

Signature · 1 line
Julien Grall
#8 lore raw
Quoted 49 lines · Julien Grall

Hi Ian,

Quoted 11 lines · Ian Campbell
Quoted 1 line · Julien Grall

Currently, the GICv3 drivers is only able to send an SGI when the cpumask

"driver"

Quoted 4 lines

is provided. Although with the modes SGI_TARGET_OTHERS and SGI_TARGET_SELF, no cpumask is provided. Any usage of those modes will crash the hypersivor.

Move the rename gicv3_send_sgi to gicv3_send_sgi_list and implement the

s/Move the r/R/

I missed while reviewing the commit message. I will fix it in the next version.

Quoted 7 lines
Quoted 4 lines

different modes:
- SGI_TARGET_OTHERS: Set the Interrupt Routing Mode (bit 40) to 1 (see Table 4 on Section 4.2.6 PRD03-GENC-010745 24.0)
- SGI_TARGET_SELF: Contrawise GICv2, the SGI registers doesn't provide

"Contrariwise"? But I think you really mean "Unlike". I'd also say "the GICv3 SGI registers" and s/doesn't/don't/.

Yes, "unlike" is better here.

Quoted 11 lines
Quoted 8 lines

a specific field. So use gicv3_send_sgi_list and pass the cpumask of the current CPU
- SGI_TARGET_LIST: Directly call gicv3_send_sgi_list with the given cpumask

Apart from the commit message nits one code comment:

Quoted 7 lines

[...]

xen/arch/arm/gic-v3.c static void gicv3_send_sgi(enum gic_sgi sgi, enum gic_sgi_mode mode, · line 848

Quoted 3 lines
xen/arch/arm/gic-v3.c +3 -0
+    case SGI_TARGET_OTHERS:
+        WRITE_SYSREG(ICH_SGI_TARGET_OTHERS << ICH_SGI_IRQMODE_SHIFT |
+                     (register_t)sgi << ICH_SGI_IRQ_SHIFT,

I don't think you want register_t here, unless ICC_SGI1R_EL1 might be a different width on different architectures.

Yes, ICC_SGIR1_EL1 is always 64-bit.

Quoted 8 lines
Quoted 1 line

I think you should just cast to uint64_t and WRITE_SYSREG64.

Right, I blindly re-use the WRITE_SYSREG as it was done on the previous implementation.

Although, the gic-v3 code seems to always use {READ,WRITE}_SYSREG. This seems wrong too. I will send a patch for replace the calls by the the 64-bit version.

Thanks (although do make sure each register really is 64-bit...)

#9 lore raw

Hi Ian,

Quoted 4 lines · Ian Campbell
Quoted 3 lines · Julien Grall
Quoted 1 line · Ian Campbell

I think you should just cast to uint64_t and WRITE_SYSREG64.

Quoted 8 lines
Quoted 6 lines

Right, I blindly re-use the WRITE_SYSREG as it was done on the previous implementation.

Although, the gic-v3 code seems to always use {READ,WRITE}_SYSREG. This seems wrong too. I will send a patch for replace the calls by the the 64-bit version.

Thanks (although do make sure each register really is 64-bit...)

I looked more closely to the call of READ_SYSREG/WRITE_SYSREG in the GICv3 code. They are use for:
- ICH_LR<n>: 64-bit on aarch64 and 32-bit on aarch32. Although, for
completion we would have to read ICH_LRC<n> for aarch32.
- ICC_SGIR1_EL1: 64-bit on both aarch64 and aarch32.

So the former is valid although it won't work correctly if someone decide to use GICv3 on AArch32. Although, I expect seen more issue than this one. So I will ignore it.

I will take care of the later in the new version of this patch.

Regards,

Signature · 1 line
Julien Grall
#10 lore raw
Quoted 16 lines · Julien Grall

Hi Ian,

Quoted 4 lines · Ian Campbell
Quoted 3 lines · Julien Grall
Quoted 1 line · Ian Campbell

I think you should just cast to uint64_t and WRITE_SYSREG64.

Quoted 8 lines
Quoted 6 lines

Right, I blindly re-use the WRITE_SYSREG as it was done on the previous implementation.

Although, the gic-v3 code seems to always use {READ,WRITE}_SYSREG. This seems wrong too. I will send a patch for replace the calls by the the 64-bit version.

Thanks (although do make sure each register really is 64-bit...)

Quoted 8 lines

I looked more closely to the call of READ_SYSREG/WRITE_SYSREG in the GICv3 code. They are use for:
- ICH_LR<n>: 64-bit on aarch64 and 32-bit on aarch32. Although, for
completion we would have to read ICH_LRC<n> for aarch32.
- ICC_SGIR1_EL1: 64-bit on both aarch64 and aarch32.

So the former is valid although it won't work correctly if someone decide to use GICv3 on AArch32.

Right, you would need a #define in cpregs.h for the arm32 case.

Quoted 4 lines

Although, I expect seen more issue than
this one. So I will ignore it.

I will take care of the later in the new version of this patch.

Thanks,

Ian.