Skip to content

Commit 3938f82

Browse files
committed
address pr comments
Signed-off-by: Krishnan Winter <krishnan.winter@unsw.edu.au>
1 parent e2661e0 commit 3938f82

3 files changed

Lines changed: 23 additions & 23 deletions

File tree

libmicrokit/include/microkit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ typedef seL4_MessageInfo_t microkit_msginfo;
3434
// @kwinter: Bounding user caps to 128. Is this restriction ok for now?
3535
#define BASE_USER_CAPS 522
3636

37+
#define MICROKIT_MAX_USER_CAPS 128
3738
#define MICROKIT_MAX_CHANNELS 62
3839
#define MICROKIT_MAX_CHANNEL_ID (MICROKIT_MAX_CHANNELS - 1)
3940
#define MICROKIT_MAX_IOPORT_ID MICROKIT_MAX_CHANNELS

tool/microkit/src/capdl/builder.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::{
2424
},
2525
elf::ElfFile,
2626
sdf::{
27-
CapMapType, CpuCore, SysMap, SysMapPerms, SystemDescription, BUDGET_DEFAULT,
27+
CapMapType, CpuCore, SysMap, SysMapPerms, SystemDescription, BUDGET_DEFAULT, CAP_MAP_TYPES,
2828
MONITOR_PD_NAME, MONITOR_PRIORITY,
2929
},
3030
sel4::{Arch, Config, PageSize},
@@ -584,7 +584,7 @@ pub fn build_capdl_spec(
584584

585585
pd_shadow_cspace
586586
.entry(pd_global_idx)
587-
.or_insert_with(|| vec![None; CapMapType::__Len as usize])[CapMapType::Tcb as usize] =
587+
.or_insert_with(|| vec![None; CAP_MAP_TYPES])[CapMapType::Tcb as usize] =
588588
Some(pd_tcb_obj.clone());
589589
pd_shadow_cspace.get_mut(&pd_global_idx).unwrap()[CapMapType::Vspace as usize] =
590590
Some(pd_vspace_obj.clone());
@@ -597,10 +597,8 @@ pub fn build_capdl_spec(
597597
}
598598

599599
// Allow PD to access their own VSpace for ops such as cache cleaning on ARM.
600-
caps_to_insert_to_pd_cspace.push(capdl_util_make_cte(
601-
PD_VSPACE_CAP_IDX as u32,
602-
pd_vspace_obj,
603-
));
600+
caps_to_insert_to_pd_cspace
601+
.push(capdl_util_make_cte(PD_VSPACE_CAP_IDX as u32, pd_vspace_obj));
604602

605603
// Step 3-2: Map in all Memory Regions
606604
for map in pd.maps.iter() {
@@ -1120,15 +1118,15 @@ pub fn build_capdl_spec(
11201118
// *********************************
11211119

11221120
for (pd_dest_idx, pd) in system.protection_domains.iter().enumerate() {
1123-
let pd_dest_cspace_id = *pd_id_to_cspace_id.get(&pd_dest_idx).unwrap();
1121+
let pd_dest_cspace_id = pd_id_to_cspace_id[&pd_dest_idx];
11241122

11251123
for cap_map in pd.cap_maps.iter() {
11261124
let pd_src_idx = pd_name_to_id.get(&cap_map.pd_name).ok_or(format!(
11271125
"PD: '{}', does not exist when trying to map extra TCB cap into PD: '{}'",
11281126
cap_map.pd_name, pd.name
11291127
))?;
11301128

1131-
let pd_obj = pd_shadow_cspace.get(pd_src_idx).unwrap()[cap_map.cap_type as usize]
1129+
let pd_obj = pd_shadow_cspace[pd_src_idx][cap_map.cap_type as usize]
11321130
.as_ref()
11331131
.unwrap();
11341132
// Map this into the destination pd's cspace and the specified slot.

tool/microkit/src/sdf.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ use std::path::{Path, PathBuf};
3737
const PD_MAX_ID: u64 = 61;
3838
const VCPU_MAX_ID: u64 = PD_MAX_ID;
3939

40+
/// This is the maximum slot allowed for cap maps. This can change if you wish,
41+
/// but also update the MICROKIT_MAX_USER_CAPS define in `microkit.h`.
42+
const CAP_MAP_MAX_SLOT: u64 = 128;
43+
4044
pub const MONITOR_PRIORITY: u8 = 255;
4145
const PD_MAX_PRIORITY: u8 = 254;
4246
/// In microseconds
@@ -276,13 +280,15 @@ pub struct ProtectionDomain {
276280
text_pos: Option<roxmltree::TextPos>,
277281
}
278282

283+
/// Update CAP_MAP_TYPES whenever making changes to the CapMapType enum
284+
pub const CAP_MAP_TYPES: usize = 4;
285+
279286
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
280287
pub enum CapMapType {
281288
Tcb = 0,
282289
Sc,
283290
Vspace,
284291
Cnode,
285-
__Len,
286292
}
287293

288294
#[derive(Debug, PartialEq, Eq)]
@@ -1240,29 +1246,24 @@ impl CapMap {
12401246
fn from_xml(xml_sdf: &XmlSystemDescription, node: &roxmltree::Node) -> Result<CapMap, String> {
12411247
check_attributes(xml_sdf, node, &["type", "pd", "dest_cspace_slot"])?;
12421248

1243-
let cap_type = match checked_lookup(xml_sdf, node, "type")? {
1249+
let xml_cap_type = checked_lookup(xml_sdf, node, "type")?;
1250+
let cap_type = match xml_cap_type {
12441251
"tcb" => CapMapType::Tcb,
12451252
"sc" => CapMapType::Sc,
12461253
"vspace" => CapMapType::Vspace,
12471254
"cnode" => CapMapType::Cnode,
1248-
_ => {
1249-
return Err(value_error(
1250-
xml_sdf,
1251-
node,
1252-
"type must be 'tcb' or 'sc' ".to_string(),
1253-
))
1254-
}
1255+
_ => return Err(format!("Cap type: '{}' is not supported.", xml_cap_type,)),
12551256
};
12561257

12571258
let pd_name = checked_lookup(xml_sdf, node, "pd")?.to_string();
12581259
let dest_cspace_slot =
12591260
sdf_parse_number(checked_lookup(xml_sdf, node, "dest_cspace_slot")?, node)?;
12601261

1261-
if dest_cspace_slot >= 128 {
1262+
if dest_cspace_slot >= CAP_MAP_MAX_SLOT {
12621263
return Err(value_error(
12631264
xml_sdf,
12641265
node,
1265-
"There are only 128 destination cspace slots available. Max slot allowed is 63"
1266+
format!("There are only {CAP_MAP_MAX_SLOT} destination cspace slots available.")
12661267
.to_string(),
12671268
));
12681269
}
@@ -1956,7 +1957,7 @@ pub fn parse(filename: &str, xml: &str, config: &Config) -> Result<SystemDescrip
19561957
let mut user_cap_slots = Vec::new();
19571958
let mut seen_pd_cap_maps: Vec<(CapMapType, String)> = Vec::new();
19581959

1959-
for cap_map in pd.cap_maps.iter() {
1960+
for cap_map in &pd.cap_maps {
19601961
if user_cap_slots.contains(&cap_map.dest_cspace_slot) {
19611962
return Err(format!(
19621963
"Error: Overlapping cap slot: {} in protection domain: '{}'",
@@ -1968,9 +1969,9 @@ pub fn parse(filename: &str, xml: &str, config: &Config) -> Result<SystemDescrip
19681969

19691970
if seen_pd_cap_maps.contains(&(cap_map.cap_type, cap_map.pd_name.clone())) {
19701971
return Err(format!(
1971-
"Error: Duplicate cap mapping of type '{:?}'. Src PD: '{}', dest PD: '{}'.",
1972-
cap_map.cap_type, cap_map.pd_name, pd.name
1973-
));
1972+
"Error: Duplicate cap mapping of type '{:?}'. Src PD: '{}', dest PD: '{}'.",
1973+
cap_map.cap_type, cap_map.pd_name, pd.name
1974+
));
19741975
} else {
19751976
seen_pd_cap_maps.push((cap_map.cap_type.clone(), cap_map.pd_name.clone()))
19761977
}

0 commit comments

Comments
 (0)