diff mbox series

[bpf] bpf, arm64: Fix BTI type used for freplace attached functions

Message ID 168926677665.316237.9953845318337455525.stgit@ahduyck-xeon-server.home.arpa (mailing list archive)
State Accepted
Delegated to: BPF
Headers show
Series [bpf] bpf, arm64: Fix BTI type used for freplace attached functions | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for bpf
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/cc_maintainers fail 5 blamed authors not CCed: jakub@cloudflare.com daniel@iogearbox.net xukuohai@huawei.com song@kernel.org jean-philippe@linaro.org; 17 maintainers not CCed: catalin.marinas@arm.com jakub@cloudflare.com daniel@iogearbox.net yhs@fb.com kpsingh@kernel.org martin.lau@linux.dev john.fastabend@gmail.com sdf@google.com zlim.lnx@gmail.com andrii@kernel.org xukuohai@huawei.com will@kernel.org song@kernel.org jolsa@kernel.org haoluo@google.com ast@kernel.org jean-philippe@linaro.org
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 14 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-VM_Test-3 success Logs for build for s390x with gcc
bpf/vmtest-bpf-VM_Test-9 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-25 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-29 success Logs for veristat
bpf/vmtest-bpf-VM_Test-7 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-10 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-11 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-13 success Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-15 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-17 success Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-18 success Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-19 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-20 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-21 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-22 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-23 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-24 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-27 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-28 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-14 success Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-26 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-VM_Test-12 success Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-VM_Test-16 success Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-PR success PR summary
bpf/vmtest-bpf-VM_Test-8 success Logs for test_maps on s390x with gcc
bpf/vmtest-bpf-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-VM_Test-5 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-6 success Logs for set-matrix
bpf/vmtest-bpf-VM_Test-2 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-VM_Test-4 success Logs for build for x86_64 with gcc

Commit Message

Alexander Duyck July 13, 2023, 4:49 p.m. UTC
From: Alexander Duyck <alexanderduyck@fb.com>

When running an freplace attached bpf program on an arm64 system w were
seeing the following issue:
  Unhandled 64-bit el1h sync exception on CPU47, ESR 0x0000000036000003 -- BTI

After a bit of work to track it down I determined that what appeared to be
happening is that the 'bti c' at the start of the program was somehow being
reached after a 'br' instruction. Further digging pointed me toward the
fact that the function was attached via freplace. This in turn led me to
build_plt which I believe is invoking the long jump which is triggering
this error.

To resolve it we can replace the 'bti c' with 'bti jc' and add a comment
explaining why this has to be modified as such.

Fixes: b2ad54e1533e ("bpf, arm64: Implement bpf_arch_text_poke() for arm64")
Signed-off-by: Alexander Duyck <alexanderduyck@fb.com>
---
 arch/arm64/net/bpf_jit_comp.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Xu Kuohai July 15, 2023, 9:03 a.m. UTC | #1
On 7/14/2023 12:49 AM, Alexander Duyck wrote:
> From: Alexander Duyck <alexanderduyck@fb.com>
> 
> When running an freplace attached bpf program on an arm64 system w were
> seeing the following issue:
>    Unhandled 64-bit el1h sync exception on CPU47, ESR 0x0000000036000003 -- BTI
> 
> After a bit of work to track it down I determined that what appeared to be
> happening is that the 'bti c' at the start of the program was somehow being
> reached after a 'br' instruction. Further digging pointed me toward the
> fact that the function was attached via freplace. This in turn led me to
> build_plt which I believe is invoking the long jump which is triggering
> this error.
> 
> To resolve it we can replace the 'bti c' with 'bti jc' and add a comment
> explaining why this has to be modified as such.
> 
> Fixes: b2ad54e1533e ("bpf, arm64: Implement bpf_arch_text_poke() for arm64")
> Signed-off-by: Alexander Duyck <alexanderduyck@fb.com>
> ---
>   arch/arm64/net/bpf_jit_comp.c |    8 +++++++-
>   1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
> index 145b540ec34f..ec2174838f2a 100644
> --- a/arch/arm64/net/bpf_jit_comp.c
> +++ b/arch/arm64/net/bpf_jit_comp.c
> @@ -322,7 +322,13 @@ static int build_prologue(struct jit_ctx *ctx, bool ebpf_from_cbpf)
>   	 *
>   	 */
>   
> -	emit_bti(A64_BTI_C, ctx);
> +	/* bpf function may be invoked by 3 instruction types:
> +	 * 1. bl, attached via freplace to bpf prog via short jump
> +	 * 2. br, attached via freplace to bpf prog via long jump
> +	 * 3. blr, working as a function pointer, used by emit_call.
> +	 * So BTI_JC should used here to support both br and blr.
> +	 */
> +	emit_bti(A64_BTI_JC, ctx);

