public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH V3 0/3] qca_spi: collection of major fixes
@ 2023-12-06 14:12 Stefan Wahren
  2023-12-06 14:12 ` [PATCH V3 1/3] qca_debug: Prevent crash on TX ring changes Stefan Wahren
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Stefan Wahren @ 2023-12-06 14:12 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: netdev, linux-kernel, Stefan Wahren

This series contains a collection of major fixes for the qca_spi driver,
which has been recently discovered.

Changes in V3:
- Avoid race condition in qcaspi_set_ringparam() as reported by Jakub and
  move all traffic handling within qcaspi_spi_thread
- use netif_tx_disable instead of netif_stop_queue

Changes in V2:
- Address the crashes caused by TX ring changes in a single patch
  instead of two separate ones ( resource allocation rework will
  be send in a separate series ). As suggested by Paolo the kthread
  is parked during ring parameter changes instead changing the device
  state
- As suggested by Paolo keep the ethtool get_ringparam behavior
  and just fix set_ringparam
- improve commit message in patch #2

Stefan Wahren (3):
  qca_debug: Prevent crash on TX ring changes
  qca_debug: Fix ethtool -G iface tx behavior
  qca_spi: Fix reset behavior

 drivers/net/ethernet/qualcomm/qca_debug.c | 17 +++++++++--------
 drivers/net/ethernet/qualcomm/qca_spi.c   | 20 +++++++++++++++++++-
 2 files changed, 28 insertions(+), 9 deletions(-)

--
2.34.1


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

* [PATCH V3 1/3] qca_debug: Prevent crash on TX ring changes
  2023-12-06 14:12 [PATCH V3 0/3] qca_spi: collection of major fixes Stefan Wahren
@ 2023-12-06 14:12 ` Stefan Wahren
  2023-12-06 14:12 ` [PATCH V3 2/3] qca_debug: Fix ethtool -G iface tx behavior Stefan Wahren
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Stefan Wahren @ 2023-12-06 14:12 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: netdev, linux-kernel, Stefan Wahren

The qca_spi driver stop and restart the SPI kernel thread
(via ndo_stop & ndo_open) in case of TX ring changes. This is
a big issue because it allows userspace to prevent restart of
the SPI kernel thread (via signals). A subsequent change of
TX ring wrongly assume a valid spi_thread pointer which result
in a crash.

So prevent this by stopping the network traffic handling and
temporary park the SPI thread.

Fixes: 291ab06ecf67 ("net: qualcomm: new Ethernet over SPI driver for QCA7000")
Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
---
 drivers/net/ethernet/qualcomm/qca_debug.c |  9 ++++-----
 drivers/net/ethernet/qualcomm/qca_spi.c   | 12 ++++++++++++
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_debug.c b/drivers/net/ethernet/qualcomm/qca_debug.c
index 6f2fa2a42770..a5445252b0c4 100644
--- a/drivers/net/ethernet/qualcomm/qca_debug.c
+++ b/drivers/net/ethernet/qualcomm/qca_debug.c
@@ -263,7 +263,6 @@ qcaspi_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ring,
 		     struct kernel_ethtool_ringparam *kernel_ring,
 		     struct netlink_ext_ack *extack)
 {
-	const struct net_device_ops *ops = dev->netdev_ops;
 	struct qcaspi *qca = netdev_priv(dev);

 	if ((ring->rx_pending) ||
@@ -271,14 +270,14 @@ qcaspi_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ring,
 	    (ring->rx_jumbo_pending))
 		return -EINVAL;

-	if (netif_running(dev))
-		ops->ndo_stop(dev);
+	if (qca->spi_thread)
+		kthread_park(qca->spi_thread);

 	qca->txr.count = max_t(u32, ring->tx_pending, TX_RING_MIN_LEN);
 	qca->txr.count = min_t(u16, qca->txr.count, TX_RING_MAX_LEN);

-	if (netif_running(dev))
-		ops->ndo_open(dev);
+	if (qca->spi_thread)
+		kthread_unpark(qca->spi_thread);

 	return 0;
 }
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c b/drivers/net/ethernet/qualcomm/qca_spi.c
index bec723028e96..b0fad69bb755 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -580,6 +580,18 @@ qcaspi_spi_thread(void *data)
 	netdev_info(qca->net_dev, "SPI thread created\n");
 	while (!kthread_should_stop()) {
 		set_current_state(TASK_INTERRUPTIBLE);
+		if (kthread_should_park()) {
+			netif_tx_disable(qca->net_dev);
+			netif_carrier_off(qca->net_dev);
+			qcaspi_flush_tx_ring(qca);
+			kthread_parkme();
+			if (qca->sync == QCASPI_SYNC_READY) {
+				netif_carrier_on(qca->net_dev);
+				netif_wake_queue(qca->net_dev);
+			}
+			continue;
+		}
+
 		if ((qca->intr_req == qca->intr_svc) &&
 		    !qca->txr.skb[qca->txr.head])
 			schedule();
--
2.34.1


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

* [PATCH V3 2/3] qca_debug: Fix ethtool -G iface tx behavior
  2023-12-06 14:12 [PATCH V3 0/3] qca_spi: collection of major fixes Stefan Wahren
  2023-12-06 14:12 ` [PATCH V3 1/3] qca_debug: Prevent crash on TX ring changes Stefan Wahren
