From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Scott Mitchell <scott.k.mitch1@gmail.com>
Cc: kadlec@netfilter.org, fw@strlen.de, phil@nwl.cc,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org,
netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
syzbot@syzkaller.appspotmail.com
Subject: Re: [PATCH v5] netfilter: nfnetlink_queue: optimize verdict lookup with hash table
Date: Thu, 15 Jan 2026 01:50:16 +0100 [thread overview]
Message-ID: <aWg5yCcSrLZka854@chamomile> (raw)
In-Reply-To: <CAFn2buDeCxJp3OHDifc5yX0pQndmLCKc=PShT+6Jq3-uy8C-OA@mail.gmail.com>
Hi Scott,
On Tue, Jan 13, 2026 at 08:32:56PM -0500, Scott Mitchell wrote:
> > > + NFQA_CFG_HASH_SIZE, /* __u32 hash table size (rounded to power of 2) */
> >
> > This should use the rhashtable implementation, I don't find a good
> > reason why this is not used in first place for this enhancement.
>
> Thank you for the review! I can make the changes. Before implementing,
> I have a few questions to ensure I understand the preferred approach:
>
> 1. For the "perns" allocation comment - which approach did you have in mind:
> a) Shared rhashtable in nfnl_queue_net (initialized in
> nfnl_queue_net_init) with key={queue_num, packet_id}
> b) Per-instance rhashtable in nfqnl_instance, with lock refactoring
> so initialization happens outside rcu_read_lock
Yes, but...
Florian suggests a single rhashtable for all netns should be good
enough, you only have to include net_hash_mix(net) in the hash.
> 2. The lock refactoring (GFP_ATOMIC → GFP_KERNEL) is independent of
> the hash structure choice, correct? We could fix that separately?
No lock refactoring anymore since rhashtable would be initialized only
once for all netns, as Florian suggests.
> 3. Can you help me understand the trade-offs you considered for
> rhashtable vs hlist_head? Removing the API makes sense, and I want to
> better understand how to weigh that against runtime overhead (RCU,
> locks, atomic ops) for future design decisions.
Your approach consumes ~1Mbyte per queue instance, and we could end
up with 64k queues per-netns.
This is exposed to unprivileged containers, this allows userspace
to deplete the atomic reserves since GFP_ATOMIC is toggled, and...
there is no GFP_ATOMIC_ACCOUNT flag, then accounting does not apply in
this case.
While rhashtable a bit heavyweight, it should consume a lot less
memory and users does not have to do any hashtable bucket tunning.
> I'll use a custom hashfn to preserve the current mask-based hashing
> for the incrementing IDs.
OK.
Thanks.
next prev parent reply other threads:[~2026-01-15 0:50 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-22 0:37 [PATCH v5] netfilter: nfnetlink_queue: optimize verdict lookup with hash table Scott Mitchell
2025-12-03 18:33 ` Scott Mitchell
2025-12-03 18:40 ` Florian Westphal
2025-12-03 21:07 ` Scott Mitchell
2026-01-13 0:25 ` Pablo Neira Ayuso
2026-01-14 1:32 ` Scott Mitchell
2026-01-15 0:50 ` Pablo Neira Ayuso [this message]
2026-01-15 17:07 ` Florian Westphal
2026-01-17 17:33 ` Scott Mitchell
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=aWg5yCcSrLZka854@chamomile \
--to=pablo@netfilter.org \
--cc=coreteam@netfilter.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=fw@strlen.de \
--cc=horms@kernel.org \
--cc=kadlec@netfilter.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=phil@nwl.cc \
--cc=scott.k.mitch1@gmail.com \
--cc=syzbot@syzkaller.appspotmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.