Skip to contentSkip to conversation

net: mana: Improve mana_set_channels() for low mem conditions

PATCH Superseded Shradha Gupta 3 participants 4 messages Aug 29, 2024 – Aug 30, 2024

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: mana: Improve mana_set_channels() for low mem conditions

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

---
 .../ethernet/microsoft/mana/mana_ethtool.c    | 28 +++++++++++--------
 1 file changed, 16 insertions(+), 12 deletions(-)
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +16 -12
index d6a35fbda447..5077493fdfde 100644
@@ -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;
 }
 
Signature · 1 line
2.34.1
maintainer
#2 lore raw
In reply to Gerhard Engleder
Quoted 57 lines

-----Original Message-----
From: Gerhard Engleder <[email protected]>
Sent: Thursday, August 29, 2024 3:54 PM
To: Shradha Gupta <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected]; [email protected]
Cc: KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; Wei Liu <[email protected]>; Dexuan Cui <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Long Li <[email protected]>; Simon Horman <[email protected]>; Konstantin Taranov <[email protected]>; Souradeep Chakrabarti <[email protected]>; Erick Archer <[email protected]>; Pavan Chebbi <[email protected]>; Ahmed Zaki <[email protected]>; Colin Ian King <[email protected]>; Shradha Gupta <[email protected]>
Subject: Re: [PATCH net-next] net: mana: Improve mana_set_channels() for low mem conditions

[Some people who received this message don't often get email from [email protected]. Learn why this is important at
https://aka.ms/LearnAboutSenderIdentification ]

Quoted 5 lines · 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,

Quoted 5 lines

to prevent complete network loss

---
  .../ethernet/microsoft/mana/mana_ethtool.c    | 28 +++++++++++-------

-

Review

Quoted 3 lines
  1 file changed, 16 insertions(+), 12 deletions(-)
(quoted diff) +0 -0

b/drivers/net/ethernet/microsoft/mana/mana_ethtool.c

drivers/net/ethernet/microsoft/mana/mana_ethtool.c static int mana_set_channels(struct net_device

Quoted 4 lines

index d6a35fbda447..5077493fdfde 100644

drivers/net/ethernet/microsoft/mana/mana_ethtool.c +0 -0
@@ -345,27 +345,31 @@ static int mana_set_channels(struct net_device

*ndev,

drivers/net/ethernet/microsoft/mana/mana_ethtool.c static int mana_set_channels(struct net_device *ndev, · line 352

Quoted 9 lines
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +5 -1
      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;
Quoted 3 lines

Are you sure that temporary changing num_queues has no side effects on other num_queues users like mana_chn_setxdp()?

mana_chn_setxdp() is protected by rtnl_lock, which is OK. But I'm not sure if all other users are protected. mana_get_stats64() seems not.

@Shradha Gupta You can add num_queues as an argument of mana_pre_alloc_rxbufs() to avoid changing apc->num_queues.

Thanks,
- Haiyang

#1 lore raw
In reply to Shradha Gupta
Quoted 17 lines · 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

---
  .../ethernet/microsoft/mana/mana_ethtool.c    | 28 +++++++++++--------
  1 file changed, 16 insertions(+), 12 deletions(-)
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +0 -0
index d6a35fbda447..5077493fdfde 100644

drivers/net/ethernet/microsoft/mana/mana_ethtool.c static int mana_set_channels(struct net_device *ndev, · line 352

Quoted 9 lines
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +5 -1
@@ -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;

Are you sure that temporary changing num_queues has no side effects on other num_queues users like mana_chn_setxdp()?

Gerhard

#3 lore raw
In reply to Haiyang Zhang
Quoted 61 lines · Haiyang Zhang
Quoted 57 lines

-----Original Message-----
From: Gerhard Engleder <[email protected]>
Sent: Thursday, August 29, 2024 3:54 PM
To: Shradha Gupta <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected]; [email protected]
Cc: KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; Wei Liu <[email protected]>; Dexuan Cui <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Long Li <[email protected]>; Simon Horman <[email protected]>; Konstantin Taranov <[email protected]>; Souradeep Chakrabarti <[email protected]>; Erick Archer <[email protected]>; Pavan Chebbi <[email protected]>; Ahmed Zaki <[email protected]>; Colin Ian King <[email protected]>; Shradha Gupta <[email protected]>
Subject: Re: [PATCH net-next] net: mana: Improve mana_set_channels() for low mem conditions

[Some people who received this message don't often get email from [email protected]. Learn why this is important at
https://aka.ms/LearnAboutSenderIdentification ]

Quoted 5 lines · 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,

Quoted 5 lines

to prevent complete network loss

---
  .../ethernet/microsoft/mana/mana_ethtool.c    | 28 +++++++++++-------

-

Review

Quoted 3 lines
  1 file changed, 16 insertions(+), 12 deletions(-)
(quoted diff) +0 -0

b/drivers/net/ethernet/microsoft/mana/mana_ethtool.c

drivers/net/ethernet/microsoft/mana/mana_ethtool.c static int mana_set_channels(struct net_device

Quoted 4 lines

index d6a35fbda447..5077493fdfde 100644

drivers/net/ethernet/microsoft/mana/mana_ethtool.c +0 -0
@@ -345,27 +345,31 @@ static int mana_set_channels(struct net_device

*ndev,

drivers/net/ethernet/microsoft/mana/mana_ethtool.c static int mana_set_channels(struct net_device *ndev, · line 352

Quoted 9 lines
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +5 -1
      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;
Quoted 3 lines

Are you sure that temporary changing num_queues has no side effects on other num_queues users like mana_chn_setxdp()?

Quoted 8 lines

mana_chn_setxdp() is protected by rtnl_lock, which is OK. But I'm not sure if all other users are protected. mana_get_stats64() seems not.

@Shradha Gupta You can add num_queues as an argument of mana_pre_alloc_rxbufs() to avoid changing apc->num_queues.

Thanks,
- Haiyang

Thanks Haiyang and Gerhard. Instead of changing the apc structure value, I will pass it to the mana_pre_alloc_rxbufs() function in the next version. That should make sure other calls are unaffected.

Thanks,
Shradha.