summary refs log tree commit diff
path: root/devices/src/virtio/gpu
diff options
context:
space:
mode:
authorZach Reizner <zachr@google.com>2018-10-03 10:22:32 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-10-09 21:14:05 -0700
commit55a9e504beef368bd97e51ffd5a7fa6c034eb8ad (patch)
tree894d8685e2fdfa105ea35d1cb6cfceee06502c7a /devices/src/virtio/gpu
parent046df60760f3b0691f23c27a7f24a96c9afe8c05 (diff)
downloadcrosvm-55a9e504beef368bd97e51ffd5a7fa6c034eb8ad.tar
crosvm-55a9e504beef368bd97e51ffd5a7fa6c034eb8ad.tar.gz
crosvm-55a9e504beef368bd97e51ffd5a7fa6c034eb8ad.tar.bz2
crosvm-55a9e504beef368bd97e51ffd5a7fa6c034eb8ad.tar.lz
crosvm-55a9e504beef368bd97e51ffd5a7fa6c034eb8ad.tar.xz
crosvm-55a9e504beef368bd97e51ffd5a7fa6c034eb8ad.tar.zst
crosvm-55a9e504beef368bd97e51ffd5a7fa6c034eb8ad.zip
cargo fmt all source code
Now that cargo fmt has landed, run it over everything at once to bring
rust source to the standard formatting.

TEST=cargo test
BUG=None

Change-Id: Ic95a48725e5a40dcbd33ba6d5aef2bd01e91865b
Reviewed-on: https://chromium-review.googlesource.com/1259287
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'devices/src/virtio/gpu')
-rw-r--r--devices/src/virtio/gpu/backend.rs685
-rw-r--r--devices/src/virtio/gpu/mod.rs399
-rw-r--r--devices/src/virtio/gpu/protocol.rs88
3 files changed, 568 insertions, 604 deletions
diff --git a/devices/src/virtio/gpu/backend.rs b/devices/src/virtio/gpu/backend.rs
index 62cceb2..9c27712 100644
--- a/devices/src/virtio/gpu/backend.rs
+++ b/devices/src/virtio/gpu/backend.rs
@@ -15,12 +15,12 @@ use data_model::*;
 
 use sys_util::{GuestAddress, GuestMemory};
 
-use super::gpu_buffer::{Device, Buffer, Format, Flags};
+use super::gpu_buffer::{Buffer, Device, Flags, Format};
 use super::gpu_display::*;
-use super::gpu_renderer::{Box3, Renderer, Context as RendererContext,
-                          Image as RendererImage,
-                          Resource as GpuRendererResource, ResourceCreateArgs,
-                          format_fourcc as renderer_fourcc};
+use super::gpu_renderer::{
+    format_fourcc as renderer_fourcc, Box3, Context as RendererContext, Image as RendererImage,
+    Renderer, Resource as GpuRendererResource, ResourceCreateArgs,
+};
 
 use super::protocol::GpuResponse;
 use super::protocol::{VIRTIO_GPU_CAPSET_VIRGL, VIRTIO_GPU_CAPSET_VIRGL2};
