diff mbox series

[net] sfc: Don't invoke xdp_do_flush() from netpoll.

Message ID 20241002125837.utOcRo6Y@linutronix.de (mailing list archive)
State Accepted
Commit 55e802468e1d38dec8e25a2fdb6078d45b647e8c
Delegated to: Netdev Maintainers
Headers show
Series [net] sfc: Don't invoke xdp_do_flush() from netpoll. | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 9 this patch: 9
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 1 maintainers not CCed: ilias.apalodimas@linaro.org
netdev/build_clang success Errors and warnings before: 9 this patch: 9
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/checkpatch warning WARNING: Please use correct Fixes: style 'Fixes: <12 chars of sha1> ("<title line>")' - ie: 'Fixes: 401cb7dae813 ("net: Reference bpf_redirect_info via task_struct on PREEMPT_RT.")'
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-10-03--18-00 (tests: 772)

Commit Message

Sebastian Andrzej Siewior Oct. 2, 2024, 12:58 p.m. UTC
Yury reported a crash in the sfc driver originated from
netpoll_send_udp(). The netconsole sends a message and then netpoll
invokes the driver's NAPI function with a budget of zero. It is
dedicated to allow driver to free TX resources, that it may have used
while sending the packet.

In the netpoll case the driver invokes xdp_do_flush() unconditionally,
leading to crash because bpf_net_context was never assigned.

Invoke xdp_do_flush() only if budget is not zero.

Fixes: 401cb7dae8130 ("net: Reference bpf_redirect_info via task_struct on PREEMPT_RT.")
Reported-by: Yury Vostrikov <mon@unformed.ru>
Closes: https://lore.kernel.org/5627f6d1-5491-4462-9d75-bc0612c26a22@app.fastmail.com
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 drivers/net/ethernet/sfc/efx_channels.c       | 3 ++-
 drivers/net/ethernet/sfc/siena/efx_channels.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

Comments

Edward Cree Oct. 2, 2024, 1:36 p.m. UTC | #1
On 02/10/2024 13:58, Sebastian Andrzej Siewior wrote:
> Yury reported a crash in the sfc driver originated from
> netpoll_send_udp(). The netconsole sends a message and then netpoll
> invokes the driver's NAPI function with a budget of zero. It is
> dedicated to allow driver to free TX resources, that it may have used
> while sending the packet.
> 
> In the netpoll case the driver invokes xdp_do_flush() unconditionally,
> leading to crash because bpf_net_context was never assigned.
> 
> Invoke xdp_do_flush() only if budget is not zero.
> 
> Fixes: 401cb7dae8130 ("net: Reference bpf_redirect_info via task_struct on PREEMPT_RT.")
> Reported-by: Yury Vostrikov <mon@unformed.ru>
> Closes: https://lore.kernel.org/5627f6d1-5491-4462-9d75-bc0612c26a22@app.fastmail.com
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Reviewed-by: Edward Cree <ecree.xilinx@gmail.com>
Jakub Kicinski Oct. 3, 2024, 10:44 p.m. UTC | #2
On Wed, 2 Oct 2024 14:58:37 +0200 Sebastian Andrzej Siewior wrote:
> Fixes: 401cb7dae8130 ("net: Reference bpf_redirect_info via task_struct on PREEMPT_RT.")

FTR I think this could have imploded even before, just a lot lower
probability.
patchwork-bot+netdevbpf@kernel.org Oct. 3, 2024, 10:50 p.m. UTC | #3
Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 2 Oct 2024 14:58:37 +0200 you wrote:
> Yury reported a crash in the sfc driver originated from
> netpoll_send_udp(). The netconsole sends a message and then netpoll
> invokes the driver's NAPI function with a budget of zero. It is
> dedicated to allow driver to free TX resources, that it may have used
> while sending the packet.
> 
> In the netpoll case the driver invokes xdp_do_flush() unconditionally,
> leading to crash because bpf_net_context was never assigned.
> 
> [...]

Here is the summary with links:
  - [net] sfc: Don't invoke xdp_do_flush() from netpoll.
    https://git.kernel.org/netdev/net/c/55e802468e1d

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/sfc/efx_channels.c b/drivers/net/ethernet/sfc/efx_channels.c
index c9e17a8208a90..f1723a6fb082b 100644
--- a/drivers/net/ethernet/sfc/efx_channels.c
+++ b/drivers/net/ethernet/sfc/efx_channels.c
@@ -1260,7 +1260,8 @@  static int efx_poll(struct napi_struct *napi, int budget)
 
 	spent = efx_process_channel(channel, budget);
 
-	xdp_do_flush();
+	if (budget)
+		xdp_do_flush();
 
 	if (spent < budget) {
 		if (efx_channel_has_rx_queue(channel) &&
diff --git a/drivers/net/ethernet/sfc/siena/efx_channels.c b/drivers/net/ethernet/sfc/siena/efx_channels.c
index a7346e965bfe7..d120b3c83ac07 100644
--- a/drivers/net/ethernet/sfc/siena/efx_channels.c
+++ b/drivers/net/ethernet/sfc/siena/efx_channels.c
@@ -1285,7 +1285,8 @@  static int efx_poll(struct napi_struct *napi, int budget)
 
 	spent = efx_process_channel(channel, budget);
 
-	xdp_do_flush();
+	if (budget)
+		xdp_do_flush();
 
 	if (spent < budget) {
 		if (efx_channel_has_rx_queue(channel) &&