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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E974C433EF for ; Fri, 17 Dec 2021 22:59:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229980AbhLQW7R (ORCPT ); Fri, 17 Dec 2021 17:59:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229569AbhLQW7R (ORCPT ); Fri, 17 Dec 2021 17:59:17 -0500 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3400C061574 for ; Fri, 17 Dec 2021 14:59:16 -0800 (PST) Received: by mail-ed1-x536.google.com with SMTP id z7so13303400edc.11 for ; Fri, 17 Dec 2021 14:59:16 -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=rs3RPGk851m6kBvnTkDZNuCHS7bqxE4YiPXPeOnsMec=; b=WSqIxUtqn5jcmA6NC9BVpsfsO/6YYpI4P+quaDiBpik06F329fj372+mpAs6nkU6hi UgKtVq/JNx9O5+tUI1FaDEc9lAWL66/z1RpLwMtAJZ086ni6cHm+R02sIgHA08fo/qlY ertG4Ei0o7WJ3lUoVgGOz1iW744OYt4w3zD7E= 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=rs3RPGk851m6kBvnTkDZNuCHS7bqxE4YiPXPeOnsMec=; b=X/LwqGhdVkCHrekthijCnB31nijQ/mwaWWYdEV6DVH4tWdUGj5woDi38oHv6spZqqx 2oEYsLpz5gJx54iW9U0852NgdRy4CP8ntY8OIEio47tCmcf+WB1R8am2vxLYiJt/BUmZ XNwIGVw0DeQYLo/sfuqaMe031MMj6F2EZq3ivM6dEIlKfqDez5DHArjevlCy2O26icmw dCXWe4PzeslxBgdTBBPU1+KBYMqbVb/wMiNbCD9i+yHHbsVLH9CljRiaTaN27NGkZZKP 1leIQ9pcxWS1IO0UdI4Oaj+q80mu5PYzcGzCjhSglV0gSoXygoNs0Y2c2nMLO3yI4UAa IokA== X-Gm-Message-State: AOAM530oWJMLmRiBXDV1bTiAqZabYGz2ydkPkoRzZVH7p5HmD9VVkNPZ AmLR/nG0M49zZIzbB/GcCjfrG+t+Bnv79Bq6Tk0= X-Google-Smtp-Source: ABdhPJyF5JPJskv4DAKcUQGOFhVddwY0rl+EJjRz6gGqbhRi8vVuNL11J6wfri+lp0zlH9cJkVH1eg== X-Received: by 2002:a17:907:2da1:: with SMTP id gt33mr4303290ejc.378.1639781954759; Fri, 17 Dec 2021 14:59:14 -0800 (PST) Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com. [209.85.221.50]) by smtp.gmail.com with ESMTPSA id y17sm4285928edd.31.2021.12.17.14.59.13 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Dec 2021 14:59:13 -0800 (PST) Received: by mail-wr1-f50.google.com with SMTP id i22so6662495wrb.13 for ; Fri, 17 Dec 2021 14:59:13 -0800 (PST) X-Received: by 2002:adf:f54e:: with SMTP id j14mr4140437wrp.442.1639781952748; Fri, 17 Dec 2021 14:59:12 -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> <0aa27d7d-0db6-94ee-ca16-91d19997286b@redhat.com> In-Reply-To: <0aa27d7d-0db6-94ee-ca16-91d19997286b@redhat.com> From: Linus Torvalds Date: Fri, 17 Dec 2021 14:58:56 -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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 17, 2021 at 2:29 PM David Hildenbrand wrote: > > While I do care about future use cases, I cannot possibly see fork() not > requiring the mmap_lock in the foreseeable future. Just so much depends > on it as of now. It's not that *fork()* depends on it. Of course fork() takes the mmap_sem. It's that fast-gup really really doesn't want it, and can't take it. So any fast-gup user fundamentally cannot look at mapcount(), because that would be fundamentally wrong and racy, and could race with fork. And yet, as far as I can tell, that's *exactly* what your gup patches do, with gup_pte_range() adding + if (!pte_write(pte) && gup_must_unshare(flags, page, false)) { + put_compound_head(head, 1, flags); + goto pte_unmap; + } which looks at the page mapcount without holding the mmap sem at all. And see my other email - I think there are other examples of your patches looking at data that isn't stable because you don't hold the right locks. And you can't even do the optimistic case without taking the lock, because in your world, a COW that optimistically copies in the case of a race condition is fundamentally *wrong* and buggy. Because in your world-view, GUP and COW are very different and have different rules, but you need things to be *exact*, and they aren't. And none of this is anything at least I can think about, because I don't see what the "design" is. I really have a hard time following what the rules actually are. You seem to think that "page_mapcount()" is a really simple rule, and I fundamentally disagree. It's a _very_ complicated thing indeed, with locking issues, AND YOU ACTIVELY VIOLATE THE LOCKING RULES! See why I'm so unhappy? We *did* do the page_mapcount() thing. It was bad. It forced COW to always take the page lock. There's a very real reason why I'm pushing my "let's have a _design_ here", instead of your "let's look at page_mapcount without even doing the locking". And yes, I *know* that fork() takes the mmap_sem, and likely always will. That really isn't the problem here. The problem is that your page_mapcount() paths DO NOT take that lock. Btw, maybe I'm misreading things. I looked at the individual patches, I didn't apply them, maybe I missed something. But I don't think I am. Linus