]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
net: mana: Fix race on per-CQ variable napi work_done
authorHaiyang Zhang <haiyangz@microsoft.com>
Fri, 2 Dec 2022 19:43:10 +0000 (11:43 -0800)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 14 Dec 2022 13:02:54 +0000 (14:02 +0100)
commit 18010ff776fa42340efc428b3ea6d19b3e7c7b21 upstream.

After calling napi_complete_done(), the NAPIF_STATE_SCHED bit may be
cleared, and another CPU can start napi thread and access per-CQ variable,
cq->work_done. If the other thread (for example, from busy_poll) sets
it to a value >= budget, this thread will continue to run when it should
stop, and cause memory corruption and panic.

To fix this issue, save the per-CQ work_done variable in a local variable
before napi_complete_done(), so it won't be corrupted by a possible
concurrent thread after napi_complete_done().

Also, add a flag bit to advertise to the NIC firmware: the NAPI work_done
variable race is fixed, so the driver is able to reliably support features
like busy_poll.

Cc: stable@vger.kernel.org
Fixes: e1b5683ff62e ("net: mana: Move NAPI from EQ to CQ")
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Link: https://lore.kernel.org/r/1670010190-28595-1-git-send-email-haiyangz@microsoft.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit fe50a9bbeb1f042e756c5cfa7708112c944368de)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
drivers/net/ethernet/microsoft/mana/gdma.h
drivers/net/ethernet/microsoft/mana/mana_en.c

index 41ecd156e95f5b86838aed415eb4f6195ef1e1a8..1038bdf28ec08fde853425b0548b8c29bf7aede8 100644 (file)
@@ -488,7 +488,14 @@ enum {
 
 #define GDMA_DRV_CAP_FLAG_1_EQ_SHARING_MULTI_VPORT BIT(0)
 
-#define GDMA_DRV_CAP_FLAGS1 GDMA_DRV_CAP_FLAG_1_EQ_SHARING_MULTI_VPORT
+/* Advertise to the NIC firmware: the NAPI work_done variable race is fixed,
+ * so the driver is able to reliably support features like busy_poll.
+ */
+#define GDMA_DRV_CAP_FLAG_1_NAPI_WKDONE_FIX BIT(2)
+
+#define GDMA_DRV_CAP_FLAGS1 \
+       (GDMA_DRV_CAP_FLAG_1_EQ_SHARING_MULTI_VPORT | \
+        GDMA_DRV_CAP_FLAG_1_NAPI_WKDONE_FIX)
 
 #define GDMA_DRV_CAP_FLAGS2 0
 
index 18dc64d7f412ffaa6bc8aa460560c8072ed51c2b..4b8c2399321780b2af5ac7f4900c7e63c9eacdc9 100644 (file)
@@ -1071,10 +1071,11 @@ static void mana_poll_rx_cq(struct mana_cq *cq)
        }
 }
 
-static void mana_cq_handler(void *context, struct gdma_queue *gdma_queue)
+static int mana_cq_handler(void *context, struct gdma_queue *gdma_queue)
 {
        struct mana_cq *cq = context;
        u8 arm_bit;
+       int w;
 
        WARN_ON_ONCE(cq->gdma_cq != gdma_queue);
 
@@ -1083,26 +1084,31 @@ static void mana_cq_handler(void *context, struct gdma_queue *gdma_queue)
        else
                mana_poll_tx_cq(cq);
 
-       if (cq->work_done < cq->budget &&
-           napi_complete_done(&cq->napi, cq->work_done)) {
+       w = cq->work_done;
+
+       if (w < cq->budget &&
+           napi_complete_done(&cq->napi, w)) {
                arm_bit = SET_ARM_BIT;
        } else {
                arm_bit = 0;
        }
 
        mana_gd_ring_cq(gdma_queue, arm_bit);
+
+       return w;
 }
 
 static int mana_poll(struct napi_struct *napi, int budget)
 {
        struct mana_cq *cq = container_of(napi, struct mana_cq, napi);
+       int w;
 
        cq->work_done = 0;
        cq->budget = budget;
 
-       mana_cq_handler(cq, cq->gdma_cq);
+       w = mana_cq_handler(cq, cq->gdma_cq);
 
-       return min(cq->work_done, budget);
+       return min(w, budget);
 }
 
 static void mana_schedule_napi(void *context, struct gdma_queue *gdma_queue)