Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

15 bpf 5.4 #14

Open
wants to merge 161 commits into
base: 15
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
161 commits
Select commit Hold shift + click to select a range
d363c5d
bpf: btf: refactor btf_int_bits_seq_show()
yonghong-song Dec 16, 2018
edbdae8
bpf: btf: Break up btf_type_is_void()
iamkafai Nov 19, 2018
896a888
BACKPORT: bpf: split verifier and program ops
Oct 16, 2017
f4a5411
device_cgroup: add DEVCG_ prefix to ACC_* and DEV_* constants
rgushchin Dec 26, 2024
0a8010b
device_cgroup: prepare code for bpf-based device controller
rgushchin Dec 26, 2024
403f144
bpf, cgroup: implement eBPF-based device controller for cgroup v2
rgushchin Nov 5, 2017
a63e677
BACKPORT: bpf: remove the verifier ops from program structure
Oct 16, 2017
3d49e7e
net: add a UID to use for ULP socket assignment
jrfastab Feb 5, 2018
122dcc8
bpf: sockmap, add sock close() hook to remove socks
jrfastab Feb 5, 2018
2241908
BACKPORT: bpf/tracing: allow user space to query prog array on the sa…
yonghong-song Dec 11, 2017
1f834bd
bpf/tracing: fix kernel/events/core.c compilation error
yonghong-song Dec 13, 2017
31bf693
macro: introduce COUNT_ARGS() macro
Mar 28, 2018
ceecefc
f2fs: macro: Switch to COUNT_ARGS macro
roberto-sartori-gl Oct 14, 2023
c50503d
cfg80211/nl80211: macro: Switch to COUNT_ARGS macro
roberto-sartori-gl Oct 14, 2023
0217dc0
BACKPORT: bpf: introduce BPF_RAW_TRACEPOINT
Mar 28, 2018
947cef5
FROMLIST: [net-next,v2,1/2] bpf: Allow CGROUP_SKB eBPF program to acc…
Jun 3, 2017
ec16235
netfilter: x_tables: use pr ratelimiting in all remaining spots
Feb 9, 2018
cb49d2a
netfilter: xt_conntrack: Support bit-shifting for CONNMARK & MARK tar…
Mar 18, 2018
4863e68
netfilter: xt_connmark: Add bit mapping for bit-shift operation.
Apr 6, 2018
694dd5c
netfilter: xt_connmark: do not cast xt_connmark_tginfo1 to xt_connmar…
ummakynes Apr 19, 2018
276834d
netfilter: xt_connmark: fix list corruption on rmmod
Jun 12, 2018
dceba4d
BACKPORT: bpf: Add base proto function for cgroup-bpf programs
rdna Mar 12, 2019
a9ad5b5
BACKPORT: flow_dissector: implements flow dissector BPF hook
Sep 14, 2018
a862446
BACKPORT: bpf: Sysctl hook
rdna Feb 27, 2019
6b8c6aa
BACKPORT: bpf: create tcp_bpf_ulp allowing BPF to monitor socket TX/R…
jrfastab Mar 18, 2018
5e6ff90
bpf: fix pointer offsets in context for 32 bit
borkmann Dec 1, 2018
330e7dd
bpf: fix bpf_prog_array_copy_to_user() issues
Feb 2, 2018
73764cd
bpf: avoid rcu_dereference inside bpf_event_mutex lock region
yonghong-song Oct 30, 2017
8bde2c3
bpf: set maximum number of attached progs to 64 for a single perf tp
yonghong-song Nov 30, 2017
f7d761c
bpf/tracing: fix a deadlock in perf_event_detach_bpf_prog
yonghong-song Apr 10, 2018
d3b38c6
bpf: introduce new bpf cpu map type BPF_MAP_TYPE_CPUMAP
netoptimizer Oct 16, 2017
8e133c2
bpf: add helper for copying attrs to struct bpf_map
Jan 12, 2018
1ecf49c
bpf: add ability to charge bpf maps memory dynamically
rgushchin Aug 2, 2018
d0a534d
bpf: introduce cgroup storage maps
rgushchin Aug 2, 2018
356e122
bpf: pass a pointer to a cgroup storage using pcpu variable
rgushchin Aug 2, 2018
1730977
bpf: include errno.h from bpf-cgroup.h
rgushchin Jul 6, 2018
0bd724f
BACKPORT: bpf: allocate cgroup storage entries on attaching bpf programs
rgushchin Aug 2, 2018
33f9c2d
bpf: extend bpf_prog_array to store pointers to the cgroup storage
rgushchin Aug 2, 2018
d7523b4
bpf/verifier: introduce BPF_PTR_TO_MAP_VALUE
rgushchin Aug 2, 2018
c5950a4
bpf: introduce the bpf_get_local_storage() helper function
rgushchin Aug 2, 2018
63d72fb
bpf: implement bpf_get_current_cgroup_id() helper
yonghong-song Jun 3, 2018
0d67f96
bpf: permit CGROUP_DEVICE programs accessing helper bpf_get_current_c…
yonghong-song Sep 27, 2018
f065bd5
bpf: extend cgroup bpf core to allow multiple cgroup storage types
rgushchin Sep 28, 2018
49dcb6e
bpf: Add PTR_TO_SOCKET verifier type
joestringer Oct 2, 2018
12e0e85
bpf: offload: ignore namespace moves
Nov 20, 2017
9c5a72b
bpf: offload: don't require rtnl for dev list manipulation
Dec 28, 2017
40c175d
nsfs: generalize ns_get_path() for path resolution with a task
Dec 28, 2017
7910061
nsfs: unobfuscate
Mar 23, 2019
34616c3
bpf: offload: report device information for offloaded programs
Dec 28, 2017
de0c623
bpf: offload: free program id when device disappears
Dec 28, 2017
c61a0f7
bpf: offload: allow netdev to disappear while verifier is running
Dec 28, 2017
2c16b6e
bpf: rename bpf_dev_offload -> bpf_prog_offload
Jan 12, 2018
80698a9
bpf: offload: factor out netdev checking at allocation time
Jan 12, 2018
659c715
bpf: add map_alloc_check callback
Jan 12, 2018
ec0f7b0
bpf: offload: add map offload infrastructure
Jan 12, 2018
4a759e8
bpf: offload: report device information about offloaded maps
Jan 18, 2018
bf534bc
bpf_obj_do_pin(): switch to vfs_mkobj(), quit abusing ->mknod()
Dec 1, 2017
3c24967
new primitive: vfs_mkobj()
Dec 1, 2017
d7b2109
nsfs: clean-up ns_get_path() signature to return int
cyphar Dec 6, 2019
b683444
bpf: btf: Add pretty print support to the basic arraymap
iamkafai Apr 18, 2018
d1d9f64
bpf: btf: Introduce BTF ID
iamkafai May 4, 2018
5aad724
bpf: move instruction printing into a separate file
Oct 9, 2017
4056d51
bpf: squash of log related commits
roberto-sartori-gl Oct 23, 2024
e92fa32
bpf: rename bpf_compute_data_end into bpf_compute_data_pointers
borkmann Sep 25, 2017
74a4abe
bpf: add meta pointer for direct access
borkmann Sep 25, 2017
c05ca06
bpf: also improve pattern matches for meta access
borkmann Nov 1, 2017
747fd2e
bpf: print liveness info to verifier log
4ast Dec 1, 2017
e8c8aa8
bpf: cleanup register_is_null()
4ast Dec 1, 2017
9514b1a
bpf: introduce function calls (verification)
4ast Dec 15, 2017
42d4ccc
bpf: add support for bpf_call to interpreter
4ast Dec 15, 2017
2eeb4b0
bpf: fix net.core.bpf_jit_enable race
4ast Dec 15, 2017
f307a78
bpf: x64: add JIT support for multi-function programs
4ast Dec 15, 2017
20703ef
bpf: Add bpf_patch_call_args prototype to include/linux/bpf.h
anakryiko Jan 12, 2021
d6dda26
stop using '%pK' for /proc/kallsyms pointer values
torvalds Nov 8, 2017
fa5c00a
/proc/module: use the same logic as /proc/kallsyms for address exposure
torvalds Nov 13, 2017
8786e35
bpf: allow for correlation of maps and helpers in dump
borkmann Dec 20, 2017
86c8820
bpf: annotate bpf_insn_print_t with __printf
Jan 16, 2018
e99b152
bpf: Remove struct bpf_verifier_env argument from print_bpf_insn
olsajiri Mar 23, 2018
b33bc8b
bpf/verifier: refine retval R0 state for bpf_get_stack helper
yonghong-song Apr 29, 2018
4a96fde
bpf: Add iterator for spilled registers
joestringer Oct 2, 2018
4442178
bpf: Generalize ptr_or_null regs check
joestringer Oct 2, 2018
ecda071
bpf: Macrofy stack state copy
joestringer Oct 2, 2018
ae61706
bpf: introduce ARG_PTR_TO_MEM_OR_NULL
gianlucaborello Nov 22, 2017
1085044
bpf, verifier: detect misconfigured mem, size argument pair
borkmann Jan 20, 2018
35152fe
bpf: properly enforce index mask to prevent out-of-bounds speculation
borkmann May 24, 2018
64c6baa
bpf: Add reference tracking to verifier
joestringer Oct 2, 2018
6451272
bpf: decouple btf from seq bpf fs dump and enable more maps
borkmann Aug 11, 2018
c4b188e
bpf, x64: fix memleak when not converging on calls
borkmann May 2, 2018
f66e80a
bpf: fix maximum stack depth tracking logic
Dec 25, 2017
285d8e0
bpf: unify main prog and subprog
May 2, 2018
7d5f33b
bpf: centre subprog information fields
May 2, 2018
4c20d82
bpf: Add gpl_compatible flag to struct bpf_prog_info
olsajiri Apr 25, 2018
6306ed1
bpf: get kernel symbol addresses via syscall
sandip4n May 24, 2018
aa1e09a
bpf: get JITed image lengths of functions via syscall
sandip4n May 24, 2018
bf1043c
bpf: Append prog->aux->name in bpf_get_prog_name()
iamkafai Oct 6, 2017
cc809b9
bpf: Expose check_uarg_tail_zero()
iamkafai May 22, 2018
cd30ebd
bpf: fix bpf_prog_get_info_by_fd to return 0 func_lens for unpriv
borkmann Nov 2, 2018
8faafb4
bpf: btf: Add BTF_KIND_FUNC and BTF_KIND_FUNC_PROTO
iamkafai Nov 19, 2018
f0bb786
bpf: Introduce bpf_func_info
yonghong-song Nov 19, 2018
03bbfac
bpf: btf: support proper non-jit func info
yonghong-song Nov 25, 2018
399da99
bpf: don't leave partial mangled prog in jit_subprogs error path
borkmann Jul 12, 2018
8847fb8
bpf: Add bpf_line_info support
iamkafai Dec 8, 2018
a3fee50
bpf: reject any prog that failed read-only lock
borkmann Jun 15, 2018
4dbd978
bpf: Create a new btf_name_by_offset() for non type name use case
iamkafai Dec 13, 2018
7115a77
bpf: fix a compilation error when CONFIG_BPF_SYSCALL is not defined
yonghong-song Nov 20, 2018
6fd413c
bpf: btf: Rename btf_key_id and btf_value_id in bpf_map_info
iamkafai May 22, 2018
4685120
bpf: introduce per-cpu cgroup local storage
rgushchin Sep 28, 2018
128bc60
bpf: Define cgroup_bpf_enabled for CONFIG_CGROUP_BPF=n
rdna May 25, 2018
80c5a38
bpf: pass struct btf pointer to the map_check_btf() callback
rgushchin Dec 10, 2018
a40bd77
bpf: add bpffs pretty print for cgroup local storage maps
rgushchin Dec 10, 2018
5d322fb
bpf: btf: fix struct/union/fwd types with kind_flag
yonghong-song Dec 16, 2018
eb8f349
bpf: enable cgroup local storage map pretty print with kind_flag
yonghong-song Dec 16, 2018
1361311
UPSTREAM: locking/barriers: Introduce smp_cond_load_relaxed() and ato…
wildea01 Apr 26, 2018
42144d3
bpf: introduce bpf_spin_lock
Jan 31, 2019
8108742
SQUASH! bpf: Add a bpf_sock pointer to __sk_buff and a bpf_sk_fullsoc…
roberto-sartori-gl Oct 24, 2024
da52829
bpf: Add helper to retrieve socket in BPF
joestringer Oct 2, 2018
559f1cb
bpf: undo prog rejection on read-only lock failure
borkmann Jun 28, 2018
10ab246
fixup: add back code missed during BPF picking
roberto-sartori-gl Oct 25, 2024
f5c14b3
xfrm: add documentation for xfrm device offload api
Nov 20, 2017
dfdc21f
sk_buff: add skb extension infrastructure
Dec 18, 2018
087bcf3
netfilter: meta: secpath support
Dec 6, 2017
29f6a7f
net: move secpath_exist helper to sk_buff.h
Dec 18, 2018
c1ec8ce
xfrm: Separate ESP handling from segmentation for GRO packets.
klassert Dec 20, 2017
b818346
net: Add asynchronous callbacks for xfrm on layer 2.
klassert Dec 20, 2017
a1d0c86
netfilter: nf_tables: add support for native socket matching
ecklm May 28, 2018
6382f2f
xdp: base API for new XDP rx-queue info concept
netoptimizer Jan 3, 2018
3a42c57
net: avoid including xdp.h in filter.h
netoptimizer Feb 13, 2018
76b7ee1
xdp: move struct xdp_buff from filter.h to xdp.h
netoptimizer Apr 17, 2018
4873fe1
xdp: generic XDP handling of xdp_rxq_info
netoptimizer Jan 3, 2018
d2043cd
bpf: Extend the sk_lookup() helper to XDP hookpoint.
nitinhande Oct 29, 2018
e3cab5d
bpf: Support socket lookup in CGROUP_SOCK_ADDR progs
rdna Nov 9, 2018
28e7bc1
bpf: Add struct bpf_tcp_sock and BPF_FUNC_tcp_sock
iamkafai Feb 10, 2019
ccebdab
bpf: add writable context for raw tracepoints
mokomull Apr 26, 2019
5cc27f2
bpf: allow map helpers access to map values directly
pchaigno Apr 24, 2018
29ffc45
bpf/verifier: add ARG_PTR_TO_UNINIT_MAP_VALUE
mauriciovasquezbernal Oct 18, 2018
65a964a
bpf: Introduce ARG_PTR_TO_{INT,LONG} arg types
rdna Mar 18, 2019
246406d
bpf: introduce BPF_F_LOCK flag
Jan 31, 2019
22c1242
bpf: Introduce bpf sk local storage
iamkafai Apr 26, 2019
08a55ab
net: socket: add __sys_getsockopt() helper; remove in-kernel call to …
Mar 13, 2018
17e908c
net: socket: add __sys_setsockopt() helper; remove in-kernel call to …
Mar 13, 2018
1beb6ac
bpf: implement getsockopt and setsockopt hooks
fomichev Jun 27, 2019
86abee8
bpf: sockmap, refactor sockmap routines to work with hashmap
jrfastab May 14, 2018
7a43760
bpf: sockmap, add hash map support
jrfastab May 14, 2018
7686370
sockmap: convert refcnt to an atomic refcnt
jrfastab Mar 18, 2018
a077c15
net: do_tcp_sendpages flag to avoid SKBTX_SHARED_FRAG
jrfastab Mar 18, 2018
9064ce5
sock: make static tls function alloc_sg generic sock helper
jrfastab Mar 18, 2018
bec5be9
net: generalize sk_alloc_sg to work with scatterlist rings
jrfastab Mar 18, 2018
ece8434
lib/scatterlist: add sg_init_marker() helper
pbhole Mar 30, 2018
4b8a3e8
bpf: sockmap: fix typos
roberto-sartori-gl Oct 26, 2024
2c716c2
bpf: sockmap, convert bpf_compute_data_pointers to bpf_*_sk_skb
jrfastab Jul 5, 2018
a46f94e
bpf, sockmap: convert to generic sk_msg interface
borkmann Oct 13, 2018
73d7589
bpf: always allocate at least 16 bytes for setsockopt hook
fomichev Jul 29, 2019
75625a4
bpf: Don't return EINVAL from {get,set}sockopt when optlen > PAGE_SIZE
fomichev Jun 17, 2020
ff2809b
bpf: Add bpf_verifier_vlog() and bpf_verifier_log_needed()
iamkafai Mar 24, 2018
2998e26
bpf: implement lookup-free direct value access for maps
borkmann Apr 9, 2019
8c567b9
bpf: allow helpers to return PTR_TO_SOCK_COMMON
lmb Mar 22, 2019
57e51a8
net/wireless: genregdb.awk: remove certain flags
backslashxx Feb 8, 2025
739e4d7
Reapply "syscall: Fake uname to 4.19 for bpfloader/netd"
backslashxx Feb 9, 2025
a88cbac
Reapply "syscall: Fake uname to 4.19 also for netbpfload"
backslashxx Feb 9, 2025
e921ac9
Reapply "syscall: Increase bpf fake uname to 5.4"
backslashxx Feb 9, 2025
51a53f7
syscall: Increase bpf fake uname to 5.4.186
Linux4 Jun 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Documentation/networking/00-INDEX
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ x25.txt
- general info on X.25 development.
x25-iface.txt
- description of the X.25 Packet Layer to LAPB device interface.
xfrm_device.txt
- description of XFRM offload API
xfrm_proc.txt
- description of the statistics package for XFRM.
xfrm_sync.txt
Expand Down
132 changes: 132 additions & 0 deletions Documentation/networking/xfrm_device.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@

