git: 0ac122c388d9 - main - ena: Use atomic_load/store functions for first_interrupt variable

From: Marcin Wojtas <mw_at_FreeBSD.org>
Date: Thu, 30 Jun 2022 16:15:36 UTC
The branch main has been updated by mw:

URL: https://cgit.FreeBSD.org/src/commit/?id=0ac122c388d9a5e189e60378f1950b82a22bbdd1

commit 0ac122c388d9a5e189e60378f1950b82a22bbdd1
Author:     Dawid Gorecki <dgr@semihalf.com>
AuthorDate: 2022-06-10 09:18:09 +0000
Commit:     Marcin Wojtas <mw@FreeBSD.org>
CommitDate: 2022-06-30 15:31:49 +0000

    ena: Use atomic_load/store functions for first_interrupt variable
    
    Surround cases of possible simultaneous access to the first_interrupt
    variable with atomic_load/store functions.
    
    Obtained from: Semihalf
    MFC after: 2 weeks
    Sponsored by: Amazon, Inc.
---
 sys/dev/ena/ena.c          | 7 ++++---
 sys/dev/ena/ena_datapath.c | 4 ++--
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/sys/dev/ena/ena.c b/sys/dev/ena/ena.c
index b4b38051b035..ab9bb177ee25 100644
--- a/sys/dev/ena/ena.c
+++ b/sys/dev/ena/ena.c
@@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/time.h>
 #include <sys/eventhandler.h>
 
+#include <machine/atomic.h>
 #include <machine/bus.h>
 #include <machine/resource.h>
 #include <machine/in_cksum.h>
@@ -381,7 +382,7 @@ ena_init_io_rings_common(struct ena_adapter *adapter, struct ena_ring *ring,
 	ring->qid = qid;
 	ring->adapter = adapter;
 	ring->ena_dev = adapter->ena_dev;
-	ring->first_interrupt = false;
+	atomic_store_8(&ring->first_interrupt, false);
 	ring->no_interrupt_event_cnt = 0;
 }
 
@@ -2983,7 +2984,7 @@ static int
 check_for_rx_interrupt_queue(struct ena_adapter *adapter,
     struct ena_ring *rx_ring)
 {
-	if (likely(rx_ring->first_interrupt))
+	if (likely(atomic_load_8(&rx_ring->first_interrupt)))
 		return (0);
 
 	if (ena_com_cq_empty(rx_ring->ena_com_io_cq))
@@ -3026,7 +3027,7 @@ check_missing_comp_in_tx_queue(struct ena_adapter *adapter,
 		bintime_sub(&time, &tx_buf->timestamp);
 		time_offset = bttosbt(time);
 
-		if (unlikely(!tx_ring->first_interrupt &&
+		if (unlikely(!atomic_load_8(&tx_ring->first_interrupt) &&
 		    time_offset > 2 * adapter->missing_tx_timeout)) {
 			/*
 			 * If after graceful period interrupt is still not
diff --git a/sys/dev/ena/ena_datapath.c b/sys/dev/ena/ena_datapath.c
index 85e9274eef14..97761c86825f 100644
--- a/sys/dev/ena/ena_datapath.c
+++ b/sys/dev/ena/ena_datapath.c
@@ -90,8 +90,8 @@ ena_cleanup(void *arg, int pending)
 	ena_qid = ENA_IO_TXQ_IDX(qid);
 	io_cq = &adapter->ena_dev->io_cq_queues[ena_qid];
 
-	tx_ring->first_interrupt = true;
-	rx_ring->first_interrupt = true;
+	atomic_store_8(&tx_ring->first_interrupt, true);
+	atomic_store_8(&rx_ring->first_interrupt, true);
 
 	for (i = 0; i < CLEAN_BUDGET; ++i) {
 		rxc = ena_rx_cleanup(rx_ring);