From fa539725eb7e7e85fbb4f51d2d4a57530afe8326 Mon Sep 17 00:00:00 2001 From: Vikram Auradkar Date: Thu, 14 Dec 2023 13:53:54 -0800 Subject: [PATCH] tools: add simple windows example script Makes gpu argument optional BUG=b:316406247 TEST=ran the script on windows Change-Id: I08e7961f2477ee56ad162420a99c469e3f4c7b1b Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5124591 Reviewed-by: Noah Gold Commit-Queue: Vikram Auradkar Auto-Submit: Vikram Auradkar --- src/crosvm/sys/windows/broker.rs | 59 +++++++++++++++++-------------- src/sys/windows.rs | 1 + src/sys/windows/generic.rs | 5 +++ tools/examples/example_simple.ps1 | 49 +++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 26 deletions(-) create mode 100644 tools/examples/example_simple.ps1 diff --git a/src/crosvm/sys/windows/broker.rs b/src/crosvm/sys/windows/broker.rs index 8a93be8b51..72fac2adf5 100644 --- a/src/crosvm/sys/windows/broker.rs +++ b/src/crosvm/sys/windows/broker.rs @@ -701,31 +701,35 @@ fn run_internal(mut cfg: Config, log_args: LogArgs) -> Result<()> { )?; #[cfg(feature = "gpu")] - let _gpu_child = if !cfg - .vhost_user - .iter() - .any(|opt| opt.type_ == DeviceType::Gpu) - { - // Pass both backend and frontend configs to main process. - cfg.gpu_backend_config = Some(gpu_cfg.0); - cfg.gpu_vmm_config = Some(gpu_cfg.1); - None + let _gpu_child = if let Some(gpu_cfg) = gpu_cfg { + if !cfg + .vhost_user + .iter() + .any(|opt| opt.type_ == DeviceType::Gpu) + { + // Pass both backend and frontend configs to main process. + cfg.gpu_backend_config = Some(gpu_cfg.0); + cfg.gpu_vmm_config = Some(gpu_cfg.1); + None + } else { + Some(start_up_gpu( + &mut cfg, + &log_args, + gpu_cfg, + &mut input_event_split_config, + &mut main_child, + &mut children, + &mut wait_ctx, + &mut metric_tubes, + window_procedure_thread_builder + .take() + .ok_or_else(|| anyhow!("window_procedure_thread_builder is missing."))?, + #[cfg(feature = "process-invariants")] + &process_invariants, + )?) + } } else { - Some(start_up_gpu( - &mut cfg, - &log_args, - gpu_cfg, - &mut input_event_split_config, - &mut main_child, - &mut children, - &mut wait_ctx, - &mut metric_tubes, - window_procedure_thread_builder - .take() - .ok_or_else(|| anyhow!("window_procedure_thread_builder is missing."))?, - #[cfg(feature = "process-invariants")] - &process_invariants, - )?) + None }; #[cfg(feature = "gpu")] @@ -1740,7 +1744,10 @@ fn platform_create_gpu( exit_evt_wrtube: SendTube, gpu_control_host_tube: Tube, gpu_control_device_tube: Tube, -) -> Result<(GpuBackendConfig, GpuVmmConfig)> { +) -> Result> { + if cfg.gpu_parameters.is_none() { + return Ok(None); + } let exit_event = Event::new().exit_context(Exit::CreateEvent, "failed to create exit event")?; exit_events.push( exit_event @@ -1770,7 +1777,7 @@ fn platform_create_gpu( product_config: vmm_config_product, }; - Ok((backend_config, vmm_config)) + Ok(Some((backend_config, vmm_config))) } #[cfg(feature = "gpu")] diff --git a/src/sys/windows.rs b/src/sys/windows.rs index 65b6ea3437..426e64b3fe 100644 --- a/src/sys/windows.rs +++ b/src/sys/windows.rs @@ -2252,6 +2252,7 @@ pub fn run_config_for_broker(raw_tube_transporter: RawDescriptor) -> Result() .exit_context(Exit::TubeFailure, "failed to read bootstrap tube")?, ); + #[cfg(feature = "crash-report")] let crash_tube_map = bootstrap_tube .recv::>>() .exit_context(Exit::TubeFailure, "failed to read bootstrap tube")?; diff --git a/src/sys/windows/generic.rs b/src/sys/windows/generic.rs index 7979e2929f..17b1ff66f9 100644 --- a/src/sys/windows/generic.rs +++ b/src/sys/windows/generic.rs @@ -3,13 +3,16 @@ // found in the LICENSE file. use std::collections::BTreeMap; +use std::thread; use std::thread::JoinHandle; +use std::time::Duration; use anyhow::Result; use arch::RunnableLinuxVm; use arch::VcpuArch; use arch::VirtioDeviceStub; use arch::VmArch; +use base::info; use base::AsRawDescriptor; use base::CloseNotifier; use base::Event; @@ -296,6 +299,8 @@ pub(super) fn virtio_sound_enabled() -> bool { } pub(crate) fn run_metrics(_args: RunMetricsCommand) -> Result<()> { + info!("sleep forever. We will get killed by broker"); + thread::sleep(Duration::MAX); Ok(()) } diff --git a/tools/examples/example_simple.ps1 b/tools/examples/example_simple.ps1 new file mode 100644 index 0000000000..29d13188b6 --- /dev/null +++ b/tools/examples/example_simple.ps1 @@ -0,0 +1,49 @@ +<# +.Description +Runs an ubuntu image. The image itself needs to be built on linux as per instructions at +https://crosvm.dev/book/running_crosvm/example_usage.html#preparing-the-guest-os-image + +The console is a pipe at \\.\pipe\crosvm-debug that you can connect to using apps like +putty. +.PARAMETER IMAGE_DIR +Directory where initrd, rootfs and vmlinuz are located. Defaults to user's tmp directory. +.PARAMETER LOGS_DIR +Directory where logs will be written to. Defaults to user's tmp directory. +#> +param ( + [Parameter( + Position = 0 + )] + [string]$IMAGE_DIR = $Env:TEMP, ## + [Parameter( + Position = 1 + )] + [string]$LOGS_DIR = $Env:TEMP ## +) + +$VMLINUZ = Join-Path $IMAGE_DIR "vmlinuz" +$ROOTFS = Join-Path $IMAGE_DIR "rootfs" +$INITRD = Join-Path $IMAGE_DIR "initrd" +$SERIAL = "\\.\pipe\crosvm-debug" +$LOGS_DIR = Join-Path $LOGS_DIR "\" + +$PATHS = $IMAGE_DIR, $VMLINUZ, $ROOTFS, $INITRD, $LOGS_DIR + +foreach ($path in $PATHS) { + if (!(Test-Path $path)) { + throw (New-Object System.IO.FileNotFoundException("Path not found: $path", $path)) + } +} + +cargo run --features "all-msvc64,whpx" -- ` + --log-level INFO ` + run-mp ` + --logs-directory $LOGS_DIR ` + --cpus 1 ` + --mem 4096 ` + --serial "hardware=serial,type=namedpipe,path=$SERIAL,num=1,console=true" ` + --params "nopat clocksource=jiffies root=/dev/vda5 loglevel=7 console=/dev/ttyS1 console=/dev/ttyS0" ` + --host-guid "dontcare" ` + --rwdisk $ROOTFS ` + --initrd $INITRD ` + $VMLINUZ