Skip to content

Commit cbe9eb2

Browse files
josh8551021gregkh
authored andcommitted
gve: guard XDP xmit NDO on existence of xdp queues
commit ff7c2de upstream. In GVE, dedicated XDP queues only exist when an XDP program is installed and the interface is up. As such, the NDO XDP XMIT callback should return early if either of these conditions are false. In the case of no loaded XDP program, priv->num_xdp_queues=0 which can cause a divide-by-zero error, and in the case of interface down, num_xdp_queues remains untouched to persist XDP queue count for the next interface up, but the TX pointer itself would be NULL. The XDP xmit callback also needs to synchronize with a device transitioning from open to close. This synchronization will happen via the GVE_PRIV_FLAGS_NAPI_ENABLED bit along with a synchronize_net() call, which waits for any RCU critical sections at call-time to complete. Fixes: 39a7f4a ("gve: Add XDP REDIRECT support for GQI-QPL format") Cc: stable@vger.kernel.org Signed-off-by: Joshua Washington <joshwash@google.com> Signed-off-by: Praveen Kaligineedi <pkaligineedi@google.com> Reviewed-by: Praveen Kaligineedi <pkaligineedi@google.com> Reviewed-by: Shailend Chand <shailend@google.com> Reviewed-by: Willem de Bruijn <willemb@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 771d66f commit cbe9eb2

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

drivers/net/ethernet/google/gve/gve_main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,6 +1755,9 @@ static void gve_turndown(struct gve_priv *priv)
17551755

17561756
gve_clear_napi_enabled(priv);
17571757
gve_clear_report_stats(priv);
1758+
1759+
/* Make sure that all traffic is finished processing. */
1760+
synchronize_net();
17581761
}
17591762

17601763
static void gve_turnup(struct gve_priv *priv)

drivers/net/ethernet/google/gve/gve_tx.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,9 +777,12 @@ int gve_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **frames,
777777
struct gve_tx_ring *tx;
778778
int i, err = 0, qid;
779779

780-
if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK))
780+
if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK) || !priv->xdp_prog)
781781
return -EINVAL;
782782

783+
if (!gve_get_napi_enabled(priv))
784+
return -ENETDOWN;
785+
783786
qid = gve_xdp_tx_queue_id(priv,
784787
smp_processor_id() % priv->num_xdp_queues);
785788

0 commit comments

Comments
 (0)