Skip to content

Commit 7896091

Browse files
committed
tool: generalise extra cap mapping implementation
Signed-off-by: Krishnan Winter <[email protected]>
1 parent 6ec5219 commit 7896091

File tree

2 files changed

+20
-38
lines changed

2 files changed

+20
-38
lines changed

tool/microkit/src/capdl/builder.rs

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::{
1212

1313
use sel4_capdl_initializer_types::{
1414
object, CapTableEntry, Fill, FillEntry, FillEntryContent, NamedObject, Object, ObjectId, Spec,
15-
Word,
15+
Word, Cap,
1616
};
1717

1818
use crate::{
@@ -556,8 +556,7 @@ pub fn build_capdl_spec(
556556
let mut pd_id_to_ep_id: HashMap<usize, ObjectId> = HashMap::new();
557557

558558
// Keep tabs on caps such as TCB and SC so that we can create additional mappings for the cap into other PD's cspaces.
559-
let mut pd_id_to_tcb_id: HashMap<usize, ObjectId> = HashMap::new();
560-
let mut pd_id_to_sc_id: HashMap<usize, ObjectId> = HashMap::new();
559+
let mut pd_shadow_cspace: HashMap<usize, Vec<Option<Cap>>> = HashMap::new();
561560

562561
// Keep track of the global count of vCPU objects so we can bind them to the monitor for setting TCB name in debug config.
563562
// Only used on ARM and RISC-V as on x86-64 VMs share the same TCB as PD's which will have their TCB name set separately.
@@ -580,14 +579,18 @@ pub fn build_capdl_spec(
580579
.unwrap();
581580
let pd_vspace_obj_id = capdl_util_get_vspace_id_from_tcb_id(&spec_container, pd_tcb_obj_id);
582581

583-
pd_id_to_tcb_id.insert(pd_global_idx, pd_tcb_obj_id);
582+
let pd_tcb_obj = capdl_util_make_tcb_cap(pd_tcb_obj_id);
583+
584+
// @kwinter: Making this size 10, this covers a PD's basic caps. Not sure if we should change to a hashmap or something in
585+
// the future
586+
pd_shadow_cspace.entry(pd_global_idx).or_insert_with(|| vec![None; 10])[CapMapType::Tcb as usize] = Some(pd_tcb_obj.clone());
584587

585588
// In the benchmark configuration, we allow PDs to access their own TCB.
586589
// This is necessary for accessing kernel's benchmark API.
587590
if kernel_config.benchmark {
588591
caps_to_insert_to_pd_cspace.push(capdl_util_make_cte(
589592
PD_TCB_CAP_IDX as u32,
590-
capdl_util_make_tcb_cap(pd_tcb_obj_id),
593+
pd_tcb_obj,
591594
));
592595
}
593596

@@ -673,9 +676,10 @@ pub fn build_capdl_spec(
673676
0x100 + pd_global_idx as u64,
674677
);
675678

676-
pd_id_to_sc_id.insert(pd_global_idx, pd_sc_obj_id);
677-
678679
let pd_sc_cap = capdl_util_make_sc_cap(pd_sc_obj_id);
680+
681+
pd_shadow_cspace.get_mut(&pd_global_idx).unwrap()[CapMapType::Sc as usize] = Some(pd_sc_cap.clone());
682+
679683
caps_to_bind_to_tcb.push(capdl_util_make_cte(
680684
TcbBoundSlot::SchedContext as u32,
681685
pd_sc_cap,
@@ -1120,36 +1124,14 @@ pub fn build_capdl_spec(
11201124
cap_map.pd_name, pd.name
11211125
))?;
11221126

1123-
if cap_map.cap_type == CapMapType::Tcb {
1124-
// Get the TCB of the pd referenced in cap_map name
1125-
let pd_tcb_id = *pd_id_to_tcb_id.get(pd_src_idx).unwrap();
1126-
1127-
// Map this into the destination pd's cspace and the specified slot.
1128-
let pd_tcb_cap = capdl_util_make_tcb_cap(pd_tcb_id);
1129-
capdl_util_insert_cap_into_cspace(
1130-
&mut spec_container,
1131-
pd_dest_cspace_id,
1132-
(PD_BASE_USER_CAPS + cap_map.dest_cspace_slot) as u32,
1133-
pd_tcb_cap,
1134-
);
1135-
} else if cap_map.cap_type == CapMapType::Sc {
1136-
if system.protection_domains[*pd_src_idx].passive {
1137-
return Err(format!(
1138-
"Trying to map scheduling context of a passive PD: '{}' into PD: '{}'",
1139-
cap_map.pd_name, pd.name
1140-
));
1141-
}
1142-
1143-
let pd_sc_id = *pd_id_to_sc_id.get(pd_src_idx).unwrap();
1144-
1145-
let pd_sc_cap = capdl_util_make_tcb_cap(pd_sc_id);
1146-
capdl_util_insert_cap_into_cspace(
1147-
&mut spec_container,
1148-
pd_dest_cspace_id,
1149-
(PD_BASE_USER_CAPS + cap_map.dest_cspace_slot) as u32,
1150-
pd_sc_cap,
1151-
);
1152-
}
1127+
let pd_obj = pd_shadow_cspace.get(pd_src_idx).unwrap()[cap_map.cap_type as usize].as_ref().unwrap();
1128+
// Map this into the destination pd's cspace and the specified slot.
1129+
capdl_util_insert_cap_into_cspace(
1130+
&mut spec_container,
1131+
pd_dest_cspace_id,
1132+
(PD_BASE_USER_CAPS + cap_map.dest_cspace_slot) as u32,
1133+
pd_obj.clone(),
1134+
);
11531135
}
11541136
}
11551137

tool/microkit/src/sdf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ pub struct ProtectionDomain {
276276
text_pos: Option<roxmltree::TextPos>,
277277
}
278278

279-
#[derive(Debug, PartialEq, Eq)]
279+
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
280280
pub enum CapMapType {
281281
Tcb = 1,
282282
Sc = 2,

0 commit comments

Comments
 (0)