From: sashiko-bot@kernel.org
To: "Wei Fang" <wei.fang@nxp.com>
Cc: imx@lists.linux.dev, Frank.Li@kernel.org
Subject: Re: [PATCH v3 net 5/9] net: enetc: fix race condition in VF MAC address configuration
Date: Sat, 30 May 2026 00:44:29 +0000 [thread overview]
Message-ID: <20260530004430.35E891F0089A@smtp.kernel.org> (raw)
In-Reply-To: <20260520064421.91569-6-wei.fang@nxp.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Incorrect MAC address programming on Big-Endian architectures due to the use of __raw_writel and __raw_writew.
--
commit 5639b35fec15cd95ac4b3347ba872a265e9e8d97
Author: Wei Fang <wei.fang@nxp.com>
net: enetc: fix race condition in VF MAC address configuration
This commit introduces a per-VF mutex to serialize access to vf_state and
hardware MAC register updates. This prevents a race condition between the
VF message handler and administrative VF MAC configuration from the host.
Link: https://sashiko.dev/#/patchset/20260511080805.2052495-1-wei.fang%40nxp.com
> diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
> index 09c6420408923..8e11a023d516b 100644
> --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c
> +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
> @@ -252,8 +252,12 @@ static int enetc_pf_set_vf_mac(struct net_device *ndev, int vf, u8 *mac)
> return -EADDRNOTAVAIL;
>
> vf_state = &pf->vf_state[vf];
> +
> + mutex_lock(&vf_state->lock);
> vf_state->flags |= ENETC_VF_FLAG_PF_SET_MAC;
> enetc_pf_set_primary_mac_addr(&priv->si->hw, vf + 1, mac);
[Severity: High]
This is a pre-existing issue, but does calling this function cause an
incorrect MAC address to be programmed on big-endian architectures?
Looking at the implementation of enetc_pf_set_primary_mac_addr():
static void enetc_pf_set_primary_mac_addr(struct enetc_hw *hw, int si,
const u8 *addr)
{
u32 upper = get_unaligned_le32(addr);
u16 lower = get_unaligned_le16(addr + 4);
__raw_writel(upper, hw->port + ENETC_PSIPMAR0(si));
__raw_writew(lower, hw->port + ENETC_PSIPMAR1(si));
}
The function parses the address using get_unaligned_le32() and
get_unaligned_le16(), which convert little-endian bytes to native CPU
byte order. It then writes these values using __raw_writel() and
__raw_writew().
Since the raw I/O accessors do not perform CPU-to-device endianness
byte-swapping, the CPU-endian values are written as-is to the device.
On big-endian architectures, would this cause the bytes to be reversed
from the hardware's perspective and corrupt the MAC address?
Could the driver use the standard writel() and writew() accessors, or
its own enetc_port_wr() wrapper, to ensure proper CPU-to-LE conversion?
> + mutex_unlock(&vf_state->lock);
> +
> return 0;
> }
>
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260520064421.91569-1-wei.fang@nxp.com?part=5
next prev parent reply other threads:[~2026-05-30 0:44 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-20 6:44 [PATCH v3 net 0/9] net: enetc: SR-IOV robustness and security fixes Wei Fang
2026-05-20 6:44 ` [PATCH v3 net 1/9] net: enetc: fix incorrect mailbox message status returned to VFs Wei Fang
2026-05-30 0:44 ` sashiko-bot
2026-05-20 6:44 ` [PATCH v3 net 2/9] net: enetc: fix missing error code when pf->vf_state allocation fails Wei Fang
2026-05-20 6:44 ` [PATCH v3 net 3/9] net: enetc: add ratelimiting to VF mailbox error messages Wei Fang
2026-05-20 6:44 ` [PATCH v3 net 4/9] net: enetc: fix TOCTOU race and validate VF MAC address Wei Fang
2026-05-20 6:44 ` [PATCH v3 net 5/9] net: enetc: fix race condition in VF MAC address configuration Wei Fang
2026-05-30 0:44 ` sashiko-bot [this message]
2026-05-20 6:44 ` [PATCH v3 net 6/9] net: enetc: fix DMA write to freed memory in enetc_msg_free_mbx() Wei Fang
2026-05-20 6:44 ` [PATCH v3 net 7/9] net: enetc: fix unbounded loop and interrupt handling in VF-to-PF messaging Wei Fang
2026-05-20 6:44 ` [PATCH v3 net 8/9] net: enetc: fix init and teardown order to prevent use of unsafe resources Wei Fang
2026-05-20 6:44 ` [PATCH v3 net 9/9] net: enetc: avoid VF->PF mailbox timeout during SR-IOV teardown Wei Fang
2026-05-21 16:00 ` [PATCH v3 net 0/9] net: enetc: SR-IOV robustness and security fixes patchwork-bot+netdevbpf
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=20260530004430.35E891F0089A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=imx@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
--cc=wei.fang@nxp.com \
/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