@ 2023-12-06 14:12 ` Stefan Wahren
  2023-12-06 14:12 ` [PATCH V3 3/3] qca_spi: Fix reset behavior Stefan Wahren
  2023-12-09  0:20 ` [PATCH V3 0/3] qca_spi: collection of major fixes patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Stefan Wahren @ 2023-12-06 14:12 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: netdev, linux-kernel, Stefan Wahren

After calling ethtool -g it was not possible to adjust the TX ring
size again:

  # ethtool -g eth1
  Ring parameters for eth1:
  Pre-set maximums:
  RX:		4
  RX Mini:	n/a
  RX Jumbo:	n/a
  TX:		10
  Current hardware settings:
  RX:		4
  RX Mini:	n/a
  RX Jumbo:	n/a
  TX:		10
  # ethtool -G eth1 tx 8
  netlink error: Invalid argument

The reason for this is that the readonly setting rx_pending get
initialized and after that the range check in qcaspi_set_ringparam()
fails regardless of the provided parameter. So fix this by accepting
the exposed RX defaults. Instead of adding another magic number
better use a new define here.

Fixes: 291ab06ecf67 ("net: qualcomm: new Ethernet over SPI driver for QCA7000")
Suggested-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
---
 drivers/net/ethernet/qualcomm/qca_debug.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_debug.c b/drivers/net/ethernet/qualcomm/qca_debug.c
index a5445252b0c4..1822f2ad8f0d 100644
--- a/drivers/net/ethernet/qualcomm/qca_debug.c
+++ b/drivers/net/ethernet/qualcomm/qca_debug.c
@@ -30,6 +30,8 @@

 #define QCASPI_MAX_REGS 0x20

+#define QCASPI_RX_MAX_FRAMES 4
+
 static const u16 qcaspi_spi_regs[] = {
 	SPI_REG_BFR_SIZE,
 	SPI_REG_WRBUF_SPC_AVA,
@@ -252,9 +254,9 @@ qcaspi_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring,
 {
 	struct qcaspi *qca = netdev_priv(dev);

-	ring->rx_max_pending = 4;
+	ring->rx_max_pending = QCASPI_RX_MAX_FRAMES;
 	ring->tx_max_pending = TX_RING_MAX_LEN;
-	ring->rx_pending = 4;
+	ring->rx_pending = QCASPI_RX_MAX_FRAMES;
 	ring->tx_pending = qca->txr.count;
 }

@@ -265,7 +267,7 @@ qcaspi_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ring,
 {
 	struct qcaspi *qca = netdev_priv(dev);

-	if ((ring->rx_pending) ||
+	if (ring->rx_pending != QCASPI_RX_MAX_FRAMES ||
 	    (ring->rx_mini_pending) ||
 	    (ring->rx_jumbo_pending))
 		return -EINVAL;
--
2.34.1


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

* [PATCH V3 3/3] qca_spi: Fix reset behavior
  2023-12-06 14:12 [PATCH V3 0/3] qca_spi: collection of major fixes Stefan Wahren
  2023-12-06 14:12 ` [PATCH V3 1/3] qca_debug: Prevent crash on TX ring changes Stefan Wahren
  2023-12-06 14:12 ` [PATCH V3 2/3] qca_debug: Fix ethtool -G iface tx behavior Stefan Wahren
@ 2023-12-06 14:12 ` Stefan Wahren
  2023-12-09  0:20 ` [PATCH V3 0/3] qca_spi: collection of major fixes patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Stefan Wahren @ 2023-12-06 14:12 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: netdev, linux-kernel, Stefan Wahren

In case of a reset triggered by the QCA7000 itself, the behavior of the
qca_spi driver was not quite correct:
- in case of a pending RX frame decoding the drop counter must be
  incremented and decoding state machine reseted
- also the reset counter must always be incremented regardless of sync
  state

Fixes: 291ab06ecf67 ("net: qualcomm: new Ethernet over SPI driver for QCA7000")
Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
---
 drivers/net/ethernet/qualcomm/qca_spi.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c b/drivers/net/ethernet/qualcomm/qca_spi.c
index b0fad69bb755..5f3c11fb3fa2 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -620,11 +620,17 @@ qcaspi_spi_thread(void *data)
 			if (intr_cause & SPI_INT_CPU_ON) {
 				qcaspi_qca7k_sync(qca, QCASPI_EVENT_CPUON);

+				/* Frame decoding in progress */
+				if (qca->frm_handle.state != qca->frm_handle.init)
+					qca->net_dev->stats.rx_dropped++;
+
+				qcafrm_fsm_init_spi(&qca->frm_handle);
+				qca->stats.device_reset++;
+
 				/* not synced. */
 				if (qca->sync != QCASPI_SYNC_READY)
 					continue;

-				qca->stats.device_reset++;
 				netif_wake_queue(qca->net_dev);
 				netif_carrier_on(qca->net_dev);
 			}
--
2.34.1


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

* Re: [PATCH V3 0/3] qca_spi: collection of major fixes
  2023-12-06 14:12 [PATCH V3 0/3] qca_spi: collection of major fixes Stefan Wahren
                   ` (2 preceding siblings ...)
  2023-12-06 14:12 ` [PATCH V3 3/3] qca_spi: Fix reset behavior Stefan Wahren
@ 2023-12-09  0:20 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-12-09  0:20 UTC (permalink / raw)
  To: Stefan Wahren; +Cc: davem, edumazet, kuba, pabeni, netdev, linux-kernel

Hello:

This series was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed,  6 Dec 2023 15:12:19 +0100 you wrote:
> This series contains a collection of major fixes for the qca_spi driver,
> which has been recently discovered.
> 
> Changes in V3:
> - Avoid race condition in qcaspi_set_ringparam() as reported by Jakub and
>   move all traffic handling within qcaspi_spi_thread
> - use netif_tx_disable instead of netif_stop_queue
> 
> [...]

Here is the summary with links:
  - [V3,1/3] qca_debug: Prevent crash on TX ring changes
    https://git.kernel.org/netdev/net/c/f4e6064c97c0
  - [V3,2/3] qca_debug: Fix ethtool -G iface tx behavior
    https://git.kernel.org/netdev/net/c/96a7e861d9e0
  - [V3,3/3] qca_spi: Fix reset behavior
    https://git.kernel.org/netdev/net/c/1057812d146d

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:[~2023-12-09  0:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-06 14:12 [PATCH V3 0/3] qca_spi: collection of major fixes Stefan Wahren
2023-12-06 14:12 ` [PATCH V3 1/3] qca_debug: Prevent crash on TX ring changes Stefan Wahren
2023-12-06 14:12 ` [PATCH V3 2/3] qca_debug: Fix ethtool -G iface tx behavior Stefan Wahren
2023-12-06 14:12 ` [PATCH V3 3/3] qca_spi: Fix reset behavior Stefan Wahren
2023-12-09  0:20 ` [PATCH V3 0/3] qca_spi: collection of major fixes 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