aboutsummaryrefslogtreecommitdiff
path: root/arch/loongarch/include
diff options
context:
space:
mode:
authorGravatar Youling Tang <tangyouling@loongson.cn> 2022-12-10 22:39:59 +0800
committerGravatar Huacai Chen <chenhuacai@loongson.cn> 2022-12-14 08:36:11 +0800
commitdbcd7f5fafea64dbe588c4ec18bc309fde5d1e1c (patch)
tree79be38ea0b16bd54fdba433f0f4166f1fed3bfee /arch/loongarch/include
parentLoongArch: Remove the .fixup section usage (diff)
downloadlinux-dbcd7f5fafea64dbe588c4ec18bc309fde5d1e1c.tar.gz
linux-dbcd7f5fafea64dbe588c4ec18bc309fde5d1e1c.tar.bz2
linux-dbcd7f5fafea64dbe588c4ec18bc309fde5d1e1c.zip
LoongArch: BPF: Add BPF exception tables
Inspired by commit 800834285361("bpf, arm64: Add BPF exception tables"), do similar to LoongArch to add BPF exception tables. When a tracing BPF program attempts to read memory without using the bpf_probe_read() helper, the verifier marks the load instruction with the BPF_PROBE_MEM flag. Since the LoongArch JIT does not currently recognize this flag it falls back to the interpreter. Add support for BPF_PROBE_MEM, by appending an exception table to the BPF program. If the load instruction causes a data abort, the fixup infrastructure finds the exception table and fixes up the fault, by clearing the destination register and jumping over the faulting instruction. To keep the compact exception table entry format, inspect the pc in fixup_exception(). A more generic solution would add a "handler" field to the table entry, like on x86, s390 and arm64, etc. Signed-off-by: Youling Tang <tangyouling@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Diffstat (limited to 'arch/loongarch/include')
-rw-r--r--arch/loongarch/include/asm/asm-extable.h1
-rw-r--r--arch/loongarch/include/asm/extable.h10
2 files changed, 11 insertions, 0 deletions
diff --git a/arch/loongarch/include/asm/asm-extable.h b/arch/loongarch/include/asm/asm-extable.h
index f5502cb50c6e..df05005f2b80 100644
--- a/arch/loongarch/include/asm/asm-extable.h
+++ b/arch/loongarch/include/asm/asm-extable.h
@@ -5,6 +5,7 @@
#define EX_TYPE_NONE 0
#define EX_TYPE_FIXUP 1
#define EX_TYPE_UACCESS_ERR_ZERO 2
+#define EX_TYPE_BPF 3
#ifdef __ASSEMBLY__
diff --git a/arch/loongarch/include/asm/extable.h b/arch/loongarch/include/asm/extable.h
index 92612b4364a1..5abf29f1bc91 100644
--- a/arch/loongarch/include/asm/extable.h
+++ b/arch/loongarch/include/asm/extable.h
@@ -32,6 +32,16 @@ do { \
(b)->data = (tmp).data; \
} while (0)
+#ifdef CONFIG_BPF_JIT
+bool ex_handler_bpf(const struct exception_table_entry *ex, struct pt_regs *regs);
+#else
+static inline
+bool ex_handler_bpf(const struct exception_table_entry *ex, struct pt_regs *regs)
+{
+ return false;
+}
+#endif /* !CONFIG_BPF_JIT */
+
bool fixup_exception(struct pt_regs *regs);
#endif