Commit 757b56a6 authored by Jakub Kicinski's avatar Jakub Kicinski

Merge tag 'for-netdev' of https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf

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
====================

Link: https://lore.kernel.org/r/20230306215944.11981-1-daniel@iogearbox.netSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents e539a105 32dfc59e
...@@ -7,8 +7,8 @@ workflows related to reporting bugs, submitting patches, and queueing ...@@ -7,8 +7,8 @@ workflows related to reporting bugs, submitting patches, and queueing
patches for stable kernels. patches for stable kernels.
For general information about submitting patches, please refer to For general information about submitting patches, please refer to
`Documentation/process/`_. This document only describes additional specifics Documentation/process/submitting-patches.rst. This document only describes
related to BPF. additional specifics related to BPF.
.. contents:: .. contents::
:local: :local:
...@@ -461,15 +461,15 @@ needed:: ...@@ -461,15 +461,15 @@ needed::
$ sudo make run_tests $ sudo make run_tests
See the kernels selftest `Documentation/dev-tools/kselftest.rst`_ See :doc:`kernel selftest documentation </dev-tools/kselftest>`
document for further documentation. for details.
To maximize the number of tests passing, the .config of the kernel To maximize the number of tests passing, the .config of the kernel
under test should match the config file fragment in under test should match the config file fragment in
tools/testing/selftests/bpf as closely as possible. tools/testing/selftests/bpf as closely as possible.
Finally to ensure support for latest BPF Type Format features - Finally to ensure support for latest BPF Type Format features -
discussed in `Documentation/bpf/btf.rst`_ - pahole version 1.16 discussed in Documentation/bpf/btf.rst - pahole version 1.16
is required for kernels built with CONFIG_DEBUG_INFO_BTF=y. is required for kernels built with CONFIG_DEBUG_INFO_BTF=y.
pahole is delivered in the dwarves package or can be built pahole is delivered in the dwarves package or can be built
from source at from source at
...@@ -684,12 +684,8 @@ when: ...@@ -684,12 +684,8 @@ when:
.. Links .. Links
.. _Documentation/process/: https://www.kernel.org/doc/html/latest/process/
.. _netdev-FAQ: Documentation/process/maintainer-netdev.rst .. _netdev-FAQ: Documentation/process/maintainer-netdev.rst
.. _selftests: .. _selftests:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/testing/selftests/bpf/ https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/testing/selftests/bpf/
.. _Documentation/dev-tools/kselftest.rst:
https://www.kernel.org/doc/html/latest/dev-tools/kselftest.html
.. _Documentation/bpf/btf.rst: btf.rst
Happy BPF hacking! Happy BPF hacking!
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <linux/filter.h> #include <linux/filter.h>
#include <linux/memory.h> #include <linux/memory.h>
#include <linux/stop_machine.h> #include <linux/stop_machine.h>
#include <asm/patch.h>
#include "bpf_jit.h" #include "bpf_jit.h"
#define RV_REG_TCC RV_REG_A6 #define RV_REG_TCC RV_REG_A6
......
...@@ -4569,6 +4569,7 @@ static int btf_datasec_resolve(struct btf_verifier_env *env, ...@@ -4569,6 +4569,7 @@ static int btf_datasec_resolve(struct btf_verifier_env *env,
struct btf *btf = env->btf; struct btf *btf = env->btf;
u16 i; u16 i;
env->resolve_mode = RESOLVE_TBD;
for_each_vsi_from(i, v->next_member, v->t, vsi) { for_each_vsi_from(i, v->next_member, v->t, vsi) {
u32 var_type_id = vsi->type, type_id, type_size = 0; u32 var_type_id = vsi->type, type_id, type_size = 0;
const struct btf_type *var_type = btf_type_by_id(env->btf, const struct btf_type *var_type = btf_type_by_id(env->btf,
......
...@@ -97,8 +97,11 @@ static bool bpf_test_timer_continue(struct bpf_test_timer *t, int iterations, ...@@ -97,8 +97,11 @@ static bool bpf_test_timer_continue(struct bpf_test_timer *t, int iterations,
struct xdp_page_head { struct xdp_page_head {
struct xdp_buff orig_ctx; struct xdp_buff orig_ctx;
struct xdp_buff ctx; struct xdp_buff ctx;
struct xdp_frame frm; union {
u8 data[]; /* ::data_hard_start starts here */
DECLARE_FLEX_ARRAY(struct xdp_frame, frame);
DECLARE_FLEX_ARRAY(u8, data);
};
}; };
struct xdp_test_data { struct xdp_test_data {
...@@ -113,6 +116,10 @@ struct xdp_test_data { ...@@ -113,6 +116,10 @@ struct xdp_test_data {
u32 frame_cnt; u32 frame_cnt;
}; };
/* tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c:%MAX_PKT_SIZE
* must be updated accordingly this gets changed, otherwise BPF selftests
* will fail.
*/
#define TEST_XDP_FRAME_SIZE (PAGE_SIZE - sizeof(struct xdp_page_head)) #define TEST_XDP_FRAME_SIZE (PAGE_SIZE - sizeof(struct xdp_page_head))
#define TEST_XDP_MAX_BATCH 256 #define TEST_XDP_MAX_BATCH 256
...@@ -132,8 +139,8 @@ static void xdp_test_run_init_page(struct page *page, void *arg) ...@@ -132,8 +139,8 @@ static void xdp_test_run_init_page(struct page *page, void *arg)
headroom -= meta_len; headroom -= meta_len;
new_ctx = &head->ctx; new_ctx = &head->ctx;
frm = &head->frm; frm = head->frame;
data = &head->data; data = head->data;
memcpy(data + headroom, orig_ctx->data_meta, frm_len); memcpy(data + headroom, orig_ctx->data_meta, frm_len);
xdp_init_buff(new_ctx, TEST_XDP_FRAME_SIZE, &xdp->rxq); xdp_init_buff(new_ctx, TEST_XDP_FRAME_SIZE, &xdp->rxq);
...@@ -223,7 +230,7 @@ static void reset_ctx(struct xdp_page_head *head) ...@@ -223,7 +230,7 @@ static void reset_ctx(struct xdp_page_head *head)
head->ctx.data = head->orig_ctx.data; head->ctx.data = head->orig_ctx.data;
head->ctx.data_meta = head->orig_ctx.data_meta; head->ctx.data_meta = head->orig_ctx.data_meta;
head->ctx.data_end = head->orig_ctx.data_end; head->ctx.data_end = head->orig_ctx.data_end;
xdp_update_frame_from_buff(&head->ctx, &head->frm); xdp_update_frame_from_buff(&head->ctx, head->frame);
} }
static int xdp_recv_frames(struct xdp_frame **frames, int nframes, 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, ...@@ -285,7 +292,7 @@ static int xdp_test_run_batch(struct xdp_test_data *xdp, struct bpf_prog *prog,
head = phys_to_virt(page_to_phys(page)); head = phys_to_virt(page_to_phys(page));
reset_ctx(head); reset_ctx(head);
ctx = &head->ctx; ctx = &head->ctx;
frm = &head->frm; frm = head->frame;
xdp->frame_cnt++; xdp->frame_cnt++;
act = bpf_prog_run_xdp(prog, ctx); act = bpf_prog_run_xdp(prog, ctx);
......
...@@ -186,6 +186,9 @@ static int tcp_bpf_recvmsg_parser(struct sock *sk, ...@@ -186,6 +186,9 @@ static int tcp_bpf_recvmsg_parser(struct sock *sk,
if (unlikely(flags & MSG_ERRQUEUE)) if (unlikely(flags & MSG_ERRQUEUE))
return inet_recv_error(sk, msg, len, addr_len); return inet_recv_error(sk, msg, len, addr_len);
if (!len)
return 0;
psock = sk_psock_get(sk); psock = sk_psock_get(sk);
if (unlikely(!psock)) if (unlikely(!psock))
return tcp_recvmsg(sk, msg, len, flags, addr_len); 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, ...@@ -244,6 +247,9 @@ static int tcp_bpf_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
if (unlikely(flags & MSG_ERRQUEUE)) if (unlikely(flags & MSG_ERRQUEUE))
return inet_recv_error(sk, msg, len, addr_len); return inet_recv_error(sk, msg, len, addr_len);
if (!len)
return 0;
psock = sk_psock_get(sk); psock = sk_psock_get(sk);
if (unlikely(!psock)) if (unlikely(!psock))
return tcp_recvmsg(sk, msg, len, flags, addr_len); 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, ...@@ -68,6 +68,9 @@ static int udp_bpf_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
if (unlikely(flags & MSG_ERRQUEUE)) if (unlikely(flags & MSG_ERRQUEUE))
return inet_recv_error(sk, msg, len, addr_len); return inet_recv_error(sk, msg, len, addr_len);
if (!len)
return 0;
psock = sk_psock_get(sk); psock = sk_psock_get(sk);
if (unlikely(!psock)) if (unlikely(!psock))
return sk_udp_recvmsg(sk, msg, len, flags, addr_len); 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, ...@@ -54,6 +54,9 @@ static int unix_bpf_recvmsg(struct sock *sk, struct msghdr *msg,
struct sk_psock *psock; struct sk_psock *psock;
int copied; int copied;
if (!len)
return 0;
psock = sk_psock_get(sk); psock = sk_psock_get(sk);
if (unlikely(!psock)) if (unlikely(!psock))
return __unix_recvmsg(sk, msg, len, flags); return __unix_recvmsg(sk, msg, len, flags);
......
...@@ -879,6 +879,34 @@ static struct btf_raw_test raw_tests[] = { ...@@ -879,6 +879,34 @@ static struct btf_raw_test raw_tests[] = {
.btf_load_err = true, .btf_load_err = true,
.err_str = "Invalid elem", .err_str = "Invalid elem",
}, },
{
.descr = "var after datasec, ptr followed by modifier",
.raw_types = {
/* .bss section */ /* [1] */
BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 2),
sizeof(void*)+4),
BTF_VAR_SECINFO_ENC(4, 0, sizeof(void*)),
BTF_VAR_SECINFO_ENC(6, sizeof(void*), 4),
/* int */ /* [2] */
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
/* int* */ /* [3] */
BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 2),
BTF_VAR_ENC(NAME_TBD, 3, 0), /* [4] */
/* const int */ /* [5] */
BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 2),
BTF_VAR_ENC(NAME_TBD, 5, 0), /* [6] */
BTF_END_RAW,
},
.str_sec = "\0a\0b\0c\0",
.str_sec_size = sizeof("\0a\0b\0c\0"),
.map_type = BPF_MAP_TYPE_ARRAY,
.map_name = ".bss",
.key_size = sizeof(int),
.value_size = sizeof(void*)+4,
.key_type_id = 0,
.value_type_id = 1,
.max_entries = 1,
},
/* Test member exceeds the size of struct. /* Test member exceeds the size of struct.
* *
* struct A { * struct A {
......
...@@ -65,12 +65,13 @@ static int attach_tc_prog(struct bpf_tc_hook *hook, int fd) ...@@ -65,12 +65,13 @@ static int attach_tc_prog(struct bpf_tc_hook *hook, int fd)
} }
/* The maximum permissible size is: PAGE_SIZE - sizeof(struct xdp_page_head) - /* The maximum permissible size is: PAGE_SIZE - sizeof(struct xdp_page_head) -
* sizeof(struct skb_shared_info) - XDP_PACKET_HEADROOM = 3368 bytes * SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) - XDP_PACKET_HEADROOM =
* 3408 bytes for 64-byte cacheline and 3216 for 256-byte one.
*/ */
#if defined(__s390x__) #if defined(__s390x__)
#define MAX_PKT_SIZE 3176 #define MAX_PKT_SIZE 3216
#else #else
#define MAX_PKT_SIZE 3368 #define MAX_PKT_SIZE 3408
#endif #endif
static void test_max_pkt_size(int fd) static void test_max_pkt_size(int fd)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment