Skip to content

Commit a8d08c5

Browse files
committed
Enable tee only in x86-64
The `tee` feature has been used by having in mind only the x86-64 case. Currently, `tee` means sense only if `x86-64` is also enabled. In the future, the `tee` will enable code that is shared by arm and x86-64. Signed-off-by: Matias Ezequiel Vara Larsen <[email protected]>
1 parent b243670 commit a8d08c5

File tree

7 files changed

+53
-53
lines changed

7 files changed

+53
-53
lines changed

src/libkrun/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ fn main() {
55
println!("cargo:rustc-link-search=/opt/homebrew/lib");
66
#[cfg(all(not(feature = "tee"), not(feature = "efi")))]
77
println!("cargo:rustc-link-lib=krunfw");
8-
#[cfg(feature = "tee")]
8+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
99
println!("cargo:rustc-link-lib=krunfw-sev");
1010
}

src/libkrun/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use vmm::vmm_config::boot_source::{BootSourceConfig, DEFAULT_KERNEL_CMDLINE};
5151
use vmm::vmm_config::fs::FsDeviceConfig;
5252
#[cfg(not(feature = "efi"))]
5353
use vmm::vmm_config::kernel_bundle::KernelBundle;
54-
#[cfg(feature = "tee")]
54+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
5555
use vmm::vmm_config::kernel_bundle::{InitrdBundle, QbootBundle};
5656
use vmm::vmm_config::machine_config::VmConfig;
5757
#[cfg(feature = "net")]
@@ -103,7 +103,7 @@ struct ContextConfig {
103103
root_block_cfg: Option<BlockDeviceConfig>,
104104
#[cfg(feature = "blk")]
105105
data_block_cfg: Option<BlockDeviceConfig>,
106-
#[cfg(feature = "tee")]
106+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
107107
tee_config_file: Option<PathBuf>,
108108
unix_ipc_port_map: Option<HashMap<u32, (PathBuf, bool)>>,
109109
shutdown_efd: Option<EventFd>,
@@ -220,12 +220,12 @@ impl ContextConfig {
220220
}
221221
}
222222

223-
#[cfg(feature = "tee")]
223+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
224224
fn set_tee_config_file(&mut self, filepath: PathBuf) {
225225
self.tee_config_file = Some(filepath);
226226
}
227227

228-
#[cfg(feature = "tee")]
228+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
229229
fn get_tee_config_file(&self) -> Option<PathBuf> {
230230
self.tee_config_file.clone()
231231
}
@@ -263,7 +263,7 @@ extern "C" {
263263
fn krunfw_get_version() -> u32;
264264
}
265265

