From 0ee6017cc0dafaaa3c9afded3cf87c6ad035cfd6 Mon Sep 17 00:00:00 2001 From: yzewei Date: Thu, 18 Apr 2024 15:37:06 +0800 Subject: [PATCH] add Signed-off-by: yzewei --- driver/CMakeLists.txt | 2 +- driver/feature_gates.h | 6 +++--- driver/syscall_compat_loongarch64.h | 6 ------ driver/syscall_table.c | 4 ++++ driver/syscall_table64.c | 2 +- .../sched_process_fork.cpp | 2 +- .../syscall_enter_suite/clone_e.cpp | 2 +- .../syscall_exit_suite/clone_x.cpp | 4 ++-- .../syscall_exit_suite/execveat_x.cpp | 6 +++--- .../open_by_handle_at_x.cpp | 10 +++++++++- .../syscall_exit_suite/openat2_x.cpp | 20 +++++++++++++++---- .../engines/gvisor/gvisor_parsers.cpp | 2 ++ userspace/libscap/engine/gvisor/parsers.cpp | 2 ++ 13 files changed, 45 insertions(+), 23 deletions(-) diff --git a/driver/CMakeLists.txt b/driver/CMakeLists.txt index 5147a7b35b3..80229cc034a 100644 --- a/driver/CMakeLists.txt +++ b/driver/CMakeLists.txt @@ -29,7 +29,7 @@ else() set(kmod_min_kver_map_s390x 2.6) set(kmod_min_kver_map_riscv64 5.0) set(kmod_min_kver_map_ppc64le 2.6) - set(kmod_min_kver_map_loongarch64 5.19) + set(kmod_min_kver_map_loongarch64 5.10) if (LINUX_KERNEL_VERSION VERSION_LESS ${kmod_min_kver_map_${TARGET_ARCH}}) message(WARNING "[KMOD] To run this driver you need a Linux kernel version >= ${kmod_min_kver_map_${TARGET_ARCH}} but actual kernel version is: ${UNAME_RESULT}") diff --git a/driver/feature_gates.h b/driver/feature_gates.h index d1b77a83ff4..e3a6fc842dc 100644 --- a/driver/feature_gates.h +++ b/driver/feature_gates.h @@ -156,7 +156,7 @@ or GPL2.txt for full copies of the license. // CAPTURE_SCHED_PROC_FORK /////////////////////////////// -#if defined(__TARGET_ARCH_arm64) || defined(__TARGET_ARCH_s390) || defined(__TARGET_ARCH_riscv) || defined(__TARGET_ARCH_loongarch) +#if defined(__TARGET_ARCH_arm64) || defined(__TARGET_ARCH_s390) || defined(__TARGET_ARCH_riscv) || defined(__TARGET_ARCH_loongarch64) #define CAPTURE_SCHED_PROC_FORK #endif @@ -178,7 +178,7 @@ or GPL2.txt for full copies of the license. // CAPTURE_64BIT_ARGS_SINGLE_REGISTER /////////////////////////////// -#if defined(__x86_64__) || defined(__aarch64__) +#if defined(__x86_64__) || defined(__aarch64__) || defined(__loongarch64) #define CAPTURE_64BIT_ARGS_SINGLE_REGISTER #endif @@ -206,7 +206,7 @@ or GPL2.txt for full copies of the license. // CAPTURE_SCHED_PROC_FORK /////////////////////////////// -#if defined(__aarch64__) || defined(__s390x__) || defined(__riscv) || defined(__loongarch__) +#if defined(__aarch64__) || defined(__s390x__) || defined(__riscv) || defined(__loongarch64) #define CAPTURE_SCHED_PROC_FORK #endif diff --git a/driver/syscall_compat_loongarch64.h b/driver/syscall_compat_loongarch64.h index 62e55e710b3..ce46405609e 100644 --- a/driver/syscall_compat_loongarch64.h +++ b/driver/syscall_compat_loongarch64.h @@ -245,9 +245,6 @@ or GPL2.txt for full copies of the license. #ifndef __NR_readlinkat #define __NR_readlinkat 78 #endif -#ifndef __NR_fstat -#define __NR_fstat 80 -#endif #ifndef __NR_sync #define __NR_sync 81 #endif @@ -494,9 +491,6 @@ or GPL2.txt for full copies of the license. #ifndef __NR_setdomainname #define __NR_setdomainname 162 #endif -#ifndef __NR_setrlimit -#define __NR_setrlimit 164 -#endif #ifndef __NR_getrusage #define __NR_getrusage 165 #endif diff --git a/driver/syscall_table.c b/driver/syscall_table.c index 8f4cf53f077..a1a25b5988c 100644 --- a/driver/syscall_table.c +++ b/driver/syscall_table.c @@ -59,7 +59,9 @@ const struct syscall_evt_pair g_syscall_table[SYSCALL_TABLE_SIZE] = { #ifdef __NR_lstat [__NR_lstat - SYSCALL_TABLE_ID0] = {UF_USED | UF_ALWAYS_DROP, PPME_SYSCALL_LSTAT_E, PPME_SYSCALL_LSTAT_X, PPM_SC_LSTAT}, #endif +#ifdef __NR_fstat [__NR_fstat - SYSCALL_TABLE_ID0] = {UF_USED | UF_ALWAYS_DROP, PPME_SYSCALL_FSTAT_E, PPME_SYSCALL_FSTAT_X, PPM_SC_FSTAT}, +#endif #ifdef __NR_epoll_wait [__NR_epoll_wait - SYSCALL_TABLE_ID0] = {UF_USED | UF_ALWAYS_DROP, PPME_SYSCALL_EPOLLWAIT_E, PPME_SYSCALL_EPOLLWAIT_X, PPM_SC_EPOLL_WAIT}, #endif @@ -126,7 +128,9 @@ const struct syscall_evt_pair g_syscall_table[SYSCALL_TABLE_SIZE] = { #ifdef __NR_getrlimit [__NR_getrlimit - SYSCALL_TABLE_ID0] = {UF_USED, PPME_SYSCALL_GETRLIMIT_E, PPME_SYSCALL_GETRLIMIT_X, PPM_SC_GETRLIMIT}, #endif +#ifdef __NR_setrlimit [__NR_setrlimit - SYSCALL_TABLE_ID0] = {UF_USED | UF_NEVER_DROP, PPME_SYSCALL_SETRLIMIT_E, PPME_SYSCALL_SETRLIMIT_X, PPM_SC_SETRLIMIT}, +#endif #ifdef __NR_prlimit64 [__NR_prlimit64 - SYSCALL_TABLE_ID0] = {UF_USED | UF_NEVER_DROP, PPME_SYSCALL_PRLIMIT_E, PPME_SYSCALL_PRLIMIT_X, PPM_SC_PRLIMIT64}, #endif diff --git a/driver/syscall_table64.c b/driver/syscall_table64.c index 181ba2b78cd..d6a7bd5b426 100644 --- a/driver/syscall_table64.c +++ b/driver/syscall_table64.c @@ -28,7 +28,7 @@ or GPL2.txt for full copies of the license. #include "syscall_compat_ppc64le.h" #elif defined(__riscv) #include "syscall_compat_riscv64.h" -#elif defined(__loongarch__) +#elif defined(__loongarch64) #include "syscall_compat_loongarch64.h" #endif /* __x86_64__ */ #elif defined(_MSC_VER) || defined(__EMSCRIPTEN__) diff --git a/test/drivers/test_suites/generic_tracepoints_suite/sched_process_fork.cpp b/test/drivers/test_suites/generic_tracepoints_suite/sched_process_fork.cpp index d5102eed71c..e8275215710 100644 --- a/test/drivers/test_suites/generic_tracepoints_suite/sched_process_fork.cpp +++ b/test/drivers/test_suites/generic_tracepoints_suite/sched_process_fork.cpp @@ -526,7 +526,7 @@ TEST(GenericTracepoints, sched_proc_fork_case_clone) #ifdef __s390x__ ret_pid = syscall(__NR_clone, newsp, clone_flags, &parent_tid, &child_tid, tls); -#elif defined(__aarch64__) || defined(__riscv) +#elif defined(__aarch64__) || defined(__riscv) || defined(__loongarch64) /*kernel clone.S*/ ret_pid = syscall(__NR_clone, clone_flags, newsp, &parent_tid, tls, &child_tid); #else ret_pid = syscall(__NR_clone, clone_flags, newsp, &parent_tid, &child_tid, tls); diff --git a/test/drivers/test_suites/syscall_enter_suite/clone_e.cpp b/test/drivers/test_suites/syscall_enter_suite/clone_e.cpp index 6161397ce78..17ac50a9648 100644 --- a/test/drivers/test_suites/syscall_enter_suite/clone_e.cpp +++ b/test/drivers/test_suites/syscall_enter_suite/clone_e.cpp @@ -45,7 +45,7 @@ TEST(SyscallEnter, cloneE) */ #ifdef __s390x__ assert_syscall_state(SYSCALL_FAILURE, "clone", syscall(__NR_clone, newsp, clone_flags, &parent_tid, &child_tid, tls)); -#elif defined(__aarch64__) || defined(__riscv) +#elif defined(__aarch64__) || defined(__riscv) || defined(__loongarch64) assert_syscall_state(SYSCALL_FAILURE, "clone", syscall(__NR_clone, clone_flags, newsp, &parent_tid, tls, &child_tid)); #else assert_syscall_state(SYSCALL_FAILURE, "clone", syscall(__NR_clone, clone_flags, newsp, &parent_tid, &child_tid, tls)); diff --git a/test/drivers/test_suites/syscall_exit_suite/clone_x.cpp b/test/drivers/test_suites/syscall_exit_suite/clone_x.cpp index ebf4fbc67a8..f325a5df05f 100644 --- a/test/drivers/test_suites/syscall_exit_suite/clone_x.cpp +++ b/test/drivers/test_suites/syscall_exit_suite/clone_x.cpp @@ -60,7 +60,7 @@ TEST(SyscallExit, cloneX_father) */ #ifdef __s390x__ ret_pid = syscall(__NR_clone, newsp, test_clone_flags, &parent_tid, &child_tid, tls); -#elif defined(__aarch64__) || defined(__riscv) +#elif defined(__aarch64__) || defined(__riscv) || defined(__loongarch64) ret_pid = syscall(__NR_clone, test_clone_flags, newsp, &parent_tid, tls, &child_tid); #else ret_pid = syscall(__NR_clone, test_clone_flags, newsp, &parent_tid, &child_tid, tls); @@ -197,7 +197,7 @@ TEST(SyscallExit, cloneX_child) #ifdef __s390x__ ret_pid = syscall(__NR_clone, newsp, test_clone_flags, &parent_tid, &child_tid, tls); -#elif defined(__aarch64__) || defined(__riscv) +#elif defined(__aarch64__) || defined(__riscv) || defined(__loongarch64) ret_pid = syscall(__NR_clone, test_clone_flags, newsp, &parent_tid, tls, &child_tid); #else ret_pid = syscall(__NR_clone, test_clone_flags, newsp, &parent_tid, &child_tid, tls); diff --git a/test/drivers/test_suites/syscall_exit_suite/execveat_x.cpp b/test/drivers/test_suites/syscall_exit_suite/execveat_x.cpp index 2c2790c4f7a..4de0dc113be 100644 --- a/test/drivers/test_suites/syscall_exit_suite/execveat_x.cpp +++ b/test/drivers/test_suites/syscall_exit_suite/execveat_x.cpp @@ -211,7 +211,7 @@ TEST(SyscallExit, execveatX_correct_exit) evt_test->disable_capture(); -#if defined(__s390x__) || defined(__riscv) || defined(__powerpc64__) +#if defined(__s390x__) || defined(__riscv) || defined(__powerpc64__) || defined(__loongarch64) /* We search for a child event. */ evt_test->assert_event_presence(ret_pid); @@ -338,7 +338,7 @@ TEST(SyscallExit, execveatX_execve_exit) evt_test->disable_capture(); /* `s390x` returns an `EXECVEAT_X` event while other architectures retun an `EXECVE_X` */ -#if defined(__s390x__) || defined(__riscv) || defined(__powerpc64__) +#if defined(__s390x__) || defined(__riscv) || defined(__powerpc64__) || defined(__loongarch64) /* We search for a child event. */ evt_test->assert_event_absence(ret_pid, PPME_SYSCALL_EXECVE_19_X); #else @@ -494,7 +494,7 @@ TEST(SyscallExit, execveatX_success_memfd) evt_test->disable_capture(); -#if defined(__s390x__) || defined(__riscv) || defined(__powerpc64__) +#if defined(__s390x__) || defined(__riscv) || defined(__powerpc64__) || defined(__loongarch64) /* We search for a child event. */ evt_test->assert_event_presence(ret_pid); diff --git a/test/drivers/test_suites/syscall_exit_suite/open_by_handle_at_x.cpp b/test/drivers/test_suites/syscall_exit_suite/open_by_handle_at_x.cpp index b31f17fb515..16996c82e6f 100644 --- a/test/drivers/test_suites/syscall_exit_suite/open_by_handle_at_x.cpp +++ b/test/drivers/test_suites/syscall_exit_suite/open_by_handle_at_x.cpp @@ -103,10 +103,12 @@ void do___open_by_handle_atX_success(int *open_by_handle_fd, int *dirfd, char *f * 6. Get dev and ino. */ struct stat file_stat; +#if defined(__loongarch64) +#else assert_syscall_state(SYSCALL_SUCCESS, "fstat", syscall(__NR_fstat, *open_by_handle_fd, &file_stat), NOT_EQUAL, -1); *dev = (uint32_t)file_stat.st_dev; *inode = file_stat.st_ino; - +#endif /* * 7. Cleaning phase. */ @@ -187,11 +189,14 @@ TEST(SyscallExit, open_by_handle_atX_success) /* Parameter 4: path (type: PT_FSPATH) */ evt_test->assert_charbuf_param(4, fspath); +#if defined(__loongarch64) +#elif /* Parameter 5: dev (type: PT_UINT32) */ evt_test->assert_numeric_param(5, dev); /* Parameter 6: ino (type: PT_UINT64) */ evt_test->assert_numeric_param(6, inode); +#endif /*=============================== ASSERT PARAMETERS ===========================*/ @@ -243,11 +248,14 @@ TEST(SyscallExit, open_by_handle_atX_success_mp) /* Parameter 4: path (type: PT_FSPATH) */ evt_test->assert_charbuf_param(4, fspath); +#if defined(__loongarch64) +#elif /* Parameter 5: dev (type: PT_UINT32) */ evt_test->assert_numeric_param(5, dev); /* Parameter 6: ino (type: PT_UINT64) */ evt_test->assert_numeric_param(6, inode); +#endif /*=============================== ASSERT PARAMETERS ===========================*/ diff --git a/test/drivers/test_suites/syscall_exit_suite/openat2_x.cpp b/test/drivers/test_suites/syscall_exit_suite/openat2_x.cpp index 99ebdd6e640..e4ea76b7a63 100644 --- a/test/drivers/test_suites/syscall_exit_suite/openat2_x.cpp +++ b/test/drivers/test_suites/syscall_exit_suite/openat2_x.cpp @@ -23,12 +23,15 @@ TEST(SyscallExit, openat2X_success) how.resolve = RESOLVE_BENEATH | RESOLVE_NO_MAGICLINKS; int32_t fd = syscall(__NR_openat2, dirfd, pathname, &how, sizeof(struct open_how)); assert_syscall_state(SYSCALL_SUCCESS, "openat2", fd, NOT_EQUAL, -1); - + +#if defined(__loongarch64) +#elif /* Call `fstat` to retrieve the `dev` and `ino`. */ struct stat file_stat; assert_syscall_state(SYSCALL_SUCCESS, "fstat", syscall(__NR_fstat, fd, &file_stat), NOT_EQUAL, -1); uint32_t dev = (uint32_t)file_stat.st_dev; uint64_t inode = file_stat.st_ino; +#endif close(fd); /*=============================== TRIGGER SYSCALL ===========================*/ @@ -66,12 +69,15 @@ TEST(SyscallExit, openat2X_success) /* Parameter 6: resolve (type: PT_FLAGS32) */ evt_test->assert_numeric_param(6, (uint32_t)PPM_RESOLVE_BENEATH | PPM_RESOLVE_NO_MAGICLINKS); +#if defined(__loongarch64) +#elif /* Parameter 7: dev (type: PT_UINT32) */ evt_test->assert_numeric_param(7, dev); /* Parameter 8: ino (type: PT_UINT64) */ evt_test->assert_numeric_param(8, inode); - +#endif + /*=============================== ASSERT PARAMETERS ===========================*/ evt_test->assert_num_params_pushed(8); @@ -164,12 +170,15 @@ TEST(SyscallExit, openat2X_create_success) syscall(__NR_unlinkat, AT_FDCWD, pathname, 0); /* remove file before creating it */ int32_t fd = syscall(__NR_openat2, dirfd, pathname, &how, sizeof(struct open_how)); assert_syscall_state(SYSCALL_SUCCESS, "openat2", fd, NOT_EQUAL, -1); - + +#if defined(__loongarch64) +#elif /* Call `fstat` to retrieve the `dev` and `ino`. */ struct stat file_stat; assert_syscall_state(SYSCALL_SUCCESS, "fstat", syscall(__NR_fstat, fd, &file_stat), NOT_EQUAL, -1); uint32_t dev = (uint32_t)file_stat.st_dev; uint64_t inode = file_stat.st_ino; +#endif close(fd); /*=============================== TRIGGER SYSCALL ===========================*/ @@ -207,12 +216,15 @@ TEST(SyscallExit, openat2X_create_success) /* Parameter 6: resolve (type: PT_FLAGS32) */ evt_test->assert_numeric_param(6, (uint32_t)PPM_RESOLVE_BENEATH | PPM_RESOLVE_NO_MAGICLINKS); +#if defined(__loongarch64) +#elif /* Parameter 7: dev (type: PT_UINT32) */ evt_test->assert_numeric_param(7, dev); /* Parameter 8: ino (type: PT_UINT64) */ evt_test->assert_numeric_param(8, inode); - +#endif + /*=============================== ASSERT PARAMETERS ===========================*/ evt_test->assert_num_params_pushed(8); diff --git a/test/libscap/test_suites/engines/gvisor/gvisor_parsers.cpp b/test/libscap/test_suites/engines/gvisor/gvisor_parsers.cpp index d6e88d58767..0487aa1c097 100644 --- a/test/libscap/test_suites/engines/gvisor/gvisor_parsers.cpp +++ b/test/libscap/test_suites/engines/gvisor/gvisor_parsers.cpp @@ -31,6 +31,8 @@ limitations under the License. #include "../../driver/syscall_compat_aarch64.h" #elif __s390x__ #include "../../driver/syscall_compat_s390x.h" +#elif __loongarch64 +#include "../../driver/syscall_compat_loongarch64.h" #endif /* __x86_64__ */ template diff --git a/userspace/libscap/engine/gvisor/parsers.cpp b/userspace/libscap/engine/gvisor/parsers.cpp index 323639f1fcc..1568f810586 100644 --- a/userspace/libscap/engine/gvisor/parsers.cpp +++ b/userspace/libscap/engine/gvisor/parsers.cpp @@ -37,6 +37,8 @@ limitations under the License. #include #elif __riscv #include +#elif __loongarch64 +#include "../../driver/syscall_compat_loongarch64.h" #endif /* __x86_64__ */ #include