From: Hou Tao <houtao1@huawei.com>
To: Florian Lehner <dev@der-flo.net>, <bpf@vger.kernel.org>
Cc: <ast@kernel.org>, <daniel@iogearbox.net>, <andrii@kernel.org>,
<martin.lau@linux.dev>, <song@kernel.org>, <yhs@fb.com>,
<john.fastabend@gmail.com>, <kpsingh@kernel.org>,
<sdf@google.com>, <haoluo@google.com>, <jolsa@kernel.org>
Subject: Re: [PATCH bpf-next] bpf: Update max_entries for array maps
Date: Wed, 26 Oct 2022 11:35:19 +0800 [thread overview]
Message-ID: <e250349c-cd3c-ac2e-f0fd-da083aa87ceb@huawei.com> (raw)
In-Reply-To: <20221025092843.81572-1-dev@der-flo.net>
Hi,
On 10/25/2022 5:28 PM, Florian Lehner wrote:
> To improve memory handling and alignment max_entries is rounded up
> before using its value to allocate memory.
> This can lead to a situation where more memory is allocated than usable
> if max_entries is no adjusted accordingly. So this change updates
> max_entries in order to make the allocated memory available.
>
> Signed-off-by: Florian Lehner <dev@der-flo.net>
> ---
> kernel/bpf/arraymap.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c
> index 832b2659e96e..9411fa255ccc 100644
> --- a/kernel/bpf/arraymap.c
> +++ b/kernel/bpf/arraymap.c
> @@ -145,6 +145,7 @@ static struct bpf_map *array_map_alloc(union bpf_attr *attr)
> /* copy mandatory map attributes */
> bpf_map_init_from_attr(&array->map, attr);
> array->elem_size = elem_size;
> + array->map.max_entries = max_entries;
>
> if (percpu && bpf_array_alloc_percpu(array)) {
> bpf_map_area_free(array);
The override of max_entries is unnecessary and is also wrong.
bpf_array_alloc_percpu() will use array->map.max_entries to allocate per-cpu
value, and if using the rounded-up max_entries, there will be memory waste
because the extra allocated per-cpu values should not be accessible to bpf
program or user-space program.
prev parent reply other threads:[~2022-10-26 3:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-25 9:28 [PATCH bpf-next] bpf: Update max_entries for array maps Florian Lehner
2022-10-26 3:35 ` Hou Tao [this message]
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=e250349c-cd3c-ac2e-f0fd-da083aa87ceb@huawei.com \
--to=houtao1@huawei.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dev@der-flo.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=martin.lau@linux.dev \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=yhs@fb.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox