From: Song Liu <song@kernel.org> To: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> Cc: Michael Ellerman <mpe@ellerman.id.au>, Nicholas Piggin <npiggin@gmail.com>, Daniel Borkmann <daniel@iogearbox.net>, Alexei Starovoitov <alexei.starovoitov@gmail.com>, Christophe Leroy <christophe.leroy@csgroup.eu>, Johan Almbladh <johan.almbladh@anyfinetworks.com>, bpf <bpf@vger.kernel.org>, linuxppc-dev@lists.ozlabs.org Subject: Re: [PATCH 1/9] powerpc/lib: Add helper to check if offset is within conditional branch range Date: Fri, 1 Oct 2021 14:37:33 -0700 [thread overview] Message-ID: <CAPhsuW4Qv5e=x6WMV1EYy+NUdu+i+i+kGY2E3WAhV66a115C=Q@mail.gmail.com> (raw) In-Reply-To: <f8d581e6a5d9555180c38e009f90d236f310f85e.1633104510.git.naveen.n.rao@linux.vnet.ibm.com> On Fri, Oct 1, 2021 at 2:16 PM Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com> wrote: > > Add a helper to check if a given offset is within the branch range for a > powerpc conditional branch instruction, and update some sites to use the > new helper. > > Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com> Acked-by: Song Liu <songliubraving@fb.com> With one nitpick: > --- > arch/powerpc/include/asm/code-patching.h | 1 + > arch/powerpc/lib/code-patching.c | 7 ++++++- > arch/powerpc/net/bpf_jit.h | 7 +------ > 3 files changed, 8 insertions(+), 7 deletions(-) > > diff --git a/arch/powerpc/include/asm/code-patching.h b/arch/powerpc/include/asm/code-patching.h > index a95f63788c6b14..4ba834599c4d4c 100644 > --- a/arch/powerpc/include/asm/code-patching.h > +++ b/arch/powerpc/include/asm/code-patching.h > @@ -23,6 +23,7 @@ > #define BRANCH_ABSOLUTE 0x2 > > bool is_offset_in_branch_range(long offset); > +bool is_offset_in_cond_branch_range(long offset); > int create_branch(struct ppc_inst *instr, const u32 *addr, > unsigned long target, int flags); > int create_cond_branch(struct ppc_inst *instr, const u32 *addr, > diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c > index f9a3019e37b43c..e2342b9a1ab9c9 100644 > --- a/arch/powerpc/lib/code-patching.c > +++ b/arch/powerpc/lib/code-patching.c > @@ -228,6 +228,11 @@ bool is_offset_in_branch_range(long offset) > return (offset >= -0x2000000 && offset <= 0x1fffffc && !(offset & 0x3)); > } > > +bool is_offset_in_cond_branch_range(long offset) > +{ > + return offset >= -0x8000 && offset <= 0x7FFF && !(offset & 0x3); > +} Why not inline this one? > + > /* > * Helper to check if a given instruction is a conditional branch > * Derived from the conditional checks in analyse_instr() > @@ -280,7 +285,7 @@ int create_cond_branch(struct ppc_inst *instr, const u32 *addr, > offset = offset - (unsigned long)addr; > > /* Check we can represent the target in the instruction format */ > - if (offset < -0x8000 || offset > 0x7FFF || offset & 0x3) > + if (!is_offset_in_cond_branch_range(offset)) > return 1; > > /* Mask out the flags and target, so they don't step on each other. */ > diff --git a/arch/powerpc/net/bpf_jit.h b/arch/powerpc/net/bpf_jit.h > index 99fad093f43ec1..935ea95b66359e 100644 > --- a/arch/powerpc/net/bpf_jit.h > +++ b/arch/powerpc/net/bpf_jit.h > @@ -78,11 +78,6 @@ > #define PPC_FUNC_ADDR(d,i) do { PPC_LI32(d, i); } while(0) > #endif > > -static inline bool is_nearbranch(int offset) > -{ > - return (offset < 32768) && (offset >= -32768); > -} > - > /* > * The fly in the ointment of code size changing from pass to pass is > * avoided by padding the short branch case with a NOP. If code size differs > @@ -91,7 +86,7 @@ static inline bool is_nearbranch(int offset) > * state. > */ > #define PPC_BCC(cond, dest) do { \ > - if (is_nearbranch((dest) - (ctx->idx * 4))) { \ > + if (is_offset_in_cond_branch_range((long)(dest) - (ctx->idx * 4))) { \ > PPC_BCC_SHORT(cond, dest); \ > EMIT(PPC_RAW_NOP()); \ > } else { \ > -- > 2.33.0 >
WARNING: multiple messages have this Message-ID (diff)
From: Song Liu <song@kernel.org> To: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> Cc: Daniel Borkmann <daniel@iogearbox.net>, Johan Almbladh <johan.almbladh@anyfinetworks.com>, Nicholas Piggin <npiggin@gmail.com>, bpf <bpf@vger.kernel.org>, linuxppc-dev@lists.ozlabs.org, Alexei Starovoitov <alexei.starovoitov@gmail.com> Subject: Re: [PATCH 1/9] powerpc/lib: Add helper to check if offset is within conditional branch range Date: Fri, 1 Oct 2021 14:37:33 -0700 [thread overview] Message-ID: <CAPhsuW4Qv5e=x6WMV1EYy+NUdu+i+i+kGY2E3WAhV66a115C=Q@mail.gmail.com> (raw) In-Reply-To: <f8d581e6a5d9555180c38e009f90d236f310f85e.1633104510.git.naveen.n.rao@linux.vnet.ibm.com> On Fri, Oct 1, 2021 at 2:16 PM Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com> wrote: > > Add a helper to check if a given offset is within the branch range for a > powerpc conditional branch instruction, and update some sites to use the > new helper. > > Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com> Acked-by: Song Liu <songliubraving@fb.com> With one nitpick: > --- > arch/powerpc/include/asm/code-patching.h | 1 + > arch/powerpc/lib/code-patching.c | 7 ++++++- > arch/powerpc/net/bpf_jit.h | 7 +------ > 3 files changed, 8 insertions(+), 7 deletions(-) > > diff --git a/arch/powerpc/include/asm/code-patching.h b/arch/powerpc/include/asm/code-patching.h > index a95f63788c6b14..4ba834599c4d4c 100644 > --- a/arch/powerpc/include/asm/code-patching.h > +++ b/arch/powerpc/include/asm/code-patching.h > @@ -23,6 +23,7 @@ > #define BRANCH_ABSOLUTE 0x2 > > bool is_offset_in_branch_range(long offset); > +bool is_offset_in_cond_branch_range(long offset); > int create_branch(struct ppc_inst *instr, const u32 *addr, > unsigned long target, int flags); > int create_cond_branch(struct ppc_inst *instr, const u32 *addr, > diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c > index f9a3019e37b43c..e2342b9a1ab9c9 100644 > --- a/arch/powerpc/lib/code-patching.c > +++ b/arch/powerpc/lib/code-patching.c > @@ -228,6 +228,11 @@ bool is_offset_in_branch_range(long offset) > return (offset >= -0x2000000 && offset <= 0x1fffffc && !(offset & 0x3)); > } > > +bool is_offset_in_cond_branch_range(long offset) > +{ > + return offset >= -0x8000 && offset <= 0x7FFF && !(offset & 0x3); > +} Why not inline this one? > + > /* > * Helper to check if a given instruction is a conditional branch > * Derived from the conditional checks in analyse_instr() > @@ -280,7 +285,7 @@ int create_cond_branch(struct ppc_inst *instr, const u32 *addr, > offset = offset - (unsigned long)addr; > > /* Check we can represent the target in the instruction format */ > - if (offset < -0x8000 || offset > 0x7FFF || offset & 0x3) > + if (!is_offset_in_cond_branch_range(offset)) > return 1; > > /* Mask out the flags and target, so they don't step on each other. */ > diff --git a/arch/powerpc/net/bpf_jit.h b/arch/powerpc/net/bpf_jit.h > index 99fad093f43ec1..935ea95b66359e 100644 > --- a/arch/powerpc/net/bpf_jit.h > +++ b/arch/powerpc/net/bpf_jit.h > @@ -78,11 +78,6 @@ > #define PPC_FUNC_ADDR(d,i) do { PPC_LI32(d, i); } while(0) > #endif > > -static inline bool is_nearbranch(int offset) > -{ > - return (offset < 32768) && (offset >= -32768); > -} > - > /* > * The fly in the ointment of code size changing from pass to pass is > * avoided by padding the short branch case with a NOP. If code size differs > @@ -91,7 +86,7 @@ static inline bool is_nearbranch(int offset) > * state. > */ > #define PPC_BCC(cond, dest) do { \ > - if (is_nearbranch((dest) - (ctx->idx * 4))) { \ > + if (is_offset_in_cond_branch_range((long)(dest) - (ctx->idx * 4))) { \ > PPC_BCC_SHORT(cond, dest); \ > EMIT(PPC_RAW_NOP()); \ > } else { \ > -- > 2.33.0 >
next prev parent reply other threads:[~2021-10-01 21:37 UTC|newest] Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-10-01 21:14 [PATCH 0/9] powerpc/bpf: Various fixes Naveen N. Rao 2021-10-01 21:14 ` Naveen N. Rao 2021-10-01 21:14 ` [PATCH 1/9] powerpc/lib: Add helper to check if offset is within conditional branch range Naveen N. Rao 2021-10-01 21:14 ` Naveen N. Rao 2021-10-01 21:37 ` Song Liu [this message] 2021-10-01 21:37 ` Song Liu 2021-10-04 18:02 ` Naveen N. Rao 2021-10-04 18:02 ` Naveen N. Rao 2021-10-03 7:50 ` Christophe Leroy 2021-10-04 18:03 ` Naveen N. Rao 2021-10-01 21:14 ` [PATCH 2/9] powerpc/bpf: Validate branch ranges Naveen N. Rao 2021-10-01 21:14 ` Naveen N. Rao 2021-10-01 21:45 ` Song Liu 2021-10-01 21:45 ` Song Liu 2021-10-02 17:29 ` Johan Almbladh 2021-10-02 17:29 ` Johan Almbladh 2021-10-03 7:54 ` Christophe Leroy 2021-10-04 18:11 ` Naveen N. Rao 2021-10-01 21:14 ` [PATCH 3/9] powerpc/bpf: Remove unused SEEN_STACK Naveen N. Rao 2021-10-01 21:14 ` Naveen N. Rao 2021-10-01 21:47 ` Song Liu 2021-10-01 21:47 ` Song Liu 2021-10-02 17:30 ` Johan Almbladh 2021-10-02 17:30 ` Johan Almbladh 2021-10-03 7:55 ` Christophe Leroy 2021-10-04 18:11 ` Naveen N. Rao 2021-10-05 5:50 ` Christophe Leroy 2021-10-05 20:22 ` Naveen N. Rao 2021-10-01 21:14 ` [PATCH 4/9] powerpc/bpf: Handle large branch ranges with BPF_EXIT Naveen N. Rao 2021-10-01 21:14 ` Naveen N. Rao 2021-10-01 21:53 ` Song Liu 2021-10-01 21:53 ` Song Liu 2021-10-02 17:31 ` Johan Almbladh 2021-10-02 17:31 ` Johan Almbladh 2021-10-03 7:59 ` Christophe Leroy 2021-10-04 18:24 ` Naveen N. Rao 2021-10-05 5:46 ` Christophe Leroy 2022-01-07 11:46 ` Naveen N. Rao 2021-10-01 21:14 ` [PATCH 5/9] powerpc/bpf: Fix BPF_MOD when imm == 1 Naveen N. Rao 2021-10-01 21:14 ` Naveen N. Rao 2021-10-01 21:55 ` Song Liu 2021-10-01 21:55 ` Song Liu 2021-10-02 17:32 ` Johan Almbladh 2021-10-02 17:32 ` Johan Almbladh 2021-10-01 21:14 ` [PATCH 6/9] powerpc/bpf: Fix BPF_SUB when imm == 0x80000000 Naveen N. Rao 2021-10-01 21:14 ` Naveen N. Rao 2021-10-01 22:01 ` Song Liu 2021-10-01 22:01 ` Song Liu 2021-10-02 17:33 ` Johan Almbladh 2021-10-02 17:33 ` Johan Almbladh 2021-10-03 8:07 ` Christophe Leroy 2021-10-04 18:18 ` Naveen N. Rao 2021-10-05 5:40 ` Christophe Leroy 2021-10-01 21:14 ` [PATCH 7/9] powerpc/bpf: Limit 'ldbrx' to processors compliant with ISA v2.06 Naveen N. Rao 2021-10-01 21:14 ` Naveen N. Rao 2021-10-02 17:35 ` Johan Almbladh 2021-10-02 17:35 ` Johan Almbladh 2021-10-01 21:14 ` [PATCH 8/9] powerpc/security: Add a helper to query stf_barrier type Naveen N. Rao 2021-10-01 21:14 ` Naveen N. Rao 2021-10-01 21:14 ` [PATCH 9/9] powerpc/bpf: Emit stf barrier instruction sequences for BPF_NOSPEC Naveen N. Rao 2021-10-01 21:14 ` Naveen N. Rao 2021-10-02 17:41 ` [PATCH 0/9] powerpc/bpf: Various fixes Johan Almbladh 2021-10-02 17:41 ` Johan Almbladh 2021-10-04 18:19 ` Naveen N. Rao 2021-10-04 18:19 ` Naveen N. Rao
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to='CAPhsuW4Qv5e=x6WMV1EYy+NUdu+i+i+kGY2E3WAhV66a115C=Q@mail.gmail.com' \ --to=song@kernel.org \ --cc=alexei.starovoitov@gmail.com \ --cc=bpf@vger.kernel.org \ --cc=christophe.leroy@csgroup.eu \ --cc=daniel@iogearbox.net \ --cc=johan.almbladh@anyfinetworks.com \ --cc=linuxppc-dev@lists.ozlabs.org \ --cc=mpe@ellerman.id.au \ --cc=naveen.n.rao@linux.vnet.ibm.com \ --cc=npiggin@gmail.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.