Skip to contentSkip to conversation

qca_spi: collection of major fixes

PATCH Applied Stefan Wahren 2 participants 5 messages Dec 6, 2023 – Dec 9, 2023

Subsystems (3)
lore
Share & tools
lore

Stefan Wahren

author maintainer
#0 lore raw

v3 cover qca_spi: collection of major fixes

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

author maintainer
#1 lore raw

PATCH v3 1/3 qca_debug: Prevent crash on TX ring changes

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")
---
 drivers/net/ethernet/qualcomm/qca_debug.c |  9 ++++-----
 drivers/net/ethernet/qualcomm/qca_spi.c   | 12 ++++++++++++
 2 files changed, 16 insertions(+), 5 deletions(-)
drivers/net/ethernet/qualcomm/qca_debug.c +4 -5
index 6f2fa2a42770..a5445252b0c4 100644
@@ -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;
 }
drivers/net/ethernet/qualcomm/qca_spi.c +12 -0
index bec723028e96..b0fad69bb755 100644
@@ -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

author maintainer
#2 lore raw

PATCH v3 2/3 qca_debug: Fix ethtool -G iface tx behavior

In reply to 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")
---
 drivers/net/ethernet/qualcomm/qca_debug.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/net/ethernet/qualcomm/qca_debug.c +5 -3
index a5445252b0c4..1822f2ad8f0d 100644
@@ -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

author maintainer
#3 lore raw

PATCH v3 3/3 qca_spi: Fix reset behavior

In reply to 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")
---
 drivers/net/ethernet/qualcomm/qca_spi.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/ethernet/qualcomm/qca_spi.c +7 -1
index b0fad69bb755..5f3c11fb3fa2 100644
@@ -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

#4 lore raw
In reply to Stefan Wahren
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 9 lines · 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!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html