From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.3 (2019-12-06) on atuin.qyliss.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FORGED_SPF_HELO,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.3 Received: by atuin.qyliss.net (Postfix, from userid 496) id C4C1017F; Mon, 27 Jul 2020 18:39:33 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by atuin.qyliss.net (Postfix) with ESMTP id 91585170; Mon, 27 Jul 2020 18:39:28 +0000 (UTC) Received: by atuin.qyliss.net (Postfix, from userid 496) id 84571165; Mon, 27 Jul 2020 18:39:26 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10olkn2075.outbound.protection.outlook.com [40.92.42.75]) by atuin.qyliss.net (Postfix) with ESMTPS id 1C405163 for ; Mon, 27 Jul 2020 18:39:24 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hhuzBKSwkLDJVYAMVAC0IRDflO9PgPzArs1HleMUpkMbLrqNfo6tq6fdNGiYLj4JXpNkDINvpbpz02FfdSWHeSza5jeKQrAaRmXMkSXm8O1r3pDDdcEpZDHAV9xMKbweduSHQJIjda7dw5RQ7Aex9AeHiL+9BTPqjvBBlNI5uPX3ZduNNeNaMyRTTQWFrnc0HBCwYg9mUe0owicvos2QfRMghQDG2BwwfjYaj+VPPh1iczMlgv6A3vKSPSks5hhJJdogMO0x/7zGHtn+KJvmQLztwry6NIrbm/uz6A9K09lRTtYOVmaIyWsEaxVudjjqhtEz68dvvXzxmW5LdFmQPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YOMGkxZNTLJGVB6MDsaZzxvMii97nVr8fHGFabw2bJA=; b=GgaM+BcZuxjHjmsLtrnfWVwQRF1w92x1xl8qbua3X3vpYf1nyr6omuKE9o/70ITjSX46r9FEVzNBZo2WBZ5vSyCTtzQ/2bwgLVQEfYXVoebmkVNalDVeE/D8U8N3wAUeV/PB5P7YJUyIAL+ueQX03DvpeKdQnvxFwM+xtQtxk80lRwZWdl3328UMhLx+nZv25sEgATmYXVqWBrOsP3Xqs20U2zBSIPrVeLqX5l7joZasAXZX98dwKSJ4t9gkqSqH3giZ8VqYCD+qmqmG7fJkUYG052hO2OLuACx9coDSrCYkzoFEnweO9Xm+PPeLD9Qd41ieiPwitXIUWHOK0hzPEw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YOMGkxZNTLJGVB6MDsaZzxvMii97nVr8fHGFabw2bJA=; b=j6r91T90A84TEZiTNlt+B7534fn1JX4xyrxlfmbk7ZieCtpeWeXb1LpCgwXA4d4zUg8a/N3G0g11If5O8L6XKC9GuwFbnfndxuG26lNHLKhJGyMHiKwE3DvZiEnjjbFJfwCBm8MDeo/9ZcB5tDmVvLVwmJCd0AyoY95zJA9LTbIEVMdxgH6tteMW9R+pzqCq3NzY3uqGd1v9dJP2zbaUNcERXxS5jqAayeoG6RozGQuv4yB2D4g45ndNHmjJDNRUCRScyHvJFFY/Q6hI2SNiHvveOPTlAxCpHWrsxSc1WN94eLoL+2K6epWAA20fZG/nI2e5EGHS+AU+3a/uiMZ69Q== Received: from DM6NAM10FT048.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e86::48) by DM6NAM10HT020.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e86::370) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.10; Mon, 27 Jul 2020 18:39:21 +0000 Received: from SJ0PR03MB5581.namprd03.prod.outlook.com (2a01:111:e400:7e86::47) by DM6NAM10FT048.mail.protection.outlook.com (2a01:111:e400:7e86::204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.10 via Frontend Transport; Mon, 27 Jul 2020 18:39:21 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:598DEDEC8CF4460911A8F96CA92B5DDD471EDF08A72727B09D0805CFCDD028D0;UpperCasedChecksum:9A89DBB9FFC66546A6B62F4328870986E8F77C69A82A8E8AEF1402DA4F112BEC;SizeAsReceived:8575;Count:46 Received: from SJ0PR03MB5581.namprd03.prod.outlook.com ([fe80::61c9:c99c:bd8f:cbd6]) by SJ0PR03MB5581.namprd03.prod.outlook.com ([fe80::61c9:c99c:bd8f:cbd6%8]) with mapi id 15.20.3216.033; Mon, 27 Jul 2020 18:39:21 +0000 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 To: "Alyssa Ross" , Subject: Re: [PATCH wayland v3] Support virtio_wl display sockets From: "Cole Helbling" Date: Mon, 27 Jul 2020 11:37:42 -0700 Message-ID: In-Reply-To: <20200726060358.24277-1-hi@alyssa.is> X-ClientProxiedBy: BYAPR02CA0042.namprd02.prod.outlook.com (2603:10b6:a03:54::19) To SJ0PR03MB5581.namprd03.prod.outlook.com (2603:10b6:a03:27b::20) X-Microsoft-Original-Message-ID: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (67.187.170.40) by BYAPR02CA0042.namprd02.prod.outlook.com (2603:10b6:a03:54::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.20 via Frontend Transport; Mon, 27 Jul 2020 18:39:20 +0000 X-Microsoft-Original-Message-ID: X-TMN: [K/1+nqhrK9zJCJsRJz+uh7DqQj0NFcbY] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 46 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: fe274505-8112-45a9-98f8-08d8325c607d X-MS-Exchange-SLBlob-MailProps: zswcL9HXbeUednymnu7YEQo6fcBKstBW9QS4wMoJyPc5Ix8TwS1yVSGKvnj/wIVfI2eAODvRtPTP6AKSN3HqzAq2uhyJNDSGL7k9oMZNV5aF2rrdl9SB0UCb/XEzKS2ZDOzxEoejgA3yJBqdxTNwpMempwah8q0a9yC+kyPOevFwd9I/gH2teymNxWyfPD9Erc16SfQaxqYN6LsyCKf2HYVsjqLnPEsYgAReTfe66p+FzP/fBwJDPkq3s2CccQX/EA0MccvTzROOTaweN2QUpDXC5+sdvWg/qZj4XJ1ooZb1mY3tq8X4Ai/6/KQbxynIfqzauoh/2F1/C9kxSpwrc9pVlfXrKKPrE2HEErafVfzU6seY621Ej3GS9BhJtAYu7rM1ilNIbZp1Lqho3p8q1Tf7vkW26MJ2cH5aj+5/c1MGxr4KbQuvnH3drxR4SmXqgYTbnxoJmhw9eA5eK8y6C9f9uwHSMvOkO7ozNSkVf0SIanxQbXUSssvTgZy7B9RurRNXA84a33+69jHhYiU28mScGt72HGusX/6jogdgOiPrxtYUYSo7y7NpCgal8sGNsGEANnANjdi+QGShK5ExloKQRis7b+BdaE1Z/OvTT+2VxYZ0J/96IQdcmOFqd6cxg2yfud7Y0ezSNKIdSJOAz1zkF+7C13PnIxaWLdIWd1olOXsXB+8+J0KcFvVJJOSALQmBWJMwAYZYP2e30jxD/geq2KoyvGHsFCnaWlgDG6Ph7w9MkD6OuIBiyHM8jjDL X-MS-TrafficTypeDiagnostic: DM6NAM10HT020: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fxAla+Ss4sdxUkHPInb8YgmsRDJpx35n7iN7iGq/yGXfkE+0lzffmDdJg94lZbsb7nF1uFwWp8YhSI0fS+8y5kAmt3AGd0GCHTVtF8sETn1cxZY0Shsb4KMFDO/oo84ZPr/AIpe+JVFcQcxIuGfCMHnqk0fPXw+Eitg29KYe6aGFssAVNQ78ZFilng6ZW96jp+21WZmB9scuBBsRn1Im1w== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:0;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR03MB5581.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:;DIR:OUT;SFP:1901; X-MS-Exchange-AntiSpam-MessageData: KAILbuDQkprLlzENkDAx7FtheIDHzuFvfdVu+eE4XINHrI+Nev2XhBomq+e2ciCLmMR11cdEup/GxgpFQRbimV/pJb0VjWvFV5AFRH0F0OinKE1vsTzrwQ3ZE/Azt3ZXYlhIqB4omGN3BGV5JU8C0A== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: fe274505-8112-45a9-98f8-08d8325c607d X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 18:39:21.1851 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: DM6NAM10FT048.eop-nam10.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6NAM10HT020 Message-ID-Hash: Y2I45HRXMYZAWKIBGQ3DHPSTUZLYB2NV X-Message-ID-Hash: Y2I45HRXMYZAWKIBGQ3DHPSTUZLYB2NV X-MailFrom: cole.e.helbling@outlook.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Cole Helbling X-Mailman-Version: 3.3.1 Precedence: list List-Id: Patches and low-level development discussion Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: On Sat Jul 25, 2020 at 11:03 PM PDT, Alyssa Ross wrote: > This patch adds libvirtio_wl, which exposes reimplementations of the > sendmsg(2) and recvmsg(2) for virtio_wl socket fds. Tests for as much > libvirtio_wl functionality as is reasonably possible to test without > requiring a working virtio_wl connection are included. (Testing > further would require running tests in a VM so that they could talk to > the virtio_wl kernel driver, which would be prohibitively complex. > > virtio_wl socket fds do not actually point to sockets, but to special > virtio_wl files. Whenever a display socket operation calls sendmsg() > or recvmsg() with a file descriptor and receives an ENOTSOCK error, it > retries the operation with the equivalent libvirtio_wl function, in > case the file descriptor is a virtio_wl. This is the least invasive > way to implement virtio_wl support -- if a normal socket is being > used, there will be no change in behaviour. > > Because virtio_wl doesn't implement every socket feature, some > workarounds are currently required to accomodate everything Wayland > expects of sockets: > > * virtio_wl_recvmsg implements the MSG_DONTWAIT flag by setting > O_NONBLOCK on the fd, attempting the VIRTWL_IOCTL_RECV operation, > and then restoring the fd's original flags. This is obviously > race-prone, but there is no reasonable alternative at present. > > * virtio_wl_sendmsg requires MSG_NOSIGNAL to be set, and ignores it. > This is because I think from looking at the code that virtio_wl does > not generate SIGPIPE signals, nor does it ever return EPIPE. I > could be wrong about this, though. > > * virtio_wl does not support credential passing -- what would it even > mean, considering the other end of the connection is on > another (virtual) machine? So wl_client's ucred member will have > pid, uid, and gid all set to -1 for a client connected over > virtio_wl. > > * virtio_wl sockets do not support accept(2), so a fallback is used. > A proxy program on the host accept(2) on a host socket. When it > receives a connection, it attaches the connection socket to the VM, > then sends the name of the connected socket over the Wayland display > socket. Wayland then receives this name, looks up the connection > socket, and uses that as the client connection socket. > > Additionally, virtio_wl memfd-like file descriptors don't support > mremap(2), so for virtio_wl sockets Wayland will munmap(2) the memfd, > and then mmap(2) it again. This should be at least mostly okay > because Wayland only ever calls mremap with MREMAP_MAYMOVE, but it is > still race-prone. To be able to do this, memfds are no longer closed > after being mmaped, but are kept around in the wl_shm_pool struct, so > that they can be passed to mmap() if required. > > This patch appears to be enough to reliably run Alacritty on the host > system, > with a Wayland compositor running in a VM. It is not capable of running > Firefox, which most of the time fails to start, and occassionally will > partially > start (sometimes even getting far enough to draw a window) before > freezing. > --- > Cole pointed out on IRC that previous versions of this patch > unnecessarily included string.h and stdio.h in src/wayland.os.c. > These includes have now been removed. > > src/connection.c | 4 + > src/meson.build | 16 +- > src/virtio_wl.c | 344 +++++++++++++++++++++++ > src/virtio_wl.h | 23 ++ > src/wayland-os.c | 21 ++ > src/wayland-os.h | 3 + > src/wayland-server.c | 20 +- > src/wayland-shm.c | 24 +- > tests/meson.build | 1 + > tests/virtio_wl-test.c | 615 +++++++++++++++++++++++++++++++++++++++++ > 10 files changed, 1062 insertions(+), 9 deletions(-) > create mode 100644 src/virtio_wl.c > create mode 100644 src/virtio_wl.h > create mode 100644 tests/virtio_wl-test.c Style and friends LGTM. As before, I'm not that great at grokking C, so I'll just hope you know what you are doing. :P Reviewed-by: Cole Helbling