Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp256023pxj; Thu, 3 Jun 2021 06:03:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+RNF/M3+FDmeJZ+cJ39zA9ffkRQyG7x9Lf8C4mtaCGT/DN87e10yNP34G9LLOAcq4kzcU X-Received: by 2002:adf:e4cf:: with SMTP id v15mr20540850wrm.162.1622725407138; Thu, 03 Jun 2021 06:03:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622725407; cv=none; d=google.com; s=arc-20160816; b=DTRo6Cnv8gmKSxrPgpLOPnc/p3bb77Zzoz1Cy1IPEBq60kuu+vEW/XUWu+sIOQql3U hU5V9zAeVO+mr51dvbT0+83/pY8RCFBulsszlnhqOo6lMAownxRBg8bn6jkZ1vsUD6eD Xr2V++NhoID/XyOtbCQBg+fxWAMjKmmQ+8gxYqOXnKrGpn+ZDxPEJkv69AznS30s5531 8cyJsVQslNWlcgOijiol0J7glHeyNjds3PQqyH1LNAqn0RVp+DPgGdiWO8wtQRzkuX4n zdyK3m1xElRnk4zUhbB6+SxKqc/5jqk9yjfe5+fjFvjie8sJrko7IUzpL8YCITC3jRcs 4zsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:reply-to:cc:from:to :dkim-signature:date; bh=g5sGIL5X/dIixwzZThRSrnzhyX4qPO3WP6FfFa5urDI=; b=n75wYMp4r4q9SdJFCjJzAxafsYIo5rIv8iAvX8fqVSIxqFzFGQaIsOGaMvTNNv2nHo x0cwsBpljK5f6v2lAhW2ZkYTZJqH9/jcLb3wCytBSfdAXb8o20cTqC0DCiPwVD7sB1sq e4VodjHx0PPAyxQEUOAI5fHsHytPL3SkLrTKvGBDcsFOgyNq1EYgzI3h6zp82L88oZ07 bVfUVYQcE9+P9I65Z+R/1rnDqwoCQUl2nH9Ll0aVots93exxvMB7Gvit74vooy1q4ZxL SmYFBQfgld1+dWRq0HsrXNAMPy2Aqe+laiIcaeNIaxvLDrNpHBe2lvrFqejYhCd6zjyB NG6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@emersion.fr header.s=protonmail3 header.b=U+ebCt29; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=emersion.fr Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j6si49644ejo.403.2021.06.03.06.03.03; Thu, 03 Jun 2021 06:03:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@emersion.fr header.s=protonmail3 header.b=U+ebCt29; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=emersion.fr Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230008AbhFCNCy (ORCPT + 99 others); Thu, 3 Jun 2021 09:02:54 -0400 Received: from mail2.protonmail.ch ([185.70.40.22]:22510 "EHLO mail2.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229801AbhFCNCx (ORCPT ); Thu, 3 Jun 2021 09:02:53 -0400 Date: Thu, 03 Jun 2021 13:01:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emersion.fr; s=protonmail3; t=1622725266; bh=g5sGIL5X/dIixwzZThRSrnzhyX4qPO3WP6FfFa5urDI=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=U+ebCt29XcCUOVQmAKecrKW5cJJH1m2/GrTsXodWhZ8hC3qxWTFmMYm0caVgO0YZF F5Rbv7z64pujOuEjj3FrpFU4uWGpD14HSYAI/pcPh31T50n5zlVURdOiX/A0h43wKS aEvw0cJbgxLFMhLvSZsFufN1qgvWeJZ8Atj7rpSXLarXql90AjGGHezF3XdfJ4ds/0 IEvHCtyDqJwRzqoWFeOYJXTIjDSnvFIJK8bGjRvslX9TLWkLEg+coa5mgB38iJq34A eaZ1pqtkJuTqRQ1mAm2zwaaBGGLYLWqdzNhOUs5mo2DG3wti30tSZml7knY9ZRFNHO cvkAEZj2rFtiw== To: Ming Lin From: Simon Ser Cc: Linus Torvalds , Hugh Dickins , Peter Xu , "Kirill A. Shutemov" , Matthew Wilcox , Dan Williams , "Kirill A. Shutemov" , Will Deacon , Linux Kernel Mailing List , David Herrmann , "linux-mm@kvack.org" , Greg Kroah-Hartman , "tytso@mit.edu" Reply-To: Simon Ser Subject: Re: Sealed memfd & no-fault mmap Message-ID: <8By7yERxX_qlsLZuOeJihJqeU-pZtFxsS2zrQ1ssN6-NkyIRrv-r81Ux_PTcb8qy7QA1HmkRxTeixT5MaJs7NKk0rqxDC9Nu9DoTRmS0UHw=@emersion.fr> In-Reply-To: <0464f8dd-d082-b246-83ff-609f0f48de59@gmail.com> References: <80c87e6b-6050-bf23-2185-ded408df4d0f@gmail.com> <36fc2485-11f1-5252-904d-f26b63a6cd58@gmail.com> <0464f8dd-d082-b246-83ff-609f0f48de59@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mailout.protonmail.ch Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tuesday, June 1st, 2021 at 9:08 AM, Ming Lin wrote: > On 5/31/2021 11:24 PM, Linus Torvalds wrote: > > On Mon, May 31, 2021 at 11:13 AM Ming Lin wrote: > >> > >> OK, I borrowed code from filemap_xip.c and implemented this behavior. > > > > I think that "unmap page" is too complicated and fragile. > > > > The only page that could possibly validly be unmapped is a stale zero > > page, but that code in shmem_unmap_nofault_page() seems to try to > > handle other cases too (ie that whole page_remove_rmap() - afaik a > > zero page has no rmap). > > > > I get the feeling that the simpler thing to do is to just say "if you > > use MAP_NOSIGBUS, and you access pages that don't have a backing > > store, you will get zero pages, and they will NOT BE SYNCHRONIZED with > > the backing store possibly later being updated". > > > > IOW, just document the fact that a MAP_NOSIGBUS mapping isn't coherent > > wrt shmem contents that are expanded and filled in later. > > > > Don't try to "fix" it - because any user that uses MAP_NOSIGBUS had > > better just accept that it's not compatible with expanding the shmem > > backing store later. > > > > Keep it simple and stupid. Hmm? > > Simon, > > Is this "simple" solution good enough for Wayland compositor use case? I've tried your patch "mm: adds MAP_NOSIGBUS extension for shmem read" with= a libwayland hack [1] and a Wayland client that shrinks a shm file after the compositor has mmap'ed it [2]. It seems to work nicely, thanks! Regarding the requirements for Wayland: - The baseline requirement is being able to avoid SIGBUS for read-only mapp= ings of shm files. - Wayland clients can expand their shm files. However the compositor doesn'= t need to immediately access the new expanded region. The client will tell = the compositor what the new shm file size is, and the compositor will re-map = it. - Ideally, MAP_NOSIGBUS would work on PROT_WRITE + MAP_SHARED mappings (of course, the no-SIGBUS behavior would be restricted to that mapping). The use-case is writing back to client buffers e.g. for screen capture. From = the earlier discussions it seems like this would be complicated to implement. This means we'll need to come up with a new libwayland API to allow compositors to opt-in to the read-only mappings. This is sub-optimal but seems doable. - Ideally, MAP_SIGBUS wouldn't be restricted to shm. There are use-cases fo= r using it on ordinary files too, e.g. for sharing ICC profiles. But from t= he earlier replies it seems very unlikely that this will become possible, an= d making it work only on shm files would already be fantastic. Thanks again for working on this! Let me know if the above is unclear or if some info is missing. Simon [1]: https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/145 [2]: https://github.com/emersion/wleird/blob/master/sigbus.c