From patchwork Fri Feb 5 10:30:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincenzo Maffione X-Patchwork-Id: 8233351 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 601B3BEEE5 for ; Fri, 5 Feb 2016 10:32:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 915482039C for ; Fri, 5 Feb 2016 10:32:09 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 77B7020397 for ; Fri, 5 Feb 2016 10:32:08 +0000 (UTC) Received: from localhost ([::1]:47352 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRdgN-0003cX-QC for patchwork-qemu-devel@patchwork.kernel.org; Fri, 05 Feb 2016 05:32:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39349) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRdgE-0003cC-Hy for qemu-devel@nongnu.org; Fri, 05 Feb 2016 05:31:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aRdgA-0005km-Ro for qemu-devel@nongnu.org; Fri, 05 Feb 2016 05:31:57 -0500 Received: from mail-wm0-x233.google.com ([2a00:1450:400c:c09::233]:38015) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRdgA-0005ip-HU for qemu-devel@nongnu.org; Fri, 05 Feb 2016 05:31:54 -0500 Received: by mail-wm0-x233.google.com with SMTP id p63so20607956wmp.1 for ; Fri, 05 Feb 2016 02:31:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=51gmoo+93XLGbkKIeXo5oEDD4/iTQvtS5/g0nU25JpM=; b=AIn7hsE14rF8v1cpRJ6d1uf0oDeLazxFl0HnQ9f7nOITcwzCyafPNi8gauL49vFAID VnDlomI6VyYMotcD6tGlUedUj2FpsbB1ZYduMpfMHuRUazxEt5e0s761nFe9EQvFJl5v 2BkyA7AZ1UlchRfltpXhssPndXkJmcnZ4yMF92Zew0xV6wFmhFaQkxSkejjAbGpuD4qU MBT67wHXe5Aby8FRgiMjtrFWFvevXuIobWOq6rqxRW20eGEoesQgohxvU7w4EdqNDpxU +bYzq7GSOCV3B3/YOp1+UoHavfvatpC9GoTF21DBo9KbcSjrWSxTAPx+CNIj8rlDA/uf 1wKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=51gmoo+93XLGbkKIeXo5oEDD4/iTQvtS5/g0nU25JpM=; b=aRJuOMk1R7X6K8yClfN/6QAv86+vnamE1ngA0+6z8m55EyXaQUVGoT7YCsP/zKDg86 31sgX+CSz6Up07dNM829aImZLv3OOInOmhU27Sda0ZyhFJg6mZzQ+82A81gAc55lssEG FHp6YZ/lL06muWZxKgCR2hctG0xburi7GmAbsmMvuSCd+9Qz+IluTasY7MzzxIlvQ28h 6/Gx415ej4DQGg5bYGfWypTfE/Xdh2Y0GyNr4GJ9BajJheY/YjzhD76f0fAGlaGVSF+b IZRtCk8TM+gN6Blm1NtCKHbSg2AGBghCBE2J/ytTYTR5HEcbD6a8V/Tto+BjPsDBK8RC ncEA== X-Gm-Message-State: AG10YOQgvaddnYovqA0qUDns9O9kB9FAsSunW48BTWYMszZbn/CEKmCvmDj4YMvNfg6y8A== X-Received: by 10.28.22.201 with SMTP id 192mr16703206wmw.1.1454668311822; Fri, 05 Feb 2016 02:31:51 -0800 (PST) Received: from localhost.localdomain (prova.iet.unipi.it. [131.114.58.86]) by smtp.gmail.com with ESMTPSA id c7sm15721918wmd.13.2016.02.05.02.31.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 05 Feb 2016 02:31:51 -0800 (PST) From: Vincenzo Maffione To: qemu-devel@nongnu.org Date: Fri, 5 Feb 2016 11:30:03 +0100 Message-Id: <47884767b4d9df94dc2660d1aef7b6124e6d701f.1454667697.git.v.maffione@gmail.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::233 Cc: jasowang@redhat.com, rizzo@iet.unipi.it, g.lettieri@iet.unipi.it, Vincenzo Maffione Subject: [Qemu-devel] [PATCH] net: netmap: probe netmap interface for virtio-net header 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham 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 Previous implementation of has_ufo, has_vnet_hdr, has_vnet_hdr_len, etc. did not really probe for virtio-net header support for the netmap interface attached to the backend. These callbacks were correct for VALE ports, but incorrect for hardware NICs, pipes, monitors, etc. This patch fixes the implementation to work properly with all kinds of netmap ports. Signed-off-by: Vincenzo Maffione --- net/netmap.c | 70 ++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/net/netmap.c b/net/netmap.c index 9710321..f2dcaeb 100644 --- a/net/netmap.c +++ b/net/netmap.c @@ -323,20 +323,55 @@ static void netmap_cleanup(NetClientState *nc) } /* Offloading manipulation support callbacks. */ -static bool netmap_has_ufo(NetClientState *nc) +static int netmap_do_set_vnet_hdr_len(NetmapState *s, int len, bool err_report) { - return true; + struct nmreq req; + int err; + + /* Issue a NETMAP_BDG_VNET_HDR command to change the virtio-net header + * length for the netmap adapter associated to 's->ifname'. + */ + memset(&req, 0, sizeof(req)); + pstrcpy(req.nr_name, sizeof(req.nr_name), s->ifname); + req.nr_version = NETMAP_API; + req.nr_cmd = NETMAP_BDG_VNET_HDR; + req.nr_arg1 = len; + err = ioctl(s->nmd->fd, NIOCREGIF, &req); + if (err) { + if (err_report) { + error_report("Unable to execute NETMAP_BDG_VNET_HDR on %s: %s", + s->ifname, strerror(errno)); + } + return -1; + } + + /* Keep track of the current length. */ + s->vnet_hdr_len = len; + + return 0; } -static bool netmap_has_vnet_hdr(NetClientState *nc) +static bool netmap_has_vnet_hdr_len(NetClientState *nc, int len) { + NetmapState *s = DO_UPCAST(NetmapState, nc, nc); + int prev_len = s->vnet_hdr_len; + + /* Check that we can set the new length. */ + if (netmap_do_set_vnet_hdr_len(s, len, false)) { + return false; + } + + /* Restore the previous length. */ + netmap_do_set_vnet_hdr_len(s, prev_len, true); + return true; } -static bool netmap_has_vnet_hdr_len(NetClientState *nc, int len) +/* A netmap interface that supports virtio-net headers always + * supports UFO, so we use this callback also for the has_ufo hook. */ +static bool netmap_has_vnet_hdr(NetClientState *nc) { - return len == 0 || len == sizeof(struct virtio_net_hdr) || - len == sizeof(struct virtio_net_hdr_mrg_rxbuf); + return netmap_has_vnet_hdr_len(nc, sizeof(struct virtio_net_hdr)); } static void netmap_using_vnet_hdr(NetClientState *nc, bool enable) @@ -346,25 +381,8 @@ static void netmap_using_vnet_hdr(NetClientState *nc, bool enable) static void netmap_set_vnet_hdr_len(NetClientState *nc, int len) { NetmapState *s = DO_UPCAST(NetmapState, nc, nc); - int err; - struct nmreq req; - /* Issue a NETMAP_BDG_VNET_HDR command to change the virtio-net header - * length for the netmap adapter associated to 's->ifname'. - */ - memset(&req, 0, sizeof(req)); - pstrcpy(req.nr_name, sizeof(req.nr_name), s->ifname); - req.nr_version = NETMAP_API; - req.nr_cmd = NETMAP_BDG_VNET_HDR; - req.nr_arg1 = len; - err = ioctl(s->nmd->fd, NIOCREGIF, &req); - if (err) { - error_report("Unable to execute NETMAP_BDG_VNET_HDR on %s: %s", - s->ifname, strerror(errno)); - } else { - /* Keep track of the current length. */ - s->vnet_hdr_len = len; - } + netmap_do_set_vnet_hdr_len(s, len, true); } static void netmap_set_offload(NetClientState *nc, int csum, int tso4, int tso6, @@ -376,7 +394,7 @@ static void netmap_set_offload(NetClientState *nc, int csum, int tso4, int tso6, * enables the offloadings. */ if (!s->vnet_hdr_len) { - netmap_set_vnet_hdr_len(nc, sizeof(struct virtio_net_hdr)); + netmap_do_set_vnet_hdr_len(s, sizeof(struct virtio_net_hdr), true); } } @@ -388,7 +406,7 @@ static NetClientInfo net_netmap_info = { .receive_iov = netmap_receive_iov, .poll = netmap_poll, .cleanup = netmap_cleanup, - .has_ufo = netmap_has_ufo, + .has_ufo = netmap_has_vnet_hdr, .has_vnet_hdr = netmap_has_vnet_hdr, .has_vnet_hdr_len = netmap_has_vnet_hdr_len, .using_vnet_hdr = netmap_using_vnet_hdr,