Skip to content

Commit cd5805d

Browse files
committed
cca-irq: add initial GICv3 delivery for timer, SGI, and SPI
Add the initial ARM GICv3 interrupt-delivery framework for CCA lower planes. Route virtual timer PPIs, self-generated SGIs, and shared SPIs through a partition-owned GIC model and inject eligible interrupts through the RMM GIC list registers. Previously, CCA IRQ exits were only logged, trapped GIC accesses did not provide a complete interrupt path, and local interrupt sources could be inserted into an LR without respecting the guest-programmed GIC enable and priority state. CCA interrupt injection ----------------------- Add a common CCA virtual-interrupt representation containing an INTID, priority, group, and pending state. Preserve the GIC list registers returned by the RMM and inject pending software-backed Group 1 interrupts into the first free LR. Avoid adding a duplicate LR when the same INTID is already pending or active. Enable ICH_HCR_EL2.TC for plane entry and encode software LRs with: * the virtual INTID in bits 31:0 * the guest-programmed priority in bits 55:48 * Group 1 in bit 60 * HW clear in bit 61 * Pending state in bits 63:62 Leave EOI-maintenance disabled because the CCA backend does not yet implement the GIC maintenance-interrupt path. Use an invalid exit-reason sentinel to distinguish a real plane exit from a host wakeup, and preserve the RMM-returned plane and LR context before processing the exit. Virtual timer PPI ----------------- Handle PlaneExitReason::Irq and recognize an asserted architectural virtual timer from the RMM-provided CNTV_CTL_EL0 state. Request the timer PPI only when: * ENABLE is set * IMASK is clear * ISTATUS is set Obtain the virtual timer INTID from ProcessorTopology instead of hardcoding PPI 20. This is required because the RMM timer exit reports the timer source but does not provide an INTID. Queue the timer as a private interrupt and pass it through the shared GIC redistributor selection path before LR injection. Delivery therefore now observes: * distributor Group 1 enable * GICR_IGROUPR0 * GICR_ISENABLER0 * GICR active state * the PPI priority programmed through GICR_IPRIORITYR * the priority threshold programmed through ICC_PMR_EL1 Decode trapped ICC_PMR_EL1 writes and retain the current priority mask for each CCA VTL. This fixes timer PPIs bypassing guest GIC enable and priority configuration. SGI --- Decode synchronous ICC_SGI1R_EL1 system-register traps and queue the requested self-SGI rather than injecting it directly. Advance the lower-plane PC after emulating ICC_SGI1R_EL1 and ICC_PMR_EL1 writes so that the trapped instruction is not executed again after re-entry. Route queued SGIs through the same private-interrupt selection used by PPIs. SGI delivery therefore also observes the redistributor enable, Group 1, active, programmed priority, and ICC_PMR_EL1 state. Add a TMK self-SGI test using INTID 5 and the Group 1 system-register interface. SPI --- Create a partition-owned GicV3Model for CCA and expose it to the VP runner so that device interrupt assertion, CCA interrupt polling, and guest GIC MMIO emulation operate on the same state. Implement the CCA ControlGic::set_spi_irq path. Record the device line level, determine the target VPs from GICD_IROUTER state, and wake those VPs through the interrupt-controller wake reason when a line is newly asserted. Track SPI state independently as: * software pending state * external line assertion level * active state * LR/in-flight ownership Select a shared interrupt only when it is pending or asserted, enabled, assigned to Group 1, inactive, routed to the current VP, not already in flight, and has a priority that passes ICC_PMR_EL1. Preserve an edge-triggered SPI request after the source line falls by latching it in the pending state until successful LR injection. Preserve the asserted state of a level-triggered SPI after injection. When the RMM retires its LR, clear only the in-flight ownership. If the device line remains asserted, make the SPI eligible for injection again. Stop redelivery only after the device deasserts the line. This fixes level-triggered SPIs being lost after their first injection and EOI. Support guest software pending and clearing through GICD_ISPENDR and GICD_ICPENDR. Deasserting a device line does not clear an independently created software-pending request. GIC model and TMK support ------------------------- Extend the reusable GICv3 model with the distributor and redistributor state needed by the CCA paths, including: * Group 1 distributor enable * interrupt group and enable state * pending, active, and trigger configuration * per-INTID priorities * SPI routing * GICR SGI/PPI enable, group, pending, active, and priority state * priority-based private and shared interrupt selection * MMIO reads and writes for the supported GICD/GICR registers Define a common TMK AArch64 platform layout: * GICD at 0xff00_0000 * GICR at 0xff02_0000 * virtual timer PPI 20 * 256 exposed INTIDs: SGI 0-15, PPI 16-31, and SPI 32-255 Add minimal EL1 IRQ support to tmk_core: * install an aligned VBAR_EL1 exception-vector table * save and restore registers around IRQ handling * provide scoped IRQ callback registration * configure GIC Group 1, interrupt enable, and priority state * program ICC_SRE_EL1, ICC_PMR_EL1, and ICC_IGRPEN1_EL1 * acknowledge through ICC_IAR1_EL1 * complete through ICC_EOIR1_EL1 * mask and unmask IRQs through DAIF * provide virtual timer, self-SGI, and software-pending SPI helpers Route TMK GIC MMIO accesses to the same partition GicV3Model used by the CCA VP. Add tests for: * architectural virtual timer PPI delivery * self-targeted SGI delivery * software-pended SPI 32 delivery * level-triggered SPI redelivery until deassertion * edge-triggered SPI pending latching * preservation of software-pending state across line deassertion * SGI/PPI enable and priority filtering Correct the RSI plane-exit layout so the timer state starts at its ABI-defined 0x400 offset and assert the resulting structure offsets and sizes. Known limitations ----------------- This is an initial CCA IRQ implementation, not a complete GICv3 implementation. * PlaneExitReason::Irq currently recognizes only the architectural virtual timer. PMU, physical timer, and other local PPI sources are not identified or mapped. * SGI support is limited to the single-VP/self-target test path. Full ICC_SGI1R_EL1 affinity routing, target lists, broadcast behavior, and multi-VP delivery are not implemented or validated. * The SPI end-to-end test uses GICD_ISPENDR to create a software-pending SPI. It does not validate a real emulated device asserting and deasserting ControlGic::set_spi_irq through the complete device/VMM/ Realm path. * Level- and edge-triggered device SPI behavior is covered by GIC model unit tests, but still needs end-to-end device validation, including routing, VP wakeup, EOI/LR retirement, and repeated level delivery. * The TMK platform currently creates one VP and exposes only INTIDs 0-255. INTIDs 256-1019 are not implemented by this test platform. * Only the GIC register subset required by the current tests is implemented. Group 0, complete security-state behavior, ITS/MSI/LPI, and full architectural GICv3 semantics are not supported. * LR allocation is first-free. There is no LR eviction, maintenance interrupt handling, or complete priority-preemption model. * Private pending storage is bounded, and running-priority, binary-point, and nested-interrupt behavior are not fully modeled. * GIC EOI-maintenance events, cross-VTL interrupts, and the CCA untrusted-SynIC interrupt path remain unimplemented. * MMIO polling in the TMK tests is a workaround for current RMM/FVP notification behavior rather than the final asynchronous delivery mechanism. * Unsupported CCA IRQ sources are traced and ignored, while unsupported system-register traps terminate the VP. * The current CCA backend supports only a single auxiliary plane; multiple planes and switching between them are not yet supported. IRQ tests --------- Add TMK tests covering the initial CCA interrupt-delivery paths: * Virtual timer PPI: program CNTV_CVAL_EL0, wait for virtual timer PPI 20, verify delivery through the GIC, and disable the timer in the IRQ handler. * Self-targeted SGI: generate Group 1 SGI 5 through ICC_SGI1R_EL1 and verify that it is delivered to the current VP. * Software-pended SPI: set SPI 32 pending through GICD_ISPENDR and verify delivery through the distributor and GIC list-register path. Install the CCA emulation environment once with: cargo xflowey cca-tests --install-emu Build and run the CCA runtime test, including these TMK IRQ tests, with: cargo xflowey cca-tests To build the test artifacts without running the emulator, use: cargo xflowey cca-tests --build-only Note taht "Software-pended SPI” is intentionally precise: this test does not exercise a real emulated device asserting an SPI line. Test results ------------ INFO test: test passed, name: "aarch64::irq::virtual_timer_irq" INFO test: test passed, name: "aarch64::irq::spi_self_pending_irq" INFO test: test passed, name: "aarch64::irq::sgi_self_irq" Signed-off-by: Wei Ding <b-weiding@microsoft.com> Signed-off-by: Ben Aram <b-bearam@microsoft.com> Signed-off-by: Jiong Wang <b-jiongwang@microsoft.com>
1 parent a908f3f commit cd5805d

