18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __ASM_EXTABLE_H
38c2ecf20Sopenharmony_ci#define __ASM_EXTABLE_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci/*
68c2ecf20Sopenharmony_ci * The exception table consists of pairs of relative offsets: the first
78c2ecf20Sopenharmony_ci * is the relative offset to an instruction that is allowed to fault,
88c2ecf20Sopenharmony_ci * and the second is the relative offset at which the program should
98c2ecf20Sopenharmony_ci * continue. No registers are modified, so it is entirely up to the
108c2ecf20Sopenharmony_ci * continuation code to figure out what to do.
118c2ecf20Sopenharmony_ci *
128c2ecf20Sopenharmony_ci * All the routines below use bits of fixup code that are out of line
138c2ecf20Sopenharmony_ci * with the main instruction path.  This means when everything is well,
148c2ecf20Sopenharmony_ci * we don't even have to jump over them.  Further, they do not intrude
158c2ecf20Sopenharmony_ci * on our cache or tlb entries.
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_cistruct exception_table_entry
198c2ecf20Sopenharmony_ci{
208c2ecf20Sopenharmony_ci	int insn, fixup;
218c2ecf20Sopenharmony_ci};
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define ARCH_HAS_RELATIVE_EXTABLE
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_cistatic inline bool in_bpf_jit(struct pt_regs *regs)
268c2ecf20Sopenharmony_ci{
278c2ecf20Sopenharmony_ci	if (!IS_ENABLED(CONFIG_BPF_JIT))
288c2ecf20Sopenharmony_ci		return false;
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci	return regs->pc >= BPF_JIT_REGION_START &&
318c2ecf20Sopenharmony_ci	       regs->pc < BPF_JIT_REGION_END;
328c2ecf20Sopenharmony_ci}
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#ifdef CONFIG_BPF_JIT
358c2ecf20Sopenharmony_ciint arm64_bpf_fixup_exception(const struct exception_table_entry *ex,
368c2ecf20Sopenharmony_ci			      struct pt_regs *regs);
378c2ecf20Sopenharmony_ci#else /* !CONFIG_BPF_JIT */
388c2ecf20Sopenharmony_cistatic inline
398c2ecf20Sopenharmony_ciint arm64_bpf_fixup_exception(const struct exception_table_entry *ex,
408c2ecf20Sopenharmony_ci			      struct pt_regs *regs)
418c2ecf20Sopenharmony_ci{
428c2ecf20Sopenharmony_ci	return 0;
438c2ecf20Sopenharmony_ci}
448c2ecf20Sopenharmony_ci#endif /* !CONFIG_BPF_JIT */
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ciextern int fixup_exception(struct pt_regs *regs);
478c2ecf20Sopenharmony_ci#endif
48