mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Subash Abhinov Kasiviswanathan <subash.a.kasiviswanathan@oss.qualcomm.com>
To: sean.tranchetti@oss.qualcomm.com, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Subash Abhinov Kasiviswanathan
	<subash.a.kasiviswanathan@oss.qualcomm.com>
Subject: [PATCH net v5 4/5] net: qualcomm: rmnet: Publish data format and mux_id only after the MTU update
Date: Mon, 16 Nov 2026 22:07:37 -0800	[thread overview]
Message-ID: <20261117060737.2764327-5-subash.a.kasiviswanathan@oss.qualcomm.com> (raw)
In-Reply-To: <20261117060737.2764327-1-subash.a.kasiviswanathan@oss.qualcomm.com>

rmnet_changelink() publishes the new shared data format before
resizing the endpoints and reverts it if the resize fails, so the
datapath can briefly observe a format whose headers do not fit the
MTUs. A mux_id change requested in the same call is also applied before
the resize, so it is kept even though the call returned an error.

rmnet_newlink() never resized the existing devices at all, so a flags
change which increases the egress headroom left them with an MTU that
is too large for the real device.

Compute the new data format locally and pass it to
rmnet_vnd_update_dev_mtu(). In both rmnet_changelink() and
rmnet_newlink(), publish the format only after all MTUs have been
updated so that no revert is needed. rmnet_changelink() also moves the
endpoint to the new mux_id last, once the checks and the MTU update have
succeeded, so that a failed request leaves no partial change behind.
Return the error from the failing MTU change instead of -1.

Fixes: b7f5eb6ba21b ("net: qualcomm: rmnet: Update rmnet device MTU based on real device")
Co-developed-by: Sean Tranchetti <sean.tranchetti@oss.qualcomm.com>
Signed-off-by: Sean Tranchetti <sean.tranchetti@oss.qualcomm.com>
Signed-off-by: Subash Abhinov Kasiviswanathan <subash.a.kasiviswanathan@oss.qualcomm.com>
---
 .../ethernet/qualcomm/rmnet/rmnet_config.c    | 58 ++++++++++++-------
 .../net/ethernet/qualcomm/rmnet/rmnet_vnd.c   | 10 ++--
 .../net/ethernet/qualcomm/rmnet/rmnet_vnd.h   |  2 +-
 3 files changed, 44 insertions(+), 26 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c
