Skip to content

Commit f7578df

Browse files
committed
Daniel Borkmann says: ==================== pull-request: bpf 2024-07-25 We've added 14 non-merge commits during the last 8 day(s) which contain a total of 19 files changed, 177 insertions(+), 70 deletions(-). The main changes are: 1) Fix af_unix to disable MSG_OOB handling for sockets in BPF sockmap and BPF sockhash. Also add test coverage for this case, from Michal Luczaj. 2) Fix a segmentation issue when downgrading gso_size in the BPF helper bpf_skb_adjust_room(), from Fred Li. 3) Fix a compiler warning in resolve_btfids due to a missing type cast, from Liwei Song. 4) Fix stack allocation for arm64 to align the stack pointer at a 16 byte boundary in the fexit_sleep BPF selftest, from Puranjay Mohan. 5) Fix a xsk regression to require a flag when actuating tx_metadata_len, from Stanislav Fomichev. 6) Fix function prototype BTF dumping in libbpf for prototypes that have no input arguments, from Andrii Nakryiko. 7) Fix stacktrace symbol resolution in perf script for BPF programs containing subprograms, from Hou Tao. * tag 'for-netdev' of https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf: selftests/bpf: Add XDP_UMEM_TX_METADATA_LEN to XSK TX metadata test xsk: Require XDP_UMEM_TX_METADATA_LEN to actuate tx_metadata_len bpf: Fix a segment issue when downgrading gso_size tools/resolve_btfids: Fix comparison of distinct pointer types warning in resolve_btfids bpf, events: Use prog to emit ksymbol event for main program selftests/bpf: Test sockmap redirect for AF_UNIX MSG_OOB selftests/bpf: Parametrize AF_UNIX redir functions to accept send() flags selftests/bpf: Support SOCK_STREAM in unix_inet_redir_to_connected() af_unix: Disable MSG_OOB handling for sockets in sockmap/sockhash bpftool: Fix typo in usage help libbpf: Fix no-args func prototype BTF dumping syntax MAINTAINERS: Update powerpc BPF JIT maintainers MAINTAINERS: Update email address of Naveen selftests/bpf: fexit_sleep: Fix stack allocation for arm64 ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents c166829 + 9b9969c commit f7578df

File tree

19 files changed

+177
-70
lines changed

19 files changed

+177
-70
lines changed

.mailmap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ Nadia Yvette Chambers <[email protected]> William Lee Irwin III <wli@holomorphy
474474
475475
476476
477+
478+
477479
478480
479481

Documentation/networking/xsk-tx-metadata.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ metadata on the receive side.
1111
General Design
1212
==============
1313

14-
The headroom for the metadata is reserved via ``tx_metadata_len`` in
15-
``struct xdp_umem_reg``. The metadata length is therefore the same for
16-
every socket that shares the same umem. The metadata layout is a fixed UAPI,
17-
refer to ``union xsk_tx_metadata`` in ``include/uapi/linux/if_xdp.h``.
18-
Thus, generally, the ``tx_metadata_len`` field above should contain
19-
``sizeof(union xsk_tx_metadata)``.
14+
The headroom for the metadata is reserved via ``tx_metadata_len`` and
15+
``XDP_UMEM_TX_METADATA_LEN`` flag in ``struct xdp_umem_reg``. The metadata
16+
length is therefore the same for every socket that shares the same umem.
17+
The metadata layout is a fixed UAPI, refer to ``union xsk_tx_metadata`` in
18+
``include/uapi/linux/if_xdp.h``. Thus, generally, the ``tx_metadata_len``
19+
field above should contain ``sizeof(union xsk_tx_metadata)``.
20+
21+
Note that in the original implementation the ``XDP_UMEM_TX_METADATA_LEN``
22+
flag was not required. Applications might attempt to create a umem
23+
with a flag first and if it fails, do another attempt without a flag.
2024

2125
The headroom and the metadata itself should be located right before
2226
``xdp_desc->addr`` in the umem frame. Within a frame, the metadata

MAINTAINERS

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3946,8 +3946,10 @@ S: Odd Fixes
39463946
F: drivers/net/ethernet/netronome/nfp/bpf/
39473947

39483948
BPF JIT for POWERPC (32-BIT AND 64-BIT)
3949-
M: Naveen N. Rao <[email protected]>
39503949
M: Michael Ellerman <[email protected]>
3950+
M: Hari Bathini <[email protected]>
3951+
M: Christophe Leroy <[email protected]>
3952+
R: Naveen N Rao <[email protected]>
39513953
39523954
S: Supported
39533955
F: arch/powerpc/net/
@@ -12484,7 +12486,7 @@ F: mm/kmsan/
1248412486
F: scripts/Makefile.kmsan
1248512487

