[Bug] aarch64: a snapshot restore leaves every SGI enabled (GIC enable bits come back as current OR saved)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 55/100
Direzione di ricerca
Start with the restore path in src/vmm/src/arch/aarch64/gic/regs.rs and the distributor and redistributor register lists cited in the report. Check how the clear-register writes interact with the saved enable and active bits, then review the suggested complement-write approach and its linked unit tests in the fork. Done means restored GIC enable and active bits match the snapshot for distributor and per-vCPU state.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
On aarch64, restoring a snapshot does not restore the GIC's interrupt enable (and active)
bits to their saved values. It restores them to current OR saved, where "current" is what
KVM gives a newly created VM. KVM enables all 16 SGIs of a new vCPU, so in a restored microVM
every SGI of every vCPU is enabled, including the SGIs the guest had left disabled (7 to 15
on the Linux 6.1 guest below) and all SGIs of a CPU the guest has taken offline.
Why, in Firecracker (read at main, 2a8d0138cdf9; observed on v1.18.0):
- The save reads each register of the set/clear pairs:
GICR_ICENABLER0and
GICR_ISENABLER0,GICR_ICACTIVER0andGICR_ISACTIVER0
(src/vmm/src/arch/aarch64/gic/gicv3/regs/redist_regs.rs:39-49), andGICD_ICENABLER,
GICD_ISENABLER,GICD_ICACTIVER,GICD_ISACTIVER(gicv3/regs/dist_regs.rs:36-49). A
read of either register of a pair returns the bits that are set (Linux
vgic_mmio_read_enable,arch/arm64/kvm/vgic/vgic-mmio.c:96at v7.3.3), so the value saved
for a clear-register is the set of enabled (or active) interrupts. - The restore writes each register with the value saved for it (
set_reg_data,
src/vmm/src/arch/aarch64/gic/regs.rs:116-130), in the order of those lists: the
clear-register first, then the set-register.
What KVM does with those writes (Linux v7.3.3, arch/arm64/kvm/vgic/):
- A userspace write to
ICENABLERclears the enable of exactly the bits set in the value
(vgic_uaccess_write_cenable,vgic-mmio.c:208); the write toISENABLERthen sets
the bits set in its value (vgic_uaccess_write_senable,vgic-mmio.c:187). The same
forICACTIVERandISACTIVER(vgic_mmio_uaccess_write_cactiveand_sactive,
vgic-mmio.c:622and:659). - So writing the saved enabled bits to the clear-register clears precisely the bits the next
write sets again. A bit that is set in the new VM and clear in the snapshot is never
cleared: the result iscurrent | saved. - A new vCPU has every SGI enabled (
vgic_setup_private_irq,vgic-init.c:279-282:
irq->enabled = 1for SGIs). PPIs and SPIs start disabled, and nothing starts active, so
the only bits that come out wrong are SGI enables.
To Reproduce
- Start Firecracker on an aarch64 host with a 2-vCPU Linux guest (GICv3).
- In the guest, take CPU 1 offline:
echo 0 > /sys/devices/system/cpu/cpu1/online. (Without
this step the difference is still visible on the SGIs Linux leaves disabled.) - Pause the microVM (
PATCH /vm,Paused). On the host, as root, read KVM's view of the
source:/sys/kernel/debug/kvm/<tid>-<vm fd>/vgic-state. - Create a full snapshot (
PUT /snapshot/create). - Start a new Firecracker and load the snapshot (
PUT /snapshot/load). - Read
vgic-stateof the new process: every SGI of both vCPUs is enabled.
Observed, with the E flag of each SGI and PPI written out as GICR_ISENABLER0:
| case | vCPU | source, paused, before the snapshot | restored VM |
|---|---|---|---|
| control, both guest CPUs online | 0 | 0x0800007f |
0x0800ffff |
| 1 | 0x0800007f |
0x0800ffff |
|
| guest CPU 1 offlined | 0 | 0x0800007f |
0x0800ffff |
| 1 | 0x00000000 |
0x0000ffff |
PPI 27 (the timer), the enabled SPIs (32, 33, 35, 36 on both sides) and the active bits
(none) were restored as saved. The script that produced this and its unedited output are in
https://github.com/ejc3/fcvm/issues/2172#issuecomment-7175754486
Expected behaviour
The restored microVM has the enable and active bits the snapshot recorded, per vCPU and for
the distributor: an SGI the guest had disabled is disabled after the restore.
Environment
- Firecracker version: v1.18.0 (commit eaf83bb718a5), the
firecracker-v1.18.0-aarch64.tgz
release binary. The code cited above is unchanged on main at 2a8d0138cdf9. - Host and guest kernel versions: host Ubuntu
7.0.0-1018-awson m8g.metal-24xl; guest
vmlinux-6.1.155from the public CI bucket (firecracker-ci/v1.15/aarch64/) - Rootfs used:
ubuntu-24.04.squashfsfrom the same prefix, converted to ext4 as the
getting-started guide does;init=/bin/sh - Architecture: aarch64 (GICv3)
- Any other relevant software versions: 2 vCPUs, 512 MiB, File memory backend on load
Additional context
How it was found: by reading, while writing a formal model of the GIC and timer state a VMM
saves and restores on arm64 KVM, then confirmed with the run above. Cloud Hypervisor had the
same code and fixed it in its commit 1ede69b5b by writing the complement of the saved value
to the clear-registers.
Impact: low, as far as we can tell. No effect on a Linux guest is known: the restored guests
above kept working, with CPU 1 still offline in the second case. Linux sends nothing on the
SGIs it leaves disabled. A pending SGI cannot wake a CPU that the guest turned off through
PSCI, because KVM does not consider a stopped vCPU runnable (kvm_arch_vcpu_runnable,
arch/arm64/kvm/arm.c:849-859), and Linux sends IPIs only to online CPUs. A guest that
relies on an SGI being disabled would see it enabled after a restore.
Suggested fix: on restore, write the complement of the saved value to GICR_ICENABLER0,
GICR_ICACTIVER0, GICD_ICENABLER and GICD_ICACTIVER before their set-registers, so that
everything not in the snapshot is cleared. A patch in that shape, with a redistributor and a
distributor unit test, is on a v1.17.0-based branch of our fork
(https://github.com/ejc3/firecracker/commit/cf5d302d8782); I can open a pull request against
main if that is useful.
This report was written with Claude's assistance.
Checks
- Have you searched the Firecracker Issues database for similar problems?
- Have you read the existing relevant Firecracker documentation?
- Are you certain the bug being reported is a Firecracker issue?
- Lingua principale
- Rust
- Stelle
- 38.2k
- Fork
- 2.8k
- Merge medio
- 2g 12h
- PR unite (30g)
- 59
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di firecracker-microvm/firecracker
-
[Bug] jailer: misc device minors below 100 are never found in /proc/misc (/dev/nitro_enclaves, /dev/userfaultfd missing from the jail)Forse già presa @Gaspardcode l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
firecracker-microvm/firecracker#6490 ·
I maintainer di solito rispondono entro 1 giorno
-
chore(deps): update libseccomp to v2.6.2Forse già presa @pederbe l’ha presa 2 giorni fa. Apertadependencies
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
firecracker-microvm/firecracker#6460 ·
I maintainer di solito rispondono entro 1 giorno
-
[Feature Request] Restore a chain of Diff snapshots with the `File` memory backend, without mergingAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 28/100
firecracker-microvm/firecracker#6485 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug] vsock: a guest connection still handshaking when a snapshot is taken can hang forever after restoreForse già presa @not4s l’ha presa 2 giorni fa. ApertaStatus: Awaiting assignee
Difficoltà 4/5 3-5 giorni Idoneità per principianti 15/100
firecracker-microvm/firecracker#6464 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug] virtio: a driver features page written again is ORed into the acked features instead of replacing themForse già presa @zulinx86 l’ha presa 2 giorni fa. ApertaStatus: Awaiting assignee
Difficoltà 3/5 1-2 giorni Idoneità per principianti 52/100
firecracker-microvm/firecracker#6463 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di firecracker-microvm/firecracker
Issue simili
-
Find/Replace panel: "Previous/Next occurrence" labels overlap and overflow their buttons (French)Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 63/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
obi1kenobi/cargo-semver-checks#1839 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Bash init calls `cygpath` unconditionally on Windows, which breaks non-Cygwin shells like `brush`Forse già presa @iliqiliev l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
ajeetdsouza/zoxide#1381 ·
I maintainer di solito rispondono entro 5 giorni
-
triage
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
kornia/kornia-rs#1416 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni