Hotfix naive basic timing cache channel for use in prefetcher experiments

This commit is contained in:
Guillume DIDIER 2021-07-19 09:01:24 +02:00
parent b7b5cbbfc3
commit 28f75075e3
3 changed files with 63 additions and 12 deletions

View File

@ -41,6 +41,7 @@ pub trait TimingChannelPrimitives: Debug + Send + Sync + Default {
const NEED_RESET: bool;
}
#[derive(Debug)]
pub struct TopologyAwareTimingChannelHandle {
threshold: Threshold,
vpn: VPN,
@ -204,7 +205,7 @@ impl<T: TimingChannelPrimitives> TopologyAwareTimingChannel<T> {
Ok(asvp_best_av_errors)
}
fn new_with_core_pairs(
pub fn new_with_core_pairs(
core_pairs: impl Iterator<Item = (usize, usize)> + Clone,
) -> Result<(Self, usize, usize), TopologyAwareError> {
let m = MMappedMemory::new(PAGE_LEN, false);

View File

@ -1,7 +1,7 @@
use crate::TimingChannelPrimitives;
use cache_side_channel::{
CacheStatus, ChannelFatalError, ChannelHandle, CoreSpec, SideChannelError,
SingleAddrCacheSideChannel,
CacheStatus, ChannelFatalError, ChannelHandle, CoreSpec, MultipleAddrCacheSideChannel,
SideChannelError, SingleAddrCacheSideChannel,
};
use cache_utils::calibration::{get_vpn, only_flush, only_reload, HashMap, Threshold, VPN};
use cache_utils::flush;
@ -58,16 +58,17 @@ impl<T: TimingChannelPrimitives> NaiveTimingChannel<T> {
&mut self,
handle: NaiveTimingChannelHandle,
) -> Result<*const u8, ChannelFatalError> {
if let Some(addr) = self.current.remove(&handle.vpn) {
//if let Some(addr) = self.current.remove(&handle.vpn) {
Ok(addr)
} else {
Err(ChannelFatalError::Oops)
}
//} else {
// Err(ChannelFatalError::Oops)
//}
}
unsafe fn test_impl(
&self,
handle: &mut NaiveTimingChannelHandle,
//limit: u32,
reset: bool,
) -> Result<CacheStatus, SideChannelError> {
// This should be handled in prepare / unprepare
@ -87,12 +88,12 @@ impl<T: TimingChannelPrimitives> NaiveTimingChannel<T> {
addr: *const u8,
) -> Result<NaiveTimingChannelHandle, ChannelFatalError> {
let vpn = get_vpn(addr);
if self.current.get(&vpn).is_some() {
/*if self.current.get(&vpn).is_some() {
return Err(ChannelFatalError::Oops);
} else {
self.current.insert(vpn, addr);
self.current.insert(vpn, addr);*/
Ok(NaiveTimingChannelHandle { vpn, addr })
}
//}
}
}
@ -139,6 +140,7 @@ impl<T: TimingChannelPrimitives + Send + Sync> CovertChannel for NaiveTimingChan
unsafe { self.calibrate_impl(page) }.map_err(|_| ())
}
}
impl<T: TimingChannelPrimitives> SingleAddrCacheSideChannel for NaiveTimingChannel<T> {
type Handle = NaiveTimingChannelHandle;
@ -178,7 +180,52 @@ impl<T: TimingChannelPrimitives> SingleAddrCacheSideChannel for NaiveTimingChann
Ok(result)
}
}
/*
impl<T: TimingChannelPrimitives> MultipleAddrCacheSideChannel for NaiveTimingChannel<T> {
type Handle = NaiveTimingChannelHandle;
const MAX_ADDR: u32 = 0;
unsafe fn test<'a>(
&mut self,
addresses: &mut Vec<&'a mut Self::Handle>,
reset: bool,
) -> Result<Vec<(*const u8, CacheStatus)>, SideChannelError>
where
Self::Handle: 'a,
{
unsafe { self.test_impl(addresses, Self::MAX_ADDR, reset) }
}
unsafe fn prepare<'a>(
&mut self,
addresses: &mut Vec<&'a mut Self::Handle>,
) -> Result<(), SideChannelError>
where
Self::Handle: 'a,
{
unsafe { self.prepare_impl(addresses, Self::MAX_ADDR) }
}
fn victim(&mut self, operation: &dyn Fn()) {
operation()
}
unsafe fn calibrate(
&mut self,
addresses: impl IntoIterator<Item = *const u8> + Clone,
) -> Result<Vec<Self::Handle>, ChannelFatalError> {
let mut result = vec![];
for addr in addresses {
match unsafe { self.calibrate_impl(addr) } {
Ok(handle) => result.push(handle),
Err(e) => {
return Err(e);
}
}
}
Ok(result)
}
}
*/
// Include a helper code to get global threshold model ?
// TODO

View File

@ -1,4 +1,7 @@
use crate::FRPrimitives;
use basic_timing_cache_channel::naive::NaiveTimingChannel;
use cache_side_channel::SingleAddrCacheSideChannel;
pub type NaiveFlushAndReload = NaiveTimingChannel<FRPrimitives>;
pub type NFRHandle = <NaiveFlushAndReload as SingleAddrCacheSideChannel>::Handle;