From nobody Thu Nov 6 06:47:58 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1497502194210684.6026804256632; Wed, 14 Jun 2017 21:49:54 -0700 (PDT) Received: from localhost ([::1]:51931 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLMj9-0001TG-QN for importer@patchew.org; Thu, 15 Jun 2017 00:49:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56480) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLMiB-00013P-DB for qemu-devel@nongnu.org; Thu, 15 Jun 2017 00:48:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dLMi8-0002CU-Av for qemu-devel@nongnu.org; Thu, 15 Jun 2017 00:48:51 -0400 Received: from cpc92310-cmbg19-2-0-cust421.5-4.cable.virginm.net ([82.9.225.166]:49956 helo=centos.localdomain) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLMi8-0002B3-2z for qemu-devel@nongnu.org; Thu, 15 Jun 2017 00:48:48 -0400 Received: by centos.localdomain (Postfix, from userid 500) id 561D49FE45; Wed, 14 Jun 2017 18:44:41 +0100 (BST) From: Felipe Franciosi To: Marc-Andre Lureau , "Michael S. Tsirkin" , Paolo Bonzini Date: Wed, 14 Jun 2017 18:44:38 +0100 Message-Id: <1497462278-15961-1-git-send-email-felipe@nutanix.com> X-Mailer: git-send-email 1.9.5 X-detected-operating-system: by eggs.gnu.org: Mac OS X [generic] [fuzzy] X-Received-From: 82.9.225.166 Subject: [Qemu-devel] [PATCH v2] vhost-user: support cross-endianess negatiation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mike Cui , qemu-devel@nongnu.org, Felipe Franciosi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Currently, vhost-user does not implement any means for notifying the backend about guest endianess. This commit introduces a new message called VHOST_USER_SET_VRING_ENDIAN which is analogous to the ioctl() called VHOST_SET_VRING_ENDIAN used for kernel vhost backends. Such message is necessary for backends supporting legacy (pre-1.0) virtio devices running in big-endian guests. Signed-off-by: Felipe Franciosi Signed-off-by: Mike Cui --- v1->v2: * Elaborated message usage on the documentation. * Fixed Id typo (22->23) on the documentation. docs/specs/vhost-user.txt | 16 ++++++++++++++++ hw/virtio/vhost-user.c | 23 +++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/docs/specs/vhost-user.txt b/docs/specs/vhost-user.txt index 481ab56..954771d 100644 --- a/docs/specs/vhost-user.txt +++ b/docs/specs/vhost-user.txt @@ -326,6 +326,7 @@ Protocol features #define VHOST_USER_PROTOCOL_F_REPLY_ACK 3 #define VHOST_USER_PROTOCOL_F_MTU 4 #define VHOST_USER_PROTOCOL_F_SLAVE_REQ 5 +#define VHOST_USER_PROTOCOL_F_CROSS_ENDIAN 6 =20 Master message types -------------------- @@ -580,6 +581,21 @@ Master message types This request should be send only when VIRTIO_F_IOMMU_PLATFORM feature has been successfully negotiated. =20 + * VHOST_USER_SET_VRING_ENDIAN + + Id: 23 + Equivalent ioctl: VHOST_SET_VRING_ENDIAN + Master payload: vring state description + + Set the endianess of a VQ for legacy devices. Little-endian is indic= ated + with state.num set to 0 and big-endian is indicated with state.num s= et + to 1. Other values are invalid. + This request should be sent only when VHOST_USER_PROTOCOL_F_CROSS_EN= DIAN + has been negotiated. + Backends that negotiated this feature should handle both endianesses + and expect this message once (per VQ) during device configuration + (ie. before the master starts the VQ). + Slave message types ------------------- =20 diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 958ee09..006af1c 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -33,6 +33,7 @@ enum VhostUserProtocolFeature { VHOST_USER_PROTOCOL_F_REPLY_ACK =3D 3, VHOST_USER_PROTOCOL_F_NET_MTU =3D 4, VHOST_USER_PROTOCOL_F_SLAVE_REQ =3D 5, + VHOST_USER_PROTOCOL_F_CROSS_ENDIAN =3D 6, =20 VHOST_USER_PROTOCOL_F_MAX }; @@ -63,6 +64,7 @@ typedef enum VhostUserRequest { VHOST_USER_NET_SET_MTU =3D 20, VHOST_USER_SET_SLAVE_REQ_FD =3D 21, VHOST_USER_IOTLB_MSG =3D 22, + VHOST_USER_SET_VRING_ENDIAN =3D 23, VHOST_USER_MAX } VhostUserRequest; =20 @@ -367,8 +369,25 @@ static int vhost_user_set_vring_addr(struct vhost_dev = *dev, static int vhost_user_set_vring_endian(struct vhost_dev *dev, struct vhost_vring_state *ring) { - error_report("vhost-user trying to send unhandled ioctl"); - return -1; + bool cross_endian =3D virtio_has_feature(dev->protocol_features, + VHOST_USER_PROTOCOL_F_CROSS_END= IAN); + VhostUserMsg msg =3D { + .request =3D VHOST_USER_SET_VRING_ENDIAN, + .flags =3D VHOST_USER_VERSION, + .payload.state =3D *ring, + .size =3D sizeof(msg.payload.state), + }; + + if (!cross_endian) { + error_report("vhost-user trying to send unhandled ioctl"); + return -1; + } + + if (vhost_user_write(dev, &msg, NULL, 0) < 0) { + return -1; + } + + return 0; } =20 static int vhost_set_vring(struct vhost_dev *dev, --=20 1.9.5