Various experiments

This commit is contained in:
Guillume DIDIER 2021-08-02 15:02:52 +02:00
parent 84cf28f21c
commit bf931bfa52
5 changed files with 42 additions and 36 deletions

View File

@ -504,13 +504,15 @@ impl<T: TimingChannelPrimitives> MultipleAddrCacheSideChannel for TopologyAwareT
.clone() .clone()
.into_iter() .into_iter()
.map(|addr: *const u8| unsafe { .map(|addr: *const u8| unsafe {
&*slice_from_raw_parts(get_vpn(addr) as *const u8, PAGE_LEN) let p = get_vpn(addr) as *const u8;
let ret = &*slice_from_raw_parts(p, PAGE_LEN);
(p, ret)
}) })
.collect::<HashSet<&[u8]>>(); .collect::<HashMap<*const u8, &[u8]>>();
let mut res = match Self::calibration_for_core_pairs( let mut res = match Self::calibration_for_core_pairs(
&self.t, &self.t,
core_pair.into_iter(), core_pair.into_iter(),
pages.into_iter(), pages.into_iter().map(|(k, v)| v),
) { ) {
Err(e) => { Err(e) => {
return Err(ChannelFatalError::Oops); return Err(ChannelFatalError::Oops);

View File

@ -0,0 +1,18 @@
use prefetcher_reverse::{Prober, PAGE_CACHELINE_LEN};
pub const NUM_ITERATION: usize = 1 << 10;
fn exp(delay: u64) {
let mut prober = Prober::<2>::new(63).unwrap();
prober.set_delay(delay);
let pattern = (0usize..(PAGE_CACHELINE_LEN * 2usize)).collect::<Vec<usize>>();
let result = prober.full_page_probe(pattern, NUM_ITERATION as u32, 100);
println!("{}", result);
}
fn main() {
for delay in [0, 5, 10, 50] {
println!("Delay after each access: {} us", delay);
exp(delay);
}
}

View File

@ -20,8 +20,7 @@ pub const NUM_PAGES: usize = 256;
fn exp(delay: u64) { fn exp(delay: u64) {
for (name, pattern) in reference_patterns() { for (name, pattern) in reference_patterns() {
let mut prober = Prober::new(63).unwrap(); let mut prober = Prober::<1>::new(63).unwrap();
prober.set_delay(delay);
println!("{}", name); println!("{}", name);
let result = prober.full_page_probe(pattern, NUM_ITERATION as u32, 100); let result = prober.full_page_probe(pattern, NUM_ITERATION as u32, 100);

View File

@ -1,4 +1,7 @@
#![deny(unsafe_op_in_unsafe_fn)] #![deny(unsafe_op_in_unsafe_fn)]
#![feature(const_generics)]
#![feature(const_evaluatable_checked)]
use crate::Probe::{Flush, FullFlush, Load}; use crate::Probe::{Flush, FullFlush, Load};
use basic_timing_cache_channel::{TopologyAwareError, TopologyAwareTimingChannel}; use basic_timing_cache_channel::{TopologyAwareError, TopologyAwareTimingChannel};
use cache_side_channel::CacheStatus::{Hit, Miss}; use cache_side_channel::CacheStatus::{Hit, Miss};
@ -22,7 +25,7 @@ use std::{thread, time};
pub const CACHE_LINE_LEN: usize = 64; pub const CACHE_LINE_LEN: usize = 64;
pub const PAGE_CACHELINE_LEN: usize = PAGE_LEN / CACHE_LINE_LEN; pub const PAGE_CACHELINE_LEN: usize = PAGE_LEN / CACHE_LINE_LEN;
pub struct Prober { pub struct Prober<const GS: usize> {
pages: Vec<MMappedMemory<u8>>, pages: Vec<MMappedMemory<u8>>,
ff_handles: Vec<Vec<FFHandle>>, ff_handles: Vec<Vec<FFHandle>>,
fr_handles: Vec<Vec<FRHandle>>, fr_handles: Vec<Vec<FRHandle>>,
@ -110,7 +113,7 @@ pub struct SingleProbeResult {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct FullPageSingleProbeResult { pub struct FullPageSingleProbeResult<const GS: usize> {
pub pattern: Vec<usize>, pub pattern: Vec<usize>,
pub probe_type: ProbeType, pub probe_type: ProbeType,
pub num_iteration: u32, pub num_iteration: u32,
@ -134,11 +137,11 @@ fn max_stride(offset: usize, len: usize) -> (isize, isize) {
} }
} }
impl Prober { impl<const GS: usize> Prober<GS> {
// turn page into page groups, which can vary in size. // turn page into page groups, which can vary in size.
// calibrate on all pages in a group with offsets within the groups. // calibrate on all pages in a group with offsets within the groups.
// keep track of the max offset // keep track of the max offset
pub fn new(num_pages: usize) -> Result<Prober, ProberError> { pub fn new(num_pages: usize) -> Result<Prober<GS>, ProberError> {
let mut vec = Vec::new(); let mut vec = Vec::new();
let mut handles = Vec::new(); let mut handles = Vec::new();
let (mut ff_channel, cpuset, core) = match FlushAndFlush::new_any_single_core() { let (mut ff_channel, cpuset, core) = match FlushAndFlush::new_any_single_core() {
@ -163,17 +166,17 @@ impl Prober {
}; };
for i in 0..num_pages { for i in 0..num_pages {
let mut p = match MMappedMemory::<u8>::try_new(PAGE_LEN, false) { let mut p = match MMappedMemory::<u8>::try_new(PAGE_LEN * GS, false) {
Ok(p) => p, Ok(p) => p,
Err(e) => { Err(e) => {
return Err(ProberError::NoMem(e)); return Err(ProberError::NoMem(e));
} }
}; };
for j in 0..PAGE_LEN { for j in 0..(PAGE_LEN * GS) {
p[j] = (i * PAGE_CACHELINE_LEN + j) as u8; p[j] = (i * PAGE_CACHELINE_LEN + j) as u8;
} }
let page_addresses = let page_addresses = ((0..(PAGE_LEN * GS)).step_by(CACHE_LINE_LEN))
((0..PAGE_LEN).step_by(CACHE_LINE_LEN)).map(|offset| &p[offset] as *const u8); .map(|offset| &p[offset] as *const u8);
let ff_page_handles = unsafe { ff_channel.calibrate(page_addresses.clone()) }.unwrap(); let ff_page_handles = unsafe { ff_channel.calibrate(page_addresses.clone()) }.unwrap();
let fr_page_handles = unsafe { fr_channel.calibrate_single(page_addresses) }.unwrap(); let fr_page_handles = unsafe { fr_channel.calibrate_single(page_addresses) }.unwrap();
@ -208,22 +211,6 @@ impl Prober {
self.delay = delay; self.delay = delay;
} }
/*
fn probe(&mut self, probe_type: Probe, offset: usize) -> CacheStatus {
let page_index = self.page_indexes.peek().unwrap();
match probe_type {
Probe::Load => {
let h = &mut self.handles[*page_index][offset].fr;
unsafe { self.fr_channel.test_single(h, false) }.unwrap()
}
Probe::Flush => {
let h = &mut self.handles[*page_index][offset].ff;
unsafe { self.ff_channel.test_single(h, false) }.unwrap()
}
}
}
*/
fn probe_pattern_once( fn probe_pattern_once(
&mut self, &mut self,
pattern: &ProbePattern, pattern: &ProbePattern,
@ -313,7 +300,7 @@ impl Prober {
probe_result: match pattern.probe { probe_result: match pattern.probe {
Load(_) => ProbeResult::Load(0), Load(_) => ProbeResult::Load(0),
Flush(_) => ProbeResult::Flush(0), Flush(_) => ProbeResult::Flush(0),
Probe::FullFlush => ProbeResult::FullFlush(vec![0; PAGE_CACHELINE_LEN]), Probe::FullFlush => ProbeResult::FullFlush(vec![0; PAGE_CACHELINE_LEN * GS]),
}, },
}; };
for _ in 0..warmup { for _ in 0..warmup {
@ -333,14 +320,14 @@ impl Prober {
probe_type: ProbeType, probe_type: ProbeType,
num_iteration: u32, num_iteration: u32,
warmup: u32, warmup: u32,
) -> FullPageSingleProbeResult { ) -> FullPageSingleProbeResult<GS> {
let mut result = FullPageSingleProbeResult { let mut result = FullPageSingleProbeResult {
pattern: pattern.pattern.clone(), pattern: pattern.pattern.clone(),
probe_type, probe_type,
num_iteration, num_iteration,
results: vec![], results: vec![],
}; };
for offset in 0..PAGE_CACHELINE_LEN { for offset in 0..(PAGE_CACHELINE_LEN * GS) {
pattern.probe = match probe_type { pattern.probe = match probe_type {
ProbeType::Load => Probe::Load(offset), ProbeType::Load => Probe::Load(offset),
ProbeType::Flush => Probe::Flush(offset), ProbeType::Flush => Probe::Flush(offset),
@ -417,9 +404,9 @@ impl Prober {
impl Display for FullPageDualProbeResults { impl Display for FullPageDualProbeResults {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let mut indices = vec![None; PAGE_CACHELINE_LEN]; let mut indices = vec![None; self.single_probe_results.len()];
let pat_len = self.pattern.len(); let pat_len = self.pattern.len();
let divider = (PAGE_CACHELINE_LEN * self.num_iteration as usize) as f32; let divider = (self.single_probe_results.len() * self.num_iteration as usize) as f32;
for (i, &offset) in self.pattern.iter().enumerate() { for (i, &offset) in self.pattern.iter().enumerate() {
indices[offset] = Some(i); indices[offset] = Some(i);
} }
@ -447,7 +434,7 @@ impl Display for FullPageDualProbeResults {
} }
} }
for i in 0..PAGE_CACHELINE_LEN { for i in 0..(self.single_probe_results.len()) {
let index = indices[i]; let index = indices[i];
let (pat, sf_ac_h, sf_ac_hr, sr_ac_h, sr_ac_hr, ff_ac_h, ff_ac_hr) = match index { let (pat, sf_ac_h, sf_ac_hr, sr_ac_h, sr_ac_hr, ff_ac_h, ff_ac_hr) = match index {

View File

@ -199,7 +199,7 @@ fn main() {
let pattern = generate_pattern(0, 3, 12).unwrap(); let pattern = generate_pattern(0, 3, 12).unwrap();
let pattern4 = generate_pattern(0, 4, 12).unwrap(); let pattern4 = generate_pattern(0, 4, 12).unwrap();
let mut new_prober = Prober::new(63).unwrap(); let mut new_prober = Prober::<1>::new(63).unwrap();
let result = new_prober.full_page_probe(pattern.clone(), NUM_ITERATION as u32, 100); let result = new_prober.full_page_probe(pattern.clone(), NUM_ITERATION as u32, 100);
println!("{}", result); println!("{}", result);
//println!("{:#?}", result); //println!("{:#?}", result);