Skip to content

Commit cc4816b

Browse files
yangflPaolo Abeni
authored andcommitted
net: openvswitch: fix data race in ovs_vport_get_upcall_stats
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: 1933ea3 ("net: openvswitch: Add support to count upcall packets") Signed-off-by: David Yang <mmyangfl@gmail.com> Acked-by: Ilya Maximets <i.maximets@ovn.org> Reviewed-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Aaron Conole <aconole@redhat.com> Link: https://patch.msgid.link/20260121072932.2360971-1-mmyangfl@gmail.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 19e4175 commit cc4816b

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

net/openvswitch/vport.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,22 +310,23 @@ void ovs_vport_get_stats(struct vport *vport, struct ovs_vport_stats *stats)
310310
*/
311311
int ovs_vport_get_upcall_stats(struct vport *vport, struct sk_buff *skb)
312312
{
313+
u64 tx_success = 0, tx_fail = 0;
313314
struct nlattr *nla;
314315
int i;
315316

316-
__u64 tx_success = 0;
317-
__u64 tx_fail = 0;
318-
319317
for_each_possible_cpu(i) {
320318
const struct vport_upcall_stats_percpu *stats;
319+
u64 n_success, n_fail;
321320
unsigned int start;
322321

323322
stats = per_cpu_ptr(vport->upcall_stats, i);
324323
do {
325324
start = u64_stats_fetch_begin(&stats->syncp);
326-
tx_success += u64_stats_read(&stats->n_success);
327-
tx_fail += u64_stats_read(&stats->n_fail);
325+
n_success = u64_stats_read(&stats->n_success);
326+
n_fail = u64_stats_read(&stats->n_fail);
328327
} while (u64_stats_fetch_retry(&stats->syncp, start));
328+
tx_success += n_success;
329+
tx_fail += n_fail;
329330
}
330331

331332
nla = nla_nest_start_noflag(skb, OVS_VPORT_ATTR_UPCALL_STATS);

0 commit comments

Comments
 (0)