kata: Integrate Image Manager and WMMU changes

This CL handles the integration of the Image Manager, which comes
concurrent with the necessary WMMU changes needed by the Image Manager.

The ML Coordinator now calls into Image Manager to make space, commit
images, and set the WMMU.

The MlCoordinator now first verifies that an image is valid by first making a pass through the section headers. It stores the two sizes that we're interested in per image: how big it is packed on flash, and how big it is unpacked in memory.

Known issues:
b/241799340: Refactor BundleImage to support unit testing
The writes to DMEM via the kata-vec-core crate was meant to be in image_manager.rs, but this interfered with the ability to run unit tests. We can refactor BundleImage to make this work.

b/241799866: Improve heap management
Right now I clear all of the "temporary data section" (bss, stack,
heap), but I suspect only the heap needs to be cleared. This needs more effort to check that that's correct, and track those locations.

Minor changes:
ImageId is used instead of (String, String) in the component.

Change-Id: I1505c6474fc60205323ce3bb13610fdac3702b89
GitOrigin-RevId: 5df9938a6cbd7ca5510ce8fcb500ce471f42b2cb
This commit is contained in:
Adam Jesionowski
2022-07-27 14:12:56 -07:00
committed by Sam Leffler
parent 50cd809320
commit fd7f31bcb2
15 changed files with 494 additions and 365 deletions

View File

@@ -10,6 +10,7 @@ kata-os-common = { path = "../../kata-os-common" }
kata-memory-interface = { path = "../../MemoryManager/kata-memory-interface" }
kata-ml-coordinator = { path = "../kata-ml-coordinator" }
kata-ml-interface = { path = "../kata-ml-interface" }
kata-ml-shared = { path = "../kata-ml-shared" }
kata-timer-interface = { path = "../../TimerService/kata-timer-interface" }
log = "0.4"
spin = "0.9"

View File

@@ -8,6 +8,7 @@ use cstr_core::CStr;
use kata_ml_coordinator::MLCoordinator;
use kata_ml_coordinator::ModelIdx;
use kata_ml_interface::MlCoordError;
use kata_ml_shared::ImageId;
use kata_os_common::camkes::Camkes;
use kata_timer_interface::*;
use log::error;
@@ -45,14 +46,17 @@ pub unsafe extern "C" fn run() {
unsafe fn validate_ids(
c_bundle_id: *const cstr_core::c_char,
c_model_id: *const cstr_core::c_char,
) -> Result<(String, String), MlCoordError> {
) -> Result<ImageId, MlCoordError> {
let bundle_id = CStr::from_ptr(c_bundle_id)
.to_str()
.map_err(|_| MlCoordError::InvalidBundleId)?;
let model_id = CStr::from_ptr(c_model_id)
.to_str()
.map_err(|_| MlCoordError::InvalidModelId)?;
Ok((String::from(bundle_id), String::from(model_id)))
Ok(ImageId {
bundle_id: String::from(bundle_id),
model_id: String::from(model_id),
})
}
#[no_mangle]
@@ -60,12 +64,12 @@ pub unsafe extern "C" fn mlcoord_oneshot(
c_bundle_id: *const cstr_core::c_char,
c_model_id: *const cstr_core::c_char,
) -> MlCoordError {
let (bundle_id, model_id) = match validate_ids(c_bundle_id, c_model_id) {
Ok(ids) => ids,
let id = match validate_ids(c_bundle_id, c_model_id) {
Ok(id) => id,
Err(e) => return e,
};
if let Err(e) = ML_COORD.lock().oneshot(bundle_id, model_id) {
if let Err(e) = ML_COORD.lock().oneshot(id) {
return e;
}
@@ -78,11 +82,11 @@ pub unsafe extern "C" fn mlcoord_periodic(
c_model_id: *const cstr_core::c_char,
rate_in_ms: u32,
) -> MlCoordError {
let (bundle_id, model_id) = match validate_ids(c_bundle_id, c_model_id) {
Ok(ids) => ids,
let id = match validate_ids(c_bundle_id, c_model_id) {
Ok(id) => id,
Err(e) => return e,
};
if let Err(e) = ML_COORD.lock().periodic(bundle_id, model_id, rate_in_ms) {
if let Err(e) = ML_COORD.lock().periodic(id, rate_in_ms) {
return e;
}
@@ -94,12 +98,12 @@ pub unsafe extern "C" fn mlcoord_cancel(
c_bundle_id: *const cstr_core::c_char,
c_model_id: *const cstr_core::c_char,
) -> MlCoordError {
let (bundle_id, model_id) = match validate_ids(c_bundle_id, c_model_id) {
Ok(ids) => ids,
let id = match validate_ids(c_bundle_id, c_model_id) {
Ok(id) => id,
Err(e) => return e,
};
if let Err(e) = ML_COORD.lock().cancel(bundle_id, model_id) {
if let Err(e) = ML_COORD.lock().cancel(&id) {
return e;
}