Skip to content

Commit 0c062d5

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: 守情 <liheng.xlh@alibaba-inc.com>
1 parent 95e652e commit 0c062d5

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
@@ -11,6 +11,9 @@ use super::*;
1111
use kvm_bindings::{KVM_IRQCHIP_IOAPIC, KVM_IRQCHIP_PIC_MASTER, KVM_IRQCHIP_PIC_SLAVE};
1212
use std::sync::atomic::{AtomicUsize, Ordering};
1313

14+
/// Maximum number of legacy interrupts supported.
15+
pub const MAX_LEGACY_IRQS: u32 = 24;
16+
1417
pub(super) struct LegacyIrq {
1518
base: u32,
1619
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,
@@ -77,7 +85,7 @@ impl LegacyIrq {
7785
}
7886

7987
// Build routings for the first IOAPIC
80-
for i in 0..24 {
88+
for i in 0..MAX_LEGACY_IRQS {
8189
if i == 0 {
8290
Self::add_legacy_entry(i, KVM_IRQCHIP_IOAPIC, 2, routes)?;
8391
} else if i != 2 {

0 commit comments

Comments
 (0)