qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Stefano Garzarella" <sgarzare@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"David Hildenbrand" <david@redhat.com>,
	"Raphael Norwitz" <raphael@enfabrica.net>,
	"Gerd Hoffmann" <kraxel@redhat.com>
Subject: [PULL v2 52/88] contrib/vhost-user-*: use QEMU bswap helper functions
Date: Tue, 2 Jul 2024 16:18:35 -0400	[thread overview]
Message-ID: <5ab04420c3de11ae4a573b08b53584a2a0c5dd00.1719951168.git.mst@redhat.com> (raw)
In-Reply-To: <cover.1719951168.git.mst@redhat.com>

From: Stefano Garzarella <sgarzare@redhat.com>

Let's replace the calls to le*toh() and htole*() with qemu/bswap.h
helpers to make the code more portable.

Suggested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Message-Id: <20240618100447.145697-1-sgarzare@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 contrib/vhost-user-blk/vhost-user-blk.c |  9 +++++----
 contrib/vhost-user-input/main.c         | 16 ++++++++--------
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-blk/vhost-user-blk.c
index a8ab9269a2..9492146855 100644
--- a/contrib/vhost-user-blk/vhost-user-blk.c
+++ b/contrib/vhost-user-blk/vhost-user-blk.c
@@ -16,6 +16,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/bswap.h"
 #include "standard-headers/linux/virtio_blk.h"
 #include "libvhost-user-glib.h"
 
