Daniel Borkmann says: ==================== pull-request: bpf 2023-03-06 We've added 8 non-merge commits during the last 7 day(s) which contain a total of 9 files changed, 64 insertions(+), 18 deletions(-). The main changes are: 1) Fix BTF resolver for DATASEC sections when a VAR points at a modifier, that is, keep resolving such instances instead of bailing out, from Lorenz Bauer. 2) Fix BPF test framework with regards to xdp_frame info misplacement in the "live packet" code, from Alexander Lobakin. 3) Fix an infinite loop in BPF sockmap code for TCP/UDP/AF_UNIX, from Liu Jian. 4) Fix a build error for riscv BPF JIT under PERF_EVENTS=n, from Randy Dunlap. 5) Several BPF doc fixes with either broken links or external instead of internal doc links, from Bagas Sanjaya. * tag 'for-netdev' of https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf: selftests/bpf: check that modifier resolves after pointer btf: fix resolving BTF_KIND_VAR after ARRAY, STRUCT, UNION, PTR bpf, test_run: fix &xdp_frame misplacement for LIVE_FRAMES bpf, doc: Link to submitting-patches.rst for general patch submission info bpf, doc: Do not link to docs.kernel.org for kselftest link bpf, sockmap: Fix an infinite loop error when len is 0 in tcp_bpf_recvmsg_parser() riscv, bpf: Fix patch_text implicit declaration bpf, docs: Fix link to BTF doc ====================
Unified · Split
| @@ -7,8 +7,8 @@ workflows related to reporting bugs, submitting patches, and queueing · 6 unmodified lines | ||
| 7 | 7 | patches for stable kernels. |
| 8 | 8 | |
| 9 | 9 | For general information about submitting patches, please refer to |
| 10 | −`Documentation/process/`_. This document only describes additional specifics | |
| 11 | −related to BPF. | |
| 10 | +Documentation/process/submitting-patches.rst. This document only describes | |
| 11 | +additional specifics related to BPF. | |
| 12 | 12 | |
| 13 | 13 | .. contents:: |
| 14 | 14 | :local: |
| @@ -461,15 +461,15 @@ needed:: · 446 unmodified lines | ||
| 461 | 461 | |
| 462 | 462 | $ sudo make run_tests |
| 463 | 463 | |
| 464 | −See the kernels selftest `Documentation/dev-tools/kselftest.rst`_ | |
| 465 | −document for further documentation. | |
| 464 | +See :doc:`kernel selftest documentation </dev-tools/kselftest>` | |
| 465 | +for details. | |
| 466 | 466 | |
| 467 | 467 | To maximize the number of tests passing, the .config of the kernel |
| 468 | 468 | under test should match the config file fragment in |
| 469 | 469 | tools/testing/selftests/bpf as closely as possible. |
| 470 | 470 | |
| 471 | 471 | Finally to ensure support for latest BPF Type Format features - |
| 472 | −discussed in `Documentation/bpf/btf.rst`_ - pahole version 1.16 | |
| 472 | +discussed in Documentation/bpf/btf.rst - pahole version 1.16 | |
| 473 | 473 | is required for kernels built with CONFIG_DEBUG_INFO_BTF=y. |
| 474 | 474 | pahole is delivered in the dwarves package or can be built |
| 475 | 475 | from source at |
| @@ -684,12 +684,8 @@ when: · 208 unmodified lines | ||
| 684 | 684 | |
| 685 | 685 | |
| 686 | 686 | .. Links |
| 687 | −.. _Documentation/process/: https://www.kernel.org/doc/html/latest/process/ | |
| 688 | 687 | .. _netdev-FAQ: Documentation/process/maintainer-netdev.rst |
| 689 | 688 | .. _selftests: |
| 690 | 689 | https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/testing/selftests/bpf/ |
| 691 | −.. _Documentation/dev-tools/kselftest.rst: | |
| 692 | − https://www.kernel.org/doc/html/latest/dev-tools/kselftest.html | |
| 693 | −.. _Documentation/bpf/btf.rst: btf.rst | |
| 694 | 690 | |
| 695 | 691 | Happy BPF hacking! |
| @@ -10,6 +10,7 @@ · 9 unmodified lines | ||
| 10 | 10 | #include <linux/filter.h> |
| 11 | 11 | #include <linux/memory.h> |
| 12 | 12 | #include <linux/stop_machine.h> |
| 13 | +#include <asm/patch.h> | |
| 13 | 14 | #include "bpf_jit.h" |
| 14 | 15 | |
| 15 | 16 | #define RV_REG_TCC RV_REG_A6 |
| @@ -4569,6 +4569,7 @@ static int btf_datasec_resolve(struct btf_verifier_env *env, · 4568 unmodified lines | ||
| 4569 | 4569 | struct btf *btf = env->btf; |
| 4570 | 4570 | u16 i; |
| 4571 | 4571 | |
| 4572 | + env->resolve_mode = RESOLVE_TBD; | |
| 4572 | 4573 | for_each_vsi_from(i, v->next_member, v->t, vsi) { |
| 4573 | 4574 | u32 var_type_id = vsi->type, type_id, type_size = 0; |
| 4574 | 4575 | const struct btf_type *var_type = btf_type_by_id(env->btf, |
| @@ -97,8 +97,11 @@ reset: · 96 unmodified lines | ||
| 97 | 97 | struct xdp_page_head { |
| 98 | 98 | struct xdp_buff orig_ctx; |
| 99 | 99 | struct xdp_buff ctx; |
| 100 | − struct xdp_frame frm; | |
| 101 | − u8 data[]; | |
| 100 | + union { | |
| 101 | + /* ::data_hard_start starts here */ | |
| 102 | + DECLARE_FLEX_ARRAY(struct xdp_frame, frame); | |
| 103 | + DECLARE_FLEX_ARRAY(u8, data); | |
| 104 | + }; | |
| 102 | 105 | }; |
| 103 | 106 | |
| 104 | 107 | struct xdp_test_data { |
| @@ -113,6 +116,10 @@ struct xdp_test_data { · 8 unmodified lines | ||
| 113 | 116 | u32 frame_cnt; |
| 114 | 117 | }; |
| 115 | 118 | |
| 119 | +/* tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c:%MAX_PKT_SIZE | |
| 120 | + * must be updated accordingly this gets changed, otherwise BPF selftests | |
| 121 | + * will fail. | |
| 122 | + */ | |
| 116 | 123 | #define TEST_XDP_FRAME_SIZE (PAGE_SIZE - sizeof(struct xdp_page_head)) |
| 117 | 124 | #define TEST_XDP_MAX_BATCH 256 |
| 118 | 125 | |
| @@ -132,8 +139,8 @@ static void xdp_test_run_init_page(struct page *page, void *arg) · 13 unmodified lines | ||
| 132 | 139 | headroom -= meta_len; |
| 133 | 140 | |
| 134 | 141 | new_ctx = &head->ctx; |
| 135 | − frm = &head->frm; | |
| 136 | − data = &head->data; | |
| 142 | + frm = head->frame; | |
| 143 | + data = head->data; | |
| 137 | 144 | memcpy(data + headroom, orig_ctx->data_meta, frm_len); |
| 138 | 145 | |
| 139 | 146 | xdp_init_buff(new_ctx, TEST_XDP_FRAME_SIZE, &xdp->rxq); |
| @@ -223,7 +230,7 @@ static void reset_ctx(struct xdp_page_head *head) · 83 unmodified lines | ||
| 223 | 230 | head->ctx.data = head->orig_ctx.data; |
| 224 | 231 | head->ctx.data_meta = head->orig_ctx.data_meta; |
| 225 | 232 | head->ctx.data_end = head->orig_ctx.data_end; |
| 226 | − xdp_update_frame_from_buff(&head->ctx, &head->frm); | |
| 233 | + xdp_update_frame_from_buff(&head->ctx, head->frame); | |
| 227 | 234 | } |
| 228 | 235 | |
| 229 | 236 | static int xdp_recv_frames(struct xdp_frame **frames, int nframes, |
| @@ -285,7 +292,7 @@ static int xdp_test_run_batch(struct xdp_test_data *xdp, struct bpf_prog *prog, · 55 unmodified lines | ||
| 285 | 292 | head = phys_to_virt(page_to_phys(page)); |
| 286 | 293 | reset_ctx(head); |
| 287 | 294 | ctx = &head->ctx; |
| 288 | − frm = &head->frm; | |
| 295 | + frm = head->frame; | |
| 289 | 296 | xdp->frame_cnt++; |
| 290 | 297 | |
| 291 | 298 | act = bpf_prog_run_xdp(prog, ctx); |
| @@ -186,6 +186,9 @@ static int tcp_bpf_recvmsg_parser(struct sock *sk, · 185 unmodified lines | ||
| 186 | 186 | if (unlikely(flags & MSG_ERRQUEUE)) |
| 187 | 187 | return inet_recv_error(sk, msg, len, addr_len); |
| 188 | 188 | |
| 189 | + if (!len) | |
| 190 | + return 0; | |
| 191 | + | |
| 189 | 192 | psock = sk_psock_get(sk); |
| 190 | 193 | if (unlikely(!psock)) |
| 191 | 194 | return tcp_recvmsg(sk, msg, len, flags, addr_len); |
| @@ -244,6 +247,9 @@ static int tcp_bpf_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, · 52 unmodified lines | ||
| 244 | 247 | if (unlikely(flags & MSG_ERRQUEUE)) |
| 245 | 248 | return inet_recv_error(sk, msg, len, addr_len); |
| 246 | 249 | |
| 250 | + if (!len) | |
| 251 | + return 0; | |
| 252 | + | |
| 247 | 253 | psock = sk_psock_get(sk); |
| 248 | 254 | if (unlikely(!psock)) |
| 249 | 255 | return tcp_recvmsg(sk, msg, len, flags, addr_len); |
| @@ -68,6 +68,9 @@ static int udp_bpf_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, · 67 unmodified lines | ||
| 68 | 68 | if (unlikely(flags & MSG_ERRQUEUE)) |
| 69 | 69 | return inet_recv_error(sk, msg, len, addr_len); |
| 70 | 70 | |
| 71 | + if (!len) | |
| 72 | + return 0; | |
| 73 | + | |
| 71 | 74 | psock = sk_psock_get(sk); |
| 72 | 75 | if (unlikely(!psock)) |
| 73 | 76 | return sk_udp_recvmsg(sk, msg, len, flags, addr_len); |
| @@ -54,6 +54,9 @@ static int unix_bpf_recvmsg(struct sock *sk, struct msghdr *msg, · 53 unmodified lines | ||
| 54 | 54 | struct sk_psock *psock; |
| 55 | 55 | int copied; |
| 56 | 56 | |
| 57 | + if (!len) | |
| 58 | + return 0; | |
| 59 | + | |
| 57 | 60 | psock = sk_psock_get(sk); |
| 58 | 61 | if (unlikely(!psock)) |
| 59 | 62 | return __unix_recvmsg(sk, msg, len, flags); |
| @@ -879,6 +879,34 @@ static struct btf_raw_test raw_tests[] = { · 878 unmodified lines | ||
| 879 | 879 | .btf_load_err = true, |
| 880 | 880 | .err_str = "Invalid elem", |
| 881 | 881 | }, |
| 882 | +{ | |
| 883 | + .descr = "var after datasec, ptr followed by modifier", | |
| 884 | + .raw_types = { | |
| 885 | + /* .bss section */ /* [1] */ | |
| 886 | + BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 2), | |
| 887 | + sizeof(void*)+4), | |
| 888 | + BTF_VAR_SECINFO_ENC(4, 0, sizeof(void*)), | |
| 889 | + BTF_VAR_SECINFO_ENC(6, sizeof(void*), 4), | |
| 890 | + /* int */ /* [2] */ | |
| 891 | + BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), | |
| 892 | + /* int* */ /* [3] */ | |
| 893 | + BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 2), | |
| 894 | + BTF_VAR_ENC(NAME_TBD, 3, 0), /* [4] */ | |
| 895 | + /* const int */ /* [5] */ | |
| 896 | + BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 2), | |
| 897 | + BTF_VAR_ENC(NAME_TBD, 5, 0), /* [6] */ | |
| 898 | + BTF_END_RAW, | |
| 899 | + }, | |
| 900 | + .str_sec = "\0a\0b\0c\0", | |
| 901 | + .str_sec_size = sizeof("\0a\0b\0c\0"), | |
| 902 | + .map_type = BPF_MAP_TYPE_ARRAY, | |
| 903 | + .map_name = ".bss", | |
| 904 | + .key_size = sizeof(int), | |
| 905 | + .value_size = sizeof(void*)+4, | |
| 906 | + .key_type_id = 0, | |
| 907 | + .value_type_id = 1, | |
| 908 | + .max_entries = 1, | |
| 909 | +}, | |
| 882 | 910 | /* Test member exceeds the size of struct. |
| 883 | 911 | * |
| 884 | 912 | * struct A { |
| @@ -65,12 +65,13 @@ static int attach_tc_prog(struct bpf_tc_hook *hook, int fd) · 64 unmodified lines | ||
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /* The maximum permissible size is: PAGE_SIZE - sizeof(struct xdp_page_head) - |
| 68 | − * sizeof(struct skb_shared_info) - XDP_PACKET_HEADROOM = 3368 bytes | |
| 68 | + * SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) - XDP_PACKET_HEADROOM = | |
| 69 | + * 3408 bytes for 64-byte cacheline and 3216 for 256-byte one. | |
| 69 | 70 | */ |
| 70 | 71 | #if defined(__s390x__) |
| 71 | −#define MAX_PKT_SIZE 3176 | |
| 72 | +#define MAX_PKT_SIZE 3216 | |
| 72 | 73 | #else |
| 73 | −#define MAX_PKT_SIZE 3368 | |
| 74 | +#define MAX_PKT_SIZE 3408 | |
| 74 | 75 | #endif |
| 75 | 76 | static void test_max_pkt_size(int fd) |
| 76 | 77 | { |