From: wuzongyo@mail.ustc.edu.cn
To: bpf@vger.kernel.org
Subject: [Question] Failed to load ebpf program with BTF-defined map
Date: Wed, 6 Apr 2022 22:38:52 +0800 (GMT+08:00) [thread overview]
Message-ID: <50b0dbb.2936.17fff506075.Coremail.wuzongyo@mail.ustc.edu.cn> (raw)
Hi,
I wrote a simple tc-bpf program like that:
#include <linux/bpf.h>
#include <linux/pkt_cls.h>
#include <linx/types.h>
#include <bpf/bpf_helpers.h>
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, 1);
__type(key, int);
__type(value, int);
} hmap SEC(".maps");
SEC("classifier")
int _classifier(struct __sk_buff *skb)
{
int key = 0;
int *val;
val = bpf_map_lookup_elem(&hmap, &key);
if (!val)
return TC_ACT_OK;
return TC_ACT_OK;
}
char __license[] SEC("license") = "GPL";
Then I tried to use tc to load the program:
tc qdisc add dev eth0 clsact
tc filter add dev eth0 egress bpf da obj test_bpf.o
But the program loading failed with error messages:
Prog section 'classifier' rejected: Permission denied (13)!
- Type: 3
- Instructions: 9 (0 over limit
- License: GPL
Verifier analysis:
Error fetching program/map!
Unable to load program
I tried to replace the map definition with the following code and the program is loaded successfully!
struct bpf_map_def SEC("maps") hmap = {
.type = BPF_MAP_TYPE_HASH,
.key_size = sizeof(int),
.value_size = sizeof(int),
.max_entries = 1,
};
With bpftrace, I can find that the errno -EACCES is returned by function do_check(). But I am still confused what's wrong with it.
Linux Version: 5.17.0-rc3+ with CONFIG_DEBUG_INFO_BTF=y
TC Version: 5.14.0
Any suggestion will be appreciated!
Thanks
next reply other threads:[~2022-04-06 17:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-06 14:38 wuzongyo [this message]
2022-04-06 17:25 ` [Question] Failed to load ebpf program with BTF-defined map Andrii Nakryiko
2022-04-06 21:23 ` Toke Høiland-Jørgensen
2022-04-07 3:15 ` wuzongyo
2022-04-07 11:39 ` Toke Høiland-Jørgensen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50b0dbb.2936.17fff506075.Coremail.wuzongyo@mail.ustc.edu.cn \
--to=wuzongyo@mail.ustc.edu.cn \
--cc=bpf@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).