From d8a1ad5952227d4215978538fa5a20253492156a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Fri, 8 Sep 2023 13:26:17 +0200 Subject: [PATCH 1/4] fix(x86_64/shutdown): don't try QEMU exit on Uhyve MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/arch/x86_64/kernel/processor.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/arch/x86_64/kernel/processor.rs b/src/arch/x86_64/kernel/processor.rs index dd76fc939f..1194a1bdb1 100644 --- a/src/arch/x86_64/kernel/processor.rs +++ b/src/arch/x86_64/kernel/processor.rs @@ -997,11 +997,12 @@ pub fn shutdown() -> ! { PlatformInfo::LinuxBootParams { .. } => without_interrupts(|| loop { halt(); }), - _ => { + PlatformInfo::Multiboot { .. } => { // Try QEMU's debug exit let exit_handler = qemu_exit::X86::new(0xf4, 3); exit_handler.exit_success() } + PlatformInfo::Uhyve { .. } => todo!(), } } } From 1b7a19aa18225586e712afa6a9af4cfa3dec2a23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Fri, 8 Sep 2023 13:47:45 +0200 Subject: [PATCH 2/4] fix(x86_64/shutdown): use triple fault to shutdown firecracker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/arch/x86_64/kernel/processor.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/arch/x86_64/kernel/processor.rs b/src/arch/x86_64/kernel/processor.rs index 1194a1bdb1..d1de318a70 100644 --- a/src/arch/x86_64/kernel/processor.rs +++ b/src/arch/x86_64/kernel/processor.rs @@ -11,12 +11,16 @@ use core::sync::atomic::{AtomicU64, Ordering}; use core::{fmt, u32}; use hermit_entry::boot_info::PlatformInfo; -use hermit_sync::{without_interrupts, Lazy}; +use hermit_sync::Lazy; use qemu_exit::QEMUExit; use x86::bits64::segmentation; use x86::controlregs::*; use x86::cpuid::*; use x86::msr::*; +use x86_64::instructions::interrupts::int3; +use x86_64::instructions::tables::lidt; +use x86_64::structures::DescriptorTablePointer; +use x86_64::VirtAddr; #[cfg(feature = "acpi")] use crate::arch::x86_64::kernel::acpi; @@ -975,6 +979,23 @@ pub fn halt() { } } +/// Causes a triple fault. +/// +/// Triple faults cause CPU resets. +/// On KVM, this results in `KVM_EXIT_SHUTDOWN`. +/// This is the preferred way of shutting down the CPU on firecracker. +/// +/// See [Triple Faulting the CPU](http://www.rcollins.org/Productivity/TripleFault.html). +fn triple_fault() -> ! { + let idt = DescriptorTablePointer { + limit: 0, + base: VirtAddr::zero(), + }; + unsafe { lidt(&idt) }; + int3(); + unreachable!() +} + /// Shutdown the system pub fn shutdown() -> ! { info!("Shutting down system"); @@ -994,9 +1015,7 @@ pub fn shutdown() -> ! { Ok(_never) => unreachable!(), Err(()) => { match boot_info().platform_info { - PlatformInfo::LinuxBootParams { .. } => without_interrupts(|| loop { - halt(); - }), + PlatformInfo::LinuxBootParams { .. } => triple_fault(), PlatformInfo::Multiboot { .. } => { // Try QEMU's debug exit let exit_handler = qemu_exit::X86::new(0xf4, 3); From d56974aeb0c59308594fbb238e2fcdea17bd5a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Fri, 8 Sep 2023 13:48:24 +0200 Subject: [PATCH 3/4] ci: wait for firecracker shutdown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- .github/workflows/ci.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 99e79f69d3..f3bb6d9921 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -427,7 +427,4 @@ jobs: - name: Build minimal profile (debug) run: cargo build -Zbuild-std=std,panic_abort --target x86_64-unknown-hermit --no-default-features --package hello_world - name: Test debug profile (Firecracker) - run: | - ./fc/firecracker-v1.4.1-x86_64 --no-api --config-file ./kernel/fc-config.json & - sleep 1 - kill -KILL $(pidof firecracker-v1.4.1-x86_64) \ No newline at end of file + run: ./fc/firecracker-v1.4.1-x86_64 --no-api --config-file ./kernel/fc-config.json \ No newline at end of file From 95700849958997718b5ac4698271a3b20107e690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Fri, 8 Sep 2023 13:50:12 +0200 Subject: [PATCH 4/4] ci: install latest firecracker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- .github/workflows/ci.yml | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f3bb6d9921..7b10ef7b5a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -414,17 +414,19 @@ jobs: with: repo: hermitcore/rusty-loader file: rusty-loader-x86_64-fc - - name: Download firecracker - uses: dsaltares/fetch-gh-release-asset@1.1.1 - with: - repo: firecracker-microvm/firecracker - version: tags/v1.4.1 - file: firecracker-v1.4.1-x86_64.tgz - target: 'firecracker-x86_64.tgz' - name: Install firecracker run: | - tar xzvf firecracker-x86_64.tgz --one-top-level=fc --strip-components 1 + # https://github.com/firecracker-microvm/firecracker/blob/7c5fc8707f26c4244d48a747631ab0fb31fc4c39/docs/getting-started.md#getting-a-firecracker-binary + ARCH="$(uname -m)" + release_url="https://github.com/firecracker-microvm/firecracker/releases" + latest=$(basename $(curl -fsSLI -o /dev/null -w %{url_effective} ${release_url}/latest)) + curl -L ${release_url}/download/${latest}/firecracker-${latest}-${ARCH}.tgz \ + | tar -xz + + # Rename the binary to "firecracker" + mv release-${latest}-$(uname -m)/firecracker-${latest}-${ARCH} firecracker + echo "$PWD" >> $GITHUB_PATH - name: Build minimal profile (debug) run: cargo build -Zbuild-std=std,panic_abort --target x86_64-unknown-hermit --no-default-features --package hello_world - name: Test debug profile (Firecracker) - run: ./fc/firecracker-v1.4.1-x86_64 --no-api --config-file ./kernel/fc-config.json \ No newline at end of file + run: firecracker --no-api --config-file ./kernel/fc-config.json