]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
powerpc: Prepare arch_static_call_transform() for supporting inline static calls
authorChristophe Leroy <christophe.leroy@csgroup.eu>
Tue, 3 Dec 2024 19:44:51 +0000 (20:44 +0100)
committerMadhavan Srinivasan <maddy@linux.ibm.com>
Wed, 26 Feb 2025 15:39:43 +0000 (21:09 +0530)
Reorganise arch_static_call_transform() in order to ease the support
of inline static calls in following patch:
- remove 'target' to nhide whether it is a 'return 0' or not.
- Don't bail out if 'tramp' is NULL, just do nothing until next patch.

Note that 'target' was 'tramp + PPC_SCT_RET0', is_short was perforce
true. So in the 'if (func && !is_short)' leg, target was perforce
equal to 'func'.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com>
Link: https://patch.msgid.link/7a8b9245e773307c315c2548a4c6cad570ac2648.1733245362.git.christophe.leroy@csgroup.eu
arch/powerpc/kernel/static_call.c

index 7cfd0710e7579e7597c3568220826a0f1755ee95..1b106fbcc567ab6acebac172c8e78b8f17c6d0da 100644 (file)
@@ -8,26 +8,32 @@ void arch_static_call_transform(void *site, void *tramp, void *func, bool tail)
 {
        int err;
        bool is_ret0 = (func == __static_call_return0);
-       unsigned long target = (unsigned long)(is_ret0 ? tramp + PPC_SCT_RET0 : func);
-       bool is_short = is_offset_in_branch_range((long)target - (long)tramp);
-
-       if (!tramp)
-               return;
+       unsigned long _tramp = (unsigned long)tramp;
+       unsigned long _func = (unsigned long)func;
+       unsigned long _ret0 = _tramp + PPC_SCT_RET0;
+       bool is_short = is_offset_in_branch_range((long)func - (long)(site ? : tramp));
 
        mutex_lock(&text_mutex);
 
-       if (func && !is_short) {
-               err = patch_ulong(tramp + PPC_SCT_DATA, target);
-               if (err)
-                       goto out;
+       if (tramp) {
+               if (func && !is_short) {
+                       err = patch_ulong(tramp + PPC_SCT_DATA, _func);
+                       if (err)
+                               goto out;
+               }
+
+               if (!func)
+                       err = patch_instruction(tramp, ppc_inst(PPC_RAW_BLR()));
+               else if (is_ret0)
+                       err = patch_branch(tramp, _ret0, 0);
+               else if (is_short)
+                       err = patch_branch(tramp, _func, 0);
+               else
+                       err = patch_instruction(tramp, ppc_inst(PPC_RAW_NOP()));
+       } else {
+               err = 0;
        }
 
-       if (!func)
-               err = patch_instruction(tramp, ppc_inst(PPC_RAW_BLR()));
-       else if (is_short)
-               err = patch_branch(tramp, target, 0);
-       else
-               err = patch_instruction(tramp, ppc_inst(PPC_RAW_NOP()));
 out:
        mutex_unlock(&text_mutex);