mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net-next v6 0/4] net: qrtr: Add support for using identical MHI endpoint devices
@ 2026-11-14 14:26 Manivannan Sadhasivam via B4 Relay
  2026-11-14 14:26 ` [PATCH net-next v6 1/4] net: qrtr: Allow the host QRTR to assign a unique node id Manivannan Sadhasivam via B4 Relay
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Manivannan Sadhasivam via B4 Relay @ 2026-11-14 14:26 UTC (permalink / raw)
  To: Manivannan Sadhasivam, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Simon Horman, Jeff Johnson, Eric Dumazet,
	Eric Dumazet
  Cc: linux-arm-msm, netdev, linux-kernel, linux-wireless, ath11k,
	ath12k, Bjorn Andersson, Chris Lew, Deepak Kumar Singh,
	Raj Kumar Bhagat, Juha-Matti Tilli, Jeff Hugo,
	Manivannan Sadhasivam, Jeff Johnson, Daizhuang Bai

Hi,

This series reworks the QRTR driver to add support for using identical MHI
endpoint devices at the same time. Currently, QRTR driver has a limitation on
using more than one identical MHI endpoint devices like QCS6490 or any Qcom
Endpoint device making use of QRTR at the same time. Because of the fact that
these devices will have the identical QRTR node id, they cannot be used at the
same time, on the same host machine.

This limitation is a blocker for running upstream kernel on devices like Qcom
based routers as they often have multiple identical WLAN Endpoint devices
connected to the Router SoC.

This series supersedes the following 2 series from Juha:
https://lore.kernel.org/all/20260915054207.2513877-1-juha-matti.tilli@iki.fi
https://lore.kernel.org/all/20260915074135.2567411-1-juha-matti.tilli@iki.fi

Compared to the series from Juha, this series simplifies the multi-endpoint
support by computing a unique node id for each MHI endpoint and uses it for the
internal QRTR book keeping. This ensures that even if the MHI endpoint devices
have same node ids, the host QRTR will always use a unique node id for each one
of them.

More details can be found in the individual patches.

Merge Strategy
==============

Since both QRTR and ath drivers are falling under the networking tree, the whole
series can be merged through netdev tree.

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
---
Changes in v6:
- Rebased on top of net-next/main
- Dropped the checks for node id collision as they were not needed
- Link to v5: https://patch.msgid.link/20261104-qrtr-multi-ep-v5-0-4cdb2b4f1920@oss.qualcomm.com

Changes in v5:
- Rebased on top of net-next/main
- Collected tags
- Link to v4: https://patch.msgid.link/20261022-qrtr-multi-ep-v4-0-c6fdb75fcd3e@oss.qualcomm.com

Changes in v4:
- Moved the 'ep_nid' and the node id assignment into a single
  'qrtr_nodes_lock' critical section and used READ_ONCE() elsewhere
- Propagated the radix tree insert error out of qrtr_node_assign() and
  rejected the packet or failed the endpoint registration
- Fixed the assign condition that stopped adding bridged node ids as
  lookup keys
- Moved the control packet length check to qrtr_endpoint_post() and
  extended it to DEL_SERVER and DEL_CLIENT
- Rejected endpoint node ids at and above QRTR_NODE_HOST_BASE
- Returned error for the QMI message received from an unknown server in
  ath{11k,12k} so that the QMI core drops the service
- Dropped Juha's Tested-by and Vasanth's Reviewed-bt as the code changed since v3
- Link to v3: https://patch.msgid.link/20260922-qrtr-multi-ep-v3-0-c00831e88957@oss.qualcomm.com

Changes in v3:
- Added missing qrtr_node_rewrite_ctrl() for QRTR_TYPE_RESUME_TX
- Fixed the types of ath{11k/12k}_pci_get_qrtr_node_id() and helpers to use
  'unsigned int' to match qrtr_host_node_id()
- Collected tags
- Link to v2: https://patch.msgid.link/20260921-qrtr-multi-ep-v2-0-27dd80d841a0@oss.qualcomm.com

Changes in v2:
- Rebased on top of net-next/main
- Used READ/WRITE_ONCE for reading/writing ep_nid
- Link to v1: https://patch.msgid.link/20260918-qrtr-multi-ep-v1-0-8a06caa368d3@oss.qualcomm.com

Cc: linux-arm-msm@vger.kernel.org
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-wireless@vger.kernel.org
Cc: ath11k@lists.infradead.org
Cc: ath12k@lists.infradead.org
To: Manivannan Sadhasivam <mani@kernel.org>
To: "David S. Miller" <davem@davemloft.net>
To: Eric Dumazet <edumazet@kernel.org>
To: Jakub Kicinski <kuba@kernel.org>
To: Paolo Abeni <pabeni@redhat.com>
To: Simon Horman <horms@kernel.org>
To: Jeff Johnson <jjohnson@kernel.org>

---
Manivannan Sadhasivam (4):
      net: qrtr: Allow the host QRTR to assign a unique node id
      net: qrtr: Assign unique node id for MHI endpoints
      wifi: ath11k: Connect to the QMI server belonging to the device owned by this driver
      wifi: ath12k: Connect to the QMI server belonging to the device owned by this driver

 MAINTAINERS                           |   1 +
 drivers/net/wireless/ath/ath11k/hif.h |   9 +++
 drivers/net/wireless/ath/ath11k/pci.c |   9 +++
 drivers/net/wireless/ath/ath11k/qmi.c |  11 +++
 drivers/net/wireless/ath/ath12k/hif.h |   9 +++
 drivers/net/wireless/ath/ath12k/pci.c |   9 +++
 drivers/net/wireless/ath/ath12k/qmi.c |  12 +++
 include/net/qrtr.h                    |  27 +++++++
 net/qrtr/af_qrtr.c                    | 136 ++++++++++++++++++++++++++++++----
 net/qrtr/mhi.c                        |   4 +-
 10 files changed, 210 insertions(+), 17 deletions(-)
---
base-commit: 6964ff21c5d8b75649211a52dbfd92753e605649
change-id: 20260918-qrtr-multi-ep-c27c2bc54ee1

Best regards,
--  
மணிவண்ணன் சதாசிவம்



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

* [PATCH net-next v6 1/4] net: qrtr: Allow the host QRTR to assign a unique node id
  2026-11-14 14:26 [PATCH net-next v6 0/4] net: qrtr: Add support for using identical MHI endpoint devices Manivannan Sadhasivam via B4 Relay
@ 2026-11-14 14:26 ` Manivannan Sadhasivam via B4 Relay
  2026-11-16  0:44   ` netdev-bot+sashiko
  2026-11-14 14:26 ` [PATCH net-next v6 2/4] net: qrtr: Assign unique node id for MHI endpoints Manivannan Sadhasivam via B4 Relay
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Manivannan Sadhasivam via B4 Relay @ 2026-11-14 14:26 UTC (permalink / raw)
  To: Manivannan Sadhasivam, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Simon Horman, Jeff Johnson, Eric Dumazet,
	Eric Dumazet
  Cc: linux-arm-msm, netdev, linux-kernel, linux-wireless, ath11k,
	ath12k, Bjorn Andersson, Chris Lew, Deepak Kumar Singh,
	Raj Kumar Bhagat, Juha-Matti Tilli, Jeff Hugo,
	Manivannan Sadhasivam

From: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>

Currently, QRTR identifies each remote node by the value of the
'src_node_id' field in the received packet and uses the node id as the key
to store the node to the internal 'qrtr_nodes' radix tree.

But this approach comes with a limitation. When more than one remote node
share the same id, then QRTR can only add the first node to the radix tree
and has to drop the successive nodes with the same node id as the 'key' in
radix tree has to be unique. This prevents connecting identical Qcom PCIe
WLAN devices to a single host at the same time.

