Skip to content

Commit f1a66f8

Browse files
borkmanndavem330
authored andcommitted
ebpf: export BPF_PSEUDO_MAP_FD to uapi
We need to export BPF_PSEUDO_MAP_FD to user space, as it's used in the ELF BPF loader where instructions are being loaded that need map fixups. An initial stage loads all maps into the kernel, and later on replaces related instructions in the eBPF blob with BPF_PSEUDO_MAP_FD as source register and the actual fd as immediate value. The kernel verifier recognizes this keyword and replaces the map fd with a real pointer internally. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Alexei Starovoitov <ast@plumgrid.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent a2c83ff commit f1a66f8

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

include/linux/filter.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ struct bpf_prog_aux;
145145
.off = 0, \
146146
.imm = ((__u64) (IMM)) >> 32 })
147147

148-
#define BPF_PSEUDO_MAP_FD 1
149-
150148
/* pseudo BPF_LD_IMM64 insn used to refer to process-local map_fd */
151149
#define BPF_LD_MAP_FD(DST, MAP_FD) \
152150
BPF_LD_IMM64_RAW(DST, BPF_PSEUDO_MAP_FD, MAP_FD)

include/uapi/linux/bpf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ enum bpf_prog_type {
120120
BPF_PROG_TYPE_SOCKET_FILTER,
121121
};
122122

123+
#define BPF_PSEUDO_MAP_FD 1
124+
123125
/* flags for BPF_MAP_UPDATE_ELEM command */
124126
#define BPF_ANY 0 /* create new element or update existing */
125127
#define BPF_NOEXIST 1 /* create new element if it didn't exist */

samples/bpf/libbpf.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ extern char bpf_log_buf[LOG_BUF_SIZE];
9292
.off = 0, \
9393
.imm = ((__u64) (IMM)) >> 32 })
9494

95-
#define BPF_PSEUDO_MAP_FD 1
95+
#ifndef BPF_PSEUDO_MAP_FD
96+
# define BPF_PSEUDO_MAP_FD 1
97+
#endif
9698

9799
/* pseudo BPF_LD_IMM64 insn used to refer to process-local map_fd */
98100
#define BPF_LD_MAP_FD(DST, MAP_FD) \

0 commit comments

Comments
 (0)