Skip to content

Commit

Permalink
Adjust the maximum number of avaiable DPE handles.
Browse files Browse the repository at this point in the history
This commit adjusts the maximum number of DPE handles via cargo feature. Exception and NMI stacks
for the mutable code (fmc, runtime) had to be adjusted to make room for the extra DPE storage.
  • Loading branch information
rusty1968 authored and jhand2 committed Jun 17, 2024
1 parent a8fa928 commit 3d6d05d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions builder/src/firmware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ pub const FMC_FAKE_WITH_UART: FwId = FwId {
pub const APP: FwId = FwId {
crate_name: "caliptra-runtime",
bin_name: "caliptra-runtime",
features: &["fips_self_test"],
features: &["fips_self_test", "arbitrary_max_handles"],
};

pub const APP_WITH_UART: FwId = FwId {
crate_name: "caliptra-runtime",
bin_name: "caliptra-runtime",
features: &["emu", "fips_self_test"],
features: &["emu", "fips_self_test", "arbitrary_max_handles"],
};

pub const APP_WITH_UART_FPGA: FwId = FwId {
Expand Down
2 changes: 1 addition & 1 deletion drivers/src/memory_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub const RTALIAS_TBS_SIZE: u32 = 1024;
pub const PCR_LOG_SIZE: u32 = 1024;
pub const MEASUREMENT_LOG_SIZE: u32 = 1024;
pub const FUSE_LOG_SIZE: u32 = 1024;
pub const DPE_SIZE: u32 = 4 * 1024;
pub const DPE_SIZE: u32 = 5 * 1024;
pub const PCR_RESET_COUNTER_SIZE: u32 = 1024;
pub const DATA_SIZE: u32 = 78 * 1024;
pub const STACK_SIZE: u32 = 22 * 1024;
Expand Down
15 changes: 10 additions & 5 deletions drivers/src/persistent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ pub const PCR_LOG_MAX_COUNT: usize = 17;
pub const FUSE_LOG_MAX_COUNT: usize = 62;
pub const MEASUREMENT_MAX_COUNT: usize = 8;

#[cfg(feature = "runtime")]
const DPE_DCCM_STORAGE: usize = size_of::<DpeInstance>()
+ size_of::<u32>() * MAX_HANDLES
+ size_of::<U8Bool>() * MAX_HANDLES
+ size_of::<U8Bool>();

#[cfg(feature = "runtime")]
const _: () = assert!(DPE_DCCM_STORAGE < memory_layout::DPE_SIZE as usize);

pub type PcrLogArray = [PcrLogEntry; PCR_LOG_MAX_COUNT];
pub type FuseLogArray = [FuseLogEntry; FUSE_LOG_MAX_COUNT];
pub type StashMeasurementArray = [MeasurementLogEntry; MEASUREMENT_MAX_COUNT];
Expand Down Expand Up @@ -63,11 +72,7 @@ pub struct PersistentData {
#[cfg(feature = "runtime")]
pub attestation_disabled: U8Bool,
#[cfg(feature = "runtime")]
reserved6: [u8; memory_layout::DPE_SIZE as usize
- size_of::<DpeInstance>()
- size_of::<u32>() * MAX_HANDLES
- size_of::<U8Bool>() * MAX_HANDLES
- size_of::<U8Bool>()],
reserved6: [u8; memory_layout::DPE_SIZE as usize - DPE_DCCM_STORAGE],
#[cfg(not(feature = "runtime"))]
dpe: [u8; memory_layout::DPE_SIZE as usize],
#[cfg(feature = "runtime")]
Expand Down
1 change: 1 addition & 0 deletions runtime/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fn main() {

println!("cargo:rustc-link-arg=-Tlink.x");
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rustc-env=ARBITRARY_MAX_HANDLES=32");
}
}
}
3 changes: 1 addition & 2 deletions runtime/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

cd "$(dirname "${BASH_SOURCE[0]}")"

ARBITRARY_MAX_HANDLES=24 cargo build \
--features arbitrary_max_handles \
cargo build \
--locked \
--target riscv32imc-unknown-none-elf \
--profile=firmware \
Expand Down
3 changes: 3 additions & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ pub const DPE_SUPPORT: Support = Support::all();
pub const MAX_CERT_CHAIN_SIZE: usize = 4096;

pub const PL0_PAUSER_FLAG: u32 = 1;
#[cfg(not(feature = "arbitrary_max_handles"))]
pub const PL0_DPE_ACTIVE_CONTEXT_THRESHOLD: usize = 8;
#[cfg(feature = "arbitrary_max_handles")]
pub const PL0_DPE_ACTIVE_CONTEXT_THRESHOLD: usize = 16;
pub const PL1_DPE_ACTIVE_CONTEXT_THRESHOLD: usize = 16;

pub struct CptraDpeTypes;
Expand Down

0 comments on commit 3d6d05d

Please sign in to comment.