* [PATCH v6 01/15] net: qrtr: ns: validate msglen before ctrl_pkt use
2026-09-01 13:19 [PATCH v6 00/15] QRTR Multi-endpoint support Juha-Matti Tilli
@ 2026-09-01 13:19 ` Juha-Matti Tilli
2026-09-01 13:19 ` [PATCH v6 02/15] net: qrtr: allocate and track endpoint ids Juha-Matti Tilli
` (13 subsequent siblings)
14 siblings, 0 replies; 20+ messages in thread
From: Juha-Matti Tilli @ 2026-09-01 13:19 UTC (permalink / raw)
To: linux-arm-msm, Manivannan Sadhasivam
Cc: Eric Dumazet, Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn,
David S . Miller, Jakub Kicinski, Simon Horman, Marcel Holtmann,
Andy Gross, Mihai Moldovan, Denis Kenzior, Juha-Matti Tilli,
linux-kernel, netdev
From: Denis Kenzior <denkenz@gmail.com>
The qrtr_ctrl_pkt structure is currently accessed without checking
if the received payload is large enough to hold the structure's fields.
Add a check to ensure the payload length is sufficient.
Signed-off-by: Denis Kenzior <denkenz@gmail.com>
Reviewed-by: Marcel Holtmann <marcel@holtmann.org>
Reviewed-by: Andy Gross <agross@kernel.org>
Signed-off-by: Mihai Moldovan <ionic@ionic.de>
Fixes: 0c2204a4ad71 ("net: qrtr: Migrate nameservice to kernel from userspace")
Signed-off-by: Juha-Matti Tilli <juha-matti.tilli@iki.fi>
---
net/qrtr/ns.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/qrtr/ns.c b/net/qrtr/ns.c
index e5b2adb161d92..d544e4998c5d5 100644
--- a/net/qrtr/ns.c
+++ b/net/qrtr/ns.c
@@ -668,6 +668,9 @@ static void qrtr_ns_worker(struct work_struct *work)
break;
}
+ if ((size_t)msglen < sizeof(*pkt))
+ break;
+
pkt = recv_buf;
cmd = le32_to_cpu(pkt->cmd);
if (cmd < ARRAY_SIZE(qrtr_ctrl_pkt_strings) &&
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread* [PATCH v6 02/15] net: qrtr: allocate and track endpoint ids
2026-09-01 13:19 [PATCH v6 00/15] QRTR Multi-endpoint support Juha-Matti Tilli
2026-09-01 13:19 ` [PATCH v6 01/15] net: qrtr: ns: validate msglen before ctrl_pkt use Juha-Matti Tilli
@ 2026-09-01 13:19 ` Juha-Matti Tilli
2026-09-01 13:19 ` [PATCH v6 03/15] net: qrtr: fit node ID + port number combination into unsigned long Juha-Matti Tilli
` (12 subsequent siblings)
14 siblings, 0 replies; 20+ messages in thread
From: Juha-Matti Tilli @ 2026-09-01 13:19 UTC (permalink / raw)
To: linux-arm-msm, Manivannan Sadhasivam
Cc: Eric Dumazet, Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn,
David S . Miller, Jakub Kicinski, Simon Horman, Marcel Holtmann,
Andy Gross, Mihai Moldovan, Denis Kenzior, Juha-Matti Tilli,
linux-kernel, netdev
From: Denis Kenzior <denkenz@gmail.com>
Currently, QRTR endpoints are tracked solely by their pointer value,
which is sufficient as they are not exposed to user space and it is
assumed that each endpoint has a unique set of node identifiers
associated with it. However, this assumption does not hold when
multiple devices of the same type are connected to the system. For
example, multiple PCIe based 5G modems. Such a setup results in
multiple endpoints with confliciting node identifiers.
To enable support for such scenarios, introduce the ability to track
and assign unique identifiers to QRTR endpoints. These identifiers
can then be exposed to user space, allowing for userspace clients to
identify which endpoint sent a given message, or to direct a message
to a specific endpoint.
A simple allocation strategy is used based on xa_alloc_cyclic. Remote
endpoint ids start at 'qrtr_local_nid' + 1. Since qrtr_local_nid is
currently always set to 1 and never changed, node identifiers start at
'1' for the local endpoint and 2..INT_MAX for remote endpoints.
Signed-off-by: Denis Kenzior <denkenz@gmail.com>
Reviewed-by: Marcel Holtmann <marcel@holtmann.org>
Reviewed-by: Andy Gross <agross@kernel.org>
Signed-off-by: Mihai Moldovan <ionic@ionic.de>
Signed-off-by: Juha-Matti Tilli <juha-matti.tilli@iki.fi>
---
net/qrtr/af_qrtr.c | 24 ++++++++++++++++++++++++
net/qrtr/qrtr.h | 1 +
2 files changed, 25 insertions(+)
diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index a30fa56e6aa31..38b6def7c5272 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -22,6 +22,7 @@
#define QRTR_MAX_EPH_SOCKET 0x7fff
#define QRTR_EPH_PORT_RANGE \
XA_LIMIT(QRTR_MIN_EPH_SOCKET, QRTR_MAX_EPH_SOCKET)
+#define QRTR_ENDPOINT_RANGE XA_LIMIT(qrtr_local_nid + 1, INT_MAX)
#define QRTR_PORT_CTRL_LEGACY 0xffff
@@ -109,6 +110,10 @@ static LIST_HEAD(qrtr_all_nodes);
/* lock for qrtr_all_nodes and node reference */
static DEFINE_MUTEX(qrtr_node_lock);
+/* endpoint id allocation management */
+static DEFINE_XARRAY_ALLOC(qrtr_endpoints);
+static u32 next_endpoint_id;
+
/* local port allocation management */
static DEFINE_XARRAY_ALLOC(qrtr_ports);
@@ -581,6 +586,8 @@ static struct sk_buff *qrtr_alloc_ctrl_packet(struct qrtr_ctrl_pkt **pkt,
int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid)
{
struct qrtr_node *node;
+ u32 endpoint_id;
+ int rc;
if (!ep || !ep->xmit)
return -EINVAL;
@@ -589,6 +596,13 @@ int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid)
if (!node)
return -ENOMEM;
+ rc = xa_alloc_cyclic(&qrtr_endpoints, &endpoint_id, NULL,
+ QRTR_ENDPOINT_RANGE, &next_endpoint_id,
+ GFP_KERNEL);
+
+ if (rc < 0)
+ goto free_node;
+
kref_init(&node->ref);
mutex_init(&node->ep_lock);
skb_queue_head_init(&node->rx_queue);
@@ -604,8 +618,12 @@ int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid)
list_add(&node->item, &qrtr_all_nodes);
mutex_unlock(&qrtr_node_lock);
ep->node = node;
+ ep->id = endpoint_id;
return 0;
+free_node:
+ kfree(node);
+ return rc;
}
EXPORT_SYMBOL_GPL(qrtr_endpoint_register);
@@ -625,8 +643,10 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep)
unsigned long flags;
unsigned long index;
void __rcu **slot;
+ u32 endpoint_id;
mutex_lock(&node->ep_lock);
+ endpoint_id = node->ep->id;
node->ep = NULL;
mutex_unlock(&node->ep_lock);
@@ -651,6 +671,10 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep)
mutex_unlock(&node->qrtr_tx_lock);
qrtr_node_release(node);
+
+ xa_erase(&qrtr_endpoints, endpoint_id);
+
+ ep->id = 0;
ep->node = NULL;
}
EXPORT_SYMBOL_GPL(qrtr_endpoint_unregister);
diff --git a/net/qrtr/qrtr.h b/net/qrtr/qrtr.h
index 3f2d28696062a..11b897af05e67 100644
--- a/net/qrtr/qrtr.h
+++ b/net/qrtr/qrtr.h
@@ -21,6 +21,7 @@ struct qrtr_endpoint {
int (*xmit)(struct qrtr_endpoint *ep, struct sk_buff *skb);
/* private: not for endpoint use */
struct qrtr_node *node;
+ u32 id;
};
int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid);
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread* [PATCH v6 03/15] net: qrtr: fit node ID + port number combination into unsigned long
2026-09-01 13:19 [PATCH v6 00/15] QRTR Multi-endpoint support Juha-Matti Tilli
2026-09-01 13:19 ` [PATCH v6 01/15] net: qrtr: ns: validate msglen before ctrl_pkt use Juha-Matti Tilli
2026-09-01 13:19 ` [PATCH v6 02/15] net: qrtr: allocate and track endpoint ids Juha-Matti Tilli
@ 2026-09-01 13:19 ` Juha-Matti Tilli
2026-09-01 13:19 ` [PATCH v6 04/15] net: qrtr: use only low 16 bits of node/port in 32-bit systems Juha-Matti Tilli
` (11 subsequent siblings)
14 siblings, 0 replies; 20+ messages in thread
From: Juha-Matti Tilli @ 2026-09-01 13:19 UTC (permalink / raw)
To: linux-arm-msm, Manivannan Sadhasivam
Cc: Eric Dumazet, Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn,
David S . Miller, Jakub Kicinski, Simon Horman, Marcel Holtmann,
Andy Gross, Mihai Moldovan, Denis Kenzior, Juha-Matti Tilli,
linux-kernel, netdev
From: Mihai Moldovan <ionic@ionic.de>
The flow control implementation uses a radix tree to store node ID and
port number combinations and the key length is hardcoded to unsigned
long.
The original implementation shifted the node ID up by 32 bits and added
the port number to the lower 32 bits of the unsigned long value to
create a key.
Unfortunately, since both node IDs and port numbers are defined as u32,
this will overflow on platforms where sizeof(unsigned long) < 8 (which
are most 32 bit platforms) and essentially just drop the node ID part.
To fix this, build the key in a generic way, using half of the unsigned
long space for the node ID and the other half for the port number.
This will be transparent to platforms where sizeof(unsigned long) >= 8
and fix overflow issues otherwise.
The caveat, of course, is that, for platforms where
sizeof(unsigned long) < 8, the supported amount of node IDs and port
numbers will be severely limited - to half of sizeof(unsigned long),
which typically will be 16 bits. Needless to say, we have to check if
both values fit into this limit.
This limitation is probably not going to be an issue in real-world
scenarios, but if it turns out to be one after all, we could switch from
a radix tree implementation to an XArray implementation.
Signed-off-by: Mihai Moldovan <ionic@ionic.de>
Fixes: 5fdeb0d372ab ("net: qrtr: Implement outgoing flow control")
Signed-off-by: Juha-Matti Tilli <juha-matti.tilli@iki.fi>
---
net/qrtr/af_qrtr.c | 74 +++++++++++++++++++++++++++++++++++++++-------
1 file changed, 64 insertions(+), 10 deletions(-)
diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index 38b6def7c5272..f2edbd2e9dea9 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -117,6 +117,26 @@ static u32 next_endpoint_id;
/* local port allocation management */
static DEFINE_XARRAY_ALLOC(qrtr_ports);
+/* The xarray API uses fixed unsigned long keys and we will have to make
+ * do with that.
+ * These keys are often a combination of node IDs (currently u32) and
+ * port numbers (also currently u32).
+ * Using the high 32 bits for the node ID and the low 32 bits for the
+ * port number will work fine to create keys on platforms where unsigned long
+ * is 64 bits wide, but obviously is not be possible on platforms where
+ * unsigned long is smaller.
+ * Virtually split up unsigned long in half and assign the upper bits to
+ * node IDs and the lower bits to the port number, however big that may be.
+ */
+#define QRTR_XARRAY_INDEX_BITS (8 /* CHAR_BIT */ * sizeof(unsigned long))
+#define QRTR_INDEX_HALF_BITS (QRTR_XARRAY_INDEX_BITS >> 1)
+
+#define QRTR_INDEX_HALF_UNSIGNED_MAX ((~(unsigned long)(0)) >> QRTR_INDEX_HALF_BITS)
+#define QRTR_INDEX_HALF_UNSIGNED_MIN ((unsigned long)(0))
+
+#define QRTR_INDEX_HALF_SIGNED_MAX ((long)(QRTR_INDEX_HALF_UNSIGNED_MAX) >> 1)
+#define QRTR_INDEX_HALF_SIGNED_MIN ((long)(-1) - QRTR_INDEX_HALF_SIGNED_MAX)
+
/**
* struct qrtr_node - endpoint node
* @ep_lock: lock for endpoint management and callbacks
@@ -221,16 +241,23 @@ static void qrtr_node_release(struct qrtr_node *node)
* qrtr_tx_resume() - reset flow control counter
* @node: qrtr_node that the QRTR_TYPE_RESUME_TX packet arrived on
* @skb: resume_tx packet
+ *
+ * Return: 0 on success; negative error code on failure
*/
-static void qrtr_tx_resume(struct qrtr_node *node, struct sk_buff *skb)
+static int qrtr_tx_resume(struct qrtr_node *node, struct sk_buff *skb)
{
struct qrtr_ctrl_pkt *pkt = (struct qrtr_ctrl_pkt *)skb->data;
u64 remote_node = le32_to_cpu(pkt->client.node);
u32 remote_port = le32_to_cpu(pkt->client.port);
struct qrtr_tx_flow *flow;
- unsigned long key;
+ unsigned long key = 0;
- key = remote_node << 32 | remote_port;
+ if (remote_node > QRTR_INDEX_HALF_UNSIGNED_MAX ||
+ remote_port > QRTR_INDEX_HALF_UNSIGNED_MAX)
+ return -EINVAL;
+
+ key = ((unsigned long)(remote_node) << QRTR_INDEX_HALF_BITS) |
+ ((unsigned long)(remote_port) & QRTR_INDEX_HALF_UNSIGNED_MAX);
flow = xa_load(&node->qrtr_tx_flow, key);
if (flow) {
@@ -241,6 +268,8 @@ static void qrtr_tx_resume(struct qrtr_node *node, struct sk_buff *skb)
}
consume_skb(skb);
+
+ return 0;
}
/**
@@ -261,11 +290,20 @@ static void qrtr_tx_resume(struct qrtr_node *node, struct sk_buff *skb)
static int qrtr_tx_wait(struct qrtr_node *node, int dest_node, int dest_port,
int type)
{
- unsigned long key = (u64)dest_node << 32 | dest_port;
+ unsigned long key = 0;
struct qrtr_tx_flow *flow;
int confirm_rx = 0;
int ret;
+ if (dest_node < QRTR_INDEX_HALF_SIGNED_MIN ||
+ dest_node > QRTR_INDEX_HALF_SIGNED_MAX ||
+ dest_port < QRTR_INDEX_HALF_SIGNED_MIN ||
+ dest_port > QRTR_INDEX_HALF_SIGNED_MAX)
+ return -EINVAL;
+
+ key = ((unsigned long)(dest_node) << QRTR_INDEX_HALF_BITS) |
+ ((unsigned long)(dest_port) & QRTR_INDEX_HALF_UNSIGNED_MAX);
+
/* Never set confirm_rx on non-data packets */
if (type != QRTR_TYPE_DATA)
return 0;
@@ -322,19 +360,32 @@ static int qrtr_tx_wait(struct qrtr_node *node, int dest_node, int dest_port,
* message associated with the dropped confirm_rx message.
* Work around this by marking the flow as having a failed transmission and
* cause the next transmission attempt to be sent with the confirm_rx.
+ *
+ * Return: 0 on success; negative error code on failure
*/
-static void qrtr_tx_flow_failed(struct qrtr_node *node, int dest_node,
- int dest_port)
+static int qrtr_tx_flow_failed(struct qrtr_node *node, int dest_node,
+ int dest_port)
{
- unsigned long key = (u64)dest_node << 32 | dest_port;
+ unsigned long key = 0;
struct qrtr_tx_flow *flow;
+ if (dest_node < QRTR_INDEX_HALF_SIGNED_MIN ||
+ dest_node > QRTR_INDEX_HALF_SIGNED_MAX ||
+ dest_port < QRTR_INDEX_HALF_SIGNED_MIN ||
+ dest_port > QRTR_INDEX_HALF_SIGNED_MAX)
+ return -EINVAL;
+
+ key = ((unsigned long)(dest_node) << QRTR_INDEX_HALF_BITS) |
+ ((unsigned long)(dest_port) & QRTR_INDEX_HALF_UNSIGNED_MAX);
+
flow = xa_load(&node->qrtr_tx_flow, key);
if (flow) {
spin_lock_irq(&flow->resume_tx.lock);
flow->tx_failed = 1;
spin_unlock_irq(&flow->resume_tx.lock);
}
+
+ return 0;
}
/* Pass an outgoing packet socket buffer to the endpoint driver. */
@@ -382,7 +433,7 @@ static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb,
/* Need to ensure that a subsequent message carries the otherwise lost
* confirm_rx flag if we dropped this one */
if (rc && confirm_rx)
- qrtr_tx_flow_failed(node, to->sq_node, to->sq_port);
+ rc = qrtr_tx_flow_failed(node, to->sq_node, to->sq_port);
return rc;
}
@@ -444,6 +495,7 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
size_t size;
unsigned int ver;
size_t hdrlen;
+ int ret = -EINVAL;
if (len == 0 || len & 3)
return -EINVAL;
@@ -526,7 +578,9 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
}
if (cb->type == QRTR_TYPE_RESUME_TX) {
- qrtr_tx_resume(node, skb);
+ ret = qrtr_tx_resume(node, skb);
+ if (ret)
+ goto err;
} else {
ipc = qrtr_port_lookup(cb->dst_port);
if (!ipc)
@@ -544,7 +598,7 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
err:
kfree_skb(skb);
- return -EINVAL;
+ return ret;
}
EXPORT_SYMBOL_GPL(qrtr_endpoint_post);
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread* [PATCH v6 04/15] net: qrtr: use only low 16 bits of node/port in 32-bit systems
2026-09-01 13:19 [PATCH v6 00/15] QRTR Multi-endpoint support Juha-Matti Tilli
` (2 preceding siblings ...)
2026-09-01 13:19 ` [PATCH v6 03/15] net: qrtr: fit node ID + port number combination into unsigned long Juha-Matti Tilli
@ 2026-09-01 13:19 ` Juha-Matti Tilli
2026-09-01 13:19 ` [PATCH v6 05/15] net: qrtr: support identical node ids Juha-Matti Tilli
` (10 subsequent siblings)
14 siblings, 0 replies; 20+ messages in thread
From: Juha-Matti Tilli @ 2026-09-01 13:19 UTC (permalink / raw)
To: linux-arm-msm, Manivannan Sadhasivam
Cc: Eric Dumazet, Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn,
David S . Miller, Jakub Kicinski, Simon Horman, Marcel Holtmann,
Andy Gross, Mihai Moldovan, Denis Kenzior, Juha-Matti Tilli,
linux-kernel, netdev
The node id is generally a single fixed value hardcoded into device
firmware. If it happens to be larger than 16 bits on a 32-bit system,
using the value modulo 65536 is enough. It is not necessary to check it
for being in range. Evidence of this is a prior implementation that fit
node_id (u32) and port (u32) into unsigned long in 32-bit systems, in a
manner that completely discarded all bits of node_id. Do the same for
port: don't check for it being in range.
This arguably creates a bug where node_id could clash with a node_id
that has the same low-order 16 bits, or a port could clash with a port
that has the same low-order 16 bits. But it's probably better than
discarding all bits of node and using only bits from port. It's probably
also better than failing if either node or port is out-of-range.
Signed-off-by: Juha-Matti Tilli <juha-matti.tilli@iki.fi>
---
net/qrtr/af_qrtr.c | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index f2edbd2e9dea9..b2cb05f2480e0 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -252,9 +252,9 @@ static int qrtr_tx_resume(struct qrtr_node *node, struct sk_buff *skb)
struct qrtr_tx_flow *flow;
unsigned long key = 0;
- if (remote_node > QRTR_INDEX_HALF_UNSIGNED_MAX ||
- remote_port > QRTR_INDEX_HALF_UNSIGNED_MAX)
- return -EINVAL;
+ /* Don't check node/port for the valid range, use only low
+ * 16 bits on 32-bit architectures.
+ */
key = ((unsigned long)(remote_node) << QRTR_INDEX_HALF_BITS) |
((unsigned long)(remote_port) & QRTR_INDEX_HALF_UNSIGNED_MAX);
@@ -295,11 +295,9 @@ static int qrtr_tx_wait(struct qrtr_node *node, int dest_node, int dest_port,
int confirm_rx = 0;
int ret;
- if (dest_node < QRTR_INDEX_HALF_SIGNED_MIN ||
- dest_node > QRTR_INDEX_HALF_SIGNED_MAX ||
- dest_port < QRTR_INDEX_HALF_SIGNED_MIN ||
- dest_port > QRTR_INDEX_HALF_SIGNED_MAX)
- return -EINVAL;
+ /* Don't check node/port for the valid range, use only low
+ * 16 bits on 32-bit architectures.
+ */
key = ((unsigned long)(dest_node) << QRTR_INDEX_HALF_BITS) |
((unsigned long)(dest_port) & QRTR_INDEX_HALF_UNSIGNED_MAX);
@@ -369,11 +367,9 @@ static int qrtr_tx_flow_failed(struct qrtr_node *node, int dest_node,
unsigned long key = 0;
struct qrtr_tx_flow *flow;
- if (dest_node < QRTR_INDEX_HALF_SIGNED_MIN ||
- dest_node > QRTR_INDEX_HALF_SIGNED_MAX ||
- dest_port < QRTR_INDEX_HALF_SIGNED_MIN ||
- dest_port > QRTR_INDEX_HALF_SIGNED_MAX)
- return -EINVAL;
+ /* Don't check node/port for the valid range, use only low
+ * 16 bits on 32-bit architectures.
+ */
key = ((unsigned long)(dest_node) << QRTR_INDEX_HALF_BITS) |
((unsigned long)(dest_port) & QRTR_INDEX_HALF_UNSIGNED_MAX);
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread* [PATCH v6 05/15] net: qrtr: support identical node ids
2026-09-01 13:19 [PATCH v6 00/15] QRTR Multi-endpoint support Juha-Matti Tilli
` (3 preceding siblings ...)
2026-09-01 13:19 ` [PATCH v6 04/15] net: qrtr: use only low 16 bits of node/port in 32-bit systems Juha-Matti Tilli
@ 2026-09-01 13:19 ` Juha-Matti Tilli
2026-09-01 13:19 ` [PATCH v6 06/15] net: qrtr: Report sender endpoint in aux data Juha-Matti Tilli
` (9 subsequent siblings)
14 siblings, 0 replies; 20+ messages in thread
From: Juha-Matti Tilli @ 2026-09-01 13:19 UTC (permalink / raw)
To: linux-arm-msm, Manivannan Sadhasivam
Cc: Eric Dumazet, Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn,
David S . Miller, Jakub Kicinski, Simon Horman, Marcel Holtmann,
Andy Gross, Mihai Moldovan, Denis Kenzior, Juha-Matti Tilli,
linux-kernel, netdev
From: Denis Kenzior <denkenz@gmail.com>
Add support for tracking multiple endpoints that may have conflicting
node identifiers. This is achieved by using both the node and endpoint
identifiers as the key inside the radix_tree data structure.
For backward compatibility with existing clients, the previous key
schema (node identifier only) is preserved. However, this schema will
only support the first endpoint/node combination. This is acceptable
for legacy clients as support for multiple endpoints with conflicting
node identifiers was not previously possible.
Signed-off-by: Denis Kenzior <denkenz@gmail.com>
Reviewed-by: Marcel Holtmann <marcel@holtmann.org>
Reviewed-by: Andy Gross <agross@kernel.org>
Signed-off-by: Mihai Moldovan <ionic@ionic.de>
Signed-off-by: Juha-Matti Tilli <juha-matti.tilli@iki.fi>
---
net/qrtr/af_qrtr.c | 57 ++++++++++++++++++++++++++++++++++------------
1 file changed, 42 insertions(+), 15 deletions(-)
diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index b2cb05f2480e0..43e48b89b5cb6 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -119,14 +119,15 @@ static DEFINE_XARRAY_ALLOC(qrtr_ports);
/* The xarray API uses fixed unsigned long keys and we will have to make
* do with that.
- * These keys are often a combination of node IDs (currently u32) and
- * port numbers (also currently u32).
- * Using the high 32 bits for the node ID and the low 32 bits for the
- * port number will work fine to create keys on platforms where unsigned long
- * is 64 bits wide, but obviously is not be possible on platforms where
- * unsigned long is smaller.
+ * These keys are often a combination of node IDs and port numbers or
+ * endpoint IDs and node IDs (all currently u32).
+ * Using the high 32 bits for the node/endpoint ID and the low 32 bits for the
+ * port number/node ID will work fine to create keys on platforms where
+ * unsigned long is 64 bits wide, but obviously is not be possible on
+ * platforms where unsigned long is smaller.
* Virtually split up unsigned long in half and assign the upper bits to
- * node IDs and the lower bits to the port number, however big that may be.
+ * node/endpoint IDs and the lower bits to the port number/node ID, however
+ * big that may be.
*/
#define QRTR_XARRAY_INDEX_BITS (8 /* CHAR_BIT */ * sizeof(unsigned long))
#define QRTR_INDEX_HALF_BITS (QRTR_XARRAY_INDEX_BITS >> 1)
@@ -457,19 +458,36 @@ static struct qrtr_node *qrtr_node_lookup(unsigned int nid)
*
* 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;
+ unsigned long key;
if (nid == QRTR_EP_NID_AUTO)
- return;
+ return 0;
+
+ if (node->ep->id > QRTR_INDEX_HALF_UNSIGNED_MAX ||
+ nid > QRTR_INDEX_HALF_UNSIGNED_MAX)
+ return -EINVAL;
spin_lock_irqsave(&qrtr_nodes_lock, flags);
- radix_tree_insert(&qrtr_nodes, nid, node);
+
+ /* Always insert with the endpoint_id + node_id */
+ key = ((unsigned long)(node->ep->id) << QRTR_INDEX_HALF_BITS) |
+ ((unsigned long)(nid) & QRTR_INDEX_HALF_UNSIGNED_MAX);
+ radix_tree_insert(&qrtr_nodes, key, node);
+
+ if (!radix_tree_lookup(&qrtr_nodes, nid))
+ radix_tree_insert(&qrtr_nodes, nid, node);
+
if (node->nid == QRTR_EP_NID_AUTO)
node->nid = nid;
spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
+
+ return 0;
}
/**
@@ -563,14 +581,18 @@ 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);
+ ret = qrtr_node_assign(node, cb->src_node);
+ if (ret)
+ goto err;
if (cb->type == QRTR_TYPE_NEW_SERVER) {
/* Remote node endpoint can bridge other distant nodes */
const struct qrtr_ctrl_pkt *pkt;
pkt = data + hdrlen;
- qrtr_node_assign(node, le32_to_cpu(pkt->server.node));
+ ret = qrtr_node_assign(node, le32_to_cpu(pkt->server.node));
+ if (ret)
+ goto err;
}
if (cb->type == QRTR_TYPE_RESUME_TX) {
@@ -579,10 +601,13 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
goto err;
} else {
ipc = qrtr_port_lookup(cb->dst_port);
- if (!ipc)
+ if (!ipc) {
+ ret = -EINVAL;
goto err;
+ }
- if (sock_queue_rcv_skb(&ipc->sk, skb)) {
+ ret = sock_queue_rcv_skb(&ipc->sk, skb);
+ if (ret) {
qrtr_port_put(ipc);
goto err;
}
@@ -662,7 +687,9 @@ 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 < 0)
+ goto free_node;
mutex_lock(&qrtr_node_lock);
list_add(&node->item, &qrtr_all_nodes);
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread* [PATCH v6 06/15] net: qrtr: Report sender endpoint in aux data
2026-09-01 13:19 [PATCH v6 00/15] QRTR Multi-endpoint support Juha-Matti Tilli
` (4 preceding siblings ...)
2026-09-01 13:19 ` [PATCH v6 05/15] net: qrtr: support identical node ids Juha-Matti Tilli
@ 2026-09-01 13:19 ` Juha-Matti Tilli
2026-09-01 13:19 ` [PATCH v6 07/15] net: qrtr: Report endpoint for locally generated messages Juha-Matti Tilli
` (8 subsequent siblings)
14 siblings, 0 replies; 20+ messages in thread
From: Juha-Matti Tilli @ 2026-09-01 13:19 UTC (permalink / raw)
To: linux-arm-msm, Manivannan Sadhasivam
Cc: Eric Dumazet, Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn,
David S . Miller, Jakub Kicinski, Simon Horman, Marcel Holtmann,
Andy Gross, Mihai Moldovan, Denis Kenzior, Juha-Matti Tilli,
linux-kernel, netdev
From: Denis Kenzior <denkenz@gmail.com>
Introduce support for reporting the remote endpoint that generated a
given QRTR message to clients using AF_QIPCRTR family sockets. This is
achieved by including QRTR_ENDPOINT auxiliary data, which carries the
endpoint identifier of the message sender. To receive this auxiliary
data, clients must explicitly opt-in by using setsockopt with the
QRTR_REPORT_ENDPOINT option enabled.
Implementation of getsockopt and setsockopt is provided. An additional
level 'SOL_QRTR' is added to socket.h for use by AF_QIPCRTR family
sockets.
Signed-off-by: Denis Kenzior <denkenz@gmail.com>
Reviewed-by: Marcel Holtmann <marcel@holtmann.org>
Reviewed-by: Andy Gross <agross@kernel.org>
Signed-off-by: Mihai Moldovan <ionic@ionic.de>
Signed-off-by: Juha-Matti Tilli <juha-matti.tilli@iki.fi>
---
include/linux/socket.h | 1 +
include/uapi/linux/qrtr.h | 6 +++
net/qrtr/af_qrtr.c | 77 +++++++++++++++++++++++++++++++++++++++
3 files changed, 84 insertions(+)
diff --git a/include/linux/socket.h b/include/linux/socket.h
index 2a8d7b14f1d11..4af1dd816dc35 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -400,6 +400,7 @@ struct ucred {
#define SOL_MCTP 285
#define SOL_SMC 286
#define SOL_VSOCK 287
+#define SOL_QRTR 288
/* IPX options */
#define IPX_TYPE 1
diff --git a/include/uapi/linux/qrtr.h b/include/uapi/linux/qrtr.h
index f7e2fb3d752b5..6d0911984a050 100644
--- a/include/uapi/linux/qrtr.h
+++ b/include/uapi/linux/qrtr.h
@@ -46,4 +46,10 @@ struct qrtr_ctrl_pkt {
};
} __packed;
+/* setsockopt / getsockopt */
+#define QRTR_REPORT_ENDPOINT 1
+
+/* CMSG */
+#define QRTR_ENDPOINT 1
+
#endif /* _LINUX_QRTR_H */
diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index 43e48b89b5cb6..897ecc8dc304d 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -26,6 +26,10 @@
#define QRTR_PORT_CTRL_LEGACY 0xffff
+enum {
+ QRTR_F_REPORT_ENDPOINT,
+};
+
/**
* struct qrtr_hdr_v1 - (I|R)PCrouter packet header version 1
* @version: protocol version
@@ -79,6 +83,7 @@ struct qrtr_cb {
u32 src_port;
u32 dst_node;
u32 dst_port;
+ u32 endpoint_id;
u8 type;
u8 confirm_rx;
@@ -92,6 +97,7 @@ struct qrtr_sock {
struct sock sk;
struct sockaddr_qrtr us;
struct sockaddr_qrtr peer;
+ unsigned long flags;
};
static inline struct qrtr_sock *qrtr_sk(struct sock *sk)
@@ -567,6 +573,8 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
if (cb->dst_port == QRTR_PORT_CTRL_LEGACY)
cb->dst_port = QRTR_PORT_CTRL;
+ cb->endpoint_id = ep->id;
+
if (!size || size > len || len != ALIGN(size, 4) + hdrlen)
goto err;
@@ -1130,6 +1138,7 @@ static int qrtr_recvmsg(struct socket *sock, struct msghdr *msg,
size_t size, int flags)
{
DECLARE_SOCKADDR(struct sockaddr_qrtr *, addr, msg->msg_name);
+ struct qrtr_sock *ipc = qrtr_sk(sock->sk);
struct sock *sk = sock->sk;
struct sk_buff *skb;
struct qrtr_cb *cb;
@@ -1155,6 +1164,10 @@ static int qrtr_recvmsg(struct socket *sock, struct msghdr *msg,
msg->msg_flags |= MSG_TRUNC;
}
+ if (cb->endpoint_id && test_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags))
+ put_cmsg(msg, SOL_QRTR, QRTR_ENDPOINT,
+ sizeof(cb->endpoint_id), &cb->endpoint_id);
+
rc = skb_copy_datagram_msg(skb, 0, msg, copied);
if (rc < 0)
goto out;
@@ -1300,6 +1313,68 @@ static int qrtr_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
return rc;
}
+static int qrtr_setsockopt(struct socket *sock, int level, int optname,
+ sockptr_t optval, unsigned int optlen)
+{
+ struct qrtr_sock *ipc = qrtr_sk(sock->sk);
+ unsigned int val = 0;
+ int rc = 0;
+
+ if (level != SOL_QRTR)
+ return -ENOPROTOOPT;
+
+ if (optlen >= sizeof(val) &&
+ copy_from_sockptr(&val, optval, sizeof(val)))
+ return -EFAULT;
+
+ switch (optname) {
+ case QRTR_REPORT_ENDPOINT:
+ assign_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags, val);
+ break;
+ default:
+ rc = -ENOPROTOOPT;
+ }
+
+ return rc;
+}
+
+static int qrtr_getsockopt(struct socket *sock, int level, int optname,
+ char __user *optval, int __user *optlen)
+{
+ struct qrtr_sock *ipc = qrtr_sk(sock->sk);
+ unsigned int val;
+ int len;
+ int rc = 0;
+
+ if (level != SOL_QRTR)
+ return -ENOPROTOOPT;
+
+ if (get_user(len, optlen))
+ return -EFAULT;
+
+ if (len < sizeof(val))
+ return -EINVAL;
+
+ switch (optname) {
+ case QRTR_REPORT_ENDPOINT:
+ val = test_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags);
+ break;
+ default:
+ rc = -ENOPROTOOPT;
+ }
+
+ if (rc)
+ return rc;
+
+ len = sizeof(int);
+
+ if (put_user(len, optlen) ||
+ copy_to_user(optval, &val, len))
+ rc = -EFAULT;
+
+ return rc;
+}
+
static int qrtr_release(struct socket *sock)
{
struct sock *sk = sock->sk;
@@ -1347,6 +1422,8 @@ static const struct proto_ops qrtr_proto_ops = {
.shutdown = sock_no_shutdown,
.release = qrtr_release,
.mmap = sock_no_mmap,
+ .setsockopt = qrtr_setsockopt,
+ .getsockopt = qrtr_getsockopt,
};
static struct proto qrtr_proto = {
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread* [PATCH v6 07/15] net: qrtr: Report endpoint for locally generated messages
2026-09-01 13:19 [PATCH v6 00/15] QRTR Multi-endpoint support Juha-Matti Tilli
` (5 preceding siblings ...)
2026-09-01 13:19 ` [PATCH v6 06/15] net: qrtr: Report sender endpoint in aux data Juha-Matti Tilli
@ 2026-09-01 13:19 ` Juha-Matti Tilli
2026-09-01 13:19 ` [PATCH v6 08/15] net: qrtr: Allow sendmsg to target an endpoint Juha-Matti Tilli
` (7 subsequent siblings)
14 siblings, 0 replies; 20+ messages in thread
From: Juha-Matti Tilli @ 2026-09-01 13:19 UTC (permalink / raw)
To: linux-arm-msm, Manivannan Sadhasivam
Cc: Eric Dumazet, Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn,
David S . Miller, Jakub Kicinski, Simon Horman, Marcel Holtmann,
Andy Gross, Mihai Moldovan, Denis Kenzior, Juha-Matti Tilli,
linux-kernel, netdev
From: Denis Kenzior <denkenz@gmail.com>
For messages generated by the local endpoint destined
to the local endpoint, report the local endpoint identifier. Same
QRTR_ENDPOINT auxiliary data and QRTR_REPORT_ENDPOINT socket option
semantics apply as for messages generated by remote endpoints.
Signed-off-by: Denis Kenzior <denkenz@gmail.com>
Reviewed-by: Marcel Holtmann <marcel@holtmann.org>
Reviewed-by: Andy Gross <agross@kernel.org>
Signed-off-by: Mihai Moldovan <ionic@ionic.de>
Signed-off-by: Juha-Matti Tilli <juha-matti.tilli@iki.fi>
---
net/qrtr/af_qrtr.c | 29 ++++++++++++++++++++---------
1 file changed, 20 insertions(+), 9 deletions(-)
diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index 897ecc8dc304d..da7ccf19c6851 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -184,9 +184,11 @@ struct qrtr_tx_flow {
#define QRTR_TX_FLOW_LOW 5
static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb,
+ u32 endpoint_id,
int type, struct sockaddr_qrtr *from,
struct sockaddr_qrtr *to);
static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb,
+ u32 endpoint_id,
int type, struct sockaddr_qrtr *from,
struct sockaddr_qrtr *to);
static struct qrtr_sock *qrtr_port_lookup(int port);
@@ -393,6 +395,7 @@ static int qrtr_tx_flow_failed(struct qrtr_node *node, int dest_node,
/* Pass an outgoing packet socket buffer to the endpoint driver. */
static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb,
+ u32 endpoint_id,
int type, struct sockaddr_qrtr *from,
struct sockaddr_qrtr *to)
{
@@ -744,7 +747,8 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep)
skb = qrtr_alloc_ctrl_packet(&pkt, GFP_ATOMIC);
if (skb) {
pkt->cmd = cpu_to_le32(QRTR_TYPE_BYE);
- qrtr_local_enqueue(NULL, skb, QRTR_TYPE_BYE, &src, &dst);
+ qrtr_local_enqueue(NULL, skb, endpoint_id,
+ QRTR_TYPE_BYE, &src, &dst);
}
}
spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
@@ -809,8 +813,8 @@ static void qrtr_port_remove(struct qrtr_sock *ipc)
pkt->client.port = cpu_to_le32(ipc->us.sq_port);
skb_set_owner_w(skb, &ipc->sk);
- qrtr_bcast_enqueue(NULL, skb, QRTR_TYPE_DEL_CLIENT, &ipc->us,
- &to);
+ qrtr_bcast_enqueue(NULL, skb, qrtr_local_nid,
+ QRTR_TYPE_DEL_CLIENT, &ipc->us, &to);
}
if (port == QRTR_PORT_CTRL)
@@ -950,6 +954,7 @@ static int qrtr_bind(struct socket *sock, struct sockaddr_unsized *saddr, int le
/* Queue packet to local peer socket. */
static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb,
+ u32 endpoint_id,
int type, struct sockaddr_qrtr *from,
struct sockaddr_qrtr *to)
{
@@ -967,6 +972,7 @@ static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb,
cb = (struct qrtr_cb *)skb->cb;
cb->src_node = from->sq_node;
cb->src_port = from->sq_port;
+ cb->endpoint_id = endpoint_id;
if (sock_queue_rcv_skb(&ipc->sk, skb)) {
qrtr_port_put(ipc);
@@ -981,6 +987,7 @@ static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb,
/* Queue packet for broadcast. */
static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb,
+ u32 endpoint_id,
int type, struct sockaddr_qrtr *from,
struct sockaddr_qrtr *to)
{
@@ -992,11 +999,11 @@ static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb,
if (!skbn)
break;
skb_set_owner_w(skbn, skb->sk);
- qrtr_node_enqueue(node, skbn, type, from, to);
+ qrtr_node_enqueue(node, skbn, endpoint_id, type, from, to);
}
mutex_unlock(&qrtr_node_lock);
- qrtr_local_enqueue(NULL, skb, type, from, to);
+ qrtr_local_enqueue(NULL, skb, endpoint_id, type, from, to);
return 0;
}
@@ -1004,12 +1011,15 @@ static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb,
static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
{
DECLARE_SOCKADDR(struct sockaddr_qrtr *, addr, msg->msg_name);
- int (*enqueue_fn)(struct qrtr_node *, struct sk_buff *, int,
- struct sockaddr_qrtr *, struct sockaddr_qrtr *);
+ int (*enqueue_fn)(struct qrtr_node *node, struct sk_buff *skb,
+ u32 endpoint_id, int type,
+ struct sockaddr_qrtr *from,
+ struct sockaddr_qrtr *to);
__le32 qrtr_type = cpu_to_le32(QRTR_TYPE_DATA);
struct qrtr_sock *ipc = qrtr_sk(sock->sk);
struct sock *sk = sock->sk;
struct qrtr_node *node;
+ u32 endpoint_id = qrtr_local_nid;
struct sk_buff *skb;
size_t plen;
u32 type;
@@ -1093,7 +1103,7 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
}
type = le32_to_cpu(qrtr_type);
- rc = enqueue_fn(node, skb, type, &ipc->us, addr);
+ rc = enqueue_fn(node, skb, endpoint_id, type, &ipc->us, addr);
if (rc >= 0)
rc = len;
@@ -1127,7 +1137,8 @@ static int qrtr_send_resume_tx(struct qrtr_cb *cb)
pkt->client.node = cpu_to_le32(cb->dst_node);
pkt->client.port = cpu_to_le32(cb->dst_port);
- ret = qrtr_node_enqueue(node, skb, QRTR_TYPE_RESUME_TX, &local, &remote);
+ ret = qrtr_node_enqueue(node, skb, cb->endpoint_id,
+ QRTR_TYPE_RESUME_TX, &local, &remote);
qrtr_node_release(node);
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread* [PATCH v6 08/15] net: qrtr: Allow sendmsg to target an endpoint
2026-09-01 13:19 [PATCH v6 00/15] QRTR Multi-endpoint support Juha-Matti Tilli
` (6 preceding siblings ...)
2026-09-01 13:19 ` [PATCH v6 07/15] net: qrtr: Report endpoint for locally generated messages Juha-Matti Tilli
@ 2026-09-01 13:19 ` Juha-Matti Tilli
2026-09-01 13:19 ` [PATCH v6 09/15] net: qrtr: allow socket endpoint binding Juha-Matti Tilli
` (6 subsequent siblings)
14 siblings, 0 replies; 20+ messages in thread
From: Juha-Matti Tilli @ 2026-09-01 13:19 UTC (permalink / raw)
To: linux-arm-msm, Manivannan Sadhasivam
Cc: Eric Dumazet, Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn,
David S . Miller, Jakub Kicinski, Simon Horman, Marcel Holtmann,
Andy Gross, Mihai Moldovan, Denis Kenzior, Juha-Matti Tilli,
linux-kernel, netdev
From: Denis Kenzior <denkenz@gmail.com>
Allow QIPCRTR family sockets to include QRTR_ENDPOINT auxiliary data
as part of the sendmsg system call. By including this parameter, the
client can ask the kernel to route the message to a given endpoint, in
situations where multiple endpoints with conflicting node identifier
sets exist in the system.
For legacy clients, or clients that do not include QRTR_ENDPOINT data,
the endpoint is looked up, as before, by only using the node identifier
of the destination qrtr socket address.
Signed-off-by: Denis Kenzior <denkenz@gmail.com>
Reviewed-by: Marcel Holtmann <marcel@holtmann.org>
Reviewed-by: Andy Gross <agross@kernel.org>
Signed-off-by: Mihai Moldovan <ionic@ionic.de>
Signed-off-by: Juha-Matti Tilli <juha-matti.tilli@iki.fi>
---
net/qrtr/af_qrtr.c | 89 ++++++++++++++++++++++++++++++++++------------
net/qrtr/qrtr.h | 2 ++
2 files changed, 68 insertions(+), 23 deletions(-)
diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index da7ccf19c6851..d4a472f0ac4d1 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -106,6 +106,36 @@ static inline struct qrtr_sock *qrtr_sk(struct sock *sk)
return container_of(sk, struct qrtr_sock, sk);
}
+int qrtr_msg_get_endpoint(struct msghdr *msg, u32 *out_endpoint_id)
+{
+ struct cmsghdr *cmsg;
+ u32 endpoint_id = 0;
+
+ for_each_cmsghdr(cmsg, msg) {
+ if (!CMSG_OK(msg, cmsg))
+ return -EINVAL;
+
+ if (cmsg->cmsg_level != SOL_QRTR)
+ continue;
+
+ if (cmsg->cmsg_type != QRTR_ENDPOINT)
+ return -EINVAL;
+
+ if (cmsg->cmsg_len < CMSG_LEN(sizeof(u32)))
+ return -EINVAL;
+
+ /* Endpoint ids start at 1 */
+ endpoint_id = *(u32 *)CMSG_DATA(cmsg);
+ if (!endpoint_id)
+ return -EINVAL;
+ }
+
+ if (out_endpoint_id)
+ *out_endpoint_id = endpoint_id;
+
+ return 0;
+}
+
static unsigned int qrtr_local_nid = 1;
/* for node ids */
@@ -448,14 +478,23 @@ static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb,
*
* callers must release with qrtr_node_release()
*/
-static struct qrtr_node *qrtr_node_lookup(unsigned int nid)
+static struct qrtr_node *qrtr_node_lookup(unsigned int endpoint_id,
+ unsigned int nid)
{
- struct qrtr_node *node;
+ struct qrtr_node *node = NULL;
unsigned long flags;
+ unsigned long key = 0;
+
+ if (endpoint_id > QRTR_INDEX_HALF_UNSIGNED_MAX ||
+ nid > QRTR_INDEX_HALF_UNSIGNED_MAX)
+ return node;
+
+ key = ((unsigned long)(endpoint_id) << QRTR_INDEX_HALF_BITS) |
+ ((unsigned long)(nid) & QRTR_INDEX_HALF_UNSIGNED_MAX);
mutex_lock(&qrtr_node_lock);
spin_lock_irqsave(&qrtr_nodes_lock, flags);
- node = radix_tree_lookup(&qrtr_nodes, nid);
+ node = radix_tree_lookup(&qrtr_nodes, key);
node = qrtr_node_acquire(node);
spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
mutex_unlock(&qrtr_node_lock);
@@ -1019,6 +1058,7 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
struct qrtr_sock *ipc = qrtr_sk(sock->sk);
struct sock *sk = sock->sk;
struct qrtr_node *node;
+ u32 msg_endpoint_id;
u32 endpoint_id = qrtr_local_nid;
struct sk_buff *skb;
size_t plen;
@@ -1031,46 +1071,48 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
if (len > 65535)
return -EMSGSIZE;
+ rc = qrtr_msg_get_endpoint(msg, &msg_endpoint_id);
+ if (rc < 0)
+ return rc;
+
lock_sock(sk);
if (addr) {
- if (msg->msg_namelen < sizeof(*addr)) {
- release_sock(sk);
- return -EINVAL;
- }
+ rc = -EINVAL;
- if (addr->sq_family != AF_QIPCRTR) {
- release_sock(sk);
- return -EINVAL;
- }
+ if (msg->msg_namelen < sizeof(*addr))
+ goto release_sock;
+
+ if (addr->sq_family != AF_QIPCRTR)
+ goto release_sock;
rc = qrtr_autobind(sock);
- if (rc) {
- release_sock(sk);
- return rc;
- }
+ if (rc)
+ goto release_sock;
} else if (sk->sk_state == TCP_ESTABLISHED) {
addr = &ipc->peer;
} else {
- release_sock(sk);
- return -ENOTCONN;
+ rc = -ENOTCONN;
+ goto release_sock;
}
node = NULL;
if (addr->sq_node == QRTR_NODE_BCAST) {
if (addr->sq_port != QRTR_PORT_CTRL &&
qrtr_local_nid != QRTR_NODE_BCAST) {
- release_sock(sk);
- return -ENOTCONN;
+ rc = -ENOTCONN;
+ goto release_sock;
}
enqueue_fn = qrtr_bcast_enqueue;
} else if (addr->sq_node == ipc->us.sq_node) {
enqueue_fn = qrtr_local_enqueue;
} else {
- node = qrtr_node_lookup(addr->sq_node);
+ endpoint_id = msg_endpoint_id;
+
+ node = qrtr_node_lookup(endpoint_id, addr->sq_node);
if (!node) {
- release_sock(sk);
- return -ECONNRESET;
+ rc = endpoint_id ? -ENXIO : -ECONNRESET;
+ goto release_sock;
}
enqueue_fn = qrtr_node_enqueue;
}
@@ -1109,6 +1151,7 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
out_node:
qrtr_node_release(node);
+release_sock:
release_sock(sk);
return rc;
@@ -1123,7 +1166,7 @@ static int qrtr_send_resume_tx(struct qrtr_cb *cb)
struct sk_buff *skb;
int ret;
- node = qrtr_node_lookup(remote.sq_node);
+ node = qrtr_node_lookup(cb->endpoint_id, remote.sq_node);
if (!node)
return -EINVAL;
diff --git a/net/qrtr/qrtr.h b/net/qrtr/qrtr.h
index 11b897af05e67..22fcecbf8de23 100644
--- a/net/qrtr/qrtr.h
+++ b/net/qrtr/qrtr.h
@@ -34,4 +34,6 @@ int qrtr_ns_init(void);
void qrtr_ns_remove(void);
+int qrtr_msg_get_endpoint(struct msghdr *msg, u32 *out_endpoint_id);
+
#endif
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread* [PATCH v6 09/15] net: qrtr: allow socket endpoint binding
2026-09-01 13:19 [PATCH v6 00/15] QRTR Multi-endpoint support Juha-Matti Tilli
` (7 preceding siblings ...)
2026-09-01 13:19 ` [PATCH v6 08/15] net: qrtr: Allow sendmsg to target an endpoint Juha-Matti Tilli
@ 2026-09-01 13:19 ` Juha-Matti Tilli
2026-09-01 13:19 ` [PATCH v6 10/15] net: qrtr: Drop remote {NEW|DEL}_LOOKUP messages Juha-Matti Tilli
` (5 subsequent siblings)
14 siblings, 0 replies; 20+ messages in thread
From: Juha-Matti Tilli @ 2026-09-01 13:19 UTC (permalink / raw)
To: linux-arm-msm, Manivannan Sadhasivam
Cc: Eric Dumazet, Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn,
David S . Miller, Jakub Kicinski, Simon Horman, Marcel Holtmann,
Andy Gross, Mihai Moldovan, Denis Kenzior, Juha-Matti Tilli,
linux-kernel, netdev
From: Denis Kenzior <denkenz@gmail.com>
Introduce the ability to bind a QIPCRTR family socket to a specific
endpoint. When a socket is bound, only messages from the bound
endpoint can be received, and any messages sent from the socket are
by default directed to the bound endpoint. Clients can bind a socket
by using the setsockopt system call with the QRTR_BIND_ENDPOINT option
set to the desired endpoint binding.
A previously set binding can be reset by setting QRTR_BIND_ENDPOINT
option to zero. This behavior matches that of SO_BINDTOIFINDEX.
This functionality is useful for clients that need to communicate
with a specific device (i.e. endpoint), such as a PCIe-based 5G modem,
and are not interested in messages from other endpoints / nodes.
Signed-off-by: Denis Kenzior <denkenz@gmail.com>
Reviewed-by: Marcel Holtmann <marcel@holtmann.org>
Reviewed-by: Andy Gross <agross@kernel.org>
Signed-off-by: Mihai Moldovan <ionic@ionic.de>
Signed-off-by: Juha-Matti Tilli <juha-matti.tilli@iki.fi>
---
include/uapi/linux/qrtr.h | 1 +
net/qrtr/af_qrtr.c | 56 ++++++++++++++++++++++++++++-----------
2 files changed, 41 insertions(+), 16 deletions(-)
diff --git a/include/uapi/linux/qrtr.h b/include/uapi/linux/qrtr.h
index 6d0911984a050..0a8667b049c3d 100644
--- a/include/uapi/linux/qrtr.h
+++ b/include/uapi/linux/qrtr.h
@@ -48,6 +48,7 @@ struct qrtr_ctrl_pkt {
/* setsockopt / getsockopt */
#define QRTR_REPORT_ENDPOINT 1
+#define QRTR_BIND_ENDPOINT 2
/* CMSG */
#define QRTR_ENDPOINT 1
diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index d4a472f0ac4d1..ccfa3ed33a996 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -98,6 +98,7 @@ struct qrtr_sock {
struct sockaddr_qrtr us;
struct sockaddr_qrtr peer;
unsigned long flags;
+ u32 bound_endpoint;
};
static inline struct qrtr_sock *qrtr_sk(struct sock *sk)
@@ -656,10 +657,14 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
goto err;
}
- ret = sock_queue_rcv_skb(&ipc->sk, skb);
- if (ret) {
- qrtr_port_put(ipc);
- goto err;
+ /* Sockets bound to an endpoint only rx from that endpoint */
+ if (!ipc->bound_endpoint ||
+ ipc->bound_endpoint == cb->endpoint_id) {
+ ret = sock_queue_rcv_skb(&ipc->sk, skb);
+ if (ret) {
+ qrtr_port_put(ipc);
+ goto err;
+ }
}
qrtr_port_put(ipc);
@@ -999,29 +1004,41 @@ static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb,
{
struct qrtr_sock *ipc;
struct qrtr_cb *cb;
+ int ret = -ENODEV;
ipc = qrtr_port_lookup(to->sq_port);
- if (!ipc || &ipc->sk == skb->sk) { /* do not send to self */
- if (ipc)
- qrtr_port_put(ipc);
- kfree_skb(skb);
- return -ENODEV;
- }
+ if (!ipc)
+ goto done;
+
+ if (&ipc->sk == skb->sk) /* do not send to self */
+ goto done;
+
+ /*
+ * Filter out unwanted packets that are not on behalf of the bound
+ * endpoint. Certain special packets (such as an empty NEW_SERVER
+ * packet that serves as a sentinel value) always go through.
+ */
+ if (endpoint_id && ipc->bound_endpoint &&
+ ipc->bound_endpoint != endpoint_id)
+ goto done;
cb = (struct qrtr_cb *)skb->cb;
cb->src_node = from->sq_node;
cb->src_port = from->sq_port;
cb->endpoint_id = endpoint_id;
- if (sock_queue_rcv_skb(&ipc->sk, skb)) {
- qrtr_port_put(ipc);
- kfree_skb(skb);
- return -ENOSPC;
- }
+ ret = -ENOSPC;
+ if (sock_queue_rcv_skb(&ipc->sk, skb))
+ goto done;
qrtr_port_put(ipc);
return 0;
+done:
+ if (ipc)
+ qrtr_port_put(ipc);
+ kfree_skb(skb);
+ return ret;
}
/* Queue packet for broadcast. */
@@ -1107,7 +1124,8 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
} else if (addr->sq_node == ipc->us.sq_node) {
enqueue_fn = qrtr_local_enqueue;
} else {
- endpoint_id = msg_endpoint_id;
+ endpoint_id = msg_endpoint_id ?
+ msg_endpoint_id : ipc->bound_endpoint;
node = qrtr_node_lookup(endpoint_id, addr->sq_node);
if (!node) {
@@ -1385,6 +1403,9 @@ static int qrtr_setsockopt(struct socket *sock, int level, int optname,
case QRTR_REPORT_ENDPOINT:
assign_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags, val);
break;
+ case QRTR_BIND_ENDPOINT:
+ WRITE_ONCE(ipc->bound_endpoint, val);
+ break;
default:
rc = -ENOPROTOOPT;
}
@@ -1413,6 +1434,9 @@ static int qrtr_getsockopt(struct socket *sock, int level, int optname,
case QRTR_REPORT_ENDPOINT:
val = test_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags);
break;
+ case QRTR_BIND_ENDPOINT:
+ val = READ_ONCE(ipc->bound_endpoint);
+ break;
default:
rc = -ENOPROTOOPT;
}
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread* [PATCH v6 10/15] net: qrtr: Drop remote {NEW|DEL}_LOOKUP messages
2026-09-01 13:19 [PATCH v6 00/15] QRTR Multi-endpoint support Juha-Matti Tilli
` (8 preceding siblings ...)
2026-09-01 13:19 ` [PATCH v6 09/15] net: qrtr: allow socket endpoint binding Juha-Matti Tilli
@ 2026-09-01 13:19 ` Juha-Matti Tilli
2026-09-01 13:19 ` [PATCH v6 11/15] net: qrtr: ns: support multiple endpoints Juha-Matti Tilli
` (4 subsequent siblings)
14 siblings, 0 replies; 20+ messages in thread
From: Juha-Matti Tilli @ 2026-09-01 13:19 UTC (permalink / raw)
To: linux-arm-msm, Manivannan Sadhasivam
Cc: Eric Dumazet, Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn,
David S . Miller, Jakub Kicinski, Simon Horman, Marcel Holtmann,
Andy Gross, Mihai Moldovan, Denis Kenzior, Juha-Matti Tilli,
linux-kernel, netdev
From: Denis Kenzior <denkenz@gmail.com>
These messages are explicitly filtered out by the in-kernel name
service (ns.c). Filter them out even earlier to save some CPU cycles.
Signed-off-by: Denis Kenzior <denkenz@gmail.com>
Reviewed-by: Marcel Holtmann <marcel@holtmann.org>
Reviewed-by: Andy Gross <agross@kernel.org>
Signed-off-by: Mihai Moldovan <ionic@ionic.de>
Signed-off-by: Juha-Matti Tilli <juha-matti.tilli@iki.fi>
---
net/qrtr/af_qrtr.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index ccfa3ed33a996..c139786c56f39 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -621,6 +621,11 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
if (!size || size > len || len != ALIGN(size, 4) + hdrlen)
goto err;
+ /* Don't allow remote lookups */
+ if (cb->type == QRTR_TYPE_NEW_LOOKUP ||
+ cb->type == QRTR_TYPE_DEL_LOOKUP)
+ goto err;
+
if ((cb->type == QRTR_TYPE_NEW_SERVER ||
cb->type == QRTR_TYPE_RESUME_TX) &&
size < sizeof(struct qrtr_ctrl_pkt))
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread* [PATCH v6 11/15] net: qrtr: ns: support multiple endpoints
2026-09-01 13:19 [PATCH v6 00/15] QRTR Multi-endpoint support Juha-Matti Tilli
` (9 preceding siblings ...)
2026-09-01 13:19 ` [PATCH v6 10/15] net: qrtr: Drop remote {NEW|DEL}_LOOKUP messages Juha-Matti Tilli
@ 2026-09-01 13:19 ` Juha-Matti Tilli
2026-09-01 13:19 ` [PATCH v6 12/15] net: qrtr: mhi: Report endpoint id in sysfs Juha-Matti Tilli
` (3 subsequent siblings)
14 siblings, 0 replies; 20+ messages in thread
From: Juha-Matti Tilli @ 2026-09-01 13:19 UTC (permalink / raw)
To: linux-arm-msm, Manivannan Sadhasivam
Cc: Eric Dumazet, Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn,
David S . Miller, Jakub Kicinski, Simon Horman, Marcel Holtmann,
Andy Gross, Mihai Moldovan, Denis Kenzior, Juha-Matti Tilli,
linux-kernel, netdev
From: Denis Kenzior <denkenz@gmail.com>
Extend the qrtr name service with the concept of an endpoint. Endpoints
can be remote or local, and are represented by a unique endpoint id.
This allows the qrtr name service to support multiple devices
(endpoints) that might have overlapping node / port combinations.
The socket used by the name service is subscribed to receive endpoint
information via a mechanism similar to the SOL_QRTR QRTR_REPORT_ENDPOINT
socket option. Internal data structures are then extended to track
endpoint information in addition to nodes and ports.
The name service directs packets to the endpoint originating the
request. For NEW_SERVER and DEL_SERVER messages triggered using lookups
or due to remote endpoints sending the corresponding message, qrtr name
service generates a NEW_SERVER and DEL_SERVER messages to all local
sockets registered to receive such notifications. The messages are made
to look as if they're coming from the remote endpoint using a special
extension to AF_QRTR sendmsg operation. This extension only works for
the local socket that owns the QRTR_PORT_CTRL port (name service).
Signed-off-by: Denis Kenzior <denkenz@gmail.com>
Reviewed-by: Marcel Holtmann <marcel@holtmann.org>
Reviewed-by: Andy Gross <agross@kernel.org>
Signed-off-by: Mihai Moldovan <ionic@ionic.de>
Signed-off-by: Juha-Matti Tilli <juha-matti.tilli@iki.fi>
---
net/qrtr/af_qrtr.c | 12 ++
net/qrtr/ns.c | 313 ++++++++++++++++++++++++++++-----------------
net/qrtr/qrtr.h | 1 +
3 files changed, 209 insertions(+), 117 deletions(-)
diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index c139786c56f39..b27c5a659795d 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -107,6 +107,13 @@ static inline struct qrtr_sock *qrtr_sk(struct sock *sk)
return container_of(sk, struct qrtr_sock, sk);
}
+void qrtr_sock_set_report_endpoint(struct sock *sk)
+{
+ struct qrtr_sock *ipc = qrtr_sk(sk);
+
+ assign_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags, 1);
+}
+
int qrtr_msg_get_endpoint(struct msghdr *msg, u32 *out_endpoint_id)
{
struct cmsghdr *cmsg;
@@ -1165,6 +1172,11 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
/* control messages already require the type as 'command' */
skb_copy_bits(skb, 0, &qrtr_type, 4);
+ /*
+ * Allow local name service to make packets appear as if
+ * they originated remotely
+ */
+ endpoint_id = msg_endpoint_id;
}
type = le32_to_cpu(qrtr_type);
diff --git a/net/qrtr/ns.c b/net/qrtr/ns.c
index d544e4998c5d5..d171035b88f69 100644
--- a/net/qrtr/ns.c
+++ b/net/qrtr/ns.c
@@ -5,6 +5,7 @@
* Copyright (c) 2020, Linaro Ltd.
*/
+#define pr_fmt(fmt) "QRTR NS: "fmt
#include <linux/module.h>
#include <linux/qrtr.h>
#include <linux/workqueue.h>
@@ -16,7 +17,7 @@
#define CREATE_TRACE_POINTS
#include <trace/events/qrtr.h>
-static DEFINE_XARRAY(nodes);
+static DEFINE_XARRAY(endpoints);
static struct {
struct socket *sock;
@@ -62,6 +63,7 @@ struct qrtr_server {
unsigned int node;
unsigned int port;
+ u32 endpoint_id;
struct list_head qli;
};
@@ -72,6 +74,11 @@ struct qrtr_node {
u32 server_count;
};
+struct qrtr_ns_endpoint {
+ unsigned int id;
+ struct xarray nodes;
+};
+
/* Max nodes, server, lookup limits are chosen based on the current platform
* requirements. If the requirement changes in the future, these values can be
* increased.
@@ -82,35 +89,90 @@ struct qrtr_node {
static u16 node_count;
-static struct qrtr_node *node_get(unsigned int node_id)
+static struct qrtr_node *node_get(u32 endpoint_id, unsigned int node_id)
{
+ struct qrtr_ns_endpoint *endpoint;
struct qrtr_node *node;
+ bool new_endpoint = false;
+
+ endpoint = xa_load(&endpoints, endpoint_id);
+ if (!endpoint) {
+ endpoint = kzalloc_obj(*endpoint);
+ if (!endpoint)
+ return NULL;
+
+ endpoint->id = endpoint_id;
+ xa_init(&endpoint->nodes);
+
+ if (xa_store(&endpoints, endpoint_id, endpoint, GFP_KERNEL)) {
+ kfree(endpoint);
+ return NULL;
+ }
+
+ new_endpoint = true;
+ }
- node = xa_load(&nodes, node_id);
+ node = xa_load(&endpoint->nodes, node_id);
if (node)
return node;
if (node_count >= QRTR_NS_MAX_NODES) {
pr_err_ratelimited("QRTR clients exceed max node limit!\n");
- return NULL;
+ goto error;
}
/* If node didn't exist, allocate and insert it to the tree */
node = kzalloc_obj(*node);
if (!node)
- return NULL;
+ goto error;
node->id = node_id;
xa_init(&node->servers);
- if (xa_store(&nodes, node_id, node, GFP_KERNEL)) {
+ if (xa_store(&endpoint->nodes, node_id, node, GFP_KERNEL)) {
kfree(node);
- return NULL;
+ goto error;
}
node_count++;
return node;
+error:
+ if (new_endpoint) {
+ xa_erase(&endpoints, endpoint_id);
+ kfree(endpoint);
+ }
+
+ return NULL;
+}
+
+static void node_erase(u32 endpoint_id, unsigned int node_id)
+{
+ struct qrtr_ns_endpoint *endpoint;
+ struct qrtr_node *node;
+
+ endpoint = xa_load(&endpoints, endpoint_id);
+ if (!endpoint)
+ return;
+
+ node = xa_load(&endpoint->nodes, node_id);
+ if (!node)
+ return;
+
+ xa_erase(&endpoint->nodes, node_id);
+ kfree(node);
+ node_count--;
+}
+
+static struct qrtr_node *node_lookup(u32 endpoint_id, unsigned int node_id)
+{
+ struct qrtr_ns_endpoint *endpoint;
+
+ endpoint = xa_load(&endpoints, endpoint_id);
+ if (!endpoint)
+ return NULL;
+
+ return xa_load(&endpoint->nodes, node_id);
}
static int server_match(const struct qrtr_server *srv,
@@ -126,19 +188,42 @@ static int server_match(const struct qrtr_server *srv,
return (srv->instance & ifilter) == f->instance;
}
-static int service_announce_new(struct sockaddr_qrtr *dest,
- struct qrtr_server *srv)
+static int qrtr_ns_sendmsg(u32 endpoint_id, struct sockaddr_qrtr *dest,
+ struct qrtr_ctrl_pkt *pkt)
{
- struct qrtr_ctrl_pkt pkt;
struct msghdr msg = { };
struct kvec iv;
+ u8 control[CMSG_SPACE(sizeof(endpoint_id))];
+ struct cmsghdr *cmsg;
+
+ iv.iov_base = pkt;
+ iv.iov_len = sizeof(*pkt);
+
+ msg.msg_name = (struct sockaddr *)dest;
+ msg.msg_namelen = sizeof(*dest);
+
+ if (endpoint_id) {
+ msg.msg_control = control;
+ msg.msg_controllen = sizeof(control);
+
+ cmsg = CMSG_FIRSTHDR(&msg);
+ cmsg->cmsg_level = SOL_QRTR;
+ cmsg->cmsg_type = QRTR_ENDPOINT;
+ cmsg->cmsg_len = CMSG_LEN(sizeof(endpoint_id));
+ memcpy(CMSG_DATA(cmsg), &endpoint_id, sizeof(endpoint_id));
+ }
+
+ return kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(*pkt));
+}
+
+static int service_announce_new(u32 endpoint_id, struct sockaddr_qrtr *dest,
+ struct qrtr_server *srv)
+{
+ struct qrtr_ctrl_pkt pkt;
trace_qrtr_ns_service_announce_new(srv->service, srv->instance,
srv->node, srv->port);
- iv.iov_base = &pkt;
- iv.iov_len = sizeof(pkt);
-
memset(&pkt, 0, sizeof(pkt));
pkt.cmd = cpu_to_le32(QRTR_TYPE_NEW_SERVER);
pkt.server.service = cpu_to_le32(srv->service);
@@ -146,26 +231,18 @@ static int service_announce_new(struct sockaddr_qrtr *dest,
pkt.server.node = cpu_to_le32(srv->node);
pkt.server.port = cpu_to_le32(srv->port);
- msg.msg_name = (struct sockaddr *)dest;
- msg.msg_namelen = sizeof(*dest);
-
- return kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt));
+ return qrtr_ns_sendmsg(endpoint_id, dest, &pkt);
}
-static void service_announce_del(struct sockaddr_qrtr *dest,
+static void service_announce_del(u32 endpoint_id, struct sockaddr_qrtr *dest,
struct qrtr_server *srv)
{
struct qrtr_ctrl_pkt pkt;
- struct msghdr msg = { };
- struct kvec iv;
int ret;
trace_qrtr_ns_service_announce_del(srv->service, srv->instance,
srv->node, srv->port);
- iv.iov_base = &pkt;
- iv.iov_len = sizeof(pkt);
-
memset(&pkt, 0, sizeof(pkt));
pkt.cmd = cpu_to_le32(QRTR_TYPE_DEL_SERVER);
pkt.server.service = cpu_to_le32(srv->service);
@@ -173,26 +250,24 @@ static void service_announce_del(struct sockaddr_qrtr *dest,
pkt.server.node = cpu_to_le32(srv->node);
pkt.server.port = cpu_to_le32(srv->port);
- msg.msg_name = (struct sockaddr *)dest;
- msg.msg_namelen = sizeof(*dest);
-
- ret = kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt));
+ ret = qrtr_ns_sendmsg(endpoint_id, dest, &pkt);
if (ret < 0 && ret != -ENODEV)
pr_err("failed to announce del service\n");
return;
}
-static void lookup_notify(struct sockaddr_qrtr *to, struct qrtr_server *srv,
- bool new)
+static void lookup_notify(u32 endpoint_id, struct sockaddr_qrtr *to,
+ struct qrtr_server *srv, bool new)
{
struct qrtr_ctrl_pkt pkt;
- struct msghdr msg = { };
- struct kvec iv;
int ret;
- iv.iov_base = &pkt;
- iv.iov_len = sizeof(pkt);
+ /*
+ * Notify a local client at @to about a server change. The aux data
+ * will look as if it came from the endpoint that reported the event
+ * (remote or local)
+ */
memset(&pkt, 0, sizeof(pkt));
pkt.cmd = new ? cpu_to_le32(QRTR_TYPE_NEW_SERVER) :
@@ -204,28 +279,25 @@ static void lookup_notify(struct sockaddr_qrtr *to, struct qrtr_server *srv,
pkt.server.port = cpu_to_le32(srv->port);
}
- msg.msg_name = (struct sockaddr *)to;
- msg.msg_namelen = sizeof(*to);
-
- ret = kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt));
+ ret = qrtr_ns_sendmsg(endpoint_id, to, &pkt);
if (ret < 0 && ret != -ENODEV)
pr_err("failed to send lookup notification\n");
}
-static int announce_servers(struct sockaddr_qrtr *sq)
+static int announce_servers(u32 endpoint_id, struct sockaddr_qrtr *sq)
{
struct qrtr_server *srv;
struct qrtr_node *node;
unsigned long index;
int ret;
- node = node_get(qrtr_ns.local_node);
+ node = node_lookup(qrtr_ns.local_node, qrtr_ns.local_node);
if (!node)
return 0;
- /* Announce the list of servers registered in this node */
+ /* Announce servers registered on local endpoint to remote endpoint */
xa_for_each(&node->servers, index, srv) {
- ret = service_announce_new(sq, srv);
+ ret = service_announce_new(endpoint_id, sq, srv);
if (ret < 0) {
if (ret == -ENODEV)
continue;
@@ -237,7 +309,8 @@ static int announce_servers(struct sockaddr_qrtr *sq)
return 0;
}
-static struct qrtr_server *server_add(unsigned int service,
+static struct qrtr_server *server_add(u32 endpoint_id,
+ unsigned int service,
unsigned int instance,
unsigned int node_id,
unsigned int port)
@@ -249,7 +322,7 @@ static struct qrtr_server *server_add(unsigned int service,
if (!service || !port)
return NULL;
- node = node_get(node_id);
+ node = node_get(endpoint_id, node_id);
if (!node)
return NULL;
@@ -293,7 +366,8 @@ static struct qrtr_server *server_add(unsigned int service,
return NULL;
}
-static int server_del(struct qrtr_node *node, unsigned int port, bool bcast)
+static int server_del(u32 endpoint_id, struct qrtr_node *node,
+ unsigned int port, bool bcast)
{
struct qrtr_lookup *lookup;
struct qrtr_server *srv;
@@ -305,9 +379,10 @@ static int server_del(struct qrtr_node *node, unsigned int port, bool bcast)
xa_erase(&node->servers, port);
- /* Broadcast the removal of local servers */
+ /* Broadcast the removal of local servers to remote endpoints */
if (srv->node == qrtr_ns.local_node && bcast)
- service_announce_del(&qrtr_ns.bcast_sq, srv);
+ service_announce_del(qrtr_ns.local_node,
+ &qrtr_ns.bcast_sq, srv);
/* Announce the service's disappearance to observers */
list_for_each(li, &qrtr_ns.lookups) {
@@ -317,7 +392,7 @@ static int server_del(struct qrtr_node *node, unsigned int port, bool bcast)
if (lookup->instance && lookup->instance != srv->instance)
continue;
- lookup_notify(&lookup->sq, srv, false);
+ lookup_notify(endpoint_id, &lookup->sq, srv, false);
}
kfree(srv);
@@ -326,23 +401,15 @@ static int server_del(struct qrtr_node *node, unsigned int port, bool bcast)
return 0;
}
-static int say_hello(struct sockaddr_qrtr *dest)
+static int say_hello(u32 endpoint_id, struct sockaddr_qrtr *dest)
{
struct qrtr_ctrl_pkt pkt;
- struct msghdr msg = { };
- struct kvec iv;
int ret;
- iv.iov_base = &pkt;
- iv.iov_len = sizeof(pkt);
-
memset(&pkt, 0, sizeof(pkt));
pkt.cmd = cpu_to_le32(QRTR_TYPE_HELLO);
- msg.msg_name = (struct sockaddr *)dest;
- msg.msg_namelen = sizeof(*dest);
-
- ret = kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt));
+ ret = qrtr_ns_sendmsg(endpoint_id, dest, &pkt);
if (ret < 0)
pr_err("failed to send hello msg\n");
@@ -350,42 +417,38 @@ static int say_hello(struct sockaddr_qrtr *dest)
}
/* Announce the list of servers registered on the local node */
-static int ctrl_cmd_hello(struct sockaddr_qrtr *sq)
+static int ctrl_cmd_hello(u32 endpoint_id, struct sockaddr_qrtr *sq)
{
int ret;
- ret = say_hello(sq);
+ /* Send Hello and New Server messages to remote endpoint */
+ ret = say_hello(endpoint_id, sq);
if (ret < 0)
return ret;
- return announce_servers(sq);
+ return announce_servers(endpoint_id, sq);
}
-static int ctrl_cmd_bye(struct sockaddr_qrtr *from)
+static int ctrl_cmd_bye(u32 endpoint_id, struct sockaddr_qrtr *from)
{
struct qrtr_node *local_node;
struct qrtr_ctrl_pkt pkt;
struct qrtr_server *srv;
struct sockaddr_qrtr sq;
- struct msghdr msg = { };
struct qrtr_node *node;
unsigned long index;
- struct kvec iv;
int ret = 0;
- iv.iov_base = &pkt;
- iv.iov_len = sizeof(pkt);
-
- node = node_get(from->sq_node);
+ node = node_get(endpoint_id, from->sq_node);
if (!node)
return 0;
/* Advertise removal of this client to all servers of remote node */
xa_for_each(&node->servers, index, srv)
- server_del(node, srv->port, true);
+ server_del(endpoint_id, node, srv->port, true);
/* Advertise the removal of this client to all local servers */
- local_node = node_get(qrtr_ns.local_node);
+ local_node = node_get(qrtr_ns.local_node, qrtr_ns.local_node);
if (!local_node) {
ret = 0;
goto delete_node;
@@ -400,10 +463,8 @@ static int ctrl_cmd_bye(struct sockaddr_qrtr *from)
sq.sq_node = srv->node;
sq.sq_port = srv->port;
- msg.msg_name = (struct sockaddr *)&sq;
- msg.msg_namelen = sizeof(sq);
-
- ret = kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt));
+ /* Bye will look as if it came from endpoint_id */
+ ret = qrtr_ns_sendmsg(endpoint_id, &sq, &pkt);
if (ret < 0 && ret != -ENODEV) {
pr_err("failed to send bye cmd\n");
goto delete_node;
@@ -414,32 +475,25 @@ static int ctrl_cmd_bye(struct sockaddr_qrtr *from)
ret = 0;
delete_node:
- xa_erase(&nodes, from->sq_node);
- kfree(node);
- node_count--;
+ node_erase(endpoint_id, from->sq_node);
return ret;
}
-static int ctrl_cmd_del_client(struct sockaddr_qrtr *from,
+static int ctrl_cmd_del_client(u32 endpoint_id, struct sockaddr_qrtr *from,
unsigned int node_id, unsigned int port)
{
struct qrtr_node *local_node;
struct qrtr_lookup *lookup;
struct qrtr_ctrl_pkt pkt;
- struct msghdr msg = { };
struct qrtr_server *srv;
struct sockaddr_qrtr sq;
struct qrtr_node *node;
struct list_head *tmp;
struct list_head *li;
unsigned long index;
- struct kvec iv;
int ret;
- iv.iov_base = &pkt;
- iv.iov_len = sizeof(pkt);
-
/* Don't accept spoofed messages */
if (from->sq_node != node_id)
return -EINVAL;
@@ -465,12 +519,12 @@ static int ctrl_cmd_del_client(struct sockaddr_qrtr *from,
* DEL_SERVER. Neighbours would've already removed the server belonging
* to this port due to the DEL_CLIENT broadcast from qrtr_port_remove().
*/
- node = node_get(node_id);
+ node = node_lookup(endpoint_id, node_id);
if (node)
- server_del(node, port, false);
+ server_del(endpoint_id, node, port, false);
/* Advertise the removal of this client to all local servers */
- local_node = node_get(qrtr_ns.local_node);
+ local_node = node_lookup(qrtr_ns.local_node, qrtr_ns.local_node);
if (!local_node)
return 0;
@@ -484,10 +538,8 @@ static int ctrl_cmd_del_client(struct sockaddr_qrtr *from,
sq.sq_node = srv->node;
sq.sq_port = srv->port;
- msg.msg_name = (struct sockaddr *)&sq;
- msg.msg_namelen = sizeof(sq);
-
- ret = kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt));
+ /* Del Client will look as if it came from endpoint_id */
+ ret = qrtr_ns_sendmsg(endpoint_id, &sq, &pkt);
if (ret < 0 && ret != -ENODEV) {
pr_err("failed to send del client cmd\n");
return ret;
@@ -496,7 +548,7 @@ static int ctrl_cmd_del_client(struct sockaddr_qrtr *from,
return 0;
}
-static int ctrl_cmd_new_server(struct sockaddr_qrtr *from,
+static int ctrl_cmd_new_server(u32 endpoint_id, struct sockaddr_qrtr *from,
unsigned int service, unsigned int instance,
unsigned int node_id, unsigned int port)
{
@@ -511,12 +563,16 @@ static int ctrl_cmd_new_server(struct sockaddr_qrtr *from,
port = from->sq_port;
}
- srv = server_add(service, instance, node_id, port);
- if (!srv)
+ srv = server_add(endpoint_id, service, instance, node_id, port);
+ if (!srv) {
+ pr_err("Failed to add server\n");
return -EINVAL;
+ }
if (srv->node == qrtr_ns.local_node) {
- ret = service_announce_new(&qrtr_ns.bcast_sq, srv);
+ /* Broadcast local server info to all peer endpoints */
+ ret = service_announce_new(qrtr_ns.local_node,
+ &qrtr_ns.bcast_sq, srv);
if (ret < 0) {
pr_err("failed to announce new service\n");
return ret;
@@ -531,13 +587,13 @@ static int ctrl_cmd_new_server(struct sockaddr_qrtr *from,
if (lookup->instance && lookup->instance != instance)
continue;
- lookup_notify(&lookup->sq, srv, true);
+ lookup_notify(endpoint_id, &lookup->sq, srv, true);
}
return ret;
}
-static int ctrl_cmd_del_server(struct sockaddr_qrtr *from,
+static int ctrl_cmd_del_server(u32 endpoint_id, struct sockaddr_qrtr *from,
unsigned int service, unsigned int instance,
unsigned int node_id, unsigned int port)
{
@@ -553,24 +609,22 @@ static int ctrl_cmd_del_server(struct sockaddr_qrtr *from,
if (from->sq_node == qrtr_ns.local_node && from->sq_port != port)
return -EINVAL;
- node = node_get(node_id);
+ node = node_lookup(endpoint_id, node_id);
if (!node)
return -ENOENT;
- server_del(node, port, true);
+ server_del(endpoint_id, node, port, true);
return 0;
}
-static int ctrl_cmd_new_lookup(struct sockaddr_qrtr *from,
+static int ctrl_cmd_new_lookup(u32 endpoint_id, struct sockaddr_qrtr *from,
unsigned int service, unsigned int instance)
{
struct qrtr_server_filter filter;
struct qrtr_lookup *lookup;
- struct qrtr_server *srv;
- struct qrtr_node *node;
- unsigned long node_idx;
- unsigned long srv_idx;
+ unsigned long id;
+ struct qrtr_ns_endpoint *endpoint;
/* Accept only local observers */
if (from->sq_node != qrtr_ns.local_node)
@@ -595,22 +649,30 @@ static int ctrl_cmd_new_lookup(struct sockaddr_qrtr *from,
filter.service = service;
filter.instance = instance;
- xa_for_each(&nodes, node_idx, node) {
- xa_for_each(&node->servers, srv_idx, srv) {
- if (!server_match(srv, &filter))
- continue;
+ xa_for_each(&endpoints, id, endpoint) {
+ struct qrtr_node *node;
+ unsigned long node_idx;
+
+ xa_for_each(&endpoint->nodes, node_idx, node) {
+ unsigned long srv_idx;
+ struct qrtr_server *srv;
- lookup_notify(from, srv, true);
+ xa_for_each(&node->servers, srv_idx, srv) {
+ if (!server_match(srv, &filter))
+ continue;
+
+ lookup_notify(id, from, srv, true);
+ }
}
}
/* Empty notification, to indicate end of listing */
- lookup_notify(from, NULL, true);
+ lookup_notify(0, from, NULL, true);
return 0;
}
-static void ctrl_cmd_del_lookup(struct sockaddr_qrtr *from,
+static void ctrl_cmd_del_lookup(u32 endpoint_id, struct sockaddr_qrtr *from,
unsigned int service, unsigned int instance)
{
struct qrtr_lookup *lookup;
@@ -644,6 +706,7 @@ static void qrtr_ns_worker(struct work_struct *work)
ssize_t msglen;
void *recv_buf;
struct kvec iv;
+ u8 control[32];
int ret;
msg.msg_name = (struct sockaddr *)&sq;
@@ -654,8 +717,12 @@ static void qrtr_ns_worker(struct work_struct *work)
return;
for (;;) {
+ u32 endpoint_id;
+
iv.iov_base = recv_buf;
iv.iov_len = recv_buf_size;
+ msg.msg_control = control;
+ msg.msg_controllen = sizeof(control);
msglen = kernel_recvmsg(qrtr_ns.sock, &msg, &iv, 1,
iv.iov_len, MSG_DONTWAIT);
@@ -668,6 +735,16 @@ static void qrtr_ns_worker(struct work_struct *work)
break;
}
+ /* AUX data is written direct into the control buffer */
+ msg.msg_control = control;
+ msg.msg_controllen = sizeof(control) - msg.msg_controllen;
+
+ ret = qrtr_msg_get_endpoint(&msg, &endpoint_id);
+ if (ret < 0) {
+ pr_err("error receiving endpoint id: %d\n", ret);
+ break;
+ }
+
if ((size_t)msglen < sizeof(*pkt))
break;
@@ -681,25 +758,25 @@ static void qrtr_ns_worker(struct work_struct *work)
ret = 0;
switch (cmd) {
case QRTR_TYPE_HELLO:
- ret = ctrl_cmd_hello(&sq);
+ ret = ctrl_cmd_hello(endpoint_id, &sq);
break;
case QRTR_TYPE_BYE:
- ret = ctrl_cmd_bye(&sq);
+ ret = ctrl_cmd_bye(endpoint_id, &sq);
break;
case QRTR_TYPE_DEL_CLIENT:
- ret = ctrl_cmd_del_client(&sq,
+ ret = ctrl_cmd_del_client(endpoint_id, &sq,
le32_to_cpu(pkt->client.node),
le32_to_cpu(pkt->client.port));
break;
case QRTR_TYPE_NEW_SERVER:
- ret = ctrl_cmd_new_server(&sq,
+ ret = ctrl_cmd_new_server(endpoint_id, &sq,
le32_to_cpu(pkt->server.service),
le32_to_cpu(pkt->server.instance),
le32_to_cpu(pkt->server.node),
le32_to_cpu(pkt->server.port));
break;
case QRTR_TYPE_DEL_SERVER:
- ret = ctrl_cmd_del_server(&sq,
+ ret = ctrl_cmd_del_server(endpoint_id, &sq,
le32_to_cpu(pkt->server.service),
le32_to_cpu(pkt->server.instance),
le32_to_cpu(pkt->server.node),
@@ -710,12 +787,12 @@ static void qrtr_ns_worker(struct work_struct *work)
case QRTR_TYPE_RESUME_TX:
break;
case QRTR_TYPE_NEW_LOOKUP:
- ret = ctrl_cmd_new_lookup(&sq,
+ ret = ctrl_cmd_new_lookup(endpoint_id, &sq,
le32_to_cpu(pkt->server.service),
le32_to_cpu(pkt->server.instance));
break;
case QRTR_TYPE_DEL_LOOKUP:
- ctrl_cmd_del_lookup(&sq,
+ ctrl_cmd_del_lookup(endpoint_id, &sq,
le32_to_cpu(pkt->server.service),
le32_to_cpu(pkt->server.instance));
break;
@@ -749,6 +826,8 @@ int qrtr_ns_init(void)
if (ret < 0)
return ret;
+ qrtr_sock_set_report_endpoint(qrtr_ns.sock->sk);
+
ret = kernel_getsockname(qrtr_ns.sock, (struct sockaddr *)&sq);
if (ret < 0) {
pr_err("failed to get socket name\n");
@@ -777,7 +856,7 @@ int qrtr_ns_init(void)
qrtr_ns.bcast_sq.sq_node = QRTR_NODE_BCAST;
qrtr_ns.bcast_sq.sq_port = QRTR_PORT_CTRL;
- ret = say_hello(&qrtr_ns.bcast_sq);
+ ret = say_hello(qrtr_ns.local_node, &qrtr_ns.bcast_sq);
if (ret < 0)
goto err_wq;
diff --git a/net/qrtr/qrtr.h b/net/qrtr/qrtr.h
index 22fcecbf8de23..b4f50336ae75a 100644
--- a/net/qrtr/qrtr.h
+++ b/net/qrtr/qrtr.h
@@ -35,5 +35,6 @@ int qrtr_ns_init(void);
void qrtr_ns_remove(void);
int qrtr_msg_get_endpoint(struct msghdr *msg, u32 *out_endpoint_id);
+void qrtr_sock_set_report_endpoint(struct sock *sk);
#endif
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread* [PATCH v6 12/15] net: qrtr: mhi: Report endpoint id in sysfs
2026-09-01 13:19 [PATCH v6 00/15] QRTR Multi-endpoint support Juha-Matti Tilli
` (10 preceding siblings ...)
2026-09-01 13:19 ` [PATCH v6 11/15] net: qrtr: ns: support multiple endpoints Juha-Matti Tilli
@ 2026-09-01 13:19 ` Juha-Matti Tilli
2026-09-01 13:19 ` [PATCH v6 13/15] net: qrtr: limit endpoint range to 16 bits on 32-bit machines Juha-Matti Tilli
` (2 subsequent siblings)
14 siblings, 0 replies; 20+ messages in thread
From: Juha-Matti Tilli @ 2026-09-01 13:19 UTC (permalink / raw)
To: linux-arm-msm, Manivannan Sadhasivam
Cc: Eric Dumazet, Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn,
David S . Miller, Jakub Kicinski, Simon Horman, Marcel Holtmann,
Andy Gross, Mihai Moldovan, Denis Kenzior, Juha-Matti Tilli,
linux-kernel, netdev
From: Denis Kenzior <denkenz@gmail.com>
Add a read-only 'endpoint' sysfs entry that contains the qrtr endpoint
identifier assigned to this mhi device. Can be used to direct / receive
qrtr traffic only from a particular MHI device.
Signed-off-by: Denis Kenzior <denkenz@gmail.com>
Reviewed-by: Marcel Holtmann <marcel@holtmann.org>
Reviewed-by: Andy Gross <agross@kernel.org>
Signed-off-by: Mihai Moldovan <ionic@ionic.de>
Signed-off-by: Juha-Matti Tilli <juha-matti.tilli@iki.fi>
---
net/qrtr/mhi.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/net/qrtr/mhi.c b/net/qrtr/mhi.c
index 3990da1a65dc4..630ce0da060e5 100644
--- a/net/qrtr/mhi.c
+++ b/net/qrtr/mhi.c
@@ -106,6 +106,16 @@ static int qcom_mhi_qrtr_queue_dl_buffers(struct mhi_device *mhi_dev)
return 0;
}
+static ssize_t endpoint_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct qrtr_mhi_dev *qdev = dev_get_drvdata(dev);
+
+ return sprintf(buf, "%u\n", qdev->ep.id);
+}
+
+static DEVICE_ATTR_RO(endpoint);
+
static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_dev,
const struct mhi_device_id *id)
{
@@ -135,6 +145,9 @@ static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_dev,
if (rc)
goto err_unregister;
+ if (device_create_file(&mhi_dev->dev, &dev_attr_endpoint) < 0)
+ dev_err(qdev->dev, "Failed to create endpoint attribute\n");
+
dev_dbg(qdev->dev, "Qualcomm MHI QRTR driver probed\n");
return 0;
@@ -151,6 +164,7 @@ static void qcom_mhi_qrtr_remove(struct mhi_device *mhi_dev)
{
struct qrtr_mhi_dev *qdev = dev_get_drvdata(&mhi_dev->dev);
+ device_remove_file(&mhi_dev->dev, &dev_attr_endpoint);
qrtr_endpoint_unregister(&qdev->ep);
mhi_unprepare_from_transfer(mhi_dev);
dev_set_drvdata(&mhi_dev->dev, NULL);
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread* [PATCH v6 13/15] net: qrtr: limit endpoint range to 16 bits on 32-bit machines
2026-09-01 13:19 [PATCH v6 00/15] QRTR Multi-endpoint support Juha-Matti Tilli
` (11 preceding siblings ...)
2026-09-01 13:19 ` [PATCH v6 12/15] net: qrtr: mhi: Report endpoint id in sysfs Juha-Matti Tilli
@ 2026-09-01 13:19 ` Juha-Matti Tilli
2026-09-05 1:40 ` Jakub Kicinski
2026-09-01 13:19 ` [PATCH v6 14/15] net: qrtr: use nid modulo 65536 in 32-bit lookups Juha-Matti Tilli
2026-09-01 13:19 ` [PATCH v6 15/15] net: qrtr: solve the 32-bit unsafe use in endpoints Juha-Matti Tilli
14 siblings, 1 reply; 20+ messages in thread
From: Juha-Matti Tilli @ 2026-09-01 13:19 UTC (permalink / raw)
To: linux-arm-msm, Manivannan Sadhasivam
Cc: Eric Dumazet, Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn,
David S . Miller, Jakub Kicinski, Simon Horman, Marcel Holtmann,
Andy Gross, Mihai Moldovan, Denis Kenzior, Juha-Matti Tilli,
linux-kernel, netdev
On 64-bit machines, use the full range for endpoint ids, but on 32-bit
machines, use only 16 bits. This gives plenty of endpoints, 65534 to
be specific, apart from the invalid zero value and the local endpoint.
This should fix any issues where a long-running system with lots of
allocations might allocate an endpoint id bigger than 65535 on a 32-bit
system. The node id, the secondary part, is already combined with port
id into a value that is potentially 32 bits in existing old code.
NOTE: please don't merge yet. This commit will have to be either
squashed or removed.
Signed-off-by: Juha-Matti Tilli <juha-matti.tilli@iki.fi>
---
net/qrtr/af_qrtr.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index b27c5a659795d..f1601c0701fdb 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -22,7 +22,11 @@
#define QRTR_MAX_EPH_SOCKET 0x7fff
#define QRTR_EPH_PORT_RANGE \
XA_LIMIT(QRTR_MIN_EPH_SOCKET, QRTR_MAX_EPH_SOCKET)
+#if BITS_PER_LONG >= 64
#define QRTR_ENDPOINT_RANGE XA_LIMIT(qrtr_local_nid + 1, INT_MAX)
+#else
+#define QRTR_ENDPOINT_RANGE XA_LIMIT(qrtr_local_nid + 1, UINT16_MAX)
+#endif
#define QRTR_PORT_CTRL_LEGACY 0xffff
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: [PATCH v6 13/15] net: qrtr: limit endpoint range to 16 bits on 32-bit machines
2026-09-01 13:19 ` [PATCH v6 13/15] net: qrtr: limit endpoint range to 16 bits on 32-bit machines Juha-Matti Tilli
@ 2026-09-05 1:40 ` Jakub Kicinski
2026-09-05 4:21 ` Juha-Matti Tilli
0 siblings, 1 reply; 20+ messages in thread
From: Jakub Kicinski @ 2026-09-05 1:40 UTC (permalink / raw)
To: Juha-Matti Tilli
Cc: linux-arm-msm, Manivannan Sadhasivam, Eric Dumazet,
Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn,
David S . Miller, Simon Horman, Marcel Holtmann, Andy Gross,
Mihai Moldovan, Denis Kenzior, linux-kernel, netdev
On Tue, 1 Sep 2026 16:19:32 +0300 Juha-Matti Tilli wrote:
> On 64-bit machines, use the full range for endpoint ids, but on 32-bit
> machines, use only 16 bits. This gives plenty of endpoints, 65534 to
> be specific, apart from the invalid zero value and the local endpoint.
>
> This should fix any issues where a long-running system with lots of
> allocations might allocate an endpoint id bigger than 65535 on a 32-bit
> system. The node id, the secondary part, is already combined with port
> id into a value that is potentially 32 bits in existing old code.
>
> NOTE: please don't merge yet. This commit will have to be either
> squashed or removed.
Doesn't build on 32bit x86:
../net/qrtr/af_qrtr.c: In function ‘qrtr_endpoint_register’:
../net/qrtr/af_qrtr.c:28:58: error: ‘UINT16_MAX’ undeclared (first use in this function)
28 | #define QRTR_ENDPOINT_RANGE XA_LIMIT(qrtr_local_nid + 1, UINT16_MAX)
| ^~~~~~~~~~
../include/linux/xarray.h:248:70: note: in definition of macro ‘XA_LIMIT’
248 | #define XA_LIMIT(_min, _max) (struct xa_limit) { .min = _min, .max = _max }
| ^~~~
../net/qrtr/af_qrtr.c:746:30: note: in expansion of macro ‘QRTR_ENDPOINT_RANGE’
746 | QRTR_ENDPOINT_RANGE, &next_endpoint_id,
| ^~~~~~~~~~~~~~~~~~~
../net/qrtr/af_qrtr.c:16:1: note: ‘UINT16_MAX’ is defined in header ‘<stdint.h>’; this is probably fixable by adding ‘#include <stdint.h>’
15 | #include "qrtr.h"
+++ |+#include <stdint.h>
16 |
../net/qrtr/af_qrtr.c:28:58: note: each undeclared identifier is reported only once for each function it appears in
28 | #define QRTR_ENDPOINT_RANGE XA_LIMIT(qrtr_local_nid + 1, UINT16_MAX)
| ^~~~~~~~~~
../include/linux/xarray.h:248:70: note: in definition of macro ‘XA_LIMIT’
248 | #define XA_LIMIT(_min, _max) (struct xa_limit) { .min = _min, .max = _max }
| ^~~~
../net/qrtr/af_qrtr.c:746:30: note: in expansion of macro ‘QRTR_ENDPOINT_RANGE’
746 | QRTR_ENDPOINT_RANGE, &next_endpoint_id,
| ^~~~~~~~~~~~~~~~~~~
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: [PATCH v6 13/15] net: qrtr: limit endpoint range to 16 bits on 32-bit machines
2026-09-05 1:40 ` Jakub Kicinski
@ 2026-09-05 4:21 ` Juha-Matti Tilli
2026-09-05 10:07 ` David Laight
0 siblings, 1 reply; 20+ messages in thread
From: Juha-Matti Tilli @ 2026-09-05 4:21 UTC (permalink / raw)
To: Jakub Kicinski
Cc: linux-arm-msm, Manivannan Sadhasivam, Eric Dumazet,
Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn,
David S . Miller, Simon Horman, Marcel Holtmann, Andy Gross,
Mihai Moldovan, Denis Kenzior, linux-kernel, netdev
On Sat, Sep 5, 2026, at 04:40, Jakub Kicinski wrote:
> On Tue, 1 Sep 2026 16:19:32 +0300 Juha-Matti Tilli wrote:
> > On 64-bit machines, use the full range for endpoint ids, but on 32-bit
> > machines, use only 16 bits. This gives plenty of endpoints, 65534 to
> > be specific, apart from the invalid zero value and the local endpoint.
> >
> > [snip]
>
> Doesn't build on 32bit x86:
>
> ../net/qrtr/af_qrtr.c: In function ‘qrtr_endpoint_register’:
> ../net/qrtr/af_qrtr.c:28:58: error: ‘UINT16_MAX’ undeclared (first use in this function)
> 28 | #define QRTR_ENDPOINT_RANGE XA_LIMIT(qrtr_local_nid + 1, UINT16_MAX)
> [snip]
Indeed, I will later post a new version with UINT16_MAX replaced by
65535.
I thought I was careful testing these, but now I recall that the
individual patches were test-compiled on 64-bit and only the branch
head with all patches was tested on 32-bit.
Thanks for noticing!
BR, Juha-Matti
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v6 13/15] net: qrtr: limit endpoint range to 16 bits on 32-bit machines
2026-09-05 4:21 ` Juha-Matti Tilli
@ 2026-09-05 10:07 ` David Laight
2026-09-05 10:55 ` Juha-Matti Tilli
0 siblings, 1 reply; 20+ messages in thread
From: David Laight @ 2026-09-05 10:07 UTC (permalink / raw)
To: Juha-Matti Tilli
Cc: Jakub Kicinski, linux-arm-msm, Manivannan Sadhasivam,
Eric Dumazet, Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn,
David S . Miller, Simon Horman, Marcel Holtmann, Andy Gross,
Mihai Moldovan, Denis Kenzior, linux-kernel, netdev
On Sat, 05 Sep 2026 07:21:33 +0300
"Juha-Matti Tilli" <juha-matti.tilli@iki.fi> wrote:
> On Sat, Sep 5, 2026, at 04:40, Jakub Kicinski wrote:
> > On Tue, 1 Sep 2026 16:19:32 +0300 Juha-Matti Tilli wrote:
> > > On 64-bit machines, use the full range for endpoint ids, but on 32-bit
> > > machines, use only 16 bits. This gives plenty of endpoints, 65534 to
> > > be specific, apart from the invalid zero value and the local endpoint.
> > >
> > > [snip]
> >
> > Doesn't build on 32bit x86:
> >
> > ../net/qrtr/af_qrtr.c: In function ‘qrtr_endpoint_register’:
> > ../net/qrtr/af_qrtr.c:28:58: error: ‘UINT16_MAX’ undeclared (first use in this function)
> > 28 | #define QRTR_ENDPOINT_RANGE XA_LIMIT(qrtr_local_nid + 1, UINT16_MAX)
> > [snip]
>
> Indeed, I will later post a new version with UINT16_MAX replaced by
> 65535.
Makes more sense anyway because it is an arbitrary bound (rather than
ensuring the result will fit in 16 bits.
Indeed, it might be better to use a different limit.
David
>
> I thought I was careful testing these, but now I recall that the
> individual patches were test-compiled on 64-bit and only the branch
> head with all patches was tested on 32-bit.
>
> Thanks for noticing!
>
> BR, Juha-Matti
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v6 13/15] net: qrtr: limit endpoint range to 16 bits on 32-bit machines
2026-09-05 10:07 ` David Laight
@ 2026-09-05 10:55 ` Juha-Matti Tilli
0 siblings, 0 replies; 20+ messages in thread
From: Juha-Matti Tilli @ 2026-09-05 10:55 UTC (permalink / raw)
To: David Laight
Cc: Jakub Kicinski, linux-arm-msm, Manivannan Sadhasivam,
Eric Dumazet, Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn,
David S . Miller, Simon Horman, Marcel Holtmann, Andy Gross,
Mihai Moldovan, Denis Kenzior, linux-kernel, netdev
On Sat, Sep 5, 2026, at 13:07, David Laight wrote:
> On Sat, 05 Sep 2026 07:21:33 +0300
> "Juha-Matti Tilli" <juha-matti.tilli@iki.fi> wrote:
> > Indeed, I will later post a new version with UINT16_MAX replaced by
> > 65535.
>
> Makes more sense anyway because it is an arbitrary bound (rather than
> ensuring the result will fit in 16 bits.
> Indeed, it might be better to use a different limit.
Well, on that I might disagree. As of this commit, the code will have to
cram that into 16 bits on 32-bit platforms. Only the later commit will
remove the restriction that lookups are limited to 32 bits total.
Node ids are 32-bit by definition, so 32+16=48 > 32, so u16 won't help.
Of course, there's the possibility that if the later commit is what we
want, that this will be squashed with the later commit.
I looked at most XA_LIMIT users and they seem to follow the policy that
allocations are limited to usually 16, 31 or 32 bits. And I found
USHRT_MAX -- that's what I was looking for instead of UINT16_MAX.
So I still think that "limited by kernel memory" is the best here. While
I can't envision a system with more than 65534 QRTR endpoints, I'm still
uncomfortable with setting the limit to a low value.
So, the next patchset will have USHRT_MAX. Soon my patchset of actually
having multiple ath11k/ath12k is ready for review so I'll post that too.
It fixes the memory leak in Mihai's original set.
BR, Juha-Matti
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v6 14/15] net: qrtr: use nid modulo 65536 in 32-bit lookups
2026-09-01 13:19 [PATCH v6 00/15] QRTR Multi-endpoint support Juha-Matti Tilli
` (12 preceding siblings ...)
2026-09-01 13:19 ` [PATCH v6 13/15] net: qrtr: limit endpoint range to 16 bits on 32-bit machines Juha-Matti Tilli
@ 2026-09-01 13:19 ` Juha-Matti Tilli
2026-09-01 13:19 ` [PATCH v6 15/15] net: qrtr: solve the 32-bit unsafe use in endpoints Juha-Matti Tilli
14 siblings, 0 replies; 20+ messages in thread
From: Juha-Matti Tilli @ 2026-09-01 13:19 UTC (permalink / raw)
To: linux-arm-msm, Manivannan Sadhasivam
Cc: Eric Dumazet, Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn,
David S . Miller, Jakub Kicinski, Simon Horman, Marcel Holtmann,
Andy Gross, Mihai Moldovan, Denis Kenzior, Juha-Matti Tilli,
linux-kernel, netdev
The node id is chosen by the device firmware, and is generally a small
single number. However, there's nothing to prevent the device from
choosing a large node id. Use node id modulo 65536 in 32-bit systems to
allow it to work in cases where the node id is large.
NOTE: please don't merge yet. This commit will have to be either
squashed or removed.
Signed-off-by: Juha-Matti Tilli <juha-matti.tilli@iki.fi>
---
net/qrtr/af_qrtr.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index f1601c0701fdb..960e6e816be41 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -497,8 +497,11 @@ static struct qrtr_node *qrtr_node_lookup(unsigned int endpoint_id,
unsigned long flags;
unsigned long key = 0;
- if (endpoint_id > QRTR_INDEX_HALF_UNSIGNED_MAX ||
- nid > QRTR_INDEX_HALF_UNSIGNED_MAX)
+ /* nid is chosen by device firmware and is generally a single
+ * and small number. If firmware chooses otherwise, use it
+ * modulo 65536 in 32-bit systems.
+ */
+ if (endpoint_id > QRTR_INDEX_HALF_UNSIGNED_MAX)
return node;
key = ((unsigned long)(endpoint_id) << QRTR_INDEX_HALF_BITS) |
@@ -529,8 +532,11 @@ static int qrtr_node_assign(struct qrtr_node *node, unsigned int nid)
if (nid == QRTR_EP_NID_AUTO)
return 0;
- if (node->ep->id > QRTR_INDEX_HALF_UNSIGNED_MAX ||
- nid > QRTR_INDEX_HALF_UNSIGNED_MAX)
+ /* nid is chosen by device firmware and is generally a single
+ * and small number. If firmware chooses otherwise, use it
+ * modulo 65536 in 32-bit systems.
+ */
+ if (node->ep->id > QRTR_INDEX_HALF_UNSIGNED_MAX)
return -EINVAL;
spin_lock_irqsave(&qrtr_nodes_lock, flags);
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread* [PATCH v6 15/15] net: qrtr: solve the 32-bit unsafe use in endpoints
2026-09-01 13:19 [PATCH v6 00/15] QRTR Multi-endpoint support Juha-Matti Tilli
` (13 preceding siblings ...)
2026-09-01 13:19 ` [PATCH v6 14/15] net: qrtr: use nid modulo 65536 in 32-bit lookups Juha-Matti Tilli
@ 2026-09-01 13:19 ` Juha-Matti Tilli
14 siblings, 0 replies; 20+ messages in thread
From: Juha-Matti Tilli @ 2026-09-01 13:19 UTC (permalink / raw)
To: linux-arm-msm, Manivannan Sadhasivam
Cc: Eric Dumazet, Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn,
David S . Miller, Jakub Kicinski, Simon Horman, Marcel Holtmann,
Andy Gross, Mihai Moldovan, Denis Kenzior, Juha-Matti Tilli,
linux-kernel, netdev
In 32-bit architectures, a single radix tree can have at most 32 bit
keys. We're cramming 64 bits in there. To solve this, use a radix tree
of radix trees. First, the endpoint is looked up. Secondly, the node is
looked up based on the endpoint.
Theoretically, there could be the option of skipping the "tree of trees"
approach if long is 64 bits. However, this has the drawback that the
code would be entirely different on 32-bit and 64-bit architectures, and
could create subtle bugs where someone commits and tests modifications
on a 64-bit architecture, and suddenly those who use a 32-bit
architecture would see them break.
This has been tested on a 32-bit ARM machine with two identical ath11k
modules, using patches by Mihai Moldovan to allow multiple modules to
work in parallel.
Signed-off-by: Juha-Matti Tilli <juha-matti.tilli@iki.fi>
Tested-by: Juha-Matti Tilli <juha-matti.tilli@iki.fi>
---
net/qrtr/af_qrtr.c | 118 ++++++++++++++++++++++++++++++---------------
net/qrtr/qrtr.h | 10 ++++
2 files changed, 89 insertions(+), 39 deletions(-)
diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index 960e6e816be41..7c50d32b11015 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -22,11 +22,7 @@
#define QRTR_MAX_EPH_SOCKET 0x7fff
#define QRTR_EPH_PORT_RANGE \
XA_LIMIT(QRTR_MIN_EPH_SOCKET, QRTR_MAX_EPH_SOCKET)
-#if BITS_PER_LONG >= 64
#define QRTR_ENDPOINT_RANGE XA_LIMIT(qrtr_local_nid + 1, INT_MAX)
-#else
-#define QRTR_ENDPOINT_RANGE XA_LIMIT(qrtr_local_nid + 1, UINT16_MAX)
-#endif
#define QRTR_PORT_CTRL_LEGACY 0xffff
@@ -186,6 +182,9 @@ static DEFINE_XARRAY_ALLOC(qrtr_ports);
#define QRTR_INDEX_HALF_SIGNED_MAX ((long)(QRTR_INDEX_HALF_UNSIGNED_MAX) >> 1)
#define QRTR_INDEX_HALF_SIGNED_MIN ((long)(-1) - QRTR_INDEX_HALF_SIGNED_MAX)
+/* endpoint not defined, i.e. endpoint 0 */
+static struct qrtr_node_lookup_helper helper0;
+
/**
* struct qrtr_node - endpoint node
* @ep_lock: lock for endpoint management and callbacks
@@ -245,9 +244,11 @@ static void __qrtr_node_release(struct kref *kref)
{
struct qrtr_node *node = container_of(kref, struct qrtr_node, ref);
struct radix_tree_iter iter;
+ struct radix_tree_iter iter2;
struct qrtr_tx_flow *flow;
unsigned long flags;
void __rcu **slot;
+ void __rcu **slot2;
unsigned long index;
spin_lock_irqsave(&qrtr_nodes_lock, flags);
@@ -255,8 +256,18 @@ static void __qrtr_node_release(struct kref *kref)
* multiple entries pointing to our released node, delete them all.
*/
radix_tree_for_each_slot(slot, &qrtr_nodes, &iter, 0) {
- if (*slot == node)
+ struct qrtr_node_lookup_helper *helper = *slot;
+
+ if (!helper)
+ continue;
+ radix_tree_for_each_slot(slot2, &helper->nodes, &iter2, 0) {
+ if (*slot2 == node)
+ radix_tree_iter_delete(&helper->nodes, &iter2, slot2);
+ }
+ if (helper != &helper0 && radix_tree_empty(&helper->nodes)) {
radix_tree_iter_delete(&qrtr_nodes, &iter, slot);
+ helper->added = 0;
+ }
}
spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
@@ -494,22 +505,14 @@ static struct qrtr_node *qrtr_node_lookup(unsigned int endpoint_id,
unsigned int nid)
{
struct qrtr_node *node = NULL;
+ struct qrtr_node_lookup_helper *helper = NULL;
unsigned long flags;
- unsigned long key = 0;
-
- /* nid is chosen by device firmware and is generally a single
- * and small number. If firmware chooses otherwise, use it
- * modulo 65536 in 32-bit systems.
- */
- if (endpoint_id > QRTR_INDEX_HALF_UNSIGNED_MAX)
- return node;
-
- key = ((unsigned long)(endpoint_id) << QRTR_INDEX_HALF_BITS) |
- ((unsigned long)(nid) & QRTR_INDEX_HALF_UNSIGNED_MAX);
mutex_lock(&qrtr_node_lock);
spin_lock_irqsave(&qrtr_nodes_lock, flags);
- node = radix_tree_lookup(&qrtr_nodes, key);
+ helper = radix_tree_lookup(&qrtr_nodes, endpoint_id);
+ if (helper)
+ node = radix_tree_lookup(&helper->nodes, nid);
node = qrtr_node_acquire(node);
spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
mutex_unlock(&qrtr_node_lock);
@@ -527,33 +530,45 @@ static struct qrtr_node *qrtr_node_lookup(unsigned int endpoint_id,
static int qrtr_node_assign(struct qrtr_node *node, unsigned int nid)
{
unsigned long flags;
- unsigned long key;
+ int rc = 0;
+ int did_insert0 = 0;
if (nid == QRTR_EP_NID_AUTO)
return 0;
- /* nid is chosen by device firmware and is generally a single
- * and small number. If firmware chooses otherwise, use it
- * modulo 65536 in 32-bit systems.
- */
- if (node->ep->id > QRTR_INDEX_HALF_UNSIGNED_MAX)
- return -EINVAL;
-
spin_lock_irqsave(&qrtr_nodes_lock, flags);
- /* Always insert with the endpoint_id + node_id */
- key = ((unsigned long)(node->ep->id) << QRTR_INDEX_HALF_BITS) |
- ((unsigned long)(nid) & QRTR_INDEX_HALF_UNSIGNED_MAX);
- radix_tree_insert(&qrtr_nodes, key, node);
-
- if (!radix_tree_lookup(&qrtr_nodes, nid))
- radix_tree_insert(&qrtr_nodes, nid, node);
+ if (!radix_tree_lookup(&helper0.nodes, nid)) {
+ rc = radix_tree_insert(&helper0.nodes, nid, node);
+ if (rc)
+ goto err_lock;
+ did_insert0 = 1;
+ }
+ if (!node->ep->helper.added) {
+ INIT_RADIX_TREE(&node->ep->helper.nodes, GFP_ATOMIC);
+ rc = radix_tree_insert(&qrtr_nodes, node->ep->id,
+ &node->ep->helper);
+ if (rc)
+ goto err_insert0;
+ node->ep->helper.added = 1;
+ }
+ rc = radix_tree_insert(&node->ep->helper.nodes, nid, node);
+ if (rc && rc != -EEXIST)
+ goto err_insert0; // Don't revert helper insertion
if (node->nid == QRTR_EP_NID_AUTO)
node->nid = nid;
spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
return 0;
+
+err_insert0:
+ if (did_insert0)
+ radix_tree_delete(&helper0.nodes, nid);
+
+err_lock:
+ spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
+ return rc;
}
/**
@@ -773,6 +788,7 @@ int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid)
mutex_unlock(&qrtr_node_lock);
ep->node = node;
ep->id = endpoint_id;
+ ep->helper.added = 0;
return 0;
free_node:
@@ -791,12 +807,14 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep)
struct sockaddr_qrtr src = {AF_QIPCRTR, node->nid, QRTR_PORT_CTRL};
struct sockaddr_qrtr dst = {AF_QIPCRTR, qrtr_local_nid, QRTR_PORT_CTRL};
struct radix_tree_iter iter;
+ struct radix_tree_iter iter2;
struct qrtr_ctrl_pkt *pkt;
struct qrtr_tx_flow *flow;
struct sk_buff *skb;
unsigned long flags;
unsigned long index;
void __rcu **slot;
+ void __rcu **slot2;
u32 endpoint_id;
mutex_lock(&node->ep_lock);
@@ -807,16 +825,28 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep)
/* Notify the local controller about the event */
spin_lock_irqsave(&qrtr_nodes_lock, flags);
radix_tree_for_each_slot(slot, &qrtr_nodes, &iter, 0) {
- if (*slot != node)
+ struct qrtr_node_lookup_helper *helper = *slot;
+
+ if (!helper)
continue;
- src.sq_node = iter.index;
- skb = qrtr_alloc_ctrl_packet(&pkt, GFP_ATOMIC);
- if (skb) {
- pkt->cmd = cpu_to_le32(QRTR_TYPE_BYE);
- qrtr_local_enqueue(NULL, skb, endpoint_id,
- QRTR_TYPE_BYE, &src, &dst);
+ radix_tree_for_each_slot(slot2, &helper->nodes, &iter2, 0) {
+ if (*slot2 != node)
+ continue;
+ src.sq_node = iter.index;
+ skb = qrtr_alloc_ctrl_packet(&pkt, GFP_ATOMIC);
+ if (skb) {
+ pkt->cmd = cpu_to_le32(QRTR_TYPE_BYE);
+ qrtr_local_enqueue(NULL, skb, endpoint_id,
+ QRTR_TYPE_BYE, &src, &dst);
+ }
}
}
+ if (ep->helper.added) {
+ radix_tree_for_each_slot(slot, &ep->helper.nodes, &iter, 0)
+ radix_tree_iter_delete(&ep->helper.nodes, &iter, slot);
+ radix_tree_delete(&qrtr_nodes, ep->id);
+ ep->helper.added = 0;
+ }
spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
/* Wake up any transmitters waiting for resume-tx from the node */
@@ -1593,8 +1623,17 @@ static int __init qrtr_proto_init(void)
if (rc)
goto err_sock;
+ rc = radix_tree_insert(&qrtr_nodes, 0, &helper0);
+ if (rc)
+ goto err_ns;
+
+ INIT_RADIX_TREE(&helper0.nodes, GFP_ATOMIC);
+ helper0.added = 1;
+
return 0;
+err_ns:
+ qrtr_ns_remove();
err_sock:
sock_unregister(qrtr_family.family);
err_proto:
@@ -1605,6 +1644,7 @@ postcore_initcall(qrtr_proto_init);
static void __exit qrtr_proto_fini(void)
{
+ radix_tree_delete(&qrtr_nodes, 0);
qrtr_ns_remove();
sock_unregister(qrtr_family.family);
proto_unregister(&qrtr_proto);
diff --git a/net/qrtr/qrtr.h b/net/qrtr/qrtr.h
index b4f50336ae75a..affc24f426c64 100644
--- a/net/qrtr/qrtr.h
+++ b/net/qrtr/qrtr.h
@@ -9,6 +9,15 @@ struct sk_buff;
/* endpoint node id auto assignment */
#define QRTR_EP_NID_AUTO (-1)
+/**
+ * struct qrtr_node_lookup_helper - node lookup helper, stored in qrtr_nodes
+ * @nodes: nodes, indexed by node_id
+ */
+struct qrtr_node_lookup_helper {
+ int added;
+ struct radix_tree_root nodes;
+};
+
/**
* struct qrtr_endpoint - endpoint handle
* @xmit: Callback for outgoing packets
@@ -21,6 +30,7 @@ struct qrtr_endpoint {
int (*xmit)(struct qrtr_endpoint *ep, struct sk_buff *skb);
/* private: not for endpoint use */
struct qrtr_node *node;
+ struct qrtr_node_lookup_helper helper;
u32 id;
};
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread