feat(tty): 为TTY设备添加page_cache方法并处理无页面缓存的情况 (#1428)

- 在TTY设备中实现page_cache方法,返回None以表明字符设备不需要页面缓存
- 在页面错误处理中增加对无页面缓存情况的处理,避免panic并返回VM_FAULT_SIGBUS

Signed-off-by: longjin <longjin@DragonOS.org>
This commit is contained in:
LoGin 2025-12-03 01:01:57 +08:00 committed by GitHub
parent 963ccded97
commit b466adff52
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 2 deletions

View File

@ -408,6 +408,11 @@ impl IndexNode for TtyDevice {
Ok(())
}
fn page_cache(&self) -> Option<Arc<crate::filesystem::page_cache::PageCache>> {
// TTY设备是字符设备不需要页面缓存
None
}
fn close(&self, data: SpinLockGuard<FilePrivateData>) -> Result<(), SystemError> {
let (tty, _flags) = if let FilePrivateData::Tty(tty_priv) = &*data {
(tty_priv.tty(), tty_priv.flags)

View File

@ -609,7 +609,17 @@ impl PageFaultHandler {
let vma = pfm.vma();
let vma_guard = vma.lock_irqsave();
let file = vma_guard.vm_file().expect("no vm_file in vma");
let page_cache = file.inode().page_cache().unwrap();
let page_cache = match file.inode().page_cache() {
Some(cache) => cache,
None => {
// 文件没有页面缓存,可能是不支持内存映射的设备文件
log::warn!(
"filemap_map_pages: file has no page cache, inode type: {}",
crate::libs::name::get_type_name(&file.inode())
);
return VmFaultReason::VM_FAULT_SIGBUS;
}
};
let mapper = &mut pfm.mapper;
// 起始页地址
@ -650,7 +660,17 @@ impl PageFaultHandler {
let vma = pfm.vma();
let vma_guard = vma.lock_irqsave();
let file = vma_guard.vm_file().expect("no vm_file in vma");
let page_cache = file.inode().page_cache().unwrap();
let page_cache = match file.inode().page_cache() {
Some(cache) => cache,
None => {
// 文件没有页面缓存,可能是不支持内存映射的设备文件
log::warn!(
"filemap_fault: file has no page cache, inode type: {}",
crate::libs::name::get_type_name(&file.inode())
);
return VmFaultReason::VM_FAULT_SIGBUS;
}
};
let file_pgoff = pfm.file_pgoff.expect("no file_pgoff");
let mut ret = VmFaultReason::empty();