From 4222b140ec594e99e77cda8539b16f21820ae155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alessandro=C2=A0Decina?= Date: Wed, 28 Apr 2021 09:45:25 +0000 Subject: [PATCH] aya: perf_map: fix bug when max_entries=0 When a perf map has max_entries=0, max_entries is dynamically set at load time to the number of possible cpus as reported by /sys/devices/system/cpu/possible. This change fixes a bug where instead of setting max_entries to the number of possible cpus, we were setting it to the cpu index of the last possible cpu. --- aya/src/bpf.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/aya/src/bpf.rs b/aya/src/bpf.rs index b3e94f59..bed764cd 100644 --- a/aya/src/bpf.rs +++ b/aya/src/bpf.rs @@ -117,13 +117,12 @@ impl Bpf { for (_, mut obj) in obj.maps.drain() { if obj.def.map_type == BPF_MAP_TYPE_PERF_EVENT_ARRAY as u32 && obj.def.max_entries == 0 { - obj.def.max_entries = *possible_cpus() + obj.def.max_entries = possible_cpus() .map_err(|error| BpfError::FileError { path: PathBuf::from(POSSIBLE_CPUS), error, })? - .last() - .unwrap_or(&0); + .len() as u32; } let mut map = Map { obj, fd: None }; let fd = map.create()?;