Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp512344pxj; Thu, 3 Jun 2021 12:11:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxa+1H/p2UgiW52VRYXf1YKemMTglxfJtqalEmeJpBzVPfGwO1m9HoNiL5FiyUHLjtHcG7P X-Received: by 2002:a17:906:1806:: with SMTP id v6mr768035eje.454.1622747469857; Thu, 03 Jun 2021 12:11:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622747469; cv=none; d=google.com; s=arc-20160816; b=EsY7MajuQ7OZMK4od2+i7QqyDFLgzYC/jegaS62wYU8d8jrC6CtlPbHoCKUsnmNJcJ Dv5mv+5ful9IixQrWVo27rTjPIzCpm4E2D2Ic5hm4gKJTMBgU9ijpNGH87a3TX6Lvve3 Ev/4fleWfa8e6h9sGMJTIbvpFk8wIpL91s1gnUwtPQp73jAqkBNSQWqrYGVDoiZoRfg+ /YftKciFlFV7yJyBTbEu48CTQ08WcEvd0fVjC/T3NpCdV4w0kH6VDZHtSneLvSQkTv3F Dnar0rBPaxRi21YGsj1cpRqxCQPOaDzmbsE5gtB+Fc1D1232lo4mvAApT64hlkK8zuyG Rl9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=j1A5KVJOcx2Sm/u6BzmYkKLVORkN+8973B9sz+toaOM=; b=0EWxDO1xxUHV6T5oziRYJwtly0BxGNsUGLLyaJxSBwaD6mWh/wg97Wc04szHzBF4rS MXEudaXdN7HIudRsOqCM4c5Qj9zPNcJ4XWQxVhi0g6xgRO27LLPolRTXo8INjq1riZ6J JnDOhlC4sfWb8lY7OOl+z7L9jaZXpTHqNb8LIuMytxSWoCul7Juli+9pwd8nuejkzlqJ w4kyJRswu6vcL/M7Xs/6B4PXqS258ww0/GpaE6aJI/YSFKh9iQn9IYFTztsAIo2WxsTw kbuH+VEBNNtdL96c2kwUWg19ViaZ0V99awzte91n71pJ1nKOFp0dxK7w3djEQNutUv2X BOgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=DxJJe+sS; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j1si2804123ejs.728.2021.06.03.12.10.47; Thu, 03 Jun 2021 12:11:09 -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=@google.com header.s=20161025 header.b=DxJJe+sS; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229656AbhFCTJT (ORCPT + 99 others); Thu, 3 Jun 2021 15:09:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229576AbhFCTJS (ORCPT ); Thu, 3 Jun 2021 15:09:18 -0400 Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 212F1C06174A for ; Thu, 3 Jun 2021 12:07:33 -0700 (PDT) Received: by mail-qk1-x72c.google.com with SMTP id u30so7020211qke.7 for ; Thu, 03 Jun 2021 12:07:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=j1A5KVJOcx2Sm/u6BzmYkKLVORkN+8973B9sz+toaOM=; b=DxJJe+sS3pZmKekJ7WUEU3udkpFiy/cthYRmwPXFXjO2t48zZcaDEQtfe95cyb0nh2 Ty5LJLkKnflgq4BScb5FM3CWAhaiJnk88gFHBAgw+V0xG4eQgIXAJ2cEqTlQv0Icxmyy J2JTuNFMIYeACbppEwU/kYMwCZQ3/hVpN9M8bUunh9aeCxT+Py7p8K/dPdtb8O3avyQp dBK97ei4/1FXNfqBi+fKboPMNKZOz3dnRTPsxL8bBl8Rwe1coC5uyY0WSaUo7n3KIQyy HTXnFw32p9oV8LhjMDc0nSJpFKTLDdgrTosILMhS05fLozoUjpsUTe1Ok5390BX2f1nA 2LrQ== 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:in-reply-to:message-id :references:user-agent:mime-version; bh=j1A5KVJOcx2Sm/u6BzmYkKLVORkN+8973B9sz+toaOM=; b=akylpLEbKEJ6Ll2FjiO1wn85So8Lr6fmWUIlbGVq+jDvlxn9j1t7Dg8n7mXtsTM6tI e9P0m7IUaWBKwfFWvauQzz0UXC+XwHRLkfrz/AgjV9PLzremyEbu6D72MRV6Xjq3vSSi WDraOGFO/VDOiqZHiRcMzs4UdQ2sxFJI/WqMhuCoFOO4+JfjF2zo2SjtsREwIKqB/F4C 5yddsFy7VpNjgSvuv3+uMxanE7d6cUrmrAko/lD+BEoQc+tcLerm3scYZ4QR0ANkvs6K PBwqeKGdDyrDh7uEtImZ68xsydUXIQNLuABq0+Oc5gaC5M6Pk71iJOvGhKILrZBlf5yT Hazg== X-Gm-Message-State: AOAM530z3MgQ94j2imzWlUFNrOIdRAUqwUW7mMa5W+i8ziMrmqV0BsO0 nhGU3VPys09WuSWJonG2bHC9bxHgdNOXAQ== X-Received: by 2002:ae9:f310:: with SMTP id p16mr697061qkg.267.1622747251960; Thu, 03 Jun 2021 12:07:31 -0700 (PDT) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id v8sm2451410qkg.102.2021.06.03.12.07.30 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Thu, 03 Jun 2021 12:07:31 -0700 (PDT) Date: Thu, 3 Jun 2021 12:07:18 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Linus Torvalds cc: Hugh Dickins , Ming Lin , Simon Ser , Linux-MM , Linux Kernel Mailing List , linux-fsdevel , Linux API Subject: Re: [PATCH 2/2] mm: adds NOSIGBUS extension for out-of-band shmem read In-Reply-To: Message-ID: References: <1622589753-9206-1-git-send-email-mlin@kernel.org> <1622589753-9206-3-git-send-email-mlin@kernel.org> <79a27014-5450-1345-9eea-12fc9ae25777@kernel.org> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 3 Jun 2021, Linus Torvalds wrote: > On Wed, Jun 2, 2021 at 5:46 PM Hugh Dickins wrote: > > > > Ideally you can simply call do_anonymous_page() from __do_fault() > > in the VM_FAULT_SIGBUS on VM_NOSIGBUS case. > > Heh. > > We're actually then back to my original patch. > > That one doesn't handle shared mappings (even read-only ones), for the > simple reason that do_anonymous_page() refuses to insert anonymous > pages into a shared mapping, and has > > /* File mapping without ->vm_ops ? */ > if (vma->vm_flags & VM_SHARED) > return VM_FAULT_SIGBUS; > > at the very top. > > But yes, if we just remove that check, I think my original patch > should actually "JustWork(tm)". But no! Sorry, I don't have time for this at present, so haven't looked at your original patch. But the point that we've arrived at, that I'm actually now fairly happy with, is do *not* permit MAP_NOSIGBUS on MAP_SHARED mappings. I didn't check the placement yet, easy to get wrong, but I believe Ming Lin is now enforcing that over at the mmap() end. On a MAP_PRIVATE mapping, the nasty opaque blob of zeroes can claim some precedent in what already happens with COW'ed pages. Which leaves MAP_NOSIGBUS on MAP_SHARED as currently unsupported, perhaps never supported on anything, perhaps one day supported on shmem; but if it's ever supported then that one will naturally be transparent to future changes in page cache - we call that "shared". Of course, internally, there's the in-between case of MAP_SHARED without PROT_WRITE and without writable fd: VM_MAYSHARE without VM_SHARED or VM_MAYWRITE. We *could* let that one accept MAP_NOSIGBUS, but who wants to write the manpage for it? Please stick to MAP_PRIVATE: that's good enough. > > I'm attaching it again, with old name and old commentary (ie that > > /* FIXME! We don't have a VM_NOFAULT bit */ > > should just be replaced with that VM_NOSIGBUS bit instead, and the > #if'ed out region should be enabled. > > Oh, and we need to think hard about one more case: mprotect(). > > In particular, I think the attached patch fails horribly for the case > of a shared mapping that starts out read-only, then inserts a zero > page, then somebody does mprotect(MAP_WRITE), and then writes to the > page. I haven't checked what the write protect fault handler does, but > I think that for a shared mapping it will just make the page dirty and > writable. Obviously the finished patch will need to be scrutinized carefully, but I think the mprotect() questions vanish when restricted to MAP_PRIVATE. > > Which would be horribly wrong for VM_NOSIGBUS. > > So that support infrastructure that adds MAP_NOSIGBUS, and checks that > it is only done on a read-only mapping, also has to make sure that it > clears the VM_MAYWRITE bit when it sets VM_NOSIGBUS. > > That way mprotect can't then later make it writable. > > Hugh, comments on this approach? Comments above, just stick to MAP_PRIVATE. Hugh > > Again: this patch is my *OLD* one, I didn't try to update it to the > new world order. It requires > > - Ming's MAP_NOSIGBUS ccode > > - removal of that "File mapping without ->vm_ops" case > > - that FIXME fixed and name updated > > - and that VM_MAYWRITE clearing if VM_NOSIGBUS is set, to avoid the > mprotect issue. > > Hmm? > > Linus