[Bug] aarch64: a snapshot restore leaves every SGI enabled (GIC enable bits come back as current OR saved)

Aperta
#6,486 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

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
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
linux, rust
Ambito
backend

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_ICENABLER0 and
    GICR_ISENABLER0, GICR_ICACTIVER0 and GICR_ISACTIVER0
    (src/vmm/src/arch/aarch64/gic/gicv3/regs/redist_regs.rs:39-49), and GICD_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:96 at 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 ICENABLER clears the enable of exactly the bits set in the value
    (vgic_uaccess_write_cenable, vgic-mmio.c:208); the write to ISENABLER then sets
    the bits set in its value (vgic_uaccess_write_senable, vgic-mmio.c:187). The same
    for ICACTIVER and ISACTIVER (vgic_mmio_uaccess_write_cactive and _sactive,
    vgic-mmio.c:622 and :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 is current | saved.
  • A new vCPU has every SGI enabled (vgic_setup_private_irq, vgic-init.c:279-282:
    irq->enabled = 1 for SGIs). PPIs and SPIs start disabled, and nothing starts active, so
    the only bits that come out wrong are SGI enables.

To Reproduce

  1. Start Firecracker on an aarch64 host with a 2-vCPU Linux guest (GICv3).
  2. 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.)
  3. 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.
  4. Create a full snapshot (PUT /snapshot/create).
  5. Start a new Firecracker and load the snapshot (PUT /snapshot/load).
  6. Read vgic-state of 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-aws on m8g.metal-24xl; guest
    vmlinux-6.1.155 from the public CI bucket (firecracker-ci/v1.15/aarch64/)
  • Rootfs used: ubuntu-24.04.squashfs from 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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di firecracker-microvm/firecracker

Tutte le issue di firecracker-microvm/firecracker

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.