@@ -194,8 +195,8 @@ vub_discard_write_zeroes(VubReq *req, struct iovec *iov, uint32_t iovcnt,
     #if defined(__linux__) && defined(BLKDISCARD) && defined(BLKZEROOUT)
     VubDev *vdev_blk = req->vdev_blk;
     desc = buf;
-    uint64_t range[2] = { le64toh(desc->sector) << 9,
-                          le32toh(desc->num_sectors) << 9 };
+    uint64_t range[2] = { le64_to_cpu(desc->sector) << 9,
+                          le32_to_cpu(desc->num_sectors) << 9 };
     if (type == VIRTIO_BLK_T_DISCARD) {
         if (ioctl(vdev_blk->blk_fd, BLKDISCARD, range) == 0) {
             g_free(buf);
@@ -267,13 +268,13 @@ static int vub_virtio_process_req(VubDev *vdev_blk,
     req->in = (struct virtio_blk_inhdr *)elem->in_sg[in_num - 1].iov_base;
     in_num--;
 
-    type = le32toh(req->out->type);
+    type = le32_to_cpu(req->out->type);
     switch (type & ~VIRTIO_BLK_T_BARRIER) {
     case VIRTIO_BLK_T_IN:
     case VIRTIO_BLK_T_OUT: {
         ssize_t ret = 0;
         bool is_write = type & VIRTIO_BLK_T_OUT;
-        req->sector_num = le64toh(req->out->sector);
+        req->sector_num = le64_to_cpu(req->out->sector);
         if (is_write) {
             ret  = vub_writev(req, &elem->out_sg[1], out_num);
         } else {
diff --git a/contrib/vhost-user-input/main.c b/contrib/vhost-user-input/main.c
index 081230da54..f3362d41ac 100644
--- a/contrib/vhost-user-input/main.c
+++ b/contrib/vhost-user-input/main.c
@@ -51,8 +51,8 @@ static void vi_input_send(VuInput *vi, struct virtio_input_event *event)
     vi->queue[vi->qindex++].event = *event;
 
     /* ... until we see a report sync ... */
-    if (event->type != htole16(EV_SYN) ||
-        event->code != htole16(SYN_REPORT)) {
+    if (event->type != cpu_to_le16(EV_SYN) ||
+        event->code != cpu_to_le16(SYN_REPORT)) {
         return;
     }
 
@@ -103,9 +103,9 @@ vi_evdev_watch(VuDev *dev, int condition, void *data)
 
         g_debug("input %d %d %d", evdev.type, evdev.code, evdev.value);
 
-        virtio.type  = htole16(evdev.type);
-        virtio.code  = htole16(evdev.code);
-        virtio.value = htole32(evdev.value);
+        virtio.type  = cpu_to_le16(evdev.type);
+        virtio.code  = cpu_to_le16(evdev.code);
+        virtio.value = cpu_to_le32(evdev.value);
         vi_input_send(vi, &virtio);
     }
 }
@@ -124,9 +124,9 @@ static void vi_handle_status(VuInput *vi, virtio_input_event *event)
 
     evdev.input_event_sec = tval.tv_sec;
     evdev.input_event_usec = tval.tv_usec;
-    evdev.type = le16toh(event->type);
-    evdev.code = le16toh(event->code);
-    evdev.value = le32toh(event->value);
+    evdev.type = le16_to_cpu(event->type);
+    evdev.code = le16_to_cpu(event->code);
+    evdev.value = le32_to_cpu(event->value);
 
     rc = write(vi->evdevfd, &evdev, sizeof(evdev));
     if (rc == -1) {
-- 
MST



  parent reply	other threads:[~2024-07-02 20:32 UTC|newest]

Thread overview: 100+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-02 20:15 [PULL v2 00/88] virtio: features,fixes Michael S. Tsirkin
2024-07-02 20:15 ` [PULL v2 01/88] vhost: dirty log should be per backend type Michael S. Tsirkin
2024-07-02 20:15 ` [PULL v2 02/88] vhost: Perform memory section dirty scans once per iteration Michael S. Tsirkin
2024-07-02 20:15 ` [PULL v2 03/88] vhost-vdpa: check vhost_vdpa_set_vring_ready() return value Michael S. Tsirkin
2024-07-02 20:15 ` [PULL v2 04/88] virtio/virtio-pci: Handle extra notification data Michael S. Tsirkin
2024-07-02 20:15 ` [PULL v2 05/88] virtio: Prevent creation of device using notification-data with ioeventfd Michael S. Tsirkin
2024-07-02 20:15 ` [PULL v2 06/88] virtio-mmio: Handle extra notification data Michael S. Tsirkin
2024-07-02 20:15 ` [PULL v2 07/88] virtio-ccw: " Michael S. Tsirkin
2024-07-02 20:15 ` [PULL v2 08/88] vhost/vhost-user: Add VIRTIO_F_NOTIFICATION_DATA to vhost feature bits Michael S. Tsirkin
2024-07-02 20:15 ` [PULL v2 09/88] Fix vhost user assertion when sending more than one fd Michael S. Tsirkin
2024-07-02 20:15 ` [PULL v2 10/88] vhost-vsock: add VIRTIO_F_RING_PACKED to feature_bits Michael S. Tsirkin
2024-07-02 20:15 ` [PULL v2 11/88] hw/virtio: Fix obtain the buffer id from the last descriptor Michael S. Tsirkin
2024-07-02 20:15 ` [PULL v2 12/88] virtio-pci: only reset pm state during resetting Michael S. Tsirkin
2024-07-02 20:15 ` [PULL v2 13/88] vhost-user-gpu: fix import of DMABUF Michael S. Tsirkin
2024-07-02 20:16 ` [PULL v2 14/88] Revert "vhost-user: fix lost reconnect" Michael S. Tsirkin
2024-07-02 20:16 ` [PULL v2 15/88] vhost-user: fix lost reconnect again Michael S. Tsirkin
2024-07-02 20:16 ` [PULL v2 16/88] hw/cxl/mailbox: change CCI cmd set structure to be a member, not a reference Michael S. Tsirkin
2024-07-02 20:16 ` [PULL v2 17/88] hw/cxl/mailbox: interface to add CCI commands to an existing CCI Michael S. Tsirkin
2024-07-02 20:16 ` [PULL v2 18/88] hw/cxl/cxl-mailbox-utils: Add dc_event_log_size field to output payload of identify memory device command Michael S. Tsirkin
2024-07-02 20:16 ` [PULL v2 19/88] hw/cxl/cxl-mailbox-utils: Add dynamic capacity region representative and mailbox command support Michael S. Tsirkin
2024-07-02 20:16 ` [PULL v2 20/88] include/hw/cxl/cxl_device: Rename mem_size as static_mem_size for type3 memory devices Michael S. Tsirkin
2024-07-02 20:16 ` [PULL v2 21/88] hw/mem/cxl_type3: Add support to create DC regions to " Michael S. Tsirkin
2024-07-02 20:16 ` [PULL v2 22/88] hw/mem/cxl-type3: Refactor ct3_build_cdat_entries_for_mr to take mr size instead of mr as argument Michael S. Tsirkin
2024-07-02 20:16 ` [PULL v2 23/88] hw/mem/cxl_type3: Add host backend and address space handling for DC regions Michael S. Tsirkin
2024-07-02 20:16 ` [PULL v2 24/88] hw/mem/cxl_type3: Add DC extent list representative and get DC extent list mailbox support Michael S. Tsirkin
2024-07-02 20:16 ` [PULL v2 25/88] hw/cxl/cxl-mailbox-utils: Add mailbox commands to support add/release dynamic capacity response Michael S. Tsirkin
2024-07-02 20:16 ` [PULL v2 26/88] hw/cxl/events: Add qmp interfaces to add/release dynamic capacity extents Michael S. Tsirkin
2024-07-02 20:16 ` [PULL v2 27/88] hw/mem/cxl_type3: Add DPA range validation for accesses to DC regions Michael S. Tsirkin
2024-07-02 20:16 ` [PULL v2 28/88] hw/cxl/cxl-mailbox-utils: Add superset extent release mailbox support Michael S. Tsirkin
2024-07-02 20:16 ` [PULL v2 29/88] hw/mem/cxl_type3: Allow to release extent superset in QMP interface Michael S. Tsirkin
2024-07-02 20:17 ` [PULL v2 30/88] linux-headers: update to 6.10-rc1 Michael S. Tsirkin
2024-07-02 20:17 ` [PULL v2 31/88] hw/misc/pvpanic: centralize definition of supported events Michael S. Tsirkin
2024-07-02 20:17 ` [PULL v2 32/88] tests/qtest/pvpanic: use centralized " Michael S. Tsirkin
2024-07-02 20:17 ` [PULL v2 33/88] hw/misc/pvpanic: add support for normal shutdowns Michael S. Tsirkin
2024-07-02 20:17 ` [PULL v2 34/88] pvpanic: Emit GUEST_PVSHUTDOWN QMP event on pvpanic shutdown signal Michael S. Tsirkin
2024-07-02 20:17 ` [PULL v2 35/88] tests/qtest/pvpanic: add tests for pvshutdown event Michael S. Tsirkin
2024-07-02 20:17 ` [PULL v2 36/88] Revert "docs/specs/pvpanic: mark shutdown event as not implemented" Michael S. Tsirkin
2024-07-02 20:17 ` [PULL v2 37/88] virtio-pci: Fix the failure process in kvm_virtio_pci_vector_use_one() Michael S. Tsirkin
2024-07-02 20:17 ` [PULL v2 38/88] hw/cxl: Fix read from bogus memory Michael S. Tsirkin
2024-07-02 20:17 ` [PULL v2 39/88] virtio-pci: implement No_Soft_Reset bit Michael S. Tsirkin
2024-07-02 20:17 ` [PULL v2 40/88] vhost-user-test: no set non-blocking for cal fd less than 0 Michael S. Tsirkin
2024-07-02 20:17 ` [PULL v2 41/88] i386/apic: Add hint on boot failure because of disabling x2APIC Michael S. Tsirkin
2024-07-02 20:17 ` [PULL v2 42/88] hw/virtio: Free vqs after vhost_dev_cleanup() Michael S. Tsirkin
2024-07-02 20:18 ` [PULL v2 43/88] virtio-iommu: add error check before assert Michael S. Tsirkin
2024-07-02 20:18 ` [PULL v2 44/88] vhost-user: Skip unnecessary duplicated VHOST_USER_SET_LOG_BASE requests Michael S. Tsirkin
2024-07-02 20:18 ` [PULL v2 45/88] hw/net/virtio-net.c: fix crash in iov_copy() Michael S. Tsirkin
2024-07-02 20:18 ` [PULL v2 46/88] qapi: clarify that the default is backend dependent Michael S. Tsirkin
2024-07-02 20:18 ` [PULL v2 47/88] libvhost-user: set msg.msg_control to NULL when it is empty Michael S. Tsirkin
2024-07-02 20:18 ` [PULL v2 48/88] libvhost-user: fail vu_message_write() if sendmsg() is failing Michael S. Tsirkin
2024-07-02 20:18 ` [PULL v2 49/88] libvhost-user: mask F_INFLIGHT_SHMFD if memfd is not supported Michael S. Tsirkin
2024-07-02 20:18 ` [PULL v2 50/88] vhost-user-server: do not set memory fd non-blocking Michael S. Tsirkin
2024-07-02 20:18 ` [PULL v2 51/88] contrib/vhost-user-blk: fix bind() using the right size of the address Michael S. Tsirkin
2024-07-02 20:18 ` Michael S. Tsirkin [this message]
2024-07-02 20:18 ` [PULL v2 53/88] vhost-user: enable frontends on any POSIX system Michael S. Tsirkin
2024-07-02 20:18 ` [PULL v2 54/88] libvhost-user: enable it " Michael S. Tsirkin
2024-07-02 20:18 ` [PULL v2 55/88] contrib/vhost-user-blk: " Michael S. Tsirkin
2024-07-02 20:18 ` [PULL v2 56/88] hostmem: add a new memory backend based on POSIX shm_open() Michael S. Tsirkin
2024-07-02 20:18 ` [PULL v2 57/88] tests/qtest/vhost-user-blk-test: use memory-backend-shm Michael S. Tsirkin
2024-07-02 20:19 ` [PULL v2 58/88] tests/qtest/vhost-user-test: add a test case for memory-backend-shm Michael S. Tsirkin
2024-07-02 20:19 ` [PULL v2 59/88] hw/virtio: Fix the de-initialization of vhost-user devices Michael S. Tsirkin
2024-07-02 20:19 ` [PULL v2 60/88] hw/arm/virt-acpi-build: Drop local iort_node_offset Michael S. Tsirkin
2024-07-02 20:19 ` [PULL v2 61/88] hw/i386/fw_cfg: Add etc/e820 to fw_cfg late Michael S. Tsirkin
2024-07-02 20:19 ` [PULL v2 62/88] hw/arm/virt-acpi-build: Fix id_count in build_iort_id_mapping Michael S. Tsirkin
2024-07-02 20:19 ` [PULL v2 63/88] uefi-test-tools/UefiTestToolsPkg: Add RISC-V support Michael S. Tsirkin
2024-07-02 20:19 ` [PULL v2 64/88] uefi-test-tools: Add support for python based build script Michael S. Tsirkin
2024-07-02 20:19 ` [PULL v2 65/88] tests/data/uefi-boot-images: Add RISC-V ISO image Michael S. Tsirkin
2024-07-02 20:19 ` [PULL v2 66/88] qtest: bios-tables-test: Rename aarch64 tests with aarch64 in them Michael S. Tsirkin
2024-07-02 20:19 ` [PULL v2 67/88] tests/qtest/bios-tables-test.c: Add support for arch in path Michael S. Tsirkin
2024-07-02 20:19 ` [PULL v2 68/88] tests/qtest/bios-tables-test.c: Set "arch" for aarch64 tests Michael S. Tsirkin
2024-07-02 20:19 ` [PULL v2 69/88] tests/qtest/bios-tables-test.c: Set "arch" for x86 tests Michael S. Tsirkin
2024-07-02 20:19 ` [PULL v2 70/88] tests/data/acpi: Move x86 ACPI tables under x86/${machine} path Michael S. Tsirkin
2024-07-02 20:19 ` [PULL v2 71/88] tests/data/acpi/virt: Move ARM64 ACPI tables under aarch64/${machine} path Michael S. Tsirkin
2024-07-02 20:19 ` [PULL v2 72/88] meson.build: Add RISC-V to the edk2-target list Michael S. Tsirkin
2024-07-02 20:20 ` [PULL v2 73/88] pc-bios/meson.build: Add support for RISC-V in unpack_edk2_blobs Michael S. Tsirkin
2024-07-02 20:20 ` [PULL v2 74/88] tests/data/acpi/rebuild-expected-aml.sh: Add RISC-V Michael S. Tsirkin
2024-07-02 20:20 ` [PULL v2 75/88] hw/cxl/events: Improve QMP interfaces and documentation for add/release dynamic capacity Michael S. Tsirkin
2024-07-02 20:20 ` [PULL v2 76/88] hw/cxl/events: Mark cxl-add-dynamic-capacity and cxl-release-dynamic-capcity unstable Michael S. Tsirkin
2024-07-02 20:20 ` [PULL v2 77/88] virtio: remove virtio_tswap16s() call in vring_packed_event_read() Michael S. Tsirkin
2024-07-02 20:20 ` [PULL v2 78/88] virtio-iommu: Clear IOMMUDevice when VFIO device is unplugged Michael S. Tsirkin
2024-07-02 20:20 ` [PULL v2 79/88] hw/pci: Rename has_power to enabled Michael S. Tsirkin
2024-07-02 20:20 ` [PULL v2 80/88] hw/ppc/spapr_pci: Do not create DT for disabled PCI device Michael S. Tsirkin
2024-07-02 20:20 ` [PULL v2 81/88] hw/ppc/spapr_pci: Do not reject VFs created after a PF Michael S. Tsirkin
2024-07-02 20:20 ` [PULL v2 82/88] pcie_sriov: Do not manually unrealize Michael S. Tsirkin
2024-07-02 20:20 ` [PULL v2 83/88] pcie_sriov: Ensure VF function number does not overflow Michael S. Tsirkin
2024-07-02 20:20 ` [PULL v2 84/88] pcie_sriov: Reuse SR-IOV VF device instances Michael S. Tsirkin
2024-07-02 20:20 ` [PULL v2 85/88] pcie_sriov: Release VFs failed to realize Michael S. Tsirkin
2024-07-02 20:20 ` [PULL v2 86/88] pcie_sriov: Remove num_vfs from PCIESriovPF Michael S. Tsirkin
2024-07-02 20:20 ` [PULL v2 87/88] pcie_sriov: Register VFs after migration Michael S. Tsirkin
2024-07-02 20:21 ` [PULL v2 88/88] hw/pci: Replace -1 with UINT32_MAX for romsize Michael S. Tsirkin
2024-07-03 16:31 ` [PULL v2 00/88] virtio: features,fixes Richard Henderson
2024-07-03 16:51   ` Michael S. Tsirkin
2024-07-03 17:01     ` Richard Henderson
2024-07-03 18:46       ` Thomas Huth
2024-07-03 19:45         ` Michael S. Tsirkin
2024-07-03 19:50           ` Michael S. Tsirkin
2024-07-04  5:51           ` Thomas Huth
2024-07-03 20:26         ` Michael S. Tsirkin
2024-07-03 22:37           ` Richard Henderson
2024-07-03 23:00             ` Michael S. Tsirkin
2024-07-04  5:48           ` Thomas Huth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5ab04420c3de11ae4a573b08b53584a2a0c5dd00.1719951168.git.mst@redhat.com \
    --to=mst@redhat.com \
    --cc=david@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=raphael@enfabrica.net \
    --cc=sgarzare@redhat.com \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).