All of lore.kernel.org
 help / color / mirror / Atom feed
* [Question] Failed to load ebpf program with BTF-defined map
@ 2022-04-06 14:38 wuzongyo
  2022-04-06 17:25 ` Andrii Nakryiko
  2022-04-06 21:23 ` Toke Høiland-Jørgensen
  0 siblings, 2 replies; 6+ messages in thread
From: wuzongyo @ 2022-04-06 14:38 UTC (permalink / raw)
  To: bpf

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Question] Failed to load ebpf program with BTF-defined map
  2022-04-06 14:38 [Question] Failed to load ebpf program with BTF-defined map wuzongyo
@ 2022-04-06 17:25 ` Andrii Nakryiko
  2022-04-06 21:23 ` Toke Høiland-Jørgensen
  1 sibling, 0 replies; 6+ messages in thread
From: Andrii Nakryiko @ 2022-04-06 17:25 UTC (permalink / raw)
  To: wuzongyo; +Cc: bpf

On Wed, Apr 6, 2022 at 10:09 AM <wuzongyo@mail.ustc.edu.cn> wrote:
>
> 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!
>

This is an iproute2 question, please find their mailing list and ask
there. Or bypass iproute2 and use libbpf-provided TC APIS
(bpf_tc_xxx()) to do all this directly from your application without
shelling out or delegating to iproute2


> Thanks
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Question] Failed to load ebpf program with BTF-defined map
  2022-04-06 14:38 [Question] Failed to load ebpf program with BTF-defined map wuzongyo
  2022-04-06 17:25 ` Andrii Nakryiko
@ 2022-04-06 21:23 ` Toke Høiland-Jørgensen
  2022-04-07  3:15   ` wuzongyo
  1 sibling, 1 reply; 6+ messages in thread
From: Toke Høiland-Jørgensen @ 2022-04-06 21:23 UTC (permalink / raw)
  To: wuzongyo, bpf

wuzongyo@mail.ustc.edu.cn writes:

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

If the latter works but the former doesn't, my guess would be that
iproute2 is compiled without libbpf support (in which case it would not
support BTF-defined maps either). If it does have libbpf support, that
(and the version of libbpf used) will be included in the output of `tc
-v`.

You could recompile iproute2 with enable libbpf support enabled, or as
Andrii suggests you can write your own loader using libbpf...

-Toke

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Re: [Question] Failed to load ebpf program with BTF-defined map
  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
  0 siblings, 1 reply; 6+ messages in thread
From: wuzongyo @ 2022-04-07  3:15 UTC (permalink / raw)
  To: Toke Høiland-Jørgensen; +Cc: bpf


> wuzongyo@mail.ustc.edu.cn writes:
> 
> > 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!
> 
> If the latter works but the former doesn't, my guess would be that
> iproute2 is compiled without libbpf support (in which case it would not
> support BTF-defined maps either). If it does have libbpf support, that
> (and the version of libbpf used) will be included in the output of `tc
> -v`.
> 
> You could recompile iproute2 with enable libbpf support enabled, or as
> Andrii suggests you can write your own loader using libbpf...
> 

It works with recompiled-iproute2. Thanks very much!

> -Toke


--
PB12011083 邬宗勇

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Re: [Question] Failed to load ebpf program with BTF-defined map
  2022-04-07  3:15   ` wuzongyo
@ 2022-04-07 11:39     ` Toke Høiland-Jørgensen
  0 siblings, 0 replies; 6+ messages in thread
From: Toke Høiland-Jørgensen @ 2022-04-07 11:39 UTC (permalink / raw)
  To: wuzongyo; +Cc: bpf

wuzongyo@mail.ustc.edu.cn writes:

>> wuzongyo@mail.ustc.edu.cn writes:
>> 
>> > 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!
>> 
>> If the latter works but the former doesn't, my guess would be that
>> iproute2 is compiled without libbpf support (in which case it would not
>> support BTF-defined maps either). If it does have libbpf support, that
>> (and the version of libbpf used) will be included in the output of `tc
>> -v`.
>> 
>> You could recompile iproute2 with enable libbpf support enabled, or as
>> Andrii suggests you can write your own loader using libbpf...
>> 
>
> It works with recompiled-iproute2. Thanks very much!

Great! You're welcome! :)

-Toke

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Question] Failed to load ebpf program with BTF-defined map
@ 2022-04-06 14:43 wuzongyo
  0 siblings, 0 replies; 6+ messages in thread
From: wuzongyo @ 2022-04-06 14:43 UTC (permalink / raw)
  To: netdev, linux-kernel

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-04-07 11:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-06 14:38 [Question] Failed to load ebpf program with BTF-defined map wuzongyo
2022-04-06 17:25 ` 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
2022-04-06 14:43 wuzongyo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.