Switch to H-mode
Hi Alistair and community,
I am working on RISC-V support upstream for Xen based on your and Bobby patches.
Adding the RISC-V support I realized that Xen is ran in S-mode. Output of OpenSBI:
...
Domain0 Next Mode : S-mode
...So the first my question is shouldn't it be in H-mode?
If I am right than it looks like we have to do a patch to OpenSBI to add support of H-mode as it is not supported now:
[1]
https://github.com/riscv-software-src/opensbi/blob/master/lib/sbi/sbi_domain.c#L380
[2]
https://github.com/riscv-software-src/opensbi/blob/master/include/sbi/riscv_encoding.h#L110
Please correct me if I am wrong.
The other option I see is to switch to H-mode in U-boot as I understand the classical boot flow is:
OpenSBI -> U-boot -> Xen -> Domain{0,...}If it is at all possible since U-boot will be in S mode after OpenSBI.
Thanks in advance.
~ Oleksii
Quoted 20 lines · Oleksii
Hi Alistair and community,
I am working on RISC-V support upstream for Xen based on your and Bobby patches.
Adding the RISC-V support I realized that Xen is ran in S-mode. Output of OpenSBI:
... Domain0 Next Mode : S-mode ...So the first my question is shouldn't it be in H-mode?
If I am right than it looks like we have to do a patch to OpenSBI to add support of H-mode as it is not supported now:
[1]
https://github.com/riscv-software-src/opensbi/blob/master/lib/sbi/sbi_domain.c#L380
[2]
https://github.com/riscv-software-src/opensbi/blob/master/include/sbi/riscv_encoding.h#L110
Please correct me if I am wrong.
Quoted 9 lines
The other option I see is to switch to H-mode in U-boot as I understand the classical boot flow is:
OpenSBI -> U-boot -> Xen -> Domain{0,...}If it is at all possible since U-boot will be in S mode after OpenSBI.
Thanks in advance.
~ Oleksii
Ah, what you are seeing there is that the openSBI's Next Mode excludes the virtualization mode (it treats HS and S synonymously) and it is only used for setting the mstatus MPP. The code also has next_virt for setting the MPV but I don't think that is exposed via the device tree yet. For Xen, you'd want next_mode = PRIV_S and next_virt = 0 (HS mode, not VS mode). The relevant setup prior to mret is here for interested readers:
https://github.com/riscv-software-src/opensbi/blob/001106d19b21cd6443ae7f7f6d4d048d80e9ecac/lib/sbi/sbi_hart.c#L759
As long as the next_mode and next_virt are set correctly, then Xen should be launching in HS mode. I do believe this should be default for the stock build too for Domain0, unless something has changed.
Thanks,
Bobby
Quoted 39 lines · Bobby Eshleman
Quoted 20 lines · Oleksii
Hi Alistair and community,
I am working on RISC-V support upstream for Xen based on your and Bobby patches.
Adding the RISC-V support I realized that Xen is ran in S-mode. Output of OpenSBI:
... Domain0 Next Mode : S-mode ...So the first my question is shouldn't it be in H-mode?
If I am right than it looks like we have to do a patch to OpenSBI to add support of H-mode as it is not supported now:
[1]
https://github.com/riscv-software-src/opensbi/blob/master/lib/sbi/sbi_domain.c#L380
[2]
https://github.com/riscv-software-src/opensbi/blob/master/include/sbi/riscv_encoding.h#L110
Please correct me if I am wrong.Quoted 9 lines
The other option I see is to switch to H-mode in U-boot as I understand the classical boot flow is:
OpenSBI -> U-boot -> Xen -> Domain{0,...}If it is at all possible since U-boot will be in S mode after OpenSBI.
Thanks in advance.
~ Oleksii
Ah, what you are seeing there is that the openSBI's Next Mode excludes the virtualization mode (it treats HS and S synonymously) and it is only used for setting the mstatus MPP. The code also has
next_virtfor setting the MPV but I don't think that is exposed via the device tree yet. For Xen, you'd wantnext_mode=PRIV_Sandnext_virt= 0 (HS mode, not VS mode). The relevant setup prior to mret is here for interested readers:
https://github.com/riscv-software-src/opensbi/blob/001106d19b21cd6443ae7f7f6d4d048d80e9ecac/lib/sbi/sbi_hart.c#L759
Quoted 3 lines
As long as the
next_modeandnext_virtare set correctly, then Xen should be launching in HS mode. I do believe this should be default for the stock build too for Domain0, unless something has changed.
Ok, so everything ought to be doing the right thing, even if it doesn't show up clearly in the logging.
At some point, Xen is going to need a if ( !hs-mode ) panic();, because we can't operate dom0 properly if Xen is in plan S-mode.
I suggested that we try and make csr_read_safe() work, then try and read hstatus to probe if the H extension is active.
Does this sound reasonable, or is there a better option?
~Andrew
Quoted 45 lines · Andrew Cooper
Quoted 39 lines · Bobby Eshleman
Quoted 20 lines · Oleksii
Hi Alistair and community,
I am working on RISC-V support upstream for Xen based on your and Bobby patches.
Adding the RISC-V support I realized that Xen is ran in S-mode. Output of OpenSBI:
... Domain0 Next Mode : S-mode ...So the first my question is shouldn't it be in H-mode?
If I am right than it looks like we have to do a patch to OpenSBI to add support of H-mode as it is not supported now:
[1]
https://github.com/riscv-software-src/opensbi/blob/master/lib/sbi/sbi_domain.c#L380
[2]
https://github.com/riscv-software-src/opensbi/blob/master/include/sbi/riscv_encoding.h#L110
Please correct me if I am wrong.Quoted 9 lines
The other option I see is to switch to H-mode in U-boot as I understand the classical boot flow is:
OpenSBI -> U-boot -> Xen -> Domain{0,...}If it is at all possible since U-boot will be in S mode after OpenSBI.
Thanks in advance.
~ Oleksii
Ah, what you are seeing there is that the openSBI's Next Mode excludes the virtualization mode (it treats HS and S synonymously) and it is only used for setting the mstatus MPP. The code also has
next_virtfor setting the MPV but I don't think that is exposed via the device tree yet. For Xen, you'd wantnext_mode=PRIV_Sandnext_virt= 0 (HS mode, not VS mode). The relevant setup prior to mret is here for interested readers:
https://github.com/riscv-software-src/opensbi/blob/001106d19b21cd6443ae7f7f6d4d048d80e9ecac/lib/sbi/sbi_hart.c#L759Quoted 3 lines
As long as the
next_modeandnext_virtare set correctly, then Xen should be launching in HS mode. I do believe this should be default for the stock build too for Domain0, unless something has changed.
Quoted 5 lines
Ok, so everything ought to be doing the right thing, even if it doesn't show up clearly in the logging.
At some point, Xen is going to need a
if ( !hs-mode ) panic();, because we can't operate dom0 properly if Xen is in plan S-mode.
There are going to be two cases where Xen won't be able to continue. If it's booting on hardware that doesn't have the Hypervisor extension or if it's booting in VS-mode (inside a guest).
In theory Xen could run as a nested Hypervisor in VS-mode, but let's worry about that later.
Quoted 3 lines
I suggested that we try and make
csr_read_safe()work, then try and readhstatusto probe if the H extension is active.
I think that makes sense. We don't need to probe for hstatus until late in the boot though. We should get the console up first so we can print a useful message. Xen won't need to touch the h* CSRs until it's about to start a guest.
Alistair
Quoted 4 lines
Does this sound reasonable, or is there a better option?
~Andrew
Quoted 40 lines · Andrew Cooper
Quoted 39 lines · Bobby Eshleman
Quoted 20 lines · Oleksii
Hi Alistair and community,
I am working on RISC-V support upstream for Xen based on your and Bobby patches.
Adding the RISC-V support I realized that Xen is ran in S-mode. Output of OpenSBI:
... Domain0 Next Mode : S-mode ...So the first my question is shouldn't it be in H-mode?
If I am right than it looks like we have to do a patch to OpenSBI to add support of H-mode as it is not supported now:
[1]
https://github.com/riscv-software-src/opensbi/blob/master/lib/sbi/sbi_domain.c#L380
[2]
https://github.com/riscv-software-src/opensbi/blob/master/include/sbi/riscv_encoding.h#L110
Please correct me if I am wrong.Quoted 9 lines
The other option I see is to switch to H-mode in U-boot as I understand the classical boot flow is:
OpenSBI -> U-boot -> Xen -> Domain{0,...}If it is at all possible since U-boot will be in S mode after OpenSBI.
Thanks in advance.
~ Oleksii
Ah, what you are seeing there is that the openSBI's Next Mode excludes the virtualization mode (it treats HS and S synonymously) and it is only used for setting the mstatus MPP. The code also has
next_virtfor setting the MPV but I don't think that is exposed via the device tree yet. For Xen, you'd wantnext_mode=PRIV_Sandnext_virt= 0 (HS mode, not VS mode). The relevant setup prior to mret is here for interested readers:
https://github.com/riscv-software-src/opensbi/blob/001106d19b21cd6443ae7f7f6d4d048d80e9ecac/lib/sbi/sbi_hart.c#L759
Quoted 7 lines
Quoted 3 lines
As long as the
next_modeandnext_virtare set correctly, then Xen should be launching in HS mode. I do believe this should be default for the stock build too for Domain0, unless something has changed.Ok, so everything ought to be doing the right thing, even if it doesn't show up clearly in the logging.
Right.
Quoted 9 lines
At some point, Xen is going to need a
if ( !hs-mode ) panic();, because we can't operate dom0 properly if Xen is in plan S-mode.I suggested that we try and make
csr_read_safe()work, then try and readhstatusto probe if the H extension is active.Does this sound reasonable, or is there a better option?
~Andrew
That sounds reasonable to me.
The alternative is parsing the isa string from the dtb, which also seems fine, but I'm not sure if it is better per se.
Best,
Bobby
Quoted 48 lines · Bobby Eshleman
Quoted 30 lines · Oleksii
Hi Alistair and community,
I am working on RISC-V support upstream for Xen based on your and Bobby
patches.Adding the RISC-V support I realized that Xen is ran in S-mode. Output
of OpenSBI:
...
Domain0 Next Mode : S-mode
...
So the first my question is shouldn't it be in H-mode?If I am right than it looks like we have to do a patch to OpenSBI to
add support of H-mode as it is not supported now:
[1]
https://github.com/riscv-software-src/opensbi/blob/master/lib/sbi/sbi_domain.c#L380
[2]
https://github.com/riscv-software-src/opensbi/blob/master/include/sbi/riscv_encoding.h#L110
Please correct me if I am wrong.The other option I see is to switch to H-mode in U-boot as I understand
the classical boot flow is:
OpenSBI -> U-boot -> Xen -> Domain{0,...}
If it is at all possible since U-boot will be in S mode after OpenSBI.Quoted 4 lines
Thanks in advance.
~ Oleksii
Ah, what you are seeing there is that the openSBI's Next Mode excludes
the virtualization mode (it treats HS and S synonymously) and it is only
used for setting the mstatus MPP. The code also hasnext_virtfor setting the MPV but I don't think that is exposed via the device tree yet. For Xen, you'd wantnext_mode=PRIV_Sandnext_virt= 0 (HS mode,
not VS mode). The relevant setup prior to mret is here for interested readers:
https://github.com/riscv-software-src/opensbi/blob/001106d19b21cd6443ae7f7f6d4d048d80e9ecac/lib/sbi/sbi_hart.c#L759
Quoted 5 lines
As long as the
next_modeandnext_virtare set correctly, then Xen should be launching in HS mode. I do believe this should be default for
the stock build too for Domain0, unless something has changed.
The same I've found in OpenSBI before but wasn't 100% sure that I'm right. Now it is clear.
Thanks for your explanation.
Quoted 2 lines
Thanks,
Bobby
~ Oleksii
Quoted 6 lines · Oleksii
Hi Alistair and community,
I am working on RISC-V support upstream for Xen based on your and Bobby
patches.
Quoted 7 lines
Adding the RISC-V support I realized that Xen is ran in S-mode. Output
of OpenSBI:
...
Domain0 Next Mode : S-mode
...
So the first my question is shouldn't it be in H-mode?
There is no H-mode in RISC-V.
When the Hypervisor extension exists the standard S-mode automatically becomes HS-mode. The two names can be used interchangeably (although the spec calls it HS-mode).
In this way Linux (with or without KVM support) and Xen all boot in the same mode and can choose to use virtulisation if desired.
Quoted 9 lines
If I am right than it looks like we have to do a patch to OpenSBI to add support of H-mode as it is not supported now:
[1]
https://github.com/riscv-software-src/opensbi/blob/master/lib/sbi/sbi_domain.c#L380
[2]
https://github.com/riscv-software-src/opensbi/blob/master/include/sbi/riscv_encoding.h#L110
Please correct me if I am wrong.
Quoted 6 lines
The other option I see is to switch to H-mode in U-boot as I understand
the classical boot flow is:
OpenSBI -> U-boot -> Xen -> Domain{0,...}
If it is at all possible since U-boot will be in S mode after OpenSBI.
S-mode is where you want to be. That's what Xen should start in.
Alistair
Quoted 4 lines
Thanks in advance.
~ Oleksii
Quoted 36 lines · Alistair Francis
Quoted 6 lines · Oleksii
Hi Alistair and community,
I am working on RISC-V support upstream for Xen based on your and Bobby
patches.Quoted 7 lines
Adding the RISC-V support I realized that Xen is ran in S-mode. Output
of OpenSBI:
...
Domain0 Next Mode : S-mode
...
So the first my question is shouldn't it be in H-mode?There is no H-mode in RISC-V.
When the Hypervisor extension exists the standard S-mode automatically
becomes HS-mode. The two names can be used interchangeably (although the spec calls it HS-mode).In this way Linux (with or without KVM support) and Xen all boot in the
same mode and can choose to use virtulisation if desired.Quoted 10 lines
If I am right than it looks like we have to do a patch to OpenSBI to
add support of H-mode as it is not supported now:
[1]
https://github.com/riscv-software-src/opensbi/blob/master/lib/sbi/sbi_domain.c#L380
[2]
https://github.com/riscv-software-src/opensbi/blob/master/include/sbi/riscv_encoding.h#L110
Please correct me if I am wrong.
Quoted 9 lines
Quoted 6 lines
The other option I see is to switch to H-mode in U-boot as I understand
the classical boot flow is:
OpenSBI -> U-boot -> Xen -> Domain{0,...}
If it is at all possible since U-boot will be in S mode after OpenSBI.S-mode is where you want to be. That's what Xen should start in.
Thanks for clarification.
~ Oleksii
Quoted 7 lines
Alistair
Quoted 4 lines
Thanks in advance.
~ Oleksii