To fix this limitation, allow the host QRTR to use the node id (nid)
received from the endpoint driver during qrtr_endpoint_register() as the
unique node id and use it as the 'key' for the internal radix tree. Also,
store the received 'src_id' in a new 'qrtr_node->ep_nid' field and replace
the 'ep_nid' with the unique 'nid' in the QRTR control packets if both
differ i.e., an endpoint driver has passed a unique 'nid' during
qrtr_endpoint_register(). To maintain symmetry, replace the 'nid' with the
'ep_nid' while sending the packet back to the remote node if both differ.

A node can also bridge other distant nodes, so the source id of an
incoming packet is not always the id the endpoint advertises for itself.
Keep adding such ids to the radix tree as additional keys for the same
node, as it was done before this change. Otherwise the bridged nodes would
lose their route and qrtr_sendmsg() would start failing with -ECONNRESET
for them.

Currently, all QRTR endpoint drivers pass 'QRTR_EP_NID_AUTO' as the 'nid'
during qrtr_endpoint_register(). So 'ep_nid' and 'nid' are same and the
routing behavior is not changed.

Finally, since qrtr_node_rewrite_ctrl() dereferences the control packet for
DEL_SERVER and DEL_CLIENT as well, extend the existing length check in
qrtr_endpoint_post() to cover both types.

Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
---
 net/qrtr/af_qrtr.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 120 insertions(+), 16 deletions(-)

diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index 45cb8e8c36ca..fff1d70fd8bf 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -118,7 +118,8 @@ static DEFINE_XARRAY_ALLOC(qrtr_ports);
  * @ep_lock: lock for endpoint management and callbacks
  * @ep: endpoint
  * @ref: reference count for node
- * @nid: node id
+ * @nid: node id assigned by the host QRTR
+ * @ep_nid: endpoint's own node id as received
  * @qrtr_tx_flow: xarray of qrtr_tx_flow, keyed by node << 32 | port
  * @qrtr_tx_lock: lock for qrtr_tx_flow inserts
  * @hello_sent: hello packet send successful
@@ -132,6 +133,7 @@ struct qrtr_node {
 	struct qrtr_endpoint *ep;
 	struct kref ref;
 	unsigned int nid;
+	unsigned int ep_nid;
 
 	struct xarray qrtr_tx_flow;
 	struct mutex qrtr_tx_lock; /* for qrtr_tx_flow */
@@ -349,6 +351,7 @@ static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb,
 {
 	struct qrtr_hdr_v1 *hdr;
 	size_t len = skb->len;
+	unsigned int dst_node;
 	int rc, confirm_rx;
 
 	mutex_lock(&node->ep_lock);
@@ -371,10 +374,14 @@ static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb,
 	hdr->src_node_id = cpu_to_le32(from->sq_node);
 	hdr->src_port_id = cpu_to_le32(from->sq_port);
 	if (to->sq_port == QRTR_PORT_CTRL) {
-		hdr->dst_node_id = cpu_to_le32(READ_ONCE(node->nid));
+		hdr->dst_node_id = cpu_to_le32(READ_ONCE(node->ep_nid));
 		hdr->dst_port_id = cpu_to_le32(QRTR_PORT_CTRL);
 	} else {
-		hdr->dst_node_id = cpu_to_le32(to->sq_node);
+		/* Put back the endpoint's own node id */
+		dst_node = to->sq_node;
+		if (dst_node == READ_ONCE(node->nid))
+			dst_node = READ_ONCE(node->ep_nid);
+		hdr->dst_node_id = cpu_to_le32(dst_node);
 		hdr->dst_port_id = cpu_to_le32(to->sq_port);
 	}
 
@@ -424,23 +431,75 @@ static struct qrtr_node *qrtr_node_lookup(unsigned int nid)
 	return node;
 }
 
-/* Assign node id to node.
+/*
+ * Add 'nid' as a lookup key for 'node', and adopt it as the node's own id if
+ * the node does not have one yet.
+ *
+ * Callers must hold 'qrtr_nodes_lock'.
  *
- * This is mostly useful for automatic node id assignment, based on
- * the source id in the incoming packet.
+ * Return: 0 on success; negative error code on failure
  */
-static void qrtr_node_assign(struct qrtr_node *node, unsigned int nid)
+static int __qrtr_node_assign(struct qrtr_node *node, unsigned int nid)
 {
-	unsigned long flags;
+	int rc;
 
 	if (nid == QRTR_EP_NID_AUTO)
-		return;
+		return 0;
+
+	if (radix_tree_lookup(&qrtr_nodes, nid) == node)
+		return 0;
+
+	rc = radix_tree_insert(&qrtr_nodes, nid, node);
+	if (rc)
+		return rc;
 
-	spin_lock_irqsave(&qrtr_nodes_lock, flags);
-	radix_tree_insert(&qrtr_nodes, nid, node);
 	if (node->nid == QRTR_EP_NID_AUTO)
 		WRITE_ONCE(node->nid, nid);
+
+	return 0;
+}
+
+/*
+ * Assign node id to node.
+ *
+ * Return: 0 on success; negative error code on failure
+ */
+static int qrtr_node_assign(struct qrtr_node *node, unsigned int nid)
+{
+	unsigned long flags;
+	int rc;
+
+	spin_lock_irqsave(&qrtr_nodes_lock, flags);
+	rc = __qrtr_node_assign(node, nid);
 	spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
+
+	return rc;
+}
+
+/*
+ * Replace the node id in the control packet with 'node->nid', if both are
+ * different.
+ */
+static void qrtr_node_rewrite_ctrl(struct qrtr_node *node, unsigned int type,
+				   struct sk_buff *skb)
+{
+	unsigned int ep_nid = READ_ONCE(node->ep_nid);
+	unsigned int host_nid = READ_ONCE(node->nid);
+	struct qrtr_ctrl_pkt *pkt;
+	__le32 *nid;
+
+	if (host_nid == ep_nid)
+		return;
+
+	pkt = (struct qrtr_ctrl_pkt *)skb->data;
+	if (type == QRTR_TYPE_DEL_CLIENT || type == QRTR_TYPE_RESUME_TX)
+		nid = &pkt->client.node;
+	else
+		nid = &pkt->server.node;
+
+	/* Rewrite only the endpoint's node id, not those of bridged nodes */
+	if (le32_to_cpu(*nid) == ep_nid)
+		*nid = cpu_to_le32(host_nid);
 }
 
 /**
@@ -459,9 +518,12 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
 	struct qrtr_sock *ipc;
 	struct sk_buff *skb;
 	struct qrtr_cb *cb;
+	unsigned long flags;
 	size_t size;
 	unsigned int ver;
+	unsigned int nid;
 	size_t hdrlen;
+	int rc = 0;
 
 	if (len == 0 || len & 3)
 		return -EINVAL;
@@ -523,6 +585,8 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
 		goto err;
 
 	if ((cb->type == QRTR_TYPE_NEW_SERVER ||
+	     cb->type == QRTR_TYPE_DEL_SERVER ||
+	     cb->type == QRTR_TYPE_DEL_CLIENT ||
 	     cb->type == QRTR_TYPE_RESUME_TX) &&
 	    size < sizeof(struct qrtr_ctrl_pkt))
 		goto err;
@@ -533,14 +597,36 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
 
 	skb_put_data(skb, data + hdrlen, size);
 
-	qrtr_node_assign(node, cb->src_node);
+	nid = cb->src_node;
+
+	spin_lock_irqsave(&qrtr_nodes_lock, flags);
+
+	if (node->ep_nid == QRTR_EP_NID_AUTO)
+		WRITE_ONCE(node->ep_nid, nid);
+
+	/*
+	 * Add the source id to the lookup table only if 'node->nid' is auto
+	 * assigned or the packet came from a bridged node.
+	 */
+	if (node->nid == QRTR_EP_NID_AUTO || nid != node->ep_nid)
+		rc = __qrtr_node_assign(node, nid);
+
+	spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
+
+	if (rc)
+		goto err_nid;
 
 	if (cb->type == QRTR_TYPE_NEW_SERVER) {
 		/* Remote node endpoint can bridge other distant nodes */
-		const struct qrtr_ctrl_pkt *pkt;
+		const struct qrtr_ctrl_pkt *pkt = data + hdrlen;
+
+		nid = le32_to_cpu(pkt->server.node);
 
-		pkt = data + hdrlen;
-		qrtr_node_assign(node, le32_to_cpu(pkt->server.node));
+		if (nid != READ_ONCE(node->ep_nid)) {
+			rc = qrtr_node_assign(node, nid);
+			if (rc)
+				goto err_nid;
+		}
 	}
 
 	if (cb->type == QRTR_TYPE_HELLO) {
@@ -548,6 +634,15 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
 		smp_store_release(&node->hello_rcvd, true);
 	}
 
+	if (cb->src_node == READ_ONCE(node->ep_nid))
+		cb->src_node = READ_ONCE(node->nid);
+
+	if (cb->type == QRTR_TYPE_NEW_SERVER ||
+	    cb->type == QRTR_TYPE_DEL_SERVER ||
+	    cb->type == QRTR_TYPE_DEL_CLIENT ||
+	    cb->type == QRTR_TYPE_RESUME_TX)
+		qrtr_node_rewrite_ctrl(node, cb->type, skb);
+
 	if (cb->type == QRTR_TYPE_RESUME_TX) {
 		qrtr_tx_resume(node, skb);
 	} else {
@@ -565,6 +660,8 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
 
 	return 0;
 
+err_nid:
+	pr_err_ratelimited("qrtr: cannot route node id %u: %d\n", nid, rc);
 err:
 	kfree_skb(skb);
 	return -EINVAL;
@@ -684,6 +781,7 @@ EXPORT_SYMBOL_GPL(qrtr_endpoint_hello);
 int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid)
 {
 	struct qrtr_node *node;
+	int rc;
 
 	if (!ep || !ep->xmit)
 		return -EINVAL;
@@ -696,6 +794,7 @@ int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid)
 	mutex_init(&node->ep_lock);
 	skb_queue_head_init(&node->rx_queue);
 	node->nid = QRTR_EP_NID_AUTO;
+	node->ep_nid = QRTR_EP_NID_AUTO;
 	node->ep = ep;
 
 	node->hello_sent = false;
@@ -704,7 +803,12 @@ int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid)
 	xa_init(&node->qrtr_tx_flow);
 	mutex_init(&node->qrtr_tx_lock);
 