266-
#[cfg(feature = "tee")]
266+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
267267
#[link(name = "krunfw-sev")]
268268
extern "C" {
269269
fn krunfw_get_qboot(size: *mut size_t) -> *mut c_char;
@@ -320,7 +320,7 @@ pub extern "C" fn krun_create_ctx() -> i32 {
320320
};
321321
ctx_cfg.vmr.set_kernel_bundle(kernel_bundle).unwrap();
322322

323-
#[cfg(feature = "tee")]
323+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
324324
{
325325
let mut qboot_size: usize = 0;
326326
let qboot_host_addr = unsafe { krunfw_get_qboot(&mut qboot_size as *mut usize) };
@@ -919,7 +919,7 @@ pub unsafe extern "C" fn krun_set_env(ctx_id: u32, c_envp: *const *const c_char)
919919

920920
#[allow(clippy::missing_safety_doc)]
921921
#[no_mangle]
922-
#[cfg(feature = "tee")]
922+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
923923
pub unsafe extern "C" fn krun_set_tee_config_file(ctx_id: u32, c_filepath: *const c_char) -> i32 {
924924
let filepath = match CStr::from_ptr(c_filepath).to_str() {
925925
Ok(f) => f,
@@ -1152,7 +1152,7 @@ pub extern "C" fn krun_start_enter(ctx_id: u32) -> i32 {
11521152
* config is not set by this point, print the relevant error message and
11531153
* fail.
11541154
*/
1155-
#[cfg(feature = "tee")]
1155+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
11561156
if let Some(tee_config) = ctx_cfg.get_tee_config_file() {
11571157
if let Err(e) = ctx_cfg.vmr.set_tee_config(tee_config) {
11581158
error!("Error setting up TEE config: {:?}", e);

src/vmm/src/builder.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ use devices::virtio::{port_io, MmioTransport, PortDescription, Vsock};
3333
#[cfg(target_os = "macos")]
3434
use hvf::MemoryMapping;
3535

36-
#[cfg(feature = "tee")]
36+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
3737
use kbs_types::Tee;
3838

3939
use crate::device_manager;
40-
#[cfg(feature = "tee")]
40+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
4141
use crate::resources::TeeConfig;
4242
#[cfg(target_os = "linux")]
4343
use crate::signal_handler::register_sigint_handler;
@@ -55,12 +55,12 @@ use crate::vstate::KvmContext;
5555
use crate::vstate::MeasuredRegion;
5656
use crate::vstate::{Error as VstateError, Vcpu, VcpuConfig, Vm};
5757
use arch::ArchMemoryInfo;
58-
#[cfg(feature = "tee")]
58+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
5959
use arch::InitrdConfig;
6060
use device_manager::shm::ShmManager;
6161
#[cfg(not(feature = "tee"))]
6262
use devices::virtio::{fs::ExportTable, VirtioShmRegion};
63-
#[cfg(feature = "tee")]
63+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
6464
use kvm_bindings::KVM_MAX_CPUID_ENTRIES;
6565
use libc::{STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO};
6666
use nix::unistd::isatty;
@@ -342,7 +342,7 @@ enum Payload {
342342
Empty,
343343
#[cfg(feature = "efi")]
344344
Efi,
345-
#[cfg(feature = "tee")]
345+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
346346
Tee(MmapRegion, u64, usize, u64, usize, u64, usize),
347347
}
348348

@@ -370,17 +370,17 @@ pub fn build_microvm(
370370
.map_err(StartMicrovmError::KernelBundle)?
371371
};
372372

373-
#[cfg(feature = "tee")]
373+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
374374
let qboot_bundle = vm_resources
375375
.qboot_bundle()
376376
.ok_or(StartMicrovmError::MissingKernelConfig)?;
377377

378-
#[cfg(feature = "tee")]
378+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
379379
let initrd_bundle = vm_resources
380380
.initrd_bundle()
381381
.ok_or(StartMicrovmError::MissingKernelConfig)?;
382382

383-
#[cfg(feature = "tee")]
383+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
384384
let payload = Payload::Tee(
385385
kernel_region,
386386
kernel_bundle.guest_addr,
@@ -402,7 +402,7 @@ pub fn build_microvm(
402402
.vm_config()
403403
.mem_size_mib
404404
.ok_or(StartMicrovmError::MissingMemSizeConfig)?,
405-
#[cfg(feature = "tee")]
405+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
406406
None,
407407
#[cfg(not(feature = "tee"))]
408408
Some(vm_resources),
@@ -422,7 +422,7 @@ pub fn build_microvm(
422422
#[allow(unused_mut)]
423423
let mut vm = setup_vm(&guest_memory)?;
424424

425-
#[cfg(feature = "tee")]
425+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
426426
let (kvm, mut vm) = {
427427
let kvm = KvmContext::new()
428428
.map_err(Error::KvmContext)
@@ -431,10 +431,10 @@ pub fn build_microvm(
431431
(kvm, vm)
432432
};
433433

434-
#[cfg(feature = "tee")]
434+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
435435
let tee = vm_resources.tee_config().tee;
436436

437-
#[cfg(feature = "tee")]
437+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
438438
let sev_launcher = match tee {
439439
Tee::Sev => Some(
440440
vm.sev_secure_virt_prepare(&guest_memory)
@@ -443,7 +443,7 @@ pub fn build_microvm(
443443
_ => None,
444444
};
445445

446-
#[cfg(feature = "tee")]
446+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
447447
let snp_launcher = match tee {
448448
Tee::Snp => Some(
449449
vm.snp_secure_virt_prepare(&guest_memory)
@@ -452,7 +452,7 @@ pub fn build_microvm(
452452
_ => None,
453453
};
454454

455-
#[cfg(feature = "tee")]
455+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
456456
let measured_regions = {
457457
println!("Injecting and measuring memory regions. This may take a while.");
458458

@@ -543,7 +543,7 @@ pub fn build_microvm(
543543

544544
#[cfg(all(target_os = "linux", target_arch = "x86_64", not(feature = "tee")))]
545545
let boot_ip: GuestAddress = GuestAddress(kernel_bundle.entry_addr);
546-
#[cfg(feature = "tee")]
546+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
547547
let boot_ip: GuestAddress = GuestAddress(arch::RESET_VECTOR);
548548

549549
let vcpus;
@@ -712,7 +712,7 @@ pub fn build_microvm(
712712
#[cfg(all(target_arch = "x86_64", not(feature = "tee")))]
713713
load_cmdline(&vmm)?;
714714

715-
#[cfg(feature = "tee")]
715+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
716716
let initrd_config = Some(InitrdConfig {
717717
address: GuestAddress(arch::x86_64::layout::INITRD_SEV_START),
718718
size: initrd_bundle.size,
@@ -728,7 +728,7 @@ pub fn build_microvm(
728728
)
729729
.map_err(StartMicrovmError::Internal)?;
730730

731-
#[cfg(feature = "tee")]
731+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
732732
{
733733
match tee {
734734
Tee::Sev => vmm
@@ -794,7 +794,7 @@ fn load_payload(
794794
.map_err(StartMicrovmError::GuestMemoryMmap),
795795
#[cfg(test)]
796796
Payload::Empty => Ok(guest_mem),
797-
#[cfg(feature = "tee")]
797+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
798798
Payload::Tee(
799799
kernel_region,
800800
kernel_load_addr,
@@ -919,7 +919,7 @@ pub(crate) fn setup_vm(
919919
.map_err(StartMicrovmError::Internal)?;
920920
Ok(vm)
921921
}
922-
#[cfg(all(target_os = "linux", feature = "tee"))]
922+
#[cfg(all(target_os = "linux", feature = "tee", target_arch = "x86_64"))]
923923
pub(crate) fn setup_vm(
924924
kvm: &KvmContext,
925925
guest_memory: &GuestMemoryMmap,

src/vmm/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl Vmm {
269269
) -> Result<()> {
270270
#[cfg(target_arch = "x86_64")]
271271
{
272-
let cmdline_len = if cfg!(feature = "tee") {
272+
let cmdline_len = if cfg!(all(feature = "tee", target_arch = "x86_64")) {
273273
arch::x86_64::layout::CMDLINE_SEV_SIZE
274274
} else {
275275
self.kernel_cmdline.len() + 1

src/vmm/src/linux/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[cfg(feature = "tee")]
1+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
22
pub mod tee;
33

44
pub mod vstate;

src/vmm/src/linux/vstate.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ use super::tee::amdsev::{AmdSev, Error as SevError};
3434
#[cfg(feature = "amd-sev")]
3535
use super::tee::amdsnp::{AmdSnp, Error as SnpError};
3636

37-
#[cfg(feature = "tee")]
37+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
3838
use kbs_types::Tee;
3939

40-
#[cfg(feature = "tee")]
40+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
4141
use crate::resources::TeeConfig;
4242
use crate::vmm_config::machine_config::CpuFeaturesTemplate;
4343
#[cfg(target_arch = "aarch64")]
@@ -103,7 +103,7 @@ pub enum Error {
103103
#[cfg(target_arch = "x86_64")]
104104
/// Cannot set the local interruption due to bad configuration.
105105
LocalIntConfiguration(arch::x86_64::interrupts::Error),
106-
#[cfg(feature = "tee")]
106+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
107107
/// Missing TEE config
108108
MissingTeeConfig,
109109
#[cfg(target_arch = "x86_64")]
@@ -148,7 +148,7 @@ pub enum Error {
148148
#[cfg(feature = "amd-sev")]
149149
/// Error attesting the Secure VM (SNP).
150150
SnpSecVirtAttest(SnpError),
151-
#[cfg(feature = "tee")]
151+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
152152
/// The TEE specified is not supported.
153153
InvalidTee,
154154
/// Failed to signal Vcpu.
@@ -294,38 +294,38 @@ impl Display for Error {
294294
SetUserMemoryRegion2(e) => write!(f, "Cannot set the memory regions: {e}"),
295295
#[cfg(feature = "tee")]
296296
CreateGuestMemfd(e) => write!(f, "Cannot create guest memfd: {e}"),
297-
#[cfg(feature = "tee")]
297+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
298298
SevSecVirtInit(e) => {
299299
write!(
300300
f,
301301
"Error initializing the Secure Virtualization Backend (SEV): {e:?}"
302302
)
303303
}
304-
#[cfg(feature = "tee")]
304+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
305305
SevSecVirtPrepare(e) => write!(
306306
f,
307307
"Error preparing the VM for Secure Virtualization (SEV): {e:?}"
308308
),
309-
#[cfg(feature = "tee")]
309+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
310310
SevSecVirtAttest(e) => write!(f, "Error attesting the Secure VM (SEV): {e:?}"),
311311

312-
#[cfg(feature = "tee")]
312+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
313313
SnpSecVirtInit(e) => write!(
314314
f,
315315
"Error initializing the Secure Virtualization Backend (SEV): {e:?}"
316316
),
317317

318-
#[cfg(feature = "tee")]
318+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
319319
SnpSecVirtPrepare(e) => write!(
320320
f,
321321
"Error preparing the VM for Secure Virtualization (SNP): {e:?}"
322322
),
323323

324-
#[cfg(feature = "tee")]
324+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
325325
SnpSecVirtAttest(e) => write!(f, "Error attesting the Secure VM (SNP): {e:?}"),
326326

327327
SignalVcpu(e) => write!(f, "Failed to signal Vcpu: {e}"),
328-
#[cfg(feature = "tee")]
328+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
329329
MissingTeeConfig => write!(f, "Missing TEE configuration"),
330330
#[cfg(target_arch = "x86_64")]
331331
MSRSConfiguration(e) => write!(f, "Error configuring the MSR registers: {e:?}"),
@@ -409,7 +409,7 @@ impl Display for Error {
409409
#[cfg(target_arch = "aarch64")]
410410
VcpuArmInit(e) => write!(f, "Error doing Vcpu Init on Arm: {e}"),
411411

412-
#[cfg(feature = "tee")]
412+
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
413413
InvalidTee => write!(f, "TEE selected is not currently supported"),
414414
}
415415
}

0 commit comments

Comments
 (0)