hw/intc/arm_gicv5: Implement virtualization support
cover hw/intc/arm_gicv5: Implement virtualization support
This patchset adds virtualization support to our GICv5 model, and lets the "virt" board use -machine gic-version=x-5,virtualization=on.
Virtualization in the GICv5 is more complicated than it is in GICv3. This is because in GICv3 virtualization is mostly delegated to software, and only the CPU interface has hardware virtualization support. In GICv5 the hardware does a lot more of the work, so virtualization support is needed in both the CPU interface and the IRS.
I've structured this patchset as:
* initial preparatory and bug-fixing patches
* add virt support to the cpu interface
* add virt support to the IRS
* remove the check in virt that stops the user enabling virt
The first 11 patches have been on this list already; I've copied across Reviewed-by tags for those patches which got them.
The current spec for the GICv5 is at
https://support.arm.com/documentation/aes0070/00eac0/
The kernel support for using GICv5 virtualization is not yet in mainline, but it has landed in the kvmarm/next tree:
https://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git next Similarly kvmtool support to run the inner guest is still work in progress, but the tree at
https://gitlab.arm.com/linux-arm/kvmtool-sb.git gicv5_wip will work with the kvmarm/next tree.
This series can pass the kernel's vgic_v5 selftest, and boot an inner guest to userspace with kvmtool.
In an ideal world I'd like to land this for 11.2, but I appreciate that it's a lot of code to review and only two weeks til softfreeze; we'll see how it goes.
If you want a git branch of this I've pushed the patchset to
https://gitlab.com/pm215/qemu.git gicv5-virt
thanks
-- PMM
Peter Maydell (86):
hw/intc/arm_gicv5: Make IRS_IDR0 reads return actual value, not 0 hw/intc/arm_gicv5: Ignore low bits in IRS_IST_BASER.ADDR hw/intc/arm_gicv5: Ignore low bits in L1_ISTE.L2_ADDR hw/intc/arm_gicv5: Regularize spacing in config_readl() switch hw/intc/arm_gicv5: Use cached IRS_IST_BASER.VALID state hw/intc/arm_gicv5: Free memory in finalize
target/arm: GICv5 cpuif: Use arm_cpu_set_irq() to set IRQ/FIQ status target/arm: Only allow GICv5 on CPUs without AArch32 at EL1..3 hw/intc/arm_gicv5: Pass CPU index to CPU interface hw/intc/arm_gicv5: Pass cpuidx rather than iaffid in gicv5_get_hppi() hw/intc/arm_gicv5: Use correct type for value in lpi_cache_get_hppi() hw/intc/arm_gicv5: Relax QEMU_GICV5_MIN_LPI_ID_BITS to 0 target/arm: GICv5 cpuif: Implement ICH_APR_EL2
target/arm: GICv5 cpuif: Implement ICH_PPI_{ENABLE,PEND,ACTIVE} regs target/arm: GICv5 cpuif: Implement ICH_PPI_PRIORITYR<n>_EL2 target/arm: GICv5 cpuif: Implement ICH_PPI_DVIR<n>_EL2 target/arm: GICv5 cpuif: Implement ICH_VCTLR_EL2 and ICH_VCMR_EL2 target/arm: GICv5 cpuif: Implement GIC fine-grained trap registers target/arm: GICv5 cpuif: Mark GIC registers for fine-grained traps target/arm: GICv5 cpuif: Mark GIC insns for fine-grained traps target/arm: GICv5 cpuif: Implement ICC_SRE_ELx
target/arm: GICv5 cpuif: Implement ICH_PPI_HVIR<n>_EL2 target/arm: GICv5 cpuif: Implement ICV_APR_EL1
target/arm: GICv5 cpuif: Implement ICV_CR0_EL1
target/arm: GICv5 cpuif: Implement ICV_PCR_EL1
target/arm: GICv5 cpuif: Implement ICV_PPI_ENABLER<n>_EL1 target/arm: GICv5 cpuif: Implement ICV_PPI_PRIORITYR<n>_EL1 target/arm: GICv5 cpuif: Add comment about ICV_PPI_HMR<n>_EL1 target/arm: GICv5 cpuif: Implement ICV_PPI_CACTIVER<n>_EL1,
ICV_PPI_SACTIVER<n>_EL1
target/arm: GICv5 cpuif: Implement ICV_PPI_CPENDR<n>_EL1,
ICV_PPI_SPENDR<n>_EL1 target/arm: GICv5 cpuif: Calculate current virtual PPI HPPI target/arm: GICv5 cpuif: Add virtual support to IRS/cpuif HPPI APIs target/arm: GICv5 cpuif: Implement ICV_HPPIR_EL1 target/arm: GICv5 cpuif: Implement gicv5_update_virq_vfiq() target/arm: GICv5 cpuif: Implement ICH_CONTEXTR_EL2 target/arm: GICv5 cpuif: ask the GIC for the virtual HPPI target/arm: GICv5 cpuif: Handle LD/VD insns when setting
domain/virtual args
target/arm: GICv5 cpuif: Handle virtual interrupts for GIC CDEOI target/arm: GICv5 cpuif: Handle virtual interrupts for GIC CDDI target/arm: GICv5 cpuif: Handle virtual interrupts for GICR CDIA,
CDNMIA
target/arm: GICv5 cpuif: Handle GIC VDPEND VM argument target/arm: GICv5 cpuif: Implement GIC VDnnn insns target/arm: GICv5 cpuif: Implement GIC LDnnn insns target/arm: GICv5 cpuif: Handle PPI injection in vPPI pending reads target/arm: GICv5 cpuif: Handle PPI injection in vPPI pending writes target/arm: GICv5 cpuif: Handle injected PPIs in GICR CDIA target/arm: GICv5 cpuif: Update on HCR_EL2.{NV,NV1} and SCR_EL3.NS
changes
target/arm: GICv5 cpuif: Update VFIQ/VIRQ when direct-injected PPIs
change
hw/intc: Move GICv5 register and data definitions into a header hw/intc/arm_gicv5: Correct offset for IRS_VMT_STATUSR hw/intc/arm_gicv5: Ask CPUs whether IRS needs virtualization support hw/intc/arm_gicv5: Indicate virtualization in ID registers hw/intc/arm_gicv5: Implement IRS_VMT_BASER and IRS_VMT_STATUSR hw/intc/arm_gicv5: IMplement IRS_VMT_CFGR hw/intc/arm_gicv5: Implement IRS_VMAP_L2_VMTR hw/intc/arm_gicv5: Implement IRS_VMAP_VMR hw/intc/arm_gicv5: Factor out code to fill in a GICv5ISTConfig hw/intc/arm_gicv5: Cache info about valid VMs in a hashtable hw/intc/arm_gicv5: Populate VM cache when VM table becomes valid hw/intc/arm_gicv5: Implement IRS_VMAP_VISTR hw/intc/arm_gicv5: Factor out "make an L2 IST valid" function hw/intc/arm_gicv5: Implement IRS_VMAP_L2_VISTR hw/intc/arm_gicv5: Cache VPE table information hw/intc/arm_gicv5: Implement IRS_VMAP_VPER hw/intc/arm_gicv5: Implement IRS_VPE_SELR and IRS_VPE_STATUSR hw/intc/arm_gicv5: Implement IRS_VPE_DBR hw/intc/arm_gicv5: Implement IRS_VPE_CR0 hw/intc/arm_gicv5: Implement gicv5_set_resident() hw/intc/arm_gicv5: Take cpuidx for stream commands on virtual
interrupts
hw/intc/arm_gicv5: Handle virtual=true in gicv5_set_priority() hw/intc/arm_gicv5: Handle virtual=true for setting enabled, pending,
handling
hw/intc/arm_gicv5: Handle virtual=true for setting pending hw/intc/arm_gicv5: Handle virtual=true in gicv5_set_target() hw/intc/arm_gicv5: Handle virtual=true in gicv5_deactivate() hw/intc/arm_gicv5: Handle activation of a virtual interrupt hw/intc/arm_gicv5: Handle virtual=true in gicv5_request_config() hw/intc/arm_gicv5: Implement irs_recalc_vhppi() hw/intc/arm_gicv5: Recalculate vHPPIs on VIST and VPE mapping hw/intc/arm_gicv5: Add virtual support to gicv5_get_hppi() hw/intc/arm_gicv5: Implement IRS_VPE_HPPIR hw/intc/arm_gicv5: Implement ringing doorbells for VPEs hw/intc/arm_gicv5: Handle vHPPIs when IRS_CR0.IRSEN is toggled hw/intc/arm_gicv5: Implement saving virtual interrupt state to guest
memory
hw/intc/arm_gicv5: Implement reporting of Quiesced state hw/intc/arm_gicv5: Implement no-passthrough IRS_SPI_VMR hw/arm/virt: allow virtualization=on with gicv5
hw/arm/virt.c | 5 +- hw/intc/arm_gicv5.c | 2554 +++++++++++++++++++++++----- hw/intc/arm_gicv5_common.c | 30 +- hw/intc/trace-events | 19 +- include/hw/intc/arm_gicv5.h | 18 + include/hw/intc/arm_gicv5_common.h | 40 +- include/hw/intc/arm_gicv5_regs.h | 325 ++++ include/hw/intc/arm_gicv5_stream.h | 81 +- target/arm/cpregs.h | 85 +- target/arm/cpu-features.h | 8 + target/arm/cpu.c | 72 +- target/arm/cpu.h | 33 +- target/arm/gicv5-stubs.c | 8 + target/arm/helper.c | 23 +- target/arm/internals.h | 23 + target/arm/tcg/gicv5-cpuif.c | 1390 +++++++++++++-- target/arm/tcg/trace-events | 10 +- 17 files changed, 4089 insertions(+), 635 deletions(-) create mode 100644 include/hw/intc/arm_gicv5_regs.h
Signature · 1 line
2.43.0
PATCH 1/86 hw/intc/arm_gicv5: Make IRS_IDR0 reads return actual value, not 0
IN the code for handling reads of IRS_IDR0, we carefully construct the correct value starting with cs->irs_idr0 and adjusting it. However, we never actually write the final value into *data, so the guest will always see zero.
We didn't notice this before, because Linux happens to not care about this register value except to check for the presence of virtualization.
--- hw/intc/arm_gicv5.c | 1 + 1 file changed, 1 insertion(+)
hw/intc/arm_gicv5.c +1 -0
@@ -1433,6 +1433,7 @@ static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset,/* ...which means VIRT_ONE_N is also RES0 */ v &= ~R_IRS_IDR0_VIRT_ONE_N_MASK ; } + *data = v;return true;case A_IRS_IDR1 :
Signature · 1 line
2.43.0
Re: [PATCH 01/86] hw/intc/arm_gicv5: Make IRS_IDR0 reads return actual value, not 0
Quoted 9 lines · Peter Maydell
IN the code for handling reads of
IRS_IDR0, we carefully construct the correct value starting withcs->irs_idr0and adjusting it. However, we never actually write the final value into *data, so the guest will always see zero.We didn't notice this before, because Linux happens to not care about this register value except to check for the presence of virtualization.
Quoted 8 lines
Fixes 405ad2e76f13254 ("hw/intc/arm_gicv5: Implement IRS ID regs")Reviewed-by Jim MacArthur<[email protected]>Reviewed-by Philippe Mathieu-Daudé<[email protected]>Signed-off-by Peter Maydell<[email protected]>--- hw/intc/arm_gicv5.c | 1 + 1 file changed, 1 insertion(+)
r~
PATCH 2/86 hw/intc/arm_gicv5: Ignore low bits in IRS_IST_BASER.ADDR
In reply to Peter MaydellThe IRS_IST_BASER.ADDR documentation says:
For IRS_IST_CFGR.STRUCTURE = 0:
Bits[N:0] of the resulting address are 0 where N depends on the ISTSZ and LPI_ID_BITS fields in IRS_IST_CFGR as follows:
N = Max(5, (ISTSZ + 1) + LPI_ID_BITS)
For IRS_IST_CFGR.STRUCTURE = 1:
Bits[N:0] of the resulting address are 0 where N depends on L2SZ, ISTSZ, and LPI_ID_BITS in IRS_IST_CFGR as follows:
N = Max(5, LPI_ID_BITS - ((10 - ISTSZ) + (2 * L2SZ)) + 2)
This enforces that the IST is aligned to the size of the IST table, or to a 64-byte boundary if the table is smaller than 64 bytes, even if the guest programs the low bits in the ADDR field to specify an insufficiently aligned address.
We were missing this check, and instead trusted the guest-provided address to be sufficiently aligned already; add the alignment enforcement.
The GICv5 spec defines the masking to be used with the expressions quoted above, which work with the raw field values from the IRS_IST_CFGR register; these simplify down to some straightforward expressions based on the sanitized values we've already extracted form those fields. You can get to the expressions we use here either by working through the simplification of the GIC spec expressions, or from first principles (the number of bits needed for the size of the table in bytes is the number of bits that index it plus the number of bits specifying the size of an individual table entry).
--- hw/intc/arm_gicv5.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
hw/intc/arm_gicv5.c +28 -0
@@ -1313,6 +1313,7 @@ static void irs_ist_baser_write(GICv5 *s, GICv5Domain domain, uint64_t value)*/ GICv5ISTConfig *cfg = &s->phys_lpi_config[domain];uint8_t istbits, l2bits, l2_idx_bits; +int tableszbits;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 );
@@ -1359,6 +1360,33 @@ static void irs_ist_baser_write(GICv5 *s, GICv5Domain domain, uint64_t value) cfg->l2_idx_bits = l2_idx_bits; cfg->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); +if (!cfg->lpi_cache) {/* * Keys are GINT_TO_POINTER(intid), so we want the g_direct_hash
Signature · 1 line
2.43.0
Re: [PATCH 02/86] hw/intc/arm_gicv5: Ignore low bits in IRS_IST_BASER.ADDR
Quoted 31 lines · Peter Maydell
The IRS_IST_BASER.ADDR documentation says:
For IRS_IST_CFGR.STRUCTURE = 0:
Bits[N:0] of the resulting address are 0 where N depends on the ISTSZ andLPI_ID_BITSfields inIRS_IST_CFGRas follows:N = Max(5, (ISTSZ + 1) + LPI_ID_BITS)For IRS_IST_CFGR.STRUCTURE = 1:
Bits[N:0] of the resulting address are 0 where N depends on L2SZ, ISTSZ, and
LPI_ID_BITSinIRS_IST_CFGRas follows:N = Max(5, LPI_ID_BITS - ((10 - ISTSZ) + (2 * L2SZ)) + 2)This enforces that the IST is aligned to the size of the IST table, or to a 64-byte boundary if the table is smaller than 64 bytes, even if the guest programs the low bits in the ADDR field to specify an insufficiently aligned address.
We were missing this check, and instead trusted the guest-provided address to be sufficiently aligned already; add the alignment enforcement.
The GICv5 spec defines the masking to be used with the expressions quoted above, which work with the raw field values from the
IRS_IST_CFGRregister; these simplify down to some straightforward expressions based on the sanitized values we've already extracted form those fields. You can get to the expressions we use here either by working through the simplification of the GIC spec expressions, or from first principles (the number of bits needed for the size of the table in bytes is the number of bits that index it plus the number of bits specifying the size of an individual table entry).
Quoted 4 lines
Signed-off-by Peter Maydell<[email protected]>--- hw/intc/arm_gicv5.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
r~
PATCH 3/86 hw/intc/arm_gicv5: Ignore low bits in L1_ISTE.L2_ADDR
In reply to Peter MaydellThe GICv5 spec defines that an L2 IST is always aligned to its size, by stating that bits [N:0] of the address are 0 where
N = 11 + (2 * L2SZ)
We were missing this check, and only aligning by applying R_L1_ISTE_L2_ADDR_MASK, so we would only enforce 4K alignment even if the L2 IST was 16K or 64K.
Add the missing masking of low bits. We already needed to calculate the number of bits needed to index each byte in the L2 table, so add it to the GICv5ISTConfig to save having to re-calculate it later.
--- hw/intc/arm_gicv5.c | 6 ++++++ include/hw/intc/arm_gicv5.h | 1 + 2 files changed, 7 insertions(+)
hw/intc/arm_gicv5.c +6 -0
@@ -595,6 +595,11 @@ static bool get_l2_iste_addr(GICv5Common *cs, const GICv5ISTConfig *cfg,return false; } l2_base = l1_iste &R_L1_ISTE_L2_ADDR_MASK ; +/* +* The effective base address of the L2 table is always +* aligned to the size of the L2 table. +*/ + l2_base &= ~MAKE_64BIT_MASK (0 , cfg->l2bits); id =extract32 (id,0 , cfg->l2_idx_bits); }else {/* 1-level table */
@@ -1358,6 +1363,7 @@ static void irs_ist_baser_write(GICv5 *s, GICv5Domain domain, uint64_t value) 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],IRS_IST_CFGR ,STRUCTURE );
include/hw/intc/arm_gicv5.h +1 -0
@@ -23,6 +23,7 @@ typedef struct GICv5ISTConfig {uint8_t id_bits;/* number of bits in an ID for this table */ uint8_t l2_idx_bits;/* number of ID bits that index into L2 table */ uint8_t istsz;/* L2 ISTE size in bytes */ +uint8_t l2bits;/* bits needed to index L2 table in bytes */ bool structure;/* true if using 2-level table */ bool valid;/* true if this table is valid and usable */ /* This caches IST information about pending LPIs */
Signature · 1 line
2.43.0
Re: [PATCH 03/86] hw/intc/arm_gicv5: Ignore low bits in L1_ISTE.L2_ADDR
Quoted 12 lines · Peter Maydell
The GICv5 spec defines that an L2 IST is always aligned to its size, by stating that bits [N:0] of the address are 0 where
N = 11 + (2 * L2SZ)We were missing this check, and only aligning by applying
R_L1_ISTE_L2_ADDR_MASK, so we would only enforce 4K alignment even if the L2 IST was 16K or 64K.Add the missing masking of low bits. We already needed to calculate the number of bits needed to index each byte in the L2 table, so add it to the GICv5ISTConfig to save having to re-calculate it later.
Quoted 5 lines
Signed-off-by Peter Maydell<[email protected]>--- hw/intc/arm_gicv5.c | 6 ++++++ include/hw/intc/arm_gicv5.h | 1 + 2 files changed, 7 insertions(+)
r~
PATCH 4/86 hw/intc/arm_gicv5: Regularize spacing in config_readl() switch
In reply to Peter MaydellIn this file we don't put blank lines between cases in switches, except that for the switch in config_readl() we've written it half with blank lines and half without. Delete the blank lines to make it consistent with itself and the rest of the file.
--- hw/intc/arm_gicv5.c | 15 --------------- 1 file changed, 15 deletions(-)
hw/intc/arm_gicv5.c +0 -15
@@ -1469,53 +1469,41 @@ static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset, } *data = v;return true; -case A_IRS_IDR1 : *data = cs->irs_idr1;return true; -case A_IRS_IDR2 : *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;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;return true; -case A_IRS_IDR5 : *data = cs->irs_idr5;return true; -case A_IRS_IDR6 : *data = cs->irs_idr6;return true; -case A_IRS_IDR7 : *data = cs->irs_idr7;return true; -case A_IRS_IIDR : *data = cs->irs_iidr;return true; -case A_IRS_AIDR : *data = cs->irs_aidr;return true; -case A_IRS_IST_BASER : *data =extract64 (cs->irs_ist_baser[domain],0 ,32 );return true; -case A_IRS_IST_BASER +4 : *data =extract64 (cs->irs_ist_baser[domain],32 ,32 );return true; -case A_IRS_IST_STATUSR :/* * For QEMU writes to IRS_IST_BASER and IRS_MAP_L2_ISTR take effect
@@ -1523,11 +1511,9 @@ static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset,*/ *data =R_IRS_IST_STATUSR_IDLE_MASK ;return true; -case A_IRS_IST_CFGR : *data = cs->irs_ist_cfgr[domain];return true; -case A_IRS_SPI_STATUSR :/* * QEMU writes to IRS_SPI_{CFGR,DOMAINR,SELR,VMR} take effect
@@ -1538,7 +1524,6 @@ static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset, v =FIELD_DP32 (v,IRS_SPI_STATUSR ,IDLE ,1 ); *data = v;return true; -case A_IRS_SPI_CFGR : {GICv5SPIState *spi =spi_for_selr (cs, domain);
Signature · 1 line
2.43.0
Re: [PATCH 04/86] hw/intc/arm_gicv5: Regularize spacing in config_readl() switch
Quoted 10 lines · Peter Maydell
In this file we don't put blank lines between cases in switches, except that for the switch in
config_readl()we've written it half with blank lines and half without. Delete the blank lines to make it consistent with itself and the rest of the file.Signed-off-by Peter Maydell<[email protected]>Reviewed-by Philippe Mathieu-Daudé<[email protected]>--- hw/intc/arm_gicv5.c | 15 --------------- 1 file changed, 15 deletions(-)
r~
PATCH 5/86 hw/intc/arm_gicv5: Use cached IRS_IST_BASER.VALID state
In reply to Peter MaydellWhen the guest writes to IRS_IST_BASER we effectively cache the value of the VALID bit in the GICv5ISTConfig valid field entry. In a few places we check whether the IST is valid by doing a bit extract on the register value; switch those to look at cfg->structure instead.
--- hw/intc/arm_gicv5.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
hw/intc/arm_gicv5.c +3 -4
@@ -1223,8 +1223,7 @@ static void irs_map_l2_istr_write(GICv5 *s, GICv5Domain domain, uint64_t value)uint64_t l1_iste;MemTxResult res; -if (!FIELD_EX64 (cs->irs_ist_baser[domain],IRS_IST_BASER ,VALID ) || - !cfg->structure) { +if (!cfg->valid || !cfg->structure) {/* WI if no IST set up or it is not 2-level */ return ; }
@@ -1294,7 +1293,7 @@ static void irs_ist_baser_write(GICv5 *s, GICv5Domain domain, uint64_t value) {GICv5Common *cs =ARM_GICV5_COMMON (s); -if (FIELD_EX64 (cs->irs_ist_baser[domain],IRS_IST_BASER ,VALID )) { +if (s->phys_lpi_config[domain].valid) {/* If VALID is set, ADDR is RO and we can only update VALID */ bool valid =FIELD_EX64 (value,IRS_IST_BASER ,VALID );if (valid) {
@@ -1605,7 +1604,7 @@ static bool config_writel(GICv5 *s, GICv5Domain domain, hwaddr offset, deposit64(cs->irs_ist_baser[domain], 32, 32, data));return true;case A_IRS_IST_CFGR : -if (FIELD_EX64 (cs->irs_ist_baser[domain],IRS_IST_BASER ,VALID )) { +if (s->phys_lpi_config[domain].valid) {qemu_log_mask (LOG_GUEST_ERROR ,"guest tried to write IRS_IST_CFGR for %s config frame " "while IST_BASER.VALID set\n" , domain_name[domain]);
Signature · 1 line
2.43.0
PATCH 6/86 hw/intc/arm_gicv5: Free memory in finalize
In reply to Peter MaydellThe GICv5 allocates memory and creates hashtables during realize and as part of its operation. Free those resources in finalize.
Since the GICv5 is created at QEMU startup and remains in existence for the lifetime of the process, this isn't an in-practice leak, only a theoretical one.
--- hw/intc/arm_gicv5.c | 11 +++++++++++ hw/intc/arm_gicv5_common.c | 3 +++ 2 files changed, 14 insertions(+)
hw/intc/arm_gicv5.c +11 -0
@@ -1971,6 +1971,17 @@ static void gicv5_init(Object *obj)static void gicv5_finalize (Object *obj) { +GICv5 *s =ARM_GICV5 (obj); + +for (int i =0 ; i <NUM_GICV5_DOMAINS ; i++) { +GHashTable *ht = s->phys_lpi_config[i].lpi_cache; + +if (ht) { +g_hash_table_destroy (ht); + } + +g_free (s->hppi[i]); + } }static void gicv5_class_init (ObjectClass *oc,const void *data)
hw/intc/arm_gicv5_common.c +3 -0
@@ -112,6 +112,9 @@ static void gicv5_common_init(Object *obj)static void gicv5_common_finalize (Object *obj) { +GICv5Common *cs =ARM_GICV5_COMMON (obj); + +g_free (cs->spi); }static void gicv5_common_realize (DeviceState *dev,Error **errp)
Signature · 1 line
2.43.0
PATCH 7/86 target/arm: GICv5 cpuif: Use arm_cpu_set_irq() to set IRQ/FIQ status
In reply to Peter MaydellCurrently the GICv5 cpu interface directly calls cpu_interrupt() and cpu_reset_interrupt() to raise and lower IRQ and FIQ. This is almost but not exactly what we do for GICv2/GICv3 external GPIO IRQ/FIQ line changes. Those are handled by arm_cpu_set_irq(), and as well as calling cpu_interrupt() or cpu_reset_interrupt() they also update env->irq_line_state.
For IRQ and FIQ it doesn't matter whether we set and clear the bits in irq_line_state, because nothing looks at them. But for VIRQ and VFIQ it will matter, because VIRQ and VFIQ are the logical OR of the line state and some bits in HCR_EL2. We're going to need to call arm_cpu_set_irq() for VIRQ and VFIQ; for consistency, handle IRQ and FIQ that way too.
Since arm_cpu_set_irq() is now a function called from other parts of the CPU code, we make its first argument a properly typed one, with a wrapper taking void* for when we need to use it as a qemu_irq_handler.
--- target/arm/cpu.c | 14 +++++++++++--- target/arm/internals.h | 14 ++++++++++++++ target/arm/tcg/gicv5-cpuif.c | 35 ++++------------------------------- 3 files changed, 29 insertions(+), 34 deletions(-)
target/arm/cpu.c +11 -3
@@ -808,9 +808,8 @@ void arm_emulate_firmware_reset(CPUState *cpustate, int target_el) #ifndef CONFIG_USER_ONLY -static void arm_cpu_set_irq(void *opaque, int irq, int level) +void arm_cpu_set_irq(ARMCPU *cpu, int irq, int level) { - ARMCPU *cpu = opaque; CPUARMState *env = &cpu->env; CPUState *cs = CPU(cpu); static const int mask[] = {
@@ -862,6 +861,15 @@ static void arm_cpu_set_irq(void *opaque, int irq, int level) } } +/* +* Wrapper of arm_cpu_set_irq with the right argument types to be a +* qemu_irq_handler function for our inbound GPIO lines. +*/ +static void arm_cpu_gpio_set_irq (void *opaque,int irq,int level) +{ +arm_cpu_set_irq (opaque, irq, level); +} +static bool arm_cpu_internal_is_big_endian (CPUState *cs) {ARMCPU *cpu =ARM_CPU (cs);
@@ -1265,7 +1273,7 @@ static void arm_cpu_initfn(Object *obj)*/ qdev_init_gpio_in (DEVICE (cpu), arm_cpu_kvm_set_irq,6 ); }else { -qdev_init_gpio_in (DEVICE (cpu), arm_cpu_set_irq,6 ); +qdev_init_gpio_in (DEVICE (cpu), arm_cpu_gpio_set_irq,6 ); } qdev_init_gpio_out(DEVICE(cpu), cpu->gt_timer_outputs,
target/arm/internals.h +14 -0
@@ -1886,6 +1886,20 @@ void define_gcs_cpregs(ARMCPU *cpu);/* Add the cpreg definitions for OMAP CP15 regs */ void define_omap_cp_regs (ARMCPU *cpu); +#ifndef CONFIG_USER_ONLY +/** +* arm_cpu_set_irq: Assert or clear an IRQ/FIQ/etc interrupt line +* @cpu: CPU to set interrupt on +* @irq: one of the ARM_CPU_IRQ/ARM_CPU_FIQ/ARM_CPU_VIRQ/etc values +* @level: 0 to deassert, non-zero to assert +* +* This function is called by the qemu_irq_handler function +* when IRQ etc are real inbound GPIO lines; it is also called +* directly by the GICv5 CPU interface. +*/ +void arm_cpu_set_irq (ARMCPU *cpu,int irq,int level); +#endif +/* Add the cpreg definitions for the GICv5 CPU interface */ void define_gicv5_cpuif_regs (ARMCPU *cpu);
target/arm/tcg/gicv5-cpuif.c +4 -31
@@ -173,33 +173,6 @@ static GICv5PendingIrq gic_hppi(CPUARMState *env, GICv5Domain domain)return best; } -static void cpu_interrupt_update (CPUARMState *env,int irqtype,bool new_state) -{ -CPUState *cs =env_cpu (env); - -/* -* OPT: calling cpu_interrupt() and cpu_reset_interrupt() has the -* correct behaviour, but is not optimal for the case where we're -* setting the interrupt line to the same level it already has. -* -* Clearing an already clear interrupt is free (it's just doing an -* atomic AND operation). Signalling an already set interrupt is a -* bit less ideal (it might unnecessarily kick the CPU). -* -* We could potentially use cpu_test_interrupt(), like -* arm_cpu_update_{virq,vfiq,vinmi,vserr}, since we always hold -* the BQL here; or perhaps there is an abstraction we could -* provide in the core code that all these places could call. -* -* For now, this is simple and definitely correct. -*/ -if (new_state) { -cpu_interrupt (cs, irqtype); - }else { -cpu_reset_interrupt (cs, irqtype); - } -} -static void gicv5_update_irq_fiq (CPUARMState *env) {/*
@@ -243,12 +216,12 @@ static void gicv5_update_irq_fiq(CPUARMState *env)/* * Unlike a GICv3 or GICv2, there is no external IRQ or FIQ line * to the CPU. Instead we directly signal the interrupt via -* cpu_interrupt()/cpu_reset_interrupt(). +* arm_cpu_set_irq(). */ trace_gicv5_update_irq_fiq (irq, fiq, superpriority); -cpu_interrupt_update (env,CPU_INTERRUPT_HARD , irq); -cpu_interrupt_update (env,CPU_INTERRUPT_FIQ , fiq); -cpu_interrupt_update (env,CPU_INTERRUPT_NMI , superpriority); +arm_cpu_set_irq (env_archcpu (env),ARM_CPU_IRQ , irq); +arm_cpu_set_irq (env_archcpu (env),ARM_CPU_FIQ , fiq); +arm_cpu_set_irq (env_archcpu (env),ARM_CPU_NMI , superpriority); }static void gic_recalc_ppi_hppi (CPUARMState *env)
Signature · 1 line
2.43.0
Re: [PATCH 07/86] target/arm: GICv5 cpuif: Use arm_cpu_set_irq() to set IRQ/FIQ status
Quoted 56 lines · Peter Maydell
Currently the GICv5 cpu interface directly calls
cpu_interrupt()andcpu_reset_interrupt()to raise and lower IRQ and FIQ. This is almost but not exactly what we do for GICv2/GICv3 external GPIO IRQ/FIQ line changes. Those are handled byarm_cpu_set_irq(), and as well as callingcpu_interrupt()orcpu_reset_interrupt()they also updateenv->irq_line_state.For IRQ and FIQ it doesn't matter whether we set and clear the bits in
irq_line_state, because nothing looks at them. But for VIRQ and VFIQ it will matter, because VIRQ and VFIQ are the logical OR of the line state and some bits inHCR_EL2. We're going to need to callarm_cpu_set_irq()for VIRQ and VFIQ; for consistency, handle IRQ and FIQ that way too.Since
arm_cpu_set_irq()is now a function called from other parts of the CPU code, we make its first argument a properly typed one, with a wrapper taking void* for when we need to use it as aqemu_irq_handler.Reviewed-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Peter Maydell <[email protected]>--- target/arm/cpu.c | 14 +++++++++++--- target/arm/internals.h | 14 ++++++++++++++ target/arm/tcg/gicv5-cpuif.c | 35 ++++------------------------------- 3 files changed, 29 insertions(+), 34 deletions(-)target/arm/tcg/gicv5-cpuif.c +0
-20@@ -173,33 +173,6 @@ static GICv5PendingIrq gic_hppi(CPUARMState *env, GICv5Domain domain)return best; } -static void cpu_interrupt_update (CPUARMState *env,int irqtype,bool new_state) -{ -CPUState *cs =env_cpu (env); - -/* -* OPT: calling cpu_interrupt() and cpu_reset_interrupt() has the -* correct behaviour, but is not optimal for the case where we're -* setting the interrupt line to the same level it already has. -* -* Clearing an already clear interrupt is free (it's just doing an -* atomic AND operation). Signalling an already set interrupt is a -* bit less ideal (it might unnecessarily kick the CPU). -* -* We could potentially use cpu_test_interrupt(), like -* arm_cpu_update_{virq,vfiq,vinmi,vserr}, since we always hold -* the BQL here; or perhaps there is an abstraction we could -* provide in the core code that all these places could call. -* -* For now, this is simple and definitely correct. -*/
target/arm/tcg/gicv5-cpuif.c static GICv5PendingIrq gic_hppi(CPUARMState *env, GICv5Domain domain) · line 178
Quoted 10 lines
target/arm/tcg/gicv5-cpuif.c +0
-7-if (new_state) { -cpu_interrupt (cs, irqtype); - }else { -cpu_reset_interrupt (cs, irqtype); - } -} -static void gicv5_update_irq_fiq (CPUARMState *env) {/*
Revisiting this comment:
* For the moment, we do not consider preemptive interrupts,
* because these only occur when there is a HPPI of sufficient
* priority for another interrupt domain, and we only support EL1
* and the NonSecure interrupt domain currently.
Is there a way to assert preemptive interrupts are not accessed by the guest?
Quoted 17 lines
target/arm/tcg/gicv5-cpuif.c +4
-4@@ -243,12 +216,12 @@ static void gicv5_update_irq_fiq(CPUARMState *env)/* * Unlike a GICv3 or GICv2, there is no external IRQ or FIQ line * to the CPU. Instead we directly signal the interrupt via -* cpu_interrupt()/cpu_reset_interrupt(). +* arm_cpu_set_irq(). */ trace_gicv5_update_irq_fiq (irq, fiq, superpriority); -cpu_interrupt_update (env,CPU_INTERRUPT_HARD , irq); -cpu_interrupt_update (env,CPU_INTERRUPT_FIQ , fiq); -cpu_interrupt_update (env,CPU_INTERRUPT_NMI , superpriority); +arm_cpu_set_irq (env_archcpu (env),ARM_CPU_IRQ , irq); +arm_cpu_set_irq (env_archcpu (env),ARM_CPU_FIQ , fiq); +arm_cpu_set_irq (env_archcpu (env),ARM_CPU_NMI , superpriority); }static void gic_recalc_ppi_hppi (CPUARMState *env)
Re: [PATCH 07/86] target/arm: GICv5 cpuif: Use arm_cpu_set_irq() to set IRQ/FIQ status
Quoted 9 lines · Philippe Mathieu-Daudé
Revisiting this comment:
* For the moment, we do not consider preemptive interrupts,
* because these only occur when there is a HPPI of sufficient
* priority for another interrupt domain, and we only support EL1
* and the NonSecure interrupt domain currently.Is there a way to assert preemptive interrupts are not accessed by the guest?
They just don't exist when there's only a single interrupt domain, so there's nothing to check. (Preemptive interrupts are either those for the EL3 domain, or else those for a domain configured via the EL3-only register ICC_CR0_EL3.) The check in virt.c that says "don't allow GICv5 when EL3 is enabled" is what keeps a guest out of this not-yet-implemented part of the spec.
thanks
-- PMM
PATCH 8/86 target/arm: Only allow GICv5 on CPUs without AArch32 at EL1..3
In reply to Peter MaydellWe previously allowed the GICv5 on any 64-bit CPU, with a hack where enabling the GICv5 silently disabled AArch32 for EL1..3.
Now that we have a separate 'max-v8' and 'max-v9' where max-v9 correctly doesn't implement AArch32 at EL1..3, we can fix the "when do we expose the has_gcie property" condition so that we only allow the GICv5 when AArch32 doesn't exist above EL0, and remove the hack disabling AArch32.
We could instead have defined a new ARM_FEATURE_V9, but "allow the feature to be present on CPUs where it doesn't actively break anything" fits the way we've generally handled things in QEMU, and it avoids having a new V9 feature bit that we only use for this one thing and where it's not clear when we should be setting it for KVM, hvf, etc accelerators.
In practice the only CPUs which will allow GICv5 now are max, max-v9 and a64fx.
--- target/arm/cpu-features.h | 8 ++++++++ target/arm/cpu.c | 37 +++++++------------------------------ 2 files changed, 15 insertions(+), 30 deletions(-)
target/arm/cpu-features.h +8 -0
@@ -1130,6 +1130,14 @@ static inline bool isar_feature_aa64_aa32_el3(const ARMISARegisters *id)return FIELD_EX64_IDREG (id,ID_AA64PFR0 ,EL3 ) >=2 ; } +static inline bool isar_feature_aa64_aa32_above_el0 (const ARMISARegisters *id) +{ +/* True if any EL above EL0 has AArch32 support */ +return isar_feature_aa64_aa32_el1 (id) || +isar_feature_aa64_aa32_el2 (id) || +isar_feature_aa64_aa32_el3 (id); +} +static inline bool isar_feature_aa64_ras (const ARMISARegisters *id) {return FIELD_EX64_IDREG (id,ID_AA64PFR0 ,RAS ) !=0 ;
target/arm/cpu.c +7 -30
@@ -1594,8 +1594,13 @@ static void arm_cpu_post_init(Object *obj) &cpu->rvbar_prop, OBJ_PROP_FLAG_READWRITE); -/* We only allow GICv5 on a 64-bit v8 CPU */ -if (arm_feature (&cpu->env,ARM_FEATURE_AARCH64 )) { +/* +* We only allow GICv5 on a CPU with no AArch32 support above EL0 +* (which is typically a v9 CPU), because GICv5 defines no AArch32 +* system registers to control it. +*/ +if (arm_feature (&cpu->env,ARM_FEATURE_AARCH64 ) && + !cpu_isar_feature (aa64_aa32_above_el0, cpu)) {qdev_property_add_static (DEVICE (obj), &arm_cpu_has_gcie_property); } }
@@ -2249,34 +2254,6 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)/* Report FEAT_GCIE in our ID registers if property was set */ FIELD_DP64_IDREG (isar,ID_AA64PFR2 ,GCIE , cpu->has_gcie); -if (cpu_isar_feature (aa64_gcie, cpu)) { -if (!arm_feature (env,ARM_FEATURE_AARCH64 )) { -/* -* We only create the have_gcie property for AArch64 CPUs, -* but the user might have tried aarch64=off with has_gcie=on. -*/ -error_setg (errp,"Cannot both enable has_gcie and disable aarch64" ); -return ; - } - -/* -* FEAT_GCIE implies Armv9, which implies no AArch32 above EL0. -* Usually we don't strictly insist on this kind of feature -* dependency, but in this case we enforce it, because the -* GICv5 CPU interface has no AArch32 versions of its system -* registers, so interrupts wouldn't work if we allowed AArch32 -* in EL1 or above. Downgrade "AArch32 and AArch64" to "AArch64". -*/ -if (cpu_isar_feature (aa64_aa32_el3, cpu)) { -FIELD_DP64_IDREG (isar,ID_AA64PFR0 ,EL3 ,1 ); - } -if (cpu_isar_feature (aa64_aa32_el2, cpu)) { -FIELD_DP64_IDREG (isar,ID_AA64PFR0 ,EL2 ,1 ); - } -if (cpu_isar_feature (aa64_aa32_el1, cpu)) { -FIELD_DP64_IDREG (isar,ID_AA64PFR0 ,EL1 ,1 ); - } - }if (cpu_isar_feature (aa64_mte, cpu)) {/*
Signature · 1 line
2.43.0
PATCH 9/86 hw/intc/arm_gicv5: Pass CPU index to CPU interface
In reply to Peter MaydellIn a real hardware GICv5, the IRS knows which CPU is talking to it because each IRS<->cpuif link is a separate 1:1 connection. In QEMU's implementation, the cpuif code calls functions like gicv5_set_priority(), and currently we usually don't pass anything to tell the IRS which cpuif is making the call, because mostly the IRS doesn't need to care. There are a few places where it does need to know, notably in gicv5_get_hppi(). Here we have the cpuif pass its IAFFID; the IRS then looks that up by doing a linear search of the cpu_iaffids[] array to get the index of the CPU.
For virtualization, many of the stream commands which don't currently need to say which cpuif is making the call will have to start doing so, because changing the state of a virtual interrupt requires the IRS to look up the VPE which is resident on the calling cpuif. This makes the IAFFID->cpuidx lookup seem increasingly awkward.
Change gicv5_set_gicv5state() to pass the IRS's CPU index value for the cpuif as well as the guest-visible IAFFID, and make the stream functions identify the cpuif by CPU index rather than IAFFID, to avoid the unnecessary IAFFID->cpuidx lookup.
As this is now three GICv5-related things that we are keeping in the CPU state struct, we push them into a sub-struct to keep them tidy.
--- hw/intc/arm_gicv5_common.c | 2 +- include/hw/intc/arm_gicv5_stream.h | 6 ++++-- target/arm/cpu.c | 10 ++++++---- target/arm/cpu.h | 10 ++++++---- target/arm/tcg/gicv5-cpuif.c | 6 +++--- 5 files changed, 20 insertions(+), 14 deletions(-)
hw/intc/arm_gicv5_common.c +1 -1
@@ -176,7 +176,7 @@ 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])) { +if (!gicv5_set_gicv5state (cs->cpus[i], cs, cs->cpu_iaffids[i], i)) {error_setg (errp,"CPU %d (IAFFID 0x%x) does not implement GICv5 CPU interface" , i, cs->cpu_iaffids[i]);
include/hw/intc/arm_gicv5_stream.h +4 -2
@@ -20,7 +20,8 @@ typedef struct GICv5Common GICv5Common;* gicv5_set_gicv5state * @cpu: CPU object to tell about its IRS * @cs: the GIC IRS it is connected to -* @iaffid: the IAFFID of this CPU +* @iaffid: the IAFFID of this CPU (guest-visible) +* @cpuidx: the index of this CPU for this IRS (QEMU-internal) * * Set the CPU object's GICv5 pointer to point to this GIC IRS. The * IRS must call this when it is realized, for each CPU it is
@@ -29,7 +30,8 @@ typedef struct GICv5Common GICv5Common;* Returns true on success, false if the CPU doesn't implement the * GICv5 CPU interface. */ -bool gicv5_set_gicv5state (ARMCPU *cpu,GICv5Common *cs,uint32_t iaffid); +bool gicv5_set_gicv5state (ARMCPU *cpu,GICv5Common *cs,uint32_t iaffid, +uint32_t cpuidx);/* * The architected Stream Protocol is asynchronous; commands can be
target/arm/cpu.c +6 -4
@@ -1215,17 +1215,19 @@ 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) +bool 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. +* connected to, and record our IAFFID and CPU index. */ if (!cpu_isar_feature (aa64_gcie, cpu)) {return false; } - cpu->env.gicv5state = cs; - cpu->env.gicv5_iaffid = iaffid; + cpu->env.gicv5.gicv5state = cs; + cpu->env.gicv5.iaffid = iaffid; + cpu->env.gicv5.cpuidx = cpuidx;return true; }#endif
target/arm/cpu.h +6 -4
@@ -814,10 +814,12 @@ typedef struct CPUArchState {const struct arm_boot_info *boot_info;/* Store GICv3CPUState to access from this struct */ void *gicv3state; -/* Similarly, for a GICv5Common */ -void *gicv5state; -/* For GICv5, this CPU's IAFFID */ -uint64_t gicv5_iaffid; +/* Information the GICv5 IRS passes to us */ +struct { +void *gicv5state;/* GICv5Common struct */ +uint64_t iaffid;/* this CPU's IAFFID */ +uint32_t cpuidx;/* GIC IRS-internal index of this CPU */ + } gicv5;#else /* CONFIG_USER_ONLY */ /* For usermode syscall translation. */ bool eabi;
target/arm/tcg/gicv5-cpuif.c +3 -3
@@ -87,7 +87,7 @@ FIELD(ICC_HPPIR_EL1, HPPIV, 32, 1)static GICv5Common *gicv5_get_gic (CPUARMState *env) { -return env->gicv5state; +return env->gicv5.gicv5state; }static GICv5Domain gicv5_logical_domain (CPUARMState *env)
@@ -147,7 +147,7 @@ static GICv5PendingIrq gic_hppi(CPUARMState *env, GICv5Domain domain)return GICV5_PENDING_IRQ_NONE ; } - irs_hppi =gicv5_get_hppi (gic, domain, env->gicv5_iaffid); + irs_hppi =gicv5_get_hppi (gic, domain, env->gicv5.iaffid);/* * If the best PPI and the best interrupt from the IRS have the
@@ -788,7 +788,7 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = { .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 10, .opc2 = 5, .access = PL1_R, .type = ARM_CP_NO_RAW,/* ICC_IAFFIDR_EL1 holds the IAFFID only, in its low bits */ - .fieldoffset = offsetof(CPUARMState, gicv5_iaffid), + .fieldoffset = offsetof(CPUARMState, gicv5.iaffid),/* * The field is a constant value set in gicv5_set_gicv5state(), * so don't allow it to be overwritten by reset.
Signature · 1 line
2.43.0
PATCH 10/86 hw/intc/arm_gicv5: Pass cpuidx rather than iaffid in gicv5_get_hppi()
In reply to Peter MaydellNow the CPU interface knows its own cpuidx, we can pass that to gicv5_get_hppi() and avoid the IAFFID->cpuidx lookup in the IRS.
--- hw/intc/arm_gicv5.c | 5 ++--- include/hw/intc/arm_gicv5_stream.h | 4 ++-- target/arm/tcg/gicv5-cpuif.c | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-)
hw/intc/arm_gicv5.c +2 -3
@@ -531,12 +531,11 @@ static void irs_recall_hppis(GICv5 *s, GICv5Domain domain) }GICv5PendingIrq gicv5_get_hppi (GICv5Common *cs,GICv5Domain domain, -uint32_t iaffid) +uint32_t cpuidx) {GICv5 *s =ARM_GICV5 (cs); -int cpuidx =irs_cpuidx_from_iaffid (cs, iaffid); -assert (cpuidx >=0 ); +assert (cpuidx < cs->num_cpus);return s->hppi[domain][cpuidx]; }
include/hw/intc/arm_gicv5_stream.h +2 -2
@@ -204,14 +204,14 @@ void gicv5_forward_interrupt(ARMCPU *cpu, GICv5Domain domain);* gicv5_get_hppi * @cs: GIC IRS to query * @domain: interrupt domain to act on -* @iaffid: IAFFID of this CPU interface +* @cpuidx: IRS CPU index of this CPU interface * * Ask the IRS for the highest priority pending interrupt that it has * for this CPU. This returns the equivalent of what in the stream * protocol is the outstanding interrupt sent with a Forward packet. */ GICv5PendingIrq gicv5_get_hppi (GICv5Common *cs,GICv5Domain domain, -uint32_t iaffid); +uint32_t cpuidx);/** * gicv5_deactivate
target/arm/tcg/gicv5-cpuif.c +1 -1
@@ -147,7 +147,7 @@ static GICv5PendingIrq gic_hppi(CPUARMState *env, GICv5Domain domain)return GICV5_PENDING_IRQ_NONE ; } - irs_hppi =gicv5_get_hppi (gic, domain, env->gicv5.iaffid); + irs_hppi =gicv5_get_hppi (gic, domain, env->gicv5.cpuidx);/* * If the best PPI and the best interrupt from the IRS have the
Signature · 1 line
2.43.0
PATCH 11/86 hw/intc/arm_gicv5: Use correct type for value in lpi_cache_get_hppi()
In reply to Peter Maydelllpi_cache_get_hppi() is a function we pass to g_hash_table_foreach() to iterate over the LPI cache hashtable. This hash table has keys which are GINT_TO_POINTER(intid) and values which hold the L2 ISTE value, allocated as "hashvalue = g_new(uint32_t, 1)".
The function is passed the key and value as type 'gpointer' and has to cast them to the real types itself, but it incorrectly casts the value pointer to a uint64_t*. This works on little-endian hosts (since we only read specific fields of the L2 ISTE using bitmasking), but won't work on big-endian, and trips the clang sanitizer.
Fix the pointer type.
--- hw/intc/arm_gicv5.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/intc/arm_gicv5.c +1 -1
@@ -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); -uint64_t l2_iste = *(uint64_t *)value; +uint64_t l2_iste = *(uint32_t *)value;uint32_t prio, iaffid;GetHPPIUserData *ud = user_data;
Signature · 1 line
2.43.0
PATCH 12/86 hw/intc/arm_gicv5: Relax QEMU_GICV5_MIN_LPI_ID_BITS to 0
In reply to Peter MaydellThe GICv5 specification allows implementations to declare a MIN_LPI_ID_BITS value in IST_IDR2, which specifies the minimum number of supported LPIs which can be configured (both for physical LPIs and for virtual LPIs in VMs). It also notes (I_ZKLJR) that it doesn't expect most hardware implementations to require a minimum numberof LPI ID bits, and that this is mostly useful for the virtual IRS that a hypervisor might expose to a guest.
QEMU generally prefers to offer the guest the highest-flexibility setting when it comes to this kind of IMPDEF value, so for instance we set our supported ID and IAFFID bit size to the maximum the spec permits. Since this value is a minimum rather than a maximum, "highest-flexibility" means allowing the guest to configure a very small LPI range if it wants to. Our current setting of 14 for QEMU_GICV5_MIN_LPI_ID_BITS is the least-flexible the architecture permits and requires that guests always configure large LPI ranges.
Set QEMU_GICV5_MIN_LPI_ID_BITS to 0, as the spec suggests real hardware would.
--- include/hw/intc/arm_gicv5_common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/hw/intc/arm_gicv5_common.h +1 -1
@@ -146,7 +146,7 @@ struct GICv5CommonClass {/* Number of INTID.ID bits we support */ #define QEMU_GICV5_ID_BITS 24/* Min LPI_ID_BITS supported */ -#define QEMU_GICV5_MIN_LPI_ID_BITS 14 +#define QEMU_GICV5_MIN_LPI_ID_BITS 0/* IAFFID bits supported */ #define QEMU_GICV5_IAFFID_BITS 16/* Number of priority bits supported in the IRS */
Signature · 1 line
2.43.0
Re: [PATCH 12/86] hw/intc/arm_gicv5: Relax QEMU_GICV5_MIN_LPI_ID_BITS to 0
Quoted 17 lines · Peter Maydell
The GICv5 specification allows implementations to declare a
MIN_LPI_ID_BITSvalue inIST_IDR2, which specifies the minimum number of supported LPIs which can be configured (both for physical LPIs and for virtual LPIs in VMs). It also notes (I_ZKLJR) that it doesn't expect most hardware implementations to require a minimum numberof LPI ID bits, and that this is mostly useful for the virtual IRS that a hypervisor might expose to a guest.QEMU generally prefers to offer the guest the highest-flexibility setting when it comes to this kind of IMPDEF value, so for instance we set our supported ID and IAFFID bit size to the maximum the spec permits. Since this value is a minimum rather than a maximum, "highest-flexibility" means allowing the guest to configure a very small LPI range if it wants to. Our current setting of 14 for
QEMU_GICV5_MIN_LPI_ID_BITSis the least-flexible the architecture permits and requires that guests always configure large LPI ranges.
Quoted 7 lines
Set
QEMU_GICV5_MIN_LPI_ID_BITSto 0, as the spec suggests real hardware would.Signed-off-by Peter Maydell <[email protected]>--- include/hw/intc/arm_gicv5_common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Still valid with A.a release.
PATCH 13/86 target/arm: GICv5 cpuif: Implement ICH_APR_EL2
In reply to Peter MaydellImplement 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.
--- target/arm/cpu.h | 2 ++ target/arm/tcg/gicv5-cpuif.c | 44 ++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+)
target/arm/cpu.h +2 -0
@@ -594,6 +594,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 {
target/arm/tcg/gicv5-cpuif.c +44 -0
62 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH 14/86 target/arm: GICv5 cpuif: Implement ICH_PPI_{ENABLE, PEND, ACTIVE} regs
In reply to Peter MaydellImplement 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.
--- target/arm/cpu.h | 3 ++ target/arm/tcg/gicv5-cpuif.c | 64 ++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+)
target/arm/cpu.h +3 -0
@@ -596,6 +596,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 {
target/arm/tcg/gicv5-cpuif.c +64 -0
76 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH 15/86 target/arm: GICv5 cpuif: Implement ICH_PPI_PRIORITYR<n>_EL2
In reply to Peter MaydellImplement 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.
--- target/arm/cpu.h | 1 + target/arm/tcg/gicv5-cpuif.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+)
target/arm/cpu.h +1 -0
@@ -599,6 +599,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 {
target/arm/tcg/gicv5-cpuif.c +21 -0
@@ -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); + } } }
Signature · 1 line
2.43.0
PATCH 16/86 target/arm: GICv5 cpuif: Implement ICH_PPI_DVIR<n>_EL2
In reply to Peter MaydellImplement 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.
--- target/arm/cpu.h | 1 + target/arm/tcg/gicv5-cpuif.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+)
target/arm/cpu.h +1 -0
@@ -599,6 +599,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;
target/arm/tcg/gicv5-cpuif.c +27 -0
@@ -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,
Signature · 1 line
2.43.0
PATCH 17/86 target/arm: GICv5 cpuif: Implement ICH_VCTLR_EL2 and ICH_VCMR_EL2
In reply to Peter MaydellImplement 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.
--- target/arm/cpu.h | 2 ++ target/arm/tcg/gicv5-cpuif.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+)
target/arm/cpu.h +2 -0
@@ -596,6 +596,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 ];
target/arm/tcg/gicv5-cpuif.c +28 -0
@@ -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)
Signature · 1 line
2.43.0
PATCH 18/86 target/arm: GICv5 cpuif: Implement GIC fine-grained trap registers
In reply to Peter MaydellThe 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.
--- target/arm/cpregs.h | 85 +++++++++++++++++++++++++++++++++++- target/arm/cpu.h | 10 +++-- target/arm/tcg/gicv5-cpuif.c | 22 ++++++++++ 3 files changed, 111 insertions(+), 6 deletions(-)
target/arm/cpregs.h +83 -2
@@ -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
target/arm/cpu.h +6 -4
@@ -550,11 +550,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;
target/arm/tcg/gicv5-cpuif.c +22 -0
@@ -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
Signature · 1 line
2.43.0
PATCH 19/86 target/arm: GICv5 cpuif: Mark GIC registers for fine-grained traps
In reply to Peter MaydellAnnotate 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.
--- target/arm/tcg/gicv5-cpuif.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
target/arm/tcg/gicv5-cpuif.c +20 -0
@@ -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_SPENDR0_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, };
Signature · 1 line
2.43.0
PATCH 20/86 target/arm: GICv5 cpuif: Mark GIC insns for fine-grained traps
In reply to Peter MaydellAnnotate the GICv5 system insn cpreg structs with the fine-grained trap information. This covers all the bits in ICH_HFGITR_EL2.
--- target/arm/tcg/gicv5-cpuif.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
target/arm/tcg/gicv5-cpuif.c +11 -0
@@ -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,
Signature · 1 line
2.43.0
PATCH 21/86 target/arm: GICv5 cpuif: Implement ICC_SRE_ELx
In reply to Peter MaydellWhen 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.
--- target/arm/tcg/gicv5-cpuif.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
target/arm/tcg/gicv5-cpuif.c +17 -0
@@ -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); + } } }
Signature · 1 line
2.43.0
PATCH 22/86 target/arm: GICv5 cpuif: Implement ICH_PPI_HVIR<n>_EL2
In reply to Peter MaydellThe 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.
--- target/arm/cpu.h | 1 + target/arm/tcg/gicv5-cpuif.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+)
target/arm/cpu.h +1 -0
@@ -600,6 +600,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 ];
target/arm/tcg/gicv5-cpuif.c +22 -0
@@ -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,
Signature · 1 line
2.43.0
PATCH 23/86 target/arm: GICv5 cpuif: Implement ICV_APR_EL1
In reply to Peter MaydellImplement 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.
--- target/arm/tcg/gicv5-cpuif.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-)
target/arm/tcg/gicv5-cpuif.c +25 -5
@@ -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)
Signature · 1 line
2.43.0
PATCH 24/86 target/arm: GICv5 cpuif: Implement ICV_CR0_EL1
In reply to Peter MaydellImplement 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).
--- target/arm/tcg/gicv5-cpuif.c | 41 +++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 12 deletions(-)
target/arm/tcg/gicv5-cpuif.c +29 -12
@@ -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 ,VMPR ,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)
Signature · 1 line
2.43.0
Re: [PATCH 24/86] target/arm: GICv5 cpuif: Implement ICV_CR0_EL1
Quoted 15 lines · Peter Maydell
Implement the redirection of the
ICC_CR0_EL1encoding to the hypervisor guest's viewICV_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 <[email protected]>--- target/arm/tcg/gicv5-cpuif.c | 41 +++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 12 deletions(-)target/arm/tcg/gicv5-cpuif.c +0
-0
target/arm/tcg/gicv5-cpuif.c FIELD(ICC_HPPIR_EL1, ID, 0, 24) · line 71
Quoted 5 lines
target/arm/tcg/gicv5-cpuif.c +2
-0@@ -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 ,VMPR ,27 ,5 )
s/VMPR/VPMR/ "Virtual Priority Mask Register"
PATCH 25/86 target/arm: GICv5 cpuif: Implement ICV_PCR_EL1
In reply to Peter MaydellImplement 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.
--- target/arm/tcg/gicv5-cpuif.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)
target/arm/tcg/gicv5-cpuif.c +20 -6
@@ -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 ,VMPR ); + }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.VMPR */ +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 ,VMPR , +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)
Signature · 1 line
2.43.0
PATCH 26/86 target/arm: GICv5 cpuif: Implement ICV_PPI_ENABLER<n>_EL1
In reply to Peter MaydellImplement 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.
--- target/arm/tcg/gicv5-cpuif.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
target/arm/tcg/gicv5-cpuif.c +20 -2
@@ -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,
Signature · 1 line
2.43.0
PATCH 27/86 target/arm: GICv5 cpuif: Implement ICV_PPI_PRIORITYR<n>_EL1
In reply to Peter MaydellImplement 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.
--- target/arm/tcg/gicv5-cpuif.c | 64 ++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-)
target/arm/tcg/gicv5-cpuif.c +62 -2
@@ -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); }
Signature · 1 line
2.43.0
PATCH 28/86 target/arm: GICv5 cpuif: Add comment about ICV_PPI_HMR<n>_EL1
In reply to Peter MaydellThe 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.
--- target/arm/tcg/gicv5-cpuif.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
target/arm/tcg/gicv5-cpuif.c +19 -0
@@ -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,
Signature · 1 line
2.43.0
PATCH 29/86 target/arm: GICv5 cpuif: Implement ICV_PPI_CACTIVER<n>_EL1, ICV_PPI_SACTIVER<n>_EL1
In reply to Peter MaydellImplement 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.
--- target/arm/tcg/gicv5-cpuif.c | 38 ++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-)
target/arm/tcg/gicv5-cpuif.c +32 -6
@@ -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,
Signature · 1 line
2.43.0
PATCH 30/86 target/arm: GICv5 cpuif: Implement ICV_PPI_CPENDR<n>_EL1, ICV_PPI_SPENDR<n>_EL1
In reply to Peter MaydellImplement 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.
--- target/arm/tcg/gicv5-cpuif.c | 40 ++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-)
target/arm/tcg/gicv5-cpuif.c +34 -6
@@ -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_SPENDR0_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,
Signature · 1 line
2.43.0
PATCH 31/86 target/arm: GICv5 cpuif: Calculate current virtual PPI HPPI
In reply to Peter MaydellImplement 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.
--- target/arm/cpu.h | 2 ++ target/arm/tcg/gicv5-cpuif.c | 51 ++++++++++++++++++++++++++++++++++++ target/arm/tcg/trace-events | 1 + 3 files changed, 54 insertions(+)
target/arm/cpu.h +2 -0
@@ -596,6 +596,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;
target/arm/tcg/gicv5-cpuif.c +51 -0
129 lines not on this page · raw message
target/arm/tcg/trace-events +1 -0
@@ -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"
Signature · 1 line
2.43.0
PATCH 32/86 target/arm: GICv5 cpuif: Add virtual support to IRS/cpuif HPPI APIs
In reply to Peter MaydellThe 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.
--- hw/intc/arm_gicv5.c | 14 +++++++++++--- include/hw/intc/arm_gicv5_stream.h | 6 ++++-- target/arm/tcg/gicv5-cpuif.c | 11 ++++++++--- 3 files changed, 23 insertions(+), 8 deletions(-)
hw/intc/arm_gicv5.c +11 -3
@@ -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]; }
include/hw/intc/arm_gicv5_stream.h +4 -2
@@ -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
target/arm/tcg/gicv5-cpuif.c +8 -3
@@ -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)
Signature · 1 line
2.43.0
PATCH 33/86 target/arm: GICv5 cpuif: Implement ICV_HPPIR_EL1
In reply to Peter MaydellImplement 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.
--- target/arm/tcg/gicv5-cpuif.c | 73 +++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-)
target/arm/tcg/gicv5-cpuif.c +71 -2
@@ -70,6 +70,9 @@ FIELD(ICC_HPPIR_EL1, HPPIV, 32, 1) FIELD(ICH_VMCR_EL2, EN, 0, 1) FIELD(ICH_VMCR_EL2, VMPR, 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 ,VMPR ) || + 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 */
Signature · 1 line
2.43.0
PATCH 34/86 target/arm: GICv5 cpuif: Implement gicv5_update_virq_vfiq()
In reply to Peter MaydellImplement 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.
--- target/arm/tcg/gicv5-cpuif.c | 43 +++++++++++++++++++++++++++++++++++- target/arm/tcg/trace-events | 1 + 2 files changed, 43 insertions(+), 1 deletion(-)
target/arm/tcg/gicv5-cpuif.c +42 -1
@@ -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 ,VMPR ,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);
target/arm/tcg/trace-events +1 -0
@@ -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"
Signature · 1 line
2.43.0
PATCH 35/86 target/arm: GICv5 cpuif: Implement ICH_CONTEXTR_EL2
In reply to Peter MaydellThe 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.
--- hw/intc/arm_gicv5.c | 8 ++ include/hw/intc/arm_gicv5_stream.h | 30 +++++++ target/arm/cpu.h | 1 + target/arm/tcg/gicv5-cpuif.c | 121 +++++++++++++++++++++++++++++ target/arm/tcg/trace-events | 1 + 5 files changed, 161 insertions(+)
hw/intc/arm_gicv5.c +8 -0
@@ -1263,6 +1263,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;
include/hw/intc/arm_gicv5_stream.h +30 -0
@@ -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
target/arm/cpu.h +1 -0
@@ -599,6 +599,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;
target/arm/tcg/gicv5-cpuif.c +121 -0
139 lines not on this page · raw message
target/arm/tcg/trace-events +1 -0
@@ -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
Signature · 1 line
2.43.0
Re: [PATCH 35/86] target/arm: GICv5 cpuif: Implement ICH_CONTEXTR_EL2
Quoted 20 lines · Peter Maydell
The
ICH_CONTEXTR_EL2register 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 <[email protected]>---
target/arm/tcg/gicv5-cpuif.c +8
-0+/* +* 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.
target/arm/tcg/gicv5-cpuif.c static void gic_ich_vmcr_write(CPUARMState *env, const ARMCPRegInfo *ri, · line 876
Quoted 10 lines
target/arm/tcg/gicv5-cpuif.c +10
-0+* +* 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 ) {
This is supposed to be the usual "did a bit change?" check, which should be "oldval ^ value", not "&"...
-- PMM
PATCH 36/86 target/arm: GICv5 cpuif: ask the GIC for the virtual HPPI
In reply to Peter MaydellNow 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.
--- target/arm/tcg/gicv5-cpuif.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-)
target/arm/tcg/gicv5-cpuif.c +21 -6
@@ -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
Signature · 1 line
2.43.0
PATCH 37/86 target/arm: GICv5 cpuif: Handle LD/VD insns when setting domain/virtual args
In reply to Peter MaydellGIC 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.)
--- target/arm/tcg/gicv5-cpuif.c | 71 +++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 18 deletions(-)
target/arm/tcg/gicv5-cpuif.c +53 -18
@@ -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);
Signature · 1 line
2.43.0
PATCH 38/86 target/arm: GICv5 cpuif: Handle virtual interrupts for GIC CDEOI
In reply to Peter MaydellGIC 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.
--- target/arm/tcg/gicv5-cpuif.c | 21 ++++++++++++++++----- target/arm/tcg/trace-events | 1 + 2 files changed, 17 insertions(+), 5 deletions(-)
target/arm/tcg/gicv5-cpuif.c +16 -5
@@ -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,
target/arm/tcg/trace-events +1 -0
@@ -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"
Signature · 1 line
2.43.0
PATCH 39/86 target/arm: GICv5 cpuif: Handle virtual interrupts for GIC CDDI
In reply to Peter MaydellHandle 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.
--- target/arm/tcg/gicv5-cpuif.c | 11 ++++++++--- target/arm/tcg/trace-events | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-)
target/arm/tcg/gicv5-cpuif.c +8 -3
@@ -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 :
target/arm/tcg/trace-events +1 -1
@@ -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"
Signature · 1 line
2.43.0
PATCH 40/86 target/arm: GICv5 cpuif: Handle virtual interrupts for GICR CDIA, CDNMIA
In reply to Peter MaydellHandle 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.
--- target/arm/tcg/gicv5-cpuif.c | 40 ++++++++++++++++++++++++++---------- target/arm/tcg/trace-events | 4 ++-- 2 files changed, 31 insertions(+), 13 deletions(-)
target/arm/tcg/gicv5-cpuif.c +29 -11
@@ -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 ();
target/arm/tcg/trace-events +2 -2
@@ -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"
Signature · 1 line
2.43.0
PATCH 41/86 target/arm: GICv5 cpuif: Handle GIC VDPEND VM argument
In reply to Peter MaydellIn 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.
--- hw/intc/arm_gicv5.c | 5 +++-- hw/intc/trace-events | 2 +- include/hw/intc/arm_gicv5_stream.h | 3 ++- target/arm/tcg/gicv5-cpuif.c | 34 +++++++++++++++++++++++++++++- 4 files changed, 39 insertions(+), 5 deletions(-)
hw/intc/arm_gicv5.c +3 -2
@@ -855,13 +855,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" );
hw/intc/trace-events +1 -1
@@ -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
include/hw/intc/arm_gicv5_stream.h +2 -1
@@ -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
target/arm/tcg/gicv5-cpuif.c +33 -1
@@ -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,
Signature · 1 line
2.43.0
PATCH 42/86 target/arm: GICv5 cpuif: Implement GIC VDnnn insns
In reply to Peter MaydellThe 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.
--- target/arm/tcg/gicv5-cpuif.c | 48 ++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
target/arm/tcg/gicv5-cpuif.c +48 -0
@@ -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,
Signature · 1 line
2.43.0
PATCH 43/86 target/arm: GICv5 cpuif: Implement GIC LDnnn insns
In reply to Peter MaydellThe 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.
--- target/arm/tcg/gicv5-cpuif.c | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
target/arm/tcg/gicv5-cpuif.c +40 -0
@@ -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,
Signature · 1 line
2.43.0
PATCH 44/86 target/arm: GICv5 cpuif: Handle PPI injection in vPPI pending reads
In reply to Peter MaydellThe 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 interupt 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.
--- target/arm/tcg/gicv5-cpuif.c | 95 +++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 2 deletions(-)
target/arm/tcg/gicv5-cpuif.c +93 -2
@@ -192,6 +192,97 @@ 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,extract64 (dvi_pend,30 ,1 ),20 ,1 ); + } +if (extract64 (ppi_dvi,27 ,1 )) { + dvi_pend =deposit64 (dvi_pend,extract64 (dvi_pend,27 ,1 ),19 ,1 ); + } + }else { +/* 30 -> 26 and 27 -> 28 */ +if (extract64 (ppi_dvi,30 ,1 )) { + dvi_pend =deposit64 (dvi_pend,extract64 (dvi_pend,30 ,1 ),26 ,1 ); + } +if (extract64 (ppi_dvi,27 ,1 )) { + dvi_pend =deposit64 (dvi_pend,extract64 (dvi_pend,27 ,1 ),28 ,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 +552,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 +807,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;
Signature · 1 line
2.43.0
Re: [PATCH 44/86] target/arm: GICv5 cpuif: Handle PPI injection in vPPI pending reads
Quoted 5 lines · Peter Maydell
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 interupt domain.
"interrupt"
Quoted 41 lines
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 <[email protected]>target/arm/tcg/gicv5-cpuif.c +20
-0+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,extract64 (dvi_pend,30 ,1 ),20 ,1 ); + } +if (extract64 (ppi_dvi,27 ,1 )) { + dvi_pend =deposit64 (dvi_pend,extract64 (dvi_pend,27 ,1 ),19 ,1 );
target/arm/tcg/gicv5-cpuif.c static GICv5Domain gicv5_domain_for_insn(CPUARMState *env, · line 279
Quoted 10 lines
target/arm/tcg/gicv5-cpuif.c +10
-0+ } + }else { +/* 30 -> 26 and 27 -> 28 */ +if (extract64 (ppi_dvi,30 ,1 )) { + dvi_pend =deposit64 (dvi_pend,extract64 (dvi_pend,30 ,1 ),26 ,1 ); + } +if (extract64 (ppi_dvi,27 ,1 )) { + dvi_pend =deposit64 (dvi_pend,extract64 (dvi_pend,27 ,1 ),28 ,1 ); + } + }
This code gets the order of arguments to deposit64() wrong:
they are value, start, length, fieldval, so should be
dvi_pend = deposit64(dvi_pend, 20, 1, extract64(....))
and so on.
-- PMM
PATCH 45/86 target/arm: GICv5 cpuif: Handle PPI injection in vPPI pending writes
In reply to Peter MaydellIn 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.
--- target/arm/tcg/gicv5-cpuif.c | 69 ++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 6 deletions(-)
target/arm/tcg/gicv5-cpuif.c +63 -6
@@ -816,16 +816,61 @@ 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 ; + } + }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);
@@ -837,13 +882,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);
Signature · 1 line
2.43.0
Re: [PATCH 45/86] target/arm: GICv5 cpuif: Handle PPI injection in vPPI pending writes
Quoted 38 lines · Peter Maydell
In this commit we update the logic for writes to the virtual PPI pending state by the guest using the
PPI_CPENDorPPI_SPENDregisters to honour the DVI registers, so that the pending state of the underlying physical PPI is updated.Signed-off-by Peter Maydell <[email protected]>--- target/arm/tcg/gicv5-cpuif.c | 69 ++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 6 deletions(-)target/arm/tcg/gicv5-cpuif.c +19
-0@@ -816,16 +816,61 @@ 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 ; + }
target/arm/tcg/gicv5-cpuif.c static uint64_t gic_ppi_pend_read(CPUARMState *env, const ARMCPRegInfo *ri) · line 847
Quoted 10 lines
target/arm/tcg/gicv5-cpuif.c +10
-0+ }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 ));
This "clear bits 26 and 28" line should be inside the "else" block, and the "if" block should have an equivalent line for "clear bits 19 and 20".
target/arm/tcg/gicv5-cpuif.c static uint64_t gic_ppi_pend_read(CPUARMState *env, const ARMCPRegInfo *ri) · line 850
Quoted 3 lines
target/arm/tcg/gicv5-cpuif.c +3
-0+ } +return value; +}
-- PMM
PATCH 46/86 target/arm: GICv5 cpuif: Handle injected PPIs in GICR CDIA
In reply to Peter MaydellWhen 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.
--- target/arm/tcg/gicv5-cpuif.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
target/arm/tcg/gicv5-cpuif.c +22 -1
@@ -1317,6 +1317,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 */
@@ -1381,7 +1402,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 {
Signature · 1 line
2.43.0
PATCH 47/86 target/arm: GICv5 cpuif: Update on HCR_EL2.{NV, NV1} and SCR_EL3.NS changes
In reply to Peter MaydellWhen 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.
--- target/arm/gicv5-stubs.c | 8 ++++++++ target/arm/helper.c | 23 ++++++++++++++++++----- target/arm/internals.h | 9 +++++++++ target/arm/tcg/gicv5-cpuif.c | 18 ++++++++++++++++++ 4 files changed, 53 insertions(+), 5 deletions(-)
target/arm/gicv5-stubs.c +8 -0
@@ -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) +{ +}
target/arm/helper.c +18 -5
@@ -1012,6 +1012,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)
@@ -3881,7 +3887,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 */
@@ -3960,6 +3966,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
@@ -3969,16 +3977,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
@@ -3998,7 +4011,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
target/arm/internals.h +9 -0
@@ -1909,6 +1909,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) {
target/arm/tcg/gicv5-cpuif.c +18 -0
@@ -630,6 +630,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) {
Signature · 1 line
2.43.0
PATCH 48/86 target/arm: GICv5 cpuif: Update VFIQ/VIRQ when direct-injected PPIs change
In reply to Peter MaydellWhen 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.
--- target/arm/tcg/gicv5-cpuif.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
target/arm/tcg/gicv5-cpuif.c +26 -0
@@ -602,6 +602,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) {/*
@@ -627,6 +649,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); } }
@@ -894,6 +917,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); } }
@@ -924,6 +948,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); } }
@@ -1428,6 +1453,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); }
Signature · 1 line
2.43.0
PATCH 49/86 hw/intc: Move GICv5 register and data definitions into a header
In reply to Peter MaydellWe 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.
--- hw/intc/arm_gicv5.c | 270 +---------------------------- include/hw/intc/arm_gicv5_regs.h | 286 +++++++++++++++++++++++++++++++ 2 files changed, 287 insertions(+), 269 deletions(-) create mode 100644 include/hw/intc/arm_gicv5_regs.h
hw/intc/arm_gicv5.c +1 -269
@@ -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) - -REG32(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_MICID_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_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) - -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_SYNDROMER2, 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 << 31) | (0x1 << 20) | 0x5a19)
include/hw/intc/arm_gicv5_regs.h new file +286 -0
286 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH 49/86] hw/intc: Move GICv5 register and data definitions into a header
Quoted 6 lines · Peter Maydell
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 inarm_gicv5_common.c).Move the definitions to their own header file.
There are pre-existing typo worth fixing before moving IMO.
Quoted 10 lines
Signed-off-by Peter Maydell <[email protected]>--- hw/intc/arm_gicv5.c | 270 +---------------------------- include/hw/intc/arm_gicv5_regs.h | 286 +++++++++++++++++++++++++++++++ 2 files changed, 287 insertions(+), 269 deletions(-)create mode 100644
include/hw/intc/arm_gicv5_regs.hhw/intc/arm_gicv5.c +0
-2-REG64(IRS_VPE_SELR, 0x240) -FIELD (IRS_VPE_SELR ,VM_ID ,0 ,16 )
hw/intc/arm_gicv5.c static const char *inttype_name(GICv5IntType t) · line 201
Quoted 10 lines
hw/intc/arm_gicv5.c +0
-10- 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) - -REG32 (IRS_VPE_HPPIR ,0x250 )
Pre-existing (or maybe that changed since previous releases) this register is 64-bit.
hw/intc/arm_gicv5.c static const char *inttype_name(GICv5IntType t) · line 204
Quoted 3 lines
hw/intc/arm_gicv5.c +0
-3- FIELD(IRS_VPE_HPPIR, ID, 0, 24) - FIELD(IRS_VPE_HPPIR, TYPE, 29, 3) -FIELD (IRS_VPE_HPPIR ,HPPIV ,32 ,1 )
(thus the expanded HPPIV definitions might be wrong).
Quoted 6 lines
hw/intc/arm_gicv5.c +0
-6-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 )
[...]
hw/intc/arm_gicv5.c static const char *inttype_name(GICv5IntType t) · line 263
Quoted 5 lines
hw/intc/arm_gicv5.c +0
-5-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 )
Pre-existing s/IRS_MEC_MECID_R/IRS_MEC_MICID_R/ typo?
hw/intc/arm_gicv5.c static const char *inttype_name(GICv5IntType t) · line 274
Quoted 11 lines
hw/intc/arm_gicv5.c +0
-11- -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_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 )
s/IRS_MPAM_IDR/IRS_MPAM_PARTID_R/ typo!
Quoted 7 lines
hw/intc/arm_gicv5.c +0
-7- -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 )
hw/intc/arm_gicv5.c static const char *inttype_name(GICv5IntType t) · line 291
Quoted 10 lines
hw/intc/arm_gicv5.c +0
-10- 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_SYNDROMER2 ,ADDR ,3 ,53 )
s/IRS_SWERR_SYNDROMER1/IRS_SWERR_SYNDROMER2/ typo?
Quoted 15 lines
hw/intc/arm_gicv5.c +0
-15- -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 )
Re: [PATCH 49/86] hw/intc: Move GICv5 register and data definitions into a header
Quoted 10 lines · Philippe Mathieu-Daudé
Quoted 6 lines · Peter Maydell
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 inarm_gicv5_common.c).Move the definitions to their own header file.
There are pre-existing typo worth fixing before moving IMO.
Yep, good idea. (None of these are in registers the current code is using, so they're harmless right now and don't need a stable backport.)
Quoted 8 lines
Quoted 6 lines
Signed-off-by Peter Maydell <[email protected]>--- hw/intc/arm_gicv5.c | 270 +---------------------------- include/hw/intc/arm_gicv5_regs.h | 286 +++++++++++++++++++++++++++++++ 2 files changed, 287 insertions(+), 269 deletions(-)create mode 100644
include/hw/intc/arm_gicv5_regs.h
Quoted 15 lines
hw/intc/arm_gicv5.c static const char *inttype_name(GICv5IntType t) · line 201
Quoted 12 lines
hw/intc/arm_gicv5.c +0
-12-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) - -REG32 (IRS_VPE_HPPIR ,0x250 )Pre-existing (or maybe that changed since previous releases) this register is 64-bit.
I think I must have just copy-pasted it wrong.
Quoted 5 lines
hw/intc/arm_gicv5.c static const char *inttype_name(GICv5IntType t) · line 204
Quoted 3 lines
hw/intc/arm_gicv5.c +0
-3- FIELD(IRS_VPE_HPPIR, ID, 0, 24) - FIELD(IRS_VPE_HPPIR, TYPE, 29, 3) -FIELD (IRS_VPE_HPPIR ,HPPIV ,32 ,1 )(thus the expanded HPPIV definitions might be wrong).
Luckily FIELD() doesn't depend on the REG32 vs REG64 macro The only difference between REG32 and REG64 is how they define the R_FOO constants, which I don't use in this series, which is why this typo didn't have any visible effects.
thanks
-- PMM
PATCH 50/86 hw/intc/arm_gicv5: Correct offset for IRS_VMT_STATUSR
In reply to Peter MaydellA 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.
--- include/hw/intc/arm_gicv5_regs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/hw/intc/arm_gicv5_regs.h +1 -1
@@ -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 )
Signature · 1 line
2.43.0
PATCH 51/86 hw/intc/arm_gicv5: Ask CPUs whether IRS needs virtualization support
In reply to Peter MaydellThe 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.
--- hw/intc/arm_gicv5_common.c | 9 ++++++++- include/hw/intc/arm_gicv5_common.h | 2 ++ include/hw/intc/arm_gicv5_stream.h | 15 +++++++++++---- target/arm/cpu.c | 17 +++++++++++------ 4 files changed, 32 insertions(+), 11 deletions(-)
hw/intc/arm_gicv5_common.c +8 -1
@@ -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 ; } }
include/hw/intc/arm_gicv5_common.h +2 -0
@@ -127,6 +127,8 @@ struct GICv5Common {uint32_t spi_base;uint32_t spi_irs_range;uint32_t spi_range; + +bool has_virt; };struct GICv5CommonClass {
include/hw/intc/arm_gicv5_stream.h +11 -4
@@ -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
target/arm/cpu.c +11 -6
@@ -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
Signature · 1 line
2.43.0
PATCH 52/86 hw/intc/arm_gicv5: Indicate virtualization in ID registers
In reply to Peter MaydellWhen 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.
--- hw/intc/arm_gicv5.c | 40 +++++++++++++++++++++++------- include/hw/intc/arm_gicv5_common.h | 25 +++++++++++++++++++ 2 files changed, 56 insertions(+), 9 deletions(-)
hw/intc/arm_gicv5.c +31 -9
@@ -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) {/*
@@ -1208,8 +1218,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 ;
@@ -1223,12 +1233,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;
@@ -1636,6 +1646,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;
@@ -1655,9 +1666,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);
include/hw/intc/arm_gicv5_common.h +25 -0
@@ -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
Signature · 1 line
2.43.0
PATCH 53/86 hw/intc/arm_gicv5: Implement IRS_VMT_BASER and IRS_VMT_STATUSR
In reply to Peter MaydellImplement 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.
--- hw/intc/arm_gicv5.c | 73 ++++++++++++++++++++++++++++++ hw/intc/arm_gicv5_common.c | 4 ++ hw/intc/trace-events | 2 + include/hw/intc/arm_gicv5_common.h | 1 + 4 files changed, 80 insertions(+)
hw/intc/arm_gicv5.c +73 -0
@@ -1166,6 +1166,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) {/*
@@ -1271,6 +1301,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
@@ -1373,6 +1428,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;
@@ -1457,6 +1520,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;
@@ -1469,6 +1539,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;
hw/intc/arm_gicv5_common.c +4 -0
@@ -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)
hw/intc/trace-events +2 -0
@@ -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"
include/hw/intc/arm_gicv5_common.h +1 -0
@@ -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
Signature · 1 line
2.43.0
PATCH 54/86 hw/intc/arm_gicv5: IMplement IRS_VMT_CFGR
In reply to Peter MaydellThe 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).
--- hw/intc/arm_gicv5.c | 83 ++++++++++++++++++++++++++++-- hw/intc/arm_gicv5_common.c | 1 + hw/intc/trace-events | 2 +- include/hw/intc/arm_gicv5.h | 10 ++++ include/hw/intc/arm_gicv5_common.h | 1 + 5 files changed, 93 insertions(+), 4 deletions(-)
hw/intc/arm_gicv5.c +80 -3
@@ -1174,7 +1174,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 );
@@ -1184,6 +1184,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 ; }
@@ -1191,8 +1192,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); } }
@@ -1326,6 +1379,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
@@ -1436,6 +1496,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;
@@ -1702,6 +1774,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)
hw/intc/arm_gicv5_common.c +1 -0
@@ -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)); } }
hw/intc/trace-events +1 -1
@@ -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
include/hw/intc/arm_gicv5.h +10 -0
@@ -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 ];
include/hw/intc/arm_gicv5_common.h +1 -0
@@ -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
Signature · 1 line
2.43.0
PATCH 55/86 hw/intc/arm_gicv5: Implement IRS_VMAP_L2_VMTR
In reply to Peter MaydellThe 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.
--- hw/intc/arm_gicv5.c | 110 ++++++++++++++++++++++++++++- hw/intc/arm_gicv5_common.c | 1 + include/hw/intc/arm_gicv5_common.h | 1 + include/hw/intc/arm_gicv5_regs.h | 9 +++ 4 files changed, 120 insertions(+), 1 deletion(-)
hw/intc/arm_gicv5.c +109 -1
@@ -49,7 +49,6 @@ static const char *inttype_name(GICv5IntType t)return names[t]; } -#define IRS_DEVARCH_VALUE ((0x23b << 31) | (0x1 << 20) | 0x5a19)static uint32_t gicv5_idreg (int regoffset)
@@ -489,6 +488,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) {
@@ -1249,6 +1261,62 @@ 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; + } + + 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) {/*
@@ -1386,6 +1454,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
@@ -1508,6 +1594,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;
@@ -1599,6 +1695,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;
@@ -1614,6 +1719,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;
hw/intc/arm_gicv5_common.c +1 -0
@@ -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)); } }
include/hw/intc/arm_gicv5_common.h +1 -0
@@ -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
include/hw/intc/arm_gicv5_regs.h +9 -0
@@ -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.
Signature · 1 line
2.43.0
Re: [PATCH 55/86] hw/intc/arm_gicv5: Implement IRS_VMAP_L2_VMTR
Quoted 43 lines · Peter Maydell
The
IRS_VMAP_L2_VMTRregister allows the guest to make a level 2 VM table valid. It's similar to what theIRS_MAP_L2_ISTRregister 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 <[email protected]>hw/intc/arm_gicv5.c +32
-0+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 ; + }
hw/intc/arm_gicv5.c static void irs_vmt_baser_write(GICv5 *s, GICv5Domain domain, uint64_t value) · line 1305
Quoted 10 lines
hw/intc/arm_gicv5.c +10
-0+ +/* 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; + } + + l1_vmte =FIELD_DP64 (l1_vmte,L1_VMTE ,VALID ,1 );
This is missing a check for "is the VALID bit already set in the L1_VMTE?" (which per the spec is supposed to be a "has no effect" situation). In this patch the lack of a check is harmless, but when we add the code later to cache VM table entries we'll fall through into that and incorrectly corrupt the cached VM table entries by re-initializing them.
Quoted 4 lines
hw/intc/arm_gicv5.c +4
-0+ +address_space_stq_le (&cs->dma_as, l1_addr, l1_vmte, cfg->txattrs, &res); +if (res !=MEMTX_OK ) { + goto txfail;
hw/intc/arm_gicv5.c static void irs_vmt_baser_write(GICv5 *s, GICv5Domain domain, uint64_t value) · line 1319
Quoted 10 lines
hw/intc/arm_gicv5.c +10
-0+ } + +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); +} +
-- PMM
PATCH 56/86 hw/intc/arm_gicv5: Implement IRS_VMAP_VMR
In reply to Peter MaydellThe 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.
--- hw/intc/arm_gicv5.c | 94 ++++++++++++++++++++++++++++++ hw/intc/arm_gicv5_common.c | 1 + hw/intc/trace-events | 1 + include/hw/intc/arm_gicv5_common.h | 1 + include/hw/intc/arm_gicv5_regs.h | 21 +++++++ 5 files changed, 118 insertions(+)
hw/intc/arm_gicv5.c +94 -0
@@ -1309,6 +1309,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:
@@ -1472,6 +1531,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
@@ -1604,6 +1679,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;
@@ -1704,6 +1787,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_l2_vmtr[domain]; + }else { +/* RAZ/WI if no virt or no VM table */ + *data =0 ; + } +return true; }return false;
@@ -1722,6 +1813,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;
hw/intc/arm_gicv5_common.c +1 -0
@@ -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)); } }
hw/intc/trace-events +1 -0
@@ -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"
include/hw/intc/arm_gicv5_common.h +1 -0
@@ -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
include/hw/intc/arm_gicv5_regs.h +21 -0
@@ -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.
Signature · 1 line
2.43.0
Re: [PATCH 56/86] hw/intc/arm_gicv5: Implement IRS_VMAP_VMR
Quoted 62 lines · Peter Maydell
The
IRS_VMAP_VMRregister lets the guest mark a VM as valid. This is a 64-bit register similar in operation toIRS_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 <[email protected]>--- hw/intc/arm_gicv5.c | 94 ++++++++++++++++++++++++++++++ hw/intc/arm_gicv5_common.c | 1 + hw/intc/trace-events | 1 + include/hw/intc/arm_gicv5_common.h | 1 + include/hw/intc/arm_gicv5_regs.h | 21 +++++++ 5 files changed, 118 insertions(+)hw/intc/arm_gicv5.c +24
-0@@ -1472,6 +1531,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 @@ -1604,6 +1679,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;
hw/intc/arm_gicv5.c static bool config_readll(GICv5 *s, GICv5Domain domain, hwaddr offset, · line 1792
Quoted 6 lines
hw/intc/arm_gicv5.c +3
-0@@ -1704,6 +1787,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_l2_vmtr[domain];
irs_vmap_l2_vmtr[] or irs_vmap_vmr[]?
Quoted 16 lines
hw/intc/arm_gicv5.c +8
-0+ }else { +/* RAZ/WI if no virt or no VM table */ + *data =0 ; + } +return true; }return false;@@ -1722,6 +1813,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; }
Re: [PATCH 56/86] hw/intc/arm_gicv5: Implement IRS_VMAP_VMR
Quoted 21 lines · Philippe Mathieu-Daudé
Quoted 19 lines · Peter Maydell
The
IRS_VMAP_VMRregister lets the guest mark a VM as valid. This is a 64-bit register similar in operation toIRS_VMAP_L2_VMTR.hw/intc/arm_gicv5.c +8
-0@@ -1604,6 +1679,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;@@ -1704,6 +1787,14 @@ static bool config_readll(GICv5 *s, GICv5Domain domain, hwaddr offset,
Quoted 8 lines
hw/intc/arm_gicv5.c static bool config_readll(GICv5 *s, GICv5Domain domain, hwaddr offset, · line 1792
Quoted 6 lines
hw/intc/arm_gicv5.c +3
-0*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_l2_vmtr[domain];irs_vmap_l2_vmtr[] or irs_vmap_vmr[]?
Should be irs_vmap_vmr[]; silly copy-paste mistake.
thanks
-- PMM
PATCH 57/86 hw/intc/arm_gicv5: Factor out code to fill in a GICv5ISTConfig
In reply to Peter Maydellirs_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.
--- hw/intc/arm_gicv5.c | 181 ++++++++++++++++++++++++-------------------- 1 file changed, 100 insertions(+), 81 deletions(-)
hw/intc/arm_gicv5.c +100 -81
@@ -976,6 +976,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. We don't +* want to free the keys, but we do want to free the values +* (which are pointer-to-uint32_t). +*/ + cfg->lpi_cache =g_hash_table_new_full (NULL ,NULL ,NULL , g_free); + } + cfg->valid = true; +} +static void irs_map_l2_istr_write (GICv5 *s,GICv5Domain domain,uint64_t value) {GICv5Common *cs =ARM_GICV5_COMMON (s);
@@ -1086,92 +1176,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. We don't -* want to free the keys, but we do want to free the values -* (which are pointer-to-uint32_t). -*/ - cfg->lpi_cache =g_hash_table_new_full (NULL ,NULL ,NULL , g_free); - } - 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);
Signature · 1 line
2.43.0
PATCH 58/86 hw/intc/arm_gicv5: Cache info about valid VMs in a hashtable
In reply to Peter MaydellThe 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.
--- hw/intc/arm_gicv5.c | 216 ++++++++++++++++++++++++++++++- hw/intc/trace-events | 1 + include/hw/intc/arm_gicv5.h | 2 + include/hw/intc/arm_gicv5_regs.h | 3 + 4 files changed, 216 insertions(+), 6 deletions(-)
hw/intc/arm_gicv5.c +210 -6
@@ -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" ,
@@ -74,6 +88,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) {/*
@@ -1116,6 +1146,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;
@@ -1197,6 +1338,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);
@@ -1213,6 +1388,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;
@@ -1273,6 +1449,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,
@@ -1346,7 +1532,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) {
@@ -1375,16 +1561,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 ;
@@ -1999,6 +2194,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); + } } }
@@ -2121,6 +2320,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]); } }
hw/intc/trace-events +1 -0
@@ -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"
include/hw/intc/arm_gicv5.h +2 -0
@@ -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;/*
include/hw/intc/arm_gicv5_regs.h +3 -0
@@ -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.
Signature · 1 line
2.43.0
PATCH 59/86 hw/intc/arm_gicv5: Populate VM cache when VM table becomes valid
In reply to Peter MaydellUnlike 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.
--- hw/intc/arm_gicv5.c | 80 +++++++++++++++++++++++++++++++- include/hw/intc/arm_gicv5_regs.h | 3 ++ 2 files changed, 82 insertions(+), 1 deletion(-)
hw/intc/arm_gicv5.c +79 -1
@@ -1257,6 +1257,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;
@@ -1461,6 +1527,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); }
@@ -1472,7 +1541,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;
@@ -1514,6 +1583,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 ;
include/hw/intc/arm_gicv5_regs.h +3 -0
@@ -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
Signature · 1 line
2.43.0
PATCH 60/86 hw/intc/arm_gicv5: Implement IRS_VMAP_VISTR
In reply to Peter MaydellA 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.
--- hw/intc/arm_gicv5.c | 154 +++++++++++++++++++++++++++++ hw/intc/arm_gicv5_common.c | 1 + hw/intc/trace-events | 1 + include/hw/intc/arm_gicv5_common.h | 1 + 4 files changed, 157 insertions(+)
hw/intc/arm_gicv5.c +154 -0
@@ -1438,6 +1438,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);
@@ -1668,6 +1691,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) {/*
@@ -1839,6 +1957,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
@@ -1979,6 +2113,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;
@@ -2087,6 +2230,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;
@@ -2108,6 +2259,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;
hw/intc/arm_gicv5_common.c +1 -0
@@ -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)); } }
hw/intc/trace-events +1 -0
@@ -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"
include/hw/intc/arm_gicv5_common.h +1 -0
@@ -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
Signature · 1 line
2.43.0
PATCH 61/86 hw/intc/arm_gicv5: Factor out "make an L2 IST valid" function
In reply to Peter Maydellirs_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.
--- hw/intc/arm_gicv5.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
hw/intc/arm_gicv5.c +10 -4
@@ -1096,11 +1096,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;
@@ -1138,6 +1135,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)
Signature · 1 line
2.43.0
PATCH 62/86 hw/intc/arm_gicv5: Implement IRS_VMAP_L2_VISTR
In reply to Peter MaydellThe 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.
--- hw/intc/arm_gicv5.c | 76 ++++++++++++++++++++++++++++++ hw/intc/arm_gicv5_common.c | 1 + include/hw/intc/arm_gicv5_common.h | 1 + 3 files changed, 78 insertions(+)
hw/intc/arm_gicv5.c +76 -0
@@ -1792,6 +1792,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) {/*
@@ -1979,6 +2019,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
@@ -2128,6 +2184,15 @@ 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_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_vistr[domain], +32 ,32 , data)); +return true;case A_IRS_SPI_SELR : cs->irs_spi_selr[domain] = data;return true;
@@ -2244,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;
@@ -2268,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;
hw/intc/arm_gicv5_common.c +1 -0
@@ -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)); } }
include/hw/intc/arm_gicv5_common.h +1 -0
@@ -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
Signature · 1 line
2.43.0
Re: [PATCH 62/86] hw/intc/arm_gicv5: Implement IRS_VMAP_L2_VISTR
Quoted 13 lines · Peter Maydell
The
IRS_VMAP_L2_VISTRallows the guest to make an L2 entry in the VM's VLPI or VSPI IST valid; it is the equivalent of whatIRS_MAP_L2_ISTRdoes for the physical LPI IST.Signed-off-by Peter Maydell <[email protected]>--- hw/intc/arm_gicv5.c | 76 ++++++++++++++++++++++++++++++ hw/intc/arm_gicv5_common.c | 1 + include/hw/intc/arm_gicv5_common.h | 1 + 3 files changed, 78 insertions(+)
hw/intc/arm_gicv5.c static bool config_writel(GICv5 *s, GICv5Domain domain, hwaddr offset, · line 2189
Quoted 6 lines
hw/intc/arm_gicv5.c +3
-0@@ -2128,6 +2184,15 @@ 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_vistr[domain],0 ,32 , data));
irs_vmap_l2_vistr[] typo?
hw/intc/arm_gicv5.c static bool config_writel(GICv5 *s, GICv5Domain domain, hwaddr offset, · line 2194
Quoted 5 lines
hw/intc/arm_gicv5.c +5
-0+return true; +case A_IRS_VMAP_L2_VISTR +4 : +irs_vmap_l2_vistr_write (s, domain, +deposit64 (cs->irs_vmap_vistr[domain], +32 ,32 , data));
(ditto?)
Quoted 4 lines
hw/intc/arm_gicv5.c +1
-0+return true;case A_IRS_SPI_SELR : cs->irs_spi_selr[domain] = data;return true;
Re: [PATCH 62/86] hw/intc/arm_gicv5: Implement IRS_VMAP_L2_VISTR
Quoted 24 lines · Philippe Mathieu-Daudé
Quoted 13 lines · Peter Maydell
The
IRS_VMAP_L2_VISTRallows the guest to make an L2 entry in the VM's VLPI or VSPI IST valid; it is the equivalent of whatIRS_MAP_L2_ISTRdoes for the physical LPI IST.Signed-off-by Peter Maydell <[email protected]>--- hw/intc/arm_gicv5.c | 76 ++++++++++++++++++++++++++++++ hw/intc/arm_gicv5_common.c | 1 + include/hw/intc/arm_gicv5_common.h | 1 + 3 files changed, 78 insertions(+)hw/intc/arm_gicv5.c static bool config_writel(GICv5 *s, GICv5Domain domain, hwaddr offset, · line 2189
Quoted 6 lines
hw/intc/arm_gicv5.c +3
-0@@ -2128,6 +2184,15 @@ 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_vistr[domain],0 ,32 , data));irs_vmap_l2_vistr[] typo?
Quoted 8 lines
hw/intc/arm_gicv5.c static bool config_writel(GICv5 *s, GICv5Domain domain, hwaddr offset, · line 2194
Quoted 5 lines
hw/intc/arm_gicv5.c +5
-0+return true; +case A_IRS_VMAP_L2_VISTR +4 : +irs_vmap_l2_vistr_write (s, domain, +deposit64 (cs->irs_vmap_vistr[domain], +32 ,32 , data));(ditto?)
Yep, more cut-n-paste mistakes; thanks for spotting them.
-- PMM
PATCH 63/86 hw/intc/arm_gicv5: Cache VPE table information
In reply to Peter MaydellEach 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.
--- hw/intc/arm_gicv5.c | 62 ++++++++++++++++++++++++++++++-- hw/intc/trace-events | 1 + include/hw/intc/arm_gicv5_regs.h | 3 ++ 3 files changed, 64 insertions(+), 2 deletions(-)
hw/intc/arm_gicv5.c +60 -2
@@ -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" ,
@@ -101,6 +111,8 @@ static void VMTE_free(void *data)g_hash_table_destroy (vmte->spi_ist.lpi_cache); } +g_free (vmte->vpet); +g_free (vmte); }
@@ -1219,6 +1231,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)
@@ -1243,6 +1300,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
hw/intc/trace-events +1 -0
@@ -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"
include/hw/intc/arm_gicv5_regs.h +3 -0
@@ -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.
Signature · 1 line
2.43.0
PATCH 64/86 hw/intc/arm_gicv5: Implement IRS_VMAP_VPER
In reply to Peter MaydellThe 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.
--- hw/intc/arm_gicv5.c | 94 ++++++++++++++++++++++++++++++ hw/intc/arm_gicv5_common.c | 1 + hw/intc/trace-events | 1 + include/hw/intc/arm_gicv5_common.h | 1 + 4 files changed, 97 insertions(+)
hw/intc/arm_gicv5.c +94 -0
@@ -1890,6 +1890,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) {/*
@@ -2093,6 +2152,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_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;
hw/intc/arm_gicv5_common.c +1 -0
@@ -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)); } }
hw/intc/trace-events +1 -0
@@ -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"
include/hw/intc/arm_gicv5_common.h +1 -0
@@ -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
Signature · 1 line
2.43.0
PATCH 65/86 hw/intc/arm_gicv5: Implement IRS_VPE_SELR and IRS_VPE_STATUSR
In reply to Peter MaydellThe 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.
--- hw/intc/arm_gicv5.c | 111 +++++++++++++++++++++++++++++ hw/intc/arm_gicv5_common.c | 6 ++ hw/intc/trace-events | 1 + include/hw/intc/arm_gicv5_common.h | 2 + 4 files changed, 120 insertions(+)
hw/intc/arm_gicv5.c +111 -0
@@ -116,6 +116,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) {/*
@@ -1949,6 +1967,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) {/*
@@ -2168,6 +2236,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;
hw/intc/arm_gicv5_common.c +6 -0
@@ -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 ; + } } }
hw/intc/trace-events +1 -0
@@ -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"
include/hw/intc/arm_gicv5_common.h +2 -0
@@ -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
Signature · 1 line
2.43.0
PATCH 66/86 hw/intc/arm_gicv5: Implement IRS_VPE_DBR
In reply to Peter MaydellThe 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.
--- hw/intc/arm_gicv5.c | 105 ++++++++++++++++++++++++++++- hw/intc/arm_gicv5_common.c | 1 + hw/intc/trace-events | 2 + include/hw/intc/arm_gicv5_common.h | 1 + 4 files changed, 107 insertions(+), 2 deletions(-)
hw/intc/arm_gicv5.c +103 -2
@@ -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 */
@@ -1257,6 +1261,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; } }
@@ -2008,7 +2014,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 ; }
@@ -2017,6 +2036,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) {/*
@@ -2252,6 +2318,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;
hw/intc/arm_gicv5_common.c +1 -0
@@ -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 ;
hw/intc/trace-events +2 -0
@@ -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"
include/hw/intc/arm_gicv5_common.h +1 -0
@@ -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
Signature · 1 line
2.43.0
PATCH 67/86 hw/intc/arm_gicv5: Implement IRS_VPE_CR0
In reply to Peter MaydellIRS_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.
--- hw/intc/arm_gicv5.c | 7 +++++++ 1 file changed, 7 insertions(+)
hw/intc/arm_gicv5.c +7 -0
@@ -2334,6 +2334,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;
Signature · 1 line
2.43.0
PATCH 68/86 hw/intc/arm_gicv5: Implement gicv5_set_resident()
In reply to Peter MaydellWhen 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.
--- hw/intc/arm_gicv5.c | 115 +++++++++++++++++++++++++++++++++++- hw/intc/trace-events | 2 + include/hw/intc/arm_gicv5.h | 5 ++ 3 files changed, 120 insertions(+), 2 deletions(-)
hw/intc/arm_gicv5.c +113 -2
@@ -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 */
@@ -1182,8 +1184,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,
@@ -1566,6 +1649,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 (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;
@@ -1713,6 +1798,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);
@@ -1762,6 +1861,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)
hw/intc/trace-events +2 -0
@@ -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"
include/hw/intc/arm_gicv5.h +5 -0
@@ -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 {
Signature · 1 line
2.43.0
Re: [PATCH 68/86] hw/intc/arm_gicv5: Implement gicv5_set_resident()
Quoted 13 lines · Peter Maydell
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 ingicv5_set_resident()and then clear it when a VM becomes invalid or the whole VM table is made invalid.
Quoted 5 lines
Signed-off-by Peter Maydell <[email protected]>--- hw/intc/arm_gicv5.c | 115 +++++++++++++++++++++++++++++++++++- hw/intc/trace-events | 2 + include/hw/intc/arm_gicv5.h | 5 ++
(please enable scripts/git.orderfile to ease mailing list code review)
hw/intc/arm_gicv5.c static void irs_vmt_baser_write(GICv5 *s, GICv5Domain domain, uint64_t value) · line 1653
Quoted 6 lines
hw/intc/arm_gicv5.c +2
-0@@ -1566,6 +1649,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 (VPE ) * cs->num_cpus);
res_vpe is declared as:
VPE **res_vpe;
so IIUC we should use sizeof(*VPE), or the sizeof(*s->res_vpe) used below to keep the same style.
hw/intc/arm_gicv5.c static void gicv5_reset_hold(Object *obj, ResetType type) · line 2991
Quoted 12 lines
hw/intc/arm_gicv5.c +4
-0cs->irs_vmt_baser[domain] =FIELD_DP64 (cs->irs_vmt_baser[domain],IRS_VMT_BASER ,VALID , valid);@@ -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);
OK.
hw/intc/arm_gicv5.c static void gicv5_realize(DeviceState *dev, Error **errp) · line 3099
Quoted 11 lines
hw/intc/arm_gicv5.c +4
-0+ } }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);
OK.
Quoted 27 lines
hw/intc/arm_gicv5.c +1
-0+ } }include/hw/intc/arm_gicv5.h +5
-0@@ -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 {
Re: [PATCH 68/86] hw/intc/arm_gicv5: Implement gicv5_set_resident()
Quoted 15 lines · Philippe Mathieu-Daudé
Quoted 13 lines · Peter Maydell
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 ingicv5_set_resident()and then clear it when a VM becomes invalid or the whole VM table is made invalid.
Quoted 7 lines
Quoted 5 lines
Signed-off-by Peter Maydell <[email protected]>--- hw/intc/arm_gicv5.c | 115 +++++++++++++++++++++++++++++++++++- hw/intc/trace-events | 2 + include/hw/intc/arm_gicv5.h | 5 ++(please enable
scripts/git.orderfileto ease mailing list code review)
Done.
Quoted 9 lines
hw/intc/arm_gicv5.c static void irs_vmt_baser_write(GICv5 *s, GICv5Domain domain, uint64_t value) · line 1653
Quoted 6 lines
hw/intc/arm_gicv5.c +2
-0@@ -1566,6 +1649,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 (VPE ) * cs->num_cpus);
res_vpeis declared as:
Quoted 4 lines
VPE **res_vpe;so IIUC we should use
sizeof(*VPE), or thesizeof(*s->res_vpe)used below to keep the same style.
Yes. I found and fixed this bug in the reset code path, which is why that part is different, but didn't notice I still had the same bug here. We should use the same thing we do below (it makes it more obvious that the type is correct than using "VPE*", I think).
Quoted 4 lines
Quoted 2 lines
hw/intc/arm_gicv5.c +0
-0cs->irs_vmt_baser[domain] =FIELD_DP64 (cs->irs_vmt_baser[domain],IRS_VMT_BASER ,VALID , valid);
Quoted 10 lines
hw/intc/arm_gicv5.c static void gicv5_reset_hold(Object *obj, ResetType type) · line 2991
Quoted 8 lines
hw/intc/arm_gicv5.c +4
-0@@ -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);OK.
thanks
-- PMM
PATCH 69/86 hw/intc/arm_gicv5: Take cpuidx for stream commands on virtual interrupts
In reply to Peter MaydellIn 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.
--- hw/intc/arm_gicv5.c | 18 ++++++++++-------- include/hw/intc/arm_gicv5_stream.h | 25 +++++++++++++++++-------- target/arm/tcg/gicv5-cpuif.c | 21 ++++++++++++--------- 3 files changed, 39 insertions(+), 25 deletions(-)
hw/intc/arm_gicv5.c +10 -8
@@ -568,7 +568,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;
@@ -623,7 +624,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;
@@ -676,7 +678,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;
@@ -729,7 +731,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);
@@ -777,7 +779,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;
@@ -889,7 +891,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;
@@ -933,7 +935,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;
@@ -991,7 +993,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;
include/hw/intc/arm_gicv5_stream.h +17 -8
@@ -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
target/arm/tcg/gicv5-cpuif.c +12 -9
@@ -680,7 +680,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,
@@ -692,7 +692,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,
@@ -705,7 +705,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,
@@ -719,7 +720,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,
@@ -759,7 +761,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,
@@ -772,7 +775,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,
@@ -785,7 +788,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)
@@ -1466,7 +1469,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 ();
@@ -1543,7 +1546,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 ;
Signature · 1 line
2.43.0
PATCH 70/86 hw/intc/arm_gicv5: Handle virtual=true in gicv5_set_priority()
In reply to Peter MaydellThe 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.
--- hw/intc/arm_gicv5.c | 90 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 82 insertions(+), 8 deletions(-)
hw/intc/arm_gicv5.c +82 -8
@@ -567,6 +567,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)
@@ -580,8 +655,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 ; }
@@ -589,15 +668,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 :
Signature · 1 line
2.43.0
PATCH 71/86 hw/intc/arm_gicv5: Handle virtual=true for setting enabled, pending, handling
In reply to Peter MaydellAdd 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.
--- hw/intc/arm_gicv5.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
hw/intc/arm_gicv5.c +15 -15
@@ -641,6 +641,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,
@@ -707,8 +709,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 ; }
@@ -716,15 +722,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 :
@@ -812,8 +813,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 ; }
@@ -821,14 +825,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 :
Signature · 1 line
2.43.0
PATCH 72/86 hw/intc/arm_gicv5: Handle virtual=true for setting pending
In reply to Peter MaydellAdd 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.
--- hw/intc/arm_gicv5.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-)
hw/intc/arm_gicv5.c +26 -8
@@ -643,6 +643,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,
@@ -761,8 +762,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 ; }
@@ -770,15 +793,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 :
Signature · 1 line
2.43.0
PATCH 73/86 hw/intc/arm_gicv5: Handle virtual=true in gicv5_set_target()
In reply to Peter MaydellSupport 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.
--- hw/intc/arm_gicv5.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-)
hw/intc/arm_gicv5.c +20 -16
@@ -644,6 +644,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,
@@ -878,11 +879,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" );
@@ -893,24 +889,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 :
Signature · 1 line
2.43.0
PATCH 74/86 hw/intc/arm_gicv5: Handle virtual=true in gicv5_deactivate()
In reply to Peter MaydellHandle deactivation of a virtual interrupt, using a similar process to virtual interrupt config updates.
--- hw/intc/arm_gicv5.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
hw/intc/arm_gicv5.c +8 -8
@@ -645,6 +645,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,
@@ -1097,8 +1098,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 ; }
@@ -1106,15 +1111,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 :
Signature · 1 line
2.43.0
PATCH 75/86 hw/intc/arm_gicv5: Handle activation of a virtual interrupt
In reply to Peter MaydellHandle 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.
--- hw/intc/arm_gicv5.c | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-)
hw/intc/arm_gicv5.c +30 -11
@@ -1031,6 +1031,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) {
@@ -1040,8 +1063,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 ; }
@@ -1049,18 +1076,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 :
Signature · 1 line
2.43.0
PATCH 76/86 hw/intc/arm_gicv5: Handle virtual=true in gicv5_request_config()
In reply to Peter MaydellSupport 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.
--- hw/intc/arm_gicv5.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
hw/intc/arm_gicv5.c +13 -3
@@ -994,9 +994,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) {
Signature · 1 line
2.43.0
PATCH 77/86 hw/intc/arm_gicv5: Implement irs_recalc_vhppi()
In reply to Peter MaydellRecalculate 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.
--- hw/intc/arm_gicv5.c | 43 ++++++++++++++++++++++++++++++++++++++++--- hw/intc/trace-events | 2 ++ 2 files changed, 42 insertions(+), 3 deletions(-)
hw/intc/arm_gicv5.c +40 -3
@@ -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 */
@@ -192,6 +193,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)
@@ -208,7 +210,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; }
@@ -257,6 +259,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); }
@@ -572,9 +575,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,
@@ -1473,6 +1509,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 ; } }
hw/intc/trace-events +2 -0
@@ -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"
Signature · 1 line
2.43.0
PATCH 78/86 hw/intc/arm_gicv5: Recalculate vHPPIs on VIST and VPE mapping
In reply to Peter MaydellIf 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.
--- hw/intc/arm_gicv5.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
hw/intc/arm_gicv5.c +17 -0
@@ -613,6 +613,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,
@@ -2131,6 +2144,8 @@ static void irs_vmap_vistr_write(GICv5 *s, GICv5Domain domain, uint64_t value) }return ; +irs_recalc_all_vhppi_for_vm (s, vmte); + 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 "
@@ -2228,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:
Signature · 1 line
2.43.0
Re: [PATCH 78/86] hw/intc/arm_gicv5: Recalculate vHPPIs on VIST and VPE mapping
Quoted 39 lines · Peter Maydell
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 viaIRS_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 <[email protected]>--- hw/intc/arm_gicv5.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)hw/intc/arm_gicv5.c +13
-0@@ -613,6 +613,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,
hw/intc/arm_gicv5.c static void irs_vmap_vistr_write(GICv5 *s, GICv5Domain domain, uint64_t value) · line 2148
Quoted 5 lines
hw/intc/arm_gicv5.c +2
-0@@ -2131,6 +2144,8 @@ static void irs_vmap_vistr_write(GICv5 *s, GICv5Domain domain, uint64_t value) }return ; +irs_recalc_all_vhppi_for_vm (s, vmte); +
This call should obviously go before the "return", not after.
-- PMM
PATCH 79/86 hw/intc/arm_gicv5: Add virtual support to gicv5_get_hppi()
In reply to Peter MaydellIf a CPU asks for the virtual HPPI for its resident VPE, return it.
--- hw/intc/arm_gicv5.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
hw/intc/arm_gicv5.c +7 -5
@@ -348,11 +348,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]; }
Signature · 1 line
2.43.0
PATCH 80/86 hw/intc/arm_gicv5: Implement IRS_VPE_HPPIR
In reply to Peter MaydellNow 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.
--- hw/intc/arm_gicv5.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
hw/intc/arm_gicv5.c +39 -0
@@ -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 ;
@@ -2962,6 +2993,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;
Signature · 1 line
2.43.0
PATCH 81/86 hw/intc/arm_gicv5: Implement ringing doorbells for VPEs
In reply to Peter MaydellFor 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 byR_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.
--- hw/intc/arm_gicv5.c | 62 ++++++++++++++++++++++++++++++++++++-------- hw/intc/trace-events | 1 + 2 files changed, 52 insertions(+), 11 deletions(-)
hw/intc/arm_gicv5.c +51 -11
@@ -572,6 +572,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) {/*
@@ -612,7 +659,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)
@@ -1428,11 +1475,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],
hw/intc/trace-events +1 -0
@@ -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"
Signature · 1 line
2.43.0
PATCH 82/86 hw/intc/arm_gicv5: Handle vHPPIs when IRS_CR0.IRSEN is toggled
In reply to Peter MaydellThe 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.
--- hw/intc/arm_gicv5.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
hw/intc/arm_gicv5.c +31 -0
@@ -340,6 +340,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) {
@@ -347,6 +372,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];
Signature · 1 line
2.43.0
PATCH 83/86 hw/intc/arm_gicv5: Implement saving virtual interrupt state to guest memory
In reply to Peter MaydellThe 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.
--- hw/intc/arm_gicv5.c | 104 +++++++++++++++++++++++++++++ hw/intc/arm_gicv5_common.c | 1 + hw/intc/trace-events | 1 + include/hw/intc/arm_gicv5_common.h | 1 + 4 files changed, 107 insertions(+)
hw/intc/arm_gicv5.c +104 -0
@@ -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) +{ +uint64_t id =GPOINTER_TO_INT (key); +uint64_t l2_iste = *(uint32_t *)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 ;
@@ -2913,6 +2998,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;
@@ -3072,6 +3165,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;
@@ -3108,6 +3209,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;
hw/intc/arm_gicv5_common.c +1 -0
@@ -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_vpe_dbr));for (int i =0 ; i <NUM_GICV5_DOMAINS ; i++) { cs->irs_vpe_statusr[i] =R_IRS_VPE_STATUSR_IDLE_MASK ;
hw/intc/trace-events +1 -0
@@ -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"
include/hw/intc/arm_gicv5_common.h +1 -0
@@ -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
Signature · 1 line
2.43.0
Re: [PATCH 83/86] hw/intc/arm_gicv5: Implement saving virtual interrupt state to guest memory
Quoted 11 lines · Peter Maydell
The
IRS_SAVE_VMRregister 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.)hw/intc/arm_gicv5_common.c +0
-0
hw/intc/arm_gicv5_common.c static void gicv5_common_reset_hold(Object *obj, ResetType type) · line 119
Quoted 4 lines
hw/intc/arm_gicv5_common.c +1
-0@@ -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_vpe_dbr));
Cut and paste error again -- should be sizeof(cs->irs_save_vmr)). (Currently a harmless error since they're the same size.)
-- PMM
PATCH 84/86 hw/intc/arm_gicv5: Implement reporting of Quiesced state
In reply to Peter MaydellImplement 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.
--- hw/intc/arm_gicv5.c | 77 ++++++++++++++++++++++++++++++++++++++++++-- hw/intc/trace-events | 1 + 2 files changed, 75 insertions(+), 3 deletions(-)
hw/intc/arm_gicv5.c +74 -3
@@ -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 */ };
@@ -914,6 +915,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 ; }
@@ -1171,7 +1174,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;
@@ -1185,6 +1189,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);
@@ -1201,10 +1208,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 ; }
@@ -1214,7 +1226,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 ;
@@ -1484,6 +1496,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 ;
hw/intc/trace-events +1 -0
@@ -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"
Signature · 1 line
2.43.0
PATCH 85/86 hw/intc/arm_gicv5: Implement no-passthrough IRS_SPI_VMR
In reply to Peter MaydellThe 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.
--- hw/intc/arm_gicv5.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
hw/intc/arm_gicv5.c +35 -0
@@ -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 ;
@@ -3077,6 +3100,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;
@@ -3244,6 +3273,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;
@@ -3283,6 +3316,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;
Signature · 1 line
2.43.0
PATCH 86/86 hw/arm/virt: allow virtualization=on with gicv5
In reply to Peter MaydellNow 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'.
--- hw/arm/virt.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
hw/arm/virt.c +2 -3
@@ -3015,9 +3015,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 ); }
Signature · 1 line
2.43.0
Hi Peter,
Quoted 15 lines · Peter Maydell
This patchset adds virtualization support to our GICv5 model, and lets the "virt" board use -machine gic-version=x-5,virtualization=on.
Virtualization in the GICv5 is more complicated than it is in GICv3. This is because in GICv3 virtualization is mostly delegated to software, and only the CPU interface has hardware virtualization support. In GICv5 the hardware does a lot more of the work, so virtualization support is needed in both the CPU interface and the IRS.
I've structured this patchset as:
* initial preparatory and bug-fixing patches
* add virt support to the cpu interface
* add virt support to the IRS
* remove the check in virt that stops the user enabling virt
Quoted 5 lines
The first 11 patches have been on this list already; I've copied across Reviewed-by tags for those patches which got them.
The current spec for the GICv5 is at
https://support.arm.com/documentation/aes0070/00eac0/
Now A.a: https://support.arm.com/documentation/111701/latest
Quoted 10 lines
The kernel support for using GICv5 virtualization is not yet in mainline, but it has landed in the kvmarm/next tree:
https://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git next Similarly kvmtool support to run the inner guest is still work in progress, but the tree at
https://gitlab.arm.com/linux-arm/kvmtool-sb.gitgicv5_wipwill work with the kvmarm/next tree.This series can pass the kernel's
vgic_v5selftest, and boot an inner guest to userspace with kvmtool.
Could we have a functional test similar totests/functional/aarch64/test_kvm.py?
Quoted 19 lines · Philippe Mathieu-Daudé
Hi Peter,
Quoted 15 lines · Peter Maydell
This patchset adds virtualization support to our GICv5 model, and lets the "virt" board use -machine gic-version=x-5,virtualization=on.
Virtualization in the GICv5 is more complicated than it is in GICv3. This is because in GICv3 virtualization is mostly delegated to software, and only the CPU interface has hardware virtualization support. In GICv5 the hardware does a lot more of the work, so virtualization support is needed in both the CPU interface and the IRS.
I've structured this patchset as:
* initial preparatory and bug-fixing patches
* add virt support to the cpu interface
* add virt support to the IRS
* remove the check in virt that stops the user enabling virt
Quoted 7 lines
Quoted 5 lines
The first 11 patches have been on this list already; I've copied across Reviewed-by tags for those patches which got them.
The current spec for the GICv5 is at
https://support.arm.com/documentation/aes0070/00eac0/Now A.a: https://support.arm.com/documentation/111701/latest
Whoops. I should have checked more carefully the google search result I got back :-) (We do get the URL right in the comments in the code -- we updated it when A.a came out.)
Quoted 8 lines
Quoted 8 lines
The kernel support for using GICv5 virtualization is not yet in mainline, but it has landed in the kvmarm/next tree:
https://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git next Similarly kvmtool support to run the inner guest is still work in progress, but the tree at
https://gitlab.arm.com/linux-arm/kvmtool-sb.gitgicv5_wipwill work with the kvmarm/next tree.
Quoted 5 lines
Quoted 2 lines
This series can pass the kernel's
vgic_v5selftest, and boot an inner guest to userspace with kvmtool.Could we have a functional test similar to
tests/functional/aarch64/test_kvm.py?
kvm-unit-tests currently has no support for GICv5.
We should be able to have some kind of functional test eventually, but it will need to wait until the kernel patches at least have hit mainline.
thanks
-- PMM
Quoted 15 lines · Peter Maydell
Quoted 11 lines · Philippe Mathieu-Daudé
Quoted 10 lines
The kernel support for using GICv5 virtualization is not yet in mainline, but it has landed in the kvmarm/next tree:
https://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git next Similarly kvmtool support to run the inner guest is still work in progress, but the tree at
https://gitlab.arm.com/linux-arm/kvmtool-sb.gitgicv5_wipwill work with the kvmarm/next tree.This series can pass the kernel's
vgic_v5selftest, and boot an inner guest to userspace with kvmtool.
Quoted 7 lines
Quoted 2 lines
Could we have a functional test similar to
tests/functional/aarch64/test_kvm.py?kvm-unit-tests currently has no support for GICv5.
We should be able to have some kind of functional test eventually, but it will need to wait until the kernel patches at least have hit mainline.
What Alex usually does is build an image and store it in share.linaro.org (previously fileserver.linaro.org, see commit ebbc04adbb079066f8d180b8744c1c01c6de23f9 for example). Better would be to store a tarball with reproducible steps and binary. That would be the custom kernel + kvmtool, allowing to have coverage and test regressions on QEMU side. We can still update / remove when Linux support is merged.
Quoted 6 lines · Peter Maydell
This patchset adds virtualization support to our GICv5 model, and lets the "virt" board use -machine gic-version=x-5,virtualization=on.
In an ideal world I'd like to land this for 11.2, but I appreciate that it's a lot of code to review and only two weeks til softfreeze; we'll see how it goes.
I did a "quick" review (2h...) and couldn't spot anything beside few typos w.r.t. the spec. The overall logic LGTM. Better if someone else can have a closer look at ARMCPRegInfo fields checked, but since this is experimental anyway I don't see any issue having it merged for 11.2. My 2 cents ;)
Hi Peter,
Quoted 150 lines · Peter Maydell
This patchset adds virtualization support to our GICv5 model, and lets the "virt" board use -machine gic-version=x-5,virtualization=on.
Virtualization in the GICv5 is more complicated than it is in GICv3. This is because in GICv3 virtualization is mostly delegated to software, and only the CPU interface has hardware virtualization support. In GICv5 the hardware does a lot more of the work, so virtualization support is needed in both the CPU interface and the IRS.
I've structured this patchset as:
* initial preparatory and bug-fixing patches
* add virt support to the cpu interface
* add virt support to the IRS
* remove the check in virt that stops the user enabling virtThe first 11 patches have been on this list already; I've copied across Reviewed-by tags for those patches which got them.
The current spec for the GICv5 is at
https://support.arm.com/documentation/aes0070/00eac0/The kernel support for using GICv5 virtualization is not yet in mainline, but it has landed in the kvmarm/next tree:
https://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git next Similarly kvmtool support to run the inner guest is still work in progress, but the tree at
https://gitlab.arm.com/linux-arm/kvmtool-sb.gitgicv5_wipwill work with the kvmarm/next tree.This series can pass the kernel's
vgic_v5selftest, and boot an inner guest to userspace with kvmtool.In an ideal world I'd like to land this for 11.2, but I appreciate that it's a lot of code to review and only two weeks til softfreeze; we'll see how it goes.
If you want a git branch of this I've pushed the patchset to
https://gitlab.com/pm215/qemu.git gicv5-virtthanks
-- PMMPeter Maydell (86):
hw/intc/arm_gicv5: MakeIRS_IDR0reads return actual value, not 0 hw/intc/arm_gicv5: Ignore low bits in IRS_IST_BASER.ADDR hw/intc/arm_gicv5: Ignore low bits in L1_ISTE.L2_ADDR hw/intc/arm_gicv5: Regularize spacing inconfig_readl()switch hw/intc/arm_gicv5: Use cached IRS_IST_BASER.VALID state hw/intc/arm_gicv5: Free memory in finalize
target/arm: GICv5 cpuif: Usearm_cpu_set_irq()to set IRQ/FIQ status target/arm: Only allow GICv5 on CPUs without AArch32 at EL1..3 hw/intc/arm_gicv5: Pass CPU index to CPU interface hw/intc/arm_gicv5: Pass cpuidx rather than iaffid ingicv5_get_hppi()hw/intc/arm_gicv5: Use correct type for value inlpi_cache_get_hppi()hw/intc/arm_gicv5: RelaxQEMU_GICV5_MIN_LPI_ID_BITSto 0 target/arm: GICv5 cpuif: ImplementICH_APR_EL2
target/arm: GICv5 cpuif: Implement ICH_PPI_{ENABLE,PEND,ACTIVE} regs target/arm: GICv5 cpuif: Implement ICH_PPI_PRIORITYR<n>_EL2 target/arm: GICv5 cpuif: Implement ICH_PPI_DVIR<n>_EL2 target/arm: GICv5 cpuif: ImplementICH_VCTLR_EL2andICH_VCMR_EL2target/arm: GICv5 cpuif: Implement GIC fine-grained trap registers target/arm: GICv5 cpuif: Mark GIC registers for fine-grained traps target/arm: GICv5 cpuif: Mark GIC insns for fine-grained traps target/arm: GICv5 cpuif: ImplementICC_SRE_ELx
target/arm: GICv5 cpuif: Implement ICH_PPI_HVIR<n>_EL2 target/arm: GICv5 cpuif: ImplementICV_APR_EL1
target/arm: GICv5 cpuif: ImplementICV_CR0_EL1
target/arm: GICv5 cpuif: ImplementICV_PCR_EL1
target/arm: GICv5 cpuif: Implement ICV_PPI_ENABLER<n>_EL1 target/arm: GICv5 cpuif: Implement ICV_PPI_PRIORITYR<n>_EL1 target/arm: GICv5 cpuif: Add comment about ICV_PPI_HMR<n>_EL1 target/arm: GICv5 cpuif: Implement ICV_PPI_CACTIVER<n>_EL1,ICV_PPI_SACTIVER<n>_EL1 target/arm: GICv5 cpuif: Implement ICV_PPI_CPENDR<n>_EL1, ICV_PPI_SPENDR<n>_EL1target/arm: GICv5 cpuif: Calculate current virtual PPI HPPI target/arm: GICv5 cpuif: Add virtual support to IRS/cpuif HPPI APIs target/arm: GICv5 cpuif: Implement
ICV_HPPIR_EL1target/arm: GICv5 cpuif: Implementgicv5_update_virq_vfiq()target/arm: GICv5 cpuif: ImplementICH_CONTEXTR_EL2target/arm: GICv5 cpuif: ask the GIC for the virtual HPPI target/arm: GICv5 cpuif: Handle LD/VD insns when setting
domain/virtual args
target/arm: GICv5 cpuif: Handle virtual interrupts for GIC CDEOI target/arm: GICv5 cpuif: Handle virtual interrupts for GIC CDDI target/arm: GICv5 cpuif: Handle virtual interrupts for GICR CDIA,
CDNMIA
target/arm: GICv5 cpuif: Handle GIC VDPEND VM argument target/arm: GICv5 cpuif: Implement GIC VDnnn insns target/arm: GICv5 cpuif: Implement GIC LDnnn insns target/arm: GICv5 cpuif: Handle PPI injection in vPPI pending reads target/arm: GICv5 cpuif: Handle PPI injection in vPPI pending writes target/arm: GICv5 cpuif: Handle injected PPIs in GICR CDIA target/arm: GICv5 cpuif: Update on HCR_EL2.{NV,NV1} and SCR_EL3.NS
changes
target/arm: GICv5 cpuif: Update VFIQ/VIRQ when direct-injected PPIs
change
hw/intc: Move GICv5 register and data definitions into a header hw/intc/arm_gicv5: Correct offset forIRS_VMT_STATUSRhw/intc/arm_gicv5: Ask CPUs whether IRS needs virtualization support hw/intc/arm_gicv5: Indicate virtualization in ID registers hw/intc/arm_gicv5: ImplementIRS_VMT_BASERandIRS_VMT_STATUSRhw/intc/arm_gicv5: IMplementIRS_VMT_CFGRhw/intc/arm_gicv5: ImplementIRS_VMAP_L2_VMTRhw/intc/arm_gicv5: ImplementIRS_VMAP_VMRhw/intc/arm_gicv5: Factor out code to fill in a GICv5ISTConfig hw/intc/arm_gicv5: Cache info about valid VMs in a hashtable hw/intc/arm_gicv5: Populate VM cache when VM table becomes valid hw/intc/arm_gicv5: ImplementIRS_VMAP_VISTRhw/intc/arm_gicv5: Factor out "make an L2 IST valid" function hw/intc/arm_gicv5: ImplementIRS_VMAP_L2_VISTRhw/intc/arm_gicv5: Cache VPE table information hw/intc/arm_gicv5: ImplementIRS_VMAP_VPERhw/intc/arm_gicv5: ImplementIRS_VPE_SELRandIRS_VPE_STATUSRhw/intc/arm_gicv5: ImplementIRS_VPE_DBRhw/intc/arm_gicv5: ImplementIRS_VPE_CR0hw/intc/arm_gicv5: Implementgicv5_set_resident()hw/intc/arm_gicv5: Take cpuidx for stream commands on virtual
interrupts
hw/intc/arm_gicv5: Handle virtual=true ingicv5_set_priority()hw/intc/arm_gicv5: Handle virtual=true for setting enabled, pending,
handling
hw/intc/arm_gicv5: Handle virtual=true for setting pending hw/intc/arm_gicv5: Handle virtual=true ingicv5_set_target()hw/intc/arm_gicv5: Handle virtual=true ingicv5_deactivate()hw/intc/arm_gicv5: Handle activation of a virtual interrupt hw/intc/arm_gicv5: Handle virtual=true ingicv5_request_config()hw/intc/arm_gicv5: Implementirs_recalc_vhppi()hw/intc/arm_gicv5: Recalculate vHPPIs on VIST and VPE mapping hw/intc/arm_gicv5: Add virtual support togicv5_get_hppi()hw/intc/arm_gicv5: ImplementIRS_VPE_HPPIRhw/intc/arm_gicv5: Implement ringing doorbells for VPEs hw/intc/arm_gicv5: Handle vHPPIs when IRS_CR0.IRSEN is toggled hw/intc/arm_gicv5: Implement saving virtual interrupt state to guest
memory
hw/intc/arm_gicv5: Implement reporting of Quiesced state hw/intc/arm_gicv5: Implement no-passthroughIRS_SPI_VMRhw/arm/virt: allow virtualization=on with gicv5hw/arm/virt.c | 5 +- hw/intc/arm_gicv5.c | 2554 +++++++++++++++++++++++----- hw/intc/arm_gicv5_common.c | 30 +- hw/intc/trace-events | 19 +- include/hw/intc/arm_gicv5.h | 18 + include/hw/intc/arm_gicv5_common.h | 40 +- include/hw/intc/arm_gicv5_regs.h | 325 ++++ include/hw/intc/arm_gicv5_stream.h | 81 +- target/arm/cpregs.h | 85 +- target/arm/cpu-features.h | 8 + target/arm/cpu.c | 72 +-
Quoted 13 lines
target/arm/cpu.h | 33 +- target/arm/gicv5-stubs.c | 8 + target/arm/helper.c | 23 +- target/arm/internals.h | 23 + target/arm/tcg/gicv5-cpuif.c | 1390 +++++++++++++-- target/arm/tcg/trace-events | 10 +- 17 files changed, 4089 insertions(+), 635 deletions(-) create mode 100644 include/hw/intc/arm_gicv5_regs.hSignature · 1 line
2.43.0
Cheers,
Gustavo
Quoted 16 lines · Peter Maydell
This patchset adds virtualization support to our GICv5 model, and lets the "virt" board use -machine gic-version=x-5,virtualization=on.
Virtualization in the GICv5 is more complicated than it is in GICv3. This is because in GICv3 virtualization is mostly delegated to software, and only the CPU interface has hardware virtualization support. In GICv5 the hardware does a lot more of the work, so virtualization support is needed in both the CPU interface and the IRS.
I've structured this patchset as:
* initial preparatory and bug-fixing patches
* add virt support to the cpu interface
* add virt support to the IRS
* remove the check in virt that stops the user enabling virt
Quoted 13 lines
Peter Maydell (86):
hw/intc/arm_gicv5: MakeIRS_IDR0reads return actual value, not 0 hw/intc/arm_gicv5: Ignore low bits in IRS_IST_BASER.ADDR hw/intc/arm_gicv5: Ignore low bits in L1_ISTE.L2_ADDR hw/intc/arm_gicv5: Regularize spacing inconfig_readl()switch hw/intc/arm_gicv5: Use cached IRS_IST_BASER.VALID state hw/intc/arm_gicv5: Free memory in finalize
target/arm: GICv5 cpuif: Usearm_cpu_set_irq()to set IRQ/FIQ status target/arm: Only allow GICv5 on CPUs without AArch32 at EL1..3 hw/intc/arm_gicv5: Pass CPU index to CPU interface hw/intc/arm_gicv5: Pass cpuidx rather than iaffid ingicv5_get_hppi()hw/intc/arm_gicv5: Use correct type for value inlpi_cache_get_hppi()hw/intc/arm_gicv5: RelaxQEMU_GICV5_MIN_LPI_ID_BITSto 0
Just a note that these first twelve patches are all now upstream. I think the rest of the series is still fit for further review, but I'm happy to do a respin of the series if that's helpful for anybody.
thanks
-- PMM