1248612488
KPROBES
12487-
M: Naveen N. Rao <naveen[email protected]>
12489+
M: Naveen N Rao <naveen@kernel.org>
1248812490
M: Anil S Keshavamurthy <[email protected]>
1248912491
M: "David S. Miller" <[email protected]>
1249012492
M: Masami Hiramatsu <[email protected]>
@@ -12861,7 +12863,7 @@ LINUX FOR POWERPC (32-BIT AND 64-BIT)
1286112863
M: Michael Ellerman <[email protected]>
1286212864
R: Nicholas Piggin <[email protected]>
1286312865
R: Christophe Leroy <[email protected]>
12864-
R: Naveen N. Rao <naveen[email protected]>
12866+
R: Naveen N Rao <naveen@kernel.org>
1286512867
1286612868
S: Supported
1286712869
W: https://github.com/linuxppc/wiki/wiki

include/uapi/linux/if_xdp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
*/
4242
#define XDP_UMEM_TX_SW_CSUM (1 << 1)
4343

44+
/* Request to reserve tx_metadata_len bytes of per-chunk metadata.
45+
*/
46+
#define XDP_UMEM_TX_METADATA_LEN (1 << 2)
47+
4448
struct sockaddr_xdp {
4549
__u16 sxdp_family;
4650
__u16 sxdp_flags;

kernel/events/core.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9327,21 +9327,19 @@ static void perf_event_bpf_emit_ksymbols(struct bpf_prog *prog,
93279327
bool unregister = type == PERF_BPF_EVENT_PROG_UNLOAD;
93289328
int i;
93299329

9330-
if (prog->aux->func_cnt == 0) {
9331-
perf_event_ksymbol(PERF_RECORD_KSYMBOL_TYPE_BPF,
9332-
(u64)(unsigned long)prog->bpf_func,
9333-
prog->jited_len, unregister,
9334-
prog->aux->ksym.name);
9335-
} else {
9336-
for (i = 0; i < prog->aux->func_cnt; i++) {
9337-
struct bpf_prog *subprog = prog->aux->func[i];
9338-
9339-
perf_event_ksymbol(
9340-
PERF_RECORD_KSYMBOL_TYPE_BPF,
9341-
(u64)(unsigned long)subprog->bpf_func,
9342-
subprog->jited_len, unregister,
9343-
subprog->aux->ksym.name);
9344-
}
9330+
perf_event_ksymbol(PERF_RECORD_KSYMBOL_TYPE_BPF,
9331+
(u64)(unsigned long)prog->bpf_func,
9332+
prog->jited_len, unregister,
9333+
prog->aux->ksym.name);
9334+
9335+
for (i = 1; i < prog->aux->func_cnt; i++) {
9336+
struct bpf_prog *subprog = prog->aux->func[i];
9337+
9338+
perf_event_ksymbol(
9339+
PERF_RECORD_KSYMBOL_TYPE_BPF,
9340+
(u64)(unsigned long)subprog->bpf_func,
9341+
subprog->jited_len, unregister,
9342+
subprog->aux->ksym.name);
93459343
}
93469344
}
93479345

net/core/filter.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3548,13 +3548,20 @@ static int bpf_skb_net_grow(struct sk_buff *skb, u32 off, u32 len_diff,
35483548
if (skb_is_gso(skb)) {
35493549
struct skb_shared_info *shinfo = skb_shinfo(skb);
35503550

3551-
/* Due to header grow, MSS needs to be downgraded. */
3552-
if (!(flags & BPF_F_ADJ_ROOM_FIXED_GSO))
3553-
skb_decrease_gso_size(shinfo, len_diff);
3554-
35553551
/* Header must be checked, and gso_segs recomputed. */
35563552
shinfo->gso_type |= gso_type;
35573553
shinfo->gso_segs = 0;
3554+
3555+
/* Due to header growth, MSS needs to be downgraded.
3556+
* There is a BUG_ON() when segmenting the frag_list with
3557+
* head_frag true, so linearize the skb after downgrading
3558+
* the MSS.
3559+
*/
3560+
if (!(flags & BPF_F_ADJ_ROOM_FIXED_GSO)) {
3561+
skb_decrease_gso_size(shinfo, len_diff);
3562+
if (shinfo->frag_list)
3563+
return skb_linearize(skb);
3564+
}
35583565
}
35593566

35603567
return 0;

net/unix/af_unix.c

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2721,10 +2721,49 @@ static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk,
27212721

27222722
static int unix_stream_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
27232723
{
2724+
struct unix_sock *u = unix_sk(sk);
2725+
struct sk_buff *skb;
2726+
int err;
2727+
27242728
if (unlikely(READ_ONCE(sk->sk_state) != TCP_ESTABLISHED))
27252729
return -ENOTCONN;
27262730

2727-
return unix_read_skb(sk, recv_actor);
2731+
mutex_lock(&u->iolock);
2732+
skb = skb_recv_datagram(sk, MSG_DONTWAIT, &err);
2733+
mutex_unlock(&u->iolock);
2734+
if (!skb)
2735+
return err;
2736+
2737+
#if IS_ENABLED(CONFIG_AF_UNIX_OOB)
2738+
if (unlikely(skb == READ_ONCE(u->oob_skb))) {
2739+
bool drop = false;
2740+
2741+
unix_state_lock(sk);
2742+
2743+
if (sock_flag(sk, SOCK_DEAD)) {
2744+
unix_state_unlock(sk);
2745+
kfree_skb(skb);
2746+
return -ECONNRESET;
2747+
}
2748+
2749+
spin_lock(&sk->sk_receive_queue.lock);
2750+
if (likely(skb == u->oob_skb)) {
2751+
WRITE_ONCE(u->oob_skb, NULL);
2752+
drop = true;
2753+
}
2754+
spin_unlock(&sk->sk_receive_queue.lock);
2755+
2756+
unix_state_unlock(sk);
2757+
2758+
if (drop) {
2759+
WARN_ON_ONCE(skb_unref(skb));
2760+
kfree_skb(skb);
2761+
return -EAGAIN;
2762+
}
2763+
}
2764+
#endif
2765+
2766+
return recv_actor(sk, skb);
27282767
}
27292768

27302769
static int unix_stream_read_generic(struct unix_stream_read_state *state,

net/unix/unix_bpf.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ static int unix_bpf_recvmsg(struct sock *sk, struct msghdr *msg,
5454
struct sk_psock *psock;
5555
int copied;
5656

57+
if (flags & MSG_OOB)
58+
return -EOPNOTSUPP;
59+
5760
if (!len)
5861
return 0;
5962

net/xdp/xdp_umem.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ static int xdp_umem_account_pages(struct xdp_umem *umem)
151151
#define XDP_UMEM_FLAGS_VALID ( \
152152
XDP_UMEM_UNALIGNED_CHUNK_FLAG | \
153153
XDP_UMEM_TX_SW_CSUM | \
154+
XDP_UMEM_TX_METADATA_LEN | \
154155
0)
155156

156157
static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr)
@@ -204,8 +205,11 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr)
204205
if (headroom >= chunk_size - XDP_PACKET_HEADROOM)
205206
return -EINVAL;
206207

207-
if (mr->tx_metadata_len >= 256 || mr->tx_metadata_len % 8)
208-
return -EINVAL;
208+
if (mr->flags & XDP_UMEM_TX_METADATA_LEN) {
209+
if (mr->tx_metadata_len >= 256 || mr->tx_metadata_len % 8)
210+
return -EINVAL;
211+
umem->tx_metadata_len = mr->tx_metadata_len;
212+
}
209213

210214
umem->size = size;
211215
umem->headroom = headroom;
@@ -215,7 +219,6 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr)
215219
umem->pgs = NULL;
216220
umem->user = NULL;
217221
umem->flags = mr->flags;
218-
umem->tx_metadata_len = mr->tx_metadata_len;
219222

220223
INIT_LIST_HEAD(&umem->xsk_dma_list);
221224
refcount_set(&umem->users, 1);

tools/bpf/bpftool/prog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2489,7 +2489,7 @@ static int do_help(int argc, char **argv)
24892489
" cgroup/connect_unix | cgroup/getpeername4 | cgroup/getpeername6 |\n"
24902490
" cgroup/getpeername_unix | cgroup/getsockname4 | cgroup/getsockname6 |\n"
24912491
" cgroup/getsockname_unix | cgroup/sendmsg4 | cgroup/sendmsg6 |\n"
2492-
" cgroup/sendmsg°unix | cgroup/recvmsg4 | cgroup/recvmsg6 | cgroup/recvmsg_unix |\n"
2492+
" cgroup/sendmsg_unix | cgroup/recvmsg4 | cgroup/recvmsg6 | cgroup/recvmsg_unix |\n"
24932493
" cgroup/getsockopt | cgroup/setsockopt | cgroup/sock_release |\n"
24942494
" struct_ops | fentry | fexit | freplace | sk_lookup }\n"
24952495
" ATTACH_TYPE := { sk_msg_verdict | sk_skb_verdict | sk_skb_stream_verdict |\n"

0 commit comments

Comments
 (0)