aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2023-01-23 19:41:05 +0000
committerMark Johnston <markj@FreeBSD.org>2023-02-01 17:22:31 +0000
commitb547900689ec6b500fefbf76585e7e4650a49dc2 (patch)
tree90ee0d4e7c822b56aa33757cde200051a1d34ce2
parent57fa543941b82410736df2ad4a0331981ac74c67 (diff)
netmap: Tell the compiler to avoid reloading ring indices
Per the removed comments these fields should be loaded only once, since they can in principle be modified concurrently, though this would be a violation of the userspace contract with netmap. No functional change intended. Reviewed by: vmaffione MFC after: 1 week Sponsored by: Zenarmor Sponsored by: OPNsense Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D38061 (cherry picked from commit 56c438fcd4a755f0abe8254779c39a0c4b530c75)
-rw-r--r--sys/dev/netmap/netmap.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/sys/dev/netmap/netmap.c b/sys/dev/netmap/netmap.c
index 1b8a4ff1d5d4..8c4481c2e6c3 100644
--- a/sys/dev/netmap/netmap.c
+++ b/sys/dev/netmap/netmap.c
@@ -1671,8 +1671,8 @@ netmap_unget_na(struct netmap_adapter *na, struct ifnet *ifp)
u_int
nm_txsync_prologue(struct netmap_kring *kring, struct netmap_ring *ring)
{
- u_int head = ring->head; /* read only once */
- u_int cur = ring->cur; /* read only once */
+ u_int head = NM_ACCESS_ONCE(ring->head);
+ u_int cur = NM_ACCESS_ONCE(ring->cur);
u_int n = kring->nkr_num_slots;
nm_prdis(5, "%s kcur %d ktail %d head %d cur %d tail %d",
@@ -1749,8 +1749,8 @@ nm_rxsync_prologue(struct netmap_kring *kring, struct netmap_ring *ring)
* - cur could in principle go back, however it does not matter
* because we are processing a brand new rxsync()
*/
- cur = kring->rcur = ring->cur; /* read only once */
- head = kring->rhead = ring->head; /* read only once */
+ cur = kring->rcur = NM_ACCESS_ONCE(ring->cur);
+ head = kring->rhead = NM_ACCESS_ONCE(ring->head);
#if 1 /* kernel sanity checks */
NM_FAIL_ON(kring->nr_hwcur >= n || kring->nr_hwtail >= n);
#endif /* kernel sanity checks */