Re: [PATCH net-next v3 03/15] quic: provide common utilities and data structures

Paolo Abeni <[email protected]> Thu, 25 Sep 2025 17:50:07 +0200
Newsgroups dev.linux.lists.quic,dev.linux.lists.kernel-tls-handshake,org.kernel.vger.linux-cifs,org.kernel.vger.netdev
Message-ID <[email protected]>
On 9/23/25 6:06 PM, Xin Long wrote:
> On Tue, Sep 23, 2025 at 7:21 AM Paolo Abeni <[email protected]> wrote:
>> On 9/19/25 12:34 AM, Xin Long wrote:
>>> +static int quic_uhash_table_init(struct quic_uhash_table *ht, u32 max_size, int order)
>>> +{
>>> +     int i, max_order, size;
>>> +
>>> +     /* Same sizing logic as in quic_shash_table_init(). */
>>> +     max_order = get_order(max_size * sizeof(struct quic_uhash_head));
>>> +     order = min(order, max_order);
>>> +     do {
>>> +             ht->hash = (struct quic_uhash_head *)
>>> +                     __get_free_pages(GFP_KERNEL | __GFP_NOWARN, order);
>>> +     } while (!ht->hash && --order > 0);
>>
>> You can avoid a little complexity, and see more consistent behaviour,
>> using plain vmalloc() or alloc_large_system_hash() with no fallback.
>>
> I wanted to use alloc_large_system_hash(), but the memory allocated
> by it is usually NOT meant to be freed at runtime. I don't see a free_
> function to do it either.
> 
> If QUIC works as a kernel module, what should I do with this memory
> in module_exit()?

Right, I did not think about such case. I suggest using a plain
vmalloc() without the loop than.

>>> +/* rfc9000#section-a.3: DecodePacketNumber()
>>> + *
>>> + * Reconstructs the full packet number from a truncated one.
>>> + */
>>> +s64 quic_get_num(s64 max_pkt_num, s64 pkt_num, u32 n)
>>> +{
>>> +     s64 expected = max_pkt_num + 1;
>>> +     s64 win = BIT_ULL(n * 8);
>>> +     s64 hwin = win / 2;
>>> +     s64 mask = win - 1;
>>> +     s64 cand;
>>> +
>>> +     cand = (expected & ~mask) | pkt_num;
>>> +     if (cand <= expected - hwin && cand < (1ULL << 62) - win)
>>> +             return cand + win;
>>> +     if (cand > expected + hwin && cand >= win)
>>> +             return cand - win;
>>> +     return cand;
>>
>> The above is a bit obscure to me; replacing magic nubers (62) with macro
>> could help. Some more comments also would do.
>>
> The code is exactly from the commented doc:
> /* rfc9000#section-a.3: DecodePacketNumber()
> 
> See:
> https://datatracker.ietf.org/doc/html/rfc9000#section-a.3
> 
> I will bring some comments from there.

You can quote or make a synopsis of the RFC where it makes sense. In any
case, please try to reduce magic numbers usage.

Thanks,

Paolo