Skip to content

Commit 827f913

Browse files
authored
Enable 32-bit x86 guest support (#1085)
* 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 <danilochiarlone@gmail.com> * 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 <danilochiarlone@gmail.com> --------- Signed-off-by: danbugs <danilochiarlone@gmail.com>
1 parent 5bfe0bf commit 827f913

File tree

6 files changed

+26
-13
lines changed

6 files changed

+26
-13
lines changed

.github/workflows/dep_rust.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ jobs:
9393
- name: Verify MSRV
9494
run: ./dev/verify-msrv.sh hyperlight-host hyperlight-guest hyperlight-guest-bin hyperlight-common
9595

96+
- name: Check hyperlight-guest builds for 32-bit (Nanvix compatibility)
97+
if: ${{ runner.os == 'Linux' }}
98+
run: |
99+
rustup target add i686-unknown-linux-gnu
100+
just check-guest-i686 ${{ inputs.config }}
101+
96102
build:
97103
if: ${{ inputs.docs_only == 'false' }}
98104
timeout-minutes: 60

Justfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ test-rust-tracing target=default-target features="":
198198
{{ cargo-cmd }} test -p hyperlight-common -F trace_guest --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }}
199199
{{ 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 }}
200200

201+
# verify hyperlight-guest builds for 32-bit (for Nanvix compatibility - uses i686 as proxy for Nanvix's custom 32-bit x86 target)
202+
check-guest-i686 target=default-target:
203+
cargo check -p hyperlight-guest --target i686-unknown-linux-gnu --profile={{ if target == "debug" { "dev" } else { target } }}
204+
201205
# Build the tracing guest to ensure it builds with the tracing feature
202206
just build-rust-guests {{ target }} trace_guest
203207
just move-rust-guests {{ target }}

src/hyperlight_guest/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ Provides only the essential building blocks for interacting with the host enviro
1515
anyhow = { version = "1.0.100", default-features = false }
1616
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
1717
hyperlight-common = { workspace = true, default-features = false }
18-
hyperlight-guest-tracing = { workspace = true, default-features = false }
1918
flatbuffers = { version= "25.9.23", default-features = false }
2019
tracing = { version = "0.1.43", default-features = false, features = ["attributes"] }
2120

21+
[target.'cfg(target_arch = "x86_64")'.dependencies]
22+
hyperlight-guest-tracing = { workspace = true, default-features = false, optional = true }
23+
2224
[features]
2325
default = []
24-
trace_guest = ["hyperlight-guest-tracing/trace"]
26+
trace_guest = ["dep:hyperlight-guest-tracing", "hyperlight-guest-tracing?/trace"]

src/hyperlight_guest/src/exit.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use tracing::instrument;
2727
#[inline(never)]
2828
#[instrument(skip_all, level = "Trace")]
2929
pub fn halt() {
30-
#[cfg(feature = "trace_guest")]
30+
#[cfg(all(feature = "trace_guest", target_arch = "x86_64"))]
3131
{
3232
// Send data before halting
3333
// If there is no data, this doesn't do anything
@@ -49,7 +49,7 @@ pub extern "C" fn abort() -> ! {
4949
/// Exits the VM with an Abort OUT action and a specific code.
5050
pub fn abort_with_code(code: &[u8]) -> ! {
5151
// End any ongoing trace before aborting
52-
#[cfg(feature = "trace_guest")]
52+
#[cfg(all(feature = "trace_guest", target_arch = "x86_64"))]
5353
hyperlight_guest_tracing::end_trace();
5454
outb(OutBAction::Abort as u16, code);
5555
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]) -> ! {
6262
/// This function is unsafe because it dereferences a raw pointer.
6363
pub unsafe fn abort_with_code_and_message(code: &[u8], message_ptr: *const c_char) -> ! {
6464
// End any ongoing trace before aborting
65-
#[cfg(feature = "trace_guest")]
65+
#[cfg(all(feature = "trace_guest", target_arch = "x86_64"))]
6666
hyperlight_guest_tracing::end_trace();
6767
unsafe {
6868
// Step 1: Send abort code (typically 1 byte, but `code` allows flexibility)
@@ -116,7 +116,7 @@ pub(crate) fn outb(port: u16, data: &[u8]) {
116116
/// in exception contexts. Because if the trace state is already locked, trying to create a span
117117
/// would cause a panic, which is undesirable in exception handling.
118118
pub(crate) unsafe fn out32(port: u16, val: u32) {
119-
#[cfg(feature = "trace_guest")]
119+
#[cfg(all(feature = "trace_guest", target_arch = "x86_64"))]
120120
{
121121
if let Some((ptr, len)) = hyperlight_guest_tracing::serialized_data() {
122122
// 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) {
142142
};
143143
}
144144
}
145-
#[cfg(not(feature = "trace_guest"))]
145+
#[cfg(not(all(feature = "trace_guest", target_arch = "x86_64")))]
146146
unsafe {
147147
asm!("out dx, eax", in("dx") port, in("eax") val, options(preserves_flags, nomem, nostack));
148148
}

src/hyperlight_guest/src/guest_handle/host_comm.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl GuestHandle {
179179
line: u32,
180180
) {
181181
// Closure to send log message to host
182-
let send_to_host = || {
182+
let _send_to_host = || {
183183
let guest_log_data = GuestLogData::new(
184184
message.to_string(),
185185
source.to_string(),
@@ -201,7 +201,7 @@ impl GuestHandle {
201201
}
202202
};
203203

204-
#[cfg(feature = "trace_guest")]
204+
#[cfg(all(feature = "trace_guest", target_arch = "x86_64"))]
205205
if hyperlight_guest_tracing::is_trace_enabled() {
206206
// If the "trace_guest" feature is enabled and tracing is initialized, log using tracing
207207
tracing::trace!(
@@ -213,11 +213,11 @@ impl GuestHandle {
213213
code.lineno = line,
214214
);
215215
} else {
216-
send_to_host();
216+
_send_to_host();
217217
}
218-
#[cfg(not(feature = "trace_guest"))]
218+
#[cfg(not(all(feature = "trace_guest", target_arch = "x86_64")))]
219219
{
220-
send_to_host();
220+
_send_to_host();
221221
}
222222
}
223223
}

src/hyperlight_guest/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ limitations under the License.
1515
*/
1616

1717
#![no_std]
18-
// Deps
18+
#[cfg(all(feature = "trace_guest", not(target_arch = "x86_64")))]
19+
compile_error!("trace_guest feature is only supported on x86_64 architecture");
1920

2021
extern crate alloc;
2122

0 commit comments

Comments
 (0)