patches and low-level development discussion
 help / color / mirror / code / Atom feed
blob e67d338af58d2aa707236224ca4b35c38746e745 1978 bytes (raw)
name: pkgs/applications/virtualization/cloud-hypervisor/0004-virtio-devices-try-mapping-shared-memory-as-RO-if-RW.patch 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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


debug log:

solving e67d338af58 ...
found e67d338af58 in https://inbox.spectrum-os.org/spectrum-devel/20220930194600.1033126-2-puck@puckipedia.com/

applying [1/1] https://inbox.spectrum-os.org/spectrum-devel/20220930194600.1033126-2-puck@puckipedia.com/
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

1:29: trailing whitespace.
 
1:33: trailing whitespace.
 
1:61: trailing whitespace.
-- 
Checking patch pkgs/applications/virtualization/cloud-hypervisor/0004-virtio-devices-try-mapping-shared-memory-as-RO-if-RW.patch...
1:63: new blank line at EOF.
+
Applied patch pkgs/applications/virtualization/cloud-hypervisor/0004-virtio-devices-try-mapping-shared-memory-as-RO-if-RW.patch cleanly.
warning: 4 lines add whitespace errors.

index at:
100644 e67d338af58d2aa707236224ca4b35c38746e745	pkgs/applications/virtualization/cloud-hypervisor/0004-virtio-devices-try-mapping-shared-memory-as-RO-if-RW.patch

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

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).