Skip to contentSkip to conversation

xen/arm: Bunch of fixes for the vGIC emulation

PATCH In review Julien Grall 4 participants 24 messages Nov 18, 2015 – Dec 3, 2015

lore
Share & tools
lore
#0 lore raw

v2 cover xen/arm: Bunch of fixes for the vGIC emulation

Hi all,

The main purpose of this patch series is to fix the access to any register when the user doesn't write at the base offset of the registers.

At the same time, I took the opportunity to re-arrange the emulation and dropping any registers which don't exist or not required by the spec.

This series is based on "xen/arm: Support 32-bit access for 64-bit registers" [1]. I've provided a branch with the 2 series applied:

git://xenbits.xen.org/people/julieng/xen-unstable.git branch gic-emulation-v2

Note that the 2 first patch what meant to be present in the previous version but I messed up my git format-patch.

For all the changes see in each patch.

Sincerely yours,

[1] http://lists.xen.org/archives/html/xen-devel/2015-11/msg02188.html

Julien Grall (11):
xen/arm: vgic-v2: Implement correctly ICFGR{0,1} read-only xen/arm: vgic-v3: Don't try to emulate IROUTER which doesn't exist in
the spec
xen/arm: vgic-v3: Use the correct offset GICR_IGRPMODR0 xen/arm: vgic-v3: Only emulate identification registers required by
the spec
xen/arm: vgic: Properly emulate the full register
xen/arm: vgic-v3: Remove GICR_MOVALLR and GICR_MOVLPIR xen/arm: vgic: Re-order the register emulations to match the memory
map
xen/arm: vgic-v3: Emulate read to GICD_ICACTIVER<n> xen/arm: vgic-v3: Remove spurious return in GICR_INVALLR xen/arm: vgic-v3: Don't implement write-only register read as zero xen/arm: vgic-v3: Make clear that GICD_*SPI_* registers are reserved

 xen/arch/arm/vgic-v2.c            | 254 +++++++------
 xen/arch/arm/vgic-v3.c            | 733 +++++++++++++++++++++++++-------------
 xen/include/asm-arm/gic.h         |   2 +
 xen/include/asm-arm/gic_v3_defs.h |  19 +-
 xen/include/asm-arm/vgic-emul.h   |  24 ++
 5 files changed, 658 insertions(+), 374 deletions(-)
 create mode 100644 xen/include/asm-arm/vgic-emul.h
Signature · 1 line
2.1.4
#1 lore raw

PATCH v2 1/11 xen/arm: vgic-v2: Implement correctly ICFGR{0, 1} read-only

Each ITARGETSR register are 4-byte wide and the offset is in byte.

The current implementation is computing the offset of ICFGR1 and ICFG2 wonrgly result to emulate only the first 2 byte of the ICFGR<n> range read-only. The rest will be treated as read-write.

For convenience introduce ITARGETSR1 and ITARGETSR2.

---

We only store the value of ICFGR<n> registers for the guest own purpose today. Xen is not using it at all. So I don't think it's worth to backport it.

Changes in v2:
- This patch was supposed to be in v1, but messed up the git format-patch command

---
 xen/arch/arm/vgic-v2.c    | 6 ++++--
 xen/include/asm-arm/gic.h | 2 ++
 2 files changed, 6 insertions(+), 2 deletions(-)
xen/arch/arm/vgic-v2.c +4 -2
index c94f0f3..4fb954b 100644
@@ -507,10 +507,12 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info,
 
     case GICD_ICFGR: /* SGIs */
         goto write_ignore_32;
-    case GICD_ICFGR + 1: /* PPIs */
+
+    case GICD_ICFGR1:
         /* It is implementation defined if these are writeable. We chose not */
         goto write_ignore_32;
-    case GICD_ICFGR + 2 ... GICD_ICFGRN: /* SPIs */
+
+    case GICD_ICFGR2 ... GICD_ICFGRN: /* SPIs */
         if ( dabt.size != DABT_WORD ) goto bad_width;
         rank = vgic_rank_offset(v, 2, gicd_reg - GICD_ICFGR, DABT_WORD);
         if ( rank == NULL) goto write_ignore;
xen/include/asm-arm/gic.h +2 -0
index 3064d1c..42a2eec 100644
@@ -46,6 +46,8 @@
 #define GICD_ITARGETSR8 (0x820)
 #define GICD_ITARGETSRN (0xBF8)
 #define GICD_ICFGR      (0xC00)
+#define GICD_ICFGR1     (0xC04)
+#define GICD_ICFGR2     (0xC08)
 #define GICD_ICFGRN     (0xCFC)
 #define GICD_NSACR      (0xE00)
 #define GICD_NSACRN     (0xEFC)
Signature · 1 line
2.1.4
#2 lore raw

Re: [PATCH v2 01/11] xen/arm: vgic-v2: Implement correctly ICFGR{0, 1} read-only

Quoted 1 line · Julien Grall

Each ITARGETSR register are 4-byte wide and the offset is in byte.

"is 4-bytes" ... "is in bytes".

Quoted 3 lines

The current implementation is computing the offset of ICFGR1 and ICFG2 wonrgly result to emulate only the first 2 byte of the ICFGR<n> range

wrongly

Quoted 27 lines

read-only. The rest will be treated as read-write.

For convenience introduce ITARGETSR1 and ITARGETSR2.

---

    We only store the value of ICFGR<n> registers for the guest own purpose
    today. Xen is not using it at all. So I don't think it's worth to backport
    it.

    Changes in v2:
        - This patch was supposed to be in v1, but messed up the git format-patch command
---
 xen/arch/arm/vgic-v2.c    | 6 ++++-- xen/include/asm-arm/gic.h | 2 ++

 2 files changed, 6 insertions(+), 2 deletions(-)
xen/arch/arm/vgic-v2.c +0 -0
index c94f0f3..4fb954b 100644
@@ -507,10 +507,12 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v,
 mmio_info_t *info,
Quoted 6 lines


     case GICD_ICFGR: /* SGIs */
         goto write_ignore_32;
-    case GICD_ICFGR + 1: /* PPIs */
+
+    case GICD_ICFGR1:

This should have a /* PPIs */ comment I think?

I think I could add that on commit if you agree.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw

Re: [PATCH v2 01/11] xen/arm: vgic-v2: Implement correctly ICFGR{0, 1} read-only

