From 4c211a4d41b9784e12bbae6d41b22de20a6dc4f4 Mon Sep 17 00:00:00 2001 From: Dennis Kempin Date: Wed, 28 Sep 2022 17:32:52 +0000 Subject: [PATCH] Extract vtpm out of the chromeos feature And enable it in upstream all-linux builds. The feature is enabled for chromeos by default, so should be a no-op for chromeos builds. We can probably simplify the cfg() attributes further by only enabling the feature for x86, so we do not need the extra check each time. But that'll require ebuild changes. BUG=b:244618505 TEST=presubmit TEST=cargo build --no-default-features --features=vtpm Change-Id: Ibb33c04ab5e6486969fefc6f3e57503be4eccdf3 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3924741 Commit-Queue: Dennis Kempin Reviewed-by: Daniel Verkamp --- Cargo.toml | 4 +++- devices/Cargo.toml | 1 + devices/src/lib.rs | 4 ++-- devices/src/virtio/mod.rs | 4 ++-- devices/src/vtpm_proxy.rs | 10 +++++----- src/crosvm/cmdline.rs | 4 ++-- src/crosvm/config.rs | 4 ++-- src/crosvm/sys/unix.rs | 2 +- src/crosvm/sys/unix/device_helpers.rs | 4 ++-- 9 files changed, 20 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cfd8f3ce3e..93edfdf048 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -122,6 +122,7 @@ all-linux = [ "power-monitor-powerd", "slirp", "tpm", + "vtpm", "virgl_renderer_next", "virgl_renderer", "wl-dmabuf", @@ -132,7 +133,7 @@ arc_quota = ["devices/arc_quota"] audio = ["devices/audio"] audio_cras = ["devices/audio_cras"] balloon = ["devices/balloon", "vm_control/balloon"] -chromeos = ["base/chromeos", "audio_cras", "devices/chromeos", "panic-memfd", "arc_quota"] +chromeos = ["base/chromeos", "audio_cras", "devices/chromeos", "panic-memfd", "arc_quota", "vtpm"] composite-disk = ["protos/composite-disk", "protobuf", "disk/composite-disk"] crash-report = ["broker_ipc/crash-report", "crash_report"] default = ["audio", "balloon", "gpu", "qcow", "usb"] @@ -174,6 +175,7 @@ video-decoder = ["devices/video-decoder"] video-encoder = ["devices/video-encoder"] virgl_renderer = ["devices/virgl_renderer"] virgl_renderer_next = ["devices/virgl_renderer_next", "rutabaga_gfx/virgl_renderer_next"] +vtpm = ["devices/vtpm"] wl-dmabuf = ["devices/minigbm"] x = ["devices/x"] diff --git a/devices/Cargo.toml b/devices/Cargo.toml index a2a2ce88d1..9f9d37eaec 100644 --- a/devices/Cargo.toml +++ b/devices/Cargo.toml @@ -21,6 +21,7 @@ minigbm = ["rutabaga_gfx/minigbm"] x = ["gpu_display/x", "rutabaga_gfx/x"] virgl_renderer = ["gpu", "rutabaga_gfx/virgl_renderer"] virgl_renderer_next = ["gpu", "rutabaga_gfx/virgl_renderer_next"] +vtpm = ["system_api", "protobuf", "dbus"] gfxstream = ["gpu", "rutabaga_gfx/gfxstream"] slirp = [] stats = [] diff --git a/devices/src/lib.rs b/devices/src/lib.rs index f74872f48d..3e6719feab 100644 --- a/devices/src/lib.rs +++ b/devices/src/lib.rs @@ -32,7 +32,7 @@ pub mod serial_device; mod software_tpm; mod sys; pub mod virtio; -#[cfg(all(feature = "tpm", feature = "chromeos", target_arch = "x86_64"))] +#[cfg(all(feature = "vtpm", target_arch = "x86_64"))] mod vtpm_proxy; cfg_if::cfg_if! { @@ -103,7 +103,7 @@ pub use self::serial_device::SerialType; pub use self::software_tpm::SoftwareTpm; pub use self::virtio::VirtioMmioDevice; pub use self::virtio::VirtioPciDevice; -#[cfg(all(feature = "tpm", feature = "chromeos", target_arch = "x86_64"))] +#[cfg(all(feature = "vtpm", target_arch = "x86_64"))] pub use self::vtpm_proxy::VtpmProxy; mod pflash; diff --git a/devices/src/virtio/mod.rs b/devices/src/virtio/mod.rs index 12cade6a48..da9dd16f6b 100644 --- a/devices/src/virtio/mod.rs +++ b/devices/src/virtio/mod.rs @@ -17,7 +17,7 @@ mod queue; mod rng; #[cfg(unix)] mod sys; -#[cfg(feature = "tpm")] +#[cfg(any(feature = "tpm", feature = "vtpm"))] mod tpm; #[cfg(any(feature = "video-decoder", feature = "video-encoder"))] mod video; @@ -44,7 +44,7 @@ pub use self::interrupt::*; pub use self::iommu::*; pub use self::queue::*; pub use self::rng::*; -#[cfg(feature = "tpm")] +#[cfg(any(feature = "tpm", feature = "vtpm"))] pub use self::tpm::*; #[cfg(any(feature = "video-decoder", feature = "video-encoder"))] pub use self::video::*; diff --git a/devices/src/vtpm_proxy.rs b/devices/src/vtpm_proxy.rs index ab61276309..c79443ac7b 100644 --- a/devices/src/vtpm_proxy.rs +++ b/devices/src/vtpm_proxy.rs @@ -48,11 +48,11 @@ impl VtpmProxy { } } - fn get_or_create_dbus_connection<'a>( - &'a mut self, - ) -> anyhow::Result<&'a dbus::blocking::Connection, dbus::Error> { + fn get_or_create_dbus_connection( + &mut self, + ) -> anyhow::Result<&dbus::blocking::Connection, dbus::Error> { return match self.dbus_connection { - Some(ref dbus_connection) => Ok(&dbus_connection), + Some(ref dbus_connection) => Ok(dbus_connection), None => { let dbus_connection = dbus::blocking::Connection::new_system()?; self.dbus_connection = Some(dbus_connection); @@ -61,7 +61,7 @@ impl VtpmProxy { }; } - fn try_execute_command<'a>(&'a mut self, command: &[u8]) -> anyhow::Result<(), Error> { + fn try_execute_command(&mut self, command: &[u8]) -> anyhow::Result<(), Error> { let dbus_connection = self .get_or_create_dbus_connection() .map_err(Error::DBusError)?; diff --git a/src/crosvm/cmdline.rs b/src/crosvm/cmdline.rs index 0ab35a77fe..6a5ad10a89 100644 --- a/src/crosvm/cmdline.rs +++ b/src/crosvm/cmdline.rs @@ -1280,7 +1280,7 @@ pub struct RunCommand { #[argh(option, long = "trackpad", arg_name = "PATH:WIDTH:HEIGHT")] /// path to a socket from where to read trackpad input events and write status updates to, optionally followed by screen width and height (defaults to 800x1280) pub virtio_trackpad: Vec, - #[cfg(all(feature = "tpm", feature = "chromeos", target_arch = "x86_64"))] + #[cfg(all(feature = "vtpm", target_arch = "x86_64"))] #[argh(switch)] /// enable the virtio-tpm connection to vtpm daemon pub vtpm_proxy: bool, @@ -1610,7 +1610,7 @@ impl TryFrom for super::config::Config { cfg.software_tpm = cmd.software_tpm; } - #[cfg(all(feature = "tpm", feature = "chromeos", target_arch = "x86_64"))] + #[cfg(all(feature = "vtpm", target_arch = "x86_64"))] { cfg.vtpm_proxy = cmd.vtpm_proxy; } diff --git a/src/crosvm/config.rs b/src/crosvm/config.rs index 35b0c7d6e2..c4af65773b 100644 --- a/src/crosvm/config.rs +++ b/src/crosvm/config.rs @@ -1328,7 +1328,7 @@ pub struct Config { pub virtio_snds: Vec, pub virtio_switches: Vec, pub virtio_trackpad: Vec, - #[cfg(all(feature = "tpm", feature = "chromeos", target_arch = "x86_64"))] + #[cfg(all(feature = "vtpm", target_arch = "x86_64"))] pub vtpm_proxy: bool, pub vvu_proxy: Vec, pub wayland_socket_paths: BTreeMap, @@ -1527,7 +1527,7 @@ impl Default for Config { virtio_snds: Vec::new(), virtio_switches: Vec::new(), virtio_trackpad: Vec::new(), - #[cfg(all(feature = "tpm", feature = "chromeos", target_arch = "x86_64"))] + #[cfg(all(feature = "vtpm", target_arch = "x86_64"))] vtpm_proxy: false, vvu_proxy: Vec::new(), wayland_socket_paths: BTreeMap::new(), diff --git a/src/crosvm/sys/unix.rs b/src/crosvm/sys/unix.rs index 4f2ea07599..af0f1f106e 100644 --- a/src/crosvm/sys/unix.rs +++ b/src/crosvm/sys/unix.rs @@ -376,7 +376,7 @@ fn create_virtio_devices( } } - #[cfg(all(feature = "tpm", feature = "chromeos", target_arch = "x86_64"))] + #[cfg(all(feature = "vtpm", target_arch = "x86_64"))] { if cfg.vtpm_proxy { devs.push(create_vtpm_proxy_device( diff --git a/src/crosvm/sys/unix/device_helpers.rs b/src/crosvm/sys/unix/device_helpers.rs index e24f92187b..e2f6959aeb 100644 --- a/src/crosvm/sys/unix/device_helpers.rs +++ b/src/crosvm/sys/unix/device_helpers.rs @@ -63,7 +63,7 @@ use devices::SoftwareTpm; use devices::VfioDevice; use devices::VfioPciDevice; use devices::VfioPlatformDevice; -#[cfg(all(feature = "tpm", feature = "chromeos", target_arch = "x86_64"))] +#[cfg(all(feature = "vtpm", target_arch = "x86_64"))] use devices::VtpmProxy; use hypervisor::ProtectionType; use hypervisor::Vm; @@ -551,7 +551,7 @@ pub fn create_software_tpm_device( }) } -#[cfg(all(feature = "tpm", feature = "chromeos", target_arch = "x86_64"))] +#[cfg(all(feature = "vtpm", target_arch = "x86_64"))] pub fn create_vtpm_proxy_device( protection_type: ProtectionType, jail_config: &Option,