From: Mihai Moldovan <ionic@ionic.de>
To: linux-arm-msm@vger.kernel.org, Manivannan Sadhasivam <mani@kernel.org>
Cc: Denis Kenzior <denkenz@gmail.com>,
Eric Dumazet <edumazet@google.com>,
Kuniyuki Iwashima <kuniyu@google.com>,
Paolo Abeni <pabeni@redhat.com>,
Willem de Bruijn <willemb@google.com>,
"David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Simon Horman <horms@kernel.org>,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH v4 02/11] net: qrtr: allocate and track endpoint ids
Date: Mon, 28 Jul 2025 18:45:19 +0200 [thread overview]
Message-ID: <347e1fb6aba96b3ef63634b21a20f36453a3bcac.1753720934.git.ionic@ionic.de> (raw)
In-Reply-To: <cover.1753720934.git.ionic@ionic.de>
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>
---
v4:
- no changes
- Link to v3: https://msgid.link/10b228a30c4416201fa90a10e75ddf05935dc3ec.1753312999.git.ionic@ionic.de
v3:
- rebase against current master
- Link to v2: https://msgid.link/86ef12964a23c9331be16961a5f9c6ec857aa56c.1752947108.git.ionic@ionic.de
v2:
- rebase against current master
- Link to v1: https://msgid.link/20241018181842.1368394-3-denkenz@gmail.com
---
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 00c51cf693f3..be275871fb2a 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);
@@ -585,6 +590,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;
@@ -593,6 +600,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);
@@ -608,8 +622,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);
@@ -628,8 +646,10 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep)
struct sk_buff *skb;
unsigned long flags;
void __rcu **slot;
+ u32 endpoint_id;
mutex_lock(&node->ep_lock);
+ endpoint_id = node->ep->id;
node->ep = NULL;
mutex_unlock(&node->ep_lock);
@@ -656,6 +676,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 3f2d28696062..11b897af05e6 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.50.0
next prev parent reply other threads:[~2025-07-28 16:45 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-28 16:45 [PATCH v4 00/11] QRTR Multi-endpoint support Mihai Moldovan
2025-07-28 16:45 ` [PATCH v4 01/11] net: qrtr: ns: validate msglen before ctrl_pkt use Mihai Moldovan
2025-07-28 16:45 ` Mihai Moldovan [this message]
2025-07-28 16:45 ` [PATCH v4 03/11] net: qrtr: fit node ID + port number combination into unsigned long Mihai Moldovan
2025-07-28 16:45 ` [PATCH v4 04/11] net: qrtr: support identical node ids Mihai Moldovan
2025-07-28 16:45 ` [PATCH v4 05/11] net: qrtr: Report sender endpoint in aux data Mihai Moldovan
2025-07-28 16:45 ` [PATCH v4 06/11] net: qrtr: Report endpoint for locally generated messages Mihai Moldovan
2025-07-28 16:45 ` [PATCH v4 07/11] net: qrtr: Allow sendmsg to target an endpoint Mihai Moldovan
2025-07-28 16:45 ` [PATCH v4 08/11] net: qrtr: allow socket endpoint binding Mihai Moldovan
2025-07-28 16:45 ` [PATCH v4 09/11] net: qrtr: Drop remote {NEW|DEL}_LOOKUP messages Mihai Moldovan
2025-07-28 16:45 ` [PATCH v4 10/11] net: qrtr: ns: support multiple endpoints Mihai Moldovan
2025-07-28 16:45 ` [PATCH v4 11/11] net: qrtr: mhi: Report endpoint id in sysfs Mihai Moldovan
2025-07-31 0:57 ` [PATCH v4 00/11] QRTR Multi-endpoint support Jakub Kicinski
2025-07-31 5:47 ` Mihai Moldovan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=347e1fb6aba96b3ef63634b21a20f36453a3bcac.1753720934.git.ionic@ionic.de \
--to=ionic@ionic.de \
--cc=davem@davemloft.net \
--cc=denkenz@gmail.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mani@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).