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 22FC8C433EF for ; Fri, 17 Dec 2021 22:44:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 956E96B0072; Fri, 17 Dec 2021 17:44:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 906D06B0073; Fri, 17 Dec 2021 17:44:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7808A6B0074; Fri, 17 Dec 2021 17:44:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0178.hostedemail.com [216.40.44.178]) by kanga.kvack.org (Postfix) with ESMTP id 658F86B0072 for ; Fri, 17 Dec 2021 17:44:00 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 2B8F3180310BA for ; Fri, 17 Dec 2021 22:43:50 +0000 (UTC) X-FDA: 78928765020.01.D317D5C Received: from us-smtp-delivery-124.mimecast.com (usb-smtp-delivery-124.mimecast.com [170.10.151.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 9CAF814002E for ; Fri, 17 Dec 2021 22:43:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639781028; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2l3tv70qw5U/DFH1AeqC7MLWadTCO2kcG/3tbtkmi6M=; b=a2x9CJGOGVCT8aT6zitmsTneNAw1uJA0p6Thl5WgH2KpX6xuD1uw5qwg91iefeYZN0uTi8 Kb16zbGkIh8ByKiWwjhpE8n5duyFbovBjx7ACE5NDvpSuClA3yfXElxqkSyjgRJxehF3T2 d7crDBzy13bXG6gBmcZbKIYyXiWKURU= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-2-y4NEM9-uOV-YYyGA97GbNw-1; Fri, 17 Dec 2021 17:43:47 -0500 X-MC-Unique: y4NEM9-uOV-YYyGA97GbNw-1 Received: by mail-wr1-f69.google.com with SMTP id l9-20020adfa389000000b001a23bd1c661so1011604wrb.6 for ; Fri, 17 Dec 2021 14:43:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:references:from:organization:subject :in-reply-to:content-transfer-encoding; bh=2l3tv70qw5U/DFH1AeqC7MLWadTCO2kcG/3tbtkmi6M=; b=UYKIrNMdh6sTY7m0d8F7Z+9wBwxuneLAxZU0+nQzs7JvjStM73oVHQhN7lKTCoZaBh 0OxolC8aPrYixT58qzrkRl2gvAoZ43jNgDZiDwlc8vHUutESHCmJtDWK3AR8xPD8bPKx LO4r8ILYJDfEgnYD4uZxhuCCo9SDazBk0Kt2hkZY8tufv9LwDB83WfwzaNAUjNoCnn9w tnZ+bMD3Ej8k1PgV9Y0s72yg5GyHenNaVwpDknVF/4KzQ3Kk5wNKLxhbB82IuZkxGtKB /lumIT7duSyGydLhIjSZgsTQ3sFToloH5dY+4QmgMZYcB3QMrMY242QUXM+0YrZcDV08 sXnA== X-Gm-Message-State: AOAM533Ah87Y+zwIJuDvHh1OSwgOyVHD9eCu2QbcUQitNHfFTRyhzTgz U10ZA6+rXKqzkXmWmycRfVkkLklgi4rhFiSP0Jhw00oj8eNCyVLtJZQzipR182Pa9+Hq2tVCuwP fnp+efJ+D+nw= X-Received: by 2002:adf:f48e:: with SMTP id l14mr4202101wro.88.1639781026624; Fri, 17 Dec 2021 14:43:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJwlsG6viaLqvbuV/wNUm4ZwQ7VL/P5e2xT8/kUZ9SE40GD4CaG/NiGfqmJpgjssvi9LApgTBw== X-Received: by 2002:adf:f48e:: with SMTP id l14mr4202074wro.88.1639781026429; Fri, 17 Dec 2021 14:43:46 -0800 (PST) Received: from [192.168.3.132] (p4ff234b8.dip0.t-ipconnect.de. [79.242.52.184]) by smtp.gmail.com with ESMTPSA id p5sm8945149wrd.13.2021.12.17.14.43.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Dec 2021 14:43:46 -0800 (PST) Message-ID: Date: Fri, 17 Dec 2021 23:43:44 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 To: Linus Torvalds 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" 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> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v1 06/11] mm: support GUP-triggered unsharing via FAULT_FLAG_UNSHARE (!hugetlb) In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=a2x9CJGO; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf23.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.151.124) smtp.mailfrom=david@redhat.com X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 9CAF814002E X-Stat-Signature: y6hyn8qmqiyeozzyahdwgotmagk1h177 X-HE-Tag: 1639781024-579016 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 17.12.21 23:18, Linus Torvalds wrote: > On Fri, Dec 17, 2021 at 1:47 PM David Hildenbrand wrote: >> >> For now I have not heard a compelling argument why the mapcount is >> dubious, I repeat: >> >> * mapcount can only increase due to fork() >> * mapcount can decrease due to unmap / zap > > And to answer the "why is this dubious", let' sjust look at your > actual code that I reacted to: > > + vmf->page = vm_normal_page(vmf->vma, vmf->address, vmf->orig_pte); > + if (vmf->page && PageAnon(vmf->page) && !PageKsm(vmf->page) && > + page_mapcount(vmf->page) > 1) { > > Note how you don't just check page_mapcount(). Why not? Because > mapcount is completely immaterial if it's not a PageAnon page, so you > test for that. > > So even when you do the mapcount read as one atomic thing, it's one > atomic thing that depends on _other_ things, and all these checks are > not atomic. > > But a PageAnon() page can actually become a swap-backed page, and as > far as I can tell, your code doesn't have any locking to protect > against that. The pages stay PageAnon(). swap-backed pages simply set a bit IIRC. mapcount still applies. > > So now you need not only the mmap_sem (to protect against fork), you > also need the page lock (to protect against rmap changing the type of > page). No, I don't think so. But I'm happy to be proven wrong because I might just be missing something important. > > I don't see you taking the page lock anywhere. Maybe the page table > lock ends up serializing sufficiently with the rmap code that it ends > up working > > In the do_wp_page() path, we currently do those kinds of racy checks > too, but then we do a trylock_page, and re-do them. And at any time > there is any question about things, we fall back to copying - because > a copy is always safe. Yes, I studied that code in detail as well. > > Well, it's always safe if we have the rule that "once we've pinned > things, we don't cause them to be COW again". We should also be handling FOLL_GET, but that's a completely different discussion. > > But that "it's safe if" was exactly my (b) case. > > That's why I much prefer the model I'm trying to push - it's > conceptually quite simple. I can literally explain mine at a > conceptual level with that "break pre-existing COW, make sure no > future COW" model. :) We really might be talking about the same thing just that my point is that the mapcount is the right thing to use for making the discussion whether to break COW -> triger unsharing. > > In contrast, I look at your page_mapcount() code, and I go "there is > no conceptual rules here, and the actual implementation details look > dodgy". > > I personally like having clear conceptual rules - as opposed to random > implementation details. Oh, don't get me wrong, me to. But for me it just all makes perfect. What we document is: "The fault is an unsharing request to unshare a shared anonymous page (-> mapped R/O). Does not apply to KSM." And the code checks for exactly that. And in that context the mapcount just expresses exactly what we want. Again, unless I am missing something important that you raise above. Anyhow, it's late in Germany. thanks for the discussion Linus! -- Thanks, David / dhildenb