drivers/net/ethernet/cavium/thunder/nicvf_main.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
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.
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>
---
Note: This change is not tested due to hardware availability.
---
drivers/net/ethernet/cavium/thunder/nicvf_main.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/cavium/thunder/nicvf_main.c b/drivers/net/ethernet/cavium/thunder/nicvf_main.c
index aebb9fef3f6eb..ba26ba31a28bf 100644
--- a/drivers/net/ethernet/cavium/thunder/nicvf_main.c
+++ b/drivers/net/ethernet/cavium/thunder/nicvf_main.c
@@ -1589,16 +1589,18 @@ static int nicvf_change_mtu(struct net_device *netdev, int new_mtu)
return -EINVAL;
}
- WRITE_ONCE(netdev->mtu, new_mtu);
- if (!netif_running(netdev))
+ if (!netif_running(netdev)) {
+ WRITE_ONCE(netdev->mtu, new_mtu);
return 0;
+ }
if (nicvf_update_hw_max_frs(nic, new_mtu)) {
- netdev->mtu = orig_mtu;
return -EINVAL;
}
+ WRITE_ONCE(netdev->mtu, new_mtu);
+
return 0;
}
--
2.46.0
Hi Alok, kernel test robot noticed the following build warnings: [auto build test WARNING on net-next/main] [also build test WARNING on net/main linus/master v6.16-rc3 next-20250627] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Alok-Tiwari/net-thunderx-avoid-direct-MTU-assignment-after-WRITE_ONCE/20250628-175420 base: net-next/main patch link: https://lore.kernel.org/r/20250628095221.461991-1-alok.a.tiwari%40oracle.com patch subject: [PATCH] net: thunderx: avoid direct MTU assignment after WRITE_ONCE() config: x86_64-buildonly-randconfig-006-20250628 (https://download.01.org/0day-ci/archive/20250629/202506290114.0EPFmc8U-lkp@intel.com/config) compiler: gcc-12 (Debian 12.2.0-14+deb12u1) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250629/202506290114.0EPFmc8U-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202506290114.0EPFmc8U-lkp@intel.com/ All warnings (new ones prefixed by >>): drivers/net/ethernet/cavium/thunder/nicvf_main.c: In function 'nicvf_change_mtu': >> drivers/net/ethernet/cavium/thunder/nicvf_main.c:1581:13: warning: unused variable 'orig_mtu' [-Wunused-variable] 1581 | int orig_mtu = netdev->mtu; | ^~~~~~~~ vim +/orig_mtu +1581 drivers/net/ethernet/cavium/thunder/nicvf_main.c 4863dea3fab0173 Sunil Goutham 2015-05-26 1577 4863dea3fab0173 Sunil Goutham 2015-05-26 1578 static int nicvf_change_mtu(struct net_device *netdev, int new_mtu) 4863dea3fab0173 Sunil Goutham 2015-05-26 1579 { 4863dea3fab0173 Sunil Goutham 2015-05-26 1580 struct nicvf *nic = netdev_priv(netdev); f9aa9dc7d2d00e6 David S. Miller 2016-11-22 @1581 int orig_mtu = netdev->mtu; 4863dea3fab0173 Sunil Goutham 2015-05-26 1582 1f227d16083b2e2 Matteo Croce 2019-04-11 1583 /* For now just support only the usual MTU sized frames, 1f227d16083b2e2 Matteo Croce 2019-04-11 1584 * plus some headroom for VLAN, QinQ. 1f227d16083b2e2 Matteo Croce 2019-04-11 1585 */ 1f227d16083b2e2 Matteo Croce 2019-04-11 1586 if (nic->xdp_prog && new_mtu > MAX_XDP_MTU) { 1f227d16083b2e2 Matteo Croce 2019-04-11 1587 netdev_warn(netdev, "Jumbo frames not yet supported with XDP, current MTU %d.\n", 1f227d16083b2e2 Matteo Croce 2019-04-11 1588 netdev->mtu); 1f227d16083b2e2 Matteo Croce 2019-04-11 1589 return -EINVAL; 1f227d16083b2e2 Matteo Croce 2019-04-11 1590 } 1f227d16083b2e2 Matteo Croce 2019-04-11 1591 712c3185344050c Sunil Goutham 2016-11-15 1592 8be8a2ba18f34d5 Alok Tiwari 2025-06-28 1593 if (!netif_running(netdev)) { 8be8a2ba18f34d5 Alok Tiwari 2025-06-28 1594 WRITE_ONCE(netdev->mtu, new_mtu); 712c3185344050c Sunil Goutham 2016-11-15 1595 return 0; 8be8a2ba18f34d5 Alok Tiwari 2025-06-28 1596 } 712c3185344050c Sunil Goutham 2016-11-15 1597 f9aa9dc7d2d00e6 David S. Miller 2016-11-22 1598 if (nicvf_update_hw_max_frs(nic, new_mtu)) { 4863dea3fab0173 Sunil Goutham 2015-05-26 1599 return -EINVAL; f9aa9dc7d2d00e6 David S. Miller 2016-11-22 1600 } 4863dea3fab0173 Sunil Goutham 2015-05-26 1601 8be8a2ba18f34d5 Alok Tiwari 2025-06-28 1602 WRITE_ONCE(netdev->mtu, new_mtu); 8be8a2ba18f34d5 Alok Tiwari 2025-06-28 1603 4863dea3fab0173 Sunil Goutham 2015-05-26 1604 return 0; 4863dea3fab0173 Sunil Goutham 2015-05-26 1605 } 4863dea3fab0173 Sunil Goutham 2015-05-26 1606 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
© 2016 - 2025 Red Hat, Inc.