===============================================
XFRM device - offloading the IPsec computations
===============================================
Shannon Nelson <[email protected]>


Overview
========

IPsec is a useful feature for securing network traffic, but the
computational cost is high: a 10Gbps link can easily be brought down
to under 1Gbps, depending on the traffic and link configuration.
Luckily, there are NICs that offer a hardware based IPsec offload which
can radically increase throughput and decrease CPU utilization. The XFRM
Device interface allows NIC drivers to offer to the stack access to the
hardware offload.

Userland access to the offload is typically through a system such as
libreswan or KAME/raccoon, but the iproute2 'ip xfrm' command set can
be handy when experimenting. An example command might look something
like this:

ip x s add proto esp dst 14.0.0.70 src 14.0.0.52 spi 0x07 mode transport \
reqid 0x07 replay-window 32 \
aead 'rfc4106(gcm(aes))' 0x44434241343332312423222114131211f4f3f2f1 128 \
sel src 14.0.0.52/24 dst 14.0.0.70/24 proto tcp \
offload dev eth4 dir in

Yes, that's ugly, but that's what shell scripts and/or libreswan are for.



Callbacks to implement
======================

/* from include/linux/netdevice.h */
struct xfrmdev_ops {
int (*xdo_dev_state_add) (struct xfrm_state *x);
void (*xdo_dev_state_delete) (struct xfrm_state *x);
void (*xdo_dev_state_free) (struct xfrm_state *x);
bool (*xdo_dev_offload_ok) (struct sk_buff *skb,
struct xfrm_state *x);
};

The NIC driver offering ipsec offload will need to implement these
callbacks to make the offload available to the network stack's
XFRM subsytem. Additionally, the feature bits NETIF_F_HW_ESP and
NETIF_F_HW_ESP_TX_CSUM will signal the availability of the offload.



Flow
====

At probe time and before the call to register_netdev(), the driver should
set up local data structures and XFRM callbacks, and set the feature bits.
The XFRM code's listener will finish the setup on NETDEV_REGISTER.

adapter->netdev->xfrmdev_ops = &ixgbe_xfrmdev_ops;
adapter->netdev->features |= NETIF_F_HW_ESP;
adapter->netdev->hw_enc_features |= NETIF_F_HW_ESP;

When new SAs are set up with a request for "offload" feature, the
driver's xdo_dev_state_add() will be given the new SA to be offloaded
and an indication of whether it is for Rx or Tx. The driver should
- verify the algorithm is supported for offloads
- store the SA information (key, salt, target-ip, protocol, etc)
- enable the HW offload of the SA

The driver can also set an offload_handle in the SA, an opaque void pointer
that can be used to convey context into the fast-path offload requests.

xs->xso.offload_handle = context;


When the network stack is preparing an IPsec packet for an SA that has
been setup for offload, it first calls into xdo_dev_offload_ok() with
the skb and the intended offload state to ask the driver if the offload
will serviceable. This can check the packet information to be sure the
offload can be supported (e.g. IPv4 or IPv6, no IPv4 options, etc) and
return true of false to signify its support.

When ready to send, the driver needs to inspect the Tx packet for the
offload information, including the opaque context, and set up the packet
send accordingly.

xs = xfrm_input_state(skb);
context = xs->xso.offload_handle;
set up HW for send

The stack has already inserted the appropriate IPsec headers in the
packet data, the offload just needs to do the encryption and fix up the
header values.


When a packet is received and the HW has indicated that it offloaded a
decryption, the driver needs to add a reference to the decoded SA into
the packet's skb. At this point the data should be decrypted but the
IPsec headers are still in the packet data; they are removed later up
the stack in xfrm_input().

find and hold the SA that was used to the Rx skb
get spi, protocol, and destination IP from packet headers
xs = find xs from (spi, protocol, dest_IP)
xfrm_state_hold(xs);

store the state information into the skb
skb->sp = secpath_dup(skb->sp);
skb->sp->xvec[skb->sp->len++] = xs;
skb->sp->olen++;

indicate the success and/or error status of the offload
xo = xfrm_offload(skb);
xo->flags = CRYPTO_DONE;
xo->status = crypto_status;

hand the packet to napi_gro_receive() as usual


When the SA is removed by the user, the driver's xdo_dev_state_delete()
is asked to disable the offload. Later, xdo_dev_state_free() is called
from a garbage collection routine after all reference counts to the state
have been removed and any remaining resources can be cleared for the
offload state. How these are used by the driver will depend on specific
hardware needs.

