Skip to content

Commit 83e65ad

Browse files
committed
[common/peb,guest/host_{error, function_call},host/{mem,func}] removed host error region
This region was unused. Ever since we ported our code from C# to Rust, if there's an error calling a host function, the host will just error out instead of returning to the guest, which is probably more sensible. Signed-off-by: danbugs <[email protected]>
1 parent af6c1a9 commit 83e65ad

File tree

9 files changed

+9
-375
lines changed

9 files changed

+9
-375
lines changed

src/hyperlight_common/src/mem/mod.rs

-6
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ pub struct HostFunctionDefinitions {
2828
pub fbHostFunctionDetails: *mut c_void,
2929
}
3030

31-
#[repr(C)]
32-
pub struct HostException {
33-
pub hostExceptionSize: u64,
34-
}
35-
3631
#[repr(C)]
3732
pub struct GuestErrorData {
3833
pub guestErrorSize: u64,
@@ -89,7 +84,6 @@ pub struct GuestPanicContextData {
8984
pub struct HyperlightPEB {
9085
pub security_cookie_seed: u64,
9186
pub guest_function_dispatch_ptr: u64,
92-
pub hostException: HostException,
9387
pub guestErrorData: GuestErrorData,
9488
pub pCode: *mut c_char,
9589
pub pOutb: *mut c_void,

src/hyperlight_guest/src/host_error.rs

-43
This file was deleted.

src/hyperlight_guest/src/host_function_call.rs

-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use hyperlight_common::flatbuffer_wrappers::util::get_flatbuffer_result;
2828
use hyperlight_common::mem::RunMode;
2929

3030
use crate::error::{HyperlightGuestError, Result};
31-
use crate::host_error::check_for_host_error;
3231
use crate::shared_input_data::try_pop_shared_input_data_into;
3332
use crate::shared_output_data::push_shared_output_data;
3433
use crate::{OUTB_PTR, OUTB_PTR_WITH_CONTEXT, P_PEB, RUNNING_MODE};
@@ -102,8 +101,6 @@ pub fn outb(port: u16, value: u8) {
102101
panic!("Tried to call outb in invalid runmode");
103102
}
104103
}
105-
106-
check_for_host_error();
107104
}
108105
}
109106

src/hyperlight_guest/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ pub mod guest_function_call;
3838
pub mod guest_function_definition;
3939
pub mod guest_function_register;
4040

41-
pub mod host_error;
4241
pub mod host_function_call;
4342

4443
pub(crate) mod guest_logger;

src/hyperlight_host/src/error.rs

-21
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use std::cell::{BorrowError, BorrowMutError};
2525
use std::convert::Infallible;
2626
use std::error::Error;
2727
use std::num::TryFromIntError;
28-
use std::str::Utf8Error;
2928
use std::string::FromUtf8Error;
3029
use std::sync::{MutexGuard, PoisonError};
3130
use std::time::SystemTimeError;
@@ -87,14 +86,6 @@ pub enum HyperlightError {
8786
#[error("{0}")]
8887
Error(String),
8988

90-
/// Exception Data Length is incorrect
91-
#[error("Exception Data Length is incorrect. Expected: {0}, Actual: {1}")]
92-
ExceptionDataLengthIncorrect(i32, usize),
93-
94-
/// Exception Message is too big
95-
#[error("Exception Message is too big. Max Size: {0}, Actual: {1}")]
96-
ExceptionMessageTooBig(usize, usize),
97-
9889
/// Execution violation
9990
#[error("Non-executable address {0:#x} tried to be executed")]
10091
ExecutionAccessViolation(u64),
@@ -171,10 +162,6 @@ pub enum HyperlightError {
171162
#[error("The flatbuffer is invalid")]
172163
InvalidFlatBuffer(#[from] InvalidFlatbuffer),
173164

174-
/// Conversion of str to Json failed
175-
#[error("Conversion of str data to json failed")]
176-
JsonConversionFailure(#[from] serde_json::Error),
177-
178165
/// Error occurred in KVM Operation
179166
#[error("KVM Error {0:?}")]
180167
#[cfg(kvm)]
@@ -225,10 +212,6 @@ pub enum HyperlightError {
225212
#[error("Restore_state called with no valid snapshot")]
226213
NoMemorySnapshot,
227214

228-
/// An error occurred handling an outb message
229-
#[error("An error occurred handling an outb message {0:?}: {1}")]
230-
OutBHandlingError(String, String),
231-
232215
/// Failed to get value from parameter value
233216
#[error("Failed To Convert Parameter Value {0:?} to {1:?}")]
234217
ParameterValueConversionFailure(ParameterValue, &'static str),
@@ -292,10 +275,6 @@ pub enum HyperlightError {
292275
#[error("The return value type is unexpected got {0:?} expected {1:?}")]
293276
UnexpectedReturnValueType(ReturnValue, String),
294277

295-
/// Slice conversion to UTF8 failed
296-
#[error("Slice Conversion of UTF8 data to str failed")]
297-
UTF8SliceConversionFailure(#[from] Utf8Error),
298-
299278
/// Slice conversion to UTF8 failed
300279
#[error("String Conversion of UTF8 data to str failed")]
301280
UTF8StringConversionFailure(#[from] FromUtf8Error),

src/hyperlight_host/src/func/guest_err.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License.
1616

1717
use hyperlight_common::flatbuffer_wrappers::guest_error::ErrorCode;
1818

19-
use crate::error::HyperlightError::{GuestError, OutBHandlingError, StackOverflow};
19+
use crate::error::HyperlightError::{GuestError, StackOverflow};
2020
use crate::mem::shared_mem::HostSharedMemory;
2121
use crate::metrics::{METRIC_GUEST_ERROR, METRIC_GUEST_ERROR_LABEL_CODE};
2222
use crate::sandbox::mem_mgr::MemMgrWrapper;
@@ -27,18 +27,6 @@ pub(crate) fn check_for_guest_error(mgr: &MemMgrWrapper<HostSharedMemory>) -> Re
2727
let guest_err = mgr.as_ref().get_guest_error()?;
2828
match guest_err.code {
2929
ErrorCode::NoError => Ok(()),
30-
ErrorCode::OutbError => match mgr.as_ref().get_host_error()? {
31-
Some(host_err) => {
32-
metrics::counter!(METRIC_GUEST_ERROR, METRIC_GUEST_ERROR_LABEL_CODE => (guest_err.code as u64).to_string()).increment(1);
33-
34-
log_then_return!(OutBHandlingError(
35-
host_err.source.clone(),
36-
guest_err.message.clone()
37-
));
38-
}
39-
// TODO: Not sure this is correct behavior. We should probably return error here
40-
None => Ok(()),
41-
},
4230
ErrorCode::StackOverflow => {
4331
metrics::counter!(METRIC_GUEST_ERROR, METRIC_GUEST_ERROR_LABEL_CODE => (guest_err.code as u64).to_string()).increment(1);
4432
log_then_return!(StackOverflow());

src/hyperlight_host/src/mem/layout.rs

+5-76
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ use rand::{rng, RngCore};
2222
use tracing::{instrument, Span};
2323

2424
use super::memory_region::MemoryRegionType::{
25-
Code, GuardPage, GuestErrorData, Heap, HostExceptionData, InputData, OutputData, PageTables,
26-
PanicContext, Peb, Stack,
25+
Code, GuardPage, GuestErrorData, Heap, InputData, OutputData, PageTables, PanicContext, Peb,
26+
Stack,
2727
};
2828
use super::memory_region::{MemoryRegion, MemoryRegionFlags, MemoryRegionVecBuilder};
2929
use super::mgr::AMOUNT_OF_MEMORY_PER_PT;
@@ -47,8 +47,6 @@ use crate::{log_then_return, new_error, Result};
4747
// +-------------------------------------------+
4848
// | Guest Error Log |
4949
// +-------------------------------------------+
50-
// | Host Exception Handlers |
51-
// +-------------------------------------------+
5250
// | PEB Struct | (HyperlightPEB size)
5351
// +-------------------------------------------+
5452
// | Guest Code |
@@ -62,12 +60,6 @@ use crate::{log_then_return, new_error, Result};
6260
// | PML4 |
6361
// +-------------------------------------------+ 0x0_000
6462

65-
///
66-
/// - `HostExceptionData` - memory that contains details of any Host Exception that
67-
/// occurred in outb function. it contains a 32 bit length following by a json
68-
/// serialisation of any error that occurred. the length of this field is
69-
/// `HostExceptionSize` from` `SandboxConfiguration`
70-
///
7163
/// - `GuestError` - contains a buffer for any guest error that occurred.
7264
/// the length of this field is `GuestErrorBufferSize` from `SandboxConfiguration`
7365
///
@@ -103,7 +95,6 @@ pub(crate) struct SandboxMemoryLayout {
10395
peb_offset: usize,
10496
peb_security_cookie_seed_offset: usize,
10597
peb_guest_dispatch_function_ptr_offset: usize, // set by guest in guest entrypoint
106-
pub(crate) peb_host_exception_offset: usize,
10798
peb_guest_error_offset: usize,
10899
peb_code_and_outb_pointer_offset: usize,
109100
peb_runmode_offset: usize,
@@ -115,7 +106,6 @@ pub(crate) struct SandboxMemoryLayout {
115106

116107
// The following are the actual values
117108
// that are written to the PEB struct
118-
pub(crate) host_exception_buffer_offset: usize,
119109
pub(super) guest_error_buffer_offset: usize,
120110
pub(super) input_data_buffer_offset: usize,
121111
pub(super) output_data_buffer_offset: usize,
@@ -153,10 +143,6 @@ impl Debug for SandboxMemoryLayout {
153143
"Guest Dispatch Function Pointer Offset",
154144
&format_args!("{:#x}", self.peb_guest_dispatch_function_ptr_offset),
155145
)
156-
.field(
157-
"Host Exception Offset",
158-
&format_args!("{:#x}", self.peb_host_exception_offset),
159-
)
160146
.field(
161147
"Guest Error Offset",
162148
&format_args!("{:#x}", self.peb_guest_error_offset),
@@ -185,10 +171,6 @@ impl Debug for SandboxMemoryLayout {
185171
"Guest Stack Offset",
186172
&format_args!("{:#x}", self.peb_guest_stack_data_offset),
187173
)
188-
.field(
189-
"Host Exception Buffer Offset",
190-
&format_args!("{:#x}", self.host_exception_buffer_offset),
191-
)
192174
.field(
193175
"Guest Error Buffer Offset",
194176
&format_args!("{:#x}", self.guest_error_buffer_offset),
@@ -277,7 +259,6 @@ impl SandboxMemoryLayout {
277259
peb_offset + offset_of!(HyperlightPEB, security_cookie_seed);
278260
let peb_guest_dispatch_function_ptr_offset =
279261
peb_offset + offset_of!(HyperlightPEB, guest_function_dispatch_ptr);
280-
let peb_host_exception_offset = peb_offset + offset_of!(HyperlightPEB, hostException);
281262
let peb_guest_error_offset = peb_offset + offset_of!(HyperlightPEB, guestErrorData);
282263
let peb_code_and_outb_pointer_offset = peb_offset + offset_of!(HyperlightPEB, pCode);
283264
let peb_runmode_offset = peb_offset + offset_of!(HyperlightPEB, runMode);
@@ -291,13 +272,8 @@ impl SandboxMemoryLayout {
291272
// The following offsets are the actual values that relate to memory layout,
292273
// which are written to PEB struct
293274
let peb_address = Self::BASE_ADDRESS + peb_offset;
294-
// make sure host exception buffer starts at 4K boundary
295-
let host_exception_buffer_offset = round_up_to(
296-
peb_guest_stack_data_offset + size_of::<GuestStackData>(),
297-
PAGE_SIZE_USIZE,
298-
);
299275
let guest_error_buffer_offset = round_up_to(
300-
host_exception_buffer_offset + cfg.get_host_exception_size(),
276+
peb_guest_stack_data_offset + size_of::<GuestStackData>(),
301277
PAGE_SIZE_USIZE,
302278
);
303279
let input_data_buffer_offset = round_up_to(
@@ -329,7 +305,6 @@ impl SandboxMemoryLayout {
329305
heap_size,
330306
peb_security_cookie_seed_offset,
331307
peb_guest_dispatch_function_ptr_offset,
332-
peb_host_exception_offset,
333308
peb_guest_error_offset,
334309
peb_code_and_outb_pointer_offset,
335310
peb_runmode_offset,
@@ -341,7 +316,6 @@ impl SandboxMemoryLayout {
341316
guest_error_buffer_offset,
342317
sandbox_memory_config: cfg,
343318
code_size,
344-
host_exception_buffer_offset,
345319
input_data_buffer_offset,
346320
output_data_buffer_offset,
347321
guest_heap_buffer_offset,
@@ -359,14 +333,6 @@ impl SandboxMemoryLayout {
359333
self.peb_runmode_offset
360334
}
361335

362-
/// Get the offset in guest memory to the size field in the
363-
/// `HostExceptionData` structure.
364-
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
365-
pub(super) fn get_host_exception_size_offset(&self) -> usize {
366-
// The size field is the first field in the `HostExceptionData` struct
367-
self.peb_host_exception_offset
368-
}
369-
370336
/// Get the offset in guest memory to the max size of the guest error buffer
371337
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
372338
pub(super) fn get_guest_error_buffer_size_offset(&self) -> usize {
@@ -398,12 +364,6 @@ impl SandboxMemoryLayout {
398364
self.stack_size
399365
}
400366

401-
/// Get the offset in guest memory to the start of host errors
402-
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
403-
pub(super) fn get_host_exception_offset(&self) -> usize {
404-
self.host_exception_buffer_offset
405-
}
406-
407367
/// Get the offset in guest memory to the OutB pointer.
408368
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
409369
pub(super) fn get_outb_pointer_offset(&self) -> usize {
@@ -582,7 +542,6 @@ impl SandboxMemoryLayout {
582542
let mut total_mapped_memory_size: usize = round_up_to(code_size, PAGE_SIZE_USIZE);
583543
total_mapped_memory_size += round_up_to(stack_size, PAGE_SIZE_USIZE);
584544
total_mapped_memory_size += round_up_to(heap_size, PAGE_SIZE_USIZE);
585-
total_mapped_memory_size += round_up_to(cfg.get_host_exception_size(), PAGE_SIZE_USIZE);
586545
total_mapped_memory_size += round_up_to(cfg.get_guest_error_buffer_size(), PAGE_SIZE_USIZE);
587546
total_mapped_memory_size += round_up_to(cfg.get_input_data_size(), PAGE_SIZE_USIZE);
588547
total_mapped_memory_size += round_up_to(cfg.get_output_data_size(), PAGE_SIZE_USIZE);
@@ -667,36 +626,18 @@ impl SandboxMemoryLayout {
667626
}
668627

669628
// PEB
670-
let host_exception_offset = builder.push_page_aligned(
629+
let guest_error_offset = builder.push_page_aligned(
671630
size_of::<HyperlightPEB>(),
672631
MemoryRegionFlags::READ | MemoryRegionFlags::WRITE,
673632
Peb,
674633
);
675634

676-
let expected_host_exception_offset =
677-
TryInto::<usize>::try_into(self.host_exception_buffer_offset)?;
678-
679-
if host_exception_offset != expected_host_exception_offset {
680-
return Err(new_error!(
681-
"Host Exception offset does not match expected Host Exception offset expected: {}, actual: {}",
682-
expected_host_exception_offset,
683-
host_exception_offset
684-
));
685-
}
686-
687-
// host exception
688-
let guest_error_offset = builder.push_page_aligned(
689-
self.sandbox_memory_config.get_host_exception_size(),
690-
MemoryRegionFlags::READ | MemoryRegionFlags::WRITE,
691-
HostExceptionData,
692-
);
693-
694635
let expected_guest_error_offset =
695636
TryInto::<usize>::try_into(self.guest_error_buffer_offset)?;
696637

697638
if guest_error_offset != expected_guest_error_offset {
698639
return Err(new_error!(
699-
"Guest Error offset does not match expected Guest Error offset expected: {}, actual: {}",
640+
"Guest error offset does not match expected Guest error offset expected: {}, actual: {}",
700641
expected_guest_error_offset,
701642
guest_error_offset
702643
));
@@ -877,16 +818,6 @@ impl SandboxMemoryLayout {
877818

878819
// Skip guest_dispatch_function_ptr_offset because it is set by the guest
879820

880-
// Set up Host Exception Header
881-
// The peb only needs to include the size, not the actual buffer
882-
// since the the guest wouldn't want to read the buffer anyway
883-
shared_mem.write_u64(
884-
self.get_host_exception_size_offset(),
885-
self.sandbox_memory_config
886-
.get_host_exception_size()
887-
.try_into()?,
888-
)?;
889-
890821
// Set up Guest Error Fields
891822
let addr = get_address!(guest_error_buffer);
892823
shared_mem.write_u64(self.get_guest_error_buffer_pointer_offset(), addr)?;
@@ -1027,8 +958,6 @@ mod tests {
1027958

1028959
expected_size += round_up_to(size_of::<HyperlightPEB>(), PAGE_SIZE_USIZE);
1029960

1030-
expected_size += round_up_to(cfg.get_host_exception_size(), PAGE_SIZE_USIZE);
1031-
1032961
expected_size += round_up_to(cfg.get_guest_error_buffer_size(), PAGE_SIZE_USIZE);
1033962

1034963
expected_size += round_up_to(cfg.get_input_data_size(), PAGE_SIZE_USIZE);

src/hyperlight_host/src/mem/memory_region.rs

-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ pub enum MemoryRegionType {
131131
Code,
132132
/// The region contains the PEB
133133
Peb,
134-
/// The region contains the Host Exception Data
135-
HostExceptionData,
136134
/// The region contains the Guest Error Data
137135
GuestErrorData,
138136
/// The region contains the Input Data

0 commit comments

Comments
 (0)