You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In PR #484 , when I confirm whether it's necesssary to share .bss map between different collections, I confirm that the global variables are used incorrectly.
// bpf/kprobe_pwru.cstatic__always_inlinevoidset_skb_btf(structsk_buff*skb, u64*event_id) {
staticstructbtf_ptrp= {};
staticstructprint_skb_valuev= {};
u64id;
p.type_id=cfg->skb_btf_id;
p.ptr=skb;
*event_id=sync_fetch_and_add(&print_skb_id_map);
v.len=bpf_snprintf_btf(v.str, PRINT_SKB_STR_SIZE, &p, sizeof(p), 0);
if (v.len<0) {
return;
}
bpf_map_update_elem(&print_skb_map, event_id, &v, BPF_ANY);
}
static__always_inlinevoidset_shinfo_btf(structsk_buff*skb, u64*event_id) {
structskb_shared_info*shinfo;
staticstructbtf_ptrp= {};
staticstructprint_shinfo_valuev= {};
unsigned char*head;
unsigned intend;
/* skb_shared_info is located at the end of skb data. * When CONFIG_NET_SKBUFF_DATA_USES_OFFSET is enabled, skb->end * is an offset from skb->head to the end of skb data. If not, * skb->end is a pointer to the end of skb data. For amd64 and * arm64 (in 64bit arch in general), CONFIG_NET_SKBUFF_DATA_USES_OFFSET * is enabled by default. */head=BPF_CORE_READ(skb, head);
end=BPF_CORE_READ(skb, end);
shinfo= (structskb_shared_info*)(head+end);
p.type_id=cfg->shinfo_btf_id;
p.ptr=shinfo;
*event_id=sync_fetch_and_add(&print_shinfo_id_map);
v.len=bpf_snprintf_btf(v.str, PRINT_SHINFO_STR_SIZE, &p, sizeof(p), 0);
if (v.len<0) {
return;
}
bpf_map_update_elem(&print_shinfo_map, event_id, &v, BPF_ANY);
}
Aha, they are used for outputting skb and shinfo.
But when there are more-than-1 running pwru bpf progs on different CPUs, they will share the same globals at the same time without memory protection.
To resolve the memory-race issue, these variables should be set as global percpu variables by utilizing percpu_array map.
The text was updated successfully, but these errors were encountered:
In PR #484 , when I confirm whether it's necesssary to share
.bss
map between different collections, I confirm that the global variables are used incorrectly.What global variables in
.bss
map?But wait, what are they?
Aha, they are used for outputting
skb
andshinfo
.But when there are more-than-1 running pwru bpf progs on different CPUs, they will share the same globals at the same time without memory protection.
To resolve the memory-race issue, these variables should be set as global percpu variables by utilizing percpu_array map.
The text was updated successfully, but these errors were encountered: