Skip to content

Commit 062fd46

Browse files
swinepuranjaymohan
authored andcommitted
create-diff-object: Check __patchable_function_entries section for aarch64
Add aarch64 support to kpatch_create_ftrace_callsite_sections(). Check for the 2 required NOP instructions on function entry, which may be preceded by a BTI C instruction depending on whether the function is a leaf function. This determines the offset of the patch site. Signed-off-by: Pete Swain <swine@google.com> Signed-off-by: Puranjay Mohan <pjy@amazon.com>
1 parent 2ed84b1 commit 062fd46

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

kpatch-build/create-diff-object.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3847,6 +3847,30 @@ static void kpatch_create_ftrace_callsite_sections(struct kpatch_elf *kelf)
38473847
}
38483848

38493849
switch(kelf->arch) {
3850+
case AARCH64: {
3851+
unsigned char *insn = sym->sec->data->d_buf;
3852+
int i;
3853+
3854+
/*
3855+
* If BTI (Branch Target Identification) is enabled then there
3856+
* might be an additional 'BTI C' instruction before the two
3857+
* patchable function entry 'NOP's.
3858+
* i.e. 0xd503245f (little endian)
3859+
*/
3860+
if (insn[0] == 0x5f) {
3861+
if (insn[1] != 0x24 || insn[2] != 0x03 || insn[3] != 0xd5)
3862+
ERROR("%s: unexpected instruction in patch section of function\n", sym->name);
3863+
insn_offset += 4;
3864+
insn += 4;
3865+
}
3866+
for (i = 0; i < 8; i += 4) {
3867+
/* We expect a NOP i.e. 0xd503201f (little endian) */
3868+
if (insn[i] != 0x1f || insn[i + 1] != 0x20 ||
3869+
insn[i + 2] != 0x03 || insn [i + 3] != 0xd5)
3870+
ERROR("%s: unexpected instruction in patch section of function\n", sym->name);
3871+
}
3872+
break;
3873+
}
38503874
case PPC64: {
38513875
unsigned char *insn;
38523876

0 commit comments

Comments
 (0)