-
-
Notifications
You must be signed in to change notification settings - Fork 162
feat(riscv platform vf2): vf2 platform adapted to riscv architecture #1285
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?
Conversation
JensenWei007
commented
Sep 16, 2025
- Add necessary platform driver support
- Modify some startup processes and assert
- Fixed some issues
- Add necessary platform driver support - Modify some startup processes and assert - Fixed some issues Signed-off-by: JensenWei007 <[email protected]>
bugbot run |
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.
This PR is being reviewed by Cursor Bugbot
Details
You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
Bug: Kernel Stack Initialization Mismatch
The init_idle
function assumes processor 0 is the Boot Strap Processor (BSP) for kernel stack initialization. This conflicts with the removed assertion and the TODO
comment noting that the boot hart might not be 0 on platforms like riscv-vf2. This mismatch can lead to incorrect kernel stack setup for the actual BSP and processor 0, potentially causing system instability.
kernel/src/process/idle.rs#L38-L46
DragonOS/kernel/src/process/idle.rs
Lines 38 to 46 in c1aa3d9
for i in 0..PerCpu::MAX_CPU_NUM { | |
let kstack = if unlikely(i == 0) { | |
let stack_ptr = | |
VirtAddr::new(Self::stack_ptr().data() & (!(KernelStack::ALIGN - 1))); | |
// 初始化bsp的idle进程 | |
let mut ks = unsafe { KernelStack::from_existed(stack_ptr) } | |
.expect("Failed to create kernel stack struct for BSP."); | |
unsafe { ks.clear_pcb(true) }; | |
ks |
if cmd.data_expected() { | ||
let buffer = // TODO: dirty | ||
buffer.unwrap_or(unsafe { core::slice::from_raw_parts_mut(core::ptr::NonNull::dangling().as_ptr(), 64) }); | ||
assert!(buffer_offset == 0); |
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.
Bug: Invalid Memory Access in send_cmd
Function
The send_cmd
function creates a mutable slice from a dangling pointer when the buffer
argument is None
. This results in a 64-element slice pointing to invalid memory, which is then accessed during data transfers. This leads to undefined behavior, potential memory corruption, and system instability. This also bypasses the debug_assert
on line 404 when data is expected.
assert!(buf.len() == BLOCK_SIZE); | ||
|
||
#[allow(mutable_transmutes)] | ||
let buf = unsafe { core::mem::transmute(buf) }; |
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.
Bug: Unsafe Transmute Violates Rust Memory Safety
The write_block
function uses mem::transmute
to convert an immutable &[u8]
slice into a mutable &mut [usize]
slice. This violates Rust's aliasing rules and memory safety, leading to undefined behavior. The transmute also changes the element type, which can cause issues with data interpretation and alignment.
impl BUFADDRU { | ||
pub fn offset() -> usize { | ||
0xA0 | ||
} |
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.
Bug: Incorrect Offset for 64-bit Buffer Address Upper Part
The BUFADDRL
and BUFADDRU
structs incorrectly share the same offset (0xA0
). As these represent the lower and upper 32-bit parts of a 64-bit buffer address, BUFADDRU
needs a distinct offset, likely 0xA4
, consistent with other 64-bit address register pairs.
let base = self.virt_base_address() as *mut CTRL; | ||
let ctrl = self.control_reg().with_fifo_reset(true); | ||
unsafe { base.byte_add(*self.fifo_offset.get()).write_volatile(ctrl) } | ||
} |
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.