Skip to content

Commit c9bd6cf

Browse files
committed
[trace] remove old tracing functionality
- This steps cleans up codebase for the new way of tracing guests - The current method involves custom macros and logic that are not the best for maintainability Signed-off-by: Doru Blânzeanu <[email protected]>
1 parent 2dd3e1b commit c9bd6cf

File tree

26 files changed

+255
-934
lines changed

26 files changed

+255
-934
lines changed

.github/workflows/CargoPublish.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,6 @@ jobs:
8585
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_PUBLISH_TOKEN }}
8686
if: env.PUBLISH_HYPERLIGHT_COMMON != 'false'
8787

88-
- name: Publish hyperlight-guest-tracing-macro
89-
continue-on-error: ${{ inputs.dry_run }}
90-
run: cargo publish --manifest-path ./src/hyperlight_guest_tracing_macro/Cargo.toml ${{ inputs.dry_run && '--dry-run' || '' }}
91-
env:
92-
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_PUBLISH_TOKEN }}
93-
if: env.PUBLISH_HYPERLIGHT_GUEST_TRACING_MACRO != 'false'
94-
9588
- name: Publish hyperlight-guest-tracing
9689
continue-on-error: ${{ inputs.dry_run }}
9790
run: cargo publish --manifest-path ./src/hyperlight_guest_tracing/Cargo.toml ${{ inputs.dry_run && '--dry-run' || '' }}

