-
-
Notifications
You must be signed in to change notification settings - Fork 169
feat(mm):添加mlock系列的系统调用 #1619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat(mm):添加mlock系列的系统调用 #1619
Conversation
- 对已设置 VM_LOCKED 标志的 VMA 调用 MADV_DONTNEED 时返回 EINVAL - 符合 Linux 语义:已锁定内存不能通过 madvise 释放 2. sys_mlock.rs - RLIMIT_MEMLOCK 资源限制检查 - 添加 RLIMIT_MEMLOCK 限制检查 - 计算当前已锁定页面数和请求数 - 超过限制时返回 ENOMEM 3. sys_mmap.rs - MAP_LOCKED 标志的资源限制 - MAP_LOCKED 映射时进行 RLIMIT_MEMLOCK 检查 - 检查 can_do_mlock() 权限 - 超过限制时返回 EAGAIN 4. sys_mremap.rs - 扩展锁定 VMA 时的资源检查 - 扩展已锁定的 VMA 时检查额外需要的页面数 - 进行 RLIMIT_MEMLOCK 限制验证 5. ucontext.rs - Fork 语义和辅助函数 - 修正 fork 语义:子进程不应继承 locked_vm 计数(从 0 开始) - 修正 fork 语义:子进程不应继承 def_flags(mlockall 设置的默认标志) - 修正 fork 语义:子进程不应继承 VM_LOCKED 和 VM_LOCKONFAULT 标志 - 添加 vma_is_accessible() 辅助函数 - mlock 前检查 VMA 可访问性(PROT_NONE 应返回 ENOMEM) - 添加 locked_vm() getter 方法 - mmap 时应用 def_flags(支持 mlockall MCL_FUTURE)
|
bugbot run |
kernel/src/mm/ucontext.rs
Outdated
| use ida::IdAllocator; | ||
| use log::warn; | ||
| use system_error::SystemError; | ||
| use x86::current; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import x86::current accidentally added
Low Severity
The import use x86::current; is added but never used anywhere in the file. The current() calls in this file refer to AddressSpace::current() and self.is_current() methods, not the x86 crate's current module. This appears to be accidentally committed code.
|
bugbot run |
|
Skipping Bugbot: Unable to authenticate your request. Please make sure Bugbot is properly installed and configured for this repository. |
|
bugbot run |
082f756 to
a9152ac
Compare
a9152ac to
447fbf9
Compare
|
bugbot run |
|
Skipping Bugbot: Unable to authenticate your request. Please make sure Bugbot is properly installed and configured for this repository. |
|
https://github.com/codex review |
|
@codex review |
|
To use Codex here, create a Codex account and connect to github. |
|
@codex review |
|
To use Codex here, create a Codex account and connect to github. |
|
@claude review |
|
Claude finished @fslongjin's task in 8m 46s —— View job Code Review for PR #1619: feat(mm): 添加mlock系列的系统调用I'm reviewing the mlock system call implementation. Let me examine the changes and provide feedback. Todo List:
SummaryThis PR implements Linux-compatible Bug Fix StatusI've examined the 15 issues identified by Cursor Bugbot. Most have been addressed in the current code: ✅ Fixed issues:
Code QualityThe implementation is well-documented with Linux references, follows Rust safety patterns, and includes comprehensive error handling. The use of atomic counters, proper locking, and page table walking is correct. Suggestions
OverallThis is a high-quality implementation of a critical OS feature. The code addresses the previously identified security and correctness issues. The PR is ready for merge pending successful CI tests. Recommended action: Approve after CI passes. CI Status: All checks passed ✅ (branch: Review performed by Claude via Claude Code |
|
这个pr有太多代码冗余了,并且封装程度也不够。 |
概述
本 PR 实现了 Linux 兼容的 mlock/munlock/mlockall/munlockall 系列系统调用,用于防止关键内存页面被换出到交换空间。这是数据库、加密应用等需要保证内存持久性的场景的重要功能。
相关 Commits (按时间顺序):
主要功能
Note
Introduces Linux-compatible memory locking with proper accounting and limits.
kernel/src/mm/mlock.rswithmlock_page/munlock_page, page-table walking (incl. huge-page subpages), andcan_do_mlockmlock,mlock2(MLOCK_ONFAULT),mlockall(MCL_CURRENT|MCL_FUTURE|MCL_ONFAULT),munlock,munlockall; validate ranges, align, CAP/RLIMIT checkslocked_vmanddef_flags; implementmlock/munlock/mlockall/munlockall; applyVM_LOCKED/VM_LOCKONFAULT; do not inherit locks on forkPG_MLOCKED, usePG_UNEVICTABLE, and per-pagemlock_countVM_LOCKONFAULTset, lock anon pages on demand indo_anonymous_pagemadvise: returnEINVALforMADV_DONTNEEDonVM_LOCKEDVMAsmmap/mremap: enforceRLIMIT_MEMLOCKforMAP_LOCKEDand locked VMA expansion, returningEPERM/EAGAIN/ENOMEMas appropriateRLIMIT_MEMLOCKto 64KBuser/apps/c_unitest/test_mlock.c; whitelistmlock_testWritten by Cursor Bugbot for commit a4aa5ad. This will update automatically on new commits. Configure here.