bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpf: Add bpf_guard_preempt() convenience macro
@ 2024-04-24 22:55 Alexei Starovoitov
  2024-04-25 12:45 ` Kumar Kartikeya Dwivedi
  2024-04-25 18:10 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Alexei Starovoitov @ 2024-04-24 22:55 UTC (permalink / raw)
  To: bpf; +Cc: daniel, andrii, martin.lau, memxor, eddyz87, kernel-team

From: Alexei Starovoitov <ast@kernel.org>

Add bpf_guard_preempt() macro that uses newly introduced
bpf_preempt_disable/enable() kfuncs to guard a critical section.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
 .../testing/selftests/bpf/bpf_experimental.h  | 22 +++++++++++++++++++
 .../selftests/bpf/progs/preempt_lock.c        |  7 ++----
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h
index 93c5a6c446b3..8b9cc87be4c4 100644
--- a/tools/testing/selftests/bpf/bpf_experimental.h
+++ b/tools/testing/selftests/bpf/bpf_experimental.h
@@ -397,6 +397,28 @@ l_true:												\
 		     , [as]"i"((dst_as << 16) | src_as));
 #endif
 
+void bpf_preempt_disable(void) __weak __ksym;
+void bpf_preempt_enable(void) __weak __ksym;
+
+typedef struct {
+} __bpf_preempt_t;
+
+static inline __bpf_preempt_t __bpf_preempt_constructor(void)
+{
+	__bpf_preempt_t ret = {};
+
+	bpf_preempt_disable();
+	return ret;
+}
+static inline void __bpf_preempt_destructor(__bpf_preempt_t *t)
+{
+	bpf_preempt_enable();
+}
+#define bpf_guard_preempt() \
+	__bpf_preempt_t ___bpf_apply(preempt, __COUNTER__)			\
+	__attribute__((__unused__, __cleanup__(__bpf_preempt_destructor))) =	\
+	__bpf_preempt_constructor()
+
 /* Description
  *	Assert that a conditional expression is true.
  * Returns
diff --git a/tools/testing/selftests/bpf/progs/preempt_lock.c b/tools/testing/selftests/bpf/progs/preempt_lock.c
index 6c637ee01ec4..672fc368d9c4 100644
--- a/tools/testing/selftests/bpf/progs/preempt_lock.c
+++ b/tools/testing/selftests/bpf/progs/preempt_lock.c
@@ -3,9 +3,7 @@
 #include <bpf/bpf_helpers.h>
 #include <bpf/bpf_tracing.h>
 #include "bpf_misc.h"
-
-void bpf_preempt_disable(void) __ksym;
-void bpf_preempt_enable(void) __ksym;
+#include "bpf_experimental.h"
 
 SEC("?tc")
 __failure __msg("1 bpf_preempt_enable is missing")
@@ -92,8 +90,7 @@ static __noinline void preempt_balance_subprog(void)
 SEC("?tc")
 __success int preempt_balance(struct __sk_buff *ctx)
 {
-	bpf_preempt_disable();
-	bpf_preempt_enable();
+	bpf_guard_preempt();
 	return 0;
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next] bpf: Add bpf_guard_preempt() convenience macro
  2024-04-24 22:55 [PATCH bpf-next] bpf: Add bpf_guard_preempt() convenience macro Alexei Starovoitov
@ 2024-04-25 12:45 ` Kumar Kartikeya Dwivedi
  2024-04-25 18:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Kumar Kartikeya Dwivedi @ 2024-04-25 12:45 UTC (permalink / raw)
  To: Alexei Starovoitov; +Cc: bpf, daniel, andrii, martin.lau, eddyz87, kernel-team

On Thu, 25 Apr 2024 at 00:55, Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> From: Alexei Starovoitov <ast@kernel.org>
>
> Add bpf_guard_preempt() macro that uses newly introduced
> bpf_preempt_disable/enable() kfuncs to guard a critical section.
>
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
> ---

Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next] bpf: Add bpf_guard_preempt() convenience macro
  2024-04-24 22:55 [PATCH bpf-next] bpf: Add bpf_guard_preempt() convenience macro Alexei Starovoitov
  2024-04-25 12:45 ` Kumar Kartikeya Dwivedi
@ 2024-04-25 18:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-04-25 18:10 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: bpf, daniel, andrii, martin.lau, memxor, eddyz87, kernel-team

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Martin KaFai Lau <martin.lau@kernel.org>:

On Wed, 24 Apr 2024 15:55:29 -0700 you wrote:
> From: Alexei Starovoitov <ast@kernel.org>
> 
> Add bpf_guard_preempt() macro that uses newly introduced
> bpf_preempt_disable/enable() kfuncs to guard a critical section.
> 
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
> 
> [...]

Here is the summary with links:
  - [bpf-next] bpf: Add bpf_guard_preempt() convenience macro
    https://git.kernel.org/bpf/bpf-next/c/8ec3bf5c31d2

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-25 18:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-24 22:55 [PATCH bpf-next] bpf: Add bpf_guard_preempt() convenience macro Alexei Starovoitov
2024-04-25 12:45 ` Kumar Kartikeya Dwivedi
2024-04-25 18:10 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).