All of lore.kernel.org
 help / color / mirror / Atom feed
* Behaviour of bpf_core_enum_value with missing value
@ 2021-04-20 13:42 Lorenz Bauer
  2021-04-20 16:55 ` Andrii Nakryiko
  0 siblings, 1 reply; 2+ messages in thread
From: Lorenz Bauer @ 2021-04-20 13:42 UTC (permalink / raw)
  To: bpf

Hi Andrii,

The documentation for bpf_core_enum_value says that a missing
enum_value will make the macro return 0:

* 64-bit value, if specified enum type and its enumerator value are
* present in target kernel's BTF;
* 0, if no matching enum and/or enum value within that enum is found.
*/
#define bpf_core_enum_value(enum_type, enum_value)

However, the enumval___err_missing test asserts that
bpf_core_enum_value with a missing value will poison the result if I
understand correctly.

$ sudo ./test_progs -n 31/77 -vvv
...
libbpf: prog 'test_core_enumval': relo #9: kind <enumval_value> (11),
spec is [5] typedef anon_enum::ANON_ENUM_VAL2 = 32
libbpf: prog 'test_core_enumval': relo #9: non-matching candidate #0
[6] typedef anon_enum___err_missing::ANON_ENUM_VAL1___err_missing =
273
libbpf: prog 'test_core_enumval': relo #9: no matching targets found
libbpf: prog 'test_core_enumval': relo #9: substituting insn #48 w/ invalid insn
libbpf: prog 'test_core_enumval': relo #9: substituting insn #47 w/ invalid insn
libbpf: load bpf program failed: Invalid argument

What is the correct behaviour in this case?

Lorenz

-- 
Lorenz Bauer  |  Systems Engineer
6th Floor, County Hall/The Riverside Building, SE1 7PB, UK

www.cloudflare.com

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

* Re: Behaviour of bpf_core_enum_value with missing value
  2021-04-20 13:42 Behaviour of bpf_core_enum_value with missing value Lorenz Bauer
@ 2021-04-20 16:55 ` Andrii Nakryiko
  0 siblings, 0 replies; 2+ messages in thread
From: Andrii Nakryiko @ 2021-04-20 16:55 UTC (permalink / raw)
  To: Lorenz Bauer; +Cc: bpf

On Tue, Apr 20, 2021 at 6:43 AM Lorenz Bauer <lmb@cloudflare.com> wrote:
>
> Hi Andrii,
>
> The documentation for bpf_core_enum_value says that a missing
> enum_value will make the macro return 0:
>
> * 64-bit value, if specified enum type and its enumerator value are
> * present in target kernel's BTF;
> * 0, if no matching enum and/or enum value within that enum is found.
> */
> #define bpf_core_enum_value(enum_type, enum_value)
>
> However, the enumval___err_missing test asserts that
> bpf_core_enum_value with a missing value will poison the result if I
> understand correctly.
>

I think comment is outdated. This was my initial approach, but after
discussing with Alexei we decided to keep the behavior consistent with
other types of relocation and require guarding with
bpf_core_enum_value_exists() to handle cases where enum value is
expected to not exist sometimes.

> $ sudo ./test_progs -n 31/77 -vvv
> ...
> libbpf: prog 'test_core_enumval': relo #9: kind <enumval_value> (11),
> spec is [5] typedef anon_enum::ANON_ENUM_VAL2 = 32
> libbpf: prog 'test_core_enumval': relo #9: non-matching candidate #0
> [6] typedef anon_enum___err_missing::ANON_ENUM_VAL1___err_missing =
> 273
> libbpf: prog 'test_core_enumval': relo #9: no matching targets found
> libbpf: prog 'test_core_enumval': relo #9: substituting insn #48 w/ invalid insn
> libbpf: prog 'test_core_enumval': relo #9: substituting insn #47 w/ invalid insn
> libbpf: load bpf program failed: Invalid argument
>
> What is the correct behaviour in this case?

Tests and code are right, comment is wrong. Now looking at
progs/test_core_reloc_enumval.c, /* NAMED_ENUM_VAL3 value is optional
*/ should be probably replaced with if (bpf_core_enum_value_exists())
{ out->named_val3 = bpf_core_enum_value() } else { out->named_val3 =
0xBAD } pattern or similar.

>
> Lorenz
>
> --
> Lorenz Bauer  |  Systems Engineer
> 6th Floor, County Hall/The Riverside Building, SE1 7PB, UK
>
> www.cloudflare.com

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

end of thread, other threads:[~2021-04-20 16:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-20 13:42 Behaviour of bpf_core_enum_value with missing value Lorenz Bauer
2021-04-20 16:55 ` Andrii Nakryiko

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.