git: 07b5d1ca52b1 - main - virtio_pci_modern: Remove endianness conversion for config space

From: Michael Tuexen <tuexen_at_FreeBSD.org>
Date: Sun, 28 Jun 2026 10:46:13 UTC
The branch main has been updated by tuexen:

URL: https://cgit.FreeBSD.org/src/commit/?id=07b5d1ca52b113cecad3cda73ff5e782d8f4d07d

commit 07b5d1ca52b113cecad3cda73ff5e782d8f4d07d
Author:     Timo Völker <timo.voelker@fh-muenster.de>
AuthorDate: 2026-06-28 10:39:10 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2026-06-28 10:39:10 +0000

    virtio_pci_modern: Remove endianness conversion for config space
    
    The bus_* functions already handle converting from PCI endianness
    (i.e. little-endian) to native endianness when accessing the config
    space (see ofw_pcib_bus_get_bus_tag), so converting again with
    virtio_htogX/virtio_gtohX undoes any byte-swapping and breaks
    big-endian systems. They should only be used for operating on shared
    memory.
    Note part of this reverts commit fb53b42e36a9 ("virtio-modern: fix PCI
    common read/write functions on big endian targets").
    
    PR:                     294706
    Reviewed by:            adrian, tuexen
    Fixes:                  fb53b42e36a9 ("virtio-modern: fix PCI common read/write functions on big endian targets")
    Fixes:                  9da9560c4dd3 ("virtio: Add VirtIO PCI modern (V1) support")
    MFC after:              1 week
    Differential Revision:  https://reviews.freebsd.org/D57392
---
 sys/dev/virtio/pci/virtio_pci_modern.c | 27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)

diff --git a/sys/dev/virtio/pci/virtio_pci_modern.c b/sys/dev/virtio/pci/virtio_pci_modern.c
index baf7c448bb95..bdd9cacd505e 100644
--- a/sys/dev/virtio/pci/virtio_pci_modern.c
+++ b/sys/dev/virtio/pci/virtio_pci_modern.c
@@ -665,16 +665,13 @@ vtpci_modern_read_dev_config(device_t dev, bus_size_t offset, void *dst,
 		*(uint8_t *) dst = vtpci_modern_read_device_1(sc, offset);
 		break;
 	case 2:
-		*(uint16_t *) dst = virtio_htog16(true,
-		    vtpci_modern_read_device_2(sc, offset));
+		*(uint16_t *) dst = vtpci_modern_read_device_2(sc, offset);
 		break;
 	case 4:
-		*(uint32_t *) dst = virtio_htog32(true,
-		    vtpci_modern_read_device_4(sc, offset));
+		*(uint32_t *) dst = vtpci_modern_read_device_4(sc, offset);
 		break;
 	case 8:
-		*(uint64_t *) dst = virtio_htog64(true,
-		    vtpci_modern_read_device_8(sc, offset));
+		*(uint64_t *) dst = vtpci_modern_read_device_8(sc, offset);
 		break;
 	default:
 		panic("%s: device %s invalid device read length %d offset %d",
@@ -700,17 +697,17 @@ vtpci_modern_write_dev_config(device_t dev, bus_size_t offset, const void *src,
 		vtpci_modern_write_device_1(sc, offset, *(const uint8_t *) src);
 		break;
 	case 2: {
-		uint16_t val = virtio_gtoh16(true, *(const uint16_t *) src);
+		uint16_t val = *(const uint16_t *) src;
 		vtpci_modern_write_device_2(sc, offset, val);
 		break;
 	}
 	case 4: {
-		uint32_t val = virtio_gtoh32(true, *(const uint32_t *) src);
+		uint32_t val = *(const uint32_t *) src;
 		vtpci_modern_write_device_4(sc, offset, val);
 		break;
 	}
 	case 8: {
-		uint64_t val = virtio_gtoh64(true, *(const uint64_t *) src);
+		uint64_t val = *(const uint64_t *) src;
 		vtpci_modern_write_device_8(sc, offset, val);
 		break;
 	}
@@ -1312,15 +1309,13 @@ vtpci_modern_read_common_1(struct vtpci_modern_softc *sc, bus_size_t off)
 static uint16_t
 vtpci_modern_read_common_2(struct vtpci_modern_softc *sc, bus_size_t off)
 {
-	return virtio_htog16(true,
-			bus_read_2(&sc->vtpci_common_res_map.vtrm_map, off));
+	return bus_read_2(&sc->vtpci_common_res_map.vtrm_map, off);
 }
 
 static uint32_t
 vtpci_modern_read_common_4(struct vtpci_modern_softc *sc, bus_size_t off)
 {
-	return virtio_htog32(true,
-			bus_read_4(&sc->vtpci_common_res_map.vtrm_map, off));
+	return bus_read_4(&sc->vtpci_common_res_map.vtrm_map, off);
 }
 
 static void
@@ -1334,16 +1329,14 @@ static void
 vtpci_modern_write_common_2(struct vtpci_modern_softc *sc, bus_size_t off,
     uint16_t val)
 {
-	bus_write_2(&sc->vtpci_common_res_map.vtrm_map,
-			off, virtio_gtoh16(true, val));
+	bus_write_2(&sc->vtpci_common_res_map.vtrm_map, off, val);
 }
 
 static void
 vtpci_modern_write_common_4(struct vtpci_modern_softc *sc, bus_size_t off,
     uint32_t val)
 {
-	bus_write_4(&sc->vtpci_common_res_map.vtrm_map,
-			off, virtio_gtoh32(true, val));
+	bus_write_4(&sc->vtpci_common_res_map.vtrm_map, off, val);
 }
 
 static void