1*93d298f0SPuranjay Mohan // SPDX-License-Identifier: GPL-2.0
2*93d298f0SPuranjay Mohan /*
3*93d298f0SPuranjay Mohan * Static call site in a patched function, laid out by hand as for
4*93d298f0SPuranjay Mohan * jump_label.c. MODNAME selects whether the key belongs to vmlinux or a
5*93d298f0SPuranjay Mohan * module.
6*93d298f0SPuranjay Mohan *
7*93d298f0SPuranjay Mohan * objtool's check pass would emit the site, and klp-write-tests.txt says to
8*93d298f0SPuranjay Mohan * let it. Not here: it does not emit the ANNOTATE_DATA_SPECIAL describing
9*93d298f0SPuranjay Mohan * the entry boundaries -- in the kernel that comes from the static_call
10*93d298f0SPuranjay Mohan * macros -- and NO_ANNOTATE below has to be able to take it away. A fixture
11*93d298f0SPuranjay Mohan * which varies the annotation has to write the entry that goes with it.
12*93d298f0SPuranjay Mohan *
13*93d298f0SPuranjay Mohan * NO_ANNOTATE drops the ANNOTATE_DATA_SPECIAL block from the patched build,
14*93d298f0SPuranjay Mohan * leaving .static_call_sites with no annotation to describe its entry
15*93d298f0SPuranjay Mohan * boundaries. The section carries no entsize either, so klp diff has to fall
16*93d298f0SPuranjay Mohan * back on the annotations it can still see -- and when the patched object is
17*93d298f0SPuranjay Mohan * the only one that lost them, the two sides disagree about how the section is
18*93d298f0SPuranjay Mohan * divided up.
19*93d298f0SPuranjay Mohan *
20*93d298f0SPuranjay Mohan * NEW_CALL puts the call site behind PATCHED, so the patch introduces one
21*93d298f0SPuranjay Mohan * where the original had none. The .static_call_sites entry is then new, with
22*93d298f0SPuranjay Mohan * nothing in the original to correlate it against.
23*93d298f0SPuranjay Mohan */
24*93d298f0SPuranjay Mohan
25*93d298f0SPuranjay Mohan #ifndef MODNAME
26*93d298f0SPuranjay Mohan #define MODNAME "vmlinux"
27*93d298f0SPuranjay Mohan #endif
28*93d298f0SPuranjay Mohan
29*93d298f0SPuranjay Mohan static const char __modinfo[]
30*93d298f0SPuranjay Mohan __attribute__((section(".modinfo"), used, aligned(1))) = "\0name=" MODNAME;
31*93d298f0SPuranjay Mohan
32*93d298f0SPuranjay Mohan long __SCK__klp_test_call;
33*93d298f0SPuranjay Mohan
target(int x)34*93d298f0SPuranjay Mohan int target(int x)
35*93d298f0SPuranjay Mohan {
36*93d298f0SPuranjay Mohan #if defined(NEW_CALL) && !defined(PATCHED)
37*93d298f0SPuranjay Mohan /* The original has no static call at all. */
38*93d298f0SPuranjay Mohan return x + 1;
39*93d298f0SPuranjay Mohan #else
40*93d298f0SPuranjay Mohan __asm__ volatile(
41*93d298f0SPuranjay Mohan "1: nop\n\t"
42*93d298f0SPuranjay Mohan ".pushsection .static_call_sites, \"aw\"\n\t"
43*93d298f0SPuranjay Mohan ".balign 8\n\t"
44*93d298f0SPuranjay Mohan "912:\n\t"
45*93d298f0SPuranjay Mohan #if !(defined(PATCHED) && defined(NO_ANNOTATE))
46*93d298f0SPuranjay Mohan ".pushsection .discard.annotate_data, \"M\", @progbits, 8\n\t"
47*93d298f0SPuranjay Mohan ".long 912b - ., 1\n\t"
48*93d298f0SPuranjay Mohan ".popsection\n\t"
49*93d298f0SPuranjay Mohan #endif
50*93d298f0SPuranjay Mohan ".long 1b - ., %c0 - .\n\t"
51*93d298f0SPuranjay Mohan ".popsection\n\t"
52*93d298f0SPuranjay Mohan :: "i" (&__SCK__klp_test_call));
53*93d298f0SPuranjay Mohan #endif
54*93d298f0SPuranjay Mohan #ifdef PATCHED
55*93d298f0SPuranjay Mohan return x + 2;
56*93d298f0SPuranjay Mohan #else
57*93d298f0SPuranjay Mohan return x + 1;
58*93d298f0SPuranjay Mohan #endif
59*93d298f0SPuranjay Mohan }
60