Quoted 10 lines · Ian Campbell
(quoted diff) +0 -0
@@ -507,10 +507,12 @@ static int vgic_v2_distr_mmio_write(struct vcpu
 > *v,
 > mmio_info_t *info,
Quoted 6 lines


     case GICD_ICFGR: /* SGIs */
         goto write_ignore_32;
-    case GICD_ICFGR + 1: /* PPIs */
+
+    case GICD_ICFGR1:

Quoted 3 lines

This should have a /* PPIs */ comment I think?

I think I could add that on commit if you agree.

With you being away this week I decided this wasn't worth holding up 11 patches over and committed without. Instead:

----8<---------

From ae3bbd51d27ac413fc948cfd3b2d5604323c7d4c Mon Sep 17 00:00:00 2001
From: Ian Campbell <[email protected]>
Date: Wed, 25 Nov 2015 12:02:18 +0000
Subject: [PATCH] xen/arm: vgic-v2: Add "PPIs" comment to GICD_ICFGR1 handler

To match the surrounding SPIs and SGIs comments.

---
 xen/arch/arm/vgic-v2.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/vgic-v2.c +0 -0
index 2c73133..c3c6b66 100644
@@ -545,7 +545,7 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info,

     case VREG32(GICD_ICFGR): /* SGIs */
         goto write_ignore_32;

-    case VREG32(GICD_ICFGR1):
+    case VREG32(GICD_ICFGR1): /* PPIs */
         /* It is implementation defined if these are writeable. We chose not */ goto write_ignore_32;

Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#4 lore raw

Re: [PATCH v2 01/11] xen/arm: vgic-v2: Implement correctly ICFGR{0, 1} read-only

Hi Ian,

Quoted 11 lines · Ian Campbell
Quoted 10 lines · Ian Campbell
(quoted diff) +0 -0
@@ -507,10 +507,12 @@ static int vgic_v2_distr_mmio_write(struct vcpu
 > *v,
 > mmio_info_t *info,
Quoted 6 lines

case GICD_ICFGR: /* SGIs */
goto write_ignore_32;

(quoted diff) +2 -1
-    case GICD_ICFGR + 1: /* PPIs */
+
+    case GICD_ICFGR1:
Quoted 6 lines
Quoted 3 lines

This should have a /* PPIs */ comment I think?

I think I could add that on commit if you agree.

With you being away this week I decided this wasn't worth holding up 11 patches over and committed without. Instead:

FWIW, I'm fine with that as it was a mistake while I wrote the patch.

Regards,

Signature · 1 line
Julien Grall
#5 lore raw

PATCH v2 2/11 xen/arm: vgic-v3: Don't try to emulate IROUTER which doesn't exist in the spec

In reply to Julien Grall

The range of valid IROUTER<n> are n = 32 - 1019 (see 8.9.13 in IHI 0069A) which correspond to the offset 0x6100-0x7FD8.

Other offset are invalid and therefore should not be emulated.

Also remove the now unused label read_as_zero_64 and write_ignore_64.

Note that GICD_IROUTER is kept to accomadate the GICv3 drivers which has been in part taken from Linux.

---

Changes in v2:
- This patch was supposed to be in v1, but messed up the git format-patch command

---
 xen/arch/arm/vgic-v3.c            | 19 ++-----------------
 xen/include/asm-arm/gic_v3_defs.h |  3 +--
 2 files changed, 3 insertions(+), 19 deletions(-)
xen/arch/arm/vgic-v3.c +2 -17
index 3a7b86f..902f64a 100644
@@ -806,10 +806,7 @@ static int vgic_v3_distr_mmio_read(struct vcpu *v, mmio_info_t *info,
          * Manage in common
          */
         return __vgic_v3_distr_common_mmio_read("vGICD", v, info, gicd_reg, r);
-    case GICD_IROUTER ... GICD_IROUTER31:
-        /* SGI/PPI is RES0 */
-        goto read_as_zero_64;
-    case GICD_IROUTER32 ... GICD_IROUTERN:
+    case GICD_IROUTER32 ... GICD_IROUTER1019:
     {
         uint64_t irouter;
 
@@ -887,11 +884,6 @@ bad_width:
     domain_crash_synchronous();
     return 0;
 
-read_as_zero_64:
-    if ( vgic_reg64_check_access(dabt) ) goto bad_width;
-    *r = 0;
-    return 1;
-
 read_as_zero_32:
     if ( dabt.size != DABT_WORD ) goto bad_width;
     *r = 0;
@@ -974,10 +966,7 @@ static int vgic_v3_distr_mmio_write(struct vcpu *v, mmio_info_t *info,
          * Manage in common */
         return __vgic_v3_distr_common_mmio_write("vGICD", v, info,
                                                  gicd_reg, r);
-    case GICD_IROUTER ... GICD_IROUTER31:
-        /* SGI/PPI is RES0 */
-        goto write_ignore_64;
-    case GICD_IROUTER32 ... GICD_IROUTERN:
+    case GICD_IROUTER32 ... GICD_IROUTER1019:
     {
         uint64_t irouter;
 
@@ -1039,10 +1028,6 @@ write_ignore_32:
     if ( dabt.size != DABT_WORD ) goto bad_width;
     return 1;
 
-write_ignore_64:
-    if ( vgic_reg64_check_access(dabt) ) goto bad_width;
-    return 1;
-
 write_ignore:
     return 1;
 }
xen/include/asm-arm/gic_v3_defs.h +1 -2
index c6d73df..89a3548 100644
@@ -29,9 +29,8 @@
 #define GICD_SETSPI_SR               (0x050)
 #define GICD_CLRSPI_SR               (0x058)
 #define GICD_IROUTER                 (0x6000)
-#define GICD_IROUTER31               (0x60F8)
 #define GICD_IROUTER32               (0x6100)
-#define GICD_IROUTERN                (0x7FF8)
+#define GICD_IROUTER1019             (0x7FD8)
 #define GICD_PIDR0                   (0xFFE0)
 #define GICD_PIDR1                   (0xFFE4)
 #define GICD_PIDR2                   (0xFFE8)
Signature · 1 line
2.1.4
Acked-by on v2 2/11
#6 lore raw

Re: [PATCH v2 02/11] xen/arm: vgic-v3: Don't try to emulate IROUTER which doesn't exist in the spec

On Wed, 2015-11-18 at 17:27 +0000, Julien Grall wrote:

Subject: ... which do not exist in the ...

Quoted 4 lines

The range of valid IROUTER<n> are n = 32 - 1019 (see 8.9.13 in IHI 0069A) which correspond to the offset 0x6100-0x7FD8.

Other offset are invalid and therefore should not be emulated.

"offsets"

Quoted 4 lines

Also remove the now unused label read_as_zero_64 and write_ignore_64.

Note that GICD_IROUTER is kept to accomadate the GICv3 drivers which has

"accommodate"

Quoted 3 lines

been in part taken from Linux.

Accesses to 0x6000-0x60FF are going to be noisy now, I suppose that is OK.

#7 lore raw

Re: [PATCH v2 02/11] xen/arm: vgic-v3: Don't try to emulate IROUTER which doesn't exist in the spec

Hi Ian,

Quoted 16 lines · Ian Campbell

On Wed, 2015-11-18 at 17:27 +0000, Julien Grall wrote:

Subject: ... which do not exist in the ...

Quoted 4 lines

The range of valid IROUTER<n> are n = 32 - 1019 (see 8.9.13 in IHI 0069A) which correspond to the offset 0x6100-0x7FD8.

Other offset are invalid and therefore should not be emulated.

"offsets"

Quoted 4 lines

Also remove the now unused label read_as_zero_64 and write_ignore_64.

Note that GICD_IROUTER is kept to accomadate the GICv3 drivers which has

Quoted 7 lines

"accommodate"

Quoted 3 lines

been in part taken from Linux.

Accesses to 0x6000-0x60FF are going to be noisy now, I suppose that is OK.

Well, those registers are reserved so the guests are not supposed to access them.

Quoted 1 line

Thank you!

Regards,

Signature · 1 line
Julien Grall
#8 lore raw

PATCH v2 3/11 xen/arm: vgic-v3: Use the correct offset GICR_IGRPMODR0

In reply to Julien Grall

The offset is 0x0D00 and not 0x0F80.

Also re-order the definition to keep all the definitions ordered.

---

Changes in v2:
- Add Ian's acked-by

---
 xen/include/asm-arm/gic_v3_defs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/include/asm-arm/gic_v3_defs.h +1 -1
index 89a3548..34e8b0a 100644
@@ -96,7 +96,6 @@
 /* GICR for SGI's & PPI's */
 
 #define GICR_IGROUPR0                (0x0080)
-#define GICR_IGRPMODR0               (0x0F80)
 #define GICR_ISENABLER0              (0x0100)
 #define GICR_ICENABLER0              (0x0180)
 #define GICR_ISPENDR0                (0x0200)
@@ -107,6 +106,7 @@
 #define GICR_IPRIORITYR7             (0x041C)
 #define GICR_ICFGR0                  (0x0C00)
 #define GICR_ICFGR1                  (0x0C04)
+#define GICR_IGRPMODR0               (0x0D00)
 #define GICR_NSACR                   (0x0E00)
 
 #define GICR_TYPER_PLPIS             (1U << 0)
Signature · 1 line
2.1.4
#9 lore raw

PATCH v2 4/11 xen/arm: vgic-v3: Only emulate identification registers required by the spec

In reply to Julien Grall

Most of the identification registers space contains implementation defined registers (see 8.1.13 in ARM IHI 0069A) and only GIC{D,R}_PIDR2 is required to be implemented.

Currently the emulation of those registers mimic the ARM implementation, but it's untrue to say that we properly emulate a such implementation.

Keep only GIC{D,R}_PIDR2 implemented with the "implementation defined bits" to zero and the ArchRev field (bits[7:4]) to 0x3 as we emulate a GICv3.

Note that the emulation of the range wasn't valid anyway because the registers are split in 2 sets (PIDR4-PIDR7 and PIDR0-PIDR2).

---

Changes in v2:
- Add Ian's acked-by
- Fix typoes

---
 xen/arch/arm/vgic-v3.c            | 127 +++++++++++++++++++++++---------------
 xen/include/asm-arm/gic_v3_defs.h |  12 ----
 2 files changed, 76 insertions(+), 63 deletions(-)
xen/arch/arm/vgic-v3.c +76 -51
index 902f64a..0f6cb95 100644
@@ -31,17 +31,15 @@
 #include <asm/gic_v3_defs.h>
 #include <asm/vgic.h>
 
-/* GICD_PIDRn register values for ARM implementations */
-#define GICV3_GICD_PIDR0  0x92
-#define GICV3_GICD_PIDR1  0xb4
-#define GICV3_GICD_PIDR2  0x3b
-#define GICV3_GICD_PIDR4  0x04
-
-/* GICR_PIDRn register values for ARM implementations */
-#define GICV3_GICR_PIDR0  0x93
-#define GICV3_GICR_PIDR1  GICV3_GICD_PIDR1
+/*
+ * PIDR2: Only bits[7:4] are not implementation defined. We are
+ * emulating a GICv3 ([7:4] = 0x3).
+ *
+ * We don't emulate a specific registers scheme so implement the others
+ * bits as RES0 as recommended by the spec (see 8.1.13 in ARM IHI 0069A).
+ */
+#define GICV3_GICD_PIDR2  0x30
 #define GICV3_GICR_PIDR2  GICV3_GICD_PIDR2
-#define GICV3_GICR_PIDR4  GICV3_GICD_PIDR4
 
 /*
  * GICD_CTLR default value:
@@ -237,28 +235,20 @@ static int __vgic_v3_rdistr_rd_mmio_read(struct vcpu *v, mmio_info_t *info,
     case GICR_MOVALLR:
         /* WO Read as zero */
         goto read_as_zero_64;
-    case GICR_PIDR0:
-        if ( dabt.size != DABT_WORD ) goto bad_width;
-        *r = vgic_reg32_extract(GICV3_GICR_PIDR0, info);
-         return 1;
-    case GICR_PIDR1:
-        if ( dabt.size != DABT_WORD ) goto bad_width;
-        *r = vgic_reg32_extract(GICV3_GICR_PIDR1, info);
-         return 1;
+
+    case 0xFFD0 ... 0xFFE4:
+        /* Implementation defined identification registers */
+       goto read_impl_defined;
+
     case GICR_PIDR2:
         if ( dabt.size != DABT_WORD ) goto bad_width;
         *r = vgic_reg32_extract(GICV3_GICR_PIDR2, info);
          return 1;
-    case GICR_PIDR3:
-        /* Manufacture/customer defined */
-        goto read_as_zero_32;
-    case GICR_PIDR4:
-        if ( dabt.size != DABT_WORD ) goto bad_width;
-        *r = vgic_reg32_extract(GICV3_GICR_PIDR4, info);
-         return 1;
-    case GICR_PIDR5 ... GICR_PIDR7:
-        /* Reserved0 */
-        goto read_as_zero_32;
+
+    case 0xFFEC ... 0xFFFC:
+         /* Implementation defined identification registers */
+         goto read_impl_defined;
+
     default:
         printk(XENLOG_G_ERR
                "%pv: vGICR: unhandled read r%d offset %#08x\n",
@@ -280,6 +270,13 @@ read_as_zero_32:
     if ( dabt.size != DABT_WORD ) goto bad_width;
     *r = 0;
     return 1;
+
+read_impl_defined:
+    printk(XENLOG_G_DEBUG
+           "%pv: vGICR: RAZ on implemention defined register offset %#08x\n",
+           v, gicr_reg);
+    *r = 0;
+    return 1;
 }
 
 static int __vgic_v3_rdistr_rd_mmio_write(struct vcpu *v, mmio_info_t *info,
@@ -332,9 +329,19 @@ static int __vgic_v3_rdistr_rd_mmio_write(struct vcpu *v, mmio_info_t *info,
     case GICR_MOVALLR:
         /* LPI is not implemented */
         goto write_ignore_64;
-    case GICR_PIDR7... GICR_PIDR0:
+
+    case 0xFFD0 ... 0xFFE4:
+        /* Implementation defined identification registers */
+       goto write_impl_defined;
+
+    case GICR_PIDR2:
         /* RO */
         goto write_ignore_32;
+
+    case 0xFFEC ... 0xFFFC:
+         /* Implementation defined identification registers */
+         goto write_impl_defined;
+
     default:
         printk(XENLOG_G_ERR "%pv: vGICR: unhandled write r%d offset %#08x\n",
                v, dabt.reg, gicr_reg);
@@ -354,6 +361,12 @@ write_ignore_64:
 write_ignore_32:
     if ( dabt.size != DABT_WORD ) goto bad_width;
     return 1;
+
+write_impl_defined:
+    printk(XENLOG_G_DEBUG
+           "%pv: vGICR: WI on implementation defined register offset %#08x\n",
+           v, gicr_reg);
+    return 1;
 }
 
 static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v,
@@ -835,32 +848,21 @@ static int vgic_v3_distr_mmio_read(struct vcpu *v, mmio_info_t *info,
     case GICD_SPENDSGIR ... GICD_SPENDSGIRN:
         /* Replaced with GICR_ISPENDR0. So ignore write */
         goto read_as_zero_32;
-    case GICD_PIDR0:
-        /* GICv3 identification value */
-        if ( dabt.size != DABT_WORD ) goto bad_width;
-        *r = vgic_reg32_extract(GICV3_GICD_PIDR0, info);
-        return 1;
-    case GICD_PIDR1:
-        /* GICv3 identification value */
-        if ( dabt.size != DABT_WORD ) goto bad_width;
-        *r = vgic_reg32_extract(GICV3_GICD_PIDR1, info);
-        return 1;
+
+    case 0xFFD0 ... 0xFFE4:
+        /* Implementation defined identification registers */
+       goto read_impl_defined;
+
     case GICD_PIDR2:
         /* GICv3 identification value */
         if ( dabt.size != DABT_WORD ) goto bad_width;
         *r = vgic_reg32_extract(GICV3_GICD_PIDR2, info);
         return 1;
-    case GICD_PIDR3:
-        /* GICv3 identification value. Manufacturer/Customer defined */
-        goto read_as_zero_32;
-    case GICD_PIDR4:
-        /* GICv3 identification value */
-        if ( dabt.size != DABT_WORD ) goto bad_width;
-        *r = vgic_reg32_extract(GICV3_GICD_PIDR4, info);
-        return 1;
-    case GICD_PIDR5 ... GICD_PIDR7:
-        /* Reserved0 */
-        goto read_as_zero_32;
+
+    case 0xFFEC ... 0xFFFC:
+         /* Implementation defined identification registers */
+         goto read_impl_defined;
+
     case 0x00c:
     case 0x044:
     case 0x04c:
@@ -892,6 +894,13 @@ read_as_zero_32:
 read_as_zero:
     *r = 0;
     return 1;
+
+read_impl_defined:
+    printk(XENLOG_G_DEBUG
+           "%pv: vGICD: RAZ on implemention defined register offset %#08x\n",
+           v, gicd_reg);
+    *r = 0;
+    return 1;
 }
 
 static int vgic_v3_distr_mmio_write(struct vcpu *v, mmio_info_t *info,
@@ -996,9 +1005,19 @@ static int vgic_v3_distr_mmio_write(struct vcpu *v, mmio_info_t *info,
         /* Replaced with GICR_ISPENDR0. So ignore write */
         if ( dabt.size != DABT_WORD ) goto bad_width;
         return 0;
-    case GICD_PIDR7... GICD_PIDR0:
+
+    case 0xFFD0 ... 0xFFE4:
+        /* Implementation defined identification registers */
+       goto write_impl_defined;
+
+    case GICD_PIDR2:
         /* RO -- write ignore */
         goto write_ignore_32;
+
+    case 0xFFEC ... 0xFFFC:
+         /* Implementation defined identification registers */
+         goto write_impl_defined;
+
     case 0x00c:
     case 0x044:
     case 0x04c:
@@ -1030,6 +1049,12 @@ write_ignore_32:
 
 write_ignore:
     return 1;
+
+write_impl_defined:
+    printk(XENLOG_G_DEBUG
+           "%pv: vGICD: WI on implementation defined register offset %#08x\n",
+           v, gicd_reg);
+    return 1;
 }
 
 static int vgic_v3_to_sgi(struct vcpu *v, register_t sgir)
xen/include/asm-arm/gic_v3_defs.h +0 -12
index 34e8b0a..5a6938c 100644
@@ -31,13 +31,7 @@
 #define GICD_IROUTER                 (0x6000)
 #define GICD_IROUTER32               (0x6100)
 #define GICD_IROUTER1019             (0x7FD8)
-#define GICD_PIDR0                   (0xFFE0)
-#define GICD_PIDR1                   (0xFFE4)
 #define GICD_PIDR2                   (0xFFE8)
-#define GICD_PIDR3                   (0xFFEC)
-#define GICD_PIDR4                   (0xFFD0)
-#define GICD_PIDR5                   (0xFFD4)
-#define GICD_PIDR7                   (0xFFDC)
 
 /* Common between GICD_PIDR2 and GICR_PIDR2 */
 #define GIC_PIDR2_ARCH_MASK         (0xf0)
@@ -85,13 +79,7 @@
 #define GICR_SYNCR                   (0x00C0)
 #define GICR_MOVLPIR                 (0x100)
 #define GICR_MOVALLR                 (0x0110)
-#define GICR_PIDR0                   GICD_PIDR0
-#define GICR_PIDR1                   GICD_PIDR1
 #define GICR_PIDR2                   GICD_PIDR2
-#define GICR_PIDR3                   GICD_PIDR3
-#define GICR_PIDR4                   GICD_PIDR4
-#define GICR_PIDR5                   GICD_PIDR5
-#define GICR_PIDR7                   GICD_PIDR7
 
 /* GICR for SGI's & PPI's */
 
Signature · 1 line
2.1.4
#10 lore raw

PATCH v2 5/11 xen/arm: vgic: Properly emulate the full register

In reply to Julien Grall

The offset in the emulation is based on byte. As most of the registers are 64/32 bits, they will span over multiple bytes.

However, the current emulation only cares about the first offset. This will result in not properly emulating any access on the register with any other offset.

Introduce new macros to help implementing access on multiple byte and use them over the vGIC emulation.

Note that I didn't convert the reserved/implementation defined registers. It will be done in a follow-up.

---

Changes in v2:
- Add Ian's acked-by
- Fix typoes

---
 xen/arch/arm/vgic-v2.c          |  81 ++++++------
 xen/arch/arm/vgic-v3.c          | 287 ++++++++++++++++++++++++----------------
 xen/include/asm-arm/vgic-emul.h |  24 ++++
 3 files changed, 240 insertions(+), 152 deletions(-)
 create mode 100644 xen/include/asm-arm/vgic-emul.h
xen/arch/arm/vgic-v2.c +42 -39
index 4fb954b..d1860a9 100644
@@ -31,6 +31,7 @@
 #include <asm/mmio.h>
 #include <asm/platform.h>
 #include <asm/vgic.h>
+#include <asm/vgic-emul.h>
 
 static struct {
     bool_t enabled;
@@ -177,13 +178,14 @@ static int vgic_v2_distr_mmio_read(struct vcpu *v, mmio_info_t *info,
 
     switch ( gicd_reg )
     {
-    case GICD_CTLR:
+    case VREG32(GICD_CTLR):
         if ( dabt.size != DABT_WORD ) goto bad_width;
         vgic_lock(v);
         *r = vgic_reg32_extract(v->domain->arch.vgic.ctlr, info);
         vgic_unlock(v);
         return 1;
-    case GICD_TYPER:
+
+    case VREG32(GICD_TYPER):
     {
         uint32_t typer;
 
@@ -198,7 +200,8 @@ static int vgic_v2_distr_mmio_read(struct vcpu *v, mmio_info_t *info,
 
         return 1;
     }
-    case GICD_IIDR:
+
+    case VREG32(GICD_IIDR):
         if ( dabt.size != DABT_WORD ) goto bad_width;
         /*
          * XXX Do we need a JEP106 manufacturer ID?
@@ -211,11 +214,11 @@ static int vgic_v2_distr_mmio_read(struct vcpu *v, mmio_info_t *info,
     case 0x020 ... 0x03c:
         goto read_as_zero;
 
-    case GICD_IGROUPR ... GICD_IGROUPRN:
+    case VRANGE32(GICD_IGROUPR, GICD_IGROUPRN):
         /* We do not implement security extensions for guests, read zero */
         goto read_as_zero_32;
 
-    case GICD_ISENABLER ... GICD_ISENABLERN:
+    case VRANGE32(GICD_ISENABLER, GICD_ISENABLERN):
         if ( dabt.size != DABT_WORD ) goto bad_width;
         rank = vgic_rank_offset(v, 1, gicd_reg - GICD_ISENABLER, DABT_WORD);
         if ( rank == NULL) goto read_as_zero;
@@ -224,7 +227,7 @@ static int vgic_v2_distr_mmio_read(struct vcpu *v, mmio_info_t *info,
         vgic_unlock_rank(v, rank, flags);
         return 1;
 
-    case GICD_ICENABLER ... GICD_ICENABLERN:
+    case VRANGE32(GICD_ICENABLER, GICD_ICENABLERN):
         if ( dabt.size != DABT_WORD ) goto bad_width;
         rank = vgic_rank_offset(v, 1, gicd_reg - GICD_ICENABLER, DABT_WORD);
         if ( rank == NULL) goto read_as_zero;
@@ -234,16 +237,16 @@ static int vgic_v2_distr_mmio_read(struct vcpu *v, mmio_info_t *info,
         return 1;
 
     /* Read the pending status of an IRQ via GICD is not supported */
-    case GICD_ISPENDR ... GICD_ISPENDRN:
-    case GICD_ICPENDR ... GICD_ICPENDRN:
+    case VRANGE32(GICD_ISPENDR, GICD_ISPENDRN):
+    case VRANGE32(GICD_ICPENDR, GICD_ICPENDRN):
         goto read_as_zero;
 
     /* Read the active status of an IRQ via GICD is not supported */
-    case GICD_ISACTIVER ... GICD_ISACTIVERN:
-    case GICD_ICACTIVER ... GICD_ICACTIVERN:
+    case VRANGE32(GICD_ISACTIVER, GICD_ISACTIVERN):
+    case VRANGE32(GICD_ICACTIVER, GICD_ICACTIVERN):
         goto read_as_zero;
 
-    case GICD_ITARGETSR ... GICD_ITARGETSRN:
+    case VRANGE32(GICD_ITARGETSR, GICD_ITARGETSRN):
     {
         uint32_t itargetsr;
 
@@ -258,7 +261,7 @@ static int vgic_v2_distr_mmio_read(struct vcpu *v, mmio_info_t *info,
         return 1;
     }
 
-    case GICD_IPRIORITYR ... GICD_IPRIORITYRN:
+    case VRANGE32(GICD_IPRIORITYR, GICD_IPRIORITYRN):
     {
         uint32_t ipriorityr;
 
@@ -276,7 +279,7 @@ static int vgic_v2_distr_mmio_read(struct vcpu *v, mmio_info_t *info,
         return 1;
     }
 
-    case GICD_ICFGR ... GICD_ICFGRN:
+    case VRANGE32(GICD_ICFGR, GICD_ICFGRN):
     {
         uint32_t icfgr;
 
@@ -292,26 +295,26 @@ static int vgic_v2_distr_mmio_read(struct vcpu *v, mmio_info_t *info,
         return 1;
     }
 
-    case GICD_NSACR ... GICD_NSACRN:
+    case VRANGE32(GICD_NSACR, GICD_NSACRN):
         /* We do not implement security extensions for guests, read zero */
         goto read_as_zero_32;
 
-    case GICD_SGIR:
+    case VREG32(GICD_SGIR):
         if ( dabt.size != DABT_WORD ) goto bad_width;
         /* Write only -- read unknown */
         *r = 0xdeadbeef;
         return 1;
 
     /* Setting/Clearing the SGI pending bit via GICD is not supported */
-    case GICD_CPENDSGIR ... GICD_CPENDSGIRN:
-    case GICD_SPENDSGIR ... GICD_SPENDSGIRN:
+    case VRANGE32(GICD_CPENDSGIR, GICD_CPENDSGIRN):
+    case VRANGE32(GICD_SPENDSGIR, GICD_SPENDSGIRN):
         goto read_as_zero;
 
     /* Implementation defined -- read as zero */
     case 0xfd0 ... 0xfe4:
         goto read_as_zero;
 
-    case GICD_ICPIDR2:
+    case VREG32(GICD_ICPIDR2):
         if ( dabt.size != DABT_WORD ) goto bad_width;
         printk(XENLOG_G_ERR "%pv: vGICD: unhandled read from ICPIDR2\n", v);
         return 0;
@@ -396,7 +399,7 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info,
 
     switch ( gicd_reg )
     {
-    case GICD_CTLR:
+    case VREG32(GICD_CTLR):
         if ( dabt.size != DABT_WORD ) goto bad_width;
         /* Ignore all but the enable bit */
         vgic_lock(v);
@@ -407,19 +410,19 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info,
         return 1;
 
     /* R/O -- write ignored */
-    case GICD_TYPER:
-    case GICD_IIDR:
+    case VREG32(GICD_TYPER):
+    case VREG32(GICD_IIDR):
         goto write_ignore_32;
 
     /* Implementation defined -- write ignored */
     case 0x020 ... 0x03c:
         goto write_ignore;
 
-    case GICD_IGROUPR ... GICD_IGROUPRN:
+    case VRANGE32(GICD_IGROUPR, GICD_IGROUPRN):
         /* We do not implement security extensions for guests, write ignore */
         goto write_ignore_32;
 
-    case GICD_ISENABLER ... GICD_ISENABLERN:
+    case VRANGE32(GICD_ISENABLER, GICD_ISENABLERN):
         if ( dabt.size != DABT_WORD ) goto bad_width;
         rank = vgic_rank_offset(v, 1, gicd_reg - GICD_ISENABLER, DABT_WORD);
         if ( rank == NULL) goto write_ignore;
@@ -430,7 +433,7 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info,
         vgic_unlock_rank(v, rank, flags);
         return 1;
 
-    case GICD_ICENABLER ... GICD_ICENABLERN:
+    case VRANGE32(GICD_ICENABLER, GICD_ICENABLERN):
         if ( dabt.size != DABT_WORD ) goto bad_width;
         rank = vgic_rank_offset(v, 1, gicd_reg - GICD_ICENABLER, DABT_WORD);
         if ( rank == NULL) goto write_ignore;
@@ -441,39 +444,39 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info,
         vgic_unlock_rank(v, rank, flags);
         return 1;
 
-    case GICD_ISPENDR ... GICD_ISPENDRN:
+    case VRANGE32(GICD_ISPENDR, GICD_ISPENDRN):
         if ( dabt.size != DABT_WORD ) goto bad_width;
         printk(XENLOG_G_ERR
                "%pv: vGICD: unhandled word write %#"PRIregister" to ISPENDR%d\n",
                v, r, gicd_reg - GICD_ISPENDR);
         return 0;
 
-    case GICD_ICPENDR ... GICD_ICPENDRN:
+    case VRANGE32(GICD_ICPENDR, GICD_ICPENDRN):
         if ( dabt.size != DABT_WORD ) goto bad_width;
         printk(XENLOG_G_ERR
                "%pv: vGICD: unhandled word write %#"PRIregister" to ICPENDR%d\n",
                v, r, gicd_reg - GICD_ICPENDR);
         return 0;
 
-    case GICD_ISACTIVER ... GICD_ISACTIVERN:
+    case VRANGE32(GICD_ISACTIVER, GICD_ISACTIVERN):
         if ( dabt.size != DABT_WORD ) goto bad_width;
         printk(XENLOG_G_ERR
                "%pv: vGICD: unhandled word write %#"PRIregister" to ISACTIVER%d\n",
                v, r, gicd_reg - GICD_ISACTIVER);
         return 0;
 
-    case GICD_ICACTIVER ... GICD_ICACTIVERN:
+    case VRANGE32(GICD_ICACTIVER, GICD_ICACTIVERN):
         if ( dabt.size != DABT_WORD ) goto bad_width;
         printk(XENLOG_G_ERR
                "%pv: vGICD: unhandled word write %#"PRIregister" to ICACTIVER%d\n",
                v, r, gicd_reg - GICD_ICACTIVER);
         return 0;
 
-    case GICD_ITARGETSR ... GICD_ITARGETSR7:
+    case VRANGE32(GICD_ITARGETSR, GICD_ITARGETSR7):
         /* SGI/PPI target is read only */
         goto write_ignore_32;
 
-    case GICD_ITARGETSR8 ... GICD_ITARGETSRN:
+    case VRANGE32(GICD_ITARGETSR8, GICD_ITARGETSRN):
     {
         uint32_t itargetsr;
 
@@ -489,7 +492,7 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info,
         return 1;
     }
 
-    case GICD_IPRIORITYR ... GICD_IPRIORITYRN:
+    case VRANGE32(GICD_IPRIORITYR, GICD_IPRIORITYRN):
     {
         uint32_t *ipriorityr;
 
@@ -505,14 +508,14 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info,
         return 1;
     }
 
-    case GICD_ICFGR: /* SGIs */
+    case VREG32(GICD_ICFGR): /* SGIs */
         goto write_ignore_32;
 
-    case GICD_ICFGR1:
+    case VREG32(GICD_ICFGR1):
         /* It is implementation defined if these are writeable. We chose not */
         goto write_ignore_32;
 
-    case GICD_ICFGR2 ... GICD_ICFGRN: /* SPIs */
+    case VRANGE32(GICD_ICFGR2, GICD_ICFGRN): /* SPIs */
         if ( dabt.size != DABT_WORD ) goto bad_width;
         rank = vgic_rank_offset(v, 2, gicd_reg - GICD_ICFGR, DABT_WORD);
         if ( rank == NULL) goto write_ignore;
@@ -523,22 +526,22 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info,
         vgic_unlock_rank(v, rank, flags);
         return 1;
 
-    case GICD_NSACR ... GICD_NSACRN:
+    case VRANGE32(GICD_NSACR, GICD_NSACRN):
         /* We do not implement security extensions for guests, write ignore */
         goto write_ignore_32;
 
-    case GICD_SGIR:
+    case VREG32(GICD_SGIR):
         if ( dabt.size != DABT_WORD ) goto bad_width;
         return vgic_v2_to_sgi(v, r);
 
-    case GICD_CPENDSGIR ... GICD_CPENDSGIRN:
+    case VRANGE32(GICD_CPENDSGIR, GICD_CPENDSGIRN):
         if ( dabt.size != DABT_BYTE && dabt.size != DABT_WORD ) goto bad_width;
         printk(XENLOG_G_ERR
                "%pv: vGICD: unhandled %s write %#"PRIregister" to ICPENDSGIR%d\n",
                v, dabt.size ? "word" : "byte", r, gicd_reg - GICD_CPENDSGIR);
         return 0;
 
-    case GICD_SPENDSGIR ... GICD_SPENDSGIRN:
+    case VRANGE32(GICD_SPENDSGIR, GICD_SPENDSGIRN):
         if ( dabt.size != DABT_BYTE && dabt.size != DABT_WORD ) goto bad_width;
         printk(XENLOG_G_ERR
                "%pv: vGICD: unhandled %s write %#"PRIregister" to ISPENDSGIR%d\n",
@@ -550,7 +553,7 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info,
         goto write_ignore;
 
     /* R/O -- write ignore */
-    case GICD_ICPIDR2:
+    case VREG32(GICD_ICPIDR2):
         goto write_ignore_32;
 
     /* Implementation defined -- write ignored */
xen/arch/arm/vgic-v3.c +174 -113

618 lines not on this page · raw message

xen/include/asm-arm/vgic-emul.h new file +24 -0
new file mode 100644
index 0000000..184a1f0
@@ -0,0 +1,24 @@
+#ifndef __ASM_ARM_VGIC_EMUL_H__
+#define __ASM_ARM_VGIC_EMUL_H__
+
+/*
+ * Helpers to create easily a case to match emulate a single register or
+ * a range of registers
+ */
+
+#define VREG32(reg) reg ... reg + 3
+#define VREG64(reg) reg ... reg + 7
+
+#define VRANGE32(start, end) start ... end + 3
+#define VRANGE64(start, end) start ... end + 7
+
+#endif /* __ASM_ARM_VGIC_EMUL_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 1 line
2.1.4
#11 lore raw

Re: [PATCH v2 05/11] xen/arm: vgic: Properly emulate the full register

Hi Julien,

xen/arch/arm/vgic-v2.c static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info, · line 473

Quoted 7 lines · Julien Grall
xen/arch/arm/vgic-v2.c +1 -1
-    case GICD_ICACTIVER ... GICD_ICACTIVERN:
+    case VRANGE32(GICD_ICACTIVER, GICD_ICACTIVERN):
         if ( dabt.size != DABT_WORD ) goto bad_width;
         printk(XENLOG_G_ERR
                "%pv: vGICD: unhandled word write %#"PRIregister" to ICACTIVER%d\n",
                v, r, gicd_reg - GICD_ICACTIVER);
         return 0;

Maybe this question is not related to what this patch does. But I have a problem when I rebase my ACPI patches on upstream Linux kernel.

Upstream Linux kernel applies below patch which will write GICD_ICACTIVER. But since Xen doesn't support it, so it will cause Dom0 initializes GIC failed.

0eece2b22849c90b730815c893425a36b9d10fd5 (irqchip/gic: Make sure all interrupts are deactivated at boot)

(XEN) d0v0: vGICD: unhandled word write 0xffffffff to ICACTIVER4 (XEN) traps.c:2447:d0v0 HSR=0x93860046 pc=0xffffffc0008d63f0 gva=0xffffff8000004384 gpa=0x0000002f000384
(XEN) DOM0: Unhandled fault: ttbr address size fault (0x96000000) at 0xffffff8000004384
(XEN) DOM0: Internal error: : 96000000 [#1] PREEMPT SMP (XEN) DOM0: Modules linked in:
(XEN) DOM0: CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.4.0-rc2+ #364 (XEN) DOM0: Hardware name: (null) (DT)
(XEN) DOM0: task: ffffffc000969970 ti: ffffffc00095c000 task.ti:
ffffffc00095c000
(XEN) DOM0: PC is at gic_dist_config+0x78/0xa0
(XEN) DOM0: LR is at __gic_init_bases+0x240/0x2bc

Do we have a plan to fix this?

Thanks,

Signature · 1 line
Shannon
#12 lore raw

unhandled word causes Xen crash with recent Linux kernels, was: Re: [PATCH v2 05/11] xen/arm: vgic: Properly emulate the full register

Hi Shannon,

Quoted 21 lines · Shannon Zhao

Upstream Linux kernel applies below patch which will write GICD_ICACTIVER. But since Xen doesn't support it, so it will cause Dom0 initializes GIC failed.

0eece2b22849c90b730815c893425a36b9d10fd5 (irqchip/gic: Make sure all interrupts are deactivated at boot)

(XEN) d0v0: vGICD: unhandled word write 0xffffffff to ICACTIVER4 (XEN) traps.c:2447:d0v0 HSR=0x93860046 pc=0xffffffc0008d63f0 gva=0xffffff8000004384 gpa=0x0000002f000384
(XEN) DOM0: Unhandled fault: ttbr address size fault (0x96000000) at 0xffffff8000004384
(XEN) DOM0: Internal error: : 96000000 [#1] PREEMPT SMP (XEN) DOM0: Modules linked in:
(XEN) DOM0: CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.4.0-rc2+ #364 (XEN) DOM0: Hardware name: (null) (DT)
(XEN) DOM0: task: ffffffc000969970 ti: ffffffc00095c000 task.ti:
ffffffc00095c000
(XEN) DOM0: PC is at gic_dist_config+0x78/0xa0
(XEN) DOM0: LR is at __gic_init_bases+0x240/0x2bc

Quoted 1 line

Do we have a plan to fix this?

Thanks for the reporting the issue, I can reproduce the problem. Given that this is a very serious regression and that we cannot really "fix" the Linux side because Linux is not doing anything wrong, I think we have to go with a very simple change, something we can easily backport to all past Xen releases.

I suggest we turn the "unhandled word write" into a write_ignore, see below:

---

xen/arm: ignore GICD_ICACTIVER writes

xen/arch/arm/vgic-v2.c +2 -5
index f7d784b..8585c44 100644
@@ -332,11 +332,8 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info,
         return 0;
 
     case GICD_ICACTIVER ... GICD_ICACTIVERN:
-        if ( dabt.size != DABT_WORD ) goto bad_width;
-        printk(XENLOG_G_ERR
-               "%pv: vGICD: unhandled word write %#"PRIregister" to ICACTIVER%d\n",
-               v, r, gicd_reg - GICD_ICACTIVER);
-        return 0;
+        /* we should really be implementing this */
+        goto write_ignore_32;
 
     case GICD_ITARGETSR ... GICD_ITARGETSR + 7:
         /* SGI/PPI target is read only */
xen/arch/arm/vgic-v3.c +2 -5
index b5249ff..6d77373 100644
@@ -421,11 +421,8 @@ static int __vgic_v3_distr_common_mmio_write(const char *name, struct vcpu *v,
         return 0;
 
     case GICD_ICACTIVER ... GICD_ICACTIVERN:
-        if ( dabt.size != DABT_WORD ) goto bad_width;
-        printk(XENLOG_G_ERR
-               "%pv: %s: unhandled word write %#"PRIregister" to ICACTIVER%d\n",
-               v, name, r, reg - GICD_ICACTIVER);
-        return 0;
+        /* we should really be implementing this */
+        goto write_ignore_32;
 
     case GICD_IPRIORITYR ... GICD_IPRIORITYRN:
         if ( dabt.size != DABT_BYTE && dabt.size != DABT_WORD ) goto bad_width;
#13 lore raw

Re: unhandled word causes Xen crash with recent Linux kernels, was: Re: [PATCH v2 05/11] xen/arm: vgic: Properly emulate the full register

Quoted 26 lines · Stefano Stabellini

Hi Shannon,

Quoted 21 lines · Shannon Zhao

Upstream Linux kernel applies below patch which will write GICD_ICACTIVER. But since Xen doesn't support it, so it will cause Dom0 initializes GIC failed.

0eece2b22849c90b730815c893425a36b9d10fd5 (irqchip/gic: Make sure all interrupts are deactivated at boot)

(XEN) d0v0: vGICD: unhandled word write 0xffffffff to ICACTIVER4 (XEN) traps.c:2447:d0v0 HSR=0x93860046 pc=0xffffffc0008d63f0 gva=0xffffff8000004384 gpa=0x0000002f000384
(XEN) DOM0: Unhandled fault: ttbr address size fault (0x96000000) at 0xffffff8000004384
(XEN) DOM0: Internal error: : 96000000 [#1] PREEMPT SMP (XEN) DOM0: Modules linked in:
(XEN) DOM0: CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.4.0-rc2+ #364 (XEN) DOM0: Hardware name: (null) (DT)
(XEN) DOM0: task: ffffffc000969970 ti: ffffffc00095c000 task.ti:
ffffffc00095c000
(XEN) DOM0: PC is at gic_dist_config+0x78/0xa0
(XEN) DOM0: LR is at __gic_init_bases+0x240/0x2bc

Quoted 1 line

Do we have a plan to fix this?

Quoted 8 lines

Thanks for the reporting the issue, I can reproduce the problem.  Given that this is a very serious regression and that we cannot really "fix" the Linux side because Linux is not doing anything wrong, I think we have to go with a very simple change, something we can easily backport to all past Xen releases.

I suggest we turn the "unhandled word write" into a write_ignore, see below:

As discussed IRL this might be tolerable as a patch intended for backporting purposes, but I would want to see it in a series along with one or more not-for-backport patches which actually makes the register work as it should.

Quoted 40 lines

---

xen/arm: ignore GICD_ICACTIVER writes

xen/arch/arm/vgic-v2.c +0 -0
index f7d784b..8585c44 100644
@@ -332,11 +332,8 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v,
 mmio_info_t *info,
          return 0;


     case GICD_ICACTIVER ... GICD_ICACTIVERN:
-        if ( dabt.size != DABT_WORD ) goto bad_width;
-        printk(XENLOG_G_ERR
-               "%pv: vGICD: unhandled word write %#"PRIregister" to ICACTIVER%d\n",
-               v, r, gicd_reg - GICD_ICACTIVER);
-        return 0;
+        /* we should really be implementing this */
+        goto write_ignore_32;

     case GICD_ITARGETSR ... GICD_ITARGETSR + 7:
         /* SGI/PPI target is read only */

xen/arch/arm/vgic-v3.c +0 -0
index b5249ff..6d77373 100644
@@ -421,11 +421,8 @@ static int __vgic_v3_distr_common_mmio_write(const
 char *name, struct vcpu *v,
          return 0;


     case GICD_ICACTIVER ... GICD_ICACTIVERN:
-        if ( dabt.size != DABT_WORD ) goto bad_width; -        printk(XENLOG_G_ERR
-               "%pv: %s: unhandled word write %#"PRIregister" to ICACTIVER%d\n",

Quoted 8 lines

-               v, name, r, reg - GICD_ICACTIVER);
-        return 0;
+        /* we should really be implementing this */
+        goto write_ignore_32;

     case GICD_IPRIORITYR ... GICD_IPRIORITYRN:
         if ( dabt.size != DABT_BYTE && dabt.size != DABT_WORD ) goto bad_width;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#14 lore raw

Re: unhandled word causes Xen crash with recent Linux kernels, was: Re: [PATCH v2 05/11] xen/arm: vgic: Properly emulate the full register

Hi Ian,

Quoted 31 lines · Ian Campbell
Quoted 30 lines · Stefano Stabellini
Quoted 21 lines · Shannon Zhao

Upstream Linux kernel applies below patch which will write GICD_ICACTIVER. But since Xen doesn't support it, so it will cause Dom0 initializes GIC failed.

0eece2b22849c90b730815c893425a36b9d10fd5 (irqchip/gic: Make sure all interrupts are deactivated at boot)

(XEN) d0v0: vGICD: unhandled word write 0xffffffff to ICACTIVER4 (XEN) traps.c:2447:d0v0 HSR=0x93860046 pc=0xffffffc0008d63f0 gva=0xffffff8000004384 gpa=0x0000002f000384
(XEN) DOM0: Unhandled fault: ttbr address size fault (0x96000000) at 0xffffff8000004384
(XEN) DOM0: Internal error: : 96000000 [#1] PREEMPT SMP (XEN) DOM0: Modules linked in:
(XEN) DOM0: CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.4.0-rc2+ #364 (XEN) DOM0: Hardware name: (null) (DT)
(XEN) DOM0: task: ffffffc000969970 ti: ffffffc00095c000 task.ti:
ffffffc00095c000
(XEN) DOM0: PC is at gic_dist_config+0x78/0xa0
(XEN) DOM0: LR is at __gic_init_bases+0x240/0x2bc

Quoted 1 line

Do we have a plan to fix this?

Thanks for the reporting the issue, I can reproduce the problem. Given that this is a very serious regression and that we cannot really "fix" the Linux side because Linux is not doing anything wrong, I think we have to go with a very simple change, something we can easily backport to all past Xen releases.

Quoted 7 lines
Quoted 2 lines

I suggest we turn the "unhandled word write" into a write_ignore, see below:

As discussed IRL this might be tolerable as a patch intended for backporting purposes, but I would want to see it in a series along with one or more not-for-backport patches which actually makes the register work as it should.

I have the feeling that fixing properly GICD_I*ACTIVER will take sometimes as we also need to take into consideration hardware interrupt routed to a guest.

As this is preventing Linux upstream to run on the latest, can we get a simple fix for now?

Regards,

Signature · 1 line
Julien Grall
#15 lore raw

Re: unhandled word causes Xen crash with recent Linux kernels, was: Re: [PATCH v2 05/11] xen/arm: vgic: Properly emulate the full register

Quoted 51 lines · Julien Grall

Hi Ian,

Quoted 41 lines · Ian Campbell
Quoted 37 lines · Stefano Stabellini
Quoted 25 lines · Shannon Zhao

Upstream Linux kernel applies below patch which will write GICD_ICACTIVER. But since Xen doesn't support it, so it will cause Dom0
initializes GIC failed.

0eece2b22849c90b730815c893425a36b9d10fd5 (irqchip/gic: Make sure all
interrupts are deactivated at boot)

(XEN) d0v0: vGICD: unhandled word write 0xffffffff to ICACTIVER4 (XEN) traps.c:2447:d0v0 HSR=0x93860046 pc=0xffffffc0008d63f0 gva=0xffffff8000004384 gpa=0x0000002f000384
(XEN) DOM0: Unhandled fault: ttbr address size fault (0x96000000) at
0xffffff8000004384
(XEN) DOM0: Internal error: : 96000000 [#1] PREEMPT SMP (XEN) DOM0: Modules linked in:
(XEN) DOM0: CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.4.0-rc2+ #364
(XEN) DOM0: Hardware name: (null) (DT)
(XEN) DOM0: task: ffffffc000969970 ti: ffffffc00095c000 task.ti:
ffffffc00095c000
(XEN) DOM0: PC is at gic_dist_config+0x78/0xa0
(XEN) DOM0: LR is at __gic_init_bases+0x240/0x2bc

Quoted 1 line

Do we have a plan to fix this?

Thanks for the reporting the issue, I can reproduce the problem.  Given
that this is a very serious regression and that we cannot really "fix"
the Linux side because Linux is not doing anything wrong, I think we have to go with a very simple change, something we can easily backport
to all past Xen releases.

Quoted 2 lines

I suggest we turn the "unhandled word write" into a write_ignore, see below:

Quoted 6 lines

As discussed IRL this might be tolerable as a patch intended for backporting purposes, but I would want to see it in a series along with one
or more not-for-backport patches which actually makes the register work as
it should.

Quoted 6 lines

I have the feeling that fixing properly GICD_I*ACTIVER will take sometimes as we also need to take into consideration hardware interrupt routed to a guest.

As this is preventing Linux upstream to run on the latest, can we get a simple fix for now?

With a suitable commit message explaining the interim/backportability nature of this patch and the intention to do it properly I'd be willing to accept it.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#16 lore raw

Re: unhandled word causes Xen crash with recent Linux kernels, was: Re: [PATCH v2 05/11] xen/arm: vgic: Properly emulate the full register

Quoted 56 lines · Ian Campbell
Quoted 55 lines · Julien Grall

Hi Ian,

Quoted 41 lines · Ian Campbell
Quoted 37 lines · Stefano Stabellini
Quoted 25 lines · Shannon Zhao

Upstream Linux kernel applies below patch which will write GICD_ICACTIVER. But since Xen doesn't support it, so it will cause Dom0
initializes GIC failed.

0eece2b22849c90b730815c893425a36b9d10fd5 (irqchip/gic: Make sure all
interrupts are deactivated at boot)

(XEN) d0v0: vGICD: unhandled word write 0xffffffff to ICACTIVER4 (XEN) traps.c:2447:d0v0 HSR=0x93860046 pc=0xffffffc0008d63f0 gva=0xffffff8000004384 gpa=0x0000002f000384
(XEN) DOM0: Unhandled fault: ttbr address size fault (0x96000000) at
0xffffff8000004384
(XEN) DOM0: Internal error: : 96000000 [#1] PREEMPT SMP (XEN) DOM0: Modules linked in:
(XEN) DOM0: CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.4.0-rc2+ #364
(XEN) DOM0: Hardware name: (null) (DT)
(XEN) DOM0: task: ffffffc000969970 ti: ffffffc00095c000 task.ti:
ffffffc00095c000
(XEN) DOM0: PC is at gic_dist_config+0x78/0xa0
(XEN) DOM0: LR is at __gic_init_bases+0x240/0x2bc

Quoted 1 line

Do we have a plan to fix this?

Thanks for the reporting the issue, I can reproduce the problem.  Given
that this is a very serious regression and that we cannot really "fix"
the Linux side because Linux is not doing anything wrong, I think we have to go with a very simple change, something we can easily backport
to all past Xen releases.

Quoted 2 lines

I suggest we turn the "unhandled word write" into a write_ignore, see below:

Quoted 6 lines

As discussed IRL this might be tolerable as a patch intended for backporting purposes, but I would want to see it in a series along with one
or more not-for-backport patches which actually makes the register work as
it should.

I have the feeling that fixing properly GICD_I*ACTIVER will take sometimes as we also need to take into consideration hardware interrupt routed to a guest.

Quoted 6 lines
Quoted 2 lines

As this is preventing Linux upstream to run on the latest, can we get a simple fix for now?

With a suitable commit message explaining the interim/backportability nature of this patch and the intention to do it properly I'd be willing to accept it.

OK, I'll resend with a better description.

That said, I am not sure how these registers can be implemented properly. Even the follow-up patch I sent, doesn't implement GICD_ICACTIVER accurately.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#17 lore raw

Re: unhandled word causes Xen crash with recent Linux kernels, was: Re: [PATCH v2 05/11] xen/arm: vgic: Properly emulate the full register

In reply to Stefano Stabellini

Hi Stefano,

Quoted 32 lines · Stefano Stabellini

Hi Shannon,

Quoted 21 lines · Shannon Zhao

Upstream Linux kernel applies below patch which will write GICD_ICACTIVER. But since Xen doesn't support it, so it will cause Dom0 initializes GIC failed.

0eece2b22849c90b730815c893425a36b9d10fd5 (irqchip/gic: Make sure all interrupts are deactivated at boot)

(XEN) d0v0: vGICD: unhandled word write 0xffffffff to ICACTIVER4 (XEN) traps.c:2447:d0v0 HSR=0x93860046 pc=0xffffffc0008d63f0 gva=0xffffff8000004384 gpa=0x0000002f000384
(XEN) DOM0: Unhandled fault: ttbr address size fault (0x96000000) at 0xffffff8000004384
(XEN) DOM0: Internal error: : 96000000 [#1] PREEMPT SMP (XEN) DOM0: Modules linked in:
(XEN) DOM0: CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.4.0-rc2+ #364 (XEN) DOM0: Hardware name: (null) (DT)
(XEN) DOM0: task: ffffffc000969970 ti: ffffffc00095c000 task.ti:
ffffffc00095c000
(XEN) DOM0: PC is at gic_dist_config+0x78/0xa0
(XEN) DOM0: LR is at __gic_init_bases+0x240/0x2bc

Quoted 1 line

Do we have a plan to fix this?

Thanks for the reporting the issue, I can reproduce the problem. Given that this is a very serious regression and that we cannot really "fix" the Linux side because Linux is not doing anything wrong, I think we have to go with a very simple change, something we can easily backport to all past Xen releases.

Quoted 6 lines

I suggest we turn the "unhandled word write" into a write_ignore, see below:

---

xen/arm: ignore GICD_ICACTIVER writes

This need more rational in the commit message to explain why you decided to implement write ignore.

Quoted 8 lines
xen/arch/arm/vgic-v2.c +0 -0
index f7d784b..8585c44 100644

xen/arch/arm/vgic-v2.c static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info, · line 339

Quoted 8 lines
xen/arch/arm/vgic-v2.c +0 -5
@@ -332,11 +332,8 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info,
         return 0;
 
     case GICD_ICACTIVER ... GICD_ICACTIVERN:
-        if ( dabt.size != DABT_WORD ) goto bad_width;
-        printk(XENLOG_G_ERR
-               "%pv: vGICD: unhandled word write %#"PRIregister" to ICACTIVER%d\n",
-               v, r, gicd_reg - GICD_ICACTIVER);implementing write ignore is fine.
-        return 0;

I would prefer if you retain the printk, it helps the guest developer to know that we don't support GICD_I*ACTIVER registers.

Maybe you can turn it to a XENLOG_G_DEBUG.

Quoted 10 lines
xen/arch/arm/vgic-v2.c +2 -0
+        /* we should really be implementing this */
+        goto write_ignore_32;
 
     case GICD_ITARGETSR ... GICD_ITARGETSR + 7:
         /* SGI/PPI target is read only */
xen/arch/arm/vgic-v3.c +0 -0
index b5249ff..6d77373 100644

xen/arch/arm/vgic-v3.c static int __vgic_v3_distr_common_mmio_write(const char *name, struct vcpu *v, · line 427

Quoted 7 lines
xen/arch/arm/vgic-v3.c +0 -4
@@ -421,11 +421,8 @@ static int __vgic_v3_distr_common_mmio_write(const char *name, struct vcpu *v,
         return 0;
 
     case GICD_ICACTIVER ... GICD_ICACTIVERN:
-        if ( dabt.size != DABT_WORD ) goto bad_width;
-        printk(XENLOG_G_ERR
-               "%pv: %s: unhandled word write %#"PRIregister" to ICACTIVER%d\n",
-               v, name, r, reg - GICD_ICACTIVER);

Ditto

xen/arch/arm/vgic-v3.c static int __vgic_v3_distr_common_mmio_write(const char *name, struct vcpu *v, · line 428

Quoted 7 lines
xen/arch/arm/vgic-v3.c +2 -1
-        return 0;
+        /* we should really be implementing this */
+        goto write_ignore_32;
 
     case GICD_IPRIORITYR ... GICD_IPRIORITYRN:
         if ( dabt.size != DABT_BYTE && dabt.size != DABT_WORD ) goto bad_width;

Regards,

Signature · 1 line
Julien Grall
#18 lore raw

PATCH v2 6/11 xen/arm: vgic-v3: Remove GICR_MOVALLR and GICR_MOVLPIR

In reply to Julien Grall

The 2 registers are not described in the software spec (ARM IHI 0069A) and their offsets are marked "implementation defined".

---

Note that I didn't combine the 2 cases because a follow-up patch will add reserved registers between the 2 cases.

Changes in v2:
- Add Ian's acked-by

---
 xen/arch/arm/vgic-v3.c            | 20 ++++++++------------
 xen/include/asm-arm/gic_v3_defs.h |  2 --
 2 files changed, 8 insertions(+), 14 deletions(-)
xen/arch/arm/vgic-v3.c +8 -12
index 892104d..28f075a 100644
@@ -241,13 +241,11 @@ static int __vgic_v3_rdistr_rd_mmio_read(struct vcpu *v, mmio_info_t *info,
         *r = vgic_reg32_extract(GICR_SYNCR_NOT_BUSY, info);
         return 1;
 
-    case VREG64(GICR_MOVLPIR):
-        /* WO Read as zero */
-        goto read_as_zero_64;
+    case VREG64(0x0100):
+        goto read_impl_defined;
 
-    case VREG64(GICR_MOVALLR):
-        /* WO Read as zero */
-        goto read_as_zero_64;
+    case VREG64(0x0110):
+        goto read_impl_defined;
 
     case 0xFFD0 ... 0xFFE4:
         /* Implementation defined identification registers */
@@ -348,13 +346,11 @@ static int __vgic_v3_rdistr_rd_mmio_write(struct vcpu *v, mmio_info_t *info,
         /* RO */
         goto write_ignore_32;
 
-    case VREG64(GICR_MOVLPIR):
-        /* LPI is not implemented */
-        goto write_ignore_64;
+    case VREG64(0x0100):
+        goto write_impl_defined;
 
-    case VREG64(GICR_MOVALLR):
-        /* LPI is not implemented */
-        goto write_ignore_64;
+    case VREG64(0x0110):
+        goto write_impl_defined;
 
     case 0xFFD0 ... 0xFFE4:
         /* Implementation defined identification registers */
xen/include/asm-arm/gic_v3_defs.h +0 -2
index 5a6938c..6d98491 100644
@@ -77,8 +77,6 @@
 #define GICR_INVLPIR                 (0x00A0)
 #define GICR_INVALLR                 (0x00B0)
 #define GICR_SYNCR                   (0x00C0)
-#define GICR_MOVLPIR                 (0x100)
-#define GICR_MOVALLR                 (0x0110)
 #define GICR_PIDR2                   GICD_PIDR2
 
 /* GICR for SGI's & PPI's */
Signature · 1 line
2.1.4
#19 lore raw

PATCH v2 7/11 xen/arm: vgic: Re-order the register emulations to match the memory map

In reply to Julien Grall

It helps to find quickly whether we forgot to emulate a register or not.

At the same time add the missing reserved/implementation defined registers. All other missing registers will be added in a follow-up if necessary.

Note that only the distributor register map explicitely say the size of a register (see 8.8 in ARM IHI 0069A). When the size is not known, the implementation defined/reserved may not be emulated correctly.

---

Note that the reserved range after IROUTER<n> is overlapping in the spec. It has been fixup in the code to avoid a build error.

Changes in v2:
- Add Ian's acked-by

---
 xen/arch/arm/vgic-v2.c | 177 ++++++++++++++++++-----------
 xen/arch/arm/vgic-v3.c | 298 +++++++++++++++++++++++++++++++++++--------------
 2 files changed, 328 insertions(+), 147 deletions(-)
xen/arch/arm/vgic-v2.c +111 -66
index d1860a9..2c73133 100644
@@ -210,9 +210,14 @@ static int vgic_v2_distr_mmio_read(struct vcpu *v, mmio_info_t *info,
         *r = vgic_reg32_extract(0x0000043b, info);
         return 1;
 
-    /* Implementation defined -- read as zero */
-    case 0x020 ... 0x03c:
-        goto read_as_zero;
+    case VRANGE32(0x00C, 0x01C):
+        goto read_reserved;
+
+    case VRANGE32(0x020, 0x03C):
+        goto read_impl_defined;
+
+    case VRANGE32(0x040, 0x07C):
+        goto read_reserved;
 
     case VRANGE32(GICD_IGROUPR, GICD_IGROUPRN):
         /* We do not implement security extensions for guests, read zero */
@@ -246,21 +251,6 @@ static int vgic_v2_distr_mmio_read(struct vcpu *v, mmio_info_t *info,
     case VRANGE32(GICD_ICACTIVER, GICD_ICACTIVERN):
         goto read_as_zero;
 
-    case VRANGE32(GICD_ITARGETSR, GICD_ITARGETSRN):
-    {
-        uint32_t itargetsr;
-
-        if ( dabt.size != DABT_BYTE && dabt.size != DABT_WORD ) goto bad_width;
-        rank = vgic_rank_offset(v, 8, gicd_reg - GICD_ITARGETSR, DABT_WORD);
-        if ( rank == NULL) goto read_as_zero;
-        vgic_lock_rank(v, rank, flags);
-        itargetsr = vgic_fetch_itargetsr(rank, gicd_reg - GICD_ITARGETSR);
-        vgic_unlock_rank(v, rank, flags);
-        *r = vgic_reg32_extract(itargetsr, info);
-
-        return 1;
-    }
-
     case VRANGE32(GICD_IPRIORITYR, GICD_IPRIORITYRN):
     {
         uint32_t ipriorityr;
@@ -279,6 +269,27 @@ static int vgic_v2_distr_mmio_read(struct vcpu *v, mmio_info_t *info,
         return 1;
     }
 
+    case VREG32(0x7FC):
+        goto read_reserved;
+
+    case VRANGE32(GICD_ITARGETSR, GICD_ITARGETSRN):
+    {
+        uint32_t itargetsr;
+
+        if ( dabt.size != DABT_BYTE && dabt.size != DABT_WORD ) goto bad_width;
+        rank = vgic_rank_offset(v, 8, gicd_reg - GICD_ITARGETSR, DABT_WORD);
+        if ( rank == NULL) goto read_as_zero;
+        vgic_lock_rank(v, rank, flags);
+        itargetsr = vgic_fetch_itargetsr(rank, gicd_reg - GICD_ITARGETSR);
+        vgic_unlock_rank(v, rank, flags);
+        *r = vgic_reg32_extract(itargetsr, info);
+
+        return 1;
+    }
+
+    case VREG32(0xBFC):
+        goto read_reserved;
+
     case VRANGE32(GICD_ICFGR, GICD_ICFGRN):
     {
         uint32_t icfgr;
@@ -295,6 +306,9 @@ static int vgic_v2_distr_mmio_read(struct vcpu *v, mmio_info_t *info,
         return 1;
     }
 
+    case VRANGE32(0xD00, 0xDFC):
+        goto read_impl_defined;
+
     case VRANGE32(GICD_NSACR, GICD_NSACRN):
         /* We do not implement security extensions for guests, read zero */
         goto read_as_zero_32;
@@ -305,32 +319,27 @@ static int vgic_v2_distr_mmio_read(struct vcpu *v, mmio_info_t *info,
         *r = 0xdeadbeef;
         return 1;
 
+    case VRANGE32(0xF04, 0xF0C):
+        goto read_reserved;
+
     /* Setting/Clearing the SGI pending bit via GICD is not supported */
     case VRANGE32(GICD_CPENDSGIR, GICD_CPENDSGIRN):
     case VRANGE32(GICD_SPENDSGIR, GICD_SPENDSGIRN):
         goto read_as_zero;
 
-    /* Implementation defined -- read as zero */
-    case 0xfd0 ... 0xfe4:
-        goto read_as_zero;
+    case VRANGE32(0xF30, 0xFCC):
+        goto read_reserved;
+
+    case VRANGE32(0xFD0, 0xFE4):
+        goto read_impl_defined;
 
     case VREG32(GICD_ICPIDR2):
         if ( dabt.size != DABT_WORD ) goto bad_width;
         printk(XENLOG_G_ERR "%pv: vGICD: unhandled read from ICPIDR2\n", v);
         return 0;
 
-    /* Implementation defined -- read as zero */
-    case 0xfec ... 0xffc:
-        goto read_as_zero;
-
-    /* Reserved -- read as zero */
-    case 0x00c ... 0x01c:
-    case 0x040 ... 0x07c:
-    case 0x7fc:
-    case 0xbfc:
-    case 0xf04 ... 0xf0c:
-    case 0xf30 ... 0xfcc:
-        goto read_as_zero;
+    case VRANGE32(0xFEC, 0xFFC):
+        goto read_impl_defined;
 
     default:
         printk(XENLOG_G_ERR "%pv: vGICD: unhandled read r%d offset %#08x\n",
@@ -349,6 +358,20 @@ read_as_zero_32:
 read_as_zero:
     *r = 0;
     return 1;
+
+read_impl_defined:
+    printk(XENLOG_G_DEBUG
+           "%pv: vGICD: RAZ on implemention defined register offset %#08x\n",
+           v, gicd_reg);
+    *r = 0;
+    return 1;
+
+read_reserved:
+    printk(XENLOG_G_DEBUG
+           "%pv: vGICD: RAZ on reserved register offset %#08x\n",
+           v, gicd_reg);
+    *r = 0;
+    return 1;
 }
 
 static int vgic_v2_to_sgi(struct vcpu *v, register_t sgir)
@@ -414,9 +437,14 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info,
     case VREG32(GICD_IIDR):
         goto write_ignore_32;
 
-    /* Implementation defined -- write ignored */
-    case 0x020 ... 0x03c:
-        goto write_ignore;
+    case VRANGE32(0x00C, 0x01C):
+        goto write_reserved;
+
+    case VRANGE32(0x020, 0x03C):
+        goto write_impl_defined;
+
+    case VRANGE32(0x040, 0x07C):
+        goto write_reserved;
 
     case VRANGE32(GICD_IGROUPR, GICD_IGROUPRN):
         /* We do not implement security extensions for guests, write ignore */
@@ -472,6 +500,25 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info,
                v, r, gicd_reg - GICD_ICACTIVER);
         return 0;
 
+    case VRANGE32(GICD_IPRIORITYR, GICD_IPRIORITYRN):
+    {
+        uint32_t *ipriorityr;
+
+        if ( dabt.size != DABT_BYTE && dabt.size != DABT_WORD ) goto bad_width;
+        rank = vgic_rank_offset(v, 8, gicd_reg - GICD_IPRIORITYR, DABT_WORD);
+        if ( rank == NULL) goto write_ignore;
+        vgic_lock_rank(v, rank, flags);
+        ipriorityr = &rank->ipriorityr[REG_RANK_INDEX(8,
+                                                      gicd_reg - GICD_IPRIORITYR,
+                                                      DABT_WORD)];
+        vgic_reg32_update(ipriorityr, r, info);
+        vgic_unlock_rank(v, rank, flags);
+        return 1;
+    }
+
+    case VREG32(0x7FC):
+        goto write_reserved;
+
     case VRANGE32(GICD_ITARGETSR, GICD_ITARGETSR7):
         /* SGI/PPI target is read only */
         goto write_ignore_32;
@@ -492,21 +539,8 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info,
         return 1;
     }
 
-    case VRANGE32(GICD_IPRIORITYR, GICD_IPRIORITYRN):
-    {
-        uint32_t *ipriorityr;
-
-        if ( dabt.size != DABT_BYTE && dabt.size != DABT_WORD ) goto bad_width;
-        rank = vgic_rank_offset(v, 8, gicd_reg - GICD_IPRIORITYR, DABT_WORD);
-        if ( rank == NULL) goto write_ignore;
-        vgic_lock_rank(v, rank, flags);
-        ipriorityr = &rank->ipriorityr[REG_RANK_INDEX(8,
-                                                      gicd_reg - GICD_IPRIORITYR,
-                                                      DABT_WORD)];
-        vgic_reg32_update(ipriorityr, r, info);
-        vgic_unlock_rank(v, rank, flags);
-        return 1;
-    }
+    case VREG32(0xBFC):
+        goto write_reserved;
 
     case VREG32(GICD_ICFGR): /* SGIs */
         goto write_ignore_32;
@@ -526,6 +560,9 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info,
         vgic_unlock_rank(v, rank, flags);
         return 1;
 
+    case VRANGE32(0xD00, 0xDFC):
+        goto write_impl_defined;
+
     case VRANGE32(GICD_NSACR, GICD_NSACRN):
         /* We do not implement security extensions for guests, write ignore */
         goto write_ignore_32;
@@ -534,6 +571,9 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info,
         if ( dabt.size != DABT_WORD ) goto bad_width;
         return vgic_v2_to_sgi(v, r);
 
+    case VRANGE32(0xF04, 0xF0C):
+        goto write_reserved;
+
     case VRANGE32(GICD_CPENDSGIR, GICD_CPENDSGIRN):
         if ( dabt.size != DABT_BYTE && dabt.size != DABT_WORD ) goto bad_width;
         printk(XENLOG_G_ERR
@@ -548,26 +588,19 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info,
                v, dabt.size ? "word" : "byte", r, gicd_reg - GICD_SPENDSGIR);
         return 0;
 
-    /* Implementation defined -- write ignored */
-    case 0xfd0 ... 0xfe4:
-        goto write_ignore;
+    case VRANGE32(0xF30, 0xFCC):
+        goto write_reserved;
+
+    case VRANGE32(0xFD0, 0xFE4):
+        /* Implementation defined identification registers */
+        goto write_impl_defined;
 
     /* R/O -- write ignore */
     case VREG32(GICD_ICPIDR2):
         goto write_ignore_32;
 
-    /* Implementation defined -- write ignored */
-    case 0xfec ... 0xffc:
-        goto write_ignore;
-
-    /* Reserved -- write ignored */
-    case 0x00c ... 0x01c:
-    case 0x040 ... 0x07c:
-    case 0x7fc:
-    case 0xbfc:
-    case 0xf04 ... 0xf0c:
-    case 0xf30 ... 0xfcc:
-        goto write_ignore;
+    case VRANGE32(0xFEC, 0xFFC):
+        /* Implementation defined identification registers */
 
     default:
         printk(XENLOG_G_ERR
@@ -587,6 +620,18 @@ write_ignore_32:
     if ( dabt.size != DABT_WORD ) goto bad_width;
 write_ignore:
     return 1;
+
+write_impl_defined:
+    printk(XENLOG_G_DEBUG
+           "%pv: vGICD: WI on implementation defined register offset %#08x\n",
+           v, gicd_reg);
+    return 1;
+
+write_reserved:
+    printk(XENLOG_G_DEBUG
+           "%pv: vGICD: WI on implementation defined register offset %#08x\n",
+           v, gicd_reg);
+    return 1;
 }
 
 static const struct mmio_handler_ops vgic_v2_distr_mmio_handler = {
xen/arch/arm/vgic-v3.c +217 -81

514 lines not on this page · raw message

Signature · 1 line
2.1.4
#20 lore raw

PATCH v2 8/11 xen/arm: vgic-v3: Emulate read to GICD_ICACTIVER<n>

In reply to Julien Grall

The GICD_ICACTIVER<n> registers are missing in the read emulation of the distributor.

Call the common emulation for the whole range.

---

Changes in v2:
- Add Ian's acked-by

---
 xen/arch/arm/vgic-v3.c | 1 +
 1 file changed, 1 insertion(+)
xen/arch/arm/vgic-v3.c +1 -0
index f9d8ecb..98104ba 100644
@@ -966,6 +966,7 @@ static int vgic_v3_distr_mmio_read(struct vcpu *v, mmio_info_t *info,
     case VRANGE32(GICD_ISPENDR, GICD_ISPENDRN):
     case VRANGE32(GICD_ICPENDR, GICD_ICPENDRN):
     case VRANGE32(GICD_ISACTIVER, GICD_ISACTIVERN):
+    case VRANGE32(GICD_ICACTIVER, GICD_ICACTIVERN):
     case VRANGE32(GICD_IPRIORITYR, GICD_IPRIORITYRN):
     case VRANGE32(GICD_ICFGR, GICD_ICFGRN):
         /*
Signature · 1 line
2.1.4
#21 lore raw

PATCH v2 9/11 xen/arm: vgic-v3: Remove spurious return in GICR_INVALLR

In reply to Julien Grall

---

Changes in v2:
- Add Ian's acked-by

---
 xen/arch/arm/vgic-v3.c | 1 -
 1 file changed, 1 deletion(-)
xen/arch/arm/vgic-v3.c +0 -1
index 98104ba..c68afdb 100644
@@ -248,7 +248,6 @@ static int __vgic_v3_rdistr_rd_mmio_read(struct vcpu *v, mmio_info_t *info,
     case VREG64(GICR_INVALLR):
         /* WO. Read as zero */
         goto read_as_zero_64;
-        return 0;
 
     case 0x00B8:
         goto read_reserved;
Signature · 1 line
2.1.4
#22 lore raw

PATCH v2 10/11 xen/arm: vgic-v3: Don't implement write-only register read as zero

In reply to Julien Grall

A read to a write only register is unknown. Use a memorable value to differentiate from an actual RAZ register.

---

Changes in v2:
- Add Ian's acked-by

---
 xen/arch/arm/vgic-v3.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
xen/arch/arm/vgic-v3.c +12 -8
index c68afdb..44e926a 100644
@@ -217,12 +217,12 @@ static int __vgic_v3_rdistr_rd_mmio_read(struct vcpu *v, mmio_info_t *info,
         goto read_impl_defined;
 
     case VREG64(GICR_SETLPIR):
-        /* WO. Read as zero */
-        goto read_as_zero_64;
+        /* WO. Read unknown */
+        goto read_unknown;
 
     case VREG64(GICR_CLRLPIR):
-        /* WO. Read as zero */
-        goto read_as_zero_64;
+        /* WO. Read unknown */
+        goto read_unknown;
 
     case 0x0050:
         goto read_reserved;
@@ -239,15 +239,15 @@ static int __vgic_v3_rdistr_rd_mmio_read(struct vcpu *v, mmio_info_t *info,
         goto read_reserved;
 
     case VREG64(GICR_INVLPIR):
-        /* WO. Read as zero */
-        goto read_as_zero_64;
+        /* WO. Read unknown */
+        goto read_unknown;
 
     case 0x00A8:
         goto read_reserved;
 
     case VREG64(GICR_INVALLR):
-        /* WO. Read as zero */
-        goto read_as_zero_64;
+        /* WO. Read unknown */
+        goto read_unknown;
 
     case 0x00B8:
         goto read_reserved;
@@ -324,6 +324,10 @@ read_reserved:
            v, gicr_reg);
     *r = 0;
     return 1;
+
+read_unknown:
+    *r = vgic_reg64_extract(0xdeadbeafdeadbeaf, info);
+    return 1;
 }
 
 static int __vgic_v3_rdistr_rd_mmio_write(struct vcpu *v, mmio_info_t *info,
Signature · 1 line
2.1.4
#23 lore raw

PATCH v2 11/11 xen/arm: vgic-v3: Make clear that GICD_*SPI_* registers are reserved

In reply to Julien Grall

Our vGIC emulation have GICD_TYPER.MBIS set to 0 which means that GICD_*SPI_* registers are reserved. Implement them using the *_reserved labels.

Also, implement theses registers for the read part.

---

Changes in v2:
- Add Ian's acked-by
- Fix typoes

---
 xen/arch/arm/vgic-v3.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)
xen/arch/arm/vgic-v3.c +20 -4
index 44e926a..985e866 100644
@@ -951,15 +951,31 @@ static int vgic_v3_distr_mmio_read(struct vcpu *v, mmio_info_t *info,
     case VRANGE32(0x0020, 0x003C):
         goto read_impl_defined;
 
+    case VREG32(GICD_SETSPI_NSR):
+        /* Message based SPI is not implemented */
+        goto read_reserved;
+
     case VREG32(0x0044):
         goto read_reserved;
 
+    case VREG32(GICD_CLRSPI_NSR):
+        /* Message based SPI is not implemented */
+        goto read_reserved;
+
     case VREG32(0x004C):
         goto read_reserved;
 
+    case VREG32(GICD_SETSPI_SR):
+        /* Message based SPI is not implemented */
+        goto read_reserved;
+
     case VREG32(0x0054):
         goto read_reserved;
 
+    case VREG32(GICD_CLRSPI_SR):
+        /* Message based SPI is not implemented */
+        goto read_reserved;
+
     case VRANGE32(0x005C, 0x007C):
         goto read_reserved;
 
@@ -1125,28 +1141,28 @@ static int vgic_v3_distr_mmio_write(struct vcpu *v, mmio_info_t *info,
 
     case VREG32(GICD_SETSPI_NSR):
         /* Message based SPI is not implemented */
-        goto write_ignore_32;
+        goto write_reserved;
 
     case VREG32(0x0044):
         goto write_reserved;
 
     case VREG32(GICD_CLRSPI_NSR):
         /* Message based SPI is not implemented */
-        goto write_ignore_32;
+        goto write_reserved;
 
     case VREG32(0x004C):
         goto write_reserved;
 
     case VREG32(GICD_SETSPI_SR):
         /* Message based SPI is not implemented */
-        goto write_ignore_32;
+        goto write_reserved;
 
     case VREG32(0x0054):
         goto write_reserved;
 
     case VREG32(GICD_CLRSPI_SR):
         /* Message based SPI is not implemented */
-        goto write_ignore_32;
+        goto write_reserved;
 
     case VRANGE32(0x005C, 0x007C):
         goto write_reserved;
Signature · 1 line
2.1.4