From patchwork Tue Apr 25 14:39:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 9698313 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 2D18D6020A for ; Tue, 25 Apr 2017 14:37:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 108B128484 for ; Tue, 25 Apr 2017 14:37:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 04F432857D; Tue, 25 Apr 2017 14:37:51 +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 vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A80E28484 for ; Tue, 25 Apr 2017 14:37:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1948215AbdDYOhq (ORCPT ); Tue, 25 Apr 2017 10:37:46 -0400 Received: from foss.arm.com ([217.140.101.70]:42110 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1948154AbdDYOhc (ORCPT ); Tue, 25 Apr 2017 10:37:32 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E6E79169F; Tue, 25 Apr 2017 07:37:31 -0700 (PDT) Received: from e104803-lin.lan (unknown [10.1.207.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9FF393F220; Tue, 25 Apr 2017 07:37:30 -0700 (PDT) From: Andre Przywara To: Will Deacon , Marc Zyngier Cc: Jean-Philippe Brucker , kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [kvmtool PATCH v10 05/15] virtio: fix endianness check for vhost support Date: Tue, 25 Apr 2017 15:39:22 +0100 Message-Id: <20170425143932.17235-6-andre.przywara@arm.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170425143932.17235-1-andre.przywara@arm.com> References: <20170425143932.17235-1-andre.przywara@arm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently we deny any VHOST_* functionality if the architecture supports guests with different endianness than the host. Most of the time even on those architectures the endianness of guest and host are the same, though, so we are denying the glory of VHOST needlessly. Switch from compile time determination to a run time scheme, which takes the actual endianness of the guest into account. For this we change the semantics of VIRTIO_ENDIAN_HOST to return the actual endianness of the host (the endianness of kvmtool at compile time, really). The actual check in vhost_net now compares this against the guest endianness. This enables vhost support on ARM and ARM64. Signed-off-by: Andre Przywara --- include/kvm/virtio.h | 9 +++++++-- virtio/net.c | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/kvm/virtio.h b/include/kvm/virtio.h index 8324ba7..00a791a 100644 --- a/include/kvm/virtio.h +++ b/include/kvm/virtio.h @@ -17,10 +17,15 @@ #define VIRTIO_PCI_O_CONFIG 0 #define VIRTIO_PCI_O_MSIX 1 -#define VIRTIO_ENDIAN_HOST 0 #define VIRTIO_ENDIAN_LE (1 << 0) #define VIRTIO_ENDIAN_BE (1 << 1) +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#define VIRTIO_ENDIAN_HOST VIRTIO_ENDIAN_LE +#else +#define VIRTIO_ENDIAN_HOST VIRTIO_ENDIAN_BE +#endif + struct virt_queue { struct vring vring; u32 pfn; @@ -40,7 +45,7 @@ struct virt_queue { #define VIRTIO_RING_ENDIAN VIRTIO_ENDIAN_HOST #endif -#if (VIRTIO_RING_ENDIAN & (VIRTIO_ENDIAN_LE | VIRTIO_ENDIAN_BE)) +#if VIRTIO_RING_ENDIAN != VIRTIO_ENDIAN_HOST static inline __u16 __virtio_g2h_u16(u16 endian, __u16 val) { diff --git a/virtio/net.c b/virtio/net.c index ffa83ab..9fb9f1e 100644 --- a/virtio/net.c +++ b/virtio/net.c @@ -530,7 +530,7 @@ static int init_vq(struct kvm *kvm, void *dev, u32 vq, u32 page_size, u32 align, } if (queue->endian != VIRTIO_ENDIAN_HOST) - die_perror("VHOST requires VIRTIO_ENDIAN_HOST"); + die_perror("VHOST requires the same endianness in guest and host"); state.num = queue->vring.num; r = ioctl(ndev->vhost_fd, VHOST_SET_VRING_NUM, &state);