Need guidance to support reading GICR_TYPER (64 bit register) on Aarch32_v8r
Hi Arm mantainers/Folks,
Please refer to the discussion https://github.com/zephyrproject-rtos/zephyr/pull/51163 .
We intend to run Zephyr as a domU guest on Xen on Aarch32_v8R fixed virtual platform.
Zephyr is trying to read GICR_TYPER which is a 64 bit register using ldrd instruction.
As GICR is emulated by Xen, so this instruction gets trapped with HSR = 0x9200000c.
As ISV is 0, so Xen cannot emulate this instruction.
The proposed solution is to use two sys_read32() on GICR_TYPER to return the lower and upper 32 bits.
With this, HSR = 0x9383 000c, ISV=1 so ISS is valid.
Now, for Xen to emulate this read, I have proposed the modifications (in my last comment).
1. Does the proposed modifications look sane ? Or could there be a better alternative ?
2. As there is no 32 bit variant for GICR_TYPER, so does it make sense to read this register at all ?
Kind regards,
Ayan
Quoted 1 line · Ayan Kumar Halder
Hi Arm mantainers/Folks,
Hello,
Quoted 8 lines
Please refer to the discussion https://github.com/zephyrproject-rtos/zephyr/pull/51163 .
We intend to run Zephyr as a domU guest on Xen on
Aarch32_v8Rfixed virtual platform.Zephyr is trying to read
GICR_TYPERwhich is a 64 bit register using ldrd instruction.As GICR is emulated by Xen, so this instruction gets trapped with HSR =
0x9200000c.
Quoted 7 lines
As ISV is 0, so Xen cannot emulate this instruction.
The proposed solution is to use two
sys_read32()onGICR_TYPERto return the lower and upper 32 bits.With this, HSR =
0x9383000c, ISV=1 so ISS is valid.Now, for Xen to emulate this read, I have proposed the modifications (in my last comment).
I am confused. Looking at the emulation of GICR_TYPER in Xen (arch/arm/vgic-v3.c), the code should already be able to handle 32-bit access.
I doesn't look like we need to modify Xen. What did I miss?
Cheers,
Signature · 1 line
Julien Grall
Quoted 4 lines · Julien Grall
Quoted 1 line · Ayan Kumar Halder
Hi Arm mantainers/Folks,
Hello,
Hi Julien,
Appreciate your help as always. :)
Quoted 11 lines
Quoted 11 lines
Please refer to the discussion https://github.com/zephyrproject-rtos/zephyr/pull/51163 .
We intend to run Zephyr as a domU guest on Xen on
Aarch32_v8Rfixed virtual platform.Zephyr is trying to read
GICR_TYPERwhich is a 64 bit register using ldrd instruction.As GICR is emulated by Xen, so this instruction gets trapped with HSR =
0x9200000c.As ISV is 0, so Xen cannot emulate this instruction.
Quoted 7 lines
Quoted 5 lines
The proposed solution is to use two
sys_read32()onGICR_TYPERto return the lower and upper 32 bits.With this, HSR =
0x9383000c, ISV=1 so ISS is valid.Now, for Xen to emulate this read, I have proposed the modifications (in my last comment).
I am confused. Looking at the emulation of
GICR_TYPERin Xen (arch/arm/vgic-v3.c), the code should already be able to handle 32-bit access.
When I compile Xen for arm32, vreg_reg64_extract() definitions do not exist.
The reason being https://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=xen/arch/arm/include/asm/vreg.h;h=f26a70d024e2d1f933ea66793ea6e42f81c7a8cf;hb=9029bc265cdf2bd63376dde9fdd91db4ce9c0586#l189 , BITS_PER_LONG is 32 (Refer xen/arch/arm/include/asm/config.h).
.Thus, the guest need to invoke sys_read32() twice (GICR_TYPER and GICR_TYPER+4).
Quoted 5 lines
I doesn't look like we need to modify Xen. What did I miss?
Cheers,
Hi Ayan,
Quoted 24 lines · Ayan Kumar Halder
Quoted 4 lines · Julien Grall
Quoted 1 line · Ayan Kumar Halder
Hi Arm mantainers/Folks,
Hello,
Hi Julien,
Appreciate your help as always. :)
Quoted 13 lines
Quoted 13 lines
Please refer to the discussion https://github.com/zephyrproject-rtos/zephyr/pull/51163 .
We intend to run Zephyr as a domU guest on Xen on
Aarch32_v8Rfixed virtual platform.Zephyr is trying to read
GICR_TYPERwhich is a 64 bit register using ldrd instruction.As GICR is emulated by Xen, so this instruction gets trapped with HSR =
0x9200000c.As ISV is 0, so Xen cannot emulate this instruction.
The proposed solution is to use two
sys_read32()onGICR_TYPERto return the lower and upper 32 bits.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
With this, HSR =
0x9383000c, ISV=1 so ISS is valid.Now, for Xen to emulate this read, I have proposed the modifications (in my last comment).
I am confused. Looking at the emulation of
GICR_TYPERin Xen (arch/arm/vgic-v3.c), the code should already be able to handle 32-bit access.When I compile Xen for arm32,
vreg_reg64_extract()definitions do not exist.
Ah. You are building Xen for arm32... This is unsupported by Xen at the moment.
Quoted 2 lines
The reason being https://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=xen/arch/arm/include/asm/vreg.h;h=f26a70d024e2d1f933ea66793ea6e42f81c7a8cf;hb=9029bc265cdf2bd63376dde9fdd91db4ce9c0586#l189 ,
BITS_PER_LONGis 32 (Referxen/arch/arm/include/asm/config.h).
Right, so that's not an architecture issue (like 'ldrd') but just Xen not providing the helper.
As I wrote above, Xen doesn't yet support GICv3 on arm32. I expect that implementing vreg_reg64_extract() will be one of the step.
Quoted 2 lines
.Thus, the guest need to invoke
sys_read32()twice (GICR_TYPERand GICR_TYPER+4).
I don't understand how you came to this conclusion with what you wrote. If we had implemented vreg_reg64_extract(), then Zephyr would still need to issue two 32-bit read because Xen doesn't emulate 'ldrd'.
Cheers,
Signature · 1 line
Julien Grall
Quoted 1 line · Julien Grall
Hi Ayan,
Hi Julien,
Quoted 28 lines · Ayan Kumar Halder
Quoted 26 lines · Julien Grall
Quoted 4 lines · Ayan Kumar Halder
Quoted 1 line
Hi Arm mantainers/Folks,
Hello,
Hi Julien,
Appreciate your help as always. :)
Quoted 15 lines
Quoted 15 lines
Please refer to the discussion https://github.com/zephyrproject-rtos/zephyr/pull/51163 .
We intend to run Zephyr as a domU guest on Xen on
Aarch32_v8Rfixed virtual platform.Zephyr is trying to read
GICR_TYPERwhich is a 64 bit register using ldrd instruction.As GICR is emulated by Xen, so this instruction gets trapped with HSR =
0x9200000c.As ISV is 0, so Xen cannot emulate this instruction.
The proposed solution is to use two
sys_read32()onGICR_TYPERto return the lower and upper 32 bits.With this, HSR =
0x9383000c, ISV=1 so ISS is valid.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Now, for Xen to emulate this read, I have proposed the modifications (in my last comment).
I am confused. Looking at the emulation of
GICR_TYPERin Xen (arch/arm/vgic-v3.c), the code should already be able to handle 32-bit access.When I compile Xen for arm32,
vreg_reg64_extract()definitions do not exist.Ah. You are building Xen for arm32... This is unsupported by Xen at the moment.
Yes.
Quoted 5 lines
Quoted 3 lines
The reason being https://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=xen/arch/arm/include/asm/vreg.h;h=f26a70d024e2d1f933ea66793ea6e42f81c7a8cf;hb=9029bc265cdf2bd63376dde9fdd91db4ce9c0586#l189 ,
BITS_PER_LONGis 32 (Referxen/arch/arm/include/asm/config.h).Right, so that's not an architecture issue (like 'ldrd') but just Xen not providing the helper.
Sorry, I was not very clear.
With ldrd, HSR=0x9200000c. As ISV=0, Xen cannot emulate the instruction.
So even if Xen had implemented vreg_reg64_extract() for arm32 GICv3, it would not have helped here. Unless, we decide to decode the instruction which may not be correct thing to do (as you explained in the comment on https://github.com/zephyrproject-rtos/zephyr/pull/51163).
Quoted 2 lines
As I wrote above, Xen doesn't yet support GICv3 on arm32. I expect that implementing
vreg_reg64_extract()will be one of the step.
I don't think it is required in this particular scenario. I have explained below.
Quoted 5 lines
Quoted 3 lines
.Thus, the guest need to invoke
sys_read32()twice (GICR_TYPERand GICR_TYPER+4).I don't understand how you came to this conclusion with what you wrote.
Sorry for confusion. I was trying to explain that the code does not handle 32 bit access of GICR_TYPER on arm32.
Quoted 1 line
If we had implemented
vreg_reg64_extract(), then Zephyr would still need to issue two 32-bit read because Xen doesn't emulate 'ldrd'.
Yes. So what we need here is not the implementation of vreg_reg64_extract() for GICR_TYPER.
Zephyr will issue two 32 bit read access for GICR_TYPER and (GICR_TYPER + 4). So Xen needs to emulate 32 bit read for GICR_TYPER and GICR_TYPER + 4.
So, we will need to modify the Xen code as follows :-
|#ifdef AARCH32 case VREG32(GICR_TYPER_L32) : { read and return lower 32 bits of GICR_TYPER return 1; } case VREG32(GICR_TYPER_H32) : { read and return the upper 32 bits of GICR_TYPER return 1; } #else /* For AARCH64 */ case VREG64(GICR_TYPER): { do as existing; } #endif Let me know if this looks sane. I can then submit a single patch to add support for this. |
Quoted 3 lines
Cheers,
Hi,
Quoted 4 lines · Ayan Kumar Halder
Quoted 2 lines · Julien Grall
Quoted 1 line
.Thus, the guest need to invoke
sys_read32()twice (GICR_TYPERand GICR_TYPER+4).
Quoted 8 lines
Quoted 1 line
I don't understand how you came to this conclusion with what you wrote.
Sorry for confusion. I was trying to explain that the code does not handle 32 bit access of
GICR_TYPERon arm32.Quoted 1 line
If we had implemented
vreg_reg64_extract(), then Zephyr would still need to issue two 32-bit read because Xen doesn't emulate 'ldrd'.Yes. So what we need here is not the implementation of
vreg_reg64_extract()forGICR_TYPER.
Why not? Your GICR_TYPER is a 64-bit and the helper is the right way to hide whether the low/high 32-bit are accessed.
Quoted 8 lines
Zephyr will issue two 32 bit read access for
GICR_TYPERand (GICR_TYPER
+ 4). So Xen needs to emulate 32 bit read forGICR_TYPERandGICR_TYPER
+ 4.So, we will need to modify the Xen code as follows :-
|#ifdef AARCH32 case
VREG32(GICR_TYPER_L32): { read and return lower 32 bits ofGICR_TYPERreturn 1; } caseVREG32(GICR_TYPER_H32): { read and return the upper 32 bits ofGICR_TYPERreturn 1; } #else /* For AARCH64 */ caseVREG64(GICR_TYPER): { do as existing; } #endif Let me know if this looks sane. I can then submit a single patch to add support for this. |
This is a bit difficult to read. So I looked at your answer on the Zephyr thread.
You will end up to duplicate code for emulating TYPER and there are quite a few other use of vreg_reg64_extract() in the code.
So I am afraid this is not an option for me. If you implement vreg_reg64_* then you will not need to implement.
I would be open to other suggestion so long we don't end up with duplication or any other kind of open-coding.
Cheers,
Signature · 1 line
Julien Grall
Quoted 1 line · Julien Grall
Hi,
Hi Julien,
Quoted 8 lines · Ayan Kumar Halder
Quoted 6 lines · Julien Grall
Quoted 3 lines
Quoted 1 line
.Thus, the guest need to invoke
sys_read32()twice (GICR_TYPERand GICR_TYPER+4).I don't understand how you came to this conclusion with what you wrote.
Quoted 7 lines
Quoted 6 lines
Sorry for confusion. I was trying to explain that the code does not handle 32 bit access of
GICR_TYPERon arm32.Quoted 1 line
If we had implemented
vreg_reg64_extract(), then Zephyr would still need to issue two 32-bit read because Xen doesn't emulate 'ldrd'.Yes. So what we need here is not the implementation of
vreg_reg64_extract()forGICR_TYPER.Why not? Your
GICR_TYPERis a 64-bit and the helper is the right way to hide whether the low/high 32-bit are accessed.
When Zephyr issues 32 bit reads for GICR_TYPER for GICR_TYPER + 4, it traps to Xen two times.
So, my understanding is that Xen needs to read two 32 bit values.
We can modify the vreg_reg64_extract() so that it can return the lower 32 bits in one case and upper 32 bits in the second case.
Is this what you are suggesting ?
- Ayan
Quoted 18 lines
Quoted 7 lines
Zephyr will issue two 32 bit read access for
GICR_TYPERand (GICR_TYPER+ 4). So Xen needs to emulate 32 bit read forGICR_TYPERandGICR_TYPER+ 4.So, we will need to modify the Xen code as follows :-
|#ifdef AARCH32 case
VREG32(GICR_TYPER_L32): { read and return lower 32 bits ofGICR_TYPERreturn 1; } caseVREG32(GICR_TYPER_H32): { read and return the upper 32 bits ofGICR_TYPERreturn 1; } #else /* For AARCH64 */ caseVREG64(GICR_TYPER): { do as existing; } #endif Let me know if this looks sane. I can then submit a single patch to add support for this. |This is a bit difficult to read. So I looked at your answer on the Zephyr thread.
You will end up to duplicate code for emulating TYPER and there are quite a few other use of
vreg_reg64_extract()in the code.So I am afraid this is not an option for me. If you implement vreg_reg64_* then you will not need to implement.
I would be open to other suggestion so long we don't end up with duplication or any other kind of open-coding.
Cheers,
Hi Ayan,
Quoted 20 lines · Ayan Kumar Halder
Quoted 1 line · Julien Grall
Hi,
Hi Julien,
Quoted 8 lines · Ayan Kumar Halder
Quoted 6 lines · Julien Grall
Quoted 3 lines
Quoted 1 line
.Thus, the guest need to invoke
sys_read32()twice (GICR_TYPERand GICR_TYPER+4).I don't understand how you came to this conclusion with what you wrote.
Quoted 7 lines
Quoted 6 lines
Sorry for confusion. I was trying to explain that the code does not handle 32 bit access of
GICR_TYPERon arm32.Quoted 1 line
If we had implemented
vreg_reg64_extract(), then Zephyr would still need to issue two 32-bit read because Xen doesn't emulate 'ldrd'.Yes. So what we need here is not the implementation of
vreg_reg64_extract()forGICR_TYPER.Why not? Your
GICR_TYPERis a 64-bit and the helper is the right way to hide whether the low/high 32-bit are accessed.
Quoted 7 lines
When Zephyr issues 32 bit reads for
GICR_TYPERforGICR_TYPER+ 4, it traps to Xen two times.So, my understanding is that Xen needs to read two 32 bit values.
We can modify the
vreg_reg64_extract()so that it can return the lower 32 bits in one case and upper 32 bits in the second case.Is this what you are suggesting ?
Well... The helper is already doing that. It was introduced to support 32-bit guest using GICv3 on 64-bit Xen.
Cheers,
Signature · 1 line
Julien Grall
Quoted 14 lines · Ayan Kumar Halder
Hi Arm mantainers/Folks,
Please refer to the discussion
https://github.com/zephyrproject-rtos/zephyr/pull/51163 .We intend to run Zephyr as a domU guest on Xen on
Aarch32_v8Rfixed virtual platform.Zephyr is trying to read
GICR_TYPERwhich is a 64 bit register using ldrd instruction.As GICR is emulated by Xen, so this instruction gets trapped with HSR =
0x9200000c.
Quoted 6 lines
As ISV is 0, so Xen cannot emulate this instruction.
The proposed solution is to use two
sys_read32()onGICR_TYPERto return the lower and upper 32 bits.With this, HSR =
0x9383000c, ISV=1 so ISS is valid.
Hi all,
I wanted to take a step back on this issue before we jump into the details.
Differently from other instructions we discussed in the past, strd and ldrd are not deprecated and are not "unusual corner cases". There is no statements such as "please don't use this" on the ARM ARM. If I were to write an register read/write function in assembly for an RTOS, it would be reasonable to use them.
So, I struggle to see how we'll be able to deal with all the possible RTOSes out there that might have them in the code. We can fix Zephyr, but what about FreeRTOS, ThreadX and the proprietary ones (VxWorks, etc.)?
Unless we can get ARM to issue a clear guidance that strd and ldrd are deprecated, I think it would be better to attempt to decode them rather than just fail. I don't like to have this kind of code in Xen, but I don't see a way to support R52s without it.
That said, of course if Zephyr was to use two 32-bit reads instead of one 64-bit read, it would be better for Xen. And we have more important things to deal with right now in terms of R52 support (it is not even upstream yet). So it is totally fine to change Zephyr and move forward for now.
But medium term it doesn't seem to me that we can get away without a solution in Xen for this (or a change in the ARM ARM).
Hi Stefano,
Quoted 28 lines · Stefano Stabellini
Quoted 14 lines · Ayan Kumar Halder
Hi Arm mantainers/Folks,
Please refer to the discussion
https://github.com/zephyrproject-rtos/zephyr/pull/51163 .We intend to run Zephyr as a domU guest on Xen on
Aarch32_v8Rfixed virtual platform.Zephyr is trying to read
GICR_TYPERwhich is a 64 bit register using ldrd instruction.As GICR is emulated by Xen, so this instruction gets trapped with HSR =
0x9200000c.Quoted 6 lines
As ISV is 0, so Xen cannot emulate this instruction.
The proposed solution is to use two
sys_read32()onGICR_TYPERto return the lower and upper 32 bits.With this, HSR =
0x9383000c, ISV=1 so ISS is valid.Hi all,
I wanted to take a step back on this issue before we jump into the details.
Quoted 5 lines
Differently from other instructions we discussed in the past, strd and ldrd are not deprecated and are not "unusual corner cases". There is no statements such as "please don't use this" on the ARM ARM. If I were to write an register read/write function in assembly for an RTOS, it would be reasonable to use them.
Just to be clear it is fine to use the ldrd/strd for accessing non MMIO area. The problem comes with MMIO access because they can be emulated by the hypervisor and we don't have the syndrome. At the moment, this is only a problem when accessing some of the GICv3 (including ITS) registers.
Quoted 5 lines
So, I struggle to see how we'll be able to deal with all the possible RTOSes out there that might have them in the code. We can fix Zephyr, but what about FreeRTOS, ThreadX and the proprietary ones (VxWorks, etc.)?
This is not an Xen issue but architecture issue. The RTOSes will face the exact same issue on any hypervisors unless they decided to decode the instruction.
As we discussed before decoding an instruction correctly is quite difficult to do (what we have in Xen for pos-increment store/load is just a band-aid). So I would expect the other hypervisors to have made the decision to not implement it. AFAIK KVM doesn't suppor them, Note that looking at ID_ISAR2, it seems that ldrd/strd is technically optional. Therefore, the RTOS would have to assume it is targeting a processor that supports them.
Quoted 3 lines
Unless we can get ARM to issue a clear guidance that strd and ldrd are deprecated,
Arm Arm cannot say that because ldrd/strd are necessary to modify the LPAE page-tables atomically. What we need to know is which instructions can be allowed on MMIO accesses.
I think I already raised that when Ayan added decoding for post-increment instructions. There are plenty of instructions (or combinations) that doesn't provide a syndrome and yet the processor doesn't prevent anyone to use them on MMIO.
I was worry we are going to have to continue to decode instructions in a non-compliant way in Xen just to please a few RTOs that may not even run anywhere else.
This would also reduce our leverage to request a change in the RTOes or the Arm Arm (maybe there is already a statement I haven't spotted) because Xen will already (badly) support the instruction.
Quoted 3 lines
I think it would be better to attempt to decode them rather than just fail. I don't like to have this kind of code in Xen, but I don't see a way to support R52s without it.
That's not specific to R52. This is anyone using GICv3 on Arm32 core.
Quoted 9 lines
That said, of course if Zephyr was to use two 32-bit reads instead of one 64-bit read, it would be better for Xen. And we have more important things to deal with right now in terms of R52 support (it is not even upstream yet). So it is totally fine to change Zephyr and move forward for now.
But medium term it doesn't seem to me that we can get away without a solution in Xen for this (or a change in the ARM ARM).
See above. This is an architecture problem and we should discuss with Arm first before continuing to add more decoding in Xen.
Cheers,
Signature · 1 line
Julien Grall
Hi,
Quoted 44 lines · Julien Grall
Hi Stefano,
Quoted 21 lines · Stefano Stabellini
Quoted 14 lines · Ayan Kumar Halder
Hi Arm mantainers/Folks,
Please refer to the discussion
https://github.com/zephyrproject-rtos/zephyr/pull/51163 .We intend to run Zephyr as a domU guest on Xen on
Aarch32_v8Rfixed virtual platform.Zephyr is trying to read
GICR_TYPERwhich is a 64 bit register using ldrd instruction.As GICR is emulated by Xen, so this instruction gets trapped with HSR =
0x9200000c.Quoted 6 lines
As ISV is 0, so Xen cannot emulate this instruction.
The proposed solution is to use two
sys_read32()onGICR_TYPERto return the lower and upper 32 bits.With this, HSR =
0x9383000c, ISV=1 so ISS is valid.Quoted 8 lines
Hi all,
I wanted to take a step back on this issue before we jump into the details.
Differently from other instructions we discussed in the past, strd and ldrd are not deprecated and are not "unusual corner cases". There is no statements such as "please don't use this" on the ARM ARM. If I were to write an register read/write function in assembly for an RTOS, it would be reasonable to use them.Just to be clear it is fine to use the ldrd/strd for accessing non MMIO area. The problem comes with MMIO access because they can be emulated by the hypervisor and we don't have the syndrome. At the moment, this is only a problem when accessing some of the GICv3 (including ITS) registers.
Quoted 4 lines
So, I struggle to see how we'll be able to deal with all the possible RTOSes out there that might have them in the code. We can fix Zephyr, but what about FreeRTOS, ThreadX and the proprietary ones (VxWorks, etc.)?
This is not an Xen issue but architecture issue. The RTOSes will face the exact same issue on any hypervisors unless they decided to decode the instruction.
Quoted 7 lines
As we discussed before decoding an instruction correctly is quite difficult to do (what we have in Xen for pos-increment store/load is just a band-aid). So I would expect the other hypervisors to have made the decision to not implement it. AFAIK KVM doesn't suppor them, Note that looking at
ID_ISAR2, it seems that ldrd/strd is technically optional. Therefore, the RTOS would have to assume it is targeting a processor that supports them.Quoted 2 lines
Unless we can get ARM to issue a clear guidance that strd and ldrd are deprecated,
Arm Arm cannot say that because ldrd/strd are necessary to modify the LPAE page-tables atomically. What we need to know is which instructions can be allowed on MMIO accesses.
Definitely this is something that arm arm cannot fully answer as it is also down to the full platform. MMIO accesses are going out of the CPU and hence wether or not 64bit MMIO accesses can be properly done might also depend on the bus or the IP on the other side (some peripherals might just refuse 64bit accesses or some bus might only be 32bit so the operations would need to be divided).
Quoted 6 lines
I think I already raised that when Ayan added decoding for post-increment instructions. There are plenty of instructions (or combinations) that doesn't provide a syndrome and yet the processor doesn't prevent anyone to use them on MMIO.
I was worry we are going to have to continue to decode instructions in a non-compliant way in Xen just to please a few RTOs that may not even run anywhere else.
This would also reduce our leverage to request a change in the RTOes or the Arm Arm (maybe there is already a statement I haven't spotted) because Xen will already (badly) support the instruction.
Going back on the ID_ISAR2, if Xen is properly setting the value seen by the guests, there is not reason for us to actually emulate those instructions. The emulation code inside Xen cost a lot in matter of lines of code and would need a lot of testing (which is missing at the moment). So as we have a standard way to inform the guest that this is not supported, we should stick to that.
Quoted 5 lines
Quoted 4 lines
I think it would be better to attempt to decode them rather than just fail. I don't like to have this kind of code in Xen, but I don't see a way to support R52s without it.
That's not specific to R52. This is anyone using GICv3 on Arm32 core.
Agree.
Quoted 10 lines
Quoted 8 lines
That said, of course if Zephyr was to use two 32-bit reads instead of one 64-bit read, it would be better for Xen. And we have more important things to deal with right now in terms of R52 support (it is not even upstream yet). So it is totally fine to change Zephyr and move forward for now.
But medium term it doesn't seem to me that we can get away without a solution in Xen for this (or a change in the ARM ARM).See above. This is an architecture problem and we should discuss with Arm first before continuing to add more decoding in Xen.
I will discuss it internally to have an answer but I think that the answer cannot only come from Arm as there are for sure hardware implementations that cannot support this, as explain before.
Cheers
Bertrand
Quoted 5 lines
Cheers,
Signature · 1 line
Julien Grall
Quoted 1 line · Bertrand Marquis
Hi,
Hi,
Quoted 57 lines
Quoted 44 lines · Julien Grall
Hi Stefano,
Quoted 21 lines · Stefano Stabellini
Quoted 14 lines · Ayan Kumar Halder
Hi Arm mantainers/Folks,
Please refer to the discussion
https://github.com/zephyrproject-rtos/zephyr/pull/51163 .We intend to run Zephyr as a domU guest on Xen on
Aarch32_v8Rfixed virtual platform.Zephyr is trying to read
GICR_TYPERwhich is a 64 bit register using ldrd instruction.As GICR is emulated by Xen, so this instruction gets trapped with HSR =
0x9200000c.Quoted 6 lines
As ISV is 0, so Xen cannot emulate this instruction.
The proposed solution is to use two
sys_read32()onGICR_TYPERto return the lower and upper 32 bits.With this, HSR =
0x9383000c, ISV=1 so ISS is valid.Quoted 8 lines
Hi all,
I wanted to take a step back on this issue before we jump into the details.
Differently from other instructions we discussed in the past, strd and ldrd are not deprecated and are not "unusual corner cases". There is no statements such as "please don't use this" on the ARM ARM. If I were to write an register read/write function in assembly for an RTOS, it would be reasonable to use them.Just to be clear it is fine to use the ldrd/strd for accessing non MMIO area. The problem comes with MMIO access because they can be emulated by the hypervisor and we don't have the syndrome. At the moment, this is only a problem when accessing some of the GICv3 (including ITS) registers.
Quoted 4 lines
So, I struggle to see how we'll be able to deal with all the possible RTOSes out there that might have them in the code. We can fix Zephyr, but what about FreeRTOS, ThreadX and the proprietary ones (VxWorks, etc.)?
This is not an Xen issue but architecture issue. The RTOSes will face the exact same issue on any hypervisors unless they decided to decode the instruction.
Quoted 7 lines
As we discussed before decoding an instruction correctly is quite difficult to do (what we have in Xen for pos-increment store/load is just a band-aid). So I would expect the other hypervisors to have made the decision to not implement it. AFAIK KVM doesn't suppor them, Note that looking at
ID_ISAR2, it seems that ldrd/strd is technically optional. Therefore, the RTOS would have to assume it is targeting a processor that supports them.Quoted 2 lines
Unless we can get ARM to issue a clear guidance that strd and ldrd are deprecated,
Arm Arm cannot say that because ldrd/strd are necessary to modify the LPAE page-tables atomically. What we need to know is which instructions can be allowed on MMIO accesses.
Definitely this is something that arm arm cannot fully answer as it is also down to the full platform. MMIO accesses are going out of the CPU and hence wether or not 64bit MMIO accesses can be properly done might also depend on the bus or the IP on the other side (some peripherals might just refuse 64bit accesses or some bus might only be 32bit so the operations would need to be divided).
Quoted 3 lines
I think I already raised that when Ayan added decoding for post-increment instructions. There are plenty of instructions (or combinations) that doesn't provide a syndrome and yet the processor doesn't prevent anyone to use them on MMIO.
Quoted 7 lines
Quoted 3 lines
I was worry we are going to have to continue to decode instructions in a non-compliant way in Xen just to please a few RTOs that may not even run anywhere else.
This would also reduce our leverage to request a change in the RTOes or the Arm Arm (maybe there is already a statement I haven't spotted) because Xen will already (badly) support the instruction.
Going back on the
ID_ISAR2, if Xen is properly setting the value seen by the guests, there is not reason for us to actually emulate those instructions. The emulation code inside Xen cost a lot in matter of lines of code and would need a lot of testing (which is missing at the moment). So as we have a standard way to inform the guest that this is not supported, we should stick to that.
Thanks for the feedback. AFAIU, the bit in ID_ISAR2 indicates whether ldrd/strd is present. If we decide to clear the bit, then it would mean the guest should not use them even when modifying LPAE page-tables.
This could be a problem because AFAIK those instructions are necessary to modify the page-tables atomically. Therefore, I don't Xen should clear the bit.
Cheers,
Signature · 1 line
Julien Grall
Quoted 68 lines · Julien Grall
Quoted 1 line · Bertrand Marquis
Hi,
Hi,
Quoted 57 lines
Quoted 44 lines · Julien Grall
Hi Stefano,
Quoted 21 lines · Stefano Stabellini
Quoted 14 lines · Ayan Kumar Halder
Hi Arm mantainers/Folks,
Please refer to the discussion
https://github.com/zephyrproject-rtos/zephyr/pull/51163 .We intend to run Zephyr as a domU guest on Xen on
Aarch32_v8Rfixed virtual platform.Zephyr is trying to read
GICR_TYPERwhich is a 64 bit register using ldrd instruction.As GICR is emulated by Xen, so this instruction gets trapped with HSR =
0x9200000c.Quoted 6 lines
As ISV is 0, so Xen cannot emulate this instruction.
The proposed solution is to use two
sys_read32()onGICR_TYPERto return the lower and upper 32 bits.With this, HSR =
0x9383000c, ISV=1 so ISS is valid.Quoted 8 lines
Hi all,
I wanted to take a step back on this issue before we jump into the details.
Differently from other instructions we discussed in the past, strd and ldrd are not deprecated and are not "unusual corner cases". There is no statements such as "please don't use this" on the ARM ARM. If I were to write an register read/write function in assembly for an RTOS, it would be reasonable to use them.Just to be clear it is fine to use the ldrd/strd for accessing non MMIO area. The problem comes with MMIO access because they can be emulated by the hypervisor and we don't have the syndrome. At the moment, this is only a problem when accessing some of the GICv3 (including ITS) registers.
Quoted 4 lines
So, I struggle to see how we'll be able to deal with all the possible RTOSes out there that might have them in the code. We can fix Zephyr, but what about FreeRTOS, ThreadX and the proprietary ones (VxWorks, etc.)?
This is not an Xen issue but architecture issue. The RTOSes will face the exact same issue on any hypervisors unless they decided to decode the instruction.
Quoted 7 lines
As we discussed before decoding an instruction correctly is quite difficult to do (what we have in Xen for pos-increment store/load is just a band-aid). So I would expect the other hypervisors to have made the decision to not implement it. AFAIK KVM doesn't suppor them, Note that looking at
ID_ISAR2, it seems that ldrd/strd is technically optional. Therefore, the RTOS would have to assume it is targeting a processor that supports them.Quoted 2 lines
Unless we can get ARM to issue a clear guidance that strd and ldrd are deprecated,
Arm Arm cannot say that because ldrd/strd are necessary to modify the LPAE page-tables atomically. What we need to know is which instructions can be allowed on MMIO accesses.
Definitely this is something that arm arm cannot fully answer as it is also down to the full platform. MMIO accesses are going out of the CPU and hence wether or not 64bit MMIO accesses can be properly done might also depend on the bus or the IP on the other side (some peripherals might just refuse 64bit accesses or some bus might only be 32bit so the operations would need to be divided).
Quoted 5 lines
I think I already raised that when Ayan added decoding for post-increment instructions. There are plenty of instructions (or combinations) that doesn't provide a syndrome and yet the processor doesn't prevent anyone to use them on MMIO.
I was worry we are going to have to continue to decode instructions in a non-compliant way in Xen just to please a few RTOs that may not even run anywhere else.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
This would also reduce our leverage to request a change in the RTOes or the Arm Arm (maybe there is already a statement I haven't spotted) because Xen will already (badly) support the instruction.
Going back on the
ID_ISAR2, if Xen is properly setting the value seen by the guests, there is not reason for us to actually emulate those instructions. The emulation code inside Xen cost a lot in matter of lines of code and would need a lot of testing (which is missing at the moment). So as we have a standard way to inform the guest that this is not supported, we should stick to that.Thanks for the feedback. AFAIU, the bit in
ID_ISAR2indicates whether ldrd/strd is present. If we decide to clear the bit, then it would mean the guest should not use them even when modifying LPAE page-tables.This could be a problem because AFAIK those instructions are necessary to modify the page-tables atomically. Therefore, I don't Xen should clear the bit.
Agree
Quoted 5 lines
Cheers,
Signature · 1 line
Julien Grall
Quoted 61 lines · Bertrand Marquis
Hi,
Quoted 44 lines · Julien Grall
Hi Stefano,
Quoted 21 lines · Stefano Stabellini
Quoted 14 lines · Ayan Kumar Halder
Hi Arm mantainers/Folks,
Please refer to the discussion
https://github.com/zephyrproject-rtos/zephyr/pull/51163 .We intend to run Zephyr as a domU guest on Xen on
Aarch32_v8Rfixed virtual platform.Zephyr is trying to read
GICR_TYPERwhich is a 64 bit register using ldrd instruction.As GICR is emulated by Xen, so this instruction gets trapped with HSR =
0x9200000c.Quoted 6 lines
As ISV is 0, so Xen cannot emulate this instruction.
The proposed solution is to use two
sys_read32()onGICR_TYPERto return the lower and upper 32 bits.With this, HSR =
0x9383000c, ISV=1 so ISS is valid.Quoted 8 lines
Hi all,
I wanted to take a step back on this issue before we jump into the details.
Differently from other instructions we discussed in the past, strd and ldrd are not deprecated and are not "unusual corner cases". There is no statements such as "please don't use this" on the ARM ARM. If I were to write an register read/write function in assembly for an RTOS, it would be reasonable to use them.Just to be clear it is fine to use the ldrd/strd for accessing non MMIO area. The problem comes with MMIO access because they can be emulated by the hypervisor and we don't have the syndrome. At the moment, this is only a problem when accessing some of the GICv3 (including ITS) registers.
Quoted 4 lines
So, I struggle to see how we'll be able to deal with all the possible RTOSes out there that might have them in the code. We can fix Zephyr, but what about FreeRTOS, ThreadX and the proprietary ones (VxWorks, etc.)?
This is not an Xen issue but architecture issue. The RTOSes will face the exact same issue on any hypervisors unless they decided to decode the instruction.
Quoted 7 lines
As we discussed before decoding an instruction correctly is quite difficult to do (what we have in Xen for pos-increment store/load is just a band-aid). So I would expect the other hypervisors to have made the decision to not implement it. AFAIK KVM doesn't suppor them, Note that looking at
ID_ISAR2, it seems that ldrd/strd is technically optional. Therefore, the RTOS would have to assume it is targeting a processor that supports them.Quoted 2 lines
Unless we can get ARM to issue a clear guidance that strd and ldrd are deprecated,
Arm Arm cannot say that because ldrd/strd are necessary to modify the LPAE page-tables atomically. What we need to know is which instructions can be allowed on MMIO accesses.
Definitely this is something that arm arm cannot fully answer as it is also down to the full platform. MMIO accesses are going out of the CPU and hence wether or not 64bit MMIO accesses can be properly done might also depend on the bus or the IP on the other side (some peripherals might just refuse 64bit accesses or some bus might only be 32bit so the operations would need to be divided).
Quoted 1 line
Quoted 7 lines
Quoted 5 lines
I think I already raised that when Ayan added decoding for post-increment instructions. There are plenty of instructions (or combinations) that doesn't provide a syndrome and yet the processor doesn't prevent anyone to use them on MMIO.
I was worry we are going to have to continue to decode instructions in a non-compliant way in Xen just to please a few RTOs that may not even run anywhere else.
This would also reduce our leverage to request a change in the RTOes or the Arm Arm (maybe there is already a statement I haven't spotted) because Xen will already (badly) support the instruction.
Going back on the
ID_ISAR2, if Xen is properly setting the value seen by the guests, there is not reason for us to actually emulate those instructions.
We need those instructions for page table access and it is mandatory to support that on armv8, so not the solution definitely.
Quoted 32 lines
The emulation code inside Xen cost a lot in matter of lines of code and would need a lot of testing (which is missing at the moment). So as we have a standard way to inform the guest that this is not supported, we should stick to that.
Quoted 5 lines
Quoted 4 lines
I think it would be better to attempt to decode them rather than just fail. I don't like to have this kind of code in Xen, but I don't see a way to support R52s without it.
That's not specific to R52. This is anyone using GICv3 on Arm32 core.
Agree.
Quoted 10 lines
Quoted 8 lines
That said, of course if Zephyr was to use two 32-bit reads instead of one 64-bit read, it would be better for Xen. And we have more important things to deal with right now in terms of R52 support (it is not even upstream yet). So it is totally fine to change Zephyr and move forward for now.
But medium term it doesn't seem to me that we can get away without a solution in Xen for this (or a change in the ARM ARM).See above. This is an architecture problem and we should discuss with Arm first before continuing to add more decoding in Xen.
I will discuss it internally to have an answer but I think that the answer cannot only come from Arm as there are for sure hardware implementations that cannot support this, as explain before.
Cheers
BertrandQuoted 5 lines
Cheers,
Signature · 1 line
Julien Grall
Hi,
Quoted 86 lines · Bertrand Marquis
Hi,
Quoted 44 lines · Julien Grall
Hi Stefano,
Quoted 21 lines · Stefano Stabellini
Quoted 14 lines · Ayan Kumar Halder
Hi Arm mantainers/Folks,
Please refer to the discussion
https://github.com/zephyrproject-rtos/zephyr/pull/51163 .We intend to run Zephyr as a domU guest on Xen on
Aarch32_v8Rfixed virtual platform.Zephyr is trying to read
GICR_TYPERwhich is a 64 bit register using ldrd instruction.As GICR is emulated by Xen, so this instruction gets trapped with HSR =
0x9200000c.Quoted 6 lines
As ISV is 0, so Xen cannot emulate this instruction.
The proposed solution is to use two
sys_read32()onGICR_TYPERto return the lower and upper 32 bits.With this, HSR =
0x9383000c, ISV=1 so ISS is valid.Quoted 8 lines
Hi all,
I wanted to take a step back on this issue before we jump into the details.
Differently from other instructions we discussed in the past, strd and ldrd are not deprecated and are not "unusual corner cases". There is no statements such as "please don't use this" on the ARM ARM. If I were to write an register read/write function in assembly for an RTOS, it would be reasonable to use them.Just to be clear it is fine to use the ldrd/strd for accessing non MMIO area. The problem comes with MMIO access because they can be emulated by the hypervisor and we don't have the syndrome. At the moment, this is only a problem when accessing some of the GICv3 (including ITS) registers.
Quoted 4 lines
So, I struggle to see how we'll be able to deal with all the possible RTOSes out there that might have them in the code. We can fix Zephyr, but what about FreeRTOS, ThreadX and the proprietary ones (VxWorks, etc.)?
This is not an Xen issue but architecture issue. The RTOSes will face the exact same issue on any hypervisors unless they decided to decode the instruction.
Quoted 7 lines
As we discussed before decoding an instruction correctly is quite difficult to do (what we have in Xen for pos-increment store/load is just a band-aid). So I would expect the other hypervisors to have made the decision to not implement it. AFAIK KVM doesn't suppor them, Note that looking at
ID_ISAR2, it seems that ldrd/strd is technically optional. Therefore, the RTOS would have to assume it is targeting a processor that supports them.Quoted 2 lines
Unless we can get ARM to issue a clear guidance that strd and ldrd are deprecated,
Arm Arm cannot say that because ldrd/strd are necessary to modify the LPAE page-tables atomically. What we need to know is which instructions can be allowed on MMIO accesses.
Definitely this is something that arm arm cannot fully answer as it is also down to the full platform. MMIO accesses are going out of the CPU and hence wether or not 64bit MMIO accesses can be properly done might also depend on the bus or the IP on the other side (some peripherals might just refuse 64bit accesses or some bus might only be 32bit so the operations would need to be divided).
Quoted 6 lines
I think I already raised that when Ayan added decoding for post-increment instructions. There are plenty of instructions (or combinations) that doesn't provide a syndrome and yet the processor doesn't prevent anyone to use them on MMIO.
I was worry we are going to have to continue to decode instructions in a non-compliant way in Xen just to please a few RTOs that may not even run anywhere else.
This would also reduce our leverage to request a change in the RTOes or the Arm Arm (maybe there is already a statement I haven't spotted) because Xen will already (badly) support the instruction.
Going back on the
ID_ISAR2, if Xen is properly setting the value seen by the guests, there is not reason for us to actually emulate those instructions. The emulation code inside Xen cost a lot in matter of lines of code and would need a lot of testing (which is missing at the moment). So as we have a standard way to inform the guest that this is not supported, we should stick to that.Quoted 5 lines
Quoted 4 lines
I think it would be better to attempt to decode them rather than just fail. I don't like to have this kind of code in Xen, but I don't see a way to support R52s without it.
That's not specific to R52. This is anyone using GICv3 on Arm32 core.
Agree.
Quoted 9 lines
Quoted 8 lines
That said, of course if Zephyr was to use two 32-bit reads instead of one 64-bit read, it would be better for Xen. And we have more important things to deal with right now in terms of R52 support (it is not even upstream yet). So it is totally fine to change Zephyr and move forward for now.
But medium term it doesn't seem to me that we can get away without a solution in Xen for this (or a change in the ARM ARM).
Quoted 3 lines
Quoted 1 line
See above. This is an architecture problem and we should discuss with Arm first before continuing to add more decoding in Xen.
I will discuss it internally to have an answer but I think that the answer cannot only come from Arm as there are for sure hardware implementations that cannot support this, as explain before.
I had some discussions internally and here is the official view:
From the architecture point of view this should always work but this is not virtualisable (as there is no syndrome register) and not recommended as deferencing a pointer accessing MMIO registers is not safe, so it should not be done for MMIO.
Linux is not doing those kind of accesses and KVM does not support guest doing them.
So I think we should not try to emulate this.
Cheers
Bertrand
Quoted 9 lines
Cheers
BertrandQuoted 5 lines
Cheers,
Signature · 1 line
Julien Grall
Quoted 84 lines · Bertrand Marquis
Quoted 80 lines · Bertrand Marquis
Quoted 41 lines · Julien Grall
Quoted 21 lines · Stefano Stabellini
Quoted 14 lines · Ayan Kumar Halder
Hi Arm mantainers/Folks,
Please refer to the discussion
https://github.com/zephyrproject-rtos/zephyr/pull/51163 .We intend to run Zephyr as a domU guest on Xen on
Aarch32_v8Rfixed virtual platform.Zephyr is trying to read
GICR_TYPERwhich is a 64 bit register using ldrd instruction.As GICR is emulated by Xen, so this instruction gets trapped with HSR =
0x9200000c.Quoted 6 lines
As ISV is 0, so Xen cannot emulate this instruction.
The proposed solution is to use two
sys_read32()onGICR_TYPERto return the lower and upper 32 bits.With this, HSR =
0x9383000c, ISV=1 so ISS is valid.Quoted 8 lines
Hi all,
I wanted to take a step back on this issue before we jump into the details.
Differently from other instructions we discussed in the past, strd and ldrd are not deprecated and are not "unusual corner cases". There is no statements such as "please don't use this" on the ARM ARM. If I were to write an register read/write function in assembly for an RTOS, it would be reasonable to use them.Just to be clear it is fine to use the ldrd/strd for accessing non MMIO area. The problem comes with MMIO access because they can be emulated by the hypervisor and we don't have the syndrome. At the moment, this is only a problem when accessing some of the GICv3 (including ITS) registers.
Quoted 4 lines
So, I struggle to see how we'll be able to deal with all the possible RTOSes out there that might have them in the code. We can fix Zephyr, but what about FreeRTOS, ThreadX and the proprietary ones (VxWorks, etc.)?
This is not an Xen issue but architecture issue. The RTOSes will face the exact same issue on any hypervisors unless they decided to decode the instruction.
Quoted 7 lines
As we discussed before decoding an instruction correctly is quite difficult to do (what we have in Xen for pos-increment store/load is just a band-aid). So I would expect the other hypervisors to have made the decision to not implement it. AFAIK KVM doesn't suppor them, Note that looking at
ID_ISAR2, it seems that ldrd/strd is technically optional. Therefore, the RTOS would have to assume it is targeting a processor that supports them.Quoted 2 lines
Unless we can get ARM to issue a clear guidance that strd and ldrd are deprecated,
Arm Arm cannot say that because ldrd/strd are necessary to modify the LPAE page-tables atomically. What we need to know is which instructions can be allowed on MMIO accesses.
Definitely this is something that arm arm cannot fully answer as it is also down to the full platform. MMIO accesses are going out of the CPU and hence wether or not 64bit MMIO accesses can be properly done might also depend on the bus or the IP on the other side (some peripherals might just refuse 64bit accesses or some bus might only be 32bit so the operations would need to be divided).
Quoted 6 lines
I think I already raised that when Ayan added decoding for post-increment instructions. There are plenty of instructions (or combinations) that doesn't provide a syndrome and yet the processor doesn't prevent anyone to use them on MMIO.
I was worry we are going to have to continue to decode instructions in a non-compliant way in Xen just to please a few RTOs that may not even run anywhere else.
This would also reduce our leverage to request a change in the RTOes or the Arm Arm (maybe there is already a statement I haven't spotted) because Xen will already (badly) support the instruction.
Going back on the
ID_ISAR2, if Xen is properly setting the value seen by the guests, there is not reason for us to actually emulate those instructions. The emulation code inside Xen cost a lot in matter of lines of code and would need a lot of testing (which is missing at the moment). So as we have a standard way to inform the guest that this is not supported, we should stick to that.Quoted 5 lines
Quoted 4 lines
I think it would be better to attempt to decode them rather than just fail. I don't like to have this kind of code in Xen, but I don't see a way to support R52s without it.
That's not specific to R52. This is anyone using GICv3 on Arm32 core.
Agree.
Quoted 9 lines
Quoted 8 lines
That said, of course if Zephyr was to use two 32-bit reads instead of one 64-bit read, it would be better for Xen. And we have more important things to deal with right now in terms of R52 support (it is not even upstream yet). So it is totally fine to change Zephyr and move forward for now.
But medium term it doesn't seem to me that we can get away without a solution in Xen for this (or a change in the ARM ARM).Quoted 3 lines
Quoted 1 line
See above. This is an architecture problem and we should discuss with Arm first before continuing to add more decoding in Xen.
I will discuss it internally to have an answer but I think that the answer cannot only come from Arm as there are for sure hardware implementations that cannot support this, as explain before.
Quoted 7 lines
I had some discussions internally and here is the official view:
Quoted 1 line
From the architecture point of view this should always work but this is not virtualisable (as there is no syndrome register) and not recommended as deferencing a pointer accessing MMIO registers is not safe, so it should not be done for MMIO.
Linux is not doing those kind of accesses and KVM does not support guest doing them.
So I think we should not try to emulate this.
I wouldn't take Linux and KVM as role models for the embedded space. Zephyr would be better (unfortunately Zephyr is not behaving as we prefer today).
At least at AMD/Xilinx, our users try something on native first, then they try it on Xen, and if it doesn't work they blame Xen. They don't typically try KVM and compare behavior. We try to explain that Xen is not necessarily to blame but this is the natural way of thinking for engineers apparently as it happened many times in the last few years for a range of issues with users in very different geographys/companies/projects.
I am writing the above just for context and to create a common understanding of Xen users' behavior and way of thinking. I don't think we can succeed in changing our users' way of thinking.
So generally my preference is to try to prevent a situation where a user might reach out to us in regard to something that used to work on native and doesn't anymore on Xen. It is always very difficult to explain in a way that is convincing to the user.
But honestly, we had zero reports of ldrd/strd causing a guest crash from users so far. So I think it is OK not to introduce code in the hypervisor to fix a "theoretical" bug. So one approach is to wait for the first real user report of the problem and then re-discuss the issue at that point in time (if it ever happens).
Documentation would help if we had it -- we don't have an official document anywhere stating that Xen as a project doesn't intend to support ltrd/strd on MMIO regions. That would help.
If we had such a document, it would be easier to explain the issue to users and they would more easily fix their RTOS if they can. There is also the possibility that they can't, because it is provided by third-parties. Like above, if it happens we can re-discuss it at that point in time.