From patchwork Wed Jun 14 17:44:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Franciosi X-Patchwork-Id: 9788045 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 36D3360348 for ; Thu, 15 Jun 2017 04:49:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28FB528562 for ; Thu, 15 Jun 2017 04:49:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C9A428572; Thu, 15 Jun 2017 04:49:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7565828562 for ; Thu, 15 Jun 2017 04:49:39 +0000 (UTC) Received: from localhost ([::1]:51929 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLMiw-00013h-1I for patchwork-qemu-devel@patchwork.kernel.org; Thu, 15 Jun 2017 00:49:38 -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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 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. + * 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 indicated + with state.num set to 0 and big-endian is indicated with state.num set + to 1. Other values are invalid. + This request should be sent only when VHOST_USER_PROTOCOL_F_CROSS_ENDIAN + 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 ------------------- 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 = 3, VHOST_USER_PROTOCOL_F_NET_MTU = 4, VHOST_USER_PROTOCOL_F_SLAVE_REQ = 5, + VHOST_USER_PROTOCOL_F_CROSS_ENDIAN = 6, VHOST_USER_PROTOCOL_F_MAX }; @@ -63,6 +64,7 @@ typedef enum VhostUserRequest { VHOST_USER_NET_SET_MTU = 20, VHOST_USER_SET_SLAVE_REQ_FD = 21, VHOST_USER_IOTLB_MSG = 22, + VHOST_USER_SET_VRING_ENDIAN = 23, VHOST_USER_MAX } VhostUserRequest; @@ -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 = virtio_has_feature(dev->protocol_features, + VHOST_USER_PROTOCOL_F_CROSS_ENDIAN); + VhostUserMsg msg = { + .request = VHOST_USER_SET_VRING_ENDIAN, + .flags = VHOST_USER_VERSION, + .payload.state = *ring, + .size = 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; } static int vhost_set_vring(struct vhost_dev *dev,