Skip to content

openvmm: a secondary PIC poll leaves a stale cascade request and the next INTA can panic #1139

Closed

Description

@tangruize

A guest polling the secondary 8259 PIC can leave the primary's cascade request asserted after the secondary interrupt has been acknowledged. The next interrupt acknowledgement can panic the VM worker with pic1 ready was set.

In vm/devices/chipset/src/pic/mod.rs, DualPic::io_read calls the state-changing read_command but returns without synchronizing outputs:

        data[0] = match io_port {
            PRIMARY_PIC_COMMAND_PORT => self.pics[0].read_command(&mut self.stats),
            PRIMARY_PIC_DATA_PORT => self.pics[0].read_data(),
            SECONDARY_PIC_COMMAND_PORT => self.pics[1].read_command(&mut self.stats),
            SECONDARY_PIC_DATA_PORT => self.pics[1].read_data(),
            PRIMARY_PIC_ELCR_PORT => self.pics[0].elcr,
            SECONDARY_PIC_ELCR_PORT => self.pics[1].elcr,
            _ => return IoResult::Err(IoError::InvalidRegister),
        };
        IoResult::Ok

In poll mode, read_command acknowledges the polled controller's interrupt. Its request falls, but the primary IRQ2 cascade input and CPU-ready output retain their previous values. DualPic::acknowledge_interrupt consequently acknowledges the primary cascade and reaches the secondary with nothing pending.

Reproduction

Initialize the dual PIC, unmask IRQ8 and the primary cascade, and enable ExtINT delivery. Assert IRQ8, write poll OCW3 0x0c to secondary command port 0xa0, then read one byte from 0xa0. The read returns 0x80, acknowledging secondary IRQ0.

The ready output remains asserted. Taking the subsequent interrupt acknowledgement reaches the secondary's no-pending-interrupt assertion instead of returning no interrupt.

Fix

fix.patch calls sync_outputs after either command-port read, matching the existing write behavior. Poll acknowledgements immediately update the cascade and ready lines; ordinary command reads are unchanged, and data/ELCR reads do not require synchronization.

Activity

  1. tangruize commented on Nov 1, 2026

    @tangruize
    ContributorAuthor

    Proposed patch

    Patch against OpenVMM 998b9f2402050cd16d1faa897bc831ef1434be48. Save the contents below as fix.patch and run git apply fix.patch.

    fix.patch
    diff --git a/vm/devices/chipset/src/pic/mod.rs b/vm/devices/chipset/src/pic/mod.rs
    index 1babcc9ce..06350f7b3 100644
    --- a/vm/devices/chipset/src/pic/mod.rs
    +++ b/vm/devices/chipset/src/pic/mod.rs
    @@ -176,6 +176,14 @@ fn io_read(&mut self, io_port: u16, data: &mut [u8]) -> IoResult {
                 SECONDARY_PIC_ELCR_PORT => self.pics[1].elcr,
                 _ => return IoResult::Err(IoError::InvalidRegister),
             };
    +        // A command-port read in poll mode acknowledges an interrupt: resync the
    +        // outputs, as after every write.
    +        if matches!(
    +            io_port,
    +            PRIMARY_PIC_COMMAND_PORT | SECONDARY_PIC_COMMAND_PORT
    +        ) {
    +            self.sync_outputs();
    +        }
             IoResult::Ok
         }
     
    @@ -963,4 +971,22 @@ fn test_non_specific_eois() {
     
             assert_eq!(pic.pics[0].isr, 0b101000);
         }
    +
    +    /// Regression test of BUG-04 (finding PIC-2): a poll-mode read of the secondary's
    +    /// command port acknowledges its interrupt; the outputs are then resynced, so the
    +    /// cascade line falls, the `ready` line falls, and a CPU acknowledgement finds nothing
    +    /// pending instead of panicking ("pic1 ready was set").
    +    #[test]
    +    fn secondary_poll_then_acknowledge_does_not_panic() {
    +        let (ready, mut pic) = create_pic();
    +        pic.set_irq(8, true);
    +        assert!(ready());
    +        pic.io_write(SECONDARY_PIC_COMMAND_PORT, &[0x0c]).unwrap();
    +        let mut data = [0];
    +        pic.io_read(SECONDARY_PIC_COMMAND_PORT, &mut data).unwrap();
    +        assert_eq!(data[0], 0x80);
    +        assert!(!ready());
    +        assert_eq!(pic.pics[0].lines & (1 << PIC_CHAIN_COMMUNICATION_IRQ), 0);
    +        assert_eq!(pic.acknowledge_interrupt(), None);
    +    }
     }
  2. ppenna commented on Nov 11, 2026

    @ppenna
    Contributor

    Closing: this is an OpenVMM bug outside NVX, the one that #1062 also reports, and upstream fixed it in microsoft/openvmm#4838, chipset: synchronize PIC outputs after poll reads, merged on 2026-11-01. NVX's OpenVMM pin, 58d3c3b1d, includes it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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