As a netdev is set to DOWN the XFRM stack's netdev listener will call
xdo_dev_state_delete() and xdo_dev_state_free() on any remaining offloaded
states.


2 changes: 1 addition & 1 deletion arch/arm/net/bpf_jit_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
/* If BPF JIT was not enabled then we must fall back to
* the interpreter.
*/
if (!bpf_jit_enable)
if (!prog->jit_requested)
return orig_prog;

/* If constant blinding was enabled and we failed during blinding
Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/net/bpf_jit_comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
int image_size;
u8 *image_ptr;

if (!bpf_jit_enable)
if (!prog->jit_requested)
return orig_prog;

tmp = bpf_jit_blind_constants(prog);
Expand Down
2 changes: 1 addition & 1 deletion arch/s390/net/bpf_jit_comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
struct bpf_jit jit;
int pass;

if (!bpf_jit_enable)
if (!fp->jit_requested)
return orig_fp;

tmp = bpf_jit_blind_constants(fp);
Expand Down
2 changes: 1 addition & 1 deletion arch/sparc/net/bpf_jit_comp_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
u8 *image_ptr;
int pass;

if (!bpf_jit_enable)
if (!prog->jit_requested)
return orig_prog;

tmp = bpf_jit_blind_constants(prog);
Expand Down
51 changes: 47 additions & 4 deletions arch/x86/net/bpf_jit_comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1129,19 +1129,29 @@ xadd: if (is_imm8(insn->off))
return proglen;
}

struct x64_jit_data {
struct bpf_binary_header *header;
int *addrs;
u8 *image;
int proglen;
struct jit_context ctx;
};

struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
{
struct bpf_binary_header *header = NULL;
struct bpf_prog *tmp, *orig_prog = prog;
struct x64_jit_data *jit_data;
int proglen, oldproglen = 0;
struct jit_context ctx = {};
bool tmp_blinded = false;
bool extra_pass = false;
u8 *image = NULL;
int *addrs;
int pass;
int i;

if (!bpf_jit_enable)
if (!prog->jit_requested)
return orig_prog;

tmp = bpf_jit_blind_constants(prog);
Expand All @@ -1155,10 +1165,28 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
prog = tmp;
}

jit_data = prog->aux->jit_data;
if (!jit_data) {
jit_data = kzalloc(sizeof(*jit_data), GFP_KERNEL);
if (!jit_data) {
prog = orig_prog;
goto out;
}
prog->aux->jit_data = jit_data;
}
addrs = jit_data->addrs;
if (addrs) {
ctx = jit_data->ctx;
oldproglen = jit_data->proglen;
image = jit_data->image;
header = jit_data->header;
extra_pass = true;
goto skip_init_addrs;
}
addrs = kmalloc(prog->len * sizeof(*addrs), GFP_KERNEL);
if (!addrs) {
prog = orig_prog;
goto out;
goto out_addrs;
}

/* Before first pass, make a rough estimation of addrs[]
Expand All @@ -1170,6 +1198,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
}
ctx.cleanup_addr = proglen;

skip_init_addrs:
/* JITed image shrinks with every pass and the loop iterates
* until the image stops shrinking. Very large bpf programs
* may converge on the last pass. In such case do one more
Expand Down Expand Up @@ -1210,16 +1239,30 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)

if (image) {
bpf_flush_icache(header, image + proglen);
bpf_jit_binary_lock_ro(header);
if (!prog->is_func || extra_pass) {
bpf_jit_binary_lock_ro(header);
} else {
jit_data->addrs = addrs;
jit_data->ctx = ctx;
jit_data->proglen = proglen;
jit_data->image = image;
jit_data->header = header;
}
prog->bpf_func = (void *)image;
prog->jited = 1;
prog->jited_len = proglen;
} else {
prog = orig_prog;
}

if (!image || !prog->is_func || extra_pass) {
if (image)
bpf_prog_fill_jited_linfo(prog, addrs);
out_addrs:
kfree(addrs);
kfree(addrs);
kfree(jit_data);
prog->aux->jit_data = NULL;
}
out:
if (tmp_blinded)
bpf_jit_prog_release_other(prog, prog == orig_prog ?
Expand Down
1 change: 1 addition & 0 deletions drivers/net/tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,

xdp.data_hard_start = buf;
xdp.data = buf + pad;
xdp_set_data_meta_invalid(&xdp);
xdp.data_end = xdp.data + len;
orig_data = xdp.data;
act = bpf_prog_run_xdp(xdp_prog, &xdp);
Expand Down
2 changes: 2 additions & 0 deletions drivers/net/virtio_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ static struct sk_buff *receive_small(struct net_device *dev,

xdp.data_hard_start = buf + VIRTNET_RX_PAD + vi->hdr_len;
xdp.data = xdp.data_hard_start + xdp_headroom;
xdp_set_data_meta_invalid(&xdp);
xdp.data_end = xdp.data + len;
orig_data = xdp.data;
act = bpf_prog_run_xdp(xdp_prog, &xdp);
Expand Down Expand Up @@ -673,6 +674,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
data = page_address(xdp_page) + offset;
xdp.data_hard_start = data - VIRTIO_XDP_HEADROOM + vi->hdr_len;
xdp.data = data + vi->hdr_len;
xdp_set_data_meta_invalid(&xdp);
xdp.data_end = xdp.data + (len - vi->hdr_len);
act = bpf_prog_run_xdp(xdp_prog, &xdp);

Expand Down
20 changes: 20 additions & 0 deletions fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -3052,6 +3052,26 @@ int vfs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
}
EXPORT_SYMBOL(vfs_create);

int vfs_mkobj(struct dentry *dentry, umode_t mode,
int (*f)(struct dentry *, umode_t, void *),
void *arg)
{
struct inode *dir = dentry->d_parent->d_inode;
int error = may_create(NULL, dir, dentry);
if (error)
return error;
mode &= S_IALLUGO;
mode |= S_IFREG;
error = security_inode_create(dir, dentry, mode);
if (error)
return error;
error = f(dentry, mode, arg);
if (!error)
fsnotify_create(dir, dentry);
return error;
}
EXPORT_SYMBOL(vfs_mkobj);

bool may_open_dev(const struct path *path)
{
return !(path->mnt->mnt_flags & MNT_NODEV) &&
Expand Down
Loading