Skip to content

Commit 0d91b43

Browse files
tylerfanellislp
authored andcommitted
nitro: Return enclave CID in krun_start_enter
The nitro enclaves device returns and enclave's CID when it starts. Return this to the caller of krun_start_enter. The caller could then set up vsocks for tasks like reading console logs. Signed-off-by: Tyler Fanelli <[email protected]>
1 parent cfa427d commit 0d91b43

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/libkrun/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ hvf = { path = "../hvf" }
3636
kvm-bindings = { version = ">=0.11", features = ["fam-wrappers"] }
3737
kvm-ioctls = ">=0.21"
3838
nitro = { path = "../nitro", optional = true }
39-
nitro-enclaves = { version = "0.2.0", optional = true }
39+
nitro-enclaves = { version = "0.3.0", optional = true }
4040
vm-memory = ">=0.13"
4141

4242
[lib]

src/libkrun/src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,10 +1896,13 @@ fn krun_start_enter_nitro(ctx_id: u32) -> i32 {
18961896
return -libc::EINVAL;
18971897
};
18981898

1899-
if let Err(e) = enclave.run() {
1900-
error!("Error running nitro enclave: {e}");
1901-
return -libc::EINVAL;
1902-
}
1899+
// Return enclave CID if successfully ran.
1900+
match enclave.run() {
1901+
Ok(cid) => cid.try_into().unwrap(), // Safe to unwrap.
1902+
Err(e) => {
1903+
error!("Error running nitro enclave: {e}");
19031904

1904-
KRUN_SUCCESS
1905+
-libc::EINVAL
1906+
}
1907+
}
19051908
}

src/nitro/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ nix = { version = "0.26.0", features = ["ioctl", "poll"] }
1212
vsock = "0.5.1"
1313

1414
[target.'cfg(target_os = "linux")'.dependencies]
15-
nitro-enclaves = "0.2.0"
15+
nitro-enclaves = "0.3.0"

src/nitro/src/enclaves.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub struct NitroEnclave {
5151

5252
impl NitroEnclave {
5353
/// Run the enclave.
54-
pub fn run(&mut self) -> Result<()> {
54+
pub fn run(&mut self) -> Result<u32> {
5555
let device = Device::open().map_err(NitroError::DeviceOpen)?;
5656

5757
let mut launcher = Launcher::new(&device).map_err(NitroError::VmCreate)?;
@@ -80,7 +80,7 @@ impl NitroEnclave {
8080

8181
self.listen(VMADDR_CID_HYPERVISOR, cid + CID_TO_CONSOLE_PORT_OFFSET)?;
8282

83-
Ok(())
83+
Ok(cid)
8484
}
8585

8686
fn listen(&mut self, cid: u32, port: u32) -> Result<()> {

0 commit comments

Comments
 (0)