From: sashiko-bot@kernel.org
To: "Long Li" <longli@microsoft.com>
Cc: linux-hyperv@vger.kernel.org
Subject: Re: [PATCH net-next 6/7] net: mana: support concurrent HWC requests with proper synchronization
Date: Thu, 16 Jul 2026 03:30:19 +0000 [thread overview]
Message-ID: <20260716033020.CC1B61F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260715032942.3945317-7-longli@microsoft.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Use-After-Free and waitqueue data corruption involving `gc->hwc_drain_waitq` due to flawed teardown logic and a race condition.
--
--- Patch [6]: [PATCH net-next 6/7] net: mana: support concurrent HWC requests with proper synchronization ---
commit c7a2831143a0268564f0b676313bc28bfee068e7
Author: Long Li <longli@microsoft.com>
net: mana: support concurrent HWC requests with proper synchronization
This patch replaces the depth-1 semaphore in the HWC with a waitqueue and
bitmap scheme to allow multiple in-flight requests. It introduces per-slot
synchronization, queue locks, and active sender tracking to serialize
channel teardown against concurrent requests.
> diff --git a/drivers/net/ethernet/microsoft/mana/gdma_main.c b/drivers/net/ethernet/microsoft/mana/gdma_main.c
> --- a/drivers/net/ethernet/microsoft/mana/gdma_main.c
> +++ b/drivers/net/ethernet/microsoft/mana/gdma_main.c
[ ... ]
> @@ -367,9 +371,25 @@ static int mana_gd_detect_devices(struct pci_dev *pdev)
> int mana_gd_send_request(struct gdma_context *gc, u32 req_len, const void *req,
> u32 resp_len, void *resp)
> {
> - struct hw_channel_context *hwc = gc->hwc.driver_data;
> + struct hw_channel_context *hwc;
> + unsigned long flags;
> + int err;
> +
> + spin_lock_irqsave(&gc->hwc_lock, flags);
> + hwc = gc->hwc.driver_data;
> + if (!hwc) {
> + spin_unlock_irqrestore(&gc->hwc_lock, flags);
> + return -ENODEV;
> + }
> + atomic_inc(&hwc->active_senders);
> + spin_unlock_irqrestore(&gc->hwc_lock, flags);
> +
> + err = mana_hwc_send_request(hwc, req_len, req, resp_len, resp);
>
> - return mana_hwc_send_request(hwc, req_len, req, resp_len, resp);
> + if (atomic_dec_and_test(&hwc->active_senders))
> + wake_up(&gc->hwc_drain_waitq);
[Severity: High]
Could this cause a use-after-free of the gdma_context (gc) structure?
If atomic_dec_and_test() drops the last reference and returns true, it
immediately unblocks the wait_event() in mana_hwc_destroy_channel(). The
teardown thread can then proceed and the caller (mana_gd_remove) might free
gc before this sender thread executes the wake_up() call on
gc->hwc_drain_waitq.
> + return err;
> }
> diff --git a/drivers/net/ethernet/microsoft/mana/hw_channel.c b/drivers/net/ethernet/microsoft/mana/hw_channel.c
> --- a/drivers/net/ethernet/microsoft/mana/hw_channel.c
> +++ b/drivers/net/ethernet/microsoft/mana/hw_channel.c
[ ... ]
> @@ -950,11 +1060,49 @@ void mana_hwc_destroy_channel(struct gdma_context *gc)
> hwc->setup_active = false;
> }
>
> + /* After SMC teardown, no more hardware events should arrive.
> + * Force-complete any remaining in-flight senders so they can
> + * exit and drop their refs.
> + */
> + if (hwc->caller_ctx) {
[ ... ]
> + }
> +
> + /* Wait for all sender threads to finish and drop their refs.
> + * After this, only slots held by timed-out senders whose
> + * handle_resp() never ran remain in the bitmap.
> + */
> + wait_event(gc->hwc_drain_waitq,
> + atomic_read(&hwc->active_senders) == 0);
[Severity: High]
What happens if the function level reset (FLR) fails during teardown?
Looking at mana_hwc_destroy_channel(), if pcie_flr() fails, it prints a
warning and returns early from the function. Because this early return
bypasses the newly added wait_event() logic above, any active sender
threads are abandoned.
When mana_gd_remove() subsequently frees gc, wouldn't these stranded
senders cause a use-after-free when they eventually time out and access
the freed gc->hwc_drain_waitq?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260715032942.3945317-1-longli@microsoft.com?part=6
next prev parent reply other threads:[~2026-07-16 3:30 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-15 3:29 [PATCH net-next 0/7] net: mana: harden the HWC and add dynamic queue depth Long Li
2026-07-15 3:29 ` [PATCH net-next 1/7] net: mana: RCU-protect gc->cq_table lookups against concurrent CQ destroy Long Li
2026-07-15 3:29 ` [PATCH net-next 2/7] net: mana: fix HWC RQ/SQ buffer size swap Long Li
2026-07-16 3:30 ` sashiko-bot
2026-07-15 3:29 ` [PATCH net-next 3/7] net: mana: free HWC comp_buf after destroying the EQ Long Li
2026-07-16 3:30 ` sashiko-bot
2026-07-15 3:29 ` [PATCH net-next 4/7] net: mana: validate hardware-supplied values in the HWC RX path Long Li
2026-07-16 3:30 ` sashiko-bot
2026-07-15 3:29 ` [PATCH net-next 5/7] net: mana: fix HWC teardown safety with setup_active flag and destroy ordering Long Li
2026-07-16 3:30 ` sashiko-bot
2026-07-15 3:29 ` [PATCH net-next 6/7] net: mana: support concurrent HWC requests with proper synchronization Long Li
2026-07-16 3:30 ` sashiko-bot [this message]
2026-07-15 3:29 ` [PATCH net-next 7/7] net: mana: add dynamic HWC queue depth with reinit path 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=20260716033020.CC1B61F000E9@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