netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Heiner Kallweit <hkallweit1@gmail.com>
To: Lev Stipakov <lstipakov@gmail.com>,
	Pravin B Shelar <pshelar@ovn.org>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	netdev@vger.kernel.org, dev@openvswitch.org,
	linux-kernel@vger.kernel.org
Cc: Lev Stipakov <lev@openvpn.net>
Subject: Re: [PATCH 2/3] net: openvswitch: use core API for updating TX stats
Date: Fri, 13 Nov 2020 08:40:42 +0100	[thread overview]
Message-ID: <598c779c-fb0b-a9a6-43be-3a7cd5b38946@gmail.com> (raw)
In-Reply-To: <20201112111150.34361-1-lev@openvpn.net>

Am 12.11.2020 um 12:11 schrieb Lev Stipakov:
> Commit d3fd65484c781 ("net: core: add dev_sw_netstats_tx_add") has added
> function "dev_sw_netstats_tx_add()" to update net device per-cpu TX
> stats.
> 
> Use this function instead of own code. While on it, replace
> "len" variable with "skb->len".
> 
Using dev_sw_netstats_tx_add() is fine, however you have to keep
variable len, see remark in the code.

In addition you can replace internal_get_stats() with dev_get_tstats64().

> Signed-off-by: Lev Stipakov <lev@openvpn.net>
> ---
>  net/openvswitch/vport-internal_dev.c | 16 +++++-----------
>  1 file changed, 5 insertions(+), 11 deletions(-)
> 
> diff --git a/net/openvswitch/vport-internal_dev.c b/net/openvswitch/vport-internal_dev.c
> index 1e30d8df3ba5..116738d36e02 100644
> --- a/net/openvswitch/vport-internal_dev.c
> +++ b/net/openvswitch/vport-internal_dev.c
> @@ -33,23 +33,17 @@ static struct internal_dev *internal_dev_priv(struct net_device *netdev)
>  static netdev_tx_t
>  internal_dev_xmit(struct sk_buff *skb, struct net_device *netdev)
>  {
> -	int len, err;
> +	int err;
>  
> -	len = skb->len;
>  	rcu_read_lock();
>  	err = ovs_vport_receive(internal_dev_priv(netdev)->vport, skb, NULL);

We would have a well-hidden problem here. ovs_vport_receive() calls function
ovs_dp_process_packet() that frees the skb under certain circumstances.
Note that the skb can be freed even if ovs_vport_receive() returns OK.
Using skb->len after calling ovs_vport_receive() could result in a
use-after-free therefore. So you have to keep variable len.

>  	rcu_read_unlock();
>  
> -	if (likely(!err)) {
> -		struct pcpu_sw_netstats *tstats = this_cpu_ptr(netdev->tstats);
> -
> -		u64_stats_update_begin(&tstats->syncp);
> -		tstats->tx_bytes += len;
> -		tstats->tx_packets++;
> -		u64_stats_update_end(&tstats->syncp);
> -	} else {
> +	if (likely(!err))
> +		dev_sw_netstats_tx_add(netdev, 1, skb->len);
> +	else
>  		netdev->stats.tx_errors++;
> -	}
> +
>  	return NETDEV_TX_OK;
>  }
>  
> 


  reply	other threads:[~2020-11-13  7:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-12 11:11 [PATCH 2/3] net: openvswitch: use core API for updating TX stats Lev Stipakov
2020-11-13  7:40 ` Heiner Kallweit [this message]
2020-11-13  9:02   ` [PATCH v2 2/3] net: openvswitch: use core API to update/provide stats Lev Stipakov
2020-11-13 10:46     ` Heiner Kallweit
2020-11-13 21:53       ` [PATCH v3] " Lev Stipakov
2020-11-15  1:10         ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=598c779c-fb0b-a9a6-43be-3a7cd5b38946@gmail.com \
    --to=hkallweit1@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dev@openvswitch.org \
    --cc=kuba@kernel.org \
    --cc=lev@openvpn.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lstipakov@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pshelar@ovn.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).