veth: Fix race with AF_XDP exposing old or uninitialized descriptors
[platform/kernel/linux-starfive.git] / drivers / net / veth.c
index 09682ea..bd385cc 100644 (file)
@@ -974,6 +974,9 @@ static int veth_poll(struct napi_struct *napi, int budget)
        xdp_set_return_frame_no_direct();
        done = veth_xdp_rcv(rq, budget, &bq, &stats);
 
+       if (stats.xdp_redirect > 0)
+               xdp_do_flush();
+
        if (done < budget && napi_complete_done(napi, done)) {
                /* Write rx_notify_masked before reading ptr_ring */
                smp_store_mb(rq->rx_notify_masked, false);
@@ -987,8 +990,6 @@ static int veth_poll(struct napi_struct *napi, int budget)
 
        if (stats.xdp_tx > 0)
                veth_xdp_flush(rq, &bq);
-       if (stats.xdp_redirect > 0)
-               xdp_do_flush();
        xdp_clear_return_frame_no_direct();
 
        return done;