Skip to content

target/riscv: fix address translation in hypervisor mode #1258

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

Open
wants to merge 3 commits into
base: riscv
Choose a base branch
from

Conversation

zqb-all
Copy link
Contributor

@zqb-all zqb-all commented May 15, 2025

address translation don't need to care hstatus.HU

@zqb-all zqb-all force-pushed the addr-translate-h-mode branch from 66379a0 to a1ce63a Compare May 15, 2025 08:42
Ubuntu 20.04 is no longer available.
See actions/runner-images#11101

Checkpatch-ignore: BAD_SIGN_OFF
Change-Id: I0ec3e3342f9212a2a79d8dca6274e7db62ecedab
Signed-off-by: Evgeniy Naydanov <[email protected]>
@en-sc
Copy link
Collaborator

en-sc commented May 15, 2025

@zqb-all, can you please expand on the motivation for the patch?

I don't know much about virtualization, but AFAIU from [21.2.10. Hypervisor Guest Address Translation and Protection (hgatp) Register] of The RISC-V Instruction Set Manual: Volume II: Privileged Architecture version 20250508

The hgatp register is considered active for the purposes of the address-translation algorithm unless the effective privilege mode is U and hstatus.HU=0.

The code you are deleting is correct.

What am I missing?

@zqb-all
Copy link
Contributor Author

zqb-all commented May 16, 2025

Field HU (Hypervisor in U-mode) controls whether the virtual-machine
load/store instructions, HLV, HLVX, and HSV, can be used also in U-mode.
When HU=1, these instructions can be executed in U-mode the same as in
HS-mode. When HU=0, all hypervisor instructions cause an
illegal-instruction exception in U-mode.

hstatus.HU only affects the behavior of the cpu when executing the virtual-machine load/store instructions HLV, HLVX, and HSV. When we do address translation in openocd, we should behave like a cpu doing normal load/store instructions

The hgatp register is considered active for the purposes of the
address-translation algorithm unless the effective privilege mode is U
and hstatus.HU=0.

active , means that the hardware mmu address translation may use this register. However, even if the register is not active, it does not mean that the address translation is not working.
In U mode, most of the time address translation is done by reading satp registers to do VA(virtual address) -> PA(Physical Addresses) . Only when cpu executes instructions such as HLV, register hgatp and vsatp are required (active) to do GVA(Guest Virtual Address)->GPA(Guest Physical Address)->SPA(Supervisor Physical Address)

Back to this patch, when we go into this if (vmode), it must be VU or VS, not U mode. And VU and VS do not need to consider hstatus.HU. To ensure that the address translation in VU mode works properly, we need to delete these code.

zhefan.lv and others added 2 commits May 16, 2025 11:02
When vmode=1 and effective_mode=PRV_U, it is VU mode but not
U mode, address translation don't need to care hstatus.HU.
Whether MMU is enabled depends on hgatp mode and vsatp mode.
Add the necessary get_filed and add a comment to indicate
this section is for VU/VS mode
@zqb-all zqb-all force-pushed the addr-translate-h-mode branch from a1ce63a to b72b83a Compare May 16, 2025 03:17
@aap-sc aap-sc requested review from en-sc and aap-sc May 18, 2025 05:50
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