Thread (40 messages) 40 messages, 4 authors, 2022-01-07

Re: [PATCH 1/9] powerpc/lib: Add helper to check if offset is within conditional branch range

From: Naveen N. Rao <hidden>
Date: 2021-10-04 18:03:55
Also in: bpf

Hi Christophe,
Thanks for the reviews.


Christophe Leroy wrote:

Le 01/10/2021 à 23:14, Naveen N. Rao a écrit :
quoted
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 <redacted>
---
  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);
+}
Would be better without capital letters in numbers, in extenso 0x7fff 
instead of 0x7FFF
Ack.

- Naveen
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help