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 DC21AC433F5 for ; Sat, 18 Dec 2021 22:53:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231624AbhLRWx6 (ORCPT ); Sat, 18 Dec 2021 17:53:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231351AbhLRWx6 (ORCPT ); Sat, 18 Dec 2021 17:53:58 -0500 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4261C061574 for ; Sat, 18 Dec 2021 14:53:57 -0800 (PST) Received: by mail-ed1-x52f.google.com with SMTP id j21so17987719edt.9 for ; Sat, 18 Dec 2021 14:53:57 -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=mJf35OulebkWfKFhXCfv+327LAJ4W2k8OGIoJTIXfIo=; b=dG1V9TzLGCecXWNdRV5Ieb7V7jx4XXm42+n2J/149xEOJE5Tg0NmZ+cfF1j3OVD1dv 4/abdSFzcm6W1ZofMPLzp3kY7w8JfzzYfQK7mjkdLbDcoe+KW25lfWOyG0w7OTq2no74 0E+b/2RDV5qKx9L2+ASDLVxYRIEppRhgOV7FQ= 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=mJf35OulebkWfKFhXCfv+327LAJ4W2k8OGIoJTIXfIo=; b=2v3BDUfx/GCUopWqz76zbVELrAEaX1cs7pi6oLhCij6430isNiMaeBzGE9xdZsgWSJ /uJ6DoBgnBPD6FqMiKBdefgtlkJT5+F32sAfzEne8eSMZpZt3UhqcLGsTL+dR0XXInJB J6NZqaGlg6hSFWjnZmD2CpChLQ/5g4ZVZGEXxZ0YpMX8Q0nHgAoqBh4JGNPibPiqbjXr BykdYETthgQyG/i4eMw5iWERYpAyYCzgQfB6Q49XIolwvBLZq7yrv9X1A5g/B+rIHc/0 Gt7p9rMytCSDIfLmCi+myqGSymAKcfCpeKVtSjmU3KzTGZVhxJt2LnnMXPJM/Kxa2mFn jzqQ== X-Gm-Message-State: AOAM5334AgLPjksJRSq1pnY72yNNsPn8D18C/KIaWXa1ZVZ4Hh+OMYjV Vx2NXwytKAEjEw6zTsxNjZvRG5Y3pQZY2/4X0eg= X-Google-Smtp-Source: ABdhPJxmSweA4UnJbbW0WpZCSJmilxLNu4uklpoODjD0WxE6Mhu0ON5eKvwgOjrRVOXMWf0sO4hXQw== X-Received: by 2002:a17:906:505:: with SMTP id j5mr7377522eja.764.1639868036111; Sat, 18 Dec 2021 14:53:56 -0800 (PST) Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com. [209.85.128.46]) by smtp.gmail.com with ESMTPSA id z16sm2340208edc.76.2021.12.18.14.53.55 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 18 Dec 2021 14:53:55 -0800 (PST) Received: by mail-wm1-f46.google.com with SMTP id a83-20020a1c9856000000b00344731e044bso3957142wme.1 for ; Sat, 18 Dec 2021 14:53:55 -0800 (PST) X-Received: by 2002:a05:600c:1e01:: with SMTP id ay1mr6056643wmb.152.1639868034874; Sat, 18 Dec 2021 14:53:54 -0800 (PST) MIME-Version: 1.0 References: <54c492d7-ddcd-dcd0-7209-efb2847adf7c@redhat.com> <20211217204705.GF6385@nvidia.com> <2E28C79D-F79C-45BE-A16C-43678AD165E9@vmware.com> <20211218030509.GA1432915@nvidia.com> <5C0A673F-8326-4484-B976-DA844298DB29@vmware.com> <20211218184233.GB1432915@nvidia.com> <5CA1D89F-9DDB-4F91-8929-FE29BB79A653@vmware.com> In-Reply-To: <5CA1D89F-9DDB-4F91-8929-FE29BB79A653@vmware.com> From: Linus Torvalds Date: Sat, 18 Dec 2021 14:53:38 -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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Dec 18, 2021 at 1:49 PM Nadav Amit wrote: > > Yes, I guess that you pin the pages early for RDMA registration, which > is also something you may do for IO-uring buffers. This would render > userfaultfd unusable. I think this is all on usefaultfd. That code literally stole two of the bits from the page table layout - bits that we could have used for better things. And guess what? Because it required those two bits in the page tables, and because that's non-portable, it turns out that UFFD_WP can only be enabled and only works on x86-64 in the first place. So UFFS_WP is fundamentally non-portable. Don't use it. Anyway, the good news is that I think that exactly because uffd_wp stole two bits from the page table layout, it already has all the knowledge it needs to handle this entirely on its own. It's just too lazy to do so now. In particular, it has that special UFFD_WP bit that basically says "this page is actually writable, but I've made it read-only just to get the fault for soft-dirty". And the hint here is that if the page truly *was* writable, then COW just shouldn't happen, and all that the page fault code should do is set soft-dirty and return with the page set writable. And if the page was *not* writable, then UFFD_WP wasn't actually needed in the first place, but the uffd code just sets it blindly. Notice? It _should_ be just an operation based purely on the page table contents, never even looking at the page AT ALL. Not even the page count, much less some mapcount thing. Done right, that soft-dirty thing could work even with no page backing at all, I think. But as far as I know, we've actually never seen a workload that does all this, so.. Does anybody even have a test-case? Because I do think that UFFD_WP really should never really look at the page, and this issue is actually independent of the "page_count() vs page_mapcount()" discussion. (Somewhat related aside: Looking up the page is actually one of the more expensive operations of a page fault and a lot of other page table manipulation functions - it's where most of the cache misses happen. That's true on the page fault side, but it's also true for things like copy_page_range() etc) Linus