On (25/05/05 09:49), Matt Bobrowski wrote: > I noticed that you've written the newly proposed BPF helper in the > legacy BPF helper form, which I believe is now discouraged, as also > stated within the above comment. You probably want to respin this > patch series having written this newly proposed BPF helper in BPF > kfuncs [0] form instead. Oh, okay, I didn't know about kfunc. So I guess it's something like the patch below. > Additionally, as part of your patch series I think you'll also want to > include some selftests. Let me take a look. Any hints on how to test it? --- include/uapi/linux/bpf.h | 8 ++++++++ kernel/bpf/helpers.c | 6 ++++++ tools/include/uapi/linux/bpf.h | 8 ++++++++ 3 files changed, 22 insertions(+) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 71d5ac83cf5d..8624cb2ac7d9 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -5814,6 +5814,14 @@ union bpf_attr { * 0 on success. * * **-ENOENT** if the bpf_local_storage cannot be found. + * + * unsigned long bpf_msleep_interruptible(unsigned int msecs) + * Description + * Make the current task sleep until *msecs* milliseconds have + * elapsed or until a signal is received. + * + * Return + * The remaining time of the sleep duration in milliseconds. */ #define ___BPF_FUNC_MAPPER(FN, ctx...) \ FN(unspec, 0, ##ctx) \ diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index e3a2662f4e33..6ba75bf816f2 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -3194,6 +3194,11 @@ __bpf_kfunc void bpf_local_irq_restore(unsigned long *flags__irq_flag) local_irq_restore(*flags__irq_flag); } +__bpf_kfunc unsigned long bpf_msleep_interruptible(unsigned int msecs) +{ + return msleep_interruptible(msecs); +} + __bpf_kfunc_end_defs(); BTF_KFUNCS_START(generic_btf_ids) @@ -3294,6 +3299,7 @@ BTF_ID_FLAGS(func, bpf_iter_kmem_cache_next, KF_ITER_NEXT | KF_RET_NULL | KF_SLE BTF_ID_FLAGS(func, bpf_iter_kmem_cache_destroy, KF_ITER_DESTROY | KF_SLEEPABLE) BTF_ID_FLAGS(func, bpf_local_irq_save) BTF_ID_FLAGS(func, bpf_local_irq_restore) +BTF_ID_FLAGS(func, bpf_msleep_interruptible) BTF_KFUNCS_END(common_btf_ids) static const struct btf_kfunc_id_set common_kfunc_set = { diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 71d5ac83cf5d..8624cb2ac7d9 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -5814,6 +5814,14 @@ union bpf_attr { * 0 on success. * * **-ENOENT** if the bpf_local_storage cannot be found. + * + * unsigned long bpf_msleep_interruptible(unsigned int msecs) + * Description + * Make the current task sleep until *msecs* milliseconds have + * elapsed or until a signal is received. + * + * Return + * The remaining time of the sleep duration in milliseconds. */ #define ___BPF_FUNC_MAPPER(FN, ctx...) \ FN(unspec, 0, ##ctx) \ -- 2.49.0.906.g1f30a19c02-goog