fix(page_cache): 修复pagecache无法直接mmap然后读写文件的bug (#1158)

* fix(page_cache): 修复pagecache无法直接mmap然后读写文件的bug

经过此commit,用户程序可以直接mmap文件然后读写(无需通过read/write去读取)

Signed-off-by: longjin <longjin@DragonOS.org>

* fix(page_cache): 修复pagecache 文件映射的bug

- 修复对同一文件mmap两次时,第二次map之后写入文件,内核panic的问题
- 修复address space已经drop之后,页面回写时的panic的问题
- 为PageCache和InnerPageCache添加唯一ID支持
- 优化页面错误处理函数,添加inline(never)属性
- 修复页面映射范围计算错误
- 改进页面回收器的地址空间处理逻辑

Signed-off-by: longjin <longjin@DragonOS.org>

---------

Signed-off-by: longjin <longjin@DragonOS.org>
This commit is contained in:
LoGin
2025-05-10 12:12:03 +08:00
committed by GitHub
parent 7486ad438c
commit d3ae9c7c4a
10 changed files with 124 additions and 99 deletions

View File

@ -171,6 +171,7 @@ impl dyn Driver {
/// ## 注意
///
/// 这里的默认实现很低效,请为特定的驱动自行实现高效的查询
#[inline(never)]
pub fn find_device_by_name(&self, name: &str) -> Option<Arc<dyn Device>> {
if let Some(r) = self.__find_device_by_name_fast(name) {
return Some(r);

View File

@ -72,7 +72,7 @@ pub fn virtio_console(
log::debug!(
"virtio_console: dev_id: {:?}, parent: {:?}",
dev_id,
dev_parent
dev_parent.as_ref().map(|x| x.name())
);
let device = VirtIOConsoleDevice::new(transport, dev_id.clone());
if device.is_none() {
@ -576,9 +576,7 @@ impl Driver for VirtIOConsoleDriver {
virtio_con_dev.dev_id(),
);
}
log::debug!("virtio console: add_device: to lock inner");
let mut inner = self.inner();
log::debug!("virtio console: add_device: inner.locked");
let dev_name = inner.alloc_id();
if dev_name.is_none() {
panic!("Failed to allocate ID for VirtIO console device: '{:?}', virtio console device limit exceeded.", virtio_con_dev.dev_id())

View File

@ -1063,7 +1063,12 @@ pub fn pci_init() {
let common_header = box_pci_device.common_header();
match box_pci_device.header_type() {
HeaderType::Standard if common_header.status & 0x10 != 0 => {
info!("Found pci standard device with class code ={} subclass={} status={:#x} cap_pointer={:#x} vendor={:#x}, device id={:#x},bdf={}", common_header.class_code, common_header.subclass, common_header.status, box_pci_device.as_standard_device().unwrap().capabilities_pointer,common_header.vendor_id, common_header.device_id,common_header.bus_device_function);
info!(
"Found pci standard device with class code ={} subclass={}, bdf={}",
common_header.class_code,
common_header.subclass,
common_header.bus_device_function
);
}
HeaderType::Standard => {
info!(

View File

@ -99,6 +99,7 @@ impl TtyLdiscManager {
/// ### 参数
/// - tty需要设置的tty
/// - o_tty: other tty 用于pty pair
#[inline(never)]
pub fn ldisc_setup(tty: Arc<TtyCore>, o_tty: Option<Arc<TtyCore>>) -> Result<(), SystemError> {
let ld = tty.ldisc();

View File

@ -196,7 +196,7 @@ impl VirtIODeviceManager {
dev.set_virtio_device_index(virtio_index);
dev.set_device_name(format!("virtio{}", virtio_index.data()));
log::debug!("virtio_device_add: dev: {:?}", dev);
log::debug!("virtio_device_add: dev: {:?}", dev.name());
// 添加设备到设备管理器
device_manager().add_device(dev.clone() as Arc<dyn Device>)?;
let r = device_manager()