From: "Zaiyu Wang" <zaiyuwang@trustnetic.com>
To: "'Stephen Hemminger'" <stephen@networkplumber.org>, <dev@dpdk.org>
Cc: <stable@dpdk.org>, "'Jiawen Wu'" <jiawenwu@trustnetic.com>
Subject: RE: [PATCH] net/txgbe: fix AML mailbox lock acquisition
Date: Fri, 22 May 2026 16:54:08 +0800 [thread overview]
Message-ID: <00a001dce9c8$8d5d3860$a817a920$@trustnetic.com> (raw)
In-Reply-To: <20260522050032.1354427-1-stephen@networkplumber.org>
> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: Friday, May 22, 2026 1:01 PM
> To: dev@dpdk.org; dev@dpdk.org
> Cc: Stephen Hemminger <stephen@networkplumber.org>; stable@dpdk.org;
> Jiawen Wu <jiawenwu@trustnetic.com>; Zaiyu Wang
> <zaiyuwang@trustnetic.com>; Stephen Hemminger
> <stephen@networkplumber.org>; stable@dpdk.org; Jiawen Wu
> <jiawenwu@trustnetic.com>; Zaiyu Wang <zaiyuwang@trustnetic.com>
> Subject: [PATCH] net/txgbe: fix AML mailbox lock acquisition
>
> The try-lock spin loop in txgbe_host_interface_command_aml() has the
condition
> inverted. rte_atomic32_test_and_set returns non-zero on successful
acquisition (0
> -> 1), zero when the lock was already held. Walk through the two cases:
>
> swfw_busy was 0 (free): test_and_set returns 1, sets to 1, loop
> body runs and sleeps 1ms. Next iteration finds 1, returns 0, loop
> exits. Lock held, after an unnecessary 1ms sleep.
>
> swfw_busy was 1 (busy): test_and_set returns 0, loop exits
> immediately. The caller proceeds without holding the lock,
> racing with the in-flight host interface command.
>
> Invert the condition so the loop spins while the lock remains held and
exits only
> when acquisition succeeds, matching the intent of the surrounding timeout
> machinery.
>
> Fixes: 6a139ade82e7 ("net/txgbe: add new SW-FW mailbox interface")
> Cc: stable@dpdk.org
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
> drivers/net/txgbe/base/txgbe_mng.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/txgbe/base/txgbe_mng.c
> b/drivers/net/txgbe/base/txgbe_mng.c
> index a1974820b6..dcd8f58a68 100644
> --- a/drivers/net/txgbe/base/txgbe_mng.c
> +++ b/drivers/net/txgbe/base/txgbe_mng.c
> @@ -185,7 +185,7 @@ txgbe_host_interface_command_aml(struct txgbe_hw
> *hw, u32 *buffer,
> }
>
> /* try to get lock */
> - while (rte_atomic32_test_and_set(&hw->swfw_busy)) {
> + while (rte_atomic32_test_and_set(&hw->swfw_busy) == 0) {
> timeout--;
> if (!timeout)
> return TXGBE_ERR_TIMEOUT;
> --
> 2.53.0
Thanks for the patch and the detailed analysis.
The fix is correct. This code was originally ported from our out-of-tree
Linux kernel driver, where it used a classic test_and_set_bit() that returns
the old bit value (0 on success). When adapting it for DPDK, we overlooked
that rte_atomic32_test_and_set() returns the opposite semantic.
Acked-by: Zaiyu Wang <zaiyuwang@trustnetic.com>
prev parent reply other threads:[~2026-05-22 8:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-22 5:00 [PATCH] net/txgbe: fix AML mailbox lock acquisition Stephen Hemminger
2026-05-22 8:54 ` Zaiyu Wang [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='00a001dce9c8$8d5d3860$a817a920$@trustnetic.com' \
--to=zaiyuwang@trustnetic.com \
--cc=dev@dpdk.org \
--cc=jiawenwu@trustnetic.com \
--cc=stable@dpdk.org \
--cc=stephen@networkplumber.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox