File Index
Files and directories
Sign in
FILE

static_call.c

File preview with syntax highlighting.

linux-6.19.14/arch/powerpc/kernel/static_call.c C
 1// SPDX-License-Identifier: GPL-2.0
 2#include <linux/memory.h>
 3#include <linux/static_call.h>
 4
 5#include <asm/text-patching.h>
 6
 7void arch_static_call_transform(void *site, void *tramp, void *func, bool tail)
 8{
 9	int err;
10	bool is_ret0 = (func == __static_call_return0);
11	unsigned long _tramp = (unsigned long)tramp;
12	unsigned long _func = (unsigned long)func;
13	unsigned long _ret0 = _tramp + PPC_SCT_RET0;
14	bool is_short = is_offset_in_branch_range((long)func - (long)(site ? : tramp));
15
16	mutex_lock(&text_mutex);
17
18	if (site && tail) {
19		if (!func)
20			err = patch_instruction(site, ppc_inst(PPC_RAW_BLR()));
21		else if (is_ret0)
22			err = patch_branch(site, _ret0, 0);
23		else if (is_short)
24			err = patch_branch(site, _func, 0);
25		else if (tramp)
26			err = patch_branch(site, _tramp, 0);
27		else
28			err = 0;
29	} else if (site) {
30		if (!func)
31			err = patch_instruction(site, ppc_inst(PPC_RAW_NOP()));
32		else if (is_ret0)
33			err = patch_instruction(site, ppc_inst(PPC_RAW_LI(_R3, 0)));
34		else if (is_short)
35			err = patch_branch(site, _func, BRANCH_SET_LINK);
36		else if (tramp)
37			err = patch_branch(site, _tramp, BRANCH_SET_LINK);
38		else
39			err = 0;
40	} else if (tramp) {
41		if (func && !is_short) {
42			err = patch_ulong(tramp + PPC_SCT_DATA, _func);
43			if (err)
44				goto out;
45		}
46
47		if (!func)
48			err = patch_instruction(tramp, ppc_inst(PPC_RAW_BLR()));
49		else if (is_ret0)
50			err = patch_branch(tramp, _ret0, 0);
51		else if (is_short)
52			err = patch_branch(tramp, _func, 0);
53		else
54			err = patch_instruction(tramp, ppc_inst(PPC_RAW_NOP()));
55	} else {
56		err = 0;
57	}
58
59out:
60	mutex_unlock(&text_mutex);
61
62	if (err)
63		panic("%s: patching failed %pS at %pS\n", __func__, func, tramp);
64}
65EXPORT_SYMBOL_GPL(arch_static_call_transform);
~/ Read-only file preview.