From: Stefano Brivio <sbrivio@redhat.com>
To: Florian Westphal <fw@strlen.de>
Cc: <netfilter-devel@vger.kernel.org>
Subject: Re: [PATCH nf-next 2/4] netfilter: nft_set_pipapo: do not rely on ZERO_SIZE_PTR
Date: Tue, 13 Feb 2024 08:20:07 +0100 [thread overview]
Message-ID: <20240213082007.3f4e689d@elisabeth> (raw)
In-Reply-To: <20240212100202.10116-3-fw@strlen.de>
On Mon, 12 Feb 2024 11:01:51 +0100
Florian Westphal <fw@strlen.de> wrote:
> pipapo relies on kmalloc(0) returning ZERO_SIZE_PTR (i.e., not NULL
> but pointer is invalid).
>
> Rework this to not call slab allocator when we'd request a 0-byte
> allocation.
>
> While at it, also use GFP_KERNEL allocations here, this is only called
> from control plane.
>
> Signed-off-by: Florian Westphal <fw@strlen.de>
> ---
> net/netfilter/nft_set_pipapo.c | 20 ++++++++++++++------
> 1 file changed, 14 insertions(+), 6 deletions(-)
>
> diff --git a/net/netfilter/nft_set_pipapo.c b/net/netfilter/nft_set_pipapo.c
> index 395420fa71e5..6a79ec98de86 100644
> --- a/net/netfilter/nft_set_pipapo.c
> +++ b/net/netfilter/nft_set_pipapo.c
> @@ -526,13 +526,16 @@ static struct nft_pipapo_elem *pipapo_get(const struct net *net,
> const struct nft_pipapo_field *f;
> int i;
>
> - res_map = kmalloc_array(m->bsize_max, sizeof(*res_map), GFP_ATOMIC);
> + if (m->bsize_max == 0)
> + return ret;
> +
> + res_map = kmalloc_array(m->bsize_max, sizeof(*res_map), GFP_KERNEL);
> if (!res_map) {
> ret = ERR_PTR(-ENOMEM);
> goto out;
> }
>
> - fill_map = kcalloc(m->bsize_max, sizeof(*res_map), GFP_ATOMIC);
> + fill_map = kcalloc(m->bsize_max, sizeof(*res_map), GFP_KERNEL);
I haven't re-checked the whole logic, but can't nft_pipapo_deactivate()
(hence pipapo_deactivate() and pipapo_get()) be called from the data
path for some reason?
If I recall correctly that's why I used GFP_ATOMIC here, but I'm not
sure anymore and I guess you know better.
> if (!fill_map) {
> ret = ERR_PTR(-ENOMEM);
> goto out;
> @@ -1367,11 +1370,16 @@ static struct nft_pipapo_match *pipapo_clone(struct nft_pipapo_match *old)
> src->bsize * sizeof(*dst->lt) *
> src->groups * NFT_PIPAPO_BUCKETS(src->bb));
>
> - dst->mt = kvmalloc(src->rules * sizeof(*src->mt), GFP_KERNEL);
> - if (!dst->mt)
> - goto out_mt;
> + if (src->rules > 0) {
> + dst->mt = kvmalloc_array(src->rules, sizeof(*src->mt), GFP_KERNEL);
Nit: equally readable within 80 columns:
dst->mt = kvmalloc_array(src->rules, sizeof(*src->mt),
GFP_KERNEL);
> + if (!dst->mt)
> + goto out_mt;
> +
> + memcpy(dst->mt, src->mt, src->rules * sizeof(*src->mt));
> + } else {
> + dst->mt = NULL;
> + }
>
> - memcpy(dst->mt, src->mt, src->rules * sizeof(*src->mt));
> src++;
> dst++;
> }
--
Stefano
next prev parent reply other threads:[~2024-02-13 7:20 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-12 10:01 [PATCH nf-next 0/4] netfilter: nft_set_pipapo: speed up bulk element insertions Florian Westphal
2024-02-12 10:01 ` [PATCH nf-next 1/4] netfilter: nft_set_pipapo: constify lookup fn args where possible Florian Westphal
2024-02-13 7:19 ` Stefano Brivio
2024-02-12 10:01 ` [PATCH nf-next 2/4] netfilter: nft_set_pipapo: do not rely on ZERO_SIZE_PTR Florian Westphal
2024-02-13 7:20 ` Stefano Brivio [this message]
2024-02-13 11:09 ` Florian Westphal
2024-02-12 10:01 ` [PATCH nf-next 3/4] netfilter: nft_set_pipapo: shrink data structures Florian Westphal
2024-02-13 13:17 ` Stefano Brivio
2024-02-12 10:01 ` [PATCH nf-next 4/4] netfilter: nft_set_pipapo: speed up bulk element insertions Florian Westphal
2024-02-13 13:17 ` Stefano Brivio
2024-02-13 13:29 ` Florian Westphal
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=20240213082007.3f4e689d@elisabeth \
--to=sbrivio@redhat.com \
--cc=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
/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).