All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hengqi Chen <hengqi.chen@gmail.com>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	martin.lau@linux.dev, song@kernel.org, yhs@fb.com,
	toke@redhat.com, hengqi.chen@gmail.com
Subject: [PATCH bpf 1/2] bpf: Check timer_off for map_in_map only when map value have timer
Date: Sat, 26 Nov 2022 18:53:50 +0800	[thread overview]
Message-ID: <20221126105351.2578782-2-hengqi.chen@gmail.com> (raw)
In-Reply-To: <20221126105351.2578782-1-hengqi.chen@gmail.com>

The timer_off value could be -EINVAL or -ENOENT when map value of
inner map is struct and contains no bpf_timer. The EINVAL case happens
when the map is created without BTF key/value info, map->timer_off
is set to -EINVAL in map_create(). The ENOENT case happens when
the map is created with BTF key/value info (e.g. from BPF skeleton),
map->timer_off is set to -ENOENT as what btf_find_timer() returns.
In bpf_map_meta_equal(), we expect timer_off to be equal even if
map value does not contains bpf_timer. This rejects map_in_map created
with BTF key/value info to be updated using inner map without BTF
key/value info in case inner map value is struct. This commit lifts
such restriction.

Fixes: 68134668c17f ("bpf: Add map side support for bpf timers.")
Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
---
 kernel/bpf/map_in_map.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/kernel/bpf/map_in_map.c b/kernel/bpf/map_in_map.c
index 135205d0d560..0840872de486 100644
--- a/kernel/bpf/map_in_map.c
+++ b/kernel/bpf/map_in_map.c
@@ -80,11 +80,18 @@ void bpf_map_meta_free(struct bpf_map *map_meta)
 bool bpf_map_meta_equal(const struct bpf_map *meta0,
 			const struct bpf_map *meta1)
 {
+	bool timer_off_equal;
+
+	if (!map_value_has_timer(meta0) && !map_value_has_timer(meta1))
+		timer_off_equal = true;
+	else
+		timer_off_equal = meta0->timer_off == meta1->timer_off;
+
 	/* No need to compare ops because it is covered by map_type */
 	return meta0->map_type == meta1->map_type &&
 		meta0->key_size == meta1->key_size &&
 		meta0->value_size == meta1->value_size &&
-		meta0->timer_off == meta1->timer_off &&
+		timer_off_equal &&
 		meta0->map_flags == meta1->map_flags &&
 		bpf_map_equal_kptr_off_tab(meta0, meta1);
 }
--
2.34.1

  reply	other threads:[~2022-11-26 10:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-26 10:53 [PATCH bpf 0/2] Check timer_off for map_in_map only when map value has timer Hengqi Chen
2022-11-26 10:53 ` Hengqi Chen [this message]
2022-11-27  3:21   ` [PATCH bpf 1/2] bpf: Check timer_off for map_in_map only when map value have timer Yonghong Song
2022-11-28  2:16     ` Hengqi Chen
2022-11-28  0:44   ` Alexei Starovoitov
2022-11-28  2:42     ` Hengqi Chen
2022-11-28  2:49       ` Alexei Starovoitov
2022-11-28  3:07         ` Hengqi Chen
2022-11-28  3:14           ` Alexei Starovoitov
2022-11-28  4:11             ` Hengqi Chen
2022-11-29  6:12       ` Andrii Nakryiko
2022-11-26 10:53 ` [PATCH bpf 2/2] selftests/bpf: Update map_in_map using map without BTF key/value info Hengqi Chen

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=20221126105351.2578782-2-hengqi.chen@gmail.com \
    --to=hengqi.chen@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=martin.lau@linux.dev \
    --cc=song@kernel.org \
    --cc=toke@redhat.com \
    --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 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.