Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH net-next 0/2] net: add netif_set_real_num_queues() for device reconfig
@ 2021-08-03 13:05 Jakub Kicinski
  2021-08-03 13:05 ` [PATCH net-next 1/2] " Jakub Kicinski
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Jakub Kicinski @ 2021-08-03 13:05 UTC (permalink / raw)
  To: davem; +Cc: netdev, simon.horman, alexanderduyck, oss-drivers, Jakub Kicinski

This short set adds a helper to make the implementation of
two-phase NIC reconfig easier.

Jakub Kicinski (2):
  net: add netif_set_real_num_queues() for device reconfig
  nfp: use netif_set_real_num_queues()

 .../ethernet/netronome/nfp/nfp_net_common.c   | 11 ++---
 include/linux/netdevice.h                     |  2 +
 net/core/dev.c                                | 44 +++++++++++++++++++
 3 files changed, 49 insertions(+), 8 deletions(-)

-- 
2.31.1


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

* [PATCH net-next 1/2] net: add netif_set_real_num_queues() for device reconfig
  2021-08-03 13:05 [PATCH net-next 0/2] net: add netif_set_real_num_queues() for device reconfig Jakub Kicinski
@ 2021-08-03 13:05 ` Jakub Kicinski
  2021-08-03 13:05 ` [PATCH net-next 2/2] nfp: use netif_set_real_num_queues() Jakub Kicinski
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Jakub Kicinski @ 2021-08-03 13:05 UTC (permalink / raw)
  To: davem; +Cc: netdev, simon.horman, alexanderduyck, oss-drivers, Jakub Kicinski

netif_set_real_num_rx_queues() and netif_set_real_num_tx_queues()
can fail which breaks drivers trying to implement reconfiguration
in a way that can't leave the device half-broken. In other words
those functions are incompatible with prepare/commit approach.

Luckily setting real number of queues can fail only if the number
is increased, meaning that if we order operations correctly we
can guarantee ending up with either new config (success), or
the old one (on error).

Provide a helper implementing such logic so that drivers don't
have to duplicate it.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 include/linux/netdevice.h |  2 ++
 net/core/dev.c            | 44 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index cd136499ec59..1b4d4509d04b 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -3916,6 +3916,8 @@ static inline int netif_set_real_num_rx_queues(struct net_device *dev,
 	return 0;
 }
 #endif
+int netif_set_real_num_queues(struct net_device *dev,
+			      unsigned int txq, unsigned int rxq);
 
 static inline struct netdev_rx_queue *
 __netif_get_rx_queue(struct net_device *dev, unsigned int rxq)
diff --git a/net/core/dev.c b/net/core/dev.c
index 4a1401008db9..360cb2f1b1e9 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -2973,6 +2973,50 @@ int netif_set_real_num_rx_queues(struct net_device *dev, unsigned int rxq)
 EXPORT_SYMBOL(netif_set_real_num_rx_queues);
 #endif
 
+/**
+ *	netif_set_real_num_queues - set actual number of RX and TX queues used
+ *	@dev: Network device
+ *	@txq: Actual number of TX queues
+ *	@rxq: Actual number of RX queues
+ *
+ *	Set the real number of both TX and RX queues.
+ *	Does nothing if the number of queues is already correct.
+ */
+int netif_set_real_num_queues(struct net_device *dev,
+			      unsigned int txq, unsigned int rxq)
+{
+	unsigned int old_rxq = dev->real_num_rx_queues;
+	int err;
+
+	if (txq < 1 || txq > dev->num_tx_queues ||
+	    rxq < 1 || rxq > dev->num_rx_queues)
+		return -EINVAL;
+
+	/* Start from increases, so the error path only does decreases -
+	 * decreases can't fail.
+	 */
+	if (rxq > dev->real_num_rx_queues) {
+		err = netif_set_real_num_rx_queues(dev, rxq);
+		if (err)
+			return err;
+	}
+	if (txq > dev->real_num_tx_queues) {
+		err = netif_set_real_num_tx_queues(dev, txq);
+		if (err)
+			goto undo_rx;
+	}
+	if (rxq < dev->real_num_rx_queues)
+		WARN_ON(netif_set_real_num_rx_queues(dev, rxq));
+	if (txq < dev->real_num_tx_queues)
+		WARN_ON(netif_set_real_num_tx_queues(dev, txq));
+
+	return 0;
+undo_rx:
+	WARN_ON(netif_set_real_num_rx_queues(dev, old_rxq));
+	return err;
+}
+EXPORT_SYMBOL(netif_set_real_num_queues);
+
 /**
  * netif_get_num_default_rss_queues - default number of RSS queues
  *
-- 
2.31.1


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

* [PATCH net-next 2/2] nfp: use netif_set_real_num_queues()
  2021-08-03 13:05 [PATCH net-next 0/2] net: add netif_set_real_num_queues() for device reconfig Jakub Kicinski
  2021-08-03 13:05 ` [PATCH net-next 1/2] " Jakub Kicinski
