Skip to content

Commit 3b4defb

Browse files
author
CKI KWF Bot
committed
Merge: bpf: v6.16 stable backport
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/7460 JIRA: https://issues.redhat.com/browse/RHEL-110274 Depends: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/7354 Stable backports for the BPF subsystem from upstream kernel version 6.16. Omitted-fix: 4f596ac ("libbpf: Fix parsing of multi-split BTF") The fixed code is in libbpf which will be built only after the last stable backport to RHEL 9. Postponing this fix to the 6.17 stable backport. Signed-off-by: Viktor Malik <vmalik@redhat.com> Approved-by: Jerome Marchand <jmarchan@redhat.com> Approved-by: Gregory Bell <grbell@redhat.com> Approved-by: Toke Høiland-Jørgensen <toke@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: CKI GitLab Kmaint Pipeline Bot <26919896-cki-kmaint-pipeline-bot@users.noreply.gitlab.com>
2 parents 4bf46be + 64e1e3a commit 3b4defb

33 files changed

+805
-252
lines changed

Documentation/bpf/map_hash.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,16 @@ attempts in order to enforce the LRU property which have increasing impacts on
233233
other CPUs involved in the following operation attempts:
234234

235235
- Attempt to use CPU-local state to batch operations
236-
- Attempt to fetch free nodes from global lists
236+
- Attempt to fetch ``target_free`` free nodes from global lists
237237
- Attempt to pull any node from a global list and remove it from the hashmap
238238
- Attempt to pull any node from any CPU's list and remove it from the hashmap
239239

240+
The number of nodes to borrow from the global list in a batch, ``target_free``,
241+
depends on the size of the map. Larger batch size reduces lock contention, but
242+
may also exhaust the global structure. The value is computed at map init to
243+
avoid exhaustion, by limiting aggregate reservation by all CPUs to half the map
244+
size. With a minimum of a single element and maximum budget of 128 at a time.
245+
240246
This algorithm is described visually in the following diagram. See the
241247
description in commit 3a08c2fd7634 ("bpf: LRU List") for a full explanation of
242248
the corresponding operations:

