All of lore.kernel.org
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: bpf@vger.kernel.org
Cc: 'Alexei Starovoitov ' <ast@kernel.org>,
	'Andrii Nakryiko ' <andrii@kernel.org>,
	'Daniel Borkmann ' <daniel@iogearbox.net>,
	kernel-team@meta.com
Subject: [PATCH bpf-next] bpf: Reduce smap->elem_size
Date: Fri, 16 Dec 2022 15:29:51 -0800	[thread overview]
Message-ID: <20221216232951.3575596-1-martin.lau@linux.dev> (raw)

From: Martin KaFai Lau <martin.lau@kernel.org>

'struct bpf_local_storage_elem' has a 56 bytes padding at the end
which can be used for attr->value_size.  The current smap->elem_size
calculation is unnecessarily inflated by 56 bytes.

The patch is to fix it by calculating the smap->elem_size
with offsetof().

Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
---
 kernel/bpf/bpf_local_storage.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storage.c
index b39a46e8fb08..cb43e70613b1 100644
--- a/kernel/bpf/bpf_local_storage.c
+++ b/kernel/bpf/bpf_local_storage.c
@@ -580,8 +580,8 @@ static struct bpf_local_storage_map *__bpf_local_storage_map_alloc(union bpf_att
 		raw_spin_lock_init(&smap->buckets[i].lock);
 	}
 
-	smap->elem_size =
-		sizeof(struct bpf_local_storage_elem) + attr->value_size;
+	smap->elem_size = offsetof(struct bpf_local_storage_elem, sdata) +
+		offsetof(struct bpf_local_storage_data, data[attr->value_size]);
 
 	return smap;
 }
-- 
2.30.2


             reply	other threads:[~2022-12-16 23:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-16 23:29 Martin KaFai Lau [this message]
2022-12-17  1:23 ` [PATCH bpf-next] bpf: Reduce smap->elem_size Yonghong Song
     [not found]   ` <844f94a4-a003-55da-dc29-adf9f448fc45@linux.dev>
     [not found]     ` <CAEf4BzbJGpkhyio9+S1U=bnYycaknw0SNada6orzNV_+VfPwGw@mail.gmail.com>
2022-12-21  0:56       ` Martin KaFai Lau
2022-12-21  1:15         ` Andrii Nakryiko

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=20221216232951.3575596-1-martin.lau@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@meta.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.