4
0
Эх сурвалжийг харах

aya: Ignore embedded BTF error if not truely required

This allows fallback to BTF manual relocation when BTF loading fail when not truely required.
Mary 1 жил өмнө
parent
commit
74b546827c
1 өөрчлөгдсөн 45 нэмэгдсэн , 3 устгасан
  1. 45 3
      aya/src/bpf.rs

+ 45 - 3
aya/src/bpf.rs

@@ -389,9 +389,51 @@ impl<'a> BpfLoader<'a> {
 
         let btf_fd = if let Some(features) = &FEATURES.btf() {
             if let Some(btf) = obj.fixup_and_sanitize_btf(features)? {
-                // load btf to the kernel
-                let btf = load_btf(btf.to_bytes(), *verifier_log_level)?;
-                Some(btf)
+                match load_btf(btf.to_bytes(), *verifier_log_level) {
+                    Ok(btf_fd) => Some(btf_fd),
+                    // Only report an error here if the BTF is truely needed, otherwise proceed without.
+                    Err(err) => {
+                        for program in obj.programs.values() {
+                            match program.section {
+                                ProgramSection::Extension { .. }
+                                | ProgramSection::FEntry { .. }
+                                | ProgramSection::FExit { .. }
+                                | ProgramSection::Lsm { .. }
+                                | ProgramSection::BtfTracePoint { .. } => {
+                                    return Err(BpfError::BtfError(err))
+                                }
+                                ProgramSection::KRetProbe { .. }
+                                | ProgramSection::KProbe { .. }
+                                | ProgramSection::UProbe { .. }
+                                | ProgramSection::URetProbe { .. }
+                                | ProgramSection::TracePoint { .. }
+                                | ProgramSection::SocketFilter { .. }
+                                | ProgramSection::Xdp { .. }
+                                | ProgramSection::SkMsg { .. }
+                                | ProgramSection::SkSkbStreamParser { .. }
+                                | ProgramSection::SkSkbStreamVerdict { .. }
+                                | ProgramSection::SockOps { .. }
+                                | ProgramSection::SchedClassifier { .. }
+                                | ProgramSection::CgroupSkb { .. }
+                                | ProgramSection::CgroupSkbIngress { .. }
+                                | ProgramSection::CgroupSkbEgress { .. }
+                                | ProgramSection::CgroupSockAddr { .. }
+                                | ProgramSection::CgroupSysctl { .. }
+                                | ProgramSection::CgroupSockopt { .. }
+                                | ProgramSection::LircMode2 { .. }
+                                | ProgramSection::PerfEvent { .. }
+                                | ProgramSection::RawTracePoint { .. }
+                                | ProgramSection::SkLookup { .. }
+                                | ProgramSection::CgroupSock { .. }
+                                | ProgramSection::CgroupDevice { .. } => {}
+                            }
+                        }
+
+                        warn!("Object BTF couldn't be loaded in the kernel: {err}");
+
+                        None
+                    }
+                }
             } else {
                 None
             }