index 40544b75e602..9e66f3804de4 100644
--- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c
+++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c
@@ -171,6 +171,13 @@ static int rmnet_newlink(struct net_device *dev,
 	if (err < 0)
 		goto err2;
 
+	/* Update existing MTUs before publishing the shared data format. */
+	err = rmnet_vnd_update_dev_mtu(port, real_dev, data_format);
+	if (err) {
+		NL_SET_ERR_MSG_MOD(extack, "Failed to update MTU of rmnet devices");
+		goto err3;
+	}
+
 	port->rmnet_mode = mode;
 	port->rmnet_dev = dev;
 
@@ -181,6 +188,8 @@ static int rmnet_newlink(struct net_device *dev,
 
 	return 0;
 
+err3:
+	netdev_upper_dev_unlink(real_dev, dev);
 err2:
 	unregister_netdevice(dev);
 	rmnet_vnd_dellink(mux_id, port, ep);
@@ -302,9 +311,14 @@ static int rmnet_changelink(struct net_device *dev, struct nlattr *tb[],
 			    struct netlink_ext_ack *extack)
 {
 	struct rmnet_priv *priv = netdev_priv(dev);
+	struct rmnet_endpoint *ep = NULL;
+	struct ifla_rmnet_flags *flags;
 	struct net_device *real_dev;
 	struct rmnet_port *port;
+	u32 old_data_format;
+	u32 data_format;
 	u16 mux_id;
+	int err;
 
 	if (!dev)
 		return -ENODEV;
@@ -321,12 +335,17 @@ static int rmnet_changelink(struct net_device *dev, struct nlattr *tb[],
 
 	port = rmnet_get_port_rtnl(real_dev);
 
+	if (data[IFLA_RMNET_FLAGS]) {
+		old_data_format = READ_ONCE(port->data_format);
+		flags = nla_data(data[IFLA_RMNET_FLAGS]);
+		data_format = old_data_format & ~flags->mask;
+		data_format |= flags->flags & flags->mask;
+	}
+
 	if (data[IFLA_RMNET_MUX_ID]) {
 		mux_id = nla_get_u16(data[IFLA_RMNET_MUX_ID]);
 
 		if (mux_id != priv->mux_id) {
-			struct rmnet_endpoint *ep;
-
 			ep = rmnet_get_endpoint(port, priv->mux_id);
 			if (!ep)
 				return -ENODEV;
@@ -336,32 +355,29 @@ static int rmnet_changelink(struct net_device *dev, struct nlattr *tb[],
 						   "MUX ID already exists");
 				return -EINVAL;
 			}
-
-			hlist_del_init_rcu(&ep->hlnode);
-			WRITE_ONCE(ep->mux_id, mux_id);
-			hlist_add_head_rcu(&ep->hlnode,
-					   &port->muxed_ep[mux_id]);
-
-			WRITE_ONCE(priv->mux_id, mux_id);
 		}
 	}
 
 	if (data[IFLA_RMNET_FLAGS]) {
-		struct ifla_rmnet_flags *flags;
-		u32 old_data_format;
-		u32 data_format;
+		err = rmnet_vnd_update_dev_mtu(port, real_dev, data_format);
+		if (err) {
+			NL_SET_ERR_MSG_MOD(extack,
+					   "Failed to update MTU of rmnet devices");
+			return err;
+		}
 
-		old_data_format = port->data_format;
-		flags = nla_data(data[IFLA_RMNET_FLAGS]);
-		data_format = old_data_format & ~flags->mask;
-		data_format |= flags->flags & flags->mask;
 		WRITE_ONCE(port->data_format, data_format);
+	}
 
-		if (rmnet_vnd_update_dev_mtu(port, real_dev)) {
-			WRITE_ONCE(port->data_format, old_data_format);
-			NL_SET_ERR_MSG_MOD(extack, "Invalid MTU on real dev");
-			return -EINVAL;
-		}
+	/* Nothing below can fail, so move the endpoint only after all the
+	 * checks and the MTU update have succeeded.
+	 */
+	if (ep) {
+		hlist_del_init_rcu(&ep->hlnode);
+		WRITE_ONCE(ep->mux_id, mux_id);
+		hlist_add_head_rcu(&ep->hlnode, &port->muxed_ep[mux_id]);
+
+		WRITE_ONCE(priv->mux_id, mux_id);
 	}
 
 	return 0;
diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c
index 2f3fefe58bce..8bf87c5ecb43 100644
--- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c
+++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c
@@ -431,14 +431,15 @@ 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)
+			     struct net_device *real_dev, u32 data_format)
 {
 	struct hlist_node *tmp_ep;
 	struct rmnet_endpoint *ep;
 	unsigned long bkt_ep;
 	int new_mtu;
+	int err;
 
-	new_mtu = rmnet_vnd_target_mtu(real_dev, READ_ONCE(port->data_format));
+	new_mtu = rmnet_vnd_target_mtu(real_dev, data_format);
 	if (new_mtu < 0)
 		return new_mtu;
 
@@ -446,8 +447,9 @@ int rmnet_vnd_update_dev_mtu(struct rmnet_port *port,
 		if (ep->egress_dev->mtu <= new_mtu)
 			continue;
 
-		if (rmnet_vnd_change_mtu(ep->egress_dev, new_mtu))
-			return -1;
+		err = rmnet_vnd_change_mtu(ep->egress_dev, new_mtu);
+		if (err)
+			return err;
 	}
 
 	return 0;
diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.h b/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.h
index 5d54c24f5c8c..901ef36900ac 100644
--- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.h
+++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.h
@@ -21,5 +21,5 @@ void rmnet_vnd_tx_fixup(struct sk_buff *skb, struct net_device *dev);
 void rmnet_vnd_setup(struct net_device *dev);
 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);
+			     struct net_device *real_dev, u32 data_format);
 #endif /* _RMNET_VND_H_ */
-- 
2.34.1


  parent reply	other threads:[~2026-11-17  6:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17  6:07 [PATCH net v5 0/5] net: qualcomm: rmnet: Update MTU handling during format changes Subash Abhinov Kasiviswanathan
2026-11-17  6:07 ` [PATCH net v5 1/5] net: qualcomm: rmnet: Account for V5 checksum header in headroom Subash Abhinov Kasiviswanathan
2026-11-17  6:07 ` [PATCH net v5 2/5] net: qualcomm: rmnet: Size the first device from the requested data format Subash Abhinov Kasiviswanathan
2026-11-21  7:04   ` netdev-bot+sashiko
2026-11-17  6:07 ` [PATCH net v5 3/5] net: qualcomm: rmnet: Fix MTU underflow and clamp to the maximum packet size Subash Abhinov Kasiviswanathan
2026-11-21  7:04   ` netdev-bot+sashiko
2026-11-17  6:07 ` Subash Abhinov Kasiviswanathan [this message]
2026-11-17  6:07 ` [PATCH net v5 5/5] net: qualcomm: rmnet: Resize endpoints with dev_set_mtu() and restore on failure Subash Abhinov Kasiviswanathan
2026-11-21  7:04   ` netdev-bot+sashiko

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=20261117060737.2764327-5-subash.a.kasiviswanathan@oss.qualcomm.com \
    --to=subash.a.kasiviswanathan@oss.qualcomm.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sean.tranchetti@oss.qualcomm.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

all inboxes | Powered by JetHome®