Skip to content

Commit 4dc66f9

Browse files
committed
intermediate commit
Signed-off-by: Jake Correnti <[email protected]>
1 parent 8ce1544 commit 4dc66f9

File tree

12 files changed

+437
-14
lines changed

12 files changed

+437
-14
lines changed

build_libkrun.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
make clean && make TDX=1 && sudo make TDX=1 install

examples/Makefile

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ ifeq ($(SEV),1)
1717
EXAMPLES := launch-tee
1818
endif
1919
ifeq ($(TDX),1)
20-
EXAMPLES := launch-tee
20+
# EXAMPLES := launch-tee
21+
EXAMPLES := chroot_vm
2122
endif
2223
ifeq ($(EFI),1)
2324
EXAMPLES := boot_efi
@@ -26,7 +27,8 @@ endif
2627
all: $(EXAMPLES)
2728

2829
chroot_vm: chroot_vm.c
29-
gcc -o $@ $< $(CFLAGS) $(LDFLAGS_$(ARCH)_$(OS))
30+
# gcc -o $@ $< $(CFLAGS) $(LDFLAGS_$(ARCH)_$(OS))
31+
gcc -o $@ $< $(CFLAGS) $(LDFLAGS_tdx)
3032
ifeq ($(OS),Darwin)
3133
codesign --entitlements chroot_vm.entitlements --force -s - $@
3234
endif

examples/chroot_vm.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,18 @@ int main(int argc, char *const argv[])
234234
}
235235

