BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Philipp Sudakas" <filzador@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net v3 2/5] vmxnet3: fix the error path of XDP program setup
Date: Thu, 26 Nov 2026 07:53:29 +0000	[thread overview]
Message-ID: <sashiko-outbox-234974@kernel.org> (raw)
In-Reply-To: <20261125075255.1517-3-filzador@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] vmxnet3: RTNL deadlock and missing RESETTING bit in
  vmxnet3_xdp_set()
--

commit 584df80e321cf69400a7b01cc8f4da9b076182a5
Author: Philipp Sudakas <filzador@gmail.com>

vmxnet3: fix the error path of XDP program setup

This commit reworks vmxnet3_xdp_set() to recover or close the interface when
recreating the RX queues or reactivating the device fails during XDP attach or
detach.

> diff --git a/drivers/net/vmxnet3/vmxnet3_xdp.c b/drivers/net/vmxnet3/vmxnet3_xdp.c
> index 5f470499e6002..a57866753d0fb 100644
> --- a/drivers/net/vmxnet3/vmxnet3_xdp.c
> +++ b/drivers/net/vmxnet3/vmxnet3_xdp.c
[ ... ]
> @@ -55,46 +72,61 @@ vmxnet3_xdp_set(struct net_device *netdev, struct netdev_bpf *bpf,
>  		adapter->netdev->features &= ~NETIF_F_LRO;
>  	}
>  
> -	old_bpf_prog = rcu_dereference(adapter->xdp_bpf_prog);
> +	old_bpf_prog = rtnl_dereference(adapter->xdp_bpf_prog);
>  	if (!new_bpf_prog && !old_bpf_prog)
>  		return 0;
>  
>  	running = netif_running(netdev);
>  	need_update = !!old_bpf_prog != !!new_bpf_prog;
>  
> -	if (running && need_update)
> -		vmxnet3_quiesce_dev(adapter);
> +	if (!running || !need_update) {
> +		vmxnet3_xdp_exchange_program(adapter, new_bpf_prog);
> +		goto done;
> +	}
>  
> +	vmxnet3_quiesce_dev(adapter);
>  	vmxnet3_xdp_exchange_program(adapter, new_bpf_prog);
> -	if (old_bpf_prog)
> -		bpf_prog_put(old_bpf_prog);
> -
> -	if (!running || !need_update)
> -		return 0;
> -
> -	if (new_bpf_prog)
> -		xdp_features_set_redirect_target(netdev, false);
> -	else
> -		xdp_features_clear_redirect_target(netdev);
> -
> -	vmxnet3_reset_dev(adapter);
> -	vmxnet3_rq_destroy_all(adapter);
> -	vmxnet3_adjust_rx_ring_size(adapter);
> -	err = vmxnet3_rq_create_all(adapter);
> -	if (err) {
> -		NL_SET_ERR_MSG_MOD(extack,
> -				   "failed to re-create rx queues for XDP.");
> -		return -EOPNOTSUPP;
> +	err = vmxnet3_xdp_restart_dev(adapter);
> +	if (err && new_bpf_prog) {
> +		/* Attach failed (old_bpf_prog is NULL here): the core drops
> +		 * its reference to the new program and keeps nothing
> +		 * attached. Bring the device back up without XDP.
> +		 */
> +		NL_SET_ERR_MSG_MOD(extack, "failed to restart device for XDP");
> +		vmxnet3_xdp_exchange_program(adapter, NULL);
> +		if (vmxnet3_xdp_restart_dev(adapter))
> +			goto err_close;
> +		return err;
>  	}
> -	err = vmxnet3_activate_dev(adapter);
>  	if (err) {
> -		NL_SET_ERR_MSG_MOD(extack,
> -				   "failed to activate device for XDP.");
> -		return -EOPNOTSUPP;
> +		/* Detach failed. The core may ignore an error here (XDP link
> +		 * release), so complete the detach on a closed device.
> +		 */
> +		netdev_err(netdev, "XDP removal failed to restart, closing\n");
> +		goto err_close;
>  	}
>  	clear_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state);
>  
> +done:
> +	if (need_update) {
> +		if (new_bpf_prog)
> +			xdp_features_set_redirect_target(netdev, false);
> +		else
> +			xdp_features_clear_redirect_target(netdev);
> +	}
> +	if (old_bpf_prog)
> +		bpf_prog_put(old_bpf_prog);
>  	return 0;
> +
> +err_close:
> +	/* The device is left quiesced, with IRQs freed and NAPI disabled,
> +	 * as vmxnet3_close() expects after a quiesce: close the interface.
> +	 * vmxnet3_force_close() would quiesce it and free the IRQs again.
> +	 */
> +	dev_close(netdev);
> +	if (new_bpf_prog)
> +		return err;
> +	goto done;
>  }

[Severity: Medium]
Can jumping to err_close deadlock on VMXNET3_STATE_BIT_RESETTING and
rtnl_lock?

vmxnet3_xdp_set() runs under rtnl_lock and clears VMXNET3_STATE_BIT_RESETTING
on the success path, but unlike vmxnet3_change_mtu() and
vmxnet3_set_ringparam() it never waits to acquire VMXNET3_STATE_BIT_RESETTING
before quiescing the device, nor clears it before calling dev_close():

CPU0                                  CPU1 (kworker)
vmxnet3_xdp_set()                     [rtnl_lock held]
  vmxnet3_quiesce_dev()
                                      vmxnet3_reset_work()
                                        test_and_set_bit(..._RESETTING)
                                        rtnl_lock()  <-- blocks
  vmxnet3_xdp_restart_dev() fails
  goto err_close
  dev_close()
    ...
      vmxnet3_close()
        while (test_and_set_bit(..._RESETTING))
          usleep_range(1000, 2000);  <-- spins forever

 *** DEADLOCK ***

Because vmxnet3_xdp_set() does not set VMXNET3_STATE_BIT_RESETTING on entry,
it also lacks serialization against paths such as vmxnet3_shutdown_device()
that rely on that bit without holding rtnl_lock, and can clear the bit on
the success path while another thread owns it.

Should vmxnet3_xdp_set() acquire VMXNET3_STATE_BIT_RESETTING with a
test_and_set_bit() loop before vmxnet3_quiesce_dev() and clear it on the
rollback and err_close paths before dev_close(), matching
vmxnet3_change_mtu()?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125075255.1517-1-filzador@gmail.com?part=2

  reply	other threads:[~2026-11-26  7:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  7:52 [PATCH net v3 0/5] vmxnet3: fix native XDP crash on oversized frames and XDP loss on reset Philipp Sudakas
2026-11-25  7:52 ` [PATCH net v3 1/5] vmxnet3: clear rx_ctx.skb after a data ring XDP verdict Philipp Sudakas
2026-11-25  7:52 ` [PATCH net v3 2/5] vmxnet3: fix the error path of XDP program setup Philipp Sudakas
2026-11-26  7:53   ` sashiko-bot [this message]
2026-11-25  7:52 ` [PATCH net v3 3/5] vmxnet3: limit the XDP MTU to the rx head buffer size Philipp Sudakas
2026-11-25  7:52 ` [PATCH net v3 4/5] vmxnet3: drop XDP frames that do not fit in one rx buffer Philipp Sudakas
2026-11-25  7:52 ` [PATCH net v3 5/5] vmxnet3: keep the XDP program across device resets Philipp Sudakas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-234974@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=filzador@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox