* [PATCH v2 01/77] hw/intc/arm_gicv5: Make lpi_cache hash value be L2 ISTE, not pointer to it
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 02/77] hw/intc/arm_gicv5: Fix type of "id" in hashtable foreach fns Peter Maydell
` (75 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
The GICv5 model uses a hashtable to cache the L2 ISTE words for
interrupts which are currently pending. For this hashtable, the keys
are GINT_TO_POINTER of the interrupt ID, and the values are pointers
to allocated memory containing the L2 ISTE value.
Because the L2 ISTE value is only 32 bits, we can avoid the memory
allocations by having the values be GINT_TO_POINTER of the L2 ISTE.
If we ever wanted to use the architecturally permitted option to
store implementation-specific metadata in guest memory in an L2 ISTE
(which makes L2 ISTEs bigger than 32 bits) then we would need to
return to having hash values be pointers to allocated memory, but it
is unlikely that QEMU's implementation will ever need to do that.
Suggested-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Message-id: 20261201113633.1083586-1-peter.maydell@linaro.org
---
hw/intc/arm_gicv5.c | 67 ++++++++++++++++++++-------------------------
1 file changed, 30 insertions(+), 37 deletions(-)
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index 59b8596bf0c..5a923eae6cf 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -390,7 +390,7 @@ typedef struct GetHPPIUserData {
static void lpi_cache_get_hppi(gpointer key, gpointer value, gpointer user_data)
{
uint64_t id = GPOINTER_TO_INT(key);
- uint32_t l2_iste = *(uint32_t *)value;
+ uint32_t l2_iste = GPOINTER_TO_INT(value);
uint32_t prio, iaffid;
GetHPPIUserData *ud = user_data;
@@ -646,12 +646,8 @@ static bool write_l2_iste_mem(GICv5Common *cs, const GICv5ISTConfig *cfg,
typedef struct L2_ISTE_Handle {
/* Guest memory address of the L2 ISTE; valid only if !hashed */
hwaddr l2_iste_addr;
- union {
- /* Actual L2_ISTE word; valid only if !hashed */
- uint32_t l2_iste;
- /* Pointer to L2 ISTE word; valid only if hashed */
- uint32_t *l2_iste_p;
- };
+ /* Actual L2_ISTE word */
+ uint32_t l2_iste;
uint32_t id;
/* True if this ISTE is currently in the cache */
bool hashed;
@@ -674,22 +670,20 @@ static uint32_t *get_l2_iste(GICv5Common *cs, const GICv5ISTConfig *cfg,
* If the ISTE could not be read (typically because of a memory
* error), return NULL.
*/
- uint32_t *hashvalue;
+ gpointer hashvalue;
if (!cfg->valid) {
/* Catch invalid config early, it has no lpi_cache */
return NULL;
}
- hashvalue = g_hash_table_lookup(cfg->lpi_cache,
- GINT_TO_POINTER(id));
-
h->id = id;
- if (hashvalue) {
+ if (g_hash_table_lookup_extended(cfg->lpi_cache, GINT_TO_POINTER(id),
+ NULL, &hashvalue)) {
h->hashed = true;
- h->l2_iste_p = hashvalue;
- return hashvalue;
+ h->l2_iste = GPOINTER_TO_INT(hashvalue);
+ return &h->l2_iste;
}
h->hashed = false;
@@ -708,32 +702,31 @@ static void put_l2_iste(GICv5Common *cs, const GICv5ISTConfig *cfg,
* Once this has been called the L2_ISTE_Handle @h and the pointer
* to the L2 ISTE word are no longer valid.
*/
- if (h->hashed) {
- uint32_t l2_iste = *h->l2_iste_p;
- if (!FIELD_EX32(l2_iste, L2_ISTE, PENDING)) {
- /*
- * We just made this not pending: remove from hash table
- * and write back to memory.
- */
- hwaddr l2_iste_addr;
+ if (h->hashed && !FIELD_EX32(h->l2_iste, L2_ISTE, PENDING)) {
+ /*
+ * We just made this not pending: remove from hash table
+ * and write back to memory.
+ */
+ hwaddr l2_iste_addr;
- g_hash_table_remove(cfg->lpi_cache, GINT_TO_POINTER(h->id));
- if (get_l2_iste_addr(cs, cfg, h->id, &l2_iste_addr)) {
- write_l2_iste_mem(cs, cfg, l2_iste_addr, l2_iste);
- /* Writeback errors are ignored. */
- }
+ g_hash_table_remove(cfg->lpi_cache, GINT_TO_POINTER(h->id));
+ if (get_l2_iste_addr(cs, cfg, h->id, &l2_iste_addr)) {
+ write_l2_iste_mem(cs, cfg, l2_iste_addr, h->l2_iste);
+ /* Writeback errors are ignored. */
}
return;
}
if (FIELD_EX32(h->l2_iste, L2_ISTE, PENDING)) {
/*
- * We just made this pending: add it to the hash table, and
- * don't bother writing it back to memory.
+ * Either we just made this pending and need to add this to the
+ * hash table, or else it was already pending and we need to
+ * update the hash table with the altered l2_iste value.
+ * Either way, insert or update the hash table value, and don't
+ * bother writing it back to memory.
*/
- uint32_t *hashvalue = g_new(uint32_t, 1);
- *hashvalue = h->l2_iste;
- g_hash_table_insert(cfg->lpi_cache, GINT_TO_POINTER(h->id), hashvalue);
+ g_hash_table_insert(cfg->lpi_cache, GINT_TO_POINTER(h->id),
+ GINT_TO_POINTER(h->l2_iste));
return;
}
write_l2_iste_mem(cs, cfg, h->l2_iste_addr, h->l2_iste);
@@ -1268,7 +1261,7 @@ static gboolean irs_clean_lpi_cache_entry(gpointer key, gpointer value,
CleanLPICacheUserData *ud = user_data;
hwaddr l2_iste_addr;
uint64_t id = GPOINTER_TO_INT(key);
- uint32_t l2_iste = *(uint32_t *)value;
+ uint32_t l2_iste = GPOINTER_TO_INT(value);
if (!get_l2_iste_addr(ud->cs, ud->cfg, id, &l2_iste_addr) ||
!write_l2_iste_mem(ud->cs, ud->cfg, l2_iste_addr, l2_iste)) {
@@ -1394,11 +1387,11 @@ static void irs_ist_baser_write(GICv5 *s, GICv5Domain domain, uint64_t value)
if (!cfg->lpi_cache) {
/*
* Keys are GINT_TO_POINTER(intid), so we want the g_direct_hash
- * and g_direct_equal hash and equality functions. We don't
- * want to free the keys, but we do want to free the values
- * (which are pointer-to-uint32_t).
+ * and g_direct_equal hash and equality functions. Keys are
+ * GINT_TO_POINTER(L2_ISTE). We don't want the hash table to try
+ * to free either keys or values.
*/
- cfg->lpi_cache = g_hash_table_new_full(NULL, NULL, NULL, g_free);
+ cfg->lpi_cache = g_hash_table_new(NULL, NULL);
}
cfg->valid = true;
trace_gicv5_ist_valid(domain_name[domain], cfg->base, cfg->id_bits,
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 02/77] hw/intc/arm_gicv5: Fix type of "id" in hashtable foreach fns
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
2026-12-03 11:10 ` [PATCH v2 01/77] hw/intc/arm_gicv5: Make lpi_cache hash value be L2 ISTE, not pointer to it Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:32 ` Manos Pitsidianakis
2026-12-03 11:10 ` [PATCH v2 03/77] hw/intc/arm_gicv5: Fix various errors in register definitions Peter Maydell
` (74 subsequent siblings)
76 siblings, 1 reply; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
lpi_cache_get_hppi() and irs_clean_lpi_cache_entry() are both
functions that we pass to g_hash_table_foreach() to iterate over the
LPI cache hashtable. They both get the interrupt ID with "uint64_t
id = GPOINTER_TO_INT(key)". This isn't the right type: interrupt IDs
are 32 bits and the gicv5 code uses uint32_t for them as a general
rule. The use of uint64_t here has no harmful effects, but we should
use uint32_t as it matches both how the hash key was set and how we
use the variable within these functions.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/intc/arm_gicv5.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index 5a923eae6cf..28ef3e71e3f 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -389,7 +389,7 @@ typedef struct GetHPPIUserData {
static void lpi_cache_get_hppi(gpointer key, gpointer value, gpointer user_data)
{
- uint64_t id = GPOINTER_TO_INT(key);
+ uint32_t id = GPOINTER_TO_INT(key);
uint32_t l2_iste = GPOINTER_TO_INT(value);
uint32_t prio, iaffid;
GetHPPIUserData *ud = user_data;
@@ -1260,7 +1260,7 @@ static gboolean irs_clean_lpi_cache_entry(gpointer key, gpointer value,
/* Drop this entry from the LPI cache, writing it back to guest memory. */
CleanLPICacheUserData *ud = user_data;
hwaddr l2_iste_addr;
- uint64_t id = GPOINTER_TO_INT(key);
+ uint32_t id = GPOINTER_TO_INT(key);
uint32_t l2_iste = GPOINTER_TO_INT(value);
if (!get_l2_iste_addr(ud->cs, ud->cfg, id, &l2_iste_addr) ||
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* Re: [PATCH v2 02/77] hw/intc/arm_gicv5: Fix type of "id" in hashtable foreach fns
2026-12-03 11:10 ` [PATCH v2 02/77] hw/intc/arm_gicv5: Fix type of "id" in hashtable foreach fns Peter Maydell
@ 2026-12-03 11:32 ` Manos Pitsidianakis
0 siblings, 0 replies; 99+ messages in thread
From: Manos Pitsidianakis @ 2026-12-03 11:32 UTC (permalink / raw)
To: Peter Maydell, qemu-arm, qemu-devel
Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
On Thu, 03 Dec 2026 13:10, Peter Maydell <peter.maydell@linaro.org> wrote:
>lpi_cache_get_hppi() and irs_clean_lpi_cache_entry() are both
>functions that we pass to g_hash_table_foreach() to iterate over the
>LPI cache hashtable. They both get the interrupt ID with "uint64_t
>id = GPOINTER_TO_INT(key)". This isn't the right type: interrupt IDs
>are 32 bits and the gicv5 code uses uint32_t for them as a general
>rule. The use of uint64_t here has no harmful effects, but we should
>use uint32_t as it matches both how the hash key was set and how we
>use the variable within these functions.
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
>
>Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>---
> hw/intc/arm_gicv5.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
>diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
>index 5a923eae6cf..28ef3e71e3f 100644
>--- a/hw/intc/arm_gicv5.c
>+++ b/hw/intc/arm_gicv5.c
>@@ -389,7 +389,7 @@ typedef struct GetHPPIUserData {
>
> static void lpi_cache_get_hppi(gpointer key, gpointer value, gpointer user_data)
> {
>- uint64_t id = GPOINTER_TO_INT(key);
>+ uint32_t id = GPOINTER_TO_INT(key);
> uint32_t l2_iste = GPOINTER_TO_INT(value);
> uint32_t prio, iaffid;
> GetHPPIUserData *ud = user_data;
>@@ -1260,7 +1260,7 @@ static gboolean irs_clean_lpi_cache_entry(gpointer key, gpointer value,
> /* Drop this entry from the LPI cache, writing it back to guest memory. */
> CleanLPICacheUserData *ud = user_data;
> hwaddr l2_iste_addr;
>- uint64_t id = GPOINTER_TO_INT(key);
>+ uint32_t id = GPOINTER_TO_INT(key);
> uint32_t l2_iste = GPOINTER_TO_INT(value);
>
> if (!get_l2_iste_addr(ud->cs, ud->cfg, id, &l2_iste_addr) ||
>--
>2.43.0
>
^ permalink raw reply [flat|nested] 99+ messages in thread
* [PATCH v2 03/77] hw/intc/arm_gicv5: Fix various errors in register definitions
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
2026-12-03 11:10 ` [PATCH v2 01/77] hw/intc/arm_gicv5: Make lpi_cache hash value be L2 ISTE, not pointer to it Peter Maydell
2026-12-03 11:10 ` [PATCH v2 02/77] hw/intc/arm_gicv5: Fix type of "id" in hashtable foreach fns Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:34 ` Manos Pitsidianakis
2026-12-03 11:10 ` [PATCH v2 04/77] target/arm: GICv5 cpuif: Implement ICH_APR_EL2 Peter Maydell
` (73 subsequent siblings)
76 siblings, 1 reply; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
The register definitions for the GIC IRS have some mistakes. Luckily
these are all in definitions for registers we don't currently
implement, so the errors are currently harmless. Correct them now,
before we try to make use of them.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/intc/arm_gicv5.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index 28ef3e71e3f..bbe141da1a3 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -198,7 +198,7 @@ REG64(IRS_VPE_DBR, 0x248)
FIELD(IRS_VPE_DBR, REQ_DB, 62, 1)
FIELD(IRS_VPE_DBR, DBV, 63, 1)
-REG32(IRS_VPE_HPPIR, 0x250)
+REG64(IRS_VPE_HPPIR, 0x250)
FIELD(IRS_VPE_HPPIR, ID, 0, 24)
FIELD(IRS_VPE_HPPIR, TYPE, 29, 3)
FIELD(IRS_VPE_HPPIR, HPPIV, 32, 1)
@@ -260,7 +260,7 @@ REG32(IRS_MEC_IDR, 0x340)
FIELD(IRS_MEC_IDR, MECIDSIZE, 0, 4)
REG32(IRS_MEC_MECID_R, 0x344)
- FIELD(IRS_MEC_MICID_R, MECID, 0, 16)
+ FIELD(IRS_MEC_MECID_R, MECID, 0, 16)
REG32(IRS_MPAM_IDR, 0x380)
FIELD(IRS_MPAM_IDR, PARTID_MAX, 0, 16)
@@ -268,10 +268,10 @@ REG32(IRS_MPAM_IDR, 0x380)
FIELD(IRS_MPAM_IDR, HAS_MPAM_SP, 24, 1)
REG32(IRS_MPAM_PARTID_R, 0x384)
- FIELD(IRS_MPAM_IDR, PARTID, 0, 16)
- FIELD(IRS_MPAM_IDR, PMG, 16, 8)
- FIELD(IRS_MPAM_IDR, MPAM_SP, 24, 2)
- FIELD(IRS_MPAM_IDR, IDLE, 31, 1)
+ FIELD(IRS_MPAM_PARTID, PARTID, 0, 16)
+ FIELD(IRS_MPAM_PARTID, PMG, 16, 8)
+ FIELD(IRS_MPAM_PARTID, MPAM_SP, 24, 2)
+ FIELD(IRS_MPAM_PARTID, IDLE, 31, 1)
REG64(IRS_SWERR_STATUSR, 0x3c0)
FIELD(IRS_SWERR_STATUSR, V, 0, 1)
@@ -288,7 +288,7 @@ REG64(IRS_SWERR_SYNDROMER0, 0x3c8)
FIELD(IRS_SWERR_SYNDROMER0, VIRTUAL, 63, 1)
REG64(IRS_SWERR_SYNDROMER1, 0x3d0)
- FIELD(IRS_SWERR_SYNDROMER2, ADDR, 3, 53)
+ FIELD(IRS_SWERR_SYNDROMER1, ADDR, 3, 53)
REG32(IRS_IDREGS, 0xffd0)
REG32(IRS_DEVARCH, 0xffbc)
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* Re: [PATCH v2 03/77] hw/intc/arm_gicv5: Fix various errors in register definitions
2026-12-03 11:10 ` [PATCH v2 03/77] hw/intc/arm_gicv5: Fix various errors in register definitions Peter Maydell
@ 2026-12-03 11:34 ` Manos Pitsidianakis
0 siblings, 0 replies; 99+ messages in thread
From: Manos Pitsidianakis @ 2026-12-03 11:34 UTC (permalink / raw)
To: Peter Maydell, qemu-arm, qemu-devel
Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
On Thu, 03 Dec 2026 13:10, Peter Maydell <peter.maydell@linaro.org> wrote:
>The register definitions for the GIC IRS have some mistakes. Luckily
>these are all in definitions for registers we don't currently
>implement, so the errors are currently harmless. Correct them now,
>before we try to make use of them.
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
>
>Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>---
> hw/intc/arm_gicv5.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
>diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
>index 28ef3e71e3f..bbe141da1a3 100644
>--- a/hw/intc/arm_gicv5.c
>+++ b/hw/intc/arm_gicv5.c
>@@ -198,7 +198,7 @@ REG64(IRS_VPE_DBR, 0x248)
> FIELD(IRS_VPE_DBR, REQ_DB, 62, 1)
> FIELD(IRS_VPE_DBR, DBV, 63, 1)
>
>-REG32(IRS_VPE_HPPIR, 0x250)
>+REG64(IRS_VPE_HPPIR, 0x250)
> FIELD(IRS_VPE_HPPIR, ID, 0, 24)
> FIELD(IRS_VPE_HPPIR, TYPE, 29, 3)
> FIELD(IRS_VPE_HPPIR, HPPIV, 32, 1)
>@@ -260,7 +260,7 @@ REG32(IRS_MEC_IDR, 0x340)
> FIELD(IRS_MEC_IDR, MECIDSIZE, 0, 4)
>
> REG32(IRS_MEC_MECID_R, 0x344)
>- FIELD(IRS_MEC_MICID_R, MECID, 0, 16)
>+ FIELD(IRS_MEC_MECID_R, MECID, 0, 16)
>
> REG32(IRS_MPAM_IDR, 0x380)
> FIELD(IRS_MPAM_IDR, PARTID_MAX, 0, 16)
>@@ -268,10 +268,10 @@ REG32(IRS_MPAM_IDR, 0x380)
> FIELD(IRS_MPAM_IDR, HAS_MPAM_SP, 24, 1)
>
> REG32(IRS_MPAM_PARTID_R, 0x384)
>- FIELD(IRS_MPAM_IDR, PARTID, 0, 16)
>- FIELD(IRS_MPAM_IDR, PMG, 16, 8)
>- FIELD(IRS_MPAM_IDR, MPAM_SP, 24, 2)
>- FIELD(IRS_MPAM_IDR, IDLE, 31, 1)
>+ FIELD(IRS_MPAM_PARTID, PARTID, 0, 16)
>+ FIELD(IRS_MPAM_PARTID, PMG, 16, 8)
>+ FIELD(IRS_MPAM_PARTID, MPAM_SP, 24, 2)
>+ FIELD(IRS_MPAM_PARTID, IDLE, 31, 1)
>
> REG64(IRS_SWERR_STATUSR, 0x3c0)
> FIELD(IRS_SWERR_STATUSR, V, 0, 1)
>@@ -288,7 +288,7 @@ REG64(IRS_SWERR_SYNDROMER0, 0x3c8)
> FIELD(IRS_SWERR_SYNDROMER0, VIRTUAL, 63, 1)
>
> REG64(IRS_SWERR_SYNDROMER1, 0x3d0)
>- FIELD(IRS_SWERR_SYNDROMER2, ADDR, 3, 53)
>+ FIELD(IRS_SWERR_SYNDROMER1, ADDR, 3, 53)
>
> REG32(IRS_IDREGS, 0xffd0)
> REG32(IRS_DEVARCH, 0xffbc)
>--
>2.43.0
>
^ permalink raw reply [flat|nested] 99+ messages in thread
* [PATCH v2 04/77] target/arm: GICv5 cpuif: Implement ICH_APR_EL2
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (2 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 03/77] hw/intc/arm_gicv5: Fix various errors in register definitions Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:40 ` Manos Pitsidianakis
2026-12-03 11:10 ` [PATCH v2 05/77] target/arm: GICv5 cpuif: Implement ICH_PPI_{ENABLE, PEND, ACTIVE} regs Peter Maydell
` (72 subsequent siblings)
76 siblings, 1 reply; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Implement the ICH_APR_EL2 register. This is part of the hypervisor
control register interface, and is the hypervisor-facing access to
the state which holds the guest's its active priority register.
The only slightly non-straightforward part of this is that because
the GICv5 allows a hypervisor to give its guest a GICv3-compatible
virtual CPU interface, this register has to UNDEF to the inner guest
when legacy-vcpu operation is enabled. We don't implement
GCIE_LEGACY in QEMU yet, but since we expect to do so in future, the
handling for this is implemented here.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/cpu.h | 2 ++
target/arm/tcg/gicv5-cpuif.c | 44 ++++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+)
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index b2f393f5018..5985e0a86e1 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -596,6 +596,8 @@ typedef struct CPUArchState {
/* Cached highest-priority pending PPI for each domain */
GICv5PendingIrq ppi_hppi[NUM_GICV5_DOMAINS];
+
+ uint64_t ich_apr_el2;
} gicv5_cpuif;
struct {
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 46039fe4a4c..a9308d8b2eb 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -90,6 +90,15 @@ static GICv5Common *gicv5_get_gic(CPUARMState *env)
return env->gicv5.gicv5state;
}
+/*
+ * Return true if GIC virtual interface legacy operation is enabled.
+ * We don't currently implement FEAT_GCIE_LEGACY.
+ */
+static bool gicv5_legacy_enabled(CPUARMState *env)
+{
+ return false;
+}
+
static GICv5Domain gicv5_logical_domain(CPUARMState *env)
{
/*
@@ -696,6 +705,34 @@ static void gic_cddi_write(CPUARMState *env, const ARMCPRegInfo *ri,
}
}
+static CPAccessResult access_gicv5_ich_reg(CPUARMState *env,
+ const ARMCPRegInfo *ri,
+ bool isread)
+{
+ /*
+ * accessfn for GICv5 ICH regs. The NV behaviour here is a little
+ * different from usual because of the optional legacy GIC feature.
+ *
+ * At EL1, if GCIE_LEGACY is disabled or not implemented, these
+ * behave like normal EL2 registers, which is that they redirect
+ * to memory if NV2 is enabled and trap to EL2 if not. If legacy
+ * operation is enabled, these registers must UNDEF to EL1
+ * (because from the inner guest's point of view it has a GICv3
+ * and this sysreg doesn't exist).
+ *
+ * The UNDEF at EL1 when NV==0 is handled already because of the
+ * .access = PL2_RW setting on the cpreg.
+ */
+ if (arm_current_el(env) == 1 && gicv5_legacy_enabled(env)) {
+ return CP_ACCESS_UNDEFINED;
+ }
+ /*
+ * continue to either redirect-to-memory, trap-to-EL2 or (if
+ * current EL is 2 or 3) access the register
+ */
+ return CP_ACCESS_OK;
+}
+
static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
/*
* Barrier: wait until the effects of a cpuif system register
@@ -893,6 +930,13 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
.writefn = gic_icc_pcr_el1_write,
.resetfn = gic_icc_pcr_el1_reset,
},
+ { .name = "ICH_APR_EL2", .state = ARM_CP_STATE_AA64,
+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 8, .opc2 = 4,
+ .access = PL2_RW, .type = ARM_CP_NO_RAW,
+ .nv2_redirect_offset = 0xb00,
+ .accessfn = access_gicv5_ich_reg,
+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_apr_el2),
+ },
};
void define_gicv5_cpuif_regs(ARMCPU *cpu)
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* Re: [PATCH v2 04/77] target/arm: GICv5 cpuif: Implement ICH_APR_EL2
2026-12-03 11:10 ` [PATCH v2 04/77] target/arm: GICv5 cpuif: Implement ICH_APR_EL2 Peter Maydell
@ 2026-12-03 11:40 ` Manos Pitsidianakis
0 siblings, 0 replies; 99+ messages in thread
From: Manos Pitsidianakis @ 2026-12-03 11:40 UTC (permalink / raw)
To: Peter Maydell, qemu-arm, qemu-devel
Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
On Thu, 03 Dec 2026 13:10, Peter Maydell <peter.maydell@linaro.org> wrote:
>Implement the ICH_APR_EL2 register. This is part of the hypervisor
>control register interface, and is the hypervisor-facing access to
>the state which holds the guest's its active priority register.
s/its//
>
>The only slightly non-straightforward part of this is that because
>the GICv5 allows a hypervisor to give its guest a GICv3-compatible
>virtual CPU interface, this register has to UNDEF to the inner guest
>when legacy-vcpu operation is enabled. We don't implement
>GCIE_LEGACY in QEMU yet, but since we expect to do so in future, the
>handling for this is implemented here.
>
>Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>---
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
> target/arm/cpu.h | 2 ++
> target/arm/tcg/gicv5-cpuif.c | 44 ++++++++++++++++++++++++++++++++++++
> 2 files changed, 46 insertions(+)
>
>diff --git a/target/arm/cpu.h b/target/arm/cpu.h
>index b2f393f5018..5985e0a86e1 100644
>--- a/target/arm/cpu.h
>+++ b/target/arm/cpu.h
>@@ -596,6 +596,8 @@ typedef struct CPUArchState {
>
> /* Cached highest-priority pending PPI for each domain */
> GICv5PendingIrq ppi_hppi[NUM_GICV5_DOMAINS];
>+
>+ uint64_t ich_apr_el2;
> } gicv5_cpuif;
>
> struct {
>diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
>index 46039fe4a4c..a9308d8b2eb 100644
>--- a/target/arm/tcg/gicv5-cpuif.c
>+++ b/target/arm/tcg/gicv5-cpuif.c
>@@ -90,6 +90,15 @@ static GICv5Common *gicv5_get_gic(CPUARMState *env)
> return env->gicv5.gicv5state;
> }
>
>+/*
>+ * Return true if GIC virtual interface legacy operation is enabled.
>+ * We don't currently implement FEAT_GCIE_LEGACY.
>+ */
>+static bool gicv5_legacy_enabled(CPUARMState *env)
>+{
>+ return false;
>+}
>+
> static GICv5Domain gicv5_logical_domain(CPUARMState *env)
> {
> /*
>@@ -696,6 +705,34 @@ static void gic_cddi_write(CPUARMState *env, const ARMCPRegInfo *ri,
> }
> }
>
>+static CPAccessResult access_gicv5_ich_reg(CPUARMState *env,
>+ const ARMCPRegInfo *ri,
>+ bool isread)
>+{
>+ /*
>+ * accessfn for GICv5 ICH regs. The NV behaviour here is a little
>+ * different from usual because of the optional legacy GIC feature.
>+ *
>+ * At EL1, if GCIE_LEGACY is disabled or not implemented, these
>+ * behave like normal EL2 registers, which is that they redirect
>+ * to memory if NV2 is enabled and trap to EL2 if not. If legacy
>+ * operation is enabled, these registers must UNDEF to EL1
>+ * (because from the inner guest's point of view it has a GICv3
>+ * and this sysreg doesn't exist).
>+ *
>+ * The UNDEF at EL1 when NV==0 is handled already because of the
>+ * .access = PL2_RW setting on the cpreg.
>+ */
>+ if (arm_current_el(env) == 1 && gicv5_legacy_enabled(env)) {
>+ return CP_ACCESS_UNDEFINED;
>+ }
>+ /*
>+ * continue to either redirect-to-memory, trap-to-EL2 or (if
>+ * current EL is 2 or 3) access the register
>+ */
>+ return CP_ACCESS_OK;
>+}
>+
> static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
> /*
> * Barrier: wait until the effects of a cpuif system register
>@@ -893,6 +930,13 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
> .writefn = gic_icc_pcr_el1_write,
> .resetfn = gic_icc_pcr_el1_reset,
> },
>+ { .name = "ICH_APR_EL2", .state = ARM_CP_STATE_AA64,
>+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 8, .opc2 = 4,
>+ .access = PL2_RW, .type = ARM_CP_NO_RAW,
>+ .nv2_redirect_offset = 0xb00,
>+ .accessfn = access_gicv5_ich_reg,
>+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_apr_el2),
>+ },
> };
>
> void define_gicv5_cpuif_regs(ARMCPU *cpu)
>--
>2.43.0
>
^ permalink raw reply [flat|nested] 99+ messages in thread
* [PATCH v2 05/77] target/arm: GICv5 cpuif: Implement ICH_PPI_{ENABLE, PEND, ACTIVE} regs
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (3 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 04/77] target/arm: GICv5 cpuif: Implement ICH_APR_EL2 Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:43 ` Manos Pitsidianakis
2026-12-03 11:10 ` [PATCH v2 06/77] target/arm: GICv5 cpuif: Implement ICH_PPI_PRIORITYR<n>_EL2 Peter Maydell
` (71 subsequent siblings)
76 siblings, 1 reply; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Implement the ICH_PPI_ENABLERn_EL2, ICH_PPI_PENDRn_EL2 and
ICH_PPI_ACTIVERn_EL2 registers. These are the hypervisor interface
to the underlying state of its guest's PPI interrupts. Unlike the
ICC PPI registers, these don't have set and clear register pairs.
We mark these as ARM_CP_IO and give them a writefn, even though right
now the only thing the writefn does is a raw_write to the underlying
CPU struct field, because eventually hypervisor writes to these
registers will need to trigger recalculation of the highest priority
pending PPI and possible signalling of VIRQ.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/cpu.h | 3 ++
target/arm/tcg/gicv5-cpuif.c | 64 ++++++++++++++++++++++++++++++++++++
2 files changed, 67 insertions(+)
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index 5985e0a86e1..fc919deeaa3 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -598,6 +598,9 @@ typedef struct CPUArchState {
GICv5PendingIrq ppi_hppi[NUM_GICV5_DOMAINS];
uint64_t ich_apr_el2;
+ uint64_t ich_ppi_active[GICV5_NUM_PPIS / 64];
+ uint64_t ich_ppi_pend[GICV5_NUM_PPIS / 64];
+ uint64_t ich_ppi_enable[GICV5_NUM_PPIS / 64];
} gicv5_cpuif;
struct {
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index a9308d8b2eb..2f9da181d58 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -463,6 +463,24 @@ static void gic_ppi_priority_write(CPUARMState *env, const ARMCPRegInfo *ri,
gic_recalc_ppi_hppi(env);
}
+static void gic_ich_ppi_enable_write(CPUARMState *env, const ARMCPRegInfo *ri,
+ uint64_t value)
+{
+ raw_write(env, ri, value);
+}
+
+static void gic_ich_ppi_pend_write(CPUARMState *env, const ARMCPRegInfo *ri,
+ uint64_t value)
+{
+ raw_write(env, ri, value);
+}
+
+static void gic_ich_ppi_active_write(CPUARMState *env, const ARMCPRegInfo *ri,
+ uint64_t value)
+{
+ raw_write(env, ri, value);
+}
+
/*
* ICC_APR_EL1 is banked and reads/writes as the version for the
* current logical interrupt domain.
@@ -937,6 +955,52 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
.accessfn = access_gicv5_ich_reg,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_apr_el2),
},
+ { .name = "ICH_PPI_ENABLER0_EL2", .state = ARM_CP_STATE_AA64,
+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 10, .opc2 = 2,
+ .access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .nv2_redirect_offset = 0xb50,
+ .accessfn = access_gicv5_ich_reg,
+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_ppi_enable[0]),
+ .writefn = gic_ich_ppi_enable_write,
+ },
+ { .name = "ICH_PPI_ENABLER1_EL2", .state = ARM_CP_STATE_AA64,
+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 10, .opc2 = 3,
+ .access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .nv2_redirect_offset = 0xb58,
+ .accessfn = access_gicv5_ich_reg,
+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_ppi_enable[1]),
+ .writefn = gic_ich_ppi_enable_write,
+ },
+ { .name = "ICH_PPI_PENDR0_EL2", .state = ARM_CP_STATE_AA64,
+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 10, .opc2 = 4,
+ .access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .accessfn = access_gicv5_ich_reg,
+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_ppi_pend[0]),
+ .writefn = gic_ich_ppi_pend_write,
+ },
+ { .name = "ICH_PPI_PENDR1_EL2", .state = ARM_CP_STATE_AA64,
+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 10, .opc2 = 5,
+ .access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .accessfn = access_gicv5_ich_reg,
+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_ppi_pend[1]),
+ .writefn = gic_ich_ppi_pend_write,
+ },
+ { .name = "ICH_PPI_ACTIVER0_EL2", .state = ARM_CP_STATE_AA64,
+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 10, .opc2 = 6,
+ .access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .nv2_redirect_offset = 0xb30,
+ .accessfn = access_gicv5_ich_reg,
+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_ppi_active[0]),
+ .writefn = gic_ich_ppi_active_write,
+ },
+ { .name = "ICH_PPI_ACTIVER1_EL2", .state = ARM_CP_STATE_AA64,
+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 10, .opc2 = 7,
+ .access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .nv2_redirect_offset = 0xb38,
+ .accessfn = access_gicv5_ich_reg,
+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_ppi_active[1]),
+ .writefn = gic_ich_ppi_active_write,
+ },
};
void define_gicv5_cpuif_regs(ARMCPU *cpu)
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* Re: [PATCH v2 05/77] target/arm: GICv5 cpuif: Implement ICH_PPI_{ENABLE, PEND, ACTIVE} regs
2026-12-03 11:10 ` [PATCH v2 05/77] target/arm: GICv5 cpuif: Implement ICH_PPI_{ENABLE, PEND, ACTIVE} regs Peter Maydell
@ 2026-12-03 11:43 ` Manos Pitsidianakis
0 siblings, 0 replies; 99+ messages in thread
From: Manos Pitsidianakis @ 2026-12-03 11:43 UTC (permalink / raw)
To: Peter Maydell, qemu-arm, qemu-devel
Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
On Thu, 03 Dec 2026 13:10, Peter Maydell <peter.maydell@linaro.org> wrote:
>Implement the ICH_PPI_ENABLERn_EL2, ICH_PPI_PENDRn_EL2 and
>ICH_PPI_ACTIVERn_EL2 registers. These are the hypervisor interface
>to the underlying state of its guest's PPI interrupts. Unlike the
>ICC PPI registers, these don't have set and clear register pairs.
>
>We mark these as ARM_CP_IO and give them a writefn, even though right
>now the only thing the writefn does is a raw_write to the underlying
>CPU struct field, because eventually hypervisor writes to these
>registers will need to trigger recalculation of the highest priority
>pending PPI and possible signalling of VIRQ.
>
>Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>---
> target/arm/cpu.h | 3 ++
> target/arm/tcg/gicv5-cpuif.c | 64 ++++++++++++++++++++++++++++++++++++
> 2 files changed, 67 insertions(+)
>
>diff --git a/target/arm/cpu.h b/target/arm/cpu.h
>index 5985e0a86e1..fc919deeaa3 100644
>--- a/target/arm/cpu.h
>+++ b/target/arm/cpu.h
>@@ -598,6 +598,9 @@ typedef struct CPUArchState {
> GICv5PendingIrq ppi_hppi[NUM_GICV5_DOMAINS];
>
> uint64_t ich_apr_el2;
>+ uint64_t ich_ppi_active[GICV5_NUM_PPIS / 64];
>+ uint64_t ich_ppi_pend[GICV5_NUM_PPIS / 64];
>+ uint64_t ich_ppi_enable[GICV5_NUM_PPIS / 64];
Nit: ich_ppi_activer[..], ich_ppi_pendr[..] etc would fit the spec more
clearly.
> } gicv5_cpuif;
>
> struct {
>diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
>index a9308d8b2eb..2f9da181d58 100644
>--- a/target/arm/tcg/gicv5-cpuif.c
>+++ b/target/arm/tcg/gicv5-cpuif.c
>@@ -463,6 +463,24 @@ static void gic_ppi_priority_write(CPUARMState *env, const ARMCPRegInfo *ri,
> gic_recalc_ppi_hppi(env);
> }
>
>+static void gic_ich_ppi_enable_write(CPUARMState *env, const ARMCPRegInfo *ri,
ditto and on other write fns
either way is fine with me
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
>+ uint64_t value)
>+{
>+ raw_write(env, ri, value);
>+}
>+
>+static void gic_ich_ppi_pend_write(CPUARMState *env, const ARMCPRegInfo *ri,
>+ uint64_t value)
>+{
>+ raw_write(env, ri, value);
>+}
>+
>+static void gic_ich_ppi_active_write(CPUARMState *env, const ARMCPRegInfo *ri,
>+ uint64_t value)
>+{
>+ raw_write(env, ri, value);
>+}
>+
> /*
> * ICC_APR_EL1 is banked and reads/writes as the version for the
> * current logical interrupt domain.
>@@ -937,6 +955,52 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
> .accessfn = access_gicv5_ich_reg,
> .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_apr_el2),
> },
>+ { .name = "ICH_PPI_ENABLER0_EL2", .state = ARM_CP_STATE_AA64,
>+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 10, .opc2 = 2,
>+ .access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
>+ .nv2_redirect_offset = 0xb50,
>+ .accessfn = access_gicv5_ich_reg,
>+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_ppi_enable[0]),
>+ .writefn = gic_ich_ppi_enable_write,
>+ },
>+ { .name = "ICH_PPI_ENABLER1_EL2", .state = ARM_CP_STATE_AA64,
>+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 10, .opc2 = 3,
>+ .access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
>+ .nv2_redirect_offset = 0xb58,
>+ .accessfn = access_gicv5_ich_reg,
>+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_ppi_enable[1]),
>+ .writefn = gic_ich_ppi_enable_write,
>+ },
>+ { .name = "ICH_PPI_PENDR0_EL2", .state = ARM_CP_STATE_AA64,
>+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 10, .opc2 = 4,
>+ .access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
>+ .accessfn = access_gicv5_ich_reg,
>+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_ppi_pend[0]),
>+ .writefn = gic_ich_ppi_pend_write,
>+ },
>+ { .name = "ICH_PPI_PENDR1_EL2", .state = ARM_CP_STATE_AA64,
>+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 10, .opc2 = 5,
>+ .access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
>+ .accessfn = access_gicv5_ich_reg,
>+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_ppi_pend[1]),
>+ .writefn = gic_ich_ppi_pend_write,
>+ },
>+ { .name = "ICH_PPI_ACTIVER0_EL2", .state = ARM_CP_STATE_AA64,
>+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 10, .opc2 = 6,
>+ .access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
>+ .nv2_redirect_offset = 0xb30,
>+ .accessfn = access_gicv5_ich_reg,
>+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_ppi_active[0]),
>+ .writefn = gic_ich_ppi_active_write,
>+ },
>+ { .name = "ICH_PPI_ACTIVER1_EL2", .state = ARM_CP_STATE_AA64,
>+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 10, .opc2 = 7,
>+ .access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
>+ .nv2_redirect_offset = 0xb38,
>+ .accessfn = access_gicv5_ich_reg,
>+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_ppi_active[1]),
>+ .writefn = gic_ich_ppi_active_write,
>+ },
> };
>
> void define_gicv5_cpuif_regs(ARMCPU *cpu)
>--
>2.43.0
>
^ permalink raw reply [flat|nested] 99+ messages in thread
* [PATCH v2 06/77] target/arm: GICv5 cpuif: Implement ICH_PPI_PRIORITYR<n>_EL2
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (4 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 05/77] target/arm: GICv5 cpuif: Implement ICH_PPI_{ENABLE, PEND, ACTIVE} regs Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:53 ` Manos Pitsidianakis
2026-12-03 11:10 ` [PATCH v2 07/77] target/arm: GICv5 cpuif: Implement ICH_PPI_DVIR<n>_EL2 Peter Maydell
` (70 subsequent siblings)
76 siblings, 1 reply; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Implement the ICH_PPI_PRIORITYR<n>_EL2 registers, which are the
hypervisor's interface to its guest's PPI priority register state.
As with ICC_PPI_PRIORITY<n>_EL1, we define these programmatically to
avoid listing out 16 near-identical cpreg definitions.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/cpu.h | 1 +
target/arm/tcg/gicv5-cpuif.c | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index fc919deeaa3..3944a2ef104 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -601,6 +601,7 @@ typedef struct CPUArchState {
uint64_t ich_ppi_active[GICV5_NUM_PPIS / 64];
uint64_t ich_ppi_pend[GICV5_NUM_PPIS / 64];
uint64_t ich_ppi_enable[GICV5_NUM_PPIS / 64];
+ uint64_t ich_ppi_priority[GICV5_NUM_PPIS / 8];
} gicv5_cpuif;
struct {
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 2f9da181d58..24065274690 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -481,6 +481,12 @@ static void gic_ich_ppi_active_write(CPUARMState *env, const ARMCPRegInfo *ri,
raw_write(env, ri, value);
}
+static void gic_ich_ppi_priority_write(CPUARMState *env, const ARMCPRegInfo *ri,
+ uint64_t value)
+{
+ raw_write(env, ri, value);
+}
+
/*
* ICC_APR_EL1 is banked and reads/writes as the version for the
* current logical interrupt domain.
@@ -1024,5 +1030,20 @@ void define_gicv5_cpuif_regs(ARMCPU *cpu)
};
define_one_arm_cp_reg(cpu, &ppi_prio);
}
+ /* Similarly for ICH_PPI_PRIORITYR<n>_EL2 */
+ for (int i = 0; i < 16; i++) {
+ g_autofree char *name = g_strdup_printf("ICH_PPI_PRIORITYR%d_EL2", i);
+ ARMCPRegInfo ppi_prio = {
+ .name = name, .state = ARM_CP_STATE_AA64,
+ .opc0 = 3, .opc1 = 4, .crn = 12,
+ .crm = 14 + (i >> 3), .opc2 = i & 7,
+ .access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .nv2_redirect_offset = 0xb80 + (8 * i),
+ .accessfn = access_gicv5_ich_reg,
+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_ppi_priority[i]),
+ .writefn = gic_ich_ppi_priority_write,
+ };
+ define_one_arm_cp_reg(cpu, &ppi_prio);
+ }
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* Re: [PATCH v2 06/77] target/arm: GICv5 cpuif: Implement ICH_PPI_PRIORITYR<n>_EL2
2026-12-03 11:10 ` [PATCH v2 06/77] target/arm: GICv5 cpuif: Implement ICH_PPI_PRIORITYR<n>_EL2 Peter Maydell
@ 2026-12-03 11:53 ` Manos Pitsidianakis
0 siblings, 0 replies; 99+ messages in thread
From: Manos Pitsidianakis @ 2026-12-03 11:53 UTC (permalink / raw)
To: qemu-devel, Peter Maydell, qemu-arm
Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
On Thu, 03 Dec 2026 13:10, Peter Maydell <peter.maydell@linaro.org> wrote:
>Implement the ICH_PPI_PRIORITYR<n>_EL2 registers, which are the
>hypervisor's interface to its guest's PPI priority register state.
>As with ICC_PPI_PRIORITY<n>_EL1, we define these programmatically to
>avoid listing out 16 near-identical cpreg definitions.
>
>Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>---
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
> target/arm/cpu.h | 1 +
> target/arm/tcg/gicv5-cpuif.c | 21 +++++++++++++++++++++
> 2 files changed, 22 insertions(+)
>
>diff --git a/target/arm/cpu.h b/target/arm/cpu.h
>index fc919deeaa3..3944a2ef104 100644
>--- a/target/arm/cpu.h
>+++ b/target/arm/cpu.h
>@@ -601,6 +601,7 @@ typedef struct CPUArchState {
> uint64_t ich_ppi_active[GICV5_NUM_PPIS / 64];
> uint64_t ich_ppi_pend[GICV5_NUM_PPIS / 64];
> uint64_t ich_ppi_enable[GICV5_NUM_PPIS / 64];
>+ uint64_t ich_ppi_priority[GICV5_NUM_PPIS / 8];
> } gicv5_cpuif;
>
> struct {
>diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
>index 2f9da181d58..24065274690 100644
>--- a/target/arm/tcg/gicv5-cpuif.c
>+++ b/target/arm/tcg/gicv5-cpuif.c
>@@ -481,6 +481,12 @@ static void gic_ich_ppi_active_write(CPUARMState *env, const ARMCPRegInfo *ri,
> raw_write(env, ri, value);
> }
>
>+static void gic_ich_ppi_priority_write(CPUARMState *env, const ARMCPRegInfo *ri,
>+ uint64_t value)
>+{
>+ raw_write(env, ri, value);
>+}
>+
> /*
> * ICC_APR_EL1 is banked and reads/writes as the version for the
> * current logical interrupt domain.
>@@ -1024,5 +1030,20 @@ void define_gicv5_cpuif_regs(ARMCPU *cpu)
> };
> define_one_arm_cp_reg(cpu, &ppi_prio);
> }
>+ /* Similarly for ICH_PPI_PRIORITYR<n>_EL2 */
>+ for (int i = 0; i < 16; i++) {
>+ g_autofree char *name = g_strdup_printf("ICH_PPI_PRIORITYR%d_EL2", i);
>+ ARMCPRegInfo ppi_prio = {
>+ .name = name, .state = ARM_CP_STATE_AA64,
>+ .opc0 = 3, .opc1 = 4, .crn = 12,
>+ .crm = 14 + (i >> 3), .opc2 = i & 7,
>+ .access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
>+ .nv2_redirect_offset = 0xb80 + (8 * i),
>+ .accessfn = access_gicv5_ich_reg,
>+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_ppi_priority[i]),
>+ .writefn = gic_ich_ppi_priority_write,
>+ };
>+ define_one_arm_cp_reg(cpu, &ppi_prio);
>+ }
> }
> }
>--
>2.43.0
>
>
^ permalink raw reply [flat|nested] 99+ messages in thread
* [PATCH v2 07/77] target/arm: GICv5 cpuif: Implement ICH_PPI_DVIR<n>_EL2
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (5 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 06/77] target/arm: GICv5 cpuif: Implement ICH_PPI_PRIORITYR<n>_EL2 Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:57 ` Manos Pitsidianakis
2026-12-03 11:10 ` [PATCH v2 08/77] target/arm: GICv5 cpuif: Implement ICH_VCTLR_EL2 and ICH_VCMR_EL2 Peter Maydell
` (69 subsequent siblings)
76 siblings, 1 reply; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Implement ICH_PPI_DVIR<n>_EL2, which is the register that controls
whether pending physical PPIs are directly injected as virtual PPIs
to the virtual interrupt domain.
Bits in this register are RAZ/WI from EL1 and EL2 if the PPI is
not assigned to the current interrupt domain, but since we don't
yet implement EL3 GICv5 support yet all PPIs are always assigned
to the current interrupt domain.
In this commit we just implement the register access to the state;
actual injection of PPIs will be dealt with later. We give the
register a writefn because eventually writing to this will need
to trigger a recalculation of VIRQ/VFIQ.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/cpu.h | 1 +
target/arm/tcg/gicv5-cpuif.c | 27 +++++++++++++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index 3944a2ef104..384c15586eb 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -601,6 +601,7 @@ typedef struct CPUArchState {
uint64_t ich_ppi_active[GICV5_NUM_PPIS / 64];
uint64_t ich_ppi_pend[GICV5_NUM_PPIS / 64];
uint64_t ich_ppi_enable[GICV5_NUM_PPIS / 64];
+ uint64_t ich_ppi_dvi[GICV5_NUM_PPIS / 64];
uint64_t ich_ppi_priority[GICV5_NUM_PPIS / 8];
} gicv5_cpuif;
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 24065274690..233adc42440 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -487,6 +487,12 @@ static void gic_ich_ppi_priority_write(CPUARMState *env, const ARMCPRegInfo *ri,
raw_write(env, ri, value);
}
+static void gic_ich_ppi_dvi_write(CPUARMState *env, const ARMCPRegInfo *ri,
+ uint64_t value)
+{
+ raw_write(env, ri, value);
+}
+
/*
* ICC_APR_EL1 is banked and reads/writes as the version for the
* current logical interrupt domain.
@@ -961,6 +967,27 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
.accessfn = access_gicv5_ich_reg,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_apr_el2),
},
+ /*
+ * Note that DVIR bits RAZ/WI when the PPI isn't assigned to the
+ * current domain, so we will need to mask them when we implement
+ * EL3 support and ICC_PPI_DOMAINR<n>_EL3
+ */
+ { .name = "ICH_PPI_DVIR0_EL2", .state = ARM_CP_STATE_AA64,
+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 10, .opc2 = 0,
+ .access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .nv2_redirect_offset = 0xb40,
+ .accessfn = access_gicv5_ich_reg,
+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_ppi_dvi[0]),
+ .writefn = gic_ich_ppi_dvi_write,
+ },
+ { .name = "ICH_PPI_DVIR1_EL2", .state = ARM_CP_STATE_AA64,
+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 10, .opc2 = 1,
+ .access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .nv2_redirect_offset = 0xb48,
+ .accessfn = access_gicv5_ich_reg,
+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_ppi_dvi[1]),
+ .writefn = gic_ich_ppi_dvi_write,
+ },
{ .name = "ICH_PPI_ENABLER0_EL2", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 4, .crn = 12, .crm = 10, .opc2 = 2,
.access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* Re: [PATCH v2 07/77] target/arm: GICv5 cpuif: Implement ICH_PPI_DVIR<n>_EL2
2026-12-03 11:10 ` [PATCH v2 07/77] target/arm: GICv5 cpuif: Implement ICH_PPI_DVIR<n>_EL2 Peter Maydell
@ 2026-12-03 11:57 ` Manos Pitsidianakis
2026-12-03 12:14 ` Peter Maydell
0 siblings, 1 reply; 99+ messages in thread
From: Manos Pitsidianakis @ 2026-12-03 11:57 UTC (permalink / raw)
To: Peter Maydell, qemu-arm, qemu-devel
Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
On Thu, 03 Dec 2026 13:10, Peter Maydell <peter.maydell@linaro.org> wrote:
>Implement ICH_PPI_DVIR<n>_EL2, which is the register that controls
>whether pending physical PPIs are directly injected as virtual PPIs
>to the virtual interrupt domain.
>
>Bits in this register are RAZ/WI from EL1 and EL2 if the PPI is
>not assigned to the current interrupt domain, but since we don't
>yet implement EL3 GICv5 support yet all PPIs are always assigned
>to the current interrupt domain.
I doubt you will forget, but maybe just in case you could add read fn
stubs for the RAZ case check to go in when this needs to be implemented.
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
>
>In this commit we just implement the register access to the state;
>actual injection of PPIs will be dealt with later. We give the
>register a writefn because eventually writing to this will need
>to trigger a recalculation of VIRQ/VFIQ.
>
>Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>---
> target/arm/cpu.h | 1 +
> target/arm/tcg/gicv5-cpuif.c | 27 +++++++++++++++++++++++++++
> 2 files changed, 28 insertions(+)
>
>diff --git a/target/arm/cpu.h b/target/arm/cpu.h
>index 3944a2ef104..384c15586eb 100644
>--- a/target/arm/cpu.h
>+++ b/target/arm/cpu.h
>@@ -601,6 +601,7 @@ typedef struct CPUArchState {
> uint64_t ich_ppi_active[GICV5_NUM_PPIS / 64];
> uint64_t ich_ppi_pend[GICV5_NUM_PPIS / 64];
> uint64_t ich_ppi_enable[GICV5_NUM_PPIS / 64];
>+ uint64_t ich_ppi_dvi[GICV5_NUM_PPIS / 64];
> uint64_t ich_ppi_priority[GICV5_NUM_PPIS / 8];
> } gicv5_cpuif;
>
>diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
>index 24065274690..233adc42440 100644
>--- a/target/arm/tcg/gicv5-cpuif.c
>+++ b/target/arm/tcg/gicv5-cpuif.c
>@@ -487,6 +487,12 @@ static void gic_ich_ppi_priority_write(CPUARMState *env, const ARMCPRegInfo *ri,
> raw_write(env, ri, value);
> }
>
>+static void gic_ich_ppi_dvi_write(CPUARMState *env, const ARMCPRegInfo *ri,
>+ uint64_t value)
>+{
>+ raw_write(env, ri, value);
>+}
>+
> /*
> * ICC_APR_EL1 is banked and reads/writes as the version for the
> * current logical interrupt domain.
>@@ -961,6 +967,27 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
> .accessfn = access_gicv5_ich_reg,
> .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_apr_el2),
> },
>+ /*
>+ * Note that DVIR bits RAZ/WI when the PPI isn't assigned to the
>+ * current domain, so we will need to mask them when we implement
>+ * EL3 support and ICC_PPI_DOMAINR<n>_EL3
>+ */
>+ { .name = "ICH_PPI_DVIR0_EL2", .state = ARM_CP_STATE_AA64,
>+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 10, .opc2 = 0,
>+ .access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
>+ .nv2_redirect_offset = 0xb40,
>+ .accessfn = access_gicv5_ich_reg,
>+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_ppi_dvi[0]),
>+ .writefn = gic_ich_ppi_dvi_write,
>+ },
>+ { .name = "ICH_PPI_DVIR1_EL2", .state = ARM_CP_STATE_AA64,
>+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 10, .opc2 = 1,
>+ .access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
>+ .nv2_redirect_offset = 0xb48,
>+ .accessfn = access_gicv5_ich_reg,
>+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_ppi_dvi[1]),
>+ .writefn = gic_ich_ppi_dvi_write,
>+ },
> { .name = "ICH_PPI_ENABLER0_EL2", .state = ARM_CP_STATE_AA64,
> .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 10, .opc2 = 2,
> .access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
>--
>2.43.0
>
^ permalink raw reply [flat|nested] 99+ messages in thread* Re: [PATCH v2 07/77] target/arm: GICv5 cpuif: Implement ICH_PPI_DVIR<n>_EL2
2026-12-03 11:57 ` Manos Pitsidianakis
@ 2026-12-03 12:14 ` Peter Maydell
0 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 12:14 UTC (permalink / raw)
To: Manos Pitsidianakis; +Cc: qemu-arm, qemu-devel, Philippe Mathieu-Daudé
On Thu, 3 Dec 2026 at 12:02, Manos Pitsidianakis
<manos.pitsidianakis@linaro.org> wrote:
>
> On Thu, 03 Dec 2026 13:10, Peter Maydell <peter.maydell@linaro.org> wrote:
> >Implement ICH_PPI_DVIR<n>_EL2, which is the register that controls
> >whether pending physical PPIs are directly injected as virtual PPIs
> >to the virtual interrupt domain.
> >
> >Bits in this register are RAZ/WI from EL1 and EL2 if the PPI is
> >not assigned to the current interrupt domain, but since we don't
> >yet implement EL3 GICv5 support yet all PPIs are always assigned
> >to the current interrupt domain.
>
> I doubt you will forget, but maybe just in case you could add read fn
> stubs for the RAZ case check to go in when this needs to be implemented.
I think the todo comment is sufficient in this case:
> >+ /*
> >+ * Note that DVIR bits RAZ/WI when the PPI isn't assigned to the
> >+ * current domain, so we will need to mask them when we implement
> >+ * EL3 support and ICC_PPI_DOMAINR<n>_EL3
> >+ */
The "bits RAZ/WI for PPIs not assigned to current interrupt domain" will
apply to most of the PPI registers (ICC_PPI_ENABLER*, ICC_PPI_CACTIVER*,
etc, which all have per-PPI bits), so when I implement the EL3
handling I'll fix them all at once.
thanks
-- PMM
^ permalink raw reply [flat|nested] 99+ messages in thread
* [PATCH v2 08/77] target/arm: GICv5 cpuif: Implement ICH_VCTLR_EL2 and ICH_VCMR_EL2
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (6 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 07/77] target/arm: GICv5 cpuif: Implement ICH_PPI_DVIR<n>_EL2 Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 12:02 ` Manos Pitsidianakis
2026-12-03 11:10 ` [PATCH v2 09/77] target/arm: GICv5 cpuif: Implement GIC fine-grained trap registers Peter Maydell
` (68 subsequent siblings)
76 siblings, 1 reply; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Implement the ICH_VCTLR_EL2 and ICH_VMCR_EL2 registers, which hold
hypervisor state for controlling its guest's GICv5 virtual cpu
interface.
We give these write functions and mark them as ARM_CP_IO even though
they currently don't do anything special on write, because later on
we will need changes to fields in these registers to trigger a
recalculation of whether the VIRQ and VFIQ interrupts are signalled.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/cpu.h | 2 ++
target/arm/tcg/gicv5-cpuif.c | 28 ++++++++++++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index 384c15586eb..5e52d552a8a 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -598,6 +598,8 @@ typedef struct CPUArchState {
GICv5PendingIrq ppi_hppi[NUM_GICV5_DOMAINS];
uint64_t ich_apr_el2;
+ uint64_t ich_vctlr_el2;
+ uint64_t ich_vmcr_el2;
uint64_t ich_ppi_active[GICV5_NUM_PPIS / 64];
uint64_t ich_ppi_pend[GICV5_NUM_PPIS / 64];
uint64_t ich_ppi_enable[GICV5_NUM_PPIS / 64];
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 233adc42440..1a89f56b94c 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -493,6 +493,18 @@ static void gic_ich_ppi_dvi_write(CPUARMState *env, const ARMCPRegInfo *ri,
raw_write(env, ri, value);
}
+static void gic_ich_vctlr_write(CPUARMState *env, const ARMCPRegInfo *ri,
+ uint64_t value)
+{
+ raw_write(env, ri, value);
+}
+
+static void gic_ich_vmcr_write(CPUARMState *env, const ARMCPRegInfo *ri,
+ uint64_t value)
+{
+ raw_write(env, ri, value);
+}
+
/*
* ICC_APR_EL1 is banked and reads/writes as the version for the
* current logical interrupt domain.
@@ -1034,6 +1046,22 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_ppi_active[1]),
.writefn = gic_ich_ppi_active_write,
},
+ { .name = "ICH_VCTLR_EL2", .state = ARM_CP_STATE_AA64,
+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 11, .opc2 = 4,
+ .access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .nv2_redirect_offset = 0xb28,
+ .accessfn = access_gicv5_ich_reg,
+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_vctlr_el2),
+ .writefn = gic_ich_vctlr_write,
+ },
+ { .name = "ICH_VMCR_EL2", .state = ARM_CP_STATE_AA64,
+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 11, .opc2 = 7,
+ .access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .nv2_redirect_offset = 0x4c8,
+ .accessfn = access_gicv5_ich_reg,
+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_vmcr_el2),
+ .writefn = gic_ich_vmcr_write,
+ },
};
void define_gicv5_cpuif_regs(ARMCPU *cpu)
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* Re: [PATCH v2 08/77] target/arm: GICv5 cpuif: Implement ICH_VCTLR_EL2 and ICH_VCMR_EL2
2026-12-03 11:10 ` [PATCH v2 08/77] target/arm: GICv5 cpuif: Implement ICH_VCTLR_EL2 and ICH_VCMR_EL2 Peter Maydell
@ 2026-12-03 12:02 ` Manos Pitsidianakis
0 siblings, 0 replies; 99+ messages in thread
From: Manos Pitsidianakis @ 2026-12-03 12:02 UTC (permalink / raw)
To: Peter Maydell, qemu-arm, qemu-devel
Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
On Thu, 03 Dec 2026 13:10, Peter Maydell <peter.maydell@linaro.org> wrote:
>Implement the ICH_VCTLR_EL2 and ICH_VMCR_EL2 registers, which hold
>hypervisor state for controlling its guest's GICv5 virtual cpu
>interface.
>
>We give these write functions and mark them as ARM_CP_IO even though
>they currently don't do anything special on write, because later on
>we will need changes to fields in these registers to trigger a
>recalculation of whether the VIRQ and VFIQ interrupts are signalled.
+ And also toggle legacy operation for FEAT_GCIE_LEGACY in
ICH_VCTLR_EL2.
>
>Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>---
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
> target/arm/cpu.h | 2 ++
> target/arm/tcg/gicv5-cpuif.c | 28 ++++++++++++++++++++++++++++
> 2 files changed, 30 insertions(+)
>
>diff --git a/target/arm/cpu.h b/target/arm/cpu.h
>index 384c15586eb..5e52d552a8a 100644
>--- a/target/arm/cpu.h
>+++ b/target/arm/cpu.h
>@@ -598,6 +598,8 @@ typedef struct CPUArchState {
> GICv5PendingIrq ppi_hppi[NUM_GICV5_DOMAINS];
>
> uint64_t ich_apr_el2;
>+ uint64_t ich_vctlr_el2;
>+ uint64_t ich_vmcr_el2;
> uint64_t ich_ppi_active[GICV5_NUM_PPIS / 64];
> uint64_t ich_ppi_pend[GICV5_NUM_PPIS / 64];
> uint64_t ich_ppi_enable[GICV5_NUM_PPIS / 64];
>diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
>index 233adc42440..1a89f56b94c 100644
>--- a/target/arm/tcg/gicv5-cpuif.c
>+++ b/target/arm/tcg/gicv5-cpuif.c
>@@ -493,6 +493,18 @@ static void gic_ich_ppi_dvi_write(CPUARMState *env, const ARMCPRegInfo *ri,
> raw_write(env, ri, value);
> }
>
>+static void gic_ich_vctlr_write(CPUARMState *env, const ARMCPRegInfo *ri,
>+ uint64_t value)
>+{
>+ raw_write(env, ri, value);
>+}
>+
>+static void gic_ich_vmcr_write(CPUARMState *env, const ARMCPRegInfo *ri,
>+ uint64_t value)
>+{
>+ raw_write(env, ri, value);
>+}
>+
> /*
> * ICC_APR_EL1 is banked and reads/writes as the version for the
> * current logical interrupt domain.
>@@ -1034,6 +1046,22 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
> .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_ppi_active[1]),
> .writefn = gic_ich_ppi_active_write,
> },
>+ { .name = "ICH_VCTLR_EL2", .state = ARM_CP_STATE_AA64,
>+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 11, .opc2 = 4,
>+ .access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
>+ .nv2_redirect_offset = 0xb28,
>+ .accessfn = access_gicv5_ich_reg,
>+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_vctlr_el2),
>+ .writefn = gic_ich_vctlr_write,
>+ },
>+ { .name = "ICH_VMCR_EL2", .state = ARM_CP_STATE_AA64,
>+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 11, .opc2 = 7,
>+ .access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
>+ .nv2_redirect_offset = 0x4c8,
>+ .accessfn = access_gicv5_ich_reg,
>+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_vmcr_el2),
>+ .writefn = gic_ich_vmcr_write,
>+ },
> };
>
> void define_gicv5_cpuif_regs(ARMCPU *cpu)
>--
>2.43.0
>
^ permalink raw reply [flat|nested] 99+ messages in thread
* [PATCH v2 09/77] target/arm: GICv5 cpuif: Implement GIC fine-grained trap registers
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (7 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 08/77] target/arm: GICv5 cpuif: Implement ICH_VCTLR_EL2 and ICH_VCMR_EL2 Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-04 6:01 ` Manos Pitsidianakis
2026-12-03 11:10 ` [PATCH v2 10/77] target/arm: GICv5 cpuif: Mark GIC registers for fine-grained traps Peter Maydell
` (67 subsequent siblings)
76 siblings, 1 reply; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
The GICv5 cpu interface includes a set of fine-grained trap registers
which allow a hypervisor to trap guest accesses to the various GIC
cpu interface registers and instructions. We implement this using
the existing fine-grained-trap mechanism.
This commit provides the definitions of the FGT register bits and the
registers themselves; we will mark up the cpreg definitions with the
fgt trap information in the following commit.
Note that because FGWTE3 has only write-traps and the indexes into
fgt_read[] and fgt_write[] have to line up, we leave a gap in the
fgt_read[] array for the unused slot. We could have moved FGTWE3 to
the end of the array, since the array location isn't encoded in the
migration stream, but that only saves us 8 bytes in the CPU struct
size and leaves the possibility that we forget about the need to
align the read/write indexes next time we add an FGT feature.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/cpregs.h | 85 +++++++++++++++++++++++++++++++++++-
target/arm/cpu.h | 10 +++--
target/arm/tcg/gicv5-cpuif.c | 22 ++++++++++
3 files changed, 111 insertions(+), 6 deletions(-)
diff --git a/target/arm/cpregs.h b/target/arm/cpregs.h
index ce651a4faa6..e46c8c979e1 100644
--- a/target/arm/cpregs.h
+++ b/target/arm/cpregs.h
@@ -389,12 +389,16 @@ typedef enum CPAccessResult {
/* Indexes into fgt_read[] */
#define FGTREG_HFGRTR 0
#define FGTREG_HDFGRTR 1
-/* Indexes into fgt_write[] */
+/* 2 unused: FGWTE3 doesn't have read-traps */
+#define FGTREG_ICH_HFGRTR 3 /* GICv5 */
+/* Indexes into fgt_write[]; these must align with the fgt_read[] ones */
#define FGTREG_HFGWTR 0
#define FGTREG_HDFGWTR 1
#define FGTREG_FGWTE3 2
-/* Indexes into fgt_exec[] */
+#define FGTREG_ICH_HFGWTR 3 /* GICv5 */
+/* Indexes into fgt_exec[] (these don't have to line up with read/write) */
#define FGTREG_HFGITR 0
+#define FGTREG_ICH_HFGITR 1 /* GICv5 */
FIELD(HFGRTR_EL2, AFSR0_EL1, 0, 1)
FIELD(HFGRTR_EL2, AFSR1_EL1, 1, 1)
@@ -720,6 +724,45 @@ FIELD(FGWTE3_EL3, TTBR0_EL3, 20, 1)
FIELD(FGWTE3_EL3, VBAR_EL3, 21, 1)
FIELD(FGWTE3_EL3, GPCBW_EL3, 22, 1)
+/* These are the GICv5 fine-grained trap registers */
+FIELD(ICH_HFGRTR_EL2, ICC_APR_EL1, 0, 1)
+FIELD(ICH_HFGRTR_EL2, ICC_IDRN_EL1, 1, 1)
+FIELD(ICH_HFGRTR_EL2, ICC_CR0_EL1, 2, 1)
+/* Bit 3 is RES1 */
+FIELD(ICH_HFGRTR_EL2, ICC_HPPIR_EL1, 4, 1)
+FIELD(ICH_HFGRTR_EL2, ICC_PCR_EL1, 5, 1)
+FIELD(ICH_HFGRTR_EL2, ICC_ICSR_EL1, 6, 1)
+FIELD(ICH_HFGRTR_EL2, ICC_IAFFIDR_EL1, 7, 1)
+FIELD(ICH_HFGRTR_EL2, ICC_PPI_HMRN_EL1, 16, 1)
+FIELD(ICH_HFGRTR_EL2, ICC_PPI_ENABLERN_EL1, 17, 1)
+FIELD(ICH_HFGRTR_EL2, ICC_PPI_PENDRN_EL1, 18, 1)
+FIELD(ICH_HFGRTR_EL2, ICC_PPI_PRIORITYRN_EL1, 19, 1)
+FIELD(ICH_HFGRTR_EL2, ICC_PPI_ACTIVERN_EL1, 20, 1)
+/* All RES1 bits in this register */
+#define ICH_HFGRTR_EL2_RES1_MASK (1 << 3)
+
+/* Matches ICH_HFGRTR_EL2, but bits for RO regs are RES0 */
+FIELD(ICH_HFGWTR_EL2, ICC_APR_EL1, 0, 1)
+FIELD(ICH_HFGWTR_EL2, ICC_CR0_EL1, 2, 1)
+FIELD(ICH_HFGWTR_EL2, ICC_PCR_EL1, 5, 1)
+FIELD(ICH_HFGWTR_EL2, ICC_ICSR_EL1, 6, 1)
+FIELD(ICH_HFGWTR_EL2, ICC_PPI_ENABLERN_EL1, 17, 1)
+FIELD(ICH_HFGWTR_EL2, ICC_PPI_PENDRN_EL1, 18, 1)
+FIELD(ICH_HFGWTR_EL2, ICC_PPI_PRIORITYRN_EL1, 19, 1)
+FIELD(ICH_HFGWTR_EL2, ICC_PPI_ACTIVERN_EL1, 20, 1)
+
+FIELD(ICH_HFGITR_EL2, GICCDEN, 0, 1);
+FIELD(ICH_HFGITR_EL2, GICCDDIS, 1, 1);
+FIELD(ICH_HFGITR_EL2, GICCDPRI, 2, 1);
+FIELD(ICH_HFGITR_EL2, GICCDAFF, 3, 1);
+FIELD(ICH_HFGITR_EL2, GICCDPEND, 4, 1);
+FIELD(ICH_HFGITR_EL2, GICCDRCFG, 5, 1);
+FIELD(ICH_HFGITR_EL2, GICCDHM, 6, 1);
+FIELD(ICH_HFGITR_EL2, GICCDEOI, 7, 1);
+FIELD(ICH_HFGITR_EL2, GICCDDI, 8, 1);
+FIELD(ICH_HFGITR_EL2, GICRCDIA, 9, 1);
+FIELD(ICH_HFGITR_EL2, GICRCDNMIA, 10, 1);
+
FIELD(FGT, NXS, 13, 1) /* Honour HCR_EL2.FGTnXS to suppress FGT */
/* Which fine-grained trap bit register to check, if any */
FIELD(FGT, TYPE, 10, 3)
@@ -798,6 +841,9 @@ typedef enum FGTBit {
FGT_HDFGWTR = FGT_W | (FGTREG_HDFGWTR << R_FGT_IDX_SHIFT),
FGT_HFGITR = FGT_EXEC | (FGTREG_HFGITR << R_FGT_IDX_SHIFT),
FGT_FGWTE3 = FGT_W | (FGTREG_FGWTE3 << R_FGT_IDX_SHIFT),
+ FGT_ICH_HFGRTR = FGT_RW | (FGTREG_ICH_HFGRTR << R_FGT_IDX_SHIFT),
+ FGT_ICH_HFGWTR = FGT_W | (FGTREG_ICH_HFGWTR << R_FGT_IDX_SHIFT),
+ FGT_ICH_HFGITR = FGT_EXEC | (FGTREG_ICH_HFGITR << R_FGT_IDX_SHIFT),
/* Trap bits in HFGRTR_EL2 / HFGWTR_EL2, starting from bit 0. */
DO_BIT(HFGRTR, AFSR0_EL1),
@@ -955,6 +1001,41 @@ typedef enum FGTBit {
DO_EL3_BIT(FGWTE3, TTBR0_EL3),
DO_EL3_BIT(FGWTE3, VBAR_EL3),
DO_EL3_BIT(FGWTE3, GPCBW_EL3),
+
+ /*
+ * Trap bits in ICH_HFGRTR_EL2 / ICH_HFGWTR_EL2, starting from bit 0.
+ * These are all "trap on 0, don't trap on 1" and don't follow the
+ * "name starts with 'n' if sense is reversed" convention of the
+ * main FEAT_FGT registers.
+ */
+ DO_REV_BIT(ICH_HFGRTR, ICC_APR_EL1),
+ DO_REV_BIT(ICH_HFGRTR, ICC_IDRN_EL1),
+ DO_REV_BIT(ICH_HFGRTR, ICC_CR0_EL1),
+ DO_REV_BIT(ICH_HFGRTR, ICC_HPPIR_EL1),
+ DO_REV_BIT(ICH_HFGRTR, ICC_PCR_EL1),
+ DO_REV_BIT(ICH_HFGRTR, ICC_ICSR_EL1),
+ DO_REV_BIT(ICH_HFGRTR, ICC_IAFFIDR_EL1),
+ DO_REV_BIT(ICH_HFGRTR, ICC_PPI_HMRN_EL1),
+ DO_REV_BIT(ICH_HFGRTR, ICC_PPI_ENABLERN_EL1),
+ DO_REV_BIT(ICH_HFGRTR, ICC_PPI_PENDRN_EL1),
+ DO_REV_BIT(ICH_HFGRTR, ICC_PPI_PRIORITYRN_EL1),
+ DO_REV_BIT(ICH_HFGRTR, ICC_PPI_ACTIVERN_EL1),
+
+ /*
+ * Trap bits in ICH_HFGITR_EL2, starting from bit 0. These also
+ * are all "trap on 0".
+ */
+ DO_REV_BIT(ICH_HFGITR, GICCDEN),
+ DO_REV_BIT(ICH_HFGITR, GICCDDIS),
+ DO_REV_BIT(ICH_HFGITR, GICCDPRI),
+ DO_REV_BIT(ICH_HFGITR, GICCDAFF),
+ DO_REV_BIT(ICH_HFGITR, GICCDPEND),
+ DO_REV_BIT(ICH_HFGITR, GICCDRCFG),
+ DO_REV_BIT(ICH_HFGITR, GICCDHM),
+ DO_REV_BIT(ICH_HFGITR, GICCDEOI),
+ DO_REV_BIT(ICH_HFGITR, GICCDDI),
+ DO_REV_BIT(ICH_HFGITR, GICRCDIA),
+ DO_REV_BIT(ICH_HFGITR, GICRCDNMIA),
} FGTBit;
#undef DO_BIT
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index 5e52d552a8a..6db66c67362 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -552,11 +552,13 @@ typedef struct CPUArchState {
* Fine-Grained Trap registers. We store these as arrays so the
* access checking code doesn't have to manually select
* HFGRTR_EL2 vs HFDFGRTR_EL2 etc when looking up the bit to test.
- * FEAT_FGT2 will add more elements to these arrays.
+ * These include the trap registers for all features which have
+ * FGT-style trapping: FEAT_FGT, FEAT_FGWTE3. GICv5, and (when we
+ * implement it) FEAT_FGT2.
*/
- uint64_t fgt_read[2]; /* HFGRTR, HDFGRTR */
- uint64_t fgt_write[3]; /* HFGWTR, HDFGWTR, FGWTE3 */
- uint64_t fgt_exec[1]; /* HFGITR */
+ uint64_t fgt_read[4]; /* HFGRTR, HDFGRTR, unused, ICH_HFGRTR */
+ uint64_t fgt_write[4]; /* HFGWTR, HDFGWTR, FGWTE3, ICH_HFGWTR */
+ uint64_t fgt_exec[2]; /* HFGITR, ICH_HFGITR */
/* RME registers */
uint64_t gpccr_el3;
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 1a89f56b94c..7ce3a2cc49a 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -979,6 +979,28 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
.accessfn = access_gicv5_ich_reg,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_apr_el2),
},
+ { .name = "ICH_HFGRTR_EL2", .state = ARM_CP_STATE_AA64,
+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 9, .opc2 = 4,
+ .access = PL2_RW, .type = ARM_CP_NO_RAW,
+ .nv2_redirect_offset = 0xb10,
+ .accessfn = access_gicv5_ich_reg,
+ .fieldoffset = offsetof(CPUARMState, cp15.fgt_read[FGTREG_ICH_HFGRTR]),
+ .resetvalue = ICH_HFGRTR_EL2_RES1_MASK,
+ },
+ { .name = "ICH_HFGWTR_EL2", .state = ARM_CP_STATE_AA64,
+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 9, .opc2 = 6,
+ .access = PL2_RW, .type = ARM_CP_NO_RAW,
+ .nv2_redirect_offset = 0xb10,
+ .accessfn = access_gicv5_ich_reg,
+ .fieldoffset = offsetof(CPUARMState, cp15.fgt_write[FGTREG_ICH_HFGWTR]),
+ },
+ { .name = "ICH_HFGITR_EL2", .state = ARM_CP_STATE_AA64,
+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 9, .opc2 = 7,
+ .access = PL2_RW, .type = ARM_CP_NO_RAW,
+ .nv2_redirect_offset = 0xb10,
+ .accessfn = access_gicv5_ich_reg,
+ .fieldoffset = offsetof(CPUARMState, cp15.fgt_exec[FGTREG_ICH_HFGITR]),
+ },
/*
* Note that DVIR bits RAZ/WI when the PPI isn't assigned to the
* current domain, so we will need to mask them when we implement
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* Re: [PATCH v2 09/77] target/arm: GICv5 cpuif: Implement GIC fine-grained trap registers
2026-12-03 11:10 ` [PATCH v2 09/77] target/arm: GICv5 cpuif: Implement GIC fine-grained trap registers Peter Maydell
@ 2026-12-04 6:01 ` Manos Pitsidianakis
0 siblings, 0 replies; 99+ messages in thread
From: Manos Pitsidianakis @ 2026-12-04 6:01 UTC (permalink / raw)
To: Peter Maydell, qemu-arm, qemu-devel
Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
On Thu, 03 Dec 2026 13:10, Peter Maydell <peter.maydell@linaro.org> wrote:
>The GICv5 cpu interface includes a set of fine-grained trap registers
>which allow a hypervisor to trap guest accesses to the various GIC
>cpu interface registers and instructions. We implement this using
>the existing fine-grained-trap mechanism.
>
>This commit provides the definitions of the FGT register bits and the
>registers themselves; we will mark up the cpreg definitions with the
>fgt trap information in the following commit.
>
>Note that because FGWTE3 has only write-traps and the indexes into
>fgt_read[] and fgt_write[] have to line up, we leave a gap in the
>fgt_read[] array for the unused slot. We could have moved FGTWE3 to
>the end of the array, since the array location isn't encoded in the
>migration stream, but that only saves us 8 bytes in the CPU struct
>size and leaves the possibility that we forget about the need to
>align the read/write indexes next time we add an FGT feature.
>
>Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>---
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
> target/arm/cpregs.h | 85 +++++++++++++++++++++++++++++++++++-
> target/arm/cpu.h | 10 +++--
> target/arm/tcg/gicv5-cpuif.c | 22 ++++++++++
> 3 files changed, 111 insertions(+), 6 deletions(-)
>
>diff --git a/target/arm/cpregs.h b/target/arm/cpregs.h
>index ce651a4faa6..e46c8c979e1 100644
>--- a/target/arm/cpregs.h
>+++ b/target/arm/cpregs.h
>@@ -389,12 +389,16 @@ typedef enum CPAccessResult {
> /* Indexes into fgt_read[] */
> #define FGTREG_HFGRTR 0
> #define FGTREG_HDFGRTR 1
>-/* Indexes into fgt_write[] */
>+/* 2 unused: FGWTE3 doesn't have read-traps */
>+#define FGTREG_ICH_HFGRTR 3 /* GICv5 */
>+/* Indexes into fgt_write[]; these must align with the fgt_read[] ones */
> #define FGTREG_HFGWTR 0
> #define FGTREG_HDFGWTR 1
> #define FGTREG_FGWTE3 2
>-/* Indexes into fgt_exec[] */
>+#define FGTREG_ICH_HFGWTR 3 /* GICv5 */
>+/* Indexes into fgt_exec[] (these don't have to line up with read/write) */
> #define FGTREG_HFGITR 0
>+#define FGTREG_ICH_HFGITR 1 /* GICv5 */
>
> FIELD(HFGRTR_EL2, AFSR0_EL1, 0, 1)
> FIELD(HFGRTR_EL2, AFSR1_EL1, 1, 1)
>@@ -720,6 +724,45 @@ FIELD(FGWTE3_EL3, TTBR0_EL3, 20, 1)
> FIELD(FGWTE3_EL3, VBAR_EL3, 21, 1)
> FIELD(FGWTE3_EL3, GPCBW_EL3, 22, 1)
>
>+/* These are the GICv5 fine-grained trap registers */
>+FIELD(ICH_HFGRTR_EL2, ICC_APR_EL1, 0, 1)
>+FIELD(ICH_HFGRTR_EL2, ICC_IDRN_EL1, 1, 1)
>+FIELD(ICH_HFGRTR_EL2, ICC_CR0_EL1, 2, 1)
>+/* Bit 3 is RES1 */
>+FIELD(ICH_HFGRTR_EL2, ICC_HPPIR_EL1, 4, 1)
>+FIELD(ICH_HFGRTR_EL2, ICC_PCR_EL1, 5, 1)
>+FIELD(ICH_HFGRTR_EL2, ICC_ICSR_EL1, 6, 1)
>+FIELD(ICH_HFGRTR_EL2, ICC_IAFFIDR_EL1, 7, 1)
>+FIELD(ICH_HFGRTR_EL2, ICC_PPI_HMRN_EL1, 16, 1)
>+FIELD(ICH_HFGRTR_EL2, ICC_PPI_ENABLERN_EL1, 17, 1)
>+FIELD(ICH_HFGRTR_EL2, ICC_PPI_PENDRN_EL1, 18, 1)
>+FIELD(ICH_HFGRTR_EL2, ICC_PPI_PRIORITYRN_EL1, 19, 1)
>+FIELD(ICH_HFGRTR_EL2, ICC_PPI_ACTIVERN_EL1, 20, 1)
>+/* All RES1 bits in this register */
>+#define ICH_HFGRTR_EL2_RES1_MASK (1 << 3)
>+
>+/* Matches ICH_HFGRTR_EL2, but bits for RO regs are RES0 */
>+FIELD(ICH_HFGWTR_EL2, ICC_APR_EL1, 0, 1)
>+FIELD(ICH_HFGWTR_EL2, ICC_CR0_EL1, 2, 1)
>+FIELD(ICH_HFGWTR_EL2, ICC_PCR_EL1, 5, 1)
>+FIELD(ICH_HFGWTR_EL2, ICC_ICSR_EL1, 6, 1)
>+FIELD(ICH_HFGWTR_EL2, ICC_PPI_ENABLERN_EL1, 17, 1)
>+FIELD(ICH_HFGWTR_EL2, ICC_PPI_PENDRN_EL1, 18, 1)
>+FIELD(ICH_HFGWTR_EL2, ICC_PPI_PRIORITYRN_EL1, 19, 1)
>+FIELD(ICH_HFGWTR_EL2, ICC_PPI_ACTIVERN_EL1, 20, 1)
>+
>+FIELD(ICH_HFGITR_EL2, GICCDEN, 0, 1);
>+FIELD(ICH_HFGITR_EL2, GICCDDIS, 1, 1);
>+FIELD(ICH_HFGITR_EL2, GICCDPRI, 2, 1);
>+FIELD(ICH_HFGITR_EL2, GICCDAFF, 3, 1);
>+FIELD(ICH_HFGITR_EL2, GICCDPEND, 4, 1);
>+FIELD(ICH_HFGITR_EL2, GICCDRCFG, 5, 1);
>+FIELD(ICH_HFGITR_EL2, GICCDHM, 6, 1);
>+FIELD(ICH_HFGITR_EL2, GICCDEOI, 7, 1);
>+FIELD(ICH_HFGITR_EL2, GICCDDI, 8, 1);
>+FIELD(ICH_HFGITR_EL2, GICRCDIA, 9, 1);
>+FIELD(ICH_HFGITR_EL2, GICRCDNMIA, 10, 1);
>+
> FIELD(FGT, NXS, 13, 1) /* Honour HCR_EL2.FGTnXS to suppress FGT */
> /* Which fine-grained trap bit register to check, if any */
> FIELD(FGT, TYPE, 10, 3)
>@@ -798,6 +841,9 @@ typedef enum FGTBit {
> FGT_HDFGWTR = FGT_W | (FGTREG_HDFGWTR << R_FGT_IDX_SHIFT),
> FGT_HFGITR = FGT_EXEC | (FGTREG_HFGITR << R_FGT_IDX_SHIFT),
> FGT_FGWTE3 = FGT_W | (FGTREG_FGWTE3 << R_FGT_IDX_SHIFT),
>+ FGT_ICH_HFGRTR = FGT_RW | (FGTREG_ICH_HFGRTR << R_FGT_IDX_SHIFT),
>+ FGT_ICH_HFGWTR = FGT_W | (FGTREG_ICH_HFGWTR << R_FGT_IDX_SHIFT),
>+ FGT_ICH_HFGITR = FGT_EXEC | (FGTREG_ICH_HFGITR << R_FGT_IDX_SHIFT),
>
> /* Trap bits in HFGRTR_EL2 / HFGWTR_EL2, starting from bit 0. */
> DO_BIT(HFGRTR, AFSR0_EL1),
>@@ -955,6 +1001,41 @@ typedef enum FGTBit {
> DO_EL3_BIT(FGWTE3, TTBR0_EL3),
> DO_EL3_BIT(FGWTE3, VBAR_EL3),
> DO_EL3_BIT(FGWTE3, GPCBW_EL3),
>+
>+ /*
>+ * Trap bits in ICH_HFGRTR_EL2 / ICH_HFGWTR_EL2, starting from bit 0.
>+ * These are all "trap on 0, don't trap on 1" and don't follow the
>+ * "name starts with 'n' if sense is reversed" convention of the
>+ * main FEAT_FGT registers.
>+ */
>+ DO_REV_BIT(ICH_HFGRTR, ICC_APR_EL1),
>+ DO_REV_BIT(ICH_HFGRTR, ICC_IDRN_EL1),
>+ DO_REV_BIT(ICH_HFGRTR, ICC_CR0_EL1),
>+ DO_REV_BIT(ICH_HFGRTR, ICC_HPPIR_EL1),
>+ DO_REV_BIT(ICH_HFGRTR, ICC_PCR_EL1),
>+ DO_REV_BIT(ICH_HFGRTR, ICC_ICSR_EL1),
>+ DO_REV_BIT(ICH_HFGRTR, ICC_IAFFIDR_EL1),
>+ DO_REV_BIT(ICH_HFGRTR, ICC_PPI_HMRN_EL1),
>+ DO_REV_BIT(ICH_HFGRTR, ICC_PPI_ENABLERN_EL1),
>+ DO_REV_BIT(ICH_HFGRTR, ICC_PPI_PENDRN_EL1),
>+ DO_REV_BIT(ICH_HFGRTR, ICC_PPI_PRIORITYRN_EL1),
>+ DO_REV_BIT(ICH_HFGRTR, ICC_PPI_ACTIVERN_EL1),
>+
>+ /*
>+ * Trap bits in ICH_HFGITR_EL2, starting from bit 0. These also
>+ * are all "trap on 0".
>+ */
>+ DO_REV_BIT(ICH_HFGITR, GICCDEN),
>+ DO_REV_BIT(ICH_HFGITR, GICCDDIS),
>+ DO_REV_BIT(ICH_HFGITR, GICCDPRI),
>+ DO_REV_BIT(ICH_HFGITR, GICCDAFF),
>+ DO_REV_BIT(ICH_HFGITR, GICCDPEND),
>+ DO_REV_BIT(ICH_HFGITR, GICCDRCFG),
>+ DO_REV_BIT(ICH_HFGITR, GICCDHM),
>+ DO_REV_BIT(ICH_HFGITR, GICCDEOI),
>+ DO_REV_BIT(ICH_HFGITR, GICCDDI),
>+ DO_REV_BIT(ICH_HFGITR, GICRCDIA),
>+ DO_REV_BIT(ICH_HFGITR, GICRCDNMIA),
> } FGTBit;
>
> #undef DO_BIT
>diff --git a/target/arm/cpu.h b/target/arm/cpu.h
>index 5e52d552a8a..6db66c67362 100644
>--- a/target/arm/cpu.h
>+++ b/target/arm/cpu.h
>@@ -552,11 +552,13 @@ typedef struct CPUArchState {
> * Fine-Grained Trap registers. We store these as arrays so the
> * access checking code doesn't have to manually select
> * HFGRTR_EL2 vs HFDFGRTR_EL2 etc when looking up the bit to test.
>- * FEAT_FGT2 will add more elements to these arrays.
>+ * These include the trap registers for all features which have
>+ * FGT-style trapping: FEAT_FGT, FEAT_FGWTE3. GICv5, and (when we
>+ * implement it) FEAT_FGT2.
> */
>- uint64_t fgt_read[2]; /* HFGRTR, HDFGRTR */
>- uint64_t fgt_write[3]; /* HFGWTR, HDFGWTR, FGWTE3 */
>- uint64_t fgt_exec[1]; /* HFGITR */
>+ uint64_t fgt_read[4]; /* HFGRTR, HDFGRTR, unused, ICH_HFGRTR */
>+ uint64_t fgt_write[4]; /* HFGWTR, HDFGWTR, FGWTE3, ICH_HFGWTR */
>+ uint64_t fgt_exec[2]; /* HFGITR, ICH_HFGITR */
>
> /* RME registers */
> uint64_t gpccr_el3;
>diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
>index 1a89f56b94c..7ce3a2cc49a 100644
>--- a/target/arm/tcg/gicv5-cpuif.c
>+++ b/target/arm/tcg/gicv5-cpuif.c
>@@ -979,6 +979,28 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
> .accessfn = access_gicv5_ich_reg,
> .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_apr_el2),
> },
>+ { .name = "ICH_HFGRTR_EL2", .state = ARM_CP_STATE_AA64,
>+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 9, .opc2 = 4,
>+ .access = PL2_RW, .type = ARM_CP_NO_RAW,
>+ .nv2_redirect_offset = 0xb10,
>+ .accessfn = access_gicv5_ich_reg,
>+ .fieldoffset = offsetof(CPUARMState, cp15.fgt_read[FGTREG_ICH_HFGRTR]),
>+ .resetvalue = ICH_HFGRTR_EL2_RES1_MASK,
>+ },
>+ { .name = "ICH_HFGWTR_EL2", .state = ARM_CP_STATE_AA64,
>+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 9, .opc2 = 6,
>+ .access = PL2_RW, .type = ARM_CP_NO_RAW,
>+ .nv2_redirect_offset = 0xb10,
>+ .accessfn = access_gicv5_ich_reg,
>+ .fieldoffset = offsetof(CPUARMState, cp15.fgt_write[FGTREG_ICH_HFGWTR]),
>+ },
>+ { .name = "ICH_HFGITR_EL2", .state = ARM_CP_STATE_AA64,
>+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 9, .opc2 = 7,
>+ .access = PL2_RW, .type = ARM_CP_NO_RAW,
>+ .nv2_redirect_offset = 0xb10,
>+ .accessfn = access_gicv5_ich_reg,
>+ .fieldoffset = offsetof(CPUARMState, cp15.fgt_exec[FGTREG_ICH_HFGITR]),
>+ },
> /*
> * Note that DVIR bits RAZ/WI when the PPI isn't assigned to the
> * current domain, so we will need to mask them when we implement
>--
>2.43.0
>
^ permalink raw reply [flat|nested] 99+ messages in thread
* [PATCH v2 10/77] target/arm: GICv5 cpuif: Mark GIC registers for fine-grained traps
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (8 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 09/77] target/arm: GICv5 cpuif: Implement GIC fine-grained trap registers Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-04 6:08 ` Manos Pitsidianakis
2026-12-03 11:10 ` [PATCH v2 11/77] target/arm: GICv5 cpuif: Mark GIC insns " Peter Maydell
` (66 subsequent siblings)
76 siblings, 1 reply; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Annotate the GICv5 cpuif register cpreg structs with the
fine-grained trap information. This covers all the bits in
ICH_HFGRTR_EL2 and ICH_HFGWTR_EL2.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/tcg/gicv5-cpuif.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 7ce3a2cc49a..b636a8fa6b9 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -855,17 +855,20 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
{ .name = "ICC_IDR0_EL1", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 0, .crn = 12, .crm = 10, .opc2 = 2,
.access = PL1_R, .type = ARM_CP_CONST | ARM_CP_NO_RAW,
+ .fgt = FGT_ICC_IDRN_EL1,
.resetvalue = QEMU_ICC_IDR0,
},
{ .name = "ICC_ICSR_EL1", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 0, .crn = 12, .crm = 10, .opc2 = 4,
.access = PL1_RW, .type = ARM_CP_NO_RAW,
+ .fgt = FGT_ICC_ICSR_EL1,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.icc_icsr_el1),
.resetvalue = 0,
},
{ .name = "ICC_IAFFIDR_EL1", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 0, .crn = 12, .crm = 10, .opc2 = 5,
.access = PL1_R, .type = ARM_CP_NO_RAW,
+ .fgt = FGT_ICC_IAFFIDR_EL1,
/* ICC_IAFFIDR_EL1 holds the IAFFID only, in its low bits */
.fieldoffset = offsetof(CPUARMState, gicv5.iaffid),
/*
@@ -877,83 +880,97 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
{ .name = "ICC_PPI_CACTIVER0_EL1", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 0, .crn = 12, .crm = 13, .opc2 = 0,
.access = PL1_RW, .type = ARM_CP_ALIAS | ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_ICC_PPI_ACTIVERN_EL1,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_active[0]),
.writefn = gic_ppi_cactive_write,
},
{ .name = "ICC_PPI_CACTIVER1_EL1", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 0, .crn = 12, .crm = 13, .opc2 = 1,
.access = PL1_RW, .type = ARM_CP_ALIAS | ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_ICC_PPI_ACTIVERN_EL1,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_active[1]),
.writefn = gic_ppi_cactive_write,
},
{ .name = "ICC_PPI_SACTIVER0_EL1", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 0, .crn = 12, .crm = 13, .opc2 = 2,
.access = PL1_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_ICC_PPI_ACTIVERN_EL1,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_active[0]),
.writefn = gic_ppi_sactive_write,
},
{ .name = "ICC_PPI_SACTIVER1_EL1", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 0, .crn = 12, .crm = 13, .opc2 = 3,
.access = PL1_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_ICC_PPI_ACTIVERN_EL1,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_active[1]),
.writefn = gic_ppi_sactive_write,
},
{ .name = "ICC_PPI_HMR0_EL1", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 0, .crn = 12, .crm = 10, .opc2 = 0,
.access = PL1_R, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_ICC_PPI_HMRN_EL1,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_hm[0]),
.resetvalue = PPI_HMR0_RESET,
},
{ .name = "ICC_PPI_HMR1_EL1", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 0, .crn = 12, .crm = 10, .opc2 = 1,
.access = PL1_R, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_ICC_PPI_HMRN_EL1,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_hm[1]),
.resetvalue = PPI_HMR1_RESET,
},
{ .name = "ICC_HPPIR_EL1", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 0, .crn = 12, .crm = 10, .opc2 = 3,
.access = PL1_R, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_ICC_HPPIR_EL1,
.readfn = gic_icc_hppir_el1_read,
},
{ .name = "ICC_PPI_ENABLER0_EL1", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 0, .crn = 12, .crm = 10, .opc2 = 6,
.access = PL1_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_ICC_PPI_ENABLERN_EL1,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_enable[0]),
.writefn = gic_ppi_enable_write,
},
{ .name = "ICC_PPI_ENABLER1_EL1", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 0, .crn = 12, .crm = 10, .opc2 = 7,
.access = PL1_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_ICC_PPI_ENABLERN_EL1,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_enable[1]),
.writefn = gic_ppi_enable_write,
},
{ .name = "ICC_PPI_CPENDR0_EL1", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 0, .crn = 12, .crm = 13, .opc2 = 4,
.access = PL1_RW, .type = ARM_CP_ALIAS | ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_ICC_PPI_PENDRN_EL1,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_pend[0]),
.writefn = gic_ppi_cpend_write,
},
{ .name = "ICC_PPI_CPENDR1_EL1", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 0, .crn = 12, .crm = 13, .opc2 = 5,
.access = PL1_RW, .type = ARM_CP_ALIAS | ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_ICC_PPI_PENDRN_EL1,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_pend[1]),
.writefn = gic_ppi_cpend_write,
},
{ .name = "ICC_PPI_SPENDR0_EL1", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 0, .crn = 12, .crm = 13, .opc2 = 6,
.access = PL1_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_ICC_PPI_PENDRN_EL1,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_pend[0]),
.writefn = gic_ppi_spend_write,
},
{ .name = "ICC_PPI_SPENDR1_EL1", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 0, .crn = 12, .crm = 13, .opc2 = 7,
.access = PL1_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_ICC_PPI_PENDRN_EL1,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_pend[1]),
.writefn = gic_ppi_spend_write,
},
{ .name = "ICC_APR_EL1", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 1, .crn = 12, .crm = 0, .opc2 = 0,
.access = PL1_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_ICC_APR_EL1,
.readfn = gic_icc_apr_el1_read,
.writefn = gic_icc_apr_el1_write,
.resetfn = gic_icc_apr_el1_reset,
@@ -961,6 +978,7 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
{ .name = "ICC_CR0_EL1", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 1, .crn = 12, .crm = 0, .opc2 = 1,
.access = PL1_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_ICC_CR0_EL1,
.readfn = gic_icc_cr0_el1_read,
.writefn = gic_icc_cr0_el1_write,
.resetfn = gic_icc_cr0_el1_reset,
@@ -968,6 +986,7 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
{ .name = "ICC_PCR_EL1", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 1, .crn = 12, .crm = 0, .opc2 = 2,
.access = PL1_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_ICC_PCR_EL1,
.readfn = gic_icc_pcr_el1_read,
.writefn = gic_icc_pcr_el1_write,
.resetfn = gic_icc_pcr_el1_reset,
@@ -1102,6 +1121,7 @@ void define_gicv5_cpuif_regs(ARMCPU *cpu)
.opc0 = 3, .opc1 = 0, .crn = 12,
.crm = 14 + (i >> 3), .opc2 = i & 7,
.access = PL1_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_ICC_PPI_PRIORITYRN_EL1,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_priority[i]),
.writefn = gic_ppi_priority_write, .raw_writefn = raw_write,
};
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* Re: [PATCH v2 10/77] target/arm: GICv5 cpuif: Mark GIC registers for fine-grained traps
2026-12-03 11:10 ` [PATCH v2 10/77] target/arm: GICv5 cpuif: Mark GIC registers for fine-grained traps Peter Maydell
@ 2026-12-04 6:08 ` Manos Pitsidianakis
0 siblings, 0 replies; 99+ messages in thread
From: Manos Pitsidianakis @ 2026-12-04 6:08 UTC (permalink / raw)
To: Peter Maydell, qemu-arm, qemu-devel
Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
On Thu, 03 Dec 2026 13:10, Peter Maydell <peter.maydell@linaro.org> wrote:
>Annotate the GICv5 cpuif register cpreg structs with the
>fine-grained trap information. This covers all the bits in
>ICH_HFGRTR_EL2 and ICH_HFGWTR_EL2.
>
>Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>---
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
> target/arm/tcg/gicv5-cpuif.c | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
>diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
>index 7ce3a2cc49a..b636a8fa6b9 100644
>--- a/target/arm/tcg/gicv5-cpuif.c
>+++ b/target/arm/tcg/gicv5-cpuif.c
>@@ -855,17 +855,20 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
> { .name = "ICC_IDR0_EL1", .state = ARM_CP_STATE_AA64,
> .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 10, .opc2 = 2,
> .access = PL1_R, .type = ARM_CP_CONST | ARM_CP_NO_RAW,
>+ .fgt = FGT_ICC_IDRN_EL1,
> .resetvalue = QEMU_ICC_IDR0,
> },
> { .name = "ICC_ICSR_EL1", .state = ARM_CP_STATE_AA64,
> .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 10, .opc2 = 4,
> .access = PL1_RW, .type = ARM_CP_NO_RAW,
>+ .fgt = FGT_ICC_ICSR_EL1,
> .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.icc_icsr_el1),
> .resetvalue = 0,
> },
> { .name = "ICC_IAFFIDR_EL1", .state = ARM_CP_STATE_AA64,
> .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 10, .opc2 = 5,
> .access = PL1_R, .type = ARM_CP_NO_RAW,
>+ .fgt = FGT_ICC_IAFFIDR_EL1,
> /* ICC_IAFFIDR_EL1 holds the IAFFID only, in its low bits */
> .fieldoffset = offsetof(CPUARMState, gicv5.iaffid),
> /*
>@@ -877,83 +880,97 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
> { .name = "ICC_PPI_CACTIVER0_EL1", .state = ARM_CP_STATE_AA64,
> .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 13, .opc2 = 0,
> .access = PL1_RW, .type = ARM_CP_ALIAS | ARM_CP_IO | ARM_CP_NO_RAW,
>+ .fgt = FGT_ICC_PPI_ACTIVERN_EL1,
> .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_active[0]),
> .writefn = gic_ppi_cactive_write,
> },
> { .name = "ICC_PPI_CACTIVER1_EL1", .state = ARM_CP_STATE_AA64,
> .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 13, .opc2 = 1,
> .access = PL1_RW, .type = ARM_CP_ALIAS | ARM_CP_IO | ARM_CP_NO_RAW,
>+ .fgt = FGT_ICC_PPI_ACTIVERN_EL1,
> .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_active[1]),
> .writefn = gic_ppi_cactive_write,
> },
> { .name = "ICC_PPI_SACTIVER0_EL1", .state = ARM_CP_STATE_AA64,
> .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 13, .opc2 = 2,
> .access = PL1_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
>+ .fgt = FGT_ICC_PPI_ACTIVERN_EL1,
> .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_active[0]),
> .writefn = gic_ppi_sactive_write,
> },
> { .name = "ICC_PPI_SACTIVER1_EL1", .state = ARM_CP_STATE_AA64,
> .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 13, .opc2 = 3,
> .access = PL1_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
>+ .fgt = FGT_ICC_PPI_ACTIVERN_EL1,
> .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_active[1]),
> .writefn = gic_ppi_sactive_write,
> },
> { .name = "ICC_PPI_HMR0_EL1", .state = ARM_CP_STATE_AA64,
> .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 10, .opc2 = 0,
> .access = PL1_R, .type = ARM_CP_IO | ARM_CP_NO_RAW,
>+ .fgt = FGT_ICC_PPI_HMRN_EL1,
> .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_hm[0]),
> .resetvalue = PPI_HMR0_RESET,
> },
> { .name = "ICC_PPI_HMR1_EL1", .state = ARM_CP_STATE_AA64,
> .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 10, .opc2 = 1,
> .access = PL1_R, .type = ARM_CP_IO | ARM_CP_NO_RAW,
>+ .fgt = FGT_ICC_PPI_HMRN_EL1,
> .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_hm[1]),
> .resetvalue = PPI_HMR1_RESET,
> },
> { .name = "ICC_HPPIR_EL1", .state = ARM_CP_STATE_AA64,
> .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 10, .opc2 = 3,
> .access = PL1_R, .type = ARM_CP_IO | ARM_CP_NO_RAW,
>+ .fgt = FGT_ICC_HPPIR_EL1,
> .readfn = gic_icc_hppir_el1_read,
> },
> { .name = "ICC_PPI_ENABLER0_EL1", .state = ARM_CP_STATE_AA64,
> .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 10, .opc2 = 6,
> .access = PL1_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
>+ .fgt = FGT_ICC_PPI_ENABLERN_EL1,
> .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_enable[0]),
> .writefn = gic_ppi_enable_write,
> },
> { .name = "ICC_PPI_ENABLER1_EL1", .state = ARM_CP_STATE_AA64,
> .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 10, .opc2 = 7,
> .access = PL1_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
>+ .fgt = FGT_ICC_PPI_ENABLERN_EL1,
> .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_enable[1]),
> .writefn = gic_ppi_enable_write,
> },
> { .name = "ICC_PPI_CPENDR0_EL1", .state = ARM_CP_STATE_AA64,
> .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 13, .opc2 = 4,
> .access = PL1_RW, .type = ARM_CP_ALIAS | ARM_CP_IO | ARM_CP_NO_RAW,
>+ .fgt = FGT_ICC_PPI_PENDRN_EL1,
> .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_pend[0]),
> .writefn = gic_ppi_cpend_write,
> },
> { .name = "ICC_PPI_CPENDR1_EL1", .state = ARM_CP_STATE_AA64,
> .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 13, .opc2 = 5,
> .access = PL1_RW, .type = ARM_CP_ALIAS | ARM_CP_IO | ARM_CP_NO_RAW,
>+ .fgt = FGT_ICC_PPI_PENDRN_EL1,
> .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_pend[1]),
> .writefn = gic_ppi_cpend_write,
> },
> { .name = "ICC_PPI_SPENDR0_EL1", .state = ARM_CP_STATE_AA64,
> .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 13, .opc2 = 6,
> .access = PL1_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
>+ .fgt = FGT_ICC_PPI_PENDRN_EL1,
> .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_pend[0]),
> .writefn = gic_ppi_spend_write,
> },
> { .name = "ICC_PPI_SPENDR1_EL1", .state = ARM_CP_STATE_AA64,
> .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 13, .opc2 = 7,
> .access = PL1_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
>+ .fgt = FGT_ICC_PPI_PENDRN_EL1,
> .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_pend[1]),
> .writefn = gic_ppi_spend_write,
> },
> { .name = "ICC_APR_EL1", .state = ARM_CP_STATE_AA64,
> .opc0 = 3, .opc1 = 1, .crn = 12, .crm = 0, .opc2 = 0,
> .access = PL1_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
>+ .fgt = FGT_ICC_APR_EL1,
> .readfn = gic_icc_apr_el1_read,
> .writefn = gic_icc_apr_el1_write,
> .resetfn = gic_icc_apr_el1_reset,
>@@ -961,6 +978,7 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
> { .name = "ICC_CR0_EL1", .state = ARM_CP_STATE_AA64,
> .opc0 = 3, .opc1 = 1, .crn = 12, .crm = 0, .opc2 = 1,
> .access = PL1_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
>+ .fgt = FGT_ICC_CR0_EL1,
> .readfn = gic_icc_cr0_el1_read,
> .writefn = gic_icc_cr0_el1_write,
> .resetfn = gic_icc_cr0_el1_reset,
>@@ -968,6 +986,7 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
> { .name = "ICC_PCR_EL1", .state = ARM_CP_STATE_AA64,
> .opc0 = 3, .opc1 = 1, .crn = 12, .crm = 0, .opc2 = 2,
> .access = PL1_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
>+ .fgt = FGT_ICC_PCR_EL1,
> .readfn = gic_icc_pcr_el1_read,
> .writefn = gic_icc_pcr_el1_write,
> .resetfn = gic_icc_pcr_el1_reset,
>@@ -1102,6 +1121,7 @@ void define_gicv5_cpuif_regs(ARMCPU *cpu)
> .opc0 = 3, .opc1 = 0, .crn = 12,
> .crm = 14 + (i >> 3), .opc2 = i & 7,
> .access = PL1_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
>+ .fgt = FGT_ICC_PPI_PRIORITYRN_EL1,
> .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_priority[i]),
> .writefn = gic_ppi_priority_write, .raw_writefn = raw_write,
> };
>--
>2.43.0
>
^ permalink raw reply [flat|nested] 99+ messages in thread
* [PATCH v2 11/77] target/arm: GICv5 cpuif: Mark GIC insns for fine-grained traps
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (9 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 10/77] target/arm: GICv5 cpuif: Mark GIC registers for fine-grained traps Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 12/77] target/arm: GICv5 cpuif: Implement ICC_SRE_ELx Peter Maydell
` (65 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Annotate the GICv5 system insn cpreg structs with the
fine-grained trap information. This covers all the bits
in ICH_HFGITR_EL2.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/tcg/gicv5-cpuif.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index b636a8fa6b9..76c7e9f86e8 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -800,56 +800,67 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
{ .name = "GIC_CDDIS", .state = ARM_CP_STATE_AA64,
.opc0 = 1, .opc1 = 0, .crn = 12, .crm = 1, .opc2 = 0,
.access = PL1_W, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_GICCDDIS,
.writefn = gic_cddis_write,
},
{ .name = "GIC_CDEN", .state = ARM_CP_STATE_AA64,
.opc0 = 1, .opc1 = 0, .crn = 12, .crm = 1, .opc2 = 1,
.access = PL1_W, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_GICCDEN,
.writefn = gic_cden_write,
},
{ .name = "GIC_CDPRI", .state = ARM_CP_STATE_AA64,
.opc0 = 1, .opc1 = 0, .crn = 12, .crm = 1, .opc2 = 2,
.access = PL1_W, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_GICCDPRI,
.writefn = gic_cdpri_write,
},
{ .name = "GIC_CDAFF", .state = ARM_CP_STATE_AA64,
.opc0 = 1, .opc1 = 0, .crn = 12, .crm = 1, .opc2 = 3,
.access = PL1_W, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_GICCDAFF,
.writefn = gic_cdaff_write,
},
{ .name = "GIC_CDPEND", .state = ARM_CP_STATE_AA64,
.opc0 = 1, .opc1 = 0, .crn = 12, .crm = 1, .opc2 = 4,
.access = PL1_W, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_GICCDPEND,
.writefn = gic_cdpend_write,
},
{ .name = "GIC_CDRCFG", .state = ARM_CP_STATE_AA64,
.opc0 = 1, .opc1 = 0, .crn = 12, .crm = 1, .opc2 = 5,
.access = PL1_W, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_GICCDRCFG,
.writefn = gic_cdrcfg_write,
},
{ .name = "GIC_CDEOI", .state = ARM_CP_STATE_AA64,
.opc0 = 1, .opc1 = 0, .crn = 12, .crm = 1, .opc2 = 7,
.access = PL1_W, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_GICCDEOI,
.writefn = gic_cdeoi_write,
},
{ .name = "GIC_CDDI", .state = ARM_CP_STATE_AA64,
.opc0 = 1, .opc1 = 0, .crn = 12, .crm = 2, .opc2 = 0,
.access = PL1_W, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_GICCDDI,
.writefn = gic_cddi_write,
},
{ .name = "GIC_CDHM", .state = ARM_CP_STATE_AA64,
.opc0 = 1, .opc1 = 0, .crn = 12, .crm = 2, .opc2 = 1,
.access = PL1_W, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_GICCDHM,
.writefn = gic_cdhm_write,
},
{ .name = "GICR_CDIA", .state = ARM_CP_STATE_AA64,
.opc0 = 1, .opc1 = 0, .crn = 12, .crm = 3, .opc2 = 0,
.access = PL1_R, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_GICRCDIA,
.readfn = gicr_cdia_read,
},
{ .name = "GICR_CDNMIA", .state = ARM_CP_STATE_AA64,
.opc0 = 1, .opc1 = 0, .crn = 12, .crm = 3, .opc2 = 1,
.access = PL1_R, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .fgt = FGT_GICRCDNMIA,
.readfn = gicr_cdia_read,
},
{ .name = "ICC_IDR0_EL1", .state = ARM_CP_STATE_AA64,
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 12/77] target/arm: GICv5 cpuif: Implement ICC_SRE_ELx
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (10 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 11/77] target/arm: GICv5 cpuif: Mark GIC insns " Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-04 6:10 ` Manos Pitsidianakis
2026-12-03 11:10 ` [PATCH v2 13/77] target/arm: GICv5 cpuif: Implement ICH_PPI_HVIR<n>_EL2 Peter Maydell
` (64 subsequent siblings)
76 siblings, 1 reply; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
When FEAT_GCIE and FEAT_EL2 are implemented, the GICv5 specification
requires that the old GICv3 ICC_SRE_EL1 and ICC_SRE_EL2 registers are
present, with RAO/WI bits, even if FEAT_GCIE_LEGACY is not
implemented or enabled. ICC_SRE_EL3 is not present, but the CPU
behaves as if its Enable and SRE bits are always set. (See R_SLVXV,
R_MCTMX, R_HQBBN.)
Implement the ICC_SRE_EL1 and ICC_SRE_EL2 registers. For QEMU, this
"all bits RAO" is identical to how we implemented it for GICv3,
because we didn't implement the memory-map register interface, we
didn't support IRQ or FIQ bypass and we took advantage of the IMPDEF
option to make the ENABLE bit RAO so we didn't need to trap lower-EL
accesses to ICC_SRE_ELx. The RAO behaviours correspond to "do
nothing" -- don't trap system register accesses, no IRQ/FIQ bypass
handling -- so we don't need any special handling in any part of the
CPU implementation, just as we didn't for GICv3.
Because ICC_SRE_EL1 is EL1-visible but only present when FEAT_EL2
is implemented, we need to put it in a cpreg array that we only
register when ARM_FEATURE_EL2 is set, rather than being able to
list it in the main gicv5_cpuif_reginfo array and relying on the
access field as we do for other FEAT_EL2 GICv5 registers.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/tcg/gicv5-cpuif.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 76c7e9f86e8..89b50cf1165 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -1017,6 +1017,11 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
.fieldoffset = offsetof(CPUARMState, cp15.fgt_read[FGTREG_ICH_HFGRTR]),
.resetvalue = ICH_HFGRTR_EL2_RES1_MASK,
},
+ { .name = "ICC_SRE_EL2", .state = ARM_CP_STATE_AA64,
+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 9, .opc2 = 5,
+ .access = PL2_RW, .type = ARM_CP_NO_RAW | ARM_CP_CONST,
+ .resetvalue = 0xf,
+ },
{ .name = "ICH_HFGWTR_EL2", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 4, .crn = 12, .crm = 9, .opc2 = 6,
.access = PL2_RW, .type = ARM_CP_NO_RAW,
@@ -1116,6 +1121,14 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
},
};
+static const ARMCPRegInfo gicv5_cpuif_el2_reginfo[] = {
+ { .name = "ICC_SRE_EL1", .state = ARM_CP_STATE_AA64,
+ .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 12, .opc2 = 5,
+ .access = PL1_RW, .type = ARM_CP_NO_RAW | ARM_CP_CONST,
+ .resetvalue = 0x7,
+ },
+};
+
void define_gicv5_cpuif_regs(ARMCPU *cpu)
{
if (cpu_isar_feature(aa64_gcie, cpu)) {
@@ -1153,5 +1166,9 @@ void define_gicv5_cpuif_regs(ARMCPU *cpu)
};
define_one_arm_cp_reg(cpu, &ppi_prio);
}
+
+ if (arm_feature(&cpu->env, ARM_FEATURE_EL2)) {
+ define_arm_cp_regs(cpu, gicv5_cpuif_el2_reginfo);
+ }
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* Re: [PATCH v2 12/77] target/arm: GICv5 cpuif: Implement ICC_SRE_ELx
2026-12-03 11:10 ` [PATCH v2 12/77] target/arm: GICv5 cpuif: Implement ICC_SRE_ELx Peter Maydell
@ 2026-12-04 6:10 ` Manos Pitsidianakis
0 siblings, 0 replies; 99+ messages in thread
From: Manos Pitsidianakis @ 2026-12-04 6:10 UTC (permalink / raw)
To: Peter Maydell, qemu-arm, qemu-devel
Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
On Thu, 03 Dec 2026 13:10, Peter Maydell <peter.maydell@linaro.org> wrote:
>When FEAT_GCIE and FEAT_EL2 are implemented, the GICv5 specification
>requires that the old GICv3 ICC_SRE_EL1 and ICC_SRE_EL2 registers are
>present, with RAO/WI bits, even if FEAT_GCIE_LEGACY is not
>implemented or enabled. ICC_SRE_EL3 is not present, but the CPU
>behaves as if its Enable and SRE bits are always set. (See R_SLVXV,
>R_MCTMX, R_HQBBN.)
>
>Implement the ICC_SRE_EL1 and ICC_SRE_EL2 registers. For QEMU, this
>"all bits RAO" is identical to how we implemented it for GICv3,
>because we didn't implement the memory-map register interface, we
>didn't support IRQ or FIQ bypass and we took advantage of the IMPDEF
>option to make the ENABLE bit RAO so we didn't need to trap lower-EL
>accesses to ICC_SRE_ELx. The RAO behaviours correspond to "do
>nothing" -- don't trap system register accesses, no IRQ/FIQ bypass
>handling -- so we don't need any special handling in any part of the
>CPU implementation, just as we didn't for GICv3.
>
>Because ICC_SRE_EL1 is EL1-visible but only present when FEAT_EL2
>is implemented, we need to put it in a cpreg array that we only
>register when ARM_FEATURE_EL2 is set, rather than being able to
>list it in the main gicv5_cpuif_reginfo array and relying on the
>access field as we do for other FEAT_EL2 GICv5 registers.
>
>Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>---
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
> target/arm/tcg/gicv5-cpuif.c | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
>diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
>index 76c7e9f86e8..89b50cf1165 100644
>--- a/target/arm/tcg/gicv5-cpuif.c
>+++ b/target/arm/tcg/gicv5-cpuif.c
>@@ -1017,6 +1017,11 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
> .fieldoffset = offsetof(CPUARMState, cp15.fgt_read[FGTREG_ICH_HFGRTR]),
> .resetvalue = ICH_HFGRTR_EL2_RES1_MASK,
> },
>+ { .name = "ICC_SRE_EL2", .state = ARM_CP_STATE_AA64,
>+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 9, .opc2 = 5,
>+ .access = PL2_RW, .type = ARM_CP_NO_RAW | ARM_CP_CONST,
>+ .resetvalue = 0xf,
>+ },
> { .name = "ICH_HFGWTR_EL2", .state = ARM_CP_STATE_AA64,
> .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 9, .opc2 = 6,
> .access = PL2_RW, .type = ARM_CP_NO_RAW,
>@@ -1116,6 +1121,14 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
> },
> };
>
>+static const ARMCPRegInfo gicv5_cpuif_el2_reginfo[] = {
>+ { .name = "ICC_SRE_EL1", .state = ARM_CP_STATE_AA64,
>+ .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 12, .opc2 = 5,
>+ .access = PL1_RW, .type = ARM_CP_NO_RAW | ARM_CP_CONST,
>+ .resetvalue = 0x7,
>+ },
>+};
>+
> void define_gicv5_cpuif_regs(ARMCPU *cpu)
> {
> if (cpu_isar_feature(aa64_gcie, cpu)) {
>@@ -1153,5 +1166,9 @@ void define_gicv5_cpuif_regs(ARMCPU *cpu)
> };
> define_one_arm_cp_reg(cpu, &ppi_prio);
> }
>+
>+ if (arm_feature(&cpu->env, ARM_FEATURE_EL2)) {
>+ define_arm_cp_regs(cpu, gicv5_cpuif_el2_reginfo);
>+ }
> }
> }
>--
>2.43.0
>
^ permalink raw reply [flat|nested] 99+ messages in thread
* [PATCH v2 13/77] target/arm: GICv5 cpuif: Implement ICH_PPI_HVIR<n>_EL2
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (11 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 12/77] target/arm: GICv5 cpuif: Implement ICC_SRE_ELx Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 14/77] target/arm: GICv5 cpuif: Implement ICV_APR_EL1 Peter Maydell
` (63 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
The ICH_PPI_HVIR<n>_EL2 registers allow a hypervisor to hide a PPI
from the virtual interrupt domain. When the bit is set, direct reads
and writes to ICV register fields for that PPI are RAZ/WI.
As we haven't yet implemented the ICV accesses, all we need to
implement here is the cpreg and its backing storage. We will then be
able to test the DVI bits in the functions that add ICV read and
write handling. We give the register a writefn because eventually
it will need to trigger a recalculation of the virtual PPI HPPI.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/cpu.h | 1 +
target/arm/tcg/gicv5-cpuif.c | 22 ++++++++++++++++++++++
2 files changed, 23 insertions(+)
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index 6db66c67362..90768300d55 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -602,6 +602,7 @@ typedef struct CPUArchState {
uint64_t ich_apr_el2;
uint64_t ich_vctlr_el2;
uint64_t ich_vmcr_el2;
+ uint64_t ich_ppi_hvi[GICV5_NUM_PPIS / 64];
uint64_t ich_ppi_active[GICV5_NUM_PPIS / 64];
uint64_t ich_ppi_pend[GICV5_NUM_PPIS / 64];
uint64_t ich_ppi_enable[GICV5_NUM_PPIS / 64];
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 89b50cf1165..e012bd76897 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -493,6 +493,12 @@ static void gic_ich_ppi_dvi_write(CPUARMState *env, const ARMCPRegInfo *ri,
raw_write(env, ri, value);
}
+static void gic_ich_ppi_hvi_write(CPUARMState *env, const ARMCPRegInfo *ri,
+ uint64_t value)
+{
+ raw_write(env, ri, value);
+}
+
static void gic_ich_vctlr_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
@@ -1002,6 +1008,22 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
.writefn = gic_icc_pcr_el1_write,
.resetfn = gic_icc_pcr_el1_reset,
},
+ { .name = "ICH_PPI_HVIR0_EL2", .state = ARM_CP_STATE_AA64,
+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 7, .opc2 = 0,
+ .access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .nv2_redirect_offset = 0xc00,
+ .accessfn = access_gicv5_ich_reg,
+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_ppi_hvi[0]),
+ .writefn = gic_ich_ppi_hvi_write,
+ },
+ { .name = "ICH_PPI_HVIR1_EL2", .state = ARM_CP_STATE_AA64,
+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 7, .opc2 = 1,
+ .access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .nv2_redirect_offset = 0xc00,
+ .accessfn = access_gicv5_ich_reg,
+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_ppi_hvi[1]),
+ .writefn = gic_ich_ppi_hvi_write,
+ },
{ .name = "ICH_APR_EL2", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 4, .crn = 12, .crm = 8, .opc2 = 4,
.access = PL2_RW, .type = ARM_CP_NO_RAW,
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 14/77] target/arm: GICv5 cpuif: Implement ICV_APR_EL1
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (12 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 13/77] target/arm: GICv5 cpuif: Implement ICH_PPI_HVIR<n>_EL2 Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-04 7:32 ` Manos Pitsidianakis
2026-12-03 11:10 ` [PATCH v2 15/77] target/arm: GICv5 cpuif: Implement ICV_CR0_EL1 Peter Maydell
` (62 subsequent siblings)
76 siblings, 1 reply; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Implement the redirection of the ICC_APR_EL1 encoding to the
hypervisor guest's view ICV_APR_EL1; the data for this is stored in
the ICH_APR_EL2 register.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/tcg/gicv5-cpuif.c | 30 +++++++++++++++++++++++++-----
1 file changed, 25 insertions(+), 5 deletions(-)
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index e012bd76897..ef37e33fded 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -99,6 +99,17 @@ static bool gicv5_legacy_enabled(CPUARMState *env)
return false;
}
+static bool gicv5_icv_access(CPUARMState *env)
+{
+ /*
+ * Return true if ICC_*_EL1 accesses should redirect to ICV_*_EL1
+ * (i.e. we are in a hypervisor guest). Note that unlike GICv3 we
+ * don't need to care about HCR_FMO. See I_XVDWC.
+ */
+ return arm_current_el(env) == 1 && (arm_hcr_el2_eff(env) & HCR_IMO) &&
+ !gicv5_legacy_enabled(env);
+}
+
static GICv5Domain gicv5_logical_domain(CPUARMState *env)
{
/*
@@ -522,16 +533,25 @@ static void gic_icc_apr_el1_write(CPUARMState *env, const ARMCPRegInfo *ri,
* With an architectural 5 bits of priority, this register has 32
* non-RES0 bits
*/
- GICv5Domain domain = gicv5_logical_domain(env);
value &= 0xffffffff;
- env->gicv5_cpuif.icc_apr[domain] = value;
- gicv5_update_irq_fiq(env);
+
+ if (gicv5_icv_access(env)) {
+ env->gicv5_cpuif.ich_apr_el2 = value;
+ } else {
+ GICv5Domain domain = gicv5_logical_domain(env);
+ env->gicv5_cpuif.icc_apr[domain] = value;
+ gicv5_update_irq_fiq(env);
+ }
}
static uint64_t gic_icc_apr_el1_read(CPUARMState *env, const ARMCPRegInfo *ri)
{
- GICv5Domain domain = gicv5_logical_domain(env);
- return env->gicv5_cpuif.icc_apr[domain];
+ if (gicv5_icv_access(env)) {
+ return env->gicv5_cpuif.ich_apr_el2;
+ } else {
+ GICv5Domain domain = gicv5_logical_domain(env);
+ return env->gicv5_cpuif.icc_apr[domain];
+ }
}
static void gic_icc_apr_el1_reset(CPUARMState *env, const ARMCPRegInfo *ri)
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* Re: [PATCH v2 14/77] target/arm: GICv5 cpuif: Implement ICV_APR_EL1
2026-12-03 11:10 ` [PATCH v2 14/77] target/arm: GICv5 cpuif: Implement ICV_APR_EL1 Peter Maydell
@ 2026-12-04 7:32 ` Manos Pitsidianakis
0 siblings, 0 replies; 99+ messages in thread
From: Manos Pitsidianakis @ 2026-12-04 7:32 UTC (permalink / raw)
To: Peter Maydell, qemu-arm, qemu-devel
Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
On Thu, 03 Dec 2026 13:10, Peter Maydell <peter.maydell@linaro.org> wrote:
>Implement the redirection of the ICC_APR_EL1 encoding to the
>hypervisor guest's view ICV_APR_EL1; the data for this is stored in
>the ICH_APR_EL2 register.
>
>Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>---
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
> target/arm/tcg/gicv5-cpuif.c | 30 +++++++++++++++++++++++++-----
> 1 file changed, 25 insertions(+), 5 deletions(-)
>
>diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
>index e012bd76897..ef37e33fded 100644
>--- a/target/arm/tcg/gicv5-cpuif.c
>+++ b/target/arm/tcg/gicv5-cpuif.c
>@@ -99,6 +99,17 @@ static bool gicv5_legacy_enabled(CPUARMState *env)
> return false;
> }
>
>+static bool gicv5_icv_access(CPUARMState *env)
>+{
>+ /*
>+ * Return true if ICC_*_EL1 accesses should redirect to ICV_*_EL1
>+ * (i.e. we are in a hypervisor guest). Note that unlike GICv3 we
>+ * don't need to care about HCR_FMO. See I_XVDWC.
>+ */
>+ return arm_current_el(env) == 1 && (arm_hcr_el2_eff(env) & HCR_IMO) &&
>+ !gicv5_legacy_enabled(env);
>+}
>+
> static GICv5Domain gicv5_logical_domain(CPUARMState *env)
> {
> /*
>@@ -522,16 +533,25 @@ static void gic_icc_apr_el1_write(CPUARMState *env, const ARMCPRegInfo *ri,
> * With an architectural 5 bits of priority, this register has 32
> * non-RES0 bits
> */
>- GICv5Domain domain = gicv5_logical_domain(env);
> value &= 0xffffffff;
>- env->gicv5_cpuif.icc_apr[domain] = value;
>- gicv5_update_irq_fiq(env);
>+
>+ if (gicv5_icv_access(env)) {
>+ env->gicv5_cpuif.ich_apr_el2 = value;
>+ } else {
>+ GICv5Domain domain = gicv5_logical_domain(env);
>+ env->gicv5_cpuif.icc_apr[domain] = value;
>+ gicv5_update_irq_fiq(env);
>+ }
> }
>
> static uint64_t gic_icc_apr_el1_read(CPUARMState *env, const ARMCPRegInfo *ri)
> {
>- GICv5Domain domain = gicv5_logical_domain(env);
>- return env->gicv5_cpuif.icc_apr[domain];
>+ if (gicv5_icv_access(env)) {
>+ return env->gicv5_cpuif.ich_apr_el2;
>+ } else {
>+ GICv5Domain domain = gicv5_logical_domain(env);
>+ return env->gicv5_cpuif.icc_apr[domain];
>+ }
> }
>
> static void gic_icc_apr_el1_reset(CPUARMState *env, const ARMCPRegInfo *ri)
>--
>2.43.0
>
^ permalink raw reply [flat|nested] 99+ messages in thread
* [PATCH v2 15/77] target/arm: GICv5 cpuif: Implement ICV_CR0_EL1
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (13 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 14/77] target/arm: GICv5 cpuif: Implement ICV_APR_EL1 Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-04 7:32 ` Manos Pitsidianakis
2026-12-03 11:10 ` [PATCH v2 16/77] target/arm: GICv5 cpuif: Implement ICV_PCR_EL1 Peter Maydell
` (61 subsequent siblings)
76 siblings, 1 reply; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Implement the redirection of the ICC_CR0_EL1 encoding to the
hypervisor guest's view ICV_CR0_EL1. This has only one bit in it,
the enable (EN) bit, which is stored in ICH_VMCR_EL2.EN at the
same bit location (0).
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/tcg/gicv5-cpuif.c | 41 +++++++++++++++++++++++++-----------
1 file changed, 29 insertions(+), 12 deletions(-)
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index ef37e33fded..67ffd259595 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -67,6 +67,9 @@ FIELD(ICC_HPPIR_EL1, ID, 0, 24)
FIELD(ICC_HPPIR_EL1, TYPE, 29, 3)
FIELD(ICC_HPPIR_EL1, HPPIV, 32, 1)
+FIELD(ICH_VMCR_EL2, EN, 0, 1)
+FIELD(ICH_VMCR_EL2, VPMR, 27, 5)
+
/*
* We implement 24 bits of interrupt ID, the mandated 5 bits of priority,
* and no legacy GICv3.3 vcpu interface (yet)
@@ -564,24 +567,38 @@ static void gic_icc_apr_el1_reset(CPUARMState *env, const ARMCPRegInfo *ri)
/* ICC_CR0_EL1 is also banked */
static uint64_t gic_icc_cr0_el1_read(CPUARMState *env, const ARMCPRegInfo *ri)
{
- GICv5Domain domain = gicv5_logical_domain(env);
- return env->gicv5_cpuif.icc_cr0[domain];
+ if (gicv5_icv_access(env)) {
+ /* ICV_CR0_EL1 has only an EN bit, stored in ICH_VMCR_EL2.EN */
+ return FIELD_EX64(env->gicv5_cpuif.ich_vmcr_el2, ICH_VMCR_EL2, EN);
+ } else {
+ GICv5Domain domain = gicv5_logical_domain(env);
+ return env->gicv5_cpuif.icc_cr0[domain];
+ }
}
static void gic_icc_cr0_el1_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
- /*
- * For our implementation the link to the IRI is always connected,
- * so LINK and LINK_IDLE are always 1. Without EL3, PID and IPPT
- * are RAZ/WI, so the only writeable bit is the main enable bit EN.
- */
- GICv5Domain domain = gicv5_logical_domain(env);
- value &= R_ICC_CR0_EN_MASK;
- value |= R_ICC_CR0_LINK_MASK | R_ICC_CR0_LINK_IDLE_MASK;
+ if (gicv5_icv_access(env)) {
+ /* Only the EN bit is writeable, and it lives in ICH_VMCR_EL2 */
+ uint64_t vmcr = env->gicv5_cpuif.ich_vmcr_el2;
- env->gicv5_cpuif.icc_cr0[domain] = value;
- gicv5_update_irq_fiq(env);
+ vmcr = FIELD_DP64(vmcr, ICH_VMCR_EL2, EN,
+ FIELD_EX64(value, ICC_CR0, EN));
+ env->gicv5_cpuif.ich_vmcr_el2 = vmcr;
+ } else {
+ /*
+ * For our implementation the link to the IRI is always connected,
+ * so LINK and LINK_IDLE are always 1. Without EL3, PID and IPPT
+ * are RAZ/WI, so the only writeable bit is the main enable bit EN.
+ */
+ GICv5Domain domain = gicv5_logical_domain(env);
+ value &= R_ICC_CR0_EN_MASK;
+ value |= R_ICC_CR0_LINK_MASK | R_ICC_CR0_LINK_IDLE_MASK;
+
+ env->gicv5_cpuif.icc_cr0[domain] = value;
+ gicv5_update_irq_fiq(env);
+ }
}
static void gic_icc_cr0_el1_reset(CPUARMState *env, const ARMCPRegInfo *ri)
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* Re: [PATCH v2 15/77] target/arm: GICv5 cpuif: Implement ICV_CR0_EL1
2026-12-03 11:10 ` [PATCH v2 15/77] target/arm: GICv5 cpuif: Implement ICV_CR0_EL1 Peter Maydell
@ 2026-12-04 7:32 ` Manos Pitsidianakis
0 siblings, 0 replies; 99+ messages in thread
From: Manos Pitsidianakis @ 2026-12-04 7:32 UTC (permalink / raw)
To: Peter Maydell, qemu-arm, qemu-devel
Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
On Thu, 03 Dec 2026 13:10, Peter Maydell <peter.maydell@linaro.org> wrote:
>Implement the redirection of the ICC_CR0_EL1 encoding to the
>hypervisor guest's view ICV_CR0_EL1. This has only one bit in it,
>the enable (EN) bit, which is stored in ICH_VMCR_EL2.EN at the
>same bit location (0).
>
>Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>---
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
> target/arm/tcg/gicv5-cpuif.c | 41 +++++++++++++++++++++++++-----------
> 1 file changed, 29 insertions(+), 12 deletions(-)
>
>diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
>index ef37e33fded..67ffd259595 100644
>--- a/target/arm/tcg/gicv5-cpuif.c
>+++ b/target/arm/tcg/gicv5-cpuif.c
>@@ -67,6 +67,9 @@ FIELD(ICC_HPPIR_EL1, ID, 0, 24)
> FIELD(ICC_HPPIR_EL1, TYPE, 29, 3)
> FIELD(ICC_HPPIR_EL1, HPPIV, 32, 1)
>
>+FIELD(ICH_VMCR_EL2, EN, 0, 1)
>+FIELD(ICH_VMCR_EL2, VPMR, 27, 5)
>+
> /*
> * We implement 24 bits of interrupt ID, the mandated 5 bits of priority,
> * and no legacy GICv3.3 vcpu interface (yet)
>@@ -564,24 +567,38 @@ static void gic_icc_apr_el1_reset(CPUARMState *env, const ARMCPRegInfo *ri)
> /* ICC_CR0_EL1 is also banked */
> static uint64_t gic_icc_cr0_el1_read(CPUARMState *env, const ARMCPRegInfo *ri)
> {
>- GICv5Domain domain = gicv5_logical_domain(env);
>- return env->gicv5_cpuif.icc_cr0[domain];
>+ if (gicv5_icv_access(env)) {
>+ /* ICV_CR0_EL1 has only an EN bit, stored in ICH_VMCR_EL2.EN */
>+ return FIELD_EX64(env->gicv5_cpuif.ich_vmcr_el2, ICH_VMCR_EL2, EN);
>+ } else {
>+ GICv5Domain domain = gicv5_logical_domain(env);
>+ return env->gicv5_cpuif.icc_cr0[domain];
>+ }
> }
>
> static void gic_icc_cr0_el1_write(CPUARMState *env, const ARMCPRegInfo *ri,
> uint64_t value)
> {
>- /*
>- * For our implementation the link to the IRI is always connected,
>- * so LINK and LINK_IDLE are always 1. Without EL3, PID and IPPT
>- * are RAZ/WI, so the only writeable bit is the main enable bit EN.
>- */
>- GICv5Domain domain = gicv5_logical_domain(env);
>- value &= R_ICC_CR0_EN_MASK;
>- value |= R_ICC_CR0_LINK_MASK | R_ICC_CR0_LINK_IDLE_MASK;
>+ if (gicv5_icv_access(env)) {
>+ /* Only the EN bit is writeable, and it lives in ICH_VMCR_EL2 */
>+ uint64_t vmcr = env->gicv5_cpuif.ich_vmcr_el2;
>
>- env->gicv5_cpuif.icc_cr0[domain] = value;
>- gicv5_update_irq_fiq(env);
>+ vmcr = FIELD_DP64(vmcr, ICH_VMCR_EL2, EN,
>+ FIELD_EX64(value, ICC_CR0, EN));
>+ env->gicv5_cpuif.ich_vmcr_el2 = vmcr;
nb It was kind of confusing for review that we add the
gicv5_update_virq_vfiq() call in a later patch instead of from the
beginning.
>+ } else {
>+ /*
>+ * For our implementation the link to the IRI is always connected,
>+ * so LINK and LINK_IDLE are always 1. Without EL3, PID and IPPT
>+ * are RAZ/WI, so the only writeable bit is the main enable bit EN.
>+ */
>+ GICv5Domain domain = gicv5_logical_domain(env);
>+ value &= R_ICC_CR0_EN_MASK;
>+ value |= R_ICC_CR0_LINK_MASK | R_ICC_CR0_LINK_IDLE_MASK;
>+
>+ env->gicv5_cpuif.icc_cr0[domain] = value;
>+ gicv5_update_irq_fiq(env);
>+ }
> }
>
> static void gic_icc_cr0_el1_reset(CPUARMState *env, const ARMCPRegInfo *ri)
>--
>2.43.0
>
^ permalink raw reply [flat|nested] 99+ messages in thread
* [PATCH v2 16/77] target/arm: GICv5 cpuif: Implement ICV_PCR_EL1
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (14 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 15/77] target/arm: GICv5 cpuif: Implement ICV_CR0_EL1 Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 17/77] target/arm: GICv5 cpuif: Implement ICV_PPI_ENABLER<n>_EL1 Peter Maydell
` (60 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Implement the redirection of the ICC_PCR_EL1 encoding to the
hypervisor guest's view ICV_PCR_EL1. This contains only the
PRIORITY field, which is stored in ICH_VMCR_EL2.VMPR.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/tcg/gicv5-cpuif.c | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 67ffd259595..6e7625b0537 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -612,18 +612,32 @@ static void gic_icc_cr0_el1_reset(CPUARMState *env, const ARMCPRegInfo *ri)
static uint64_t gic_icc_pcr_el1_read(CPUARMState *env, const ARMCPRegInfo *ri)
{
- GICv5Domain domain = gicv5_logical_domain(env);
- return env->gicv5_cpuif.icc_pcr[domain];
+ if (gicv5_icv_access(env)) {
+ return FIELD_EX64(env->gicv5_cpuif.ich_vmcr_el2,
+ ICH_VMCR_EL2, VPMR);
+ } else {
+ GICv5Domain domain = gicv5_logical_domain(env);
+ return env->gicv5_cpuif.icc_pcr[domain];
+ }
}
static void gic_icc_pcr_el1_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
- GICv5Domain domain = gicv5_logical_domain(env);
+ if (gicv5_icv_access(env)) {
+ /* The PRIORITY field lives in ICH_VMCR_EL2.VPMR */
+ uint64_t vmcr = env->gicv5_cpuif.ich_vmcr_el2;
- value &= R_ICC_PCR_PRIORITY_MASK;
- env->gicv5_cpuif.icc_pcr[domain] = value;
- gicv5_update_irq_fiq(env);
+ vmcr = FIELD_DP64(vmcr, ICH_VMCR_EL2, VPMR,
+ FIELD_EX64(value, ICC_PCR, PRIORITY));
+ env->gicv5_cpuif.ich_vmcr_el2 = vmcr;
+ } else {
+ GICv5Domain domain = gicv5_logical_domain(env);
+
+ value &= R_ICC_PCR_PRIORITY_MASK;
+ env->gicv5_cpuif.icc_pcr[domain] = value;
+ gicv5_update_irq_fiq(env);
+ }
}
static void gic_icc_pcr_el1_reset(CPUARMState *env, const ARMCPRegInfo *ri)
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 17/77] target/arm: GICv5 cpuif: Implement ICV_PPI_ENABLER<n>_EL1
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (15 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 16/77] target/arm: GICv5 cpuif: Implement ICV_PCR_EL1 Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 18/77] target/arm: GICv5 cpuif: Implement ICV_PPI_PRIORITYR<n>_EL1 Peter Maydell
` (59 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Implement the redirection of ICC_PPI_ENABLER<n>_EL1 to
ICV_PPI_ENABLER<n>_EL1; the data for this is stored in
ICH_PPI_ENABLER<n>_EL2.
For the ICV access we need to honour the "make this RAZ/WI"
config bits in ICH_PPI_HVIR<n>_EL2.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/tcg/gicv5-cpuif.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 6e7625b0537..8de0aeb87be 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -463,11 +463,28 @@ static void gic_ppi_spend_write(CPUARMState *env, const ARMCPRegInfo *ri,
gic_recalc_ppi_hppi(env);
}
+static uint64_t gic_ppi_enable_read(CPUARMState *env, const ARMCPRegInfo *ri)
+{
+ if (gicv5_icv_access(env)) {
+ uint64_t r = env->gicv5_cpuif.ich_ppi_enable[ri->opc2 & 1];
+
+ r &= ~env->gicv5_cpuif.ich_ppi_hvi[ri->opc2 & 1];
+ return r;
+ } else {
+ return raw_read(env, ri);
+ }
+}
+
static void gic_ppi_enable_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
- raw_write(env, ri, value);
- gic_recalc_ppi_hppi(env);
+ if (gicv5_icv_access(env)) {
+ value &= ~env->gicv5_cpuif.ich_ppi_hvi[ri->opc2 & 1];
+ env->gicv5_cpuif.ich_ppi_enable[ri->opc2 & 1] = value;
+ } else {
+ raw_write(env, ri, value);
+ gic_recalc_ppi_hppi(env);
+ }
}
static void gic_ppi_priority_write(CPUARMState *env, const ARMCPRegInfo *ri,
@@ -998,6 +1015,7 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
.access = PL1_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
.fgt = FGT_ICC_PPI_ENABLERN_EL1,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_enable[0]),
+ .readfn = gic_ppi_enable_read,
.writefn = gic_ppi_enable_write,
},
{ .name = "ICC_PPI_ENABLER1_EL1", .state = ARM_CP_STATE_AA64,
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 18/77] target/arm: GICv5 cpuif: Implement ICV_PPI_PRIORITYR<n>_EL1
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (16 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 17/77] target/arm: GICv5 cpuif: Implement ICV_PPI_ENABLER<n>_EL1 Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 19/77] target/arm: GICv5 cpuif: Add comment about ICV_PPI_HMR<n>_EL1 Peter Maydell
` (58 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Implement the redirection of ICC_PPI_PRIORITYR<n>_EL1 to
ICV_PPI_ENABLER<n>_EL1; the data for this is stored in
ICH_PPI_ENABLER<n>_EL2.
The algorithm in gic_ppi_prio_hvi_mask() for expanding 8 mask
bits out into 8 mask bytes is suggested by an AI, but it is
only 4 lines of code, and I wrote the comments.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/tcg/gicv5-cpuif.c | 64 ++++++++++++++++++++++++++++++++++--
1 file changed, 62 insertions(+), 2 deletions(-)
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 8de0aeb87be..40653410f85 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -487,11 +487,70 @@ static void gic_ppi_enable_write(CPUARMState *env, const ARMCPRegInfo *ri,
}
}
+static int icc_ppi_prio_reg_index(const ARMCPRegInfo *ri)
+{
+ /*
+ * Return the index of the ICC or ICV PPI_PRIORITYR register,
+ * which is CRm[0]:opc2[2:0].
+ */
+ return deposit32(ri->opc2, 3, 1, ri->crm);
+}
+
+static uint64_t gic_ppi_prio_hvi_mask(CPUARMState *env, int idx)
+{
+ /*
+ * Return the mask of which fields in the given priority register
+ * the guest cannot see, which is controlled by the ICH_PPI_HVI
+ * registers. We need to expand the appropriate 8 bits from
+ * ICH_PPI_HVI out to a mask where each byte is either all-1s or
+ * all-0s. The return value here is 1s for "do not show the
+ * guest", the same sense as the ICH_PPI_HVI registers.
+ */
+ int regno = idx >> 3;
+ int startbit = idx & 7;
+ /* Extract the relevant 8 HVI bits from the right register */
+ uint64_t mask = extract64(env->gicv5_cpuif.ich_ppi_hvi[regno], startbit, 8);
+
+ /*
+ * Now we're going to distribute those 8 bits so they end up in
+ * bits 0, 8, 16, ... 56 of the mask (i.e. in the LSB of each byte).
+ */
+ /* Split the 8 bits into two 4-bit chunks at bits 0 and 32 */
+ mask = (mask | (mask << 28)) & 0x0000000f0000000fULL;
+ /* Split again into four 2-bit chunks at bits 0, 16, 32, 48 */
+ mask = (mask | (mask << 14)) & 0x0003000300030003ULL;
+ /* Split again into eight 1-bit chunks, at the LSB of each byte */
+ mask = (mask | (mask << 7)) & 0x0101010101010101ULL;
+ /* Finally, the multiply turns each 0x1 byte into 0xFF */
+ mask *= 0xff;
+ return mask;
+}
+
+static uint64_t gic_ppi_priority_read(CPUARMState *env, const ARMCPRegInfo *ri)
+{
+ if (gicv5_icv_access(env)) {
+ int idx = icc_ppi_prio_reg_index(ri);
+ uint64_t r = env->gicv5_cpuif.ich_ppi_priority[idx];
+ uint64_t hvi_mask = gic_ppi_prio_hvi_mask(env, idx);
+
+ return r & ~hvi_mask;
+ } else {
+ return raw_read(env, ri);
+ }
+}
+
static void gic_ppi_priority_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
- raw_write(env, ri, value);
- gic_recalc_ppi_hppi(env);
+ if (gicv5_icv_access(env)) {
+ int idx = icc_ppi_prio_reg_index(ri);
+ uint64_t hvi_mask = gic_ppi_prio_hvi_mask(env, idx);
+
+ env->gicv5_cpuif.ich_ppi_priority[idx] = value & ~hvi_mask;
+ } else {
+ raw_write(env, ri, value);
+ gic_recalc_ppi_hppi(env);
+ }
}
static void gic_ich_ppi_enable_write(CPUARMState *env, const ARMCPRegInfo *ri,
@@ -1239,6 +1298,7 @@ void define_gicv5_cpuif_regs(ARMCPU *cpu)
.fgt = FGT_ICC_PPI_PRIORITYRN_EL1,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_priority[i]),
.writefn = gic_ppi_priority_write, .raw_writefn = raw_write,
+ .readfn = gic_ppi_priority_read,
};
define_one_arm_cp_reg(cpu, &ppi_prio);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 19/77] target/arm: GICv5 cpuif: Add comment about ICV_PPI_HMR<n>_EL1
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (17 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 18/77] target/arm: GICv5 cpuif: Implement ICV_PPI_PRIORITYR<n>_EL1 Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 20/77] target/arm: GICv5 cpuif: Implement ICV_PPI_CACTIVER<n>_EL1, ICV_PPI_SACTIVER<n>_EL1 Peter Maydell
` (57 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
The ICC_PPI_HMR<n>_EL1 and ICV_PPI_HMR<n>_EL1 registers are both
read-only and report whether PPIs have the edge or level handling
mode. This doesn't change under virtualization and there is no
mechanism for the hypervisor to report a different value to the
guest. However, we do need to honour the ICH_PPI_HVI bits that
make the PPI behave as if it was unimplemented (bit is RAZ/WI).
Add a readfn for these registers so we can mask them when they are
read by the hypervisor guest.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/tcg/gicv5-cpuif.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 40653410f85..075dd069553 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -425,6 +425,23 @@ static void gic_cdhm_write(CPUARMState *env, const ARMCPRegInfo *ri,
gicv5_set_handling(gic, id, hm, domain, type, virtual);
}
+static uint64_t gic_ppi_hmr_read(CPUARMState *env, const ARMCPRegInfo *ri)
+{
+ uint64_t value = raw_read(env, ri);
+
+ if (gicv5_icv_access(env)) {
+ /*
+ * The spec defines ICV_PPI_HMR<n>_EL1 virtual versions of these
+ * registers, but they are read-only and can only ever report the
+ * same value as the physical ICC_ versions. However we do need
+ * to make sure the bits RAZ/WI if the hypervisor has made the
+ * PPI appear disabled to the guest via ICH_PPI_HVIR<n>_EL2.
+ */
+ value &= ~env->gicv5_cpuif.ich_ppi_hvi[ri->opc2 & 1];
+ }
+ return value;
+}
+
static void gic_ppi_cactive_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
@@ -1054,6 +1071,7 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
.access = PL1_R, .type = ARM_CP_IO | ARM_CP_NO_RAW,
.fgt = FGT_ICC_PPI_HMRN_EL1,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_hm[0]),
+ .readfn = gic_ppi_hmr_read,
.resetvalue = PPI_HMR0_RESET,
},
{ .name = "ICC_PPI_HMR1_EL1", .state = ARM_CP_STATE_AA64,
@@ -1061,6 +1079,7 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
.access = PL1_R, .type = ARM_CP_IO | ARM_CP_NO_RAW,
.fgt = FGT_ICC_PPI_HMRN_EL1,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_hm[1]),
+ .readfn = gic_ppi_hmr_read,
.resetvalue = PPI_HMR1_RESET,
},
{ .name = "ICC_HPPIR_EL1", .state = ARM_CP_STATE_AA64,
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 20/77] target/arm: GICv5 cpuif: Implement ICV_PPI_CACTIVER<n>_EL1, ICV_PPI_SACTIVER<n>_EL1
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (18 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 19/77] target/arm: GICv5 cpuif: Add comment about ICV_PPI_HMR<n>_EL1 Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 21/77] target/arm: GICv5 cpuif: Implement ICV_PPI_CPENDR<n>_EL1, ICV_PPI_SPENDR<n>_EL1 Peter Maydell
` (56 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Implement the redirection of ICC_PPI_CACTIVER<n>_EL1 and
ICC_PPI_SACTIVER<n>_EL1 to the virtual ICV_ versions of these
registers. The underlying state here is held in
ICH_PPI_ACTIVER<n>_EL2, but the inner-guest facing view has set/clear
semantics.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/tcg/gicv5-cpuif.c | 38 ++++++++++++++++++++++++++++++------
1 file changed, 32 insertions(+), 6 deletions(-)
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 075dd069553..fe77dd9f5cf 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -442,20 +442,42 @@ static uint64_t gic_ppi_hmr_read(CPUARMState *env, const ARMCPRegInfo *ri)
return value;
}
+static uint64_t gic_ppi_active_read(CPUARMState *env, const ARMCPRegInfo *ri)
+{
+ if (gicv5_icv_access(env)) {
+ uint64_t value = env->gicv5_cpuif.ich_ppi_active[ri->opc2 & 1];
+
+ value &= ~env->gicv5_cpuif.ich_ppi_hvi[ri->opc2 & 1];
+ return value;
+ } else {
+ return raw_read(env, ri);
+ }
+}
+
static void gic_ppi_cactive_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
- uint64_t old = raw_read(env, ri);
- raw_write(env, ri, old & ~value);
- gic_recalc_ppi_hppi(env);
+ if (gicv5_icv_access(env)) {
+ value &= ~env->gicv5_cpuif.ich_ppi_hvi[ri->opc2 & 1];
+ env->gicv5_cpuif.ich_ppi_active[ri->opc2 & 1] &= ~value;
+ } else {
+ uint64_t old = raw_read(env, ri);
+ raw_write(env, ri, old & ~value);
+ gic_recalc_ppi_hppi(env);
+ }
}
static void gic_ppi_sactive_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
- uint64_t old = raw_read(env, ri);
- raw_write(env, ri, old | value);
- gic_recalc_ppi_hppi(env);
+ if (gicv5_icv_access(env)) {
+ value &= ~env->gicv5_cpuif.ich_ppi_hvi[ri->opc2 & 1];
+ env->gicv5_cpuif.ich_ppi_active[ri->opc2 & 1] |= value;
+ } else {
+ uint64_t old = raw_read(env, ri);
+ raw_write(env, ri, old | value);
+ gic_recalc_ppi_hppi(env);
+ }
}
static void gic_ppi_cpend_write(CPUARMState *env, const ARMCPRegInfo *ri,
@@ -1043,6 +1065,7 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
.access = PL1_RW, .type = ARM_CP_ALIAS | ARM_CP_IO | ARM_CP_NO_RAW,
.fgt = FGT_ICC_PPI_ACTIVERN_EL1,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_active[0]),
+ .readfn = gic_ppi_active_read,
.writefn = gic_ppi_cactive_write,
},
{ .name = "ICC_PPI_CACTIVER1_EL1", .state = ARM_CP_STATE_AA64,
@@ -1050,6 +1073,7 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
.access = PL1_RW, .type = ARM_CP_ALIAS | ARM_CP_IO | ARM_CP_NO_RAW,
.fgt = FGT_ICC_PPI_ACTIVERN_EL1,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_active[1]),
+ .readfn = gic_ppi_active_read,
.writefn = gic_ppi_cactive_write,
},
{ .name = "ICC_PPI_SACTIVER0_EL1", .state = ARM_CP_STATE_AA64,
@@ -1057,6 +1081,7 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
.access = PL1_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
.fgt = FGT_ICC_PPI_ACTIVERN_EL1,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_active[0]),
+ .readfn = gic_ppi_active_read,
.writefn = gic_ppi_sactive_write,
},
{ .name = "ICC_PPI_SACTIVER1_EL1", .state = ARM_CP_STATE_AA64,
@@ -1064,6 +1089,7 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
.access = PL1_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
.fgt = FGT_ICC_PPI_ACTIVERN_EL1,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_active[1]),
+ .readfn = gic_ppi_active_read,
.writefn = gic_ppi_sactive_write,
},
{ .name = "ICC_PPI_HMR0_EL1", .state = ARM_CP_STATE_AA64,
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 21/77] target/arm: GICv5 cpuif: Implement ICV_PPI_CPENDR<n>_EL1, ICV_PPI_SPENDR<n>_EL1
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (19 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 20/77] target/arm: GICv5 cpuif: Implement ICV_PPI_CACTIVER<n>_EL1, ICV_PPI_SACTIVER<n>_EL1 Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 22/77] target/arm: GICv5 cpuif: Calculate current virtual PPI HPPI Peter Maydell
` (55 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Implement the redirection of ICC_PPI_CPENDR<n>_EL1 and
ICC_PPI_SPENDoR<n>_EL1 to the virtual ICV_ versions of these
registers. The underlying state here is held in
ICH_PPI_PENDR<n>_EL2, but the inner-guest facing view has set/clear
semantics.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/tcg/gicv5-cpuif.c | 40 ++++++++++++++++++++++++++++++------
1 file changed, 34 insertions(+), 6 deletions(-)
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index fe77dd9f5cf..63364d9189f 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -480,26 +480,50 @@ static void gic_ppi_sactive_write(CPUARMState *env, const ARMCPRegInfo *ri,
}
}
+static uint64_t gic_ppi_pend_read(CPUARMState *env, const ARMCPRegInfo *ri)
+{
+ if (gicv5_icv_access(env)) {
+ uint64_t value = env->gicv5_cpuif.ich_ppi_pend[ri->opc2 & 1];
+
+ value &= ~env->gicv5_cpuif.ich_ppi_hvi[ri->opc2 & 1];
+ return value;
+ } else {
+ return raw_read(env, ri);
+ }
+}
+
static void gic_ppi_cpend_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
- uint64_t old = raw_read(env, ri);
/* If ICC_PPI_HMR_EL1[n].HM is 1, PEND bits are RO */
uint64_t hm = env->gicv5_cpuif.ppi_hm[ri->opc2 & 1];
value &= ~hm;
- raw_write(env, ri, old & ~value);
- gic_recalc_ppi_hppi(env);
+
+ if (gicv5_icv_access(env)) {
+ value &= ~env->gicv5_cpuif.ich_ppi_hvi[ri->opc2 & 1];
+ env->gicv5_cpuif.ich_ppi_pend[ri->opc2 & 1] &= ~value;
+ } else {
+ uint64_t old = raw_read(env, ri);
+ raw_write(env, ri, old & ~value);
+ gic_recalc_ppi_hppi(env);
+ }
}
static void gic_ppi_spend_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
- uint64_t old = raw_read(env, ri);
/* If ICC_PPI_HMR_EL1[n].HM is 1, PEND bits are RO */
uint64_t hm = env->gicv5_cpuif.ppi_hm[ri->opc2 & 1];
value &= ~hm;
- raw_write(env, ri, old | value);
- gic_recalc_ppi_hppi(env);
+
+ if (gicv5_icv_access(env)) {
+ value &= ~env->gicv5_cpuif.ich_ppi_hvi[ri->opc2 & 1];
+ env->gicv5_cpuif.ich_ppi_pend[ri->opc2 & 1] |= value;
+ } else {
+ uint64_t old = raw_read(env, ri);
+ raw_write(env, ri, old | value);
+ gic_recalc_ppi_hppi(env);
+ }
}
static uint64_t gic_ppi_enable_read(CPUARMState *env, const ARMCPRegInfo *ri)
@@ -1134,6 +1158,7 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
.access = PL1_RW, .type = ARM_CP_ALIAS | ARM_CP_IO | ARM_CP_NO_RAW,
.fgt = FGT_ICC_PPI_PENDRN_EL1,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_pend[0]),
+ .readfn = gic_ppi_pend_read,
.writefn = gic_ppi_cpend_write,
},
{ .name = "ICC_PPI_CPENDR1_EL1", .state = ARM_CP_STATE_AA64,
@@ -1141,6 +1166,7 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
.access = PL1_RW, .type = ARM_CP_ALIAS | ARM_CP_IO | ARM_CP_NO_RAW,
.fgt = FGT_ICC_PPI_PENDRN_EL1,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_pend[1]),
+ .readfn = gic_ppi_pend_read,
.writefn = gic_ppi_cpend_write,
},
{ .name = "ICC_PPI_SPENDR0_EL1", .state = ARM_CP_STATE_AA64,
@@ -1148,6 +1174,7 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
.access = PL1_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
.fgt = FGT_ICC_PPI_PENDRN_EL1,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_pend[0]),
+ .readfn = gic_ppi_pend_read,
.writefn = gic_ppi_spend_write,
},
{ .name = "ICC_PPI_SPENDR1_EL1", .state = ARM_CP_STATE_AA64,
@@ -1155,6 +1182,7 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
.access = PL1_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
.fgt = FGT_ICC_PPI_PENDRN_EL1,
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_pend[1]),
+ .readfn = gic_ppi_pend_read,
.writefn = gic_ppi_spend_write,
},
{ .name = "ICC_APR_EL1", .state = ARM_CP_STATE_AA64,
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 22/77] target/arm: GICv5 cpuif: Calculate current virtual PPI HPPI
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (20 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 21/77] target/arm: GICv5 cpuif: Implement ICV_PPI_CPENDR<n>_EL1, ICV_PPI_SPENDR<n>_EL1 Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-04 7:47 ` Manos Pitsidianakis
2026-12-03 11:10 ` [PATCH v2 23/77] target/arm: GICv5 cpuif: Add virtual support to IRS/cpuif HPPI APIs Peter Maydell
` (54 subsequent siblings)
76 siblings, 1 reply; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Implement gic_recalc_virt_ppi_hppi(), which calculates the current
HPPI PPI for the virtual interrupt domain, using similar logic to
gic_recalc_ppi_hppi(). We call this from everywhere where we update
the state of the virtual PPIs.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/cpu.h | 2 ++
target/arm/tcg/gicv5-cpuif.c | 51 ++++++++++++++++++++++++++++++++++++
target/arm/tcg/trace-events | 1 +
3 files changed, 54 insertions(+)
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index 90768300d55..5abfd2c95f7 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -598,6 +598,8 @@ typedef struct CPUArchState {
/* Cached highest-priority pending PPI for each domain */
GICv5PendingIrq ppi_hppi[NUM_GICV5_DOMAINS];
+ /* And for the virtual interrupt domain */
+ GICv5PendingIrq virt_ppi_hppi;
uint64_t ich_apr_el2;
uint64_t ich_vctlr_el2;
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 63364d9189f..910d72ff65e 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -298,6 +298,45 @@ static void gic_recalc_ppi_hppi(CPUARMState *env)
gicv5_update_irq_fiq(env);
}
+static void gic_recalc_virt_ppi_hppi(CPUARMState *env)
+{
+ /*
+ * Recalculate the HPPI PPI for the virtual interrupt domain: this is
+ * the best PPI which is enabled, pending and not active.
+ */
+ env->gicv5_cpuif.virt_ppi_hppi = GICV5_PENDING_IRQ_NONE;
+
+ for (int i = 0; i < ARRAY_SIZE(env->gicv5_cpuif.ich_ppi_active); i++) {
+ uint64_t en_pend_nact = env->gicv5_cpuif.ich_ppi_enable[i] &
+ env->gicv5_cpuif.ich_ppi_pend[i] &
+ ~env->gicv5_cpuif.ich_ppi_active[i];
+
+ while (en_pend_nact) {
+ uint8_t prio;
+ int ppi;
+ int bit = ctz64(en_pend_nact);
+
+ en_pend_nact &= ~(1ULL << bit);
+
+ ppi = i * 64 + bit;
+ prio = extract64(env->gicv5_cpuif.ich_ppi_priority[ppi / 8],
+ (ppi & 7) * 8, 5);
+
+ if (prio < env->gicv5_cpuif.virt_ppi_hppi.prio) {
+ uint32_t intid = 0;
+
+ intid = FIELD_DP32(intid, INTID, ID, ppi);
+ intid = FIELD_DP32(intid, INTID, TYPE, GICV5_PPI);
+ env->gicv5_cpuif.virt_ppi_hppi.intid = intid;
+ env->gicv5_cpuif.virt_ppi_hppi.prio = prio;
+ }
+ }
+ }
+
+ trace_gicv5_recalc_virt_ppi_hppi(env->gicv5_cpuif.virt_ppi_hppi.intid,
+ env->gicv5_cpuif.virt_ppi_hppi.prio);
+}
+
void gicv5_forward_interrupt(ARMCPU *cpu, GICv5Domain domain)
{
/*
@@ -460,6 +499,7 @@ static void gic_ppi_cactive_write(CPUARMState *env, const ARMCPRegInfo *ri,
if (gicv5_icv_access(env)) {
value &= ~env->gicv5_cpuif.ich_ppi_hvi[ri->opc2 & 1];
env->gicv5_cpuif.ich_ppi_active[ri->opc2 & 1] &= ~value;
+ gic_recalc_virt_ppi_hppi(env);
} else {
uint64_t old = raw_read(env, ri);
raw_write(env, ri, old & ~value);
@@ -473,6 +513,7 @@ static void gic_ppi_sactive_write(CPUARMState *env, const ARMCPRegInfo *ri,
if (gicv5_icv_access(env)) {
value &= ~env->gicv5_cpuif.ich_ppi_hvi[ri->opc2 & 1];
env->gicv5_cpuif.ich_ppi_active[ri->opc2 & 1] |= value;
+ gic_recalc_virt_ppi_hppi(env);
} else {
uint64_t old = raw_read(env, ri);
raw_write(env, ri, old | value);
@@ -502,6 +543,7 @@ static void gic_ppi_cpend_write(CPUARMState *env, const ARMCPRegInfo *ri,
if (gicv5_icv_access(env)) {
value &= ~env->gicv5_cpuif.ich_ppi_hvi[ri->opc2 & 1];
env->gicv5_cpuif.ich_ppi_pend[ri->opc2 & 1] &= ~value;
+ gic_recalc_virt_ppi_hppi(env);
} else {
uint64_t old = raw_read(env, ri);
raw_write(env, ri, old & ~value);
@@ -519,6 +561,7 @@ static void gic_ppi_spend_write(CPUARMState *env, const ARMCPRegInfo *ri,
if (gicv5_icv_access(env)) {
value &= ~env->gicv5_cpuif.ich_ppi_hvi[ri->opc2 & 1];
env->gicv5_cpuif.ich_ppi_pend[ri->opc2 & 1] |= value;
+ gic_recalc_virt_ppi_hppi(env);
} else {
uint64_t old = raw_read(env, ri);
raw_write(env, ri, old | value);
@@ -544,6 +587,7 @@ static void gic_ppi_enable_write(CPUARMState *env, const ARMCPRegInfo *ri,
if (gicv5_icv_access(env)) {
value &= ~env->gicv5_cpuif.ich_ppi_hvi[ri->opc2 & 1];
env->gicv5_cpuif.ich_ppi_enable[ri->opc2 & 1] = value;
+ gic_recalc_virt_ppi_hppi(env);
} else {
raw_write(env, ri, value);
gic_recalc_ppi_hppi(env);
@@ -610,6 +654,7 @@ static void gic_ppi_priority_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t hvi_mask = gic_ppi_prio_hvi_mask(env, idx);
env->gicv5_cpuif.ich_ppi_priority[idx] = value & ~hvi_mask;
+ gic_recalc_virt_ppi_hppi(env);
} else {
raw_write(env, ri, value);
gic_recalc_ppi_hppi(env);
@@ -620,36 +665,42 @@ static void gic_ich_ppi_enable_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
raw_write(env, ri, value);
+ gic_recalc_virt_ppi_hppi(env);
}
static void gic_ich_ppi_pend_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
raw_write(env, ri, value);
+ gic_recalc_virt_ppi_hppi(env);
}
static void gic_ich_ppi_active_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
raw_write(env, ri, value);
+ gic_recalc_virt_ppi_hppi(env);
}
static void gic_ich_ppi_priority_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
raw_write(env, ri, value);
+ gic_recalc_virt_ppi_hppi(env);
}
static void gic_ich_ppi_dvi_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
raw_write(env, ri, value);
+ gic_recalc_virt_ppi_hppi(env);
}
static void gic_ich_ppi_hvi_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
raw_write(env, ri, value);
+ gic_recalc_virt_ppi_hppi(env);
}
static void gic_ich_vctlr_write(CPUARMState *env, const ARMCPRegInfo *ri,
diff --git a/target/arm/tcg/trace-events b/target/arm/tcg/trace-events
index bf1803c8722..da25ec994cc 100644
--- a/target/arm/tcg/trace-events
+++ b/target/arm/tcg/trace-events
@@ -3,6 +3,7 @@
# gicv5-cpuif.c
gicv5_recalc_ppi_hppi(int domain, uint32_t id, uint8_t prio) "domain %d new PPI HPPI id 0x%x prio %u"
+gicv5_recalc_virt_ppi_hppi(uint32_t id, uint8_t prio) "virtual domain new PPI HPPI id 0x%x prio %u"
gicv5_gicr_cdia_fail(int domain, const char *reason) "domain %d CDIA attempt failed: %s"
gicv5_gicr_cdia(int domain, uint32_t id) "domain %d CDIA acknowledge of interrupt 0x%x"
gicv5_cdeoi(int domain) "domain %d CDEOI performing priority drop"
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* Re: [PATCH v2 22/77] target/arm: GICv5 cpuif: Calculate current virtual PPI HPPI
2026-12-03 11:10 ` [PATCH v2 22/77] target/arm: GICv5 cpuif: Calculate current virtual PPI HPPI Peter Maydell
@ 2026-12-04 7:47 ` Manos Pitsidianakis
2026-12-04 9:33 ` Peter Maydell
0 siblings, 1 reply; 99+ messages in thread
From: Manos Pitsidianakis @ 2026-12-04 7:47 UTC (permalink / raw)
To: Peter Maydell, qemu-arm, qemu-devel
Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
On Thu, 03 Dec 2026 13:10, Peter Maydell <peter.maydell@linaro.org> wrote:
>Implement gic_recalc_virt_ppi_hppi(), which calculates the current
>HPPI PPI for the virtual interrupt domain, using similar logic to
>gic_recalc_ppi_hppi(). We call this from everywhere where we update
>the state of the virtual PPIs.
>
>Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>---
> target/arm/cpu.h | 2 ++
> target/arm/tcg/gicv5-cpuif.c | 51 ++++++++++++++++++++++++++++++++++++
> target/arm/tcg/trace-events | 1 +
> 3 files changed, 54 insertions(+)
>
>diff --git a/target/arm/cpu.h b/target/arm/cpu.h
>index 90768300d55..5abfd2c95f7 100644
>--- a/target/arm/cpu.h
>+++ b/target/arm/cpu.h
>@@ -598,6 +598,8 @@ typedef struct CPUArchState {
>
> /* Cached highest-priority pending PPI for each domain */
> GICv5PendingIrq ppi_hppi[NUM_GICV5_DOMAINS];
>+ /* And for the virtual interrupt domain */
>+ GICv5PendingIrq virt_ppi_hppi;
>
> uint64_t ich_apr_el2;
> uint64_t ich_vctlr_el2;
>diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
>index 63364d9189f..910d72ff65e 100644
>--- a/target/arm/tcg/gicv5-cpuif.c
>+++ b/target/arm/tcg/gicv5-cpuif.c
>@@ -298,6 +298,45 @@ static void gic_recalc_ppi_hppi(CPUARMState *env)
> gicv5_update_irq_fiq(env);
> }
>
>+static void gic_recalc_virt_ppi_hppi(CPUARMState *env)
>+{
>+ /*
>+ * Recalculate the HPPI PPI for the virtual interrupt domain: this is
>+ * the best PPI which is enabled, pending and not active.
>+ */
>+ env->gicv5_cpuif.virt_ppi_hppi = GICV5_PENDING_IRQ_NONE;
>+
>+ for (int i = 0; i < ARRAY_SIZE(env->gicv5_cpuif.ich_ppi_active); i++) {
>+ uint64_t en_pend_nact = env->gicv5_cpuif.ich_ppi_enable[i] &
>+ env->gicv5_cpuif.ich_ppi_pend[i] &
>+ ~env->gicv5_cpuif.ich_ppi_active[i];
>+
>+ while (en_pend_nact) {
>+ uint8_t prio;
>+ int ppi;
>+ int bit = ctz64(en_pend_nact);
>+
>+ en_pend_nact &= ~(1ULL << bit);
>+
>+ ppi = i * 64 + bit;
>+ prio = extract64(env->gicv5_cpuif.ich_ppi_priority[ppi / 8],
>+ (ppi & 7) * 8, 5);
>+
>+ if (prio < env->gicv5_cpuif.virt_ppi_hppi.prio) {
>+ uint32_t intid = 0;
>+
>+ intid = FIELD_DP32(intid, INTID, ID, ppi);
>+ intid = FIELD_DP32(intid, INTID, TYPE, GICV5_PPI);
>+ env->gicv5_cpuif.virt_ppi_hppi.intid = intid;
>+ env->gicv5_cpuif.virt_ppi_hppi.prio = prio;
>+ }
>+ }
>+ }
>+
>+ trace_gicv5_recalc_virt_ppi_hppi(env->gicv5_cpuif.virt_ppi_hppi.intid,
>+ env->gicv5_cpuif.virt_ppi_hppi.prio);
>+}
Question: Is this the process described in I_VDZVT or am I looking at
the wrong thing?
>+
> void gicv5_forward_interrupt(ARMCPU *cpu, GICv5Domain domain)
> {
> /*
>@@ -460,6 +499,7 @@ static void gic_ppi_cactive_write(CPUARMState *env, const ARMCPRegInfo *ri,
> if (gicv5_icv_access(env)) {
> value &= ~env->gicv5_cpuif.ich_ppi_hvi[ri->opc2 & 1];
> env->gicv5_cpuif.ich_ppi_active[ri->opc2 & 1] &= ~value;
>+ gic_recalc_virt_ppi_hppi(env);
> } else {
> uint64_t old = raw_read(env, ri);
> raw_write(env, ri, old & ~value);
>@@ -473,6 +513,7 @@ static void gic_ppi_sactive_write(CPUARMState *env, const ARMCPRegInfo *ri,
> if (gicv5_icv_access(env)) {
> value &= ~env->gicv5_cpuif.ich_ppi_hvi[ri->opc2 & 1];
> env->gicv5_cpuif.ich_ppi_active[ri->opc2 & 1] |= value;
>+ gic_recalc_virt_ppi_hppi(env);
> } else {
> uint64_t old = raw_read(env, ri);
> raw_write(env, ri, old | value);
>@@ -502,6 +543,7 @@ static void gic_ppi_cpend_write(CPUARMState *env, const ARMCPRegInfo *ri,
> if (gicv5_icv_access(env)) {
> value &= ~env->gicv5_cpuif.ich_ppi_hvi[ri->opc2 & 1];
> env->gicv5_cpuif.ich_ppi_pend[ri->opc2 & 1] &= ~value;
>+ gic_recalc_virt_ppi_hppi(env);
> } else {
> uint64_t old = raw_read(env, ri);
> raw_write(env, ri, old & ~value);
>@@ -519,6 +561,7 @@ static void gic_ppi_spend_write(CPUARMState *env, const ARMCPRegInfo *ri,
> if (gicv5_icv_access(env)) {
> value &= ~env->gicv5_cpuif.ich_ppi_hvi[ri->opc2 & 1];
> env->gicv5_cpuif.ich_ppi_pend[ri->opc2 & 1] |= value;
>+ gic_recalc_virt_ppi_hppi(env);
> } else {
> uint64_t old = raw_read(env, ri);
> raw_write(env, ri, old | value);
>@@ -544,6 +587,7 @@ static void gic_ppi_enable_write(CPUARMState *env, const ARMCPRegInfo *ri,
> if (gicv5_icv_access(env)) {
> value &= ~env->gicv5_cpuif.ich_ppi_hvi[ri->opc2 & 1];
> env->gicv5_cpuif.ich_ppi_enable[ri->opc2 & 1] = value;
>+ gic_recalc_virt_ppi_hppi(env);
> } else {
> raw_write(env, ri, value);
> gic_recalc_ppi_hppi(env);
>@@ -610,6 +654,7 @@ static void gic_ppi_priority_write(CPUARMState *env, const ARMCPRegInfo *ri,
> uint64_t hvi_mask = gic_ppi_prio_hvi_mask(env, idx);
>
> env->gicv5_cpuif.ich_ppi_priority[idx] = value & ~hvi_mask;
>+ gic_recalc_virt_ppi_hppi(env);
> } else {
> raw_write(env, ri, value);
> gic_recalc_ppi_hppi(env);
>@@ -620,36 +665,42 @@ static void gic_ich_ppi_enable_write(CPUARMState *env, const ARMCPRegInfo *ri,
> uint64_t value)
> {
> raw_write(env, ri, value);
>+ gic_recalc_virt_ppi_hppi(env);
> }
>
> static void gic_ich_ppi_pend_write(CPUARMState *env, const ARMCPRegInfo *ri,
> uint64_t value)
> {
> raw_write(env, ri, value);
>+ gic_recalc_virt_ppi_hppi(env);
> }
>
> static void gic_ich_ppi_active_write(CPUARMState *env, const ARMCPRegInfo *ri,
> uint64_t value)
> {
> raw_write(env, ri, value);
>+ gic_recalc_virt_ppi_hppi(env);
> }
>
> static void gic_ich_ppi_priority_write(CPUARMState *env, const ARMCPRegInfo *ri,
> uint64_t value)
> {
> raw_write(env, ri, value);
>+ gic_recalc_virt_ppi_hppi(env);
> }
>
> static void gic_ich_ppi_dvi_write(CPUARMState *env, const ARMCPRegInfo *ri,
> uint64_t value)
> {
> raw_write(env, ri, value);
>+ gic_recalc_virt_ppi_hppi(env);
> }
>
> static void gic_ich_ppi_hvi_write(CPUARMState *env, const ARMCPRegInfo *ri,
> uint64_t value)
> {
> raw_write(env, ri, value);
>+ gic_recalc_virt_ppi_hppi(env);
> }
>
> static void gic_ich_vctlr_write(CPUARMState *env, const ARMCPRegInfo *ri,
>diff --git a/target/arm/tcg/trace-events b/target/arm/tcg/trace-events
>index bf1803c8722..da25ec994cc 100644
>--- a/target/arm/tcg/trace-events
>+++ b/target/arm/tcg/trace-events
>@@ -3,6 +3,7 @@
>
> # gicv5-cpuif.c
> gicv5_recalc_ppi_hppi(int domain, uint32_t id, uint8_t prio) "domain %d new PPI HPPI id 0x%x prio %u"
>+gicv5_recalc_virt_ppi_hppi(uint32_t id, uint8_t prio) "virtual domain new PPI HPPI id 0x%x prio %u"
> gicv5_gicr_cdia_fail(int domain, const char *reason) "domain %d CDIA attempt failed: %s"
> gicv5_gicr_cdia(int domain, uint32_t id) "domain %d CDIA acknowledge of interrupt 0x%x"
> gicv5_cdeoi(int domain) "domain %d CDEOI performing priority drop"
>--
>2.43.0
>
^ permalink raw reply [flat|nested] 99+ messages in thread* Re: [PATCH v2 22/77] target/arm: GICv5 cpuif: Calculate current virtual PPI HPPI
2026-12-04 7:47 ` Manos Pitsidianakis
@ 2026-12-04 9:33 ` Peter Maydell
0 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-04 9:33 UTC (permalink / raw)
To: Manos Pitsidianakis; +Cc: qemu-arm, qemu-devel, Philippe Mathieu-Daudé
On Fri, 4 Dec 2026 at 07:49, Manos Pitsidianakis
<manos.pitsidianakis@linaro.org> wrote:
>
> On Thu, 03 Dec 2026 13:10, Peter Maydell <peter.maydell@linaro.org> wrote:
> >Implement gic_recalc_virt_ppi_hppi(), which calculates the current
> >HPPI PPI for the virtual interrupt domain, using similar logic to
> >gic_recalc_ppi_hppi(). We call this from everywhere where we update
> >the state of the virtual PPIs.
> >
> >Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> >---
> > target/arm/cpu.h | 2 ++
> > target/arm/tcg/gicv5-cpuif.c | 51 ++++++++++++++++++++++++++++++++++++
> > target/arm/tcg/trace-events | 1 +
> > 3 files changed, 54 insertions(+)
> >
> >diff --git a/target/arm/cpu.h b/target/arm/cpu.h
> >index 90768300d55..5abfd2c95f7 100644
> >--- a/target/arm/cpu.h
> >+++ b/target/arm/cpu.h
> >@@ -598,6 +598,8 @@ typedef struct CPUArchState {
> >
> > /* Cached highest-priority pending PPI for each domain */
> > GICv5PendingIrq ppi_hppi[NUM_GICV5_DOMAINS];
> >+ /* And for the virtual interrupt domain */
> >+ GICv5PendingIrq virt_ppi_hppi;
> >
> > uint64_t ich_apr_el2;
> > uint64_t ich_vctlr_el2;
> >diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
> >index 63364d9189f..910d72ff65e 100644
> >--- a/target/arm/tcg/gicv5-cpuif.c
> >+++ b/target/arm/tcg/gicv5-cpuif.c
> >@@ -298,6 +298,45 @@ static void gic_recalc_ppi_hppi(CPUARMState *env)
> > gicv5_update_irq_fiq(env);
> > }
> >
> >+static void gic_recalc_virt_ppi_hppi(CPUARMState *env)
> >+{
> >+ /*
> >+ * Recalculate the HPPI PPI for the virtual interrupt domain: this is
> >+ * the best PPI which is enabled, pending and not active.
> >+ */
> >+ env->gicv5_cpuif.virt_ppi_hppi = GICV5_PENDING_IRQ_NONE;
> >+
> >+ for (int i = 0; i < ARRAY_SIZE(env->gicv5_cpuif.ich_ppi_active); i++) {
> >+ uint64_t en_pend_nact = env->gicv5_cpuif.ich_ppi_enable[i] &
> >+ env->gicv5_cpuif.ich_ppi_pend[i] &
> >+ ~env->gicv5_cpuif.ich_ppi_active[i];
> >+
> >+ while (en_pend_nact) {
> >+ uint8_t prio;
> >+ int ppi;
> >+ int bit = ctz64(en_pend_nact);
> >+
> >+ en_pend_nact &= ~(1ULL << bit);
> >+
> >+ ppi = i * 64 + bit;
> >+ prio = extract64(env->gicv5_cpuif.ich_ppi_priority[ppi / 8],
> >+ (ppi & 7) * 8, 5);
> >+
> >+ if (prio < env->gicv5_cpuif.virt_ppi_hppi.prio) {
> >+ uint32_t intid = 0;
> >+
> >+ intid = FIELD_DP32(intid, INTID, ID, ppi);
> >+ intid = FIELD_DP32(intid, INTID, TYPE, GICV5_PPI);
> >+ env->gicv5_cpuif.virt_ppi_hppi.intid = intid;
> >+ env->gicv5_cpuif.virt_ppi_hppi.prio = prio;
> >+ }
> >+ }
> >+ }
> >+
> >+ trace_gicv5_recalc_virt_ppi_hppi(env->gicv5_cpuif.virt_ppi_hppi.intid,
> >+ env->gicv5_cpuif.virt_ppi_hppi.prio);
> >+}
>
> Question: Is this the process described in I_VDZVT or am I looking at
> the wrong thing?
This part is calculating the virtual candidate HPPI from the virtual
PPIs, which is one of the inputs into I_VDZVT. The definition of whether
something is a virtual candidate HPPI is D_HCZPD (which is basically
"is it enabled, pending and inactive, and targeted to this vCPU",
and PPIs are always targeted to their own vCPU). R_JMKJM is the rule
that says that the highest priority vPPI wins.
I_VDZVT is covered by the gic_virt_hppi() function (which takes the
value we calculate here plus the vHPPI from the IRS, applies the
priority mask and so on).
thanks
-- PMM
^ permalink raw reply [flat|nested] 99+ messages in thread
* [PATCH v2 23/77] target/arm: GICv5 cpuif: Add virtual support to IRS/cpuif HPPI APIs
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (21 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 22/77] target/arm: GICv5 cpuif: Calculate current virtual PPI HPPI Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-04 7:50 ` Manos Pitsidianakis
2026-12-03 11:10 ` [PATCH v2 24/77] target/arm: GICv5 cpuif: Implement ICV_HPPIR_EL1 Peter Maydell
` (53 subsequent siblings)
76 siblings, 1 reply; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
The APIs between the IRS and the cpuif for the IRS to tell the CPU
that it has a new HPPI candidate and for the CPU to ask the IRS what
its current HPPI candidate is do not currently allow for
virtualization. Extend them to allow the IRS to tell the CPU about
the candidate virtual HPPI and for the CPU to ask about the candidate
virtual HPPI, using an extra 'virtual' parameter.
This commit implements the CPU side of this interface, where a new
virtual HPPI candidate makes us reevaluate our VIRQ/VFIQ status. As
the IRS does not yet implement virtualization, it will always respond
"no interrupt" when asked about the current virtual HPPI candidate.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
include/hw/intc/arm_gicv5_stream.h | 6 ++++--
hw/intc/arm_gicv5.c | 14 +++++++++++---
target/arm/tcg/gicv5-cpuif.c | 11 ++++++++---
3 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/include/hw/intc/arm_gicv5_stream.h b/include/hw/intc/arm_gicv5_stream.h
index 641f3d0f499..21be859a233 100644
--- a/include/hw/intc/arm_gicv5_stream.h
+++ b/include/hw/intc/arm_gicv5_stream.h
@@ -180,6 +180,7 @@ void gicv5_activate(GICv5Common *cs, uint32_t id, GICv5Domain domain,
* gicv5_forward_interrupt
* @cpu: CPU interface to forward interrupt to
* @domain: domain this interrupt is for
+ * @virtual: true if this is a virtual interrupt for the resident VPE
*
* Tell the CPU interface that the highest priority pending interrupt
* that the IRS has available for it has changed. This is the
@@ -198,12 +199,13 @@ void gicv5_activate(GICv5Common *cs, uint32_t id, GICv5Domain domain,
* HPPI info via a function call, so we do not need to pass it across
* here.
*/
-void gicv5_forward_interrupt(ARMCPU *cpu, GICv5Domain domain);
+void gicv5_forward_interrupt(ARMCPU *cpu, GICv5Domain domain, bool virtual);
/**
* gicv5_get_hppi
* @cs: GIC IRS to query
* @domain: interrupt domain to act on
+ * @virtual: true to ask for the virtual HPPI for the resident VPE
* @cpuidx: IRS CPU index of this CPU interface
*
* Ask the IRS for the highest priority pending interrupt that it has
@@ -211,7 +213,7 @@ void gicv5_forward_interrupt(ARMCPU *cpu, GICv5Domain domain);
* protocol is the outstanding interrupt sent with a Forward packet.
*/
GICv5PendingIrq gicv5_get_hppi(GICv5Common *cs, GICv5Domain domain,
- uint32_t cpuidx);
+ bool virtual, uint32_t cpuidx);
/**
* gicv5_deactivate
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index bbe141da1a3..d853e4126ca 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -495,7 +495,7 @@ static void irs_recalc_hppi(GICv5 *s, GICv5Domain domain, uint32_t iaffid)
* the cpuif asks for the current HPPI when it needs it
* - the cpuif does not cache the HPPI on its end
*/
- gicv5_forward_interrupt(cpu, domain);
+ gicv5_forward_interrupt(cpu, domain, false);
}
static void irs_recalc_hppi_all_cpus(GICv5 *s, GICv5Domain domain)
@@ -526,16 +526,24 @@ static void irs_recall_hppis(GICv5 *s, GICv5Domain domain)
for (int i = 0; i < cs->num_cpus; i++) {
s->hppi[domain][i] = GICV5_PENDING_IRQ_NONE;
- gicv5_forward_interrupt(cs->cpus[i], domain);
+ gicv5_forward_interrupt(cs->cpus[i], domain, false);
}
}
GICv5PendingIrq gicv5_get_hppi(GICv5Common *cs, GICv5Domain domain,
- uint32_t cpuidx)
+ bool virtual, uint32_t cpuidx)
{
GICv5 *s = ARM_GICV5(cs);
assert(cpuidx < cs->num_cpus);
+
+ if (virtual) {
+ /*
+ * Until we implement virtualization there is never
+ * an available virtual HPPI candidate.
+ */
+ return GICV5_PENDING_IRQ_NONE;
+ }
return s->hppi[domain][cpuidx];
}
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 910d72ff65e..057b03f56c3 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -170,7 +170,7 @@ static GICv5PendingIrq gic_hppi(CPUARMState *env, GICv5Domain domain)
return GICV5_PENDING_IRQ_NONE;
}
- irs_hppi = gicv5_get_hppi(gic, domain, env->gicv5.cpuidx);
+ irs_hppi = gicv5_get_hppi(gic, domain, false, env->gicv5.cpuidx);
/*
* If the best PPI and the best interrupt from the IRS have the
@@ -337,13 +337,18 @@ static void gic_recalc_virt_ppi_hppi(CPUARMState *env)
env->gicv5_cpuif.virt_ppi_hppi.prio);
}
-void gicv5_forward_interrupt(ARMCPU *cpu, GICv5Domain domain)
+void gicv5_forward_interrupt(ARMCPU *cpu, GICv5Domain domain, bool virtual)
{
/*
* IRS HPPI has changed: recalculate the IRQ/FIQ levels by
* combining the IRS HPPI with the PPI HPPI.
+ * If this is a virtual interrupt, do similarly for VIRQ/VFIQ.
*/
- gicv5_update_irq_fiq(&cpu->env);
+ if (virtual) {
+ /* Here we will eventually update the VIRQ/VFIQ state */
+ } else {
+ gicv5_update_irq_fiq(&cpu->env);
+ }
}
void gicv5_update_ppi_state(CPUARMState *env, int ppi, bool level)
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* Re: [PATCH v2 23/77] target/arm: GICv5 cpuif: Add virtual support to IRS/cpuif HPPI APIs
2026-12-03 11:10 ` [PATCH v2 23/77] target/arm: GICv5 cpuif: Add virtual support to IRS/cpuif HPPI APIs Peter Maydell
@ 2026-12-04 7:50 ` Manos Pitsidianakis
0 siblings, 0 replies; 99+ messages in thread
From: Manos Pitsidianakis @ 2026-12-04 7:50 UTC (permalink / raw)
To: Peter Maydell, qemu-arm, qemu-devel
Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
On Thu, 03 Dec 2026 13:10, Peter Maydell <peter.maydell@linaro.org> wrote:
>The APIs between the IRS and the cpuif for the IRS to tell the CPU
>that it has a new HPPI candidate and for the CPU to ask the IRS what
>its current HPPI candidate is do not currently allow for
>virtualization. Extend them to allow the IRS to tell the CPU about
>the candidate virtual HPPI and for the CPU to ask about the candidate
>virtual HPPI, using an extra 'virtual' parameter.
>
>This commit implements the CPU side of this interface, where a new
>virtual HPPI candidate makes us reevaluate our VIRQ/VFIQ status. As
>the IRS does not yet implement virtualization, it will always respond
>"no interrupt" when asked about the current virtual HPPI candidate.
>
>Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>---
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
> include/hw/intc/arm_gicv5_stream.h | 6 ++++--
> hw/intc/arm_gicv5.c | 14 +++++++++++---
> target/arm/tcg/gicv5-cpuif.c | 11 ++++++++---
> 3 files changed, 23 insertions(+), 8 deletions(-)
>
>diff --git a/include/hw/intc/arm_gicv5_stream.h b/include/hw/intc/arm_gicv5_stream.h
>index 641f3d0f499..21be859a233 100644
>--- a/include/hw/intc/arm_gicv5_stream.h
>+++ b/include/hw/intc/arm_gicv5_stream.h
>@@ -180,6 +180,7 @@ void gicv5_activate(GICv5Common *cs, uint32_t id, GICv5Domain domain,
> * gicv5_forward_interrupt
> * @cpu: CPU interface to forward interrupt to
> * @domain: domain this interrupt is for
>+ * @virtual: true if this is a virtual interrupt for the resident VPE
> *
> * Tell the CPU interface that the highest priority pending interrupt
> * that the IRS has available for it has changed. This is the
>@@ -198,12 +199,13 @@ void gicv5_activate(GICv5Common *cs, uint32_t id, GICv5Domain domain,
> * HPPI info via a function call, so we do not need to pass it across
> * here.
> */
>-void gicv5_forward_interrupt(ARMCPU *cpu, GICv5Domain domain);
>+void gicv5_forward_interrupt(ARMCPU *cpu, GICv5Domain domain, bool virtual);
>
> /**
> * gicv5_get_hppi
> * @cs: GIC IRS to query
> * @domain: interrupt domain to act on
>+ * @virtual: true to ask for the virtual HPPI for the resident VPE
> * @cpuidx: IRS CPU index of this CPU interface
> *
> * Ask the IRS for the highest priority pending interrupt that it has
>@@ -211,7 +213,7 @@ void gicv5_forward_interrupt(ARMCPU *cpu, GICv5Domain domain);
> * protocol is the outstanding interrupt sent with a Forward packet.
> */
> GICv5PendingIrq gicv5_get_hppi(GICv5Common *cs, GICv5Domain domain,
>- uint32_t cpuidx);
>+ bool virtual, uint32_t cpuidx);
>
> /**
> * gicv5_deactivate
>diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
>index bbe141da1a3..d853e4126ca 100644
>--- a/hw/intc/arm_gicv5.c
>+++ b/hw/intc/arm_gicv5.c
>@@ -495,7 +495,7 @@ static void irs_recalc_hppi(GICv5 *s, GICv5Domain domain, uint32_t iaffid)
> * the cpuif asks for the current HPPI when it needs it
> * - the cpuif does not cache the HPPI on its end
> */
>- gicv5_forward_interrupt(cpu, domain);
>+ gicv5_forward_interrupt(cpu, domain, false);
> }
>
> static void irs_recalc_hppi_all_cpus(GICv5 *s, GICv5Domain domain)
>@@ -526,16 +526,24 @@ static void irs_recall_hppis(GICv5 *s, GICv5Domain domain)
>
> for (int i = 0; i < cs->num_cpus; i++) {
> s->hppi[domain][i] = GICV5_PENDING_IRQ_NONE;
>- gicv5_forward_interrupt(cs->cpus[i], domain);
>+ gicv5_forward_interrupt(cs->cpus[i], domain, false);
> }
> }
>
> GICv5PendingIrq gicv5_get_hppi(GICv5Common *cs, GICv5Domain domain,
>- uint32_t cpuidx)
>+ bool virtual, uint32_t cpuidx)
> {
> GICv5 *s = ARM_GICV5(cs);
>
> assert(cpuidx < cs->num_cpus);
>+
>+ if (virtual) {
>+ /*
>+ * Until we implement virtualization there is never
>+ * an available virtual HPPI candidate.
>+ */
>+ return GICV5_PENDING_IRQ_NONE;
>+ }
> return s->hppi[domain][cpuidx];
> }
>
>diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
>index 910d72ff65e..057b03f56c3 100644
>--- a/target/arm/tcg/gicv5-cpuif.c
>+++ b/target/arm/tcg/gicv5-cpuif.c
>@@ -170,7 +170,7 @@ static GICv5PendingIrq gic_hppi(CPUARMState *env, GICv5Domain domain)
> return GICV5_PENDING_IRQ_NONE;
> }
>
>- irs_hppi = gicv5_get_hppi(gic, domain, env->gicv5.cpuidx);
>+ irs_hppi = gicv5_get_hppi(gic, domain, false, env->gicv5.cpuidx);
>
> /*
> * If the best PPI and the best interrupt from the IRS have the
>@@ -337,13 +337,18 @@ static void gic_recalc_virt_ppi_hppi(CPUARMState *env)
> env->gicv5_cpuif.virt_ppi_hppi.prio);
> }
>
>-void gicv5_forward_interrupt(ARMCPU *cpu, GICv5Domain domain)
>+void gicv5_forward_interrupt(ARMCPU *cpu, GICv5Domain domain, bool virtual)
> {
> /*
> * IRS HPPI has changed: recalculate the IRQ/FIQ levels by
> * combining the IRS HPPI with the PPI HPPI.
>+ * If this is a virtual interrupt, do similarly for VIRQ/VFIQ.
> */
>- gicv5_update_irq_fiq(&cpu->env);
>+ if (virtual) {
>+ /* Here we will eventually update the VIRQ/VFIQ state */
>+ } else {
>+ gicv5_update_irq_fiq(&cpu->env);
>+ }
> }
>
> void gicv5_update_ppi_state(CPUARMState *env, int ppi, bool level)
>--
>2.43.0
>
^ permalink raw reply [flat|nested] 99+ messages in thread
* [PATCH v2 24/77] target/arm: GICv5 cpuif: Implement ICV_HPPIR_EL1
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (22 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 23/77] target/arm: GICv5 cpuif: Add virtual support to IRS/cpuif HPPI APIs Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 25/77] target/arm: GICv5 cpuif: Implement gicv5_update_virq_vfiq() Peter Maydell
` (52 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Implement the redirection of ICC_HPPIR_EL1 to the virtual
ICV_HPPIR_EL1 register. This requires us to calculate the highest
priority pending interrupt for the virtual interrupt domain, using a
gic_virt_hppi() function that works in a similar way to the existing
gic_hppi() for the physical interrupt domains.
As we have not yet implemented IRS_CONTEXTR_EL2, we leave a
placeholder "IRS does not have a virtual HPPI candidate"; we will
fill this in later by calling gicv5_get_hppi() when the IRICHPPIDS
bit in that register tells us we should.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/tcg/gicv5-cpuif.c | 73 +++++++++++++++++++++++++++++++++++-
1 file changed, 71 insertions(+), 2 deletions(-)
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 057b03f56c3..56de88a521a 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -70,6 +70,9 @@ FIELD(ICC_HPPIR_EL1, HPPIV, 32, 1)
FIELD(ICH_VMCR_EL2, EN, 0, 1)
FIELD(ICH_VMCR_EL2, VPMR, 27, 5)
+FIELD(ICH_VCTLR_EL2, EN, 0, 1)
+FIELD(ICH_VCTLR_EL2, V3, 1, 1)
+
/*
* We implement 24 bits of interrupt ID, the mandated 5 bits of priority,
* and no legacy GICv3.3 vcpu interface (yet)
@@ -153,6 +156,13 @@ static uint64_t gic_running_prio(CPUARMState *env, GICv5Domain domain)
return hap < 32 ? hap : PRIO_IDLE;
}
+static uint64_t gic_virt_running_prio(CPUARMState *env)
+{
+ /* Return the current virtual running priority */
+ uint64_t hap = ctz64(env->gicv5_cpuif.ich_apr_el2);
+ return hap < 32 ? hap : PRIO_IDLE;
+}
+
static GICv5PendingIrq gic_hppi(CPUARMState *env, GICv5Domain domain)
{
/*
@@ -196,6 +206,59 @@ static GICv5PendingIrq gic_hppi(CPUARMState *env, GICv5Domain domain)
return best;
}
+static GICv5PendingIrq gic_virt_hppi(CPUARMState *env)
+{
+ /*
+ * Return the current highest priority pending interrupt for the
+ * virtual interrupt domain, if it has sufficient priority to
+ * preempt. If there is no interrupt that can preempt we signal
+ * this by returning a struct with prio == PRIO_IDLE.
+ */
+ GICv5PendingIrq best, irs_hppi;
+
+ /*
+ * R_ZKPVN: No virtual HPPI if EL2 is not implemented and enabled
+ * in the Security state identified by SCR_EL3.{NSE,NS}, or if the
+ * enable bits in ICV_CR0_EL1 (stored in VMCR_EL2) or
+ * ICH_VCTLR_EL2 are 0.
+ */
+ if (!arm_is_el2_enabled(env) ||
+ !(env->gicv5_cpuif.ich_vctlr_el2 & R_ICH_VCTLR_EL2_EN_MASK) ||
+ !(env->gicv5_cpuif.ich_vmcr_el2 & R_ICH_VMCR_EL2_EN_MASK)) {
+ return GICV5_PENDING_IRQ_NONE;
+ }
+
+ /*
+ * TODO: When we implement ICH_CONTEXTR_EL2, we need to check
+ * IRICHPPIDS and if it is 0 get the IRS candidate HPPI. For now,
+ * set irs_hppi to "no candidate".
+ */
+ irs_hppi = GICV5_PENDING_IRQ_NONE;
+
+ /*
+ * If the best PPI and the best interrupt from the IRS have the
+ * same priority, it's IMPDEF which we pick (R_VVBPS). We choose
+ * the PPI.
+ */
+ if (env->gicv5_cpuif.virt_ppi_hppi.prio <= irs_hppi.prio) {
+ best = env->gicv5_cpuif.virt_ppi_hppi;
+ } else {
+ best = irs_hppi;
+ }
+
+ /*
+ * D_MSQKF: an interrupt has sufficient priority if its priority
+ * is higher than the current running priority and equal to or
+ * higher than the priority mask.
+ */
+ if (best.prio == PRIO_IDLE ||
+ best.prio > FIELD_EX64(env->gicv5_cpuif.ich_vmcr_el2, ICH_VMCR_EL2, VPMR) ||
+ best.prio >= gic_virt_running_prio(env)) {
+ return GICV5_PENDING_IRQ_NONE;
+ }
+ return best;
+}
+
static void gicv5_update_irq_fiq(CPUARMState *env)
{
/*
@@ -844,8 +907,14 @@ static void gic_icc_pcr_el1_reset(CPUARMState *env, const ARMCPRegInfo *ri)
static uint64_t gic_icc_hppir_el1_read(CPUARMState *env, const ARMCPRegInfo *ri)
{
- GICv5Domain domain = gicv5_logical_domain(env);
- GICv5PendingIrq hppi = gic_hppi(env, domain);
+ GICv5PendingIrq hppi;
+
+ if (gicv5_icv_access(env)) {
+ hppi = gic_virt_hppi(env);
+ } else {
+ GICv5Domain domain = gicv5_logical_domain(env);
+ hppi = gic_hppi(env, domain);
+ }
if (hppi.prio == PRIO_IDLE) {
/* No valid interrupt */
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 25/77] target/arm: GICv5 cpuif: Implement gicv5_update_virq_vfiq()
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (23 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 24/77] target/arm: GICv5 cpuif: Implement ICV_HPPIR_EL1 Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 26/77] target/arm: GICv5 cpuif: Implement ICH_CONTEXTR_EL2 Peter Maydell
` (51 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Implement gicv5_update_virq_vfiq(), the virtual interrupt domain
equivalent of gicv5_update_irq_fiq(). Based on the current highest
priority pending interrupt for the virtual interrupt domain, we
signal either the VIRQ or VINMI lines.
For VIRQ and VINMI it is important that we call arm_cpu_set_irq()
rather than calling cpu_interrupt() and cpu_reset_interrupt()
directly, because arm_cpu_set_irq() handles the logical OR of the
state from the cpuif and the value of HCR_EL2.{VI,VINMI} to produce
the VIRQ/VINMI signals seen by the rest of the CPU.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/tcg/gicv5-cpuif.c | 43 +++++++++++++++++++++++++++++++++++-
target/arm/tcg/trace-events | 1 +
2 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 56de88a521a..88844c332f8 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -310,6 +310,35 @@ static void gicv5_update_irq_fiq(CPUARMState *env)
arm_cpu_set_irq(env_archcpu(env), ARM_CPU_NMI, superpriority);
}
+static void gicv5_update_virq_vfiq(CPUARMState *env)
+{
+ /*
+ * Update whether we are signalling VIRQ or VFIQ based on the
+ * current state of the CPU interface.
+ */
+ GICv5PendingIrq current_hppi;
+ bool virq, superpriority;
+
+ /*
+ * Only the legacy vCPU interface signals VFIQ, and we don't
+ * implement that yet. So we leave ARM_CPU_VFIQ and ARM_CPU_VFNMI
+ * at their default unasserted levels.
+ */
+
+ /*
+ * We signal VIRQ if there is a HPPI of sufficient priority for
+ * the virtual interrupt domain. It has Superpriority if its
+ * priority is 0 (in which case it is CPU_INTERRUPT_VINMI).
+ */
+ current_hppi = gic_virt_hppi(env);
+ superpriority = current_hppi.prio == 0;
+ virq = current_hppi.prio != PRIO_IDLE && !superpriority;
+
+ trace_gicv5_update_virq_vfiq(virq, superpriority);
+ arm_cpu_set_irq(env_archcpu(env), ARM_CPU_VIRQ, virq);
+ arm_cpu_set_irq(env_archcpu(env), ARM_CPU_VINMI, superpriority);
+}
+
static void gic_recalc_ppi_hppi(CPUARMState *env)
{
/*
@@ -398,6 +427,8 @@ static void gic_recalc_virt_ppi_hppi(CPUARMState *env)
trace_gicv5_recalc_virt_ppi_hppi(env->gicv5_cpuif.virt_ppi_hppi.intid,
env->gicv5_cpuif.virt_ppi_hppi.prio);
+
+ gicv5_update_virq_vfiq(env);
}
void gicv5_forward_interrupt(ARMCPU *cpu, GICv5Domain domain, bool virtual)
@@ -408,7 +439,12 @@ void gicv5_forward_interrupt(ARMCPU *cpu, GICv5Domain domain, bool virtual)
* If this is a virtual interrupt, do similarly for VIRQ/VFIQ.
*/
if (virtual) {
- /* Here we will eventually update the VIRQ/VFIQ state */
+ /*
+ * We don't need to check here for a mismatch between domain
+ * and the domain of the resident VPE, because that will
+ * be checked when gic_virt_hppi() calls back into the IRS.
+ */
+ gicv5_update_virq_vfiq(&cpu->env);
} else {
gicv5_update_irq_fiq(&cpu->env);
}
@@ -775,12 +811,14 @@ static void gic_ich_vctlr_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
raw_write(env, ri, value);
+ gicv5_update_virq_vfiq(env);
}
static void gic_ich_vmcr_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
raw_write(env, ri, value);
+ gicv5_update_virq_vfiq(env);
}
/*
@@ -798,6 +836,7 @@ static void gic_icc_apr_el1_write(CPUARMState *env, const ARMCPRegInfo *ri,
if (gicv5_icv_access(env)) {
env->gicv5_cpuif.ich_apr_el2 = value;
+ gicv5_update_virq_vfiq(env);
} else {
GICv5Domain domain = gicv5_logical_domain(env);
env->gicv5_cpuif.icc_apr[domain] = value;
@@ -844,6 +883,7 @@ static void gic_icc_cr0_el1_write(CPUARMState *env, const ARMCPRegInfo *ri,
vmcr = FIELD_DP64(vmcr, ICH_VMCR_EL2, EN,
FIELD_EX64(value, ICC_CR0, EN));
env->gicv5_cpuif.ich_vmcr_el2 = vmcr;
+ gicv5_update_virq_vfiq(env);
} else {
/*
* For our implementation the link to the IRI is always connected,
@@ -889,6 +929,7 @@ static void gic_icc_pcr_el1_write(CPUARMState *env, const ARMCPRegInfo *ri,
vmcr = FIELD_DP64(vmcr, ICH_VMCR_EL2, VPMR,
FIELD_EX64(value, ICC_PCR, PRIORITY));
env->gicv5_cpuif.ich_vmcr_el2 = vmcr;
+ gicv5_update_virq_vfiq(env);
} else {
GICv5Domain domain = gicv5_logical_domain(env);
diff --git a/target/arm/tcg/trace-events b/target/arm/tcg/trace-events
index da25ec994cc..71f1369fcda 100644
--- a/target/arm/tcg/trace-events
+++ b/target/arm/tcg/trace-events
@@ -9,4 +9,5 @@ gicv5_gicr_cdia(int domain, uint32_t id) "domain %d CDIA acknowledge of interrup
gicv5_cdeoi(int domain) "domain %d CDEOI performing priority drop"
gicv5_cddi(int domain, uint32_t id) "domain %d CDDI deactivating interrupt ID 0x%x"
gicv5_update_irq_fiq(bool irq, bool fiq, bool nmi) "now IRQ %d FIQ %d NMI %d"
+gicv5_update_virq_vfiq(bool virq, bool vinmi) "now VIRQ %d VINMI %d"
gicv5_update_ppi_state(int ppi, bool level) "PPI %d source level now %d"
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 26/77] target/arm: GICv5 cpuif: Implement ICH_CONTEXTR_EL2
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (24 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 25/77] target/arm: GICv5 cpuif: Implement gicv5_update_virq_vfiq() Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 27/77] target/arm: GICv5 cpuif: ask the GIC for the virtual HPPI Peter Maydell
` (50 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
The ICH_CONTEXTR_EL2 register is how the hypervisor tells the GICv5
to make a VCPU for a VM resident on a CPU, so that the IRS will
forward virtual interrupts for that VCPU to this CPU. We implement
this similarly to the GICv5 stream protocol, which uses a
SetResident command to tell the IRS to make the VCPU resident.
This will always fail until we have implemented the IRS's
end of virtualization support.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
include/hw/intc/arm_gicv5_stream.h | 30 +++++++
target/arm/cpu.h | 1 +
hw/intc/arm_gicv5.c | 8 ++
target/arm/tcg/gicv5-cpuif.c | 121 +++++++++++++++++++++++++++++
target/arm/tcg/trace-events | 1 +
5 files changed, 161 insertions(+)
diff --git a/include/hw/intc/arm_gicv5_stream.h b/include/hw/intc/arm_gicv5_stream.h
index 21be859a233..162d55a8e6b 100644
--- a/include/hw/intc/arm_gicv5_stream.h
+++ b/include/hw/intc/arm_gicv5_stream.h
@@ -229,4 +229,34 @@ GICv5PendingIrq gicv5_get_hppi(GICv5Common *cs, GICv5Domain domain,
void gicv5_deactivate(GICv5Common *cs, uint32_t id, GICv5Domain domain,
GICv5IntType type, bool virtual);
+/**
+ * gicv5_set_resident
+ * @cs: GIC IRS to send command to
+ * @domain: interrupt domain to act on
+ * @valid: true if setting resident VPE, false to clear it
+ * @vpeid: identifier of the VPE to make resident
+ * @db: true to request a doorbell
+ * @dbpm: doorbell priority mask
+ * @vmid: Virtual Machine identifier
+ * @cpuidx: IRS CPU index of this CPU interface
+ *
+ * Tell the IRS to make the specified VPE resident for this CPU. This
+ * corresponds approximately to the stream protocol SetResident command.
+ *
+ * Returns the Fault state: false if the SetResident operation
+ * succeeded, true if the VPE could not be made resident. Clearing the
+ * VPE always succeeds and returns false.
+ *
+ * For QEMU this is a synchronous operation: the function does not return
+ * until the IRS has either succeeded or failed in making the VPE resident
+ * (including identifying whether there is a pending virtual interrupt for
+ * the VPE and forwarding it by calling gicv5_forward_interrupt() if so).
+ *
+ * Unlike the stream protocol (where the IRS knows which CPU it is talking
+ * to), we have to pass the cpuidx to tell the IRS which CPU we are.
+ */
+bool gicv5_set_resident(GICv5Common *cs, GICv5Domain domain, bool valid,
+ uint32_t vpeid, bool db, uint8_t dbpm, uint32_t vmid,
+ uint32_t cpuidx);
+
#endif
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index 5abfd2c95f7..21f9865dd8d 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -601,6 +601,7 @@ typedef struct CPUArchState {
/* And for the virtual interrupt domain */
GICv5PendingIrq virt_ppi_hppi;
+ uint64_t ich_contextr_el2;
uint64_t ich_apr_el2;
uint64_t ich_vctlr_el2;
uint64_t ich_vmcr_el2;
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index d853e4126ca..f25dbd7b426 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -1256,6 +1256,14 @@ txfail:
"physical address 0x" HWADDR_FMT_plx "\n", intid, l1_addr);
}
+bool gicv5_set_resident(GICv5Common *cs, GICv5Domain domain, bool valid,
+ uint32_t vpeid, bool db, uint8_t dbpm, uint32_t vmid,
+ uint32_t cpuidx)
+{
+ /* Until we implement virtualization, SetResident always fails */
+ return true;
+}
+
/* Data we need to pass through to irs_clean_lpi_cache_entry() */
typedef struct CleanLPICacheUserData {
GICv5Common *cs;
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 88844c332f8..e862afa966f 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -73,6 +73,14 @@ FIELD(ICH_VMCR_EL2, VPMR, 27, 5)
FIELD(ICH_VCTLR_EL2, EN, 0, 1)
FIELD(ICH_VCTLR_EL2, V3, 1, 1)
+FIELD(ICH_CONTEXTR_EL2, VM, 0, 16)
+FIELD(ICH_CONTEXTR_EL2, VPE, 32, 16)
+FIELD(ICH_CONTEXTR_EL2, DBPM, 55, 5)
+FIELD(ICH_CONTEXTR_EL2, DB, 60, 1)
+FIELD(ICH_CONTEXTR_EL2, IRICHPPIDIS, 61, 1)
+FIELD(ICH_CONTEXTR_EL2, F, 62, 1)
+FIELD(ICH_CONTEXTR_EL2, V, 63, 1)
+
/*
* We implement 24 bits of interrupt ID, the mandated 5 bits of priority,
* and no legacy GICv3.3 vcpu interface (yet)
@@ -821,6 +829,110 @@ static void gic_ich_vmcr_write(CPUARMState *env, const ARMCPRegInfo *ri,
gicv5_update_virq_vfiq(env);
}
+static void gic_ich_contextr_write(CPUARMState *env, const ARMCPRegInfo *ri,
+ uint64_t value)
+{
+ GICv5Common *gic = gicv5_get_gic(env);
+ GICv5Domain domain = gicv5_logical_domain(env);
+ bool valid = FIELD_EX64(value, ICH_CONTEXTR_EL2, V);
+ uint32_t vpe = FIELD_EX64(value, ICH_CONTEXTR_EL2, VPE);
+ bool db = FIELD_EX64(value, ICH_CONTEXTR_EL2, DB);
+ uint8_t dbpm = FIELD_EX64(value, ICH_CONTEXTR_EL2, DBPM);
+ uint32_t vm = FIELD_EX64(value, ICH_CONTEXTR_EL2, VM);
+ uint32_t cpuidx = env->gicv5.cpuidx;
+ bool fault;
+ uint64_t oldval = env->gicv5_cpuif.ich_contextr_el2;
+ bool vm_vpe_changed = (oldval ^ value) & (R_ICH_CONTEXTR_EL2_VM_MASK |
+ R_ICH_CONTEXTR_EL2_VPE_MASK);
+ bool valid_changed = (oldval ^ value) & R_ICH_CONTEXTR_EL2_V_MASK;
+
+ /*
+ * DB and DBPM are RAZ: they are write-only fields that have
+ * an effect when V is changed from 1 to 0.
+ */
+ value &= ~(R_ICH_CONTEXTR_EL2_DB_MASK | R_ICH_CONTEXTR_EL2_DBPM_MASK);
+
+ raw_write(env, ri, value);
+
+ trace_gicv5_ich_contextr_write(cpuidx, value);
+
+ /*
+ * Changing V definitely causes us to make a new VPE resident, or
+ * remove the old one.
+ *
+ * Changing VPE or VM while V=1 is CONSTRAINED UNPREDICTABLE
+ * (R_VFKHN): we choose to make the new VPE resident so that we
+ * can trust that the information we have in the register matches
+ * what the IRS thinks the resident VPE is.
+ *
+ * For writes that don't trigger a change of resident VPE, we only
+ * need to update our copy of the register, and recalculate
+ * interrupts if IIRICHPPIDIS changed.
+ *
+ * If we do change the resident VPE, the interrupt recalculation
+ * will happen when the IRS calls gicv5_forward_interrupt().
+ */
+ if (!(valid_changed || (valid && vm_vpe_changed))) {
+ if ((oldval ^ value) & R_ICH_CONTEXTR_EL2_IRICHPPIDIS_MASK) {
+ gicv5_update_virq_vfiq(env);
+ }
+ return;
+ }
+
+ if (valid) {
+ /* Doorbell info is only relevant when clearing the VPE */
+ dbpm = 0;
+ db = false;
+ } else {
+ /* The IRS knows what the VPE is so we don't need to tell it */
+ vm = 0;
+ vpe = 0;
+ }
+
+ fault = gicv5_set_resident(gic, domain, valid, vpe, db, dbpm, vm, cpuidx);
+
+ if (valid) {
+ /*
+ * We only update F for a VPE set, not a clear.
+ *
+ * On a failure, it is CONSTRAINED UNPREDICTABLE whether V
+ * reads as 0 or 1 (R_NHCGW); we choose to set it to 0 so we
+ * can reliably use it to track whether a VPE is resident. We
+ * use this for instance in GIC VDPEND: we trust the V and VM
+ * fields to be accurate.
+ */
+ value = env->gicv5_cpuif.ich_contextr_el2;
+ value = FIELD_DP64(value, ICH_CONTEXTR_EL2, F, fault);
+ if (fault) {
+ value = FIELD_DP64(value, ICH_CONTEXTR_EL2, V, 0);
+ }
+ env->gicv5_cpuif.ich_contextr_el2 = value;
+ }
+}
+
+static void gic_ich_contextr_reset(CPUARMState *env, const ARMCPRegInfo *ri)
+{
+ /*
+ * This register resets to zero, which includes telling the IRS
+ * that there is no longer a resident VPE for it.
+ *
+ * It doesn't matter if the domain we pass here doesn't match the
+ * domain of the VM/VPE: as with the GIC stream interface (see
+ * rule R_PYWKM) our IRS ignores the mismatch for a SetResident
+ * request with valid = false.
+ *
+ * As this is a reset fn we may get here before the GIC pointer
+ * has been set up yet, so unusually we need to check for NULL>
+ */
+ raw_write(env, ri, 0);
+ GICv5Common *gic = gicv5_get_gic(env);
+
+ if (gic) {
+ gicv5_set_resident(gic, gicv5_logical_domain(env),
+ false, 0, false, 0, 0, env->gicv5.cpuidx);
+ }
+}
+
/*
* ICC_APR_EL1 is banked and reads/writes as the version for the
* current logical interrupt domain.
@@ -1500,6 +1612,15 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
.fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_vctlr_el2),
.writefn = gic_ich_vctlr_write,
},
+ { .name = "ICH_CONTEXTR_EL2", .state = ARM_CP_STATE_AA64,
+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 11, .opc2 = 6,
+ .access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .nv2_redirect_offset = 0xb08,
+ .accessfn = access_gicv5_ich_reg,
+ .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ich_contextr_el2),
+ .writefn = gic_ich_contextr_write,
+ .resetfn = gic_ich_contextr_reset,
+ },
{ .name = "ICH_VMCR_EL2", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 4, .crn = 12, .crm = 11, .opc2 = 7,
.access = PL2_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW,
diff --git a/target/arm/tcg/trace-events b/target/arm/tcg/trace-events
index 71f1369fcda..75f40c44f26 100644
--- a/target/arm/tcg/trace-events
+++ b/target/arm/tcg/trace-events
@@ -11,3 +11,4 @@ gicv5_cddi(int domain, uint32_t id) "domain %d CDDI deactivating interrupt ID 0x
gicv5_update_irq_fiq(bool irq, bool fiq, bool nmi) "now IRQ %d FIQ %d NMI %d"
gicv5_update_virq_vfiq(bool virq, bool vinmi) "now VIRQ %d VINMI %d"
gicv5_update_ppi_state(int ppi, bool level) "PPI %d source level now %d"
+gicv5_ich_contextr_write(uint32_t cpuidx, uint64_t value) "cpuidx %d ICH_CONTEXTR_WRITE 0x%" PRIx64
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 27/77] target/arm: GICv5 cpuif: ask the GIC for the virtual HPPI
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (25 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 26/77] target/arm: GICv5 cpuif: Implement ICH_CONTEXTR_EL2 Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-04 7:52 ` Manos Pitsidianakis
2026-12-03 11:10 ` [PATCH v2 28/77] target/arm: GICv5 cpuif: Handle LD/VD insns when setting domain/virtual args Peter Maydell
` (49 subsequent siblings)
76 siblings, 1 reply; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Now that we have an implementation of ICH_CONTEXTR_EL2 and the API to
the IRS provides a way to query the virtual HPPI candidate, we can
fix the TODO remark in gic_virt_hppi() by making the cpuif ask the
IRS for its virtual HPPI candidate.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/tcg/gicv5-cpuif.c | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index e862afa966f..6d90f3133c9 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -214,6 +214,19 @@ static GICv5PendingIrq gic_hppi(CPUARMState *env, GICv5Domain domain)
return best;
}
+static bool gic_get_irs_virt_hppi(CPUARMState *env)
+{
+ /*
+ * Return true if we should ask the IRS for its candidate virtual
+ * HPPI. We do this only if we have a resident VPE and are not
+ * ignoring IRS candidate HPPIs because of IRICHPPIDIS.
+ */
+ uint64_t ich_contextr_el2 = env->gicv5_cpuif.ich_contextr_el2;
+
+ return (ich_contextr_el2 & R_ICH_CONTEXTR_EL2_V_MASK) &&
+ !(ich_contextr_el2 & R_ICH_CONTEXTR_EL2_IRICHPPIDIS_MASK);
+}
+
static GICv5PendingIrq gic_virt_hppi(CPUARMState *env)
{
/*
@@ -236,12 +249,14 @@ static GICv5PendingIrq gic_virt_hppi(CPUARMState *env)
return GICV5_PENDING_IRQ_NONE;
}
- /*
- * TODO: When we implement ICH_CONTEXTR_EL2, we need to check
- * IRICHPPIDS and if it is 0 get the IRS candidate HPPI. For now,
- * set irs_hppi to "no candidate".
- */
- irs_hppi = GICV5_PENDING_IRQ_NONE;
+ if (gic_get_irs_virt_hppi(env)) {
+ GICv5Common *gic = gicv5_get_gic(env);
+ GICv5Domain domain = gicv5_logical_domain(env);
+
+ irs_hppi = gicv5_get_hppi(gic, domain, true, env->gicv5.cpuidx);
+ } else {
+ irs_hppi = GICV5_PENDING_IRQ_NONE;
+ }
/*
* If the best PPI and the best interrupt from the IRS have the
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* Re: [PATCH v2 27/77] target/arm: GICv5 cpuif: ask the GIC for the virtual HPPI
2026-12-03 11:10 ` [PATCH v2 27/77] target/arm: GICv5 cpuif: ask the GIC for the virtual HPPI Peter Maydell
@ 2026-12-04 7:52 ` Manos Pitsidianakis
2026-12-04 9:37 ` Peter Maydell
0 siblings, 1 reply; 99+ messages in thread
From: Manos Pitsidianakis @ 2026-12-04 7:52 UTC (permalink / raw)
To: Peter Maydell, qemu-arm, qemu-devel
Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
On Thu, 03 Dec 2026 13:10, Peter Maydell <peter.maydell@linaro.org> wrote:
>Now that we have an implementation of ICH_CONTEXTR_EL2 and the API to
>the IRS provides a way to query the virtual HPPI candidate, we can
>fix the TODO remark in gic_virt_hppi() by making the cpuif ask the
>IRS for its virtual HPPI candidate.
>
>Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>---
> target/arm/tcg/gicv5-cpuif.c | 27 +++++++++++++++++++++------
> 1 file changed, 21 insertions(+), 6 deletions(-)
>
>diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
>index e862afa966f..6d90f3133c9 100644
>--- a/target/arm/tcg/gicv5-cpuif.c
>+++ b/target/arm/tcg/gicv5-cpuif.c
>@@ -214,6 +214,19 @@ static GICv5PendingIrq gic_hppi(CPUARMState *env, GICv5Domain domain)
> return best;
> }
>
>+static bool gic_get_irs_virt_hppi(CPUARMState *env)
>+{
>+ /*
>+ * Return true if we should ask the IRS for its candidate virtual
>+ * HPPI. We do this only if we have a resident VPE and are not
>+ * ignoring IRS candidate HPPIs because of IRICHPPIDIS.
>+ */
You could move the doc comment above the function instead of in the
body.
Regardless:
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
>+ uint64_t ich_contextr_el2 = env->gicv5_cpuif.ich_contextr_el2;
>+
>+ return (ich_contextr_el2 & R_ICH_CONTEXTR_EL2_V_MASK) &&
>+ !(ich_contextr_el2 & R_ICH_CONTEXTR_EL2_IRICHPPIDIS_MASK);
>+}
>+
> static GICv5PendingIrq gic_virt_hppi(CPUARMState *env)
> {
> /*
>@@ -236,12 +249,14 @@ static GICv5PendingIrq gic_virt_hppi(CPUARMState *env)
> return GICV5_PENDING_IRQ_NONE;
> }
>
>- /*
>- * TODO: When we implement ICH_CONTEXTR_EL2, we need to check
>- * IRICHPPIDS and if it is 0 get the IRS candidate HPPI. For now,
>- * set irs_hppi to "no candidate".
>- */
>- irs_hppi = GICV5_PENDING_IRQ_NONE;
>+ if (gic_get_irs_virt_hppi(env)) {
>+ GICv5Common *gic = gicv5_get_gic(env);
>+ GICv5Domain domain = gicv5_logical_domain(env);
>+
>+ irs_hppi = gicv5_get_hppi(gic, domain, true, env->gicv5.cpuidx);
>+ } else {
>+ irs_hppi = GICV5_PENDING_IRQ_NONE;
>+ }
>
> /*
> * If the best PPI and the best interrupt from the IRS have the
>--
>2.43.0
>
^ permalink raw reply [flat|nested] 99+ messages in thread* Re: [PATCH v2 27/77] target/arm: GICv5 cpuif: ask the GIC for the virtual HPPI
2026-12-04 7:52 ` Manos Pitsidianakis
@ 2026-12-04 9:37 ` Peter Maydell
0 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-04 9:37 UTC (permalink / raw)
To: Manos Pitsidianakis; +Cc: qemu-arm, qemu-devel, Philippe Mathieu-Daudé
On Fri, 4 Dec 2026 at 07:53, Manos Pitsidianakis
<manos.pitsidianakis@linaro.org> wrote:
>
> On Thu, 03 Dec 2026 13:10, Peter Maydell <peter.maydell@linaro.org> wrote:
> >Now that we have an implementation of ICH_CONTEXTR_EL2 and the API to
> >the IRS provides a way to query the virtual HPPI candidate, we can
> >fix the TODO remark in gic_virt_hppi() by making the cpuif ask the
> >IRS for its virtual HPPI candidate.
> >
> >Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> >---
> > target/arm/tcg/gicv5-cpuif.c | 27 +++++++++++++++++++++------
> > 1 file changed, 21 insertions(+), 6 deletions(-)
> >
> >diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
> >index e862afa966f..6d90f3133c9 100644
> >--- a/target/arm/tcg/gicv5-cpuif.c
> >+++ b/target/arm/tcg/gicv5-cpuif.c
> >@@ -214,6 +214,19 @@ static GICv5PendingIrq gic_hppi(CPUARMState *env, GICv5Domain domain)
> > return best;
> > }
> >
> >+static bool gic_get_irs_virt_hppi(CPUARMState *env)
> >+{
> >+ /*
> >+ * Return true if we should ask the IRS for its candidate virtual
> >+ * HPPI. We do this only if we have a resident VPE and are not
> >+ * ignoring IRS candidate HPPIs because of IRICHPPIDIS.
> >+ */
>
> You could move the doc comment above the function instead of in the
> body.
This is part of a personal style quirk I have, where for
file-local functions I put the "what does this do" comment
inside the function, and as an informal description.
Functions with a wider scope get doc-comment-format comments
with their prototype. You'll find a lot of this style all
over the Arm parts of QEMU by now :-)
thanks
-- PMM
^ permalink raw reply [flat|nested] 99+ messages in thread
* [PATCH v2 28/77] target/arm: GICv5 cpuif: Handle LD/VD insns when setting domain/virtual args
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (26 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 27/77] target/arm: GICv5 cpuif: ask the GIC for the virtual HPPI Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 29/77] target/arm: GICv5 cpuif: Handle virtual interrupts for GIC CDEOI Peter Maydell
` (48 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
GIC system instructions come in several families where the prefix
of the name indicates which interrupt domain they operate on:
- LD* commands (opc1 == 6) operate on the logical interrupt domain.
- VD* commands (opc1 == 4) operate on the virtual interrupt domain,
which is the domain of the current resident VM, which is the same
as the logical interrupt domain but with the virtual flag set.
- CD* commands (opc1 == 0) operate on the current domain, which is
the virtual one if ICC accesses redirect to ICV, and the current
physical interrupt domain otherwise.
The actual operation of the command in each case is the same apart
from the domain/virtual parameter selection.
Currently we hardcode "virtual = false, domain = current physical
interrupt domain" in our writefns for the system insns, which is
only correct for the CD* commands when virtualization is not
enabled.
Generalize our code for implementing the various GIC system insns so
they call a new function gicv5_domain_for_insn() which sets the
domain and virtual parameters based on the insn family (which can be
determined from the system insn's opc1 field) and whether the virtual
CPU interface is enabled. This will make the CD commands work
correctly in the virtual CPU interface, and will let us use the same
writefns for the LD and VD insns as we do for the CD insns.
This change is all we need for the CD* commands to handle the virtual
interrupt domain correctly in most cases; the commands which don't
simply pass the argument through to the IRS (CDEOI, CDDI, CDIA,
CDNMIA) need further changes which we will handle in the following
commits. VDPEND also needs adjustment as it has an extra argument
from the guest to specify the VM (making it the only LD* or VD*
command that has a different field layout from the CD* version).
(The IRS will currently reject any commands with virtual=true;
we add virtualization support to the IRS later in the series.)
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/tcg/gicv5-cpuif.c | 71 +++++++++++++++++++++++++++---------
1 file changed, 53 insertions(+), 18 deletions(-)
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 6d90f3133c9..9fc24c62789 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -154,6 +154,39 @@ static GICv5Domain gicv5_current_phys_domain(CPUARMState *env)
return gicv5_logical_domain(env);
}
+static GICv5Domain gicv5_domain_for_insn(CPUARMState *env,
+ const ARMCPRegInfo *ri,
+ bool *virtual)
+{
+ /*
+ * Return the domain and virtual flag to use when GIC system insns
+ * result in commands to the IRS.
+ *
+ * GIC system insns come in several families where the prefix of
+ * the name indicates which interrupt domain they operate on:
+ *
+ * LD* commands (opc1 == 6) operate on the logical interrupt domain.
+ * VD* commands (opc1 == 4) operate on the virtual interrupt domain,
+ * which is the domain of the current resident VM, which is the
+ * the logical interrupt domain but with the virtual flag set.
+ * CD* commands (opc1 == 0) operate on the current domain, which is
+ * the virtual one if ICC accesses redirect to ICV, and the
+ * current physical interrupt domain otherwise.
+ *
+ * Returns the domain to use, and updates *virtual to return
+ * whether this is the virtual interrupt domain. The caller can
+ * then pass domain and virtual directly to the IRS functions.
+ */
+ bool logical = ri->opc1 == 6;
+
+ *virtual = ri->opc1 == 4 || gicv5_icv_access(env);
+
+ if (logical || *virtual) {
+ return gicv5_logical_domain(env);
+ }
+ return gicv5_current_phys_domain(env);
+}
+
static uint64_t gic_running_prio(CPUARMState *env, GICv5Domain domain)
{
/*
@@ -507,8 +540,8 @@ static void gic_cddis_write(CPUARMState *env, const ARMCPRegInfo *ri,
GICv5Common *gic = gicv5_get_gic(env);
GICv5IntType type = FIELD_EX64(value, GIC_CDDIS, TYPE);
uint32_t id = FIELD_EX64(value, GIC_CDDIS, ID);
- bool virtual = false;
- GICv5Domain domain = gicv5_current_phys_domain(env);
+ bool virtual;
+ GICv5Domain domain = gicv5_domain_for_insn(env, ri, &virtual);
gicv5_set_enabled(gic, id, false, domain, type, virtual);
}
@@ -519,8 +552,8 @@ static void gic_cden_write(CPUARMState *env, const ARMCPRegInfo *ri,
GICv5Common *gic = gicv5_get_gic(env);
GICv5IntType type = FIELD_EX64(value, GIC_CDEN, TYPE);
uint32_t id = FIELD_EX64(value, GIC_CDEN, ID);
- bool virtual = false;
- GICv5Domain domain = gicv5_current_phys_domain(env);
+ bool virtual;
+ GICv5Domain domain = gicv5_domain_for_insn(env, ri, &virtual);
gicv5_set_enabled(gic, id, true, domain, type, virtual);
}
@@ -532,8 +565,8 @@ static void gic_cdpri_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint8_t priority = FIELD_EX64(value, GIC_CDPRI, PRIORITY);
GICv5IntType type = FIELD_EX64(value, GIC_CDPRI, TYPE);
uint32_t id = FIELD_EX64(value, GIC_CDPRI, ID);
- bool virtual = false;
- GICv5Domain domain = gicv5_current_phys_domain(env);
+ bool virtual;
+ GICv5Domain domain = gicv5_domain_for_insn(env, ri, &virtual);
gicv5_set_priority(gic, id, priority, domain, type, virtual);
}
@@ -546,8 +579,8 @@ static void gic_cdaff_write(CPUARMState *env, const ARMCPRegInfo *ri,
GICv5RoutingMode irm = FIELD_EX64(value, GIC_CDAFF, IRM);
GICv5IntType type = FIELD_EX64(value, GIC_CDAFF, TYPE);
uint32_t id = FIELD_EX64(value, GIC_CDAFF, ID);
- bool virtual = false;
- GICv5Domain domain = gicv5_current_phys_domain(env);
+ bool virtual;
+ GICv5Domain domain = gicv5_domain_for_insn(env, ri, &virtual);
gicv5_set_target(gic, id, iaffid, irm, domain, type, virtual);
}
@@ -559,8 +592,8 @@ static void gic_cdpend_write(CPUARMState *env, const ARMCPRegInfo *ri,
bool pending = FIELD_EX64(value, GIC_CDPEND, PENDING);
GICv5IntType type = FIELD_EX64(value, GIC_CDPEND, TYPE);
uint32_t id = FIELD_EX64(value, GIC_CDPEND, ID);
- bool virtual = false;
- GICv5Domain domain = gicv5_current_phys_domain(env);
+ bool virtual;
+ GICv5Domain domain = gicv5_domain_for_insn(env, ri, &virtual);
gicv5_set_pending(gic, id, pending, domain, type, virtual);
}
@@ -571,8 +604,8 @@ static void gic_cdrcfg_write(CPUARMState *env, const ARMCPRegInfo *ri,
GICv5Common *gic = gicv5_get_gic(env);
GICv5IntType type = FIELD_EX64(value, GIC_CDRCFG, TYPE);
uint32_t id = FIELD_EX64(value, GIC_CDRCFG, ID);
- bool virtual = false;
- GICv5Domain domain = gicv5_current_phys_domain(env);
+ bool virtual;
+ GICv5Domain domain = gicv5_domain_for_insn(env, ri, &virtual);
env->gicv5_cpuif.icc_icsr_el1 =
gicv5_request_config(gic, id, domain, type, virtual);
@@ -585,8 +618,8 @@ static void gic_cdhm_write(CPUARMState *env, const ARMCPRegInfo *ri,
GICv5HandlingMode hm = FIELD_EX64(value, GIC_CDHM, HM);
GICv5IntType type = FIELD_EX64(value, GIC_CDAFF, TYPE);
uint32_t id = FIELD_EX64(value, GIC_CDAFF, ID);
- bool virtual = false;
- GICv5Domain domain = gicv5_current_phys_domain(env);
+ bool virtual;
+ GICv5Domain domain = gicv5_domain_for_insn(env, ri, &virtual);
gicv5_set_handling(gic, id, hm, domain, type, virtual);
}
@@ -1108,7 +1141,8 @@ static uint64_t gicr_cdia_read(CPUARMState *env, const ARMCPRegInfo *ri)
{
/* Acknowledge HPPI in the current interrupt domain */
GICv5Common *gic = gicv5_get_gic(env);
- GICv5Domain domain = gicv5_current_phys_domain(env);
+ bool virtual;
+ GICv5Domain domain = gicv5_domain_for_insn(env, ri, &virtual);
GICv5PendingIrq hppi = gic_hppi(env, domain);
GICv5IntType type = FIELD_EX64(hppi.intid, INTID, TYPE);
uint32_t id = FIELD_EX64(hppi.intid, INTID, ID);
@@ -1185,7 +1219,8 @@ static void gic_cdeoi_write(CPUARMState *env, const ARMCPRegInfo *ri,
* Perform Priority Drop in the current interrupt domain.
* This is just clearing the lowest set bit in the APR.
*/
- GICv5Domain domain = gicv5_current_phys_domain(env);
+ bool virtual;
+ GICv5Domain domain = gicv5_domain_for_insn(env, ri, &virtual);
uint64_t *apr = &env->gicv5_cpuif.icc_apr[domain];
trace_gicv5_cdeoi(domain);
@@ -1203,10 +1238,10 @@ static void gic_cddi_write(CPUARMState *env, const ARMCPRegInfo *ri,
* current interrupt domain.
*/
GICv5Common *gic = gicv5_get_gic(env);
- GICv5Domain domain = gicv5_current_phys_domain(env);
+ bool virtual;
+ GICv5Domain domain = gicv5_domain_for_insn(env, ri, &virtual);
GICv5IntType type = FIELD_EX64(value, GIC_CDDI, TYPE);
uint32_t id = FIELD_EX64(value, GIC_CDDI, ID);
- bool virtual = false;
trace_gicv5_cddi(domain, value);
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 29/77] target/arm: GICv5 cpuif: Handle virtual interrupts for GIC CDEOI
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (27 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 28/77] target/arm: GICv5 cpuif: Handle LD/VD insns when setting domain/virtual args Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 30/77] target/arm: GICv5 cpuif: Handle virtual interrupts for GIC CDDI Peter Maydell
` (47 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
GIC CDEOI does a priority-drop for the current interrupt domain; when
this is the virtual interrupt domain we must update the virtual APR
register rather than a physical one.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/tcg/gicv5-cpuif.c | 21 ++++++++++++++++-----
target/arm/tcg/trace-events | 1 +
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 9fc24c62789..0d03f784cff 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -1221,13 +1221,24 @@ static void gic_cdeoi_write(CPUARMState *env, const ARMCPRegInfo *ri,
*/
bool virtual;
GICv5Domain domain = gicv5_domain_for_insn(env, ri, &virtual);
- uint64_t *apr = &env->gicv5_cpuif.icc_apr[domain];
- trace_gicv5_cdeoi(domain);
+ if (virtual) {
+ uint64_t *apr = &env->gicv5_cpuif.ich_apr_el2;
- /* clear lowest bit, doing nothing if already zero */
- *apr &= *apr - 1;
- gicv5_update_irq_fiq(env);
+ trace_gicv5_vcdeoi();
+
+ /* clear lowest bit, doing nothing if already zero */
+ *apr &= *apr - 1;
+ gicv5_update_virq_vfiq(env);
+ } else {
+ uint64_t *apr = &env->gicv5_cpuif.icc_apr[domain];
+
+ trace_gicv5_cdeoi(domain);
+
+ /* clear lowest bit, doing nothing if already zero */
+ *apr &= *apr - 1;
+ gicv5_update_irq_fiq(env);
+ }
}
static void gic_cddi_write(CPUARMState *env, const ARMCPRegInfo *ri,
diff --git a/target/arm/tcg/trace-events b/target/arm/tcg/trace-events
index 75f40c44f26..8e7e4c119db 100644
--- a/target/arm/tcg/trace-events
+++ b/target/arm/tcg/trace-events
@@ -7,6 +7,7 @@ gicv5_recalc_virt_ppi_hppi(uint32_t id, uint8_t prio) "virtual domain new PPI HP
gicv5_gicr_cdia_fail(int domain, const char *reason) "domain %d CDIA attempt failed: %s"
gicv5_gicr_cdia(int domain, uint32_t id) "domain %d CDIA acknowledge of interrupt 0x%x"
gicv5_cdeoi(int domain) "domain %d CDEOI performing priority drop"
+gicv5_vcdeoi(void) "virtual interrupt domain CDEOI performing priority drop"
gicv5_cddi(int domain, uint32_t id) "domain %d CDDI deactivating interrupt ID 0x%x"
gicv5_update_irq_fiq(bool irq, bool fiq, bool nmi) "now IRQ %d FIQ %d NMI %d"
gicv5_update_virq_vfiq(bool virq, bool vinmi) "now VIRQ %d VINMI %d"
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 30/77] target/arm: GICv5 cpuif: Handle virtual interrupts for GIC CDDI
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (28 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 29/77] target/arm: GICv5 cpuif: Handle virtual interrupts for GIC CDEOI Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 31/77] target/arm: GICv5 cpuif: Handle virtual interrupts for GICR CDIA, CDNMIA Peter Maydell
` (46 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Handle the virtual interrupt domain in our GIC CDDI implementation:
for LPIs and SPIs we just pass through the "virtual" parameter, but
for PPIs we must look at the virtual PPI state rather than the
physical PPI state.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/tcg/gicv5-cpuif.c | 11 ++++++++---
target/arm/tcg/trace-events | 2 +-
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 0d03f784cff..cf67f0ed94d 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -1254,7 +1254,7 @@ static void gic_cddi_write(CPUARMState *env, const ARMCPRegInfo *ri,
GICv5IntType type = FIELD_EX64(value, GIC_CDDI, TYPE);
uint32_t id = FIELD_EX64(value, GIC_CDDI, ID);
- trace_gicv5_cddi(domain, value);
+ trace_gicv5_cddi(domain, virtual, value);
switch (type) {
case GICV5_PPI:
@@ -1268,8 +1268,13 @@ static void gic_cddi_write(CPUARMState *env, const ARMCPRegInfo *ri,
ppireg = id / 64;
ppibit = 1ULL << (id % 64);
- env->gicv5_cpuif.ppi_active[ppireg] &= ~ppibit;
- gic_recalc_ppi_hppi(env);
+ if (virtual) {
+ env->gicv5_cpuif.ich_ppi_active[ppireg] &= ~ppibit;
+ gic_recalc_virt_ppi_hppi(env);
+ } else {
+ env->gicv5_cpuif.ppi_active[ppireg] &= ~ppibit;
+ gic_recalc_ppi_hppi(env);
+ }
break;
}
case GICV5_LPI:
diff --git a/target/arm/tcg/trace-events b/target/arm/tcg/trace-events
index 8e7e4c119db..31c6eafd8ed 100644
--- a/target/arm/tcg/trace-events
+++ b/target/arm/tcg/trace-events
@@ -8,7 +8,7 @@ gicv5_gicr_cdia_fail(int domain, const char *reason) "domain %d CDIA attempt fai
gicv5_gicr_cdia(int domain, uint32_t id) "domain %d CDIA acknowledge of interrupt 0x%x"
gicv5_cdeoi(int domain) "domain %d CDEOI performing priority drop"
gicv5_vcdeoi(void) "virtual interrupt domain CDEOI performing priority drop"
-gicv5_cddi(int domain, uint32_t id) "domain %d CDDI deactivating interrupt ID 0x%x"
+gicv5_cddi(int domain, bool virtual, uint32_t id) "domain %d virtual %d CDDI deactivating interrupt ID 0x%x"
gicv5_update_irq_fiq(bool irq, bool fiq, bool nmi) "now IRQ %d FIQ %d NMI %d"
gicv5_update_virq_vfiq(bool virq, bool vinmi) "now VIRQ %d VINMI %d"
gicv5_update_ppi_state(int ppi, bool level) "PPI %d source level now %d"
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 31/77] target/arm: GICv5 cpuif: Handle virtual interrupts for GICR CDIA, CDNMIA
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (29 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 30/77] target/arm: GICv5 cpuif: Handle virtual interrupts for GIC CDDI Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 32/77] target/arm: GICv5 cpuif: Handle GIC VDPEND VM argument Peter Maydell
` (45 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Handle the virtual interrupt domain in our GICR CDIA and
GICR CDNMIA implementation. LPIs and SPIs are handled by
passing through the 'virtual' parameter; PPIs look at the
virtual PPI state.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/tcg/gicv5-cpuif.c | 40 ++++++++++++++++++++++++++----------
target/arm/tcg/trace-events | 4 ++--
2 files changed, 31 insertions(+), 13 deletions(-)
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index cf67f0ed94d..93a627108da 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -1143,7 +1143,7 @@ static uint64_t gicr_cdia_read(CPUARMState *env, const ARMCPRegInfo *ri)
GICv5Common *gic = gicv5_get_gic(env);
bool virtual;
GICv5Domain domain = gicv5_domain_for_insn(env, ri, &virtual);
- GICv5PendingIrq hppi = gic_hppi(env, domain);
+ GICv5PendingIrq hppi = virtual ? gic_virt_hppi(env) : gic_hppi(env, domain);
GICv5IntType type = FIELD_EX64(hppi.intid, INTID, TYPE);
uint32_t id = FIELD_EX64(hppi.intid, INTID, ID);
@@ -1151,20 +1151,20 @@ static uint64_t gicr_cdia_read(CPUARMState *env, const ARMCPRegInfo *ri)
if (hppi.prio == PRIO_IDLE) {
/* No interrupt available to acknowledge */
- trace_gicv5_gicr_cdia_fail(domain,
+ trace_gicv5_gicr_cdia_fail(domain, virtual,
"no available interrupt to acknowledge");
return 0;
}
if (gic_hppi_is_nmi(env, hppi, domain) != cdnmia) {
/* GICR CDIA only acknowledges non-NMI; GICR CDNMIA only NMI */
- trace_gicv5_gicr_cdia_fail(domain,
+ trace_gicv5_gicr_cdia_fail(domain, virtual,
cdnmia ? "CDNMIA but HPPI is not NMI" :
"CDIA but HPPI is NMI");
return 0;
}
- trace_gicv5_gicr_cdia(domain, hppi.intid);
+ trace_gicv5_gicr_cdia(domain, virtual, hppi.intid);
/*
* The interrupt becomes Active. If the handling mode of the
@@ -1177,23 +1177,41 @@ static uint64_t gicr_cdia_read(CPUARMState *env, const ARMCPRegInfo *ri)
* gicv5_activate() cause a re-evaluation of HPPIs they use the
* right (new) running priority.
*/
- env->gicv5_cpuif.icc_apr[domain] |= (1ULL << hppi.prio);
+ if (virtual) {
+ env->gicv5_cpuif.ich_apr_el2 |= (1ULL << hppi.prio);
+ } else {
+ env->gicv5_cpuif.icc_apr[domain] |= (1ULL << hppi.prio);
+ }
+
switch (type) {
case GICV5_PPI:
{
uint32_t ppireg;
uint64_t ppibit;
+ bool hm_edge;
assert(id < GICV5_NUM_PPIS);
ppireg = id / 64;
ppibit = 1ULL << (id % 64);
- env->gicv5_cpuif.ppi_active[ppireg] |= ppibit;
- if (!(env->gicv5_cpuif.ppi_hm[ppireg] & ppibit)) {
- /* handling mode is Edge: clear pending */
- env->gicv5_cpuif.ppi_pend[ppireg] &= ~ppibit;
+ /* handling mode is constant and doesn't differ for virt vs phys */
+ hm_edge = !(env->gicv5_cpuif.ppi_hm[ppireg] & ppibit);
+
+ if (virtual) {
+ env->gicv5_cpuif.ich_ppi_active[ppireg] |= ppibit;
+ if (hm_edge) {
+ /* handling mode is Edge: clear pending */
+ env->gicv5_cpuif.ich_ppi_pend[ppireg] &= ~ppibit;
+ }
+ gic_recalc_virt_ppi_hppi(env);
+ } else {
+ env->gicv5_cpuif.ppi_active[ppireg] |= ppibit;
+ if (hm_edge) {
+ /* handling mode is Edge: clear pending */
+ env->gicv5_cpuif.ppi_pend[ppireg] &= ~ppibit;
+ }
+ gic_recalc_ppi_hppi(env);
}
- gic_recalc_ppi_hppi(env);
break;
}
case GICV5_LPI:
@@ -1203,7 +1221,7 @@ static uint64_t gicr_cdia_read(CPUARMState *env, const ARMCPRegInfo *ri)
* name of the stream command, does both "set Active" and
* "maybe set not Pending" as a single atomic action.
*/
- gicv5_activate(gic, id, domain, type, false);
+ gicv5_activate(gic, id, domain, type, virtual);
break;
default:
g_assert_not_reached();
diff --git a/target/arm/tcg/trace-events b/target/arm/tcg/trace-events
index 31c6eafd8ed..856a11b7d1b 100644
--- a/target/arm/tcg/trace-events
+++ b/target/arm/tcg/trace-events
@@ -4,8 +4,8 @@
# gicv5-cpuif.c
gicv5_recalc_ppi_hppi(int domain, uint32_t id, uint8_t prio) "domain %d new PPI HPPI id 0x%x prio %u"
gicv5_recalc_virt_ppi_hppi(uint32_t id, uint8_t prio) "virtual domain new PPI HPPI id 0x%x prio %u"
-gicv5_gicr_cdia_fail(int domain, const char *reason) "domain %d CDIA attempt failed: %s"
-gicv5_gicr_cdia(int domain, uint32_t id) "domain %d CDIA acknowledge of interrupt 0x%x"
+gicv5_gicr_cdia_fail(int domain, bool virtual, const char *reason) "domain %d virtual %d CDIA attempt failed: %s"
+gicv5_gicr_cdia(int domain, bool virtual, uint32_t id) "domain %d virtual %d CDIA acknowledge of interrupt 0x%x"
gicv5_cdeoi(int domain) "domain %d CDEOI performing priority drop"
gicv5_vcdeoi(void) "virtual interrupt domain CDEOI performing priority drop"
gicv5_cddi(int domain, bool virtual, uint32_t id) "domain %d virtual %d CDDI deactivating interrupt ID 0x%x"
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 32/77] target/arm: GICv5 cpuif: Handle GIC VDPEND VM argument
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (30 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 31/77] target/arm: GICv5 cpuif: Handle virtual interrupts for GICR CDIA, CDNMIA Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 33/77] target/arm: GICv5 cpuif: Implement GIC VDnnn insns Peter Maydell
` (44 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
In the GIC system instructions, VDPEND is special: the other "act on
virtual interrupt domain" operations act on the resident VPE/VM, but
this one allows the guest to pass in the VM ID, so that a hypervisor
can pend an interrupt for a VM even if there isn't currently a VPE
for that VM resident on the CPU.
Add the VM argument to gicv5_set_pending(), and fill it in with the
VM argument from the guest for VDPEND, or the current VM (as set in
ICH_CONTEXTR_EL2) for CDPEND and LDPEND. (The IRS will fail all
virtual interrupt operations until we implement its virtualization
support.)
The placing of the VM field moves the PENDING bit from bit 32 to 63,
so we need also to special case the reading of that bit.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
include/hw/intc/arm_gicv5_stream.h | 3 ++-
hw/intc/arm_gicv5.c | 5 +++--
target/arm/tcg/gicv5-cpuif.c | 34 +++++++++++++++++++++++++++++-
hw/intc/trace-events | 2 +-
4 files changed, 39 insertions(+), 5 deletions(-)
diff --git a/include/hw/intc/arm_gicv5_stream.h b/include/hw/intc/arm_gicv5_stream.h
index 162d55a8e6b..f6d32c6beca 100644
--- a/include/hw/intc/arm_gicv5_stream.h
+++ b/include/hw/intc/arm_gicv5_stream.h
@@ -86,6 +86,7 @@ void gicv5_set_enabled(GICv5Common *cs, uint32_t id,
* @domain: interrupt Domain to act on
* @type: interrupt type (LPI or SPI)
* @virtual: true if this is a virtual interrupt
+ * @vm: VM ID (for virtual interrupts)
*
* Set pending state of an interrupt; matches stream interface
* SetPending command from CPUIF to IRS. There is no report back of
@@ -93,7 +94,7 @@ void gicv5_set_enabled(GICv5Common *cs, uint32_t id,
*/
void gicv5_set_pending(GICv5Common *cs, uint32_t id,
bool pending, GICv5Domain domain,
- GICv5IntType type, bool virtual);
+ GICv5IntType type, bool virtual, uint32_t vm);
/**
* gicv5_set_handling
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index f25dbd7b426..c0e3e906754 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -848,13 +848,14 @@ void gicv5_set_enabled(GICv5Common *cs, uint32_t id, bool enabled,
}
void gicv5_set_pending(GICv5Common *cs, uint32_t id, bool pending,
- GICv5Domain domain, GICv5IntType type, bool virtual)
+ GICv5Domain domain, GICv5IntType type, bool virtual,
+ uint32_t vm)
{
GICv5 *s = ARM_GICV5(cs);
uint32_t iaffid;
trace_gicv5_set_pending(domain_name[domain], inttype_name(type), virtual,
- id, pending);
+ vm, id, pending);
if (virtual) {
qemu_log_mask(LOG_GUEST_ERROR, "gicv5_set_pending: tried to set "
"pending state of a virtual interrupt\n");
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 93a627108da..2fc854c02a1 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -40,6 +40,11 @@ FIELD(GIC_CDPEND, ID, 0, 24)
FIELD(GIC_CDPEND, TYPE, 29, 3)
FIELD(GIC_CDPEND, PENDING, 32, 1)
+FIELD(GIC_VDPEND, ID, 0, 24)
+FIELD(GIC_VDPEND, TYPE, 29, 3)
+FIELD(GIC_VDPEND, VM, 32, 16)
+FIELD(GIC_VDPEND, PENDING, 63, 1)
+
FIELD(GIC_CDHM, ID, 0, 24)
FIELD(GIC_CDHM, TYPE, 29, 3)
FIELD(GIC_CDHM, HM, 32, 1)
@@ -594,8 +599,35 @@ static void gic_cdpend_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint32_t id = FIELD_EX64(value, GIC_CDPEND, ID);
bool virtual;
GICv5Domain domain = gicv5_domain_for_insn(env, ri, &virtual);
+ uint32_t vm = 0;
- gicv5_set_pending(gic, id, pending, domain, type, virtual);
+ if (virtual) {
+ if (ri->opc1 == 4) {
+ /*
+ * GIC VDPEND has a VM argument field, and PENDING
+ * is in a different bit location to normal
+ */
+ vm = FIELD_EX64(value, GIC_VDPEND, VM);
+ pending = FIELD_EX64(value, GIC_VDPEND, PENDING);
+ } else {
+ /*
+ * GIC CDPEND for the virtual interrupt domain operates on
+ * the VM for the resident VPE. Our implementation of
+ * ICH_CONTEXTR_EL2 means we can trust that if the V bit
+ * is set the VM field is the right one.
+ */
+ if (FIELD_EX64(env->gicv5_cpuif.ich_contextr_el2,
+ ICH_CONTEXTR_EL2, V)) {
+ vm = FIELD_EX64(env->gicv5_cpuif.ich_contextr_el2,
+ ICH_CONTEXTR_EL2, VM);
+ } else {
+ /* no resident VPE: instruction is a NOP */
+ return;
+ }
+ }
+ }
+
+ gicv5_set_pending(gic, id, pending, domain, type, virtual, vm);
}
static void gic_cdrcfg_write(CPUARMState *env, const ARMCPRegInfo *ri,
diff --git a/hw/intc/trace-events b/hw/intc/trace-events
index 003924ddb43..2016842450b 100644
--- a/hw/intc/trace-events
+++ b/hw/intc/trace-events
@@ -237,7 +237,7 @@ gicv5_ist_valid(const char *domain, uint64_t base, uint8_t id_bits, uint8_t l2_i
gicv5_ist_invalid(const char *domain) "GICv5 IRS %s IST no longer valid"
gicv5_set_priority(const char *domain, const char *type, bool virtual, uint32_t id, uint8_t priority) "GICv5 IRS SetPriority %s %s virtual:%d ID %u prio %u"
gicv5_set_enabled(const char *domain, const char *type, bool virtual, uint32_t id, bool enabled) "GICv5 IRS SetEnabled %s %s virtual:%d ID %u enabled %d"
-gicv5_set_pending(const char *domain, const char *type, bool virtual, uint32_t id, bool pending) "GICv5 IRS SetPending %s %s virtual:%d ID %u pending %d"
+gicv5_set_pending(const char *domain, const char *type, bool virtual, uint32_t vm, uint32_t id, bool pending) "GICv5 IRS SetPending %s %s virtual:%d VM %u ID %u pending %d"
gicv5_set_handling(const char *domain, const char *type, bool virtual, uint32_t id, int handling) "GICv5 IRS SetHandling %s %s virtual:%d ID %u handling %d"
gicv5_set_target(const char *domain, const char *type, bool virtual, uint32_t id, uint32_t iaffid, int irm) "GICv5 IRS SetTarget %s %s virtual:%d ID %u IAFFID %u routingmode %d"
gicv5_request_config(const char *domain, const char *type, bool virtual, uint32_t id, uint64_t icsr) "GICv5 IRS RequestConfig %s %s virtual:%d ID %u ICSR 0x%" PRIx64
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 33/77] target/arm: GICv5 cpuif: Implement GIC VDnnn insns
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (31 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 32/77] target/arm: GICv5 cpuif: Handle GIC VDPEND VM argument Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 34/77] target/arm: GICv5 cpuif: Implement GIC LDnnn insns Peter Maydell
` (43 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
The GIC cpu interface has a set of GIC VDnnn insns which behave
exactly like the GIC CDnnn ones except that they always operate
on the virtual interrupt domain. (EL2 can use these to examine
and update the state of the interrupts of its guest.)
Now we've updated the writefns to handle the virtual interrupt
domain by looking at the opc1 field, we can implement these
using the existing writefns.
Note that there is no VD insn for CDIA, CDNMIA or CDEOI.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/tcg/gicv5-cpuif.c | 48 ++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 2fc854c02a1..277755fd4a1 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -1453,6 +1453,54 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
.fgt = FGT_GICRCDNMIA,
.readfn = gicr_cdia_read,
},
+ { .name = "GIC_VDDIS", .state = ARM_CP_STATE_AA64,
+ .opc0 = 1, .opc1 = 4, .crn = 12, .crm = 1, .opc2 = 0,
+ .access = PL2_W, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .accessfn = access_gicv5_ich_reg,
+ .writefn = gic_cddis_write,
+ },
+ { .name = "GIC_VDEN", .state = ARM_CP_STATE_AA64,
+ .opc0 = 1, .opc1 = 4, .crn = 12, .crm = 1, .opc2 = 1,
+ .access = PL2_W, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .accessfn = access_gicv5_ich_reg,
+ .writefn = gic_cden_write,
+ },
+ { .name = "GIC_VDPRI", .state = ARM_CP_STATE_AA64,
+ .opc0 = 1, .opc1 = 4, .crn = 12, .crm = 1, .opc2 = 2,
+ .access = PL2_W, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .accessfn = access_gicv5_ich_reg,
+ .writefn = gic_cdpri_write,
+ },
+ { .name = "GIC_VDAFF", .state = ARM_CP_STATE_AA64,
+ .opc0 = 1, .opc1 = 4, .crn = 12, .crm = 1, .opc2 = 3,
+ .access = PL2_W, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .accessfn = access_gicv5_ich_reg,
+ .writefn = gic_cdaff_write,
+ },
+ { .name = "GIC_VDPEND", .state = ARM_CP_STATE_AA64,
+ .opc0 = 1, .opc1 = 4, .crn = 12, .crm = 1, .opc2 = 4,
+ .access = PL2_W, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .accessfn = access_gicv5_ich_reg,
+ .writefn = gic_cdpend_write,
+ },
+ { .name = "GIC_VDRCFG", .state = ARM_CP_STATE_AA64,
+ .opc0 = 1, .opc1 = 4, .crn = 12, .crm = 1, .opc2 = 5,
+ .access = PL2_W, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .accessfn = access_gicv5_ich_reg,
+ .writefn = gic_cdrcfg_write,
+ },
+ { .name = "GIC_VDDI", .state = ARM_CP_STATE_AA64,
+ .opc0 = 1, .opc1 = 4, .crn = 12, .crm = 2, .opc2 = 0,
+ .access = PL2_W, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .accessfn = access_gicv5_ich_reg,
+ .writefn = gic_cddi_write,
+ },
+ { .name = "GIC_VDHM", .state = ARM_CP_STATE_AA64,
+ .opc0 = 1, .opc1 = 4, .crn = 12, .crm = 2, .opc2 = 1,
+ .access = PL2_W, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .accessfn = access_gicv5_ich_reg,
+ .writefn = gic_cdhm_write,
+ },
{ .name = "ICC_IDR0_EL1", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 0, .crn = 12, .crm = 10, .opc2 = 2,
.access = PL1_R, .type = ARM_CP_CONST | ARM_CP_NO_RAW,
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 34/77] target/arm: GICv5 cpuif: Implement GIC LDnnn insns
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (32 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 33/77] target/arm: GICv5 cpuif: Implement GIC VDnnn insns Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 35/77] target/arm: GICv5 cpuif: Handle PPI injection in vPPI pending reads Peter Maydell
` (42 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
The GIC cpu interface has a set of GIC LDnnn insns which behave
exactly like the GIC CDnnn ones except that they always operate on
the logical interrupt domain. (EL3 can use these to examine and
update the state of the interrupts in the physical interrupt domain
for lower exception levels.)
We won't need these until we implement EL3 support, but since
we've put in all the necessary groundwork for the reginfo
structs to just work, we might as well add them now. The writefns
will select the domain to use based on the opc1 field.
As with VD, there is no LD insn for CDIA, CDNMIA or CDEOI.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/tcg/gicv5-cpuif.c | 40 ++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 277755fd4a1..6fd3efc2880 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -1501,6 +1501,46 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = {
.accessfn = access_gicv5_ich_reg,
.writefn = gic_cdhm_write,
},
+ { .name = "GIC_LDDIS", .state = ARM_CP_STATE_AA64,
+ .opc0 = 1, .opc1 = 6, .crn = 12, .crm = 1, .opc2 = 0,
+ .access = PL3_W, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .writefn = gic_cddis_write,
+ },
+ { .name = "GIC_LDEN", .state = ARM_CP_STATE_AA64,
+ .opc0 = 1, .opc1 = 6, .crn = 12, .crm = 1, .opc2 = 1,
+ .access = PL3_W, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .writefn = gic_cden_write,
+ },
+ { .name = "GIC_LDPRI", .state = ARM_CP_STATE_AA64,
+ .opc0 = 1, .opc1 = 6, .crn = 12, .crm = 1, .opc2 = 2,
+ .access = PL3_W, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .writefn = gic_cdpri_write,
+ },
+ { .name = "GIC_LDAFF", .state = ARM_CP_STATE_AA64,
+ .opc0 = 1, .opc1 = 6, .crn = 12, .crm = 1, .opc2 = 3,
+ .access = PL3_W, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .writefn = gic_cdaff_write,
+ },
+ { .name = "GIC_LDPEND", .state = ARM_CP_STATE_AA64,
+ .opc0 = 1, .opc1 = 6, .crn = 12, .crm = 1, .opc2 = 4,
+ .access = PL3_W, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .writefn = gic_cdpend_write,
+ },
+ { .name = "GIC_LDRCFG", .state = ARM_CP_STATE_AA64,
+ .opc0 = 1, .opc1 = 6, .crn = 12, .crm = 1, .opc2 = 5,
+ .access = PL3_W, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .writefn = gic_cdrcfg_write,
+ },
+ { .name = "GIC_LDDI", .state = ARM_CP_STATE_AA64,
+ .opc0 = 1, .opc1 = 6, .crn = 12, .crm = 2, .opc2 = 0,
+ .access = PL3_W, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .writefn = gic_cddi_write,
+ },
+ { .name = "GIC_LDHM", .state = ARM_CP_STATE_AA64,
+ .opc0 = 1, .opc1 = 6, .crn = 12, .crm = 2, .opc2 = 1,
+ .access = PL3_W, .type = ARM_CP_IO | ARM_CP_NO_RAW,
+ .writefn = gic_cdhm_write,
+ },
{ .name = "ICC_IDR0_EL1", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 0, .crn = 12, .crm = 10, .opc2 = 2,
.access = PL1_R, .type = ARM_CP_CONST | ARM_CP_NO_RAW,
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 35/77] target/arm: GICv5 cpuif: Handle PPI injection in vPPI pending reads
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (33 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 34/77] target/arm: GICv5 cpuif: Implement GIC LDnnn insns Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 36/77] target/arm: GICv5 cpuif: Handle PPI injection in vPPI pending writes Peter Maydell
` (41 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
The GICv5 cpuif allows the hypervisor to configure PPIs to be
directly injected into a VM. Setting the appropriate bit in
ICH_PPI_DVIR<n>_EL2 causes that physical PPI to appear as a virtual
PPI in the virtual interrupt domain.
Directly injected PPIs mostly behave like true virtual PPIs; the
exception is that their pending state tracks the pending state of the
underlying physical PPI, and guest operations that read or update the
pending state work on the physical PPI's pending state. (Hypervisor
operations via ICH_PPI_PENDR<n>_EL2 are not changed, and don't work
with the physical PPI pending state.)
The complication here is that when nested virtualization is active
the EL1 timer PPIs must be redirected so that they appear with
different virtual PPI IDs from their physical PPI IDs. All other
injection is a simple 1:1 mapping with a physical PPI always
injecting to the virtual PPI with the same ID.
In this commit we update the places which read the pending state
of virtual PPIs to honour the DVI bits and report the pending
state of the underlying direct-injected PPI.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/tcg/gicv5-cpuif.c | 99 +++++++++++++++++++++++++++++++++++-
1 file changed, 97 insertions(+), 2 deletions(-)
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 6fd3efc2880..73476dc40bf 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -192,6 +192,101 @@ static GICv5Domain gicv5_domain_for_insn(CPUARMState *env,
return gicv5_current_phys_domain(env);
}
+static uint64_t gic_virt_dvi_mask(CPUARMState *env, int reg)
+{
+ /*
+ * Return the mask of bits of virtual PPIs which are being direct
+ * injected. 'reg' is which of the two ICH_PPI_DVIR<n>_EL2 regs we
+ * are dealing with.
+ *
+ * The complexity here comes from the requirement when doing
+ * nested virtualization to redirect injected EL1 timer PPIs so
+ * that they appear with the PPI numbers that the inner hypervisor
+ * expects (see R_GYGNW).
+ *
+ * Note that the ICH_PPI_DVIRn bits correspond to physical PPIs;
+ * the ICH_PPI_HVIRn bits correspond to virtual PPIs.
+ */
+ uint64_t dvi_mask = env->gicv5_cpuif.ich_ppi_dvi[reg];
+
+ if (reg == 0 &&
+ (arm_hcr_el2_eff(env) & (HCR_NV | HCR_NV1)) == HCR_NV) {
+ if (arm_is_secure_below_el3(env)) {
+ /*
+ * If we are injecting phys PPI 30, it appears as virtual
+ * PPI 20; phys PPI 27 appears as virtual PPI 19. Note
+ * that if we are not injecting the phys PPI 30/27 then
+ * the guest is allowed to configure phys PPI 20 to
+ * direct-inject to virt PPI 20 if it likes.
+ */
+ if (extract64(dvi_mask, 30, 1)) {
+ dvi_mask |= 1 << 20;
+ }
+ if (extract64(dvi_mask, 27, 1)) {
+ dvi_mask |= 1 << 19;
+ }
+ } else {
+ /* phys PPI 30 -> vPPI 26; phys PPI 27 -> vPPI 28 */
+ if (extract64(dvi_mask, 30, 1)) {
+ dvi_mask |= 1 << 26;
+ }
+ if (extract64(dvi_mask, 27, 1)) {
+ dvi_mask |= 1 << 28;
+ }
+ }
+ /* We aren't direct injecting to virtual PPIs 30 or 27 */
+ dvi_mask &= ~((1 << 30) | (1 << 27));
+ }
+
+ /*
+ * Now we've converted dvi_mask to virtual PPIs, fold in
+ * ICH_PPI_HVIR<n>_EL2: if the vPPI is hidden it can't be
+ * direct-injected to.
+ */
+ dvi_mask &= ~env->gicv5_cpuif.ich_ppi_hvi[reg];
+ return dvi_mask;
+}
+
+static uint64_t gic_virt_ppi_pending(CPUARMState *env, int reg)
+{
+ /*
+ * Return the pending state of the virtual PPIs; this is the
+ * combination of the ICH_PPI_PENDR<n>_EL2 state and the pending
+ * state of the physical PPIs which are being direct-injected.
+ */
+ uint64_t dvi_pend = env->gicv5_cpuif.ppi_pend[reg];
+ uint64_t ppi_dvi = env->gicv5_cpuif.ich_ppi_dvi[reg];
+ uint64_t dvi_mask = gic_virt_dvi_mask(env, reg);
+
+ if (reg == 0 &&
+ (arm_hcr_el2_eff(env) & (HCR_NV | HCR_NV1)) == HCR_NV) {
+ if (arm_is_secure_below_el3(env)) {
+ /* 30 -> 20 and 27 -> 19 */
+ if (extract64(ppi_dvi, 30, 1)) {
+ dvi_pend = deposit64(dvi_pend, 20, 1,
+ extract64(dvi_pend, 30, 1));
+ }
+ if (extract64(ppi_dvi, 27, 1)) {
+ dvi_pend = deposit64(dvi_pend, 19, 1,
+ extract64(dvi_pend, 27, 1));
+ }
+ } else {
+ /* 30 -> 26 and 27 -> 28 */
+ if (extract64(ppi_dvi, 30, 1)) {
+ dvi_pend = deposit64(dvi_pend, 26, 1,
+ extract64(dvi_pend, 30, 1));
+ }
+ if (extract64(ppi_dvi, 27, 1)) {
+ dvi_pend = deposit64(dvi_pend, 28, 1,
+ extract64(dvi_pend, 27, 1));
+ }
+ }
+ dvi_pend &= ~((1 << 30) | (1 << 27));
+ }
+ dvi_pend &= dvi_mask;
+ return (env->gicv5_cpuif.ich_ppi_pend[reg] & ~dvi_mask) | dvi_pend;
+}
+
static uint64_t gic_running_prio(CPUARMState *env, GICv5Domain domain)
{
/*
@@ -461,7 +556,7 @@ static void gic_recalc_virt_ppi_hppi(CPUARMState *env)
for (int i = 0; i < ARRAY_SIZE(env->gicv5_cpuif.ich_ppi_active); i++) {
uint64_t en_pend_nact = env->gicv5_cpuif.ich_ppi_enable[i] &
- env->gicv5_cpuif.ich_ppi_pend[i] &
+ gic_virt_ppi_pending(env, i) &
~env->gicv5_cpuif.ich_ppi_active[i];
while (en_pend_nact) {
@@ -716,7 +811,7 @@ static void gic_ppi_sactive_write(CPUARMState *env, const ARMCPRegInfo *ri,
static uint64_t gic_ppi_pend_read(CPUARMState *env, const ARMCPRegInfo *ri)
{
if (gicv5_icv_access(env)) {
- uint64_t value = env->gicv5_cpuif.ich_ppi_pend[ri->opc2 & 1];
+ uint64_t value = gic_virt_ppi_pending(env, ri->opc2 & 1);
value &= ~env->gicv5_cpuif.ich_ppi_hvi[ri->opc2 & 1];
return value;
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 36/77] target/arm: GICv5 cpuif: Handle PPI injection in vPPI pending writes
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (34 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 35/77] target/arm: GICv5 cpuif: Handle PPI injection in vPPI pending reads Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 37/77] target/arm: GICv5 cpuif: Handle injected PPIs in GICR CDIA Peter Maydell
` (40 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
In this commit we update the logic for writes to the virtual PPI
pending state by the guest using the PPI_CPEND or PPI_SPEND registers
to honour the DVI registers, so that the pending state of the
underlying physical PPI is updated.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/tcg/gicv5-cpuif.c | 70 ++++++++++++++++++++++++++++++++----
1 file changed, 64 insertions(+), 6 deletions(-)
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 73476dc40bf..2e9528bb2c3 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -820,16 +820,62 @@ static uint64_t gic_ppi_pend_read(CPUARMState *env, const ARMCPRegInfo *ri)
}
}
+static uint64_t gic_ppi_vpend_to_ppend(CPUARMState *env,
+ uint64_t value, int reg)
+{
+ /*
+ * Given a mask of bits which are virtual PPI pending bits being
+ * changed, output the mask of bits which are to be changed in the
+ * physical PPI pending state, by adjusting them for the the timer
+ * PPI redirection. We require that the input value has already
+ * had the bits masked out for vPPIs that are not direct-injected.
+ */
+ if (reg == 0 && (arm_hcr_el2_eff(env) & (HCR_NV | HCR_NV1)) == HCR_NV) {
+ if (arm_is_secure_below_el3(env)) {
+ /* vPPI 20 is pPPI 30; vPPI 19 is pPPI 27 */
+ if (value & (1 << 20)) {
+ value |= 1 << 30;
+ }
+ if (value & (1 << 19)) {
+ value |= 1 << 27;
+ }
+ value &= ~((1 << 19) | (1 << 20));
+ } else {
+ /* vPPI 26 is pPPI 30; vPPI 28 is pPPI 27 */
+ if (value & (1 << 26)) {
+ value |= 1 << 30;
+ }
+ if (value & (1 << 28)) {
+ value |= 1 << 27;
+ }
+ value &= ~((1 << 26) | (1 << 28));
+ }
+ }
+ return value;
+}
+
static void gic_ppi_cpend_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
+ int reg = ri->opc2 & 1;
/* If ICC_PPI_HMR_EL1[n].HM is 1, PEND bits are RO */
- uint64_t hm = env->gicv5_cpuif.ppi_hm[ri->opc2 & 1];
+ uint64_t hm = env->gicv5_cpuif.ppi_hm[reg];
value &= ~hm;
if (gicv5_icv_access(env)) {
- value &= ~env->gicv5_cpuif.ich_ppi_hvi[ri->opc2 & 1];
- env->gicv5_cpuif.ich_ppi_pend[ri->opc2 & 1] &= ~value;
+ uint64_t dvi_mask = gic_virt_dvi_mask(env, reg);
+
+ value &= ~env->gicv5_cpuif.ich_ppi_hvi[reg];
+
+ /* Update state for non-injected virtual PPIs */
+ env->gicv5_cpuif.ich_ppi_pend[reg] &= ~(value & ~dvi_mask);
+ /* Update state for injected PPIs */
+ value &= dvi_mask;
+ value = gic_ppi_vpend_to_ppend(env, value, reg);
+ if (value) {
+ env->gicv5_cpuif.ppi_pend[reg] &= ~value;
+ gic_recalc_ppi_hppi(env);
+ }
gic_recalc_virt_ppi_hppi(env);
} else {
uint64_t old = raw_read(env, ri);
@@ -841,13 +887,25 @@ static void gic_ppi_cpend_write(CPUARMState *env, const ARMCPRegInfo *ri,
static void gic_ppi_spend_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
+ int reg = ri->opc2 & 1;
/* If ICC_PPI_HMR_EL1[n].HM is 1, PEND bits are RO */
- uint64_t hm = env->gicv5_cpuif.ppi_hm[ri->opc2 & 1];
+ uint64_t hm = env->gicv5_cpuif.ppi_hm[reg];
value &= ~hm;
if (gicv5_icv_access(env)) {
- value &= ~env->gicv5_cpuif.ich_ppi_hvi[ri->opc2 & 1];
- env->gicv5_cpuif.ich_ppi_pend[ri->opc2 & 1] |= value;
+ uint64_t dvi_mask = gic_virt_dvi_mask(env, reg);
+
+ value &= ~env->gicv5_cpuif.ich_ppi_hvi[reg];
+
+ /* Update state for non-injected virtual PPIs */
+ env->gicv5_cpuif.ich_ppi_pend[reg] |= (value & ~dvi_mask);
+ /* Update state for injected PPIs */
+ value &= dvi_mask;
+ value = gic_ppi_vpend_to_ppend(env, value, reg);
+ if (value) {
+ env->gicv5_cpuif.ppi_pend[reg] |= value;
+ gic_recalc_ppi_hppi(env);
+ }
gic_recalc_virt_ppi_hppi(env);
} else {
uint64_t old = raw_read(env, ri);
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 37/77] target/arm: GICv5 cpuif: Handle injected PPIs in GICR CDIA
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (35 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 36/77] target/arm: GICv5 cpuif: Handle PPI injection in vPPI pending writes Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 38/77] target/arm: GICv5 cpuif: Update on HCR_EL2.{NV, NV1} and SCR_EL3.NS changes Peter Maydell
` (39 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
When GICR CDIA for the virtual interrupt domain acknowledges an edge
handling-mode interrupt, it causes it to no longer be pending. If
this is a PPI which is being direct-injected, we need to update the
physical PPI pending state, not the virtual state.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/tcg/gicv5-cpuif.c | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 2e9528bb2c3..6b667b5729f 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -1322,6 +1322,27 @@ static bool gic_hppi_is_nmi(CPUARMState *env, GICv5PendingIrq hppi,
return hppi.prio == 0 && arm_sctlr(env, arm_current_el(env)) & SCTLR_NMI;
}
+static void gic_clear_vppi_pending(CPUARMState *env, uint32_t ppireg,
+ uint64_t ppibit)
+{
+ /*
+ * Mark the specified virtual PPI as no longer pending. ppireg is
+ * the PPI register index (0 or 1) and ppibit is a mask with
+ * exactly 1 bit set in it.
+ */
+ uint64_t dvi_mask = gic_virt_dvi_mask(env, ppireg);
+
+ if (!(dvi_mask & ppibit)) {
+ /* Easy case: vPPI not direct injected */
+ env->gicv5_cpuif.ich_ppi_pend[ppireg] &= ~ppibit;
+ return;
+ }
+ /* vPPI is direct-injected: unpend the physical PPI */
+ ppibit = gic_ppi_vpend_to_ppend(env, ppibit, ppireg);
+ env->gicv5_cpuif.ppi_pend[ppireg] &= ~ppibit;
+ gic_recalc_ppi_hppi(env);
+}
+
static uint64_t gicr_cdia_read(CPUARMState *env, const ARMCPRegInfo *ri)
{
/* Acknowledge HPPI in the current interrupt domain */
@@ -1386,7 +1407,7 @@ static uint64_t gicr_cdia_read(CPUARMState *env, const ARMCPRegInfo *ri)
env->gicv5_cpuif.ich_ppi_active[ppireg] |= ppibit;
if (hm_edge) {
/* handling mode is Edge: clear pending */
- env->gicv5_cpuif.ich_ppi_pend[ppireg] &= ~ppibit;
+ gic_clear_vppi_pending(env, ppireg, ppibit);
}
gic_recalc_virt_ppi_hppi(env);
} else {
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 38/77] target/arm: GICv5 cpuif: Update on HCR_EL2.{NV, NV1} and SCR_EL3.NS changes
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (36 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 37/77] target/arm: GICv5 cpuif: Handle injected PPIs in GICR CDIA Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 39/77] target/arm: GICv5 cpuif: Update VFIQ/VIRQ when direct-injected PPIs change Peter Maydell
` (38 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
When HCR_EL2.{NV,NV1} or SCR_EL3.NS change, this can affect how
direct injection of timer PPIs is handled, which in turn can
potentially affect what the highest priority virtual pending PPI is.
Since the virtual HPPI can be read from EL2 or EL3, we need to
arrange that changes to these bits trigger a GICv5 recalculation.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/internals.h | 9 +++++++++
target/arm/gicv5-stubs.c | 8 ++++++++
target/arm/helper.c | 23 ++++++++++++++++++-----
target/arm/tcg/gicv5-cpuif.c | 18 ++++++++++++++++++
4 files changed, 53 insertions(+), 5 deletions(-)
diff --git a/target/arm/internals.h b/target/arm/internals.h
index 033d6d66da3..42107b9470d 100644
--- a/target/arm/internals.h
+++ b/target/arm/internals.h
@@ -1912,6 +1912,15 @@ void define_gicv5_cpuif_regs(ARMCPU *cpu);
*/
void gicv5_update_ppi_state(CPUARMState *env, int ppi, bool level);
+/*
+ * Tell the GICv5 when HCR_EL2.{NV,NV1} change. Does nothing if GICv5 not
+ * present.
+ */
+void gicv5_update_on_hcr_nv_change(CPUARMState *env);
+
+/* Tell the GICv5 when SCR_EL3.NS changes. Does nothing if GICv5 not present */
+void gicv5_update_on_scr_ns_change(CPUARMState *env);
+
/* Effective value of MDCR_EL2 */
static inline uint64_t arm_mdcr_el2_eff(CPUARMState *env)
{
diff --git a/target/arm/gicv5-stubs.c b/target/arm/gicv5-stubs.c
index 845626d7c6b..b8c926744cb 100644
--- a/target/arm/gicv5-stubs.c
+++ b/target/arm/gicv5-stubs.c
@@ -15,3 +15,11 @@ void define_gicv5_cpuif_regs(ARMCPU *cpu)
void gicv5_update_ppi_state(CPUARMState *env, int ppi, bool level)
{
}
+
+void gicv5_update_on_hcr_nv_change(CPUARMState *env)
+{
+}
+
+void gicv5_update_on_scr_ns_change(CPUARMState *env)
+{
+}
diff --git a/target/arm/helper.c b/target/arm/helper.c
index f413b15eb74..791f7c9cd62 100644
--- a/target/arm/helper.c
+++ b/target/arm/helper.c
@@ -1016,6 +1016,12 @@ static void scr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value)
ARMMMUIdxBit_E2 |
ARMMMUIdxBit_E2_GCS));
}
+ /* The GICv5 cpuif needs to know if SCR_EL3.NS changes */
+#ifndef CONFIG_USER_ONLY
+ if (changed & SCR_NS) {
+ gicv5_update_on_scr_ns_change(env);
+ }
+#endif
}
static void scr_reset(CPUARMState *env, const ARMCPRegInfo *ri)
@@ -3873,7 +3879,7 @@ static const ARMCPRegInfo v8_aa32_el1_reginfo[] = {
static void do_hcr_write(CPUARMState *env, uint64_t value, uint64_t valid_mask)
{
ARMCPU *cpu = env_archcpu(env);
- bool hcr_change_timer;
+ uint64_t changed;
if (arm_feature(env, ARM_FEATURE_V8)) {
valid_mask |= MAKE_64BIT_MASK(0, 34); /* ARMv8.0 */
@@ -3952,6 +3958,8 @@ static void do_hcr_write(CPUARMState *env, uint64_t value, uint64_t valid_mask)
}
}
+ changed = env->cp15.hcr_el2 ^ value;
+
/*
* These bits change the MMU setup:
* HCR_VM enables stage 2 translation
@@ -3961,16 +3969,21 @@ static void do_hcr_write(CPUARMState *env, uint64_t value, uint64_t valid_mask)
* HCR_FWB changes the interpretation of stage2 descriptor bits
* HCR_NV and HCR_NV1 affect interpretation of descriptor bits
*/
- if ((env->cp15.hcr_el2 ^ value) &
+ if (changed &
(HCR_VM | HCR_PTW | HCR_DC | HCR_DCT | HCR_FWB | HCR_NV | HCR_NV1)) {
tlb_flush(CPU(cpu));
}
- hcr_change_timer = (env->cp15.hcr_el2 ^ value) &
- (HCR_E2H | HCR_TGE);
/* update */
env->cp15.hcr_el2 = value;
+ /* If HCR_EL2.{NV,NV1} change we must inform the GICv5 cpuif */
+#ifndef CONFIG_USER_ONLY
+ if (changed & (HCR_NV | HCR_NV1)) {
+ gicv5_update_on_hcr_nv_change(env);
+ }
+#endif
+
/*
* Updates to VI and VF require us to update the status of
* virtual interrupts, which are the logical OR of these bits
@@ -3990,7 +4003,7 @@ static void do_hcr_write(CPUARMState *env, uint64_t value, uint64_t valid_mask)
arm_cpu_update_vinmi(cpu);
arm_cpu_update_vfnmi(cpu);
}
- if (hcr_change_timer) {
+ if (changed & (HCR_E2H | HCR_TGE)) {
#ifndef CONFIG_USER_ONLY
gt_recalc_timer(cpu, GTIMER_PHYS);
#endif
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index 6b667b5729f..dd40a0c23b6 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -634,6 +634,24 @@ void gicv5_update_ppi_state(CPUARMState *env, int ppi, bool level)
}
}
+void gicv5_update_on_hcr_nv_change(CPUARMState *env)
+{
+ /* HCR_EL2.{NV,NV1} changed, which affects DVI timer PPI remapping */
+ if (!cpu_isar_feature(aa64_gcie, env_archcpu(env))) {
+ return;
+ }
+ gic_recalc_virt_ppi_hppi(env);
+}
+
+void gicv5_update_on_scr_ns_change(CPUARMState *env)
+{
+ /* SCR_EL3.NS changed, which affects DVI timer PPI remapping */
+ if (!cpu_isar_feature(aa64_gcie, env_archcpu(env))) {
+ return;
+ }
+ gic_recalc_virt_ppi_hppi(env);
+}
+
static void gic_cddis_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 39/77] target/arm: GICv5 cpuif: Update VFIQ/VIRQ when direct-injected PPIs change
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (37 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 38/77] target/arm: GICv5 cpuif: Update on HCR_EL2.{NV, NV1} and SCR_EL3.NS changes Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 40/77] hw/intc: Move GICv5 register and data definitions into a header Peter Maydell
` (37 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
When a physical PPI changes its pending state we usually don't need
to update the virtual PPI state. However, if the PPI is
direct-injected to the VM then we do need to do that update. Make
this check and call gic_recalc_virt_ppi_hppi() where we update
physical PPI pending state.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/tcg/gicv5-cpuif.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index dd40a0c23b6..ec4ee9825e8 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -606,6 +606,28 @@ void gicv5_forward_interrupt(ARMCPU *cpu, GICv5Domain domain, bool virtual)
}
}
+static void gic_recalc_virt_ppi_hppi_for_dvi(CPUARMState *env, int reg,
+ uint64_t mask)
+{
+ /*
+ * Called after the physical PPI pending state has changed for the
+ * PPIs indicated by the mask and reg arguments. If any of these
+ * PPIs are direct-injected, we need to recalculate the virtual
+ * HPPI.
+ *
+ * It is possible that even if the DVI bit is set we might not
+ * actually be direct-injecting the PPI (e.g. if HVI is set, or if
+ * timer-PPI redirection means we're ignoring this DVI bit), but
+ * if so the recalculation will just do nothing. These cases are
+ * "the guest did something valid but odd" in that it set a DVI
+ * bit it knew wasn't going to have any effect, so not worth
+ * trying to catch early.
+ */
+ if (env->gicv5_cpuif.ich_ppi_dvi[reg] & mask) {
+ gic_recalc_virt_ppi_hppi(env);
+ }
+}
+
void gicv5_update_ppi_state(CPUARMState *env, int ppi, bool level)
{
/*
@@ -631,6 +653,7 @@ void gicv5_update_ppi_state(CPUARMState *env, int ppi, bool level)
env->gicv5_cpuif.ppi_pend[0] =
deposit64(env->gicv5_cpuif.ppi_pend[0], ppi, 1, level);
gic_recalc_ppi_hppi(env);
+ gic_recalc_virt_ppi_hppi_for_dvi(env, 0, 1ULL << ppi);
}
}
@@ -899,6 +922,7 @@ static void gic_ppi_cpend_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t old = raw_read(env, ri);
raw_write(env, ri, old & ~value);
gic_recalc_ppi_hppi(env);
+ gic_recalc_virt_ppi_hppi_for_dvi(env, reg, value);
}
}
@@ -929,6 +953,7 @@ static void gic_ppi_spend_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t old = raw_read(env, ri);
raw_write(env, ri, old | value);
gic_recalc_ppi_hppi(env);
+ gic_recalc_virt_ppi_hppi_for_dvi(env, reg, value);
}
}
@@ -1433,6 +1458,7 @@ static uint64_t gicr_cdia_read(CPUARMState *env, const ARMCPRegInfo *ri)
if (hm_edge) {
/* handling mode is Edge: clear pending */
env->gicv5_cpuif.ppi_pend[ppireg] &= ~ppibit;
+ gic_recalc_virt_ppi_hppi_for_dvi(env, ppireg, ppibit);
}
gic_recalc_ppi_hppi(env);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 40/77] hw/intc: Move GICv5 register and data definitions into a header
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (38 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 39/77] target/arm: GICv5 cpuif: Update VFIQ/VIRQ when direct-injected PPIs change Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-04 7:56 ` Manos Pitsidianakis
2026-12-03 11:10 ` [PATCH v2 41/77] hw/intc/arm_gicv5: Correct offset for IRS_VMT_STATUSR Peter Maydell
` (36 subsequent siblings)
76 siblings, 1 reply; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
We put the definitions of GICv5 IRS registers and guest-memory data
structures directly into arm_gicv5.c. It turns out that there are a
few cases where we would like them outside that file (for instance
register reset is handled in arm_gicv5_common.c).
Move the definitions to their own header file.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
include/hw/intc/arm_gicv5_regs.h | 286 +++++++++++++++++++++++++++++++
hw/intc/arm_gicv5.c | 270 +----------------------------
2 files changed, 287 insertions(+), 269 deletions(-)
create mode 100644 include/hw/intc/arm_gicv5_regs.h
diff --git a/include/hw/intc/arm_gicv5_regs.h b/include/hw/intc/arm_gicv5_regs.h
new file mode 100644
index 00000000000..c504d8642d7
--- /dev/null
+++ b/include/hw/intc/arm_gicv5_regs.h
@@ -0,0 +1,286 @@
+/*
+ * ARM GICv5 emulation: Interrupt Routing Service (IRS) registers
+ *
+ * Copyright (c) 2025 Linaro Limited
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * This file has definitions of IRS register layouts and
+ * in-guest-memory data structures, that shouldn't be needed
+ * outside the IRS implementation.
+ */
+
+#ifndef HW_INTC_ARM_GICV5_REGS_H
+#define HW_INTC_ARM_GICV5_REGS_H
+
+REG32(IRS_IDR0, 0x0)
+ FIELD(IRS_IDR0, INT_DOM, 0, 2)
+ FIELD(IRS_IDR0, PA_RANGE, 2, 4)
+ FIELD(IRS_IDR0, VIRT, 6, 1)
+ FIELD(IRS_IDR0, ONE_N, 7, 1)
+ FIELD(IRS_IDR0, VIRT_ONE_N, 8, 1)
+ FIELD(IRS_IDR0, SETLPI, 9, 1)
+ FIELD(IRS_IDR0, MEC, 10, 1)
+ FIELD(IRS_IDR0, MPAM, 11, 1)
+ FIELD(IRS_IDR0, SWE, 12, 1)
+ FIELD(IRS_IDR0, IRSID, 16, 16)
+
+REG32(IRS_IDR1, 0x4)
+ FIELD(IRS_IDR1, PE_CNT, 0, 16)
+ FIELD(IRS_IDR1, IAFFID_BITS, 16, 4)
+ FIELD(IRS_IDR1, PRI_BITS, 20, 3)
+
+REG32(IRS_IDR2, 0x8)
+ FIELD(IRS_IDR2, ID_BITS, 0, 5)
+ FIELD(IRS_IDR2, LPI, 5, 1)
+ FIELD(IRS_IDR2, MIN_LPI_ID_BITS, 6, 4)
+ FIELD(IRS_IDR2, IST_LEVELS, 10, 1)
+ FIELD(IRS_IDR2, IST_L2SZ, 11, 3)
+ FIELD(IRS_IDR2, IST_MD, 14, 1)
+ FIELD(IRS_IDR2, ISTMD_SZ, 15, 5)
+
+REG32(IRS_IDR3, 0xc)
+ FIELD(IRS_IDR3, VMD, 0, 1)
+ FIELD(IRS_IDR3, VMD_SZ, 1, 4)
+ FIELD(IRS_IDR3, VM_ID_BITS, 5, 5)
+ FIELD(IRS_IDR3, VMT_LEVELS, 10, 1)
+
+REG32(IRS_IDR4, 0x10)
+ FIELD(IRS_IDR4, VPED_SZ, 0, 6)
+ FIELD(IRS_IDR4, VPE_ID_BITS, 6, 4)
+
+REG32(IRS_IDR5, 0x14)
+ FIELD(IRS_IDR5, SPI_RANGE, 0, 25)
+
+REG32(IRS_IDR6, 0x18)
+ FIELD(IRS_IDR6, SPI_IRS_RANGE, 0, 25)
+
+REG32(IRS_IDR7, 0x1c)
+ FIELD(IRS_IDR7, SPI_BASE, 0, 24)
+
+REG32(IRS_IIDR, 0x40)
+ FIELD(IRS_IIDR, IMPLEMENTER, 0, 12)
+ FIELD(IRS_IIDR, REVISION, 12, 4)
+ FIELD(IRS_IIDR, VARIANT, 16, 4)
+ FIELD(IRS_IIDR, PRODUCTID, 20, 12)
+
+REG32(IRS_AIDR, 0x44)
+ FIELD(IRS_AIDR, ARCHMINORREV, 0, 4)
+ FIELD(IRS_AIDR, ARCHMAJORREV, 4, 4)
+ FIELD(IRS_AIDR, COMPONENT, 8, 4)
+
+REG32(IRS_CR0, 0x80)
+ FIELD(IRS_CR0, IRSEN, 0, 1)
+ FIELD(IRS_CR0, IDLE, 1, 1)
+
+REG32(IRS_CR1, 0x84)
+ FIELD(IRS_CR1, SH, 0, 2)
+ FIELD(IRS_CR1, OC, 2, 2)
+ FIELD(IRS_CR1, IC, 4, 2)
+ FIELD(IRS_CR1, IST_RA, 6, 1)
+ FIELD(IRS_CR1, IST_WA, 7, 1)
+ FIELD(IRS_CR1, VMT_RA, 8, 1)
+ FIELD(IRS_CR1, VMT_WA, 9, 1)
+ FIELD(IRS_CR1, VPET_RA, 10, 1)
+ FIELD(IRS_CR1, VPET_WA, 11, 1)
+ FIELD(IRS_CR1, VMD_RA, 12, 1)
+ FIELD(IRS_CR1, VMD_WA, 13, 1)
+ FIELD(IRS_CR1, VPED_RA, 14, 1)
+ FIELD(IRS_CR1, VPED_WA, 15, 1)
+
+REG32(IRS_SYNCR, 0xc0)
+ FIELD(IRS_SYNCR, SYNC, 31, 1)
+
+REG32(IRS_SYNC_STATUSR, 0xc4)
+ FIELD(IRS_SYNC_STATUSR, IDLE, 0, 1)
+
+REG64(IRS_SPI_VMR, 0x100)
+ FIELD(IRS_SPI_VMR, VM_ID, 0, 16)
+ FIELD(IRS_SPI_VMR, VIRT, 63, 1)
+
+REG32(IRS_SPI_SELR, 0x108)
+ FIELD(IRS_SPI_SELR, ID, 0, 24)
+
+REG32(IRS_SPI_DOMAINR, 0x10c)
+ FIELD(IRS_SPI_DOMAINR, DOMAIN, 0, 2)
+
+REG32(IRS_SPI_RESAMPLER, 0x110)
+ FIELD(IRS_SPI_RESAMPLER, SPI_ID, 0, 24)
+
+REG32(IRS_SPI_CFGR, 0x114)
+ FIELD(IRS_SPI_CFGR, TM, 0, 1)
+
+REG32(IRS_SPI_STATUSR, 0x118)
+ FIELD(IRS_SPI_STATUSR, IDLE, 0, 1)
+ FIELD(IRS_SPI_STATUSR, V, 1, 1)
+
+REG32(IRS_PE_SELR, 0x140)
+ FIELD(IRS_PE_SELR, IAFFID, 0, 16)
+
+REG32(IRS_PE_STATUSR, 0x144)
+ FIELD(IRS_PE_STATUSR, IDLE, 0, 1)
+ FIELD(IRS_PE_STATUSR, V, 1, 1)
+ FIELD(IRS_PE_STATUSR, ONLINE, 2, 1)
+
+REG32(IRS_PE_CR0, 0x148)
+ FIELD(IRS_PE_CR0, DPS, 0, 1)
+
+REG64(IRS_IST_BASER, 0x180)
+ FIELD(IRS_IST_BASER, VALID, 0, 1)
+ FIELD(IRS_IST_BASER, ADDR, 6, 50)
+
+REG32(IRS_IST_CFGR, 0x190)
+ FIELD(IRS_IST_CFGR, LPI_ID_BITS, 0, 5)
+ FIELD(IRS_IST_CFGR, L2SZ, 5, 2)
+ FIELD(IRS_IST_CFGR, ISTSZ, 7, 2)
+ FIELD(IRS_IST_CFGR, STRUCTURE, 16, 1)
+
+REG32(IRS_IST_STATUSR, 0x194)
+ FIELD(IRS_IST_STATUSR, IDLE, 0, 1)
+
+REG32(IRS_MAP_L2_ISTR, 0x1c0)
+ FIELD(IRS_MAP_L2_ISTR, ID, 0, 24)
+
+REG64(IRS_VMT_BASER, 0x200)
+ FIELD(IRS_VMT_BASER, VALID, 0, 1)
+ FIELD(IRS_VMT_BASER, ADDR, 3, 53)
+
+REG32(IRS_VMT_CFGR, 0x210)
+ FIELD(IRS_VMT_CFGR, VM_ID_BITS, 0, 5)
+ FIELD(IRS_VMT_CFGR, STRUCTURE, 16, 1)
+
+REG32(IRS_VMT_STATUSR, 0x124)
+ FIELD(IRS_VMT_STATUSR, IDLE, 0, 1)
+
+REG64(IRS_VPE_SELR, 0x240)
+ FIELD(IRS_VPE_SELR, VM_ID, 0, 16)
+ FIELD(IRS_VPE_SELR, VPE_ID, 32, 16)
+ FIELD(IRS_VPE_SELR, S, 63, 1)
+
+REG64(IRS_VPE_DBR, 0x248)
+ FIELD(IRS_VPE_DBR, INTID, 0, 24)
+ FIELD(IRS_VPE_DBR, DBPM, 32, 5)
+ FIELD(IRS_VPE_DBR, REQ_DB, 62, 1)
+ FIELD(IRS_VPE_DBR, DBV, 63, 1)
+
+REG64(IRS_VPE_HPPIR, 0x250)
+ FIELD(IRS_VPE_HPPIR, ID, 0, 24)
+ FIELD(IRS_VPE_HPPIR, TYPE, 29, 3)
+ FIELD(IRS_VPE_HPPIR, HPPIV, 32, 1)
+
+REG32(IRS_VPE_CR0, 0x258)
+ FIELD(IRS_VPE_CR0, DPS, 0, 1)
+
+REG32(IRS_VPE_STATUSR, 0x25c)
+ FIELD(IRS_VPE_STATUSR, IDLE, 0, 1)
+ FIELD(IRS_VPE_STATUSR, V, 1, 1)
+
+REG64(IRS_VM_DBR, 0x280)
+ FIELD(IRS_VM_DBR, VPE_ID, 0, 16)
+ FIELD(IRS_VM_DBR, EN, 63, 1)
+
+REG32(IRS_VM_SELR, 0x288)
+ FIELD(IRS_VM_SELR, VM_ID, 0, 16)
+
+REG32(IRS_VM_STATUSR, 0x28c)
+ FIELD(IRS_VM_STATUSR, IDLE, 0, 1)
+ FIELD(IRS_VM_STATUSR, V, 1, 1)
+
+REG64(IRS_VMAP_L2_VMTR, 0x2c0)
+ FIELD(IRS_VMAP_L2_VMTR, VM_ID, 0, 16)
+ FIELD(IRS_VMAP_L2_VMTR, M, 63, 1)
+
+REG64(IRS_VMAP_VMR, 0x2c8)
+ FIELD(IRS_VMAP_VMR, VM_ID, 0, 16)
+ FIELD(IRS_VMAP_VMR, U, 62, 1)
+ FIELD(IRS_VMAP_VMR, M, 63, 1)
+
+REG64(IRS_VMAP_VISTR, 0x2d0)
+ FIELD(IRS_VMAP_VISTR, TYPE, 29, 3)
+ FIELD(IRS_VMAP_VISTR, VM_ID, 32, 16)
+ FIELD(IRS_VMAP_VISTR, U, 62, 1)
+ FIELD(IRS_VMAP_VISTR, M, 63, 1)
+
+REG64(IRS_VMAP_L2_VISTR, 0x2d8)
+ FIELD(IRS_VMAP_L2_VISTR, ID, 0, 24)
+ FIELD(IRS_VMAP_L2_VISTR, TYPE, 29, 3)
+ FIELD(IRS_VMAP_L2_VISTR, VM_ID, 32, 16)
+ FIELD(IRS_VMAP_L2_VISTR, M, 63, 1)
+
+REG64(IRS_VMAP_VPER, 0x2e0)
+ FIELD(IRS_VMAP_VPER, VPE_ID, 0, 16)
+ FIELD(IRS_VMAP_VPER, VM_ID, 32, 16)
+ FIELD(IRS_VMAP_VPER, M, 63, 1)
+
+REG64(IRS_SAVE_VMR, 0x300)
+ FIELD(IRS_SAVE_VMR, VM_ID, 0, 16)
+ FIELD(IRS_SAVE_VMR, Q, 62, 1)
+ FIELD(IRS_SAVE_VMR, S, 63, 1)
+
+REG32(IRS_SAVE_VM_STATUSR, 0x308)
+ FIELD(IRS_SAVE_VM_STATUSR, IDLE, 0, 1)
+ FIELD(IRS_SAVE_VM_STATUSR, Q, 1, 1)
+
+REG32(IRS_MEC_IDR, 0x340)
+ FIELD(IRS_MEC_IDR, MECIDSIZE, 0, 4)
+
+REG32(IRS_MEC_MECID_R, 0x344)
+ FIELD(IRS_MEC_MECID_R, MECID, 0, 16)
+
+REG32(IRS_MPAM_IDR, 0x380)
+ FIELD(IRS_MPAM_IDR, PARTID_MAX, 0, 16)
+ FIELD(IRS_MPAM_IDR, PMG_MAX, 16, 8)
+ FIELD(IRS_MPAM_IDR, HAS_MPAM_SP, 24, 1)
+
+REG32(IRS_MPAM_PARTID_R, 0x384)
+ FIELD(IRS_MPAM_PARTID, PARTID, 0, 16)
+ FIELD(IRS_MPAM_PARTID, PMG, 16, 8)
+ FIELD(IRS_MPAM_PARTID, MPAM_SP, 24, 2)
+ FIELD(IRS_MPAM_PARTID, IDLE, 31, 1)
+
+REG64(IRS_SWERR_STATUSR, 0x3c0)
+ FIELD(IRS_SWERR_STATUSR, V, 0, 1)
+ FIELD(IRS_SWERR_STATUSR, S0V, 1, 1)
+ FIELD(IRS_SWERR_STATUSR, S1V, 2, 1)
+ FIELD(IRS_SWERR_STATUSR, OF, 3, 1)
+ FIELD(IRS_SWERR_STATUSR, EC, 16, 8)
+ FIELD(IRS_SWERR_STATUSR, IMP_EC, 24, 8)
+
+REG64(IRS_SWERR_SYNDROMER0, 0x3c8)
+ FIELD(IRS_SWERR_SYNDROMER0, VM_ID, 0, 16)
+ FIELD(IRS_SWERR_SYNDROMER0, ID, 32, 24)
+ FIELD(IRS_SWERR_SYNDROMER0, TYPE, 60, 3)
+ FIELD(IRS_SWERR_SYNDROMER0, VIRTUAL, 63, 1)
+
+REG64(IRS_SWERR_SYNDROMER1, 0x3d0)
+ FIELD(IRS_SWERR_SYNDROMER1, ADDR, 3, 53)
+
+REG32(IRS_IDREGS, 0xffd0)
+REG32(IRS_DEVARCH, 0xffbc)
+
+FIELD(L1_ISTE, VALID, 0, 1)
+FIELD(L1_ISTE, L2_ADDR, 12, 44)
+
+FIELD(L2_ISTE, PENDING, 0, 1)
+FIELD(L2_ISTE, ACTIVE, 1, 1)
+FIELD(L2_ISTE, HM, 2, 1)
+FIELD(L2_ISTE, ENABLE, 3, 1)
+FIELD(L2_ISTE, IRM, 4, 1)
+FIELD(L2_ISTE, HWU, 9, 2)
+FIELD(L2_ISTE, PRIORITY, 11, 5)
+FIELD(L2_ISTE, IAFFID, 16, 16)
+
+/*
+ * Format used for gicv5_request_config() return value, which matches
+ * the ICC_ICSR_EL1 bit layout.
+ */
+FIELD(ICSR, F, 0, 1)
+FIELD(ICSR, ENABLED, 1, 1)
+FIELD(ICSR, PENDING, 2, 1)
+FIELD(ICSR, IRM, 3, 1)
+FIELD(ICSR, ACTIVE, 4, 1)
+FIELD(ICSR, HM, 5, 1)
+FIELD(ICSR, PRIORITY, 11, 5)
+FIELD(ICSR, IAFFID, 32, 16)
+
+#endif
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index c0e3e906754..2b9a8ad8718 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -15,6 +15,7 @@
#include "hw/core/registerfields.h"
#include "hw/intc/arm_gicv5.h"
#include "hw/intc/arm_gicv5_stream.h"
+#include "hw/intc/arm_gicv5_regs.h"
#include "qapi/error.h"
#include "qemu/log.h"
#include "trace.h"
@@ -48,275 +49,6 @@ static const char *inttype_name(GICv5IntType t)
return names[t];
}
-REG32(IRS_IDR0, 0x0)
- FIELD(IRS_IDR0, INT_DOM, 0, 2)
- FIELD(IRS_IDR0, PA_RANGE, 2, 4)
- FIELD(IRS_IDR0, VIRT, 6, 1)
- FIELD(IRS_IDR0, ONE_N, 7, 1)
- FIELD(IRS_IDR0, VIRT_ONE_N, 8, 1)
- FIELD(IRS_IDR0, SETLPI, 9, 1)
- FIELD(IRS_IDR0, MEC, 10, 1)
- FIELD(IRS_IDR0, MPAM, 11, 1)
- FIELD(IRS_IDR0, SWE, 12, 1)
- FIELD(IRS_IDR0, IRSID, 16, 16)
-
-REG32(IRS_IDR1, 0x4)
- FIELD(IRS_IDR1, PE_CNT, 0, 16)
- FIELD(IRS_IDR1, IAFFID_BITS, 16, 4)
- FIELD(IRS_IDR1, PRI_BITS, 20, 3)
-
-REG32(IRS_IDR2, 0x8)
- FIELD(IRS_IDR2, ID_BITS, 0, 5)
- FIELD(IRS_IDR2, LPI, 5, 1)
- FIELD(IRS_IDR2, MIN_LPI_ID_BITS, 6, 4)
- FIELD(IRS_IDR2, IST_LEVELS, 10, 1)
- FIELD(IRS_IDR2, IST_L2SZ, 11, 3)
- FIELD(IRS_IDR2, IST_MD, 14, 1)
- FIELD(IRS_IDR2, ISTMD_SZ, 15, 5)
-
-REG32(IRS_IDR3, 0xc)
- FIELD(IRS_IDR3, VMD, 0, 1)
- FIELD(IRS_IDR3, VMD_SZ, 1, 4)
- FIELD(IRS_IDR3, VM_ID_BITS, 5, 5)
- FIELD(IRS_IDR3, VMT_LEVELS, 10, 1)
-
-REG32(IRS_IDR4, 0x10)
- FIELD(IRS_IDR4, VPED_SZ, 0, 6)
- FIELD(IRS_IDR4, VPE_ID_BITS, 6, 4)
-
-REG32(IRS_IDR5, 0x14)
- FIELD(IRS_IDR5, SPI_RANGE, 0, 25)
-
-REG32(IRS_IDR6, 0x18)
- FIELD(IRS_IDR6, SPI_IRS_RANGE, 0, 25)
-
-REG32(IRS_IDR7, 0x1c)
- FIELD(IRS_IDR7, SPI_BASE, 0, 24)
-
-REG32(IRS_IIDR, 0x40)
- FIELD(IRS_IIDR, IMPLEMENTER, 0, 12)
- FIELD(IRS_IIDR, REVISION, 12, 4)
- FIELD(IRS_IIDR, VARIANT, 16, 4)
- FIELD(IRS_IIDR, PRODUCTID, 20, 12)
-
-REG32(IRS_AIDR, 0x44)
- FIELD(IRS_AIDR, ARCHMINORREV, 0, 4)
- FIELD(IRS_AIDR, ARCHMAJORREV, 4, 4)
- FIELD(IRS_AIDR, COMPONENT, 8, 4)
-
-REG32(IRS_CR0, 0x80)
- FIELD(IRS_CR0, IRSEN, 0, 1)
- FIELD(IRS_CR0, IDLE, 1, 1)
-
-REG32(IRS_CR1, 0x84)
- FIELD(IRS_CR1, SH, 0, 2)
- FIELD(IRS_CR1, OC, 2, 2)
- FIELD(IRS_CR1, IC, 4, 2)
- FIELD(IRS_CR1, IST_RA, 6, 1)
- FIELD(IRS_CR1, IST_WA, 7, 1)
- FIELD(IRS_CR1, VMT_RA, 8, 1)
- FIELD(IRS_CR1, VMT_WA, 9, 1)
- FIELD(IRS_CR1, VPET_RA, 10, 1)
- FIELD(IRS_CR1, VPET_WA, 11, 1)
- FIELD(IRS_CR1, VMD_RA, 12, 1)
- FIELD(IRS_CR1, VMD_WA, 13, 1)
- FIELD(IRS_CR1, VPED_RA, 14, 1)
- FIELD(IRS_CR1, VPED_WA, 15, 1)
-
-REG32(IRS_SYNCR, 0xc0)
- FIELD(IRS_SYNCR, SYNC, 31, 1)
-
-REG32(IRS_SYNC_STATUSR, 0xc4)
- FIELD(IRS_SYNC_STATUSR, IDLE, 0, 1)
-
-REG64(IRS_SPI_VMR, 0x100)
- FIELD(IRS_SPI_VMR, VM_ID, 0, 16)
- FIELD(IRS_SPI_VMR, VIRT, 63, 1)
-
-REG32(IRS_SPI_SELR, 0x108)
- FIELD(IRS_SPI_SELR, ID, 0, 24)
-
-REG32(IRS_SPI_DOMAINR, 0x10c)
- FIELD(IRS_SPI_DOMAINR, DOMAIN, 0, 2)
-
-REG32(IRS_SPI_RESAMPLER, 0x110)
- FIELD(IRS_SPI_RESAMPLER, SPI_ID, 0, 24)
-
-REG32(IRS_SPI_CFGR, 0x114)
- FIELD(IRS_SPI_CFGR, TM, 0, 1)
-
-REG32(IRS_SPI_STATUSR, 0x118)
- FIELD(IRS_SPI_STATUSR, IDLE, 0, 1)
- FIELD(IRS_SPI_STATUSR, V, 1, 1)
-
-REG32(IRS_PE_SELR, 0x140)
- FIELD(IRS_PE_SELR, IAFFID, 0, 16)
-
-REG32(IRS_PE_STATUSR, 0x144)
- FIELD(IRS_PE_STATUSR, IDLE, 0, 1)
- FIELD(IRS_PE_STATUSR, V, 1, 1)
- FIELD(IRS_PE_STATUSR, ONLINE, 2, 1)
-
-REG32(IRS_PE_CR0, 0x148)
- FIELD(IRS_PE_CR0, DPS, 0, 1)
-
-REG64(IRS_IST_BASER, 0x180)
- FIELD(IRS_IST_BASER, VALID, 0, 1)
- FIELD(IRS_IST_BASER, ADDR, 6, 50)
-
-REG32(IRS_IST_CFGR, 0x190)
- FIELD(IRS_IST_CFGR, LPI_ID_BITS, 0, 5)
- FIELD(IRS_IST_CFGR, L2SZ, 5, 2)
- FIELD(IRS_IST_CFGR, ISTSZ, 7, 2)
- FIELD(IRS_IST_CFGR, STRUCTURE, 16, 1)
-
-REG32(IRS_IST_STATUSR, 0x194)
- FIELD(IRS_IST_STATUSR, IDLE, 0, 1)
-
-REG32(IRS_MAP_L2_ISTR, 0x1c0)
- FIELD(IRS_MAP_L2_ISTR, ID, 0, 24)
-
-REG64(IRS_VMT_BASER, 0x200)
- FIELD(IRS_VMT_BASER, VALID, 0, 1)
- FIELD(IRS_VMT_BASER, ADDR, 3, 53)
-
-REG32(IRS_VMT_CFGR, 0x210)
- FIELD(IRS_VMT_CFGR, VM_ID_BITS, 0, 5)
- FIELD(IRS_VMT_CFGR, STRUCTURE, 16, 1)
-
-REG32(IRS_VMT_STATUSR, 0x124)
- FIELD(IRS_VMT_STATUSR, IDLE, 0, 1)
-
-REG64(IRS_VPE_SELR, 0x240)
- FIELD(IRS_VPE_SELR, VM_ID, 0, 16)
- FIELD(IRS_VPE_SELR, VPE_ID, 32, 16)
- FIELD(IRS_VPE_SELR, S, 63, 1)
-
-REG64(IRS_VPE_DBR, 0x248)
- FIELD(IRS_VPE_DBR, INTID, 0, 24)
- FIELD(IRS_VPE_DBR, DBPM, 32, 5)
- FIELD(IRS_VPE_DBR, REQ_DB, 62, 1)
- FIELD(IRS_VPE_DBR, DBV, 63, 1)
-
-REG64(IRS_VPE_HPPIR, 0x250)
- FIELD(IRS_VPE_HPPIR, ID, 0, 24)
- FIELD(IRS_VPE_HPPIR, TYPE, 29, 3)
- FIELD(IRS_VPE_HPPIR, HPPIV, 32, 1)
-
-REG32(IRS_VPE_CR0, 0x258)
- FIELD(IRS_VPE_CR0, DPS, 0, 1)
-
-REG32(IRS_VPE_STATUSR, 0x25c)
- FIELD(IRS_VPE_STATUSR, IDLE, 0, 1)
- FIELD(IRS_VPE_STATUSR, V, 1, 1)
-
-REG64(IRS_VM_DBR, 0x280)
- FIELD(IRS_VM_DBR, VPE_ID, 0, 16)
- FIELD(IRS_VM_DBR, EN, 63, 1)
-
-REG32(IRS_VM_SELR, 0x288)
- FIELD(IRS_VM_SELR, VM_ID, 0, 16)
-
-REG32(IRS_VM_STATUSR, 0x28c)
- FIELD(IRS_VM_STATUSR, IDLE, 0, 1)
- FIELD(IRS_VM_STATUSR, V, 1, 1)
-
-REG64(IRS_VMAP_L2_VMTR, 0x2c0)
- FIELD(IRS_VMAP_L2_VMTR, VM_ID, 0, 16)
- FIELD(IRS_VMAP_L2_VMTR, M, 63, 1)
-
-REG64(IRS_VMAP_VMR, 0x2c8)
- FIELD(IRS_VMAP_VMR, VM_ID, 0, 16)
- FIELD(IRS_VMAP_VMR, U, 62, 1)
- FIELD(IRS_VMAP_VMR, M, 63, 1)
-
-REG64(IRS_VMAP_VISTR, 0x2d0)
- FIELD(IRS_VMAP_VISTR, TYPE, 29, 3)
- FIELD(IRS_VMAP_VISTR, VM_ID, 32, 16)
- FIELD(IRS_VMAP_VISTR, U, 62, 1)
- FIELD(IRS_VMAP_VISTR, M, 63, 1)
-
-REG64(IRS_VMAP_L2_VISTR, 0x2d8)
- FIELD(IRS_VMAP_L2_VISTR, ID, 0, 24)
- FIELD(IRS_VMAP_L2_VISTR, TYPE, 29, 3)
- FIELD(IRS_VMAP_L2_VISTR, VM_ID, 32, 16)
- FIELD(IRS_VMAP_L2_VISTR, M, 63, 1)
-
-REG64(IRS_VMAP_VPER, 0x2e0)
- FIELD(IRS_VMAP_VPER, VPE_ID, 0, 16)
- FIELD(IRS_VMAP_VPER, VM_ID, 32, 16)
- FIELD(IRS_VMAP_VPER, M, 63, 1)
-
-REG64(IRS_SAVE_VMR, 0x300)
- FIELD(IRS_SAVE_VMR, VM_ID, 0, 16)
- FIELD(IRS_SAVE_VMR, Q, 62, 1)
- FIELD(IRS_SAVE_VMR, S, 63, 1)
-
-REG32(IRS_SAVE_VM_STATUSR, 0x308)
- FIELD(IRS_SAVE_VM_STATUSR, IDLE, 0, 1)
- FIELD(IRS_SAVE_VM_STATUSR, Q, 1, 1)
-
-REG32(IRS_MEC_IDR, 0x340)
- FIELD(IRS_MEC_IDR, MECIDSIZE, 0, 4)
-
-REG32(IRS_MEC_MECID_R, 0x344)
- FIELD(IRS_MEC_MECID_R, MECID, 0, 16)
-
-REG32(IRS_MPAM_IDR, 0x380)
- FIELD(IRS_MPAM_IDR, PARTID_MAX, 0, 16)
- FIELD(IRS_MPAM_IDR, PMG_MAX, 16, 8)
- FIELD(IRS_MPAM_IDR, HAS_MPAM_SP, 24, 1)
-
-REG32(IRS_MPAM_PARTID_R, 0x384)
- FIELD(IRS_MPAM_PARTID, PARTID, 0, 16)
- FIELD(IRS_MPAM_PARTID, PMG, 16, 8)
- FIELD(IRS_MPAM_PARTID, MPAM_SP, 24, 2)
- FIELD(IRS_MPAM_PARTID, IDLE, 31, 1)
-
-REG64(IRS_SWERR_STATUSR, 0x3c0)
- FIELD(IRS_SWERR_STATUSR, V, 0, 1)
- FIELD(IRS_SWERR_STATUSR, S0V, 1, 1)
- FIELD(IRS_SWERR_STATUSR, S1V, 2, 1)
- FIELD(IRS_SWERR_STATUSR, OF, 3, 1)
- FIELD(IRS_SWERR_STATUSR, EC, 16, 8)
- FIELD(IRS_SWERR_STATUSR, IMP_EC, 24, 8)
-
-REG64(IRS_SWERR_SYNDROMER0, 0x3c8)
- FIELD(IRS_SWERR_SYNDROMER0, VM_ID, 0, 16)
- FIELD(IRS_SWERR_SYNDROMER0, ID, 32, 24)
- FIELD(IRS_SWERR_SYNDROMER0, TYPE, 60, 3)
- FIELD(IRS_SWERR_SYNDROMER0, VIRTUAL, 63, 1)
-
-REG64(IRS_SWERR_SYNDROMER1, 0x3d0)
- FIELD(IRS_SWERR_SYNDROMER1, ADDR, 3, 53)
-
-REG32(IRS_IDREGS, 0xffd0)
-REG32(IRS_DEVARCH, 0xffbc)
-
-FIELD(L1_ISTE, VALID, 0, 1)
-FIELD(L1_ISTE, L2_ADDR, 12, 44)
-
-FIELD(L2_ISTE, PENDING, 0, 1)
-FIELD(L2_ISTE, ACTIVE, 1, 1)
-FIELD(L2_ISTE, HM, 2, 1)
-FIELD(L2_ISTE, ENABLE, 3, 1)
-FIELD(L2_ISTE, IRM, 4, 1)
-FIELD(L2_ISTE, HWU, 9, 2)
-FIELD(L2_ISTE, PRIORITY, 11, 5)
-FIELD(L2_ISTE, IAFFID, 16, 16)
-
-/*
- * Format used for gicv5_request_config() return value, which matches
- * the ICC_ICSR_EL1 bit layout.
- */
-FIELD(ICSR, F, 0, 1)
-FIELD(ICSR, ENABLED, 1, 1)
-FIELD(ICSR, PENDING, 2, 1)
-FIELD(ICSR, IRM, 3, 1)
-FIELD(ICSR, ACTIVE, 4, 1)
-FIELD(ICSR, HM, 5, 1)
-FIELD(ICSR, PRIORITY, 11, 5)
-FIELD(ICSR, IAFFID, 32, 16)
#define IRS_DEVARCH_VALUE ((0x23b << 21) | (0x1 << 20) | 0x5a19)
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* Re: [PATCH v2 40/77] hw/intc: Move GICv5 register and data definitions into a header
2026-12-03 11:10 ` [PATCH v2 40/77] hw/intc: Move GICv5 register and data definitions into a header Peter Maydell
@ 2026-12-04 7:56 ` Manos Pitsidianakis
0 siblings, 0 replies; 99+ messages in thread
From: Manos Pitsidianakis @ 2026-12-04 7:56 UTC (permalink / raw)
To: Peter Maydell, qemu-arm, qemu-devel
Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
On Thu, 03 Dec 2026 13:10, Peter Maydell <peter.maydell@linaro.org> wrote:
>We put the definitions of GICv5 IRS registers and guest-memory data
>structures directly into arm_gicv5.c. It turns out that there are a
>few cases where we would like them outside that file (for instance
>register reset is handled in arm_gicv5_common.c).
>
>Move the definitions to their own header file.
>
>Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>---
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
> include/hw/intc/arm_gicv5_regs.h | 286 +++++++++++++++++++++++++++++++
> hw/intc/arm_gicv5.c | 270 +----------------------------
> 2 files changed, 287 insertions(+), 269 deletions(-)
> create mode 100644 include/hw/intc/arm_gicv5_regs.h
>
>diff --git a/include/hw/intc/arm_gicv5_regs.h b/include/hw/intc/arm_gicv5_regs.h
>new file mode 100644
>index 00000000000..c504d8642d7
>--- /dev/null
>+++ b/include/hw/intc/arm_gicv5_regs.h
>@@ -0,0 +1,286 @@
>+/*
>+ * ARM GICv5 emulation: Interrupt Routing Service (IRS) registers
>+ *
>+ * Copyright (c) 2025 Linaro Limited
>+ *
>+ * SPDX-License-Identifier: GPL-2.0-or-later
>+ *
>+ * This file has definitions of IRS register layouts and
>+ * in-guest-memory data structures, that shouldn't be needed
>+ * outside the IRS implementation.
>+ */
>+
>+#ifndef HW_INTC_ARM_GICV5_REGS_H
>+#define HW_INTC_ARM_GICV5_REGS_H
>+
>+REG32(IRS_IDR0, 0x0)
>+ FIELD(IRS_IDR0, INT_DOM, 0, 2)
>+ FIELD(IRS_IDR0, PA_RANGE, 2, 4)
>+ FIELD(IRS_IDR0, VIRT, 6, 1)
>+ FIELD(IRS_IDR0, ONE_N, 7, 1)
>+ FIELD(IRS_IDR0, VIRT_ONE_N, 8, 1)
>+ FIELD(IRS_IDR0, SETLPI, 9, 1)
>+ FIELD(IRS_IDR0, MEC, 10, 1)
>+ FIELD(IRS_IDR0, MPAM, 11, 1)
>+ FIELD(IRS_IDR0, SWE, 12, 1)
>+ FIELD(IRS_IDR0, IRSID, 16, 16)
>+
>+REG32(IRS_IDR1, 0x4)
>+ FIELD(IRS_IDR1, PE_CNT, 0, 16)
>+ FIELD(IRS_IDR1, IAFFID_BITS, 16, 4)
>+ FIELD(IRS_IDR1, PRI_BITS, 20, 3)
>+
>+REG32(IRS_IDR2, 0x8)
>+ FIELD(IRS_IDR2, ID_BITS, 0, 5)
>+ FIELD(IRS_IDR2, LPI, 5, 1)
>+ FIELD(IRS_IDR2, MIN_LPI_ID_BITS, 6, 4)
>+ FIELD(IRS_IDR2, IST_LEVELS, 10, 1)
>+ FIELD(IRS_IDR2, IST_L2SZ, 11, 3)
>+ FIELD(IRS_IDR2, IST_MD, 14, 1)
>+ FIELD(IRS_IDR2, ISTMD_SZ, 15, 5)
>+
>+REG32(IRS_IDR3, 0xc)
>+ FIELD(IRS_IDR3, VMD, 0, 1)
>+ FIELD(IRS_IDR3, VMD_SZ, 1, 4)
>+ FIELD(IRS_IDR3, VM_ID_BITS, 5, 5)
>+ FIELD(IRS_IDR3, VMT_LEVELS, 10, 1)
>+
>+REG32(IRS_IDR4, 0x10)
>+ FIELD(IRS_IDR4, VPED_SZ, 0, 6)
>+ FIELD(IRS_IDR4, VPE_ID_BITS, 6, 4)
>+
>+REG32(IRS_IDR5, 0x14)
>+ FIELD(IRS_IDR5, SPI_RANGE, 0, 25)
>+
>+REG32(IRS_IDR6, 0x18)
>+ FIELD(IRS_IDR6, SPI_IRS_RANGE, 0, 25)
>+
>+REG32(IRS_IDR7, 0x1c)
>+ FIELD(IRS_IDR7, SPI_BASE, 0, 24)
>+
>+REG32(IRS_IIDR, 0x40)
>+ FIELD(IRS_IIDR, IMPLEMENTER, 0, 12)
>+ FIELD(IRS_IIDR, REVISION, 12, 4)
>+ FIELD(IRS_IIDR, VARIANT, 16, 4)
>+ FIELD(IRS_IIDR, PRODUCTID, 20, 12)
>+
>+REG32(IRS_AIDR, 0x44)
>+ FIELD(IRS_AIDR, ARCHMINORREV, 0, 4)
>+ FIELD(IRS_AIDR, ARCHMAJORREV, 4, 4)
>+ FIELD(IRS_AIDR, COMPONENT, 8, 4)
>+
>+REG32(IRS_CR0, 0x80)
>+ FIELD(IRS_CR0, IRSEN, 0, 1)
>+ FIELD(IRS_CR0, IDLE, 1, 1)
>+
>+REG32(IRS_CR1, 0x84)
>+ FIELD(IRS_CR1, SH, 0, 2)
>+ FIELD(IRS_CR1, OC, 2, 2)
>+ FIELD(IRS_CR1, IC, 4, 2)
>+ FIELD(IRS_CR1, IST_RA, 6, 1)
>+ FIELD(IRS_CR1, IST_WA, 7, 1)
>+ FIELD(IRS_CR1, VMT_RA, 8, 1)
>+ FIELD(IRS_CR1, VMT_WA, 9, 1)
>+ FIELD(IRS_CR1, VPET_RA, 10, 1)
>+ FIELD(IRS_CR1, VPET_WA, 11, 1)
>+ FIELD(IRS_CR1, VMD_RA, 12, 1)
>+ FIELD(IRS_CR1, VMD_WA, 13, 1)
>+ FIELD(IRS_CR1, VPED_RA, 14, 1)
>+ FIELD(IRS_CR1, VPED_WA, 15, 1)
>+
>+REG32(IRS_SYNCR, 0xc0)
>+ FIELD(IRS_SYNCR, SYNC, 31, 1)
>+
>+REG32(IRS_SYNC_STATUSR, 0xc4)
>+ FIELD(IRS_SYNC_STATUSR, IDLE, 0, 1)
>+
>+REG64(IRS_SPI_VMR, 0x100)
>+ FIELD(IRS_SPI_VMR, VM_ID, 0, 16)
>+ FIELD(IRS_SPI_VMR, VIRT, 63, 1)
>+
>+REG32(IRS_SPI_SELR, 0x108)
>+ FIELD(IRS_SPI_SELR, ID, 0, 24)
>+
>+REG32(IRS_SPI_DOMAINR, 0x10c)
>+ FIELD(IRS_SPI_DOMAINR, DOMAIN, 0, 2)
>+
>+REG32(IRS_SPI_RESAMPLER, 0x110)
>+ FIELD(IRS_SPI_RESAMPLER, SPI_ID, 0, 24)
>+
>+REG32(IRS_SPI_CFGR, 0x114)
>+ FIELD(IRS_SPI_CFGR, TM, 0, 1)
>+
>+REG32(IRS_SPI_STATUSR, 0x118)
>+ FIELD(IRS_SPI_STATUSR, IDLE, 0, 1)
>+ FIELD(IRS_SPI_STATUSR, V, 1, 1)
>+
>+REG32(IRS_PE_SELR, 0x140)
>+ FIELD(IRS_PE_SELR, IAFFID, 0, 16)
>+
>+REG32(IRS_PE_STATUSR, 0x144)
>+ FIELD(IRS_PE_STATUSR, IDLE, 0, 1)
>+ FIELD(IRS_PE_STATUSR, V, 1, 1)
>+ FIELD(IRS_PE_STATUSR, ONLINE, 2, 1)
>+
>+REG32(IRS_PE_CR0, 0x148)
>+ FIELD(IRS_PE_CR0, DPS, 0, 1)
>+
>+REG64(IRS_IST_BASER, 0x180)
>+ FIELD(IRS_IST_BASER, VALID, 0, 1)
>+ FIELD(IRS_IST_BASER, ADDR, 6, 50)
>+
>+REG32(IRS_IST_CFGR, 0x190)
>+ FIELD(IRS_IST_CFGR, LPI_ID_BITS, 0, 5)
>+ FIELD(IRS_IST_CFGR, L2SZ, 5, 2)
>+ FIELD(IRS_IST_CFGR, ISTSZ, 7, 2)
>+ FIELD(IRS_IST_CFGR, STRUCTURE, 16, 1)
>+
>+REG32(IRS_IST_STATUSR, 0x194)
>+ FIELD(IRS_IST_STATUSR, IDLE, 0, 1)
>+
>+REG32(IRS_MAP_L2_ISTR, 0x1c0)
>+ FIELD(IRS_MAP_L2_ISTR, ID, 0, 24)
>+
>+REG64(IRS_VMT_BASER, 0x200)
>+ FIELD(IRS_VMT_BASER, VALID, 0, 1)
>+ FIELD(IRS_VMT_BASER, ADDR, 3, 53)
>+
>+REG32(IRS_VMT_CFGR, 0x210)
>+ FIELD(IRS_VMT_CFGR, VM_ID_BITS, 0, 5)
>+ FIELD(IRS_VMT_CFGR, STRUCTURE, 16, 1)
>+
>+REG32(IRS_VMT_STATUSR, 0x124)
>+ FIELD(IRS_VMT_STATUSR, IDLE, 0, 1)
>+
>+REG64(IRS_VPE_SELR, 0x240)
>+ FIELD(IRS_VPE_SELR, VM_ID, 0, 16)
>+ FIELD(IRS_VPE_SELR, VPE_ID, 32, 16)
>+ FIELD(IRS_VPE_SELR, S, 63, 1)
>+
>+REG64(IRS_VPE_DBR, 0x248)
>+ FIELD(IRS_VPE_DBR, INTID, 0, 24)
>+ FIELD(IRS_VPE_DBR, DBPM, 32, 5)
>+ FIELD(IRS_VPE_DBR, REQ_DB, 62, 1)
>+ FIELD(IRS_VPE_DBR, DBV, 63, 1)
>+
>+REG64(IRS_VPE_HPPIR, 0x250)
>+ FIELD(IRS_VPE_HPPIR, ID, 0, 24)
>+ FIELD(IRS_VPE_HPPIR, TYPE, 29, 3)
>+ FIELD(IRS_VPE_HPPIR, HPPIV, 32, 1)
>+
>+REG32(IRS_VPE_CR0, 0x258)
>+ FIELD(IRS_VPE_CR0, DPS, 0, 1)
>+
>+REG32(IRS_VPE_STATUSR, 0x25c)
>+ FIELD(IRS_VPE_STATUSR, IDLE, 0, 1)
>+ FIELD(IRS_VPE_STATUSR, V, 1, 1)
>+
>+REG64(IRS_VM_DBR, 0x280)
>+ FIELD(IRS_VM_DBR, VPE_ID, 0, 16)
>+ FIELD(IRS_VM_DBR, EN, 63, 1)
>+
>+REG32(IRS_VM_SELR, 0x288)
>+ FIELD(IRS_VM_SELR, VM_ID, 0, 16)
>+
>+REG32(IRS_VM_STATUSR, 0x28c)
>+ FIELD(IRS_VM_STATUSR, IDLE, 0, 1)
>+ FIELD(IRS_VM_STATUSR, V, 1, 1)
>+
>+REG64(IRS_VMAP_L2_VMTR, 0x2c0)
>+ FIELD(IRS_VMAP_L2_VMTR, VM_ID, 0, 16)
>+ FIELD(IRS_VMAP_L2_VMTR, M, 63, 1)
>+
>+REG64(IRS_VMAP_VMR, 0x2c8)
>+ FIELD(IRS_VMAP_VMR, VM_ID, 0, 16)
>+ FIELD(IRS_VMAP_VMR, U, 62, 1)
>+ FIELD(IRS_VMAP_VMR, M, 63, 1)
>+
>+REG64(IRS_VMAP_VISTR, 0x2d0)
>+ FIELD(IRS_VMAP_VISTR, TYPE, 29, 3)
>+ FIELD(IRS_VMAP_VISTR, VM_ID, 32, 16)
>+ FIELD(IRS_VMAP_VISTR, U, 62, 1)
>+ FIELD(IRS_VMAP_VISTR, M, 63, 1)
>+
>+REG64(IRS_VMAP_L2_VISTR, 0x2d8)
>+ FIELD(IRS_VMAP_L2_VISTR, ID, 0, 24)
>+ FIELD(IRS_VMAP_L2_VISTR, TYPE, 29, 3)
>+ FIELD(IRS_VMAP_L2_VISTR, VM_ID, 32, 16)
>+ FIELD(IRS_VMAP_L2_VISTR, M, 63, 1)
>+
>+REG64(IRS_VMAP_VPER, 0x2e0)
>+ FIELD(IRS_VMAP_VPER, VPE_ID, 0, 16)
>+ FIELD(IRS_VMAP_VPER, VM_ID, 32, 16)
>+ FIELD(IRS_VMAP_VPER, M, 63, 1)
>+
>+REG64(IRS_SAVE_VMR, 0x300)
>+ FIELD(IRS_SAVE_VMR, VM_ID, 0, 16)
>+ FIELD(IRS_SAVE_VMR, Q, 62, 1)
>+ FIELD(IRS_SAVE_VMR, S, 63, 1)
>+
>+REG32(IRS_SAVE_VM_STATUSR, 0x308)
>+ FIELD(IRS_SAVE_VM_STATUSR, IDLE, 0, 1)
>+ FIELD(IRS_SAVE_VM_STATUSR, Q, 1, 1)
>+
>+REG32(IRS_MEC_IDR, 0x340)
>+ FIELD(IRS_MEC_IDR, MECIDSIZE, 0, 4)
>+
>+REG32(IRS_MEC_MECID_R, 0x344)
>+ FIELD(IRS_MEC_MECID_R, MECID, 0, 16)
>+
>+REG32(IRS_MPAM_IDR, 0x380)
>+ FIELD(IRS_MPAM_IDR, PARTID_MAX, 0, 16)
>+ FIELD(IRS_MPAM_IDR, PMG_MAX, 16, 8)
>+ FIELD(IRS_MPAM_IDR, HAS_MPAM_SP, 24, 1)
>+
>+REG32(IRS_MPAM_PARTID_R, 0x384)
>+ FIELD(IRS_MPAM_PARTID, PARTID, 0, 16)
>+ FIELD(IRS_MPAM_PARTID, PMG, 16, 8)
>+ FIELD(IRS_MPAM_PARTID, MPAM_SP, 24, 2)
>+ FIELD(IRS_MPAM_PARTID, IDLE, 31, 1)
>+
>+REG64(IRS_SWERR_STATUSR, 0x3c0)
>+ FIELD(IRS_SWERR_STATUSR, V, 0, 1)
>+ FIELD(IRS_SWERR_STATUSR, S0V, 1, 1)
>+ FIELD(IRS_SWERR_STATUSR, S1V, 2, 1)
>+ FIELD(IRS_SWERR_STATUSR, OF, 3, 1)
>+ FIELD(IRS_SWERR_STATUSR, EC, 16, 8)
>+ FIELD(IRS_SWERR_STATUSR, IMP_EC, 24, 8)
>+
>+REG64(IRS_SWERR_SYNDROMER0, 0x3c8)
>+ FIELD(IRS_SWERR_SYNDROMER0, VM_ID, 0, 16)
>+ FIELD(IRS_SWERR_SYNDROMER0, ID, 32, 24)
>+ FIELD(IRS_SWERR_SYNDROMER0, TYPE, 60, 3)
>+ FIELD(IRS_SWERR_SYNDROMER0, VIRTUAL, 63, 1)
>+
>+REG64(IRS_SWERR_SYNDROMER1, 0x3d0)
>+ FIELD(IRS_SWERR_SYNDROMER1, ADDR, 3, 53)
>+
>+REG32(IRS_IDREGS, 0xffd0)
>+REG32(IRS_DEVARCH, 0xffbc)
>+
>+FIELD(L1_ISTE, VALID, 0, 1)
>+FIELD(L1_ISTE, L2_ADDR, 12, 44)
>+
>+FIELD(L2_ISTE, PENDING, 0, 1)
>+FIELD(L2_ISTE, ACTIVE, 1, 1)
>+FIELD(L2_ISTE, HM, 2, 1)
>+FIELD(L2_ISTE, ENABLE, 3, 1)
>+FIELD(L2_ISTE, IRM, 4, 1)
>+FIELD(L2_ISTE, HWU, 9, 2)
>+FIELD(L2_ISTE, PRIORITY, 11, 5)
>+FIELD(L2_ISTE, IAFFID, 16, 16)
>+
>+/*
>+ * Format used for gicv5_request_config() return value, which matches
>+ * the ICC_ICSR_EL1 bit layout.
>+ */
>+FIELD(ICSR, F, 0, 1)
>+FIELD(ICSR, ENABLED, 1, 1)
>+FIELD(ICSR, PENDING, 2, 1)
>+FIELD(ICSR, IRM, 3, 1)
>+FIELD(ICSR, ACTIVE, 4, 1)
>+FIELD(ICSR, HM, 5, 1)
>+FIELD(ICSR, PRIORITY, 11, 5)
>+FIELD(ICSR, IAFFID, 32, 16)
>+
>+#endif
>diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
>index c0e3e906754..2b9a8ad8718 100644
>--- a/hw/intc/arm_gicv5.c
>+++ b/hw/intc/arm_gicv5.c
>@@ -15,6 +15,7 @@
> #include "hw/core/registerfields.h"
> #include "hw/intc/arm_gicv5.h"
> #include "hw/intc/arm_gicv5_stream.h"
>+#include "hw/intc/arm_gicv5_regs.h"
> #include "qapi/error.h"
> #include "qemu/log.h"
> #include "trace.h"
>@@ -48,275 +49,6 @@ static const char *inttype_name(GICv5IntType t)
> return names[t];
> }
>
>-REG32(IRS_IDR0, 0x0)
>- FIELD(IRS_IDR0, INT_DOM, 0, 2)
>- FIELD(IRS_IDR0, PA_RANGE, 2, 4)
>- FIELD(IRS_IDR0, VIRT, 6, 1)
>- FIELD(IRS_IDR0, ONE_N, 7, 1)
>- FIELD(IRS_IDR0, VIRT_ONE_N, 8, 1)
>- FIELD(IRS_IDR0, SETLPI, 9, 1)
>- FIELD(IRS_IDR0, MEC, 10, 1)
>- FIELD(IRS_IDR0, MPAM, 11, 1)
>- FIELD(IRS_IDR0, SWE, 12, 1)
>- FIELD(IRS_IDR0, IRSID, 16, 16)
>-
>-REG32(IRS_IDR1, 0x4)
>- FIELD(IRS_IDR1, PE_CNT, 0, 16)
>- FIELD(IRS_IDR1, IAFFID_BITS, 16, 4)
>- FIELD(IRS_IDR1, PRI_BITS, 20, 3)
>-
>-REG32(IRS_IDR2, 0x8)
>- FIELD(IRS_IDR2, ID_BITS, 0, 5)
>- FIELD(IRS_IDR2, LPI, 5, 1)
>- FIELD(IRS_IDR2, MIN_LPI_ID_BITS, 6, 4)
>- FIELD(IRS_IDR2, IST_LEVELS, 10, 1)
>- FIELD(IRS_IDR2, IST_L2SZ, 11, 3)
>- FIELD(IRS_IDR2, IST_MD, 14, 1)
>- FIELD(IRS_IDR2, ISTMD_SZ, 15, 5)
>-
>-REG32(IRS_IDR3, 0xc)
>- FIELD(IRS_IDR3, VMD, 0, 1)
>- FIELD(IRS_IDR3, VMD_SZ, 1, 4)
>- FIELD(IRS_IDR3, VM_ID_BITS, 5, 5)
>- FIELD(IRS_IDR3, VMT_LEVELS, 10, 1)
>-
>-REG32(IRS_IDR4, 0x10)
>- FIELD(IRS_IDR4, VPED_SZ, 0, 6)
>- FIELD(IRS_IDR4, VPE_ID_BITS, 6, 4)
>-
>-REG32(IRS_IDR5, 0x14)
>- FIELD(IRS_IDR5, SPI_RANGE, 0, 25)
>-
>-REG32(IRS_IDR6, 0x18)
>- FIELD(IRS_IDR6, SPI_IRS_RANGE, 0, 25)
>-
>-REG32(IRS_IDR7, 0x1c)
>- FIELD(IRS_IDR7, SPI_BASE, 0, 24)
>-
>-REG32(IRS_IIDR, 0x40)
>- FIELD(IRS_IIDR, IMPLEMENTER, 0, 12)
>- FIELD(IRS_IIDR, REVISION, 12, 4)
>- FIELD(IRS_IIDR, VARIANT, 16, 4)
>- FIELD(IRS_IIDR, PRODUCTID, 20, 12)
>-
>-REG32(IRS_AIDR, 0x44)
>- FIELD(IRS_AIDR, ARCHMINORREV, 0, 4)
>- FIELD(IRS_AIDR, ARCHMAJORREV, 4, 4)
>- FIELD(IRS_AIDR, COMPONENT, 8, 4)
>-
>-REG32(IRS_CR0, 0x80)
>- FIELD(IRS_CR0, IRSEN, 0, 1)
>- FIELD(IRS_CR0, IDLE, 1, 1)
>-
>-REG32(IRS_CR1, 0x84)
>- FIELD(IRS_CR1, SH, 0, 2)
>- FIELD(IRS_CR1, OC, 2, 2)
>- FIELD(IRS_CR1, IC, 4, 2)
>- FIELD(IRS_CR1, IST_RA, 6, 1)
>- FIELD(IRS_CR1, IST_WA, 7, 1)
>- FIELD(IRS_CR1, VMT_RA, 8, 1)
>- FIELD(IRS_CR1, VMT_WA, 9, 1)
>- FIELD(IRS_CR1, VPET_RA, 10, 1)
>- FIELD(IRS_CR1, VPET_WA, 11, 1)
>- FIELD(IRS_CR1, VMD_RA, 12, 1)
>- FIELD(IRS_CR1, VMD_WA, 13, 1)
>- FIELD(IRS_CR1, VPED_RA, 14, 1)
>- FIELD(IRS_CR1, VPED_WA, 15, 1)
>-
>-REG32(IRS_SYNCR, 0xc0)
>- FIELD(IRS_SYNCR, SYNC, 31, 1)
>-
>-REG32(IRS_SYNC_STATUSR, 0xc4)
>- FIELD(IRS_SYNC_STATUSR, IDLE, 0, 1)
>-
>-REG64(IRS_SPI_VMR, 0x100)
>- FIELD(IRS_SPI_VMR, VM_ID, 0, 16)
>- FIELD(IRS_SPI_VMR, VIRT, 63, 1)
>-
>-REG32(IRS_SPI_SELR, 0x108)
>- FIELD(IRS_SPI_SELR, ID, 0, 24)
>-
>-REG32(IRS_SPI_DOMAINR, 0x10c)
>- FIELD(IRS_SPI_DOMAINR, DOMAIN, 0, 2)
>-
>-REG32(IRS_SPI_RESAMPLER, 0x110)
>- FIELD(IRS_SPI_RESAMPLER, SPI_ID, 0, 24)
>-
>-REG32(IRS_SPI_CFGR, 0x114)
>- FIELD(IRS_SPI_CFGR, TM, 0, 1)
>-
>-REG32(IRS_SPI_STATUSR, 0x118)
>- FIELD(IRS_SPI_STATUSR, IDLE, 0, 1)
>- FIELD(IRS_SPI_STATUSR, V, 1, 1)
>-
>-REG32(IRS_PE_SELR, 0x140)
>- FIELD(IRS_PE_SELR, IAFFID, 0, 16)
>-
>-REG32(IRS_PE_STATUSR, 0x144)
>- FIELD(IRS_PE_STATUSR, IDLE, 0, 1)
>- FIELD(IRS_PE_STATUSR, V, 1, 1)
>- FIELD(IRS_PE_STATUSR, ONLINE, 2, 1)
>-
>-REG32(IRS_PE_CR0, 0x148)
>- FIELD(IRS_PE_CR0, DPS, 0, 1)
>-
>-REG64(IRS_IST_BASER, 0x180)
>- FIELD(IRS_IST_BASER, VALID, 0, 1)
>- FIELD(IRS_IST_BASER, ADDR, 6, 50)
>-
>-REG32(IRS_IST_CFGR, 0x190)
>- FIELD(IRS_IST_CFGR, LPI_ID_BITS, 0, 5)
>- FIELD(IRS_IST_CFGR, L2SZ, 5, 2)
>- FIELD(IRS_IST_CFGR, ISTSZ, 7, 2)
>- FIELD(IRS_IST_CFGR, STRUCTURE, 16, 1)
>-
>-REG32(IRS_IST_STATUSR, 0x194)
>- FIELD(IRS_IST_STATUSR, IDLE, 0, 1)
>-
>-REG32(IRS_MAP_L2_ISTR, 0x1c0)
>- FIELD(IRS_MAP_L2_ISTR, ID, 0, 24)
>-
>-REG64(IRS_VMT_BASER, 0x200)
>- FIELD(IRS_VMT_BASER, VALID, 0, 1)
>- FIELD(IRS_VMT_BASER, ADDR, 3, 53)
>-
>-REG32(IRS_VMT_CFGR, 0x210)
>- FIELD(IRS_VMT_CFGR, VM_ID_BITS, 0, 5)
>- FIELD(IRS_VMT_CFGR, STRUCTURE, 16, 1)
>-
>-REG32(IRS_VMT_STATUSR, 0x124)
>- FIELD(IRS_VMT_STATUSR, IDLE, 0, 1)
>-
>-REG64(IRS_VPE_SELR, 0x240)
>- FIELD(IRS_VPE_SELR, VM_ID, 0, 16)
>- FIELD(IRS_VPE_SELR, VPE_ID, 32, 16)
>- FIELD(IRS_VPE_SELR, S, 63, 1)
>-
>-REG64(IRS_VPE_DBR, 0x248)
>- FIELD(IRS_VPE_DBR, INTID, 0, 24)
>- FIELD(IRS_VPE_DBR, DBPM, 32, 5)
>- FIELD(IRS_VPE_DBR, REQ_DB, 62, 1)
>- FIELD(IRS_VPE_DBR, DBV, 63, 1)
>-
>-REG64(IRS_VPE_HPPIR, 0x250)
>- FIELD(IRS_VPE_HPPIR, ID, 0, 24)
>- FIELD(IRS_VPE_HPPIR, TYPE, 29, 3)
>- FIELD(IRS_VPE_HPPIR, HPPIV, 32, 1)
>-
>-REG32(IRS_VPE_CR0, 0x258)
>- FIELD(IRS_VPE_CR0, DPS, 0, 1)
>-
>-REG32(IRS_VPE_STATUSR, 0x25c)
>- FIELD(IRS_VPE_STATUSR, IDLE, 0, 1)
>- FIELD(IRS_VPE_STATUSR, V, 1, 1)
>-
>-REG64(IRS_VM_DBR, 0x280)
>- FIELD(IRS_VM_DBR, VPE_ID, 0, 16)
>- FIELD(IRS_VM_DBR, EN, 63, 1)
>-
>-REG32(IRS_VM_SELR, 0x288)
>- FIELD(IRS_VM_SELR, VM_ID, 0, 16)
>-
>-REG32(IRS_VM_STATUSR, 0x28c)
>- FIELD(IRS_VM_STATUSR, IDLE, 0, 1)
>- FIELD(IRS_VM_STATUSR, V, 1, 1)
>-
>-REG64(IRS_VMAP_L2_VMTR, 0x2c0)
>- FIELD(IRS_VMAP_L2_VMTR, VM_ID, 0, 16)
>- FIELD(IRS_VMAP_L2_VMTR, M, 63, 1)
>-
>-REG64(IRS_VMAP_VMR, 0x2c8)
>- FIELD(IRS_VMAP_VMR, VM_ID, 0, 16)
>- FIELD(IRS_VMAP_VMR, U, 62, 1)
>- FIELD(IRS_VMAP_VMR, M, 63, 1)
>-
>-REG64(IRS_VMAP_VISTR, 0x2d0)
>- FIELD(IRS_VMAP_VISTR, TYPE, 29, 3)
>- FIELD(IRS_VMAP_VISTR, VM_ID, 32, 16)
>- FIELD(IRS_VMAP_VISTR, U, 62, 1)
>- FIELD(IRS_VMAP_VISTR, M, 63, 1)
>-
>-REG64(IRS_VMAP_L2_VISTR, 0x2d8)
>- FIELD(IRS_VMAP_L2_VISTR, ID, 0, 24)
>- FIELD(IRS_VMAP_L2_VISTR, TYPE, 29, 3)
>- FIELD(IRS_VMAP_L2_VISTR, VM_ID, 32, 16)
>- FIELD(IRS_VMAP_L2_VISTR, M, 63, 1)
>-
>-REG64(IRS_VMAP_VPER, 0x2e0)
>- FIELD(IRS_VMAP_VPER, VPE_ID, 0, 16)
>- FIELD(IRS_VMAP_VPER, VM_ID, 32, 16)
>- FIELD(IRS_VMAP_VPER, M, 63, 1)
>-
>-REG64(IRS_SAVE_VMR, 0x300)
>- FIELD(IRS_SAVE_VMR, VM_ID, 0, 16)
>- FIELD(IRS_SAVE_VMR, Q, 62, 1)
>- FIELD(IRS_SAVE_VMR, S, 63, 1)
>-
>-REG32(IRS_SAVE_VM_STATUSR, 0x308)
>- FIELD(IRS_SAVE_VM_STATUSR, IDLE, 0, 1)
>- FIELD(IRS_SAVE_VM_STATUSR, Q, 1, 1)
>-
>-REG32(IRS_MEC_IDR, 0x340)
>- FIELD(IRS_MEC_IDR, MECIDSIZE, 0, 4)
>-
>-REG32(IRS_MEC_MECID_R, 0x344)
>- FIELD(IRS_MEC_MECID_R, MECID, 0, 16)
>-
>-REG32(IRS_MPAM_IDR, 0x380)
>- FIELD(IRS_MPAM_IDR, PARTID_MAX, 0, 16)
>- FIELD(IRS_MPAM_IDR, PMG_MAX, 16, 8)
>- FIELD(IRS_MPAM_IDR, HAS_MPAM_SP, 24, 1)
>-
>-REG32(IRS_MPAM_PARTID_R, 0x384)
>- FIELD(IRS_MPAM_PARTID, PARTID, 0, 16)
>- FIELD(IRS_MPAM_PARTID, PMG, 16, 8)
>- FIELD(IRS_MPAM_PARTID, MPAM_SP, 24, 2)
>- FIELD(IRS_MPAM_PARTID, IDLE, 31, 1)
>-
>-REG64(IRS_SWERR_STATUSR, 0x3c0)
>- FIELD(IRS_SWERR_STATUSR, V, 0, 1)
>- FIELD(IRS_SWERR_STATUSR, S0V, 1, 1)
>- FIELD(IRS_SWERR_STATUSR, S1V, 2, 1)
>- FIELD(IRS_SWERR_STATUSR, OF, 3, 1)
>- FIELD(IRS_SWERR_STATUSR, EC, 16, 8)
>- FIELD(IRS_SWERR_STATUSR, IMP_EC, 24, 8)
>-
>-REG64(IRS_SWERR_SYNDROMER0, 0x3c8)
>- FIELD(IRS_SWERR_SYNDROMER0, VM_ID, 0, 16)
>- FIELD(IRS_SWERR_SYNDROMER0, ID, 32, 24)
>- FIELD(IRS_SWERR_SYNDROMER0, TYPE, 60, 3)
>- FIELD(IRS_SWERR_SYNDROMER0, VIRTUAL, 63, 1)
>-
>-REG64(IRS_SWERR_SYNDROMER1, 0x3d0)
>- FIELD(IRS_SWERR_SYNDROMER1, ADDR, 3, 53)
>-
>-REG32(IRS_IDREGS, 0xffd0)
>-REG32(IRS_DEVARCH, 0xffbc)
>-
>-FIELD(L1_ISTE, VALID, 0, 1)
>-FIELD(L1_ISTE, L2_ADDR, 12, 44)
>-
>-FIELD(L2_ISTE, PENDING, 0, 1)
>-FIELD(L2_ISTE, ACTIVE, 1, 1)
>-FIELD(L2_ISTE, HM, 2, 1)
>-FIELD(L2_ISTE, ENABLE, 3, 1)
>-FIELD(L2_ISTE, IRM, 4, 1)
>-FIELD(L2_ISTE, HWU, 9, 2)
>-FIELD(L2_ISTE, PRIORITY, 11, 5)
>-FIELD(L2_ISTE, IAFFID, 16, 16)
>-
>-/*
>- * Format used for gicv5_request_config() return value, which matches
>- * the ICC_ICSR_EL1 bit layout.
>- */
>-FIELD(ICSR, F, 0, 1)
>-FIELD(ICSR, ENABLED, 1, 1)
>-FIELD(ICSR, PENDING, 2, 1)
>-FIELD(ICSR, IRM, 3, 1)
>-FIELD(ICSR, ACTIVE, 4, 1)
>-FIELD(ICSR, HM, 5, 1)
>-FIELD(ICSR, PRIORITY, 11, 5)
>-FIELD(ICSR, IAFFID, 32, 16)
>
> #define IRS_DEVARCH_VALUE ((0x23b << 21) | (0x1 << 20) | 0x5a19)
>
>--
>2.43.0
>
^ permalink raw reply [flat|nested] 99+ messages in thread
* [PATCH v2 41/77] hw/intc/arm_gicv5: Correct offset for IRS_VMT_STATUSR
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (39 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 40/77] hw/intc: Move GICv5 register and data definitions into a header Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-04 7:53 ` Manos Pitsidianakis
2026-12-03 11:10 ` [PATCH v2 42/77] hw/intc/arm_gicv5: Ask CPUs whether IRS needs virtualization support Peter Maydell
` (35 subsequent siblings)
76 siblings, 1 reply; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
A typo in the definition of IRS_VMT_STATUSR made its offset 0x124
instead of the correct 0x214. This was harmless for our initial
EL1-only GICv5, where the register doesn't exist, but needs to be
fixed for virtualization support.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
include/hw/intc/arm_gicv5_regs.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/hw/intc/arm_gicv5_regs.h b/include/hw/intc/arm_gicv5_regs.h
index c504d8642d7..997444a0195 100644
--- a/include/hw/intc/arm_gicv5_regs.h
+++ b/include/hw/intc/arm_gicv5_regs.h
@@ -149,7 +149,7 @@ REG32(IRS_VMT_CFGR, 0x210)
FIELD(IRS_VMT_CFGR, VM_ID_BITS, 0, 5)
FIELD(IRS_VMT_CFGR, STRUCTURE, 16, 1)
-REG32(IRS_VMT_STATUSR, 0x124)
+REG32(IRS_VMT_STATUSR, 0x214)
FIELD(IRS_VMT_STATUSR, IDLE, 0, 1)
REG64(IRS_VPE_SELR, 0x240)
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* Re: [PATCH v2 41/77] hw/intc/arm_gicv5: Correct offset for IRS_VMT_STATUSR
2026-12-03 11:10 ` [PATCH v2 41/77] hw/intc/arm_gicv5: Correct offset for IRS_VMT_STATUSR Peter Maydell
@ 2026-12-04 7:53 ` Manos Pitsidianakis
0 siblings, 0 replies; 99+ messages in thread
From: Manos Pitsidianakis @ 2026-12-04 7:53 UTC (permalink / raw)
To: Peter Maydell, qemu-arm, qemu-devel
Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
On Thu, 03 Dec 2026 13:10, Peter Maydell <peter.maydell@linaro.org> wrote:
>A typo in the definition of IRS_VMT_STATUSR made its offset 0x124
>instead of the correct 0x214. This was harmless for our initial
>EL1-only GICv5, where the register doesn't exist, but needs to be
>fixed for virtualization support.
>
>Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>---
(You could move this patch at the start of the series and merge it
earlier if you want like you did with the previous revision)
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
> include/hw/intc/arm_gicv5_regs.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/include/hw/intc/arm_gicv5_regs.h b/include/hw/intc/arm_gicv5_regs.h
>index c504d8642d7..997444a0195 100644
>--- a/include/hw/intc/arm_gicv5_regs.h
>+++ b/include/hw/intc/arm_gicv5_regs.h
>@@ -149,7 +149,7 @@ REG32(IRS_VMT_CFGR, 0x210)
> FIELD(IRS_VMT_CFGR, VM_ID_BITS, 0, 5)
> FIELD(IRS_VMT_CFGR, STRUCTURE, 16, 1)
>
>-REG32(IRS_VMT_STATUSR, 0x124)
>+REG32(IRS_VMT_STATUSR, 0x214)
> FIELD(IRS_VMT_STATUSR, IDLE, 0, 1)
>
> REG64(IRS_VPE_SELR, 0x240)
>--
>2.43.0
>
^ permalink raw reply [flat|nested] 99+ messages in thread
* [PATCH v2 42/77] hw/intc/arm_gicv5: Ask CPUs whether IRS needs virtualization support
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (40 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 41/77] hw/intc/arm_gicv5: Correct offset for IRS_VMT_STATUSR Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-04 7:56 ` Manos Pitsidianakis
2026-12-03 11:10 ` [PATCH v2 43/77] hw/intc/arm_gicv5: Indicate virtualization in ID registers Peter Maydell
` (34 subsequent siblings)
76 siblings, 1 reply; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
The GICv5 IRS must support virtualization if any CPU in the system
has EL2 (by spec rule R_KDSPG). Add a has_virt field to the
GICv5Common struct to track this, and automatically set it if any
connected CPU has EL2.
We get the CPU to tell us whether it needs virtualization in the
return value of gicv5_set_gicv5state(); this allows us to maintain
the arm's-length relationship between the IRS and the CPU (and in
particular we don't need to include cpu.h in arm_gicv5_common.c, as
we would if we directly called arm_feature() there).
We could alternatively have provided a has-virtualization QOM
property, but then the board code would need to take care to
explicitly configure the IRS to match the CPUs.
(The GICv3 doesn't have an equivalent to this, because in the GICv3
design virtualization is handled entirely by the CPU interface and
software; in GICv5 the IRS has hardware support, to reduce the work
software needs to do.)
None of the code we are about to add in future commits that tests the
has_virt flag will be accessible until we remove the check in virt.c
that prevents creation of a machine with the GICv5 and an EL2 CPU, so
no behaviour will change until we have completed the entire
virtualization support feature and allow the user to select it.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
include/hw/intc/arm_gicv5_common.h | 2 ++
include/hw/intc/arm_gicv5_stream.h | 15 +++++++++++----
hw/intc/arm_gicv5_common.c | 9 ++++++++-
target/arm/cpu.c | 17 +++++++++++------
4 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/include/hw/intc/arm_gicv5_common.h b/include/hw/intc/arm_gicv5_common.h
index a47f639e84c..d8f6f5d5db9 100644
--- a/include/hw/intc/arm_gicv5_common.h
+++ b/include/hw/intc/arm_gicv5_common.h
@@ -127,6 +127,8 @@ struct GICv5Common {
uint32_t spi_base;
uint32_t spi_irs_range;
uint32_t spi_range;
+
+ bool has_virt;
};
struct GICv5CommonClass {
diff --git a/include/hw/intc/arm_gicv5_stream.h b/include/hw/intc/arm_gicv5_stream.h
index f6d32c6beca..ea27d6aec0f 100644
--- a/include/hw/intc/arm_gicv5_stream.h
+++ b/include/hw/intc/arm_gicv5_stream.h
@@ -16,6 +16,12 @@
typedef struct GICv5Common GICv5Common;
+typedef enum GICv5CPUIFStatus {
+ GICV5_CPUIF_MISSING, /* CPU does not have GICv5 cpuif support */
+ GICV5_CPUIF_PRESENT, /* CPU has GICv5 cpuif */
+ GICV5_CPUIF_NEEDS_VIRT, /* CPU has GICv5, and needs virt support in IRS */
+} GICv5CPUIFStatus;
+
/**
* gicv5_set_gicv5state
* @cpu: CPU object to tell about its IRS
@@ -27,11 +33,12 @@ typedef struct GICv5Common GICv5Common;
* IRS must call this when it is realized, for each CPU it is
* connected to.
*
- * Returns true on success, false if the CPU doesn't implement the
- * GICv5 CPU interface.
+ * The return value indicates whether the CPU has a GICv5 CPU
+ * interface, and if it does whether it needs virtualization support
+ * from the IRS.
*/
-bool gicv5_set_gicv5state(ARMCPU *cpu, GICv5Common *cs, uint32_t iaffid,
- uint32_t cpuidx);
+GICv5CPUIFStatus gicv5_set_gicv5state(ARMCPU *cpu, GICv5Common *cs,
+ uint32_t iaffid, uint32_t cpuidx);
/*
* The architected Stream Protocol is asynchronous; commands can be
diff --git a/hw/intc/arm_gicv5_common.c b/hw/intc/arm_gicv5_common.c
index cfadfee4f05..17fd67b5ccd 100644
--- a/hw/intc/arm_gicv5_common.c
+++ b/hw/intc/arm_gicv5_common.c
@@ -176,11 +176,18 @@ static void gicv5_common_realize(DeviceState *dev, Error **errp)
}
for (int i = 0; i < cs->num_cpus; i++) {
- if (!gicv5_set_gicv5state(cs->cpus[i], cs, cs->cpu_iaffids[i], i)) {
+ switch (gicv5_set_gicv5state(cs->cpus[i], cs, cs->cpu_iaffids[i], i)) {
+ case GICV5_CPUIF_MISSING:
error_setg(errp,
"CPU %d (IAFFID 0x%x) does not implement GICv5 CPU interface",
i, cs->cpu_iaffids[i]);
return;
+ case GICV5_CPUIF_PRESENT:
+ break;
+ case GICV5_CPUIF_NEEDS_VIRT:
+ /* R_KDSPG: IRS must implement virtualization if any CPU has EL2 */
+ cs->has_virt = true;
+ break;
}
}
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index dde03ffdd6f..aba81bfcdb0 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -1215,20 +1215,25 @@ static void arm_cpu_dump_state(CPUState *cs, FILE *f, int flags)
}
#ifndef CONFIG_USER_ONLY
-bool gicv5_set_gicv5state(ARMCPU *cpu, GICv5Common *cs, uint32_t iaffid,
- uint32_t cpuidx)
+GICv5CPUIFStatus gicv5_set_gicv5state(ARMCPU *cpu, GICv5Common *cs,
+ uint32_t iaffid, uint32_t cpuidx)
{
/*
- * Set this CPU's gicv5state pointer to point to the GIC that we are
- * connected to, and record our IAFFID and CPU index.
+ * Set this CPU's gicv5state pointer to point to the GIC that we
+ * are connected to, record our IAFFID and cpuidx, and let the IRS
+ * know if it needs to implement virtualization support.
*/
if (!cpu_isar_feature(aa64_gcie, cpu)) {
- return false;
+ return GICV5_CPUIF_MISSING;
}
cpu->env.gicv5.gicv5state = cs;
cpu->env.gicv5.iaffid = iaffid;
cpu->env.gicv5.cpuidx = cpuidx;
- return true;
+ if (arm_feature(&cpu->env, ARM_FEATURE_EL2)) {
+ return GICV5_CPUIF_NEEDS_VIRT;
+ } else {
+ return GICV5_CPUIF_PRESENT;
+ }
}
#endif
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* Re: [PATCH v2 42/77] hw/intc/arm_gicv5: Ask CPUs whether IRS needs virtualization support
2026-12-03 11:10 ` [PATCH v2 42/77] hw/intc/arm_gicv5: Ask CPUs whether IRS needs virtualization support Peter Maydell
@ 2026-12-04 7:56 ` Manos Pitsidianakis
0 siblings, 0 replies; 99+ messages in thread
From: Manos Pitsidianakis @ 2026-12-04 7:56 UTC (permalink / raw)
To: Peter Maydell, qemu-arm, qemu-devel
Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
On Thu, 03 Dec 2026 13:10, Peter Maydell <peter.maydell@linaro.org> wrote:
>The GICv5 IRS must support virtualization if any CPU in the system
>has EL2 (by spec rule R_KDSPG). Add a has_virt field to the
>GICv5Common struct to track this, and automatically set it if any
>connected CPU has EL2.
>
>We get the CPU to tell us whether it needs virtualization in the
>return value of gicv5_set_gicv5state(); this allows us to maintain
>the arm's-length relationship between the IRS and the CPU (and in
>particular we don't need to include cpu.h in arm_gicv5_common.c, as
>we would if we directly called arm_feature() there).
>
>We could alternatively have provided a has-virtualization QOM
>property, but then the board code would need to take care to
>explicitly configure the IRS to match the CPUs.
Yes, the approach in this patch sounds better than the QOM prop
alternative.
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
>
>(The GICv3 doesn't have an equivalent to this, because in the GICv3
>design virtualization is handled entirely by the CPU interface and
>software; in GICv5 the IRS has hardware support, to reduce the work
>software needs to do.)
>
>None of the code we are about to add in future commits that tests the
>has_virt flag will be accessible until we remove the check in virt.c
>that prevents creation of a machine with the GICv5 and an EL2 CPU, so
>no behaviour will change until we have completed the entire
>virtualization support feature and allow the user to select it.
>
>Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>---
> include/hw/intc/arm_gicv5_common.h | 2 ++
> include/hw/intc/arm_gicv5_stream.h | 15 +++++++++++----
> hw/intc/arm_gicv5_common.c | 9 ++++++++-
> target/arm/cpu.c | 17 +++++++++++------
> 4 files changed, 32 insertions(+), 11 deletions(-)
>
>diff --git a/include/hw/intc/arm_gicv5_common.h b/include/hw/intc/arm_gicv5_common.h
>index a47f639e84c..d8f6f5d5db9 100644
>--- a/include/hw/intc/arm_gicv5_common.h
>+++ b/include/hw/intc/arm_gicv5_common.h
>@@ -127,6 +127,8 @@ struct GICv5Common {
> uint32_t spi_base;
> uint32_t spi_irs_range;
> uint32_t spi_range;
>+
>+ bool has_virt;
> };
>
> struct GICv5CommonClass {
>diff --git a/include/hw/intc/arm_gicv5_stream.h b/include/hw/intc/arm_gicv5_stream.h
>index f6d32c6beca..ea27d6aec0f 100644
>--- a/include/hw/intc/arm_gicv5_stream.h
>+++ b/include/hw/intc/arm_gicv5_stream.h
>@@ -16,6 +16,12 @@
>
> typedef struct GICv5Common GICv5Common;
>
>+typedef enum GICv5CPUIFStatus {
>+ GICV5_CPUIF_MISSING, /* CPU does not have GICv5 cpuif support */
>+ GICV5_CPUIF_PRESENT, /* CPU has GICv5 cpuif */
>+ GICV5_CPUIF_NEEDS_VIRT, /* CPU has GICv5, and needs virt support in IRS */
>+} GICv5CPUIFStatus;
>+
> /**
> * gicv5_set_gicv5state
> * @cpu: CPU object to tell about its IRS
>@@ -27,11 +33,12 @@ typedef struct GICv5Common GICv5Common;
> * IRS must call this when it is realized, for each CPU it is
> * connected to.
> *
>- * Returns true on success, false if the CPU doesn't implement the
>- * GICv5 CPU interface.
>+ * The return value indicates whether the CPU has a GICv5 CPU
>+ * interface, and if it does whether it needs virtualization support
>+ * from the IRS.
> */
>-bool gicv5_set_gicv5state(ARMCPU *cpu, GICv5Common *cs, uint32_t iaffid,
>- uint32_t cpuidx);
>+GICv5CPUIFStatus gicv5_set_gicv5state(ARMCPU *cpu, GICv5Common *cs,
>+ uint32_t iaffid, uint32_t cpuidx);
>
> /*
> * The architected Stream Protocol is asynchronous; commands can be
>diff --git a/hw/intc/arm_gicv5_common.c b/hw/intc/arm_gicv5_common.c
>index cfadfee4f05..17fd67b5ccd 100644
>--- a/hw/intc/arm_gicv5_common.c
>+++ b/hw/intc/arm_gicv5_common.c
>@@ -176,11 +176,18 @@ static void gicv5_common_realize(DeviceState *dev, Error **errp)
> }
>
> for (int i = 0; i < cs->num_cpus; i++) {
>- if (!gicv5_set_gicv5state(cs->cpus[i], cs, cs->cpu_iaffids[i], i)) {
>+ switch (gicv5_set_gicv5state(cs->cpus[i], cs, cs->cpu_iaffids[i], i)) {
>+ case GICV5_CPUIF_MISSING:
> error_setg(errp,
> "CPU %d (IAFFID 0x%x) does not implement GICv5 CPU interface",
> i, cs->cpu_iaffids[i]);
> return;
>+ case GICV5_CPUIF_PRESENT:
>+ break;
>+ case GICV5_CPUIF_NEEDS_VIRT:
>+ /* R_KDSPG: IRS must implement virtualization if any CPU has EL2 */
>+ cs->has_virt = true;
>+ break;
> }
> }
>
>diff --git a/target/arm/cpu.c b/target/arm/cpu.c
>index dde03ffdd6f..aba81bfcdb0 100644
>--- a/target/arm/cpu.c
>+++ b/target/arm/cpu.c
>@@ -1215,20 +1215,25 @@ static void arm_cpu_dump_state(CPUState *cs, FILE *f, int flags)
> }
>
> #ifndef CONFIG_USER_ONLY
>-bool gicv5_set_gicv5state(ARMCPU *cpu, GICv5Common *cs, uint32_t iaffid,
>- uint32_t cpuidx)
>+GICv5CPUIFStatus gicv5_set_gicv5state(ARMCPU *cpu, GICv5Common *cs,
>+ uint32_t iaffid, uint32_t cpuidx)
> {
> /*
>- * Set this CPU's gicv5state pointer to point to the GIC that we are
>- * connected to, and record our IAFFID and CPU index.
>+ * Set this CPU's gicv5state pointer to point to the GIC that we
>+ * are connected to, record our IAFFID and cpuidx, and let the IRS
>+ * know if it needs to implement virtualization support.
> */
> if (!cpu_isar_feature(aa64_gcie, cpu)) {
>- return false;
>+ return GICV5_CPUIF_MISSING;
> }
> cpu->env.gicv5.gicv5state = cs;
> cpu->env.gicv5.iaffid = iaffid;
> cpu->env.gicv5.cpuidx = cpuidx;
>- return true;
>+ if (arm_feature(&cpu->env, ARM_FEATURE_EL2)) {
>+ return GICV5_CPUIF_NEEDS_VIRT;
>+ } else {
>+ return GICV5_CPUIF_PRESENT;
>+ }
> }
> #endif
>
>--
>2.43.0
>
^ permalink raw reply [flat|nested] 99+ messages in thread
* [PATCH v2 43/77] hw/intc/arm_gicv5: Indicate virtualization in ID registers
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (41 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 42/77] hw/intc/arm_gicv5: Ask CPUs whether IRS needs virtualization support Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 44/77] hw/intc/arm_gicv5: Implement IRS_VMT_BASER and IRS_VMT_STATUSR Peter Maydell
` (33 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
When has_virt is true, report virtualization support in the IRS ID
registers. This includes reporting various specifics of our
implementation. We choose to implement the maximum possible sizes
for VM and VPE IDs. We don't need to store any implementation state
in the IMPDEF guest memory VM descriptor and VPE descriptor
structures, so we indicate that we have no VM descriptors and that
the VPE descriptor is the smallest size the spec allows.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
include/hw/intc/arm_gicv5_common.h | 25 +++++++++++++++++++
hw/intc/arm_gicv5.c | 40 +++++++++++++++++++++++-------
2 files changed, 56 insertions(+), 9 deletions(-)
diff --git a/include/hw/intc/arm_gicv5_common.h b/include/hw/intc/arm_gicv5_common.h
index d8f6f5d5db9..7b24cad211b 100644
--- a/include/hw/intc/arm_gicv5_common.h
+++ b/include/hw/intc/arm_gicv5_common.h
@@ -153,6 +153,31 @@ struct GICv5CommonClass {
#define QEMU_GICV5_IAFFID_BITS 16
/* Number of priority bits supported in the IRS */
#define QEMU_GICV5_PRI_BITS 5
+/* Number of VM ID bits */
+#define QEMU_GICV5_VM_ID_BITS 16
+/* Number of VPE ID bits */
+#define QEMU_GICV5_VPE_ID_BITS 16
+
+/*
+ * The VPE descriptor is IMPDEF in size and contents; it stores
+ * - the VPE's residency status and location
+ * - VPE doorbell settings
+ * - metadata tracking pending interrupts for the VPE
+ * In a real hardware implementation, the IRS will keep its per-VPE data
+ * in guest memory with a cache so it isn't actually doing full memory
+ * accesses all the time. For QEMU we will keep the per-VPE data in
+ * host-side data structures, which don't have any size limitations.
+ * The specification doesn't define any situations where the IRS
+ * must write its state back out to guest memory, except for the
+ * entirely IMPDEF and optional power-management suspend/resume.
+ * QEMU's IRS doesn't implement power-management, so we will never
+ * write out anything to the VPE descriptors in guest memory.
+ * We therefore define them to the smallest size the spec permits,
+ * which is 8 bytes.
+ * (We similarly do not use VM descriptors, but for those the spec
+ * permits an implementation to tell software it does not use them.)
+ */
+#define QEMU_GICV5_VPED_SZ 3
/*
* There are no TRMs currently published for hardware implementations
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index 2b9a8ad8718..588616bd40c 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -75,6 +75,16 @@ static uint32_t gicv5_idreg(int regoffset)
return gic_ids[regoffset];
}
+static bool gicv5_domain_has_virt(GICv5Common *cs, GICv5Domain domain)
+{
+ /*
+ * Return true if this domain implements virtualization.
+ * EL3 never does; if any CPU connected to the IRS has EL2
+ * then all other domains must implement virtualization (R_KDSPG)
+ */
+ return cs->has_virt && domain != GICV5_ID_EL3;
+}
+
static GICv5SPIState *spi_for_selr(GICv5Common *cs, GICv5Domain domain)
{
/*
@@ -1201,8 +1211,8 @@ static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset,
/* MEC field RES0 except for the Realm domain */
v &= ~R_IRS_IDR0_MEC_MASK;
}
- if (domain == GICV5_ID_EL3) {
- /* VIRT is RES0 for EL3 domain */
+ if (!gicv5_domain_has_virt(cs, domain)) {
+ /* VIRT is RES0 for this domain */
v &= ~R_IRS_IDR0_VIRT_MASK;
/* ...which means VIRT_ONE_N is also RES0 */
v &= ~R_IRS_IDR0_VIRT_ONE_N_MASK;
@@ -1216,12 +1226,12 @@ static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset,
*data = cs->irs_idr2;
return true;
case A_IRS_IDR3:
- /* In EL3 IDR0.VIRT is 0 so this is RES0 */
- *data = domain == GICV5_ID_EL3 ? 0 : cs->irs_idr3;
+ /* All fields are RES0 if domain doesn't have virt */
+ *data = gicv5_domain_has_virt(cs, domain) ? cs->irs_idr3 : 0;
return true;
case A_IRS_IDR4:
- /* In EL3 IDR0.VIRT is 0 so this is RES0 */
- *data = domain == GICV5_ID_EL3 ? 0 : cs->irs_idr4;
+ /* All fields are RES0 if domain doesn't have virt */
+ *data = gicv5_domain_has_virt(cs, domain) ? cs->irs_idr4 : 0;
return true;
case A_IRS_IDR5:
*data = cs->irs_idr5;
@@ -1629,6 +1639,7 @@ static void gicv5_set_idregs(GICv5Common *cs)
* for 56 bits of physical address space.
*/
v = FIELD_DP32(v, IRS_IDR0, PA_RANGE, 7);
+ v = FIELD_DP32(v, IRS_IDR0, VIRT, cs->has_virt);
v = FIELD_DP32(v, IRS_IDR0, IRSID, cs->irsid);
cs->irs_idr0 = v;
@@ -1648,9 +1659,20 @@ static void gicv5_set_idregs(GICv5Common *cs)
/* Our impl does not need IST metadata, so ISTMD and ISTMD_SZ are 0 */
cs->irs_idr2 = v;
- /* We don't implement virtualization yet, so these are zero */
- cs->irs_idr3 = 0;
- cs->irs_idr4 = 0;
+ v = 0;
+ if (cs->has_virt) {
+ /* Our impl doesn't need a VM descriptor, so VMD and VMD_SZ are zero. */
+ v = FIELD_DP32(v, IRS_IDR3, VM_ID_BITS, QEMU_GICV5_VM_ID_BITS);
+ v = FIELD_DP32(v, IRS_IDR3, VMT_LEVELS, 1);
+ }
+ cs->irs_idr3 = v;
+
+ v = 0;
+ if (cs->has_virt) {
+ v = FIELD_DP32(v, IRS_IDR4, VPED_SZ, QEMU_GICV5_VPED_SZ);
+ v = FIELD_DP32(v, IRS_IDR4, VPE_ID_BITS, QEMU_GICV5_VPE_ID_BITS - 1);
+ }
+ cs->irs_idr4 = v;
/* These three have just one field each */
cs->irs_idr5 = FIELD_DP32(0, IRS_IDR5, SPI_RANGE, cs->spi_range);
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 44/77] hw/intc/arm_gicv5: Implement IRS_VMT_BASER and IRS_VMT_STATUSR
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (42 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 43/77] hw/intc/arm_gicv5: Indicate virtualization in ID registers Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 45/77] hw/intc/arm_gicv5: IMplement IRS_VMT_CFGR Peter Maydell
` (32 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Implement the GICv5 IRS_VMT_BASER register, which holds the base
address of the VM table. This is very similar to the IRS_IST_BASER
register: it is 64 bits wide but can be accessed as two 32 bit
pieces, it has a valid bit which the guest sets to make the table
valid, and there is an associated IRS_VMT_STATUSR register which has
an IDLE bit which the guest can read to find out when the write to
VALID has completed.
Implement IRS_VMT_BASER and IRS_VMT_STATUSR, using the same pattern
we have for IRS_IST_BASER and IRS_IST_STATUSR.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
include/hw/intc/arm_gicv5_common.h | 1 +
hw/intc/arm_gicv5.c | 73 ++++++++++++++++++++++++++++++
hw/intc/arm_gicv5_common.c | 4 ++
hw/intc/trace-events | 2 +
4 files changed, 80 insertions(+)
diff --git a/include/hw/intc/arm_gicv5_common.h b/include/hw/intc/arm_gicv5_common.h
index 7b24cad211b..f134602d66e 100644
--- a/include/hw/intc/arm_gicv5_common.h
+++ b/include/hw/intc/arm_gicv5_common.h
@@ -89,6 +89,7 @@ struct GICv5Common {
uint32_t irs_cr0[NUM_GICV5_DOMAINS];
uint32_t irs_cr1[NUM_GICV5_DOMAINS];
uint32_t irs_pe_selr[NUM_GICV5_DOMAINS];
+ uint64_t irs_vmt_baser[NUM_GICV5_DOMAINS];
/*
* Pointer to an array of state information for the SPIs. Array
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index 588616bd40c..c697e6300b9 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -1159,6 +1159,36 @@ static void irs_ist_baser_write(GICv5 *s, GICv5Domain domain, uint64_t value)
}
}
+static void irs_vmt_baser_write(GICv5 *s, GICv5Domain domain, uint64_t value)
+{
+ GICv5Common *cs = ARM_GICV5_COMMON(s);
+
+ if (!gicv5_domain_has_virt(cs, domain)) {
+ return;
+ }
+
+ if (FIELD_EX64(cs->irs_vmt_baser[domain], IRS_VMT_BASER, VALID)) {
+ /* If VALID is set, ADDR is RO and we can only update VALID */
+ bool valid = FIELD_EX64(value, IRS_VMT_BASER, VALID);
+
+ if (valid) {
+ /* Ignore 1->1 transition */
+ return;
+ }
+ cs->irs_vmt_baser[domain] = FIELD_DP64(cs->irs_vmt_baser[domain],
+ IRS_VMT_BASER, VALID, valid);
+ trace_gicv5_vmt_invalid(domain_name[domain]);
+ return;
+ }
+
+ cs->irs_vmt_baser[domain] = value;
+
+ if (FIELD_EX64(cs->irs_vmt_baser[domain], IRS_VMT_BASER, VALID)) {
+ trace_gicv5_vmt_valid(domain_name[domain],
+ cs->irs_vmt_baser[domain] & R_IRS_VMT_BASER_ADDR_MASK);
+ }
+}
+
static void spi_sample(GICv5SPIState *spi)
{
/*
@@ -1264,6 +1294,31 @@ static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset,
case A_IRS_IST_CFGR:
*data = cs->irs_ist_cfgr[domain];
return true;
+ case A_IRS_VMT_BASER:
+ if (gicv5_domain_has_virt(cs, domain)) {
+ *data = extract64(cs->irs_vmt_baser[domain], 0, 32);
+ } else {
+ *data = 0;
+ }
+ return true;
+ case A_IRS_VMT_BASER + 4:
+ if (gicv5_domain_has_virt(cs, domain)) {
+ *data = extract64(cs->irs_vmt_baser[domain], 32, 32);
+ } else {
+ *data = 0;
+ }
+ return true;
+ case A_IRS_VMT_STATUSR:
+ /*
+ * QEMU writes to IRS_VMT_BASER and IRS_VMAP_* take effect
+ * instantaneously, so the guest can never see the IDLE bit as 0.
+ */
+ if (gicv5_domain_has_virt(cs, domain)) {
+ *data = R_IRS_VMT_STATUSR_IDLE_MASK;
+ } else {
+ *data = 0;
+ }
+ return true;
case A_IRS_SPI_STATUSR:
/*
* QEMU writes to IRS_SPI_{CFGR,DOMAINR,SELR,VMR} take effect
@@ -1366,6 +1421,14 @@ static bool config_writel(GICv5 *s, GICv5Domain domain, hwaddr offset,
case A_IRS_MAP_L2_ISTR:
irs_map_l2_istr_write(s, domain, data);
return true;
+ case A_IRS_VMT_BASER:
+ irs_vmt_baser_write(s, domain,
+ deposit64(cs->irs_vmt_baser[domain], 0, 32, data));
+ return true;
+ case A_IRS_VMT_BASER + 4:
+ irs_vmt_baser_write(s, domain,
+ deposit64(cs->irs_vmt_baser[domain], 32, 32, data));
+ return true;
case A_IRS_SPI_SELR:
cs->irs_spi_selr[domain] = data;
return true;
@@ -1450,6 +1513,13 @@ static bool config_readll(GICv5 *s, GICv5Domain domain, hwaddr offset,
case A_IRS_IST_BASER:
*data = cs->irs_ist_baser[domain];
return true;
+ case A_IRS_VMT_BASER:
+ if (gicv5_domain_has_virt(cs, domain)) {
+ *data = cs->irs_vmt_baser[domain];
+ } else {
+ *data = 0;
+ }
+ return true;
}
return false;
@@ -1462,6 +1532,9 @@ static bool config_writell(GICv5 *s, GICv5Domain domain, hwaddr offset,
case A_IRS_IST_BASER:
irs_ist_baser_write(s, domain, data);
return true;
+ case A_IRS_VMT_BASER:
+ irs_vmt_baser_write(s, domain, data);
+ return true;
}
return false;
diff --git a/hw/intc/arm_gicv5_common.c b/hw/intc/arm_gicv5_common.c
index 17fd67b5ccd..89669493b83 100644
--- a/hw/intc/arm_gicv5_common.c
+++ b/hw/intc/arm_gicv5_common.c
@@ -104,6 +104,10 @@ static void gicv5_common_reset_hold(Object *obj, ResetType type)
*/
cs->irs_spi_selr[i] = cs->spi_base + cs->spi_irs_range;
}
+
+ if (cs->has_virt) {
+ memset(cs->irs_vmt_baser, 0, sizeof(cs->irs_vmt_baser));
+ }
}
static void gicv5_common_init(Object *obj)
diff --git a/hw/intc/trace-events b/hw/intc/trace-events
index 2016842450b..fd832455a77 100644
--- a/hw/intc/trace-events
+++ b/hw/intc/trace-events
@@ -246,6 +246,8 @@ gicv5_deactivate(const char *domain, const char *type, bool virtual, uint32_t id
gicv5_spi_state(uint32_t spi_id, bool level, bool pending, bool active) "GICv5 IRS SPI ID %u now level %d pending %d active %d"
gicv5_irs_recalc_hppi_fail(const char *domain, uint32_t iaffid, const char *reason) "GICv5 IRS %s IAFFID %u: no HPPI: %s"
gicv5_irs_recalc_hppi(const char *domain, uint32_t iaffid, uint32_t id, uint8_t prio) "GICv5 IRS %s IAFFID %u: new HPPI ID 0x%x prio %u"
+gicv5_vmt_valid(const char *domain, uint64_t base) "GICv5 IRS %s VM table now valid: base 0x%" PRIx64
+gicv5_vmt_invalid(const char *domain) "GICv5 IRS %s VM table no longer valid"
# arm_gicv5_common.c
gicv5_common_realize(uint32_t irsid, uint32_t num_cpus, uint32_t spi_base, uint32_t spi_irs_range, uint32_t spi_range) "GICv5 IRS realized: IRS ID %u, %u CPUs, SPI base %u, SPI IRS range %u, SPI range %u"
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 45/77] hw/intc/arm_gicv5: IMplement IRS_VMT_CFGR
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (43 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 44/77] hw/intc/arm_gicv5: Implement IRS_VMT_BASER and IRS_VMT_STATUSR Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 46/77] hw/intc/arm_gicv5: Implement IRS_VMAP_L2_VMTR Peter Maydell
` (31 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
The ISR_VMT_CFGR register is similar to the IRS_IST_CFGR register:
the guest writes to it to specify some details of the VM table before
writing to ISR_VMT_BASER.
Implement this register, including capturing the config info in it
and the ISR_VMT_BASER register into a GICv5VMTConfig struct when the
VM table becomes valid (following the same pattern we have for
IRS_IST_BASER and IRS_IST_CFGR).
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
include/hw/intc/arm_gicv5.h | 10 ++++
include/hw/intc/arm_gicv5_common.h | 1 +
hw/intc/arm_gicv5.c | 83 ++++++++++++++++++++++++++++--
hw/intc/arm_gicv5_common.c | 1 +
hw/intc/trace-events | 2 +-
5 files changed, 93 insertions(+), 4 deletions(-)
diff --git a/include/hw/intc/arm_gicv5.h b/include/hw/intc/arm_gicv5.h
index d763a7939c7..785c7112fd9 100644
--- a/include/hw/intc/arm_gicv5.h
+++ b/include/hw/intc/arm_gicv5.h
@@ -30,6 +30,14 @@ typedef struct GICv5ISTConfig {
GHashTable *lpi_cache;
} GICv5ISTConfig;
+typedef struct GICv5VMTConfig {
+ hwaddr base; /* Base address */
+ MemTxAttrs txattrs; /* TX attrs to use for this table */
+ uint8_t vm_id_bits; /* number of VM ID bits for the domain */
+ bool structure; /* true if using 2-level table */
+ bool valid; /* true if this table is valid and usable */
+} GICv5VMTConfig;
+
/*
* This class is for TCG-specific state for the GICv5.
*/
@@ -38,6 +46,8 @@ struct GICv5 {
/* This is the info from IRS_IST_BASER and IRS_IST_CFGR */
GICv5ISTConfig phys_lpi_config[NUM_GICV5_DOMAINS];
+ /* This is the info from IRS_VMT_BASER and IRS_VMT_CFGR */
+ GICv5VMTConfig vmt_config[NUM_GICV5_DOMAINS];
/* We cache the HPPI for each CPU for each domain here */
GICv5PendingIrq *hppi[NUM_GICV5_DOMAINS];
diff --git a/include/hw/intc/arm_gicv5_common.h b/include/hw/intc/arm_gicv5_common.h
index f134602d66e..fb88c39e8b4 100644
--- a/include/hw/intc/arm_gicv5_common.h
+++ b/include/hw/intc/arm_gicv5_common.h
@@ -90,6 +90,7 @@ struct GICv5Common {
uint32_t irs_cr1[NUM_GICV5_DOMAINS];
uint32_t irs_pe_selr[NUM_GICV5_DOMAINS];
uint64_t irs_vmt_baser[NUM_GICV5_DOMAINS];
+ uint32_t irs_vmt_cfgr[NUM_GICV5_DOMAINS];
/*
* Pointer to an array of state information for the SPIs. Array
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index c697e6300b9..bd83e5d191b 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -1167,7 +1167,7 @@ static void irs_vmt_baser_write(GICv5 *s, GICv5Domain domain, uint64_t value)
return;
}
- if (FIELD_EX64(cs->irs_vmt_baser[domain], IRS_VMT_BASER, VALID)) {
+ if (s->vmt_config[domain].valid) {
/* If VALID is set, ADDR is RO and we can only update VALID */
bool valid = FIELD_EX64(value, IRS_VMT_BASER, VALID);
@@ -1177,6 +1177,7 @@ static void irs_vmt_baser_write(GICv5 *s, GICv5Domain domain, uint64_t value)
}
cs->irs_vmt_baser[domain] = FIELD_DP64(cs->irs_vmt_baser[domain],
IRS_VMT_BASER, VALID, valid);
+ s->vmt_config[domain].valid = false;
trace_gicv5_vmt_invalid(domain_name[domain]);
return;
}
@@ -1184,8 +1185,60 @@ static void irs_vmt_baser_write(GICv5 *s, GICv5Domain domain, uint64_t value)
cs->irs_vmt_baser[domain] = value;
if (FIELD_EX64(cs->irs_vmt_baser[domain], IRS_VMT_BASER, VALID)) {
- trace_gicv5_vmt_valid(domain_name[domain],
- cs->irs_vmt_baser[domain] & R_IRS_VMT_BASER_ADDR_MASK);
+ /*
+ * If the guest just set VALID then capture data into config
+ * struct and sanitize.
+ */
+ GICv5VMTConfig *cfg = &s->vmt_config[domain];
+ uint8_t vm_id_bits = FIELD_EX64(cs->irs_vmt_cfgr[domain],
+ IRS_VMT_CFGR, VM_ID_BITS);
+ int tableszbits;
+
+ vm_id_bits = MIN(vm_id_bits, QEMU_GICV5_VM_ID_BITS);
+
+ cfg->structure = FIELD_EX64(cs->irs_vmt_cfgr[domain],
+ IRS_VMT_CFGR, STRUCTURE);
+ cfg->vm_id_bits = vm_id_bits;
+ /*
+ * L2 VMTEs are always 32 bytes, and the L2 VM table is always 4KB,
+ * so 7 bits in a VM ID index the L2 table. As the L2 VMTE size
+ * and l2 index bits are constant, we don't need to precalculate
+ * them the way we do for GICv5ISTConfig.
+ */
+ cfg->base = cs->irs_vmt_baser[domain] & R_IRS_VMT_BASER_ADDR_MASK;
+ cfg->txattrs = irs_txattrs(cs, domain);
+
+ /*
+ * Enforce aligment of VM table, ignoring bits [N:0] of the address.
+ * When STRUCTURE = 0, N = VM_ID_BITS + 4
+ * When STRUCTURE = 1, N = VM_ID_BITS - 5
+ * For us, tableszbits = N + 1.
+ */
+ if (cfg->structure) {
+ /*
+ * L1 table indexed by (vm_id_bits - 7) bits, and each entry
+ * is 2^3 == 8 bytes.
+ */
+ tableszbits = vm_id_bits - 4;
+ } else {
+ /* table has 2^vm_id_bits entries of 2^5 == 32 bytes each */
+ tableszbits = vm_id_bits + 5;
+ }
+ /*
+ * tableszbits is <= 0 for the silly but valid config where
+ * STRUCTURE = 1 but VM_ID_BITS is so small that there is only
+ * one L1 table entry pointing to a single L2 table with all
+ * the VMTEs in it. In this case the R_IRS_VMT_BASER_ADDR_MASK
+ * already aligned cfg->base sufficiently.
+ */
+ if (tableszbits > 0) {
+ cfg->base &= ~MAKE_64BIT_MASK(0, tableszbits);
+ }
+
+ cfg->valid = true;
+
+ trace_gicv5_vmt_valid(domain_name[domain], cfg->base,
+ cfg->vm_id_bits, cfg->structure);
}
}
@@ -1319,6 +1372,13 @@ static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset,
*data = 0;
}
return true;
+ case A_IRS_VMT_CFGR:
+ if (gicv5_domain_has_virt(cs, domain)) {
+ *data = cs->irs_vmt_cfgr[domain];
+ } else {
+ *data = 0;
+ }
+ return true;
case A_IRS_SPI_STATUSR:
/*
* QEMU writes to IRS_SPI_{CFGR,DOMAINR,SELR,VMR} take effect
@@ -1429,6 +1489,18 @@ static bool config_writel(GICv5 *s, GICv5Domain domain, hwaddr offset,
irs_vmt_baser_write(s, domain,
deposit64(cs->irs_vmt_baser[domain], 32, 32, data));
return true;
+ case A_IRS_VMT_CFGR:
+ if (gicv5_domain_has_virt(cs, domain)) {
+ if (s->vmt_config[domain].valid) {
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "guest tried to write IRS_VMT_CFGR for %s "
+ "config frame while IRS_VMT_BASER.VALID set\n",
+ domain_name[domain]);
+ } else {
+ cs->irs_vmt_cfgr[domain] = data;
+ }
+ }
+ return true;
case A_IRS_SPI_SELR:
cs->irs_spi_selr[domain] = data;
return true;
@@ -1695,6 +1767,11 @@ static void gicv5_reset_hold(Object *obj, ResetType type)
g_hash_table_remove_all(s->phys_lpi_config[i].lpi_cache);
}
}
+
+ /* IRS_VMT_BASER and IRS_VMT_CFGR reset to 0, clear cached info */
+ for (int i = 0; i < NUM_GICV5_DOMAINS; i++) {
+ s->vmt_config[i].valid = false;
+ }
}
static void gicv5_set_idregs(GICv5Common *cs)
diff --git a/hw/intc/arm_gicv5_common.c b/hw/intc/arm_gicv5_common.c
index 89669493b83..6a9d727bb65 100644
--- a/hw/intc/arm_gicv5_common.c
+++ b/hw/intc/arm_gicv5_common.c
@@ -107,6 +107,7 @@ static void gicv5_common_reset_hold(Object *obj, ResetType type)
if (cs->has_virt) {
memset(cs->irs_vmt_baser, 0, sizeof(cs->irs_vmt_baser));
+ memset(cs->irs_vmt_cfgr, 0, sizeof(cs->irs_vmt_cfgr));
}
}
diff --git a/hw/intc/trace-events b/hw/intc/trace-events
index fd832455a77..3267b3c240c 100644
--- a/hw/intc/trace-events
+++ b/hw/intc/trace-events
@@ -246,7 +246,7 @@ gicv5_deactivate(const char *domain, const char *type, bool virtual, uint32_t id
gicv5_spi_state(uint32_t spi_id, bool level, bool pending, bool active) "GICv5 IRS SPI ID %u now level %d pending %d active %d"
gicv5_irs_recalc_hppi_fail(const char *domain, uint32_t iaffid, const char *reason) "GICv5 IRS %s IAFFID %u: no HPPI: %s"
gicv5_irs_recalc_hppi(const char *domain, uint32_t iaffid, uint32_t id, uint8_t prio) "GICv5 IRS %s IAFFID %u: new HPPI ID 0x%x prio %u"
-gicv5_vmt_valid(const char *domain, uint64_t base) "GICv5 IRS %s VM table now valid: base 0x%" PRIx64
+gicv5_vmt_valid(const char *domain, uint64_t base, uint8_t vm_id_bits, bool structure) "GICv5 IRS %s VM table now valid: base 0x%" PRIx64 " vm_id_bits %u 2-level %d"
gicv5_vmt_invalid(const char *domain) "GICv5 IRS %s VM table no longer valid"
# arm_gicv5_common.c
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 46/77] hw/intc/arm_gicv5: Implement IRS_VMAP_L2_VMTR
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (44 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 45/77] hw/intc/arm_gicv5: IMplement IRS_VMT_CFGR Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 47/77] hw/intc/arm_gicv5: Implement IRS_VMAP_VMR Peter Maydell
` (30 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
The IRS_VMAP_L2_VMTR register allows the guest to make a level 2 VM
table valid. It's similar to what the IRS_MAP_L2_ISTR register does
for the IST, but it's 64 bits, and so it is R/W and has an M bit for
"actually do the operation" so that the guest can write it as two 32
bit halves. Since we don't cache anything yet, all the "make valid"
operation needs to do is write to the VALID bit in the L1 table entry
in guest memory.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
include/hw/intc/arm_gicv5_common.h | 1 +
include/hw/intc/arm_gicv5_regs.h | 9 +++
hw/intc/arm_gicv5.c | 114 +++++++++++++++++++++++++++++
hw/intc/arm_gicv5_common.c | 1 +
4 files changed, 125 insertions(+)
diff --git a/include/hw/intc/arm_gicv5_common.h b/include/hw/intc/arm_gicv5_common.h
index fb88c39e8b4..19700c7d5e3 100644
--- a/include/hw/intc/arm_gicv5_common.h
+++ b/include/hw/intc/arm_gicv5_common.h
@@ -91,6 +91,7 @@ struct GICv5Common {
uint32_t irs_pe_selr[NUM_GICV5_DOMAINS];
uint64_t irs_vmt_baser[NUM_GICV5_DOMAINS];
uint32_t irs_vmt_cfgr[NUM_GICV5_DOMAINS];
+ uint64_t irs_vmap_l2_vmtr[NUM_GICV5_DOMAINS];
/*
* Pointer to an array of state information for the SPIs. Array
diff --git a/include/hw/intc/arm_gicv5_regs.h b/include/hw/intc/arm_gicv5_regs.h
index 997444a0195..3fe82330873 100644
--- a/include/hw/intc/arm_gicv5_regs.h
+++ b/include/hw/intc/arm_gicv5_regs.h
@@ -270,6 +270,15 @@ FIELD(L2_ISTE, HWU, 9, 2)
FIELD(L2_ISTE, PRIORITY, 11, 5)
FIELD(L2_ISTE, IAFFID, 16, 16)
+FIELD(L1_VMTE, VALID, 0, 1)
+FIELD(L1_VMTE, L2_ADDR, 12, 44)
+
+/*
+ * L2 VMTEs are always 32 bytes, and the L2 table is always 4KB,
+ * so the lower 7 bits in a VM ID index the L2 table.
+ */
+#define VMT_L2_IDX_BITS 7
+
/*
* Format used for gicv5_request_config() return value, which matches
* the ICC_ICSR_EL1 bit layout.
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index bd83e5d191b..a5468b8d61e 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -482,6 +482,19 @@ static void put_l2_iste(GICv5Common *cs, const GICv5ISTConfig *cfg,
write_l2_iste_mem(cs, cfg, h->l2_iste_addr, h->l2_iste);
}
+static hwaddr l1_vmte_addr(GICv5Common *cs, const GICv5VMTConfig *cfg,
+ uint32_t vmid)
+{
+ /*
+ * In a 2-level VMT configuration, return the address of the L1
+ * VMT entry for this VM ID. The bottom VMT_L2_IDX_BITS of the
+ * ID value are the index into the L2 table, and the higher bits
+ * of the ID index the L1 table. The L1 table entries are 8 bytes.
+ */
+ uint32_t l1_index = vmid >> VMT_L2_IDX_BITS;
+ return cfg->base + (l1_index * 8);
+}
+
void gicv5_set_priority(GICv5Common *cs, uint32_t id, uint8_t priority,
GICv5Domain domain, GICv5IntType type, bool virtual)
{
@@ -1242,6 +1255,67 @@ static void irs_vmt_baser_write(GICv5 *s, GICv5Domain domain, uint64_t value)
}
}
+static void irs_vmap_l2_vmtr_write(GICv5 *s, GICv5Domain domain, uint64_t value)
+{
+ GICv5Common *cs = ARM_GICV5_COMMON(s);
+ GICv5VMTConfig *cfg = &s->vmt_config[domain];
+ uint32_t vmid = FIELD_EX64(value, IRS_VMAP_L2_VMTR, VM_ID);
+ bool m = FIELD_EX64(value, IRS_VMAP_L2_VMTR, M);
+ hwaddr l1_addr;
+ uint64_t l1_vmte;
+ MemTxResult res;
+
+ if (!gicv5_domain_has_virt(cs, domain) || !cfg->valid || !cfg->structure) {
+ /*
+ * The whole register is RAZ/WI if no virt, or if the VM
+ * table is invalid or not 2 level.
+ */
+ return;
+ }
+
+ /*
+ * Otherwise, write to the register. The M bit is WO/UNKNOWN,
+ * and we make sure it is 0, so that a 32-bit write to the low
+ * half of the register never appears to have the M bit set.
+ */
+ cs->irs_vmap_l2_vmtr[domain] = value & ~R_IRS_VMAP_L2_VMTR_M_MASK;
+
+ if (!m || vmid >= (1 << cfg->vm_id_bits)) {
+ /*
+ * If guest didn't actually ask to make the L2 table valid, or
+ * the ID is out of range, do nothing except the register update.
+ */
+ return;
+ }
+
+ /* Find the relevant L1 VMTE and set its VALID bit */
+ l1_addr = l1_vmte_addr(cs, cfg, vmid);
+
+ l1_vmte = address_space_ldq_le(&cs->dma_as, l1_addr, cfg->txattrs, &res);
+ if (res != MEMTX_OK) {
+ goto txfail;
+ }
+
+ if (FIELD_EX64(l1_vmte, L1_VMTE, VALID) == 1) {
+ /* L2 VM table already valid is "no effect" */
+ return;
+ }
+
+ l1_vmte = FIELD_DP64(l1_vmte, L1_VMTE, VALID, 1);
+
+ address_space_stq_le(&cs->dma_as, l1_addr, l1_vmte, cfg->txattrs, &res);
+ if (res != MEMTX_OK) {
+ goto txfail;
+ }
+
+ return;
+
+txfail:
+ /* Reportable with EC=0x0 if sw error reporting implemented */
+ qemu_log_mask(LOG_GUEST_ERROR, "L1 VMTE update failed for VMID 0x%x at "
+ "physical address 0x" HWADDR_FMT_plx "\n", vmid, l1_addr);
+}
+
static void spi_sample(GICv5SPIState *spi)
{
/*
@@ -1379,6 +1453,24 @@ static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset,
*data = 0;
}
return true;
+ case A_IRS_VMAP_L2_VMTR:
+ if (gicv5_domain_has_virt(cs, domain) &&
+ s->vmt_config[domain].valid && s->vmt_config[domain].structure) {
+ *data = extract64(cs->irs_vmap_l2_vmtr[domain], 0, 32);
+ } else {
+ /* RAZ/WI if no virt or no VM table or VM table not 2 level */
+ *data = 0;
+ }
+ return true;
+ case A_IRS_VMAP_L2_VMTR + 4:
+ if (gicv5_domain_has_virt(cs, domain) &&
+ s->vmt_config[domain].valid && s->vmt_config[domain].structure) {
+ *data = extract64(cs->irs_vmap_l2_vmtr[domain], 32, 32);
+ } else {
+ /* RAZ/WI if no virt or no VM table or VM table not 2 level */
+ *data = 0;
+ }
+ return true;
case A_IRS_SPI_STATUSR:
/*
* QEMU writes to IRS_SPI_{CFGR,DOMAINR,SELR,VMR} take effect
@@ -1501,6 +1593,16 @@ static bool config_writel(GICv5 *s, GICv5Domain domain, hwaddr offset,
}
}
return true;
+ case A_IRS_VMAP_L2_VMTR:
+ irs_vmap_l2_vmtr_write(s, domain,
+ deposit64(cs->irs_vmap_l2_vmtr[domain],
+ 0, 32, data));
+ return true;
+ case A_IRS_VMAP_L2_VMTR + 4:
+ irs_vmap_l2_vmtr_write(s, domain,
+ deposit64(cs->irs_vmap_l2_vmtr[domain],
+ 32, 32, data));
+ return true;
case A_IRS_SPI_SELR:
cs->irs_spi_selr[domain] = data;
return true;
@@ -1592,6 +1694,15 @@ static bool config_readll(GICv5 *s, GICv5Domain domain, hwaddr offset,
*data = 0;
}
return true;
+ case A_IRS_VMAP_L2_VMTR:
+ if (gicv5_domain_has_virt(cs, domain) &&
+ s->vmt_config[domain].valid && s->vmt_config[domain].structure) {
+ *data = cs->irs_vmap_l2_vmtr[domain];
+ } else {
+ /* RAZ/WI if no virt or no VM table or not 2-level */
+ *data = 0;
+ }
+ return true;
}
return false;
@@ -1607,6 +1718,9 @@ static bool config_writell(GICv5 *s, GICv5Domain domain, hwaddr offset,
case A_IRS_VMT_BASER:
irs_vmt_baser_write(s, domain, data);
return true;
+ case A_IRS_VMAP_L2_VMTR:
+ irs_vmap_l2_vmtr_write(s, domain, data);
+ return true;
}
return false;
diff --git a/hw/intc/arm_gicv5_common.c b/hw/intc/arm_gicv5_common.c
index 6a9d727bb65..945257fef2c 100644
--- a/hw/intc/arm_gicv5_common.c
+++ b/hw/intc/arm_gicv5_common.c
@@ -108,6 +108,7 @@ static void gicv5_common_reset_hold(Object *obj, ResetType type)
if (cs->has_virt) {
memset(cs->irs_vmt_baser, 0, sizeof(cs->irs_vmt_baser));
memset(cs->irs_vmt_cfgr, 0, sizeof(cs->irs_vmt_cfgr));
+ memset(cs->irs_vmap_l2_vmtr, 0, sizeof(cs->irs_vmap_l2_vmtr));
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 47/77] hw/intc/arm_gicv5: Implement IRS_VMAP_VMR
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (45 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 46/77] hw/intc/arm_gicv5: Implement IRS_VMAP_L2_VMTR Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 48/77] hw/intc/arm_gicv5: Factor out code to fill in a GICv5ISTConfig Peter Maydell
` (29 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
The IRS_VMAP_VMR register lets the guest mark a VM as valid. This is
a 64-bit register similar in operation to IRS_VMAP_L2_VMTR.
We are eventually going to want to cache the information in a VM
table entry, but for the moment implement the "make valid" operation
as simply writing 1 to the VALID bit in the L2 VMTE.
Note that unlike many of the other address fields in GICv5 data
structures, we don't need to clear any of the low bits in
L1_VMTE.L2_ADDR beyond masking with R_L1_VMTE_L2_ADDR_MASK. This is
because a level 2 VMT is always 4KB and so the alignment is fixed;
the mask clears the low 12 bits, enforcing 4KB alignment.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
include/hw/intc/arm_gicv5_common.h | 1 +
include/hw/intc/arm_gicv5_regs.h | 21 +++++++
hw/intc/arm_gicv5.c | 94 ++++++++++++++++++++++++++++++
hw/intc/arm_gicv5_common.c | 1 +
hw/intc/trace-events | 1 +
5 files changed, 118 insertions(+)
diff --git a/include/hw/intc/arm_gicv5_common.h b/include/hw/intc/arm_gicv5_common.h
index 19700c7d5e3..5707111b98a 100644
--- a/include/hw/intc/arm_gicv5_common.h
+++ b/include/hw/intc/arm_gicv5_common.h
@@ -92,6 +92,7 @@ struct GICv5Common {
uint64_t irs_vmt_baser[NUM_GICV5_DOMAINS];
uint32_t irs_vmt_cfgr[NUM_GICV5_DOMAINS];
uint64_t irs_vmap_l2_vmtr[NUM_GICV5_DOMAINS];
+ uint64_t irs_vmap_vmr[NUM_GICV5_DOMAINS];
/*
* Pointer to an array of state information for the SPIs. Array
diff --git a/include/hw/intc/arm_gicv5_regs.h b/include/hw/intc/arm_gicv5_regs.h
index 3fe82330873..764117d5d1b 100644
--- a/include/hw/intc/arm_gicv5_regs.h
+++ b/include/hw/intc/arm_gicv5_regs.h
@@ -273,6 +273,27 @@ FIELD(L2_ISTE, IAFFID, 16, 16)
FIELD(L1_VMTE, VALID, 0, 1)
FIELD(L1_VMTE, L2_ADDR, 12, 44)
+/* The L2 VMTE is 32 bytes, four 64-bit words */
+FIELD(L2_VMTE_0, VALID, 0, 1)
+FIELD(L2_VMTE_0, VMD_ADDR, 3, 53)
+
+FIELD(L2_VMTE_1, VPET_ADDR, 3, 53)
+FIELD(L2_VMTE_1, VPE_ID_BITS, 59, 5)
+
+FIELD(L2_VMTE_2, LPI_IST_VALID, 0, 1)
+FIELD(L2_VMTE_2, LPI_IST_L2SZ, 1, 2)
+FIELD(L2_VMTE_2, LPI_IST_ADDR, 6, 50)
+FIELD(L2_VMTE_2, LPI_ISTSZ, 56, 2)
+FIELD(L2_VMTE_2, LPI_IST_STRUCTURE, 58, 1)
+FIELD(L2_VMTE_2, LPI_ID_BITS, 59, 5)
+
+FIELD(L2_VMTE_3, SPI_IST_VALID, 0, 1)
+FIELD(L2_VMTE_3, SPI_IST_L2SZ, 1, 2)
+FIELD(L2_VMTE_3, SPI_IST_ADDR, 6, 50)
+FIELD(L2_VMTE_3, SPI_ISTSZ, 56, 2)
+FIELD(L2_VMTE_3, SPI_IST_STRUCTURE, 58, 1)
+FIELD(L2_VMTE_3, SPI_ID_BITS, 59, 5)
+
/*
* L2 VMTEs are always 32 bytes, and the L2 table is always 4KB,
* so the lower 7 bits in a VM ID index the L2 table.
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index a5468b8d61e..410b7b45251 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -1308,6 +1308,65 @@ static void irs_vmap_l2_vmtr_write(GICv5 *s, GICv5Domain domain, uint64_t value)
goto txfail;
}
+ trace_gicv5_vmap_l2_vmtr(domain_name[domain], vmid);
+
+ return;
+
+txfail:
+ /* Reportable with EC=0x0 if sw error reporting implemented */
+ qemu_log_mask(LOG_GUEST_ERROR, "L1 VMTE update failed for VMID 0x%x at "
+ "physical address 0x" HWADDR_FMT_plx "\n", vmid, l1_addr);
+}
+
+static void irs_vmap_vmr_write(GICv5 *s, GICv5Domain domain, uint64_t value)
+{
+ GICv5Common *cs = ARM_GICV5_COMMON(s);
+ GICv5VMTConfig *cfg = &s->vmt_config[domain];
+ uint32_t vmid = FIELD_EX64(value, IRS_VMAP_VMR, VM_ID);
+ bool m = FIELD_EX64(value, IRS_VMAP_VMR, M);
+ bool u = FIELD_EX64(value, IRS_VMAP_VMR, U);
+ hwaddr l1_addr, l2_addr;
+ uint64_t l1_vmte, l2_vmte_0;
+ MemTxResult res;
+
+ if (!gicv5_domain_has_virt(cs, domain) || !cfg->valid) {
+ /* Whole register RAZ/WI if no virt or no VM table */
+ return;
+ }
+
+ /* M bit is WO/UNKNOWN; write the other fields */
+ cs->irs_vmap_vmr[domain] = value & ~R_IRS_VMAP_VMR_M_MASK;
+
+ if (!m || vmid >= (1 << cfg->vm_id_bits)) {
+ return;
+ }
+
+ /* Find the L1 VMTE */
+ l1_addr = l1_vmte_addr(cs, cfg, vmid);
+ l1_vmte = address_space_ldq_le(&cs->dma_as, l1_addr, cfg->txattrs, &res);
+ if (res != MEMTX_OK) {
+ goto txfail;
+ }
+
+ if (FIELD_EX64(l1_vmte, L1_VMTE, VALID) == 0) {
+ /* No effect if L2 VM table is not valid */
+ return;
+ }
+
+ l2_addr = l1_vmte & R_L1_VMTE_L2_ADDR_MASK;
+
+ l2_vmte_0 = address_space_ldq_le(&cs->dma_as, l2_addr, cfg->txattrs, &res);
+ if (res != MEMTX_OK) {
+ goto txfail;
+ }
+
+ l2_vmte_0 = FIELD_DP64(l2_vmte_0, L2_VMTE_0, VALID, !u);
+
+ address_space_stq_le(&cs->dma_as, l2_addr, l2_vmte_0, cfg->txattrs, &res);
+ if (res != MEMTX_OK) {
+ goto txfail;
+ }
+
return;
txfail:
@@ -1471,6 +1530,22 @@ static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset,
*data = 0;
}
return true;
+ case A_IRS_VMAP_VMR:
+ if (gicv5_domain_has_virt(cs, domain) && s->vmt_config[domain].valid) {
+ *data = extract64(cs->irs_vmap_vmr[domain], 0, 32);
+ } else {
+ /* RAZ/WI if no virt or no VM table */
+ *data = 0;
+ }
+ return true;
+ case A_IRS_VMAP_VMR + 4:
+ if (gicv5_domain_has_virt(cs, domain) && s->vmt_config[domain].valid) {
+ *data = extract64(cs->irs_vmap_vmr[domain], 32, 32);
+ } else {
+ /* RAZ/WI if no virt or no VM table */
+ *data = 0;
+ }
+ return true;
case A_IRS_SPI_STATUSR:
/*
* QEMU writes to IRS_SPI_{CFGR,DOMAINR,SELR,VMR} take effect
@@ -1603,6 +1678,14 @@ static bool config_writel(GICv5 *s, GICv5Domain domain, hwaddr offset,
deposit64(cs->irs_vmap_l2_vmtr[domain],
32, 32, data));
return true;
+ case A_IRS_VMAP_VMR:
+ irs_vmap_vmr_write(s, domain,
+ deposit64(cs->irs_vmap_vmr[domain], 0, 32, data));
+ return true;
+ case A_IRS_VMAP_VMR + 4:
+ irs_vmap_vmr_write(s, domain,
+ deposit64(cs->irs_vmap_vmr[domain], 32, 32, data));
+ return true;
case A_IRS_SPI_SELR:
cs->irs_spi_selr[domain] = data;
return true;
@@ -1703,6 +1786,14 @@ static bool config_readll(GICv5 *s, GICv5Domain domain, hwaddr offset,
*data = 0;
}
return true;
+ case A_IRS_VMAP_VMR:
+ if (gicv5_domain_has_virt(cs, domain) && s->vmt_config[domain].valid) {
+ *data = cs->irs_vmap_vmr[domain];
+ } else {
+ /* RAZ/WI if no virt or no VM table */
+ *data = 0;
+ }
+ return true;
}
return false;
@@ -1721,6 +1812,9 @@ static bool config_writell(GICv5 *s, GICv5Domain domain, hwaddr offset,
case A_IRS_VMAP_L2_VMTR:
irs_vmap_l2_vmtr_write(s, domain, data);
return true;
+ case A_IRS_VMAP_VMR:
+ irs_vmap_vmr_write(s, domain, data);
+ return true;
}
return false;
diff --git a/hw/intc/arm_gicv5_common.c b/hw/intc/arm_gicv5_common.c
index 945257fef2c..19338ad5b9c 100644
--- a/hw/intc/arm_gicv5_common.c
+++ b/hw/intc/arm_gicv5_common.c
@@ -109,6 +109,7 @@ static void gicv5_common_reset_hold(Object *obj, ResetType type)
memset(cs->irs_vmt_baser, 0, sizeof(cs->irs_vmt_baser));
memset(cs->irs_vmt_cfgr, 0, sizeof(cs->irs_vmt_cfgr));
memset(cs->irs_vmap_l2_vmtr, 0, sizeof(cs->irs_vmap_l2_vmtr));
+ memset(cs->irs_vmap_vmr, 0, sizeof(cs->irs_vmap_vmr));
}
}
diff --git a/hw/intc/trace-events b/hw/intc/trace-events
index 3267b3c240c..439739088d0 100644
--- a/hw/intc/trace-events
+++ b/hw/intc/trace-events
@@ -248,6 +248,7 @@ gicv5_irs_recalc_hppi_fail(const char *domain, uint32_t iaffid, const char *reas
gicv5_irs_recalc_hppi(const char *domain, uint32_t iaffid, uint32_t id, uint8_t prio) "GICv5 IRS %s IAFFID %u: new HPPI ID 0x%x prio %u"
gicv5_vmt_valid(const char *domain, uint64_t base, uint8_t vm_id_bits, bool structure) "GICv5 IRS %s VM table now valid: base 0x%" PRIx64 " vm_id_bits %u 2-level %d"
gicv5_vmt_invalid(const char *domain) "GICv5 IRS %s VM table no longer valid"
+gicv5_vmap_l2_vmtr(const char *domain, uint32_t vmid) "GICv5 IRS %s VM ID %u now valid"
# arm_gicv5_common.c
gicv5_common_realize(uint32_t irsid, uint32_t num_cpus, uint32_t spi_base, uint32_t spi_irs_range, uint32_t spi_range) "GICv5 IRS realized: IRS ID %u, %u CPUs, SPI base %u, SPI IRS range %u, SPI range %u"
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 48/77] hw/intc/arm_gicv5: Factor out code to fill in a GICv5ISTConfig
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (46 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 47/77] hw/intc/arm_gicv5: Implement IRS_VMAP_VMR Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 49/77] hw/intc/arm_gicv5: Cache info about valid VMs in a hashtable Peter Maydell
` (28 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
irs_ist_baser_write() has code that fills in a GICv5ISTConfig based
on various register fields, including sanitizing uses of reserved
values, enforcing minimum and maximum values, and pre-calculating how
many bits index the L2 table.
We will want exactly the same logic for setting up GICv5ISTConfig
structs for a VM's LPI and SPI IST structures based on the fields in
the L2 VMTE. Factor out the "fill in the GICv5ISTConfig" code to a
separate function that we can call.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/intc/arm_gicv5.c | 181 ++++++++++++++++++++++++--------------------
1 file changed, 100 insertions(+), 81 deletions(-)
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index 410b7b45251..db814e12cae 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -970,6 +970,96 @@ void gicv5_deactivate(GICv5Common *cs, uint32_t id, GICv5Domain domain,
irs_recalc_hppi(s, domain, iaffid);
}
+static void initialize_ist_config(GICv5Common *cs, GICv5Domain domain,
+ GICv5ISTConfig *cfg,
+ hwaddr base,
+ uint8_t id_bits, uint8_t istsz, uint8_t l2sz,
+ bool structure)
+{
+ uint8_t istbits, l2bits, l2_idx_bits;
+ int tableszbits;
+
+ switch (istsz) {
+ case 0:
+ case 3: /* reserved: acts like the minimum required size */
+ istbits = 2;
+ break;
+ case 1:
+ istbits = 3;
+ break;
+ case 2:
+ istbits = 4;
+ break;
+ default:
+ g_assert_not_reached();
+ }
+ switch (l2sz) {
+ case 0:
+ case 3: /* reserved; CONSTRAINED UNPREDICTABLE */
+ l2bits = 12; /* 4K: 12 bits */
+ break;
+ case 1:
+ l2bits = 14; /* 16K: 14 bits */
+ break;
+ case 2:
+ l2bits = 16; /* 64K: 16 bits */
+ break;
+ default:
+ g_assert_not_reached();
+ }
+ /*
+ * Calculate how many bits of an ID index the L2 table
+ * (e.g. if we need 14 bits to index each byte in a 16K L2 table,
+ * but each entry is 4 bytes wide then we need 14 - 2 = 12 bits
+ * to index an entry in the table).
+ */
+ l2_idx_bits = l2bits - istbits;
+ cfg->base = base;
+ cfg->txattrs = irs_txattrs(cs, domain);
+ cfg->id_bits = id_bits;
+ cfg->istsz = 1 << istbits;
+ cfg->l2_idx_bits = l2_idx_bits;
+ cfg->l2bits = l2bits;
+ cfg->structure = structure;
+
+ /*
+ * Bits [N:0] of the base addr are ignored, to enforce that in a
+ * 1-level IST it is aligned to the size of the ISTE array,
+ * and in a 2-level IST it is aligned to the size of the L1 table.
+ * The spec defines N in terms of the raw L2SZ, ISTSZ and LPI_ID_BITS
+ * fields, but we have already sanitized these to
+ * istbits = ISTSZ + 2
+ * l2bits = (L2SZ * 2) + 12
+ * id_bits = LPI_ID_BITS
+ * We have also already enforced the "bottom 6 bits are 0" via
+ * the fixed field mask, so can skip the Max() operation.
+ * We want tableszbits == the number of bits to zero, which is N + 1.
+ */
+ if (cfg->structure) {
+ /*
+ * L1 table is indexed by the (id_bits - l2_idx_bits) bits in
+ * the ID, so has 2^(id_bits - l2_idx_bits) entries, and each
+ * entry is 8 bytes == 2^3.
+ */
+ tableszbits = id_bits - l2_idx_bits + 3;
+ } else {
+ /* table has 2^id_bits entries of 2^istbits size each */
+ tableszbits = id_bits + istbits;
+ }
+ cfg->base &= ~MAKE_64BIT_MASK(0, tableszbits);
+
+ if (!cfg->lpi_cache) {
+ /*
+ * Keys are GINT_TO_POINTER(intid), so we want the g_direct_hash
+ * and g_direct_equal hash and equality functions. Keys are
+ * GINT_TO_POINTER(L2_ISTE). We don't want the hash table to try
+ * to free either keys or values.
+ */
+ cfg->lpi_cache = g_hash_table_new(NULL, NULL);
+ }
+ cfg->valid = true;
+}
+
static void irs_map_l2_istr_write(GICv5 *s, GICv5Domain domain, uint64_t value)
{
GICv5Common *cs = ARM_GICV5_COMMON(s);
@@ -1080,92 +1170,21 @@ static void irs_ist_baser_write(GICv5 *s, GICv5Domain domain, uint64_t value)
* sanitize the reserved values, and expand fields out into byte counts.
*/
GICv5ISTConfig *cfg = &s->phys_lpi_config[domain];
- uint8_t istbits, l2bits, l2_idx_bits;
- int tableszbits;
+ hwaddr base = cs->irs_ist_baser[domain] & R_IRS_IST_BASER_ADDR_MASK;
uint8_t id_bits = FIELD_EX64(cs->irs_ist_cfgr[domain],
IRS_IST_CFGR, LPI_ID_BITS);
- id_bits = MIN(MAX(id_bits, QEMU_GICV5_MIN_LPI_ID_BITS), QEMU_GICV5_ID_BITS);
-
- switch (FIELD_EX64(cs->irs_ist_cfgr[domain], IRS_IST_CFGR, ISTSZ)) {
- case 0:
- case 3: /* reserved: acts like the minimum required size */
- istbits = 2;
- break;
- case 1:
- istbits = 3;
- break;
- case 2:
- istbits = 4;
- break;
- default:
- g_assert_not_reached();
- }
- switch (FIELD_EX64(cs->irs_ist_cfgr[domain], IRS_IST_CFGR, L2SZ)) {
- case 0:
- case 3: /* reserved; CONSTRAINED UNPREDICTABLE */
- l2bits = 12; /* 4K: 12 bits */
- break;
- case 1:
- l2bits = 14; /* 16K: 14 bits */
- break;
- case 2:
- l2bits = 16; /* 64K: 16 bits */
- break;
- default:
- g_assert_not_reached();
- }
- /*
- * Calculate how many bits of an ID index the L2 table
- * (e.g. if we need 14 bits to index each byte in a 16K L2 table,
- * but each entry is 4 bytes wide then we need 14 - 2 = 12 bits
- * to index an entry in the table).
- */
- l2_idx_bits = l2bits - istbits;
- cfg->base = cs->irs_ist_baser[domain] & R_IRS_IST_BASER_ADDR_MASK;
- cfg->txattrs = irs_txattrs(cs, domain),
- cfg->id_bits = id_bits;
- cfg->istsz = 1 << istbits;
- cfg->l2_idx_bits = l2_idx_bits;
- cfg->l2bits = l2bits;
- cfg->structure = FIELD_EX64(cs->irs_ist_cfgr[domain],
+ uint8_t istsz = FIELD_EX64(cs->irs_ist_cfgr[domain],
+ IRS_IST_CFGR, ISTSZ);
+ uint8_t l2sz = FIELD_EX64(cs->irs_ist_cfgr[domain],
+ IRS_IST_CFGR, L2SZ);
+ bool structure = FIELD_EX64(cs->irs_ist_cfgr[domain],
IRS_IST_CFGR, STRUCTURE);
- /*
- * Bits [N:0] of the base addr are ignored, to enforce that in a
- * 1-level IST it is aligned to the size of the ISTE array,
- * and in a 2-level IST it is aligned to the size of the L1 table.
- * The spec defines N in terms of the raw L2SZ, ISTSZ and LPI_ID_BITS
- * fields, but we have already sanitized these to
- * istbits = ISTSZ + 2
- * l2bits = (L2SZ * 2) + 12
- * id_bits = LPI_ID_BITS
- * We have also already enforced the "bottom 6 bits are 0" via
- * R_IRS_IST_BASER_ADDR_MASK, so can skip the Max() operation.
- * We want tableszbits == the number of bits to zero, which is N + 1.
- */
- if (cfg->structure) {
- /*
- * L1 table is indexed by the (id_bits - l2_idx_bits) bits in
- * the ID, so has 2^(id_bits - l2_idx_bits) entries, and each
- * entry is 8 bytes == 2^3.
- */
- tableszbits = id_bits - l2_idx_bits + 3;
- } else {
- /* table has 2^id_bits entries of 2^istbits size each */
- tableszbits = id_bits + istbits;
- }
- cfg->base &= ~MAKE_64BIT_MASK(0, tableszbits);
+ id_bits = MIN(MAX(id_bits, QEMU_GICV5_MIN_LPI_ID_BITS), QEMU_GICV5_ID_BITS);
+
+ initialize_ist_config(cs, domain, cfg, base, id_bits,
+ istsz, l2sz, structure);
- if (!cfg->lpi_cache) {
- /*
- * Keys are GINT_TO_POINTER(intid), so we want the g_direct_hash
- * and g_direct_equal hash and equality functions. Keys are
- * GINT_TO_POINTER(L2_ISTE). We don't want the hash table to try
- * to free either keys or values.
- */
- cfg->lpi_cache = g_hash_table_new(NULL, NULL);
- }
- cfg->valid = true;
trace_gicv5_ist_valid(domain_name[domain], cfg->base, cfg->id_bits,
cfg->l2_idx_bits, cfg->istsz, cfg->structure);
irs_recalc_hppi_all_cpus(s, domain);
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 49/77] hw/intc/arm_gicv5: Cache info about valid VMs in a hashtable
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (47 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 48/77] hw/intc/arm_gicv5: Factor out code to fill in a GICv5ISTConfig Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 50/77] hw/intc/arm_gicv5: Populate VM cache when VM table becomes valid Peter Maydell
` (27 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
The VM table in guest memory contains information about each VM the
guest has set up. In particular, it has information about other data
structures such as the VM's LPI and SPI tables and their
configuration. We don't want to have to read this from guest memory
and extract the fields every time we use it.
Add a hash table to GICv5VMTConfig: the keys are VM IDs, and
the values are structs with the extracted and sanitized information
from the L2 VMTE.
In this commit we populate the hash table entry when the guest makes
a VM valid via a write ta IRS_VMAP_VMR. It is also permitted for the
guest to pass us an L1 or L2 VM table where some entries are
pre-marked as valid; we will handle creating the hash table entries
for that case in the following commit.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
include/hw/intc/arm_gicv5.h | 2 +
include/hw/intc/arm_gicv5_regs.h | 3 +
hw/intc/arm_gicv5.c | 216 ++++++++++++++++++++++++++++++-
hw/intc/trace-events | 1 +
4 files changed, 216 insertions(+), 6 deletions(-)
diff --git a/include/hw/intc/arm_gicv5.h b/include/hw/intc/arm_gicv5.h
index 785c7112fd9..28417317376 100644
--- a/include/hw/intc/arm_gicv5.h
+++ b/include/hw/intc/arm_gicv5.h
@@ -36,6 +36,8 @@ typedef struct GICv5VMTConfig {
uint8_t vm_id_bits; /* number of VM ID bits for the domain */
bool structure; /* true if using 2-level table */
bool valid; /* true if this table is valid and usable */
+ /* This caches information about valid VMs */
+ GHashTable *vm_cache;
} GICv5VMTConfig;
/*
diff --git a/include/hw/intc/arm_gicv5_regs.h b/include/hw/intc/arm_gicv5_regs.h
index 764117d5d1b..a2bd6e4fe17 100644
--- a/include/hw/intc/arm_gicv5_regs.h
+++ b/include/hw/intc/arm_gicv5_regs.h
@@ -294,6 +294,9 @@ FIELD(L2_VMTE_3, SPI_ISTSZ, 56, 2)
FIELD(L2_VMTE_3, SPI_IST_STRUCTURE, 58, 1)
FIELD(L2_VMTE_3, SPI_ID_BITS, 59, 5)
+/* Size of L2 VMTE in 64-bit words */
+#define L2_VMTE_WORDS 4
+
/*
* L2 VMTEs are always 32 bytes, and the L2 table is always 4KB,
* so the lower 7 bits in a VM ID index the L2 table.
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index db814e12cae..1120026851a 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -23,6 +23,20 @@
OBJECT_DEFINE_TYPE(GICv5, gicv5, ARM_GICV5, ARM_GICV5_COMMON)
+/* In the GICv5VMTConfig::vm_cache this is how we store VMTE info */
+typedef struct VMTE {
+ GICv5ISTConfig lpi_ist;
+ GICv5ISTConfig spi_ist;
+ /* Address of the in-memory L2_VMTE for this VMTE */
+ hwaddr vmte_addr;
+ hwaddr vpet_addr;
+ uint32_t vmid;
+ uint8_t vpe_id_bits;
+ GICv5Domain domain;
+ /* We don't cache the VMD_ADDR as we don't use VMDs */
+ /* We don't cache VALID: the existence of this struct implies VALID=1 */
+} VMTE;
+
static const char *domain_name[] = {
[GICV5_ID_S] = "Secure",
[GICV5_ID_NS] = "NonSecure",
@@ -75,6 +89,22 @@ static uint32_t gicv5_idreg(int regoffset)
return gic_ids[regoffset];
}
+/* GDestroyNotify function for VMTE struct */
+static void VMTE_free(void *data)
+{
+ VMTE *vmte = data;
+
+ /* Destroy (without writing back to guest memory) the ISTConfigs */
+ if (vmte->lpi_ist.lpi_cache) {
+ g_hash_table_destroy(vmte->lpi_ist.lpi_cache);
+ }
+ if (vmte->spi_ist.lpi_cache) {
+ g_hash_table_destroy(vmte->spi_ist.lpi_cache);
+ }
+
+ g_free(vmte);
+}
+
static bool gicv5_domain_has_virt(GICv5Common *cs, GICv5Domain domain)
{
/*
@@ -1110,6 +1140,117 @@ bool gicv5_set_resident(GICv5Common *cs, GICv5Domain domain, bool valid,
return true;
}
+static bool read_first_vmte_word(GICv5Common *cs, GICv5VMTConfig *cfg,
+ hwaddr l2_addr,
+ uint64_t l2_vmte[L2_VMTE_WORDS])
+{
+ /* Read the first word of the L2 VMTE, returning false on failure */
+ MemTxResult res;
+
+ l2_vmte[0] = address_space_ldq_le(&cs->dma_as, l2_addr,
+ cfg->txattrs, &res);
+ return res == MEMTX_OK;
+}
+
+static bool read_other_vmte_words(GICv5Common *cs, GICv5VMTConfig *cfg,
+ hwaddr l2_addr,
+ uint64_t l2_vmte[L2_VMTE_WORDS])
+{
+ /*
+ * Read L2 VMTE words 1..3, returning false on failure.
+ * @l2_addr is the address of the start of the VMTE.
+ */
+ for (int i = 1; i < L2_VMTE_WORDS; i++) {
+ MemTxResult res;
+
+ l2_vmte[i] = address_space_ldq_le(&cs->dma_as,
+ l2_addr + i * sizeof(uint64_t),
+ cfg->txattrs, &res);
+ if (res != MEMTX_OK) {
+ return false;
+ }
+ }
+ return true;
+}
+
+static void initialize_vlpi_ist_config(GICv5Common *cs, GICv5Domain domain,
+ VMTE *vmte, uint64_t *l2_vmte)
+{
+ hwaddr base = l2_vmte[2] & R_L2_VMTE_2_LPI_IST_ADDR_MASK;
+ uint8_t l2sz = FIELD_EX64(l2_vmte[2], L2_VMTE_2, LPI_IST_L2SZ);
+ uint8_t istsz = FIELD_EX64(l2_vmte[2], L2_VMTE_2, LPI_ISTSZ);
+ uint8_t id_bits = FIELD_EX64(l2_vmte[2], L2_VMTE_2, LPI_ID_BITS);
+ bool structure = FIELD_EX64(l2_vmte[2], L2_VMTE_2, LPI_IST_STRUCTURE);
+
+ id_bits = MIN(MAX(id_bits, QEMU_GICV5_MIN_LPI_ID_BITS), QEMU_GICV5_ID_BITS);
+
+ initialize_ist_config(cs, domain, &vmte->lpi_ist, base,
+ id_bits, istsz, l2sz, structure);
+}
+
+static void initialize_vspi_ist_config(GICv5Common *cs, GICv5Domain domain,
+ VMTE *vmte, uint64_t *l2_vmte)
+{
+ hwaddr base = l2_vmte[3] & R_L2_VMTE_3_SPI_IST_ADDR_MASK;
+ uint8_t l2sz = FIELD_EX64(l2_vmte[3], L2_VMTE_3, SPI_IST_L2SZ);
+ uint8_t istsz = FIELD_EX64(l2_vmte[3], L2_VMTE_3, SPI_ISTSZ);
+ uint8_t id_bits = FIELD_EX64(l2_vmte[3], L2_VMTE_3, SPI_ID_BITS);
+ bool structure = FIELD_EX64(l2_vmte[3], L2_VMTE_3, SPI_IST_STRUCTURE);
+
+ /*
+ * Note that QEMU_GICV5_MIN_LPI_ID_BITS applies to physical
+ * LPIs and virtual LPIs but not to vSPIs.
+ */
+ id_bits = MIN(id_bits, QEMU_GICV5_ID_BITS);
+
+ initialize_ist_config(cs, domain, &vmte->spi_ist, base,
+ id_bits, istsz, l2sz, structure);
+}
+
+static void cache_vmte(GICv5Common *cs, GICv5Domain domain,
+ GICv5VMTConfig *cfg,
+ uint32_t vmid, uint64_t *l2_vmte, hwaddr l2_addr)
+{
+ /*
+ * Add a VMTE struct for an L2 VMTE to the VM cache for @cfg.
+ * @l2_addr should be the address of the L2 VMTE in guest memory.
+ * @l2_vmte is the contents of that VMTE. The caller guarantees
+ * that the VALID bit is set both in @l2_vmte and in memory.
+ */
+ VMTE *vmte = g_new0(VMTE, 1);
+
+ vmte->vmte_addr = l2_addr;
+ vmte->vmid = vmid;
+ vmte->domain = domain;
+
+ vmte->vpet_addr = l2_vmte[1] & R_L2_VMTE_1_VPET_ADDR_MASK;
+ vmte->vpe_id_bits = MIN(FIELD_EX64(l2_vmte[1], L2_VMTE_1, VPE_ID_BITS),
+ QEMU_GICV5_VPE_ID_BITS);
+ /*
+ * Enforce alignment of the VPE table to its size:
+ * it has 2^vpe_id_bits entries of 2^3 == 8 bytes each
+ */
+ vmte->vpet_addr &= ~MAKE_64BIT_MASK(0, vmte->vpe_id_bits + 3);
+
+ /*
+ * If the VALID bits are set for the LPI and SPI ISTs, we can read
+ * the address and config fields now to set up the GICv5ISTConfig.
+ * Otherwise, the guest can make them valid later via IRS_VMAP_VISTR,
+ * and we must not read the address/config fields yet.
+ */
+ if (FIELD_EX64(l2_vmte[2], L2_VMTE_2, LPI_IST_VALID)) {
+ initialize_vlpi_ist_config(cs, domain, vmte, l2_vmte);
+ }
+
+ if (FIELD_EX64(l2_vmte[3], L2_VMTE_3, SPI_IST_VALID)) {
+ initialize_vspi_ist_config(cs, domain, vmte, l2_vmte);
+ }
+
+ g_hash_table_insert(cfg->vm_cache, GINT_TO_POINTER(vmid), vmte);
+
+ trace_gicv5_cache_vmte(domain_name[domain], vmid);
+}
+
/* Data we need to pass through to irs_clean_lpi_cache_entry() */
typedef struct CleanLPICacheUserData {
GICv5Common *cs;
@@ -1191,6 +1332,40 @@ static void irs_ist_baser_write(GICv5 *s, GICv5Domain domain, uint64_t value)
}
}
+typedef struct CleanVMCacheUserData {
+ GICv5Common *cs;
+ GICv5VMTConfig *cfg;
+} CleanVMCacheUserData;
+
+static gboolean irs_clean_vm_cache_entry(gpointer key, gpointer value,
+ gpointer user_data)
+{
+ /*
+ * Drop this entry from the VM cache, including cleaning up its
+ * LPI and SPI caches.
+ */
+ CleanVMCacheUserData *ud = user_data;
+ VMTE *vmte = (VMTE *)value;
+
+ irs_clean_lpi_cache(ud->cs, &vmte->lpi_ist);
+ irs_clean_lpi_cache(ud->cs, &vmte->spi_ist);
+ return true;
+}
+
+static void irs_clean_vm_cache(GICv5Common *cs, GICv5VMTConfig *cfg)
+{
+ /*
+ * Drop the VM table cache. We don't need to write anything back
+ * to guest memory for the VM table entries themselves, but we
+ * need to clean the LPI/SPI cache, which might do writeback.
+ */
+ CleanVMCacheUserData ud;
+
+ ud.cs = cs;
+ ud.cfg = cfg;
+ g_hash_table_foreach_remove(cfg->vm_cache, irs_clean_vm_cache_entry, &ud);
+}
+
static void irs_vmt_baser_write(GICv5 *s, GICv5Domain domain, uint64_t value)
{
GICv5Common *cs = ARM_GICV5_COMMON(s);
@@ -1207,6 +1382,7 @@ static void irs_vmt_baser_write(GICv5 *s, GICv5Domain domain, uint64_t value)
/* Ignore 1->1 transition */
return;
}
+ irs_clean_vm_cache(cs, &s->vmt_config[domain]);
cs->irs_vmt_baser[domain] = FIELD_DP64(cs->irs_vmt_baser[domain],
IRS_VMT_BASER, VALID, valid);
s->vmt_config[domain].valid = false;
@@ -1267,6 +1443,16 @@ static void irs_vmt_baser_write(GICv5 *s, GICv5Domain domain, uint64_t value)
cfg->base &= ~MAKE_64BIT_MASK(0, tableszbits);
}
+ if (!cfg->vm_cache) {
+ /*
+ * Keys are GINT_TO_POINTER(intid), so we want the g_direct_hash
+ * and g_direct_equal hash and equality functions. We don't
+ * want to free the keys, but we do want to free the values
+ * (which are VMTE*).
+ */
+ cfg->vm_cache = g_hash_table_new_full(NULL, NULL, NULL, VMTE_free);
+ }
+
cfg->valid = true;
trace_gicv5_vmt_valid(domain_name[domain], cfg->base,
@@ -1345,7 +1531,7 @@ static void irs_vmap_vmr_write(GICv5 *s, GICv5Domain domain, uint64_t value)
bool m = FIELD_EX64(value, IRS_VMAP_VMR, M);
bool u = FIELD_EX64(value, IRS_VMAP_VMR, U);
hwaddr l1_addr, l2_addr;
- uint64_t l1_vmte, l2_vmte_0;
+ uint64_t l1_vmte, l2_vmte[L2_VMTE_WORDS];
MemTxResult res;
if (!gicv5_domain_has_virt(cs, domain) || !cfg->valid) {
@@ -1374,16 +1560,25 @@ static void irs_vmap_vmr_write(GICv5 *s, GICv5Domain domain, uint64_t value)
l2_addr = l1_vmte & R_L1_VMTE_L2_ADDR_MASK;
- l2_vmte_0 = address_space_ldq_le(&cs->dma_as, l2_addr, cfg->txattrs, &res);
+ if (!read_first_vmte_word(cs, cfg, l2_addr, l2_vmte)) {
+ goto txfail;
+ }
+
+ l2_vmte[0] = FIELD_DP64(l2_vmte[0], L2_VMTE_0, VALID, !u);
+
+ address_space_stq_le(&cs->dma_as, l2_addr, l2_vmte[0], cfg->txattrs, &res);
if (res != MEMTX_OK) {
goto txfail;
}
- l2_vmte_0 = FIELD_DP64(l2_vmte_0, L2_VMTE_0, VALID, !u);
+ if (u) {
+ g_hash_table_remove(cfg->vm_cache, GINT_TO_POINTER(vmid));
+ } else {
+ if (!read_other_vmte_words(cs, cfg, l2_addr, l2_vmte)) {
+ goto txfail;
+ }
- address_space_stq_le(&cs->dma_as, l2_addr, l2_vmte_0, cfg->txattrs, &res);
- if (res != MEMTX_OK) {
- goto txfail;
+ cache_vmte(cs, domain, cfg, vmid, l2_vmte, l2_addr);
}
return;
@@ -1998,6 +2193,10 @@ static void gicv5_reset_hold(Object *obj, ResetType type)
/* IRS_VMT_BASER and IRS_VMT_CFGR reset to 0, clear cached info */
for (int i = 0; i < NUM_GICV5_DOMAINS; i++) {
s->vmt_config[i].valid = false;
+ /* Drop the VM cache entries without writeback */
+ if (s->vmt_config[i].vm_cache) {
+ g_hash_table_remove_all(s->vmt_config[i].vm_cache);
+ }
}
}
@@ -2120,6 +2319,11 @@ static void gicv5_finalize(Object *obj)
g_hash_table_destroy(ht);
}
+ ht = s->vmt_config[i].vm_cache;
+ if (ht) {
+ g_hash_table_destroy(ht);
+ }
+
g_free(s->hppi[i]);
}
}
diff --git a/hw/intc/trace-events b/hw/intc/trace-events
index 439739088d0..623953b8ddf 100644
--- a/hw/intc/trace-events
+++ b/hw/intc/trace-events
@@ -249,6 +249,7 @@ gicv5_irs_recalc_hppi(const char *domain, uint32_t iaffid, uint32_t id, uint8_t
gicv5_vmt_valid(const char *domain, uint64_t base, uint8_t vm_id_bits, bool structure) "GICv5 IRS %s VM table now valid: base 0x%" PRIx64 " vm_id_bits %u 2-level %d"
gicv5_vmt_invalid(const char *domain) "GICv5 IRS %s VM table no longer valid"
gicv5_vmap_l2_vmtr(const char *domain, uint32_t vmid) "GICv5 IRS %s VM ID %u now valid"
+gicv5_cache_vmte(const char *domain, uint32_t vmid) "GICv5 IRS %s VM ID %u valid and cached"
# arm_gicv5_common.c
gicv5_common_realize(uint32_t irsid, uint32_t num_cpus, uint32_t spi_base, uint32_t spi_irs_range, uint32_t spi_range) "GICv5 IRS realized: IRS ID %u, %u CPUs, SPI base %u, SPI IRS range %u, SPI range %u"
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 50/77] hw/intc/arm_gicv5: Populate VM cache when VM table becomes valid
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (48 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 49/77] hw/intc/arm_gicv5: Cache info about valid VMs in a hashtable Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 51/77] hw/intc/arm_gicv5: Implement IRS_VMAP_VISTR Peter Maydell
` (26 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Unlike the IST data structure, the VM table entries are allowed to be
set up in guest memory with the VALID bit set, so that the VM becomes
valid when whe VM table is made valid (e.g. by setting up the L1 VM
table in IRS_VMT_BASER, or by making an L2 VM table valid through
IRS_VMAP_L2_VMTR). So we need to scan through the VM table in memory
to populate the hash table when these things happen.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
include/hw/intc/arm_gicv5_regs.h | 3 ++
hw/intc/arm_gicv5.c | 80 +++++++++++++++++++++++++++++++-
2 files changed, 82 insertions(+), 1 deletion(-)
diff --git a/include/hw/intc/arm_gicv5_regs.h b/include/hw/intc/arm_gicv5_regs.h
index a2bd6e4fe17..a08aff61a20 100644
--- a/include/hw/intc/arm_gicv5_regs.h
+++ b/include/hw/intc/arm_gicv5_regs.h
@@ -296,12 +296,15 @@ FIELD(L2_VMTE_3, SPI_ID_BITS, 59, 5)
/* Size of L2 VMTE in 64-bit words */
#define L2_VMTE_WORDS 4
+/* ...and in bytes */
+#define L2_VMTE_BYTES (L2_VMTE_WORDS * sizeof(uint64_t))
/*
* L2 VMTEs are always 32 bytes, and the L2 table is always 4KB,
* so the lower 7 bits in a VM ID index the L2 table.
*/
#define VMT_L2_IDX_BITS 7
+#define VMT_L2_TABLE_SIZE 4096
/*
* Format used for gicv5_request_config() return value, which matches
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index 1120026851a..2eb85d0e504 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -1251,6 +1251,72 @@ static void cache_vmte(GICv5Common *cs, GICv5Domain domain,
trace_gicv5_cache_vmte(domain_name[domain], vmid);
}
+static void fill_vmt_cache_from_l2_vmt(GICv5Common *cs, GICv5Domain domain,
+ GICv5VMTConfig *cfg, hwaddr l2_addr,
+ hwaddr l2_limit, uint32_t vmid)
+{
+ /*
+ * Scan an L2 VM table in guest memory, and populate our VMT
+ * cache for each entry that is marked as valid.
+ */
+ for (; l2_addr < l2_limit; l2_addr += 32, vmid += 1) {
+ uint64_t l2_vmte[L2_VMTE_WORDS];
+
+ if (!read_first_vmte_word(cs, cfg, l2_addr, l2_vmte)) {
+ goto txfail;
+ }
+ if (FIELD_EX64(l2_vmte[0], L2_VMTE_0, VALID) == 0) {
+ continue;
+ }
+ if (!read_other_vmte_words(cs, cfg, l2_addr, l2_vmte)) {
+ goto txfail;
+ }
+ cache_vmte(cs, domain, cfg, vmid, l2_vmte, l2_addr);
+ }
+
+txfail:
+ /* Reportable with EC=0x0 if sw error reporting implemented */
+ qemu_log_mask(LOG_GUEST_ERROR, "L2 VMTE read failed for VMID 0x%x at "
+ "physical address 0x" HWADDR_FMT_plx "\n", vmid, l2_addr);
+}
+
+static void fill_vmt_cache_from_l1_vmt(GICv5Common *cs, GICv5Domain domain,
+ GICv5VMTConfig *cfg)
+{
+ /*
+ * Scan the whole VM table in guest memory, and populate our VMT
+ * cache for each entry that is marked as valid.
+ */
+ if (!cfg->structure) {
+ hwaddr l2_limit = cfg->base + (1ULL << cfg->vm_id_bits) * L2_VMTE_BYTES;
+
+ fill_vmt_cache_from_l2_vmt(cs, domain, cfg, cfg->base, l2_limit, 0);
+ } else {
+ uint32_t vmid = 0;
+ hwaddr l1_limit = l1_vmte_addr(cs, cfg, (1ULL << cfg->vm_id_bits));
+
+ for (hwaddr l1_addr = cfg->base;
+ l1_addr < l1_limit;
+ l1_addr += 8, vmid += VMT_L2_TABLE_SIZE / L2_VMTE_BYTES) {
+ MemTxResult res;
+ uint64_t l1_vmte;
+ hwaddr l2_addr;
+
+ l1_vmte = address_space_ldq_le(&cs->dma_as, l1_addr,
+ cfg->txattrs, &res);
+ if (res != MEMTX_OK) {
+ continue;
+ }
+ if (FIELD_EX64(l1_vmte, L1_VMTE, VALID) == 0) {
+ continue;
+ }
+ l2_addr = l1_vmte & R_L1_VMTE_L2_ADDR_MASK;
+ fill_vmt_cache_from_l2_vmt(cs, domain, cfg, l2_addr,
+ l2_addr + VMT_L2_TABLE_SIZE, vmid);
+ }
+ }
+}
+
/* Data we need to pass through to irs_clean_lpi_cache_entry() */
typedef struct CleanLPICacheUserData {
GICv5Common *cs;
@@ -1455,6 +1521,9 @@ static void irs_vmt_baser_write(GICv5 *s, GICv5Domain domain, uint64_t value)
cfg->valid = true;
+ /* The VMT may already have some VMTEs with VALID=1 */
+ fill_vmt_cache_from_l1_vmt(cs, domain, cfg);
+
trace_gicv5_vmt_valid(domain_name[domain], cfg->base,
cfg->vm_id_bits, cfg->structure);
}
@@ -1466,7 +1535,7 @@ static void irs_vmap_l2_vmtr_write(GICv5 *s, GICv5Domain domain, uint64_t value)
GICv5VMTConfig *cfg = &s->vmt_config[domain];
uint32_t vmid = FIELD_EX64(value, IRS_VMAP_L2_VMTR, VM_ID);
bool m = FIELD_EX64(value, IRS_VMAP_L2_VMTR, M);
- hwaddr l1_addr;
+ hwaddr l1_addr, l2_addr;
uint64_t l1_vmte;
MemTxResult res;
@@ -1513,6 +1582,15 @@ static void irs_vmap_l2_vmtr_write(GICv5 *s, GICv5Domain domain, uint64_t value)
goto txfail;
}
+ /*
+ * The L2 VM table we just made valid can have VMTEs which
+ * already have VALID=1 set: read them into the VM cache.
+ */
+ l2_addr = l1_vmte & R_L1_VMTE_L2_ADDR_MASK;
+ fill_vmt_cache_from_l2_vmt(cs, domain, cfg, l2_addr,
+ l2_addr + VMT_L2_TABLE_SIZE,
+ vmid & ~MAKE_64BIT_MASK(0, VMT_L2_IDX_BITS));
+
trace_gicv5_vmap_l2_vmtr(domain_name[domain], vmid);
return;
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 51/77] hw/intc/arm_gicv5: Implement IRS_VMAP_VISTR
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (49 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 50/77] hw/intc/arm_gicv5: Populate VM cache when VM table becomes valid Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 52/77] hw/intc/arm_gicv5: Factor out "make an L2 IST valid" function Peter Maydell
` (25 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
A VM in the VM table does not have to specify the LPI and
SPI ISTs up-front. Instead, it can leave the VMTE LPI_IST_VALID
or SPI_IST_VALID bits 0, and set up the IST later using
IRS_VMAP_VISTR. The sequence here is:
* software writes to the L2 VM table entry to set the
configuration fields associated with the IST
* software writes to IRS_VMAP_VISTR
* the IRS reads the info from the L2 VM table entry,
sets up the IST, and writes to the VALID bit in the
L2 VM table entry
Software can also use IRS_VMAP_VISTR to change an IST from
valid to invalid.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
include/hw/intc/arm_gicv5_common.h | 1 +
hw/intc/arm_gicv5.c | 154 +++++++++++++++++++++++++++++
hw/intc/arm_gicv5_common.c | 1 +
hw/intc/trace-events | 1 +
4 files changed, 157 insertions(+)
diff --git a/include/hw/intc/arm_gicv5_common.h b/include/hw/intc/arm_gicv5_common.h
index 5707111b98a..19e13693de9 100644
--- a/include/hw/intc/arm_gicv5_common.h
+++ b/include/hw/intc/arm_gicv5_common.h
@@ -93,6 +93,7 @@ struct GICv5Common {
uint32_t irs_vmt_cfgr[NUM_GICV5_DOMAINS];
uint64_t irs_vmap_l2_vmtr[NUM_GICV5_DOMAINS];
uint64_t irs_vmap_vmr[NUM_GICV5_DOMAINS];
+ uint64_t irs_vmap_vistr[NUM_GICV5_DOMAINS];
/*
* Pointer to an array of state information for the SPIs. Array
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index 2eb85d0e504..37114b30620 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -1432,6 +1432,29 @@ static void irs_clean_vm_cache(GICv5Common *cs, GICv5VMTConfig *cfg)
g_hash_table_foreach_remove(cfg->vm_cache, irs_clean_vm_cache_entry, &ud);
}
+static void invalidate_vlpi_ist_config(GICv5Common *cs, GICv5Domain domain,
+ VMTE *vmte)
+{
+ /*
+ * Make the VLPI IST invalid. The caller must also update the
+ * VALID bit in the L2 VMTE in guest memory.
+ * We must write any cached VLPI IST info back to guest memory,
+ */
+ irs_clean_lpi_cache(cs, &vmte->lpi_ist);
+ vmte->lpi_ist.valid = false;
+}
+
+static void invalidate_vspi_ist_config(GICv5Common *cs, GICv5Domain domain,
+ VMTE *vmte)
+{
+ /*
+ * Make the VSPI IST invalid. The caller must also update the
+ * VALID bit in the L2 VMTE in guest memory.
+ */
+ irs_clean_lpi_cache(cs, &vmte->spi_ist);
+ vmte->spi_ist.valid = false;
+}
+
static void irs_vmt_baser_write(GICv5 *s, GICv5Domain domain, uint64_t value)
{
GICv5Common *cs = ARM_GICV5_COMMON(s);
@@ -1667,6 +1690,101 @@ txfail:
"physical address 0x" HWADDR_FMT_plx "\n", vmid, l1_addr);
}
+static void irs_vmap_vistr_write(GICv5 *s, GICv5Domain domain, uint64_t value)
+{
+ GICv5Common *cs = ARM_GICV5_COMMON(s);
+ GICv5VMTConfig *cfg = &s->vmt_config[domain];
+ uint32_t vmid = FIELD_EX64(value, IRS_VMAP_VISTR, VM_ID);
+ bool m = FIELD_EX64(value, IRS_VMAP_VISTR, M);
+ /* U = 0 for "make invalid", 1 for "make valid" */
+ bool valid = !FIELD_EX64(value, IRS_VMAP_VISTR, U);
+ GICv5IntType type = FIELD_EX64(value, IRS_VMAP_VISTR, TYPE);
+ uint64_t l2_vmte[L2_VMTE_WORDS];
+ MemTxResult res;
+ VMTE *vmte;
+ bool was_valid;
+
+ if (!gicv5_domain_has_virt(cs, domain) || !cfg->valid) {
+ /* Whole register RAZ/WI if no virt or no VM table */
+ return;
+ }
+
+ /* M bit is WO/UNKNOWN; write the other fields */
+ cs->irs_vmap_vistr[domain] = value & ~R_IRS_VMAP_VISTR_M_MASK;
+
+ /*
+ * M = 0 and bad VMID must be ignored; invalid TYPE is
+ * UNPREDICTABLE, and we choose to ignore
+ */
+ if (!m || vmid >= (1 << cfg->vm_id_bits) ||
+ (type != GICV5_LPI && type != GICV5_SPI)) {
+ return;
+ }
+
+ trace_gicv5_irs_vmap_vistr_write(domain_name[domain], vmid,
+ inttype_name(type),
+ valid ? "valid" : "invalid");
+
+ vmte = g_hash_table_lookup(cfg->vm_cache, GINT_TO_POINTER(vmid));
+ if (!vmte) {
+ /* VM is not valid */
+ return;
+ }
+
+ was_valid = type == GICV5_LPI ? vmte->lpi_ist.valid : vmte->spi_ist.valid;
+ /* Ignore request to make IST valid/invalid when it already is so */
+ if (valid == was_valid) {
+ return;
+ }
+
+ if (!read_first_vmte_word(cs, cfg, vmte->vmte_addr, l2_vmte) ||
+ !read_other_vmte_words(cs, cfg, vmte->vmte_addr, l2_vmte)) {
+ goto txfail;
+ }
+
+ switch (type) {
+ case GICV5_LPI:
+ l2_vmte[2] = FIELD_DP64(l2_vmte[2], L2_VMTE_2, LPI_IST_VALID, valid);
+ address_space_stq_le(&cs->dma_as,
+ vmte->vmte_addr + sizeof(uint64_t) * 2,
+ l2_vmte[2], cfg->txattrs, &res);
+ if (res != MEMTX_OK) {
+ goto txfail;
+ }
+
+ if (valid) {
+ initialize_vlpi_ist_config(cs, domain, vmte, l2_vmte);
+ } else {
+ invalidate_vlpi_ist_config(cs, domain, vmte);
+ }
+ break;
+ case GICV5_SPI:
+ l2_vmte[3] = FIELD_DP64(l2_vmte[3], L2_VMTE_3, SPI_IST_VALID, valid);
+ address_space_stq_le(&cs->dma_as,
+ vmte->vmte_addr + sizeof(uint64_t) * 3,
+ l2_vmte[3], cfg->txattrs, &res);
+ if (res != MEMTX_OK) {
+ goto txfail;
+ }
+
+ if (valid) {
+ initialize_vspi_ist_config(cs, domain, vmte, l2_vmte);
+ } else {
+ invalidate_vspi_ist_config(cs, domain, vmte);
+ }
+ break;
+ default:
+ g_assert_not_reached();
+ }
+ return;
+
+txfail:
+ /* Reportable with EC=0x0 if sw error reporting implemented */
+ qemu_log_mask(LOG_GUEST_ERROR, "L2 VMTE update failed for VMID 0x%x at "
+ "physical address 0x" HWADDR_FMT_plx "\n",
+ vmid, vmte->vmte_addr);
+}
+
static void spi_sample(GICv5SPIState *spi)
{
/*
@@ -1838,6 +1956,22 @@ static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset,
*data = 0;
}
return true;
+ case A_IRS_VMAP_VISTR:
+ if (gicv5_domain_has_virt(cs, domain) && s->vmt_config[domain].valid) {
+ *data = extract64(cs->irs_vmap_vistr[domain], 0, 32);
+ } else {
+ /* RAZ/WI if no virt or no VM table */
+ *data = 0;
+ }
+ return true;
+ case A_IRS_VMAP_VISTR + 4:
+ if (gicv5_domain_has_virt(cs, domain) && s->vmt_config[domain].valid) {
+ *data = extract64(cs->irs_vmap_vistr[domain], 32, 32);
+ } else {
+ /* RAZ/WI if no virt or no VM table */
+ *data = 0;
+ }
+ return true;
case A_IRS_SPI_STATUSR:
/*
* QEMU writes to IRS_SPI_{CFGR,DOMAINR,SELR,VMR} take effect
@@ -1978,6 +2112,15 @@ static bool config_writel(GICv5 *s, GICv5Domain domain, hwaddr offset,
irs_vmap_vmr_write(s, domain,
deposit64(cs->irs_vmap_vmr[domain], 32, 32, data));
return true;
+ case A_IRS_VMAP_VISTR:
+ irs_vmap_vistr_write(s, domain,
+ deposit64(cs->irs_vmap_vistr[domain], 0, 32, data));
+ return true;
+ case A_IRS_VMAP_VISTR + 4:
+ irs_vmap_vistr_write(s, domain,
+ deposit64(cs->irs_vmap_vistr[domain],
+ 32, 32, data));
+ return true;
case A_IRS_SPI_SELR:
cs->irs_spi_selr[domain] = data;
return true;
@@ -2086,6 +2229,14 @@ static bool config_readll(GICv5 *s, GICv5Domain domain, hwaddr offset,
*data = 0;
}
return true;
+ case A_IRS_VMAP_VISTR:
+ if (gicv5_domain_has_virt(cs, domain) && s->vmt_config[domain].valid) {
+ *data = cs->irs_vmap_vistr[domain];
+ } else {
+ /* RAZ/WI if no virt or no VM table */
+ *data = 0;
+ }
+ return true;
}
return false;
@@ -2107,6 +2258,9 @@ static bool config_writell(GICv5 *s, GICv5Domain domain, hwaddr offset,
case A_IRS_VMAP_VMR:
irs_vmap_vmr_write(s, domain, data);
return true;
+ case A_IRS_VMAP_VISTR:
+ irs_vmap_vistr_write(s, domain, data);
+ return true;
}
return false;
diff --git a/hw/intc/arm_gicv5_common.c b/hw/intc/arm_gicv5_common.c
index 19338ad5b9c..181171e000b 100644
--- a/hw/intc/arm_gicv5_common.c
+++ b/hw/intc/arm_gicv5_common.c
@@ -110,6 +110,7 @@ static void gicv5_common_reset_hold(Object *obj, ResetType type)
memset(cs->irs_vmt_cfgr, 0, sizeof(cs->irs_vmt_cfgr));
memset(cs->irs_vmap_l2_vmtr, 0, sizeof(cs->irs_vmap_l2_vmtr));
memset(cs->irs_vmap_vmr, 0, sizeof(cs->irs_vmap_vmr));
+ memset(cs->irs_vmap_vistr, 0, sizeof(cs->irs_vmap_vistr));
}
}
diff --git a/hw/intc/trace-events b/hw/intc/trace-events
index 623953b8ddf..e8b4a5108e5 100644
--- a/hw/intc/trace-events
+++ b/hw/intc/trace-events
@@ -250,6 +250,7 @@ gicv5_vmt_valid(const char *domain, uint64_t base, uint8_t vm_id_bits, bool stru
gicv5_vmt_invalid(const char *domain) "GICv5 IRS %s VM table no longer valid"
gicv5_vmap_l2_vmtr(const char *domain, uint32_t vmid) "GICv5 IRS %s VM ID %u now valid"
gicv5_cache_vmte(const char *domain, uint32_t vmid) "GICv5 IRS %s VM ID %u valid and cached"
+gicv5_irs_vmap_vistr_write(const char *domain, uint32_t vmid, const char *type, const char *what) "GICv5 IRS %s VM ID %u %s IST now %s"
# arm_gicv5_common.c
gicv5_common_realize(uint32_t irsid, uint32_t num_cpus, uint32_t spi_base, uint32_t spi_irs_range, uint32_t spi_range) "GICv5 IRS realized: IRS ID %u, %u CPUs, SPI base %u, SPI IRS range %u, SPI range %u"
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 52/77] hw/intc/arm_gicv5: Factor out "make an L2 IST valid" function
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (50 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 51/77] hw/intc/arm_gicv5: Implement IRS_VMAP_VISTR Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 53/77] hw/intc/arm_gicv5: Implement IRS_VMAP_L2_VISTR Peter Maydell
` (24 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
irs_map_l2_istr_write() makes the L2 IST for a specified interrupt
valid by finding the L1 ISTE and setting its valid bit. For
virtualization, we want to do something similar for the ISTs
used for virtual LPIs and SPIs. Factor out the "do the work"
part of the function from the specifics of the IRS_MAP_L2_ISTR
register.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/intc/arm_gicv5.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index 37114b30620..2b0ab78acff 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -1090,11 +1090,8 @@ static void initialize_ist_config(GICv5Common *cs, GICv5Domain domain,
cfg->valid = true;
}
-static void irs_map_l2_istr_write(GICv5 *s, GICv5Domain domain, uint64_t value)
+static void map_l2_istr(GICv5Common *cs, GICv5ISTConfig *cfg, uint32_t intid)
{
- GICv5Common *cs = ARM_GICV5_COMMON(s);
- GICv5ISTConfig *cfg = &s->phys_lpi_config[domain];
- uint32_t intid = FIELD_EX32(value, IRS_MAP_L2_ISTR, ID);
hwaddr l1_addr;
uint64_t l1_iste;
MemTxResult res;
@@ -1132,6 +1129,15 @@ txfail:
"physical address 0x" HWADDR_FMT_plx "\n", intid, l1_addr);
}
+static void irs_map_l2_istr_write(GICv5 *s, GICv5Domain domain, uint64_t value)
+{
+ GICv5Common *cs = ARM_GICV5_COMMON(s);
+ GICv5ISTConfig *cfg = &s->phys_lpi_config[domain];
+ uint32_t intid = FIELD_EX32(value, IRS_MAP_L2_ISTR, ID);
+
+ map_l2_istr(cs, cfg, intid);
+}
+
bool gicv5_set_resident(GICv5Common *cs, GICv5Domain domain, bool valid,
uint32_t vpeid, bool db, uint8_t dbpm, uint32_t vmid,
uint32_t cpuidx)
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 53/77] hw/intc/arm_gicv5: Implement IRS_VMAP_L2_VISTR
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (51 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 52/77] hw/intc/arm_gicv5: Factor out "make an L2 IST valid" function Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 54/77] hw/intc/arm_gicv5: Cache VPE table information Peter Maydell
` (23 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
The IRS_VMAP_L2_VISTR allows the guest to make an L2 entry in the
VM's VLPI or VSPI IST valid; it is the equivalent of what
IRS_MAP_L2_ISTR does for the physical LPI IST.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
include/hw/intc/arm_gicv5_common.h | 1 +
hw/intc/arm_gicv5.c | 77 ++++++++++++++++++++++++++++++
hw/intc/arm_gicv5_common.c | 1 +
3 files changed, 79 insertions(+)
diff --git a/include/hw/intc/arm_gicv5_common.h b/include/hw/intc/arm_gicv5_common.h
index 19e13693de9..8103f14ba44 100644
--- a/include/hw/intc/arm_gicv5_common.h
+++ b/include/hw/intc/arm_gicv5_common.h
@@ -94,6 +94,7 @@ struct GICv5Common {
uint64_t irs_vmap_l2_vmtr[NUM_GICV5_DOMAINS];
uint64_t irs_vmap_vmr[NUM_GICV5_DOMAINS];
uint64_t irs_vmap_vistr[NUM_GICV5_DOMAINS];
+ uint64_t irs_vmap_l2_vistr[NUM_GICV5_DOMAINS];
/*
* Pointer to an array of state information for the SPIs. Array
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index 2b0ab78acff..c25d4a8b542 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -1791,6 +1791,46 @@ txfail:
vmid, vmte->vmte_addr);
}
+static void irs_vmap_l2_vistr_write(GICv5 *s, GICv5Domain domain,
+ uint64_t value)
+{
+ GICv5Common *cs = ARM_GICV5_COMMON(s);
+ GICv5VMTConfig *cfg = &s->vmt_config[domain];
+ uint32_t vmid = FIELD_EX64(value, IRS_VMAP_L2_VISTR, VM_ID);
+ bool m = FIELD_EX64(value, IRS_VMAP_L2_VISTR, M);
+ uint32_t intid = FIELD_EX64(value, IRS_VMAP_L2_VISTR, ID);
+ GICv5IntType type = FIELD_EX64(value, IRS_VMAP_VISTR, TYPE);
+ VMTE *vmte;
+ GICv5ISTConfig *vist;
+
+ if (!gicv5_domain_has_virt(cs, domain) || !cfg->valid) {
+ /* Whole register RAZ/WI if no virt or no VM table */
+ return;
+ }
+
+ /* M bit is WO/UNKNOWN; write the other fields */
+ cs->irs_vmap_l2_vistr[domain] = value & ~R_IRS_VMAP_L2_VISTR_M_MASK;
+
+ /*
+ * M = 0 and bad VMID must be ignored; invalid TYPE is
+ * UNPREDICTABLE, and we choose to ignore
+ */
+ if (!m || vmid >= (1 << cfg->vm_id_bits) ||
+ (type != GICV5_LPI && type != GICV5_SPI)) {
+ return;
+ }
+
+ vmte = g_hash_table_lookup(cfg->vm_cache, GINT_TO_POINTER(vmid));
+ if (!vmte) {
+ /* VM is not valid */
+ return;
+ }
+
+ vist = type == GICV5_LPI ? &vmte->lpi_ist : &vmte->spi_ist;
+
+ map_l2_istr(cs, vist, intid);
+}
+
static void spi_sample(GICv5SPIState *spi)
{
/*
@@ -1978,6 +2018,22 @@ static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset,
*data = 0;
}
return true;
+ case A_IRS_VMAP_L2_VISTR:
+ if (gicv5_domain_has_virt(cs, domain) && s->vmt_config[domain].valid) {
+ *data = extract64(cs->irs_vmap_l2_vistr[domain], 0, 32);
+ } else {
+ /* RAZ/WI if no virt or no VM table */
+ *data = 0;
+ }
+ return true;
+ case A_IRS_VMAP_L2_VISTR + 4:
+ if (gicv5_domain_has_virt(cs, domain) && s->vmt_config[domain].valid) {
+ *data = extract64(cs->irs_vmap_l2_vistr[domain], 32, 32);
+ } else {
+ /* RAZ/WI if no virt or no VM table */
+ *data = 0;
+ }
+ return true;
case A_IRS_SPI_STATUSR:
/*
* QEMU writes to IRS_SPI_{CFGR,DOMAINR,SELR,VMR} take effect
@@ -2127,6 +2183,16 @@ static bool config_writel(GICv5 *s, GICv5Domain domain, hwaddr offset,
deposit64(cs->irs_vmap_vistr[domain],
32, 32, data));
return true;
+ case A_IRS_VMAP_L2_VISTR:
+ irs_vmap_l2_vistr_write(s, domain,
+ deposit64(cs->irs_vmap_l2_vistr[domain],
+ 0, 32, data));
+ return true;
+ case A_IRS_VMAP_L2_VISTR + 4:
+ irs_vmap_l2_vistr_write(s, domain,
+ deposit64(cs->irs_vmap_l2_vistr[domain],
+ 32, 32, data));
+ return true;
case A_IRS_SPI_SELR:
cs->irs_spi_selr[domain] = data;
return true;
@@ -2243,6 +2309,14 @@ static bool config_readll(GICv5 *s, GICv5Domain domain, hwaddr offset,
*data = 0;
}
return true;
+ case A_IRS_VMAP_L2_VISTR:
+ if (gicv5_domain_has_virt(cs, domain) && s->vmt_config[domain].valid) {
+ *data = cs->irs_vmap_l2_vistr[domain];
+ } else {
+ /* RAZ/WI if no virt or no VM table */
+ *data = 0;
+ }
+ return true;
}
return false;
@@ -2267,6 +2341,9 @@ static bool config_writell(GICv5 *s, GICv5Domain domain, hwaddr offset,
case A_IRS_VMAP_VISTR:
irs_vmap_vistr_write(s, domain, data);
return true;
+ case A_IRS_VMAP_L2_VISTR:
+ irs_vmap_l2_vistr_write(s, domain, data);
+ return true;
}
return false;
diff --git a/hw/intc/arm_gicv5_common.c b/hw/intc/arm_gicv5_common.c
index 181171e000b..b52dba3d3b4 100644
--- a/hw/intc/arm_gicv5_common.c
+++ b/hw/intc/arm_gicv5_common.c
@@ -111,6 +111,7 @@ static void gicv5_common_reset_hold(Object *obj, ResetType type)
memset(cs->irs_vmap_l2_vmtr, 0, sizeof(cs->irs_vmap_l2_vmtr));
memset(cs->irs_vmap_vmr, 0, sizeof(cs->irs_vmap_vmr));
memset(cs->irs_vmap_vistr, 0, sizeof(cs->irs_vmap_vistr));
+ memset(cs->irs_vmap_l2_vistr, 0, sizeof(cs->irs_vmap_l2_vistr));
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 54/77] hw/intc/arm_gicv5: Cache VPE table information
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (52 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 53/77] hw/intc/arm_gicv5: Implement IRS_VMAP_L2_VISTR Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 55/77] hw/intc/arm_gicv5: Implement IRS_VMAP_VPER Peter Maydell
` (22 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Each VM has a VPE table which is a single linear table with an entry
for each possible vCPU in the VM. Each VPE has a 'valid' bit and a
pointer to a VPE descriptor which has IMPDEF contents. When the VM
is made valid, the table can contain a mix of already-valid and
not-yet-valid VPEs.
Cache this information. Since the GICv5 architecture requires a
simple linear table here, we can assume that the guest is unlikely to
populate it sparsely, so we use a simple array rather than a
hashtable.
We will gradually expand the information we put into our VPE struct,
but for now we just have a boolean tracking whether the VPE is valid
or not, the guest address of the VPED, and a back-pointer to the
VMTE.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
include/hw/intc/arm_gicv5_regs.h | 3 ++
hw/intc/arm_gicv5.c | 62 ++++++++++++++++++++++++++++++--
hw/intc/trace-events | 1 +
3 files changed, 64 insertions(+), 2 deletions(-)
diff --git a/include/hw/intc/arm_gicv5_regs.h b/include/hw/intc/arm_gicv5_regs.h
index a08aff61a20..d67aef3c118 100644
--- a/include/hw/intc/arm_gicv5_regs.h
+++ b/include/hw/intc/arm_gicv5_regs.h
@@ -306,6 +306,9 @@ FIELD(L2_VMTE_3, SPI_ID_BITS, 59, 5)
#define VMT_L2_IDX_BITS 7
#define VMT_L2_TABLE_SIZE 4096
+FIELD(VPETE, VALID, 0, 1)
+FIELD(VPETE, VPED_ADDR, 3, 53)
+
/*
* Format used for gicv5_request_config() return value, which matches
* the ICC_ICSR_EL1 bit layout.
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index c25d4a8b542..b813c5cb71a 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -23,10 +23,20 @@
OBJECT_DEFINE_TYPE(GICv5, gicv5, ARM_GICV5, ARM_GICV5_COMMON)
+typedef struct VMTE VMTE;
+
+/* Cached per-VPE information, from VPE and VPE descriptor */
+typedef struct VPE {
+ VMTE *vmte;
+ hwaddr vped_addr;
+ bool valid;
+} VPE;
+
/* In the GICv5VMTConfig::vm_cache this is how we store VMTE info */
-typedef struct VMTE {
+struct VMTE {
GICv5ISTConfig lpi_ist;
GICv5ISTConfig spi_ist;
+ VPE *vpet;
/* Address of the in-memory L2_VMTE for this VMTE */
hwaddr vmte_addr;
hwaddr vpet_addr;
@@ -35,7 +45,7 @@ typedef struct VMTE {
GICv5Domain domain;
/* We don't cache the VMD_ADDR as we don't use VMDs */
/* We don't cache VALID: the existence of this struct implies VALID=1 */
-} VMTE;
+};
static const char *domain_name[] = {
[GICV5_ID_S] = "Secure",
@@ -102,6 +112,8 @@ static void VMTE_free(void *data)
g_hash_table_destroy(vmte->spi_ist.lpi_cache);
}
+ g_free(vmte->vpet);
+
g_free(vmte);
}
@@ -1213,6 +1225,51 @@ static void initialize_vspi_ist_config(GICv5Common *cs, GICv5Domain domain,
id_bits, istsz, l2sz, structure);
}
+static void init_vpe_from_vpete(VPE *vpe, VMTE *vmte, uint64_t vpete)
+{
+ /* Given the value of the in-memory VPETE, set up one VPE struct */
+ vpe->vmte = vmte;
+ vpe->valid = FIELD_EX64(vpete, VPETE, VALID);
+ if (vpe->valid) {
+ vpe->vped_addr = vpete & R_VPETE_VPED_ADDR_MASK;
+ vpe->vped_addr &= ~MAKE_64BIT_MASK(0, QEMU_GICV5_VPED_SZ);
+ }
+}
+
+static void initialize_vpet(GICv5Common *cs, GICv5Domain domain,
+ GICv5VMTConfig *cfg, VMTE *vmte)
+{
+ /*
+ * Allocate our cached VPE table, and populate it from guest memory.
+ * Note that (per R_DLKTX) the VPE descriptor is supposed to be all
+ * zeroes at this point, and behaviour is UNPREDICTABLE if it is not,
+ * so we do not need to read the descriptor here. In any case QEMU
+ * doesn't use the VPE descriptors.
+ */
+ int num_vpes = 1 << vmte->vpe_id_bits;
+ hwaddr vpete_addr = vmte->vpet_addr;
+
+ vmte->vpet = g_new0(VPE, num_vpes);
+
+ for (int i = 0; i < num_vpes; i++, vpete_addr += 8) {
+ MemTxResult res;
+ uint64_t vpete;
+
+ vpete = address_space_ldq_le(&cs->dma_as, vpete_addr,
+ cfg->txattrs, &res);
+ if (res != MEMTX_OK) {
+ qemu_log_mask(LOG_GUEST_ERROR, "VPET lookup failed for VPE 0x%x"
+ " at physical address 0x" HWADDR_FMT_plx "\n",
+ i, vpete_addr);
+ return;
+ }
+
+ init_vpe_from_vpete(&vmte->vpet[i], vmte, vpete);
+ trace_gicv5_initialize_vpet(domain_name[vmte->domain], vmte->vmid,
+ i, vmte->vpet[i].valid);
+ }
+}
+
static void cache_vmte(GICv5Common *cs, GICv5Domain domain,
GICv5VMTConfig *cfg,
uint32_t vmid, uint64_t *l2_vmte, hwaddr l2_addr)
@@ -1237,6 +1294,7 @@ static void cache_vmte(GICv5Common *cs, GICv5Domain domain,
* it has 2^vpe_id_bits entries of 2^3 == 8 bytes each
*/
vmte->vpet_addr &= ~MAKE_64BIT_MASK(0, vmte->vpe_id_bits + 3);
+ initialize_vpet(cs, domain, cfg, vmte);
/*
* If the VALID bits are set for the LPI and SPI ISTs, we can read
diff --git a/hw/intc/trace-events b/hw/intc/trace-events
index e8b4a5108e5..b08e5614370 100644
--- a/hw/intc/trace-events
+++ b/hw/intc/trace-events
@@ -251,6 +251,7 @@ gicv5_vmt_invalid(const char *domain) "GICv5 IRS %s VM table no longer valid"
gicv5_vmap_l2_vmtr(const char *domain, uint32_t vmid) "GICv5 IRS %s VM ID %u now valid"
gicv5_cache_vmte(const char *domain, uint32_t vmid) "GICv5 IRS %s VM ID %u valid and cached"
gicv5_irs_vmap_vistr_write(const char *domain, uint32_t vmid, const char *type, const char *what) "GICv5 IRS %s VM ID %u %s IST now %s"
+gicv5_initialize_vpet(const char *domain, uint32_t vmid, uint32_t vpeid, bool valid) "GICv5 IRS %s VM ID %u VPE %u starts as valid %d"
# arm_gicv5_common.c
gicv5_common_realize(uint32_t irsid, uint32_t num_cpus, uint32_t spi_base, uint32_t spi_irs_range, uint32_t spi_range) "GICv5 IRS realized: IRS ID %u, %u CPUs, SPI base %u, SPI IRS range %u, SPI range %u"
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 55/77] hw/intc/arm_gicv5: Implement IRS_VMAP_VPER
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (53 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 54/77] hw/intc/arm_gicv5: Cache VPE table information Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 56/77] hw/intc/arm_gicv5: Implement IRS_VPE_SELR and IRS_VPE_STATUSR Peter Maydell
` (21 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
The IRS_VMAP_VPER allows software to mark a VPE as valid if
it was not originally valid when the VM was created. For us
this means updating the valid bit in our cached VPE struct
and in the VPE table in guest memory.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
include/hw/intc/arm_gicv5_common.h | 1 +
hw/intc/arm_gicv5.c | 94 ++++++++++++++++++++++++++++++
hw/intc/arm_gicv5_common.c | 1 +
hw/intc/trace-events | 1 +
4 files changed, 97 insertions(+)
diff --git a/include/hw/intc/arm_gicv5_common.h b/include/hw/intc/arm_gicv5_common.h
index 8103f14ba44..c8574f66a63 100644
--- a/include/hw/intc/arm_gicv5_common.h
+++ b/include/hw/intc/arm_gicv5_common.h
@@ -95,6 +95,7 @@ struct GICv5Common {
uint64_t irs_vmap_vmr[NUM_GICV5_DOMAINS];
uint64_t irs_vmap_vistr[NUM_GICV5_DOMAINS];
uint64_t irs_vmap_l2_vistr[NUM_GICV5_DOMAINS];
+ uint64_t irs_vmap_vper[NUM_GICV5_DOMAINS];
/*
* Pointer to an array of state information for the SPIs. Array
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index b813c5cb71a..19d8ce815d9 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -1889,6 +1889,65 @@ static void irs_vmap_l2_vistr_write(GICv5 *s, GICv5Domain domain,
map_l2_istr(cs, vist, intid);
}
+static void irs_vmap_vper_write(GICv5 *s, GICv5Domain domain, uint64_t value)
+{
+ GICv5Common *cs = ARM_GICV5_COMMON(s);
+ GICv5VMTConfig *cfg = &s->vmt_config[domain];
+ bool m = FIELD_EX64(value, IRS_VMAP_VPER, M);
+ uint32_t vmid = FIELD_EX64(value, IRS_VMAP_VPER, VM_ID);
+ uint32_t vpeid = FIELD_EX64(value, IRS_VMAP_VPER, VPE_ID);
+ VMTE *vmte;
+ hwaddr vpete_addr;
+ MemTxResult res;
+ uint64_t vpete;
+
+ if (!gicv5_domain_has_virt(cs, domain) || !cfg->valid) {
+ /* Whole register RAZ/WI if no virt or no VM table */
+ return;
+ }
+
+ /* M bit is WO/UNKNOWN; write the other fields */
+ cs->irs_vmap_vper[domain] = value & ~R_IRS_VMAP_VPER_M_MASK;
+
+ /* M = 0 and bad VMID must be ignored */
+ if (!m || vmid >= (1 << cfg->vm_id_bits)) {
+ return;
+ }
+
+ vmte = g_hash_table_lookup(cfg->vm_cache, GINT_TO_POINTER(vmid));
+ if (!vmte) {
+ /* VM is not valid */
+ return;
+ }
+
+ if (vpeid >= (1 << vmte->vpe_id_bits) || vmte->vpet[vpeid].valid) {
+ /* Invalid VPE ID, VPE already valid */
+ return;
+ }
+
+ vpete_addr = vmte->vpet_addr + vpeid * 8;
+ vpete = address_space_ldq_le(&cs->dma_as, vpete_addr, cfg->txattrs, &res);
+ if (res != MEMTX_OK) {
+ goto txfail;
+ }
+ vpete = FIELD_DP64(vpete, VPETE, VALID, 1);
+ address_space_stq_le(&cs->dma_as, vpete_addr, vpete, cfg->txattrs, &res);
+ if (res != MEMTX_OK) {
+ goto txfail;
+ }
+
+ init_vpe_from_vpete(&vmte->vpet[vpeid], vmte, vpete);
+ trace_gicv5_irs_vmap_vper_write(domain_name[domain], vmte->vmid, vpeid);
+
+ return;
+
+txfail:
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "VPETE update failed for VMID 0x%x VPEID 0x%x at "
+ "physical address 0x" HWADDR_FMT_plx "\n",
+ vmid, vpeid, vpete_addr);
+}
+
static void spi_sample(GICv5SPIState *spi)
{
/*
@@ -2092,6 +2151,22 @@ static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset,
*data = 0;
}
return true;
+ case A_IRS_VMAP_VPER:
+ if (gicv5_domain_has_virt(cs, domain) && s->vmt_config[domain].valid) {
+ *data = extract64(cs->irs_vmap_vper[domain], 0, 32);
+ } else {
+ /* RAZ/WI if no virt or no VM table */
+ *data = 0;
+ }
+ return true;
+ case A_IRS_VMAP_VPER + 4:
+ if (gicv5_domain_has_virt(cs, domain) && s->vmt_config[domain].valid) {
+ *data = extract64(cs->irs_vmap_vper[domain], 32, 32);
+ } else {
+ /* RAZ/WI if no virt or no VM table */
+ *data = 0;
+ }
+ return true;
case A_IRS_SPI_STATUSR:
/*
* QEMU writes to IRS_SPI_{CFGR,DOMAINR,SELR,VMR} take effect
@@ -2251,6 +2326,14 @@ static bool config_writel(GICv5 *s, GICv5Domain domain, hwaddr offset,
deposit64(cs->irs_vmap_l2_vistr[domain],
32, 32, data));
return true;
+ case A_IRS_VMAP_VPER:
+ irs_vmap_vper_write(s, domain,
+ deposit64(cs->irs_vmap_vper[domain], 0, 32, data));
+ return true;
+ case A_IRS_VMAP_VPER + 4:
+ irs_vmap_vper_write(s, domain,
+ deposit64(cs->irs_vmap_vper[domain], 32, 32, data));
+ return true;
case A_IRS_SPI_SELR:
cs->irs_spi_selr[domain] = data;
return true;
@@ -2375,6 +2458,14 @@ static bool config_readll(GICv5 *s, GICv5Domain domain, hwaddr offset,
*data = 0;
}
return true;
+ case A_IRS_VMAP_VPER:
+ if (gicv5_domain_has_virt(cs, domain) && s->vmt_config[domain].valid) {
+ *data = cs->irs_vmap_vper[domain];
+ } else {
+ /* RAZ/WI if no virt or no VM table */
+ *data = 0;
+ }
+ return true;
}
return false;
@@ -2402,6 +2493,9 @@ static bool config_writell(GICv5 *s, GICv5Domain domain, hwaddr offset,
case A_IRS_VMAP_L2_VISTR:
irs_vmap_l2_vistr_write(s, domain, data);
return true;
+ case A_IRS_VMAP_VPER:
+ irs_vmap_vper_write(s, domain, data);
+ return true;
}
return false;
diff --git a/hw/intc/arm_gicv5_common.c b/hw/intc/arm_gicv5_common.c
index b52dba3d3b4..6e0e2295fde 100644
--- a/hw/intc/arm_gicv5_common.c
+++ b/hw/intc/arm_gicv5_common.c
@@ -112,6 +112,7 @@ static void gicv5_common_reset_hold(Object *obj, ResetType type)
memset(cs->irs_vmap_vmr, 0, sizeof(cs->irs_vmap_vmr));
memset(cs->irs_vmap_vistr, 0, sizeof(cs->irs_vmap_vistr));
memset(cs->irs_vmap_l2_vistr, 0, sizeof(cs->irs_vmap_l2_vistr));
+ memset(cs->irs_vmap_vper, 0, sizeof(cs->irs_vmap_vper));
}
}
diff --git a/hw/intc/trace-events b/hw/intc/trace-events
index b08e5614370..cc242125d6a 100644
--- a/hw/intc/trace-events
+++ b/hw/intc/trace-events
@@ -252,6 +252,7 @@ gicv5_vmap_l2_vmtr(const char *domain, uint32_t vmid) "GICv5 IRS %s VM ID %u now
gicv5_cache_vmte(const char *domain, uint32_t vmid) "GICv5 IRS %s VM ID %u valid and cached"
gicv5_irs_vmap_vistr_write(const char *domain, uint32_t vmid, const char *type, const char *what) "GICv5 IRS %s VM ID %u %s IST now %s"
gicv5_initialize_vpet(const char *domain, uint32_t vmid, uint32_t vpeid, bool valid) "GICv5 IRS %s VM ID %u VPE %u starts as valid %d"
+gicv5_irs_vmap_vper_write(const char *domain, uint32_t vmid, uint32_t vpeid) "GICv5 IRS %s VM ID %u VPE %u now made valid"
# arm_gicv5_common.c
gicv5_common_realize(uint32_t irsid, uint32_t num_cpus, uint32_t spi_base, uint32_t spi_irs_range, uint32_t spi_range) "GICv5 IRS realized: IRS ID %u, %u CPUs, SPI base %u, SPI IRS range %u, SPI range %u"
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 56/77] hw/intc/arm_gicv5: Implement IRS_VPE_SELR and IRS_VPE_STATUSR
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (54 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 55/77] hw/intc/arm_gicv5: Implement IRS_VMAP_VPER Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 57/77] hw/intc/arm_gicv5: Implement IRS_VPE_DBR Peter Maydell
` (20 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
The IRS provides a set of registers to allow software to read and
write the configuration of a VPE. IRS_VPE_SELR selects the VPE to
operate on, IRS_VPE_STATUSR indicates whether that selection was
successful, and other registers like IRS_VPE_DBR will then provide
access to the config for the selected VPE.
Implement IRS_VPE_SELR and IRS_VPE_STATUSR, for the "select a VPE"
part of this mechanism.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
include/hw/intc/arm_gicv5_common.h | 2 +
hw/intc/arm_gicv5.c | 111 +++++++++++++++++++++++++++++
hw/intc/arm_gicv5_common.c | 6 ++
hw/intc/trace-events | 1 +
4 files changed, 120 insertions(+)
diff --git a/include/hw/intc/arm_gicv5_common.h b/include/hw/intc/arm_gicv5_common.h
index c8574f66a63..5823a7f78a0 100644
--- a/include/hw/intc/arm_gicv5_common.h
+++ b/include/hw/intc/arm_gicv5_common.h
@@ -96,6 +96,8 @@ struct GICv5Common {
uint64_t irs_vmap_vistr[NUM_GICV5_DOMAINS];
uint64_t irs_vmap_l2_vistr[NUM_GICV5_DOMAINS];
uint64_t irs_vmap_vper[NUM_GICV5_DOMAINS];
+ uint64_t irs_vpe_selr[NUM_GICV5_DOMAINS];
+ uint32_t irs_vpe_statusr[NUM_GICV5_DOMAINS];
/*
* Pointer to an array of state information for the SPIs. Array
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index 19d8ce815d9..9efa082cbca 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -117,6 +117,24 @@ static void VMTE_free(void *data)
g_free(vmte);
}
+static VPE *vpe_for_vpeid(VMTE *vmte, uint32_t vpeid)
+{
+ /*
+ * Return the VPE struct for the specified VPEID for this VM, or
+ * NULL if there is no such valid VPE.
+ */
+ VPE *vpe;
+
+ if (!vmte || vpeid >= (1 << vmte->vpe_id_bits)) {
+ return NULL;
+ }
+ vpe = &vmte->vpet[vpeid];
+ if (!vpe->valid) {
+ return NULL;
+ }
+ return vpe;
+}
+
static bool gicv5_domain_has_virt(GICv5Common *cs, GICv5Domain domain)
{
/*
@@ -1948,6 +1966,56 @@ txfail:
vmid, vpeid, vpete_addr);
}
+static VPE *vpe_from_selr(GICv5 *s, GICv5Domain domain)
+{
+ /*
+ * Return the VPE for the VM/VPE indicated by the current value of
+ * IRS_VPE_SELR, or NULL if none.
+ */
+ GICv5Common *cs = ARM_GICV5_COMMON(s);
+ GICv5VMTConfig *cfg = &s->vmt_config[domain];
+ uint32_t vmid, vpeid;
+ VMTE *vmte;
+
+ if (FIELD_EX64(cs->irs_vpe_selr[domain], IRS_VPE_SELR, S) == 0) {
+ return NULL;
+ }
+
+ vmid = FIELD_EX64(cs->irs_vpe_selr[domain], IRS_VPE_SELR, VM_ID);
+ vpeid = FIELD_EX64(cs->irs_vpe_selr[domain], IRS_VPE_SELR, VPE_ID);
+
+ if (!cfg->valid || vmid >= (1 << cfg->vm_id_bits)) {
+ return NULL;
+ }
+
+ vmte = g_hash_table_lookup(cfg->vm_cache, GINT_TO_POINTER(vmid));
+ return vpe_for_vpeid(vmte, vpeid);
+}
+
+static void irs_vpe_selr_write(GICv5 *s, GICv5Domain domain, uint64_t value)
+{
+ GICv5Common *cs = ARM_GICV5_COMMON(s);
+ uint32_t status = R_IRS_VPE_STATUSR_IDLE_MASK;
+ VPE *vpe;
+
+ /* RES0 if we don't have virt */
+ if (!gicv5_domain_has_virt(cs, domain)) {
+ return;
+ }
+
+ cs->irs_vpe_selr[domain] = value;
+
+ vpe = vpe_from_selr(s, domain);
+ if (vpe) {
+ /* We successfully selected a valid VPE */
+ status |= R_IRS_VPE_STATUSR_V_MASK;
+ }
+
+ trace_gicv5_irs_vpe_selr_write(domain_name[domain], value, status);
+
+ cs->irs_vpe_statusr[domain] = status;
+}
+
static void spi_sample(GICv5SPIState *spi)
{
/*
@@ -2167,6 +2235,30 @@ static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset,
*data = 0;
}
return true;
+ case A_IRS_VPE_SELR:
+ if (gicv5_domain_has_virt(cs, domain)) {
+ *data = extract64(cs->irs_vpe_selr[domain], 0, 32);
+ } else {
+ /* RAZ/WI if no virt */
+ *data = 0;
+ }
+ return true;
+ case A_IRS_VPE_SELR + 4:
+ if (gicv5_domain_has_virt(cs, domain)) {
+ *data = extract64(cs->irs_vpe_selr[domain], 32, 32);
+ } else {
+ /* RAZ/WI if no virt */
+ *data = 0;
+ }
+ return true;
+ case A_IRS_VPE_STATUSR:
+ if (gicv5_domain_has_virt(cs, domain)) {
+ *data = cs->irs_vpe_statusr[domain];
+ } else {
+ /* RAZ/WI if no virt */
+ *data = 0;
+ }
+ return true;
case A_IRS_SPI_STATUSR:
/*
* QEMU writes to IRS_SPI_{CFGR,DOMAINR,SELR,VMR} take effect
@@ -2334,6 +2426,14 @@ static bool config_writel(GICv5 *s, GICv5Domain domain, hwaddr offset,
irs_vmap_vper_write(s, domain,
deposit64(cs->irs_vmap_vper[domain], 32, 32, data));
return true;
+ case A_IRS_VPE_SELR:
+ irs_vpe_selr_write(s, domain,
+ deposit64(cs->irs_vpe_selr[domain], 0, 32, data));
+ return true;
+ case A_IRS_VPE_SELR + 4:
+ irs_vpe_selr_write(s, domain,
+ deposit64(cs->irs_vpe_selr[domain], 32, 32, data));
+ return true;
case A_IRS_SPI_SELR:
cs->irs_spi_selr[domain] = data;
return true;
@@ -2466,6 +2566,14 @@ static bool config_readll(GICv5 *s, GICv5Domain domain, hwaddr offset,
*data = 0;
}
return true;
+ case A_IRS_VPE_SELR:
+ if (gicv5_domain_has_virt(cs, domain)) {
+ *data = cs->irs_vpe_selr[domain];
+ } else {
+ /* RAZ/WI if no virt */
+ *data = 0;
+ }
+ return true;
}
return false;
@@ -2496,6 +2604,9 @@ static bool config_writell(GICv5 *s, GICv5Domain domain, hwaddr offset,
case A_IRS_VMAP_VPER:
irs_vmap_vper_write(s, domain, data);
return true;
+ case A_IRS_VPE_SELR:
+ irs_vpe_selr_write(s, domain, data);
+ return true;
}
return false;
diff --git a/hw/intc/arm_gicv5_common.c b/hw/intc/arm_gicv5_common.c
index 6e0e2295fde..553598e3178 100644
--- a/hw/intc/arm_gicv5_common.c
+++ b/hw/intc/arm_gicv5_common.c
@@ -9,6 +9,7 @@
#include "qemu/osdep.h"
#include "hw/intc/arm_gicv5_common.h"
#include "hw/intc/arm_gicv5_stream.h"
+#include "hw/intc/arm_gicv5_regs.h"
#include "hw/core/qdev-properties.h"
#include "qapi/error.h"
#include "trace.h"
@@ -113,6 +114,11 @@ static void gicv5_common_reset_hold(Object *obj, ResetType type)
memset(cs->irs_vmap_vistr, 0, sizeof(cs->irs_vmap_vistr));
memset(cs->irs_vmap_l2_vistr, 0, sizeof(cs->irs_vmap_l2_vistr));
memset(cs->irs_vmap_vper, 0, sizeof(cs->irs_vmap_vper));
+ memset(cs->irs_vpe_selr, 0, sizeof(cs->irs_vpe_selr));
+
+ for (int i = 0; i < NUM_GICV5_DOMAINS; i++) {
+ cs->irs_vpe_statusr[i] = R_IRS_VPE_STATUSR_IDLE_MASK;
+ }
}
}
diff --git a/hw/intc/trace-events b/hw/intc/trace-events
index cc242125d6a..36c952d3c2f 100644
--- a/hw/intc/trace-events
+++ b/hw/intc/trace-events
@@ -253,6 +253,7 @@ gicv5_cache_vmte(const char *domain, uint32_t vmid) "GICv5 IRS %s VM ID %u valid
gicv5_irs_vmap_vistr_write(const char *domain, uint32_t vmid, const char *type, const char *what) "GICv5 IRS %s VM ID %u %s IST now %s"
gicv5_initialize_vpet(const char *domain, uint32_t vmid, uint32_t vpeid, bool valid) "GICv5 IRS %s VM ID %u VPE %u starts as valid %d"
gicv5_irs_vmap_vper_write(const char *domain, uint32_t vmid, uint32_t vpeid) "GICv5 IRS %s VM ID %u VPE %u now made valid"
+gicv5_irs_vpe_selr_write(const char *domain, uint64_t selr, uint32_t status) "GICv5 IRS %s IRS_VPE_SELR written 0x%" PRIx64 " IRS_VPE_STATUSR now 0x%x"
# arm_gicv5_common.c
gicv5_common_realize(uint32_t irsid, uint32_t num_cpus, uint32_t spi_base, uint32_t spi_irs_range, uint32_t spi_range) "GICv5 IRS realized: IRS ID %u, %u CPUs, SPI base %u, SPI IRS range %u, SPI range %u"
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 57/77] hw/intc/arm_gicv5: Implement IRS_VPE_DBR
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (55 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 56/77] hw/intc/arm_gicv5: Implement IRS_VPE_SELR and IRS_VPE_STATUSR Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:10 ` [PATCH v2 58/77] hw/intc/arm_gicv5: Implement IRS_VPE_CR0 Peter Maydell
` (19 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
The IRS_VPE_DBR register provides access to the doorbell config of
the VPE selected with IRS_VPE_SELR. The config is sampled into the
register when SELR is successfully written. Writes to IRS_VPE_DBR
will update the config if the VPE selected by IRS_VPE_SELR is still
valid; if the VPE became invalid between the SELR write and the
CR0/DBR write then IRS_VPE_STATUSR.V is updated to report this.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
include/hw/intc/arm_gicv5_common.h | 1 +
hw/intc/arm_gicv5.c | 105 ++++++++++++++++++++++++++++-
hw/intc/arm_gicv5_common.c | 1 +
hw/intc/trace-events | 2 +
4 files changed, 107 insertions(+), 2 deletions(-)
diff --git a/include/hw/intc/arm_gicv5_common.h b/include/hw/intc/arm_gicv5_common.h
index 5823a7f78a0..d82cc23d10c 100644
--- a/include/hw/intc/arm_gicv5_common.h
+++ b/include/hw/intc/arm_gicv5_common.h
@@ -98,6 +98,7 @@ struct GICv5Common {
uint64_t irs_vmap_vper[NUM_GICV5_DOMAINS];
uint64_t irs_vpe_selr[NUM_GICV5_DOMAINS];
uint32_t irs_vpe_statusr[NUM_GICV5_DOMAINS];
+ uint64_t irs_vpe_dbr[NUM_GICV5_DOMAINS];
/*
* Pointer to an array of state information for the SPIs. Array
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index 9efa082cbca..7c5b8670333 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -29,7 +29,11 @@ typedef struct VMTE VMTE;
typedef struct VPE {
VMTE *vmte;
hwaddr vped_addr;
- bool valid;
+ uint32_t db_intid; /* doorbell interrupt ID */
+ uint8_t dbpm; /* doorbell priority mask */
+ bool valid; /* is the VPE valid? */
+ bool db_valid; /* are doorbell settings valid? */
+ bool db_req; /* is a doorbell requested? */
} VPE;
/* In the GICv5VMTConfig::vm_cache this is how we store VMTE info */
@@ -1251,6 +1255,8 @@ static void init_vpe_from_vpete(VPE *vpe, VMTE *vmte, uint64_t vpete)
if (vpe->valid) {
vpe->vped_addr = vpete & R_VPETE_VPED_ADDR_MASK;
vpe->vped_addr &= ~MAKE_64BIT_MASK(0, QEMU_GICV5_VPED_SZ);
+ /* Doorbell settings always start invalid */
+ vpe->db_valid = false;
}
}
@@ -2007,7 +2013,20 @@ static void irs_vpe_selr_write(GICv5 *s, GICv5Domain domain, uint64_t value)
vpe = vpe_from_selr(s, domain);
if (vpe) {
- /* We successfully selected a valid VPE */
+ /*
+ * We successfully selected a valid VPE. Sample the config
+ * into IRS_VPE_DBR.
+ */
+ uint64_t dbr = 0;
+
+ if (vpe->db_valid) {
+ dbr = FIELD_DP64(dbr, IRS_VPE_DBR, DBV, vpe->db_valid);
+ dbr = FIELD_DP64(dbr, IRS_VPE_DBR, DBPM, vpe->dbpm);
+ dbr = FIELD_DP64(dbr, IRS_VPE_DBR, REQ_DB, vpe->db_req);
+ dbr = FIELD_DP64(dbr, IRS_VPE_DBR, INTID, vpe->db_intid);
+ }
+ cs->irs_vpe_dbr[domain] = dbr;
+
status |= R_IRS_VPE_STATUSR_V_MASK;
}
@@ -2016,6 +2035,53 @@ static void irs_vpe_selr_write(GICv5 *s, GICv5Domain domain, uint64_t value)
cs->irs_vpe_statusr[domain] = status;
}
+static void irs_vpe_dbr_write(GICv5 *s, GICv5Domain domain, uint64_t value)
+{
+ GICv5Common *cs = ARM_GICV5_COMMON(s);
+ VPE *vpe;
+
+ /* RES0 if we don't have virt */
+ if (!gicv5_domain_has_virt(cs, domain)) {
+ return;
+ }
+
+ cs->irs_vpe_dbr[domain] = value;
+
+ if (!FIELD_EX64(cs->irs_vpe_statusr[domain], IRS_VPE_STATUSR, V)) {
+ /* No valid VPE selected via SELR */
+ return;
+ }
+
+ vpe = vpe_from_selr(s, domain);
+ if (!vpe) {
+ /* VPE became invalid since SELR was last written */
+ cs->irs_vpe_statusr[domain] &= ~R_IRS_VPE_STATUSR_V_MASK;
+ return;
+ }
+
+ vpe->db_valid = FIELD_EX64(value, IRS_VPE_DBR, DBV);
+ if (vpe->db_valid) {
+ vpe->dbpm = FIELD_EX64(value, IRS_VPE_DBR, DBPM);
+ vpe->db_intid = FIELD_EX64(value, IRS_VPE_DBR, INTID);
+ vpe->db_req = FIELD_EX64(value, IRS_VPE_DBR, REQ_DB);
+
+ trace_gicv5_irs_vpe_dbr_write(domain_name[domain], vpe->vmte->vmid,
+ FIELD_EX64(cs->irs_vpe_selr[domain],
+ IRS_VPE_SELR, VPE_ID),
+ vpe->dbpm, vpe->db_intid, vpe->db_req);
+
+ /*
+ * TODO: when we implement VPE doorbells, check here whether
+ * this config change means we should now generate a VPE
+ * doorbell event for this VPE.
+ */
+ } else {
+ trace_gicv5_irs_vpe_dbr_write_nv(domain_name[domain], vpe->vmte->vmid,
+ FIELD_EX64(cs->irs_vpe_selr[domain],
+ IRS_VPE_SELR, VPE_ID));
+ }
+}
+
static void spi_sample(GICv5SPIState *spi)
{
/*
@@ -2251,6 +2317,22 @@ static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset,
*data = 0;
}
return true;
+ case A_IRS_VPE_DBR:
+ if (gicv5_domain_has_virt(cs, domain)) {
+ *data = extract64(cs->irs_vpe_dbr[domain], 0, 32);
+ } else {
+ /* RAZ/WI if no virt */
+ *data = 0;
+ }
+ return true;
+ case A_IRS_VPE_DBR + 4:
+ if (gicv5_domain_has_virt(cs, domain)) {
+ *data = extract64(cs->irs_vpe_dbr[domain], 32, 32);
+ } else {
+ /* RAZ/WI if no virt */
+ *data = 0;
+ }
+ return true;
case A_IRS_VPE_STATUSR:
if (gicv5_domain_has_virt(cs, domain)) {
*data = cs->irs_vpe_statusr[domain];
@@ -2434,6 +2516,14 @@ static bool config_writel(GICv5 *s, GICv5Domain domain, hwaddr offset,
irs_vpe_selr_write(s, domain,
deposit64(cs->irs_vpe_selr[domain], 32, 32, data));
return true;
+ case A_IRS_VPE_DBR:
+ irs_vpe_dbr_write(s, domain,
+ deposit64(cs->irs_vpe_dbr[domain], 0, 32, data));
+ return true;
+ case A_IRS_VPE_DBR + 4:
+ irs_vpe_dbr_write(s, domain,
+ deposit64(cs->irs_vpe_dbr[domain], 32, 32, data));
+ return true;
case A_IRS_SPI_SELR:
cs->irs_spi_selr[domain] = data;
return true;
@@ -2574,6 +2664,14 @@ static bool config_readll(GICv5 *s, GICv5Domain domain, hwaddr offset,
*data = 0;
}
return true;
+ case A_IRS_VPE_DBR:
+ if (gicv5_domain_has_virt(cs, domain)) {
+ *data = cs->irs_vpe_dbr[domain];
+ } else {
+ /* RAZ/WI if no virt */
+ *data = 0;
+ }
+ return true;
}
return false;
@@ -2607,6 +2705,9 @@ static bool config_writell(GICv5 *s, GICv5Domain domain, hwaddr offset,
case A_IRS_VPE_SELR:
irs_vpe_selr_write(s, domain, data);
return true;
+ case A_IRS_VPE_DBR:
+ irs_vpe_dbr_write(s, domain, data);
+ return true;
}
return false;
diff --git a/hw/intc/arm_gicv5_common.c b/hw/intc/arm_gicv5_common.c
index 553598e3178..50365c4dfe6 100644
--- a/hw/intc/arm_gicv5_common.c
+++ b/hw/intc/arm_gicv5_common.c
@@ -115,6 +115,7 @@ static void gicv5_common_reset_hold(Object *obj, ResetType type)
memset(cs->irs_vmap_l2_vistr, 0, sizeof(cs->irs_vmap_l2_vistr));
memset(cs->irs_vmap_vper, 0, sizeof(cs->irs_vmap_vper));
memset(cs->irs_vpe_selr, 0, sizeof(cs->irs_vpe_selr));
+ memset(cs->irs_vpe_dbr, 0, sizeof(cs->irs_vpe_dbr));
for (int i = 0; i < NUM_GICV5_DOMAINS; i++) {
cs->irs_vpe_statusr[i] = R_IRS_VPE_STATUSR_IDLE_MASK;
diff --git a/hw/intc/trace-events b/hw/intc/trace-events
index 36c952d3c2f..97a141c9d0d 100644
--- a/hw/intc/trace-events
+++ b/hw/intc/trace-events
@@ -254,6 +254,8 @@ gicv5_irs_vmap_vistr_write(const char *domain, uint32_t vmid, const char *type,
gicv5_initialize_vpet(const char *domain, uint32_t vmid, uint32_t vpeid, bool valid) "GICv5 IRS %s VM ID %u VPE %u starts as valid %d"
gicv5_irs_vmap_vper_write(const char *domain, uint32_t vmid, uint32_t vpeid) "GICv5 IRS %s VM ID %u VPE %u now made valid"
gicv5_irs_vpe_selr_write(const char *domain, uint64_t selr, uint32_t status) "GICv5 IRS %s IRS_VPE_SELR written 0x%" PRIx64 " IRS_VPE_STATUSR now 0x%x"
+gicv5_irs_vpe_dbr_write(const char *domain, uint32_t vmid, uint32_t vpeid, uint8_t dbpm, uint32_t db_intid, bool db_req) "GICv5 IRS %s VM ID %u VPE %u IRS_VPE_DBR doorbell now valid: prio mask %u intid %u requested %d"
+gicv5_irs_vpe_dbr_write_nv(const char *domain, uint32_t vmid, uint32_t vpeid) "GICv5 IRS %s VM ID %u VPE %u IRS_VPE_DBR doorbell info no longer valid"
# arm_gicv5_common.c
gicv5_common_realize(uint32_t irsid, uint32_t num_cpus, uint32_t spi_base, uint32_t spi_irs_range, uint32_t spi_range) "GICv5 IRS realized: IRS ID %u, %u CPUs, SPI base %u, SPI IRS range %u, SPI range %u"
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 58/77] hw/intc/arm_gicv5: Implement IRS_VPE_CR0
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (56 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 57/77] hw/intc/arm_gicv5: Implement IRS_VPE_DBR Peter Maydell
@ 2026-12-03 11:10 ` Peter Maydell
2026-12-03 11:11 ` [PATCH v2 59/77] hw/intc/arm_gicv5: Implement gicv5_set_resident() Peter Maydell
` (18 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:10 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
IRS_VPE_CR0 is a 32-bit VPE configuration register which has
semantics similar to IRS_VPE_DBR. However, the only configuration
field it has is for configuring 1-of-N VPE selection. Since QEMU
does not implement the optional 1-of-N handling, for us the entire
register is RES0.
We don't need to implement the "writes to the register trigger a
re-check of the validity of the VPE in IRS_VPE_SELR and update
IRS_VPE_STATUSR.V" when the whole register is RES0, so our
handling of the register can be simple.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/intc/arm_gicv5.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index 7c5b8670333..dcada1b68f5 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -2333,6 +2333,10 @@ static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset,
*data = 0;
}
return true;
+ case A_IRS_VPE_CR0:
+ /* RES0 when VIRT_ONE_N is not implemented */
+ *data = 0;
+ return true;
case A_IRS_VPE_STATUSR:
if (gicv5_domain_has_virt(cs, domain)) {
*data = cs->irs_vpe_statusr[domain];
@@ -2524,6 +2528,9 @@ static bool config_writel(GICv5 *s, GICv5Domain domain, hwaddr offset,
irs_vpe_dbr_write(s, domain,
deposit64(cs->irs_vpe_dbr[domain], 32, 32, data));
return true;
+ case A_IRS_VPE_CR0:
+ /* RES0 when VIRT_ONE_N is not implemented */
+ return true;
case A_IRS_SPI_SELR:
cs->irs_spi_selr[domain] = data;
return true;
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 59/77] hw/intc/arm_gicv5: Implement gicv5_set_resident()
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (57 preceding siblings ...)
2026-12-03 11:10 ` [PATCH v2 58/77] hw/intc/arm_gicv5: Implement IRS_VPE_CR0 Peter Maydell
@ 2026-12-03 11:11 ` Peter Maydell
2026-12-03 11:11 ` [PATCH v2 60/77] hw/intc/arm_gicv5: Take cpuidx for stream commands on virtual interrupts Peter Maydell
` (17 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:11 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
When the GICv5 CPU interface wants to make a VPE resident, it calls
gicv5_set_resident(). Currently that is a do-nothing placeholder;
implement the required behaviour of tracking on the IRS side that
the VPE is resident on this CPU, and remembering the information
about the doorbell interrupt.
For each CPU, we keep a note of the current VPE that is resident (if
any), so we have an easy way to get to that information given the CPU
index in functions like gicv5_set_priority(). Since the only way to
make a VPE invalid is to make the entire VM invalid, we only need to
set this info in gicv5_set_resident() and then clear it when a VM
becomes invalid or the whole VM table is made invalid.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
include/hw/intc/arm_gicv5.h | 5 ++
hw/intc/arm_gicv5.c | 115 +++++++++++++++++++++++++++++++++++-
hw/intc/trace-events | 2 +
3 files changed, 120 insertions(+), 2 deletions(-)
diff --git a/include/hw/intc/arm_gicv5.h b/include/hw/intc/arm_gicv5.h
index 28417317376..ac85cad3eb5 100644
--- a/include/hw/intc/arm_gicv5.h
+++ b/include/hw/intc/arm_gicv5.h
@@ -40,6 +40,8 @@ typedef struct GICv5VMTConfig {
GHashTable *vm_cache;
} GICv5VMTConfig;
+typedef struct VPE VPE;
+
/*
* This class is for TCG-specific state for the GICv5.
*/
@@ -53,6 +55,9 @@ struct GICv5 {
/* We cache the HPPI for each CPU for each domain here */
GICv5PendingIrq *hppi[NUM_GICV5_DOMAINS];
+
+ /* Array: for each CPU, either NULL or ptr to the resident VPE */
+ VPE **res_vpe;
};
struct GICv5Class {
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index dcada1b68f5..b1ce04fe414 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -29,11 +29,13 @@ typedef struct VMTE VMTE;
typedef struct VPE {
VMTE *vmte;
hwaddr vped_addr;
+ uint32_t cpuidx; /* CPU we're currently resident on */
uint32_t db_intid; /* doorbell interrupt ID */
uint8_t dbpm; /* doorbell priority mask */
bool valid; /* is the VPE valid? */
bool db_valid; /* are doorbell settings valid? */
bool db_req; /* is a doorbell requested? */
+ bool resident; /* is VPE resident on some CPU? */
} VPE;
/* In the GICv5VMTConfig::vm_cache this is how we store VMTE info */
@@ -1176,8 +1178,89 @@ bool gicv5_set_resident(GICv5Common *cs, GICv5Domain domain, bool valid,
uint32_t vpeid, bool db, uint8_t dbpm, uint32_t vmid,
uint32_t cpuidx)
{
- /* Until we implement virtualization, SetResident always fails */
- return true;
+ VMTE *vmte;
+ VPE *vpe;
+ GICv5 *s = ARM_GICV5(cs);
+ GICv5VMTConfig *cfg = &s->vmt_config[domain];
+
+ assert(cpuidx < cs->num_cpus);
+
+ if (!gicv5_domain_has_virt(cs, domain) || !cfg->valid) {
+ return true;
+ }
+
+ /*
+ * R_PYWKM: if resident VPE is for wrong domain, then ignore
+ * attempts to set a resident VPE. Allow an attempt to clear the
+ * resident VPE, but treat DB as zero.
+ */
+ if (s->res_vpe[cpuidx] &&
+ s->res_vpe[cpuidx]->vmte->domain != domain) {
+ if (valid) {
+ return true;
+ }
+ db = 0;
+ }
+
+ if (valid) {
+ /* Trying to make a VPE resident */
+
+ vmte = g_hash_table_lookup(cfg->vm_cache, GINT_TO_POINTER(vmid));
+ vpe = vpe_for_vpeid(vmte, vpeid);
+ if (!vpe) {
+ return true;
+ }
+
+ if (vpe->resident) {
+ /*
+ * Trying to make a VPE resident when it's already
+ * resident somewhere else is CONSTRAINED UNPREDICTABLE
+ * per R_JJKJV. We choose to fail the request.
+ */
+ return true;
+ }
+
+ vpe->resident = true;
+ vpe->cpuidx = cpuidx;
+
+ s->res_vpe[cpuidx] = vpe;
+ trace_gicv5_set_resident(domain_name[domain], vmid, vpeid, cpuidx);
+ } else {
+ vpe = s->res_vpe[cpuidx];
+ if (!vpe) {
+ /* Making non-resident when already no VPE resident */
+ return true;
+ }
+
+ vmte = vpe->vmte;
+
+ vpe->resident = false;
+ vpe->cpuidx = UINT32_MAX;
+ vpe->db_req = db;
+ if (db) {
+ vpe->dbpm = dbpm;
+ }
+ s->res_vpe[cpuidx] = NULL;
+
+ trace_gicv5_set_non_resident(domain_name[domain], cpuidx, db, dbpm);
+
+ /*
+ * TODO: when we implement VPE doorbells, we should check whether
+ * we should immediately generate a doorbell for a VPE that has
+ * just been made non-resident.
+ */
+ }
+
+ /*
+ * Tell the cpuif that the vHPPI for its resident VPE has changed;
+ * it will then call gicv5_get_hppi() which will return either
+ * IRQ_NONE if this is make-non-resident or the vHPPI for the
+ * now-resident VPE if this is make-resident.
+ */
+ gicv5_forward_interrupt(cs->cpus[cpuidx], vmte->domain, true);
+
+ /* SetResident succeeded */
+ return false;
}
static bool read_first_vmte_word(GICv5Common *cs, GICv5VMTConfig *cfg,
@@ -1560,6 +1643,8 @@ static void irs_vmt_baser_write(GICv5 *s, GICv5Domain domain, uint64_t value)
return;
}
irs_clean_vm_cache(cs, &s->vmt_config[domain]);
+ /* No VPE is now resident on any CPU */
+ memset(s->res_vpe, 0, sizeof(*s->res_vpe) * cs->num_cpus);
cs->irs_vmt_baser[domain] = FIELD_DP64(cs->irs_vmt_baser[domain],
IRS_VMT_BASER, VALID, valid);
s->vmt_config[domain].valid = false;
@@ -1712,6 +1797,20 @@ txfail:
"physical address 0x" HWADDR_FMT_plx "\n", vmid, l1_addr);
}
+static void remove_res_vpe_by_vmid(GICv5 *s, uint32_t vmid)
+{
+ /* Remove all res_vpe cached information for VPEs for this VMID */
+ GICv5Common *cs = ARM_GICV5_COMMON(s);
+
+ for (int i = 0; i < cs->num_cpus; i++) {
+ VPE *vpe = s->res_vpe[i];
+
+ if (vpe && vpe->vmte->vmid == vmid) {
+ s->res_vpe[i] = NULL;
+ }
+ }
+}
+
static void irs_vmap_vmr_write(GICv5 *s, GICv5Domain domain, uint64_t value)
{
GICv5Common *cs = ARM_GICV5_COMMON(s);
@@ -1761,6 +1860,7 @@ static void irs_vmap_vmr_write(GICv5 *s, GICv5Domain domain, uint64_t value)
}
if (u) {
+ remove_res_vpe_by_vmid(s, vmid);
g_hash_table_remove(cfg->vm_cache, GINT_TO_POINTER(vmid));
} else {
if (!read_other_vmte_words(cs, cfg, l2_addr, l2_vmte)) {
@@ -2858,6 +2958,7 @@ static void gicv5_set_spi(void *opaque, int irq, int level)
static void gicv5_reset_hold(Object *obj, ResetType type)
{
GICv5 *s = ARM_GICV5(obj);
+ GICv5Common *cs = ARM_GICV5_COMMON(obj);
GICv5Class *c = ARM_GICV5_GET_CLASS(s);
if (c->parent_phases.hold) {
@@ -2884,6 +2985,11 @@ static void gicv5_reset_hold(Object *obj, ResetType type)
g_hash_table_remove_all(s->vmt_config[i].vm_cache);
}
}
+
+ if (s->res_vpe) {
+ /* No VPE is now resident on any CPU */
+ memset(s->res_vpe, 0, sizeof(*s->res_vpe) * cs->num_cpus);
+ }
}
static void gicv5_set_idregs(GICv5Common *cs)
@@ -2988,6 +3094,10 @@ static void gicv5_realize(DeviceState *dev, Error **errp)
s->hppi[i] = g_new0(GICv5PendingIrq, cs->num_cpus);
}
}
+
+ if (cs->has_virt) {
+ s->res_vpe = g_new0(VPE *, cs->num_cpus);
+ }
}
static void gicv5_init(Object *obj)
@@ -3012,6 +3122,7 @@ static void gicv5_finalize(Object *obj)
g_free(s->hppi[i]);
}
+ g_free(s->res_vpe);
}
static void gicv5_class_init(ObjectClass *oc, const void *data)
diff --git a/hw/intc/trace-events b/hw/intc/trace-events
index 97a141c9d0d..b7435a47b94 100644
--- a/hw/intc/trace-events
+++ b/hw/intc/trace-events
@@ -256,6 +256,8 @@ gicv5_irs_vmap_vper_write(const char *domain, uint32_t vmid, uint32_t vpeid) "GI
gicv5_irs_vpe_selr_write(const char *domain, uint64_t selr, uint32_t status) "GICv5 IRS %s IRS_VPE_SELR written 0x%" PRIx64 " IRS_VPE_STATUSR now 0x%x"
gicv5_irs_vpe_dbr_write(const char *domain, uint32_t vmid, uint32_t vpeid, uint8_t dbpm, uint32_t db_intid, bool db_req) "GICv5 IRS %s VM ID %u VPE %u IRS_VPE_DBR doorbell now valid: prio mask %u intid %u requested %d"
gicv5_irs_vpe_dbr_write_nv(const char *domain, uint32_t vmid, uint32_t vpeid) "GICv5 IRS %s VM ID %u VPE %u IRS_VPE_DBR doorbell info no longer valid"
+gicv5_set_resident(const char *domain, uint32_t vmid, uint32_t vpeid, uint32_t cpuidx) "GICv5 IRS %s VM ID %u VPE %u set_resident phys CPU idx %u: now resident"
+gicv5_set_non_resident(const char *domain, uint32_t cpuidx, bool db, uint8_t dbpm) "GICv5 IRS %s set_resident phys CPU idx %u: now no resident VPE; db_req %d dbpm %u"
# arm_gicv5_common.c
gicv5_common_realize(uint32_t irsid, uint32_t num_cpus, uint32_t spi_base, uint32_t spi_irs_range, uint32_t spi_range) "GICv5 IRS realized: IRS ID %u, %u CPUs, SPI base %u, SPI IRS range %u, SPI range %u"
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 60/77] hw/intc/arm_gicv5: Take cpuidx for stream commands on virtual interrupts
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (58 preceding siblings ...)
2026-12-03 11:11 ` [PATCH v2 59/77] hw/intc/arm_gicv5: Implement gicv5_set_resident() Peter Maydell
@ 2026-12-03 11:11 ` Peter Maydell
2026-12-03 11:11 ` [PATCH v2 61/77] hw/intc/arm_gicv5: Handle virtual=true in gicv5_set_priority() Peter Maydell
` (16 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:11 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
In hardware, the GICv5 stream protocol is a set of 1:1 links between
the IRS and the attached CPU interfaces, which means the IRS always
implicitly knows which CPU it has received a command from. For QEMU,
these are all function calls, and so the IRS doesn't know unless we
pass the cpuidx. For most of the stream protocol commands, the IRS
so far hasn't needed to know, because operations on physical
interrupts are the same whichever CPU requests them. But for virtual
interrupts the operation will be on the interrupts of whichever VM
owns the VPE currently resident on the requesting CPU, so we do need
to know which one that is.
Add a cpuidx argument to every function corresponding to a stream
protocol command that can operate on a virtual interrupt.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
include/hw/intc/arm_gicv5_stream.h | 25 +++++++++++++++++--------
hw/intc/arm_gicv5.c | 18 ++++++++++--------
target/arm/tcg/gicv5-cpuif.c | 21 ++++++++++++---------
3 files changed, 39 insertions(+), 25 deletions(-)
diff --git a/include/hw/intc/arm_gicv5_stream.h b/include/hw/intc/arm_gicv5_stream.h
index ea27d6aec0f..0d62f86820d 100644
--- a/include/hw/intc/arm_gicv5_stream.h
+++ b/include/hw/intc/arm_gicv5_stream.h
@@ -59,6 +59,7 @@ GICv5CPUIFStatus gicv5_set_gicv5state(ARMCPU *cpu, GICv5Common *cs,
* @domain: interrupt Domain to act on
* @type: interrupt type (LPI or SPI)
* @virtual: true if this is a virtual interrupt
+ * @cpuidx: IRS CPU index of this CPU interface
*
* Set priority of an interrupt; matches stream interface SetPriority
* command from CPUIF to IRS. There is no report back of
@@ -66,7 +67,7 @@ GICv5CPUIFStatus gicv5_set_gicv5state(ARMCPU *cpu, GICv5Common *cs,
*/
void gicv5_set_priority(GICv5Common *cs, uint32_t id,
uint8_t priority, GICv5Domain domain,
- GICv5IntType type, bool virtual);
+ GICv5IntType type, bool virtual, uint32_t cpuidx);
/**
* gicv5_set_enabled
@@ -76,6 +77,7 @@ void gicv5_set_priority(GICv5Common *cs, uint32_t id,
* @domain: interrupt Domain to act on
* @type: interrupt type (LPI or SPI)
* @virtual: true if this is a virtual interrupt
+ * @cpuidx: IRS CPU index of this CPU interface
*
* Set enabled state of an interrupt; matches stream interface
* SetEnabled command from CPUIF to IRS. There is no report back of
@@ -83,7 +85,7 @@ void gicv5_set_priority(GICv5Common *cs, uint32_t id,
*/
void gicv5_set_enabled(GICv5Common *cs, uint32_t id,
bool enabled, GICv5Domain domain,
- GICv5IntType type, bool virtual);
+ GICv5IntType type, bool virtual, uint32_t cpuidx);
/**
* gicv5_set_pending
@@ -94,6 +96,7 @@ void gicv5_set_enabled(GICv5Common *cs, uint32_t id,
* @type: interrupt type (LPI or SPI)
* @virtual: true if this is a virtual interrupt
* @vm: VM ID (for virtual interrupts)
+ * @cpuidx: IRS CPU index of this CPU interface
*
* Set pending state of an interrupt; matches stream interface
* SetPending command from CPUIF to IRS. There is no report back of
@@ -101,7 +104,8 @@ void gicv5_set_enabled(GICv5Common *cs, uint32_t id,
*/
void gicv5_set_pending(GICv5Common *cs, uint32_t id,
bool pending, GICv5Domain domain,
- GICv5IntType type, bool virtual, uint32_t vm);
+ GICv5IntType type, bool virtual, uint32_t vm,
+ uint32_t cpuidx);
/**
* gicv5_set_handling
@@ -111,6 +115,7 @@ void gicv5_set_pending(GICv5Common *cs, uint32_t id,
* @domain: interrupt Domain to act on
* @type: interrupt type (LPI or SPI)
* @virtual: true if this is a virtual interrupt
+ * @cpuidx: IRS CPU index of this CPU interface
*
* Set handling mode of an interrupt (edge/level); matches stream
* interface SetHandling command from CPUIF to IRS. There is no report
@@ -118,7 +123,7 @@ void gicv5_set_pending(GICv5Common *cs, uint32_t id,
*/
void gicv5_set_handling(GICv5Common *cs, uint32_t id,
GICv5HandlingMode handling, GICv5Domain domain,
- GICv5IntType type, bool virtual);
+ GICv5IntType type, bool virtual, uint32_t cpuidx);
/**
* gicv5_set_target
@@ -129,6 +134,7 @@ void gicv5_set_handling(GICv5Common *cs, uint32_t id,
* @domain: interrupt Domain to act on
* @type: interrupt type (LPI or SPI)
* @virtual: true if this is a virtual interrupt
+ * @cpuidx: IRS CPU index of this CPU interface
*
* Set handling mode of an interrupt (edge/level); matches stream
* interface SetHandling command from CPUIF to IRS. There is no report
@@ -136,7 +142,7 @@ void gicv5_set_handling(GICv5Common *cs, uint32_t id,
*/
void gicv5_set_target(GICv5Common *cs, uint32_t id, uint32_t iaffid,
GICv5RoutingMode irm, GICv5Domain domain,
- GICv5IntType type, bool virtual);
+ GICv5IntType type, bool virtual, uint32_t cpuidx);
/**
* gicv5_request_config
@@ -145,6 +151,7 @@ void gicv5_set_target(GICv5Common *cs, uint32_t id, uint32_t iaffid,
* @domain: interrupt domain to act on
* @type: interrupt type (LPI or SPI)
* @virtual: true if this is a virtual interrupt
+ * @cpuidx: IRS CPU index of this CPU interface
*
* Query the current configuration of an interrupt; matches stream
* interface RequestConfig command from CPUIF to IRS and the
@@ -159,7 +166,7 @@ void gicv5_set_target(GICv5Common *cs, uint32_t id, uint32_t iaffid,
* ICC_ICSR_EL1.
*/
uint64_t gicv5_request_config(GICv5Common *cs, uint32_t id, GICv5Domain domain,
- GICv5IntType type, bool virtual);
+ GICv5IntType type, bool virtual, uint32_t cpuidx);
/**
* gicv5_activate
@@ -168,6 +175,7 @@ uint64_t gicv5_request_config(GICv5Common *cs, uint32_t id, GICv5Domain domain,
* @domain: interrupt domain to act on
* @type: interrupt type (LPI or SPI)
* @virtual: true if this is a virtual interrupt
+ * @cpuidx: IRS CPU index of this CPU interface
*
* Activate the IRS's highest priority pending interrupt; matches the
* stream interface's Activate command.
@@ -182,7 +190,7 @@ uint64_t gicv5_request_config(GICv5Common *cs, uint32_t id, GICv5Domain domain,
* its hppi[][] array.
*/
void gicv5_activate(GICv5Common *cs, uint32_t id, GICv5Domain domain,
- GICv5IntType type, bool virtual);
+ GICv5IntType type, bool virtual, uint32_t cpuidx);
/**
* gicv5_forward_interrupt
@@ -230,12 +238,13 @@ GICv5PendingIrq gicv5_get_hppi(GICv5Common *cs, GICv5Domain domain,
* @domain: interrupt Domain to act on
* @type: interrupt type (LPI or SPI)
* @virtual: true if this is a virtual interrupt
+ * @cpuidx: IRS CPU index of this CPU interface
*
* Deactivate the specified interrupt. There is no report back of
* success/failure to the CPUIF in the protocol.
*/
void gicv5_deactivate(GICv5Common *cs, uint32_t id, GICv5Domain domain,
- GICv5IntType type, bool virtual);
+ GICv5IntType type, bool virtual, uint32_t cpuidx);
/**
* gicv5_set_resident
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index b1ce04fe414..3d7d87a2ff0 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -562,7 +562,8 @@ static hwaddr l1_vmte_addr(GICv5Common *cs, const GICv5VMTConfig *cfg,
}
void gicv5_set_priority(GICv5Common *cs, uint32_t id, uint8_t priority,
- GICv5Domain domain, GICv5IntType type, bool virtual)
+ GICv5Domain domain, GICv5IntType type, bool virtual,
+ uint32_t cpuidx)
{
GICv5 *s = ARM_GICV5(cs);
uint32_t iaffid;
@@ -617,7 +618,8 @@ void gicv5_set_priority(GICv5Common *cs, uint32_t id, uint8_t priority,
}
void gicv5_set_enabled(GICv5Common *cs, uint32_t id, bool enabled,
- GICv5Domain domain, GICv5IntType type, bool virtual)
+ GICv5Domain domain, GICv5IntType type, bool virtual,
+ uint32_t cpuidx)
{
GICv5 *s = ARM_GICV5(cs);
uint32_t iaffid;
@@ -670,7 +672,7 @@ void gicv5_set_enabled(GICv5Common *cs, uint32_t id, bool enabled,
void gicv5_set_pending(GICv5Common *cs, uint32_t id, bool pending,
GICv5Domain domain, GICv5IntType type, bool virtual,
- uint32_t vm)
+ uint32_t vm, uint32_t cpuidx)
{
GICv5 *s = ARM_GICV5(cs);
uint32_t iaffid;
@@ -723,7 +725,7 @@ void gicv5_set_pending(GICv5Common *cs, uint32_t id, bool pending,
void gicv5_set_handling(GICv5Common *cs, uint32_t id,
GICv5HandlingMode handling, GICv5Domain domain,
- GICv5IntType type, bool virtual)
+ GICv5IntType type, bool virtual, uint32_t cpuidx)
{
GICv5 *s = ARM_GICV5(cs);
@@ -771,7 +773,7 @@ void gicv5_set_handling(GICv5Common *cs, uint32_t id,
void gicv5_set_target(GICv5Common *cs, uint32_t id, uint32_t iaffid,
GICv5RoutingMode irm, GICv5Domain domain,
- GICv5IntType type, bool virtual)
+ GICv5IntType type, bool virtual, uint32_t cpuidx)
{
GICv5 *s = ARM_GICV5(cs);
uint32_t old_iaffid;
@@ -883,7 +885,7 @@ static uint64_t spi_state_to_icsr(GICv5SPIState *spi)
}
uint64_t gicv5_request_config(GICv5Common *cs, uint32_t id, GICv5Domain domain,
- GICv5IntType type, bool virtual)
+ GICv5IntType type, bool virtual, uint32_t cpuidx)
{
GICv5 *s = ARM_GICV5(cs);
uint64_t icsr;
@@ -927,7 +929,7 @@ uint64_t gicv5_request_config(GICv5Common *cs, uint32_t id, GICv5Domain domain,
}
void gicv5_activate(GICv5Common *cs, uint32_t id, GICv5Domain domain,
- GICv5IntType type, bool virtual)
+ GICv5IntType type, bool virtual, uint32_t cpuidx)
{
GICv5 *s = ARM_GICV5(cs);
uint32_t iaffid;
@@ -985,7 +987,7 @@ void gicv5_activate(GICv5Common *cs, uint32_t id, GICv5Domain domain,
}
void gicv5_deactivate(GICv5Common *cs, uint32_t id, GICv5Domain domain,
- GICv5IntType type, bool virtual)
+ GICv5IntType type, bool virtual, uint32_t cpuidx)
{
GICv5 *s = ARM_GICV5(cs);
uint32_t iaffid;
diff --git a/target/arm/tcg/gicv5-cpuif.c b/target/arm/tcg/gicv5-cpuif.c
index ec4ee9825e8..08fffa16dfc 100644
--- a/target/arm/tcg/gicv5-cpuif.c
+++ b/target/arm/tcg/gicv5-cpuif.c
@@ -684,7 +684,7 @@ static void gic_cddis_write(CPUARMState *env, const ARMCPRegInfo *ri,
bool virtual;
GICv5Domain domain = gicv5_domain_for_insn(env, ri, &virtual);
- gicv5_set_enabled(gic, id, false, domain, type, virtual);
+ gicv5_set_enabled(gic, id, false, domain, type, virtual, env->gicv5.cpuidx);
}
static void gic_cden_write(CPUARMState *env, const ARMCPRegInfo *ri,
@@ -696,7 +696,7 @@ static void gic_cden_write(CPUARMState *env, const ARMCPRegInfo *ri,
bool virtual;
GICv5Domain domain = gicv5_domain_for_insn(env, ri, &virtual);
- gicv5_set_enabled(gic, id, true, domain, type, virtual);
+ gicv5_set_enabled(gic, id, true, domain, type, virtual, env->gicv5.cpuidx);
}
static void gic_cdpri_write(CPUARMState *env, const ARMCPRegInfo *ri,
@@ -709,7 +709,8 @@ static void gic_cdpri_write(CPUARMState *env, const ARMCPRegInfo *ri,
bool virtual;
GICv5Domain domain = gicv5_domain_for_insn(env, ri, &virtual);
- gicv5_set_priority(gic, id, priority, domain, type, virtual);
+ gicv5_set_priority(gic, id, priority, domain, type, virtual,
+ env->gicv5.cpuidx);
}
static void gic_cdaff_write(CPUARMState *env, const ARMCPRegInfo *ri,
@@ -723,7 +724,8 @@ static void gic_cdaff_write(CPUARMState *env, const ARMCPRegInfo *ri,
bool virtual;
GICv5Domain domain = gicv5_domain_for_insn(env, ri, &virtual);
- gicv5_set_target(gic, id, iaffid, irm, domain, type, virtual);
+ gicv5_set_target(gic, id, iaffid, irm, domain, type, virtual,
+ env->gicv5.cpuidx);
}
static void gic_cdpend_write(CPUARMState *env, const ARMCPRegInfo *ri,
@@ -763,7 +765,8 @@ static void gic_cdpend_write(CPUARMState *env, const ARMCPRegInfo *ri,
}
}
- gicv5_set_pending(gic, id, pending, domain, type, virtual, vm);
+ gicv5_set_pending(gic, id, pending, domain, type, virtual, vm,
+ env->gicv5.cpuidx);
}
static void gic_cdrcfg_write(CPUARMState *env, const ARMCPRegInfo *ri,
@@ -776,7 +779,7 @@ static void gic_cdrcfg_write(CPUARMState *env, const ARMCPRegInfo *ri,
GICv5Domain domain = gicv5_domain_for_insn(env, ri, &virtual);
env->gicv5_cpuif.icc_icsr_el1 =
- gicv5_request_config(gic, id, domain, type, virtual);
+ gicv5_request_config(gic, id, domain, type, virtual, env->gicv5.cpuidx);
}
static void gic_cdhm_write(CPUARMState *env, const ARMCPRegInfo *ri,
@@ -789,7 +792,7 @@ static void gic_cdhm_write(CPUARMState *env, const ARMCPRegInfo *ri,
bool virtual;
GICv5Domain domain = gicv5_domain_for_insn(env, ri, &virtual);
- gicv5_set_handling(gic, id, hm, domain, type, virtual);
+ gicv5_set_handling(gic, id, hm, domain, type, virtual, env->gicv5.cpuidx);
}
static uint64_t gic_ppi_hmr_read(CPUARMState *env, const ARMCPRegInfo *ri)
@@ -1471,7 +1474,7 @@ static uint64_t gicr_cdia_read(CPUARMState *env, const ARMCPRegInfo *ri)
* name of the stream command, does both "set Active" and
* "maybe set not Pending" as a single atomic action.
*/
- gicv5_activate(gic, id, domain, type, virtual);
+ gicv5_activate(gic, id, domain, type, virtual, env->gicv5.cpuidx);
break;
default:
g_assert_not_reached();
@@ -1548,7 +1551,7 @@ static void gic_cddi_write(CPUARMState *env, const ARMCPRegInfo *ri,
case GICV5_LPI:
case GICV5_SPI:
/* Tell the IRS to deactivate this interrupt */
- gicv5_deactivate(gic, id, domain, type, virtual);
+ gicv5_deactivate(gic, id, domain, type, virtual, env->gicv5.cpuidx);
break;
default:
break;
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 61/77] hw/intc/arm_gicv5: Handle virtual=true in gicv5_set_priority()
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (59 preceding siblings ...)
2026-12-03 11:11 ` [PATCH v2 60/77] hw/intc/arm_gicv5: Take cpuidx for stream commands on virtual interrupts Peter Maydell
@ 2026-12-03 11:11 ` Peter Maydell
2026-12-03 11:11 ` [PATCH v2 62/77] hw/intc/arm_gicv5: Handle virtual=true for setting enabled, pending, handling Peter Maydell
` (15 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:11 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
The gicv5_set_priority() function has a 'bool virtual' argument so the
CPU interface can tell us whether it is setting a virtual or physical
interrupt's priority. Implement the handling for this.
What we need to do is identical to what we do for physical LPIs,
except that we need to do it on the IST for vLPIs or vSPIs for the
resident vCPU. So we can factor out the "update the appropriate
field in the L2 ISTE". We do this via a macro, because we're going
to want identical behaviour for the other fields in an L2_ISTE that
gicv5_set_enabled(), gicv5_set_pending(), etc update.
Actually recalculating the vHPPI for the affected vCPU will be
implemented in a later commit.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/intc/arm_gicv5.c | 90 +++++++++++++++++++++++++++++++++++++++++----
1 file changed, 82 insertions(+), 8 deletions(-)
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index 3d7d87a2ff0..90a925e681b 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -561,6 +561,81 @@ static hwaddr l1_vmte_addr(GICv5Common *cs, const GICv5VMTConfig *cfg,
return cfg->base + (l1_index * 8);
}
+static void irs_recalc_vhppi(GICv5 *s, VMTE *vmte, uint32_t iaffid)
+{
+ /*
+ * Recalculate the highest priority pending virtual interrupt for
+ * the specified VM and vCPU.
+ *
+ * TODO: we will implement this in a future commit.
+ */
+}
+
+static const GICv5ISTConfig *ist_for_vint(GICv5 *s,
+ GICv5Common *cs,
+ GICv5Domain domain,
+ GICv5IntType type,
+ uint32_t cpuidx)
+{
+ /*
+ * Return the GICv5ISTConfig to use to look up the virtual interrupt.
+ * Return NULL for any case where the operation should be a NOP.
+ */
+ VMTE *vmte;
+ VPE *vpe;
+
+ if (!gicv5_domain_has_virt(cs, domain)) {
+ return NULL;
+ }
+
+ vpe = s->res_vpe[cpuidx];
+ if (!vpe) {
+ return NULL;
+ }
+ vmte = vpe->vmte;
+ if (vmte->domain != domain) {
+ /* Ignore commands for the wrong domain (see R_PYWKM) */
+ return NULL;
+ }
+
+ return type == GICV5_LPI ? &vmte->lpi_ist : &vmte->spi_ist;
+}
+
+/*
+ * Define a function that, given a GICv5ISTConfig and an interrupt ID,
+ * will update the L2_ISTE entry for that interrupt in that IST to
+ * set the given field to a new value. The function returns true on
+ * success and if iaffid is non-NULL updates *iaffid with the IAFFID from
+ * the L2_ISTE (which is the IAFFID whose current HPPI will need to be
+ * recalculated).
+ */
+#define DEF_SET_FIELD_FOR_IST(NAME, TYPE, FIELDNAME) \
+ static bool set_##NAME##_for_ist(GICv5Common *cs, \
+ const GICv5ISTConfig *cfg, \
+ uint32_t id, \
+ TYPE NAME, \
+ uint32_t *iaffid) \
+ { \
+ L2_ISTE_Handle h; \
+ uint32_t *l2_iste_p; \
+ if (!cfg) { \
+ return false; \
+ } \
+ l2_iste_p = get_l2_iste(cs, cfg, id, &h); \
+ if (!l2_iste_p) { \
+ return false; \
+ } \
+ /* read IAFFID first in case we are about to write to it */ \
+ if (iaffid) { \
+ *iaffid = FIELD_EX32(*l2_iste_p, L2_ISTE, IAFFID); \
+ } \
+ *l2_iste_p = FIELD_DP32(*l2_iste_p, L2_ISTE, FIELDNAME, NAME); \
+ put_l2_iste(cs, cfg, &h); \
+ return true; \
+ }
+
+DEF_SET_FIELD_FOR_IST(priority, uint8_t, PRIORITY)
+
void gicv5_set_priority(GICv5Common *cs, uint32_t id, uint8_t priority,
GICv5Domain domain, GICv5IntType type, bool virtual,
uint32_t cpuidx)
@@ -574,8 +649,12 @@ void gicv5_set_priority(GICv5Common *cs, uint32_t id, uint8_t priority,
priority &= MAKE_64BIT_MASK(5 - QEMU_GICV5_PRI_BITS, QEMU_GICV5_PRI_BITS);
if (virtual) {
- qemu_log_mask(LOG_GUEST_ERROR, "gicv5_set_priority: tried to set "
- "priority of a virtual interrupt\n");
+ const GICv5ISTConfig *cfg = ist_for_vint(s, cs, domain, type, cpuidx);
+
+ if (!set_priority_for_ist(cs, cfg, id, priority, &iaffid)) {
+ return;
+ }
+ irs_recalc_vhppi(s, s->res_vpe[cpuidx]->vmte, iaffid);
return;
}
@@ -583,15 +662,10 @@ void gicv5_set_priority(GICv5Common *cs, uint32_t id, uint8_t priority,
case GICV5_LPI:
{
const GICv5ISTConfig *cfg = &s->phys_lpi_config[domain];
- L2_ISTE_Handle h;
- uint32_t *l2_iste_p = get_l2_iste(cs, cfg, id, &h);
- if (!l2_iste_p) {
+ if (!set_priority_for_ist(cs, cfg, id, priority, &iaffid)) {
return;
}
- *l2_iste_p = FIELD_DP32(*l2_iste_p, L2_ISTE, PRIORITY, priority);
- iaffid = FIELD_EX32(*l2_iste_p, L2_ISTE, IAFFID);
- put_l2_iste(cs, cfg, &h);
break;
}
case GICV5_SPI:
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 62/77] hw/intc/arm_gicv5: Handle virtual=true for setting enabled, pending, handling
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (60 preceding siblings ...)
2026-12-03 11:11 ` [PATCH v2 61/77] hw/intc/arm_gicv5: Handle virtual=true in gicv5_set_priority() Peter Maydell
@ 2026-12-03 11:11 ` Peter Maydell
2026-12-03 11:11 ` [PATCH v2 63/77] hw/intc/arm_gicv5: Handle virtual=true for setting pending Peter Maydell
` (14 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:11 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Add virtual=true support to gicv5_set_enabled() and
gicv5_set_handling(), in the same way we already did for
gicv5_set_priority().
Note that changing the handling mode doesn't affect interrupt
prioritization, so we don't need to recalculate the vHPPI for that.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/intc/arm_gicv5.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index 90a925e681b..6a42246fb95 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -635,6 +635,8 @@ static const GICv5ISTConfig *ist_for_vint(GICv5 *s,
}
DEF_SET_FIELD_FOR_IST(priority, uint8_t, PRIORITY)
+DEF_SET_FIELD_FOR_IST(enabled, bool, ENABLE)
+DEF_SET_FIELD_FOR_IST(handling, bool, HM)
void gicv5_set_priority(GICv5Common *cs, uint32_t id, uint8_t priority,
GICv5Domain domain, GICv5IntType type, bool virtual,
@@ -701,8 +703,12 @@ void gicv5_set_enabled(GICv5Common *cs, uint32_t id, bool enabled,
trace_gicv5_set_enabled(domain_name[domain], inttype_name(type), virtual,
id, enabled);
if (virtual) {
- qemu_log_mask(LOG_GUEST_ERROR, "gicv5_set_enabled: tried to set "
- "enable state of a virtual interrupt\n");
+ const GICv5ISTConfig *cfg = ist_for_vint(s, cs, domain, type, cpuidx);
+
+ if (!set_enabled_for_ist(cs, cfg, id, enabled, &iaffid)) {
+ return;
+ }
+ irs_recalc_vhppi(s, s->res_vpe[cpuidx]->vmte, iaffid);
return;
}
@@ -710,15 +716,10 @@ void gicv5_set_enabled(GICv5Common *cs, uint32_t id, bool enabled,
case GICV5_LPI:
{
const GICv5ISTConfig *cfg = &s->phys_lpi_config[domain];
- L2_ISTE_Handle h;
- uint32_t *l2_iste_p = get_l2_iste(cs, cfg, id, &h);
- if (!l2_iste_p) {
+ if (!set_enabled_for_ist(cs, cfg, id, enabled, &iaffid)) {
return;
}
- *l2_iste_p = FIELD_DP32(*l2_iste_p, L2_ISTE, ENABLE, enabled);
- iaffid = FIELD_EX32(*l2_iste_p, L2_ISTE, IAFFID);
- put_l2_iste(cs, cfg, &h);
break;
}
case GICV5_SPI:
@@ -806,8 +807,11 @@ void gicv5_set_handling(GICv5Common *cs, uint32_t id,
trace_gicv5_set_handling(domain_name[domain], inttype_name(type), virtual,
id, handling);
if (virtual) {
- qemu_log_mask(LOG_GUEST_ERROR, "gicv5_set_handling: tried to set "
- "handling mode of a virtual interrupt\n");
+ const GICv5ISTConfig *cfg = ist_for_vint(s, cs, domain, type, cpuidx);
+
+ if (!set_handling_for_ist(cs, cfg, id, handling, NULL)) {
+ return;
+ }
return;
}
@@ -815,14 +819,10 @@ void gicv5_set_handling(GICv5Common *cs, uint32_t id,
case GICV5_LPI:
{
const GICv5ISTConfig *cfg = &s->phys_lpi_config[domain];
- L2_ISTE_Handle h;
- uint32_t *l2_iste_p = get_l2_iste(cs, cfg, id, &h);
- if (!l2_iste_p) {
+ if (!set_handling_for_ist(cs, cfg, id, handling, NULL)) {
return;
}
- *l2_iste_p = FIELD_DP32(*l2_iste_p, L2_ISTE, HM, handling);
- put_l2_iste(cs, cfg, &h);
break;
}
case GICV5_SPI:
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 63/77] hw/intc/arm_gicv5: Handle virtual=true for setting pending
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (61 preceding siblings ...)
2026-12-03 11:11 ` [PATCH v2 62/77] hw/intc/arm_gicv5: Handle virtual=true for setting enabled, pending, handling Peter Maydell
@ 2026-12-03 11:11 ` Peter Maydell
2026-12-03 11:11 ` [PATCH v2 64/77] hw/intc/arm_gicv5: Handle virtual=true in gicv5_set_target() Peter Maydell
` (13 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:11 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Add virtual=true support to gicv5_set_pending(). This is similar
to the handling for set_priority and friends, except that the
Pending state is the one change a cpuif can make to an interrupt
that doesn't require a VPE for the VM to be resident on it.
Instead gicv5_set_pending() is passed the VM ID to operate on.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/intc/arm_gicv5.c | 34 ++++++++++++++++++++++++++--------
1 file changed, 26 insertions(+), 8 deletions(-)
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index 6a42246fb95..bc542ab6a88 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -637,6 +637,7 @@ static const GICv5ISTConfig *ist_for_vint(GICv5 *s,
DEF_SET_FIELD_FOR_IST(priority, uint8_t, PRIORITY)
DEF_SET_FIELD_FOR_IST(enabled, bool, ENABLE)
DEF_SET_FIELD_FOR_IST(handling, bool, HM)
+DEF_SET_FIELD_FOR_IST(pending, bool, PENDING)
void gicv5_set_priority(GICv5Common *cs, uint32_t id, uint8_t priority,
GICv5Domain domain, GICv5IntType type, bool virtual,
@@ -755,8 +756,30 @@ void gicv5_set_pending(GICv5Common *cs, uint32_t id, bool pending,
trace_gicv5_set_pending(domain_name[domain], inttype_name(type), virtual,
vm, id, pending);
if (virtual) {
- qemu_log_mask(LOG_GUEST_ERROR, "gicv5_set_pending: tried to set "
- "pending state of a virtual interrupt\n");
+ /*
+ * SetPending is the one operation on an interrupt that a cpuif
+ * can do without having a VPE for the VM resident. Instead it
+ * passes us the VM ID to operate on, and we must look up the
+ * IST to use that way rather than with ist_for_vint().
+ */
+ GICv5VMTConfig *vmcfg = &s->vmt_config[domain];
+ const GICv5ISTConfig *cfg;
+ VMTE *vmte;
+
+ if (!gicv5_domain_has_virt(cs, domain) || !vmcfg->valid) {
+ return;
+ }
+
+ vmte = g_hash_table_lookup(vmcfg->vm_cache, GINT_TO_POINTER(vm));
+ if (!vmte) {
+ return;
+ }
+
+ cfg = type == GICV5_LPI ? &vmte->lpi_ist : &vmte->spi_ist;
+ if (!set_pending_for_ist(cs, cfg, id, pending, &iaffid)) {
+ return;
+ }
+ irs_recalc_vhppi(s, vmte, iaffid);
return;
}
@@ -764,15 +787,10 @@ void gicv5_set_pending(GICv5Common *cs, uint32_t id, bool pending,
case GICV5_LPI:
{
const GICv5ISTConfig *cfg = &s->phys_lpi_config[domain];
- L2_ISTE_Handle h;
- uint32_t *l2_iste_p = get_l2_iste(cs, cfg, id, &h);
- if (!l2_iste_p) {
+ if (!set_pending_for_ist(cs, cfg, id, pending, &iaffid)) {
return;
}
- *l2_iste_p = FIELD_DP32(*l2_iste_p, L2_ISTE, PENDING, pending);
- iaffid = FIELD_EX32(*l2_iste_p, L2_ISTE, IAFFID);
- put_l2_iste(cs, cfg, &h);
break;
}
case GICV5_SPI:
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 64/77] hw/intc/arm_gicv5: Handle virtual=true in gicv5_set_target()
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (62 preceding siblings ...)
2026-12-03 11:11 ` [PATCH v2 63/77] hw/intc/arm_gicv5: Handle virtual=true for setting pending Peter Maydell
@ 2026-12-03 11:11 ` Peter Maydell
2026-12-03 11:11 ` [PATCH v2 65/77] hw/intc/arm_gicv5: Handle virtual=true in gicv5_deactivate() Peter Maydell
` (12 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:11 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Support virtual=true in gicv5_set_target(). This is basically the
same approach as for the other gicv5_set_*() functions, with the
slight wrinkle that we will need to update the vHPPI for both the old
IAFFID and the new one, and that the comments and handling for (lack
of) 1-of-N routing apply equally to virtual interrupts as to physical
ones.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/intc/arm_gicv5.c | 36 ++++++++++++++++++++----------------
1 file changed, 20 insertions(+), 16 deletions(-)
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index bc542ab6a88..d34a72f3c3c 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -638,6 +638,7 @@ DEF_SET_FIELD_FOR_IST(priority, uint8_t, PRIORITY)
DEF_SET_FIELD_FOR_IST(enabled, bool, ENABLE)
DEF_SET_FIELD_FOR_IST(handling, bool, HM)
DEF_SET_FIELD_FOR_IST(pending, bool, PENDING)
+DEF_SET_FIELD_FOR_IST(target, uint32_t, IAFFID)
void gicv5_set_priority(GICv5Common *cs, uint32_t id, uint8_t priority,
GICv5Domain domain, GICv5IntType type, bool virtual,
@@ -872,11 +873,6 @@ void gicv5_set_target(GICv5Common *cs, uint32_t id, uint32_t iaffid,
trace_gicv5_set_target(domain_name[domain], inttype_name(type), virtual,
id, iaffid, irm);
- if (virtual) {
- qemu_log_mask(LOG_GUEST_ERROR, "gicv5_set_target: tried to set "
- "target of a virtual interrupt\n");
- return;
- }
if (irm != GICV5_TARGETED) {
qemu_log_mask(LOG_GUEST_ERROR, "gicv5_set_target: tried to set "
"1-of-N routing\n");
@@ -887,24 +883,32 @@ void gicv5_set_target(GICv5Common *cs, uint32_t id, uint32_t iaffid,
*/
}
+ /*
+ * For QEMU we do not implement 1-of-N routing, and so L2_ISTE.IRM
+ * is RES0. We never read it, and we can skip explicitly writing
+ * it to zero: it's sufficient to update L2_ISTE.IAFFID alone via
+ * set_target_for_ist().
+ */
+
+ if (virtual) {
+ const GICv5ISTConfig *cfg = ist_for_vint(s, cs, domain, type, cpuidx);
+
+ if (!set_target_for_ist(cs, cfg, id, iaffid, &old_iaffid)) {
+ return;
+ }
+ irs_recalc_vhppi(s, s->res_vpe[cpuidx]->vmte, old_iaffid);
+ irs_recalc_vhppi(s, s->res_vpe[cpuidx]->vmte, iaffid);
+ return;
+ }
+
switch (type) {
case GICV5_LPI:
{
const GICv5ISTConfig *cfg = &s->phys_lpi_config[domain];
- L2_ISTE_Handle h;
- uint32_t *l2_iste_p = get_l2_iste(cs, cfg, id, &h);
- if (!l2_iste_p) {
+ if (!set_target_for_ist(cs, cfg, id, iaffid, &old_iaffid)) {
return;
}
- /*
- * For QEMU we do not implement 1-of-N routing, and so
- * L2_ISTE.IRM is RES0. We never read it, and we can skip
- * explicitly writing it to zero here.
- */
- old_iaffid = FIELD_EX32(*l2_iste_p, L2_ISTE, IAFFID);
- *l2_iste_p = FIELD_DP32(*l2_iste_p, L2_ISTE, IAFFID, iaffid);
- put_l2_iste(cs, cfg, &h);
break;
}
case GICV5_SPI:
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 65/77] hw/intc/arm_gicv5: Handle virtual=true in gicv5_deactivate()
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (63 preceding siblings ...)
2026-12-03 11:11 ` [PATCH v2 64/77] hw/intc/arm_gicv5: Handle virtual=true in gicv5_set_target() Peter Maydell
@ 2026-12-03 11:11 ` Peter Maydell
2026-12-03 11:11 ` [PATCH v2 66/77] hw/intc/arm_gicv5: Handle activation of a virtual interrupt Peter Maydell
` (11 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:11 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Handle deactivation of a virtual interrupt, using a similar process
to virtual interrupt config updates.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/intc/arm_gicv5.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index d34a72f3c3c..934acebc870 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -639,6 +639,7 @@ DEF_SET_FIELD_FOR_IST(enabled, bool, ENABLE)
DEF_SET_FIELD_FOR_IST(handling, bool, HM)
DEF_SET_FIELD_FOR_IST(pending, bool, PENDING)
DEF_SET_FIELD_FOR_IST(target, uint32_t, IAFFID)
+DEF_SET_FIELD_FOR_IST(active, bool, ACTIVE)
void gicv5_set_priority(GICv5Common *cs, uint32_t id, uint8_t priority,
GICv5Domain domain, GICv5IntType type, bool virtual,
@@ -1091,8 +1092,12 @@ void gicv5_deactivate(GICv5Common *cs, uint32_t id, GICv5Domain domain,
trace_gicv5_deactivate(domain_name[domain], inttype_name(type), virtual, id);
if (virtual) {
- qemu_log_mask(LOG_GUEST_ERROR, "gicv5_deactivate: tried to "
- "deactivate a virtual interrupt\n");
+ const GICv5ISTConfig *cfg = ist_for_vint(s, cs, domain, type, cpuidx);
+
+ if (!set_active_for_ist(cs, cfg, id, false, &iaffid)) {
+ return;
+ }
+ irs_recalc_vhppi(s, s->res_vpe[cpuidx]->vmte, iaffid);
return;
}
@@ -1100,15 +1105,10 @@ void gicv5_deactivate(GICv5Common *cs, uint32_t id, GICv5Domain domain,
case GICV5_LPI:
{
const GICv5ISTConfig *cfg = &s->phys_lpi_config[domain];
- L2_ISTE_Handle h;
- uint32_t *l2_iste_p = get_l2_iste(cs, cfg, id, &h);
- if (!l2_iste_p) {
+ if (!set_active_for_ist(cs, cfg, id, false, &iaffid)) {
return;
}
- *l2_iste_p = FIELD_DP32(*l2_iste_p, L2_ISTE, ACTIVE, false);
- iaffid = FIELD_EX32(*l2_iste_p, L2_ISTE, IAFFID);
- put_l2_iste(cs, cfg, &h);
break;
}
case GICV5_SPI:
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 66/77] hw/intc/arm_gicv5: Handle activation of a virtual interrupt
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (64 preceding siblings ...)
2026-12-03 11:11 ` [PATCH v2 65/77] hw/intc/arm_gicv5: Handle virtual=true in gicv5_deactivate() Peter Maydell
@ 2026-12-03 11:11 ` Peter Maydell
2026-12-03 11:11 ` [PATCH v2 67/77] hw/intc/arm_gicv5: Handle virtual=true in gicv5_request_config() Peter Maydell
` (10 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:11 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Handle activation of a virtual interrupt. Because this is more
complex than just updating a single field in the L2_ISTE, we can't
use the DEF_SET_FIELD_FOR_IST() macro, but activate_for_ist() follows
the same basic pattern.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/intc/arm_gicv5.c | 41 ++++++++++++++++++++++++++++++-----------
1 file changed, 30 insertions(+), 11 deletions(-)
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index 934acebc870..f72a354cae1 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -1025,6 +1025,29 @@ uint64_t gicv5_request_config(GICv5Common *cs, uint32_t id, GICv5Domain domain,
}
}
+static bool activate_for_ist(GICv5Common *cs,
+ const GICv5ISTConfig *cfg,
+ uint32_t id,
+ uint32_t *iaffid)
+{
+ L2_ISTE_Handle h;
+ uint32_t *l2_iste_p;
+ if (!cfg) {
+ return false;
+ }
+ l2_iste_p = get_l2_iste(cs, cfg, id, &h);
+ if (!l2_iste_p) {
+ return false;
+ }
+ *l2_iste_p = FIELD_DP32(*l2_iste_p, L2_ISTE, ACTIVE, true);
+ if (FIELD_EX32(*l2_iste_p, L2_ISTE, HM) == GICV5_EDGE) {
+ *l2_iste_p = FIELD_DP32(*l2_iste_p, L2_ISTE, PENDING, false);
+ }
+ *iaffid = FIELD_EX32(*l2_iste_p, L2_ISTE, IAFFID);
+ put_l2_iste(cs, cfg, &h);
+ return true;
+}
+
void gicv5_activate(GICv5Common *cs, uint32_t id, GICv5Domain domain,
GICv5IntType type, bool virtual, uint32_t cpuidx)
{
@@ -1034,8 +1057,12 @@ void gicv5_activate(GICv5Common *cs, uint32_t id, GICv5Domain domain,
trace_gicv5_activate(domain_name[domain], inttype_name(type), virtual, id);
if (virtual) {
- qemu_log_mask(LOG_GUEST_ERROR, "gicv5_activate: tried to "
- "activate a virtual interrupt\n");
+ const GICv5ISTConfig *cfg = ist_for_vint(s, cs, domain, type, cpuidx);
+
+ if (!activate_for_ist(cs, cfg, id, &iaffid)) {
+ return;
+ }
+ irs_recalc_vhppi(s, s->res_vpe[cpuidx]->vmte, iaffid);
return;
}
@@ -1043,18 +1070,10 @@ void gicv5_activate(GICv5Common *cs, uint32_t id, GICv5Domain domain,
case GICV5_LPI:
{
const GICv5ISTConfig *cfg = &s->phys_lpi_config[domain];
- L2_ISTE_Handle h;
- uint32_t *l2_iste_p = get_l2_iste(cs, cfg, id, &h);
- if (!l2_iste_p) {
+ if (!activate_for_ist(cs, cfg, id, &iaffid)) {
return;
}
- *l2_iste_p = FIELD_DP32(*l2_iste_p, L2_ISTE, ACTIVE, true);
- if (FIELD_EX32(*l2_iste_p, L2_ISTE, HM) == GICV5_EDGE) {
- *l2_iste_p = FIELD_DP32(*l2_iste_p, L2_ISTE, PENDING, false);
- }
- iaffid = FIELD_EX32(*l2_iste_p, L2_ISTE, IAFFID);
- put_l2_iste(cs, cfg, &h);
break;
}
case GICV5_SPI:
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 67/77] hw/intc/arm_gicv5: Handle virtual=true in gicv5_request_config()
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (65 preceding siblings ...)
2026-12-03 11:11 ` [PATCH v2 66/77] hw/intc/arm_gicv5: Handle activation of a virtual interrupt Peter Maydell
@ 2026-12-03 11:11 ` Peter Maydell
2026-12-03 11:11 ` [PATCH v2 68/77] hw/intc/arm_gicv5: Implement irs_recalc_vhppi() Peter Maydell
` (9 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:11 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Support returning the config of a virtual interrupt; as with all the
config-setting functions, virtual interrupts can be dealt with
similarly to physical LPIs, just searching in a different IST.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/intc/arm_gicv5.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index f72a354cae1..f75c9ce0f8f 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -988,9 +988,19 @@ uint64_t gicv5_request_config(GICv5Common *cs, uint32_t id, GICv5Domain domain,
uint64_t icsr;
if (virtual) {
- qemu_log_mask(LOG_GUEST_ERROR, "gicv5_request_config: tried to "
- "read config of a virtual interrupt\n");
- return R_ICSR_F_MASK;
+ const GICv5ISTConfig *cfg = ist_for_vint(s, cs, domain, type, cpuidx);
+
+ if (!cfg) {
+ qemu_log_mask(LOG_GUEST_ERROR, "gicv5_request_config: tried to "
+ "read config of unreachable virtual %s %d\n",
+ inttype_name(type), id);
+ return R_ICSR_F_MASK;
+ }
+
+ icsr = l2_iste_to_icsr(cs, cfg, id);
+ trace_gicv5_request_config(domain_name[domain], inttype_name(type),
+ virtual, id, icsr);
+ return icsr;
}
switch (type) {
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 68/77] hw/intc/arm_gicv5: Implement irs_recalc_vhppi()
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (66 preceding siblings ...)
2026-12-03 11:11 ` [PATCH v2 67/77] hw/intc/arm_gicv5: Handle virtual=true in gicv5_request_config() Peter Maydell
@ 2026-12-03 11:11 ` Peter Maydell
2026-12-03 11:11 ` [PATCH v2 69/77] hw/intc/arm_gicv5: Recalculate vHPPIs on VIST and VPE mapping Peter Maydell
` (8 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:11 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Recalculate the highest priority pending virtual interrupt for a
specified (VM, VPE) when we're called for interrupt state changes.
Because vSPIs and vLPIs are both stored in ISTs, we can reuse our
existing lpi_cache_get_hppi() function by making it take an extra
type argument for which kind of interrupt it is working on.
The logic for generating a doorbell interrupt if necessary for
a non-resident VPE will be added in a later commit.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/intc/arm_gicv5.c | 43 ++++++++++++++++++++++++++++++++++++++++---
hw/intc/trace-events | 2 ++
2 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index f75c9ce0f8f..7efc9969f7b 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -29,6 +29,7 @@ typedef struct VMTE VMTE;
typedef struct VPE {
VMTE *vmte;
hwaddr vped_addr;
+ GICv5PendingIrq vhppi; /* vHPPI candidate, if any */
uint32_t cpuidx; /* CPU we're currently resident on */
uint32_t db_intid; /* doorbell interrupt ID */
uint8_t dbpm; /* doorbell priority mask */
@@ -193,6 +194,7 @@ static MemTxAttrs irs_txattrs(GICv5Common *cs, GICv5Domain domain)
typedef struct GetHPPIUserData {
GICv5PendingIrq *best;
uint32_t iaffid;
+ GICv5IntType type;
} GetHPPIUserData;
static void lpi_cache_get_hppi(gpointer key, gpointer value, gpointer user_data)
@@ -209,7 +211,7 @@ static void lpi_cache_get_hppi(gpointer key, gpointer value, gpointer user_data)
prio = FIELD_EX32(l2_iste, L2_ISTE, PRIORITY);
iaffid = FIELD_EX32(l2_iste, L2_ISTE, IAFFID);
if (iaffid == ud->iaffid && prio < ud->best->prio) {
- id = FIELD_DP32(id, INTID, TYPE, GICV5_LPI);
+ id = FIELD_DP32(id, INTID, TYPE, ud->type);
ud->best->intid = id;
ud->best->prio = prio;
}
@@ -258,6 +260,7 @@ static void irs_recalc_hppi(GICv5 *s, GICv5Domain domain, uint32_t iaffid)
ud.best = &best;
ud.iaffid = iaffid;
+ ud.type = GICV5_LPI;
g_hash_table_foreach(s->phys_lpi_config[domain].lpi_cache,
lpi_cache_get_hppi, &ud);
}
@@ -566,9 +569,42 @@ static void irs_recalc_vhppi(GICv5 *s, VMTE *vmte, uint32_t iaffid)
/*
* Recalculate the highest priority pending virtual interrupt for
* the specified VM and vCPU.
- *
- * TODO: we will implement this in a future commit.
*/
+ GICv5Common *cs = ARM_GICV5_COMMON(s);
+ GICv5PendingIrq best = GICV5_PENDING_IRQ_NONE;
+ GetHPPIUserData ud;
+ VPE *vpe = vpe_for_vpeid(vmte, iaffid);
+
+ if (!vpe) {
+ trace_gicv5_irs_recalc_vhppi_fail(domain_name[vmte->domain],
+ vmte->vmid, iaffid,
+ "IAFFID doesn't match valid VPEID");
+ return;
+ }
+
+ ud.best = &best;
+ ud.iaffid = iaffid;
+ if (vmte->lpi_ist.valid) {
+ ud.type = GICV5_LPI;
+ g_hash_table_foreach(vmte->lpi_ist.lpi_cache, lpi_cache_get_hppi, &ud);
+ }
+ if (vmte->spi_ist.valid) {
+ ud.type = GICV5_SPI;
+ g_hash_table_foreach(vmte->spi_ist.lpi_cache, lpi_cache_get_hppi, &ud);
+ }
+
+ trace_gicv5_irs_recalc_vhppi(domain_name[vmte->domain], vmte->vmid,
+ iaffid, best.intid, best.prio);
+
+ vpe->vhppi = best;
+
+ if (FIELD_EX32(cs->irs_cr0[vmte->domain], IRS_CR0, IRSEN) &&
+ vpe->vhppi.prio != PRIO_IDLE && vpe->resident) {
+ /* R_VBPZM: tell the PE about this vHPPI */
+ gicv5_forward_interrupt(cs->cpus[vpe->cpuidx], vmte->domain, true);
+ }
+
+ /* TODO: we may need to generate a doorbell interrupt. */
}
static const GICv5ISTConfig *ist_for_vint(GICv5 *s,
@@ -1467,6 +1503,7 @@ static void init_vpe_from_vpete(VPE *vpe, VMTE *vmte, uint64_t vpete)
vpe->vped_addr &= ~MAKE_64BIT_MASK(0, QEMU_GICV5_VPED_SZ);
/* Doorbell settings always start invalid */
vpe->db_valid = false;
+ vpe->vhppi = GICV5_PENDING_IRQ_NONE;
}
}
diff --git a/hw/intc/trace-events b/hw/intc/trace-events
index b7435a47b94..c3142fbc08e 100644
--- a/hw/intc/trace-events
+++ b/hw/intc/trace-events
@@ -246,6 +246,8 @@ gicv5_deactivate(const char *domain, const char *type, bool virtual, uint32_t id
gicv5_spi_state(uint32_t spi_id, bool level, bool pending, bool active) "GICv5 IRS SPI ID %u now level %d pending %d active %d"
gicv5_irs_recalc_hppi_fail(const char *domain, uint32_t iaffid, const char *reason) "GICv5 IRS %s IAFFID %u: no HPPI: %s"
gicv5_irs_recalc_hppi(const char *domain, uint32_t iaffid, uint32_t id, uint8_t prio) "GICv5 IRS %s IAFFID %u: new HPPI ID 0x%x prio %u"
+gicv5_irs_recalc_vhppi_fail(const char *domain, uint32_t vmid, uint32_t iaffid, const char *reason) "GICv5 IRS %s VMID %u IAFFID %u: no HPPI: %s"
+gicv5_irs_recalc_vhppi(const char *domain, uint32_t vmid, uint32_t iaffid, uint32_t id, uint8_t prio) "GICv5 IRS %s VMID %u IAFFID %u: new HPPI ID 0x%x prio %u"
gicv5_vmt_valid(const char *domain, uint64_t base, uint8_t vm_id_bits, bool structure) "GICv5 IRS %s VM table now valid: base 0x%" PRIx64 " vm_id_bits %u 2-level %d"
gicv5_vmt_invalid(const char *domain) "GICv5 IRS %s VM table no longer valid"
gicv5_vmap_l2_vmtr(const char *domain, uint32_t vmid) "GICv5 IRS %s VM ID %u now valid"
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 69/77] hw/intc/arm_gicv5: Recalculate vHPPIs on VIST and VPE mapping
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (67 preceding siblings ...)
2026-12-03 11:11 ` [PATCH v2 68/77] hw/intc/arm_gicv5: Implement irs_recalc_vhppi() Peter Maydell
@ 2026-12-03 11:11 ` Peter Maydell
2026-12-03 11:11 ` [PATCH v2 70/77] hw/intc/arm_gicv5: Add virtual support to gicv5_get_hppi() Peter Maydell
` (7 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:11 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
If the guest maps or unmaps the vLPI or vSPI for a VM via
IRS_VMAP_VISTR, this affects the vHPPI for every VPE in that VM, so
we need to recalculate it. Similarly, if the guest maps a VPE for a
VM via IRS_VMAP_VPER_WRITE, we need to calculate the initial vHPPI
for that VPE.
Add the calls to recalculate the vHPPI for these register writes.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/intc/arm_gicv5.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index 7efc9969f7b..3aae9357cef 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -607,6 +607,19 @@ static void irs_recalc_vhppi(GICv5 *s, VMTE *vmte, uint32_t iaffid)
/* TODO: we may need to generate a doorbell interrupt. */
}
+static void irs_recalc_all_vhppi_for_vm(GICv5 *s, VMTE *vmte)
+{
+ /* Recalculate the vHPPI for all VPEs in this VM */
+
+ for (uint32_t i = 0; i < (1 << vmte->vpe_id_bits); i++) {
+ VPE *vpe = &vmte->vpet[i];
+
+ if (vpe->valid) {
+ irs_recalc_vhppi(s, vmte, i);
+ }
+ }
+}
+
static const GICv5ISTConfig *ist_for_vint(GICv5 *s,
GICv5Common *cs,
GICv5Domain domain,
@@ -2128,6 +2141,9 @@ static void irs_vmap_vistr_write(GICv5 *s, GICv5Domain domain, uint64_t value)
default:
g_assert_not_reached();
}
+
+ irs_recalc_all_vhppi_for_vm(s, vmte);
+
return;
txfail:
@@ -2227,6 +2243,8 @@ static void irs_vmap_vper_write(GICv5 *s, GICv5Domain domain, uint64_t value)
init_vpe_from_vpete(&vmte->vpet[vpeid], vmte, vpete);
trace_gicv5_irs_vmap_vper_write(domain_name[domain], vmte->vmid, vpeid);
+ irs_recalc_vhppi(s, vmte, vpeid);
+
return;
txfail:
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 70/77] hw/intc/arm_gicv5: Add virtual support to gicv5_get_hppi()
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (68 preceding siblings ...)
2026-12-03 11:11 ` [PATCH v2 69/77] hw/intc/arm_gicv5: Recalculate vHPPIs on VIST and VPE mapping Peter Maydell
@ 2026-12-03 11:11 ` Peter Maydell
2026-12-03 11:11 ` [PATCH v2 71/77] hw/intc/arm_gicv5: Implement IRS_VPE_HPPIR Peter Maydell
` (6 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:11 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
If a CPU asks for the virtual HPPI for its resident VPE, return it.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/intc/arm_gicv5.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index 3aae9357cef..af00c099be5 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -349,11 +349,13 @@ GICv5PendingIrq gicv5_get_hppi(GICv5Common *cs, GICv5Domain domain,
assert(cpuidx < cs->num_cpus);
if (virtual) {
- /*
- * Until we implement virtualization there is never
- * an available virtual HPPI candidate.
- */
- return GICV5_PENDING_IRQ_NONE;
+ VPE *vpe = s->res_vpe[cpuidx];
+
+ if (!vpe || vpe->vmte->domain != domain) {
+ return GICV5_PENDING_IRQ_NONE;
+ }
+
+ return vpe->vhppi;
}
return s->hppi[domain][cpuidx];
}
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 71/77] hw/intc/arm_gicv5: Implement IRS_VPE_HPPIR
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (69 preceding siblings ...)
2026-12-03 11:11 ` [PATCH v2 70/77] hw/intc/arm_gicv5: Add virtual support to gicv5_get_hppi() Peter Maydell
@ 2026-12-03 11:11 ` Peter Maydell
2026-12-03 11:11 ` [PATCH v2 72/77] hw/intc/arm_gicv5: Implement ringing doorbells for VPEs Peter Maydell
` (5 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:11 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Now we are calculating and storing the vHPPI for each VPE, we can
implement IRS_VPE_HPPIR, which allows the guest to read the current
vHPPI for the VPE it has selected using IRS_VPE_SELR.
The specification allows the IRS to return the current vHPPI on
reads, rather than having to sample and hold the vHPPI at the point
when a VPE is selected by writing to IRS_VPE_SELR. We choose to do
this.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/intc/arm_gicv5.c | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index af00c099be5..078c90c765a 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -2319,6 +2319,21 @@ static void irs_vpe_selr_write(GICv5 *s, GICv5Domain domain, uint64_t value)
cs->irs_vpe_statusr[domain] = status;
}
+static uint64_t irs_vpe_hppir_read(GICv5 *s, GICv5Domain domain)
+{
+ /*
+ * The spec allows the IRS to update IRS_VPE_HPPIR as the VPE's
+ * vHPPI changes, rather than sampling it when IRS_VPE_SELR
+ * is written like e.g. IRS_VPE_DBR. That's what we choose to do.
+ */
+ VPE *vpe = vpe_from_selr(s, domain);
+
+ if (vpe && vpe->vhppi.prio != PRIO_IDLE) {
+ return vpe->vhppi.intid | R_IRS_VPE_HPPIR_HPPIV_MASK;
+ }
+ return 0;
+}
+
static void irs_vpe_dbr_write(GICv5 *s, GICv5Domain domain, uint64_t value)
{
GICv5Common *cs = ARM_GICV5_COMMON(s);
@@ -2617,6 +2632,22 @@ static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset,
*data = 0;
}
return true;
+ case A_IRS_VPE_HPPIR:
+ if (gicv5_domain_has_virt(cs, domain)) {
+ *data = extract64(irs_vpe_hppir_read(s, domain), 0, 32);
+ } else {
+ /* RAZ if no virt */
+ *data = 0;
+ }
+ return true;
+ case A_IRS_VPE_HPPIR + 4:
+ if (gicv5_domain_has_virt(cs, domain)) {
+ *data = extract64(irs_vpe_hppir_read(s, domain), 32, 32);
+ } else {
+ /* RAZ if no virt */
+ *data = 0;
+ }
+ return true;
case A_IRS_VPE_CR0:
/* RES0 when VIRT_ONE_N is not implemented */
*data = 0;
@@ -2963,6 +2994,14 @@ static bool config_readll(GICv5 *s, GICv5Domain domain, hwaddr offset,
*data = 0;
}
return true;
+ case A_IRS_VPE_HPPIR:
+ if (gicv5_domain_has_virt(cs, domain)) {
+ *data = irs_vpe_hppir_read(s, domain);
+ } else {
+ /* RAZ if no virt */
+ *data = 0;
+ }
+ return true;
}
return false;
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 72/77] hw/intc/arm_gicv5: Implement ringing doorbells for VPEs
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (70 preceding siblings ...)
2026-12-03 11:11 ` [PATCH v2 71/77] hw/intc/arm_gicv5: Implement IRS_VPE_HPPIR Peter Maydell
@ 2026-12-03 11:11 ` Peter Maydell
2026-12-03 11:11 ` [PATCH v2 73/77] hw/intc/arm_gicv5: Handle vHPPIs when IRS_CR0.IRSEN is toggled Peter Maydell
` (4 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:11 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
For the GICv5, if the IRS has a potential virtual interrupt for a VPE
which is not currently resident on some CPU, then it might need to
"ring the doorbell" by triggering a physical LPI to tell the
hypervisor that it ought to schedule the VPE so it can handle the
virtual interrupt.
The conditions when we need to do this are defined in the spec by
R_CWZMW: the VPE must be non-resident, have valid doorbell settings
that request a doorbell, and the pending virtual interrupt must be
high enough priority to satisfy the doorbell priority mask. We thus
need to reconsider whether to ring the doorbell when the vHPPI for
the VPE changes, when the VPE transitions between resident and
non-resident, and when the doorbell settings are changed.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/intc/arm_gicv5.c | 62 ++++++++++++++++++++++++++++++++++++--------
hw/intc/trace-events | 1 +
2 files changed, 52 insertions(+), 11 deletions(-)
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index 078c90c765a..fdecf8b5157 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -566,6 +566,53 @@ static hwaddr l1_vmte_addr(GICv5Common *cs, const GICv5VMTConfig *cfg,
return cfg->base + (l1_index * 8);
}
+static void irs_maybe_ring_doorbell(GICv5 *s, VPE *vpe)
+{
+ /*
+ * Ring the doorbell for the VPE if required by the conditions
+ * defined in R_CWZMW: the VPE must be non-resident, and have
+ * valid doorbell settings that actually request a doorbell, and
+ * a doorbell priority mask that allows it.
+ */
+ GICv5Common *cs = ARM_GICV5_COMMON(s);
+ GICv5ISTConfig *cfg;
+ L2_ISTE_Handle h;
+ uint32_t *l2_iste_p;
+ uint32_t iaffid;
+
+ if (!vpe->valid || vpe->resident || !vpe->db_valid || !vpe->db_req) {
+ return;
+ }
+ if (vpe->vhppi.prio > vpe->dbpm) {
+ return;
+ }
+ trace_gicv5_irs_ring_doorbell(domain_name[vpe->vmte->domain],
+ vpe->vmte->vmid, vpe->db_intid);
+ /*
+ * Generate the doorbell event, and clear db_req so we only do it once.
+ * This is a SET_EDGE event for an LPI, so (R_HHKMN) it forces the
+ * LPI's handling mode to Edge ond its Pending state to Pending.
+ * If the LPI is unreachable (no LPI table, etc) then we would
+ * report it in IRS_SWERR_STATUSR if we implemented error reporting;
+ * the doorbell is marked as no-longer-requested regardless.
+ */
+ vpe->db_req = false;
+
+ cfg = &s->phys_lpi_config[vpe->vmte->domain];
+ if (!cfg) {
+ return;
+ }
+ l2_iste_p = get_l2_iste(cs, cfg, vpe->db_intid, &h);
+ if (!l2_iste_p) {
+ return;
+ }
+ *l2_iste_p = FIELD_DP32(*l2_iste_p, L2_ISTE, PENDING, true);
+ *l2_iste_p = FIELD_DP32(*l2_iste_p, L2_ISTE, HM, GICV5_EDGE);
+ iaffid = FIELD_EX32(*l2_iste_p, L2_ISTE, IAFFID);
+ put_l2_iste(cs, cfg, &h);
+ irs_recalc_hppi(s, vpe->vmte->domain, iaffid);
+}
+
static void irs_recalc_vhppi(GICv5 *s, VMTE *vmte, uint32_t iaffid)
{
/*
@@ -606,7 +653,7 @@ static void irs_recalc_vhppi(GICv5 *s, VMTE *vmte, uint32_t iaffid)
gicv5_forward_interrupt(cs->cpus[vpe->cpuidx], vmte->domain, true);
}
- /* TODO: we may need to generate a doorbell interrupt. */
+ irs_maybe_ring_doorbell(s, vpe);
}
static void irs_recalc_all_vhppi_for_vm(GICv5 *s, VMTE *vmte)
@@ -1422,11 +1469,7 @@ bool gicv5_set_resident(GICv5Common *cs, GICv5Domain domain, bool valid,
trace_gicv5_set_non_resident(domain_name[domain], cpuidx, db, dbpm);
- /*
- * TODO: when we implement VPE doorbells, we should check whether
- * we should immediately generate a doorbell for a VPE that has
- * just been made non-resident.
- */
+ irs_maybe_ring_doorbell(s, vpe);
}
/*
@@ -2369,11 +2412,8 @@ static void irs_vpe_dbr_write(GICv5 *s, GICv5Domain domain, uint64_t value)
IRS_VPE_SELR, VPE_ID),
vpe->dbpm, vpe->db_intid, vpe->db_req);
- /*
- * TODO: when we implement VPE doorbells, check here whether
- * this config change means we should now generate a VPE
- * doorbell event for this VPE.
- */
+ /* This config change might mean we now need to ring the doorbell */
+ irs_maybe_ring_doorbell(s, vpe);
} else {
trace_gicv5_irs_vpe_dbr_write_nv(domain_name[domain], vpe->vmte->vmid,
FIELD_EX64(cs->irs_vpe_selr[domain],
diff --git a/hw/intc/trace-events b/hw/intc/trace-events
index c3142fbc08e..0f6fab89605 100644
--- a/hw/intc/trace-events
+++ b/hw/intc/trace-events
@@ -260,6 +260,7 @@ gicv5_irs_vpe_dbr_write(const char *domain, uint32_t vmid, uint32_t vpeid, uint8
gicv5_irs_vpe_dbr_write_nv(const char *domain, uint32_t vmid, uint32_t vpeid) "GICv5 IRS %s VM ID %u VPE %u IRS_VPE_DBR doorbell info no longer valid"
gicv5_set_resident(const char *domain, uint32_t vmid, uint32_t vpeid, uint32_t cpuidx) "GICv5 IRS %s VM ID %u VPE %u set_resident phys CPU idx %u: now resident"
gicv5_set_non_resident(const char *domain, uint32_t cpuidx, bool db, uint8_t dbpm) "GICv5 IRS %s set_resident phys CPU idx %u: now no resident VPE; db_req %d dbpm %u"
+gicv5_irs_ring_doorbell(const char *domain, uint32_t vmid, uint32_t db_intid) "GICv5 IRS %s VM ID %u: ringing doorbell LPI %u"
# arm_gicv5_common.c
gicv5_common_realize(uint32_t irsid, uint32_t num_cpus, uint32_t spi_base, uint32_t spi_irs_range, uint32_t spi_range) "GICv5 IRS realized: IRS ID %u, %u CPUs, SPI base %u, SPI IRS range %u, SPI range %u"
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 73/77] hw/intc/arm_gicv5: Handle vHPPIs when IRS_CR0.IRSEN is toggled
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (71 preceding siblings ...)
2026-12-03 11:11 ` [PATCH v2 72/77] hw/intc/arm_gicv5: Implement ringing doorbells for VPEs Peter Maydell
@ 2026-12-03 11:11 ` Peter Maydell
2026-12-03 11:11 ` [PATCH v2 74/77] hw/intc/arm_gicv5: Implement saving virtual interrupt state to guest memory Peter Maydell
` (3 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:11 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
The IRS_CR0.IRSEN bit is somewhat misleadingly named: it is not so
much an "enable the IRS" bit, but instead an "enable having the IRS
forward HPPIs to the CPU" bit. If it's 0 then the IRS still does
all its usual activities, apart from telling the CPUs about
interrupt candidates.
This applies also to virtual interrupts. For physical interrupts,
we implemented this by not calculating the pending HPPI when IRSEN
is zero, but for virtual interrupts we can't do it that way, for
several reasons:
* the vHPPI is visible to the guest via IRS_VPE_HPPIR
* whether we should ring a doorbell interrupt depends on the
vHPPI, and this still happens even when IRSEN is 0
So instead we need to check IRSEN in gicv5_get_hppi() and return
"no interrupt available" if it is 0. We also need to re-prod the
CPUs to ask the IRS about its HPPI candidates when IRSEN changes.
We could check IRSEN only inside the "is (virtual)" block of
gicv5_get_hppi(), but it's equivalent to do it unconditionally
(s->hppi[domain][cpuidx] will bo IRQ_NONE in that case), and
it's a bit clearer I think.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/intc/arm_gicv5.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index fdecf8b5157..af08601342e 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -341,6 +341,31 @@ static void irs_recall_hppis(GICv5 *s, GICv5Domain domain)
}
}
+static void irs_resend_vhppis(GICv5 *s, GICv5Domain domain)
+{
+ /*
+ * The IRS was enabled or disabled for this domain. In hardware
+ * this makes the IRS either forward or recall any pending vHPPI
+ * it had for a VPE resident on the CPU. For QEMU, we tell the CPU
+ * interface that it needs to ask the IRS about the status of
+ * virtual interrupts for any VPE that is currently resident
+ * (which will return either "none" or "here's the new one").
+ */
+ GICv5Common *cs = ARM_GICV5_COMMON(s);
+
+ if (!gicv5_domain_has_virt(cs, domain)) {
+ return;
+ }
+
+ for (int i = 0; i < cs->num_cpus; i++) {
+ VPE *vpe = s->res_vpe[i];
+
+ if (vpe && vpe->vmte->domain == domain) {
+ gicv5_forward_interrupt(cs->cpus[i], domain, true);
+ }
+ }
+}
+
GICv5PendingIrq gicv5_get_hppi(GICv5Common *cs, GICv5Domain domain,
bool virtual, uint32_t cpuidx)
{
@@ -348,6 +373,10 @@ GICv5PendingIrq gicv5_get_hppi(GICv5Common *cs, GICv5Domain domain,
assert(cpuidx < cs->num_cpus);
+ if (!FIELD_EX32(cs->irs_cr0[domain], IRS_CR0, IRSEN)) {
+ return GICV5_PENDING_IRQ_NONE;
+ }
+
if (virtual) {
VPE *vpe = s->res_vpe[cpuidx];
@@ -2738,6 +2767,8 @@ static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset,
} else {
irs_recall_hppis(s, domain);
}
+ /* IRSEN affects whether we should forward vHPPIs */
+ irs_resend_vhppis(s, domain);
return true;
case A_IRS_CR1:
*data = cs->irs_cr1[domain];
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 74/77] hw/intc/arm_gicv5: Implement saving virtual interrupt state to guest memory
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (72 preceding siblings ...)
2026-12-03 11:11 ` [PATCH v2 73/77] hw/intc/arm_gicv5: Handle vHPPIs when IRS_CR0.IRSEN is toggled Peter Maydell
@ 2026-12-03 11:11 ` Peter Maydell
2026-12-03 11:11 ` [PATCH v2 75/77] hw/intc/arm_gicv5: Implement reporting of Quiesced state Peter Maydell
` (2 subsequent siblings)
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:11 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
The IRS_SAVE_VMR register allows software to force the IRS to write
out any cached virtual interrupt state and configuration to the guest
memory data structures. (A hypervisor will use this as part of
saving the configuration of a VM for migration.)
When software writes the S bit to 1, we need to write out cached
information in our hash tables for the vLPI and vSPI for the VM. As
usual for QEMU, this operation is instantaneous from the guest's
point of view.
IRS_SAVE_VMR also has functionality for software to check that the
state of the VM didn't change during the save procedure. Because we
will have only one IRS, we take advantage of I_DSRQY's suggestion
that we make writing {0,1} to {S,Q} be a no-op. This means handling
of the reporting of the Quiesced state can be done entirely in the
implementation of IRS_SAVE_VM_STATUSR, which will be done in the
following commit.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
include/hw/intc/arm_gicv5_common.h | 1 +
hw/intc/arm_gicv5.c | 104 +++++++++++++++++++++++++++++
hw/intc/arm_gicv5_common.c | 1 +
hw/intc/trace-events | 1 +
4 files changed, 107 insertions(+)
diff --git a/include/hw/intc/arm_gicv5_common.h b/include/hw/intc/arm_gicv5_common.h
index d82cc23d10c..7bd6f557058 100644
--- a/include/hw/intc/arm_gicv5_common.h
+++ b/include/hw/intc/arm_gicv5_common.h
@@ -99,6 +99,7 @@ struct GICv5Common {
uint64_t irs_vpe_selr[NUM_GICV5_DOMAINS];
uint32_t irs_vpe_statusr[NUM_GICV5_DOMAINS];
uint64_t irs_vpe_dbr[NUM_GICV5_DOMAINS];
+ uint64_t irs_save_vmr[NUM_GICV5_DOMAINS];
/*
* Pointer to an array of state information for the SPIs. Array
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index af08601342e..0347f38e4c7 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -2450,6 +2450,75 @@ static void irs_vpe_dbr_write(GICv5 *s, GICv5Domain domain, uint64_t value)
}
}
+/* Data we need to pass to sync_l2_iste() */
+typedef struct SyncL2ISTEUserData {
+ GICv5Common *cs;
+ GICv5ISTConfig *cfg;
+} SyncL2ISTEUserData;
+
+static void sync_l2_iste(gpointer key, gpointer value, gpointer user_data)
+{
+ uint32_t id = GPOINTER_TO_INT(key);
+ uint32_t l2_iste = GPOINTER_TO_INT(value);
+ SyncL2ISTEUserData *ud = user_data;
+ hwaddr l2_iste_addr;
+
+ if (get_l2_iste_addr(ud->cs, ud->cfg, id, &l2_iste_addr)) {
+ write_l2_iste_mem(ud->cs, ud->cfg, l2_iste_addr, l2_iste);
+ }
+}
+
+static void irs_sync_ist_to_memory(GICv5Common *cs, GICv5ISTConfig *cfg)
+{
+ /*
+ * Push any information in the IST hash table out to guest memory
+ * (but don't drop the hash table entries). Writeback errors are
+ * ignored. Compare put_l2_iste()'s code for writing out data whon
+ * it removes L2_ISTE entries from the hash table.
+ */
+ SyncL2ISTEUserData ud;
+
+ if (!cfg->valid) {
+ return;
+ }
+
+ ud.cs = cs;
+ ud.cfg = cfg;
+
+ g_hash_table_foreach(cfg->lpi_cache, sync_l2_iste, &ud);
+}
+
+static void irs_save_vmr_write(GICv5 *s, GICv5Domain domain, uint64_t value)
+{
+ GICv5Common *cs = ARM_GICV5_COMMON(s);
+ GICv5VMTConfig *cfg = &s->vmt_config[domain];
+ uint32_t vmid;
+ VMTE *vmte;
+
+ cs->irs_save_vmr[domain] = value;
+
+ if (!FIELD_EX64(cs->irs_save_vmr[domain], IRS_SAVE_VMR, S)) {
+ return;
+ }
+
+ /* Write out vLPI and vSPI config to guest memory */
+ vmid = FIELD_EX64(cs->irs_save_vmr[domain], IRS_SAVE_VMR, VM_ID);
+
+ if (!cfg->valid || vmid >= (1 << cfg->vm_id_bits)) {
+ return;
+ }
+
+ vmte = g_hash_table_lookup(cfg->vm_cache, GINT_TO_POINTER(vmid));
+ if (!vmte) {
+ return;
+ }
+
+ trace_gicv5_irs_save_vmr_write(domain_name[domain], vmid);
+
+ irs_sync_ist_to_memory(cs, &vmte->lpi_ist);
+ irs_sync_ist_to_memory(cs, &vmte->spi_ist);
+}
+
static void spi_sample(GICv5SPIState *spi)
{
/*
@@ -2717,6 +2786,22 @@ static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset,
*data = 0;
}
return true;
+ case A_IRS_SAVE_VMR:
+ if (gicv5_domain_has_virt(cs, domain)) {
+ *data = extract64(cs->irs_save_vmr[domain], 0, 32);
+ } else {
+ /* RAZ if no virt */
+ *data = 0;
+ }
+ return true;
+ case A_IRS_SAVE_VMR + 4:
+ if (gicv5_domain_has_virt(cs, domain)) {
+ *data = extract64(cs->irs_save_vmr[domain], 32, 32);
+ } else {
+ /* RAZ if no virt */
+ *data = 0;
+ }
+ return true;
case A_IRS_VPE_CR0:
/* RES0 when VIRT_ONE_N is not implemented */
*data = 0;
@@ -2914,6 +2999,14 @@ static bool config_writel(GICv5 *s, GICv5Domain domain, hwaddr offset,
irs_vpe_dbr_write(s, domain,
deposit64(cs->irs_vpe_dbr[domain], 32, 32, data));
return true;
+ case A_IRS_SAVE_VMR:
+ irs_save_vmr_write(s, domain,
+ deposit64(cs->irs_save_vmr[domain], 0, 32, data));
+ return true;
+ case A_IRS_SAVE_VMR + 4:
+ irs_save_vmr_write(s, domain,
+ deposit64(cs->irs_save_vmr[domain], 32, 32, data));
+ return true;
case A_IRS_VPE_CR0:
/* RES0 when VIRT_ONE_N is not implemented */
return true;
@@ -3073,6 +3166,14 @@ static bool config_readll(GICv5 *s, GICv5Domain domain, hwaddr offset,
*data = 0;
}
return true;
+ case A_IRS_SAVE_VMR:
+ if (gicv5_domain_has_virt(cs, domain)) {
+ *data = cs->irs_save_vmr[domain];
+ } else {
+ /* RAZ/WI if no virt */
+ *data = 0;
+ }
+ return true;
}
return false;
@@ -3109,6 +3210,9 @@ static bool config_writell(GICv5 *s, GICv5Domain domain, hwaddr offset,
case A_IRS_VPE_DBR:
irs_vpe_dbr_write(s, domain, data);
return true;
+ case A_IRS_SAVE_VMR:
+ irs_save_vmr_write(s, domain, data);
+ return true;
}
return false;
diff --git a/hw/intc/arm_gicv5_common.c b/hw/intc/arm_gicv5_common.c
index 50365c4dfe6..6627c16a949 100644
--- a/hw/intc/arm_gicv5_common.c
+++ b/hw/intc/arm_gicv5_common.c
@@ -116,6 +116,7 @@ static void gicv5_common_reset_hold(Object *obj, ResetType type)
memset(cs->irs_vmap_vper, 0, sizeof(cs->irs_vmap_vper));
memset(cs->irs_vpe_selr, 0, sizeof(cs->irs_vpe_selr));
memset(cs->irs_vpe_dbr, 0, sizeof(cs->irs_vpe_dbr));
+ memset(cs->irs_save_vmr, 0, sizeof(cs->irs_save_vmr));
for (int i = 0; i < NUM_GICV5_DOMAINS; i++) {
cs->irs_vpe_statusr[i] = R_IRS_VPE_STATUSR_IDLE_MASK;
diff --git a/hw/intc/trace-events b/hw/intc/trace-events
index 0f6fab89605..e2bf5131d2b 100644
--- a/hw/intc/trace-events
+++ b/hw/intc/trace-events
@@ -261,6 +261,7 @@ gicv5_irs_vpe_dbr_write_nv(const char *domain, uint32_t vmid, uint32_t vpeid) "G
gicv5_set_resident(const char *domain, uint32_t vmid, uint32_t vpeid, uint32_t cpuidx) "GICv5 IRS %s VM ID %u VPE %u set_resident phys CPU idx %u: now resident"
gicv5_set_non_resident(const char *domain, uint32_t cpuidx, bool db, uint8_t dbpm) "GICv5 IRS %s set_resident phys CPU idx %u: now no resident VPE; db_req %d dbpm %u"
gicv5_irs_ring_doorbell(const char *domain, uint32_t vmid, uint32_t db_intid) "GICv5 IRS %s VM ID %u: ringing doorbell LPI %u"
+gicv5_irs_save_vmr_write(const char *domain, uint32_t vmid) "GICv5 IRS %s VM ID %u saving IST data to memory"
# arm_gicv5_common.c
gicv5_common_realize(uint32_t irsid, uint32_t num_cpus, uint32_t spi_base, uint32_t spi_irs_range, uint32_t spi_range) "GICv5 IRS realized: IRS ID %u, %u CPUs, SPI base %u, SPI IRS range %u, SPI range %u"
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 75/77] hw/intc/arm_gicv5: Implement reporting of Quiesced state
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (73 preceding siblings ...)
2026-12-03 11:11 ` [PATCH v2 74/77] hw/intc/arm_gicv5: Implement saving virtual interrupt state to guest memory Peter Maydell
@ 2026-12-03 11:11 ` Peter Maydell
2026-12-03 11:11 ` [PATCH v2 76/77] hw/intc/arm_gicv5: Implement no-passthrough IRS_SPI_VMR Peter Maydell
2026-12-03 11:11 ` [PATCH v2 77/77] hw/arm/virt: allow virtualization=on with gicv5 Peter Maydell
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:11 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Implement the IRS_SAVE_VM_STATUSR register and its reporting of
Quiescent state. For QEMU, save-vm operations are instantaneous from
the point of view of the guest, and so the IDLE bit is (as usual for
these status registers) always 1. The other bit in the register is
Q, which reports whether the VM is still in the Quiesced state
following some previous write of 1 to IRS_SAVE_VMR.S.
As I_DSRQY notes, the set of conditions when Q is UNKNOWN give us
the latitude to implement it as "always returns the current state,
and the guest doesn't need to trigger an update by writing
IRS_SAVE_VMR.{S,Q} to {0,1}".
A VM is Quiesced (D_MGVXX) if:
* no VPEs in the VM are resident
* there is no change in the Pending state of any virtual interrupt
* there is no change to the number of valid VPEs in the VM
* the VM does not become invalid
We can therefore track Quiesced state via a flag in our VMTE struct,
which is set to 'true' on an IRS_SAVE_VM_STATUSR S=1 write, and then
flipped to false for changes in Pending state, number of VPEs, and so
on. IRS_SAVE_VM_STATUSR.Q returns that flag value, or 0 if the
VM selected by IRS_SAVE_VMR.VM_ID isn't valid.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/intc/arm_gicv5.c | 77 ++++++++++++++++++++++++++++++++++++++++++--
hw/intc/trace-events | 1 +
2 files changed, 75 insertions(+), 3 deletions(-)
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index 0347f38e4c7..b04e6d4981d 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -50,6 +50,7 @@ struct VMTE {
uint32_t vmid;
uint8_t vpe_id_bits;
GICv5Domain domain;
+ bool quiesced;
/* We don't cache the VMD_ADDR as we don't use VMDs */
/* We don't cache VALID: the existence of this struct implies VALID=1 */
};
@@ -908,6 +909,8 @@ void gicv5_set_pending(GICv5Common *cs, uint32_t id, bool pending,
if (!set_pending_for_ist(cs, cfg, id, pending, &iaffid)) {
return;
}
+ /* changing Pending state breaks Quiesced */
+ vmte->quiesced = false;
irs_recalc_vhppi(s, vmte, iaffid);
return;
}
@@ -1165,7 +1168,8 @@ uint64_t gicv5_request_config(GICv5Common *cs, uint32_t id, GICv5Domain domain,
static bool activate_for_ist(GICv5Common *cs,
const GICv5ISTConfig *cfg,
uint32_t id,
- uint32_t *iaffid)
+ uint32_t *iaffid,
+ bool *changed_pending)
{
L2_ISTE_Handle h;
uint32_t *l2_iste_p;
@@ -1179,6 +1183,9 @@ static bool activate_for_ist(GICv5Common *cs,
*l2_iste_p = FIELD_DP32(*l2_iste_p, L2_ISTE, ACTIVE, true);
if (FIELD_EX32(*l2_iste_p, L2_ISTE, HM) == GICV5_EDGE) {
*l2_iste_p = FIELD_DP32(*l2_iste_p, L2_ISTE, PENDING, false);
+ if (changed_pending) {
+ *changed_pending = true;
+ }
}
*iaffid = FIELD_EX32(*l2_iste_p, L2_ISTE, IAFFID);
put_l2_iste(cs, cfg, &h);
@@ -1195,10 +1202,15 @@ void gicv5_activate(GICv5Common *cs, uint32_t id, GICv5Domain domain,
if (virtual) {
const GICv5ISTConfig *cfg = ist_for_vint(s, cs, domain, type, cpuidx);
+ bool changed_pending = false;
- if (!activate_for_ist(cs, cfg, id, &iaffid)) {
+ if (!activate_for_ist(cs, cfg, id, &iaffid, &changed_pending)) {
return;
}
+ /* Changing Pending breaks Quiesced state */
+ if (changed_pending) {
+ s->res_vpe[cpuidx]->vmte->quiesced = false;
+ }
irs_recalc_vhppi(s, s->res_vpe[cpuidx]->vmte, iaffid);
return;
}
@@ -1208,7 +1220,7 @@ void gicv5_activate(GICv5Common *cs, uint32_t id, GICv5Domain domain,
{
const GICv5ISTConfig *cfg = &s->phys_lpi_config[domain];
- if (!activate_for_ist(cs, cfg, id, &iaffid)) {
+ if (!activate_for_ist(cs, cfg, id, &iaffid, NULL)) {
return;
}
break;
@@ -1478,6 +1490,10 @@ bool gicv5_set_resident(GICv5Common *cs, GICv5Domain domain, bool valid,
vpe->cpuidx = cpuidx;
s->res_vpe[cpuidx] = vpe;
+
+ /* Making a VPE resident breaks Quiesced state */
+ vmte->quiesced = false;
+
trace_gicv5_set_resident(domain_name[domain], vmid, vpeid, cpuidx);
} else {
vpe = s->res_vpe[cpuidx];
@@ -2317,6 +2333,9 @@ static void irs_vmap_vper_write(GICv5 *s, GICv5Domain domain, uint64_t value)
init_vpe_from_vpete(&vmte->vpet[vpeid], vmte, vpete);
trace_gicv5_irs_vmap_vper_write(domain_name[domain], vmte->vmid, vpeid);
+ /* Adding a VPE to the VM breaks it being Quiesced */
+ vmte->quiesced = false;
+
irs_recalc_vhppi(s, vmte, vpeid);
return;
@@ -2514,11 +2533,55 @@ static void irs_save_vmr_write(GICv5 *s, GICv5Domain domain, uint64_t value)
}
trace_gicv5_irs_save_vmr_write(domain_name[domain], vmid);
+ /*
+ * Writing S = 1 is the start of a check for if the VM stays
+ * Quiesced. If some VPE is currently resident than the VM is not
+ * Quiesced. Other state changes later may also flip it to
+ * not-Quiesced.
+ */
+ vmte->quiesced = true;
+ for (uint32_t i = 0; i < (1 << vmte->vpe_id_bits); i++) {
+ VPE *vpe = &vmte->vpet[i];
+
+ if (vpe->valid && vpe->resident) {
+ vmte->quiesced = false;
+ break;
+ }
+ }
irs_sync_ist_to_memory(cs, &vmte->lpi_ist);
irs_sync_ist_to_memory(cs, &vmte->spi_ist);
}
+static uint64_t irs_save_vm_statusr_read(GICv5 *s, GICv5Domain domain)
+{
+ GICv5Common *cs = ARM_GICV5_COMMON(s);
+ GICv5VMTConfig *cfg = &s->vmt_config[domain];
+ uint32_t vmid;
+ VMTE *vmte;
+ /* IDLE always set; Q set only if VM is Quiesced */
+ uint64_t value = R_IRS_SAVE_VM_STATUSR_IDLE_MASK;
+
+ vmid = FIELD_EX64(cs->irs_save_vmr[domain], IRS_SAVE_VMR, VM_ID);
+
+ if (!cfg->valid || vmid >= (1 << cfg->vm_id_bits)) {
+ return value;
+ }
+
+ vmte = g_hash_table_lookup(cfg->vm_cache, GINT_TO_POINTER(vmid));
+ if (!vmte) {
+ return value;
+ }
+
+ trace_gicv5_irs_save_vm_statusr_read(domain_name[domain],
+ vmid, vmte->quiesced);
+
+ if (vmte->quiesced) {
+ value |= R_IRS_SAVE_VM_STATUSR_Q_MASK;
+ }
+ return value;
+}
+
static void spi_sample(GICv5SPIState *spi)
{
/*
@@ -2802,6 +2865,14 @@ static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset,
*data = 0;
}
return true;
+ case A_IRS_SAVE_VM_STATUSR:
+ if (gicv5_domain_has_virt(cs, domain)) {
+ *data = irs_save_vm_statusr_read(s, domain);
+ } else {
+ /* RAZ if no virt */
+ *data = 0;
+ }
+ return true;
case A_IRS_VPE_CR0:
/* RES0 when VIRT_ONE_N is not implemented */
*data = 0;
diff --git a/hw/intc/trace-events b/hw/intc/trace-events
index e2bf5131d2b..c60daf70bd2 100644
--- a/hw/intc/trace-events
+++ b/hw/intc/trace-events
@@ -262,6 +262,7 @@ gicv5_set_resident(const char *domain, uint32_t vmid, uint32_t vpeid, uint32_t c
gicv5_set_non_resident(const char *domain, uint32_t cpuidx, bool db, uint8_t dbpm) "GICv5 IRS %s set_resident phys CPU idx %u: now no resident VPE; db_req %d dbpm %u"
gicv5_irs_ring_doorbell(const char *domain, uint32_t vmid, uint32_t db_intid) "GICv5 IRS %s VM ID %u: ringing doorbell LPI %u"
gicv5_irs_save_vmr_write(const char *domain, uint32_t vmid) "GICv5 IRS %s VM ID %u saving IST data to memory"
+gicv5_irs_save_vm_statusr_read(const char *domain, uint32_t vmid, bool quiesced) "GICv5 IRS %s VM ID %u reporting quiesced %d"
# arm_gicv5_common.c
gicv5_common_realize(uint32_t irsid, uint32_t num_cpus, uint32_t spi_base, uint32_t spi_irs_range, uint32_t spi_range) "GICv5 IRS realized: IRS ID %u, %u CPUs, SPI base %u, SPI IRS range %u, SPI range %u"
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 76/77] hw/intc/arm_gicv5: Implement no-passthrough IRS_SPI_VMR
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (74 preceding siblings ...)
2026-12-03 11:11 ` [PATCH v2 75/77] hw/intc/arm_gicv5: Implement reporting of Quiesced state Peter Maydell
@ 2026-12-03 11:11 ` Peter Maydell
2026-12-03 11:11 ` [PATCH v2 77/77] hw/arm/virt: allow virtualization=on with gicv5 Peter Maydell
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:11 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
The GICv5 spec recommends, but does not require, that the IRS
implements passthrough of SPIs to VMs. Linux does not currently use
SPI passthrough.
For our initial implementation, implement the IRS_SPI_VMR register as
RAZ/WI, corresponding to "passthrough is not supported for any SPI",
and with a LOG_UNIMP message if the guest attempts to configure
passthrough for an SPI.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/intc/arm_gicv5.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/hw/intc/arm_gicv5.c b/hw/intc/arm_gicv5.c
index b04e6d4981d..b1947c21fec 100644
--- a/hw/intc/arm_gicv5.c
+++ b/hw/intc/arm_gicv5.c
@@ -2582,6 +2582,24 @@ static uint64_t irs_save_vm_statusr_read(GICv5 *s, GICv5Domain domain)
return value;
}
+static void irs_spi_vmr_write(GICv5 *s, GICv5Domain domain)
+{
+ GICv5Common *cs = ARM_GICV5_COMMON(s);
+
+ /* RAZ/WI if no virt */
+ if (!gicv5_domain_has_virt(cs, domain)) {
+ return;
+ }
+
+ /*
+ * The spec merely recommends that passthrough of SPIs is supported.
+ * For an SPI where passthrough is not supported, IRS_SPI_VMR is
+ * RAZ/WI (indicating "not passed through" and not permitting it to
+ * be set to "passed through"). Log the missing functionality.
+ */
+ qemu_log_mask(LOG_UNIMP, "QEMU GICv5 SPI passthrough not implemented\n");
+}
+
static void spi_sample(GICv5SPIState *spi)
{
/*
@@ -2873,6 +2891,11 @@ static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset,
*data = 0;
}
return true;
+ case A_IRS_SPI_VMR:
+ case A_IRS_SPI_VMR + 4:
+ /* Always RAZ/WI until we implement SPI passthrough */
+ *data = 0;
+ return true;
case A_IRS_VPE_CR0:
/* RES0 when VIRT_ONE_N is not implemented */
*data = 0;
@@ -3078,6 +3101,12 @@ static bool config_writel(GICv5 *s, GICv5Domain domain, hwaddr offset,
irs_save_vmr_write(s, domain,
deposit64(cs->irs_save_vmr[domain], 32, 32, data));
return true;
+ case A_IRS_SPI_VMR:
+ irs_spi_vmr_write(s, domain);
+ return true;
+ case A_IRS_SPI_VMR + 4:
+ irs_spi_vmr_write(s, domain);
+ return true;
case A_IRS_VPE_CR0:
/* RES0 when VIRT_ONE_N is not implemented */
return true;
@@ -3245,6 +3274,10 @@ static bool config_readll(GICv5 *s, GICv5Domain domain, hwaddr offset,
*data = 0;
}
return true;
+ case A_IRS_SPI_VMR:
+ /* Always RAZ/WI until we implement SPI passthrough */
+ *data = 0;
+ return true;
}
return false;
@@ -3284,6 +3317,8 @@ static bool config_writell(GICv5 *s, GICv5Domain domain, hwaddr offset,
case A_IRS_SAVE_VMR:
irs_save_vmr_write(s, domain, data);
return true;
+ case A_IRS_SPI_VMR:
+ irs_spi_vmr_write(s, domain);
}
return false;
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread* [PATCH v2 77/77] hw/arm/virt: allow virtualization=on with gicv5
2026-12-03 11:10 [PATCH v2 00/77] hw/intc/arm_gicv5: Implement virtualization support Peter Maydell
` (75 preceding siblings ...)
2026-12-03 11:11 ` [PATCH v2 76/77] hw/intc/arm_gicv5: Implement no-passthrough IRS_SPI_VMR Peter Maydell
@ 2026-12-03 11:11 ` Peter Maydell
76 siblings, 0 replies; 99+ messages in thread
From: Peter Maydell @ 2026-12-03 11:11 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Philippe Mathieu-Daudé, Manos Pitsidianakis
Now that the GICv5 implementation supports virtualization, we can
remove the check in the virt board that prevented you from
using 'virtualization=on' with 'gic-version=x-5'.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/arm/virt.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 0b11f7e328c..3c99a8e0641 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -3032,9 +3032,8 @@ static void machvirt_init(MachineState *machine)
exit(1);
}
- if ((vms->virt || vms->secure) &&
- vms->gic_version == VIRT_GIC_VERSION_5) {
- error_report("mach-virt: GICv5 currently supports EL1 only");
+ if (vms->secure && vms->gic_version == VIRT_GIC_VERSION_5) {
+ error_report("mach-virt: GICv5 currently supports EL1 and EL2 only");
exit(1);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 99+ messages in thread