Cargo.lock

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

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ members = [
1111
"src/hyperlight_host",
1212
"src/hyperlight_guest_capi",
1313
"src/hyperlight_guest_tracing",
14-
"src/hyperlight_guest_tracing_macro",
1514
"src/hyperlight_testing",
1615
"fuzz",
1716
"src/hyperlight_guest_bin",
@@ -42,7 +41,6 @@ hyperlight-guest = { path = "src/hyperlight_guest", version = "0.9.0", default-f
4241
hyperlight-guest-bin = { path = "src/hyperlight_guest_bin", version = "0.9.0", default-features = false }
4342
hyperlight-testing = { path = "src/hyperlight_testing", default-features = false }
4443
hyperlight-guest-tracing = { path = "src/hyperlight_guest_tracing", version = "0.9.0", default-features = false }
45-
hyperlight-guest-tracing-macro = { path = "src/hyperlight_guest_tracing_macro", version = "0.9.0", default-features = false }
4644
hyperlight-component-util = { path = "src/hyperlight_component_util", version = "0.9.0", default-features = false }
4745
hyperlight-component-macro = { path = "src/hyperlight_component_macro", version = "0.9.0", default-features = false }
4846

src/hyperlight_common/src/outb.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,11 @@ impl TryFrom<u8> for Exception {
9292
/// - DebugPrint: prints a message to the host
9393
/// - TraceMemoryAlloc: records memory allocation events
9494
/// - TraceMemoryFree: records memory deallocation events
95-
/// - TraceRecord: records a trace event in the guest
9695
pub enum OutBAction {
9796
Log = 99,
9897
CallFunction = 101,
9998
Abort = 102,
10099
DebugPrint = 103,
101-
#[cfg(feature = "trace_guest")]
102-
TraceRecord = 104,
103100
#[cfg(feature = "mem_profile")]
104101
TraceMemoryAlloc = 105,
105102
#[cfg(feature = "mem_profile")]
@@ -114,8 +111,6 @@ impl TryFrom<u16> for OutBAction {
114111
101 => Ok(OutBAction::CallFunction),
115112
102 => Ok(OutBAction::Abort),
116113
103 => Ok(OutBAction::DebugPrint),
117-
#[cfg(feature = "trace_guest")]
118-
104 => Ok(OutBAction::TraceRecord),
119114
#[cfg(feature = "mem_profile")]
120115
105 => Ok(OutBAction::TraceMemoryAlloc),
121116
#[cfg(feature = "mem_profile")]

src/hyperlight_guest/src/exit.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,17 @@ use hyperlight_common::outb::OutBAction;
2121

2222
/// Halt the execution of the guest and returns control to the host.
2323
#[inline(never)]
24-
#[hyperlight_guest_tracing::trace_function]
2524
pub fn halt() {
26-
// Ensure all tracing data is flushed before halting
27-
hyperlight_guest_tracing::flush!();
2825
unsafe { asm!("hlt", options(nostack)) }
2926
}
3027

3128
/// Exits the VM with an Abort OUT action and code 0.
3229
#[unsafe(no_mangle)]
33-
#[hyperlight_guest_tracing::trace_function]
3430
pub extern "C" fn abort() -> ! {
3531
abort_with_code(&[0, 0xFF])
3632
}
3733

3834
/// Exits the VM with an Abort OUT action and a specific code.
39-
#[hyperlight_guest_tracing::trace_function]
4035
pub fn abort_with_code(code: &[u8]) -> ! {
4136
outb(OutBAction::Abort as u16, code);
4237
outb(OutBAction::Abort as u16, &[0xFF]); // send abort terminator (if not included in code)
@@ -47,7 +42,6 @@ pub fn abort_with_code(code: &[u8]) -> ! {
4742
///
4843
/// # Safety
4944
/// This function is unsafe because it dereferences a raw pointer.
50-
#[hyperlight_guest_tracing::trace_function]
5145
pub unsafe fn abort_with_code_and_message(code: &[u8], message_ptr: *const c_char) -> ! {
5246
unsafe {
5347
// Step 1: Send abort code (typically 1 byte, but `code` allows flexibility)
@@ -76,10 +70,8 @@ pub fn write_abort(code: &[u8]) {
7670
}
7771

7872
/// OUT bytes to the host through multiple exits.
79-
#[hyperlight_guest_tracing::trace_function]
8073
pub(crate) fn outb(port: u16, data: &[u8]) {
8174
// Ensure all tracing data is flushed before sending OUT bytes
82-
hyperlight_guest_tracing::flush!();
8375
unsafe {
8476
let mut i = 0;
8577
while i < data.len() {
@@ -96,7 +88,6 @@ pub(crate) fn outb(port: u16, data: &[u8]) {
9688
}
9789

9890
/// OUT function for sending a 32-bit value to the host.
99-
#[hyperlight_guest_tracing::trace_function]
10091
pub(crate) unsafe fn out32(port: u16, val: u32) {
10192
unsafe {
10293
asm!("out dx, eax", in("dx") port, in("eax") val, options(preserves_flags, nomem, nostack));

src/hyperlight_guest/src/guest_handle/host_comm.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ use crate::exit::out32;
3737

3838
impl GuestHandle {
3939
/// Get user memory region as bytes.
40-
#[hyperlight_guest_tracing::trace_function]
4140
pub fn read_n_bytes_from_user_memory(&self, num: u64) -> Result<Vec<u8>> {
4241
let peb_ptr = self.peb().unwrap();
4342
let user_memory_region_ptr = unsafe { (*peb_ptr).init_data.ptr as *mut u8 };
@@ -66,7 +65,6 @@ impl GuestHandle {
6665
///
6766
/// When calling `call_host_function<T>`, this function is called
6867
/// internally to get the return value.
69-
#[hyperlight_guest_tracing::trace_function]
7068
pub fn get_host_return_value<T: TryFrom<ReturnValue>>(&self) -> Result<T> {
7169
let return_value = self
7270
.try_pop_shared_input_data_into::<ReturnValue>()
@@ -87,7 +85,6 @@ impl GuestHandle {
8785
///
8886
/// Note: The function return value must be obtained by calling
8987
/// `get_host_return_value`.
90-
#[hyperlight_guest_tracing::trace_function]
9188
pub fn call_host_function_without_returning_result(
9289
&self,
9390
function_name: &str,
@@ -121,7 +118,6 @@ impl GuestHandle {
121118
/// sends it to the host, and then retrieves the return value.
122119
///
123120
/// The return value is deserialized into the specified type `T`.
124-
#[hyperlight_guest_tracing::trace_function]
125121
pub fn call_host_function<T: TryFrom<ReturnValue>>(
126122
&self,
127123
function_name: &str,
@@ -132,7 +128,6 @@ impl GuestHandle {
132128
self.get_host_return_value::<T>()
133129
}
134130

135-
#[hyperlight_guest_tracing::trace_function]
136131
pub fn get_host_function_details(&self) -> HostFunctionDetails {
137132
let peb_ptr = self.peb().unwrap();
138133
let host_function_details_buffer =
@@ -149,7 +144,6 @@ impl GuestHandle {
149144
}
150145

151146
/// Write an error to the shared output data buffer.
152-
#[hyperlight_guest_tracing::trace_function]
153147
pub fn write_error(&self, error_code: ErrorCode, message: Option<&str>) {
154148
let guest_error: GuestError = GuestError::new(
155149
error_code,
@@ -165,7 +159,6 @@ impl GuestHandle {
165159
}
166160

167161
/// Log a message with the specified log level, source, caller, source file, and line number.
168-
#[hyperlight_guest_tracing::trace_function]
169162
pub fn log_message(
170163
&self,
171164
log_level: LogLevel,

src/hyperlight_guest/src/guest_handle/io.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use crate::error::{HyperlightGuestError, Result};
2626

2727
impl GuestHandle {
2828
/// Pops the top element from the shared input data buffer and returns it as a T
29-
#[hyperlight_guest_tracing::trace_function]
3029
pub fn try_pop_shared_input_data_into<T>(&self) -> Result<T>
3130
where
3231
T: for<'a> TryFrom<&'a [u8]>,
@@ -68,18 +67,15 @@ impl GuestHandle {
6867
let buffer = &idb[last_element_offset_rel as usize..];
6968

7069
// convert the buffer to T
71-
let type_t = hyperlight_guest_tracing::trace!(
72-
"convert buffer",
73-
match T::try_from(buffer) {
74-
Ok(t) => Ok(t),
75-
Err(_e) => {
76-
return Err(HyperlightGuestError::new(
77-
ErrorCode::GuestError,
78-
format!("Unable to convert buffer to {}", type_name::<T>()),
79-
));
80-
}
70+
let type_t = match T::try_from(buffer) {
71+
Ok(t) => Ok(t),
72+
Err(_e) => {
73+
return Err(HyperlightGuestError::new(
74+
ErrorCode::GuestError,
75+
format!("Unable to convert buffer to {}", type_name::<T>()),
76+
));
8177
}
82-
);
78+
};
8379

8480
// update the stack pointer to point to the element we just popped of since that is now free
8581
idb[..8].copy_from_slice(&last_element_offset_rel.to_le_bytes());
@@ -91,7 +87,6 @@ impl GuestHandle {
9187
}
9288

9389
/// Pushes the given data onto the shared output data buffer.
94-
#[hyperlight_guest_tracing::trace_function]
9590
pub fn push_shared_output_data(&self, data: &[u8]) -> Result<()> {
9691
let peb_ptr = self.peb().unwrap();
9792
let output_stack_size = unsafe { (*peb_ptr).output_stack.size as usize };
@@ -137,9 +132,7 @@ impl GuestHandle {
137132
}
138133

139134
// write the actual data
140-
hyperlight_guest_tracing::trace!("copy data", {
141-
odb[stack_ptr_rel as usize..stack_ptr_rel as usize + data.len()].copy_from_slice(data);
142-
});
135+
odb[stack_ptr_rel as usize..stack_ptr_rel as usize + data.len()].copy_from_slice(data);
143136

144137
// write the offset to the newly written data, to the top of the stack
145138
let bytes: [u8; 8] = stack_ptr_rel.to_le_bytes();

src/hyperlight_guest_bin/src/exceptions/gdt.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ struct GdtPointer {
7272
}
7373

7474
/// Load the GDT
75-
#[hyperlight_guest_tracing::trace_function]
7675
pub unsafe fn load_gdt() {
7776
unsafe {
7877
let gdt_ptr = GdtPointer {

src/hyperlight_guest_bin/src/exceptions/handler.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,6 @@ pub extern "C" fn hl_exception_handler(
6565
exception_number: u64,
6666
page_fault_address: u64,
6767
) {
68-
// When using the `trace_function` macro, it wraps the function body with create_trace_record
69-
// call, which generates a warning because of the `abort_with_code_and_message` call which does
70-
// not return.
71-
// This is manually added to avoid the warning.
72-
hyperlight_guest_tracing::trace!("> hl_exception_handler");
73-
7468
let ctx = stack_pointer as *mut Context;
7569
let exn_info = (stack_pointer + size_of::<Context>() as u64) as *mut ExceptionInfo;
7670

@@ -101,7 +95,6 @@ pub extern "C" fn hl_exception_handler(
10195
)(exception_number, exn_info, ctx, page_fault_address)
10296
}
10397
{
104-
hyperlight_guest_tracing::trace!("< hl_exception_handler");
10598
return;
10699
}
107100
}

src/hyperlight_guest_bin/src/exceptions/idt.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ impl IdtEntry {
7171
// Architectures Software Developer's Manual).
7272
pub(crate) static mut IDT: [IdtEntry; 256] = unsafe { core::mem::zeroed() };
7373

74-
#[hyperlight_guest_tracing::trace_function]
7574
pub(crate) fn init_idt() {
7675
set_idt_entry(Exception::DivideByZero as usize, _do_excp0); // Divide by zero
7776
set_idt_entry(Exception::Debug as usize, _do_excp1); // Debug

0 commit comments

Comments
 (0)