Skip to content

Commit 01cc5fa

Browse files
juliusxlhjiangliu
authored andcommitted
Limit number of legacy irqs
With some kvm version, setting irq_routing for non-existing legaccy IRQs may cause system crash. So limit the number to available legacy interrupts. Signed-off-by: 守情 <[email protected]>
1 parent 709581c commit 01cc5fa

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/interrupt/kvm/legacy_irq.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ use kvm_bindings::{
1212
KVM_IRQCHIP_IOAPIC, KVM_IRQCHIP_PIC_MASTER, KVM_IRQCHIP_PIC_SLAVE, KVM_IRQ_ROUTING_IRQCHIP,
1313
};
1414

15+
/// Maximum number of legacy interrupts supported.
16+
pub const MAX_LEGACY_IRQS: u32 = 24;
17+
1518
pub(super) struct LegacyIrq {
1619
base: u32,
1720
vmfd: Arc<VmFd>,
@@ -29,6 +32,11 @@ impl LegacyIrq {
2932
if count != 1 {
3033
return Err(std::io::Error::from_raw_os_error(libc::EINVAL));
3134
}
35+
36+
if base >= MAX_LEGACY_IRQS {
37+
return Err(std::io::Error::from_raw_os_error(libc::EINVAL));
38+
}
39+
3240
Ok(LegacyIrq {
3341
base,
3442
vmfd,
@@ -74,7 +82,7 @@ impl LegacyIrq {
7482
}
7583

7684
// Build routings for the first IOAPIC
77-
for i in 0..24 {
85+
for i in 0..MAX_LEGACY_IRQS {
7886
if i == 0 {
7987
Self::add_legacy_entry(i, KVM_IRQCHIP_IOAPIC, 2, routes)?;
8088
} else if i != 2 {

0 commit comments

Comments
 (0)