Skip to content

Commit 17dc558

Browse files
authored
修复vma映射标志错误 (#801)
1 parent 7db6e06 commit 17dc558

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

kernel/src/mm/fault.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ impl PageFaultMessage {
7575
}
7676
}
7777

78+
impl Clone for PageFaultMessage {
79+
fn clone(&self) -> Self {
80+
Self {
81+
vma: self.vma.clone(),
82+
address: self.address,
83+
flags: self.flags,
84+
}
85+
}
86+
}
87+
7888
/// 缺页中断处理结构体
7989
pub struct PageFaultHandler;
8090

@@ -167,27 +177,30 @@ impl PageFaultHandler {
167177
let address = pfm.address_aligned_down();
168178
let flags = pfm.flags;
169179
let vma = pfm.vma.clone();
180+
let mut ret = VmFaultReason::VM_FAULT_COMPLETED;
170181
if let Some(mut entry) = mapper.get_entry(address, 0) {
171182
if !entry.present() {
172-
return Self::do_swap_page(pfm, mapper);
183+
ret = Self::do_swap_page(pfm.clone(), mapper);
173184
}
174185
if entry.protnone() && vma.is_accessible() {
175-
return Self::do_numa_page(pfm, mapper);
186+
ret = Self::do_numa_page(pfm.clone(), mapper);
176187
}
177188
if flags.intersects(FaultFlags::FAULT_FLAG_WRITE | FaultFlags::FAULT_FLAG_UNSHARE) {
178189
if !entry.write() {
179-
return Self::do_wp_page(pfm, mapper);
190+
ret = Self::do_wp_page(pfm.clone(), mapper);
180191
} else {
181192
entry.set_flags(PageFlags::from_data(MMArch::ENTRY_FLAG_DIRTY));
182193
}
183194
}
184195
} else if vma.is_anonymous() {
185-
return Self::do_anonymous_page(pfm, mapper);
196+
ret = Self::do_anonymous_page(pfm.clone(), mapper);
186197
} else {
187-
return Self::do_fault(pfm, mapper);
198+
ret = Self::do_fault(pfm.clone(), mapper);
188199
}
189200

190-
VmFaultReason::VM_FAULT_COMPLETED
201+
vma.lock().set_mapped(true);
202+
203+
return ret;
191204
}
192205

193206
/// 处理匿名映射页缺页异常

kernel/src/mm/ucontext.rs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -299,18 +299,12 @@ impl InnerAddressSpace {
299299
prot_flags,
300300
map_flags,
301301
move |page, count, flags, _mapper, _flusher| {
302-
Ok(LockedVMA::new(VMA {
303-
region: VirtRegion::new(
304-
page.virt_address(),
305-
count.data() * MMArch::PAGE_SIZE,
306-
),
302+
Ok(LockedVMA::new(VMA::new(
303+
VirtRegion::new(page.virt_address(), count.data() * MMArch::PAGE_SIZE),
307304
vm_flags,
308305
flags,
309-
mapped: true,
310-
user_address_space: None,
311-
self_ref: Weak::default(),
312-
provider: Provider::Allocated,
313-
}))
306+
false,
307+
)))
314308
},
315309
)?
316310
};
@@ -1033,7 +1027,6 @@ impl LockedVMA {
10331027
mut flusher: impl Flusher<MMArch>,
10341028
) -> Result<(), SystemError> {
10351029
let mut guard = self.lock();
1036-
assert!(guard.mapped);
10371030
for page in guard.region.pages() {
10381031
// 暂时要求所有的页帧都已经映射到页表
10391032
// TODO: 引入Lazy Mapping, 通过缺页中断来映射页帧,这里就不必要求所有的页帧都已经映射到页表了
@@ -1052,7 +1045,6 @@ impl LockedVMA {
10521045
// todo: 如果当前vma与文件相关,完善文件相关的逻辑
10531046

10541047
let mut guard = self.lock();
1055-
assert!(guard.mapped);
10561048

10571049
// 获取物理页的anon_vma的守卫
10581050
let mut page_manager_guard: SpinLockGuard<'_, crate::mm::page::PageManager> =
@@ -1347,7 +1339,6 @@ impl VMA {
13471339
mapper: &mut PageMapper,
13481340
mut flusher: impl Flusher<MMArch>,
13491341
) -> Result<(), SystemError> {
1350-
assert!(self.mapped);
13511342
for page in self.region.pages() {
13521343
// kdebug!("remap page {:?}", page.virt_address());
13531344
if mapper.translate(page.virt_address()).is_some() {
@@ -1477,18 +1468,15 @@ impl VMA {
14771468
flusher.consume(r);
14781469
cur_dest = cur_dest.next();
14791470
}
1480-
let r = LockedVMA::new(VMA {
1481-
region: VirtRegion::new(
1471+
let r = LockedVMA::new(VMA::new(
1472+
VirtRegion::new(
14821473
destination.virt_address(),
14831474
page_count.data() * MMArch::PAGE_SIZE,
14841475
),
14851476
vm_flags,
14861477
flags,
1487-
mapped: true,
1488-
user_address_space: None,
1489-
self_ref: Weak::default(),
1490-
provider: Provider::Allocated,
1491-
});
1478+
true,
1479+
));
14921480
drop(flusher);
14931481
// kdebug!("VMA::zeroed: flusher dropped");
14941482

0 commit comments

Comments
 (0)