Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7013741rdb; Wed, 3 Jan 2024 01:17:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IGNjTJY/EbspVaWlMQEiMBAJr7fAAQ41y6QfcQzNSjG5Ttt4Xjb8dxIxYuyweyvmQ+qTlgZ X-Received: by 2002:a50:cdd9:0:b0:553:6c79:ac7 with SMTP id h25-20020a50cdd9000000b005536c790ac7mr11560994edj.9.1704273427194; Wed, 03 Jan 2024 01:17:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704273427; cv=none; d=google.com; s=arc-20160816; b=kp+MibOpaTKX2T+1vHDmoLBYxl/Bk6E3Mro0nqgr4/BjiWzZnbwtdRHZr4KRW3xepw zFHlC1O+ua669UJvuO8MuGQ4Mfx4RuLpvjwIb2gL9O33/YKd/5vdN67OEoiae7y3a08b voAtGVGGhpkwhr3vkwChtAep7BjoccBIXn9zp5w7aAyxCMQl/IJRAdS7lBL1jbco/Ecj +b0GVv0bND/u+j1c+NDYZ24kc+n6MY6xYKr7Eg8/3XmC+/u0yuP686Yf5w+6qpVgU0oA fIgIp9BrHbt2EtOpEGnU2wrGweT9wF+/UJittEgAstHDKxj/VdU7g1+jlpb9efHXLY91 bpMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=G2mMJAnaoVdNju5RvSwq+KPjZVLCTkTT7F8NTqIl1do=; fh=JvQ3nGflNTIwPBfhSW2OJAIjHOHR+R1SiFkwzYoQoWY=; b=tA+mKGY2cBBkw4rAchZp9dRQn7912ui+Dfx9BSMBQ/epJSTlFW6SNFhw04Dgh2wlZq 4b79eVln7dk6aV3L9AwiKPNw1Fi5tVgs4HWHS9AZUciEVgLTI4w8GTQyij8QK31G0uzE xzfl8ea8OE8RfIlQSPwYEj0l4y0nnWXUmokNHzgiX3dXW4UX3ECMcxTazXXeJ/R7WbZW YJXGPVfrheOLWy2TgwtPgNigPi8OmpZG3k6BmHf7zX3WtxgwpxNcGP3g6HxRde0kH1Vi QVfA7er2FoArqIPNi+b8q3LS/NkNDaqQAlTeW3B2ZqXcqSNcKDgOFUWSqFjhS7jKBjSU 7GPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=W2nDFnAo; spf=pass (google.com: domain of linux-kernel+bounces-15321-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15321-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g9-20020a0564021ec900b00554b6ac5ef4si9210544edg.110.2024.01.03.01.17.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 01:17:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15321-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=W2nDFnAo; spf=pass (google.com: domain of linux-kernel+bounces-15321-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15321-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E3AD81F210EF for ; Wed, 3 Jan 2024 09:17:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B631019470; Wed, 3 Jan 2024 09:16:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="W2nDFnAo" X-Original-To: linux-kernel@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D61D19460 for ; Wed, 3 Jan 2024 09:15:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704273357; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G2mMJAnaoVdNju5RvSwq+KPjZVLCTkTT7F8NTqIl1do=; b=W2nDFnAo2k/r2mcW39A/X1smFLZBFebFY6dVdlmkG+cpBa/G5kzVVIe0fdI9hvcNc5oWNf DelYLVoXhZnROpgS8bGkAsCTxEYKxi08nEdhGsDRZt1vA3QQqcJZbXG+eKrIZHI5cmFBlA Ei37M+7CX10S+m/zLlaHsccumopGPpk= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-597-sJHnyUgTOIGCIKVC1MWAaQ-1; Wed, 03 Jan 2024 04:15:53 -0500 X-MC-Unique: sJHnyUgTOIGCIKVC1MWAaQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 731831C0512D; Wed, 3 Jan 2024 09:15:52 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.69]) by smtp.corp.redhat.com (Postfix) with ESMTP id DBCD9492BE6; Wed, 3 Jan 2024 09:15:41 +0000 (UTC) From: peterx@redhat.com To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: James Houghton , David Hildenbrand , "Kirill A . Shutemov" , Yang Shi , peterx@redhat.com, linux-riscv@lists.infradead.org, Andrew Morton , "Aneesh Kumar K . V" , Rik van Riel , Andrea Arcangeli , Axel Rasmussen , Mike Rapoport , John Hubbard , Vlastimil Babka , Michael Ellerman , Christophe Leroy , Andrew Jones , linuxppc-dev@lists.ozlabs.org, Mike Kravetz , Muchun Song , linux-arm-kernel@lists.infradead.org, Jason Gunthorpe , Christoph Hellwig , Lorenzo Stoakes , Matthew Wilcox Subject: [PATCH v2 06/13] mm/gup: Drop folio_fast_pin_allowed() in hugepd processing Date: Wed, 3 Jan 2024 17:14:16 +0800 Message-ID: <20240103091423.400294-7-peterx@redhat.com> In-Reply-To: <20240103091423.400294-1-peterx@redhat.com> References: <20240103091423.400294-1-peterx@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 From: Peter Xu Hugepd format for GUP is only used in PowerPC with hugetlbfs. There are some kernel usage of hugepd (can refer to hugepd_populate_kernel() for PPC_8XX), however those pages are not candidates for GUP. Commit a6e79df92e4a ("mm/gup: disallow FOLL_LONGTERM GUP-fast writing to file-backed mappings") added a check to fail gup-fast if there's potential risk of violating GUP over writeback file systems. That should never apply to hugepd. Considering that hugepd is an old format (and even software-only), there's no plan to extend hugepd into other file typed memories that is prone to the same issue. Drop that check, not only because it'll never be true for hugepd per any known plan, but also it paves way for reusing the function outside fast-gup. To make sure we'll still remember this issue just in case hugepd will be extended to support non-hugetlbfs memories, add a rich comment above gup_huge_pd(), explaining the issue with proper references. Cc: Christoph Hellwig Cc: Lorenzo Stoakes Cc: Michael Ellerman Cc: linuxppc-dev@lists.ozlabs.org Signed-off-by: Peter Xu --- mm/gup.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index eebae70d2465..fa93e14b7fca 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2820,11 +2820,6 @@ static int gup_hugepte(pte_t *ptep, unsigned long sz, unsigned long addr, return 0; } - if (!folio_fast_pin_allowed(folio, flags)) { - gup_put_folio(folio, refs, flags); - return 0; - } - if (!pte_write(pte) && gup_must_unshare(NULL, flags, &folio->page)) { gup_put_folio(folio, refs, flags); return 0; @@ -2835,6 +2830,14 @@ static int gup_hugepte(pte_t *ptep, unsigned long sz, unsigned long addr, return 1; } +/* + * NOTE: currently GUP for a hugepd is only possible on hugetlbfs file + * systems on Power, which does not have issue with folio writeback against + * GUP updates. When hugepd will be extended to support non-hugetlbfs or + * even anonymous memory, we need to do extra check as what we do with most + * of the other folios. See writable_file_mapping_allowed() and + * folio_fast_pin_allowed() for more information. + */ static int gup_huge_pd(hugepd_t hugepd, unsigned long addr, unsigned int pdshift, unsigned long end, unsigned int flags, struct page **pages, int *nr) -- 2.41.0