Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp4556004rwe; Tue, 30 Aug 2022 12:17:02 -0700 (PDT) X-Google-Smtp-Source: AA6agR68OmccJafmE4ez3A5bR3H9S4jXMb4+tAjcKWKALPER2+IF2Py4W/+dQPcTF5SkVwyP84hT X-Received: by 2002:a17:906:8a54:b0:73d:c3c4:5db4 with SMTP id gx20-20020a1709068a5400b0073dc3c45db4mr18743884ejc.17.1661887022315; Tue, 30 Aug 2022 12:17:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661887022; cv=none; d=google.com; s=arc-20160816; b=TPNwi5WIU/1iksIjDfuk4C2UFdzfTZlMwMMORFDxkOFeb+KGJ8qhrVF48QR63TiXSV OwEvPdVORDMJRo4FrXvbR80mPhaRnE2D/KfqlxsxMbpP3II6xvWevlkhT65EOFm+y1gl YvPGN/raGUzqHiodeFDejfJA7+ffCeFNpNKkA+q5JnA21YN24bg85NbAiVG/5IoQparN PTErx1XnmbvdK6WL5k6qzCdqFFYB2MjjfkjGkVULtmWVvABMFvNbAFsI4sTP9UJTzszb bFCGgSeW7YODXL4q9xtwrtW4KyR2ijhD9CmeEQX9rIZRUdkFJO0COZbbIwr4kFXh6Cou 1bDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:references:cc:to:from:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=Ir5bMIFXiZONcKjtB/Oq1xcLlKJ3S8ekcvj8t7HWk6Q=; b=PEiUlXf1mpObbSeKs7Eeb6bm9Lku5ja+YVrYrS6r9SsL1hKMY51IZL3Qt8XAnOklsD hLeFdQ2OOmYO+oG4H4g4gdKtNmMo83+gdlY3yKv5QACQId+7m8p3lB15DwoORFNFZARu MERFXX6FVHuHY16jWpqcZzpbM1iiEpgPpd3tsXXr/LsQkTu9DxeLojd0Mf8TsXU59UaF AP8qm6K1OyCR6HbL4ZLWnyax/qwqGhviTrVaXLSyscLJIXdE1Yz+iXuEo2TilI79yCZP WQVDR8WZRuSWN0gimch1U2t40l99dC6eYXRYiFlf2ELlvDDQqz1xgxw7e5w2phshWKOz zP5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MRgX0vms; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ga32-20020a1709070c2000b0073d8663d88csi11058915ejc.685.2022.08.30.12.16.33; Tue, 30 Aug 2022 12:17:02 -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=@redhat.com header.s=mimecast20190719 header.b=MRgX0vms; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231264AbiH3SYB (ORCPT + 99 others); Tue, 30 Aug 2022 14:24:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230328AbiH3SX7 (ORCPT ); Tue, 30 Aug 2022 14:23:59 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D96B34F689 for ; Tue, 30 Aug 2022 11:23:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661883837; 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=Ir5bMIFXiZONcKjtB/Oq1xcLlKJ3S8ekcvj8t7HWk6Q=; b=MRgX0vmsN/+At5l58zch/I7BjOJpuxWX9obtA02MORy+LhY0LfoEVTNaI2LRL8WbCq8j+i JDsEwBsg24Z6kuubodmUXt/LsiXYKI0uxQBRoSME05kQqKDhGM8G+4kNeqec3cb5kNvJJt rpP8gFX1iYFg27p0vIXC7WbkIpFOXc4= 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.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-1-DetVjwetPf65Nthl2j4zrQ-1; Tue, 30 Aug 2022 14:23:56 -0400 X-MC-Unique: DetVjwetPf65Nthl2j4zrQ-1 Received: by mail-wr1-f69.google.com with SMTP id j4-20020adfa544000000b002255264474bso1929170wrb.17 for ; Tue, 30 Aug 2022 11:23:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc; bh=Ir5bMIFXiZONcKjtB/Oq1xcLlKJ3S8ekcvj8t7HWk6Q=; b=s0Ys0YxQ9M24qC2quS6FxeISsAQXLwZ4WXj6xCczoSihqL0W097MahvBuQpUP49AN+ Y/tHrtZ5QZ4SooXhHo46GNtRyVDALS8RmoEoNVYBDKz7pl46/kTGbxUOG2HqPphIbkv7 iI5hkqEnZQ6civkOnktM/kjcMXr1uX/6nbvX64d0QGUplgD1ZZi24H9acaIQUGsNdrhV kHvSc9o1WCqmAVwsIFVdoAYQkR7rnwelLgFyaYrZfMaVd3vaP7o9ttEV55iZuAliPXLp s/FFWjQRByAMa0+ekQV0OL5ldmlwR1mEk0E+atL6Lnj2K4HfYsAQ/DQErLzV6YSFF/pU 1vww== X-Gm-Message-State: ACgBeo1UDGx/vCSXhF2Qtsq4qvdoud0hiQy06jyAHTO0E/Jg0Ulf5pjO eLasyAbS8V1wsul749PwMGptC3qOftOtDSTkzmHL5XkY9p6foGkr5KTamEwW0Zc4hvq6hJeWqRq 0jUavbydj3ndr30Ox4mQzH8unTMNlWYPPPdD6SdGBcZlt3aWlCWk/OW6Pc8dwXQGiyZt/EtiR X-Received: by 2002:a05:600c:4e0f:b0:3a5:e065:9b50 with SMTP id b15-20020a05600c4e0f00b003a5e0659b50mr10494561wmq.35.1661883834506; Tue, 30 Aug 2022 11:23:54 -0700 (PDT) X-Received: by 2002:a05:600c:4e0f:b0:3a5:e065:9b50 with SMTP id b15-20020a05600c4e0f00b003a5e0659b50mr10494538wmq.35.1661883834131; Tue, 30 Aug 2022 11:23:54 -0700 (PDT) Received: from ?IPV6:2003:cb:c70a:1000:ecb4:919b:e3d3:e20b? (p200300cbc70a1000ecb4919be3d3e20b.dip0.t-ipconnect.de. [2003:cb:c70a:1000:ecb4:919b:e3d3:e20b]) by smtp.gmail.com with ESMTPSA id c124-20020a1c3582000000b003a30fbde91dsm12810957wma.20.2022.08.30.11.23.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Aug 2022 11:23:53 -0700 (PDT) Message-ID: <2e20c90d-4d1f-dd83-aa63-9d8d17021263@redhat.com> Date: Tue, 30 Aug 2022 20:23:52 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [PATCH v1 2/3] mm/gup: use gup_can_follow_protnone() also in GUP-fast Content-Language: en-US From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Andrew Morton , Mel Gorman , Jason Gunthorpe , John Hubbard , "Matthew Wilcox (Oracle)" , Andrea Arcangeli , Hugh Dickins , Peter Xu References: <20220825164659.89824-1-david@redhat.com> <20220825164659.89824-3-david@redhat.com> <1892f6de-fd22-0e8b-3ff6-4c8641e1c68e@redhat.com> Organization: Red Hat In-Reply-To: <1892f6de-fd22-0e8b-3ff6-4c8641e1c68e@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 26.08.22 16:59, David Hildenbrand wrote: > On 25.08.22 18:46, David Hildenbrand wrote: >> There seems to be no reason why FOLL_FORCE during GUP-fast would have to >> fallback to the slow path when stumbling over a PROT_NONE mapped page. We >> only have to trigger hinting faults in case FOLL_FORCE is not set, and any >> kind of fault handling naturally happens from the slow path -- where >> NUMA hinting accounting/handling would be performed. >> >> Note that the comment regarding THP migration is outdated: >> commit 2b4847e73004 ("mm: numa: serialise parallel get_user_page against >> THP migration") described that this was required for THP due to lack of PMD >> migration entries. Nowadays, we do have proper PMD migration entries in >> place -- see set_pmd_migration_entry(), which does a proper >> pmdp_invalidate() when placing the migration entry. >> >> So let's just reuse gup_can_follow_protnone() here to make it >> consistent and drop the somewhat outdated comments. >> >> Signed-off-by: David Hildenbrand >> --- >> mm/gup.c | 14 +++----------- >> 1 file changed, 3 insertions(+), 11 deletions(-) >> >> diff --git a/mm/gup.c b/mm/gup.c >> index a1355dbd848e..dfef23071dc8 100644 >> --- a/mm/gup.c >> +++ b/mm/gup.c >> @@ -2350,11 +2350,7 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end, >> struct page *page; >> struct folio *folio; >> >> - /* >> - * Similar to the PMD case below, NUMA hinting must take slow >> - * path using the pte_protnone check. >> - */ >> - if (pte_protnone(pte)) >> + if (pte_protnone(pte) && !gup_can_follow_protnone(flags)) >> goto pte_unmap; >> >> if (!pte_access_permitted(pte, flags & FOLL_WRITE)) >> @@ -2736,12 +2732,8 @@ static int gup_pmd_range(pud_t *pudp, pud_t pud, unsigned long addr, unsigned lo >> >> if (unlikely(pmd_trans_huge(pmd) || pmd_huge(pmd) || >> pmd_devmap(pmd))) { >> - /* >> - * NUMA hinting faults need to be handled in the GUP >> - * slowpath for accounting purposes and so that they >> - * can be serialised against THP migration. >> - */ >> - if (pmd_protnone(pmd)) >> + if (pmd_protnone(pmd) && >> + !gup_can_follow_protnone(flags)) >> return 0; >> >> if (!gup_huge_pmd(pmd, pmdp, addr, next, flags, > > > I just stumbled over something interesting. If we have a pte_protnone() > entry, ptep_clear_flush() might not flush, because the !pte_accessible() > does not hold. > > Consequently, we could be in trouble when using ptep_clear_flush() on a > pte_protnone() PTE to make sure that GUP cannot run anymore. > > Will give this a better thought, but most probably I'll replace this > patch by a proper documentation update here. ... and looking into the details of TLB flush and GUP-fast interaction nowadays, that case is no longer relevant. A TLB flush is no longer sufficient to stop concurrent GUP-fast ever since we introduced generic RCU GUP-fast. -- Thanks, David / dhildenb