@ 2021-08-03 13:05 ` Jakub Kicinski
  2021-08-03 15:03 ` [PATCH net-next 0/2] net: add netif_set_real_num_queues() for device reconfig Simon Horman
  2021-08-04  9:40 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Jakub Kicinski @ 2021-08-03 13:05 UTC (permalink / raw)
  To: davem; +Cc: netdev, simon.horman, alexanderduyck, oss-drivers, Jakub Kicinski

Avoid reconfig problems due to failures in netif_set_real_num_tx_queues()
by using netif_set_real_num_queues().

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 drivers/net/ethernet/netronome/nfp/nfp_net_common.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
index 15078f9dc9f1..5bfa22accf2c 100644
--- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
+++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
@@ -3281,17 +3281,12 @@ static int nfp_net_dp_swap_enable(struct nfp_net *nn, struct nfp_net_dp *dp)
 	for (r = 0; r <	nn->max_r_vecs; r++)
 		nfp_net_vector_assign_rings(&nn->dp, &nn->r_vecs[r], r);
 
-	err = netif_set_real_num_rx_queues(nn->dp.netdev, nn->dp.num_rx_rings);
+	err = netif_set_real_num_queues(nn->dp.netdev,
+					nn->dp.num_stack_tx_rings,
+					nn->dp.num_rx_rings);
 	if (err)
 		return err;
 
-	if (nn->dp.netdev->real_num_tx_queues != nn->dp.num_stack_tx_rings) {
-		err = netif_set_real_num_tx_queues(nn->dp.netdev,
-						   nn->dp.num_stack_tx_rings);
-		if (err)
-			return err;
-	}
-
 	return nfp_net_set_config_and_enable(nn);
 }
 
-- 
2.31.1


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

* Re: [PATCH net-next 0/2] net: add netif_set_real_num_queues() for device reconfig
  2021-08-03 13:05 [PATCH net-next 0/2] net: add netif_set_real_num_queues() for device reconfig Jakub Kicinski
  2021-08-03 13:05 ` [PATCH net-next 1/2] " Jakub Kicinski
  2021-08-03 13:05 ` [PATCH net-next 2/2] nfp: use netif_set_real_num_queues() Jakub Kicinski
@ 2021-08-03 15:03 ` Simon Horman
  2021-08-04  9:40 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Simon Horman @ 2021-08-03 15:03 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: davem, netdev, alexanderduyck, oss-drivers

On Tue, Aug 03, 2021 at 06:05:25AM -0700, Jakub Kicinski wrote:
> This short set adds a helper to make the implementation of
> two-phase NIC reconfig easier.
> 
> Jakub Kicinski (2):
>   net: add netif_set_real_num_queues() for device reconfig
>   nfp: use netif_set_real_num_queues()

Reviewed-by: Simon Horman <simon.horman@corigine.com>


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

* Re: [PATCH net-next 0/2] net: add netif_set_real_num_queues() for device reconfig
  2021-08-03 13:05 [PATCH net-next 0/2] net: add netif_set_real_num_queues() for device reconfig Jakub Kicinski
                   ` (2 preceding siblings ...)
  2021-08-03 15:03 ` [PATCH net-next 0/2] net: add netif_set_real_num_queues() for device reconfig Simon Horman
@ 2021-08-04  9:40 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-08-04  9:40 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: davem, netdev, simon.horman, alexanderduyck, oss-drivers

Hello:

This series was applied to netdev/net-next.git (refs/heads/master):

On Tue,  3 Aug 2021 06:05:25 -0700 you wrote:
> This short set adds a helper to make the implementation of
> two-phase NIC reconfig easier.
> 
> Jakub Kicinski (2):
>   net: add netif_set_real_num_queues() for device reconfig
>   nfp: use netif_set_real_num_queues()
> 
> [...]

Here is the summary with links:
  - [net-next,1/2] net: add netif_set_real_num_queues() for device reconfig
    https://git.kernel.org/netdev/net-next/c/271e5b7d00ae
  - [net-next,2/2] nfp: use netif_set_real_num_queues()
    https://git.kernel.org/netdev/net-next/c/e874f4557b36

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2021-08-04  9:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-03 13:05 [PATCH net-next 0/2] net: add netif_set_real_num_queues() for device reconfig Jakub Kicinski
2021-08-03 13:05 ` [PATCH net-next 1/2] " Jakub Kicinski
2021-08-03 13:05 ` [PATCH net-next 2/2] nfp: use netif_set_real_num_queues() Jakub Kicinski
2021-08-03 15:03 ` [PATCH net-next 0/2] net: add netif_set_real_num_queues() for device reconfig Simon Horman
2021-08-04  9:40 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).