bpf: Introduce bpf_arch_text_copy
authorSong Liu <song@kernel.org>
Fri, 4 Feb 2022 18:57:39 +0000 (10:57 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 8 Feb 2022 02:13:01 +0000 (18:13 -0800)
This will be used to copy JITed text to RO protected module memory. On
x86, bpf_arch_text_copy is implemented with text_poke_copy.

bpf_arch_text_copy returns pointer to dst on success, and ERR_PTR(errno)
on errors.

Signed-off-by: Song Liu <song@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20220204185742.271030-7-song@kernel.org
arch/x86/net/bpf_jit_comp.c
include/linux/bpf.h
kernel/bpf/core.c

index 36f6fc3e6e690ce382aa05293ebb8c45001d2664..c13d148f73966ea3f90f7e14e5d0873c71c104e7 100644 (file)
@@ -2412,3 +2412,10 @@ bool bpf_jit_supports_kfunc_call(void)
 {
        return true;
 }
+
+void *bpf_arch_text_copy(void *dst, void *src, size_t len)
+{
+       if (text_poke_copy(dst, src, len) == NULL)
+               return ERR_PTR(-EINVAL);
+       return dst;
+}
index 366f88afd56b4c7a86d378dbf2e33e664e5eb812..ea0d7fd4a410a3e2b7fed5ce984dcbd7a8efbc87 100644 (file)
@@ -2362,6 +2362,8 @@ enum bpf_text_poke_type {
 int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
                       void *addr1, void *addr2);
 
+void *bpf_arch_text_copy(void *dst, void *src, size_t len);
+
 struct btf_id_set;
 bool btf_id_set_contains(const struct btf_id_set *set, u32 id);
 
index e3fe53df0a717ed5c3335917ded1c1f6d84d88a9..a5ec480f9862af7c4306243b1bc41973bb370f74 100644 (file)
@@ -2440,6 +2440,11 @@ int __weak bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
        return -ENOTSUPP;
 }
 
+void * __weak bpf_arch_text_copy(void *dst, void *src, size_t len)
+{
+       return ERR_PTR(-ENOTSUPP);
+}
+
 DEFINE_STATIC_KEY_FALSE(bpf_stats_enabled_key);
 EXPORT_SYMBOL(bpf_stats_enabled_key);