* [PATCH bpf-next v2] bpf, mips: No need to use min() to get MAX_TAIL_CALL_CNT
@ 2022-08-29 3:05 Tiezhu Yang
2022-08-29 14:00 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Tiezhu Yang @ 2022-08-29 3:05 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Johan Almbladh, Paul Burton, Thomas Bogendoerfer
Cc: bpf, linux-mips
MAX_TAIL_CALL_CNT is 33, so min(MAX_TAIL_CALL_CNT, 0xffff) is always
MAX_TAIL_CALL_CNT, it is better to use MAX_TAIL_CALL_CNT directly.
At the same time, add BUILD_BUG_ON(MAX_TAIL_CALL_CNT > 0xffff) with a
comment on why the assertion is there.
Suggested-by: Daniel Borkmann <daniel@iogearbox.net>
Suggested-by: Johan Almbladh <johan.almbladh@anyfinetworks.com>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
v2: Add BUILD_BUG_ON(MAX_TAIL_CALL_CNT > 0xffff) with a comment
suggested by Daniel and Johan, thank you.
arch/mips/net/bpf_jit_comp32.c | 10 +++++++++-
arch/mips/net/bpf_jit_comp64.c | 10 +++++++++-
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/arch/mips/net/bpf_jit_comp32.c b/arch/mips/net/bpf_jit_comp32.c
index 83c975d..ace5db3 100644
--- a/arch/mips/net/bpf_jit_comp32.c
+++ b/arch/mips/net/bpf_jit_comp32.c
@@ -1377,11 +1377,19 @@ void build_prologue(struct jit_context *ctx)
int stack, saved, locals, reserved;
/*
+ * In the unlikely event that the TCC limit is raised to more
+ * than 16 bits, it is clamped to the maximum value allowed for
+ * the generated code (0xffff). It is better fail to compile
+ * instead of degrading gracefully.
+ */
+ BUILD_BUG_ON(MAX_TAIL_CALL_CNT > 0xffff);
+
+ /*
* The first two instructions initialize TCC in the reserved (for us)
* 16-byte area in the parent's stack frame. On a tail call, the
* calling function jumps into the prologue after these instructions.
*/
- emit(ctx, ori, MIPS_R_T9, MIPS_R_ZERO, min(MAX_TAIL_CALL_CNT, 0xffff));
+ emit(ctx, ori, MIPS_R_T9, MIPS_R_ZERO, MAX_TAIL_CALL_CNT);
emit(ctx, sw, MIPS_R_T9, 0, MIPS_R_SP);
/*
diff --git a/arch/mips/net/bpf_jit_comp64.c b/arch/mips/net/bpf_jit_comp64.c
index 6475828..0e7c1bd 100644
--- a/arch/mips/net/bpf_jit_comp64.c
+++ b/arch/mips/net/bpf_jit_comp64.c
@@ -548,11 +548,19 @@ void build_prologue(struct jit_context *ctx)
int stack, saved, locals, reserved;
/*
+ * In the unlikely event that the TCC limit is raised to more
+ * than 16 bits, it is clamped to the maximum value allowed for
+ * the generated code (0xffff). It is better fail to compile
+ * instead of degrading gracefully.
+ */
+ BUILD_BUG_ON(MAX_TAIL_CALL_CNT > 0xffff);
+
+ /*
* The first instruction initializes the tail call count register.
* On a tail call, the calling function jumps into the prologue
* after this instruction.
*/
- emit(ctx, ori, tc, MIPS_R_ZERO, min(MAX_TAIL_CALL_CNT, 0xffff));
+ emit(ctx, ori, tc, MIPS_R_ZERO, MAX_TAIL_CALL_CNT);
/* === Entry-point for tail calls === */
--
2.1.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH bpf-next v2] bpf, mips: No need to use min() to get MAX_TAIL_CALL_CNT
2022-08-29 3:05 [PATCH bpf-next v2] bpf, mips: No need to use min() to get MAX_TAIL_CALL_CNT Tiezhu Yang
@ 2022-08-29 14:00 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-08-29 14:00 UTC (permalink / raw)
To: Tiezhu Yang
Cc: ast, daniel, andrii, johan.almbladh, paulburton, tsbogend, bpf,
linux-mips
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:
On Mon, 29 Aug 2022 11:05:09 +0800 you wrote:
> MAX_TAIL_CALL_CNT is 33, so min(MAX_TAIL_CALL_CNT, 0xffff) is always
> MAX_TAIL_CALL_CNT, it is better to use MAX_TAIL_CALL_CNT directly.
>
> At the same time, add BUILD_BUG_ON(MAX_TAIL_CALL_CNT > 0xffff) with a
> comment on why the assertion is there.
>
> Suggested-by: Daniel Borkmann <daniel@iogearbox.net>
> Suggested-by: Johan Almbladh <johan.almbladh@anyfinetworks.com>
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
>
> [...]
Here is the summary with links:
- [bpf-next,v2] bpf, mips: No need to use min() to get MAX_TAIL_CALL_CNT
https://git.kernel.org/bpf/bpf-next/c/bbcf0f55e578
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] 2+ messages in thread
end of thread, other threads:[~2022-08-29 14:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-29 3:05 [PATCH bpf-next v2] bpf, mips: No need to use min() to get MAX_TAIL_CALL_CNT Tiezhu Yang
2022-08-29 14:00 ` 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).