public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] net: mana: Improve mana_set_channels() for low mem conditions
@ 2024-08-29 14:16 Shradha Gupta
  2024-08-29 19:54 ` Gerhard Engleder
  0 siblings, 1 reply; 4+ messages in thread
From: Shradha Gupta @ 2024-08-29 14:16 UTC (permalink / raw)
  To: linux-hyperv, netdev, linux-kernel, linux-rdma
  Cc: Shradha Gupta, K. Y. Srinivasan, Haiyang Zhang, Wei Liu,
	Dexuan Cui, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Long Li, Simon Horman, Konstantin Taranov,
	Souradeep Chakrabarti, Erick Archer, Pavan Chebbi, Ahmed Zaki,
	Colin Ian King, Shradha Gupta

The mana_set_channels() function requires detaching the mana
driver and reattaching it with changed channel values.
During this operation if the system is low on memory, the reattach
might fail, causing the network device being down.
To avoid this we pre-allocate buffers at the beginning of set operation,
to prevent complete network loss

Signed-off-by: Shradha Gupta <shradhagupta@linux.microsoft.com>
---
 .../ethernet/microsoft/mana/mana_ethtool.c    | 28 +++++++++++--------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/microsoft/mana/mana_ethtool.c b/drivers/net/ethernet/microsoft/mana/mana_ethtool.c
index d6a35fbda447..5077493fdfde 100644
--- a/drivers/net/ethernet/microsoft/mana/mana_ethtool.c
+++ b/drivers/net/ethernet/microsoft/mana/mana_ethtool.c
@@ -345,27 +345,31 @@ static int mana_set_channels(struct net_device *ndev,
 	struct mana_port_context *apc = netdev_priv(ndev);
 	unsigned int new_count = channels->combined_count;
 	unsigned int old_count = apc->num_queues;
-	int err, err2;
+	int err;
+
+	apc->num_queues = new_count;
+	err = mana_pre_alloc_rxbufs(apc, ndev->mtu);
+	apc->num_queues = old_count;
+	if (err) {
+		netdev_err(ndev, "Insufficient memory for new allocations");
+		return err;
+	}
 
 	err = mana_detach(ndev, false);
 	if (err) {
 		netdev_err(ndev, "mana_detach failed: %d\n", err);
-		return err;
+		goto out;
 	}
 
 	apc->num_queues = new_count;
 	err = mana_attach(ndev);
-	if (!err)
-		return 0;
-
-	netdev_err(ndev, "mana_attach failed: %d\n", err);
-
-	/* Try to roll it back to the old configuration. */
-	apc->num_queues = old_count;
-	err2 = mana_attach(ndev);
-	if (err2)
-		netdev_err(ndev, "mana re-attach failed: %d\n", err2);
+	if (err) {
+		apc->num_queues = old_count;
+		netdev_err(ndev, "mana_attach failed: %d\n", err);
+	}
 
+out:
+	mana_pre_dealloc_rxbufs(apc);
 	return err;
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-08-30  5:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-29 14:16 [PATCH net-next] net: mana: Improve mana_set_channels() for low mem conditions Shradha Gupta
2024-08-29 19:54 ` Gerhard Engleder
2024-08-29 21:00   ` Haiyang Zhang
2024-08-30  5:13     ` Shradha Gupta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox