lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <83852e9f8ca11e75db07a2f4c3577633c01fc68b.camel@redhat.com>
Date:   Tue, 22 Nov 2022 11:26:05 +0100
From:   Paolo Abeni <pabeni@...hat.com>
To:     wangchuanlei <wangchuanlei@...pur.com>, echaudro@...hat.com,
        pshelar@....org, davem@...emloft.net, edumazet@...gle.com,
        kuba@...nel.org
Cc:     wangpeihui@...pur.com, netdev@...r.kernel.org, dev@...nvswitch.org
Subject: Re: [PATCH] [openvswitch v3 1/2] openvswitch: Add support to count
 upcall packets

Hello,

On Fri, 2022-11-18 at 06:19 -0500, wangchuanlei wrote:
> Add support to count upall packets
> 
> Signed-off-by: wangchuanlei <wangchuanlei@...pur.com>

The fact that you are posting this series simultaneusly to netdev and
the ovs ML with only patch 1/2 landing here is confusing. On next
iteration please sent this patch to netdev as an individual one.

Additionally, please write a more verbose changelog.

[...]

> diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
> index c8a9075ddd0a..17146200e7c5 100644
> --- a/net/openvswitch/datapath.c
> +++ b/net/openvswitch/datapath.c
> @@ -209,6 +209,28 @@ static struct vport *new_vport(const struct vport_parms *parms)
>  	return vport;
>  }
>  
> +static void ovs_vport_upcalls(struct sk_buff *skb,
> +			      const struct dp_upcall_info *upcall_info,
> +			      bool upcall_success)
> +{
> +	if (upcall_info->cmd == OVS_PACKET_CMD_MISS ||
> +	    upcall_info->cmd == OVS_PACKET_CMD_ACTION) {
> +		const struct vport *p = OVS_CB(skb)->input_vport;
> +		struct vport_upcall_stats_percpu *vport_stats;
> +		u64 *stats_counter_upcall;
> +
> +		vport_stats = this_cpu_ptr(p->vport_upcall_stats_percpu);
> +		if (upcall_success)
> +			stats_counter_upcall = &vport_stats->n_upcall_success;
> +		else
> +			stats_counter_upcall = &vport_stats->n_upcall_fail;

You can move the 'if' statement inside the stats update block and
simplify the code a bit

> +
> +		u64_stats_update_begin(&vport_stats->syncp);
> +		(*stats_counter_upcall)++;

This should be u64_stats_inc()

> +		u64_stats_update_end(&vport_stats->syncp);
> +	}
> +}
> +

[...]

> @@ -305,8 +330,12 @@ int ovs_dp_upcall(struct datapath *dp, struct sk_buff *skb,
>  		err = queue_userspace_packet(dp, skb, key, upcall_info, cutlen);
>  	else
>  		err = queue_gso_packets(dp, skb, key, upcall_info, cutlen);
> -	if (err)
> +	if (err) {
> +		ovs_vport_upcalls(skb, upcall_info, false);
>  		goto err;
> +	} else {
> +		ovs_vport_upcalls(skb, upcall_info, true);

Or simply:

	ovs_vport_upcalls(skb, upcall_info, !ret);

before the 'if'

> +	}
>  
>  	return 0;
>  
> @@ -1825,6 +1854,13 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
>  		goto err_destroy_portids;
>  	}
>  
> +	vport->vport_upcall_stats_percpu =
> +				netdev_alloc_pcpu_stats(struct vport_upcall_stats_percpu);
> +	if (!vport->vport_upcall_stats_percpu) {
> +		err = -ENOMEM;
> +		goto err_destroy_portids;

You likelly need to additionally destroy 'vport' on this error path.

> +	}
> +
>  	err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid,
>  				   info->snd_seq, 0, OVS_DP_CMD_NEW);
>  	BUG_ON(err < 0);

[...]

> diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c
> index 82a74f998966..17b8ad1a9a16 100644
> --- a/net/openvswitch/vport.c
> +++ b/net/openvswitch/vport.c
> @@ -284,6 +284,56 @@ void ovs_vport_get_stats(struct vport *vport, struct ovs_vport_stats *stats)
>  	stats->tx_packets = dev_stats->tx_packets;
>  }
>  
> +/**
> + *	ovs_vport_get_upcall_stats - retrieve upcall stats
> + *
> + * @vport: vport from which to retrieve the stats
> + * @ovs_vport_upcall_stats: location to store stats
> + *
> + * Retrieves upcall stats for the given device.
> + *
> + * Must be called with ovs_mutex or rcu_read_lock.
> + */
> +void ovs_vport_get_upcall_stats(struct vport *vport, struct ovs_vport_upcall_stats *stats)
> +{
> +	int i;
> +
> +	stats->upcall_success = 0;
> +	stats->upcall_fail = 0;
> +
> +	for_each_possible_cpu(i) {
> +		const struct vport_upcall_stats_percpu *percpu_upcall_stats;
> +		struct vport_upcall_stats_percpu local_stats;
> +		unsigned int start;
> +
> +		percpu_upcall_stats = per_cpu_ptr(vport->vport_upcall_stats_percpu, i);
> +		do {
> +			start = u64_stats_fetch_begin_irq(&percpu_upcall_stats->syncp);

This is an obsolted API, please use plain u64_stats_fetch_begin()
instead

> +			local_stats = *percpu_upcall_stats;

You need to fetch each stat individually with u64_stats_read()


> +		} while (u64_stats_fetch_retry_irq(&percpu_upcall_stats->syncp, start));
> +
> +		stats->upcall_success += local_stats.n_upcall_success;
> +		stats->upcall_fail += local_stats.n_upcall_fail;
> +	}
> +}
> +

Thanks,

Paolo

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