-	qrtr_node_assign(node, nid);
+	rc = qrtr_node_assign(node, nid);
+	if (rc) {
+		pr_err("qrtr: cannot assign node id %u: %d\n", nid, rc);
+		kfree(node);
+		return rc;
+	}
 
 	mutex_lock(&qrtr_node_lock);
 	list_add(&node->item, &qrtr_all_nodes);

-- 
2.43.0



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

* [PATCH net-next v6 2/4] net: qrtr: Assign unique node id for MHI endpoints
  2026-11-14 14:26 [PATCH net-next v6 0/4] net: qrtr: Add support for using identical MHI endpoint devices Manivannan Sadhasivam via B4 Relay
  2026-11-14 14:26 ` [PATCH net-next v6 1/4] net: qrtr: Allow the host QRTR to assign a unique node id Manivannan Sadhasivam via B4 Relay
@ 2026-11-14 14:26 ` Manivannan Sadhasivam via B4 Relay
  2026-11-16  0:44   ` netdev-bot+sashiko
  2026-11-14 14:26 ` [PATCH net-next v6 3/4] wifi: ath11k: Connect to the QMI server belonging to the device owned by this driver Manivannan Sadhasivam via B4 Relay
  2026-11-14 14:26 ` [PATCH net-next v6 4/4] wifi: ath12k: " Manivannan Sadhasivam via B4 Relay
  3 siblings, 1 reply; 7+ messages in thread
From: Manivannan Sadhasivam via B4 Relay @ 2026-11-14 14:26 UTC (permalink / raw)
  To: Manivannan Sadhasivam, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Simon Horman, Jeff Johnson, Eric Dumazet,
	Eric Dumazet
  Cc: linux-arm-msm, netdev, linux-kernel, linux-wireless, ath11k,
	ath12k, Bjorn Andersson, Chris Lew, Deepak Kumar Singh,
	Raj Kumar Bhagat, Juha-Matti Tilli, Jeff Hugo,
	Manivannan Sadhasivam

From: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>

Now that the QRTR driver allows using the unique node id for each device,
which is different from the node id received from the remote node, compute
a unique node id using a new API, qrtr_host_node_id().

This API takes the 'index' parameter and adds it to QRTR_NODE_HOST_BASE.
The index comes from an allocator, so the host assigned ids are unique
among themselves. The base is chosen just above the 16-bit range a v2
header can express, so an endpoint using v2 can never claim an id in the
host range. An endpoint using v1 can claim any 32-bit id, so a collision
is possible, but unlikely as the firmware assigned node ids are either
smaller than this base or in the range of 0x08e5ff85. Such a collision is
caught when the id is added to the node lookup table.

Finally, call the new API from MHI endpoint driver by passing the MHI
controller index as the parameter. The MHI controller index is unique for
each controller, thereby for each MHI endpoint device.

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
---
 MAINTAINERS        |  1 +
 include/net/qrtr.h | 27 +++++++++++++++++++++++++++
 net/qrtr/mhi.c     |  4 +++-
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 0cf311e6c4be..dfec5181c6e1 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -23139,6 +23139,7 @@ QUALCOMM IPC ROUTER (QRTR) DRIVER
 M:	Manivannan Sadhasivam <mani@kernel.org>
 L:	linux-arm-msm@vger.kernel.org
 S:	Maintained
+F:	include/net/qrtr.h
 F:	include/trace/events/qrtr.h
 F:	include/uapi/linux/qrtr.h
 F:	net/qrtr/
diff --git a/include/net/qrtr.h b/include/net/qrtr.h
new file mode 100644
index 000000000000..e2a8d93564b5
--- /dev/null
+++ b/include/net/qrtr.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef _NET_QRTR_H
+#define _NET_QRTR_H
+
+#include <linux/types.h>
+
+/*
+ * Base for the node ids the host assigns to endpoints. It sits just above the
+ * 16-bit range a v2 header can express, so a v2 endpoint can never claim an id
+ * in it. A v1 endpoint can claim any 32-bit id, so a collision is possible,
+ * but unlikely as the firmware assigned node ids are either smaller than this
+ * base or in the range of 0x08e5ff85. A collision is caught when the id is
+ * added to the node lookup table.
+ */
+#define QRTR_NODE_HOST_BASE 0x10000u
+
+/*
+ * Compute host node id from a per-device index. The index must be unique among
+ * the host assigned endpoints.
+ */
+static inline unsigned int qrtr_host_node_id(unsigned int index)
+{
+	return QRTR_NODE_HOST_BASE + index;
+}
+
+#endif /* _NET_QRTR_H */
diff --git a/net/qrtr/mhi.c b/net/qrtr/mhi.c
index 1040c3c8cfd6..e9377f818b4d 100644
--- a/net/qrtr/mhi.c
+++ b/net/qrtr/mhi.c
@@ -6,6 +6,7 @@
 #include <linux/mhi.h>
 #include <linux/module.h>
 #include <linux/skbuff.h>
+#include <net/qrtr.h>
 #include <net/sock.h>
 
 #include "qrtr.h"
@@ -127,7 +128,8 @@ static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_dev,
 	if (rc)
 		return rc;
 
-	rc = qrtr_endpoint_register(&qdev->ep, QRTR_EP_NID_AUTO);
+	rc = qrtr_endpoint_register(&qdev->ep,
+				    qrtr_host_node_id(mhi_dev->mhi_cntrl->index));
 	if (rc)
 		goto err_unprepare;
 

-- 
2.43.0



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

* [PATCH net-next v6 3/4] wifi: ath11k: Connect to the QMI server belonging to the device owned by this driver
  2026-11-14 14:26 [PATCH net-next v6 0/4] net: qrtr: Add support for using identical MHI endpoint devices Manivannan Sadhasivam via B4 Relay
  2026-11-14 14:26 ` [PATCH net-next v6 1/4] net: qrtr: Allow the host QRTR to assign a unique node id Manivannan Sadhasivam via B4 Relay
  2026-11-14 14:26 ` [PATCH net-next v6 2/4] net: qrtr: Assign unique node id for MHI endpoints Manivannan Sadhasivam via B4 Relay
@ 2026-11-14 14:26 ` Manivannan Sadhasivam via B4 Relay
  2026-11-14 14:26 ` [PATCH net-next v6 4/4] wifi: ath12k: " Manivannan Sadhasivam via B4 Relay
  3 siblings, 0 replies; 7+ messages in thread
From: Manivannan Sadhasivam via B4 Relay @ 2026-11-14 14:26 UTC (permalink / raw)
  To: Manivannan Sadhasivam, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Simon Horman, Jeff Johnson, Eric Dumazet,
	Eric Dumazet
  Cc: linux-arm-msm, netdev, linux-kernel, linux-wireless, ath11k,
	ath12k, Bjorn Andersson, Chris Lew, Deepak Kumar Singh,
	Raj Kumar Bhagat, Juha-Matti Tilli, Jeff Hugo,
	Manivannan Sadhasivam, Jeff Johnson

From: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>

When two identical ath11k PCIe devices are connected to the same host, both
advertise the WLFW service with the same service and instance id. The QMI
lookup reports both servers to each device, so a device may connect to the
firmware running on the other device.

But now, QRTR provides each MHI endpoint a unique node id which is
different from the node id announced by the device. So use the same id to
pick the correct server. Add a get_qrtr_node_id() HIF callback that returns
the node id derived from the MHI controller index and zero for transports
that do not assign one. In the new_server callback, reject any service
whose node id does not match. A node id of zero disables the check, so
transports that do not assign one keep their current behavior.

Reviewed-by: Simon Horman <horms@kernel.org>
Acked-by: Jeff Johnson <jeff.johnson@oss.qualcomm.com>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
---
 drivers/net/wireless/ath/ath11k/hif.h |  9 +++++++++
 drivers/net/wireless/ath/ath11k/pci.c |  9 +++++++++
 drivers/net/wireless/ath/ath11k/qmi.c | 11 +++++++++++
 3 files changed, 29 insertions(+)

diff --git a/drivers/net/wireless/ath/ath11k/hif.h b/drivers/net/wireless/ath/ath11k/hif.h
index 017fed1b4bd1..f432fa4890be 100644
--- a/drivers/net/wireless/ath/ath11k/hif.h
+++ b/drivers/net/wireless/ath/ath11k/hif.h
@@ -32,6 +32,7 @@ struct ath11k_hif_ops {
 	void (*ce_irq_disable)(struct ath11k_base *ab);
 	void (*get_ce_msi_idx)(struct ath11k_base *ab, u32 ce_id, u32 *msi_idx);
 	void (*coredump_download)(struct ath11k_base *ab);
+	unsigned int (*get_qrtr_node_id)(struct ath11k_base *ab);
 };
 
 static inline void ath11k_hif_ce_irq_enable(struct ath11k_base *ab)
@@ -159,4 +160,12 @@ static inline void ath11k_hif_coredump_download(struct ath11k_base *ab)
 		ab->hif.ops->coredump_download(ab);
 }
 
+static inline unsigned int ath11k_hif_get_qrtr_node_id(struct ath11k_base *ab)
+{
+	if (!ab->hif.ops->get_qrtr_node_id)
+		return 0;
+
+	return ab->hif.ops->get_qrtr_node_id(ab);
+}
+
 #endif /* _HIF_H_ */
diff --git a/drivers/net/wireless/ath/ath11k/pci.c b/drivers/net/wireless/ath/ath11k/pci.c
index a163168f3617..d40c057e130c 100644
--- a/drivers/net/wireless/ath/ath11k/pci.c
+++ b/drivers/net/wireless/ath/ath11k/pci.c
@@ -10,6 +10,7 @@
 #include <linux/of.h>
 #include <linux/time.h>
 #include <linux/vmalloc.h>
+#include <net/qrtr.h>
 
 #include "pci.h"
 #include "core.h"
@@ -900,6 +901,13 @@ static int ath11k_pci_start(struct ath11k_base *ab)
 	return 0;
 }
 
+static unsigned int ath11k_pci_get_qrtr_node_id(struct ath11k_base *ab)
+{
+	struct ath11k_pci *ab_pci = ath11k_pci_priv(ab);
+
+	return qrtr_host_node_id(ab_pci->mhi_ctrl->index);
+}
+
 static const struct ath11k_hif_ops ath11k_pci_hif_ops = {
 	.start = ath11k_pci_start,
 	.stop = ath11k_pcic_stop,
@@ -921,6 +929,7 @@ static const struct ath11k_hif_ops ath11k_pci_hif_ops = {
 #ifdef CONFIG_DEV_COREDUMP
 	.coredump_download = ath11k_pci_coredump_download,
 #endif
+	.get_qrtr_node_id = ath11k_pci_get_qrtr_node_id,
 };
 
 static void ath11k_pci_read_hw_version(struct ath11k_base *ab, u32 *major, u32 *minor)
diff --git a/drivers/net/wireless/ath/ath11k/qmi.c b/drivers/net/wireless/ath/ath11k/qmi.c
index 7dc07339b957..09c23ddffb38 100644
--- a/drivers/net/wireless/ath/ath11k/qmi.c
+++ b/drivers/net/wireless/ath/ath11k/qmi.c
@@ -3170,8 +3170,19 @@ static int ath11k_qmi_ops_new_server(struct qmi_handle *qmi_hdl,
 	struct ath11k_qmi *qmi = container_of(qmi_hdl, struct ath11k_qmi, handle);
 	struct ath11k_base *ab = qmi->ab;
 	struct sockaddr_qrtr *sq = &qmi->sq;
+	unsigned int node_id;
 	int ret;
 
+	/*
+	 * Identical devices advertise the same QMI services, so connect only
+	 * to the QMI server on this device's node. A node id of 0 means the
+	 * transport has not assigned a unique node id, so accept the server
+	 * unfiltered.
+	 */
+	node_id = ath11k_hif_get_qrtr_node_id(ab);
+	if (node_id && service->node != node_id)
+		return -EINVAL;
+
 	sq->sq_family = AF_QIPCRTR;
 	sq->sq_node = service->node;
 	sq->sq_port = service->port;

-- 
2.43.0



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

* [PATCH net-next v6 4/4] wifi: ath12k: Connect to the QMI server belonging to the device owned by this driver
  2026-11-14 14:26 [PATCH net-next v6 0/4] net: qrtr: Add support for using identical MHI endpoint devices Manivannan Sadhasivam via B4 Relay
                   ` (2 preceding siblings ...)
  2026-11-14 14:26 ` [PATCH net-next v6 3/4] wifi: ath11k: Connect to the QMI server belonging to the device owned by this driver Manivannan Sadhasivam via B4 Relay
@ 2026-11-14 14:26 ` Manivannan Sadhasivam via B4 Relay
  3 siblings, 0 replies; 7+ messages in thread
