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 New, archived
Headers show
Series Fix incorrect bpf runtime stats for arm64 and riscv64 | expand

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)