crosvm: bind mount all wayland socket directories (take 3)

In 781d975d0bc6 ("Revert "Revert "rutabaga_gfx: cross-domain: a
new year's miracle in February""), we went back to just bind mount
the wayland socket instead of all the sockets.

The logs indicated a weird interaction between the camera socket
and the Mali driver.

This is incorrect, and I would like to this opportunity to apologize
to the camera team for this outrageous slander.  I'm sorry.  Please
forgive me.  I hope we can put this behind us.

In the end, we were just mounting the wrong directories.

BUG=b:150239451, b:173630595
TEST=arc.Boot.vm

Change-Id: I5e5d5afba074c3aaed79df058558a295d03732f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2906128
Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
diff --git a/src/linux.rs b/src/linux.rs
index 7bad24e..27b4d98 100644
--- a/src/linux.rs
+++ b/src/linux.rs
@@ -864,21 +864,22 @@
     map_request: Arc<Mutex<Option<ExternalMapping>>>,
     mem: &GuestMemory,
 ) -> DeviceResult {
-    let jailed_wayland_path = Path::new("/wayland-0");
-
     let mut display_backends = vec![
         virtio::DisplayBackend::X(x_display),
         virtio::DisplayBackend::Stub,
     ];
 
+    let wayland_socket_dirs = cfg
+        .wayland_socket_paths
+        .iter()
+        .map(|(_name, path)| path.parent())
+        .collect::<Option<Vec<_>>>()
+        .ok_or(Error::InvalidWaylandPath)?;
+
     if let Some(socket_path) = wayland_socket_path {
         display_backends.insert(
             0,
-            virtio::DisplayBackend::Wayland(if cfg.sandbox {
-                Some(jailed_wayland_path.to_owned())
-            } else {
-                Some(socket_path.to_owned())
-            }),
+            virtio::DisplayBackend::Wayland(Some(socket_path.to_owned())),
         );
     }
 
@@ -976,13 +977,12 @@
                 }
             }
 
-            // Bind mount the wayland socket into jail's root. This is necessary since each
-            // new wayland context must open() the socket.  Don't bind mount the camera socket
-            // since it seems to cause problems on ARCVM (b/180126126) + Mali.  It's unclear if
-            // camera team will opt for virtio-camera or continue using virtio-wl, so this should
-            // be fine for now.
-            if let Some(path) = wayland_socket_path {
-                jail.mount_bind(path, jailed_wayland_path, true)?;
+            // Bind mount the wayland socket's directory into jail's root. This is necessary since
+            // each new wayland context must open() the socket. If the wayland socket is ever
+            // destroyed and remade in the same host directory, new connections will be possible
+            // without restarting the wayland device.
+            for dir in &wayland_socket_dirs {
+                jail.mount_bind(dir, dir, true)?;
             }
 
             add_crosvm_user_to_jail(&mut jail, "gpu")?;