From 7ec58fafbace41df54b439f9239edc9e9e12d3b7 Mon Sep 17 00:00:00 2001 From: Gurchetan Singh Date: Wed, 15 May 2019 15:30:38 -0700 Subject: virtio-gpu: add gpu control socket The GPU process will need access to KVM. BUG=chromium:924405 TEST=compile Change-Id: I9e454d79a36a40a20c6c4b3a62ea367f339e526b Reviewed-on: https://chromium-review.googlesource.com/1626793 Commit-Ready: Gurchetan Singh Tested-by: Gurchetan Singh Tested-by: kokoro Legacy-Commit-Queue: Commit Bot Reviewed-by: David Riley --- devices/src/virtio/gpu/backend.rs | 11 +++- devices/src/virtio/gpu/mod.rs | 132 ++++++++++++++++++++++---------------- 2 files changed, 85 insertions(+), 58 deletions(-) (limited to 'devices/src') diff --git a/devices/src/virtio/gpu/backend.rs b/devices/src/virtio/gpu/backend.rs index cda00ce..e53adb3 100644 --- a/devices/src/virtio/gpu/backend.rs +++ b/devices/src/virtio/gpu/backend.rs @@ -27,6 +27,7 @@ use super::protocol::{ GpuResponse, GpuResponsePlaneInfo, VIRTIO_GPU_CAPSET_VIRGL, VIRTIO_GPU_CAPSET_VIRGL2, }; use crate::virtio::resource_bridge::*; +use vm_control::VmMemoryControlRequestSocket; const DEFAULT_WIDTH: u32 = 1280; const DEFAULT_HEIGHT: u32 = 1024; @@ -314,6 +315,8 @@ pub struct Backend { renderer: Renderer, resources: Map>, contexts: Map, + #[allow(dead_code)] + gpu_device_socket: VmMemoryControlRequestSocket, scanout_surface: Option, cursor_surface: Option, scanout_resource: u32, @@ -324,11 +327,17 @@ impl Backend { /// Creates a new backend for virtio-gpu that realizes all commands using the given `device` for /// allocating buffers, `display` for showing the results, and `renderer` for submitting /// rendering commands. - pub fn new(device: Device, display: GpuDisplay, renderer: Renderer) -> Backend { + pub fn new( + device: Device, + display: GpuDisplay, + renderer: Renderer, + gpu_device_socket: VmMemoryControlRequestSocket, + ) -> Backend { Backend { display: Rc::new(RefCell::new(display)), device, renderer, + gpu_device_socket, resources: Default::default(), contexts: Default::default(), scanout_surface: None, diff --git a/devices/src/virtio/gpu/mod.rs b/devices/src/virtio/gpu/mod.rs index e8fb49f..cc42ace 100644 --- a/devices/src/virtio/gpu/mod.rs +++ b/devices/src/virtio/gpu/mod.rs @@ -36,6 +36,8 @@ use self::backend::Backend; use self::protocol::*; use crate::pci::{PciBarConfiguration, PciBarPrefetchable, PciBarRegionType}; +use vm_control::VmMemoryControlRequestSocket; + // First queue is for virtio gpu commands. Second queue is for cursor commands, which we expect // there to be fewer of. const QUEUE_SIZES: &[u16] = &[256, 16]; @@ -601,6 +603,7 @@ impl Worker { pub struct Gpu { config_event: bool, exit_evt: EventFd, + gpu_device_socket: Option, resource_bridge: Option, kill_evt: Option, wayland_socket_path: PathBuf, @@ -609,12 +612,14 @@ pub struct Gpu { impl Gpu { pub fn new>( exit_evt: EventFd, + gpu_device_socket: Option, resource_bridge: Option, wayland_socket_path: P, ) -> Gpu { Gpu { config_event: false, exit_evt, + gpu_device_socket, resource_bridge, kill_evt: None, wayland_socket_path: wayland_socket_path.as_ref().to_path_buf(), @@ -653,6 +658,11 @@ impl VirtioDevice for Gpu { keep_fds.push(libc::STDOUT_FILENO); keep_fds.push(libc::STDERR_FILENO); } + + if let Some(ref gpu_device_socket) = self.gpu_device_socket { + keep_fds.push(gpu_device_socket.as_raw_fd()); + } + keep_fds.push(self.exit_evt.as_raw_fd()); if let Some(resource_bridge) = &self.resource_bridge { keep_fds.push(resource_bridge.as_raw_fd()); @@ -736,70 +746,78 @@ impl VirtioDevice for Gpu { let cursor_queue = queues.remove(0); let cursor_evt = queue_evts.remove(0); let socket_path = self.wayland_socket_path.clone(); - let worker_result = - thread::Builder::new() - .name("virtio_gpu".to_string()) - .spawn(move || { - const UNDESIRED_CARDS: &[&str] = &["vgem", "pvr"]; - let drm_card = match gpu_buffer::rendernode::open_device(UNDESIRED_CARDS) { - Ok(f) => f, - Err(()) => { - error!("failed to open card"); - return; - } - }; + if let Some(gpu_device_socket) = self.gpu_device_socket.take() { + let worker_result = + thread::Builder::new() + .name("virtio_gpu".to_string()) + .spawn(move || { + const UNDESIRED_CARDS: &[&str] = &["vgem", "pvr"]; + let drm_card = match gpu_buffer::rendernode::open_device(UNDESIRED_CARDS) { + Ok(f) => f, + Err(()) => { + error!("failed to open card"); + return; + } + }; - let device = match Device::new(drm_card) { - Ok(d) => d, - Err(()) => { - error!("failed to open device"); - return; - } - }; + let device = match Device::new(drm_card) { + Ok(d) => d, + Err(()) => { + error!("failed to open device"); + return; + } + }; - let display = match GpuDisplay::new(socket_path) { - Ok(c) => c, - Err(e) => { - error!("failed to open display: {}", e); - return; - } - }; + let display = match GpuDisplay::new(socket_path) { + Ok(c) => c, + Err(e) => { + error!("failed to open display: {}", e); + return; + } + }; - if cfg!(debug_assertions) { - let ret = unsafe { libc::dup2(libc::STDOUT_FILENO, libc::STDERR_FILENO) }; - if ret == -1 { - warn!("unable to dup2 stdout to stderr: {}", Error::last()); + if cfg!(debug_assertions) { + let ret = + unsafe { libc::dup2(libc::STDOUT_FILENO, libc::STDERR_FILENO) }; + if ret == -1 { + warn!("unable to dup2 stdout to stderr: {}", Error::last()); + } } - } - let renderer = match Renderer::init() { - Ok(r) => r, - Err(e) => { - error!("failed to initialize gpu renderer: {}", e); - return; + let renderer = match Renderer::init() { + Ok(r) => r, + Err(e) => { + error!("failed to initialize gpu renderer: {}", e); + return; + } + }; + + Worker { + exit_evt, + mem, + interrupt_evt, + interrupt_resample_evt, + interrupt_status, + ctrl_queue, + ctrl_evt, + cursor_queue, + cursor_evt, + resource_bridge, + kill_evt, + state: Frontend::new(Backend::new( + device, + display, + renderer, + gpu_device_socket, + )), } - }; - - Worker { - exit_evt, - mem, - interrupt_evt, - interrupt_resample_evt, - interrupt_status, - ctrl_queue, - ctrl_evt, - cursor_queue, - cursor_evt, - resource_bridge, - kill_evt, - state: Frontend::new(Backend::new(device, display, renderer)), - } - .run() - }); + .run() + }); - if let Err(e) = worker_result { - error!("failed to spawn virtio_gpu worker: {}", e); - return; + if let Err(e) = worker_result { + error!("failed to spawn virtio_gpu worker: {}", e); + return; + } } } -- cgit 1.4.1