@@ -59,13 +59,15 @@ trait VirglResource {
 
     /// Copies the given rectangle of pixels from guest memory, using the backing specified from a
     /// call to `attach_guest_backing`.
-    fn write_from_guest_memory(&mut self,
-                               x: u32,
-                               y: u32,
-                               width: u32,
-                               height: u32,
-                               src_offset: u64,
-                               mem: &GuestMemory);
+    fn write_from_guest_memory(
+        &mut self,
+        x: u32,
+        y: u32,
+        width: u32,
+        height: u32,
+        src_offset: u64,
+        mem: &GuestMemory,
+    );
 
     /// Reads from the given rectangle of pixels in the resource to the `dst` slice of memory.
     fn read_to_volatile(&mut self, x: u32, y: u32, width: u32, height: u32, dst: VolatileSlice);
@@ -99,53 +101,56 @@ impl VirglResource for GpuRendererResource {
         Some(self)
     }
 
-    fn write_from_guest_memory(&mut self,
-                               x: u32,
-                               y: u32,
-                               width: u32,
-                               height: u32,
-                               src_offset: u64,
-                               _mem: &GuestMemory) {
-        let res = self.transfer_write(None,
-                                      0,
-                                      0,
-                                      0,
-                                      Box3 {
-                                          x,
-                                          y,
-                                          z: 0,
-                                          w: width,
-                                          h: height,
-                                          d: 0,
-                                      },
-                                      src_offset);
+    fn write_from_guest_memory(
+        &mut self,
+        x: u32,
+        y: u32,
+        width: u32,
+        height: u32,
+        src_offset: u64,
+        _mem: &GuestMemory,
+    ) {
+        let res = self.transfer_write(
+            None,
+            0,
+            0,
+            0,
+            Box3 {
+                x,
+                y,
+                z: 0,
+                w: width,
+                h: height,
+                d: 0,
+            },
+            src_offset,
+        );
         if let Err(e) = res {
-            error!("failed to write to resource (x={} y={} w={} h={}, src_offset={}): {}",
-                   x,
-                   y,
-                   width,
-                   height,
-                   src_offset,
-                   e);
+            error!(
+                "failed to write to resource (x={} y={} w={} h={}, src_offset={}): {}",
+                x, y, width, height, src_offset, e
+            );
         }
     }
 
     fn read_to_volatile(&mut self, x: u32, y: u32, width: u32, height: u32, dst: VolatileSlice) {
-        let res = GpuRendererResource::read_to_volatile(self,
-                                                        None,
-                                                        0,
-                                                        0,
-                                                        0,
-                                                        Box3 {
-                                                            x,
-                                                            y,
-                                                            z: 0,
-                                                            w: width,
-                                                            h: height,
-                                                            d: 0,
-                                                        },
-                                                        0,
-                                                        dst);
+        let res = GpuRendererResource::read_to_volatile(
+            self,
+            None,
+            0,
+            0,
+            0,
+            Box3 {
+                x,
+                y,
+                z: 0,
+                w: width,
+                h: height,
+                d: 0,
+            },
+            0,
+            dst,
+        );
         if let Err(e) = res {
             error!("failed to read from resource: {}", e);
         }
@@ -162,9 +167,11 @@ struct BackedBuffer {
 }
 
 impl BackedBuffer {
-    fn new_renderer_registered(buffer: Buffer,
-                               gpu_renderer_resource: GpuRendererResource,
-                               image: RendererImage) -> BackedBuffer {
+    fn new_renderer_registered(
+        buffer: Buffer,
+        gpu_renderer_resource: GpuRendererResource,
+        image: RendererImage,
+    ) -> BackedBuffer {
         BackedBuffer {
             display_import: None,
             backing: Vec::new(),
@@ -226,15 +233,15 @@ impl VirglResource for BackedBuffer {
             }
         };
 
-        match display
-                  .borrow_mut()
-                  .import_dmabuf(dmabuf.as_raw_fd(),
-                                 0, /* offset */
-                                 self.buffer.stride(),
-                                 self.buffer.format_modifier(),
-                                 self.buffer.width(),
-                                 self.buffer.height(),
-                                 self.buffer.format().into()) {
+        match display.borrow_mut().import_dmabuf(
+            dmabuf.as_raw_fd(),
+            0, /* offset */
+            self.buffer.stride(),
+            self.buffer.format_modifier(),
+            self.buffer.width(),
+            self.buffer.height(),
+            self.buffer.format().into(),
+        ) {
             Ok(import_id) => {
                 self.display_import = Some((display.clone(), import_id));
                 Some(import_id)
@@ -246,29 +253,33 @@ impl VirglResource for BackedBuffer {
         }
     }
 
-    fn write_from_guest_memory(&mut self,
-                               x: u32,
-                               y: u32,
-                               width: u32,
-                               height: u32,
-                               src_offset: u64,
-                               mem: &GuestMemory) {
+    fn write_from_guest_memory(
+        &mut self,
+        x: u32,
+        y: u32,
+        width: u32,
+        height: u32,
+        src_offset: u64,
+        mem: &GuestMemory,
+    ) {
         if src_offset >= usize::MAX as u64 {
-            error!("failed to write to resource with given offset: {}", src_offset);
-            return
-        }
-        let res = self.buffer
-            .write_from_sg(x,
-                           y,
-                           width,
-                           height,
-                           0, // plane
-                           src_offset as usize,
-                           self.backing
-                               .iter()
-                               .map(|&(addr, len)| {
-                                        mem.get_slice(addr.offset(), len as u64).unwrap_or_default()
-                                    }));
+            error!(
+                "failed to write to resource with given offset: {}",
+                src_offset
+            );
+            return;
+        }
+        let res = self.buffer.write_from_sg(
+            x,
+            y,
+            width,
+            height,
+            0, // plane
+            src_offset as usize,
+            self.backing
+                .iter()
+                .map(|&(addr, len)| mem.get_slice(addr.offset(), len as u64).unwrap_or_default()),
+        );
         if let Err(e) = res {
             error!("failed to write to resource from guest memory: {:?}", e)
         }
@@ -336,22 +347,24 @@ impl Backend {
     }
 
     /// Creates a 2D resource with the given properties and associated it with the given id.
-    pub fn create_resource_2d(&mut self,
-                              id: u32,
-                              width: u32,
-                              height: u32,
-                              fourcc: u32)
-                              -> GpuResponse {
+    pub fn create_resource_2d(
+        &mut self,
+        id: u32,
+        width: u32,
+        height: u32,
+        fourcc: u32,
+    ) -> GpuResponse {
         if id == 0 {
             return GpuResponse::ErrInvalidResourceId;
         }
         match self.resources.entry(id) {
             Entry::Vacant(slot) => {
-                let res = self.device
-                    .create_buffer(width,
-                                   height,
-                                   Format::from(fourcc),
-                                   Flags::empty().use_scanout(true).use_linear(true));
+                let res = self.device.create_buffer(
+                    width,
+                    height,
+                    Format::from(fourcc),
+                    Flags::empty().use_scanout(true).use_linear(true),
+                );
                 match res {
                     Ok(res) => {
                         slot.insert(Box::from(BackedBuffer::from(res)));
@@ -403,14 +416,15 @@ impl Backend {
         }
     }
 
-    fn flush_resource_to_surface(&mut self,
-                                 resource_id: u32,
-                                 surface_id: u32,
-                                 x: u32,
-                                 y: u32,
-                                 width: u32,
-                                 height: u32)
-                                 -> GpuResponse {
+    fn flush_resource_to_surface(
+        &mut self,
+        resource_id: u32,
+        surface_id: u32,
+        x: u32,
+        y: u32,
+        width: u32,
+        height: u32,
+    ) -> GpuResponse {
         let resource = match self.resources.get_mut(&resource_id) {
             Some(r) => r,
             None => return GpuResponse::ErrInvalidResourceId,
@@ -442,13 +456,14 @@ impl Backend {
     }
 
     /// Flushes the given rectangle of pixels of the given resource to the display.
-    pub fn flush_resource(&mut self,
-                          id: u32,
-                          x: u32,
-                          y: u32,
-                          width: u32,
-                          height: u32)
-                          -> GpuResponse {
+    pub fn flush_resource(
+        &mut self,
+        id: u32,
+        x: u32,
+        y: u32,
+        width: u32,
+        height: u32,
+    ) -> GpuResponse {
         if id == 0 {
             return GpuResponse::OkNoData;
         }
@@ -476,15 +491,16 @@ impl Backend {
 
     /// Copes the given rectangle of pixels of the given resource's backing memory to the host side
     /// resource.
-    pub fn transfer_to_resource_2d(&mut self,
-                                   id: u32,
-                                   x: u32,
-                                   y: u32,
-                                   width: u32,
-                                   height: u32,
-                                   src_offset: u64,
-                                   mem: &GuestMemory)
-                                   -> GpuResponse {
+    pub fn transfer_to_resource_2d(
+        &mut self,
+        id: u32,
+        x: u32,
+        y: u32,
+        width: u32,
+        height: u32,
+        src_offset: u64,
+        mem: &GuestMemory,
+    ) -> GpuResponse {
         match self.resources.get_mut(&id) {
             Some(res) => {
                 res.write_from_guest_memory(x, y, width, height, src_offset, mem);
@@ -496,11 +512,12 @@ impl Backend {
 
     /// Attaches backing memory to the given resource, represented by a `Vec` of `(address, size)`
     /// tuples in the guest's physical address space.
-    pub fn attach_backing(&mut self,
-                          id: u32,
-                          mem: &GuestMemory,
-                          vecs: Vec<(GuestAddress, usize)>)
-                          -> GpuResponse {
+    pub fn attach_backing(
+        &mut self,
+        id: u32,
+        mem: &GuestMemory,
+        vecs: Vec<(GuestAddress, usize)>,
+    ) -> GpuResponse {
         match self.resources.get_mut(&id) {
             Some(resource) => {
                 resource.attach_guest_backing(mem, vecs);
@@ -532,11 +549,11 @@ impl Backend {
         } else if let Some(resource) = self.resources.get_mut(&id) {
             self.cursor_resource = id;
             if self.cursor_surface.is_none() {
-                match self.display
-                          .borrow_mut()
-                          .create_surface(self.scanout_surface,
-                                          resource.width(),
-                                          resource.height()) {
+                match self.display.borrow_mut().create_surface(
+                    self.scanout_surface,
+                    resource.width(),
+                    resource.height(),
+                ) {
                     Ok(surface) => self.cursor_surface = Some(surface),
                     Err(e) => {
                         error!("failed to create cursor surface: {:?}", e);
@@ -546,30 +563,21 @@ impl Backend {
             }
 
             let cursor_surface = self.cursor_surface.unwrap();
-            self.display
-                .borrow_mut()
-                .set_position(cursor_surface, x, y);
+            self.display.borrow_mut().set_position(cursor_surface, x, y);
 
             // Gets the resource's pixels into the display by importing the buffer.
             if let Some(import_id) = resource.import_to_display(&self.display) {
-                self.display
-                    .borrow_mut()
-                    .flip_to(cursor_surface, import_id);
+                self.display.borrow_mut().flip_to(cursor_surface, import_id);
                 return GpuResponse::OkNoData;
             }
 
             // Importing failed, so try copying the pixels into the surface's slower shared memory
             // framebuffer.
             if let Some(buffer) = resource.buffer() {
-                if let Some(fb) = self.display
-                       .borrow_mut()
-                       .framebuffer_memory(cursor_surface) {
-                    if let Err(e) = buffer.read_to_volatile(0,
-                                                            0,
-                                                            buffer.width(),
-                                                            buffer.height(),
-                                                            0,
-                                                            fb) {
+                if let Some(fb) = self.display.borrow_mut().framebuffer_memory(cursor_surface) {
+                    if let Err(e) =
+                        buffer.read_to_volatile(0, 0, buffer.width(), buffer.height(), 0, fb)
+                    {
                         error!("failed to copy resource to cursor: {:?}", e);
                         return GpuResponse::ErrInvalidParameter;
                     }
@@ -617,18 +625,16 @@ impl Backend {
         }
         match self.contexts.entry(id) {
             Entry::Occupied(_) => GpuResponse::ErrInvalidContextId,
-            Entry::Vacant(slot) => {
-                match self.renderer.create_context(id) {
-                    Ok(ctx) => {
-                        slot.insert(ctx);
-                        GpuResponse::OkNoData
-                    }
-                    Err(e) => {
-                        error!("failed to create renderer ctx: {}", e);
-                        GpuResponse::ErrUnspec
-                    }
+            Entry::Vacant(slot) => match self.renderer.create_context(id) {
+                Ok(ctx) => {
+                    slot.insert(ctx);
+                    GpuResponse::OkNoData
                 }
-            }
+                Err(e) => {
+                    error!("failed to create renderer ctx: {}", e);
+                    GpuResponse::ErrUnspec
+                }
+            },
         }
     }
 
@@ -642,10 +648,12 @@ impl Backend {
 
     /// Attaches the indicated resource to the given context.
     pub fn context_attach_resource(&mut self, ctx_id: u32, res_id: u32) -> GpuResponse {
-        match (self.contexts.get_mut(&ctx_id),
-               self.resources
-                   .get_mut(&res_id)
-                   .and_then(|res| res.gpu_renderer_resource())) {
+        match (
+            self.contexts.get_mut(&ctx_id),
+            self.resources
+                .get_mut(&res_id)
+                .and_then(|res| res.gpu_renderer_resource()),
+        ) {
             (Some(ctx), Some(res)) => {
                 ctx.attach(res);
                 GpuResponse::OkNoData
@@ -657,10 +665,12 @@ impl Backend {
 
     /// detaches the indicated resource to the given context.
     pub fn context_detach_resource(&mut self, ctx_id: u32, res_id: u32) -> GpuResponse {
-        match (self.contexts.get_mut(&ctx_id),
-               self.resources
-                   .get_mut(&res_id)
-                   .and_then(|res| res.gpu_renderer_resource())) {
+        match (
+            self.contexts.get_mut(&ctx_id),
+            self.resources
+                .get_mut(&res_id)
+                .and_then(|res| res.gpu_renderer_resource()),
+        ) {
             (Some(ctx), Some(res)) => {
                 ctx.detach(res);
                 GpuResponse::OkNoData
@@ -671,10 +681,7 @@ impl Backend {
     }
 
     pub fn validate_args_as_fourcc(args: ResourceCreateArgs) -> Option<u32> {
-        if args.depth == 1 &&
-           args.array_size == 1 &&
-           args.last_level == 0 &&
-           args.nr_samples == 0 {
+        if args.depth == 1 && args.array_size == 1 && args.last_level == 0 && args.nr_samples == 0 {
             renderer_fourcc(args.format)
         } else {
             None
@@ -682,19 +689,20 @@ impl Backend {
     }
 
     /// Creates a 3D resource with the given properties and associated it with the given id.
-    pub fn resource_create_3d(&mut self,
-                              id: u32,
-                              target: u32,
-                              format: u32,
-                              bind: u32,
-                              width: u32,
-                              height: u32,
-                              depth: u32,
-                              array_size: u32,
-                              last_level: u32,
-                              nr_samples: u32,
-                              flags: u32)
-                              -> GpuResponse {
+    pub fn resource_create_3d(
+        &mut self,
+        id: u32,
+        target: u32,
+        format: u32,
+        bind: u32,
+        width: u32,
+        height: u32,
+        depth: u32,
+        array_size: u32,
+        last_level: u32,
+        nr_samples: u32,
+        flags: u32,
+    ) -> GpuResponse {
         if id == 0 {
             return GpuResponse::ErrInvalidResourceId;
         }
@@ -715,192 +723,173 @@ impl Backend {
 
         match self.resources.entry(id) {
             Entry::Occupied(_) => GpuResponse::ErrInvalidResourceId,
-            Entry::Vacant(slot) => {
-                match Backend::validate_args_as_fourcc(create_args) {
-                    Some(fourcc) => {
-                        let buffer = match self.device
-                            .create_buffer(width,
-                                           height,
-                                           Format::from(fourcc),
-                                           Flags::empty().use_scanout(true).use_linear(true)) {
-                            Ok(buffer) => buffer,
-                            Err(e) => {
-                                error!("failed to create buffer for 3d resource {}: {}", format, e);
-                                return GpuResponse::ErrUnspec;
-                            }
-                        };
-
-                        let dma_buf_fd = match buffer.export_plane_fd(0) {
-                            Ok(dma_buf_fd) => dma_buf_fd,
-                            Err(e) => {
-                                error!("failed to export plane fd: {}", e);
-                                return GpuResponse::ErrUnspec
-                            }
-                        };
-
-                        let image = match self.renderer
-                            .image_from_dmabuf(fourcc,
-                                               width,
-                                               height,
-                                               dma_buf_fd.as_raw_fd(),
-                                               buffer.plane_offset(0),
-                                               buffer.plane_stride(0)) {
-                            Ok(image) => image,
-                            Err(e) => {
-                                error!("failed to create egl image: {}", e);
-                                return GpuResponse::ErrUnspec
-                            }
-                        };
-
-                        let res = self.renderer
-                            .import_resource(create_args, &image);
-                        match res {
-                            Ok(res) => {
-                                let mut backed =
-                                    BackedBuffer::new_renderer_registered(buffer,
-                                                                          res,
-                                                                          image);
-                                slot.insert(Box::new(backed));
-                                GpuResponse::OkNoData
-                            }
-                            Err(e) => {
-                                error!("failed to import renderer resource: {}",
-                                       e);
-                                GpuResponse::ErrUnspec
-                            }
+            Entry::Vacant(slot) => match Backend::validate_args_as_fourcc(create_args) {
+                Some(fourcc) => {
+                    let buffer = match self.device.create_buffer(
+                        width,
+                        height,
+                        Format::from(fourcc),
+                        Flags::empty().use_scanout(true).use_linear(true),
+                    ) {
+                        Ok(buffer) => buffer,
+                        Err(e) => {
+                            error!("failed to create buffer for 3d resource {}: {}", format, e);
+                            return GpuResponse::ErrUnspec;
+                        }
+                    };
+
+                    let dma_buf_fd = match buffer.export_plane_fd(0) {
+                        Ok(dma_buf_fd) => dma_buf_fd,
+                        Err(e) => {
+                            error!("failed to export plane fd: {}", e);
+                            return GpuResponse::ErrUnspec;
+                        }
+                    };
+
+                    let image = match self.renderer.image_from_dmabuf(
+                        fourcc,
+                        width,
+                        height,
+                        dma_buf_fd.as_raw_fd(),
+                        buffer.plane_offset(0),
+                        buffer.plane_stride(0),
+                    ) {
+                        Ok(image) => image,
+                        Err(e) => {
+                            error!("failed to create egl image: {}", e);
+                            return GpuResponse::ErrUnspec;
                         }
-                    },
-                    None => {
-                        let res = self.renderer.create_resource(create_args);
-                        match res {
-                            Ok(res) => {
-                                slot.insert(Box::new(res));
-                                GpuResponse::OkNoData
-                            }
-                            Err(e) => {
-                                error!("failed to create renderer resource: {}",
-                                       e);
-                                GpuResponse::ErrUnspec
-                            }
+                    };
+
+                    let res = self.renderer.import_resource(create_args, &image);
+                    match res {
+                        Ok(res) => {
+                            let mut backed =
+                                BackedBuffer::new_renderer_registered(buffer, res, image);
+                            slot.insert(Box::new(backed));
+                            GpuResponse::OkNoData
+                        }
+                        Err(e) => {
+                            error!("failed to import renderer resource: {}", e);
+                            GpuResponse::ErrUnspec
                         }
                     }
                 }
-            }
+                None => {
+                    let res = self.renderer.create_resource(create_args);
+                    match res {
+                        Ok(res) => {
+                            slot.insert(Box::new(res));
+                            GpuResponse::OkNoData
+                        }
+                        Err(e) => {
+                            error!("failed to create renderer resource: {}", e);
+                            GpuResponse::ErrUnspec
+                        }
+                    }
+                }
+            },
         }
     }
 
     /// Copes the given 3D rectangle of pixels of the given resource's backing memory to the host
     /// side resource.
-    pub fn transfer_to_resource_3d(&mut self,
-                                   ctx_id: u32,
-                                   res_id: u32,
-                                   x: u32,
-                                   y: u32,
-                                   z: u32,
-                                   width: u32,
-                                   height: u32,
-                                   depth: u32,
-                                   level: u32,
-                                   stride: u32,
-                                   layer_stride: u32,
-                                   offset: u64)
-                                   -> GpuResponse {
+    pub fn transfer_to_resource_3d(
+        &mut self,
+        ctx_id: u32,
+        res_id: u32,
+        x: u32,
+        y: u32,
+        z: u32,
+        width: u32,
+        height: u32,
+        depth: u32,
+        level: u32,
+        stride: u32,
+        layer_stride: u32,
+        offset: u64,
+    ) -> GpuResponse {
         let ctx = match ctx_id {
             0 => None,
-            id => {
-                match self.contexts.get(&id) {
-                    None => return GpuResponse::ErrInvalidContextId,
-                    ctx => ctx,
-                }
-            }
+            id => match self.contexts.get(&id) {
+                None => return GpuResponse::ErrInvalidContextId,
+                ctx => ctx,
+            },
         };
         match self.resources.get_mut(&res_id) {
-            Some(res) => {
-                match res.gpu_renderer_resource() {
-                    Some(res) => {
-                        let transfer_box = Box3 {
-                            x,
-                            y,
-                            z,
-                            w: width,
-                            h: height,
-                            d: depth,
-                        };
-                        let res = res.transfer_write(ctx,
-                                                     level,
-                                                     stride,
-                                                     layer_stride,
-                                                     transfer_box,
-                                                     offset);
-                        match res {
-                            Ok(_) => GpuResponse::OkNoData,
-                            Err(e) => {
-                                error!("failed to transfer to host: {}", e);
-                                GpuResponse::ErrUnspec
-                            }
+            Some(res) => match res.gpu_renderer_resource() {
+                Some(res) => {
+                    let transfer_box = Box3 {
+                        x,
+                        y,
+                        z,
+                        w: width,
+                        h: height,
+                        d: depth,
+                    };
+                    let res =
+                        res.transfer_write(ctx, level, stride, layer_stride, transfer_box, offset);
+                    match res {
+                        Ok(_) => GpuResponse::OkNoData,
+                        Err(e) => {
+                            error!("failed to transfer to host: {}", e);
+                            GpuResponse::ErrUnspec
                         }
                     }
-                    None => GpuResponse::ErrInvalidResourceId,
                 }
-            }
+                None => GpuResponse::ErrInvalidResourceId,
+            },
             None => GpuResponse::ErrInvalidResourceId,
         }
     }
 
     /// Copes the given rectangle of pixels from the resource to the given resource's backing
     /// memory.
-    pub fn transfer_from_resource_3d(&mut self,
-                                     ctx_id: u32,
-                                     res_id: u32,
-                                     x: u32,
-                                     y: u32,
-                                     z: u32,
-                                     width: u32,
-                                     height: u32,
-                                     depth: u32,
-                                     level: u32,
-                                     stride: u32,
-                                     layer_stride: u32,
-                                     offset: u64)
-                                     -> GpuResponse {
+    pub fn transfer_from_resource_3d(
+        &mut self,
+        ctx_id: u32,
+        res_id: u32,
+        x: u32,
+        y: u32,
+        z: u32,
+        width: u32,
+        height: u32,
+        depth: u32,
+        level: u32,
+        stride: u32,
+        layer_stride: u32,
+        offset: u64,
+    ) -> GpuResponse {
         let ctx = match ctx_id {
             0 => None,
-            id => {
-                match self.contexts.get(&id) {
-                    None => return GpuResponse::ErrInvalidContextId,
-                    ctx => ctx,
-                }
-            }
+            id => match self.contexts.get(&id) {
+                None => return GpuResponse::ErrInvalidContextId,
+                ctx => ctx,
+            },
         };
         match self.resources.get_mut(&res_id) {
-            Some(res) => {
-                match res.gpu_renderer_resource() {
-                    Some(res) => {
-                        let transfer_box = Box3 {
-                            x,
-                            y,
-                            z,
-                            w: width,
-                            h: height,
-                            d: depth,
-                        };
-                        let res = res.transfer_read(ctx,
-                                                    level,
-                                                    stride,
-                                                    layer_stride,
-                                                    transfer_box,
-                                                    offset);
-                        match res {
-                            Ok(_) => GpuResponse::OkNoData,
-                            Err(e) => {
-                                error!("failed to transfer from host: {}", e);
-                                GpuResponse::ErrUnspec
-                            }
+            Some(res) => match res.gpu_renderer_resource() {
+                Some(res) => {
+                    let transfer_box = Box3 {
+                        x,
+                        y,
+                        z,
+                        w: width,
+                        h: height,
+                        d: depth,
+                    };
+                    let res =
+                        res.transfer_read(ctx, level, stride, layer_stride, transfer_box, offset);
+                    match res {
+                        Ok(_) => GpuResponse::OkNoData,
+                        Err(e) => {
+                            error!("failed to transfer from host: {}", e);
+                            GpuResponse::ErrUnspec
                         }
                     }
-                    None => GpuResponse::ErrInvalidResourceId,
                 }
-            }
+                None => GpuResponse::ErrInvalidResourceId,
+            },
             None => GpuResponse::ErrInvalidResourceId,
         }
     }
@@ -908,15 +897,13 @@ impl Backend {
     /// Submits a command buffer to the given rendering context.
     pub fn submit_command(&mut self, ctx_id: u32, commands: &mut [u8]) -> GpuResponse {
         match self.contexts.get_mut(&ctx_id) {
-            Some(ctx) => {
-                match ctx.submit(&mut commands[..]) {
-                    Ok(_) => GpuResponse::OkNoData,
-                    Err(e) => {
-                        error!("failed to submit command buffer: {}", e);
-                        GpuResponse::ErrUnspec
-                    }
+            Some(ctx) => match ctx.submit(&mut commands[..]) {
+                Ok(_) => GpuResponse::OkNoData,
+                Err(e) => {
+                    error!("failed to submit command buffer: {}", e);
+                    GpuResponse::ErrUnspec
                 }
-            }
+            },
             None => GpuResponse::ErrInvalidContextId,
         }
     }
diff --git a/devices/src/virtio/gpu/mod.rs b/devices/src/virtio/gpu/mod.rs
index 0b6f05e..ec60634 100644
--- a/devices/src/virtio/gpu/mod.rs
+++ b/devices/src/virtio/gpu/mod.rs
@@ -6,8 +6,8 @@ extern crate gpu_buffer;
 extern crate gpu_display;
 extern crate gpu_renderer;
 
-mod protocol;
 mod backend;
+mod protocol;
 
 use std::cell::RefCell;
 use std::collections::VecDeque;
@@ -16,24 +16,25 @@ use std::mem::size_of;
 use std::os::unix::io::{AsRawFd, RawFd};
 use std::path::{Path, PathBuf};
 use std::rc::Rc;
-use std::sync::Arc;
 use std::sync::atomic::{AtomicUsize, Ordering};
+use std::sync::Arc;
 use std::thread::spawn;
 use std::time::Duration;
 
 use data_model::*;
 
-use sys_util::{EventFd, PollContext, PollToken, GuestAddress, GuestMemory};
+use sys_util::{EventFd, GuestAddress, GuestMemory, PollContext, PollToken};
 
 use self::gpu_buffer::Device;
 use self::gpu_display::*;
-use self::gpu_renderer::{Renderer, format_fourcc};
+use self::gpu_renderer::{format_fourcc, Renderer};
 
-use super::{VirtioDevice, Queue, AvailIter, VIRTIO_F_VERSION_1, INTERRUPT_STATUS_USED_RING,
-            TYPE_GPU};
+use super::{
+    AvailIter, Queue, VirtioDevice, INTERRUPT_STATUS_USED_RING, TYPE_GPU, VIRTIO_F_VERSION_1,
+};
 
-use self::protocol::*;
 use self::backend::Backend;
+use self::protocol::*;
 
 // First queue is for virtio gpu commands. Second queue is for cursor commands, which we expect
 // there to be fewer of.
@@ -88,11 +89,12 @@ impl Frontend {
         self.backend.process_display()
     }
 
-    fn process_gpu_command(&mut self,
-                           mem: &GuestMemory,
-                           cmd: GpuCommand,
-                           data: Option<VolatileSlice>)
-                           -> GpuResponse {
+    fn process_gpu_command(
+        &mut self,
+        mem: &GuestMemory,
+        cmd: GpuCommand,
+        data: Option<VolatileSlice>,
+    ) -> GpuResponse {
         self.backend.force_ctx_0();
 
         match cmd {
@@ -102,50 +104,49 @@ impl Frontend {
             GpuCommand::ResourceCreate2d(info) => {
                 let format = info.format.to_native();
                 match format_fourcc(format) {
-                    Some(fourcc) => {
-                        self.backend
-                            .create_resource_2d(info.resource_id.to_native(),
-                                                info.width.to_native(),
-                                                info.height.to_native(),
-                                                fourcc)
-                    }
+                    Some(fourcc) => self.backend.create_resource_2d(
+                        info.resource_id.to_native(),
+                        info.width.to_native(),
+                        info.height.to_native(),
+                        fourcc,
+                    ),
                     None => {
-                        warn!("failed to create resource with unrecognized pipe format {}",
-                              format);
+                        warn!(
+                            "failed to create resource with unrecognized pipe format {}",
+                            format
+                        );
                         GpuResponse::ErrInvalidParameter
                     }
                 }
-
             }
             GpuCommand::ResourceUnref(info) => {
                 self.backend.unref_resource(info.resource_id.to_native())
             }
             GpuCommand::SetScanout(info) => self.backend.set_scanout(info.resource_id.to_native()),
-            GpuCommand::ResourceFlush(info) => {
-                self.backend
-                    .flush_resource(info.resource_id.to_native(),
-                                    info.r.x.to_native(),
-                                    info.r.y.to_native(),
-                                    info.r.width.to_native(),
-                                    info.r.height.to_native())
-            }
-            GpuCommand::TransferToHost2d(info) => {
-                self.backend
-                    .transfer_to_resource_2d(info.resource_id.to_native(),
-                                             info.r.x.to_native(),
-                                             info.r.y.to_native(),
-                                             info.r.width.to_native(),
-                                             info.r.height.to_native(),
-                                             info.offset.to_native(),
-                                             mem)
-            }
+            GpuCommand::ResourceFlush(info) => self.backend.flush_resource(
+                info.resource_id.to_native(),
+                info.r.x.to_native(),
+                info.r.y.to_native(),
+                info.r.width.to_native(),
+                info.r.height.to_native(),
+            ),
+            GpuCommand::TransferToHost2d(info) => self.backend.transfer_to_resource_2d(
+                info.resource_id.to_native(),
+                info.r.x.to_native(),
+                info.r.y.to_native(),
+                info.r.width.to_native(),
+                info.r.height.to_native(),
+                info.offset.to_native(),
+                mem,
+            ),
             GpuCommand::ResourceAttachBacking(info) if data.is_some() => {
                 let data = data.unwrap();
                 let entry_count = info.nr_entries.to_native() as usize;
                 let mut iovecs = Vec::with_capacity(entry_count);
                 for i in 0..entry_count {
-                    if let Ok(entry_ref) = data.get_ref((i * size_of::<virtio_gpu_mem_entry>()) as
-                                                        u64) {
+                    if let Ok(entry_ref) =
+                        data.get_ref((i * size_of::<virtio_gpu_mem_entry>()) as u64)
+                    {
                         let entry: virtio_gpu_mem_entry = entry_ref.load();
                         let addr = GuestAddress(entry.addr.to_native());
                         let len = entry.length.to_native() as usize;
@@ -160,42 +161,32 @@ impl Frontend {
             GpuCommand::ResourceDetachBacking(info) => {
                 self.backend.detach_backing(info.resource_id.to_native())
             }
-            GpuCommand::UpdateCursor(info) => {
-                self.backend
-                    .update_cursor(info.resource_id.to_native(),
-                                   info.pos.x.into(),
-                                   info.pos.y.into())
-            }
-            GpuCommand::MoveCursor(info) => {
-                self.backend
-                    .move_cursor(info.pos.x.into(), info.pos.y.into())
-            }
+            GpuCommand::UpdateCursor(info) => self.backend.update_cursor(
+                info.resource_id.to_native(),
+                info.pos.x.into(),
+                info.pos.y.into(),
+            ),
+            GpuCommand::MoveCursor(info) => self
+                .backend
+                .move_cursor(info.pos.x.into(), info.pos.y.into()),
             GpuCommand::GetCapsetInfo(info) => {
-                self.backend
-                    .get_capset_info(info.capset_index.to_native())
-            }
-            GpuCommand::GetCapset(info) => {
-                self.backend
-                    .get_capset(info.capset_id.to_native(), info.capset_version.to_native())
-            }
-            GpuCommand::CtxCreate(info) => {
-                self.backend
-                    .create_renderer_context(info.hdr.ctx_id.to_native())
-            }
-            GpuCommand::CtxDestroy(info) => {
-                self.backend
-                    .destroy_renderer_context(info.hdr.ctx_id.to_native())
-            }
-            GpuCommand::CtxAttachResource(info) => {
-                self.backend
-                    .context_attach_resource(info.hdr.ctx_id.to_native(),
-                                             info.resource_id.to_native())
-            }
-            GpuCommand::CtxDetachResource(info) => {
-                self.backend
-                    .context_detach_resource(info.hdr.ctx_id.to_native(),
-                                             info.resource_id.to_native())
+                self.backend.get_capset_info(info.capset_index.to_native())
             }
+            GpuCommand::GetCapset(info) => self
+                .backend
+                .get_capset(info.capset_id.to_native(), info.capset_version.to_native()),
+            GpuCommand::CtxCreate(info) => self
+                .backend
+                .create_renderer_context(info.hdr.ctx_id.to_native()),
+            GpuCommand::CtxDestroy(info) => self
+                .backend
+                .destroy_renderer_context(info.hdr.ctx_id.to_native()),
+            GpuCommand::CtxAttachResource(info) => self
+                .backend
+                .context_attach_resource(info.hdr.ctx_id.to_native(), info.resource_id.to_native()),
+            GpuCommand::CtxDetachResource(info) => self
+                .backend
+                .context_detach_resource(info.hdr.ctx_id.to_native(), info.resource_id.to_native()),
             GpuCommand::ResourceCreate3d(info) => {
                 let id = info.resource_id.to_native();
                 let target = info.target.to_native();
@@ -208,18 +199,10 @@ impl Frontend {
                 let last_level = info.last_level.to_native();
                 let nr_samples = info.nr_samples.to_native();
                 let flags = info.flags.to_native();
-                self.backend
-                    .resource_create_3d(id,
-                                        target,
-                                        format,
-                                        bind,
-                                        width,
-                                        height,
-                                        depth,
-                                        array_size,
-                                        last_level,
-                                        nr_samples,
-                                        flags)
+                self.backend.resource_create_3d(
+                    id, target, format, bind, width, height, depth, array_size, last_level,
+                    nr_samples, flags,
+                )
             }
             GpuCommand::TransferToHost3d(info) => {
                 let ctx_id = info.hdr.ctx_id.to_native();
@@ -234,20 +217,20 @@ impl Frontend {
                 let stride = info.stride.to_native();
                 let layer_stride = info.layer_stride.to_native();
                 let offset = info.offset.to_native();
-                self.backend
-                    .transfer_to_resource_3d(ctx_id,
-                                             res_id,
-                                             x,
-                                             y,
-                                             z,
-                                             width,
-                                             height,
-                                             depth,
-                                             level,
-                                             stride,
-                                             layer_stride,
-                                             offset)
-
+                self.backend.transfer_to_resource_3d(
+                    ctx_id,
+                    res_id,
+                    x,
+                    y,
+                    z,
+                    width,
+                    height,
+                    depth,
+                    level,
+                    stride,
+                    layer_stride,
+                    offset,
+                )
             }
             GpuCommand::TransferFromHost3d(info) => {
                 let ctx_id = info.hdr.ctx_id.to_native();
@@ -262,19 +245,20 @@ impl Frontend {
                 let stride = info.stride.to_native();
                 let layer_stride = info.layer_stride.to_native();
                 let offset = info.offset.to_native();
-                self.backend
-                    .transfer_from_resource_3d(ctx_id,
-                                               res_id,
-                                               x,
-                                               y,
-                                               z,
-                                               width,
-                                               height,
-                                               depth,
-                                               level,
-                                               stride,
-                                               layer_stride,
-                                               offset)
+                self.backend.transfer_from_resource_3d(
+                    ctx_id,
+                    res_id,
+                    x,
+                    y,
+                    z,
+                    width,
+                    height,
+                    depth,
+                    level,
+                    stride,
+                    layer_stride,
+                    offset,
+                )
             }
             GpuCommand::CmdSubmit3d(info) if data.is_some() => {
                 let data = data.unwrap(); // guarded by this match arm
@@ -296,10 +280,12 @@ impl Frontend {
         }
     }
 
-    fn take_descriptors(mem: &GuestMemory,
-                        desc_iter: AvailIter,
-                        descriptors: &mut VecDeque<QueueDescriptor>,
-                        return_descriptors: &mut VecDeque<ReturnDescriptor>) {
+    fn take_descriptors(
+        mem: &GuestMemory,
+        desc_iter: AvailIter,
+        descriptors: &mut VecDeque<QueueDescriptor>,
+        return_descriptors: &mut VecDeque<ReturnDescriptor>,
+    ) {
         for desc in desc_iter {
             if desc.len as usize >= size_of::<virtio_gpu_ctrl_hdr>() && !desc.is_write_only() {
                 let mut q_desc = QueueDescriptor {
@@ -323,38 +309,45 @@ impl Frontend {
                 }
                 descriptors.push_back(q_desc);
             } else {
-                let likely_type = mem.read_obj_from_addr(desc.addr)
-                    .unwrap_or(Le32::from(0));
-                debug!("ctrl queue bad descriptor index = {} len = {} write = {} type = {}",
-                       desc.index,
-                       desc.len,
-                       desc.is_write_only(),
-                       virtio_gpu_cmd_str(likely_type.to_native()));
+                let likely_type = mem.read_obj_from_addr(desc.addr).unwrap_or(Le32::from(0));
+                debug!(
+                    "ctrl queue bad descriptor index = {} len = {} write = {} type = {}",
+                    desc.index,
+                    desc.len,
+                    desc.is_write_only(),
+                    virtio_gpu_cmd_str(likely_type.to_native())
+                );
                 return_descriptors.push_back(ReturnDescriptor {
-                                                 index: desc.index,
-                                                 len: 0,
-                                             });
+                    index: desc.index,
+                    len: 0,
+                });
             }
         }
     }
 
     fn take_ctrl_descriptors(&mut self, mem: &GuestMemory, desc_iter: AvailIter) {
-        Frontend::take_descriptors(mem,
-                                   desc_iter,
-                                   &mut self.ctrl_descriptors,
-                                   &mut self.return_ctrl_descriptors);
+        Frontend::take_descriptors(
+            mem,
+            desc_iter,
+            &mut self.ctrl_descriptors,
+            &mut self.return_ctrl_descriptors,
+        );
     }
 
     fn take_cursor_descriptors(&mut self, mem: &GuestMemory, desc_iter: AvailIter) {
-        Frontend::take_descriptors(mem,
-                                   desc_iter,
-                                   &mut self.cursor_descriptors,
-                                   &mut self.return_cursor_descriptors);
+        Frontend::take_descriptors(
+            mem,
+            desc_iter,
+            &mut self.cursor_descriptors,
+            &mut self.return_cursor_descriptors,
+        );
     }
 
-    fn process_descriptor(&mut self,
-                          mem: &GuestMemory,
-                          desc: QueueDescriptor) -> Option<ReturnDescriptor> {
+    fn process_descriptor(
+        &mut self,
+        mem: &GuestMemory,
+        desc: QueueDescriptor,
+    ) -> Option<ReturnDescriptor> {
         let mut resp = GpuResponse::ErrUnspec;
         let mut gpu_cmd = None;
         let mut len = 0;
@@ -392,17 +385,14 @@ impl Frontend {
                         ctx_id = ctrl_hdr.ctx_id.to_native();
                         flags = VIRTIO_GPU_FLAG_FENCE;
 
-                        let fence_resp = self.backend
-                            .create_fence(ctx_id, fence_id as u32);
+                        let fence_resp = self.backend.create_fence(ctx_id, fence_id as u32);
                         if fence_resp.is_err() {
-                            warn!("create_fence {} -> {:?}",
-                                  fence_id, fence_resp);
+                            warn!("create_fence {} -> {:?}", fence_id, fence_resp);
                             resp = fence_resp;
                         }
                     }
                 }
 
-
                 // Prepare the response now, even if it is going to wait until
                 // fence is complete.
                 match resp.encode(flags, fence_id, ctx_id, ret_desc_mem) {
@@ -417,7 +407,7 @@ impl Frontend {
                         desc,
                     });
 
-                    return None
+                    return None;
                 }
 
                 // No fence, respond now.
@@ -430,23 +420,19 @@ impl Frontend {
     }
 
     fn process_ctrl(&mut self, mem: &GuestMemory) -> Option<ReturnDescriptor> {
-        self.return_ctrl_descriptors
-            .pop_front()
-            .or_else(|| {
-                         self.ctrl_descriptors
-                             .pop_front()
-                             .and_then(|desc| self.process_descriptor(mem, desc))
-                     })
+        self.return_ctrl_descriptors.pop_front().or_else(|| {
+            self.ctrl_descriptors
+                .pop_front()
+                .and_then(|desc| self.process_descriptor(mem, desc))
+        })
     }
 
     fn process_cursor(&mut self, mem: &GuestMemory) -> Option<ReturnDescriptor> {
-        self.return_cursor_descriptors
-            .pop_front()
-            .or_else(|| {
-                         self.cursor_descriptors
-                             .pop_front()
-                             .and_then(|desc| self.process_descriptor(mem, desc))
-                     })
+        self.return_cursor_descriptors.pop_front().or_else(|| {
+            self.cursor_descriptors
+                .pop_front()
+                .and_then(|desc| self.process_descriptor(mem, desc))
+        })
     }
 
     fn fence_poll(&mut self) {
@@ -457,9 +443,9 @@ impl Frontend {
                 true
             } else {
                 return_descs.push_back(ReturnDescriptor {
-                                           index: f_desc.desc.index,
-                                           len: f_desc.len
-                                       });
+                    index: f_desc.desc.index,
+                    len: f_desc.len,
+                });
                 false
             }
         })
@@ -486,7 +472,6 @@ impl Worker {
         let _ = self.interrupt_evt.write(1);
     }
 
-
     fn run(&mut self) {
         #[derive(PollToken)]
         enum Token {
@@ -496,23 +481,20 @@ impl Worker {
             Kill,
         }
 
-        let poll_ctx: PollContext<Token> =
-            match PollContext::new()
-                      .and_then(|pc| pc.add(&self.ctrl_evt, Token::CtrlQueue).and(Ok(pc)))
-                      .and_then(|pc| {
-                                    pc.add(&self.cursor_evt, Token::CursorQueue).and(Ok(pc))
-                                })
-                      .and_then(|pc| {
-                                    pc.add(&*self.state.display().borrow(), Token::Display)
-                                        .and(Ok(pc))
-                                })
-                      .and_then(|pc| pc.add(&self.kill_evt, Token::Kill).and(Ok(pc))) {
-                Ok(pc) => pc,
-                Err(e) => {
-                    error!("failed creating PollContext: {:?}", e);
-                    return;
-                }
-            };
+        let poll_ctx: PollContext<Token> = match PollContext::new()
+            .and_then(|pc| pc.add(&self.ctrl_evt, Token::CtrlQueue).and(Ok(pc)))
+            .and_then(|pc| pc.add(&self.cursor_evt, Token::CursorQueue).and(Ok(pc)))
+            .and_then(|pc| {
+                pc.add(&*self.state.display().borrow(), Token::Display)
+                    .and(Ok(pc))
+            }).and_then(|pc| pc.add(&self.kill_evt, Token::Kill).and(Ok(pc)))
+        {
+            Ok(pc) => pc,
+            Err(e) => {
+                error!("failed creating PollContext: {:?}", e);
+                return;
+            }
+        };
 
         'poll: loop {
             // If there are outstanding fences, wake up early to poll them.
@@ -653,7 +635,6 @@ impl VirtioDevice for Gpu {
         let _ = value;
     }
 
-
     fn read_config(&self, offset: u64, data: &mut [u8]) {
         let offset = offset as usize;
         let len = data.len();
@@ -679,12 +660,14 @@ impl VirtioDevice for Gpu {
         }
     }
 
-    fn activate(&mut self,
-                mem: GuestMemory,
-                interrupt_evt: EventFd,
-                interrupt_status: Arc<AtomicUsize>,
-                mut queues: Vec<Queue>,
-                mut queue_evts: Vec<EventFd>) {
+    fn activate(
+        &mut self,
+        mem: GuestMemory,
+        interrupt_evt: EventFd,
+        interrupt_status: Arc<AtomicUsize>,
+        mut queues: Vec<Queue>,
+        mut queue_evts: Vec<EventFd>,
+    ) {
         if queues.len() != QUEUE_SIZES.len() || queue_evts.len() != QUEUE_SIZES.len() {
             return;
         }
@@ -697,14 +680,13 @@ impl VirtioDevice for Gpu {
             }
         };
 
-        let (self_kill_evt, kill_evt) =
-            match EventFd::new().and_then(|e| Ok((e.try_clone()?, e))) {
-                Ok(v) => v,
-                Err(e) => {
-                    error!("error creating kill EventFd pair: {:?}", e);
-                    return;
-                }
-            };
+        let (self_kill_evt, kill_evt) = match EventFd::new().and_then(|e| Ok((e.try_clone()?, e))) {
+            Ok(v) => v,
+            Err(e) => {
+                error!("error creating kill EventFd pair: {:?}", e);
+                return;
+            }
+        };
         self.kill_evt = Some(self_kill_evt);
 
         let ctrl_queue = queues.remove(0);
@@ -726,7 +708,7 @@ impl VirtioDevice for Gpu {
                 Ok(d) => d,
                 Err(()) => {
                     error!("failed to open device");
-                    return
+                    return;
                 }
             };
 
@@ -747,18 +729,17 @@ impl VirtioDevice for Gpu {
             };
 
             Worker {
-                    exit_evt,
-                    mem,
-                    interrupt_evt,
-                    interrupt_status,
-                    ctrl_queue,
-                    ctrl_evt,
-                    cursor_queue,
-                    cursor_evt,
-                    kill_evt,
-                    state: Frontend::new(Backend::new(device, display, renderer)),
-                }
-                .run()
+                exit_evt,
+                mem,
+                interrupt_evt,
+                interrupt_status,
+                ctrl_queue,
+                ctrl_evt,
+                cursor_queue,
+                cursor_evt,
+                kill_evt,
+                state: Frontend::new(Backend::new(device, display, renderer)),
+            }.run()
         });
     }
 }
diff --git a/devices/src/virtio/gpu/protocol.rs b/devices/src/virtio/gpu/protocol.rs
index 1c9b1c3..2001cd7 100644
--- a/devices/src/virtio/gpu/protocol.rs
+++ b/devices/src/virtio/gpu/protocol.rs
@@ -7,7 +7,7 @@ use std::marker::PhantomData;
 use std::mem::{size_of, size_of_val};
 use std::str::from_utf8;
 
-use data_model::{DataInit, Le32, Le64, VolatileMemory, VolatileSlice, VolatileMemoryError};
+use data_model::{DataInit, Le32, Le64, VolatileMemory, VolatileMemoryError, VolatileSlice};
 
 pub const VIRTIO_GPU_F_VIRGL: u32 = 0;
 
@@ -122,9 +122,9 @@ unsafe impl DataInit for virtio_gpu_cursor_pos {}
 pub struct virtio_gpu_update_cursor {
     pub hdr: virtio_gpu_ctrl_hdr,
     pub pos: virtio_gpu_cursor_pos, /* update & move */
-    pub resource_id: Le32, /* update only */
-    pub hot_x: Le32, /* update only */
-    pub hot_y: Le32, /* update only */
+    pub resource_id: Le32,          /* update only */
+    pub hot_x: Le32,                /* update only */
+    pub hot_y: Le32,                /* update only */
     pub padding: Le32,
 }
 
@@ -417,7 +417,6 @@ pub struct virtio_gpu_resp_capset {
 
 unsafe impl DataInit for virtio_gpu_resp_capset {}
 
-
 pub const VIRTIO_GPU_EVENT_DISPLAY: u32 = 1 << 0;
 
 #[derive(Copy, Clone, Debug)]
@@ -516,32 +515,28 @@ impl GpuCommand {
         use self::GpuCommand::*;
         let hdr: virtio_gpu_ctrl_hdr = cmd.get_ref(0)?.load();
         Ok(match hdr.type_.into() {
-               VIRTIO_GPU_CMD_GET_DISPLAY_INFO => GetDisplayInfo(cmd.get_ref(0)?.load()),
-               VIRTIO_GPU_CMD_RESOURCE_CREATE_2D => ResourceCreate2d(cmd.get_ref(0)?.load()),
-               VIRTIO_GPU_CMD_RESOURCE_UNREF => ResourceUnref(cmd.get_ref(0)?.load()),
-               VIRTIO_GPU_CMD_SET_SCANOUT => SetScanout(cmd.get_ref(0)?.load()),
-               VIRTIO_GPU_CMD_RESOURCE_FLUSH => ResourceFlush(cmd.get_ref(0)?.load()),
-               VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D => TransferToHost2d(cmd.get_ref(0)?.load()),
-               VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING => {
-                   ResourceAttachBacking(cmd.get_ref(0)?.load())
-               }
-               VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING => {
-                   ResourceDetachBacking(cmd.get_ref(0)?.load())
-               }
-               VIRTIO_GPU_CMD_GET_CAPSET_INFO => GetCapsetInfo(cmd.get_ref(0)?.load()),
-               VIRTIO_GPU_CMD_GET_CAPSET => GetCapset(cmd.get_ref(0)?.load()),
-               VIRTIO_GPU_CMD_CTX_CREATE => CtxCreate(cmd.get_ref(0)?.load()),
-               VIRTIO_GPU_CMD_CTX_DESTROY => CtxDestroy(cmd.get_ref(0)?.load()),
-               VIRTIO_GPU_CMD_CTX_ATTACH_RESOURCE => CtxAttachResource(cmd.get_ref(0)?.load()),
-               VIRTIO_GPU_CMD_CTX_DETACH_RESOURCE => CtxDetachResource(cmd.get_ref(0)?.load()),
-               VIRTIO_GPU_CMD_RESOURCE_CREATE_3D => ResourceCreate3d(cmd.get_ref(0)?.load()),
-               VIRTIO_GPU_CMD_TRANSFER_TO_HOST_3D => TransferToHost3d(cmd.get_ref(0)?.load()),
-               VIRTIO_GPU_CMD_TRANSFER_FROM_HOST_3D => TransferFromHost3d(cmd.get_ref(0)?.load()),
-               VIRTIO_GPU_CMD_SUBMIT_3D => CmdSubmit3d(cmd.get_ref(0)?.load()),
-               VIRTIO_GPU_CMD_UPDATE_CURSOR => UpdateCursor(cmd.get_ref(0)?.load()),
-               VIRTIO_GPU_CMD_MOVE_CURSOR => MoveCursor(cmd.get_ref(0)?.load()),
-               _ => return Err(GpuCommandDecodeError::InvalidType(hdr.type_.into())),
-           })
+            VIRTIO_GPU_CMD_GET_DISPLAY_INFO => GetDisplayInfo(cmd.get_ref(0)?.load()),
+            VIRTIO_GPU_CMD_RESOURCE_CREATE_2D => ResourceCreate2d(cmd.get_ref(0)?.load()),
+            VIRTIO_GPU_CMD_RESOURCE_UNREF => ResourceUnref(cmd.get_ref(0)?.load()),
+            VIRTIO_GPU_CMD_SET_SCANOUT => SetScanout(cmd.get_ref(0)?.load()),
+            VIRTIO_GPU_CMD_RESOURCE_FLUSH => ResourceFlush(cmd.get_ref(0)?.load()),
+            VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D => TransferToHost2d(cmd.get_ref(0)?.load()),
+            VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING => ResourceAttachBacking(cmd.get_ref(0)?.load()),
+            VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING => ResourceDetachBacking(cmd.get_ref(0)?.load()),
+            VIRTIO_GPU_CMD_GET_CAPSET_INFO => GetCapsetInfo(cmd.get_ref(0)?.load()),
+            VIRTIO_GPU_CMD_GET_CAPSET => GetCapset(cmd.get_ref(0)?.load()),
+            VIRTIO_GPU_CMD_CTX_CREATE => CtxCreate(cmd.get_ref(0)?.load()),
+            VIRTIO_GPU_CMD_CTX_DESTROY => CtxDestroy(cmd.get_ref(0)?.load()),
+            VIRTIO_GPU_CMD_CTX_ATTACH_RESOURCE => CtxAttachResource(cmd.get_ref(0)?.load()),
+            VIRTIO_GPU_CMD_CTX_DETACH_RESOURCE => CtxDetachResource(cmd.get_ref(0)?.load()),
+            VIRTIO_GPU_CMD_RESOURCE_CREATE_3D => ResourceCreate3d(cmd.get_ref(0)?.load()),
+            VIRTIO_GPU_CMD_TRANSFER_TO_HOST_3D => TransferToHost3d(cmd.get_ref(0)?.load()),
+            VIRTIO_GPU_CMD_TRANSFER_FROM_HOST_3D => TransferFromHost3d(cmd.get_ref(0)?.load()),
+            VIRTIO_GPU_CMD_SUBMIT_3D => CmdSubmit3d(cmd.get_ref(0)?.load()),
+            VIRTIO_GPU_CMD_UPDATE_CURSOR => UpdateCursor(cmd.get_ref(0)?.load()),
+            VIRTIO_GPU_CMD_MOVE_CURSOR => MoveCursor(cmd.get_ref(0)?.load()),
+            _ => return Err(GpuCommandDecodeError::InvalidType(hdr.type_.into())),
+        })
     }
 
     /// Gets the generic `virtio_gpu_ctrl_hdr` from this command.
@@ -604,12 +599,13 @@ impl From<VolatileMemoryError> for GpuResponseEncodeError {
 
 impl GpuResponse {
     /// Encodes a this `GpuResponse` into `resp` and the given set of metadata.
-    pub fn encode(&self,
-                  flags: u32,
-                  fence_id: u64,
-                  ctx_id: u32,
-                  resp: VolatileSlice)
-                  -> Result<u32, GpuResponseEncodeError> {
+    pub fn encode(
+        &self,
+        flags: u32,
+        fence_id: u64,
+        ctx_id: u32,
+        resp: VolatileSlice,
+    ) -> Result<u32, GpuResponseEncodeError> {
         let hdr = virtio_gpu_ctrl_hdr {
             type_: Le32::from(self.get_type()),
             flags: Le32::from(flags),
@@ -635,19 +631,19 @@ impl GpuResponse {
                 size_of_val(&disp_info)
             }
             &GpuResponse::OkCapsetInfo { id, version, size } => {
-                resp.get_ref(0)?
-                    .store(virtio_gpu_resp_capset_info {
-                               hdr,
-                               capset_id: Le32::from(id),
-                               capset_max_version: Le32::from(version),
-                               capset_max_size: Le32::from(size),
-                               padding: Le32::from(0),
-                           });
+                resp.get_ref(0)?.store(virtio_gpu_resp_capset_info {
+                    hdr,
+                    capset_id: Le32::from(id),
+                    capset_max_version: Le32::from(version),
+                    capset_max_size: Le32::from(size),
+                    padding: Le32::from(0),
+                });
                 size_of::<virtio_gpu_resp_capset_info>()
             }
             &GpuResponse::OkCapset(ref data) => {
                 resp.get_ref(0)?.store(hdr);
-                let resp_data_slice = resp.get_slice(size_of_val(&hdr) as u64, data.len() as u64)?;
+                let resp_data_slice =
+                    resp.get_slice(size_of_val(&hdr) as u64, data.len() as u64)?;
                 resp_data_slice.copy_from(data);
                 size_of_val(&hdr) + data.len()
             }