Skip to content

Conversation

JensenWei007
Copy link
Contributor

  • 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]>
@fslongjin
Copy link
Member

bugbot run

Copy link

@cursor cursor bot left a 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

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

Fix in Cursor Fix in Web


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);
Copy link

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.

Fix in Cursor Fix in Web

assert!(buf.len() == BLOCK_SIZE);

#[allow(mutable_transmutes)]
let buf = unsafe { core::mem::transmute(buf) };
Copy link

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.

Fix in Cursor Fix in Web

impl BUFADDRU {
pub fn offset() -> usize {
0xA0
}
Copy link

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.

Fix in Cursor Fix in Web

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) }
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: FIFO Reset Error

In reset_fifo, the control register value is written to the FIFO data offset (0x600) instead of the correct control register offset (0x00). This prevents the FIFO from resetting and may corrupt other hardware registers.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants