GIC DEVICE_LITTLE_ENDIAN clean-ups and potential bug fix
cover GIC DEVICE_LITTLE_ENDIAN clean-ups and potential bug fix
Following on from my RFC on Monday I have split the DEVICE_LITTLE_ENDIAN changes apart from the corner case bug fix as well as updating the other GIC regions.
Alex.
Alex Bennée (4):
hw/intc: declare NVIC regions as little endian hw/intc: declare GIC regions as little endian hw/intc: declare GICv3 regions as little endian hw/intc: avoid byte swap fiddling in gicv3 its path
hw/intc/arm_gic.c | 12 ++++++------ hw/intc/arm_gicv3.c | 4 ++-- hw/intc/arm_gicv3_its.c | 4 ++-- hw/intc/arm_gicv3_its_common.c | 4 ++-- hw/intc/arm_gicv3_its_kvm.c | 2 +- hw/intc/armv7m_nvic.c | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-)
Signature · 1 line
2.47.3
PATCH 1/4 hw/intc: declare NVIC regions as little endian
The NVIC should always be a little-endian device as big-endian behaviour is a function of the current CPU configuration not the system as a whole. Indeed the Armv8-M architecture reference manual declares:
All accesses to the Private Peripheral Bus (PPB) are always little-endian, which means that the PE assumes a little-endian arrangement of the PPB registers.
This should have no functional effect as the NVIC cannot be instantiated on a BE system but will help the single binary efforts.
--- hw/intc/armv7m_nvic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/intc/armv7m_nvic.c +1 -1
@@ -2467,7 +2467,7 @@ static MemTxResult nvic_sysreg_write(void *opaque, hwaddr addr,static const MemoryRegionOps nvic_sysreg_ops = { .read_with_attrs = nvic_sysreg_read, .write_with_attrs = nvic_sysreg_write, - .endianness =DEVICE_NATIVE_ENDIAN , + .endianness =DEVICE_LITTLE_ENDIAN , };static int nvic_post_load (void *opaque,int version_id)
Signature · 1 line
2.47.3
Re: [PATCH 1/4] hw/intc: declare NVIC regions as little endian
Quoted 10 lines · Alex Bennée
The NVIC should always be a little-endian device as big-endian behaviour is a function of the current CPU configuration not the system as a whole. Indeed the Armv8-M architecture reference manual declares:
All accesses to the Private Peripheral Bus (PPB) are always little-endian, which means that the PE assumes a little-endian arrangement of the PPB registers.
Quoted 7 lines
This should have no functional effect as the NVIC cannot be instantiated on a BE system but will help the single binary efforts.
Signed-off-by Alex Bennée <[email protected]>--- hw/intc/armv7m_nvic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
thanks
-- PMM
Re: [PATCH 1/4] hw/intc: declare NVIC regions as little endian
In reply to Alex BennéeQuoted 9 lines · Alex Bennée
The NVIC should always be a little-endian device as big-endian behaviour is a function of the current CPU configuration not the system as a whole. Indeed the Armv8-M architecture reference manual declares:
All accesses to the Private Peripheral Bus (PPB) are always little-endian, which means that the PE assumes a little-endian arrangement of the PPB registers.
Quoted 7 lines
This should have no functional effect as the NVIC cannot be instantiated on a BE system but will help the single binary efforts.
Signed-off-by Alex Bennée <[email protected]>--- hw/intc/armv7m_nvic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH 2/4 hw/intc: declare GIC regions as little endian
In reply to Alex BennéeThe GIC should always be a little-endian device as big-endian behaviour is a function of the current CPU configuration not the system as a whole. This should have no functional effect as the GIC cannot be instantiated on a BE system but will help the single binary efforts.
--- hw/intc/arm_gic.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
hw/intc/arm_gic.c +6 -6
@@ -2062,38 +2062,38 @@ static const MemoryRegionOps gic_ops[2] = { { .read_with_attrs = gic_dist_read, .write_with_attrs = gic_dist_write, - .endianness = DEVICE_NATIVE_ENDIAN, + .endianness = DEVICE_LITTLE_ENDIAN, }, { .read_with_attrs = gic_thiscpu_read, .write_with_attrs = gic_thiscpu_write, - .endianness = DEVICE_NATIVE_ENDIAN, + .endianness = DEVICE_LITTLE_ENDIAN, } };static const MemoryRegionOps gic_cpu_ops = { .read_with_attrs = gic_do_cpu_read, .write_with_attrs = gic_do_cpu_write, - .endianness =DEVICE_NATIVE_ENDIAN , + .endianness =DEVICE_LITTLE_ENDIAN , };static const MemoryRegionOps gic_virt_ops[2 ] = { { .read_with_attrs = gic_thiscpu_hyp_read, .write_with_attrs = gic_thiscpu_hyp_write, - .endianness =DEVICE_NATIVE_ENDIAN , + .endianness =DEVICE_LITTLE_ENDIAN , }, { .read_with_attrs = gic_thisvcpu_read, .write_with_attrs = gic_thisvcpu_write, - .endianness =DEVICE_NATIVE_ENDIAN , + .endianness =DEVICE_LITTLE_ENDIAN , } };static const MemoryRegionOps gic_viface_ops = { .read_with_attrs = gic_do_hyp_read, .write_with_attrs = gic_do_hyp_write, - .endianness =DEVICE_NATIVE_ENDIAN , + .endianness =DEVICE_LITTLE_ENDIAN , };static void arm_gic_realize (DeviceState *dev,Error **errp)
Signature · 1 line
2.47.3
Re: [PATCH 2/4] hw/intc: declare GIC regions as little endian
Quoted 11 lines · Alex Bennée
The GIC should always be a little-endian device as big-endian behaviour is a function of the current CPU configuration not the system as a whole. This should have no functional effect as the GIC cannot be instantiated on a BE system but will help the single binary efforts.
Signed-off-by Alex Bennée <[email protected]>--- hw/intc/arm_gic.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
thanks
-- PMM
Re: [PATCH 2/4] hw/intc: declare GIC regions as little endian
In reply to Alex BennéeQuoted 10 lines · Alex Bennée
The GIC should always be a little-endian device as big-endian behaviour is a function of the current CPU configuration not the system as a whole. This should have no functional effect as the GIC cannot be instantiated on a BE system but will help the single binary efforts.
Signed-off-by Alex Bennée <[email protected]>--- hw/intc/arm_gic.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
PATCH 3/4 hw/intc: declare GICv3 regions as little endian
In reply to Alex BennéeThe GIC should always be a little-endian device as big-endian behaviour is a function of the current CPU configuration not the system as a whole. This should have no functional effect as the GIC cannot be instantiated on a BE system but will help the single binary efforts.
--- hw/intc/arm_gicv3.c | 4 ++-- hw/intc/arm_gicv3_its.c | 4 ++-- hw/intc/arm_gicv3_its_common.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
hw/intc/arm_gicv3.c +2 -2
@@ -417,7 +417,7 @@ static const MemoryRegionOps gic_ops[] = { { .read_with_attrs = gicv3_dist_read, .write_with_attrs = gicv3_dist_write, - .endianness = DEVICE_NATIVE_ENDIAN, + .endianness = DEVICE_LITTLE_ENDIAN, .valid.min_access_size = 1, .valid.max_access_size = 8, .impl.min_access_size = 1,
@@ -426,7 +426,7 @@ static const MemoryRegionOps gic_ops[] = { { .read_with_attrs = gicv3_redist_read, .write_with_attrs = gicv3_redist_write, - .endianness = DEVICE_NATIVE_ENDIAN, + .endianness = DEVICE_LITTLE_ENDIAN, .valid.min_access_size = 1, .valid.max_access_size = 8, .impl.min_access_size = 1,
hw/intc/arm_gicv3_its.c +2 -2
@@ -1906,7 +1906,7 @@ static const MemoryRegionOps gicv3_its_control_ops = { .valid.max_access_size = 8, .impl.min_access_size = 4, .impl.max_access_size = 8, - .endianness = DEVICE_NATIVE_ENDIAN, + .endianness = DEVICE_LITTLE_ENDIAN, };static const MemoryRegionOps gicv3_its_translation_ops = {
@@ -1916,7 +1916,7 @@ static const MemoryRegionOps gicv3_its_translation_ops = { .valid.max_access_size = 4, .impl.min_access_size = 2, .impl.max_access_size = 4, - .endianness = DEVICE_NATIVE_ENDIAN, + .endianness = DEVICE_LITTLE_ENDIAN, };static void gicv3_arm_its_realize (DeviceState *dev,Error **errp)
hw/intc/arm_gicv3_its_common.c +1 -1
@@ -97,7 +97,7 @@ static MemTxResult gicv3_its_trans_write(void *opaque, hwaddr offset,static const MemoryRegionOps gicv3_its_trans_ops = { .read_with_attrs = gicv3_its_trans_read, .write_with_attrs = gicv3_its_trans_write, - .endianness =DEVICE_NATIVE_ENDIAN , + .endianness =DEVICE_LITTLE_ENDIAN , }; void gicv3_its_init_mmio(GICv3ITSState *s, const MemoryRegionOps *ops,
Signature · 1 line
2.47.3
Re: [PATCH 3/4] hw/intc: declare GICv3 regions as little endian
Quoted 7 lines · Alex Bennée
The GIC should always be a little-endian device as big-endian behaviour is a function of the current CPU configuration not the system as a whole. This should have no functional effect as the GIC cannot be instantiated on a BE system but will help the single binary efforts.
Quoted 7 lines
Signed-off-by Alex Bennée <[email protected]>--- hw/intc/arm_gicv3.c | 4 ++-- hw/intc/arm_gicv3_its.c | 4 ++-- hw/intc/arm_gicv3_its_common.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
thanks
-- PMM
Re: [PATCH 3/4] hw/intc: declare GICv3 regions as little endian
In reply to Alex BennéeQuoted 6 lines · Alex Bennée
The GIC should always be a little-endian device as big-endian behaviour is a function of the current CPU configuration not the system as a whole. This should have no functional effect as the GIC cannot be instantiated on a BE system but will help the single binary efforts.
Quoted 6 lines
Signed-off-by Alex Bennée <[email protected]>--- hw/intc/arm_gicv3.c | 4 ++-- hw/intc/arm_gicv3_its.c | 4 ++-- hw/intc/arm_gicv3_its_common.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
PATCH 4/4 hw/intc: avoid byte swap fiddling in gicv3 its path
In reply to Alex BennéeThis allows us to keep the MSI data in plain host order all the way from the MemoryRegionOps write method to the final KVM_SIGNAL_MSI ioctl. This fixes a theoretical bug on big-endian hosts because we were using different size byte swaps which would have truncated the data.
---
v2
- split from DEVICE_LITTLE_ENDIAN changes
- expanded the commit message
- cc stable
--- hw/intc/arm_gicv3_its_common.c | 2 +- hw/intc/arm_gicv3_its_kvm.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
hw/intc/arm_gicv3_its_common.c +1 -1
@@ -81,7 +81,7 @@ static MemTxResult gicv3_its_trans_write(void *opaque, hwaddr offset,if (offset ==0x0040 && ((size ==2 ) || (size ==4 ))) {GICv3ITSState *s =ARM_GICV3_ITS_COMMON (opaque);GICv3ITSCommonClass *c =ARM_GICV3_ITS_COMMON_GET_CLASS (s); -int ret = c->send_msi (s,le64_to_cpu (value), attrs.requester_id); +int ret = c->send_msi (s, value, attrs.requester_id);if (ret <=0 ) { qemu_log_mask(LOG_GUEST_ERROR,
hw/intc/arm_gicv3_its_kvm.c +1 -1
@@ -58,7 +58,7 @@ static int kvm_its_send_msi(GICv3ITSState *s, uint32_t value, uint16_t devid) msi.address_lo =extract64 (s->gits_translater_gpa,0 ,32 ); msi.address_hi =extract64 (s->gits_translater_gpa,32 ,32 ); - msi.data =le32_to_cpu (value); + msi.data = value; msi.flags =KVM_MSI_VALID_DEVID ; msi.devid = devid;memset (msi.pad,0 ,sizeof (msi.pad));
Signature · 1 line
2.47.3
Re: [PATCH 4/4] hw/intc: avoid byte swap fiddling in gicv3 its path
Quoted 10 lines · Alex Bennée
This allows us to keep the MSI data in plain host order all the way from the MemoryRegionOps write method to the final
KVM_SIGNAL_MSIioctl. This fixes a theoretical bug on big-endian hosts because we were using different size byte swaps which would have truncated the data.Signed-off-by Alex Bennée <[email protected]>---
thanks
-- PMM
Peter Maydell
AppliedQuoted 5 lines · Alex Bennée
Following on from my RFC on Monday I have split the
DEVICE_LITTLE_ENDIANchanges apart from the corner case bug fix as well as updating the other GIC regions.
Quoted 7 lines
Alex.
Alex Bennée (4):
hw/intc: declare NVIC regions as little endian hw/intc: declare GIC regions as little endian hw/intc: declare GICv3 regions as little endian hw/intc: avoid byte swap fiddling in gicv3 its path
Applied to target-arm.next, thanks.
-- PMM