[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <67a91c79-3b4a-4ab6-850d-dc09a75fff28@ovn.org>
Date: Mon, 19 Jan 2026 22:05:16 +0100
From: Ilya Maximets <i.maximets@....org>
To: David Yang <mmyangfl@...il.com>, netdev@...r.kernel.org
Cc: i.maximets@....org, Aaron Conole <aconole@...hat.com>,
Eelco Chaudron <echaudro@...hat.com>, "David S. Miller"
<davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
Simon Horman <horms@...nel.org>, wangchuanlei <wangchuanlei@...pur.com>,
dev@...nvswitch.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH net] net: openvswitch: fix data race in
ovs_vport_get_upcall_stats
On 1/19/26 7:13 PM, David Yang wrote:
> In ovs_vport_get_upcall_stats(), some statistics protected by
> u64_stats_sync, are read and accumulated in ignorance of possible
> u64_stats_fetch_retry() events. These statistics are already accumulated
> by u64_stats_inc(). Fix this by reading them into temporary variables
> first.
>
> Fixes: 1933ea365aa7 ("net: openvswitch: Add support to count upcall packets")
> Signed-off-by: David Yang <mmyangfl@...il.com>
> ---
> net/openvswitch/vport.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
Hi, David. The change makes sense to me, thanks!
> diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c
> index 6bbbc16ab778..bc46d661b527 100644
> --- a/net/openvswitch/vport.c
> +++ b/net/openvswitch/vport.c
> @@ -319,13 +319,17 @@ int ovs_vport_get_upcall_stats(struct vport *vport, struct sk_buff *skb)
> for_each_possible_cpu(i) {
> const struct vport_upcall_stats_percpu *stats;
> unsigned int start;
> + __u64 n_success;
> + __u64 n_fail;
In addition to Eric's suggestion on using plain u64, you may also
put these two together on the same line, right above the definition
for 'start', to keep the reverse x-mass tree ordering.
>
> stats = per_cpu_ptr(vport->upcall_stats, i);
> do {
> start = u64_stats_fetch_begin(&stats->syncp);
> - tx_success += u64_stats_read(&stats->n_success);
> - tx_fail += u64_stats_read(&stats->n_fail);
> + n_success = u64_stats_read(&stats->n_success);
> + n_fail = u64_stats_read(&stats->n_fail);
> } while (u64_stats_fetch_retry(&stats->syncp, start));
> + tx_success += n_success;
> + tx_fail += n_fail;
> }
>
> nla = nla_nest_start_noflag(skb, OVS_VPORT_ATTR_UPCALL_STATS);
Best regards, Ilya Maximets.
Powered by blists - more mailing lists