Re: [PATCH v7 03/15] net: qrtr: fit node ID + port number combination into unsigned long
From: Manivannan Sadhasivam
Date: Wed Sep 16 2026 - 03:06:39 EST
On Tue, Sep 15, 2026 at 08:41:55AM +0300, Juha-Matti Tilli wrote:
> From: Mihai Moldovan <ionic@xxxxxxxx>
>
> 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.
>
Documentation/core-api/xarray.rst says:
"If your index can be larger than ``ULONG_MAX`` then the XArray is not the data
type for you."
So the fix is to not make XArray work, but switch over to some other storage
mechanism instead of XArray, like hashtable.
- Mani
--
மணிவண்ணன் சதாசிவம்