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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C96B3C433F5 for ; Fri, 17 Dec 2021 23:21:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2EB526B0072; Fri, 17 Dec 2021 18:21:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 29BB06B0073; Fri, 17 Dec 2021 18:21:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 13BE96B0074; Fri, 17 Dec 2021 18:21:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0151.hostedemail.com [216.40.44.151]) by kanga.kvack.org (Postfix) with ESMTP id 04D946B0072 for ; Fri, 17 Dec 2021 18:21:05 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id B16808249980 for ; Fri, 17 Dec 2021 23:20:54 +0000 (UTC) X-FDA: 78928858428.13.3739CCE Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) by imf23.hostedemail.com (Postfix) with ESMTP id 5144914002A for ; Fri, 17 Dec 2021 23:20:49 +0000 (UTC) Received: by mail-lf1-f52.google.com with SMTP id b22so7648072lfb.9 for ; Fri, 17 Dec 2021 15:20:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=WST3wy6+xYPOuwZfmt2/JLJvcXf3cy26kl3RLbkPveE=; b=VXGkS6mNdOeYceL24plAqQedawFCC8HX6+aSsCsVUhO2s6J2TZ1wsFmTez6n6ZomIG 5YBwdy2IW3gUrcz7i1tItWl9dq+k4ECH2BsU3alhEJ8YHr5HifsTOO3nAPkUG8bB06jL ahLbuER/HW4tHaC0gLpnI/AXbWLi6gpSl3ka0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=WST3wy6+xYPOuwZfmt2/JLJvcXf3cy26kl3RLbkPveE=; b=jORL8e4v37ojxWKZ7PH6eFgS4DekYVhAnKKH1iJQG/nmjIAPVuvgqtArYbQP+3JtWf TFX9DAsGKDHUv2kZrHQ32ar1Ncm7eN74G+lnolkdwxW2wZroOH2PN9byBXHoVCI/PETL vZ9tZnGeeVjY4bh0gl6kVeH5+x48Eimi5p2NF0sOMOxXdi+/NjEhQpVIXEPpaxDZhrVE w7SKyeeLrlSVndXcAPu2Ux73WLUjYtJAuBO66jcWV429p4CCQ3dD53MeAAR9EPZ4W3WZ xaZfYQVAKqbI7LOU7WhD8psGTECFsnOnc2bRuRs8e5z4FAT1nxBEYE0xxLBHamp4jwfK T+2g== X-Gm-Message-State: AOAM531OpWprBksoyP2C83CveZfn16q/jJGlW0bj4BmVQMm8zNqt8bD/ pmf+dNlEONSAYp9eKU72OvYBgS/5y25Rqni/Vh4= X-Google-Smtp-Source: ABdhPJw8fdb1kBNIxeXFSw7vS8E0Gdu2sLwruWm/bfFUFO9nG8mtab1kexL8eYdq91uiH4p9H/i0mA== X-Received: by 2002:a05:6512:3402:: with SMTP id i2mr4768725lfr.447.1639783252234; Fri, 17 Dec 2021 15:20:52 -0800 (PST) Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com. [209.85.167.49]) by smtp.gmail.com with ESMTPSA id p3sm1538074lfg.273.2021.12.17.15.20.51 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Dec 2021 15:20:52 -0800 (PST) Received: by mail-lf1-f49.google.com with SMTP id b40so7638884lfv.10 for ; Fri, 17 Dec 2021 15:20:51 -0800 (PST) X-Received: by 2002:a5d:6211:: with SMTP id y17mr4203233wru.97.1639783240817; Fri, 17 Dec 2021 15:20:40 -0800 (PST) MIME-Version: 1.0 References: <20211217113049.23850-1-david@redhat.com> <20211217113049.23850-7-david@redhat.com> <9c3ba92e-9e36-75a9-9572-a08694048c1d@redhat.com> <02cf4dcf-74e8-9cbd-ffbf-8888f18a9e8a@redhat.com> In-Reply-To: From: Linus Torvalds Date: Fri, 17 Dec 2021 15:20:24 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v1 06/11] mm: support GUP-triggered unsharing via FAULT_FLAG_UNSHARE (!hugetlb) To: David Hildenbrand Cc: Linux Kernel Mailing List , Andrew Morton , Hugh Dickins , David Rientjes , Shakeel Butt , John Hubbard , Jason Gunthorpe , Mike Kravetz , Mike Rapoport , Yang Shi , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Jann Horn , Michal Hocko , Nadav Amit , Rik van Riel , Roman Gushchin , Andrea Arcangeli , Peter Xu , Donald Dutile , Christoph Hellwig , Oleg Nesterov , Jan Kara , Linux-MM , "open list:KERNEL SELFTEST FRAMEWORK" , "open list:DOCUMENTATION" Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 5144914002A X-Stat-Signature: z5baba5wetpcdiyeg11fr4qsoqz3b6tk Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=google header.b=VXGkS6mN; spf=pass (imf23.hostedemail.com: domain of torvalds@linuxfoundation.org designates 209.85.167.52 as permitted sender) smtp.mailfrom=torvalds@linuxfoundation.org; dmarc=none X-HE-Tag: 1639783249-448384 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 Fri, Dec 17, 2021 at 2:43 PM David Hildenbrand wrote: > > The pages stay PageAnon(). swap-backed pages simply set a bit IIRC. > mapcount still applies. Our code-base is too large for me to remember all the details, but if we still end up having PageAnon for swapbacked pages, then mapcount can increase from another process faulting in an pte with that swap entry. And mmap_sem doesn't protect against that. Again, page_lock() does. And taking the page lock was a big performance issue. One of the reasons that new COW handling is so nice is that you can do things like if (!trylock_page(page)) goto copy; exactly because in the a/b world order, the copy case is always safe. In your model, as far as I can tell, you leave the page read-only and a subsequent COW fault _can_ happen, which means that now the subsequent COW needs to b every very careful, because if it ever copies a page that was GUP'ed, you just broke the rules. So COWing too much is a bug (because it breaks the page from the GUP), but COWing too little is an even worse problem (because it measn that now the GUP user can see data it shouldn't have seen). Our old code literally COWed too little. It's why all those changes happened in the first place. This is why I'm pushing that whole story line of (1) COW is based purely on refcounting, because that's the only thing that obviously can never COW too little. (2) GUP pre-COWs (the thing I called the "(a)" rule earlier) and then makes sure to not mark pinned pages COW again (that "(b)" rule). and here "don't use page_mapcount()" really is about that (1). You do seem to have kept (1) in that your COW rules don't seem to change (but maybe I missed it), but because your GUP-vs-COW semantics are very different indeed, I'm not at all convinced about (2). Linus