Skip to content

Commit ce30e31

Browse files
committed
fix(env): feature-gate is_uhyve()
1 parent 93fe45e commit ce30e31

8 files changed

Lines changed: 45 additions & 21 deletions

File tree

src/arch/aarch64/kernel/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,14 @@ pub fn boot_next_processor() {
9999
#[allow(unused_variables)]
100100
let cpu_online = CPU_ONLINE.0.fetch_add(1, Ordering::Release);
101101

102+
#[allow(clippy::needless_return)]
103+
#[cfg(feature = "uhyve")]
104+
if crate::env::is_uhyve() {
105+
return;
106+
}
107+
102108
#[cfg(all(target_os = "none", feature = "smp"))]
103-
if !crate::env::is_uhyve() && get_possible_cpus() > 1 {
109+
if get_possible_cpus() > 1 {
104110
use core::arch::asm;
105111
use core::hint::spin_loop;
106112

src/arch/aarch64/kernel/processor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ pub fn supports_2mib_pages() -> bool {
262262
}
263263

264264
pub fn configure() {
265+
#[cfg(feature = "uhyve")]
265266
if env::is_uhyve() {
266267
return;
267268
}

src/arch/riscv64/kernel/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,14 @@ pub fn boot_next_processor() {
149149
// TODO: Old: Changing cpu_online will cause uhyve to start the next processor
150150
CPU_ONLINE.fetch_add(1, Ordering::Release);
151151

152-
//When running bare-metal/QEMU we use the firmware to start the next hart
153-
if !env::is_uhyve() {
154-
let start_addr = (start::_start as *const ()).expose_provenance();
155-
sbi_rt::hart_start(next_hart_id as usize, start_addr, 0).unwrap();
152+
#[cfg(feature = "uhyve")]
153+
if env::is_uhyve() {
154+
return;
156155
}
156+
157+
//When running bare-metal/QEMU we use the firmware to start the next hart
158+
let start_addr = (start::_start as *const ()).expose_provenance();
159+
sbi_rt::hart_start(next_hart_id as usize, start_addr, 0).unwrap();
157160
}
158161

159162
pub fn print_statistics() {

src/arch/x86_64/kernel/acpi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ pub fn poweroff() {
517517
}
518518

519519
pub fn init() {
520+
#[cfg(feature = "uhyve")]
520521
if env::is_uhyve() {
521522
return;
522523
}

src/arch/x86_64/kernel/apic.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -506,19 +506,24 @@ fn default_apic() -> PhysAddr {
506506
default_local
507507
}
508508

509+
fn apic_addr() -> PhysAddr {
510+
#[cfg(feature = "uhyve")]
511+
if env::is_uhyve() {
512+
return default_apic();
513+
}
514+
515+
detect_from_acpi()
516+
.or_else(|()| detect_from_mp())
517+
.unwrap_or_else(|()| default_apic())
518+
}
519+
509520
pub fn eoi() {
510521
local_apic_write(IA32_X2APIC_EOI, APIC_EOI_ACK);
511522
}
512523

513524
pub fn init() {
514525
// Detect CPUs and APICs.
515-
let local_apic_physical_address = if env::is_uhyve() {
516-
default_apic()
517-
} else {
518-
detect_from_acpi()
519-
.or_else(|()| detect_from_mp())
520-
.unwrap_or_else(|()| default_apic())
521-
};
526+
let local_apic_physical_address = apic_addr();
522527

523528
// Initialize x2APIC or xAPIC, depending on what's available.
524529
if processor::supports_x2apic() {

src/arch/x86_64/kernel/mod.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ pub fn application_processor_init() {
110110
}
111111

112112
fn finish_processor_init() {
113+
#[cfg(feature = "uhyve")]
113114
if env::is_uhyve() {
114115
// uhyve does not use apic::detect_from_acpi and therefore does not know the number of processors and
115116
// their APIC IDs in advance.
@@ -129,15 +130,18 @@ pub fn boot_next_processor() {
129130
// to initialize the next processor.
130131
let cpu_online = CPU_ONLINE.fetch_add(1, Ordering::Release);
131132

132-
if !env::is_uhyve() {
133-
if cpu_online == 0 {
134-
#[cfg(all(target_os = "none", feature = "smp"))]
135-
apic::boot_application_processors();
136-
}
133+
#[cfg(feature = "uhyve")]
134+
if env::is_uhyve() {
135+
return;
136+
}
137137

138-
if !cfg!(feature = "smp") {
139-
apic::print_information();
140-
}
138+
if cpu_online == 0 {
139+
#[cfg(all(target_os = "none", feature = "smp"))]
140+
apic::boot_application_processors();
141+
}
142+
143+
if !cfg!(feature = "smp") {
144+
apic::print_information();
141145
}
142146
}
143147

src/arch/x86_64/kernel/vga.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ impl VgaScreen {
133133
}
134134

135135
pub fn init() {
136+
#[cfg(feature = "uhyve")]
136137
if crate::env::is_uhyve() {
137138
return;
138139
}

src/env.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use ahash::RandomState;
1010
use fdt::Fdt;
1111
use hashbrown::HashMap;
1212
use hashbrown::hash_map::Iter;
13-
use hermit_entry::boot_info::{BootInfo, PlatformInfo, RawBootInfo};
13+
use hermit_entry::boot_info::{BootInfo, RawBootInfo};
1414
use hermit_sync::OnceCell;
1515
use memory_addresses::PhysAddr;
1616

@@ -44,7 +44,10 @@ struct Cli {
4444
}
4545

4646
/// Whether Hermit is running under the "uhyve" hypervisor.
47+
#[cfg(feature = "uhyve")]
4748
pub fn is_uhyve() -> bool {
49+
use hermit_entry::boot_info::PlatformInfo;
50+
4851
matches!(boot_info().platform_info, PlatformInfo::Uhyve { .. })
4952
}
5053

0 commit comments

Comments
 (0)