From: Manivannan Sadhasivam via B4 Relay @ 2026-11-14 14:26 UTC (permalink / raw)
  To: Manivannan Sadhasivam, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Simon Horman, Jeff Johnson, Eric Dumazet,
	Eric Dumazet
  Cc: linux-arm-msm, netdev, linux-kernel, linux-wireless, ath11k,
	ath12k, Bjorn Andersson, Chris Lew, Deepak Kumar Singh,
	Raj Kumar Bhagat, Juha-Matti Tilli, Jeff Hugo,
	Manivannan Sadhasivam, Daizhuang Bai, Jeff Johnson

From: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>

When two identical ath12k PCIe devices are connected to the same host, both
advertise the WLFW service with the same service and instance id. The QMI
lookup reports both servers to each device, so a device may connect to the
firmware running on the other device.

But now, QRTR provides each MHI endpoint a unique node id which is
different from the node id announced by the device. So use the same id to
pick the correct server. Add a get_qrtr_node_id() HIF callback that returns
the node id derived from the MHI controller index and zero for transports
that do not assign one. In the new_server callback, reject any service
whose node id does not match. A node id of zero disables the check, so
transports that do not assign one keep their current behavior.

Tested-on: 2x WCN7850 hw2.0 WLAN.IOE_HMT.1.1-00018-QCAHMTSWPL_V1.0_V2.0_SILICONZ-1
Tested-on: QCC2072 hw1.0 PCI WLAN.COL.1.0.c2-00277-QCACOLSWPL_V1_TO_SILICONZ-1

