Skip to content

openvmm: KVM snapshots drop the interrupt-shadow kind (STI vs MOV SS) #1369

Closed

Description

@tangruize

On KVM on an Intel (VMX) host, a VP that is stopped in an STI interrupt shadow is restored in a MOV SS shadow. The save keeps only a boolean, Activity::interrupt_shadow, and the restore writes it back as 1, which is KVM_X86_SHADOW_INT_MOV_SS; KVM reports an STI shadow as KVM_X86_SHADOW_INT_STI (2). A MOV SS shadow survives the round trip. The kinds differ at the next instruction boundary, where a MOV SS shadow also blocks certain debug exceptions and an STI shadow does not, so the restored guest can differ from the saved one only there. AMD hosts are not affected: SVM has one shadow kind, which KVM reports with both bits. Any guest can be stopped in such a shadow; no crafted input is needed. No panic results.

Reproduction

Not reproduced. On an Intel host, stop a vCPU right after an sti executed with IF clear, so that KVM_GET_VCPU_EVENTS reports interrupt.shadow = 2 (KVM_X86_SHADOW_INT_STI). Save and restore its activity. Expected: 2. Actual, from OpenVMM's and KVM's code: set_activity writes 1, and KVM_GET_VCPU_EVENTS then reports 1 (KVM_X86_SHADOW_INT_MOV_SS). A vCPU stopped right after mov ss reports 1 before and after, so it does not show the bug.

Cause

KvmVpStateAccess::activity and set_activity (vmm_core/virt_kvm/src/arch/x86_64/vp_state.rs) turn the shadow into a boolean and back, because vp::Activity (vmm_core/virt/src/x86/vp.rs) has no field for the kind:

// vmm_core/virt_kvm/src/arch/x86_64/vp_state.rs
Ok(vp::Activity {
    // ...
    interrupt_shadow: events.interrupt.shadow != 0,
// ...
let mut events = kvm::kvm_vcpu_events {
    // ...
    interrupt: kvm::kvm_vcpu_events__bindgen_ty_2 {
        // ...
        shadow: interrupt_shadow.into(),

Fix

No patch is attached. Preserving the kind adds a saved-state field, so a format decision is needed:

  • Add an optional interrupt_shadow_kind (MOV SS, STI) to Activity. KVM fills it and restores it exactly. Other backends, and older snapshots, fall back to the boolean.
  • Keep the boolean, and document that the restore promises a shadow, not its kind.

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions