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 <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
Dennis Kempin 2022-09-28 17:32:52 +00:00 committed by crosvm LUCI
parent eb52905d36
commit 4c211a4d41
9 changed files with 20 additions and 17 deletions

View file

@ -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"]

View file

@ -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 = []

View file

@ -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;

View file

@ -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::*;

View file

@ -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)?;

View file

@ -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<TouchDeviceOption>,
#[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<RunCommand> 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;
}

View file

@ -1328,7 +1328,7 @@ pub struct Config {
pub virtio_snds: Vec<SndParameters>,
pub virtio_switches: Vec<PathBuf>,
pub virtio_trackpad: Vec<TouchDeviceOption>,
#[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<VvuOption>,
pub wayland_socket_paths: BTreeMap<String, PathBuf>,
@ -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(),

View file

@ -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(

View file

@ -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<JailConfig>,