powerpc/code-patching: Move patch_exception() outside code-patching.c
authorChristophe Leroy <christophe.leroy@csgroup.eu>
Thu, 2 Dec 2021 12:00:24 +0000 (13:00 +0100)
committerMichael Ellerman <mpe@ellerman.id.au>
Thu, 23 Dec 2021 11:36:55 +0000 (22:36 +1100)
patch_exception() is dedicated to book3e/64 is nothing more than
a normal use of patch_branch(), so move it into a place dedicated
to book3e/64.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/0968622b98b1fb51838c35b844c42ad6609de62e.1638446239.git.christophe.leroy@csgroup.eu
arch/powerpc/include/asm/code-patching.h
arch/powerpc/include/asm/exception-64e.h
arch/powerpc/include/asm/nohash/64/pgtable.h
arch/powerpc/lib/code-patching.c
arch/powerpc/mm/nohash/book3e_pgtable.c

index 46e8c5a..275061c 100644 (file)
@@ -63,13 +63,6 @@ int instr_is_relative_link_branch(ppc_inst_t instr);
 unsigned long branch_target(const u32 *instr);
 int translate_branch(ppc_inst_t *instr, const u32 *dest, const u32 *src);
 bool is_conditional_branch(ppc_inst_t instr);
-#ifdef CONFIG_PPC_BOOK3E_64
-void __patch_exception(int exc, unsigned long addr);
-#define patch_exception(exc, name) do { \
-       extern unsigned int name; \
-       __patch_exception((exc), (unsigned long)&name); \
-} while (0)
-#endif
 
 #define OP_RT_RA_MASK  0xffff0000UL
 #define LIS_R2         (PPC_RAW_LIS(_R2, 0))
index 40cdcb2..b1ef1e9 100644 (file)
@@ -149,6 +149,10 @@ exc_##label##_book3e:
        addi    r11,r13,PACA_EXTLB;                                         \
        TLB_MISS_RESTORE(r11)
 
+#ifndef __ASSEMBLY__
+extern unsigned int interrupt_base_book3e;
+#endif
+
 #define SET_IVOR(vector_number, vector_offset) \
        LOAD_REG_ADDR(r3,interrupt_base_book3e);\
        ori     r3,r3,vector_offset@l;          \
index 9d2905a..a3313e8 100644 (file)
@@ -313,6 +313,12 @@ extern int __meminit vmemmap_create_mapping(unsigned long start,
                                            unsigned long phys);
 extern void vmemmap_remove_mapping(unsigned long start,
                                   unsigned long page_size);
+void __patch_exception(int exc, unsigned long addr);
+#define patch_exception(exc, name) do { \
+       extern unsigned int name; \
+       __patch_exception((exc), (unsigned long)&name); \
+} while (0)
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* _ASM_POWERPC_NOHASH_64_PGTABLE_H */
index 441a71c..f4986a7 100644 (file)
@@ -370,22 +370,6 @@ int translate_branch(ppc_inst_t *instr, const u32 *dest, const u32 *src)
        return 1;
 }
 
-#ifdef CONFIG_PPC_BOOK3E_64
-void __patch_exception(int exc, unsigned long addr)
-{
-       extern unsigned int interrupt_base_book3e;
-       unsigned int *ibase = &interrupt_base_book3e;
-
-       /* Our exceptions vectors start with a NOP and -then- a branch
-        * to deal with single stepping from userspace which stops on
-        * the second instruction. Thus we need to patch the second
-        * instruction of the exception, not the first one
-        */
-
-       patch_branch(ibase + (exc / 4) + 1, addr, 0);
-}
-#endif
-
 #ifdef CONFIG_CODE_PATCHING_SELFTEST
 
 static int __init instr_is_branch_to_addr(const u32 *instr, unsigned long addr)
index 77884e2..7d4368d 100644 (file)
@@ -10,6 +10,7 @@
 #include <asm/pgalloc.h>
 #include <asm/tlb.h>
 #include <asm/dma.h>
+#include <asm/code-patching.h>
 
 #include <mm/mmu_decl.h>
 
@@ -115,3 +116,17 @@ int __ref map_kernel_page(unsigned long ea, unsigned long pa, pgprot_t prot)
        smp_wmb();
        return 0;
 }
+
+void __patch_exception(int exc, unsigned long addr)
+{
+       unsigned int *ibase = &interrupt_base_book3e;
+
+       /*
+        * Our exceptions vectors start with a NOP and -then- a branch
+        * to deal with single stepping from userspace which stops on
+        * the second instruction. Thus we need to patch the second
+        * instruction of the exception, not the first one.
+        */
+
+       patch_branch(ibase + (exc / 4) + 1, addr, 0);
+}