Reviewed-by: Simon Horman <horms@kernel.org>
Tested-by: Juha-Matti Tilli <juha-matti.tilli@iki.fi>
Tested-by: Daizhuang Bai <daizhuang.bai@oss.qualcomm.com>
Acked-by: Jeff Johnson <jeff.johnson@oss.qualcomm.com>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
---
 drivers/net/wireless/ath/ath12k/hif.h |  9 +++++++++
 drivers/net/wireless/ath/ath12k/pci.c |  9 +++++++++
 drivers/net/wireless/ath/ath12k/qmi.c | 12 ++++++++++++
 3 files changed, 30 insertions(+)

diff --git a/drivers/net/wireless/ath/ath12k/hif.h b/drivers/net/wireless/ath/ath12k/hif.h
index aecdb0c5f285..c2cfe9a75493 100644
--- a/drivers/net/wireless/ath/ath12k/hif.h
+++ b/drivers/net/wireless/ath/ath12k/hif.h
@@ -31,6 +31,7 @@ struct ath12k_hif_ops {
 	void (*ce_irq_disable)(struct ath12k_base *ab);
 	void (*get_ce_msi_idx)(struct ath12k_base *ab, u32 ce_id, u32 *msi_idx);
 	void (*coredump_download)(struct ath12k_base *ab);
+	unsigned int (*get_qrtr_node_id)(struct ath12k_base *ab);
 };
 
 static inline int ath12k_hif_map_service_to_pipe(struct ath12k_base *ab, u16 service_id,
@@ -153,4 +154,12 @@ static inline void ath12k_hif_coredump_download(struct ath12k_base *ab)
 	if (ab->hif.ops->coredump_download)
 		ab->hif.ops->coredump_download(ab);
 }
+
+static inline unsigned int ath12k_hif_get_qrtr_node_id(struct ath12k_base *ab)
+{
+	if (!ab->hif.ops->get_qrtr_node_id)
+		return 0;
+
+	return ab->hif.ops->get_qrtr_node_id(ab);
+}
 #endif /* ATH12K_HIF_H */
diff --git a/drivers/net/wireless/ath/ath12k/pci.c b/drivers/net/wireless/ath/ath12k/pci.c
index 12bbb75570f1..e56f2f9d721e 100644
--- a/drivers/net/wireless/ath/ath12k/pci.c
+++ b/drivers/net/wireless/ath/ath12k/pci.c
@@ -10,6 +10,7 @@
 #include <linux/pci.h>
 #include <linux/time.h>
 #include <linux/vmalloc.h>
+#include <net/qrtr.h>
 
 #include "pci.h"
 #include "core.h"
@@ -1493,6 +1494,13 @@ void ath12k_pci_power_down(struct ath12k_base *ab, bool is_suspend)
 	ath12k_pci_sw_reset(ab_pci->ab, false);
 }
 
