Avoid potential deadlock in iommu remapping

This commit is contained in:
Shaowei Song 2024-10-16 14:33:32 +00:00 committed by Tate, Hongliang Tian
parent 601040f2fa
commit da5e7a21cb
2 changed files with 10 additions and 4 deletions

View File

@ -11,7 +11,7 @@ use crate::{
bus::pci::PciDeviceLocation,
mm::{Daddr, PageTable},
prelude::Paddr,
sync::SpinLock,
sync::{LocalIrqDisabled, SpinLock},
};
mod context_table;
@ -74,4 +74,7 @@ pub fn init() {
info!("[IOMMU] DMA remapping enabled");
}
static PAGE_TABLE: Once<SpinLock<RootTable>> = Once::new();
// TODO: Currently `map()` or `unmap()` could be called in both task and interrupt
// contexts (e.g., within the virtio-blk module), potentially leading to deadlocks.
// Once this issue is resolved, `LocalIrqDisabled` is no longer needed.
static PAGE_TABLE: Once<SpinLock<RootTable, LocalIrqDisabled>> = Once::new();

View File

@ -26,7 +26,7 @@ use crate::{
x86::kernel::acpi::dmar::{Dmar, Remapping},
},
mm::paddr_to_vaddr,
sync::SpinLock,
sync::{LocalIrqDisabled, SpinLock},
};
#[derive(Debug, Clone, Copy)]
@ -91,7 +91,10 @@ impl IommuRegisters {
}
/// Enable DMA remapping with static RootTable
pub(super) fn enable_dma_remapping(&mut self, root_table: &'static SpinLock<RootTable>) {
pub(super) fn enable_dma_remapping(
&mut self,
root_table: &'static SpinLock<RootTable, LocalIrqDisabled>,
) {
// Set root table address
self.root_table_address
.write(root_table.lock().root_paddr() as u64);