Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp267796pxj; Thu, 3 Jun 2021 06:17:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSrfjjxsuOVJQdksgle9mlvBu7xulAs4ezSXSk0Py6WOM9QtxqxDGIXO66Km/cknkUof0c X-Received: by 2002:a5d:6e0d:: with SMTP id h13mr39155613wrz.118.1622726246475; Thu, 03 Jun 2021 06:17:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622726246; cv=none; d=google.com; s=arc-20160816; b=spdYFfNiRCabSiNFwPex4YLkWxEVgcHRF4xtarhiZea81y3zfL2axrRNdcCJZpk47E XXxBMw0haf2jHoRyjfaca1NSYhlWbJPxBVnUoZoMVObIZa8k+FgTT3/RLXH3rWpwEwq2 gSU09wNp3xAQ0ARnJHYysMpg3torscBnpYxc/fFsnkCiEWhPtam/xwj0mepWh4b6z5sW uKYf4TFUd851gcbiM5lpfkBc5jARh6nAz2WE6usm0TG6/XbrT6wt2l01lOu0g/+i/ra4 bHRPWXjSJfGaXxQOHhzT1QGkRRP4dHLUJGP5Zyy600YrqAF6hmq+z2dhELiDTM1lpyPT BsfA== 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=zvZG+KNrKsbetpCBgPErfPJwO6MpNxHlXwG7DMuT3J4=; b=pEqlJ2w4TxLxYs4IC2CfyXblinXwhtohOhniAoubFMqksG4QS4vuMLpcMywziU2/Kg dhQqvZlQwDZpHMGS+/OvFkKsZDYolZeIeiZPL1r6B/nAa8wQ+jqKPZyluAV2/wUlW+P/ nPn0beq634FJL2N5wGiBhP51o1VntPSYuONSxDwn4TyeNz3Jv0kTtrJ+SEiTzlvc5pFZ snkvtBKA20DkL1UcDrVwIZU6k/SQg05AkTcM99We25lkDwf8Uou28uIINCi464ghOQr3 GLlWbqShaOYhQ0/VrOt+hNfQnNOIJDC/be79zoagDJT7V/kuwXJrdxWLus8Ij7rDd47T BaKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@emersion.fr header.s=protonmail3 header.b="KLrPCUk/"; 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 nb19si2452649ejc.713.2021.06.03.06.17.03; Thu, 03 Jun 2021 06:17:26 -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="KLrPCUk/"; 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 S231258AbhFCNQg (ORCPT + 99 others); Thu, 3 Jun 2021 09:16:36 -0400 Received: from mail1.protonmail.ch ([185.70.40.18]:57266 "EHLO mail1.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230252AbhFCNQf (ORCPT ); Thu, 3 Jun 2021 09:16:35 -0400 Date: Thu, 03 Jun 2021 13:14:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emersion.fr; s=protonmail3; t=1622726088; bh=zvZG+KNrKsbetpCBgPErfPJwO6MpNxHlXwG7DMuT3J4=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=KLrPCUk/xa/J4AxaB3vZpUw7LDGaakyDvn37cAL+jfr6vlg3jC9MKqq4hzM964NPJ rmUciJgUMX39tk9SLPMJFZk+tfBtXMpf7/nrMNMmX3rvnSLAG3zrE+97SAmhW0b+A5 WogkweWoBKYwmlq8mBE0WpdmRJNElUBKxUknUA48lODDpXmIB0KYKTgAeNKb9TvVQr ox1IHZ6HZ1llIuCu3Tc4gYYDnZRx/igojes/AqkbR7UU3321vI5dwusDAY1CQmgjNF M7AcT9L6ZKQd05h89IaNJd06AhsftywLt25vOHSMVBZTq4ZEnyu7NmOwASb5AqriVz 3pfpv8akEgz2A== To: Hugh Dickins From: Simon Ser Cc: Linus Torvalds , "Lin, Ming" , 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: In-Reply-To: References: <7718ec5b-0a9e-ffa6-16f2-bc0b6afbd9ab@gmail.com> <80c87e6b-6050-bf23-2185-ded408df4d0f@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 Saturday, May 29th, 2021 at 10:15 PM, Hugh Dickins wr= ote: > And IIUC it would have to be the recipient (Wayland compositor) doing > the NOFAULT business, because (going back to the original mail) we are > only considering this so that Wayland might satisfy clients who predate > or refuse Linux-only APIs. So, an ioctl (or fcntl, as sealing chose) > at the client end cannot be expected; and could not be relied on anyway. Yes, that is correct. > NOFAULT? Does BSD use "fault" differently, and in Linux terms we > would say NOSIGBUS to mean the same? > > Can someone point to a specification of BSD's __MAP_NOFAULT? > Searching just found me references to bugs. __MAP_NOFAULT isn't documented, sadly. The commit that introduces the flag [1] is the best we're going to get, I think. > What mainly worries me about the suggestion is: what happens to the > zero page inserted into NOFAULT mappings, when later a page for that > offset is created and added to page cache? Not 100% sure exactly this means what I think it means, but from my PoV, it's fine if the contents of an expanded shm file aren't visible from the process that has mapped it with MAP_NOFAULT/MAP_NOSIGBUS. In other words, it's fine if: - The client sets up a 1KiB shm file and sends it to the compositor. - The compositor maps it with MAP_NOFAULT/MAP_NOSIGBUS. - The client expands the file to 2KiB and writes interesting data in it. - The compositor still sees zeros past the 1KiB mark. The compositor needs to unmap and re-map the file to see the data past the 1KiB mark. If the MAP_NOFAULT/MAP_NOSIGBUS flag only affects the mapping itself and nothing else, this should be fine? > Treating it as an opaque blob of zeroes, that stays there ever after, > hiding the subsequent data: easy to implement, but a hack that we would > probably regret. (And I notice that even the quote from David Herrmann > in the original post allows for the possibility that client may want to > expand the object.) > > I believe the correct behaviour would be to unmap the nofault page > then, allowing the proper page to be faulted in after. That is > certainly doable (the old mm/filemap_xip.c used to do so), but might > get into some awkward race territory, with filesystem dependence > (reminiscent of hole punch, in reverse). shmem could operate that > way, and be the better for it: but I wouldn't want to add that, > without also cleaning away all the shmem_recalc_inode() stuff. [1]: https://github.com/openbsd/src/commit/37f480c7e4870332b7ffb802fa6578f5= 47c8a19f