From patchwork Mon Nov 12 07:19:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 198322 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6B9022C0082 for ; Mon, 12 Nov 2012 18:16:58 +1100 (EST) Received: from localhost ([::1]:46491 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TXoGN-0003Jp-KS for incoming@patchwork.ozlabs.org; Mon, 12 Nov 2012 02:16:55 -0500 Received: from eggs.gnu.org ([208.118.235.92]:35365) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TXoGE-0003Ja-A4 for qemu-devel@nongnu.org; Mon, 12 Nov 2012 02:16:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TXoGB-0003Tv-7x for qemu-devel@nongnu.org; Mon, 12 Nov 2012 02:16:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:61094) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TXoGA-0003Tf-WA for qemu-devel@nongnu.org; Mon, 12 Nov 2012 02:16:43 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qAC7Ge4x009366 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 12 Nov 2012 02:16:41 -0500 Received: from redhat.com (vpn1-4-218.ams2.redhat.com [10.36.4.218]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id qAC7GcbG029667; Mon, 12 Nov 2012 02:16:39 -0500 Date: Mon, 12 Nov 2012 09:19:18 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org, agraf@suse.de Message-ID: <20121112071918.GA31752@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Anthony Liguori , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH] tap: reset vnet header size on open X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org For tap, we currently assume the vnet header size is 10 (the default value) but that might not be the case if tap is persistent and has been used by qemu previously. To fix, set vnet header size correctly on open. Signed-off-by: Michael S. Tsirkin --- This fixes the issue reported by Alexander Graf on the kvm forum. Alexander, could you confirm please? Thanks, net/tap-linux.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/net/tap-linux.c b/net/tap-linux.c index c6521be..3eaedc4 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -39,6 +39,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required { struct ifreq ifr; int fd, ret; + int len = sizeof(struct virtio_net_hdr); TFR(fd = open(PATH_NET_TUN, O_RDWR)); if (fd < 0) { @@ -65,6 +66,13 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required close(fd); return -1; } + /* + * Make sure vnet header size has the default value: for a persistent + * tap it might have been modified e.g. by another instance of qemu. + * Ignore errors since old kernels do not support this ioctl: in this + * case the header size implicitly has the correct value. + */ + ioctl(fd, TUNSETVNETHDRSZ, &len); } if (ifname[0] != '\0')