From: Florian Lehner <dev@der-flo.net>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org,
yonghong.song@linux.dev, john.fastabend@gmail.com,
kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com,
jolsa@kernel.org, aspsk@isovalent.com, kees@kernel.org,
quic_abchauha@quicinc.com, martin.kelly@crowdstrike.com,
mykolal@fb.com, shuah@kernel.org, yikai.lin@vivo.com,
Florian Lehner <dev@der-flo.net>
Subject: [bpf-next 1/2] bpf: Add flag to continue batch operation
Date: Sun, 10 Nov 2024 12:29:03 +0100 [thread overview]
Message-ID: <20241110112905.64616-2-dev@der-flo.net> (raw)
In-Reply-To: <20241110112905.64616-1-dev@der-flo.net>
Introduce flag for batch operations to continue batch deletes when missing
keys are encountered. This allows to flush maps at once without the need to
keep track of the keys in a map.
Signed-off-by: Florian Lehner <dev@der-flo.net>
---
include/uapi/linux/bpf.h | 5 +++++
kernel/bpf/syscall.c | 14 +++++++++++---
tools/include/uapi/linux/bpf.h | 5 +++++
3 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 4162afc6b5d0..b38884cf6fe3 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -1423,6 +1423,11 @@ enum {
*/
#define BPF_F_QUERY_EFFECTIVE (1U << 0)
+/* Flags for batch operations. */
+
+/* If set, continue with batch operation even if a key is missing. */
+#define BPF_F_BATCH_IGNORE_MISSING_KEY (1U << 1)
+
/* Flags for BPF_PROG_TEST_RUN */
/* If set, run the test on the cpu specified by bpf_attr.test.cpu */
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 58190ca724a2..860d6dc0c6d9 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -1851,7 +1851,7 @@ int generic_map_delete_batch(struct bpf_map *map,
union bpf_attr __user *uattr)
{
void __user *keys = u64_to_user_ptr(attr->batch.keys);
- u32 cp, max_count;
+ u32 count, cp, max_count;
int err = 0;
void *key;
@@ -1874,6 +1874,7 @@ int generic_map_delete_batch(struct bpf_map *map,
if (!key)
return -ENOMEM;
+ count = 0;
for (cp = 0; cp < max_count; cp++) {
err = -EFAULT;
if (copy_from_user(key, keys + cp * map->key_size,
@@ -1890,11 +1891,18 @@ int generic_map_delete_batch(struct bpf_map *map,
err = map->ops->map_delete_elem(map, key);
rcu_read_unlock();
bpf_enable_instrumentation();
- if (err)
+ if (err) {
+ if (err == -ENOENT &&
+ (attr->batch.flags & BPF_F_BATCH_IGNORE_MISSING_KEY)) {
+ cond_resched();
+ continue;
+ }
break;
+ }
cond_resched();
+ count++;
}
- if (copy_to_user(&uattr->batch.count, &cp, sizeof(cp)))
+ if (copy_to_user(&uattr->batch.count, &count, sizeof(count)))
err = -EFAULT;
kvfree(key);
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 4162afc6b5d0..ea03e7e8272b 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -1423,6 +1423,11 @@ enum {
*/
#define BPF_F_QUERY_EFFECTIVE (1U << 0)
+/* Flags for batch operations. */
+
+/* If set, continue with batch operation even if a key is missing. */
+#define BPF_F_BATCH_IGNORE_MISSING_KEY (1U << 1)
+
/* Flags for BPF_PROG_TEST_RUN */
/* If set, run the test on the cpu specified by bpf_attr.test.cpu */
--
2.47.0
next prev parent reply other threads:[~2024-11-10 11:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-10 11:29 [bpf-next 0/2] bpf: Add flag for batch operation Florian Lehner
2024-11-10 11:29 ` Florian Lehner [this message]
2024-11-10 11:29 ` [bpf-next 2/2] selftests/bpf: Add a test for batch operation flag Florian Lehner
2024-11-11 14:15 ` [bpf-next 0/2] bpf: Add flag for batch operation Hou Tao
2024-11-12 3:01 ` Alexei Starovoitov
2024-11-12 19:13 ` dev
2024-11-12 19:47 ` Alexei Starovoitov
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=20241110112905.64616-2-dev@der-flo.net \
--to=dev@der-flo.net \
--cc=andrii@kernel.org \
--cc=aspsk@isovalent.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kees@kernel.org \
--cc=kpsingh@kernel.org \
--cc=martin.kelly@crowdstrike.com \
--cc=martin.lau@linux.dev \
--cc=mykolal@fb.com \
--cc=quic_abchauha@quicinc.com \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yikai.lin@vivo.com \
--cc=yonghong.song@linux.dev \
/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