Skip to content

Commit d8be0ac

Browse files
authored
Merge pull request #901 from mkroening/firecracker-ci
fix: proper firecracker shutdown
2 parents 00f93f0 + 9570084 commit d8be0ac

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -414,20 +414,19 @@ jobs:
414414
with:
415415
repo: hermitcore/rusty-loader
416416
file: rusty-loader-x86_64-fc
417-
- name: Download firecracker
418-
uses: dsaltares/fetch-gh-release-asset@1.1.1
419-
with:
420-
repo: firecracker-microvm/firecracker
421-
version: tags/v1.4.1
422-
file: firecracker-v1.4.1-x86_64.tgz
423-
target: 'firecracker-x86_64.tgz'
424417
- name: Install firecracker
425418
run: |
426-
tar xzvf firecracker-x86_64.tgz --one-top-level=fc --strip-components 1
419+
# https://github.com/firecracker-microvm/firecracker/blob/7c5fc8707f26c4244d48a747631ab0fb31fc4c39/docs/getting-started.md#getting-a-firecracker-binary
420+
ARCH="$(uname -m)"
421+
release_url="https://github.com/firecracker-microvm/firecracker/releases"
422+
latest=$(basename $(curl -fsSLI -o /dev/null -w %{url_effective} ${release_url}/latest))
423+
curl -L ${release_url}/download/${latest}/firecracker-${latest}-${ARCH}.tgz \
424+
| tar -xz
425+
426+
# Rename the binary to "firecracker"
427+
mv release-${latest}-$(uname -m)/firecracker-${latest}-${ARCH} firecracker
428+
echo "$PWD" >> $GITHUB_PATH
427429
- name: Build minimal profile (debug)
428430
run: cargo build -Zbuild-std=std,panic_abort --target x86_64-unknown-hermit --no-default-features --package hello_world
429431
- name: Test debug profile (Firecracker)
430-
run: |
431-
./fc/firecracker-v1.4.1-x86_64 --no-api --config-file ./kernel/fc-config.json &
432-
sleep 1
433-
kill -KILL $(pidof firecracker-v1.4.1-x86_64)
432+
run: firecracker --no-api --config-file ./kernel/fc-config.json

src/arch/x86_64/kernel/processor.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ use core::sync::atomic::{AtomicU64, Ordering};
1111
use core::{fmt, u32};
1212

1313
use hermit_entry::boot_info::PlatformInfo;
14-
use hermit_sync::{without_interrupts, Lazy};
14+
use hermit_sync::Lazy;
1515
use qemu_exit::QEMUExit;
1616
use x86::bits64::segmentation;
1717
use x86::controlregs::*;
1818
use x86::cpuid::*;
1919
use x86::msr::*;
20+
use x86_64::instructions::interrupts::int3;
21+
use x86_64::instructions::tables::lidt;
22+
use x86_64::structures::DescriptorTablePointer;
23+
use x86_64::VirtAddr;
2024

2125
#[cfg(feature = "acpi")]
2226
use crate::arch::x86_64::kernel::acpi;
@@ -975,6 +979,23 @@ pub fn halt() {
975979
}
976980
}
977981

982+
/// Causes a triple fault.
983+
///
984+
/// Triple faults cause CPU resets.
985+
/// On KVM, this results in `KVM_EXIT_SHUTDOWN`.
986+
/// This is the preferred way of shutting down the CPU on firecracker.
987+
///
988+
/// See [Triple Faulting the CPU](http://www.rcollins.org/Productivity/TripleFault.html).
989+
fn triple_fault() -> ! {
990+
let idt = DescriptorTablePointer {
991+
limit: 0,
992+
base: VirtAddr::zero(),
993+
};
994+
unsafe { lidt(&idt) };
995+
int3();
996+
unreachable!()
997+
}
998+
978999
/// Shutdown the system
9791000
pub fn shutdown() -> ! {
9801001
info!("Shutting down system");
@@ -994,14 +1015,13 @@ pub fn shutdown() -> ! {
9941015
Ok(_never) => unreachable!(),
9951016
Err(()) => {
9961017
match boot_info().platform_info {
997-
PlatformInfo::LinuxBootParams { .. } => without_interrupts(|| loop {
998-
halt();
999-
}),
1000-
_ => {
1018+
PlatformInfo::LinuxBootParams { .. } => triple_fault(),
1019+
PlatformInfo::Multiboot { .. } => {
10011020
// Try QEMU's debug exit
10021021
let exit_handler = qemu_exit::X86::new(0xf4, 3);
10031022
exit_handler.exit_success()
10041023
}
1024+
PlatformInfo::Uhyve { .. } => todo!(),
10051025
}
10061026
}
10071027
}

0 commit comments

Comments
 (0)