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 X-Spam-Level: X-Spam-Status: No, score=-13.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5AD5DC4167D for ; Wed, 22 Sep 2021 20:55:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EA8B5611CA for ; Wed, 22 Sep 2021 20:55:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EA8B5611CA Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 492AE900003; Wed, 22 Sep 2021 16:55:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 41AD6900002; Wed, 22 Sep 2021 16:55:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 294EC900003; Wed, 22 Sep 2021 16:55:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0149.hostedemail.com [216.40.44.149]) by kanga.kvack.org (Postfix) with ESMTP id 16690900002 for ; Wed, 22 Sep 2021 16:55:31 -0400 (EDT) Received: from smtpin40.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id AFED81827E8F5 for ; Wed, 22 Sep 2021 20:55:30 +0000 (UTC) X-FDA: 78616415220.40.F0B38B1 Received: from mail-il1-f177.google.com (mail-il1-f177.google.com [209.85.166.177]) by imf12.hostedemail.com (Postfix) with ESMTP id 7541F100009D for ; Wed, 22 Sep 2021 20:55:30 +0000 (UTC) Received: by mail-il1-f177.google.com with SMTP id q14so4242404ils.5 for ; Wed, 22 Sep 2021 13:55:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=aW7ecSqbhvxt64O8aRVTZrLeEfv4TrofY/NqSmwmjHw=; b=DmJdXNCE0Nwcny13XuvXj5QJZWat2PFmP5CPAJfHFH7Q58HPTBwXGfOqlWV+8UWn6a 0iSCRzDWeqahYzCSxROnGBaXNJEECxbay1jRcMai2r4ckP9VJc14nBtHIaOle3YrUGCX kTV5DcjeE9Mf0f7u1m+YhEDzqR7tDTXA8xgSB/di5CgOnuaOx5L3H7mO/CND50iDNq8x Yspu5AMci3sXRtVPdGZidivUlISiIWfEkrkILlfYOxK1WKJPzTqPIS32rT1PPKfL3l+T 3L4U4Xj+1G636vd2t1gMi0qQJweUVmBXeaap/L4wvcgwPZ+qqYg6rn0+PUZ7Rl87Z8hH uI0A== 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=aW7ecSqbhvxt64O8aRVTZrLeEfv4TrofY/NqSmwmjHw=; b=ZynyRsMgteO/4BHMYNu1FWur2uUduLMwd84lfJbHl7QqhRyyOQMBWyRuz7OdCAxL+L shcZJebENCyISC7dDl7dpqPW5uBV11k1iO7GP+1zHzYreYxoR+1wlMnvdJP0ssh8ygCO sauWjgOdFr1IPkBQPaxxnvgeO0E+yHOSMTWUCXw0WKYvipY+2m8w4XeFnQUexqWJbLw2 oTa4R2S4GbLD7lz8DEgCOWBHw2Mcgmxpj0lhswvRLqBzpNr5kyhChN4TH7PJ1rhM8cq9 llmH3pktWRbcuWtfEUDCsJ/pAI5Pc7e2Qz81PAf32Y5uorR/VcFPOwnXUnZfRLsaOheC FIMg== X-Gm-Message-State: AOAM533iZg98mVOTqsayQlbkgT0OfDD34A+FzJ5h/QB6For08C2ErwCJ GqEhL/vJSxOw7qUQskdSTCQMPHMoJKThug04CwaBig== X-Google-Smtp-Source: ABdhPJzJ6nlzdCA9XqAxn2VzCOP46m3faMrD4uuSH/bEsyFxe4U4fP2ZKPRkTcIZA3nHbrHwqw4kohVKUHsNhN2aFKQ= X-Received: by 2002:a92:db0b:: with SMTP id b11mr774872iln.275.1632344129664; Wed, 22 Sep 2021 13:55:29 -0700 (PDT) MIME-Version: 1.0 References: <20210921163323.944352-1-axelrasmussen@google.com> In-Reply-To: From: Axel Rasmussen Date: Wed, 22 Sep 2021 13:54:53 -0700 Message-ID: Subject: Re: [PATCH 1/3] userfaultfd/selftests: fix feature support detection To: Peter Xu Cc: Andrew Morton , Shuah Khan , Linux MM , Linuxkselftest , LKML Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: x33iogwprxu73ebstnj7m791ejsgjb57 Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=DmJdXNCE; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of axelrasmussen@google.com designates 209.85.166.177 as permitted sender) smtp.mailfrom=axelrasmussen@google.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 7541F100009D X-HE-Tag: 1632344130-90315 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000004, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Sep 22, 2021 at 10:33 AM Peter Xu wrote: > > Hello, Axel, > > On Wed, Sep 22, 2021 at 10:04:03AM -0700, Axel Rasmussen wrote: > > Thanks for discussing the design Peter. I have some ideas which might > > make for a nicer v2; I'll massage the code a bit and see what I can > > come up with. > > Sure thing. Note again that as I don't have a strong opinion on that, feel > free to keep it. However if you provide v2, I'll read. > > [off-topic below] > > Another thing I probably have forgot but need your confirmation is, when you > worked on uffd minor mode, did you explicitly disable thp, or is it allowed? I gave a more detailed answer in the other thread, but: currently it is allowed, but this was a bug / oversight on my part. :) THP collapse can break the guarantees minor fault registration is trying to provide. I think your approach of checking the VMA flags *in retract_page_tables specifically* is correct, and a similar thing should be done for minor registered VMAs too. > > When I'm reworking the uffd-wp series, I noticed that commit e1e267c7928f > ("khugepaged: skip collapse if uffd-wp detected", 2020-04-07) was actually > awkward and not efficient, as we can simply lookup the vma flags for detecting > uffd-wp enablement. I'm preparing a patch for it to do it by checking vmas > (and that patch will also pave the way for file-backed). > > Then I noticed we need similar thing for minor mode? > > I think the answer is yes, but I didn't see any code that explicitly handled > thp for minor mode, do you remember? > > To be explicit, what if in mcontinue_atomic_pte() we get a shmem_getpage() call > with a thp returned? Will minor mode break? Ah so this I am not quite as sure about. The issue I was describing in the other thread was more about THP collapse racing with UFFDIO_CONTINUE. E.g., collapsing after registration has happened, but before faults have been resolved. But there's another scenario: what if the collapse happened well before registration happened? I *think* the existing code deals with THPs correctly in that case, but then again I don't think our selftest really covers this case, and it's not something I've tested in production either (to work around the other bug, we currently MADV_NOHUGEPAGE the area until after VM demand paging completes, and the UFFD registration is removed), so I am not super confident this is the case. > > I plan to post the khugepaged patch soon and I plan to cover minor mode too > there, but I'm not sure whether that's enough, as the thp can be there from the > 1st day I think, but I could have missed something. > > -- > Peter Xu > 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 X-Spam-Level: X-Spam-Status: No, score=-13.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 184FDC433EF for ; Wed, 22 Sep 2021 20:56:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EFCDF6112F for ; Wed, 22 Sep 2021 20:56:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238025AbhIVU53 (ORCPT ); Wed, 22 Sep 2021 16:57:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237948AbhIVU5A (ORCPT ); Wed, 22 Sep 2021 16:57:00 -0400 Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6472AC061762 for ; Wed, 22 Sep 2021 13:55:30 -0700 (PDT) Received: by mail-il1-x129.google.com with SMTP id d11so4223474ilc.8 for ; Wed, 22 Sep 2021 13:55:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=aW7ecSqbhvxt64O8aRVTZrLeEfv4TrofY/NqSmwmjHw=; b=DmJdXNCE0Nwcny13XuvXj5QJZWat2PFmP5CPAJfHFH7Q58HPTBwXGfOqlWV+8UWn6a 0iSCRzDWeqahYzCSxROnGBaXNJEECxbay1jRcMai2r4ckP9VJc14nBtHIaOle3YrUGCX kTV5DcjeE9Mf0f7u1m+YhEDzqR7tDTXA8xgSB/di5CgOnuaOx5L3H7mO/CND50iDNq8x Yspu5AMci3sXRtVPdGZidivUlISiIWfEkrkILlfYOxK1WKJPzTqPIS32rT1PPKfL3l+T 3L4U4Xj+1G636vd2t1gMi0qQJweUVmBXeaap/L4wvcgwPZ+qqYg6rn0+PUZ7Rl87Z8hH uI0A== 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=aW7ecSqbhvxt64O8aRVTZrLeEfv4TrofY/NqSmwmjHw=; b=ok1hwN1avWuST9Vt5u1gajKL607Z1Unesa+hgqs2Q+waH2mVYOKkJuGlDR2MEos2q0 V+VY9GhghwDOvrWENs8rxHLqWiO9CJRdWthuuNoXR1uyAmPx/x22RgAzB8L2F91jabxG BZTlaiBnC/R0nKliQ3wkL9Jnk3+IYgLf9ufwOlRVdpWgoIplpFDX8LgpLj4Egu/Uv5Bu XUWBejYu/irgi2TGp5grMN6G9cMe15lDtLOZkkaY2yeZFgXDOpPpiKwgTlAKt70Bqu5J C11KqHFJiG6Tm6GbPTxH/s3KuLDBrvENpA3P9LMoDEFf8WhGLKOw2f5Fx371hVuWGmOt n9HQ== X-Gm-Message-State: AOAM532+lu7hagWSCfL6GllCatV/hpBjk/1VTWtr6hgbNLGT2OCdfboZ gq9J5oXm8xcHMhPTlTF7UBGN/qptx0fg/2LD1Q8NpQ== X-Google-Smtp-Source: ABdhPJzJ6nlzdCA9XqAxn2VzCOP46m3faMrD4uuSH/bEsyFxe4U4fP2ZKPRkTcIZA3nHbrHwqw4kohVKUHsNhN2aFKQ= X-Received: by 2002:a92:db0b:: with SMTP id b11mr774872iln.275.1632344129664; Wed, 22 Sep 2021 13:55:29 -0700 (PDT) MIME-Version: 1.0 References: <20210921163323.944352-1-axelrasmussen@google.com> In-Reply-To: From: Axel Rasmussen Date: Wed, 22 Sep 2021 13:54:53 -0700 Message-ID: Subject: Re: [PATCH 1/3] userfaultfd/selftests: fix feature support detection To: Peter Xu Cc: Andrew Morton , Shuah Khan , Linux MM , Linuxkselftest , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 22, 2021 at 10:33 AM Peter Xu wrote: > > Hello, Axel, > > On Wed, Sep 22, 2021 at 10:04:03AM -0700, Axel Rasmussen wrote: > > Thanks for discussing the design Peter. I have some ideas which might > > make for a nicer v2; I'll massage the code a bit and see what I can > > come up with. > > Sure thing. Note again that as I don't have a strong opinion on that, feel > free to keep it. However if you provide v2, I'll read. > > [off-topic below] > > Another thing I probably have forgot but need your confirmation is, when you > worked on uffd minor mode, did you explicitly disable thp, or is it allowed? I gave a more detailed answer in the other thread, but: currently it is allowed, but this was a bug / oversight on my part. :) THP collapse can break the guarantees minor fault registration is trying to provide. I think your approach of checking the VMA flags *in retract_page_tables specifically* is correct, and a similar thing should be done for minor registered VMAs too. > > When I'm reworking the uffd-wp series, I noticed that commit e1e267c7928f > ("khugepaged: skip collapse if uffd-wp detected", 2020-04-07) was actually > awkward and not efficient, as we can simply lookup the vma flags for detecting > uffd-wp enablement. I'm preparing a patch for it to do it by checking vmas > (and that patch will also pave the way for file-backed). > > Then I noticed we need similar thing for minor mode? > > I think the answer is yes, but I didn't see any code that explicitly handled > thp for minor mode, do you remember? > > To be explicit, what if in mcontinue_atomic_pte() we get a shmem_getpage() call > with a thp returned? Will minor mode break? Ah so this I am not quite as sure about. The issue I was describing in the other thread was more about THP collapse racing with UFFDIO_CONTINUE. E.g., collapsing after registration has happened, but before faults have been resolved. But there's another scenario: what if the collapse happened well before registration happened? I *think* the existing code deals with THPs correctly in that case, but then again I don't think our selftest really covers this case, and it's not something I've tested in production either (to work around the other bug, we currently MADV_NOHUGEPAGE the area until after VM demand paging completes, and the UFFD registration is removed), so I am not super confident this is the case. > > I plan to post the khugepaged patch soon and I plan to cover minor mode too > there, but I'm not sure whether that's enough, as the thp can be there from the > 1st day I think, but I could have missed something. > > -- > Peter Xu >