From: sashiko-bot@kernel.org
To: "Long Li" <longli@microsoft.com>
Cc: linux-hyperv@vger.kernel.org
Subject: Re: [PATCH net-next v2 07/13] net: mana: do not bail out of mana_detach on dealloc failure
Date: Fri, 14 Aug 2026 05:05:16 +0000 [thread overview]
Message-ID: <20260814050516.7629A1F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260813050418.2906468-8-longli@microsoft.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] The 'channel_changing' boolean flag is used as an ad-hoc lock to guard code sections and prevent concurrent access, violating kernel synchronization guidelines.
Pre-existing issues:
- [Critical] Hardware queue memory and RX page pools are freed while the device may still be DMAing to them if it fails to quiesce during teardown (DMA Use-After-Free).
--
--- Patch [7]: [PATCH net-next v2 07/13] net: mana: do not bail out of mana_detach on dealloc failure ---
commit 04170ba1361c402d70e39fad639e6d6455da30a2
Author: Dipayaan Roy <dipayanroy@linux.microsoft.com>
net: mana: do not bail out of mana_detach on dealloc failure
This commit modifies mana_detach() to remove the early return if
mana_dealloc_queues() fails. This ensures that the function completes its
full teardown, including netif_device_detach() and mana_cleanup_port_context(),
avoiding an inconsistent port state.
> diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c
> index e54ad4db918ce..2b3250483b439 100644
> --- a/drivers/net/ethernet/microsoft/mana/mana_en.c
> +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c
> @@ -4502,10 +4502,8 @@ int mana_detach(struct net_device *ndev, bool from_close)
>
> if (apc->port_st_save) {
> err = mana_dealloc_queues(ndev);
[Severity: Critical]
This is a pre-existing issue, but does mana_dealloc_queues() safely handle a
failure to quiesce the device?
If mana_drain_txqs() times out and pci_try_reset_function() fails, it skips
freeing the TX SKB buffers and returns false:
drivers/net/ethernet/microsoft/mana/mana_en.c:mana_drain_txqs() {
...
err = pci_try_reset_function(to_pci_dev(gd->gdma_context->dev));
if (err) {
netdev_err(apc->ndev,
"function reset failed: %d, %d pkts pending in txq %u\n",
err, atomic_read(&txq->pending_sends),
txq->gdma_txq_id);
quiesced = false;
...
if (!quiesced) {
netdev_err(apc->ndev,
"device not quiesced, leaking pending TX buffers instead of unmapping memory it can still DMA from\n");
return reset;
}
...
}
However, mana_dealloc_queues() ignores this false return value and proceeds
with the teardown:
drivers/net/ethernet/microsoft/mana/mana_en.c:mana_dealloc_queues() {
...
if (mana_drain_txqs(apc)) {
struct mana_context *ac = apc->ac;
unsigned int i;
...
/* Even in err case, still need to cleanup the vPort */
mana_destroy_rxqs(apc);
mana_destroy_txq(apc);
...
}
Because the device was never successfully quiesced, it remains active. Will
unconditionally freeing the GDMA SQ and RQ hardware ring buffers and RX page
pool buffers here lead to a DMA use-after-free when the hardware continues to
DMA read/write to the now-freed memory?
> - if (err) {
> + if (err)
> netdev_err(ndev, "%s failed to deallocate queues: %d\n", __func__, err);
> - return err;
> - }
> }
[Severity: High]
Is the channel_changing boolean flag being used as an ad-hoc lock to guard
code sections and prevent concurrent access?
drivers/net/ethernet/microsoft/mana/mana_ethtool.c:mana_set_ringparam() {
...
mutex_lock(&apc->vport_mutex);
if (apc->channel_changing) {
mutex_unlock(&apc->vport_mutex);
return -EBUSY;
}
apc->channel_changing = true;
mutex_unlock(&apc->vport_mutex);
...
}
Using a boolean flag to protect entire blocks of code bypasses standard kernel
locking mechanisms. This prevents lockdep from analyzing lock dependencies and
forces concurrent callers to fail with -EBUSY instead of gracefully waiting.
Could a proper mutex or rwsem be used here instead?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260813050418.2906468-1-longli@microsoft.com?part=7
next prev parent reply other threads:[~2026-08-14 5:05 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-13 5:04 [PATCH net-next v2 00/13] net: mana: reconfigure by replacing the queue set Long Li
2026-08-13 5:04 ` [PATCH net-next v2 01/13] net: mana: add queue-set allocation and teardown helpers Long Li
2026-08-14 5:05 ` sashiko-bot
2026-08-13 5:04 ` [PATCH net-next v2 02/13] net: mana: swap queue sets in mana_set_channels Long Li
2026-08-14 5:05 ` sashiko-bot
2026-08-13 5:04 ` [PATCH net-next v2 03/13] net: mana: swap queue sets in mana_set_ringparam Long Li
2026-08-14 5:05 ` sashiko-bot
2026-08-13 5:04 ` [PATCH net-next v2 04/13] net: mana: swap queue sets in mana_set_priv_flags Long Li
2026-08-14 5:05 ` sashiko-bot
2026-08-13 5:04 ` [PATCH net-next v2 05/13] net: mana: swap queue sets in mana_change_mtu Long Li
2026-08-14 5:05 ` sashiko-bot
2026-08-13 5:04 ` [PATCH net-next v2 06/13] net: mana: swap queue sets in mana_xdp_set Long Li
2026-08-13 5:04 ` [PATCH net-next v2 07/13] net: mana: do not bail out of mana_detach on dealloc failure Long Li
2026-08-14 5:05 ` sashiko-bot [this message]
2026-08-13 5:04 ` [PATCH net-next v2 08/13] net: mana: keep per-queue statistics in the port context Long Li
2026-08-14 5:05 ` sashiko-bot
2026-08-13 5:04 ` [PATCH net-next v2 09/13] net: mana: share the EQ pool across a queue-set swap Long Li
2026-08-13 5:04 ` [PATCH net-next v2 10/13] net: mana: release EQs left idle by a channel-count reduction Long Li
2026-08-13 5:04 ` [PATCH net-next v2 11/13] net: mana: keep a user-configured RSS table across a queue rebuild Long Li
2026-08-14 5:05 ` sashiko-bot
2026-08-13 5:04 ` [PATCH net-next v2 12/13] net: mana: keep the surviving queues when the channel count is reduced Long Li
2026-08-13 5:04 ` [PATCH net-next v2 13/13] net: mana: keep the existing queues when the channel count is raised Long Li
-- strict thread matches above, loose matches on Subject: below --
2026-08-11 6:34 [PATCH net-next v2 00/13] net: mana: reconfigure by replacing the queue set Long Li
2026-08-11 6:35 ` [PATCH net-next v2 07/13] net: mana: do not bail out of mana_detach on dealloc failure Long Li
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=20260814050516.7629A1F00A3D@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-hyperv@vger.kernel.org \
--cc=longli@microsoft.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