git: b423f9fd210a - stable/12 - ena: Use atomic_load/store functions for first_interrupt variable

From: Marcin Wojtas <mw_at_FreeBSD.org>
Date: Tue, 26 Jul 2022 19:33:25 UTC
The branch stable/12 has been updated by mw:

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

commit b423f9fd210a0bd337de2219ac5d4f24c3ce789c
Author:     Dawid Gorecki <dgr@semihalf.com>
AuthorDate: 2022-06-10 09:18:09 +0000
Commit:     Marcin Wojtas <mw@FreeBSD.org>
CommitDate: 2022-07-26 19:33:03 +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.
    
    (cherry picked from commit 0ac122c388d9a5e189e60378f1950b82a22bbdd1)
---
 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 74dcd37973b5..82f8d42ea0b0 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;
 }
 
@@ -2987,7 +2988,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))
@@ -3030,7 +3031,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 31de514d4b19..f17bad380c09 100644
--- a/sys/dev/ena/ena_datapath.c
+++ b/sys/dev/ena/ena_datapath.c
@@ -91,8 +91,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);