All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Fan Wu <fanwu01@zju.edu.cn>
Cc: netdev@vger.kernel.org, kys@microsoft.com,
	haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com,
	longli@microsoft.com, andrew+netdev@lunn.ch, davem@davemloft.net,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org, Song Li <songl@zju.edu.cn>
Subject: Re: [PATCH net v2] net: mana: fix reset work race with device removal
Date: Tue, 8 Sep 2026 12:22:57 +0100	[thread overview]
Message-ID: <20260908112257.GU40544@horms.kernel.org> (raw)
In-Reply-To: <20260905023602.425827-1-fanwu01@zju.edu.cn>

On Sat, Sep 05, 2026 at 02:36:02AM +0000, Fan Wu wrote:
> The reset service work is queued on the system workqueue and can
> outlive mana_gd_remove(), which frees the GDMA context. It may
> then dereference gc through the stale service work.
> 
> Embed the service work in gdma_context and make GC_IN_SERVICE describe
> whether it may still access gc. Removal and probe unwind close new
> admission with GC_REMOVING and wait for an admitted cycle to retire
> before clearing drvdata and freeing gc. Service exits retire before
> taking the PCI rescan/remove lock, avoiding a lock-cycle with remove.
> 
> Do not admit service work while probe is still constructing or
> unwinding the device. Latch reset events seen during probe and let
> the probe rollback/recovery path handle them; a boundary recheck
> preserves events racing probe completion.
> 
> The service work stays on the system workqueue because a reset cycle
> destroys and re-creates gc->service_wq.
> 
> This issue was found by an in-house static analysis tool.
> 
> Fixes: fbe346ce9d62 ("net: mana: Handle Reset Request from MANA NIC")
> Cc: stable@vger.kernel.org
> Assisted-by: Codex:gpt-5.6
> Co-developed-by: Song Li <songl@zju.edu.cn>
> Signed-off-by: Song Li <songl@zju.edu.cn>
> Signed-off-by: Fan Wu <fanwu01@zju.edu.cn>
> ---
> 
> Changes since v1 (<20260805143812.220509-1-fanwu01@zju.edu.cn>,
> https://lore.kernel.org/netdev/20260805143812.220509-1-fanwu01@zju.edu.cn):
> 
> - Dropped the device_lock() serialisation: holding the driver-core
>   device lock across mana_gd_suspend() + msleep() + mana_gd_resume()
>   blocks unbind, reboot, device PM and all PCI hotplug for up to a
>   full reset cycle, and can deadlock against the
>   flush_workqueue()/destroy_workqueue() of gc->service_wq.
> 
> - Replaced it with admission/drain gates: GC_REMOVING closes new
>   admission and the freeing paths wait for an admitted cycle to
>   retire (clear_bit_unlock/test_bit_acquire pairing) before clearing
>   drvdata and calling vfree(); the failed-resume rescan no longer
>   reopens admission, and mana_tx_timeout() also skips queue-reset
>   work during removal.
> 
> - No longer admit service work before the probe completes (the
>   reset-event handler no longer overloads GC_PROBE_SUCCEEDED with a
>   mid-probe latch); the FPGA reconfig exit and the probe-failure
>   recovery path are gated as well.
> 
> - Reference series for the HWC lifecycle model:
>   https://lore.kernel.org/netdev/20260813174243.3044348-1-longli@microsoft.com

Thanks for the updates and reference.

...

> @@ -2558,19 +2611,36 @@ static int mana_gd_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>  
>  	err = mana_rdma_probe(&gc->mana_ib);
>  	if (err)
> -		goto cleanup_mana;
> +		goto service_quiesce;
>  
>  	/*
>  	 * If a hardware reset event has occurred over HWC during probe,
> -	 * rollback and perform hardware reset procedure.
> +	 * rollback and perform hardware reset procedure.  Storing the
> +	 * success bit before the latch check pairs with the handler's
> +	 * latch-then-recheck, so an event racing probe completion is
> +	 * admitted rather than lost.
>  	 */
> -	if (test_and_set_bit(GC_PROBE_SUCCEEDED, &gc->flags)) {
> +	set_bit(GC_PROBE_SUCCEEDED, &gc->flags);
> +	if (test_and_set_bit(GC_SERVICE_DURING_PROBE, &gc->flags)) {
>  		err = -EPROTO;
> -		goto cleanup_mana_rdma;
> +		goto service_quiesce;
>  	}
>  
>  	return 0;
>  
> +service_quiesce:
> +	/* The stats work can admit a service cycle once mana_probe()
> +	 * has run: close admission and retire an in-flight cycle
> +	 * before any teardown, like mana_gd_remove() does.  Earlier
> +	 * failure points cannot have admitted service work.
> +	 */
> +	set_bit(GC_REMOVING, &gc->flags);
> +	/* Pairs with the ordered test_and_set_bit(GC_IN_SERVICE) in
> +	 * mana_schedule_serv_work().
> +	 */
> +	smp_mb__after_atomic();
> +	wait_var_event(&gc->flags,
> +		       !test_bit_acquire(GC_IN_SERVICE, &gc->flags));
>  cleanup_mana_rdma:
>  	mana_rdma_remove(&gc->mana_ib);
>  cleanup_mana:

The cleanup_mana_rdma and cleanup_mana labels are now unused.
They should be removed.

With that addressed feel free to add:
Reviewed-by: Simon Horman <horms@kernel.org>

...

      parent reply	other threads:[~2026-09-08 11:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-05  2:36 [PATCH net v2] net: mana: fix reset work race with device removal Fan Wu
2026-09-06  2:38 ` sashiko-bot
2026-09-08 11:20   ` Simon Horman
2026-09-08 11:22 ` Simon Horman [this message]

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=20260908112257.GU40544@horms.kernel.org \
    --to=horms@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=decui@microsoft.com \
    --cc=edumazet@google.com \
    --cc=fanwu01@zju.edu.cn \
    --cc=haiyangz@microsoft.com \
    --cc=kuba@kernel.org \
    --cc=kys@microsoft.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longli@microsoft.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=songl@zju.edu.cn \
    --cc=stable@vger.kernel.org \
    --cc=wei.liu@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.