Skip to content

Commit 92575a3

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 52bf859 commit 92575a3

File tree

27 files changed

+261
-950
lines changed

27 files changed

+261
-950
lines changed

.github/workflows/CargoPublish.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
VERSION="${VERSION#refs/heads/release/v}"
4646
echo "VERSION=$VERSION" >> $GITHUB_ENV
4747
fi
48-
./dev/verify-version.sh "$VERSION" hyperlight-common hyperlight-guest hyperlight-guest-bin hyperlight-host hyperlight-component-util hyperlight-component-macro hyperlight-guest-tracing-macro hyperlight-guest-tracing
48+
./dev/verify-version.sh "$VERSION" hyperlight-common hyperlight-guest hyperlight-guest-bin hyperlight-host hyperlight-component-util hyperlight-component-macro hyperlight-guest-tracing
4949
5050
- name: Determine which crates need publishing
5151
run: |
@@ -74,7 +74,6 @@ jobs:
7474
needs_publish hyperlight-component-util
7575
needs_publish hyperlight-component-macro
7676
needs_publish hyperlight-host
77-
needs_publish hyperlight-guest-tracing-macro
7877
needs_publish hyperlight-guest-tracing
7978
8079
- name: Publish hyperlight-common
@@ -84,13 +83,6 @@ jobs:
8483
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_PUBLISH_TOKEN }}
8584
if: env.PUBLISH_HYPERLIGHT_COMMON != 'false'
8685

87-
- name: Publish hyperlight-guest-tracing-macro
88-
continue-on-error: ${{ inputs.dry_run }}
89-
run: cargo publish --manifest-path ./src/hyperlight_guest_tracing_macro/Cargo.toml ${{ inputs.dry_run && '--dry-run' || '' }}
90-
env:
91-
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_PUBLISH_TOKEN }}
92-
if: env.PUBLISH_HYPERLIGHT_GUEST_TRACING_MACRO != 'false'
93-
9486
- name: Publish hyperlight-guest-tracing
9587
continue-on-error: ${{ inputs.dry_run }}
9688
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.10.0", default-
4241
hyperlight-guest-bin = { path = "src/hyperlight_guest_bin", version = "0.10.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.10.0", default-features = false }
45-
hyperlight-guest-tracing-macro = { path = "src/hyperlight_guest_tracing_macro", version = "0.10.0", default-features = false }
4644
hyperlight-component-util = { path = "src/hyperlight_component_util", version = "0.10.0", default-features = false }
4745
hyperlight-component-macro = { path = "src/hyperlight_component_macro", version = "0.10.0", default-features = false }
4846

Justfile

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ like-ci config=default-target hypervisor="kvm":
110110
{{ if os() == "linux" { "just clippy-exhaustive " + config } else { "" } }}
111111

112112
@# Verify MSRV
113-
./dev/verify-msrv.sh hyperlight-common hyperlight-guest hyperlight-guest-bin hyperlight-host hyperlight-component-util hyperlight-component-macro hyperlight-guest-tracing-macro hyperlight-guest-tracing
113+
./dev/verify-msrv.sh hyperlight-common hyperlight-guest hyperlight-guest-bin hyperlight-host hyperlight-component-util hyperlight-component-macro hyperlight-guest-tracing
114114

115115
@# Build and move Rust guests
116116
just build-rust-guests {{config}}
@@ -200,22 +200,10 @@ test-rust-crashdump target=default-target features="":
200200
test-rust-tracing target=default-target features="":
201201
# Run tests for the tracing guest and macro
202202
{{ cargo-cmd }} test -p hyperlight-guest-tracing --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }}
203-
{{ cargo-cmd }} test -p hyperlight-guest-tracing-macro --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }}
204203

