patches and low-level development discussion
 help / color / mirror / code / Atom feed
From: Puck Meerburg <puck@puckipedia.com>
To: devel@spectrum-os.org
Cc: Puck Meerburg <puck@puckipedia.com>
Subject: [RFC PATCH nixpkgs 1/4] cloud-hypervisor: workaround keymap mmap
Date: Fri, 30 Sep 2022 19:45:57 +0000	[thread overview]
Message-ID: <20220930194600.1033126-2-puck@puckipedia.com> (raw)
In-Reply-To: <20220930194600.1033126-1-puck@puckipedia.com>

See the commit message in the patch.

Signed-off-by: Puck Meerburg <puck@puckipedia.com>
---
 ...ry-mapping-shared-memory-as-RO-if-RW.patch | 57 +++++++++++++++++++
 .../cloud-hypervisor/default.nix              |  1 +
 2 files changed, 58 insertions(+)
 create mode 100644 pkgs/applications/virtualization/cloud-hypervisor/0004-virtio-devices-try-mapping-shared-memory-as-RO-if-RW.patch

diff --git a/pkgs/applications/virtualization/cloud-hypervisor/0004-virtio-devices-try-mapping-shared-memory-as-RO-if-RW.patch b/pkgs/applications/virtualization/cloud-hypervisor/0004-virtio-devices-try-mapping-shared-memory-as-RO-if-RW.patch
new file mode 100644
index 00000000000..e67d338af58
--- /dev/null
+++ b/pkgs/applications/virtualization/cloud-hypervisor/0004-virtio-devices-try-mapping-shared-memory-as-RO-if-RW.patch
@@ -0,0 +1,57 @@
+From 165787d5cb1969fe855b8fa96d964efeefb96d94 Mon Sep 17 00:00:00 2001
+From: Puck Meerburg <puck@puckipedia.com>
+Date: Fri, 30 Sep 2022 14:10:27 +0000
+Subject: [PATCH 4/4] virtio-devices: try mapping shared memory as RO if RW
+ fails
+
+wlroots' keymaps are read-only, and crosvm does not properly handle
+this, causing cloud-hypervisor to crash. Work around this for now by
+retrying any mmap as read-only if read-write mapping fails.
+---
+ virtio-devices/src/vhost_user/gpu.rs | 17 ++++++++++++++++-
+ 1 file changed, 16 insertions(+), 1 deletion(-)
+
+diff --git a/virtio-devices/src/vhost_user/gpu.rs b/virtio-devices/src/vhost_user/gpu.rs
+index b0a9ee7c..2eb18445 100644
+--- a/virtio-devices/src/vhost_user/gpu.rs
++++ b/virtio-devices/src/vhost_user/gpu.rs
+@@ -1,5 +1,6 @@
+ // Copyright 2019 Intel Corporation. All Rights Reserved.
+ // Copyright 2022 Unikie
++// Copyright 2022 Puck Meerburg
+ // SPDX-License-Identifier: Apache-2.0
+ 
+ use crate::seccomp_filters::Thread;
+@@ -59,7 +60,7 @@ impl VhostUserMasterReqHandler for SlaveReqHandler {
+         }
+ 
+         let addr = self.mmap_cache_addr + req.shm_offset;
+-        let ret = unsafe {
++        let mut ret = unsafe {
+             libc::mmap(
+                 addr as *mut libc::c_void,
+                 req.len as usize,
+@@ -69,6 +70,20 @@ impl VhostUserMasterReqHandler for SlaveReqHandler {
+                 req.fd_offset as libc::off_t,
+             )
+         };
++
++        if ret == libc::MAP_FAILED {
++            ret = unsafe {
++                libc::mmap(
++                    addr as *mut libc::c_void,
++                    req.len as usize,
++                    (req.flags.bits() as i32) & !libc::PROT_WRITE,
++                    libc::MAP_SHARED | libc::MAP_FIXED,
++                    fd.as_raw_fd(),
++                    req.fd_offset as libc::off_t,
++                )
++            };
++        }
++
+         if ret == libc::MAP_FAILED {
+             return Err(io::Error::last_os_error());
+         }
+-- 
+2.35.1
+
diff --git a/pkgs/applications/virtualization/cloud-hypervisor/default.nix b/pkgs/applications/virtualization/cloud-hypervisor/default.nix
index d4fc8d46265..17e344e67e8 100644
--- a/pkgs/applications/virtualization/cloud-hypervisor/default.nix
+++ b/pkgs/applications/virtualization/cloud-hypervisor/default.nix
@@ -39,6 +39,7 @@ rustPlatform.buildRustPackage rec {
     ./0001-build-use-local-vhost.patch
     ./0002-build-use-local-virtio-bindings.patch
     ./0003-virtio-devices-add-a-vhost-user-gpu-device.patch
+    ./0004-virtio-devices-try-mapping-shared-memory-as-RO-if-RW.patch
   ];
 
   vhostPatches = [
-- 
2.35.1



  reply	other threads:[~2022-09-30 19:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-30 19:45 [RFC PATCH nixpkgs 0/4] Wayland security-context support Puck Meerburg
2022-09-30 19:45 ` Puck Meerburg [this message]
2022-09-30 19:45 ` [RFC PATCH nixpkgs 2/4] wlroots: apply security-context patches Puck Meerburg
2022-09-30 19:45 ` [RFC PATCH nixpkgs 3/4] sway: " Puck Meerburg
2022-09-30 19:46 ` [RFC PATCH nixpkgs 4/4] crosvm: " Puck Meerburg
2022-09-30 22:08 ` [RFC PATCH nixpkgs 0/4] Wayland security-context support Puck Meerburg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220930194600.1033126-2-puck@puckipedia.com \
    --to=puck@puckipedia.com \
    --cc=devel@spectrum-os.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/crosvm
	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/nixpkgs
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock
	https://spectrum-os.org/git/www

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).