236236
// Configure the number of vCPUs (1) and the amount of RAM (512 MiB).
237-
if (err = krun_set_vm_config(ctx_id, 4, 4096)) {
237+
if (err = krun_set_vm_config(ctx_id, 1, 4096)) {
238238
errno = -err;
239239
perror("Error configuring the number of vCPUs and/or the amount of RAM");
240240
return -1;
241241
}
242242

243+
if (err = krun_set_tee_config_file(ctx_id, "/home/jcorrent/slp-libkrun/examples/tdx-config-noattest.json")) {
244+
errno = -err;
245+
perror("Error setting the TEE config file");
246+
return -1;
247+
}
248+
243249
// Raise RLIMIT_NOFILE to the maximum allowed to create some room for virtio-fs
244250
getrlimit(RLIMIT_NOFILE, &rlim);
245251
rlim.rlim_cur = rlim.rlim_max;

examples/launch-tee

-23.2 KB
Binary file not shown.

examples/output.txt

+372
Large diffs are not rendered by default.

examples/run_tdx_example.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
make clean && make TDX=1 && sudo LD_LIBRARY_PATH=/usr/local/lib64 ./chroot_vm ./rootfs_fedora /bin/sh

init/init.c

+1
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ int setup_redirects()
810810

811811
int main(int argc, char **argv)
812812
{
813+
printf("HELLO FROM THE INIT BINARY\n");
813814
struct ifreq ifr;
814815
int sockfd;
815816
char localhost[] = "localhost\0";

src/libkrun/src/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use vmm::resources::VmResources;
3535
#[cfg(feature = "blk")]
3636
use vmm::vmm_config::block::BlockDeviceConfig;
3737
use vmm::vmm_config::boot_source::{BootSourceConfig, DEFAULT_KERNEL_CMDLINE};
38-
#[cfg(not(feature = "tee"))]
38+
// #[cfg(not(feature = "tee"))]
3939
use vmm::vmm_config::fs::FsDeviceConfig;
4040
#[cfg(not(feature = "efi"))]
4141
use vmm::vmm_config::kernel_bundle::KernelBundle;
@@ -408,7 +408,7 @@ pub extern "C" fn krun_set_vm_config(ctx_id: u32, num_vcpus: u8, ram_mib: u32) -
408408

409409
#[allow(clippy::missing_safety_doc)]
410410
#[no_mangle]
411-
#[cfg(not(feature = "tee"))]
411+
// #[cfg(not(feature = "tee"))]
412412
pub unsafe extern "C" fn krun_set_root(ctx_id: u32, c_root_path: *const c_char) -> i32 {
413413
let root_path = match CStr::from_ptr(c_root_path).to_str() {
414414
Ok(root) => root,
@@ -1109,6 +1109,8 @@ pub extern "C" fn krun_start_enter(ctx_id: u32) -> i32 {
11091109
kernel_cmdline_epilog: Some(format!(" -- {}", ctx_cfg.get_args())),
11101110
};
11111111

1112+
println!("boot_source: {:?}", boot_source);
1113+
11121114
if ctx_cfg.vmr.set_boot_source(boot_source).is_err() {
11131115
return -libc::EINVAL;
11141116
}

src/vmm/src/builder.rs

+38
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ pub fn build_microvm(
643643
)?;
644644
}
645645

646+
println!("kernel cmdline before adding to vmm: {:?}", kernel_cmdline);
646647
let mut vmm = Vmm {
647648
guest_memory,
648649
guest_memfd_regions,
@@ -713,6 +714,7 @@ pub fn build_microvm(
713714
}
714715

715716
if let Some(s) = &vm_resources.boot_config.kernel_cmdline_epilog {
717+
println!("EPILOG STRING: {:?}", s);
716718
vmm.kernel_cmdline.insert_str(s).unwrap();
717719
};
718720

@@ -789,6 +791,7 @@ pub fn build_microvm(
789791
println!("Starting TEE/microVM.");
790792
}
791793

794+
println!("kernel cmdline before starting vcpus: {:?}", vmm.kernel_cmdline);
792795
vmm.start_vcpus(vcpus)
793796
.map_err(StartMicrovmError::Internal)?;
794797

@@ -1176,6 +1179,41 @@ fn create_vcpus_x86_64(
11761179
if entry.index == 0x1 {
11771180
entry.ecx &= 1 << 21;
11781181
}
1182+
1183+
if entry.function == 0xD && entry.index == 0 {
1184+
const XFEATURE_MASK_XTILE: u32 = (1 << 17) | (1 << 18);
1185+
if (entry.eax & XFEATURE_MASK_XTILE) != XFEATURE_MASK_XTILE {
1186+
entry.eax &= !XFEATURE_MASK_XTILE;
1187+
}
1188+
}
1189+
1190+
if entry.function == 0xD && entry.index == 1 {
1191+
entry.ecx &= !(1 << 15);
1192+
const XFEATURE_MASK_CET: u32 = (1 << 11) | (1 << 12);
1193+
if entry.ecx & XFEATURE_MASK_CET > 0 {
1194+
entry.ecx |= XFEATURE_MASK_CET;
1195+
}
1196+
}
1197+
1198+
if entry.function == 0x4000_0001 {
1199+
// KVM feature bits
1200+
const KVM_FEATURE_CLOCKSOURCE_BIT: u8 = 0;
1201+
const KVM_FEATURE_CLOCKSOURCE2_BIT: u8 = 3;
1202+
const KVM_FEATURE_CLOCKSOURCE_STABLE_BIT: u8 = 24;
1203+
const KVM_FEATURE_ASYNC_PF_BIT: u8 = 4;
1204+
const KVM_FEATURE_ASYNC_PF_VMEXIT_BIT: u8 = 10;
1205+
const KVM_FEATURE_STEAL_TIME_BIT: u8 = 5;
1206+
const KVM_FEATURE_PV_EOI: u8 = 6;
1207+
1208+
// These features are not supported by TDX
1209+
entry.eax &= !(1 << KVM_FEATURE_CLOCKSOURCE_BIT
1210+
| 1 << KVM_FEATURE_CLOCKSOURCE2_BIT
1211+
| 1 << KVM_FEATURE_CLOCKSOURCE_STABLE_BIT
1212+
| 1 << KVM_FEATURE_ASYNC_PF_BIT
1213+
| 1 << KVM_FEATURE_ASYNC_PF_VMEXIT_BIT
1214+
| 1 << KVM_FEATURE_PV_EOI
1215+
| 1 << KVM_FEATURE_STEAL_TIME_BIT);
1216+
}
11791217
}
11801218

11811219
#[cfg(feature = "intel-tdx")]

src/vmm/src/linux/tee/inteltdx.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub enum Error {
2424
}
2525

2626
pub struct IntelTdx {
27-
caps: TdxCapabilities,
27+
// caps: TdxCapabilities,
2828
vm: TdxVm,
2929
tdvf_sections: Vec<TdvfSection>,
3030
tdvf_file: File,
@@ -34,9 +34,9 @@ impl IntelTdx {
3434
pub fn new(vm_fd: &VmFd) -> Result<Self, Error> {
3535
// FIXME(jakecorrenti): need to specify the max number of VCPUs here and not just assume 100. This should come from the VmResources that we set when doing krun_set_vm_config()
3636
let vm = TdxVm::new(vm_fd, 1).or_else(|_| return Err(Error::CreateTdxVmStruct))?;
37-
let caps = vm
38-
.get_capabilities(vm_fd)
39-
.or_else(|_| return Err(Error::GetCapabilities))?;
37+
// let caps = vm
38+
// .get_capabilities(vm_fd)
39+
// .or_else(|_| return Err(Error::GetCapabilities))?;
4040

4141
// let mut firmware = std::fs::File::open("/home/jcorrent/edk2/Build/IntelTdx/RELEASE_GCC5/FV/OVMF.fd")
4242
let mut firmware = std::fs::File::open("/home/slp/OVMF.fd")
@@ -45,7 +45,7 @@ impl IntelTdx {
4545
tdx::tdvf::parse_sections(&mut firmware).map_err(Error::ParseTdvfSections)?;
4646

4747
Ok(IntelTdx {
48-
caps,
48+
// caps,
4949
vm,
5050
tdvf_sections,
5151
tdvf_file: firmware,

src/vmm/src/resources.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use kbs_types::Tee;
1818
#[cfg(feature = "blk")]
1919
use crate::vmm_config::block::{BlockBuilder, BlockConfigError, BlockDeviceConfig};
2020
use crate::vmm_config::boot_source::{BootSourceConfig, BootSourceConfigError};
21-
#[cfg(not(feature = "tee"))]
21+
// #[cfg(not(feature = "tee"))]
2222
use crate::vmm_config::fs::*;
2323
#[cfg(feature = "tee")]
2424
use crate::vmm_config::kernel_bundle::{InitrdBundle, QbootBundle, QbootBundleError};
@@ -92,7 +92,7 @@ pub struct VmResources {
9292
#[cfg(feature = "tee")]
9393
pub initrd_bundle: Option<InitrdBundle>,
9494
/// The fs device.
95-
#[cfg(not(feature = "tee"))]
95+
// #[cfg(not(feature = "tee"))]
9696
pub fs: Vec<FsDeviceConfig>,
9797
/// The vsock device.
9898
pub vsock: VsockBuilder,
@@ -233,7 +233,7 @@ impl VmResources {
233233
Ok(())
234234
}
235235

236-
#[cfg(not(feature = "tee"))]
236+
// #[cfg(not(feature = "tee"))]
237237
pub fn add_fs_device(&mut self, config: FsDeviceConfig) {
238238
self.fs.push(config)
239239
}

src/vmm/src/vmm_config/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub mod block;
99
pub mod boot_source;
1010

1111
/// Wrapper for configuring the Fs devices attached to the microVM.
12-
#[cfg(not(feature = "tee"))]
12+
// #[cfg(not(feature = "tee"))]
1313
pub mod fs;
1414

1515
/// Wrapper over the microVM general information attached to the microVM.

0 commit comments

Comments
 (0)