From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.8 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4841C47082 for ; Thu, 3 Jun 2021 19:07:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 678B9613F1 for ; Thu, 3 Jun 2021 19:07:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 678B9613F1 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B91746B0036; Thu, 3 Jun 2021 15:07:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B41A16B006C; Thu, 3 Jun 2021 15:07:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9A66D6B006E; Thu, 3 Jun 2021 15:07:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0137.hostedemail.com [216.40.44.137]) by kanga.kvack.org (Postfix) with ESMTP id 633D76B0036 for ; Thu, 3 Jun 2021 15:07:43 -0400 (EDT) Received: from smtpin40.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id D47C08783 for ; Thu, 3 Jun 2021 19:07:42 +0000 (UTC) X-FDA: 78213346764.40.D582889 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) by imf05.hostedemail.com (Postfix) with ESMTP id 5E263E0004CE for ; Thu, 3 Jun 2021 19:07:19 +0000 (UTC) Received: by mail-qk1-f171.google.com with SMTP id d196so1900829qkg.12 for ; Thu, 03 Jun 2021 12:07:37 -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=Hk9yVs+BNVkUc/UfPBI9DiGV5VrtQzhEXhNRG9okOE8DUttVfmFO2EAasHleJ49OY8 cxxBNj1X6wWIek8yx7hwLHSQS09IsM8MKqbWdB3CLuBRpYNZWE0nDyk5TwOIYnXOF9MY JAzOPlKErKErt9S5r0oMLcck4qOD018ESBs/+PE9d7ekBbtNuarT0OZmoBUosiwlUFH5 AiVZKPR1dP8STnsciW9+Cdka4HcaW1+NMsq6np4FWDoCFZCfBBoUQSYSzKOyLaoI8jxy 7oXwYxv+VilLyA2cLETNRv4ZMLPi0lkzW3hw/fQmESWVKkBlo2OtfwU0p/XSiwlVIqWM KVrg== X-Gm-Message-State: AOAM532c92TlP2mW+PNtovxv0lXYsz4TYTCplrGddZDG3BqvhuYk9ESl HFpR+3hyoxWHuQ/03rbNCRtPbg== X-Google-Smtp-Source: ABdhPJy0iLvQA3EpRpciKhPlEkLxhoPyCANwdMooLs3uoQCCY5zReAZamVDSUB5Nz1XmH4UP27XScg== 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 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=DxJJe+sS; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf05.hostedemail.com: domain of hughd@google.com designates 209.85.222.171 as permitted sender) smtp.mailfrom=hughd@google.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 5E263E0004CE X-Stat-Signature: e691tad1jj4mms1xors8g59815gt59ge X-HE-Tag: 1622747239-581725 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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