Documentation/bpf/map_lru_hash_update.dot

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ digraph {
3535
fn_bpf_lru_list_pop_free_to_local [shape=rectangle,fillcolor=2,
3636
label="Flush local pending,
3737
Rotate Global list, move
38-
LOCAL_FREE_TARGET
38+
target_free
3939
from global -> local"]
4040
// Also corresponds to:
4141
// fn__local_list_flush()
4242
// fn_bpf_lru_list_rotate()
4343
fn___bpf_lru_node_move_to_free[shape=diamond,fillcolor=2,
44-
label="Able to free\nLOCAL_FREE_TARGET\nnodes?"]
44+
label="Able to free\ntarget_free\nnodes?"]
4545

4646
fn___bpf_lru_list_shrink_inactive [shape=rectangle,fillcolor=3,
4747
label="Shrink inactive list
4848
up to remaining
49-
LOCAL_FREE_TARGET
49+
target_free
5050
(global LRU -> local)"]
5151
fn___bpf_lru_list_shrink [shape=diamond,fillcolor=2,
5252
label="> 0 entries in\nlocal free list?"]

arch/s390/net/bpf_jit_comp.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,15 @@ static void bpf_jit_plt(struct bpf_plt *plt, void *ret, void *target)
544544
{
545545
memcpy(plt, &bpf_plt, sizeof(*plt));
546546
plt->ret = ret;
547-
plt->target = target;
547+
/*
548+
* (target == NULL) implies that the branch to this PLT entry was
549+
* patched and became a no-op. However, some CPU could have jumped
550+
* to this PLT entry before patching and may be still executing it.
551+
*
552+
* Since the intention in this case is to make the PLT entry a no-op,
553+
* make the target point to the return label instead of NULL.
554+
*/
555+
plt->target = target ?: ret;
548556
}
549557

550558
/*
@@ -605,17 +613,15 @@ static void bpf_jit_prologue(struct bpf_jit *jit, struct bpf_prog *fp,
605613
}
606614
/* Setup stack and backchain */
607615
if (is_first_pass(jit) || (jit->seen & SEEN_STACK)) {
608-
if (is_first_pass(jit) || (jit->seen & SEEN_FUNC))
609-
/* lgr %w1,%r15 (backchain) */
610-
EMIT4(0xb9040000, REG_W1, REG_15);
616+
/* lgr %w1,%r15 (backchain) */
617+
EMIT4(0xb9040000, REG_W1, REG_15);
611618
/* la %bfp,STK_160_UNUSED(%r15) (BPF frame pointer) */
612619
EMIT4_DISP(0x41000000, BPF_REG_FP, REG_15, STK_160_UNUSED);
613620
/* aghi %r15,-STK_OFF */
614621
EMIT4_IMM(0xa70b0000, REG_15, -(STK_OFF + stack_depth));
615-
if (is_first_pass(jit) || (jit->seen & SEEN_FUNC))
616-
/* stg %w1,152(%r15) (backchain) */
617-
EMIT6_DISP_LH(0xe3000000, 0x0024, REG_W1, REG_0,
618-
REG_15, 152);
622+
/* stg %w1,152(%r15) (backchain) */
623+
EMIT6_DISP_LH(0xe3000000, 0x0024, REG_W1, REG_0,
624+
REG_15, 152);
619625
}
620626
}
621627

include/linux/bpf_verifier.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,11 @@ enum {
361361
INSN_F_SPI_MASK = 0x3f, /* 6 bits */
362362
INSN_F_SPI_SHIFT = 3, /* shifted 3 bits to the left */
363363

364-
INSN_F_STACK_ACCESS = BIT(9), /* we need 10 bits total */
364+
INSN_F_STACK_ACCESS = BIT(9),
365+
366+
INSN_F_DST_REG_STACK = BIT(10), /* dst_reg is PTR_TO_STACK */
367+
INSN_F_SRC_REG_STACK = BIT(11), /* src_reg is PTR_TO_STACK */
368+
/* total 12 bits are used now. */
365369
};
366370

367371
static_assert(INSN_F_FRAMENO_MASK + 1 >= MAX_CALL_FRAMES);
@@ -370,9 +374,9 @@ static_assert(INSN_F_SPI_MASK + 1 >= MAX_BPF_STACK / 8);
370374
struct bpf_jmp_history_entry {
371375
u32 idx;
372376
/* insn idx can't be bigger than 1 million */
373-
u32 prev_idx : 22;
374-
/* special flags, e.g., whether insn is doing register stack spill/load */
375-
u32 flags : 10;
377+
u32 prev_idx : 20;
378+
/* special INSN_F_xxx flags */
379+
u32 flags : 12;
376380
/* additional registers that need precision tracking when this
377381
* jump is backtracked, vector of six 10-bit records
378382
*/

kernel/bpf/bpf_lru_list.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,12 @@ static void bpf_lru_list_pop_free_to_local(struct bpf_lru *lru,
337337
list) {
338338
__bpf_lru_node_move_to_free(l, node, local_free_list(loc_l),
339339
BPF_LRU_LOCAL_LIST_T_FREE);
340-
if (++nfree == LOCAL_FREE_TARGET)
340+
if (++nfree == lru->target_free)
341341
break;
342342
}
343343

344-
if (nfree < LOCAL_FREE_TARGET)
345-
__bpf_lru_list_shrink(lru, l, LOCAL_FREE_TARGET - nfree,
344+
if (nfree < lru->target_free)
345+
__bpf_lru_list_shrink(lru, l, lru->target_free - nfree,
346346
local_free_list(loc_l),
347347
BPF_LRU_LOCAL_LIST_T_FREE);
348348

@@ -577,6 +577,9 @@ static void bpf_common_lru_populate(struct bpf_lru *lru, void *buf,
577577
list_add(&node->list, &l->lists[BPF_LRU_LIST_T_FREE]);
578578
buf += elem_size;
579579
}
580+
581+
lru->target_free = clamp((nr_elems / num_possible_cpus()) / 2,
582+
1, LOCAL_FREE_TARGET);
580583
}
581584

582585
static void bpf_percpu_lru_populate(struct bpf_lru *lru, void *buf,

kernel/bpf/bpf_lru_list.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct bpf_lru {
5858
del_from_htab_func del_from_htab;
5959
void *del_arg;
6060
unsigned int hash_offset;
61+
unsigned int target_free;
6162
unsigned int nr_scans;
6263
bool percpu;
6364
};

kernel/bpf/bpf_struct_ops.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ int bpf_struct_ops_prepare_trampoline(struct bpf_tramp_links *tlinks,
577577
if (model->ret_size > 0)
578578
flags |= BPF_TRAMP_F_RET_FENTRY_RET;
579579

580-
size = arch_bpf_trampoline_size(model, flags, tlinks, NULL);
580+
size = arch_bpf_trampoline_size(model, flags, tlinks, stub_func);
581581
if (size <= 0)
582582
return size ? : -EFAULT;
583583

kernel/bpf/btf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6780,10 +6780,10 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type,
67806780
/* Is this a func with potential NULL args? */
67816781
if (strcmp(tname, raw_tp_null_args[i].func))
67826782
continue;
6783-
if (raw_tp_null_args[i].mask & (0x1 << (arg * 4)))
6783+
if (raw_tp_null_args[i].mask & (0x1ULL << (arg * 4)))
67846784
info->reg_type |= PTR_MAYBE_NULL;
67856785
/* Is the current arg IS_ERR? */
6786-
if (raw_tp_null_args[i].mask & (0x2 << (arg * 4)))
6786+
if (raw_tp_null_args[i].mask & (0x2ULL << (arg * 4)))
67876787
ptr_err_raw_tp = true;
67886788
break;
67896789
}

kernel/bpf/cgroup.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,22 +2404,22 @@ static bool cg_sockopt_is_valid_access(int off, int size,
24042404
}
24052405

24062406
switch (off) {
2407-
case offsetof(struct bpf_sockopt, sk):
2407+
case bpf_ctx_range_ptr(struct bpf_sockopt, sk):
24082408
if (size != sizeof(__u64))
24092409
return false;
24102410
info->reg_type = PTR_TO_SOCKET;
24112411
break;
2412-
case offsetof(struct bpf_sockopt, optval):
2412+
case bpf_ctx_range_ptr(struct bpf_sockopt, optval):
24132413
if (size != sizeof(__u64))
24142414
return false;
24152415
info->reg_type = PTR_TO_PACKET;
24162416
break;
2417-
case offsetof(struct bpf_sockopt, optval_end):
2417+
case bpf_ctx_range_ptr(struct bpf_sockopt, optval_end):
24182418
if (size != sizeof(__u64))
24192419
return false;
24202420
info->reg_type = PTR_TO_PACKET_END;
24212421
break;
2422-
case offsetof(struct bpf_sockopt, retval):
2422+
case bpf_ctx_range(struct bpf_sockopt, retval):
24232423
if (size != size_default)
24242424
return false;
24252425
return prog->expected_attach_type == BPF_CGROUP_GETSOCKOPT;

0 commit comments

Comments
 (0)