From 0d08cb1fe494cf19079bfdd14449d79016050105 Mon Sep 17 00:00:00 2001 From: Tie Liu Date: Tue, 29 Aug 2023 14:54:01 +0800 Subject: [PATCH 1/2] add set hpage rto flag and remove build id check --- bin/daemon.rs | 3 +++ bin/kmod_util.rs | 15 +++++++++++++++ src/elf_read_elf.c | 4 ++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/bin/daemon.rs b/bin/daemon.rs index 121b55d..94ea883 100644 --- a/bin/daemon.rs +++ b/bin/daemon.rs @@ -11,6 +11,7 @@ use crate::lib::fs_ext; use crate::kmod_util::set_ko_rto_flag; +use crate::kmod_util::set_hpage_rto_flag; use crate::kmod_util::insmod_sysboost_ko; use crate::config::RtoConfig; use crate::config::read_config; @@ -182,6 +183,7 @@ fn refresh_all_config(rto_configs: &mut Vec) { if rto_configs.len() > 0 { set_ko_rto_flag(true); + set_hpage_rto_flag(true); } } @@ -258,6 +260,7 @@ fn check_files_modify(inotify: &mut Inotify) -> bool { fn start_service() { set_ko_rto_flag(false); + set_hpage_rto_flag(false); clean_last_rto(); let mut rto_configs: Vec = Vec::new(); diff --git a/bin/kmod_util.rs b/bin/kmod_util.rs index 193142c..78e0e86 100644 --- a/bin/kmod_util.rs +++ b/bin/kmod_util.rs @@ -12,6 +12,7 @@ use crate::lib::process_ext::run_child; const KO_RTO_PARAM_PATH: &str = "/sys/module/sysboost_loader/parameters/use_rto"; +const HPAGE_RTO_PARAM_PATH: &str = "/sys/module/sysboost_loader/parameters/use_hpage"; const KO_PATH: &str = "/lib/modules/sysboost/sysboost_loader.ko"; // echo 1 > /sys/module/sysboost_loader/parameters/use_rto @@ -28,6 +29,20 @@ pub fn set_ko_rto_flag(is_set: bool) -> i32 { return ret; } +// echo 1 > /sys/module/sysboost_loader/parameters/use_hpage +pub fn set_hpage_rto_flag(is_set: bool) -> i32 { + let mut args: Vec = Vec::new(); + if is_set { + args.push("1".to_string()); + } else { + args.push("0".to_string()); + } + args.push(">".to_string()); + args.push(HPAGE_RTO_PARAM_PATH.to_string()); + let ret = run_child("/usr/bin/echo", &args); + return ret; +} + fn insmod_ko(path: &String) { let mut args: Vec = Vec::new(); args.push(path.to_string()); diff --git a/src/elf_read_elf.c b/src/elf_read_elf.c index 29cd4a7..3a1796b 100644 --- a/src/elf_read_elf.c +++ b/src/elf_read_elf.c @@ -741,9 +741,9 @@ static int read_relocation_file(char *file_name, elf_file_t *ef) } // Compare the value with the build ID in the ELF file, the length of the build ID is 40 characters. + // In the future, you need to modify related packages to ensure that the build ID of the relocation file is the same as that of the elf file. if (memcmp(ef->build_id, old_build_id, BUILD_ID_LEN) != 0) { - SI_LOG_ERR("build id mismatch for %s\n", rel_file_name); - return -1; + SI_LOG_INFO("build id mismatch for %s\n", rel_file_name); } return 0; -- Gitee From 98da517537dfbe327ce9626948c3f07a6ba3495f Mon Sep 17 00:00:00 2001 From: Tie Liu Date: Tue, 29 Aug 2023 18:38:39 +0800 Subject: [PATCH 2/2] fix some bugs of sysboostd --- bin/aot.rs | 14 ++++++--- bin/daemon.rs | 24 ++++++++-------- bin/kmod_util.rs | 41 ++++++++++++++++++--------- src/static_template/static_template.c | 1 + 4 files changed, 50 insertions(+), 30 deletions(-) diff --git a/bin/aot.rs b/bin/aot.rs index 047f542..0e3a854 100644 --- a/bin/aot.rs +++ b/bin/aot.rs @@ -139,8 +139,8 @@ pub fn gen_app_rto(conf: &RtoConfig) -> i32 { } let mut args: Vec = Vec::new(); - args.push(format!("--output={}.tmp.rto", conf.elf_path)); - args.push(format!("-{}", conf.mode)); + //args.push(format!("--output={}.tmp.rto", conf.elf_path)); + args.push(format!("--{}", conf.mode)); args.push(conf.elf_path.to_owned()); for lib in conf.libs.iter() { args.push(lib.split_whitespace().collect()); @@ -149,7 +149,13 @@ pub fn gen_app_rto(conf: &RtoConfig) -> i32 { if ret != 0 { return ret; } - - ret = fs_ext::move_file(&format!("{}.rto", conf.elf_path), &format!("{}.tmp.rto", conf.elf_path)); + let mut set: Vec = Vec::new(); + set.push("--set-rto".to_string()); + set.push("/usr/bin/bash.rto".to_string()); + ret = run_child(SYSBOOST_PATH, &set); + if ret != 0 { + return ret; + } + //ret = fs_ext::move_file(&format!("{}.rto", conf.elf_path), &format!("{}.tmp.rto", conf.elf_path)); return ret; } diff --git a/bin/daemon.rs b/bin/daemon.rs index 94ea883..8781d2a 100644 --- a/bin/daemon.rs +++ b/bin/daemon.rs @@ -109,22 +109,22 @@ fn process_config(path: PathBuf) -> Option { None => return None, }; - let elf = match parse_elf_file(&conf.elf_path) { - Some(elf) => elf, - None => return None, - }; + //let elf = match parse_elf_file(&conf.elf_path) { + // Some(elf) => elf, + // None => return None, + //}; // auto get lib path // In static-nolibc mode, ld and libc need to be deleted after detection. // In share mode, no detection is performed based on libs. if conf.mode == "static" { - let libs = find_libs(&conf, &elf); - conf.libs = libs; + //let libs = find_libs(&conf, &elf); + //conf.libs = libs; } else if conf.mode == "static-nolibc" { - let mut libs = find_libs(&conf, &elf); - libs.retain(|s| !s.contains(LDSO)); - libs.retain(|s| !s.contains(LIBCSO)); - conf.libs = libs; + //let mut libs = find_libs(&conf, &elf); + //libs.retain(|s| !s.contains(LDSO)); + //libs.retain(|s| !s.contains(LIBCSO)); + //conf.libs = libs; } // add elf file to watch list @@ -259,8 +259,8 @@ fn check_files_modify(inotify: &mut Inotify) -> bool { } fn start_service() { - set_ko_rto_flag(false); - set_hpage_rto_flag(false); + set_ko_rto_flag(true); + set_hpage_rto_flag(true); clean_last_rto(); let mut rto_configs: Vec = Vec::new(); diff --git a/bin/kmod_util.rs b/bin/kmod_util.rs index 78e0e86..8cbc908 100644 --- a/bin/kmod_util.rs +++ b/bin/kmod_util.rs @@ -10,6 +10,7 @@ // Create: 2023-8-26 use crate::lib::process_ext::run_child; +use std::fs; const KO_RTO_PARAM_PATH: &str = "/sys/module/sysboost_loader/parameters/use_rto"; const HPAGE_RTO_PARAM_PATH: &str = "/sys/module/sysboost_loader/parameters/use_hpage"; @@ -17,30 +18,42 @@ const KO_PATH: &str = "/lib/modules/sysboost/sysboost_loader.ko"; // echo 1 > /sys/module/sysboost_loader/parameters/use_rto pub fn set_ko_rto_flag(is_set: bool) -> i32 { - let mut args: Vec = Vec::new(); + let mut args; if is_set { - args.push("1".to_string()); + args = "1".to_string(); } else { - args.push("0".to_string()); + args= "0".to_string(); } - args.push(">".to_string()); - args.push(KO_RTO_PARAM_PATH.to_string()); - let ret = run_child("/usr/bin/echo", &args); - return ret; + match fs::write(KO_RTO_PARAM_PATH.to_string(), args) { + Ok(_) => { + return 0; + } + Err(e) => { + log::error!("Error writing use_rto"); + return -1; + } + } + 0 } // echo 1 > /sys/module/sysboost_loader/parameters/use_hpage pub fn set_hpage_rto_flag(is_set: bool) -> i32 { - let mut args: Vec = Vec::new(); + let mut args; if is_set { - args.push("1".to_string()); + args = "1".to_string(); } else { - args.push("0".to_string()); + args= "0".to_string(); } - args.push(">".to_string()); - args.push(HPAGE_RTO_PARAM_PATH.to_string()); - let ret = run_child("/usr/bin/echo", &args); - return ret; + match fs::write(HPAGE_RTO_PARAM_PATH.to_string(), args) { + Ok(_) => { + return 0; + } + Err(e) => { + log::error!("Error writing use_hpage"); + return -1; + } + } + 0 } fn insmod_ko(path: &String) { diff --git a/src/static_template/static_template.c b/src/static_template/static_template.c index 951c0ec..fb7df7e 100644 --- a/src/static_template/static_template.c +++ b/src/static_template/static_template.c @@ -113,6 +113,7 @@ int main(void) NO_COMPILE_OPTIMIZE("sigfillset"); NO_COMPILE_OPTIMIZE("siglongjmp"); NO_COMPILE_OPTIMIZE("vfprintf"); + NO_COMPILE_OPTIMIZE("arc4random"); #ifdef __aarch64__ // The __stack_chk_guard and __stack_chk_fail symbols are normally supplied by a GCC library called libssp -- Gitee