From nobody Wed Sep 18 23:35:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1716892680; cv=none; d=zohomail.com; s=zohoarc; b=VgMBmM29SX81mA7iCmz0bpBT3frGL3VykaOHvY6m6hGIzKbr+apPmNRFvtSF4TE/yfKiNiUa5Zo3MBdhx1//f/IcazeMWsHMUw6KqK9L8hFqE8Gpn02hAFI0TVklbIeCbAzgWP1g+7pQImNZGTDm1jKrxRqNGaWSn3QF4ahBsLs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716892680; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=e7uQF4Gi0pZ6bwyXQv9cyLYqbc38Kf+gnOBq39sMLzc=; b=P0HwHE5VwcQ7m+yg5yLFWBqZA1FHfteT4Rx1xyQW4eR0JXd6384K2ktk6xH8onfae4H0/ojYa4oqTjDcqFAQgnhzIQ5F4O8ET7xPgX4j0+wwiEywYC6c3jp4vqhcKrK7jdzIbJM9DIydDhaEnzBVnI5w52cIJo8VDKJfL8fOlx0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1716892679999436.4417043715042; Tue, 28 May 2024 03:37:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBuBw-0004Ss-5k; Tue, 28 May 2024 06:36:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sBuBs-0004Px-DI for qemu-devel@nongnu.org; Tue, 28 May 2024 06:36:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sBuBq-0008F5-NX for qemu-devel@nongnu.org; Tue, 28 May 2024 06:36:24 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-508-sfcix_OQMvyYS04tUludeA-1; Tue, 28 May 2024 06:36:20 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4211211e18cso3266475e9.3 for ; Tue, 28 May 2024 03:36:20 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42100fad638sm170283785e9.29.2024.05.28.03.36.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 03:36:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716892582; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=e7uQF4Gi0pZ6bwyXQv9cyLYqbc38Kf+gnOBq39sMLzc=; b=gfvx1msfygBzUOmeKcJGXZvp4cGBNDPUJ6G1LJXvfSMQqvT70ViT7lcgzkXfGAFYA7Ga1Y 2rvr66JE7utDgMWA0oUFfAXgwvIN04WFx8a9/iZPDVfO287DBY7/E1KK7SsSon4wHkJzAi 13wANqPnJ5FEnRK42OIZo2XDTUzuBic= X-MC-Unique: sfcix_OQMvyYS04tUludeA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716892576; x=1717497376; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=e7uQF4Gi0pZ6bwyXQv9cyLYqbc38Kf+gnOBq39sMLzc=; b=mkHNdfle9cvY/H94PZy01ZhPfKR3d9Q4+Rbo+teoeGck0aA8se/b8g9kKCG2usuNQN X7xXjKT0tjh7NQJFhnvHKY5WmSPuw/oJNCYHaD83Edew2PsRfdj2B2h2alOypQUq7vO6 39FrTp6MNbFOMBuRp4Qql/pZzB9KRABRZ0Al/UHdssS/ek3i7jDSYzq/ts830rh6A2ls sTKWtM33KIwOUwxaZzV8n56Wk2uCR9y8xdwhSEKTnZG+EZ1csxS9Y//K7YLhrIzc2CM3 zLXSoO9xKTWnL2KQPSAMLOoABfYT1gRre8EFuDe5b+uL/gDkYb0L7zDg67Tooq8OsKJj /4uA== X-Gm-Message-State: AOJu0Yy+SJzLNJ2UWOUcVA0CDsAoUuwe3U2skGpPiVnjlhiOqZI2rVfe XS8QrOhou+ukhOIFlmGYPnE48wTPMOFzZheG7z2r0ENaSZvnnX4tgIQa4YZocnfacTIeRnSt2ju 1a7+vnqDXYkQGpNcdihP2/9e8lMxvoDP8ZqLCjohkq4+WY8swGW+yJBpv4IgZynQXWYcHUOh+Fq sVOrW1cr7UTBRx1qZ2akENNAW3/wHTJuPCOljF X-Received: by 2002:a05:600c:2948:b0:41f:ec3e:9797 with SMTP id 5b1f17b1804b1-421089de607mr105969355e9.16.1716892576015; Tue, 28 May 2024 03:36:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGIxOxzA8eL9YpWF+7ehAGvkh3xRIaVcT9fg19M67elzzhEy+5NF+4HBuR6WsYqq00Etmm/Tw== X-Received: by 2002:a05:600c:2948:b0:41f:ec3e:9797 with SMTP id 5b1f17b1804b1-421089de607mr105968945e9.16.1716892575649; Tue, 28 May 2024 03:36:15 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: slp@redhat.com, David Hildenbrand , Paolo Bonzini , Eduardo Habkost , Igor Mammedov , Brad Smith , gmaglione@redhat.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , Kevin Wolf , Jason Wang , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Coiby Xu , qemu-block@nongnu.org, Hanna Reitz , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Raphael Norwitz , Thomas Huth , stefanha@redhat.com, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Gerd Hoffmann , Stefano Garzarella Subject: [PATCH v6 06/12] contrib/vhost-user-*: use QEMU bswap helper functions Date: Tue, 28 May 2024 12:35:37 +0200 Message-ID: <20240528103543.145412-7-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240528103543.145412-1-sgarzare@redhat.com> References: <20240528103543.145412-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.034, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1716892680228100001 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=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Stefan Hajnoczi Reviewed-by: David Hildenbrand Signed-off-by: Stefano Garzarella --- 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-b= lk/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 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/bswap.h" #include "standard-headers/linux/virtio_blk.h" #include "libvhost-user-glib.h" =20 @@ -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 =3D req->vdev_blk; desc =3D buf; - uint64_t range[2] =3D { le64toh(desc->sector) << 9, - le32toh(desc->num_sectors) << 9 }; + uint64_t range[2] =3D { le64_to_cpu(desc->sector) << 9, + le32_to_cpu(desc->num_sectors) << 9 }; if (type =3D=3D VIRTIO_BLK_T_DISCARD) { if (ioctl(vdev_blk->blk_fd, BLKDISCARD, range) =3D=3D 0) { g_free(buf); @@ -267,13 +268,13 @@ static int vub_virtio_process_req(VubDev *vdev_blk, req->in =3D (struct virtio_blk_inhdr *)elem->in_sg[in_num - 1].iov_bas= e; in_num--; =20 - type =3D le32toh(req->out->type); + type =3D 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 =3D 0; bool is_write =3D type & VIRTIO_BLK_T_OUT; - req->sector_num =3D le64toh(req->out->sector); + req->sector_num =3D le64_to_cpu(req->out->sector); if (is_write) { ret =3D vub_writev(req, &elem->out_sg[1], out_num); } else { diff --git a/contrib/vhost-user-input/main.c b/contrib/vhost-user-input/mai= n.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_inpu= t_event *event) vi->queue[vi->qindex++].event =3D *event; =20 /* ... until we see a report sync ... */ - if (event->type !=3D htole16(EV_SYN) || - event->code !=3D htole16(SYN_REPORT)) { + if (event->type !=3D cpu_to_le16(EV_SYN) || + event->code !=3D cpu_to_le16(SYN_REPORT)) { return; } =20 @@ -103,9 +103,9 @@ vi_evdev_watch(VuDev *dev, int condition, void *data) =20 g_debug("input %d %d %d", evdev.type, evdev.code, evdev.value); =20 - virtio.type =3D htole16(evdev.type); - virtio.code =3D htole16(evdev.code); - virtio.value =3D htole32(evdev.value); + virtio.type =3D cpu_to_le16(evdev.type); + virtio.code =3D cpu_to_le16(evdev.code); + virtio.value =3D 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) =20 evdev.input_event_sec =3D tval.tv_sec; evdev.input_event_usec =3D tval.tv_usec; - evdev.type =3D le16toh(event->type); - evdev.code =3D le16toh(event->code); - evdev.value =3D le32toh(event->value); + evdev.type =3D le16_to_cpu(event->type); + evdev.code =3D le16_to_cpu(event->code); + evdev.value =3D le32_to_cpu(event->value); =20 rc =3D write(vi->evdevfd, &evdev, sizeof(evdev)); if (rc =3D=3D -1) { --=20 2.45.1