^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2012 ARM Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #ifndef __ASM_MODULE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #define __ASM_MODULE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <asm-generic/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #ifdef CONFIG_ARM64_MODULE_PLTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) struct mod_plt_sec {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) int plt_shndx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) int plt_num_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) int plt_max_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) struct mod_arch_specific {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct mod_plt_sec core;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct mod_plt_sec init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) /* for CONFIG_DYNAMIC_FTRACE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct plt_entry *ftrace_trampolines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) /* for FIPS 140 certified kernel module */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) const Elf64_Rela *text_relocations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) const Elf64_Rela *rodata_relocations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) int num_text_relocations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) int num_rodata_relocations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) u64 module_emit_plt_entry(struct module *mod, Elf64_Shdr *sechdrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) void *loc, const Elf64_Rela *rela,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) Elf64_Sym *sym);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) u64 module_emit_veneer_for_adrp(struct module *mod, Elf64_Shdr *sechdrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) void *loc, u64 val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #ifdef CONFIG_RANDOMIZE_BASE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) extern u64 module_alloc_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define module_alloc_base ((u64)_etext - MODULES_VSIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct plt_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * A program that conforms to the AArch64 Procedure Call Standard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * (AAPCS64) must assume that a veneer that alters IP0 (x16) and/or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * IP1 (x17) may be inserted at any branch instruction that is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * exposed to a relocation that supports long branches. Since that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * is exactly what we are dealing with here, we are free to use x16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * as a scratch register in the PLT veneers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) __le32 adrp; /* adrp x16, .... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) __le32 add; /* add x16, x16, #0x.... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) __le32 br; /* br x16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static inline bool is_forbidden_offset_for_adrp(void *place)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) return IS_ENABLED(CONFIG_ARM64_ERRATUM_843419) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) cpus_have_const_cap(ARM64_WORKAROUND_843419) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) ((u64)place & 0xfff) >= 0xff8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct plt_entry get_plt_entry(u64 dst, void *pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) bool plt_entries_equal(const struct plt_entry *a, const struct plt_entry *b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static inline bool plt_entry_is_initialized(const struct plt_entry *e)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return e->adrp || e->add || e->br;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #endif /* __ASM_MODULE_H */