* [PATCH net v3] net: thunderx: avoid direct MTU assignment after WRITE_ONCE()
@ 2025-07-06 19:43 Alok Tiwari
2025-07-09 22:35 ` Jacob Keller
2025-07-10 2:30 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Alok Tiwari @ 2025-07-06 19:43 UTC (permalink / raw)
To: sgoutham, andrew+netdev, davem, edumazet, kuba, pabeni, horms,
netdev
Cc: alok.a.tiwari, linux-arm-kernel, darren.kenny, linux-kernel
The current logic in nicvf_change_mtu() writes the new MTU to
netdev->mtu using WRITE_ONCE() before verifying if the hardware
update succeeds. However on hardware update failure, it attempts
to revert to the original MTU using a direct assignment
(netdev->mtu = orig_mtu)
which violates the intended of WRITE_ONCE protection introduced in
commit 1eb2cded45b3 ("net: annotate writes on dev->mtu from
ndo_change_mtu()")
Additionally, WRITE_ONCE(netdev->mtu, new_mtu) is unnecessarily
performed even when the device is not running.
Fix this by:
Only writing netdev->mtu after successfully updating the hardware.
Skipping hardware update when the device is down, and setting MTU
directly. Remove unused variable orig_mtu.
This ensures that all writes to netdev->mtu are consistent with
WRITE_ONCE expectations and avoids unintended state corruption
on failure paths.
Signed-off-by: Alok Tiwari <alok.a.tiwari@oracle.com>
---
v2 -> v3
https://lore.kernel.org/all/20250630111836.GE41770@horms.kernel.org/
Simplify code as suggested by Simon
---
drivers/net/ethernet/cavium/thunder/nicvf_main.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/drivers/net/ethernet/cavium/thunder/nicvf_main.c b/drivers/net/ethernet/cavium/thunder/nicvf_main.c
index aebb9fef3f6eb..1be2dc40a1a63 100644
--- a/drivers/net/ethernet/cavium/thunder/nicvf_main.c
+++ b/drivers/net/ethernet/cavium/thunder/nicvf_main.c
@@ -1578,7 +1578,6 @@ int nicvf_open(struct net_device *netdev)
static int nicvf_change_mtu(struct net_device *netdev, int new_mtu)
{
struct nicvf *nic = netdev_priv(netdev);
- int orig_mtu = netdev->mtu;
/* For now just support only the usual MTU sized frames,
* plus some headroom for VLAN, QinQ.
@@ -1589,15 +1588,10 @@ static int nicvf_change_mtu(struct net_device *netdev, int new_mtu)
return -EINVAL;
}
- WRITE_ONCE(netdev->mtu, new_mtu);
-
- if (!netif_running(netdev))
- return 0;
-
- if (nicvf_update_hw_max_frs(nic, new_mtu)) {
- netdev->mtu = orig_mtu;
+ if (netif_running(netdev) && nicvf_update_hw_max_frs(nic, new_mtu))
return -EINVAL;
- }
+
+ WRITE_ONCE(netdev->mtu, new_mtu);
return 0;
}
--
2.46.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net v3] net: thunderx: avoid direct MTU assignment after WRITE_ONCE()
2025-07-06 19:43 [PATCH net v3] net: thunderx: avoid direct MTU assignment after WRITE_ONCE() Alok Tiwari
@ 2025-07-09 22:35 ` Jacob Keller
2025-07-10 2:30 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Jacob Keller @ 2025-07-09 22:35 UTC (permalink / raw)
To: Alok Tiwari, sgoutham, andrew+netdev, davem, edumazet, kuba,
pabeni, horms, netdev
Cc: linux-arm-kernel, darren.kenny, linux-kernel
[-- Attachment #1.1: Type: text/plain, Size: 1100 bytes --]
On 7/6/2025 12:43 PM, Alok Tiwari wrote:
> The current logic in nicvf_change_mtu() writes the new MTU to
> netdev->mtu using WRITE_ONCE() before verifying if the hardware
> update succeeds. However on hardware update failure, it attempts
> to revert to the original MTU using a direct assignment
> (netdev->mtu = orig_mtu)
> which violates the intended of WRITE_ONCE protection introduced in
> commit 1eb2cded45b3 ("net: annotate writes on dev->mtu from
> ndo_change_mtu()")
>
> Additionally, WRITE_ONCE(netdev->mtu, new_mtu) is unnecessarily
> performed even when the device is not running.
>
> Fix this by:
> Only writing netdev->mtu after successfully updating the hardware.
> Skipping hardware update when the device is down, and setting MTU
> directly. Remove unused variable orig_mtu.
>
> This ensures that all writes to netdev->mtu are consistent with
> WRITE_ONCE expectations and avoids unintended state corruption
> on failure paths.
>
> Signed-off-by: Alok Tiwari <alok.a.tiwari@oracle.com>
> ---
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net v3] net: thunderx: avoid direct MTU assignment after WRITE_ONCE()
2025-07-06 19:43 [PATCH net v3] net: thunderx: avoid direct MTU assignment after WRITE_ONCE() Alok Tiwari
2025-07-09 22:35 ` Jacob Keller
@ 2025-07-10 2:30 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-07-10 2:30 UTC (permalink / raw)
To: Alok Tiwari
Cc: sgoutham, andrew+netdev, davem, edumazet, kuba, pabeni, horms,
netdev, linux-arm-kernel, darren.kenny, linux-kernel
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Sun, 6 Jul 2025 12:43:21 -0700 you wrote:
> The current logic in nicvf_change_mtu() writes the new MTU to
> netdev->mtu using WRITE_ONCE() before verifying if the hardware
> update succeeds. However on hardware update failure, it attempts
> to revert to the original MTU using a direct assignment
> (netdev->mtu = orig_mtu)
> which violates the intended of WRITE_ONCE protection introduced in
> commit 1eb2cded45b3 ("net: annotate writes on dev->mtu from
> ndo_change_mtu()")
>
> [...]
Here is the summary with links:
- [net,v3] net: thunderx: avoid direct MTU assignment after WRITE_ONCE()
https://git.kernel.org/netdev/net/c/849704b8b211
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-10 2:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-06 19:43 [PATCH net v3] net: thunderx: avoid direct MTU assignment after WRITE_ONCE() Alok Tiwari
2025-07-09 22:35 ` Jacob Keller
2025-07-10 2:30 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).