From nobody Thu Dec 18 09:48:56 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE97A1BEF68 for ; Wed, 18 Dec 2024 13:34:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734528871; cv=none; b=K3Zr+yUG/Gu6B+uMedMZjMXp3vJE+uLLLPMjfjN4Lx+d0MpxAM7p9RThNoKhPR2zMzfADfWcyad+mtGLOOA/Nsdpk6GMBsEL7bUJnwpPDC1GWxGz2rio0hgLf0T13PXCA9ibO7BftWGIpbvTEI2cExQSan+GeYebnLIimPcJZFo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734528871; c=relaxed/simple; bh=OriOUj3M1nI27Avpba3wIze2vFUhMiy7qxk7DOa3psI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=koB9yLrJu2tuBUITvajZ/uH47AJvCnpErhRSSUlh4/UnKMZP8Ut5NRh5mNaAiTvQGbNptz/d7SVyCfZzyRi1D7iTsJZEe3Moho86KWpiBWtiOwMqVFQ82Z6r2hjddDvV7OT4OIi71V+6PzF5fhI6cFq7RlOPVY8YdxZJXJxy+Z8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--pkaligineedi.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ItRufYRn; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--pkaligineedi.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ItRufYRn" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2163dc0f689so97542345ad.1 for ; Wed, 18 Dec 2024 05:34:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734528867; x=1735133667; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=eAFTBo7ivhTuc59SVtnRzpksnEHu505WEYyIklRMIGY=; b=ItRufYRn/73cAfP6i7/w4xR+14kfugMij8ku+JWTbkQf+FHOFKda45OGjyvTo5TEhL +wB+F5azOSCleL5sHELza2tqeF8gcUObN7PZEWvILq5qKxVhunwm1YqFbIqy704UtMfR 5MS0FLYK5P8Kv9Bmjt8//yK/RxGOdQObI5AC1cj7Fi5znnLYktJcBIRVdFWH5zxcErpK pFHC4EQFXNqjvIX82zmRlW89H4ylAd1KXuvlfnQzEu8HnBAVp2OY+Q4lUp4FAp5i5Tb3 VJRlWt4MLSqUlKNb46LC4qXBFWXo4EU+6OH/AZxQ46NwJl3gQgfzt6web5aRGNyUDNVG Rjhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734528867; x=1735133667; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=eAFTBo7ivhTuc59SVtnRzpksnEHu505WEYyIklRMIGY=; b=OKW706mh+YNFh3f5VtnEC/hxgHFLKpFF+0d60n4Qs5aouqodSpOdUuiyqi1FAN7ky0 HS/6Z2vguMZDbjhcky5lNLFIWTGw2CBu3XRzR30lHwVCa/WUPhT0AxPhM7pJlfl7vBuL vHFK9HGFC+QcsebGk4ioZSFbO9wKMOb6cxQnJRQEef3iEL44QQcBsdrgGJn/TkX5JJSD EtFDKD5LCrkSdSlig4CWQd7YjNbIXYgRFYVAYyQmAxuR3YFE0Fl8IaCQIc3seRCZMffS MjxcQ4K+KvlEYDcdsHcWE9suPMRfmn2uqW2ojenirY5WZC7XHrJHqxjGE4JeiJpXowA4 /joA== X-Forwarded-Encrypted: i=1; AJvYcCVsbx+cppdptdWm4i6Pj14vvJoHXDKmqvwWsI6GsM5iwU5KIlv1ZY96Erht7Ju4JWYew/rzz2jvuZ57IV0=@vger.kernel.org X-Gm-Message-State: AOJu0YzkankWKWcTpsufdrewNVP9tOXBUbH081xHDSibAv6EDKROX5Ni 8ivMBJZktjy+DlT9K54K9GjiCJSu9Vku0upT64b3PQ/xr4PXxM32OIW2IymBcCOKhG64KR4JDj5 syUvO6dZGvK7iU81UNzkod1qzqQ== X-Google-Smtp-Source: AGHT+IFY1SuAyxxaS/Chpz8wp/cqmlqOOaKMj+QKltDNe140ZmyzZdNe/qSR+a8+kqBKh2wehr1iKLZ6ofMLYYyTL+M= X-Received: from plbmf12.prod.google.com ([2002:a17:902:fc8c:b0:215:3fc5:cd3f]) (user=pkaligineedi job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:f70a:b0:215:b9a7:526d with SMTP id d9443c01a7336-218d7223339mr44408425ad.32.1734528867093; Wed, 18 Dec 2024 05:34:27 -0800 (PST) Date: Wed, 18 Dec 2024 05:34:11 -0800 In-Reply-To: <20241218133415.3759501-1-pkaligineedi@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241218133415.3759501-1-pkaligineedi@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241218133415.3759501-2-pkaligineedi@google.com> Subject: [PATCH net 1/5] gve: clean XDP queues in gve_tx_stop_ring_gqi From: Praveen Kaligineedi To: netdev@vger.kernel.org Cc: jeroendb@google.com, shailend@google.com, willemb@google.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, horms@kernel.org, hramamurthy@google.com, joshwash@google.com, ziweixiao@google.com, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, stable@vger.kernel.org, Praveen Kaligineedi Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Joshua Washington When stopping XDP TX rings, the XDP clean function needs to be called to clean out the entire queue, similar to what happens in the normal TX queue case. Otherwise, the FIFO won't be cleared correctly, and xsk_tx_completed won't be reported. Fixes: 75eaae158b1b ("gve: Add XDP DROP and TX support for GQI-QPL format") Cc: stable@vger.kernel.org Signed-off-by: Joshua Washington Signed-off-by: Praveen Kaligineedi Reviewed-by: Praveen Kaligineedi Reviewed-by: Willem de Bruijn --- drivers/net/ethernet/google/gve/gve_tx.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/google/gve/gve_tx.c b/drivers/net/etherne= t/google/gve/gve_tx.c index e7fb7d6d283d..83ad278ec91f 100644 --- a/drivers/net/ethernet/google/gve/gve_tx.c +++ b/drivers/net/ethernet/google/gve/gve_tx.c @@ -206,7 +206,10 @@ void gve_tx_stop_ring_gqi(struct gve_priv *priv, int i= dx) return; =20 gve_remove_napi(priv, ntfy_idx); - gve_clean_tx_done(priv, tx, priv->tx_desc_cnt, false); + if (tx->q_num < priv->tx_cfg.num_queues) + gve_clean_tx_done(priv, tx, priv->tx_desc_cnt, false); + else + gve_clean_xdp_done(priv, tx, priv->tx_desc_cnt); netdev_tx_reset_queue(tx->netdev_txq); gve_tx_remove_from_block(priv, idx); } --=20 2.47.1.613.gc27f4b7a9f-goog From nobody Thu Dec 18 09:48:56 2025 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72DDA1BEF80 for ; Wed, 18 Dec 2024 13:34:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734528871; cv=none; b=irNpIKT16skTR0aGdlpqgfKjcOevb0zpDe/q1rj2+TZ53cz8p0R2xrZaKPhmFjkmCmg1myIgxUR6AzlDyQnBmKiszsrI50Zd+Qqgv9nLLdfp/zmw7z6VlRHPamEagr9uwM/0KpTxVPDNB+OoYHrjKVpCjB9kWo6HBV4zp3LrAA4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734528871; c=relaxed/simple; bh=CvjpZzap2JTZv3aoX0brnCAcyXx3Af2l9Bmavz1WSA4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=lAZwx7PTdl4i3/DaH4Y8o+apkXfK1yoCX7pl1XzCDZmcM6rTrhGp1coAWRJ/oeFvSo7uUAsEiRVHqvyouxC55r4kz2Xbrt5JbR/MYbzQ2toYFitUnRui/5TN9HJwW/1w5RWS7KmInM/YPQyFpSZqmtjtxJYT6Wxlmcl63Tw+bG8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--pkaligineedi.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=0/JaCxdu; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--pkaligineedi.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="0/JaCxdu" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-728f1c4b95aso5077104b3a.0 for ; Wed, 18 Dec 2024 05:34:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734528869; x=1735133669; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=NRgIGaGDm4cvXXtjC5u8gCurbHYhRvv9RGqvrTy9ue8=; b=0/JaCxduaU21L5RaQx1ihJQkMX1AE95D59KPUyoGVH8hJltOXiXJqNS3vX4009WxH7 rjpAASdQXLKI/+jO1QdHUfThNL8htyOBJzRrXOoN8z13/4tprvTc1bF+j5iAerBkM/9C vDuF04wu1F32nO8QvX/5a6TnWttMCrImbvkysgqaj8VF9dM7SdZVy8EatBls/34C/KTi LOCh/CRcBkWUuYrGSuLCdwgT5ImdZYYv3b98OHWzvq6hpkgjZ3vrDkjD0EFDEoC9h+Ov f2WchjMngQRtdwc457HC6V/svmX+Vqay5lFNygRpNw4Pg+O9VNyKDEQbx8ODPbox863J 7SzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734528869; x=1735133669; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NRgIGaGDm4cvXXtjC5u8gCurbHYhRvv9RGqvrTy9ue8=; b=g7346nCSDE/urQb8RbHUVizFfv4I92qJBdW3DIaVPim8mGgJWtvh0jD+OjrVado002 Mmn9YbBSCHhZ6VZWxKxFyDKHV9FQJYguZhpMDUsol7PTn1NVNjNY1hVNpHfXseTktCoo j3snoc+SXTZJrd1dfvslmrPEM5f3tpZZ4HcwvhETemy/FB+01lsKkbwq+bfrwtU/5s74 sm0IDKPM+7AH2C3pNQh1ukoK7eykXUGsCLC7F0GiYv306mn06d3Qmi9gVtnrAB7lKGX/ oDHf2Rh2KDiHZfZOiwyXM8yLL/eJ/QW9YSj7QelbjmFLn8cl1mZII/Rk0HKrBWb7J/HB 55fw== X-Forwarded-Encrypted: i=1; AJvYcCUg0swU8/eEAWn7hJnUHfSDScNSuc0ktcHNHqO/G+Wtr1Hyn1dBuA4FpKab7hnh4PIyKLXpkV6/zI2KizE=@vger.kernel.org X-Gm-Message-State: AOJu0YxUS4hXHOv42cMif8Y48cs/2N+0Dvy5BOaS+F4SjAM1X3GogT+F bXTsr+7gdhaNHx3FbLt02KJ2ScGH7pkveRT4X2GcYIkYCUX3xnBGDDZcyAvkzWvRMGk27oBdeOi MLr9gHwIJQVQomN3T0nvSDsqXfQ== X-Google-Smtp-Source: AGHT+IELVRUurFW8tfDDC0iUwFPiFsqYStc2zOYCPV3iXlkA6nU0se344US+p9bexkbh23hUu3k2oyF3UnV/97X3x9c= X-Received: from pgeu9.prod.google.com ([2002:a63:a909:0:b0:7ff:d6:4f28]) (user=pkaligineedi job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:1013:b0:1e1:e2d9:307 with SMTP id adf61e73a8af0-1e5b487e6e8mr4675360637.33.1734528868845; Wed, 18 Dec 2024 05:34:28 -0800 (PST) Date: Wed, 18 Dec 2024 05:34:12 -0800 In-Reply-To: <20241218133415.3759501-1-pkaligineedi@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241218133415.3759501-1-pkaligineedi@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241218133415.3759501-3-pkaligineedi@google.com> Subject: [PATCH net 2/5] gve: guard XDP xmit NDO on existence of xdp queues From: Praveen Kaligineedi To: netdev@vger.kernel.org Cc: jeroendb@google.com, shailend@google.com, willemb@google.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, horms@kernel.org, hramamurthy@google.com, joshwash@google.com, ziweixiao@google.com, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, stable@vger.kernel.org, Praveen Kaligineedi Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Joshua Washington 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=3D0 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: 39a7f4aa3e4a ("gve: Add XDP REDIRECT support for GQI-QPL format") Cc: stable@vger.kernel.org Signed-off-by: Joshua Washington Signed-off-by: Praveen Kaligineedi Reviewed-by: Praveen Kaligineedi Reviewed-by: Shailend Chand Reviewed-by: Willem de Bruijn --- drivers/net/ethernet/google/gve/gve_main.c | 3 +++ drivers/net/ethernet/google/gve/gve_tx.c | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ether= net/google/gve/gve_main.c index e171ca248f9a..5d7b0cc59959 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -1899,6 +1899,9 @@ static void gve_turndown(struct gve_priv *priv) =20 gve_clear_napi_enabled(priv); gve_clear_report_stats(priv); + + /* Make sure that all traffic is finished processing. */ + synchronize_net(); } =20 static void gve_turnup(struct gve_priv *priv) diff --git a/drivers/net/ethernet/google/gve/gve_tx.c b/drivers/net/etherne= t/google/gve/gve_tx.c index 83ad278ec91f..852f8c7e39d2 100644 --- a/drivers/net/ethernet/google/gve/gve_tx.c +++ b/drivers/net/ethernet/google/gve/gve_tx.c @@ -837,9 +837,12 @@ int gve_xdp_xmit(struct net_device *dev, int n, struct= xdp_frame **frames, struct gve_tx_ring *tx; int i, err =3D 0, qid; =20 - if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK)) + if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK) || !priv->xdp_prog) return -EINVAL; =20 + if (!gve_get_napi_enabled(priv)) + return -ENETDOWN; + qid =3D gve_xdp_tx_queue_id(priv, smp_processor_id() % priv->num_xdp_queues); =20 --=20 2.47.1.613.gc27f4b7a9f-goog From nobody Thu Dec 18 09:48:56 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3A2A1C5CA4 for ; Wed, 18 Dec 2024 13:34:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734528873; cv=none; b=gt8sORJG8jb/g07FCqQAseeRKd58zLdYjomM5x+pKreE9UJhCxFQ+CXCD3Y7FWbIFUl7GqWLYbmQLO8/Vz4ggdB97EqC5ESU8TKFGOP7gVllB+m9krMi4RrYd2NfCsNWiPMq/B4VP/YShwPyrFTjVh0lGPVrbWlcoIFbxUcVGpQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734528873; c=relaxed/simple; bh=9BgVkXA7sAnOzdE3qY+1AbaUb+6u5iOoRd5soMYqiXc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=rRWcozqCXUeATSEpxz2iuf+guV5cGy7IF7JtieqvgaZmnaZeSyZClUYOU5+9/NZ12LklseffvhM5D6xkEKejvnD1KvyuuhPV58KuvHNI9Op5nIol3JOqrBapOsVyVvx+lBJ4UXKWLmZ8ZjF8QQoxiNcSsYxjGqaCsWb2ys071l8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--pkaligineedi.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=IXWbzG2m; arc=none smtp.client-ip=209.85.215.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--pkaligineedi.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="IXWbzG2m" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-7fcd2430636so4424389a12.2 for ; Wed, 18 Dec 2024 05:34:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734528870; x=1735133670; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=BaCLJGMJQz1qP4MJHET69CAtZwrd4CwtIMp86qT77Mc=; b=IXWbzG2mrE2Dgmp2VecBKZDqSTOTG+1q7SmlCb1dvlnUzHgd4wOwi5xd0t1j+XuxTX kAL2IEiCdUngsEiCuXaxY57WrRB1F7LE0RqRErFQEukXROCcX2q9uXy85pQZy50QGK1x ZfTsg31xaQ0ZmFeJMAa4VusJOuN6pNg7ZesloqvjFO+2WvK/TKh77xhU9H9nJUBw9wLz s4cIFFlES+h9i8E0FwqT9KG4pdE+a2AELeSsKNHICC8GIar9umw3LUgGkfv2qVjJ0ssb 2ngQZHly+V4Mu1tC5706hCbX72a/EEVpj1mg/viqpAXmvS+rvlxfFBdT7fanj2esiAXJ ob3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734528870; x=1735133670; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BaCLJGMJQz1qP4MJHET69CAtZwrd4CwtIMp86qT77Mc=; b=OxhkioKpuwyJV2qbjjdnZiT9PPKfN1ak3BzEMn+ekEk0OhGBqzz000e7qZQElLV3aS SjsqSPMeJZP9KjKB5TqKhiPUqddBqhbMhlkbsd1EUq2DP9Fz8A59vDaKn1xrM60ws0wm ZiqEq214iuGpCKVdzooP+i31xbFY+ovm0QYgdJRXRkjY1f7JfNZuPdz7kHwRGaEMIBI8 9HbKuyXFbfPo0kWkqw8eYxJPOOdo/az8nBOKiGZhMEdtfHVm6T862FW9YmZpEwN1HGWs OD3q5qJwm98zyvS+Mo9g3JLVJYWaVRYjkL0exyy4R+WS5FCqlNhVqgKQuz5CWBUHLkXW H6HQ== X-Forwarded-Encrypted: i=1; AJvYcCVEX+XGcFaPJZrM4N6AuPif2EFzM6lze49O99rgkKM2zo4I/8050OIVRGoeENxWChaAHYkCUWXAD1rm4co=@vger.kernel.org X-Gm-Message-State: AOJu0YzzubA2t1E+YnnIajJxmJKB6eLdo4lxHQThYiecETQFiltelCae bwKdqTBBK41njDdk5J+4KklAOrwidIjCkBQyU+x6ffkBvfIFuR0QmyFduW2byzljLhTrEyOuC7c gQZyWGIjq6LKqSindvueS0MDATA== X-Google-Smtp-Source: AGHT+IEtLKXZPbOvOiUsezPjGdVej+2Jrgenj3uZFiHh0CPqYPWhY/GVn4ZOUteMHaxZiVYXA9nTm51H7JWqV6EAjaI= X-Received: from pgmt35.prod.google.com ([2002:a63:2263:0:b0:7fd:5835:26d1]) (user=pkaligineedi job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:8408:b0:1e1:c26d:d7fd with SMTP id adf61e73a8af0-1e5b48a0f20mr4449943637.37.1734528870243; Wed, 18 Dec 2024 05:34:30 -0800 (PST) Date: Wed, 18 Dec 2024 05:34:13 -0800 In-Reply-To: <20241218133415.3759501-1-pkaligineedi@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241218133415.3759501-1-pkaligineedi@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241218133415.3759501-4-pkaligineedi@google.com> Subject: [PATCH net 3/5] gve: guard XSK operations on the existence of queues From: Praveen Kaligineedi To: netdev@vger.kernel.org Cc: jeroendb@google.com, shailend@google.com, willemb@google.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, horms@kernel.org, hramamurthy@google.com, joshwash@google.com, ziweixiao@google.com, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, stable@vger.kernel.org, Praveen Kaligineedi Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Joshua Washington This patch predicates the enabling and disabling of XSK pools on the existence of queues. As it stands, if the interface is down, disabling or enabling XSK pools would result in a crash, as the RX queue pointer would be NULL. XSK pool registration will occur as part of the next interface up. Similarly, xsk_wakeup needs be guarded against queues disappearing while the function is executing, so a check against the GVE_PRIV_FLAGS_NAPI_ENABLED flag is added to synchronize with the disabling of the bit and the synchronize_net() in gve_turndown. Fixes: fd8e40321a12 ("gve: Add AF_XDP zero-copy support for GQI-QPL format") Cc: stable@vger.kernel.org Signed-off-by: Joshua Washington Signed-off-by: Praveen Kaligineedi Reviewed-by: Praveen Kaligineedi Reviewed-by: Shailend Chand Reviewed-by: Willem de Bruijn Reviewed-by: Larysa Zaremba --- drivers/net/ethernet/google/gve/gve_main.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ether= net/google/gve/gve_main.c index 5d7b0cc59959..e4e8ff4f9f80 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -1623,8 +1623,8 @@ static int gve_xsk_pool_enable(struct net_device *dev, if (err) return err; =20 - /* If XDP prog is not installed, return */ - if (!priv->xdp_prog) + /* If XDP prog is not installed or interface is down, return. */ + if (!priv->xdp_prog || !netif_running(dev)) return 0; =20 rx =3D &priv->rx[qid]; @@ -1669,21 +1669,16 @@ static int gve_xsk_pool_disable(struct net_device *= dev, if (qid >=3D priv->rx_cfg.num_queues) return -EINVAL; =20 - /* If XDP prog is not installed, unmap DMA and return */ - if (!priv->xdp_prog) + /* If XDP prog is not installed or interface is down, unmap DMA and + * return. + */ + if (!priv->xdp_prog || !netif_running(dev)) goto done; =20 - tx_qid =3D gve_xdp_tx_queue_id(priv, qid); - if (!netif_running(dev)) { - priv->rx[qid].xsk_pool =3D NULL; - xdp_rxq_info_unreg(&priv->rx[qid].xsk_rxq); - priv->tx[tx_qid].xsk_pool =3D NULL; - goto done; - } - napi_rx =3D &priv->ntfy_blocks[priv->rx[qid].ntfy_id].napi; napi_disable(napi_rx); /* make sure current rx poll is done */ =20 + tx_qid =3D gve_xdp_tx_queue_id(priv, qid); napi_tx =3D &priv->ntfy_blocks[priv->tx[tx_qid].ntfy_id].napi; napi_disable(napi_tx); /* make sure current tx poll is done */ =20 @@ -1711,6 +1706,9 @@ static int gve_xsk_wakeup(struct net_device *dev, u32= queue_id, u32 flags) struct gve_priv *priv =3D netdev_priv(dev); int tx_queue_id =3D gve_xdp_tx_queue_id(priv, queue_id); =20 + if (!gve_get_napi_enabled(priv)) + return -ENETDOWN; + if (queue_id >=3D priv->rx_cfg.num_queues || !priv->xdp_prog) return -EINVAL; =20 --=20 2.47.1.613.gc27f4b7a9f-goog From nobody Thu Dec 18 09:48:56 2025 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 94B641D79BB for ; Wed, 18 Dec 2024 13:34:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734528875; cv=none; b=bTxXhmU97r2ZiqvWRW8zDd3MTnOl5frwC4Vu/B5Yb20AoOeJyBTe2R6w4hto6nxR2X64e2ZNOgEUxPUR6ab6oYOEB3ETk6+8h+6XXFy1IBBjfr/cgdjriDzE6ESwaUcXL4M+RXG5iXyS4GyZVn7cdybcPRI9QCaBQWcg/p/TBWo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734528875; c=relaxed/simple; bh=u3ksI8X3LHlmnWlWNsr7oSVKMPEqKsRuUTAg+bTe+00=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=nhdEIB11LPS52jrJm1VqBSGCb7X3CaFvbKQUED+KpezVr9ysMCqbjxob3vJLtBAr/lTiX1foJOs10agyMLX4et6/vqjSaWqPbDE+zTa8A36G0Y4ebBZz3kJ37Xlmuy8JBUWpc3kBUJX+4wiHHDrZe/EU7pEHCFZchDImCfeCbDk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--pkaligineedi.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=MPxc0dho; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--pkaligineedi.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MPxc0dho" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-21632eacb31so44351245ad.0 for ; Wed, 18 Dec 2024 05:34:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734528872; x=1735133672; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=YwlRUX1jaF5zrf3pwivF6X+hM80Z5phrYRTqYk/3DoI=; b=MPxc0dhofPFnXcILg06kG+YRGWPh4xf2Jay20u120zc0dKqN9UxHQ7AMA81rLhgXmb ZVqMkn/rIzJH0nSIiQQ3z+EjssO0gXN7iV27NaPDEAJCFAuRmo/JRJqgBG9KLyoExo/J zfXhn4kVlf4usRO89FOZIN7PrUnA0Ef20z6MIkhYvZFnQ/OutucxOUuFF1ilYZXAxC34 lOzOXJIZHHK6HRghsVoS79wZ4NEyWdcvCla3Bi3YeSb4PjzpTZslTx3cvvuIbCnWzR0c Y0pOr28Q+UKFULWe+0RbB/OS42OZ9BYI/7vy6OIBWu27DNVF2zOg8iZpVEGPpDiH1wVJ X1Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734528872; x=1735133672; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YwlRUX1jaF5zrf3pwivF6X+hM80Z5phrYRTqYk/3DoI=; b=humyTE8JPBGpX19Arq61UQmoBqQSxTp9gKtB+jMFEjlQLZzGgZ112pZSsJpTtRsme0 Ls/kRVf7FxR85EVoGXFjtwk5+HTzOvoNWMeEyjxzZXZvBCWppWrpRGZ8u+MmLv+n/NMJ Q0MEv20yLnu2VMnRbU9OGSROLCaWFcIvPXIBrCX6eImUfXcOsUOJFPbrh7b7xXLfd69e exzwwp+8m65Clp416KUrWB6JO4EPuU4LGi3Pecwo8xNicQl6xacy5grncn/gqQEFjKxv yzqn5pCaC1TgMvyRGzzWyxsDAeRReT9GdeleytNX6VaGgWiE1AAlKQ+8TQkDnCMS5gHH qf7g== X-Forwarded-Encrypted: i=1; AJvYcCVHJDPBoj8aPwY6cCNTjLtVEcnc0kFu5SeT3upxoHX6CZWwXrcd5xxPabDL05s4zslSbE5Tj1ZWCJjKzY4=@vger.kernel.org X-Gm-Message-State: AOJu0YwSJOz+CzQs8yT31jzABhuH2N6iFOxQzukPA+3F0kAwgANg9PQw Odzbm3lV64y/xoWJK3WCV5WGygYgkenf80km0BkLhB76Naqc6qicaDyxNPJH0TCtDJOlu2hIDNG D1I88eqc+3umHhuZLbl8gGEDRwQ== X-Google-Smtp-Source: AGHT+IGoZ3BfldQRegdOBvsvUntzPVMpURPuoWRCP2EtNiBtWfT4ejOfM4mqohMkYW+FU9E8z71bR23/h0c1KA2OAKc= X-Received: from pgid5.prod.google.com ([2002:a63:ed05:0:b0:7fd:5437:9912]) (user=pkaligineedi job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:dac6:b0:216:1ec6:9888 with SMTP id d9443c01a7336-218d72368afmr37261205ad.33.1734528871967; Wed, 18 Dec 2024 05:34:31 -0800 (PST) Date: Wed, 18 Dec 2024 05:34:14 -0800 In-Reply-To: <20241218133415.3759501-1-pkaligineedi@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241218133415.3759501-1-pkaligineedi@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241218133415.3759501-5-pkaligineedi@google.com> Subject: [PATCH net 4/5] gve: process XSK TX descriptors as part of RX NAPI From: Praveen Kaligineedi To: netdev@vger.kernel.org Cc: jeroendb@google.com, shailend@google.com, willemb@google.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, horms@kernel.org, hramamurthy@google.com, joshwash@google.com, ziweixiao@google.com, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, stable@vger.kernel.org, Praveen Kaligineedi Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Joshua Washington When busy polling is enabled, xsk_sendmsg for AF_XDP zero copy marks the NAPI ID corresponding to the memory pool allocated for the socket. In GVE, this NAPI ID will never correspond to a NAPI ID of one of the dedicated XDP TX queues registered with the umem because XDP TX is not set up to share a NAPI with a corresponding RX queue. This patch moves XSK TX descriptor processing from the TX NAPI to the RX NAPI, and the gve_xsk_wakeup callback is updated to use the RX NAPI instead of the TX NAPI, accordingly. The branch on if the wakeup is for TX is removed, as the NAPI poll should be invoked whether the wakeup is for TX or for RX. Fixes: fd8e40321a12 ("gve: Add AF_XDP zero-copy support for GQI-QPL format") Cc: stable@vger.kernel.org Signed-off-by: Praveen Kaligineedi Signed-off-by: Joshua Washington Reviewed-by: Willem de Bruijn --- drivers/net/ethernet/google/gve/gve.h | 1 + drivers/net/ethernet/google/gve/gve_main.c | 8 +++++ drivers/net/ethernet/google/gve/gve_tx.c | 36 +++++++++++++--------- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve.h b/drivers/net/ethernet/g= oogle/gve/gve.h index dd92949bb214..8167cc5fb0df 100644 --- a/drivers/net/ethernet/google/gve/gve.h +++ b/drivers/net/ethernet/google/gve/gve.h @@ -1140,6 +1140,7 @@ int gve_xdp_xmit_one(struct gve_priv *priv, struct gv= e_tx_ring *tx, void gve_xdp_tx_flush(struct gve_priv *priv, u32 xdp_qid); bool gve_tx_poll(struct gve_notify_block *block, int budget); bool gve_xdp_poll(struct gve_notify_block *block, int budget); +int gve_xsk_tx_poll(struct gve_notify_block *block, int budget); int gve_tx_alloc_rings_gqi(struct gve_priv *priv, struct gve_tx_alloc_rings_cfg *cfg); void gve_tx_free_rings_gqi(struct gve_priv *priv, diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ether= net/google/gve/gve_main.c index e4e8ff4f9f80..5cab7b88610f 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -333,6 +333,14 @@ int gve_napi_poll(struct napi_struct *napi, int budget) =20 if (block->rx) { work_done =3D gve_rx_poll(block, budget); + + /* Poll XSK TX as part of RX NAPI. Setup re-poll based on max of + * TX and RX work done. + */ + if (priv->xdp_prog) + work_done =3D max_t(int, work_done, + gve_xsk_tx_poll(block, budget)); + reschedule |=3D work_done =3D=3D budget; } =20 diff --git a/drivers/net/ethernet/google/gve/gve_tx.c b/drivers/net/etherne= t/google/gve/gve_tx.c index 852f8c7e39d2..4350ebd9c2bd 100644 --- a/drivers/net/ethernet/google/gve/gve_tx.c +++ b/drivers/net/ethernet/google/gve/gve_tx.c @@ -981,33 +981,41 @@ static int gve_xsk_tx(struct gve_priv *priv, struct g= ve_tx_ring *tx, return sent; } =20 +int gve_xsk_tx_poll(struct gve_notify_block *rx_block, int budget) +{ + struct gve_rx_ring *rx =3D rx_block->rx; + struct gve_priv *priv =3D rx->gve; + struct gve_tx_ring *tx; + int sent =3D 0; + + tx =3D &priv->tx[gve_xdp_tx_queue_id(priv, rx->q_num)]; + if (tx->xsk_pool) { + sent =3D gve_xsk_tx(priv, tx, budget); + + u64_stats_update_begin(&tx->statss); + tx->xdp_xsk_sent +=3D sent; + u64_stats_update_end(&tx->statss); + if (xsk_uses_need_wakeup(tx->xsk_pool)) + xsk_set_tx_need_wakeup(tx->xsk_pool); + } + + return sent; +} + bool gve_xdp_poll(struct gve_notify_block *block, int budget) { struct gve_priv *priv =3D block->priv; struct gve_tx_ring *tx =3D block->tx; u32 nic_done; - bool repoll; u32 to_do; =20 /* Find out how much work there is to be done */ nic_done =3D gve_tx_load_event_counter(priv, tx); to_do =3D min_t(u32, (nic_done - tx->done), budget); gve_clean_xdp_done(priv, tx, to_do); - repoll =3D nic_done !=3D tx->done; - - if (tx->xsk_pool) { - int sent =3D gve_xsk_tx(priv, tx, budget); - - u64_stats_update_begin(&tx->statss); - tx->xdp_xsk_sent +=3D sent; - u64_stats_update_end(&tx->statss); - repoll |=3D (sent =3D=3D budget); - if (xsk_uses_need_wakeup(tx->xsk_pool)) - xsk_set_tx_need_wakeup(tx->xsk_pool); - } =20 /* If we still have work we want to repoll */ - return repoll; + return nic_done !=3D tx->done; } =20 bool gve_tx_poll(struct gve_notify_block *block, int budget) --=20 2.47.1.613.gc27f4b7a9f-goog From nobody Thu Dec 18 09:48:56 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2844C1E9B2C for ; Wed, 18 Dec 2024 13:34:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734528877; cv=none; b=SEVrkwEAu0+kXWx4pxt8/eYbTt1tpatY/YCKdTouzd4QbJDZbYjtPVmDGFRTPzjAKaB+XEyd7ffGQVxLXNOaba3B4C7/ucSlrOOECLeA3rXuoRmPC6m1LiNyXRPVwp60Gk1Opu6z812ka8xL7fjecK8Cmr91bBBjTnU4+koYx88= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734528877; c=relaxed/simple; bh=5nW61vOKeFgt2Ca3diR0gPzoG2D8KLy0Ubznq3j8i3w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=YZ4fCVOPpeOXQ/jUBHUO8WMn3rX9upG118tnZ+QJEEQqLZ1NxoCZmomeoKnFc61nAwS/7RUMDVcqCn7mGWKv4FrCQDRrezbR04zpQFspbANLUFz4VVSSXlSPjeY0D9x1t3inOAdR0rQ67ktVuYA4ybygxSto4aUnoFv5Vtgw5iI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--pkaligineedi.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=xfz5QjC+; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--pkaligineedi.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="xfz5QjC+" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-8019860a003so4419011a12.1 for ; Wed, 18 Dec 2024 05:34:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734528873; x=1735133673; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=T5p6vlUBAsmQyOt8BuyoWsG+1hipC/LRRSVT0CsAjCw=; b=xfz5QjC+/jESiv2uFvLF7rUuOSlvdU5UBtL8Zkt4O0ZXCoAZdgPaXDdijcxVsWITru HcmSIsWy80R71wgIMCGdjrJeeDRX++FLMrlmeZLjS4oHGnjYypKkni4/blLGJxCEInth eip0fZuoxqh/nDopdSQzPsdp6RGkqFaFCbft0UsNrXDW2rUIlNhg+a93nXNc22tB0WcE 9UGJI/u/6mLWyg61qAA0Zv256zRIRNQtCTVHbg7/A6Gh0mtZ0KikFiDRi5++rsZC1SfX hsF4gs0h/yhycSJtQEg/bIWRs/ljOomEIPdn+IAuNv7FMUwJyP37DFdSwcBRpyd0FkU+ LgFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734528873; x=1735133673; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=T5p6vlUBAsmQyOt8BuyoWsG+1hipC/LRRSVT0CsAjCw=; b=VxuxlRes3Owy0TTTBgBxy/f2q7zCtLP9rhJyGA8KaXQoBbV1PTResw0igVZulf1Unw tJAiMiSwkTRdu+QcN4h+8EyDdNvOPdLU52g5Uq/6lFO98jJ1t8lEv4nAhCQ99Ap2YjJG FEGJThXG/2ma8vhRtjPteVsQ3B+DRtxsRFmwk0lgkJNA6X3Vvdgq+aTTxBUCe62T/8g+ 9scWubh3pNBntW+idhJM1wy19XRXqYtoDOhnExx2peb5ZdU8BURhBMvpj5YeXHmrC21N fGYYoQ57K8hMs8SvtXox2ZLcdxy4eUxEdignvKI++o1z4qdVr2Hdp65twXriXiSPajDP dUxw== X-Forwarded-Encrypted: i=1; AJvYcCVSfIQuzKXFy5YWkjOXpsdUWYNLKtX4mftmsmO6qeuZUu5cKtaOQAaE0fED6GJvwVo7sRr13lrko2nwDaE=@vger.kernel.org X-Gm-Message-State: AOJu0YwlpcZITdb861MgbpHa7ii4few4QX9MPSlbPMD8CKpriaQ3x4bk oR7ltJI4/ItSmCsNYtSx8Fy7bmwbbpb/WGIlRyoYSSxQ34bVVFAJcphqBBS8kILi1h8uPVghDBo DR3USWhTClMMxc2SSV8TW/V1gPg== X-Google-Smtp-Source: AGHT+IESNBKLCTm0uqLX+DRFxTtWjk+95d5i9mTaDJzn1eicqwfkpRcGBjtCrRCjQo4wMO7Q8jBDvY0A+fhe0GGi+qI= X-Received: from pjbqx3.prod.google.com ([2002:a17:90b:3e43:b0:2ee:4b69:50e1]) (user=pkaligineedi job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2b8f:b0:2ee:df57:b194 with SMTP id 98e67ed59e1d1-2f2e91fef48mr3520473a91.21.1734528873500; Wed, 18 Dec 2024 05:34:33 -0800 (PST) Date: Wed, 18 Dec 2024 05:34:15 -0800 In-Reply-To: <20241218133415.3759501-1-pkaligineedi@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241218133415.3759501-1-pkaligineedi@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241218133415.3759501-6-pkaligineedi@google.com> Subject: [PATCH net 5/5] gve: fix XDP allocation path in edge cases From: Praveen Kaligineedi To: netdev@vger.kernel.org Cc: jeroendb@google.com, shailend@google.com, willemb@google.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, horms@kernel.org, hramamurthy@google.com, joshwash@google.com, ziweixiao@google.com, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, stable@vger.kernel.org, Praveen Kaligineedi Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Joshua Washington This patch fixes a number of consistency issues in the queue allocation path related to XDP. As it stands, the number of allocated XDP queues changes in three different scenarios. 1) Adding an XDP program while the interface is up via gve_add_xdp_queues 2) Removing an XDP program while the interface is up via gve_remove_xdp_queues 3) After queues have been allocated and the old queue memory has been removed in gve_queues_start. However, the requirement for the interface to be up for gve_(add|remove)_xdp_queues to be called, in conjunction with the fact that the number of queues stored in priv isn't updated until _after_ XDP queues have been allocated in the normal queue allocation path means that if an XDP program is added while the interface is down, XDP queues won't be added until the _second_ if_up, not the first. Given the expectation that the number of XDP queues is equal to the number of RX queues, scenario (3) has another problematic implication. When changing the number of queues while an XDP program is loaded, the number of XDP queues must be updated as well, as there is logic in the driver (gve_xdp_tx_queue_id()) which relies on every RX queue having a corresponding XDP TX queue. However, the number of XDP queues stored in priv would not be updated until _after_ a close/open leading to a mismatch in the number of XDP queues reported vs the number of XDP queues which actually exist after the queue count update completes. This patch remedies these issues by doing the following: 1) The allocation config getter function is set up to retrieve the _expected_ number of XDP queues to allocate instead of relying on the value stored in `priv` which is only updated once the queues have been allocated. 2) When adjusting queues, XDP queues are adjusted to match the number of RX queues when XDP is enabled. This only works in the case when queues are live, so part (1) of the fix must still be available in the case that queues are adjusted when there is an XDP program and the interface is down. Fixes: 5f08cd3d6423 ("gve: Alloc before freeing when adjusting queues") Cc: stable@vger.kernel.org Signed-off-by: Joshua Washington Signed-off-by: Praveen Kaligineedi Reviewed-by: Praveen Kaligineedi Reviewed-by: Shailend Chand Reviewed-by: Willem de Bruijn --- drivers/net/ethernet/google/gve/gve_main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ether= net/google/gve/gve_main.c index 5cab7b88610f..09fb7f16f73e 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -930,11 +930,13 @@ static void gve_init_sync_stats(struct gve_priv *priv) static void gve_tx_get_curr_alloc_cfg(struct gve_priv *priv, struct gve_tx_alloc_rings_cfg *cfg) { + int num_xdp_queues =3D priv->xdp_prog ? priv->rx_cfg.num_queues : 0; + cfg->qcfg =3D &priv->tx_cfg; cfg->raw_addressing =3D !gve_is_qpl(priv); cfg->ring_size =3D priv->tx_desc_cnt; cfg->start_idx =3D 0; - cfg->num_rings =3D gve_num_tx_queues(priv); + cfg->num_rings =3D priv->tx_cfg.num_queues + num_xdp_queues; cfg->tx =3D priv->tx; } =20 @@ -1843,6 +1845,7 @@ int gve_adjust_queues(struct gve_priv *priv, { struct gve_tx_alloc_rings_cfg tx_alloc_cfg =3D {0}; struct gve_rx_alloc_rings_cfg rx_alloc_cfg =3D {0}; + int num_xdp_queues; int err; =20 gve_get_curr_alloc_cfgs(priv, &tx_alloc_cfg, &rx_alloc_cfg); @@ -1853,6 +1856,10 @@ int gve_adjust_queues(struct gve_priv *priv, rx_alloc_cfg.qcfg =3D &new_rx_config; tx_alloc_cfg.num_rings =3D new_tx_config.num_queues; =20 + /* Add dedicated XDP TX queues if enabled. */ + num_xdp_queues =3D priv->xdp_prog ? new_rx_config.num_queues : 0; + tx_alloc_cfg.num_rings +=3D num_xdp_queues; + if (netif_running(priv->dev)) { err =3D gve_adjust_config(priv, &tx_alloc_cfg, &rx_alloc_cfg); return err; --=20 2.47.1.613.gc27f4b7a9f-goog