riscvarchive / riscv-qemu

QEMU with RISC-V (RV64G, RV32G) Emulation Support
384 stars 154 forks source link

User mode can access address which has a page table entry with U=0. #146

Open LuChengTHU opened 6 years ago

LuChengTHU commented 6 years ago

I print the PTE and see U=0, V=R=W=X=1. My user mode program can access the address of kernel, but it cannot access CSR (so it is indeed in user mode). The spec says "U-mode software may only accessthe page when U=1". What is the meaning of "may"???

michaeljclark commented 6 years ago

Thanks for the bug report. Can you please provide a link to your test code.

michaeljclark commented 6 years ago

The following code in cpu_helper.c should do the following (if my reading is correct):

https://github.com/riscv/riscv-qemu/blob/63506ec079cd4eef319775fd48882900d41d439c/target/riscv/cpu_helper.c#L234-L241

The second clause should trigger for your test case (U=0 and U-mode). Perhaps we can try your test and instrument this code with some log messages to see what is going on with your test case.