+static unsigned int ath12k_pci_get_qrtr_node_id(struct ath12k_base *ab)
+{
+	struct ath12k_pci *ab_pci = ath12k_pci_priv(ab);
+
+	return qrtr_host_node_id(ab_pci->mhi_ctrl->index);
+}
+
 static const struct ath12k_hif_ops ath12k_pci_hif_ops = {
 	.start = ath12k_pci_start,
 	.stop = ath12k_pci_stop,
@@ -1513,6 +1521,7 @@ static const struct ath12k_hif_ops ath12k_pci_hif_ops = {
 #ifdef CONFIG_ATH12K_COREDUMP
 	.coredump_download = ath12k_pci_coredump_download,
 #endif
+	.get_qrtr_node_id = ath12k_pci_get_qrtr_node_id,
 };
 
 static enum ath12k_device_family
diff --git a/drivers/net/wireless/ath/ath12k/qmi.c b/drivers/net/wireless/ath/ath12k/qmi.c
index 817bd820623d..86ec7f2431e2 100644
--- a/drivers/net/wireless/ath/ath12k/qmi.c
+++ b/drivers/net/wireless/ath/ath12k/qmi.c
@@ -9,6 +9,7 @@
 #include "qmi.h"
 #include "core.h"
 #include "debug.h"
+#include "hif.h"
 #include <linux/of.h>
 #include <linux/firmware.h>
 #include <linux/of_address.h>
@@ -3992,8 +3993,19 @@ static int ath12k_qmi_ops_new_server(struct qmi_handle *qmi_hdl,
 	struct ath12k_qmi *qmi = container_of(qmi_hdl, struct ath12k_qmi, handle);
 	struct ath12k_base *ab = qmi->ab;
 	struct sockaddr_qrtr *sq = &qmi->sq;
+	unsigned int node_id;
 	int ret;
 
+	/*
+	 * Identical devices advertise the same QMI services, so connect only
+	 * to the QMI server on this device's node. A node id of 0 means the
+	 * transport has not assigned a unique node id, so accept the server
+	 * unfiltered.
+	 */
+	node_id = ath12k_hif_get_qrtr_node_id(ab);
+	if (node_id && service->node != node_id)
+		return -EINVAL;
+
 	sq->sq_family = AF_QIPCRTR;
 	sq->sq_node = service->node;
 	sq->sq_port = service->port;

-- 
2.43.0



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

* Re: [PATCH net-next v6 1/4] net: qrtr: Allow the host QRTR to assign a unique node id
  2026-11-14 14:26 ` [PATCH net-next v6 1/4] net: qrtr: Allow the host QRTR to assign a unique node id Manivannan Sadhasivam via B4 Relay
@ 2026-11-16  0:44   ` netdev-bot+sashiko
  0 siblings, 0 replies; 7+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16  0:44 UTC (permalink / raw)
  To: manivannan.sadhasivam
  Cc: mani, davem, kuba, pabeni, horms, jjohnson, edumazet,
	linux-arm-msm, netdev, linux-kernel, linux-wireless, ath11k,
	ath12k, andersson, christopher.lew, deepak.singh, raj.bhagat,
	juha-matti.tilli, jeff.hugo, daizhuang.bai, jeff.johnson

Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · Low: 3

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] A failed node-id insert now drops the packet, where the old
  code still delivered it, and a dropped HELLO is never recovered.
- [Medium] In AUTO mode, nid and ep_nid can end up different, which the
  commit message says cannot happen, and the rewrite logic then…
- [Low] The TX path now uses node->ep_nid as the destination, but the
  readiness guard still checks node->nid, so packets can go out…
- [Low] The new control-packet handling is keyed on the QRTR header type
  (cb->type), but the consumer acts on the payload cmd field.
- [Low] The struct qrtr_node kernel-doc describes @ep_nid as the
  "endpoint's own node id as received", but qrtr_endpoint_post() latches…

--

net: qrtr: Allow the host QRTR to assign a unique node id

This commit lets the host QRTR use the nid passed to
qrtr_endpoint_register() as the key in the qrtr_nodes radix tree. The
endpoint's own source id is stored in a new qrtr_node->ep_nid field.
Node ids in incoming packets are rewritten from ep_nid to nid, and
outgoing destinations are rewritten from nid back to ep_nid. Errors from
radix_tree_insert() are now passed back to the caller.

> diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
> index 45cb8e8c36ca2..fff1d70fd8bfc 100644
> --- a/net/qrtr/af_qrtr.c
> +++ b/net/qrtr/af_qrtr.c
> @@ -118,7 +118,8 @@ static DEFINE_XARRAY_ALLOC(qrtr_ports);
>   * @ep_lock: lock for endpoint management and callbacks
>   * @ep: endpoint
>   * @ref: reference count for node
> - * @nid: node id
> + * @nid: node id assigned by the host QRTR
> + * @ep_nid: endpoint's own node id as received

[Severity: Low]
Is this description accurate? qrtr_endpoint_post() sets ep_nid from the
src_node of the first packet that arrives, whatever its type:

	if (node->ep_nid == QRTR_EP_NID_AUTO)
		WRITE_ONCE(node->ep_nid, nid);

Nothing checks that this packet is a HELLO, or that it came from the
endpoint itself and not from a node it bridges. The commit message itself
says incoming source ids can belong to bridged nodes.

Suppose the first packet is forwarded from a bridged node Y. Then ep_nid
becomes Y, and the endpoint's real id X is treated as a bridged key. Y's
traffic is rewritten to the host nid in qrtr_endpoint_post() and
qrtr_node_rewrite_ctrl(). TX addressed to the host nid in
qrtr_node_enqueue() goes to Y.

With the later explicit-nid MHI change, would the ath11k/ath12k host nid
filter in their qmi_ops_new_server() callbacks then accept Y's services
and reject X's?

[ ... ]

> @@ -371,10 +374,14 @@ static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb,
>  	hdr->src_node_id = cpu_to_le32(from->sq_node);
>  	hdr->src_port_id = cpu_to_le32(from->sq_port);
>  	if (to->sq_port == QRTR_PORT_CTRL) {
> -		hdr->dst_node_id = cpu_to_le32(READ_ONCE(node->nid));
> +		hdr->dst_node_id = cpu_to_le32(READ_ONCE(node->ep_nid));
>  		hdr->dst_port_id = cpu_to_le32(QRTR_PORT_CTRL);
>  	} else {
> -		hdr->dst_node_id = cpu_to_le32(to->sq_node);
> +		/* Put back the endpoint's own node id */
> +		dst_node = to->sq_node;
> +		if (dst_node == READ_ONCE(node->nid))
> +			dst_node = READ_ONCE(node->ep_nid);
> +		hdr->dst_node_id = cpu_to_le32(dst_node);
>  		hdr->dst_port_id = cpu_to_le32(to->sq_port);
>  	}

[Severity: Low]
Can ep_nid still be QRTR_EP_NID_AUTO at this point?

The readiness guard in qrtr_bcast_enqueue() still checks node->nid, not
ep_nid:

	/* Skip nodes with no assigned node ID yet. */
	if (READ_ONCE(node->nid) == QRTR_EP_NID_AUTO)
		continue;

When qrtr_endpoint_register() is given an explicit nid, node->nid is set
at registration time. ep_nid stays QRTR_EP_NID_AUTO until the first RX
packet. The later commit "net: qrtr: Assign unique node id for MHI
endpoints" makes this the normal MHI case.

Consider the window after hello_sent is set but before the remote's first
packet arrives. Would ns broadcasts (NEW_SERVER, DEL_SERVER, DEL_CLIENT)
and data packets sent to the host nid go out with dst_node_id 0xffffffff
during that window?

In QRTR_EP_NID_AUTO mode, ep_nid and node->nid are written by separate
WRITE_ONCE() stores in qrtr_endpoint_post() and __qrtr_node_assign(), with
no ordering between them. qrtr_bcast_enqueue() and qrtr_node_enqueue()
read both without taking qrtr_nodes_lock. Could a weakly ordered CPU see
the new nid together with the old ep_nid?

[ ... ]

> @@ -533,14 +597,36 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
>  
>  	skb_put_data(skb, data + hdrlen, size);
>  
> -	qrtr_node_assign(node, cb->src_node);
> +	nid = cb->src_node;
> +
> +	spin_lock_irqsave(&qrtr_nodes_lock, flags);
> +
> +	if (node->ep_nid == QRTR_EP_NID_AUTO)
> +		WRITE_ONCE(node->ep_nid, nid);
> +
> +	/*
> +	 * Add the source id to the lookup table only if 'node->nid' is auto
> +	 * assigned or the packet came from a bridged node.
> +	 */
> +	if (node->nid == QRTR_EP_NID_AUTO || nid != node->ep_nid)
> +		rc = __qrtr_node_assign(node, nid);
> +

[Severity: Medium]
Can node->nid and ep_nid end up different for an endpoint registered with
QRTR_EP_NID_AUTO? The commit message says they stay the same for these
callers.

ep_nid is set before __qrtr_node_assign() runs, whether or not it
succeeds. Consider an AUTO endpoint where:

1. The first packet's src X is already owned by another node (-EEXIST),
   or the GFP_ATOMIC insert fails (-ENOMEM). ep_nid = X is set,
   node->nid stays QRTR_EP_NID_AUTO, and the packet is dropped.

2. The next packet is forwarded from a bridged node Y. node->nid is still
   QRTR_EP_NID_AUTO, so __qrtr_node_assign(Y) succeeds and adopts Y:

	if (node->nid == QRTR_EP_NID_AUTO)
		WRITE_ONCE(node->nid, nid);

Now nid == Y and ep_nid == X. From then on, packets from X have
cb->src_node rewritten to Y. qrtr_node_rewrite_ctrl() also rewrites
NEW_SERVER, DEL_SERVER, DEL_CLIENT and RESUME_TX payloads that name X so
they name Y.

In qrtr_node_enqueue(), packets addressed to the real bridged node Y are
rewritten to dst_node_id X, so Y can no longer be reached. X is never
inserted later either, because the condition above skips the insert once
node->nid is set and nid == ep_nid.

Before this patch, node->nid would simply have become X, and Y was routed
through its own key. Is this change in behavior intended?

> +	spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
> +
> +	if (rc)
> +		goto err_nid;
>  
>  	if (cb->type == QRTR_TYPE_NEW_SERVER) {
>  		/* Remote node endpoint can bridge other distant nodes */
> -		const struct qrtr_ctrl_pkt *pkt;
> +		const struct qrtr_ctrl_pkt *pkt = data + hdrlen;
> +
> +		nid = le32_to_cpu(pkt->server.node);
>  
> -		pkt = data + hdrlen;
> -		qrtr_node_assign(node, le32_to_cpu(pkt->server.node));
> +		if (nid != READ_ONCE(node->ep_nid)) {
> +			rc = qrtr_node_assign(node, nid);
> +			if (rc)
> +				goto err_nid;
> +		}
>  	}

[Severity: Medium]
Is it intended that a failed node id insert now drops the whole packet?

Before this patch, qrtr_node_assign() ignored the result of
radix_tree_insert(). The packet was still delivered, and node->nid was set
anyway. Now __qrtr_node_assign() can return -EEXIST, or -ENOMEM because
qrtr_nodes is a GFP_ATOMIC radix tree. Both goto err_nid sites above then
free the skb.

For QRTR_EP_NID_AUTO endpoints (smd and tun, and MHI as of this commit),
these cases seem to follow.

If the source id X is already a key owned by another qrtr_node, every
packet from this node is dropped. node->nid stays QRTR_EP_NID_AUTO, the
insert is retried and fails on every packet, and qrtr_bcast_enqueue()
skips the node.

If the first packet hits a transient -ENOMEM or a stale key, the remote's
HELLO is dropped before hello_rcvd is set and before it reaches the ns
control port. Stale keys are possible because keys are only removed in
__qrtr_node_release() at the final kref put, not in
qrtr_endpoint_unregister(). qrtr_sendmsg() and qrtr_send_resume_tx() can
hold that reference.

In that case qrtr_hello_work() does not reschedule:

	/* Pairs with smp_store_release() in qrtr_endpoint_post() */
	if (!smp_load_acquire(&node->hello_rcvd))
		goto out;

Would the ns then never see this node's HELLO, even after the conflict
goes away?

Even with an explicit nid, a whole NEW_SERVER is now dropped when its
bridged server.node is owned by another node. Before, only the extra key
was skipped.

The commit message says:

    Currently, all QRTR endpoint drivers pass 'QRTR_EP_NID_AUTO' as the 'nid'
    during qrtr_endpoint_register(). So 'ep_nid' and 'nid' are same and the
    routing behavior is not changed.

Given these new drops, is that statement still accurate?

> @@ -548,6 +634,15 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
>  		smp_store_release(&node->hello_rcvd, true);
>  	}
>  
> +	if (cb->src_node == READ_ONCE(node->ep_nid))
> +		cb->src_node = READ_ONCE(node->nid);
> +
> +	if (cb->type == QRTR_TYPE_NEW_SERVER ||
> +	    cb->type == QRTR_TYPE_DEL_SERVER ||
> +	    cb->type == QRTR_TYPE_DEL_CLIENT ||
> +	    cb->type == QRTR_TYPE_RESUME_TX)
> +		qrtr_node_rewrite_ctrl(node, cb->type, skb);
> +

