From a4678ee95c4802f73bf960f285f2d84e83492dce Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 27 Apr 2021 00:39:18 +0800 Subject: [PATCH] remove dependency of xous-names on ticktimer; use d11ctimeout instead this allows susres to manage ticktimer and have secured namespace integration --- services/xous-names/Cargo.toml | 1 - services/xous-names/src/main.rs | 54 +++++++++++++++++++++++++++------ 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/services/xous-names/Cargo.toml b/services/xous-names/Cargo.toml index bf9850147..3fd193d41 100644 --- a/services/xous-names/Cargo.toml +++ b/services/xous-names/Cargo.toml @@ -13,7 +13,6 @@ num-derive = {version = "0.3", default-features = false} num-traits = {version = "0.2", default-features = false} log = "0.4" log-server = {path = "../log-server"} -ticktimer-server = {path = "../ticktimer-server"} xous = {path = "../../xous-rs"} xous-ipc = {path = "../../xous-ipc"} rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]} diff --git a/services/xous-names/src/main.rs b/services/xous-names/src/main.rs index 1d3e2a4ca..9dc067749 100644 --- a/services/xous-names/src/main.rs +++ b/services/xous-names/src/main.rs @@ -15,11 +15,52 @@ use xous_ipc::{String, Buffer}; use log::{error, info}; -const FAIL_TIMEOUT_MS: u64 = 100; +#[cfg(target_os = "none")] +mod implementation { + use utralib::generated::*; + pub struct D11cTimeout { + d11t_csr: utralib::CSR, + } + impl D11cTimeout { + pub fn new() -> Self { + let csr = xous::syscall::map_memory( + xous::MemoryAddress::new(utra::d11ctime::HW_D11CTIME_BASE), + None, + 4096, + xous::MemoryFlags::R | xous::MemoryFlags::W, + ) + .expect("couldn't map D11cTimeout CSR range"); + + D11cTimeout { + d11t_csr: CSR::new(csr.as_mut_ptr() as *mut u32), + } + } + pub fn deterministic_busy_wait(&self) { + let phase = self.d11t_csr.rf(utra::d11ctime::HEARTBEAT_BEAT); + while phase == self.d11t_csr.rf(utra::d11ctime::HEARTBEAT_BEAT) { + xous::yield_slice(); + } + } + } +} + +#[cfg(not(target_os = "none"))] +mod implementation { + pub struct D11cTimeout {} + impl D11cTimeout { + pub fn new() -> Self { + D11cTimeout {} + } + pub fn deterministic_busy_wait(&self) { + // don't do anything for hosted mode + } + } +} #[xous::xous_main] fn xmain() -> ! { + use implementation::*; let debug1 = false; log_server::init_wait().unwrap(); log::set_max_level(log::LevelFilter::Info); @@ -28,7 +69,7 @@ fn xmain() -> ! { let name_server = xous::create_server_with_address(b"xous-name-server") .expect("Couldn't create xousnames-server"); - let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer"); + let d11ctimeout = D11cTimeout::new(); // this limits the number of available servers to be requested to 128...! let mut name_table = FnvIndexMap::<_, _, U128>::new(); @@ -57,15 +98,8 @@ fn xmain() -> ! { response = api::Return::SID(new_sid.into()); } else { - // compute the next interval, rounded to a multiple of FAIL_TIMEOUT_MS to reduce timing side channels - let target_time: u64 = ((ticktimer.elapsed_ms() - / FAIL_TIMEOUT_MS) - + 1) - * FAIL_TIMEOUT_MS; info!("request failed, waiting for deterministic timeout"); - while ticktimer.elapsed_ms() < target_time { - xous::yield_slice(); - } + d11ctimeout.deterministic_busy_wait(); info!("deterministic timeout done"); response = api::Return::Failure }