diff mbox series

[bpf-next,2/2] riscv, bpf: Fix incorrect runtime stats

Message ID 20240416064208.2919073-3-xukuohai@huaweicloud.com (mailing list archive)
State Handled Elsewhere
Headers show
Series Fix incorrect bpf runtime stats for arm64 and riscv64 | expand

Checks

Context Check Description
conchuod/vmtest-for-next-PR success PR summary
conchuod/patch-2-test-1 success .github/scripts/patches/tests/build_rv32_defconfig.sh
conchuod/patch-2-test-2 success .github/scripts/patches/tests/build_rv64_clang_allmodconfig.sh
conchuod/patch-2-test-3 success .github/scripts/patches/tests/build_rv64_gcc_allmodconfig.sh
conchuod/patch-2-test-4 success .github/scripts/patches/tests/build_rv64_nommu_k210_defconfig.sh
conchuod/patch-2-test-5 success .github/scripts/patches/tests/build_rv64_nommu_virt_defconfig.sh
conchuod/patch-2-test-6 success .github/scripts/patches/tests/checkpatch.sh
conchuod/patch-2-test-7 success .github/scripts/patches/tests/dtb_warn_rv64.sh
conchuod/patch-2-test-8 success .github/scripts/patches/tests/header_inline.sh
conchuod/patch-2-test-9 success .github/scripts/patches/tests/kdoc.sh
conchuod/patch-2-test-10 success .github/scripts/patches/tests/module_param.sh
conchuod/patch-2-test-11 success .github/scripts/patches/tests/verify_fixes.sh
conchuod/patch-2-test-12 success .github/scripts/patches/tests/verify_signedoff.sh

Commit Message

Xu Kuohai April 16, 2024, 6:42 a.m. UTC
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(-)

Comments

Pu Lehui April 16, 2024, 9:35 a.m. UTC | #1
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>
Björn Töpel April 16, 2024, 2:09 p.m. UTC | #2
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>
diff mbox series

Patch

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)