[Severity: Low]
Should these checks and the rewrite be keyed on the payload cmd instead of
cb->type?

qrtr_ns_worker() in net/qrtr/ns.c dispatches on the payload and never sees
the header type:

	cmd = le32_to_cpu(pkt->cmd);

qrtr_endpoint_post() accepts any header type sent to QRTR_PORT_CTRL. So a
remote can send a QRTR_TYPE_DATA packet to the CTRL port carrying a
NEW_SERVER, DEL_SERVER or DEL_CLIENT payload. For such a packet, the new
NEW_SERVER server.node ownership check and qrtr_node_rewrite_ctrl() are
both skipped. The cb->src_node rewrite above still runs.

This seems to lead to the following.

A NEW_SERVER payload that names another device's host nid gets past the
new -EEXIST rejection and is registered in the ns.

For a DEL_CLIENT payload under a different header type, from is rewritten
to the host nid but client.node stays at ep_nid. The anti-spoof check in
ctrl_cmd_del_client() then rejects it:

	/* Don't accept spoofed messages */
	if (from->sq_node != node_id)
		return -EINVAL;

NEW_SERVER payloads are recorded under ep_nid instead of the unique host
nid.

Also, qrtr_node_rewrite_ctrl() chooses the union member from the header
type:

	if (type == QRTR_TYPE_DEL_CLIENT || type == QRTR_TYPE_RESUME_TX)
		nid = &pkt->client.node;
	else
		nid = &pkt->server.node;

With a DEL_CLIENT header and a NEW_SERVER payload, would this rewrite
client.node? That field is at the same offset as server.service.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261114-qrtr-multi-ep-v6-0-2eb9885659e2%40oss.qualcomm.com

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

* Re: [PATCH net-next v6 2/4] net: qrtr: Assign unique node id for MHI endpoints
  2026-11-14 14:26 ` [PATCH net-next v6 2/4] net: qrtr: Assign unique node id for MHI endpoints Manivannan Sadhasivam via B4 Relay
@ 2026-11-16  0:44   ` netdev-bot+sashiko
  0 siblings, 0 replies; 7+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16  0:44 UTC (permalink / raw)
  To: manivannan.sadhasivam
  Cc: mani, davem, kuba, pabeni, horms, jjohnson, edumazet,
	linux-arm-msm, netdev, linux-kernel, linux-wireless, ath11k,
	ath12k, andersson, christopher.lew, deepak.singh, raj.bhagat,
	juha-matti.tilli, jeff.hugo, daizhuang.bai, jeff.johnson

Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 3 · Low: 2

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] Both the commit message and the new comment in
  include/net/qrtr.h say that 'an endpoint using v2 can never claim an…
- [Medium] MHI QRTR now registers a fixed nid, 0x10000 +
  mhi_cntrl->index, and this id is reused.
- [Medium] net: qrtr: missing sysfs ABI for host node ID in
  qcom_mhi_qrtr_probe()
- [Low] The comment in include/net/qrtr.h says 'A collision is caught
  when the id is added to the node lookup table.' One case is not…
- [Low] The host nid is now in qrtr_nodes from the moment
  qrtr_endpoint_register() runs.

--

net: qrtr: Assign unique node id for MHI endpoints

This adds include/net/qrtr.h. The header defines QRTR_NODE_HOST_BASE
(0x10000) and a qrtr_host_node_id() helper that returns the base plus a
per-device index. The MHI QRTR driver now registers its endpoint with
qrtr_host_node_id(mhi_cntrl->index) instead of QRTR_EP_NID_AUTO.

> diff --git a/include/net/qrtr.h b/include/net/qrtr.h
> new file mode 100644
> index 0000000000000..e2a8d93564b58
> --- /dev/null
> +++ b/include/net/qrtr.h
> @@ -0,0 +1,27 @@

[ ... ]

> +/*
> + * Base for the node ids the host assigns to endpoints. It sits just above the
> + * 16-bit range a v2 header can express, so a v2 endpoint can never claim an id
> + * in it. A v1 endpoint can claim any 32-bit id, so a collision is possible,
> + * but unlikely as the firmware assigned node ids are either smaller than this
> + * base or in the range of 0x08e5ff85. A collision is caught when the id is
> + * added to the node lookup table.
> + */
> +#define QRTR_NODE_HOST_BASE 0x10000u

[Severity: Medium]
Is it accurate that a v2 endpoint can never claim an id in this range?
The commit message makes the same claims:

  "The base is chosen just above the 16-bit range a v2 header can
  express, so an endpoint using v2 can never claim an id in the host
  range."

  "Such a collision is caught when the id is added to the node lookup
  table."

In qrtr_endpoint_post(), the NEW_SERVER handler reads a 32-bit node id
from the payload, whatever the header version:

