From patchwork Mon Jul 23 14:36:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Toshiaki Makita X-Patchwork-Id: 947805 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="U2aXyEZs"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41Z3w83795z9s4Z for ; Tue, 24 Jul 2018 00:36:40 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388490AbeGWPiK (ORCPT ); Mon, 23 Jul 2018 11:38:10 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:40142 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387877AbeGWPiK (ORCPT ); Mon, 23 Jul 2018 11:38:10 -0400 Received: by mail-pg1-f194.google.com with SMTP id x5-v6so531270pgp.7 for ; Mon, 23 Jul 2018 07:36:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=m2ICIg96s9kuKwbBqDXYmTCJ2WfaaUNvd1/n8E6L6BE=; b=U2aXyEZsd+g7Gzgt/vtDOwYw14NCtUqzW+xtAFABZRSjSV7SNjIOA49VuULQ0tGEyV 1y4kwL27/q+Igt2aA1M/yjg4qA+fILIP6ovEwm+8Ls95xguwYmOexMyNX7CLWbdj/dHF 16YGWXlmZjAqS3kflLQx1Ydh7YVSsMO7ZDJcV4LJSPTfKnbV8KBlzIbB39k+AbR4Ti05 xgumwlqf2q4/Ce6st6h9jYVh3XWIh6icFq8WvULB3ie5OfB/bNFXK2EKiyXHIyRVjQEC Ue0vMcpsYbh3elN2kJ1xo6gdes7EBaxPtkIZ6HvG6X3I8E2FNUVD1ofHlz3GxS7CLmar nU6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=m2ICIg96s9kuKwbBqDXYmTCJ2WfaaUNvd1/n8E6L6BE=; b=bowCXA36WB2xcJkS5fDsV5jikrhdujcyJiRxgAigPNlp4Sm4BC1IRC44kVWRXfGObh rttocKkQWPt839+Bf/GyBPMDnQ2UJS5lJ1Zf5zcuhUs8JfUdXeZSAor3GqiUtMXhy4VA KtjEU11DYQtUKhAlpV7jd7HwmnFvxcPns0zlVQWHGuojcCq24hfmkt61Dde+IoynG9Xp sKxrJbuG84TwP+QjiMP5fkyYs5uErVoeooEcZIwg9eTrqe/6n4pWQw3n7ubpOYLDWc6k kWrmaOOmjzajrLmcgMDNAKG45D/sOgDqIewRVxMM1nehF8pyVe/ylNlc2y10/NlgRGOd FHYg== X-Gm-Message-State: AOUpUlEfJfXT/F8DV9lpc8Ly2t+Io90BKPACCGIhwuqlsS4CdmSRH2La xBzopjCrrfl5htmUEa5CuYdKwmXY X-Google-Smtp-Source: AAOMgpd35Ojb4DfKB/h2o/Hye8pTgULFfq1nKgS70RjrKUNqNL6o80PTTWAZ25uqjLDb6m3z8udz1g== X-Received: by 2002:a63:fc0a:: with SMTP id j10-v6mr12448165pgi.1.1532356597068; Mon, 23 Jul 2018 07:36:37 -0700 (PDT) Received: from localhost.localdomain (i153-145-22-9.s42.a013.ap.plala.or.jp. [153.145.22.9]) by smtp.gmail.com with ESMTPSA id 65-v6sm14415503pfq.81.2018.07.23.07.36.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Jul 2018 07:36:36 -0700 (PDT) From: Toshiaki Makita To: "Michael S. Tsirkin" , Jason Wang , "David S. Miller" Cc: Toshiaki Makita , netdev@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH net-next 1/6] virtio_net: Fix incosistent received bytes counter Date: Mon, 23 Jul 2018 23:36:04 +0900 Message-Id: <20180723143609.2242-2-toshiaki.makita1@gmail.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180723143609.2242-1-toshiaki.makita1@gmail.com> References: <20180723143609.2242-1-toshiaki.makita1@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Toshiaki Makita When received packets are dropped in virtio_net driver, received packets counter is incremented but bytes counter is not. As a result, for instance if we drop all packets by XDP, only received is counted and bytes stays 0, which looks inconsistent. IMHO received packets/bytes should be counted if packets are produced by the hypervisor, like what common NICs on physical machines are doing. So fix the bytes counter. Signed-off-by: Toshiaki Makita --- drivers/net/virtio_net.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 2ff08bc103a9..abbd3bc83b62 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -586,7 +586,8 @@ static struct sk_buff *receive_small(struct net_device *dev, struct receive_queue *rq, void *buf, void *ctx, unsigned int len, - unsigned int *xdp_xmit) + unsigned int *xdp_xmit, + unsigned int *rbytes) { struct sk_buff *skb; struct bpf_prog *xdp_prog; @@ -601,6 +602,7 @@ static struct sk_buff *receive_small(struct net_device *dev, int err; len -= vi->hdr_len; + *rbytes += len; rcu_read_lock(); xdp_prog = rcu_dereference(rq->xdp_prog); @@ -705,11 +707,13 @@ static struct sk_buff *receive_big(struct net_device *dev, struct virtnet_info *vi, struct receive_queue *rq, void *buf, - unsigned int len) + unsigned int len, + unsigned int *rbytes) { struct page *page = buf; struct sk_buff *skb = page_to_skb(vi, rq, page, 0, len, PAGE_SIZE); + *rbytes += len - vi->hdr_len; if (unlikely(!skb)) goto err; @@ -727,7 +731,8 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, void *buf, void *ctx, unsigned int len, - unsigned int *xdp_xmit) + unsigned int *xdp_xmit, + unsigned int *rbytes) { struct virtio_net_hdr_mrg_rxbuf *hdr = buf; u16 num_buf = virtio16_to_cpu(vi->vdev, hdr->num_buffers); @@ -740,6 +745,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, int err; head_skb = NULL; + *rbytes += len - vi->hdr_len; rcu_read_lock(); xdp_prog = rcu_dereference(rq->xdp_prog); @@ -877,6 +883,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, goto err_buf; } + *rbytes += len; page = virt_to_head_page(buf); truesize = mergeable_ctx_to_truesize(ctx); @@ -932,6 +939,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, dev->stats.rx_length_errors++; break; } + *rbytes += len; page = virt_to_head_page(buf); put_page(page); } @@ -942,14 +950,13 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, return NULL; } -static int receive_buf(struct virtnet_info *vi, struct receive_queue *rq, - void *buf, unsigned int len, void **ctx, - unsigned int *xdp_xmit) +static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq, + void *buf, unsigned int len, void **ctx, + unsigned int *xdp_xmit, unsigned int *rbytes) { struct net_device *dev = vi->dev; struct sk_buff *skb; struct virtio_net_hdr_mrg_rxbuf *hdr; - int ret; if (unlikely(len < vi->hdr_len + ETH_HLEN)) { pr_debug("%s: short packet %i\n", dev->name, len); @@ -961,23 +968,22 @@ static int receive_buf(struct virtnet_info *vi, struct receive_queue *rq, } else { put_page(virt_to_head_page(buf)); } - return 0; + return; } if (vi->mergeable_rx_bufs) - skb = receive_mergeable(dev, vi, rq, buf, ctx, len, xdp_xmit); + skb = receive_mergeable(dev, vi, rq, buf, ctx, len, xdp_xmit, + rbytes); else if (vi->big_packets) - skb = receive_big(dev, vi, rq, buf, len); + skb = receive_big(dev, vi, rq, buf, len, rbytes); else - skb = receive_small(dev, vi, rq, buf, ctx, len, xdp_xmit); + skb = receive_small(dev, vi, rq, buf, ctx, len, xdp_xmit, rbytes); if (unlikely(!skb)) - return 0; + return; hdr = skb_vnet_hdr(skb); - ret = skb->len; - if (hdr->hdr.flags & VIRTIO_NET_HDR_F_DATA_VALID) skb->ip_summed = CHECKSUM_UNNECESSARY; @@ -994,12 +1000,11 @@ static int receive_buf(struct virtnet_info *vi, struct receive_queue *rq, ntohs(skb->protocol), skb->len, skb->pkt_type); napi_gro_receive(&rq->napi, skb); - return ret; + return; frame_err: dev->stats.rx_frame_errors++; dev_kfree_skb(skb); - return 0; } /* Unlike mergeable buffers, all buffers are allocated to the @@ -1249,13 +1254,13 @@ static int virtnet_receive(struct receive_queue *rq, int budget, while (received < budget && (buf = virtqueue_get_buf_ctx(rq->vq, &len, &ctx))) { - bytes += receive_buf(vi, rq, buf, len, ctx, xdp_xmit); + receive_buf(vi, rq, buf, len, ctx, xdp_xmit, &bytes); received++; } } else { while (received < budget && (buf = virtqueue_get_buf(rq->vq, &len)) != NULL) { - bytes += receive_buf(vi, rq, buf, len, NULL, xdp_xmit); + receive_buf(vi, rq, buf, len, NULL, xdp_xmit, &bytes); received++; } }