Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp1501556rwb; Fri, 28 Jul 2023 10:14:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlF54xp9rJyGqgcoYNRt9+n16Z4eSF2SlOo5uZ2Nw9dY15Br+Uqs/lGkR7SLDcdbHoQLyXCl X-Received: by 2002:a17:902:e751:b0:1b0:f727:bc41 with SMTP id p17-20020a170902e75100b001b0f727bc41mr2359118plf.42.1690564458323; Fri, 28 Jul 2023 10:14:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690564458; cv=none; d=google.com; s=arc-20160816; b=L1BgLHygzL+xuYIMwgEsWILkPwQvs8Ur2CM+OzAi+R6L4IJPf3N3dzY6T505VzPXJs X9W4MyUBBjG3y+hjp6v9bApYkjR+vqaBBLtj4u/qsupdGE4QSZZFbdXN/YWqtQTIczYQ AMsFr26lclbXI2yc6RC79LgEC/bp//QmOGsty1URrGRFFeArCRSgz3M85aB/kzGX8oz2 amDBgW+J+pLdhA6XLQ5ByG0ZiMhe1qtBXKuXIb2KUy6BujzVKP0qbS4w4GcQmdu271UR PQ5BQY+NOSHE1p3g9cDlnCN42EWAh641syfPu4qIWbKI1p14hoGnTYD5SXsdZKjWeRuM BfYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=oiqXtLXb56gWHpFHlkrGXB0htpi3zn1ShhYELBek5ko=; fh=bnh+SVW6DtfOZQygvKh07tiSRTo7kAIX8qvMSlPp7xA=; b=Sl0S4Vyqfkey77I6RkC3I4/f0aYFAYTBajop0e76ch2dHXFMtj58QT/ZNX88sY9Q0E dVYwe0xDy/n2vvBetdXEfmwvlqxs5kIdTC9JP+N7vlb2/rb7mW/ASUkk9tqa5M5oaNP+ 0DnZaoNP+d5XmK/PAsWiyMIK9QZZU7d3FbqCD6H7+N0PbgEmRhgdoqS/lv9hSDgpYJAE daf4kK1aXq16DpEbijB0KYXvaXpFZjQXFCQ7czhIvIVM/YTvBSC8x90UKzGMkXcXu9It uFmhxt5oLNDU1Lssq9V/A1Wc/5YGCros5pAFXU7bhWGbvs049UHeATPoXWoabMO3QdZO VywQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=bynKf6n+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j14-20020a170903028e00b001b81a112f9bsi3298211plr.586.2023.07.28.10.14.04; Fri, 28 Jul 2023 10:14:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=bynKf6n+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230244AbjG1QTK (ORCPT + 99 others); Fri, 28 Jul 2023 12:19:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229885AbjG1QTH (ORCPT ); Fri, 28 Jul 2023 12:19:07 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A659F1BF2 for ; Fri, 28 Jul 2023 09:19:04 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-99bed101b70so129084766b.3 for ; Fri, 28 Jul 2023 09:19:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1690561143; x=1691165943; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=oiqXtLXb56gWHpFHlkrGXB0htpi3zn1ShhYELBek5ko=; b=bynKf6n+TpRfz0DyR2rYNbqu0v4M0dTgmVz8xWQq8X+28lhY2cl5XnPRKgqX9HAqiE H79vFTkAB/9Itwu2leZ1xBpWwBB4F2uReu+dWnEz72qQ+dgV9BK2g3sOlh+7HQG5ShkZ 9P+UQsfvk3Zbb2D6K+z9GjqGwuGQGpMLf/2Vk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690561143; x=1691165943; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=oiqXtLXb56gWHpFHlkrGXB0htpi3zn1ShhYELBek5ko=; b=OuzElrfl70+GCeOfi5AujhdSfCarjsZWEopwmYp5EMS+S5Sxkdk2oubCc/9lfyUddG je0RSUfICqhycR+eqvud7Ft1Q0qKpBB6vavBcMPlaNjSAiVPb5wWdLbZbzdAPpmNY7h8 bjhrlcLfeb/GmEHZKxbRrWd2fmK/x67mD9g+fibNRmyRKiw2s3DUAJTFfqsGMXSAwIWj dxBQ/xzSgG2Tv/cBb97sfMU+XMnjztyntVlqHkjhXnLC1GvKBl7EyaHSegwSNX7skddH b5auryxmOaC93N5Bk7AdcW2cLGhpjWA5rwotsrwZhoW3w/oMVZslDXiQ0SMw7DOiNrN6 9crw== X-Gm-Message-State: ABy/qLaBuWSid5N+T8Pej8yiye02/kuiy2CCqgbIP1nJE8SdoEeh7RKq P75Gd1Zw3GxC70KPZRNUVcuhKWiLd58N+b5XWVL7aBDt X-Received: by 2002:a17:906:845c:b0:99b:465c:fb9f with SMTP id e28-20020a170906845c00b0099b465cfb9fmr2787546ejy.8.1690561142849; Fri, 28 Jul 2023 09:19:02 -0700 (PDT) Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com. [209.85.208.44]) by smtp.gmail.com with ESMTPSA id dc26-20020a170906c7da00b00988e953a586sm2220259ejb.61.2023.07.28.09.19.02 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 28 Jul 2023 09:19:02 -0700 (PDT) Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-5222b917e0cso3093600a12.0 for ; Fri, 28 Jul 2023 09:19:02 -0700 (PDT) X-Received: by 2002:a05:6402:1141:b0:51e:5322:a642 with SMTP id g1-20020a056402114100b0051e5322a642mr2296690edw.27.1690561141923; Fri, 28 Jul 2023 09:19:01 -0700 (PDT) MIME-Version: 1.0 References: <20230727212845.135673-1-david@redhat.com> In-Reply-To: <20230727212845.135673-1-david@redhat.com> From: Linus Torvalds Date: Fri, 28 Jul 2023 09:18:45 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v1 0/4] smaps / mm/gup: fix gup_can_follow_protnone fallout To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Andrew Morton , liubo , Peter Xu , Matthew Wilcox , Hugh Dickins , Jason Gunthorpe , John Hubbard Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 27 Jul 2023 at 14:28, David Hildenbrand wrote: > > This is my proposal on how to handle the fallout of 474098edac26 > ("mm/gup: replace FOLL_NUMA by gup_can_follow_protnone()") where I > accidentially missed that follow_page() and smaps implicitly kept the > FOLL_NUMA flag clear by *not* setting it if FOLL_FORCE is absent, to > not trigger faults on PROT_NONE-mapped PTEs. Ugh. I hate how it uses FOLL_FORCE that is inherently scary. Why do we have that "gup_can_follow_protnone()" logic AT ALL? Couldn't we just get rid of that disgusting thing, and just say that GUP (and follow_page()) always just ignores NUMA hinting, and always just follows protnone? We literally used to have this: if (!(gup_flags & FOLL_FORCE)) gup_flags |= FOLL_NUMA; ie we *always* set FOLL_NUMA for any sane situation. FOLL_FORCE should be the rare crazy case. The original reason for not setting FOLL_NUMA all the time is documented in commit 0b9d705297b2 ("mm: numa: Support NUMA hinting page faults from gup/gup_fast") from way back in 2012: * If FOLL_FORCE and FOLL_NUMA are both set, handle_mm_fault * would be called on PROT_NONE ranges. We must never invoke * handle_mm_fault on PROT_NONE ranges or the NUMA hinting * page faults would unprotect the PROT_NONE ranges if * _PAGE_NUMA and _PAGE_PROTNONE are sharing the same pte/pmd * bitflag. So to avoid that, don't set FOLL_NUMA if * FOLL_FORCE is set. but I don't think the original reason for this is *true* any more. Because then two years later in 2014, in commit c46a7c817e66 ("x86: define _PAGE_NUMA by reusing software bits on the PMD and PTE levels") Mel made the code able to distinguish between PROT_NONE and NUMA pages, and he changed the comment above too. But I get the very very strong feeling that instead of changing the comment, he should have actually removed the comment and the code. So I get the strong feeling that all these FOLL_NUMA games should just go away. You removed the FOLL_NUMA bit, but you replaced it with using FOLL_FORCE. So rather than make this all even more opaque and make it even harder to figure out why we have that code in the first place, I think it should all just be removed. The original reason for FOLL_NUMA simply does not exist any more. We know exactly when a page is marked for NUMA faulting, and we should simply *ignore* it for GUP and follow_page(). I think we should treat a NUMA-faulting page as just being present (and not NUMA-fault it). Am I missing something? Linus