net/qrtr/af_qrtr.c:qrtr_endpoint_post() {
    ...
	if (cb->type == QRTR_TYPE_NEW_SERVER) {
		...
		nid = le32_to_cpu(pkt->server.node);

		if (nid != READ_ONCE(node->ep_nid)) {
			rc = qrtr_node_assign(node, nid);
    ...
}

That means a v2 endpoint can insert an id such as 0x10001 into
qrtr_nodes as a bridged key. A v1 endpoint can do the same through
src_node_id. __qrtr_node_assign() does not check the id against
QRTR_NODE_HOST_BASE.

The only collision handling is radix_tree_insert() returning -EEXIST,
so whoever claims the id first keeps it:

	rc = radix_tree_insert(&qrtr_nodes, nid, node);
	if (rc)
		return rc;

The host ids are easy to predict. They are 0x10000 plus the lowest free
IDA index, and they stay the same across MHI recovery. Another remote
endpoint could claim 0x10000 + N before MHI controller N registers, or
while it is between remove and re-probe. That endpoint could be another
MHI card's firmware, an SMD/rpmsg remoteproc, or a /dev/qrtr-tun user.

In that case, wouldn't
qcom_mhi_qrtr_probe()->qrtr_endpoint_register()->qrtr_node_assign()
get -EEXIST and abort the probe, so the device's QRTR link never comes
up? With QRTR_EP_NID_AUTO, registration could not fail on an id
conflict.

[Severity: Low]
One collision is not caught the way this comment describes: a
remote-claimed id that equals the endpoint's own host nid.
__qrtr_node_assign() returns success without an error in that case:

	if (radix_tree_lookup(&qrtr_nodes, nid) == node)
		return 0;

Suppose the remote behind MHI endpoint N sends a v1 src_node_id of
0x10000 + N (which differs from ep_nid), or a NEW_SERVER with
server.node = 0x10000 + N. The assign succeeds silently. The source id
is not rewritten either, because qrtr_endpoint_post() only rewrites
ep_nid:

	if (cb->src_node == READ_ONCE(node->ep_nid))
		cb->src_node = READ_ONCE(node->nid);

A local reply to 0x10000 + N is then rewritten in qrtr_node_enqueue():

		dst_node = to->sq_node;
		if (dst_node == READ_ONCE(node->nid))
			dst_node = READ_ONCE(node->ep_nid);

Wouldn't that send the reply to the endpoint's own node rather than the
bridged node that sent the packet? It would also merge the bridged
node's services with the endpoint's own.

[ ... ]

> diff --git a/net/qrtr/mhi.c b/net/qrtr/mhi.c
> index 1040c3c8cfd68..e9377f818b4dd 100644
> --- a/net/qrtr/mhi.c
> +++ b/net/qrtr/mhi.c

[ ... ]

> @@ -127,7 +128,8 @@ static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_dev,
>  	if (rc)
>  		return rc;
>  
> -	rc = qrtr_endpoint_register(&qdev->ep, QRTR_EP_NID_AUTO);
> +	rc = qrtr_endpoint_register(&qdev->ep,
> +				    qrtr_host_node_id(mhi_dev->mhi_cntrl->index));

[Severity: Medium]
This changes the node id that userspace sees for every MHI QRTR
endpoint. Before, the remote's own id was what ended up in qrtr_nodes
and in the NEW_SERVER notifications delivered to AF_QIPCRTR sockets.
Now a host nid is passed to qrtr_endpoint_register(), and
qrtr_endpoint_post() and qrtr_node_rewrite_ctrl() rewrite the
firmware-advertised id (node->ep_nid) to node->nid. Lookups therefore
report 0x10000 + mhi_cntrl->index.

How is a userspace client supposed to map an MHI device to its QRTR
node after this? As I understand it, on QAIC the firmware nid matches
the serial number exposed through sysfs and the QAIC control channel,
so a client could correlate the two. The lookup notifications only
carry service, instance, node and port. They have no device
identifier.

In-kernel users such as ath11k and ath12k can call
qrtr_host_node_id() on their own mhi_cntrl->index. However,
include/net/qrtr.h is not UAPI. The only option left for userspace
seems to be parsing the mhiN controller name and hardcoding
QRTR_NODE_HOST_BASE. That would turn an internal constant into ABI
without documenting it.

My understanding from earlier review of this series was that the
assigned node id would be exposed through a sysfs attribute. I can't
find that anywhere in v6. Was it dropped on purpose, or is it planned
for a follow-up? Since this is the patch that changes the ids
userspace sees, shouldn't the attribute land together with it?

[Severity: Medium]
Can a re-probe fail here while the previous qrtr_node is still
referenced?

This nid is now fixed and gets reused. mhi_unregister_controller()
frees the IDA index, and mhi_register_controller() gets the same value
back from ida_alloc(). MHI SYS_ERR recovery or a power cycle also
recreates the devices on the same controller.

qrtr_endpoint_register() now inserts the nid into qrtr_nodes at
registration time and returns -EEXIST if the slot is taken. However,
qrtr_endpoint_unregister() only drops its own reference:

	qrtr_node_release(node);
	ep->node = NULL;

The radix tree slots are removed only in __qrtr_node_release(), on the
final kref put:

	radix_tree_for_each_slot(slot, &qrtr_nodes, &iter, 0) {
		if (*slot == node)
			radix_tree_iter_delete(&qrtr_nodes, &iter, slot);
	}

qrtr_sendmsg() takes a node reference with qrtr_node_lookup() and holds
it until qrtr_node_release(). In between it calls
sock_alloc_send_skb(), which can block, and memcpy_from_msg(), which
can fault on user memory. qrtr_send_resume_tx() holds a reference in a
similar way.

qrtr_create() has no capability check, so an unprivileged user can
sendmsg() to the predictable host nid with a slow-faulting buffer, for
example a FUSE-backed mapping. That keeps the old node referenced.

If the device is re-probed during that window, wouldn't
radix_tree_insert() return -EEXIST and make qcom_mhi_qrtr_probe() fail?
The QRTR link would then stay down until the next probe. With
QRTR_EP_NID_AUTO, registration always succeeded and later packets
retried the assignment.

[Severity: Low]
Does passing a concrete nid here open a window where DATA packets go
out with a broadcast destination node id?

The node can be looked up by 0x10000 + index as soon as
qrtr_endpoint_register() runs. node->ep_nid stays QRTR_EP_NID_AUTO
(0xFFFFFFFF) until qrtr_endpoint_post() receives the first packet.
qrtr_hello_work() sends HELLO right away, and hello_sent is set once
xmit succeeds, whether or not the remote has replied.

Consider a qrtr_sendmsg() of a DATA packet to (0x10000 + index, port)
in that window. It passes the lookup and the hello_sent check, and then
qrtr_node_enqueue() does:

		dst_node = to->sq_node;
		if (dst_node == READ_ONCE(node->nid))
			dst_node = READ_ONCE(node->ep_nid);
		hdr->dst_node_id = cpu_to_le32(dst_node);

Wouldn't that put dst_node_id = 0xFFFFFFFF (QRTR_NODE_BCAST) in a
unicast DATA header sent to the firmware? With QRTR_EP_NID_AUTO, a node
only became findable in the same critical section that set ep_nid, so
this state could not occur.

>  	if (rc)
>  		goto err_unprepare;
>

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261114-qrtr-multi-ep-v6-0-2eb9885659e2%40oss.qualcomm.com

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

end of thread, other threads:[~2026-11-16  0:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-14 14:26 [PATCH net-next v6 0/4] net: qrtr: Add support for using identical MHI endpoint devices Manivannan Sadhasivam via B4 Relay
2026-11-14 14:26 ` [PATCH net-next v6 1/4] net: qrtr: Allow the host QRTR to assign a unique node id Manivannan Sadhasivam via B4 Relay
2026-11-16  0:44   ` netdev-bot+sashiko
2026-11-14 14:26 ` [PATCH net-next v6 2/4] net: qrtr: Assign unique node id for MHI endpoints Manivannan Sadhasivam via B4 Relay
2026-11-16  0:44   ` netdev-bot+sashiko
2026-11-14 14:26 ` [PATCH net-next v6 3/4] wifi: ath11k: Connect to the QMI server belonging to the device owned by this driver Manivannan Sadhasivam via B4 Relay
2026-11-14 14:26 ` [PATCH net-next v6 4/4] wifi: ath12k: " Manivannan Sadhasivam via B4 Relay

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

all inboxes | Powered by JetHome®