BPF Archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/2] Fix incorrect bpf runtime stats for arm64 and riscv64
@ 2024-04-16  6:42 Xu Kuohai
  2024-04-16  6:42 ` [PATCH bpf-next 1/2] bpf, arm64: Fix incorrect runtime stats Xu Kuohai
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Xu Kuohai @ 2024-04-16  6:42 UTC (permalink / raw
  To: bpf, linux-arm-kernel, linux-riscv
  Cc: Ivan Babrou, Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
	Björn Töpel, Pu Lehui

From: Xu Kuohai <xukuohai@huawei.com>

Fix incorrect bpf runtime stats for arm64 and riscv64.

Xu Kuohai (2):
  bpf, arm64: Fix incorrect runtime stats
  riscv, bpf: Fix incorrect runtime stats

 arch/arm64/net/bpf_jit_comp.c   | 6 +++---
 arch/riscv/net/bpf_jit_comp64.c | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

-- 
2.40.1


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

* [PATCH bpf-next 1/2] bpf, arm64: Fix incorrect runtime stats
  2024-04-16  6:42 [PATCH bpf-next 0/2] Fix incorrect bpf runtime stats for arm64 and riscv64 Xu Kuohai
@ 2024-04-16  6:42 ` Xu Kuohai
  2024-04-16  6:42 ` [PATCH bpf-next 2/2] riscv, bpf: " Xu Kuohai
  2024-04-16 15:30 ` [PATCH bpf-next 0/2] Fix incorrect bpf runtime stats for arm64 and riscv64 patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: Xu Kuohai @ 2024-04-16  6:42 UTC (permalink / raw
  To: bpf, linux-arm-kernel, linux-riscv
  Cc: Ivan Babrou, Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
	Björn Töpel, Pu Lehui

From: Xu Kuohai <xukuohai@huawei.com>

When __bpf_prog_enter() returns zero, the arm64 register x20 that stores
prog start time is not assigned to zero, causing incorrect runtime stats.

To fix it, assign the return value of bpf_prog_enter() to x20 register
immediately upon its return.

Fixes: efc9909fdce0 ("bpf, arm64: Add bpf trampoline for arm64")
Reported-by: Ivan Babrou <ivan@cloudflare.com>
Tested-by: Ivan Babrou <ivan@cloudflare.com>
Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
---
 arch/arm64/net/bpf_jit_comp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index 76b91f36c729..cf9a9ebb4cda 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -1905,15 +1905,15 @@ static void invoke_bpf_prog(struct jit_ctx *ctx, struct bpf_tramp_link *l,
 
 	emit_call(enter_prog, ctx);
 
+	/* save return value to callee saved register x20 */
+	emit(A64_MOV(1, A64_R(20), A64_R(0)), ctx);
+
 	/* if (__bpf_prog_enter(prog) == 0)
 	 *         goto skip_exec_of_prog;
 	 */
 	branch = ctx->image + ctx->idx;
 	emit(A64_NOP, ctx);
 
-	/* save return value to callee saved register x20 */
-	emit(A64_MOV(1, A64_R(20), A64_R(0)), ctx);
-
 	emit(A64_ADD_I(1, A64_R(0), A64_SP, args_off), ctx);
 	if (!p->jited)
 		emit_addr_mov_i64(A64_R(1), (const u64)p->insnsi, ctx);
-- 
2.40.1


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

* [PATCH bpf-next 2/2] riscv, bpf: Fix incorrect runtime stats
  2024-04-16  6:42 [PATCH bpf-next 0/2] Fix incorrect bpf runtime stats for arm64 and riscv64 Xu Kuohai
  2024-04-16  6:42 ` [PATCH bpf-next 1/2] bpf, arm64: Fix incorrect runtime stats Xu Kuohai
@ 2024-04-16  6:42 ` Xu Kuohai
  2024-04-16  9:35   ` Pu Lehui
  2024-04-16 15:30 ` [PATCH bpf-next 0/2] Fix incorrect bpf runtime stats for arm64 and riscv64 patchwork-bot+netdevbpf
  2 siblings, 1 reply; 6+ messages in thread
From: Xu Kuohai @ 2024-04-16  6:42 UTC (permalink / raw
  To: bpf, linux-arm-kernel, linux-riscv
  Cc: Ivan Babrou, Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
	Björn Töpel, Pu Lehui

From: Xu Kuohai <xukuohai@huawei.com>

When __bpf_prog_enter() returns zero, the s1 register is not set to zero,
resulting in incorrect runtime stats. Fix it by setting s1 immediately upon
the return of __bpf_prog_enter().

Fixes: 49b5e77ae3e2 ("riscv, bpf: Add bpf trampoline support for RV64")
Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
---
 arch/riscv/net/bpf_jit_comp64.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
index 15e482f2c657..e713704be837 100644
--- a/arch/riscv/net/bpf_jit_comp64.c
+++ b/arch/riscv/net/bpf_jit_comp64.c
@@ -730,6 +730,9 @@ static int invoke_bpf_prog(struct bpf_tramp_link *l, int args_off, int retval_of
 	if (ret)
 		return ret;
 
+	/* store prog start time */
+	emit_mv(RV_REG_S1, RV_REG_A0, ctx);
+
 	/* if (__bpf_prog_enter(prog) == 0)
 	 *	goto skip_exec_of_prog;
 	 */
@@ -737,9 +740,6 @@ static int invoke_bpf_prog(struct bpf_tramp_link *l, int args_off, int retval_of
 	/* nop reserved for conditional jump */
 	emit(rv_nop(), ctx);
 
-	/* store prog start time */
-	emit_mv(RV_REG_S1, RV_REG_A0, ctx);
-
 	/* arg1: &args_off */
 	emit_addi(RV_REG_A0, RV_REG_FP, -args_off, ctx);
 	if (!p->jited)
-- 
2.40.1


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

* Re: [PATCH bpf-next 2/2] riscv, bpf: Fix incorrect runtime stats
  2024-04-16  6:42 ` [PATCH bpf-next 2/2] riscv, bpf: " Xu Kuohai
@ 2024-04-16  9:35   ` Pu Lehui
  2024-04-16 14:09     ` Björn Töpel
  0 siblings, 1 reply; 6+ messages in thread
From: Pu Lehui @ 2024-04-16  9:35 UTC (permalink / raw
  To: Xu Kuohai, bpf, linux-arm-kernel, linux-riscv
  Cc: Ivan Babrou, Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
	Björn Töpel


On 2024/4/16 14:42, Xu Kuohai wrote:
> From: Xu Kuohai <xukuohai@huawei.com>
> 
> When __bpf_prog_enter() returns zero, the s1 register is not set to zero,
> resulting in incorrect runtime stats. Fix it by setting s1 immediately upon
> the return of __bpf_prog_enter().
> 
> Fixes: 49b5e77ae3e2 ("riscv, bpf: Add bpf trampoline support for RV64")
> Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
> ---
>   arch/riscv/net/bpf_jit_comp64.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
> index 15e482f2c657..e713704be837 100644
> --- a/arch/riscv/net/bpf_jit_comp64.c
> +++ b/arch/riscv/net/bpf_jit_comp64.c
> @@ -730,6 +730,9 @@ static int invoke_bpf_prog(struct bpf_tramp_link *l, int args_off, int retval_of
>   	if (ret)
>   		return ret;
>   
> +	/* store prog start time */
> +	emit_mv(RV_REG_S1, RV_REG_A0, ctx);
> +
>   	/* if (__bpf_prog_enter(prog) == 0)
>   	 *	goto skip_exec_of_prog;
>   	 */
> @@ -737,9 +740,6 @@ static int invoke_bpf_prog(struct bpf_tramp_link *l, int args_off, int retval_of
>   	/* nop reserved for conditional jump */
>   	emit(rv_nop(), ctx);
>   
> -	/* store prog start time */
> -	emit_mv(RV_REG_S1, RV_REG_A0, ctx);
> -
>   	/* arg1: &args_off */
>   	emit_addi(RV_REG_A0, RV_REG_FP, -args_off, ctx);
>   	if (!p->jited)

Thanks.

Reviewed-by: Pu Lehui <pulehui@huawei.com>


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

* Re: [PATCH bpf-next 2/2] riscv, bpf: Fix incorrect runtime stats
  2024-04-16  9:35   ` Pu Lehui
@ 2024-04-16 14:09     ` Björn Töpel
  0 siblings, 0 replies; 6+ messages in thread
From: Björn Töpel @ 2024-04-16 14:09 UTC (permalink / raw
  To: Pu Lehui, Xu Kuohai, bpf, linux-arm-kernel, linux-riscv
  Cc: Ivan Babrou, Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann

Pu Lehui <pulehui@huawei.com> writes:

> On 2024/4/16 14:42, Xu Kuohai wrote:
>> From: Xu Kuohai <xukuohai@huawei.com>
>> 
>> When __bpf_prog_enter() returns zero, the s1 register is not set to zero,
>> resulting in incorrect runtime stats. Fix it by setting s1 immediately upon
>> the return of __bpf_prog_enter().
>> 
>> Fixes: 49b5e77ae3e2 ("riscv, bpf: Add bpf trampoline support for RV64")
>> Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
>> ---
>>   arch/riscv/net/bpf_jit_comp64.c | 6 +++---
>>   1 file changed, 3 insertions(+), 3 deletions(-)
>> 
>> diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
>> index 15e482f2c657..e713704be837 100644
>> --- a/arch/riscv/net/bpf_jit_comp64.c
>> +++ b/arch/riscv/net/bpf_jit_comp64.c
>> @@ -730,6 +730,9 @@ static int invoke_bpf_prog(struct bpf_tramp_link *l, int args_off, int retval_of
>>   	if (ret)
>>   		return ret;
>>   
>> +	/* store prog start time */
>> +	emit_mv(RV_REG_S1, RV_REG_A0, ctx);
>> +
>>   	/* if (__bpf_prog_enter(prog) == 0)
>>   	 *	goto skip_exec_of_prog;
>>   	 */
>> @@ -737,9 +740,6 @@ static int invoke_bpf_prog(struct bpf_tramp_link *l, int args_off, int retval_of
>>   	/* nop reserved for conditional jump */
>>   	emit(rv_nop(), ctx);
>>   
>> -	/* store prog start time */
>> -	emit_mv(RV_REG_S1, RV_REG_A0, ctx);
>> -
>>   	/* arg1: &args_off */
>>   	emit_addi(RV_REG_A0, RV_REG_FP, -args_off, ctx);
>>   	if (!p->jited)
>
> Thanks.
>
> Reviewed-by: Pu Lehui <pulehui@huawei.com>

Acked-by: Björn Töpel <bjorn@kernel.org>

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

* Re: [PATCH bpf-next 0/2] Fix incorrect bpf runtime stats for arm64 and riscv64
  2024-04-16  6:42 [PATCH bpf-next 0/2] Fix incorrect bpf runtime stats for arm64 and riscv64 Xu Kuohai
  2024-04-16  6:42 ` [PATCH bpf-next 1/2] bpf, arm64: Fix incorrect runtime stats Xu Kuohai
  2024-04-16  6:42 ` [PATCH bpf-next 2/2] riscv, bpf: " Xu Kuohai
@ 2024-04-16 15:30 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-04-16 15:30 UTC (permalink / raw
  To: Xu Kuohai
  Cc: bpf, linux-arm-kernel, linux-riscv, ivan, ast, andrii, daniel,
	bjorn, pulehui

Hello:

This series was applied to bpf/bpf.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

On Tue, 16 Apr 2024 14:42:06 +0800 you wrote:
> From: Xu Kuohai <xukuohai@huawei.com>
> 
> Fix incorrect bpf runtime stats for arm64 and riscv64.
> 
> Xu Kuohai (2):
>   bpf, arm64: Fix incorrect runtime stats
>   riscv, bpf: Fix incorrect runtime stats
> 
> [...]

Here is the summary with links:
  - [bpf-next,1/2] bpf, arm64: Fix incorrect runtime stats
    https://git.kernel.org/bpf/bpf/c/dc7d7447b56b
  - [bpf-next,2/2] riscv, bpf: Fix incorrect runtime stats
    https://git.kernel.org/bpf/bpf/c/10541b374aa0

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] 6+ messages in thread

end of thread, other threads:[~2024-04-16 15:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-16  6:42 [PATCH bpf-next 0/2] Fix incorrect bpf runtime stats for arm64 and riscv64 Xu Kuohai
2024-04-16  6:42 ` [PATCH bpf-next 1/2] bpf, arm64: Fix incorrect runtime stats Xu Kuohai
2024-04-16  6:42 ` [PATCH bpf-next 2/2] riscv, bpf: " Xu Kuohai
2024-04-16  9:35   ` Pu Lehui
2024-04-16 14:09     ` Björn Töpel
2024-04-16 15:30 ` [PATCH bpf-next 0/2] Fix incorrect bpf runtime stats for arm64 and riscv64 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 read-only IMAP folder(s) and NNTP newsgroup(s).