Skip to content

Commit

Permalink
miri: Update RTT related TCs
Browse files Browse the repository at this point in the history
* Covered RMIs: RTT_DESTROY, RTT_READ_ENTRY, RTT_INIT_RIPAS

Signed-off-by: Sangwan Kwon <[email protected]>
  • Loading branch information
bitboom committed Oct 14, 2024
1 parent 8466a91 commit 0733283
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 32 deletions.
2 changes: 2 additions & 0 deletions rmm/src/realm/mm/stage2_translation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,12 @@ impl<'a> IPATranslation for Stage2Translation<'a> {
if let Ok(_x) = res {
match invalidate {
Tlbi::LEAF(vmid) => {
#[cfg(not(any(miri, test)))]
Self::tlbi_by_vmid_ipa(level, map_addr, vmid);
self.dirty = true;
}
Tlbi::BREAKDOWN(vmid) => {
#[cfg(not(any(miri, test)))]
Self::tlbi_by_vmid_ipa_range(level, map_addr, vmid);
self.dirty = true;
}
Expand Down
8 changes: 1 addition & 7 deletions rmm/src/rmi/realm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,7 @@ mod test {
assert!(rd_obj.at_state(State::Active));
};

let ret = rmi::<REALM_DESTROY>(&[rd]);
assert_eq!(ret[0], SUCCESS);

for mocking_addr in &[granule_addr(0), granule_addr(1)] {
let ret = rmi::<GRANULE_UNDELEGATE>(&[*mocking_addr]);
assert_eq!(ret[0], SUCCESS);
}
realm_destroy(rd);
}

// Source: https://github.com/ARM-software/cca-rmm-acs
Expand Down
112 changes: 88 additions & 24 deletions rmm/src/rmi/rtt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,26 +357,21 @@ pub fn validate_ipa(rd: &Rd, ipa: usize) -> Result<(), Error> {
#[cfg(test)]
mod test {
use crate::granule::array::granule_addr;
use crate::rmi::{GRANULE_DELEGATE, RTT_CREATE, SUCCESS};
use crate::realm::rd::{Rd, State};
use crate::rmi::{
GRANULE_DELEGATE, GRANULE_UNDELEGATE, RTT_CREATE, RTT_DESTROY, RTT_INIT_RIPAS,
RTT_READ_ENTRY, SUCCESS,
};
use crate::test_utils::*; // alloc_granule

use alloc::vec;

// Source: https://github.com/ARM-software/cca-rmm-acs
// Test Case: cmd_rtt_create
// Covered RMIs: RTT_CREATE, RTT_DESTROY, RTT_READ_ENTRY
#[test]
fn rmi_rtt_create_positive() {
let rd = realm_create();
let mut ipa: usize = 0x0;
let mut level: usize = 0x1;

for mocking_addr in &[
granule_addr(3),
granule_addr(4),
granule_addr(5),
granule_addr(6),
] {
let ret = rmi::<GRANULE_DELEGATE>(&[*mocking_addr]);
assert_eq!(ret[0], SUCCESS);
}

let (rtt1, rtt2, rtt3, rtt4) = (
granule_addr(3),
Expand All @@ -385,34 +380,103 @@ mod test {
granule_addr(6),
);

use crate::realm::rd::{Rd, State};
for rtt in &[rtt1, rtt2, rtt3, rtt4] {
let ret = rmi::<GRANULE_DELEGATE>(&[*rtt]);
assert_eq!(ret[0], SUCCESS);
}

let test_data = vec![
(rtt1, 0x0, 0x1),
(rtt2, 0x0, 0x2),
(rtt3, 0x0, 0x3),
(rtt4, 0x40000000, 0x2),
];

unsafe {
let rd_obj = &*(rd as *const Rd);
assert!(rd_obj.at_state(State::New));
};

let ret = rmi::<RTT_CREATE>(&[rd, rtt1, ipa, level]);
assert_eq!(ret[0], SUCCESS);

// This seems that it should be a failure condition
unsafe {
let mut rd_obj = &mut *(rd as *mut Rd);
rd_obj.set_state(State::SystemOff);
assert!(rd_obj.at_state(State::SystemOff));
};

level = 0x2;
let ret = rmi::<RTT_CREATE>(&[rd, rtt2, ipa, level]);
for (rtt, ipa, level) in &test_data {
let ret = rmi::<RTT_CREATE>(&[rd, *rtt, *ipa, *level]);
assert_eq!(ret[0], SUCCESS);
}

let (rtt4_ipa, rtt4_level) = (test_data[3].1, test_data[3].2);
let ret = rmi::<RTT_READ_ENTRY>(&[rd, rtt4_ipa, rtt4_level - 1]);
assert_eq!(ret[0], SUCCESS);

level = 0x3;
let ret = rmi::<RTT_CREATE>(&[rd, rtt3, ipa, level]);
let (state, desc) = (ret[2], ret[3]);
const RMI_TABLE: usize = 2;
assert_eq!(state, RMI_TABLE);
assert_eq!(desc, rtt4);

for (_, ipa, level) in test_data.iter().rev() {
let ret = rmi::<RTT_DESTROY>(&[rd, *ipa, *level]);
assert_eq!(ret[0], SUCCESS);
}

for rtt in &[rtt1, rtt2, rtt3, rtt4] {
let ret = rmi::<GRANULE_UNDELEGATE>(&[*rtt]);
assert_eq!(ret[0], SUCCESS);
}

realm_destroy(rd);
}

// Source: https://github.com/ARM-software/cca-rmm-acs
// Test Case: cmd_rtt_init_ripas
// Covered RMIs: RTT_INIT_RIPAS, RTT_READ_ENTRY
#[test]
fn rmi_rtt_init_ripas_positive() {
let rd = realm_create();

let (rtt1, rtt2, rtt3) = (granule_addr(3), granule_addr(4), granule_addr(5));

for rtt in &[rtt1, rtt2, rtt3] {
let ret = rmi::<GRANULE_DELEGATE>(&[*rtt]);
assert_eq!(ret[0], SUCCESS);
}

let test_data = vec![(rtt1, 0x0, 0x1), (rtt2, 0x0, 0x2), (rtt3, 0x0, 0x3)];

for (rtt, ipa, level) in &test_data {
let ret = rmi::<RTT_CREATE>(&[rd, *rtt, *ipa, *level]);
assert_eq!(ret[0], SUCCESS);
}

let base = test_data[2].1;
let top = 0x1000;
let ret = rmi::<RTT_INIT_RIPAS>(&[rd, base, top]);
assert_eq!(ret[0], SUCCESS);
assert_eq!(ret[1], top);

ipa = 0x40000000;
level = 0x2;
let ret = rmi::<RTT_CREATE>(&[rd, rtt4, ipa, level]);
let (rtt3_ipa, rtt3_level) = (test_data[2].1, test_data[2].2);
let ret = rmi::<RTT_READ_ENTRY>(&[rd, rtt3_ipa, rtt3_level]);
assert_eq!(ret[0], SUCCESS);

let (level, ripas) = (ret[1], ret[4]);
const RMI_RAM: usize = 1;
assert_eq!(level, rtt3_level);
assert_eq!(ripas, RMI_RAM);

for (_, ipa, level) in test_data.iter().rev() {
let ret = rmi::<RTT_DESTROY>(&[rd, *ipa, *level]);
assert_eq!(ret[0], SUCCESS);
}

for rtt in &[rtt1, rtt2, rtt3] {
let ret = rmi::<GRANULE_UNDELEGATE>(&[*rtt]);
assert_eq!(ret[0], SUCCESS);
}

realm_destroy(rd);
}
}
12 changes: 11 additions & 1 deletion rmm/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::event::Mainloop;
use crate::granule::array::granule_addr; // alloc_granule
use crate::monitor::Monitor;
use crate::rmi::realm::Params;
use crate::rmi::{GRANULE_DELEGATE, REALM_CREATE, SUCCESS};
use crate::rmi::{GRANULE_DELEGATE, GRANULE_UNDELEGATE, REALM_CREATE, REALM_DESTROY, SUCCESS};

use alloc::vec::Vec;

Expand Down Expand Up @@ -56,3 +56,13 @@ pub fn realm_create() -> usize {

rd
}

pub fn realm_destroy(rd: usize) {
let ret = rmi::<REALM_DESTROY>(&[rd]);
assert_eq!(ret[0], SUCCESS);

for mocking_addr in &[granule_addr(0), granule_addr(1)] {
let ret = rmi::<GRANULE_UNDELEGATE>(&[*mocking_addr]);
assert_eq!(ret[0], SUCCESS);
}
}

0 comments on commit 0733283

Please sign in to comment.