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 46E47ECAAA1 for ; Tue, 30 Aug 2022 18:24:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C35838D0002; Tue, 30 Aug 2022 14:23:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BBCEF8D0001; Tue, 30 Aug 2022 14:23:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A36D78D0002; Tue, 30 Aug 2022 14:23:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8DA8B8D0001 for ; Tue, 30 Aug 2022 14:23:59 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 51BFA1404FC for ; Tue, 30 Aug 2022 18:23:59 +0000 (UTC) X-FDA: 79857082998.04.5027505 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 9EAC580059 for ; Tue, 30 Aug 2022 18:23:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661883838; 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=bvkFpN94R5cZg3/KW+m8BXutmrC9388CdG6tsEtPnYzSGHvgjEBBj1dnwdQTj4lsknamzn b1xScVdxyNvBTsh6PdfGwAc91qcRxMbWeU2GmOpBpk4oM8Bwo/y+84QiG+8ePj+kUnrwsY ZmrEl9uHW3Ylrg+g6/MDoNP16yS4+fI= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-627-9HDvxLcyMFSEWeIMIFZorg-1; Tue, 30 Aug 2022 14:23:56 -0400 X-MC-Unique: 9HDvxLcyMFSEWeIMIFZorg-1 Received: by mail-wr1-f71.google.com with SMTP id r20-20020adfb1d4000000b002258c581ba2so1915484wra.1 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=VSq7vfmc4alaZ2/N8t6YbgUMirNDSCPbzq8rNjxzK8CoWQ77mmJwmAaISPV7SmsZIG +rnCqCMM/1HsHOzNaFHweg9sqWB3VwASbYUrbEMaC1QIRYAVqs9okHt0pXJEgH7KA0UJ iH4pP/vIzWWkRbRoP0pUjxYVdybss3Ab8chIppfF1R+VtSx3CnNk1QqGsfXSQvxGohPX frTuQbrKmCsP5ZSXV0qrlc+kjjRE8VAFG+F9HtjzSX37YKDR2NHyRErHlDUmruiKxDif MCTrZ2c8h+pUpWnoPc4UGGADxrpyght1OXPQ+YyTD5+XNcgScOuYUrnfQc7dBnhZzviO pmaA== X-Gm-Message-State: ACgBeo3SNlVFAUpIaYiAah6tIV8SvfzUvpqR8XKgcMyPkgMrCFg1NVTT mUWDV5tcDk42vJevSUODXH6jcX+Cc0Yb2B9dTK5queK1S3klHA3ufTjudbfiIAN6uA9yjFE6Dza v4w7DVef1kWk= X-Received: by 2002:a05:600c:4e0f:b0:3a5:e065:9b50 with SMTP id b15-20020a05600c4e0f00b003a5e0659b50mr10494551wmq.35.1661883834467; Tue, 30 Aug 2022 11:23:54 -0700 (PDT) X-Google-Smtp-Source: AA6agR4oOp4zxQ/thee2JZtJ0alh2W3O9idTGxyH9xQar4vvfTNOtE/WqskpiaC27YCXMgTh0Fj/gQ== 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 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> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661883839; a=rsa-sha256; cv=none; b=Js/Z4/6Us/3p2W5O26Xe2+ZpMS9htPVdZv5GG/LbZGEfnh+WR0b/dU0WfCuz67JqRDWIAM Ae6SmCSo9MdcHR3+xx8xwBnTECHYrxLO2EKBt6/M/ukYtoEI9n2VaBaxemm6nhHzdDiG0k nZif2cTsLedX3fTXPLUH6WYUF9iYyOo= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bvkFpN94; spf=pass (imf30.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661883839; h=from:from:sender: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:dkim-signature; bh=Ir5bMIFXiZONcKjtB/Oq1xcLlKJ3S8ekcvj8t7HWk6Q=; b=CyeVfuuGfF5j7KbvFA9wDvIM0kIDF1et/TMJlVTISasbRr3RRueavwVISPiYZKjCHEi152 yM4FPH40rtqe4YbmR+HwlyxvWKrN+sHBnr0/Ly6SxjJC4mwqdqPJlWcfwdD6H+wp9Cydzv qNM7LmzyHlaAeVtCLEzRCMVAgmaNfug= X-Rspam-User: Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bvkFpN94; spf=pass (imf30.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: t6pp9jeez6q3md5hophip8iy7tso7ewp X-Rspamd-Queue-Id: 9EAC580059 X-Rspamd-Server: rspam10 X-HE-Tag: 1661883838-765998 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 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