Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1526720pxy; Thu, 29 Apr 2021 08:49:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjlkmi9cipVW/bVldzy+mcEDOgWx8cYw65n/5g3ZL1b+3Xdvrfi324c+oaKCPoOY2Di+jt X-Received: by 2002:a65:52c3:: with SMTP id z3mr335721pgp.338.1619711344260; Thu, 29 Apr 2021 08:49:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619711344; cv=none; d=google.com; s=arc-20160816; b=Jd+zfDY1mB9aIEa+ujbNAR56D3biz1DDOBsZx1RCoeZiS/lACi7HiNFF3UxhtdZD6m BM1KmCBEK5DzEpjQW3qCm6QUpHQgJU0QF1UNGerfNtAP4PNNYZ/uUN2kyv3AuAHi2sgK /wMBGjW516+Ot0iTq/2SKh6j4wOAS48WJ99RmA4QcUVd+H27cpOUL+vvaA0NnCj51DY5 FN142kAyKf/F6EkDReAAXeUyxVzqQlxGG3pdT8d8NtzfrrDjOEEwxpILUdMF6bGsqxvi w+/+8MUKct5JZG8XWpZZ7X5FF2he/LqeIFKMOdnk/zZ/3rfvYXwsBHBDGCdktMrM6lmO t/uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=3NyxbJCwhqb1aqLdIOSz5lukrN8T+dDDlsyMoLY0gW4=; b=VngHez1VLqgYdI/GQB8op6PhNQCVGX9XI3v+PuPEeZE/ofHzr+GTy+oATOdXX2Lh0K 3v2mlXcg9yjHrisdDMCPmnSdt89en+fEyWqzCsVL/ioIwCAcRk8qkOjiEvTD7PtAn9/i F+fnMyo66xFOx9XeMJSXBxgjnPXsiIuzs8VcF/O7NcmiZ9bz25mCHGxrKIZfuIzV7MoZ CPpKPSPSN76XMZ7k/p+H/uafMTYzkNjqVtdtEGQ/2B1tA4j9vCcmb5FbCBTd5sedwKEQ gCpYaBpjYxLmxqKwXfVbQFg1F2vtpHTpRLes7kp3k1cP2PXnnhIE6m1TgCQ0wkmWL7Vk sBWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=cbYC8SxT; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 77si357327pge.14.2021.04.29.08.48.50; Thu, 29 Apr 2021 08:49:04 -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=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=cbYC8SxT; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234144AbhD2Ps6 (ORCPT + 99 others); Thu, 29 Apr 2021 11:48:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233420AbhD2Ps5 (ORCPT ); Thu, 29 Apr 2021 11:48:57 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 517C4C06138B for ; Thu, 29 Apr 2021 08:48:09 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id x19so75220963lfa.2 for ; Thu, 29 Apr 2021 08:48:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=3NyxbJCwhqb1aqLdIOSz5lukrN8T+dDDlsyMoLY0gW4=; b=cbYC8SxTjuN7PL/HHpWnlrg/QN1hbVMX8F6WKSRM2DjP4eDx+2x+t4E0/GMgzTxeUO 8IZnyKtuvzyQ3D8CHxgPBCUcbxohWBWSZeMojKYswbWhlX3U9Q7Th0J/+IhWbre9r0Eb 5cKkEh5sjhR2Us2DIWa/9crBm8yfFuMvC1foJOzjGZQrUSCMc4K4SAcEAyLTokeM1vWn PILewUSWyy4LQur7FqhLQWHTyKwEPBcJDwFFE4IoDouS9bHTEzFU4Ch1b6fDojeAV6on 6mS/xGS/4MMurv31BIf6i016OPdTJjBIyh9tq7CKBVCAiaEeLWvq8GgyjFLUMkr5oOaJ o4FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=3NyxbJCwhqb1aqLdIOSz5lukrN8T+dDDlsyMoLY0gW4=; b=icju8V0QGfn9+x6swRZKvK8ugZe/0bBVvlpNDA5xLpAf0eWA9JvyVgpz/1fYtaKSnS epp/T9IXef25UAJxsP7Xcxz35d/ZP9Bb8CcmDnVX4/aO3XMg5m40fM9+Kd3AJcRFo/cV VSnJfIkDlGJzDDEUdhJtjQ0cAYYny6zB7o7iTdn+ctk5oxSOoPTgobfu/Lc+8FdqTWaM 5U5gFDSzGirkv3wgB/MhUcK2DFxzMe4WO3qyV+OEC/JllsHaRTTLad2JspIY1N9V9qsa +fwO55utshm8Cx900h5xvTuLl+OUQPdBYVnoZoKUB8GMG/fjIg79HGAkTNmxXLFAvP6W aZxg== X-Gm-Message-State: AOAM530xpbJTYJ2LjKKSSxWR6KITFmEovi2p8dRFKOnQ3p1rluE3fO2E doAtJpF8ga5Es0eahKBlrhRweg== X-Received: by 2002:ac2:5f6a:: with SMTP id c10mr159706lfc.286.1619711287786; Thu, 29 Apr 2021 08:48:07 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id j8sm13949lfg.250.2021.04.29.08.48.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Apr 2021 08:48:06 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id 29D45101C51; Thu, 29 Apr 2021 18:48:07 +0300 (+03) Date: Thu, 29 Apr 2021 18:48:07 +0300 From: "Kirill A. Shutemov" To: Linus Torvalds , Matthew Wilcox , Dan Williams Cc: Simon Ser , "Kirill A. Shutemov" , Peter Xu , Will Deacon , Linux Kernel Mailing List , David Herrmann , "linux-mm@kvack.org" , Greg Kroah-Hartman , "tytso@mit.edu" Subject: Re: Sealed memfd & no-fault mmap Message-ID: <20210429154807.hptls4vnmq2svuea@box> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 27, 2021 at 09:51:58AM -0700, Linus Torvalds wrote: > On Tue, Apr 27, 2021 at 1:25 AM Simon Ser wrote: > > > > Rather than requiring changes in all compositors *and* clients, can we > > maybe only require changes in compositors? For instance, OpenBSD has a > > __MAP_NOFAULT flag. When passed to mmap, it means that out-of-bound > > accesses will read as zeroes instead of triggering SIGBUS. Such a flag > > would be very helpful to unblock the annoying SIGBUS situation. > > > > Would something among these lines be welcome in the Linux kernel? > > Hmm. It doesn't look too hard to do. The biggest problem is actually > that we've run out of flags in the vma (on 32-bit architectures), but > you could try this UNTESTED patch that just does the MAP_NOFAULT thing > unconditionally. > > NOTE! Not only is it untested, not only is this a "for your testing > only" (because it does it unconditionally rather than only for > __MAP_NOFAULT), but it might be bogus for other reasons. In > particular, this patch depends on "vmf->address" not being changed by > the ->fault() infrastructure, so that we can just re-use the vmf for > the anonymous case if we get a SIGBUS. > > I think that's all ok these days, because Kirill and Peter Xu cleaned > up those paths, but I didn't actually check. So I'm cc'ing Kirill, > Peter and Will, who have been working in this area for other reasons > fairly recently. > > Side note: this will only ever work for non-shared mappings. I think it's show-stopper for the use-case, no? IIUC, the mappings is used for communication between a compositor and a client and has to be shared. > That's fundamental. We won't add an anonymous page to a shared mapping, > and do_anonymous_page() does verify that. So a MAP_SHARED mappign will > still return SIGBUS even with this patch (although it's not obvious from > the patch - the VM_FAULT_SIGBUS will just be re-created by > do_anonymous_page()). > > So if you want a _shared_ mapping to honor __MAP_NOFAULT and insert > random anonymous pages into it, I think the answer is "no, that's not > going to be viable". + Matthew, Dan. DAX uses zero pages in page cache to avoid allocating backing storage read accesses to holes. Maybe we can generalize it beyond DAX to any page cache and add a (per-inode?) flag to do the same for accesses beyond i_size? > So _if_ this works for you, and if it's ok that only MAP_PRIVATE can > have __MAP_NOFAULT, and if Kirill/Peter/Will don't say "Oh, Linus, > you're completely off your rocker and clearly need to be taking your > meds", something like this - if we figure out the conditional bit - > might be doable. > > That's a fair number of "ifs". > > Ok, back to the merge window for me, I'll be throwing away this crazy > untested patch immediately after hitting "send". This is very much a > "throw the idea over to other people" patch, in other words. > > Linus -- Kirill A. Shutemov