[PATCH v2 03/10] net: qrtr: support identical node ids

Mihai Moldovan posted 10 patches 2 months, 2 weeks ago
There is a newer version of this series
[PATCH v2 03/10] net: qrtr: support identical node ids
Posted by Mihai Moldovan 2 months, 2 weeks ago
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>

---

v2:
  - rebase against current master
  - no action on review comment regarding integer overflow on 32 bit
    long platforms (thus far)
---
 net/qrtr/af_qrtr.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index be275871fb2a..e83d491a8da9 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -418,12 +418,20 @@ static struct qrtr_node *qrtr_node_lookup(unsigned int nid)
 static void qrtr_node_assign(struct qrtr_node *node, unsigned int nid)
 {
 	unsigned long flags;
+	unsigned long key;
 
 	if (nid == QRTR_EP_NID_AUTO)
 		return;
 
 	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 << 32 | nid;
+	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);
-- 
2.50.0
Re: [PATCH v2 03/10] net: qrtr: support identical node ids
Posted by kernel test robot 2 months, 2 weeks ago
Hi Mihai,

kernel test robot noticed the following build warnings:

[auto build test WARNING on mani-mhi/mhi-next]
[also build test WARNING on net-next/main net/main linus/master v6.16-rc6 next-20250718]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Mihai-Moldovan/net-qrtr-ns-validate-msglen-before-ctrl_pkt-use/20250720-030426
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mani/mhi.git mhi-next
patch link:    https://lore.kernel.org/r/4d0fe1eab4b38fb85e2ec53c07289bc0843611a2.1752947108.git.ionic%40ionic.de
patch subject: [PATCH v2 03/10] net: qrtr: support identical node ids
config: arc-randconfig-002-20250720 (https://download.01.org/0day-ci/archive/20250720/202507200739.pd0Gkp22-lkp@intel.com/config)
compiler: arc-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250720/202507200739.pd0Gkp22-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202507200739.pd0Gkp22-lkp@intel.com/

All warnings (new ones prefixed by >>):

   net/qrtr/af_qrtr.c: In function 'qrtr_node_assign':
>> net/qrtr/af_qrtr.c:429:36: warning: left shift count >= width of type [-Wshift-count-overflow]
     key = (unsigned long)node->ep->id << 32 | nid;
                                       ^~


vim +429 net/qrtr/af_qrtr.c

   412	
   413	/* Assign node id to node.
   414	 *
   415	 * This is mostly useful for automatic node id assignment, based on
   416	 * the source id in the incoming packet.
   417	 */
   418	static void qrtr_node_assign(struct qrtr_node *node, unsigned int nid)
   419	{
   420		unsigned long flags;
   421		unsigned long key;
   422	
   423		if (nid == QRTR_EP_NID_AUTO)
   424			return;
   425	
   426		spin_lock_irqsave(&qrtr_nodes_lock, flags);
   427	
   428		/* Always insert with the endpoint_id + node_id */
 > 429		key = (unsigned long)node->ep->id << 32 | nid;
   430		radix_tree_insert(&qrtr_nodes, key, node);
   431	
   432		if (!radix_tree_lookup(&qrtr_nodes, nid))
   433			radix_tree_insert(&qrtr_nodes, nid, node);
   434	
   435		if (node->nid == QRTR_EP_NID_AUTO)
   436			node->nid = nid;
   437		spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
   438	}
   439	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki