Skip to content

Commit

Permalink
temporary: share realm data pages with nw
Browse files Browse the repository at this point in the history
Signed-off-by: Bokdeuk Jeong <bd.jeong@samsung.com>
  • Loading branch information
bokdeuk-jeong committed Nov 21, 2022
1 parent e048871 commit 685b279
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion rmm/armv9a/src/exception/trap.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod frame;
mod syndrome;
pub mod syndrome;

use self::frame::TrapFrame;
use self::syndrome::Syndrome;
Expand Down
1 change: 1 addition & 0 deletions rmm/armv9a/src/helper/regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ define_sys_register!(
IL[25 - 25],
ISS[24 - 00],
ISS_BRK_CMT[15 - 00],
S1PTW[7 - 7],
DFSC[5 - 0]
);

Expand Down
43 changes: 23 additions & 20 deletions rmm/armv9a/src/rmi/realm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use monitor::realm::mm::address::{GuestPhysAddr, PhysAddr};
use monitor::{listen, mainloop::Mainloop};

use crate::config::PAGE_SIZE;
use crate::exception::trap::syndrome::Syndrome;
use crate::helper;
use crate::helper::ESR_EL2;
use crate::realm;
use crate::realm::mm::page_table::pte;
use crate::realm::mm::translation_granule_4k::RawPTE;
Expand Down Expand Up @@ -129,21 +131,29 @@ pub fn set_event_handler(mainloop: &mut Mainloop<rmi::Receiver>) {
);

let mut flags = 0;
// TODO: define bit mask
if prot & 0b1 == 0b1 {
flags |= helper::bits_in_reg(RawPTE::S2AP, pte::permission::RW);
} else {
flags |= helper::bits_in_reg(RawPTE::S2AP, pte::permission::RO);
}
if prot & 0b100 == 0b100 {
flags |= helper::bits_in_reg(RawPTE::ATTR, pte::attribute::DEVICE_NGNRE)
} else {
flags |= helper::bits_in_reg(RawPTE::ATTR, pte::attribute::NORMAL)
//FIXME: temporary
unsafe {
if let Some(vcpu) = realm::vcpu::current() {
let esr = vcpu.context.sys_regs.esr_el2 as u32;
// share all data pages except those had s2 page fault with s1ptw is set
match Syndrome::from(esr) {
Syndrome::DataAbort(_) => {
if esr & ESR_EL2::S1PTW as u32 == 0 {
flags |= helper::bits_in_reg(RawPTE::NS, 0b1);
}
}
_ => (),
}
}
}
// TODO: define bit mask
flags |= helper::bits_in_reg(RawPTE::S2AP, pte::permission::RW);

// TODO: shared between NS and Linux Ream for GITS_CBASER
if guest >= 0x40C2_0000 && guest < 0x40C4_0000 {
if prot & 0b100 == 0b100 {
flags |= helper::bits_in_reg(RawPTE::ATTR, pte::attribute::DEVICE_NGNRE);
flags |= helper::bits_in_reg(RawPTE::NS, 0b1);
} else {
flags |= helper::bits_in_reg(RawPTE::ATTR, pte::attribute::NORMAL);
}

realm::registry::get(vm)
Expand All @@ -158,17 +168,11 @@ pub fn set_event_handler(mainloop: &mut Mainloop<rmi::Receiver>) {
flags as usize,
);

// TODO: shared between NS and Linux Ream for GITS_CBASER
if guest >= 0x40C2_0000 && guest < 0x40C4_0000 {
return Ok(());
}

let cmd = usize::from(smc::Code::MarkRealm);
let mut arg = [phys, 0, 0, 0];
let mut remain = size;
while remain > 0 {
//TODO change to use dtb
if arg[0] >= 0x4000_0000 {
if (flags & helper::bits_in_reg(RawPTE::NS, 0b1)) == 0 {
let ret = smc::call(cmd, arg)[0];
if ret != 0 {
//Just show a warn message not return fail
Expand All @@ -178,7 +182,6 @@ pub fn set_event_handler(mainloop: &mut Mainloop<rmi::Receiver>) {
arg[0] += PAGE_SIZE;
remain -= PAGE_SIZE;
}

call.reply(rmi::RET_SUCCESS)?;
Ok(())
});
Expand Down

0 comments on commit 685b279

Please sign in to comment.