14 files changed

Lines changed: 1775 additions & 44 deletions

File tree

‎Cargo.lock‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8383,6 +8383,7 @@ dependencies = [
83838383
name = "tmk_vmm"
83848384
version = "0.0.0"
83858385
dependencies = [
8386+
"aarch64defs",
83868387
"anyhow",
83878388
"build_rs_guest_arch",
83888389
"clap",
@@ -8408,6 +8409,7 @@ dependencies = [
84088409
"virt_kvm",
84098410
"virt_mshv",
84108411
"virt_mshv_vtl",
8412+
"virt_support_gic",
84118413
"virt_whp",
84128414
"vm_loader",
84138415
"vm_topology",
@@ -9665,6 +9667,7 @@ dependencies = [
96659667
"virt",
96669668
"virt_support_aarch64emu",
96679669
"virt_support_apic",
9670+
"virt_support_gic",
96689671
"virt_support_x86emu",
96699672
"vm_topology",
96709673
"vmcore",

‎openhcl/virt_mshv_vtl/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ safe_intrinsics.workspace = true
5757
aarch64defs.workspace = true
5858
aarch64emu.workspace = true
5959
virt_support_aarch64emu.workspace = true
60+
virt_support_gic.workspace = true
6061

6162
[build-dependencies]
6263
build_rs_guest_arch.workspace = true

‎openhcl/virt_mshv_vtl/src/lib.rs‎

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ cfg_if::cfg_if!(
4242
use crate::processor::mshv::arm64::HypervisorBackedArm64Shared as HypervisorBackedShared;
4343
use processor::cca::CcaBackedShared;
4444
use safe_intrinsics::read_cntfrq_el0;
45+
use virt_support_gic::GicV3Model;
46+
use virt_support_gic::GicV3ModelError;
4547
}
4648
);
4749

@@ -154,6 +156,9 @@ pub enum Error {
154156
#[error("failed to create cpuid tables for cvm")]
155157
#[cfg(guest_arch = "x86_64")]
156158
CvmCpuid(#[source] cvm_cpuid::CpuidResultsError),
159+
#[error("failed to create GICv3 model")]
160+
#[cfg(guest_arch = "aarch64")]
161+
GicV3Model(#[source] GicV3ModelError),
157162
#[error("failed to update hypercall msr")]
158163
UpdateHypercallMsr,
159164
#[error("failed to update reference tsc msr")]
@@ -292,9 +297,10 @@ impl BackingShared {
292297
backing_shared_params,
293298
)?),
294299
#[cfg(guest_arch = "aarch64")]
295-
IsolationType::Cca => {
296-
BackingShared::Cca(Box::new(CcaBackedShared::new(backing_shared_params)?))
297-
}
300+
IsolationType::Cca => BackingShared::Cca(Box::new(CcaBackedShared::new(
301+
backing_shared_params,
302+
partition_params.topology.virt_timer_ppi(),
303+
)?)),
298304
_ => unreachable!(),
299305
})
300306
}
@@ -494,6 +500,9 @@ struct UhCvmPartitionState {
494500
#[cfg(guest_arch = "x86_64")]
495501
/// The emulated local APIC set.
496502
lapic: VtlArray<LocalApicSet, 2>,
503+
#[cfg(guest_arch = "aarch64")]
504+
#[inspect(skip)]
505+
gic: Arc<GicV3Model>,
497506
/// The emulated hypervisor state.
498507
hv: GlobalHv<2>,
499508
/// Guest VSM state.
@@ -651,6 +660,25 @@ impl GetReferenceTime for TscReferenceTimeSource {
651660

652661
impl virt::irqcon::ControlGic for UhPartitionInner {
653662
fn set_spi_irq(&self, irq_id: u32, high: bool) {
663+
#[cfg(guest_arch = "aarch64")]
664+
if self.isolation == IsolationType::Cca {
665+
let Some(cvm) = self.backing_shared.cvm_state() else {
666+
tracelimit::warn_ratelimited!(
667+
irq = irq_id,
668+
asserted = high,
669+
"failed to request CCA SPI without CVM state"
670+
);
671+
return;
672+
};
673+
674+
for vp_index in cvm.gic.set_spi_irq(irq_id, high) {
675+
if let Some(vp) = self.vp(vp_index) {
676+
vp.wake(GuestVtl::Vtl0, WakeReason::INTCON);
677+
}
678+
}
679+
return;
680+
}
681+
654682
if let Err(err) = self.hcl.request_interrupt(
655683
hvdef::HvInterruptControl::new()
656684
.with_arm64_asserted(high)
@@ -705,6 +733,15 @@ impl UhProcessorBox {
705733
.sidecar_base_cpu(self.vp_info.base.vp_index.index())
706734
}
707735

736+
/// Returns the partition-owned GICv3 model, when this processor belongs to a CCA partition.
737+
#[cfg(guest_arch = "aarch64")]
738+
pub fn gic_v3_model(&self) -> Option<Arc<GicV3Model>> {
739+
match &self.partition.backing_shared {
740+
BackingShared::Cca(shared) => Some(Arc::clone(&shared.cvm.gic)),
741+
_ => None,
742+
}
743+
}
744+
708745
/// Returns the processor object, bound to this thread.
709746
///
710747
/// If `control` is provided, then this must be called on the VP's
@@ -836,7 +873,6 @@ impl WakeReason {
836873
const MESSAGE_QUEUES: Self = Self::new().with_message_queues(true);
837874
#[cfg(guest_arch = "x86_64")]
838875
const HV_START_ENABLE_VP_VTL: Self = Self::new().with_hv_start_enable_vtl_vp(true); // StartVp/EnableVpVtl handling
839-
#[cfg(guest_arch = "x86_64")]
840876
const INTCON: Self = Self::new().with_intcon(true);
841877
#[cfg(guest_arch = "x86_64")]
842878
const UPDATE_PROXY_IRR_FILTER: Self = Self::new().with_update_proxy_irr_filter(true);
@@ -2355,6 +2391,9 @@ impl UhProtoPartition<'_> {
23552391
.build()
23562392
});
23572393

2394+
#[cfg(guest_arch = "aarch64")]
2395+
let gic = Arc::new(GicV3Model::new(params.topology).map_err(Error::GicV3Model)?);
2396+
23582397
let tsc_frequency = get_tsc_frequency(params.isolation)?;
23592398
let ref_time = ReferenceTimeSource::new(TscReferenceTimeSource::new(tsc_frequency));
23602399

@@ -2381,6 +2420,8 @@ impl UhProtoPartition<'_> {
23812420
isolated_memory_protector: late_params.isolated_memory_protector,
23822421
#[cfg(guest_arch = "x86_64")]
23832422
lapic,
2423+
#[cfg(guest_arch = "aarch64")]
2424+
gic,
23842425
hv,
23852426
guest_vsm: RwLock::new(GuestVsmState::from_availability(guest_vsm_available)),
23862427
access_vsm_privilege: guest_vsm_available,

0 commit comments

Comments
 (0)