When a data format change requires a smaller MTU, existing endpoints are shrunk by writing dev->mtu directly. No MTU notifiers run and userspace gets no link notification. Resize the endpoints with dev_set_mtu() so that the normal notifiers and link notifications are delivered. Notifiers may veto the change, in which case the request now fails. If resizing an endpoint fails, restore the endpoints which were already resized, ignoring any errors from the restore, so that a failed request does not leave their MTUs shrunk. Restoring the MTU does not recreate state which a notifier may have torn down while the endpoint was shrunk, such as IPv6 addresses. The data format is not yet published while the endpoints are resized, so the restore is validated against the format the endpoints were sized for. The error from the failing dev_set_mtu() call is returned to the caller. Fixes: b7f5eb6ba21b ("net: qualcomm: rmnet: Update rmnet device MTU based on real device") Co-developed-by: Sean Tranchetti <sean…@oss.qualcomm.com> Signed-off-by: Sean Tranchetti <sean…@oss.qualcomm.com> Signed-off-by: Subash Abhinov Kasiviswanathan <suba…@oss.qualcomm.com> --- v6: Update the coding style in rmnet_vnd_update_dev_mtu() to align better with Networking code as mentioned by Simon Horman. v5: https://lore.kernel.org/all/2026…@oss.qualcomm.com/ .../ethernet/qualcomm/rmnet/rmnet_config.h | 1 + .../net/ethernet/qualcomm/rmnet/rmnet_vnd.c | 26 ++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h index 5adda0323dda..47b8db3206b9 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h @@ -19,6 +19,7 @@ struct rmnet_endpoint { struct net_device *egress_dev; struct hlist_node hlnode; struct rcu_head rcu; + int saved_mtu; }; struct rmnet_egress_agg_params { diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c index defad78ff598..ea08c71e0e35 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c @@ -433,6 +433,7 @@ int rmnet_vnd_validate_real_dev_mtu(struct net_device *real_dev) int rmnet_vnd_update_dev_mtu(struct rmnet_port *port, struct net_device *real_dev, u32 data_format) { + struct rmnet_endpoint *fail_ep; struct hlist_node *tmp_ep; struct rmnet_endpoint *ep; unsigned long bkt_ep; @@ -444,13 +445,30 @@ int rmnet_vnd_update_dev_mtu(struct rmnet_port *port, return new_mtu; hash_for_each_safe(port->muxed_ep, bkt_ep, tmp_ep, ep, hlnode) { - if (ep->egress_dev->mtu <= new_mtu) + ep->saved_mtu = ep->egress_dev->mtu; + if (ep->saved_mtu <= new_mtu) continue; - err = rmnet_vnd_change_mtu(ep->egress_dev, new_mtu); - if (err) - return err; + err = dev_set_mtu(ep->egress_dev, new_mtu); + if (err) { + fail_ep = ep; + goto restore_mtu; + } } return 0; + +restore_mtu: + /* Restore the endpoints which were already resized. Failures here + * are ignored since the original error is the one to report. + */ + hash_for_each_safe(port->muxed_ep, bkt_ep, tmp_ep, ep, hlnode) { + if (ep == fail_ep) + break; + + if (ep->egress_dev->mtu != ep->saved_mtu) + dev_set_mtu(ep->egress_dev, ep->saved_mtu); + } + + return err; }
-- 2.34.1