LGTM. Thanks for the fixes.

Acked-by: Xu Kuohai <xukuohai@huawei.com>

>   
>   	emit(A64_MOV(1, A64_R(9), A64_LR), ctx);
>   	emit(A64_NOP, ctx);
> 
>
Alexei Starovoitov July 18, 2023, 10:28 p.m. UTC | #2
On Sat, Jul 15, 2023 at 2:03 AM Xu Kuohai <xukuohai@huaweicloud.com> wrote:
>
> On 7/14/2023 12:49 AM, Alexander Duyck wrote:
> > From: Alexander Duyck <alexanderduyck@fb.com>
> >
> > When running an freplace attached bpf program on an arm64 system w were
> > seeing the following issue:
> >    Unhandled 64-bit el1h sync exception on CPU47, ESR 0x0000000036000003 -- BTI
> >
> > After a bit of work to track it down I determined that what appeared to be
> > happening is that the 'bti c' at the start of the program was somehow being
> > reached after a 'br' instruction. Further digging pointed me toward the
> > fact that the function was attached via freplace. This in turn led me to
> > build_plt which I believe is invoking the long jump which is triggering
> > this error.
> >
> > To resolve it we can replace the 'bti c' with 'bti jc' and add a comment
> > explaining why this has to be modified as such.
> >
> > Fixes: b2ad54e1533e ("bpf, arm64: Implement bpf_arch_text_poke() for arm64")
> > Signed-off-by: Alexander Duyck <alexanderduyck@fb.com>
> > ---
> >   arch/arm64/net/bpf_jit_comp.c |    8 +++++++-
> >   1 file changed, 7 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
> > index 145b540ec34f..ec2174838f2a 100644
> > --- a/arch/arm64/net/bpf_jit_comp.c
> > +++ b/arch/arm64/net/bpf_jit_comp.c
> > @@ -322,7 +322,13 @@ static int build_prologue(struct jit_ctx *ctx, bool ebpf_from_cbpf)
> >        *
> >        */
> >
> > -     emit_bti(A64_BTI_C, ctx);
> > +     /* bpf function may be invoked by 3 instruction types:
> > +      * 1. bl, attached via freplace to bpf prog via short jump
> > +      * 2. br, attached via freplace to bpf prog via long jump
> > +      * 3. blr, working as a function pointer, used by emit_call.
> > +      * So BTI_JC should used here to support both br and blr.
> > +      */
> > +     emit_bti(A64_BTI_JC, ctx);
>
> LGTM. Thanks for the fixes.
>
> Acked-by: Xu Kuohai <xukuohai@huawei.com>

Applied. Thanks
diff mbox series

Patch

diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index 145b540ec34f..ec2174838f2a 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -322,7 +322,13 @@  static int build_prologue(struct jit_ctx *ctx, bool ebpf_from_cbpf)
 	 *
 	 */
 
-	emit_bti(A64_BTI_C, ctx);
+	/* bpf function may be invoked by 3 instruction types:
+	 * 1. bl, attached via freplace to bpf prog via short jump
+	 * 2. br, attached via freplace to bpf prog via long jump
+	 * 3. blr, working as a function pointer, used by emit_call.
+	 * So BTI_JC should used here to support both br and blr.
+	 */
+	emit_bti(A64_BTI_JC, ctx);
 
 	emit(A64_MOV(1, A64_R(9), A64_LR), ctx);
 	emit(A64_NOP, ctx);