Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: alacritech: Use u64_stats_t with u64_stats_sync properly

On 64bit arches, struct u64_stats_sync is empty and provides no help
against load/store tearing. Convert to u64_stats_t to ensure atomic
operations.

Signed-off-by: David Yang <mmyangfl@gmail.com>
Link: https://patch.msgid.link/20260122185113.2760355-1-mmyangfl@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

David Yang and committed by
Jakub Kicinski
6e9674a9 3da35aa8

+29 -29
+25 -25
drivers/net/ethernet/alacritech/slic.h
··· 284 284 #define SLIC_INC_STATS_COUNTER(st, counter) \ 285 285 do { \ 286 286 u64_stats_update_begin(&(st)->syncp); \ 287 - (st)->counter++; \ 287 + u64_stats_inc(&(st)->counter); \ 288 288 u64_stats_update_end(&(st)->syncp); \ 289 289 } while (0) 290 290 ··· 293 293 unsigned int start; \ 294 294 do { \ 295 295 start = u64_stats_fetch_begin(&(st)->syncp); \ 296 - newst = (st)->counter; \ 296 + newst = u64_stats_read(&(st)->counter); \ 297 297 } while (u64_stats_fetch_retry(&(st)->syncp, start)); \ 298 298 } 299 299 ··· 407 407 }; 408 408 409 409 struct slic_stats { 410 - u64 rx_packets; 411 - u64 rx_bytes; 412 - u64 rx_mcasts; 413 - u64 rx_errors; 414 - u64 tx_packets; 415 - u64 tx_bytes; 410 + u64_stats_t rx_packets; 411 + u64_stats_t rx_bytes; 412 + u64_stats_t rx_mcasts; 413 + u64_stats_t rx_errors; 414 + u64_stats_t tx_packets; 415 + u64_stats_t tx_bytes; 416 416 /* HW STATS */ 417 - u64 rx_buff_miss; 418 - u64 tx_dropped; 419 - u64 irq_errs; 417 + u64_stats_t rx_buff_miss; 418 + u64_stats_t tx_dropped; 419 + u64_stats_t irq_errs; 420 420 /* transport layer */ 421 - u64 rx_tpcsum; 422 - u64 rx_tpoflow; 423 - u64 rx_tphlen; 421 + u64_stats_t rx_tpcsum; 422 + u64_stats_t rx_tpoflow; 423 + u64_stats_t rx_tphlen; 424 424 /* ip layer */ 425 - u64 rx_ipcsum; 426 - u64 rx_iplen; 427 - u64 rx_iphlen; 425 + u64_stats_t rx_ipcsum; 426 + u64_stats_t rx_iplen; 427 + u64_stats_t rx_iphlen; 428 428 /* link layer */ 429 - u64 rx_early; 430 - u64 rx_buffoflow; 431 - u64 rx_lcode; 432 - u64 rx_drbl; 433 - u64 rx_crc; 434 - u64 rx_oflow802; 435 - u64 rx_uflow802; 429 + u64_stats_t rx_early; 430 + u64_stats_t rx_buffoflow; 431 + u64_stats_t rx_lcode; 432 + u64_stats_t rx_drbl; 433 + u64_stats_t rx_crc; 434 + u64_stats_t rx_oflow802; 435 + u64_stats_t rx_uflow802; 436 436 /* oasis only */ 437 - u64 tx_carrier; 437 + u64_stats_t tx_carrier; 438 438 struct u64_stats_sync syncp; 439 439 }; 440 440
+4 -4
drivers/net/ethernet/alacritech/slicoss.c
··· 378 378 smp_wmb(); 379 379 380 380 u64_stats_update_begin(&sdev->stats.syncp); 381 - sdev->stats.tx_bytes += bytes; 382 - sdev->stats.tx_packets += frames; 381 + u64_stats_add(&sdev->stats.tx_bytes, bytes); 382 + u64_stats_add(&sdev->stats.tx_packets, frames); 383 383 u64_stats_update_end(&sdev->stats.syncp); 384 384 385 385 netif_tx_lock(dev); ··· 615 615 } 616 616 617 617 u64_stats_update_begin(&sdev->stats.syncp); 618 - sdev->stats.rx_bytes += bytes; 619 - sdev->stats.rx_packets += frames; 618 + u64_stats_add(&sdev->stats.rx_bytes, bytes); 619 + u64_stats_add(&sdev->stats.rx_packets, frames); 620 620 u64_stats_update_end(&sdev->stats.syncp); 621 621 622 622 slic_refill_rx_queue(sdev, GFP_ATOMIC);