From patchwork Wed Jan 3 09:14:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13509768 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 A39FEC47079 for ; Wed, 3 Jan 2024 09:16:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 217838D0054; Wed, 3 Jan 2024 04:16:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1C5948D0053; Wed, 3 Jan 2024 04:16:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E6F748D0054; Wed, 3 Jan 2024 04:16:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C22888D0035 for ; Wed, 3 Jan 2024 04:16:05 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 69FC31A08FD for ; Wed, 3 Jan 2024 09:16:02 +0000 (UTC) X-FDA: 81637442964.19.135BA4C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf20.hostedemail.com (Postfix) with ESMTP id 77FF51C0046 for ; Wed, 3 Jan 2024 09:15:58 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=W2nDFnAo; spf=pass (imf20.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@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=1704273358; 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=G2mMJAnaoVdNju5RvSwq+KPjZVLCTkTT7F8NTqIl1do=; b=Ha6zlxughOBOzESekTIcaH/vzsfE284iyWOWkGyxmbmNOEnCodD2NzCGbAeMZFMkzxQZC3 4smwPDUSuLzZrqv9v97i3tPwNJkLaXGOwwm3K8iEy/xkAucjQczFFm/CoC4M9BbS+mnyAz Sm+VuykwpmBfx5rDvWCTrdJ2V12iS0I= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704273358; a=rsa-sha256; cv=none; b=YYzB/DFH/u4cWgc6jtU7yLXRNUlLalbBZ7qkijUVHoQ0ZN2lS1+2Ed5qMcYdLYxDrvnALx dbDOI40x+CW5xrXJKveiSeSI6CyOeDWSsYP9UjhW0ZK/+sbrC5KMZTn2QVZdK/WQz6Sn73 aMKfj8hsvXvD3YsMtuAGsfvTf++n9Ac= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=W2nDFnAo; spf=pass (imf20.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=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> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Stat-Signature: ph7y8wst48k4fdozrdyik8bcrcgdr3ji X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 77FF51C0046 X-Rspam-User: X-HE-Tag: 1704273358-790057 X-HE-Meta: U2FsdGVkX18L5IvFNLIxkQ9I798jJCpk/7/ExBUR/Vq4j+xQD+c01woB+Ge9EjBRmemktfN/7YfKPD7pdReKGJahm/cAdmj+T6UhNxdRy9evHbdE/DkFhgSQ1qh0uz5Cf1arXWgFab5gb6ZRlX5Sm63LERd59QsLsioF6I7P2kPwGFvIBfDuWSCZAKKuvg3wsSkKLuZAasvd4k/eyVHwPOF1oD5ae/pD7DyPlBsuhgL2RDwbp2sg8qF9Le8WnvOi6kAMGwmtWYVV68B/Jlg77eCX9Sjr+ht4xujsweW0uX7DzOrKrcpyVEPPKZ3h0ggd7iDxTAgxVVRboVRO5MU2I+hmVik5C4B2/sJNnIUvzLu7x+u4548BK9rTBGYIFLwlMBOJvMVACvO4uSm/OieUc03DgpBOG7M3Q8d6vUlZvQTNT+5ONEKF2othSllHtEJ1mY+b1pKGK0TmExdkZnm3ZftMStTxkd37P25fTBOV6OfC8yuv6D6TJPH+B/BEecqfAOvsyR8I+UpDBFPfeEn38JmOllapZIDeZxh1e4kAfitduIoEuAYSyvbyRB8754y3LzlOu/XSGPgqnCTSX/+tzp5/JGL0zxpoemTEdm1MPoq5/w4GqtietkbDaeLcAQIuGE+UJI1t08W7A5WWFdcVTEIvfQ5H9XubMZ00QLF36ChedHB8WvW3PCAV02dldENkXbwoKS1O8O9+3NYyy/hSCCyDLxtwhDQ+7ZwetE7+wAJnajqlwMSWi5MyINd0HxerQWvfyOOtquBfUnnScXygKa9aIxwO9KvRN4Dagm6Eq1yi7RvJNlTRbQvcA6Ufo3HxKiKk2FLvDRQbb/+uQC39kT0LbOtSn0F7VVNJ/eCbKWB3qIx/IeW//67VXpTxAYJupWjIubq66wMa/4xPCyNkGx8uRusdUUvr4ta6KYwDN3OwlWdZBW96P0HDIov0YhRIGMBuGXF9z6L8fWdBMCf KVihbwZO b5tP0m8CkmwnoOq6oyAuENqEprrKE0CvROCooUHS7GnvdNtnVDGWYOzrpnG0jr22FltZJACo7VqTJwpA6p6AmyBjNh1YcPILdB9b7FsHQ7WaKQ03ZXMZjgn0fynvtuEMjKEBRgb5rb5zZvC6aRAxXGFMo2B1qDX+y8h6JdxsgsORFkzS/ZvBcUfVvuZe0W57V9dNflh1P63MSgvYgXfdWcTSmjOYuigmvA/K3kbbO31lL4gyY9gQ2yPYX91NkoQJKEKVeaK7s0NsA4MkweSztqtU8N85LRhxaRdCCaDo4T15S7pwRahAbPcXvjxko2riDFwyaEl4KNrfvQZv4Xsz8+BVRXrpyLosbm6CAZVnohKGZMAU= 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 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)