From 55f40c978bdb4d8f0c6afcf31268bebfb2c5cb11 Mon Sep 17 00:00:00 2001 From: danbugs Date: Tue, 9 Dec 2025 00:11:10 +0000 Subject: [PATCH 1/2] Gate hyperlight-guest-tracing to x86_64 only Move hyperlight-guest-tracing dependency to target-specific section for x86_64 architecture only. This allows i686 and other architectures to build without x86_64-specific tracing functionality. Signed-off-by: danbugs --- src/hyperlight_guest/Cargo.toml | 6 ++++-- src/hyperlight_guest/src/exit.rs | 10 +++++----- src/hyperlight_guest/src/guest_handle/host_comm.rs | 10 +++++----- src/hyperlight_guest/src/lib.rs | 3 ++- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/hyperlight_guest/Cargo.toml b/src/hyperlight_guest/Cargo.toml index ed6d80421..1602d1f0d 100644 --- a/src/hyperlight_guest/Cargo.toml +++ b/src/hyperlight_guest/Cargo.toml @@ -15,10 +15,12 @@ Provides only the essential building blocks for interacting with the host enviro anyhow = { version = "1.0.100", default-features = false } serde_json = { version = "1.0", default-features = false, features = ["alloc"] } hyperlight-common = { workspace = true, default-features = false } -hyperlight-guest-tracing = { workspace = true, default-features = false } flatbuffers = { version= "25.9.23", default-features = false } tracing = { version = "0.1.43", default-features = false, features = ["attributes"] } +[target.'cfg(target_arch = "x86_64")'.dependencies] +hyperlight-guest-tracing = { workspace = true, default-features = false, optional = true } + [features] default = [] -trace_guest = ["hyperlight-guest-tracing/trace"] +trace_guest = ["dep:hyperlight-guest-tracing", "hyperlight-guest-tracing?/trace"] diff --git a/src/hyperlight_guest/src/exit.rs b/src/hyperlight_guest/src/exit.rs index 787bf90c8..6e7a61465 100644 --- a/src/hyperlight_guest/src/exit.rs +++ b/src/hyperlight_guest/src/exit.rs @@ -27,7 +27,7 @@ use tracing::instrument; #[inline(never)] #[instrument(skip_all, level = "Trace")] pub fn halt() { - #[cfg(feature = "trace_guest")] + #[cfg(all(feature = "trace_guest", target_arch = "x86_64"))] { // Send data before halting // If there is no data, this doesn't do anything @@ -49,7 +49,7 @@ pub extern "C" fn abort() -> ! { /// Exits the VM with an Abort OUT action and a specific code. pub fn abort_with_code(code: &[u8]) -> ! { // End any ongoing trace before aborting - #[cfg(feature = "trace_guest")] + #[cfg(all(feature = "trace_guest", target_arch = "x86_64"))] hyperlight_guest_tracing::end_trace(); outb(OutBAction::Abort as u16, code); outb(OutBAction::Abort as u16, &[0xFF]); // send abort terminator (if not included in code) @@ -62,7 +62,7 @@ pub fn abort_with_code(code: &[u8]) -> ! { /// This function is unsafe because it dereferences a raw pointer. pub unsafe fn abort_with_code_and_message(code: &[u8], message_ptr: *const c_char) -> ! { // End any ongoing trace before aborting - #[cfg(feature = "trace_guest")] + #[cfg(all(feature = "trace_guest", target_arch = "x86_64"))] hyperlight_guest_tracing::end_trace(); unsafe { // Step 1: Send abort code (typically 1 byte, but `code` allows flexibility) @@ -116,7 +116,7 @@ pub(crate) fn outb(port: u16, data: &[u8]) { /// in exception contexts. Because if the trace state is already locked, trying to create a span /// would cause a panic, which is undesirable in exception handling. pub(crate) unsafe fn out32(port: u16, val: u32) { - #[cfg(feature = "trace_guest")] + #[cfg(all(feature = "trace_guest", target_arch = "x86_64"))] { if let Some((ptr, len)) = hyperlight_guest_tracing::serialized_data() { // If tracing is enabled and there is data to send, send it along with the OUT action @@ -142,7 +142,7 @@ pub(crate) unsafe fn out32(port: u16, val: u32) { }; } } - #[cfg(not(feature = "trace_guest"))] + #[cfg(not(all(feature = "trace_guest", target_arch = "x86_64")))] unsafe { asm!("out dx, eax", in("dx") port, in("eax") val, options(preserves_flags, nomem, nostack)); } diff --git a/src/hyperlight_guest/src/guest_handle/host_comm.rs b/src/hyperlight_guest/src/guest_handle/host_comm.rs index 6761a21d4..37c5979d9 100644 --- a/src/hyperlight_guest/src/guest_handle/host_comm.rs +++ b/src/hyperlight_guest/src/guest_handle/host_comm.rs @@ -179,7 +179,7 @@ impl GuestHandle { line: u32, ) { // Closure to send log message to host - let send_to_host = || { + let _send_to_host = || { let guest_log_data = GuestLogData::new( message.to_string(), source.to_string(), @@ -201,7 +201,7 @@ impl GuestHandle { } }; - #[cfg(feature = "trace_guest")] + #[cfg(all(feature = "trace_guest", target_arch = "x86_64"))] if hyperlight_guest_tracing::is_trace_enabled() { // If the "trace_guest" feature is enabled and tracing is initialized, log using tracing tracing::trace!( @@ -213,11 +213,11 @@ impl GuestHandle { code.lineno = line, ); } else { - send_to_host(); + _send_to_host(); } - #[cfg(not(feature = "trace_guest"))] + #[cfg(not(all(feature = "trace_guest", target_arch = "x86_64")))] { - send_to_host(); + _send_to_host(); } } } diff --git a/src/hyperlight_guest/src/lib.rs b/src/hyperlight_guest/src/lib.rs index add2e21c7..fce0767c0 100644 --- a/src/hyperlight_guest/src/lib.rs +++ b/src/hyperlight_guest/src/lib.rs @@ -15,7 +15,8 @@ limitations under the License. */ #![no_std] -// Deps +#[cfg(all(feature = "trace_guest", not(target_arch = "x86_64")))] +compile_error!("trace_guest feature is only supported on x86_64 architecture"); extern crate alloc; From b8d8b2f9e3d4ef1b33dc963fde4be02acb811480 Mon Sep 17 00:00:00 2001 From: danbugs Date: Tue, 9 Dec 2025 08:09:10 +0000 Subject: [PATCH 2/2] ci: verify hyperlight-guest builds for 32-bit x86 Add CI check to ensure hyperlight-guest library builds for 32-bit x86 architecture (i686-unknown-linux-gnu) to maintain compatibility with Nanvix's custom 32-bit x86 target. Signed-off-by: danbugs --- .github/workflows/dep_rust.yml | 6 ++++++ Justfile | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/.github/workflows/dep_rust.yml b/.github/workflows/dep_rust.yml index 865228186..55a3bbc86 100644 --- a/.github/workflows/dep_rust.yml +++ b/.github/workflows/dep_rust.yml @@ -93,6 +93,12 @@ jobs: - name: Verify MSRV run: ./dev/verify-msrv.sh hyperlight-host hyperlight-guest hyperlight-guest-bin hyperlight-common + - name: Check hyperlight-guest builds for 32-bit (Nanvix compatibility) + if: ${{ runner.os == 'Linux' }} + run: | + rustup target add i686-unknown-linux-gnu + just check-guest-i686 ${{ inputs.config }} + build: if: ${{ inputs.docs_only == 'false' }} timeout-minutes: 60 diff --git a/Justfile b/Justfile index 5ef96acd3..0e4392720 100644 --- a/Justfile +++ b/Justfile @@ -198,6 +198,10 @@ test-rust-tracing target=default-target features="": {{ cargo-cmd }} test -p hyperlight-common -F trace_guest --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} {{ cargo-cmd }} test -p hyperlight-host --profile={{ if target == "debug" { "dev" } else { target } }} {{ if features =="" {'--features trace_guest'} else { "--features trace_guest," + features } }} {{ target-triple-flag }} +# verify hyperlight-guest builds for 32-bit (for Nanvix compatibility - uses i686 as proxy for Nanvix's custom 32-bit x86 target) +check-guest-i686 target=default-target: + cargo check -p hyperlight-guest --target i686-unknown-linux-gnu --profile={{ if target == "debug" { "dev" } else { target } }} + # Build the tracing guest to ensure it builds with the tracing feature just build-rust-guests {{ target }} trace_guest just move-rust-guests {{ target }}