From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on atuin.qyliss.net X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from atuin.qyliss.net (localhost [IPv6:::1]) by atuin.qyliss.net (Postfix) with ESMTP id CA75971BB5; Fri, 30 Sep 2022 19:48:50 +0000 (UTC) Received: by atuin.qyliss.net (Postfix, from userid 496) id E15D071B8E; Fri, 30 Sep 2022 19:48:48 +0000 (UTC) Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) by atuin.qyliss.net (Postfix) with ESMTPS id 05A2F71B89 for ; Fri, 30 Sep 2022 19:48:46 +0000 (UTC) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 9E6EE3200A1D; Fri, 30 Sep 2022 15:48:44 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Fri, 30 Sep 2022 15:48:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=puckipedia.com; h=cc:cc:content-transfer-encoding:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1664567324; x= 1664653724; bh=GWaCJPEIlgdq8TZvpClxrdOZd4al5r5zSpahmO4FUAo=; b=F TSbl0XAeRTP4im6lpj/TaaGx16H/vZhFIyCncRLnj8DIlItKdzq39s1aEXYn+64U fiV8I1WmA2vVFGK56jlqQ2XLnRjBRSrFF26HZC2nj4etL7MwVBbWa7/L60JeITYf pUW43jxpVT/b7/JdZ85Mm6adHvlevA8nGosl2bIAFABs/5b9GwWF2Dkf1ynoSi3d YBcZTjEeod7P764FtFiuxbKmPhtVzZMhgDpjfAtcsgjKgVEfMZ3xOUJXx/rx4pFq dTt1TAzFPOLY8HwKIVMOd46Tq5XGaI5CiDLiVDRS2S0b3S7fXCNeGlLyKcTdYhRX ZghM8pSH2PS814Pm8KGiw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1664567324; x=1664653724; bh=GWaCJPEIlgdq8 TZvpClxrdOZd4al5r5zSpahmO4FUAo=; b=UtAXSG7i0EG6sj4zW71k/ydFpfQ+c 6ozPnAYsgTYoynQNzxKlxugGTorhWKotd0fN4iomRO71t01JP0Ct0IO3OAECLhMY rLu5tmuvGBQVvaeqj2zxZTMLK2gPG/RE98grR3yNu/IOysSfEuHz+4NoqFLsXRkD hl8LcGioBTcFBJpUaUNADknEzhSZADLg3Z5+VIxFRFlBYp4vdKU4Avc+G9cVkqG0 uTC/o8fUpouqKBxSmWJjOpQAAPQrpA7BCC0awk0mWLCea9//OmLHf4gQIv1dASMn 2LrYrDE7XAqP0fyGLFMKvX7oLPmKR6ldxFwuF/6dlh0HYtL8gVzf56HXg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfeehvddgudegvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestd ekredtredttdenucfhrhhomheprfhutghkucfovggvrhgsuhhrghcuoehpuhgtkhesphhu tghkihhpvgguihgrrdgtohhmqeenucggtffrrghtthgvrhhnpedutdffledvueeikeevge evffekieeuleehuedvtdetvdegleehvdevvdffveeghfenucevlhhushhtvghrufhiiigv pedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpuhgtkhesphhutghkihhpvgguihgrrd gtohhm X-ME-Proxy: Feedback-ID: ie69944d9:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Sep 2022 15:48:43 -0400 (EDT) From: Puck Meerburg To: devel@spectrum-os.org Subject: [RFC PATCH nixpkgs 1/4] cloud-hypervisor: workaround keymap mmap Date: Fri, 30 Sep 2022 19:45:57 +0000 Message-Id: <20220930194600.1033126-2-puck@puckipedia.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220930194600.1033126-1-puck@puckipedia.com> References: <20220930194600.1033126-1-puck@puckipedia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: VMD4AP2Q4TD2PDWOMZPNN7ARJ65WJLLP X-Message-ID-Hash: VMD4AP2Q4TD2PDWOMZPNN7ARJ65WJLLP X-MailFrom: puck@puckipedia.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-devel.spectrum-os.org-0; header-match-devel.spectrum-os.org-1; header-match-devel.spectrum-os.org-2; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Puck Meerburg X-Mailman-Version: 3.3.5 Precedence: list List-Id: Patches and low-level development discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: See the commit message in the patch. Signed-off-by: Puck Meerburg --- ...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 +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