205-
# Prepare the tracing guest for testing
204+
# Build the tracing guest to ensure it builds with the tracing feature
206205
just build-rust-guests {{ target }} trace_guest
207206
just move-rust-guests {{ target }}
208-
# Run hello-world example with tracing enabled to get the trace output
209-
# note that trace-dump doesn't run on MUSL target as of now
210-
TRACE_OUTPUT="$({{ cargo-cmd }} run --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} --example hello-world --features {{ if features =="" {"trace_guest"} else { "trace_guest," + features } }})" && \
211-
TRACE_FILE="$(echo "$TRACE_OUTPUT" | grep -oE 'Creating trace file at: [^ ]+' | awk -F': ' '{print $2}')" && \
212-
TRACE_FILE="$(echo "$TRACE_OUTPUT" | grep -oE 'Creating trace file at: [^ ]+' | awk -F': ' '{print $2}' | sed -E 's|^(trace/[^ ]+\.trace)$|./\1|; s|.*/(trace/[^ ]+\.trace)$|./\1|')" && \
213-
echo "$TRACE_OUTPUT" && \
214-
if [ -z "$TRACE_FILE" ]; then \
215-
echo "Error: Could not extract trace file path from output." >&2 ; \
216-
exit 1 ; \
217-
fi && \
218-
cargo run -p trace_dump ./{{ simpleguest_source }}/{{ target }}/simpleguest "$TRACE_FILE" list_frames
219207

220208
# Rebuild the tracing guests without the tracing feature
221209
# This is to ensure that the tracing feature does not affect the other tests
@@ -275,7 +263,6 @@ clippy-exhaustive target=default-target: (witguest-wit)
275263
./hack/clippy-package-features.sh hyperlight-testing {{ target }} {{ target-triple }}
276264
./hack/clippy-package-features.sh hyperlight-component-macro {{ target }} {{ target-triple }}
277265
./hack/clippy-package-features.sh hyperlight-component-util {{ target }} {{ target-triple }}
278-
./hack/clippy-package-features.sh hyperlight-guest-tracing-macro {{ target }}
279266
./hack/clippy-package-features.sh hyperlight-guest-tracing {{ target }}
280267
just clippy-guests {{ target }}
281268

@@ -285,7 +272,7 @@ clippy-package package target=default-target: (witguest-wit)
285272

286273
# Verify Minimum Supported Rust Version
287274
verify-msrv:
288-
./dev/verify-msrv.sh hyperlight-common hyperlight-guest hyperlight-guest-bin hyperlight-host hyperlight-component-util hyperlight-component-macro hyperlight-guest-tracing-macro hyperlight-guest-tracing
275+
./dev/verify-msrv.sh hyperlight-common hyperlight-guest hyperlight-guest-bin hyperlight-host hyperlight-component-util hyperlight-component-macro hyperlight-guest-tracing
289276

290277
#####################
291278
### RUST EXAMPLES ###

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 & 6 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 inner = self
7270
.try_pop_shared_input_data_into::<FunctionCallResult>()
@@ -93,7 +91,6 @@ impl GuestHandle {
9391
///
9492
/// Note: The function return value must be obtained by calling
9593
/// `get_host_return_value`.
96-
#[hyperlight_guest_tracing::trace_function]
9794
pub fn call_host_function_without_returning_result(
9895
&self,
9996
function_name: &str,
@@ -127,7 +124,6 @@ impl GuestHandle {
127124
/// sends it to the host, and then retrieves the return value.
128125
///
129126
/// The return value is deserialized into the specified type `T`.
130-
#[hyperlight_guest_tracing::trace_function]
131127
pub fn call_host_function<T: TryFrom<ReturnValue>>(
132128
&self,
133129
function_name: &str,
@@ -138,7 +134,6 @@ impl GuestHandle {
138134
self.get_host_return_value::<T>()
139135
}
140136

141-
#[hyperlight_guest_tracing::trace_function]
142137
pub fn get_host_function_details(&self) -> HostFunctionDetails {
143138
let peb_ptr = self.peb().unwrap();
144139
let host_function_details_buffer =
@@ -155,7 +150,6 @@ impl GuestHandle {
155150
}
156151

157152
/// Log a message with the specified log level, source, caller, source file, and line number.
158-
#[hyperlight_guest_tracing::trace_function]
159153
pub fn log_message(
160154
&self,
161155
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
}

0 commit comments

Comments
 (0)