Determine slice using msr instead of reversed hashing fn
This commit is contained in:
parent
087997ce5c
commit
989ae0c0ea
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -126,6 +126,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"atomic",
|
"atomic",
|
||||||
"bitvec",
|
"bitvec",
|
||||||
|
"cache_slice",
|
||||||
"cpuid",
|
"cpuid",
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
"itertools 0.12.1",
|
"itertools 0.12.1",
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use cache_slice::monitor_address;
|
use cache_slice::determine_slice;
|
||||||
use cache_slice::utils::core_per_package;
|
use cache_slice::utils::core_per_package;
|
||||||
use nix::sched::{sched_getaffinity, sched_setaffinity, CpuSet};
|
use nix::sched::{sched_getaffinity, sched_setaffinity, CpuSet};
|
||||||
use nix::unistd::Pid;
|
use nix::unistd::Pid;
|
||||||
@ -24,10 +24,9 @@ pub fn main() {
|
|||||||
cpu_set.set(core).unwrap();
|
cpu_set.set(core).unwrap();
|
||||||
sched_setaffinity(Pid::this(), &cpu_set).unwrap();
|
sched_setaffinity(Pid::this(), &cpu_set).unwrap();
|
||||||
for addr in target.iter() {
|
for addr in target.iter() {
|
||||||
let res = unsafe { monitor_address(addr as *const u64 as *const u8, core as u8, nb_cores) }.unwrap();
|
let slice = determine_slice(addr, nb_cores, Some(core));
|
||||||
let slice = res.iter().enumerate().max_by_key(|(_i, val)| { **val });
|
|
||||||
match slice {
|
match slice {
|
||||||
Some((slice, _)) => {
|
Some(slice) => {
|
||||||
println!("({:2}) Slice for addr {:x}: {}", core, addr as *const u64 as usize, slice)
|
println!("({:2}) Slice for addr {:x}: {}", core, addr as *const u64 as usize, slice)
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
@ -36,14 +35,13 @@ pub fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for addr in target.iter() {
|
for addr in target.iter() {
|
||||||
let res = unsafe { monitor_address(addr as *const u64 as *const u8, 0, nb_cores) }.unwrap();
|
let slice = determine_slice(addr, nb_cores, Some(0));
|
||||||
let slice = res.iter().enumerate().max_by_key(|(_i, val)| { **val });
|
|
||||||
match slice {
|
match slice {
|
||||||
Some((slice, _)) => {
|
Some(slice) => {
|
||||||
println!("({:2}) Slice for addr {:x}: {}", 0, addr as *const u64 as usize, slice)
|
println!("({:2}) Slice for addr {:x}: {}", core, addr as *const u64 as usize, slice)
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
eprintln!("({:2}) Failed to find slice for addr {:x}", 0, addr as *const u64 as usize)
|
eprintln!("({:2}) Failed to find slice for addr {:x}", core, addr as *const u64 as usize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,6 +125,22 @@ pub unsafe fn monitor_address(addr: *const u8, cpu: u8, max_cbox: u16) -> Result
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn determine_slice(addr: *const u8, nb_cores: u16, core: Option<u16>) -> Option<usize> {
|
||||||
|
let res = unsafe {
|
||||||
|
monitor_address(addr as *const u64 as *const u8, core.unwrap_or(0) as u8, nb_cores)
|
||||||
|
}.unwrap();
|
||||||
|
|
||||||
|
let slice = res.iter().enumerate().max_by_key(|(_i, val)| { **val });
|
||||||
|
|
||||||
|
let maxi = res.iter().max().unwrap();
|
||||||
|
let slice = if *maxi == 0 { None } else { slice };
|
||||||
|
|
||||||
|
match slice {
|
||||||
|
Some((slice, _)) => { Some(slice) }
|
||||||
|
None => { None }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -20,6 +20,7 @@ nix = { version = "0.29.0", optional = true, features = ["process", "mman", "sch
|
|||||||
libc = { version = "0.2.153", optional = true }
|
libc = { version = "0.2.153", optional = true }
|
||||||
hashbrown = { version = "0.11.2", optional = true }
|
hashbrown = { version = "0.11.2", optional = true }
|
||||||
turn_lock = { path = "../turn_lock", optional = true }
|
turn_lock = { path = "../turn_lock", optional = true }
|
||||||
|
cache_slice = { path = "../cache_slice" }
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
bitvec = { version = "0.22.3", optional = true }
|
bitvec = { version = "0.22.3", optional = true }
|
||||||
|
|
||||||
|
@ -7,6 +7,8 @@ use crate::complex_addressing::CacheAttackSlicing;
|
|||||||
use core::arch::x86_64 as arch_x86;
|
use core::arch::x86_64 as arch_x86;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use nix::sched::{sched_getaffinity, sched_setaffinity, CpuSet};
|
use nix::sched::{sched_getaffinity, sched_setaffinity, CpuSet};
|
||||||
|
use cache_slice::utils::core_per_package;
|
||||||
|
use cache_slice::determine_slice;
|
||||||
use nix::unistd::Pid;
|
use nix::unistd::Pid;
|
||||||
use nix::Error;
|
use nix::Error;
|
||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
@ -210,12 +212,14 @@ fn calibrate_fixed_freq_2_thread_impl<I: Iterator<Item = (usize, usize)>, T>(
|
|||||||
Some(ref ima) => Box::new(ima.values().copied()),
|
Some(ref ima) => Box::new(ima.values().copied()),
|
||||||
None => Box::new((0..len as isize).step_by(cache_line_length)),
|
None => Box::new((0..len as isize).step_by(cache_line_length)),
|
||||||
};*/
|
};*/
|
||||||
|
let nb_cores = core_per_package();
|
||||||
|
|
||||||
for i in offsets {
|
for i in offsets {
|
||||||
let pointer = unsafe { p.offset(i) };
|
let pointer = unsafe { p.offset(i) };
|
||||||
params.address = pointer;
|
params.address = pointer;
|
||||||
|
|
||||||
let hash = slicing.hash(pointer as usize);
|
//let hash = slicing.hash(pointer as usize);
|
||||||
|
let hash = determine_slice(pointer, nb_cores, None).unwrap();
|
||||||
|
|
||||||
if options.verbosity >= Thresholds {
|
if options.verbosity >= Thresholds {
|
||||||
print!("Calibration for {:p}", pointer);
|
print!("Calibration for {:p}", pointer);
|
||||||
|
Loading…
Reference in New Issue
Block a user