From patchwork Fri Feb 20 10:15:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 5854901 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9C6EF9F399 for ; Fri, 20 Feb 2015 10:15:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D0FA920328 for ; Fri, 20 Feb 2015 10:15:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F16C420340 for ; Fri, 20 Feb 2015 10:15:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754401AbbBTKPP (ORCPT ); Fri, 20 Feb 2015 05:15:15 -0500 Received: from e06smtp13.uk.ibm.com ([195.75.94.109]:35853 "EHLO e06smtp13.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753942AbbBTKPN (ORCPT ); Fri, 20 Feb 2015 05:15:13 -0500 Received: from /spool/local by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 20 Feb 2015 10:15:12 -0000 Received: from d06dlp03.portsmouth.uk.ibm.com (9.149.20.15) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 20 Feb 2015 10:15:10 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id C955D1B08067; Fri, 20 Feb 2015 10:15:22 +0000 (GMT) Received: from d06av01.portsmouth.uk.ibm.com (d06av01.portsmouth.uk.ibm.com [9.149.37.212]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t1KAF93Z64684214; Fri, 20 Feb 2015 10:15:09 GMT Received: from d06av01.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t1KAF8ER002085; Fri, 20 Feb 2015 03:15:09 -0700 Received: from smtp.lab.toulouse-stg.fr.ibm.com (srv01.lab.toulouse-stg.fr.ibm.com [9.101.4.1]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t1KAF7xC002062; Fri, 20 Feb 2015 03:15:07 -0700 Received: from bahia.local (sig-9-79-51-96.de.ibm.com [9.79.51.96]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id 8020A22043E; Fri, 20 Feb 2015 11:15:06 +0100 (CET) Subject: [PATCH 3/3] vhost_net: fix virtio_net header endianness From: Greg Kurz To: "Michael S. Tsirkin" Cc: Cedric Le Goater , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Date: Fri, 20 Feb 2015 11:15:05 +0100 Message-ID: <20150220101454.18608.64016.stgit@bahia.local> In-Reply-To: <20150220100724.18608.74654.stgit@bahia.local> References: <20150220100724.18608.74654.stgit@bahia.local> User-Agent: StGit/0.17-dirty MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15022010-0013-0000-0000-000003088A1B Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Without this patch, packets are being silently dropped by the tap backend. Signed-off-by: Greg Kurz --- drivers/vhost/net.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index afa06d2..2923eee 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -288,6 +288,16 @@ static void vhost_zerocopy_callback(struct ubuf_info *ubuf, bool success) rcu_read_unlock_bh(); } +static void fix_virtio_net_hdr(struct vhost_virtqueue *vq) +{ + struct virtio_net_hdr *hdr = vq->iov[0].iov_base; + + hdr->hdr_len = vhost16_to_cpu(vq, hdr->hdr_len); + hdr->gso_size = vhost16_to_cpu(vq, hdr->gso_size); + hdr->csum_start = vhost16_to_cpu(vq, hdr->csum_start); + hdr->csum_offset = vhost16_to_cpu(vq, hdr->csum_offset); +} + /* Expects to be always run from workqueue - which acts as * read-size critical section for our kind of RCU. */ static void handle_tx(struct vhost_net *net) @@ -352,6 +362,10 @@ static void handle_tx(struct vhost_net *net) "out %d, int %d\n", out, in); break; } + + if (!hdr_size) + fix_virtio_net_hdr(vq); + /* Skip header. TODO: support TSO. */ len = iov_length(vq->iov, out); iov_iter_init(&msg.msg_iter, WRITE, vq->iov, out, len); @@ -609,12 +623,18 @@ static void handle_rx(struct vhost_net *net) continue; } /* Supply virtio_net_hdr if VHOST_NET_F_VIRTIO_NET_HDR */ - if (unlikely(vhost_hlen) && - copy_to_iter(&hdr, sizeof(hdr), &fixup) != sizeof(hdr)) { - vq_err(vq, "Unable to write vnet_hdr at addr %p\n", - vq->iov->iov_base); - break; - } + if (unlikely(vhost_hlen)) { + size_t len = copy_to_iter(&hdr, sizeof(hdr), &fixup); + + if (len != sizeof(hdr)) { + vq_err(vq, + "Unable to write vnet_hdr at addr %p\n", + vq->iov->iov_base); + break; + } + } else + fix_virtio_net_hdr(vq); + /* TODO: Should check and handle checksum. */ num_buffers = cpu_to_vhost16(vq, headcount);