Skip to content
This repository was archived by the owner on Apr 15, 2022. It is now read-only.

Commit 695bf2d

Browse files
Connor Kuehlenarxbot
authored andcommitted
Propagate SEV platform errors from ioctl calls
This information is way more helpful than just the errno returned from the ioctl. Signed-off-by: Connor Kuehl <[email protected]>
1 parent 638a3d5 commit 695bf2d

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/launch/launcher.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ impl<'a, U: AsRawFd, V: AsRawFd> Launcher<'a, New, U, V> {
3434
};
3535

3636
let mut cmd = Command::from(launcher.sev, &Init);
37-
INIT.ioctl(launcher.kvm, &mut cmd)?;
37+
INIT.ioctl(launcher.kvm, &mut cmd)
38+
.map_err(|e| cmd.encapsulate(e))?;
3839

3940
Ok(launcher)
4041
}
@@ -43,7 +44,9 @@ impl<'a, U: AsRawFd, V: AsRawFd> Launcher<'a, New, U, V> {
4344
pub fn start(self, start: Start) -> Result<Launcher<'a, Started, U, V>> {
4445
let mut launch_start = LaunchStart::new(&start.policy, &start.cert, &start.session);
4546
let mut cmd = Command::from_mut(self.sev, &mut launch_start);
46-
LAUNCH_START.ioctl(self.kvm, &mut cmd)?;
47+
LAUNCH_START
48+
.ioctl(self.kvm, &mut cmd)
49+
.map_err(|e| cmd.encapsulate(e))?;
4750

4851
let next = Launcher {
4952
state: Started(launch_start.into()),
@@ -60,7 +63,9 @@ impl<'a, U: AsRawFd, V: AsRawFd> Launcher<'a, Started, U, V> {
6063
pub fn update_data(&mut self, data: &[u8]) -> Result<()> {
6164
let launch_update_data = LaunchUpdateData::new(data);
6265
let mut cmd = Command::from(self.sev, &launch_update_data);
63-
LAUNCH_UPDATE_DATA.ioctl(self.kvm, &mut cmd)?;
66+
LAUNCH_UPDATE_DATA
67+
.ioctl(self.kvm, &mut cmd)
68+
.map_err(|e| cmd.encapsulate(e))?;
6469
Ok(())
6570
}
6671

@@ -69,7 +74,9 @@ impl<'a, U: AsRawFd, V: AsRawFd> Launcher<'a, Started, U, V> {
6974
let mut measurement = MaybeUninit::uninit();
7075
let mut launch_measure = LaunchMeasure::new(&mut measurement);
7176
let mut cmd = Command::from_mut(self.sev, &mut launch_measure);
72-
LAUNCH_MEASUREMENT.ioctl(self.kvm, &mut cmd)?;
77+
LAUNCH_MEASUREMENT
78+
.ioctl(self.kvm, &mut cmd)
79+
.map_err(|e| cmd.encapsulate(e))?;
7380

7481
let next = Launcher {
7582
state: Measured(self.state.0, unsafe { measurement.assume_init() }),
@@ -95,14 +102,18 @@ impl<'a, U: AsRawFd, V: AsRawFd> Launcher<'a, Measured, U, V> {
95102
pub fn inject(&mut self, secret: Secret, guest: usize) -> Result<()> {
96103
let launch_secret = LaunchSecret::new(&secret.header, guest, &secret.ciphertext[..]);
97104
let mut cmd = Command::from(self.sev, &launch_secret);
98-
LAUNCH_SECRET.ioctl(self.kvm, &mut cmd)?;
105+
LAUNCH_SECRET
106+
.ioctl(self.kvm, &mut cmd)
107+
.map_err(|e| cmd.encapsulate(e))?;
99108
Ok(())
100109
}
101110

102111
/// Complete the SEV launch process.
103112
pub fn finish(self) -> Result<Handle> {
104113
let mut cmd = Command::from(self.sev, &LaunchFinish);
105-
LAUNCH_FINISH.ioctl(self.kvm, &mut cmd)?;
114+
LAUNCH_FINISH
115+
.ioctl(self.kvm, &mut cmd)
116+
.map_err(|e| cmd.encapsulate(e))?;
106117
Ok(self.state.0)
107118
}
108119
}

src/launch/linux/ioctl.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// SPDX-License-Identifier: Apache-2.0
22

3+
use crate::firmware::{Error, Indeterminate};
34
use crate::impl_const_id;
45
use crate::kvm::types::*;
56
use iocuddle::*;
@@ -84,4 +85,11 @@ impl<'a, T: Id> Command<'a, T> {
8485
_phantom: PhantomData,
8586
}
8687
}
88+
89+
pub fn encapsulate(&self, err: std::io::Error) -> Indeterminate<Error> {
90+
match self.error {
91+
0 => Indeterminate::<Error>::from(err),
92+
_ => Indeterminate::<Error>::from(self.error as u32),
93+
}
94+
}
8795
}

0 commit comments

Comments
 (0)