xen/arm: vgic: Correctly emulate write when byte is used
PATCH 1/1 xen/arm: vgic: Correctly emulate write when byte is used
When a guest is writing a byte, the value will be located in bits[7:0] of the register.
Although the current implementation is expecting the byte at the Nth byte of the register where N = address & 4;
When the address is not 4-byte aligned, the corresponding byte in the internal state will always be set to zero rather.
Note that byte access are only used for GICD_IPRIORITYR and GICD_ITARGETSR. So the worst things that could happen is not setting the priority correctly and ignore the target vCPU written.
---
This patch is a candidate for Xen 4.6 and backport to Xen 4.5 and Xen 4.4. Without it, write a byte to a register won't work as expected.
Spotted while doing some test on the vGICv2 driver. FWIW, Linux doesn't use byte access in both GICv3 and GICv2 driver.
Note that Xen 4.4 will require a different patch because the function was living in vgic.c at that time.
--- xen/include/asm-arm/vgic.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xen/include/asm-arm/vgic.h +2 -2
@@ -174,10 +174,10 @@ static inline void vgic_byte_write(uint32_t *reg, uint32_t var, int offset) {int byte = offset &0x3 ; - var &= (0xff << (8 *byte)); + var &=0xff ; *reg &= ~(0xff << (8 *byte)); - *reg |= var; + *reg |= (var << (8 *byte)); }enum gic_sgi_mode ;
Signature · 1 line
2.1.4
Quoted 6 lines · Julien Grall
When a guest is writing a byte, the value will be located in bits[7:0] of the register.
Although the current implementation is expecting the byte at the Nth byte of the register where N = address & 4;
Quoted 9 lines
When the address is not 4-byte aligned, the corresponding byte in the internal state will always be set to zero rather.
Note that byte access are only used for
GICD_IPRIORITYRandGICD_ITARGETSR. So the worst things that could happen is not setting the priority correctly and ignore the target vCPU written.Signed-off-by Julien Grall <[email protected]>
Subject to an ack / review from ARM folks:
Quoted 33 lines
---
This patch is a candidate for Xen 4.6 and backport to Xen 4.5 and Xen 4.4. Without it, write a byte to a register won't work as expected.
Spotted while doing some test on the vGICv2 driver. FWIW, Linux doesn't use byte access in both GICv3 and GICv2 driver.
Note that Xen 4.4 will require a different patch because the function was living in
vgic.cat that time.--- xen/include/asm-arm/vgic.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)xen/include/asm-arm/vgic.h +2
-2@@ -174,10 +174,10 @@ static inline void vgic_byte_write(uint32_t *reg, uint32_t var, int offset) {int byte = offset &0x3 ; - var &= (0xff << (8 *byte)); + var &=0xff ; *reg &= ~(0xff << (8 *byte)); - *reg |= var; + *reg |= (var << (8 *byte)); }enum gic_sgi_mode ;Signature · 1 line
2.1.4
Quoted 15 lines · Wei Liu
Quoted 14 lines · Julien Grall
When a guest is writing a byte, the value will be located in bits[7:0] of the register.
Although the current implementation is expecting the byte at the Nth byte of the register where N = address & 4;
When the address is not 4-byte aligned, the corresponding byte in the internal state will always be set to zero rather.
Note that byte access are only used for
GICD_IPRIORITYRandGICD_ITARGETSR. So the worst things that could happen is not setting the
priority correctly and ignore the target vCPU written.
Quoted 6 lines
Quoted 2 lines
Signed-off-by Julien Grall <[email protected]>Subject to an ack / review from ARM folks:
Release-acked-by Wei Liu <[email protected]>
Acked + applied to staging and staging-4.6, noted for later backport to 4.5 and 4.4.