From patchwork Tue Dec 19 07:55:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13497942 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 AE4CDC41535 for ; Tue, 19 Dec 2023 07:57:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 47F2C8D000A; Tue, 19 Dec 2023 02:57:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 406D78D0005; Tue, 19 Dec 2023 02:57:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2830D8D000A; Tue, 19 Dec 2023 02:57:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 106878D0005 for ; Tue, 19 Dec 2023 02:57:13 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E48ED120480 for ; Tue, 19 Dec 2023 07:57:12 +0000 (UTC) X-FDA: 81582812304.02.C486C37 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 221504000F for ; Tue, 19 Dec 2023 07:57:10 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OmeSxnUw; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702972631; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=uyBT0nqGKaQsvTTr5mCIJmcBkZIho6YT9IXUJI5Nmzw=; b=HB08hR42PLdHIEu58BxNFikAO1C6KkibTXcN83WI931Xc5ei5xCAg9W2OLalPVSfQ3CVmS 08DO9tLIESrjabZWz4yz2Q91B7s2EOF7KWTizASZls7vTsEJISHYiRjRbcIBitYD5/zrxu TEzYy2B9w2JL2QhPTlJ4eQl2sb8nOtU= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OmeSxnUw; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702972631; a=rsa-sha256; cv=none; b=LYUDkh9n/uTyqlYbM8n0iioeFV/Xc/UWdYMAjNQPtQVKO00knIonTZtoKZiWEtND3IBGoI m+h91QluJeUM7jDyuigEzrEgflMMW9Pas6uhPbOEjx+Kcdg5YQoI7qp49InbL/jbgO3fik iKsCbWu1q6oAlaB1qjFfbk8ArHfTkgk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702972630; 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=uyBT0nqGKaQsvTTr5mCIJmcBkZIho6YT9IXUJI5Nmzw=; b=OmeSxnUwWoa6tJ92TEOtR66UT11ctZnKhQExLfg5A/gxJiEJyQXNN9esZEndlyUOV1QssQ FDfhQRtavalAv+kVai8dgU++/wN8+fOhJURpiHAgFywr7UWQnM4bvY0nn8Q+2EzpcOXrZV 09ouaY5IqGNgSE3ZIuDkV8X89tVNuoA= 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-150-L9GGlqWjOR6XdFWT616TOg-1; Tue, 19 Dec 2023 02:57:06 -0500 X-MC-Unique: L9GGlqWjOR6XdFWT616TOg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 E4B5F3813F20; Tue, 19 Dec 2023 07:57:04 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id EAA8A2026D66; Tue, 19 Dec 2023 07:56:53 +0000 (UTC) From: peterx@redhat.com To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Matthew Wilcox , Christophe Leroy , Lorenzo Stoakes , David Hildenbrand , Vlastimil Babka , Mike Kravetz , Mike Rapoport , Christoph Hellwig , John Hubbard , Andrew Jones , linux-arm-kernel@lists.infradead.org, Michael Ellerman , "Kirill A . Shutemov" , linuxppc-dev@lists.ozlabs.org, Rik van Riel , linux-riscv@lists.infradead.org, Yang Shi , James Houghton , "Aneesh Kumar K . V" , Andrew Morton , Jason Gunthorpe , Andrea Arcangeli , peterx@redhat.com, Axel Rasmussen Subject: [PATCH 06/13] mm/gup: Drop folio_fast_pin_allowed() in hugepd processing Date: Tue, 19 Dec 2023 15:55:31 +0800 Message-ID: <20231219075538.414708-7-peterx@redhat.com> In-Reply-To: <20231219075538.414708-1-peterx@redhat.com> References: <20231219075538.414708-1-peterx@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 221504000F X-Stat-Signature: sptwqcr6g7sx4s1djaknm963nke8t8ts X-HE-Tag: 1702972630-640464 X-HE-Meta: U2FsdGVkX191wX89E29jUwHk6UFQxZQVcaRpTR6nQjBuDwv/iFKRhvKZ/S7tjAfsSoV2Qd/hi0itt3LdHYegkP31vP29J5PE/9Vju4R96HGRZ/RaUG+c6QrOsQGjjDqTbHJKdufbF6d5UH/3/866WyGI9LWTyL3aYt168xFI/0Fi1OUmUwM9kbyob1cJittefHdzOeJH/Nk+8bm+pKWgcM0O5vZxkvFIRBem0Urfd0MVQyPRuja20OZKZODPMWpWWDjEPGjO4vKMogc6tw0oXzbhz/19oAt733XzobmFwD/PCtAfh+rZNhPT86L3Rx6/NVICu/pP9wB/74PF9chyP3P4/q4Q68kXVM13g5PozfHwf/QXw8z6NkqD/dzRfHTuTAW7O0Z65UbloHgy/7qG8Erp8l3zh7HOc79jC+iubOgW0b4c5gvRvvNoc8u1gol6jMuzp2j1MgaDAYGk06/BS/UOXwx5+wP/1lcmADJ1p2rnNgnse+lHoi0jYXHGVTZd4BDnes1LOR09sQ81VZrtqJVD5imLvSSddIn/3MrsosRVx0Np/cXWrc2WeaqTZUEhCNjWXcgwYZ+i2ZNV5LnNhDvtcuTtW9L36KlAnt0F7S5cx7Olo2iDcDjDTauSb6x6VyZFEjqQ6ll4C+8Wh9nYkhSrvddZXb4+ZXKpNaw5CkAyVY2EJupGg85iKJx8fkXoN3QtC2o8A/QxFer3T23FgJ0w2IRggk6GVzcnY9NLr1EV3RWReliDKxRhmuucLBtL6znFLkL9to5wnavNmxXx9ItDhF1tk+ZX0ZSeF7MjsSnBcdU827E9Lg+vw2BlCSA54Ehnj+mVCVDz+/EwKGcFCiyyabT/2Y6yiYbFQ+7iZ4QOriqPgyoAK8aF7weKXFtruxaGr5OM4zHan39xTcCZrK/qlXdGX+b/poUmzDCpKCNh8STdHjDXVk307e6rd12j2t2SX86VlJmBrcJ2XOS uyq/th6x l4BLYQsH7Jy+eX3zWNQre0zqobRALJlO0uhzR8FXk7G7Csh2AXzpbYqjZd6u6Nb2qafGikxhgPcmet3Lizy9U/01AOYP4reh9AcoDFBon7qg5KDZcunnTiqp/B2AoKc+L3LLQTgXoYVhX82ejpHf+KmQa8F7RVD83Kia/FvT/lXZrii+py6uLfJQmBn6K8LvcKVaN/QfVgoySP1oDRR7DzKqEpitE9KSn07SHWUW5Vd8jMWp79jCcyHD8uRbN2p6q27y6pA3O7J5my1nbSHYLxN54QPfa8lry3poMfrYJZ+5uHaVkMKl61LBpuT9rNYQrC6/UGVbJ85KgdSx5a61jVQR3SM+N6Krts3sL93btHaCUYeI= 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: List-Subscribe: List-Unsubscribe: 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 efc9847e58fb..bb5b7134f10b 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)