libbpf: soften BTF map error
PATCH 1/1 libbpf: soften BTF map error
For map-in-map types, the first time the map is loaded, we get a scary error looking like this:
libbpf: bpf_create_map_xattr(map_name):ERROR: strerror_r(-524)=22(-524). Retrying without BTF.
On the second try without BTF, everything works fine. However, as this is logged at error level, it looks needlessly scary to users. Soften this to be at debug level; if the second attempt still fails, we'll still get an error as expected.
--- tools/lib/bpf/libbpf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/libbpf.c +1 -1
@@ -5123,7 +5123,7 @@ static int bpf_object__create_map(struct bpf_object *obj, struct bpf_map *map, b err = -errno; cp =libbpf_strerror_r (err, errmsg,sizeof (errmsg)); -pr_warn ("Error in bpf_create_map_xattr(%s):%s(%d). Retrying without BTF.\n" , +pr_debug ("bpf_create_map_xattr(%s):%s(%d). Retrying without BTF.\n" , map->name, cp, err); create_attr.btf_fd =0 ; create_attr.btf_key_type_id =0 ;
Signature · 1 line
2.34.1
Daniel Borkmann
maintainerQuoted 11 lines · Martin Kelly
For map-in-map types, the first time the map is loaded, we get a scary error looking like this:
libbpf: bpf_create_map_xattr(map_name):ERROR: strerror_r(-524)=22(-524). Retrying without BTF.
On the second try without BTF, everything works fine. However, as this is logged at error level, it looks needlessly scary to users. Soften this to be at debug level; if the second attempt still fails, we'll still get an error as expected.
Signed-off-by Martin Kelly <[email protected]>
nit: $subj should be for bpf-next instead of bpf
Quoted 9 lines
--- tools/lib/bpf/libbpf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/lib/bpf/libbpf.c +0
-0
tools/lib/bpf/libbpf.c static int bpf_object__create_map(struct bpf_object *obj, struct bpf_map *map, b · line 5127
Quoted 6 lines
tools/lib/bpf/libbpf.c +1
-1@@ -5123,7 +5123,7 @@ static int bpf_object__create_map(struct bpf_object *obj, struct bpf_map *map, b err = -errno; cp =libbpf_strerror_r (err, errmsg,sizeof (errmsg)); -pr_warn ("Error in bpf_create_map_xattr(%s):%s(%d). Retrying without BTF.\n" , +pr_debug ("bpf_create_map_xattr(%s):%s(%d). Retrying without BTF.\n" , map->name, cp, err);
There are also several other places with pr_warns about BTF when loading an obj. Did you audit them as well under !BTF kernel? nit: Why changing the fmt string itself, looked ok as-is, no?
There is also libbpf_needs_btf(obj), perhaps this could be left as pr_warn similar as in bpf_object__init_btf() - or would this still trigger in your case?
tools/lib/bpf/libbpf.c static int bpf_object__create_map(struct bpf_object *obj, struct bpf_map *map, b · line 5129
Quoted 3 lines
tools/lib/bpf/libbpf.c +0
-0create_attr.btf_fd =0 ; create_attr.btf_key_type_id =0 ;
Thanks,
Daniel
Quoted 6 lines · Daniel Borkmann
Quoted 5 lines · Martin Kelly
For map-in-map types, the first time the map is loaded, we get a scary error looking like this:
libbpf: bpf_create_map_xattr(map_name):ERROR: strerror_r(-524)=22(-524). Retrying without BTF.
Quoted 8 lines
Quoted 6 lines
On the second try without BTF, everything works fine. However, as this is logged at error level, it looks needlessly scary to users. Soften this to be at debug level; if the second attempt still fails, we'll still get an error as expected.
Signed-off-by Martin Kelly <[email protected]>nit: $subj should be for bpf-next instead of bpf
I had purposefully sent to "bpf" instead of "bpf-next" as it felt like a fix, but I'm fine with "bpf-next" instead if that's better.
Quoted 14 lines
Quoted 14 lines
---
tools/lib/bpf/libbpf.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)tools/lib/bpf/libbpf.c +0
-0@@ -5123,7 +5123,7 @@ static int bpf_object__create_map(struct
bpf_object*obj, structbpf_map*map, b
err = -errno;
cp =libbpf_strerror_r(err, errmsg, sizeof(errmsg)); - pr_warn("Error in bpf_create_map_xattr(%s):%s(%d). Retrying
Quoted 8 lines
Quoted 4 lines
without BTF.\n",
+ pr_debug("bpf_create_map_xattr(%s):%s(%d). Retrying without BTF.\n",
map->name, cp, err);There are also several other places with
pr_warnsabout BTF when loading an obj. Did you audit them as well under !BTF kernel? nit: Why changing the fmt string itself, looked ok as-is, no?
This message is actually printed even for a BTF-supported kernel. Basically, the first call to bpf_create_map_xattr using BTF *always* fails for map-in-map types, printing this message, and then the second always succeeds. So this isn't really about BTF support but simply about an over-zealous message.
I changed the format string because calling this an "Error" feels (to me) unnecessarily alarming, given that this is totally normal behavior. I'm OK keeping the "Error in" part if you think that's better. The most important thing to me was that, when the program loads successfully, we shouldn't be logging to stderr and scaring the user.
Let me know if you'd like me to keep the "Error in" part for a v2 patch.
Quoted 3 lines
There is also
libbpf_needs_btf(obj), perhaps this could be left aspr_warnsimilar as inbpf_object__init_btf()- or would this still trigger in your case?
I think this one should stay as a warning, as it looks like the code path is a fatal error, and if you try to load a BTF-requiring program but don't have BTF, that seems like an error to me. This patch was more about an error being logged 100% of the time in a totally normal, non-fatal, BTF-supported case due to the quirks of map-in-map types and BTF.
Quoted 7 lines
Quoted 4 lines
create_attr.btf_fd = 0;
create_attr.btf_key_type_id = 0;Thanks,
Daniel
Quoted 45 lines · Martin Kelly
Quoted 6 lines · Daniel Borkmann
Quoted 5 lines · Martin Kelly
For map-in-map types, the first time the map is loaded, we get a scary error looking like this:
libbpf: bpf_create_map_xattr(map_name):ERROR: strerror_r(-524)=22(-524). Retrying without BTF.
Quoted 8 lines
Quoted 6 lines
On the second try without BTF, everything works fine. However, as this is logged at error level, it looks needlessly scary to users. Soften this to be at debug level; if the second attempt still fails, we'll still get an error as expected.
Signed-off-by Martin Kelly <[email protected]>nit: $subj should be for bpf-next instead of bpf
I had purposefully sent to "bpf" instead of "bpf-next" as it felt like a fix, but I'm fine with "bpf-next" instead if that's better.
Quoted 14 lines
Quoted 14 lines
---
tools/lib/bpf/libbpf.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)tools/lib/bpf/libbpf.c +0
-0@@ -5123,7 +5123,7 @@ static int bpf_object__create_map(struct
bpf_object*obj, structbpf_map*map, b
err = -errno;
cp =libbpf_strerror_r(err, errmsg, sizeof(errmsg)); - pr_warn("Error in bpf_create_map_xattr(%s):%s(%d). RetryingQuoted 8 lines
Quoted 4 lines
without BTF.\n",
+ pr_debug("bpf_create_map_xattr(%s):%s(%d). Retrying without BTF.\n",
map->name, cp, err);There are also several other places with
pr_warnsabout BTF when loading an obj. Did you audit them as well under !BTF kernel? nit: Why changing the fmt string itself, looked ok as-is, no?This message is actually printed even for a BTF-supported kernel. Basically, the first call to
bpf_create_map_xattrusing BTF *always* fails for map-in-map types, printing this message, and then the second always succeeds. So this isn't really about BTF support but simply about an over-zealous message.I changed the format string because calling this an "Error" feels (to me) unnecessarily alarming, given that this is totally normal behavior. I'm OK keeping the "Error in" part if you think that's better. The most important thing to me was that, when the program loads successfully, we shouldn't be logging to stderr and scaring the user.
Quoted 15 lines
Let me know if you'd like me to keep the "Error in" part for a v2 patch.
Quoted 3 lines
There is also
libbpf_needs_btf(obj), perhaps this could be left aspr_warnsimilar as inbpf_object__init_btf()- or would this still trigger in your case?I think this one should stay as a warning, as it looks like the code path is a fatal error, and if you try to load a BTF-requiring program but don't have BTF, that seems like an error to me. This patch was more about an error being logged 100% of the time in a totally normal, non-fatal, BTF-supported case due to the quirks of map-in-map types and BTF.
Quoted 7 lines
Quoted 4 lines
create_attr.btf_fd = 0;
create_attr.btf_key_type_id = 0;Thanks,
Daniel
(ping) any thoughts on the above? I'm happy to send a v2 patch but want to make sure we're on the same page with what should be in it.
Quoted 79 lines · Martin Kelly
Quoted 77 lines · Martin Kelly
Quoted 7 lines · Daniel Borkmann
Quoted 6 lines · Martin Kelly
For map-in-map types, the first time the map is loaded, we get a scary error looking like this:
libbpf: bpf_create_map_xattr(map_name):ERROR:
strerror_r(-524)=22(-524). Retrying without BTF.Quoted 8 lines
Quoted 6 lines
On the second try without BTF, everything works fine. However, as this is logged at error level, it looks needlessly scary to users. Soften this to be at debug level; if the second attempt still fails, we'll still get an error as expected.
Signed-off-by Martin Kelly <[email protected]>nit: $subj should be for bpf-next instead of bpf
I had purposefully sent to "bpf" instead of "bpf-next" as it felt like a fix, but I'm fine with "bpf-next" instead if that's better.
Quoted 16 lines
Quoted 16 lines
--- tools/lib/bpf/libbpf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/lib/bpf/libbpf.c +0
-0@@ -5123,7 +5123,7 @@ static int bpf_object__create_map(struct
bpf_object*obj, structbpf_map*map, berr = -errno; cp = libbpf_strerror_r(err, errmsg, sizeof(errmsg));- pr_warn("Error in bpf_create_map_xattr(%s):%s(%d). Retrying
without BTF.\n",
+ pr_debug("bpf_create_map_xattr(%s):%s(%d). Retrying withoutQuoted 8 lines
Quoted 2 lines
BTF.\n",
map->name, cp, err);There are also several other places with
pr_warnsabout BTF when loading an obj. Did
you audit them as well under !BTF kernel? nit: Why changing the fmt string itself,
looked ok as-is, no?This message is actually printed even for a BTF-supported kernel. Basically, the first call to
bpf_create_map_xattrusing BTF *always* fails for map-in-map types, printing this message, and then the second always succeeds. So this isn't really about BTF support but simply about an over-zealous message.I changed the format string because calling this an "Error" feels (to me) unnecessarily alarming, given that this is totally normal behavior. I'm OK keeping the "Error in" part if you think that's better. The most important thing to me was that, when the program loads successfully, we shouldn't be logging to stderr and scaring the user.
Let me know if you'd like me to keep the "Error in" part for a v2 patch.
Quoted 4 lines
There is also
libbpf_needs_btf(obj), perhaps this could be left aspr_warnsimilar
as inbpf_object__init_btf()- or would this still trigger in your case?I think this one should stay as a warning, as it looks like the code path is a fatal error, and if you try to load a BTF-requiring program but don't have BTF, that seems like an error to me. This patch was more about an error being logged 100% of the time in a totally normal, non-fatal, BTF-supported case due to the quirks of map-in-map types and BTF.
Quoted 5 lines
Quoted 4 lines
create_attr.btf_fd = 0; create_attr.btf_key_type_id = 0;
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Thanks,
Daniel(ping) any thoughts on the above? I'm happy to send a v2 patch but want to make sure we're on the same page with what should be in it.
map creation failing due to having a BTF information should be a rather exception than the norm, for two reasons: 1) libbpf sanitizes BTF, so even older kernels can still retain some (modified) BTF information, and 2) libbpf drops BTF for maps that don't support BTF type info for keys/values. So if you see this, then it would be useful to actually look into why this is happening.
So I'd prefer this to keep pretty visible. Can you try to debug what makes the kernel reject your BTF information?
Quoted 83 lines · Andrii Nakryiko
Quoted 66 lines · Martin Kelly
Quoted 65 lines · Martin Kelly
Quoted 7 lines · Daniel Borkmann
Quoted 6 lines · Martin Kelly
For map-in-map types, the first time the map is loaded, we get a scary error looking like this:
libbpf: bpf_create_map_xattr(map_name):ERROR:
strerror_r(-524)=22(-524). Retrying without BTF.Quoted 7 lines
Quoted 6 lines
On the second try without BTF, everything works fine. However, as this is logged at error level, it looks needlessly scary to users. Soften this to be at debug level; if the second attempt still fails, we'll still get an error as expected.
Signed-off-by Martin Kelly <[email protected]>nit: $subj should be for bpf-next instead of bpf
I had purposefully sent to "bpf" instead of "bpf-next" as it felt like a fix, but I'm fine with "bpf-next" instead if that's better.
Quoted 14 lines
Quoted 14 lines
--- tools/lib/bpf/libbpf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/lib/bpf/libbpf.c +0
-0@@ -5123,7 +5123,7 @@ static int bpf_object__create_map(struct
bpf_object*obj, structbpf_map*map, berr = -errno; cp = libbpf_strerror_r(err, errmsg, sizeof(errmsg));- pr_warn("Error in bpf_create_map_xattr(%s):%s(%d). Retrying
without BTF.\n",Quoted 8 lines
Quoted 3 lines
+ pr_debug("bpf_create_map_xattr(%s):%s(%d). Retrying without
BTF.\n",map->name, cp, err);There are also several other places with
pr_warnsabout BTF when loading an obj. Did
you audit them as well under !BTF kernel? nit: Why changing the fmt string itself,
looked ok as-is, no?This message is actually printed even for a BTF-supported kernel. Basically, the first call to
bpf_create_map_xattrusing BTF *always* fails for map-in-map types, printing this message, and then the second always succeeds. So this isn't really about BTF support but simply about an over-zealous message.I changed the format string because calling this an "Error" feels (to me) unnecessarily alarming, given that this is totally normal behavior. I'm OK keeping the "Error in" part if you think that's better. The most important thing to me was that, when the program loads successfully, we shouldn't be logging to stderr and scaring the user.
Let me know if you'd like me to keep the "Error in" part for a v2 patch.
Quoted 3 lines
There is also
libbpf_needs_btf(obj), perhaps this could be left aspr_warnsimilar
as inbpf_object__init_btf()- or would this still trigger in your case?I think this one should stay as a warning, as it looks like the code path is a fatal error, and if you try to load a BTF-requiring program but don't have BTF, that seems like an error to me. This patch was more about an error being logged 100% of the time in a totally normal, non-fatal, BTF-supported case due to the quirks of map-in-map types and BTF.
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
create_attr.btf_fd = 0; create_attr.btf_key_type_id = 0;Thanks,
Daniel(ping) any thoughts on the above? I'm happy to send a v2 patch but want to make sure we're on the same page with what should be in it.
map creation failing due to having a BTF information should be a rather exception than the norm, for two reasons: 1) libbpf sanitizes BTF, so even older kernels can still retain some (modified) BTF information, and 2) libbpf drops BTF for maps that don't support BTF type info for keys/values. So if you see this, then it would be useful to actually look into why this is happening.
Quoted 2 lines
So I'd prefer this to keep pretty visible. Can you try to debug what makes the kernel reject your BTF information?
I'm happy to report that the issue that prompted this patch doesn't repro anymore on latest bpf-next; I originally wrote this some time back, so something must have changed in either the BPF code or libbpf. Thanks for following up; let's drop this patch.