On 9/7/26 20:35, Miao Wang via B4 Relay wrote:
From: Miao Wang <[email protected]>
This patch improves the implementation of the pvscsi device by
translating the endianness of the data sent or received from the guest.
This ensures pvscsi can work on big-endian hosts with little-endian
guests.
This patch assumes, although not having found any specifications, that
the pvscsi device is little-endian, since pvscsi seems to be used only
on x86 platforms, which are little-endian.
Signed-off-by: Miao Wang <[email protected]>
---
Changes in v2:
- Assume pvscsi is little-endian instead of native-endian, and thus
replace tswap*() with le*_to_cpu() and cpu_to_le*() to convert the
endianness of pvscsi data structures to/from CPU endianness.
- Link to v1:
https://lore.kernel.org/qemu-devel/[email protected]
---
hw/scsi/vmw_pvscsi.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 56 insertions(+), 1 deletion(-)
diff --git a/hw/scsi/vmw_pvscsi.c b/hw/scsi/vmw_pvscsi.c
index
11ae6b9b7474b9bc87621137eb7911361b5fd721..e6befe9be2c49d1dc04e6e6384f9d24f7a6a4273
100644
--- a/hw/scsi/vmw_pvscsi.c
+++ b/hw/scsi/vmw_pvscsi.c
@@ -392,9 +392,18 @@ static void
pvscsi_cmp_ring_put(PVSCSIState *s, struct PVSCSIRingCmpDesc *cmp_desc)
{
hwaddr cmp_descr_pa;
+ struct PVSCSIRingCmpDesc cmp_desc_conv;
Nitpicking, s/struct// as PVSCSIRingCmpDesc is already type
defined.
If you ever respin, please add a comment in hw/scsi/vmw_pvscsi.h
clarifying the choosen endianness; but can be done later, so:
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Thanks!
cmp_descr_pa = pvscsi_ring_pop_cmp_descr(&s->rings);
trace_pvscsi_cmp_ring_put(cmp_descr_pa);
+ cmp_desc_conv = (struct PVSCSIRingCmpDesc) {
+ .context = cpu_to_le64(cmp_desc->context),
+ .dataLen = cpu_to_le64(cmp_desc->dataLen),
+ .senseLen = cpu_to_le32(cmp_desc->senseLen),
+ .hostStatus = cpu_to_le16(cmp_desc->hostStatus),
+ .scsiStatus = cpu_to_le16(cmp_desc->scsiStatus),
+ };
+ cmp_desc = &cmp_desc_conv;
cpu_physical_memory_write(cmp_descr_pa, cmp_desc, sizeof(*cmp_desc));
}