Skip to content

Commit 2b40473

Browse files
committed
Revert "libbpf-cargo: Don't provide kconfig data access after "open""
Commit 27dfe16 "libbpf-cargo: Don't provide kconfig data access after "open"" worked around the fact that the kconfig data member may not be present whenever. As it turns out, there is no guarantee that any of the data members are available as memory mapped data: on older kernels that "do not support memory-mapped global variable maps, libbpf will just avoid doing mmap" [0]. Revert this special sauce work around, as that means it's basically unnecessary now and we have to come up with a generic solution instead. This reverts commit 27dfe16. [0]: #1151 (comment) Signed-off-by: Daniel Müller <[email protected]>
1 parent 3fbef95 commit 2b40473

File tree

1 file changed

+29
-52
lines changed

1 file changed

+29
-52
lines changed

libbpf-cargo/src/gen/mod.rs

Lines changed: 29 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,6 @@ use crate::metadata::UnprocessedObj;
4747
pub(crate) use self::btf::GenBtf;
4848
pub(crate) use self::btf::GenStructOps;
4949

50-
51-
/// Name of the `.kconfig` map.
52-
///
53-
/// It requires special treatment because `libbpf` doesn't set the
54-
/// corresponding mmap pointer during "open", only as part of "load".
55-
const MAP_NAME_KCONFIG: &str = "kconfig";
56-
57-
5850
/// Escape certain characters in a "raw" name of a section, for example.
5951
fn escape_raw_name(name: &str) -> String {
6052
name.replace('.', "_")
@@ -91,20 +83,15 @@ impl Display for InternalMapType<'_> {
9183
/// Meta-data about a BPF map.
9284
enum MapMeta {
9385
NonDatasec,
94-
Datasec {
95-
mmap_idx: usize,
96-
read_only: bool,
97-
not_openable: bool,
98-
},
86+
Datasec { mmap_idx: usize, read_only: bool },
9987
}
10088

10189
impl MapMeta {
102-
fn new(name: &str, idx: usize, map: &Map<'_>) -> Self {
90+
fn new(idx: usize, map: &Map<'_>) -> Self {
10391
if map_is_datasec(map) {
10492
Self::Datasec {
10593
mmap_idx: idx,
10694
read_only: map_is_readonly(map),
107-
not_openable: name == MAP_NAME_KCONFIG,
10895
}
10996
} else {
11097
Self::NonDatasec
@@ -138,8 +125,8 @@ impl MapData {
138125

139126
let slf = Self {
140127
raw_name,
141-
meta: MapMeta::new(&name, idx, map),
142128
name,
129+
meta: MapMeta::new(idx, map),
143130
};
144131
Ok(Some(slf))
145132
}
@@ -411,24 +398,17 @@ fn gen_skel_map_defs(
411398
name = map.name
412399
)?;
413400

414-
if let MapMeta::Datasec {
415-
read_only,
416-
not_openable,
417-
..
418-
} = map.meta
419-
{
420-
if !(open && not_openable) {
421-
// After "open" all maps are writable. That's the point,
422-
// they can be modified.
423-
let ref_mut = if open || !read_only { " mut" } else { "" };
424-
write!(
425-
skel,
426-
"\
427-
pub {name}_data: &'obj{ref_mut} types::{name},
428-
",
429-
name = map.name,
430-
)?;
431-
}
401+
if let MapMeta::Datasec { read_only, .. } = map.meta {
402+
// After "open" all maps are writable. That's the point,
403+
// they can be modified.
404+
let ref_mut = if open || !read_only { " mut" } else { "" };
405+
write!(
406+
skel,
407+
"\
408+
pub {name}_data: &'obj{ref_mut} types::{name},
409+
",
410+
name = map.name,
411+
)?;
432412
}
433413
}
434414

@@ -507,26 +487,23 @@ fn gen_skel_map_defs(
507487
if let MapMeta::Datasec {
508488
mmap_idx,
509489
read_only,
510-
not_openable,
511490
} = map.meta
512491
{
513-
if !(open && not_openable) {
514-
let ref_conv = if open || !read_only { "mut" } else { "ref" };
515-
write!(
516-
skel,
517-
"\
518-
{name}_data: unsafe {{
519-
config
520-
.map_mmap_ptr({mmap_idx})
521-
.expect(\"BPF map `{name}` does not have mmap pointer\")
522-
.cast::<types::{name}>()
523-
.as_{ref_conv}()
524-
.expect(\"BPF map `{name}` mmap pointer is NULL\")
525-
}},
526-
",
527-
name = map.name,
528-
)?;
529-
}
492+
let ref_conv = if open || !read_only { "mut" } else { "ref" };
493+
write!(
494+
skel,
495+
"\
496+
{name}_data: unsafe {{
497+
config
498+
.map_mmap_ptr({mmap_idx})
499+
.expect(\"BPF map `{name}` does not have mmap pointer\")
500+
.cast::<types::{name}>()
501+
.as_{ref_conv}()
502+
.expect(\"BPF map `{name}` mmap pointer is NULL\")
503+
}},
504+
",
505+
name = map.name,
506+
)?;
530507
}
531508
}
532509

0 commit comments

Comments
 (0)