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 20F0EC433EF for ; Sat, 18 Dec 2021 02:18:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4723F6B0072; Fri, 17 Dec 2021 21:18:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3D4496B0073; Fri, 17 Dec 2021 21:18:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 200396B0074; Fri, 17 Dec 2021 21:18:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 0AFDB6B0072 for ; Fri, 17 Dec 2021 21:18:27 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id BFA388CA3C for ; Sat, 18 Dec 2021 02:18:16 +0000 (UTC) X-FDA: 78929305392.10.5A5E543 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) by imf28.hostedemail.com (Postfix) with ESMTP id 7AC07C003F for ; Sat, 18 Dec 2021 02:18:16 +0000 (UTC) Received: by mail-ed1-f46.google.com with SMTP id z29so14541351edl.7 for ; Fri, 17 Dec 2021 18:18: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=AfupmJVw696CKh2wf7N7HMHG3vz5teOJsmL4ec+wmM8=; b=IUPaQZX69rMmZQKAKGGYWzmkdEjxHnCf/dJozdJRT6iSeScVVhJQA3eJPwRdZBnjtj 4nl/n6cx4fG5pNmZRBZfXVsKfdHuTO+/HYnh1jqWn0GhuuYgZUGrnQPzaA4sv3RxWBpL /BjmCRMa66r7d4jQSZIIpjUkYeAoTWSKYRW7Y= 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=AfupmJVw696CKh2wf7N7HMHG3vz5teOJsmL4ec+wmM8=; b=pDerbW4IS5A9qHAWjUKzbf8JlnoYczx4JfgD+MyUWemQ56Zh5Grl+cDJwdsxM8cgfC x6TPpGO+Lih+tWXGUNSaG1m1NbfdoP00saeA48FE0RiKh6eahdFtuCIXXued2ZUGlILH PeaDPbeq96cI2YMifFQtjKunNVYM+kmCUKZL7ePfjTw0Q7YCqe++P8bLu586/3H0hr/A c1uV8V4ui6gYpEgLgV261TTI4JBx2a/mmSV3MZcyp+xFAOg2RfxZPbSa3LexfnxzqNi5 g0oGsvAo+QgLop5TQiQltoV8WkwDuiFehqk0yY/ERpyV1aTFAMXuISSCLjkagVyjeLAs +72w== X-Gm-Message-State: AOAM531OCbDHJj6FP/eV0X5aTy/gmiie0EEmflR7Q9kOrcoOuWBmQ3Ls OF58uVs42aqIsOIsdgMSbC8JdD+cEsWYahLry+g= X-Google-Smtp-Source: ABdhPJwiN1qq3UcypNLZYt2HTE/jsPHjencD2QAKzDvMPd9tL5v4wrUQN4sgLZm9OwrFnDfuTcSBjw== X-Received: by 2002:a17:907:3ea7:: with SMTP id hs39mr4673746ejc.164.1639793894732; Fri, 17 Dec 2021 18:18:14 -0800 (PST) Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com. [209.85.128.43]) by smtp.gmail.com with ESMTPSA id nc24sm3435399ejc.94.2021.12.17.18.18.14 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Dec 2021 18:18:14 -0800 (PST) Received: by mail-wm1-f43.google.com with SMTP id y83-20020a1c7d56000000b003456dfe7c5cso4323155wmc.1 for ; Fri, 17 Dec 2021 18:18:14 -0800 (PST) X-Received: by 2002:a05:600c:1914:: with SMTP id j20mr11833156wmq.26.1639793883730; Fri, 17 Dec 2021 18:18:03 -0800 (PST) MIME-Version: 1.0 References: <20211217113049.23850-1-david@redhat.com> <20211217113049.23850-7-david@redhat.com> <54c492d7-ddcd-dcd0-7209-efb2847adf7c@redhat.com> <20211217204705.GF6385@nvidia.com> <2E28C79D-F79C-45BE-A16C-43678AD165E9@vmware.com> In-Reply-To: From: Linus Torvalds Date: Fri, 17 Dec 2021 18:17:47 -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: Nadav Amit Cc: Jason Gunthorpe , David Hildenbrand , Linux Kernel Mailing List , Andrew Morton , Hugh Dickins , David Rientjes , Shakeel Butt , John Hubbard , Mike Kravetz , Mike Rapoport , Yang Shi , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Jann Horn , Michal Hocko , 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: 7AC07C003F X-Stat-Signature: tbon69rimaicdft7ryxbhyr8kect7mz9 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=google header.b=IUPaQZX6; spf=pass (imf28.hostedemail.com: domain of torvalds@linuxfoundation.org designates 209.85.208.46 as permitted sender) smtp.mailfrom=torvalds@linuxfoundation.org; dmarc=none X-HE-Tag: 1639793896-531180 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 5:53 PM Linus Torvalds wrote: > > > And then there's THP and HUGETLB, that I do think needs fixing and > aren't about those two kinds of cases. > > I think we never got around to just doing the same thing we did for > regular pages. I think the hugepage code simply doesn't follow that > "COW on GUP, mark to not COW later" pattern. In particular, do_huge_pmd_wp_page() has this pattern: /* * We can only reuse the page if nobody else maps the huge page or it's * part. */ if (reuse_swap_page(page, NULL)) { ... mark it writable ... and that never got converted to "only mark it writable if we actually have exclusive access to this huge page". So the problem is literally that reuse_swap_page() uses that "page_mapcount()" logic, and doesn't take into account that the page is actually used by a GUP reference. Which is exactly why David then sees that "oh, we got a GUP reference to it, and now we're seeing the writes come through". Because that code looks at mapcount, and it shouldn't. I think the hugepage code should use the exact same logic that the regular wp fault code does. Linus