From d90d572bc99973bfb40df3cdd6d99a491b9920ba Mon Sep 17 00:00:00 2001 From: Guillume DIDIER Date: Tue, 5 Jan 2021 11:40:34 +0100 Subject: [PATCH] Update cache util for new nightly --- cache_utils/src/bin/l3.rs | 2 +- cache_utils/src/calibrate_2t.rs | 33 ++++++++++++++++++++++++++++ cache_utils/src/calibration.rs | 39 +++++---------------------------- cache_utils/src/lib.rs | 3 +++ cache_utils/src/main.rs | 3 +-- 5 files changed, 43 insertions(+), 37 deletions(-) diff --git a/cache_utils/src/bin/l3.rs b/cache_utils/src/bin/l3.rs index b1437fe..d643dfd 100644 --- a/cache_utils/src/bin/l3.rs +++ b/cache_utils/src/bin/l3.rs @@ -2,7 +2,7 @@ use cache_utils::flush; use cache_utils::mmap::MMappedMemory; pub fn main() { - let m = MMappedMemory::new(2 << 20); + let m = MMappedMemory::new(2 << 20, true); let array = m.slice(); loop { unsafe { diff --git a/cache_utils/src/calibrate_2t.rs b/cache_utils/src/calibrate_2t.rs index e69de29..1cef30a 100644 --- a/cache_utils/src/calibrate_2t.rs +++ b/cache_utils/src/calibrate_2t.rs @@ -0,0 +1,33 @@ +use crate::calibration::{CalibrateResult, CalibrateResult2T, HashMap, ASVP}; + +pub fn calibration_result_to_ASVP T>( + results: Vec, + analysis: Analysis, + slicing: &impl Fn(usize) -> u8, +) -> Result, nix::Error> { + let mut analysis_result: HashMap = HashMap::new(); + for calibrate_2t_result in results { + let attacker = calibrate_2t_result.main_core; + let victim = calibrate_2t_result.helper_core; + match calibrate_2t_result.res { + Err(e) => return Err(e), + Ok(calibrate_1t_results) => { + for result_1t in calibrate_1t_results { + let offset = result_1t.offset; + let page = result_1t.page; + let addr = page + offset as usize; + let slice = slicing(addr as usize); + let analysed = analysis(result_1t); + let asvp = ASVP { + attacker, + slice, + victim, + page, + }; + analysis_result.insert(asvp, analysed); + } + } + } + } + Ok(analysis_result) +} diff --git a/cache_utils/src/calibration.rs b/cache_utils/src/calibration.rs index 1bed49e..39af87c 100644 --- a/cache_utils/src/calibration.rs +++ b/cache_utils/src/calibration.rs @@ -24,6 +24,9 @@ use std::sync::Arc; #[cfg(feature = "use_std")] use std::thread; +#[cfg(feature = "use_std")] +pub use crate::calibrate_2t::*; + extern crate alloc; use crate::calibration::Verbosity::*; use alloc::vec; @@ -37,9 +40,9 @@ use atomic::Atomic; use core::hash::Hash; use core::ops::{Add, AddAssign}; #[cfg(feature = "no_std")] -use hashbrown::HashMap; +pub use hashbrown::HashMap; #[cfg(feature = "use_std")] -use std::collections::HashMap; +pub use std::collections::HashMap; #[derive(Ord, PartialOrd, Eq, PartialEq)] pub enum Verbosity { @@ -1576,38 +1579,6 @@ impl Threshold { } } -pub fn calibration_result_to_ASVP T>( - results: Vec, - analysis: Analysis, - slicing: &impl Fn(usize) -> u8, -) -> Result, nix::Error> { - let mut analysis_result: HashMap = HashMap::new(); - for calibrate_2t_result in results { - let attacker = calibrate_2t_result.main_core; - let victim = calibrate_2t_result.helper_core; - match calibrate_2t_result.res { - Err(e) => return Err(e), - Ok(calibrate_1t_results) => { - for result_1t in calibrate_1t_results { - let offset = result_1t.offset; - let page = result_1t.page; - let addr = page + offset as usize; - let slice = slicing(addr as usize); - let analysed = analysis(result_1t); - let asvp = ASVP { - attacker, - slice, - victim, - page, - }; - analysis_result.insert(asvp, analysed); - } - } - } - } - Ok(analysis_result) -} - pub fn map_values(input: HashMap, f: F) -> HashMap where K: Hash + Eq, diff --git a/cache_utils/src/lib.rs b/cache_utils/src/lib.rs index 74c7440..f6b422b 100644 --- a/cache_utils/src/lib.rs +++ b/cache_utils/src/lib.rs @@ -21,6 +21,9 @@ pub mod prefetcher; pub mod frequency; +#[cfg(feature = "use_std")] +mod calibrate_2t; + use core::arch::x86_64 as arch_x86; use core::ptr; diff --git a/cache_utils/src/main.rs b/cache_utils/src/main.rs index c8faec5..93ddab1 100644 --- a/cache_utils/src/main.rs +++ b/cache_utils/src/main.rs @@ -4,7 +4,6 @@ //fn execute_on_core(FnOnce) -#![feature(vec_resize_default)] use cache_utils::calibration::calibrate_flush; use cache_utils::calibration::Verbosity; @@ -35,7 +34,7 @@ struct Page { } */ pub fn main() { - let m = MMappedMemory::new(SIZE); + let m = MMappedMemory::new(SIZE, true); let array = m.slice(); let old = sched_getaffinity(Pid::from_raw(0)).unwrap();