Browse Source

enable bpf_target_arch = loongarch64

Signed-off-by: Godones <chenlinfeng25@outlook.com>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
Godones 1 week ago
parent
commit
4b4b9f83bd

+ 2 - 0
.github/workflows/ci.yml

@@ -81,6 +81,7 @@ jobs:
         arch:
           - aarch64-unknown-linux-gnu
           - armv7-unknown-linux-gnueabi
+          - loongarch64-unknown-linux-gnu
           - powerpc64le-unknown-linux-gnu
           - riscv64gc-unknown-linux-gnu
           - s390x-unknown-linux-gnu
@@ -149,6 +150,7 @@ jobs:
         bpf_target_arch:
           - aarch64
           - arm
+          - loongarch64
           - mips
           - powerpc64
           - riscv64

+ 45 - 0
ebpf/aya-ebpf/src/args.rs

@@ -162,6 +162,21 @@ impl<T> FromPtRegs for *const T {
     }
 }
 
+#[cfg(bpf_target_arch = "loongarch64")]
+impl<T> FromPtRegs for *const T {
+    fn from_argument(ctx: &pt_regs, n: usize) -> Option<Self> {
+        if n <= 7 {
+            unsafe { bpf_probe_read(&ctx.regs[4 + n]).map(|v| v as *const _).ok() }
+        } else {
+            None
+        }
+    }
+
+    fn from_retval(ctx: &pt_regs) -> Option<Self> {
+        unsafe { bpf_probe_read(&ctx.regs[4]).map(|v| v as *const _).ok() }
+    }
+}
+
 #[cfg(bpf_target_arch = "riscv64")]
 impl<T> FromPtRegs for *const T {
     fn from_argument(ctx: &pt_regs, n: usize) -> Option<Self> {
@@ -278,6 +293,21 @@ impl<T> FromPtRegs for *mut T {
     }
 }
 
+#[cfg(bpf_target_arch = "loongarch64")]
+impl<T> FromPtRegs for *mut T {
+    fn from_argument(ctx: &pt_regs, n: usize) -> Option<Self> {
+        if n <= 7 {
+            unsafe { bpf_probe_read(&ctx.regs[4 + n]).map(|v| v as *mut _).ok() }
+        } else {
+            None
+        }
+    }
+
+    fn from_retval(ctx: &pt_regs) -> Option<Self> {
+        unsafe { bpf_probe_read(&ctx.regs[4]).map(|v| v as *mut _).ok() }
+    }
+}
+
 #[cfg(bpf_target_arch = "riscv64")]
 impl<T> FromPtRegs for *mut T {
     fn from_argument(ctx: &pt_regs, n: usize) -> Option<Self> {
@@ -397,6 +427,21 @@ macro_rules! impl_from_pt_regs {
             }
         }
 
+        #[cfg(bpf_target_arch = "loongarch64")]
+        impl FromPtRegs for $type {
+            fn from_argument(ctx: &pt_regs, n: usize) -> Option<Self> {
+                if n <= 7 {
+                    Some(ctx.regs[4 + n] as *const $type as _)
+                } else {
+                    None
+                }
+            }
+
+            fn from_retval(ctx: &pt_regs) -> Option<Self> {
+                Some(ctx.regs[4] as *const $type as _)
+            }
+        }
+
         #[cfg(bpf_target_arch = "riscv64")]
         impl FromPtRegs for $type {
             fn from_argument(ctx: &pt_regs, n: usize) -> Option<Self> {

+ 5 - 3
ebpf/aya-ebpf/src/programs/probe.rs

@@ -7,10 +7,12 @@ use core::ffi::c_void;
     bpf_target_arch = "mips"
 ))]
 use crate::bindings::pt_regs;
-// aarch64 uses user_pt_regs instead of pt_regs
-#[cfg(any(bpf_target_arch = "aarch64", bpf_target_arch = "s390x"))]
+#[cfg(any(
+    bpf_target_arch = "aarch64",
+    bpf_target_arch = "loongarch64",
+    bpf_target_arch = "s390x",
+))]
 use crate::bindings::user_pt_regs as pt_regs;
-// riscv64 uses user_regs_struct instead of pt_regs
 #[cfg(bpf_target_arch = "riscv64")]
 use crate::bindings::user_regs_struct as pt_regs;
 use crate::{EbpfContext, args::FromPtRegs};

+ 5 - 3
ebpf/aya-ebpf/src/programs/retprobe.rs

@@ -7,10 +7,12 @@ use core::ffi::c_void;
     bpf_target_arch = "mips"
 ))]
 use crate::bindings::pt_regs;
-// aarch64 uses user_pt_regs instead of pt_regs
-#[cfg(any(bpf_target_arch = "aarch64", bpf_target_arch = "s390x"))]
+#[cfg(any(
+    bpf_target_arch = "aarch64",
+    bpf_target_arch = "loongarch64",
+    bpf_target_arch = "s390x",
+))]
 use crate::bindings::user_pt_regs as pt_regs;
-// riscv64 uses user_regs_struct instead of pt_regs
 #[cfg(bpf_target_arch = "riscv64")]
 use crate::bindings::user_regs_struct as pt_regs;
 use crate::{EbpfContext, args::FromPtRegs};