From: Yosry Ahmed <yosryahmed-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
To: Alexei Starovoitov <ast-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
Daniel Borkmann <daniel-FeC+5ew28dpmcu3hnIyYJQ@public.gmane.org>,
Andrii Nakryiko <andrii-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
Martin KaFai Lau <kafai-b10kYP2dOMg@public.gmane.org>,
Song Liu <songliubraving-b10kYP2dOMg@public.gmane.org>,
Yonghong Song <yhs-b10kYP2dOMg@public.gmane.org>,
Hao Luo <haoluo-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
Zefan Li <lizefan.x-EC8Uxl6Npydl57MIdRCFDg@public.gmane.org>
Cc: "Johannes Weiner"
<hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org>,
"Shuah Khan" <shuah-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
"Michal Hocko" <mhocko-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
"KP Singh" <kpsingh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
"Benjamin Tissoires"
<benjamin.tissoires-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
"John Fastabend"
<john.fastabend-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
"Michal Koutný" <mkoutny-IBi9RG/b67k@public.gmane.org>,
"Roman Gushchin"
<roman.gushchin-fxUVXftIFDnyG1zEObXtfA@public.gmane.org>,
"David Rientjes"
<rientjes-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
"Stanislav Fomichev"
<sdf-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
"Greg Thelen" <gthelen-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
"Shakeel Butt" <shakeelb-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
bpf-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
"Yosry Ahmed"
<yosryahmed-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
Subject: [PATCH bpf-next v3 1/8] btf: Add a new kfunc set which allows to mark a function to be sleepable
Date: Sat, 9 Jul 2022 00:04:32 +0000 [thread overview]
Message-ID: <20220709000439.243271-2-yosryahmed@google.com> (raw)
In-Reply-To: <20220709000439.243271-1-yosryahmed-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
From: Benjamin Tissoires <benjamin.tissoires-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
This allows to declare a kfunc as sleepable and prevents its use in
a non sleepable program.
Signed-off-by: Benjamin Tissoires <benjamin.tissoires-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Signed-off-by: Yosry Ahmed <yosryahmed-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
---
include/linux/btf.h | 2 ++
kernel/bpf/btf.c | 13 +++++++++++--
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/include/linux/btf.h b/include/linux/btf.h
index 1bfed7fa04287..6e7517573d9e4 100644
--- a/include/linux/btf.h
+++ b/include/linux/btf.h
@@ -18,6 +18,7 @@ enum btf_kfunc_type {
BTF_KFUNC_TYPE_RELEASE,
BTF_KFUNC_TYPE_RET_NULL,
BTF_KFUNC_TYPE_KPTR_ACQUIRE,
+ BTF_KFUNC_TYPE_SLEEPABLE,
BTF_KFUNC_TYPE_MAX,
};
@@ -37,6 +38,7 @@ struct btf_kfunc_id_set {
struct btf_id_set *release_set;
struct btf_id_set *ret_null_set;
struct btf_id_set *kptr_acquire_set;
+ struct btf_id_set *sleepable_set;
};
struct btf_id_set *sets[BTF_KFUNC_TYPE_MAX];
};
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 4f2408a4df08b..2a4b4e50b6fb7 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -6172,7 +6172,7 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env,
struct bpf_verifier_log *log = &env->log;
u32 i, nargs, ref_id, ref_obj_id = 0;
bool is_kfunc = btf_is_kernel(btf);
- bool rel = false, kptr_get = false;
+ bool rel = false, kptr_get = false, sleepable = false;
const char *func_name, *ref_tname;
const struct btf_type *t, *ref_t;
const struct btf_param *args;
@@ -6203,11 +6203,13 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env,
}
if (is_kfunc) {
- /* Only kfunc can be release func */
+ /* Only kfunc can be release, kptr acquire, or sleepable func */
rel = btf_kfunc_id_set_contains(btf, resolve_prog_type(env->prog),
BTF_KFUNC_TYPE_RELEASE, func_id);
kptr_get = btf_kfunc_id_set_contains(btf, resolve_prog_type(env->prog),
BTF_KFUNC_TYPE_KPTR_ACQUIRE, func_id);
+ sleepable = btf_kfunc_id_set_contains(btf, resolve_prog_type(env->prog),
+ BTF_KFUNC_TYPE_SLEEPABLE, func_id);
}
/* check that BTF function arguments match actual types that the
@@ -6405,6 +6407,13 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env,
func_name);
return -EINVAL;
}
+
+ if (sleepable && !env->prog->aux->sleepable) {
+ bpf_log(log, "kernel function %s is sleepable but the program is not\n",
+ func_name);
+ return -EINVAL;
+ }
+
/* returns argument register number > 0 in case of reference release kfunc */
return rel ? ref_regno : 0;
}
--
2.37.0.rc0.161.g10f37bed90-goog
next prev parent reply other threads:[~2022-07-09 0:04 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-09 0:04 [PATCH bpf-next v3 0/8] bpf: rstat: cgroup hierarchical stats Yosry Ahmed
[not found] ` <20220709000439.243271-1-yosryahmed-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2022-07-09 0:04 ` Yosry Ahmed [this message]
2022-07-09 0:04 ` [PATCH bpf-next v3 4/8] bpf: Introduce cgroup iter Yosry Ahmed
2022-07-11 0:19 ` Yonghong Song
2022-07-11 23:20 ` Yonghong Song
2022-07-12 0:42 ` Hao Luo
2022-07-12 3:45 ` Yonghong Song
[not found] ` <2a26b45d-6fab-b2a2-786e-5cb4572219ea-b10kYP2dOMg@public.gmane.org>
2022-07-21 0:40 ` Hao Luo
2022-07-21 16:15 ` Yonghong Song
[not found] ` <3f3ffe0e-d2ac-c868-a1bf-cdf1b58fd666-b10kYP2dOMg@public.gmane.org>
2022-07-21 17:21 ` Hao Luo
2022-07-21 18:15 ` Yonghong Song
2022-07-21 21:07 ` Hao Luo
2022-07-09 0:04 ` [PATCH bpf-next v3 2/8] cgroup: enable cgroup_get_from_file() on cgroup1 Yosry Ahmed
2022-07-09 0:04 ` [PATCH bpf-next v3 3/8] bpf, iter: Fix the condition on p when calling stop Yosry Ahmed
2022-07-09 0:04 ` [PATCH bpf-next v3 5/8] selftests/bpf: Test cgroup_iter Yosry Ahmed
2022-07-09 0:04 ` [PATCH bpf-next v3 6/8] cgroup: bpf: enable bpf programs to integrate with rstat Yosry Ahmed
2022-07-09 0:04 ` [PATCH bpf-next v3 7/8] selftests/bpf: extend cgroup helpers Yosry Ahmed
2022-07-09 0:04 ` [PATCH bpf-next v3 8/8] bpf: add a selftest for cgroup hierarchical stats collection Yosry Ahmed
2022-07-11 0:26 ` Yonghong Song
[not found] ` <b4936952-2fe7-656c-2d0d-69044265392a-b10kYP2dOMg@public.gmane.org>
2022-07-11 0:51 ` Yonghong Song
2022-07-11 6:01 ` Hao Luo
2022-07-11 6:19 ` Yonghong Song
[not found] ` <e2f8fcd8-9219-1119-86ca-69714789d494-b10kYP2dOMg@public.gmane.org>
2022-07-12 0:44 ` Hao Luo
2022-07-12 3:55 ` Yosry Ahmed
2022-07-18 19:34 ` Yosry Ahmed
[not found] ` <CAJD7tkb8-scb1sstre0LRhY3dgfUJhGvSR=DgEqfwcVtBwb+5w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2022-07-19 0:19 ` Hao Luo
2022-07-19 16:17 ` Yonghong Song
2022-07-19 17:02 ` Yosry Ahmed
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=20220709000439.243271-2-yosryahmed@google.com \
--to=yosryahmed-hpiqsd4aklfqt0dzr+alfa@public.gmane.org \
--cc=andrii-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=ast-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=benjamin.tissoires-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=bpf-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=daniel-FeC+5ew28dpmcu3hnIyYJQ@public.gmane.org \
--cc=gthelen-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
--cc=hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org \
--cc=haoluo-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
--cc=john.fastabend-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=kafai-b10kYP2dOMg@public.gmane.org \
--cc=kpsingh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=lizefan.x-EC8Uxl6Npydl57MIdRCFDg@public.gmane.org \
--cc=mhocko-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=mkoutny-IBi9RG/b67k@public.gmane.org \
--cc=netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=rientjes-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
--cc=roman.gushchin-fxUVXftIFDnyG1zEObXtfA@public.gmane.org \
--cc=sdf-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
--cc=shakeelb-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
--cc=shuah-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=songliubraving-b10kYP2dOMg@public.gmane.org \
--cc=tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=yhs-b10kYP2dOMg@public.gmane.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