Skip to content

Commit a46107c

Browse files
bpf: Allow XDP dev-bound programs to perform XDP_REDIRECT into maps
JIRA: https://issues.redhat.com/browse/RHEL-78204 commit 714070c Author: Lorenzo Bianconi <[email protected]> Date: Mon Apr 28 17:44:02 2025 +0200 bpf: Allow XDP dev-bound programs to perform XDP_REDIRECT into maps In the current implementation if the program is dev-bound to a specific device, it will not be possible to perform XDP_REDIRECT into a DEVMAP or CPUMAP even if the program is running in the driver NAPI context and it is not attached to any map entry. This seems in contrast with the explanation available in bpf_prog_map_compatible routine. Fix the issue introducing __bpf_prog_map_compatible utility routine in order to avoid bpf_prog_is_dev_bound() check running bpf_check_tail_call() at program load time (bpf_prog_select_runtime()). Continue forbidding to attach a dev-bound program to XDP maps (BPF_MAP_TYPE_PROG_ARRAY, BPF_MAP_TYPE_DEVMAP and BPF_MAP_TYPE_CPUMAP). Fixes: 3d76a4d ("bpf: XDP metadata RX kfuncs") Signed-off-by: Lorenzo Bianconi <[email protected]> Signed-off-by: Martin KaFai Lau <[email protected]> Acked-by: Stanislav Fomichev <[email protected]> Signed-off-by: Jerome Marchand <[email protected]>
1 parent 910e483 commit a46107c

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

kernel/bpf/core.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2378,8 +2378,8 @@ static unsigned int __bpf_prog_ret0_warn(const void *ctx,
23782378
return 0;
23792379
}
23802380

2381-
bool bpf_prog_map_compatible(struct bpf_map *map,
2382-
const struct bpf_prog *fp)
2381+
static bool __bpf_prog_map_compatible(struct bpf_map *map,
2382+
const struct bpf_prog *fp)
23832383
{
23842384
enum bpf_prog_type prog_type = resolve_prog_type(fp);
23852385
bool ret;
@@ -2388,14 +2388,6 @@ bool bpf_prog_map_compatible(struct bpf_map *map,
23882388
if (fp->kprobe_override)
23892389
return false;
23902390

2391-
/* XDP programs inserted into maps are not guaranteed to run on
2392-
* a particular netdev (and can run outside driver context entirely
2393-
* in the case of devmap and cpumap). Until device checks
2394-
* are implemented, prohibit adding dev-bound programs to program maps.
2395-
*/
2396-
if (bpf_prog_is_dev_bound(aux))
2397-
return false;
2398-
23992391
spin_lock(&map->owner.lock);
24002392
if (!map->owner.type) {
24012393
/* There's no owner yet where we could check for
@@ -2429,6 +2421,19 @@ bool bpf_prog_map_compatible(struct bpf_map *map,
24292421
return ret;
24302422
}
24312423

2424+
bool bpf_prog_map_compatible(struct bpf_map *map, const struct bpf_prog *fp)
2425+
{
2426+
/* XDP programs inserted into maps are not guaranteed to run on
2427+
* a particular netdev (and can run outside driver context entirely
2428+
* in the case of devmap and cpumap). Until device checks
2429+
* are implemented, prohibit adding dev-bound programs to program maps.
2430+
*/
2431+
if (bpf_prog_is_dev_bound(fp->aux))
2432+
return false;
2433+
2434+
return __bpf_prog_map_compatible(map, fp);
2435+
}
2436+
24322437
static int bpf_check_tail_call(const struct bpf_prog *fp)
24332438
{
24342439
struct bpf_prog_aux *aux = fp->aux;
@@ -2441,7 +2446,7 @@ static int bpf_check_tail_call(const struct bpf_prog *fp)
24412446
if (!map_type_contains_progs(map))
24422447
continue;
24432448

2444-
if (!bpf_prog_map_compatible(map, fp)) {
2449+
if (!__bpf_prog_map_compatible(map, fp)) {
24452450
ret = -EINVAL;
24462451
goto out;
24472452
}

0 commit comments

Comments
 (0)