From patchwork Wed Mar 27 15:23:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13606786 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 9C03DC47DD9 for ; Wed, 27 Mar 2024 15:23:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F262B6B009A; Wed, 27 Mar 2024 11:23:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E84B16B009B; Wed, 27 Mar 2024 11:23:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD8F66B009C; Wed, 27 Mar 2024 11:23:53 -0400 (EDT) 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 ABB8B6B009A for ; Wed, 27 Mar 2024 11:23:53 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 76F46C0CFE for ; Wed, 27 Mar 2024 15:23:53 +0000 (UTC) X-FDA: 81943189146.30.C96F7C9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf17.hostedemail.com (Postfix) with ESMTP id 9381740003 for ; Wed, 27 Mar 2024 15:23:51 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MmVWvOTm; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf17.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=1711553031; a=rsa-sha256; cv=none; b=lPBjk4e69PH5/kecs+GZK+1Uddk+/YcGXD3EhQ7IxVb70CSuLxFNACavhaftaC79Xfg0qo K7G4WhVlJPXOELLrf2M1p0RpyA2jEz0spX+K/HW/cCCeJ/ehUKvSPodVo4Q1KXs9P382n8 2ytioV9JIBBfyOt88sA0uA3evC/Zul8= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MmVWvOTm; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf17.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=1711553031; 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=gD68z8/n0HSMW69QF19tjjGBtDgz4n3uypdcneHmRPc=; b=CU2EFhWREtLh++opZAuTs0DpPFytXBTz1l51vmLD7QFKF+GFS7T05nJpRgI0Ikiq8IZGid UvCf1GjSxVlmEMJYZv2mn4ZGGosYhGv8CqErENpHKWHxud3OTJbP5Q3JBMxflKrh+BT+mL HX/trS1lOun8bqVOI7CH/5GHF8dUK5Y= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711553031; 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=gD68z8/n0HSMW69QF19tjjGBtDgz4n3uypdcneHmRPc=; b=MmVWvOTmTU6nujh5vqCWOvh40F2hfZGnujaJOTLKSL1yFnAGxQ4g3uLfFiByr/zlkmcOQY ilQbcnWPImt4PEV4bgatJGE6JiNqgsB0sGlqJhncvrw/Z5NtDTHzinR+sWw6JzChrB51nU VvMjCL3Zn3JP7dFwbrsQZySMmR31jtA= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-310-ThSDHml2MlGi7AMbtsoiGw-1; Wed, 27 Mar 2024 11:23:49 -0400 X-MC-Unique: ThSDHml2MlGi7AMbtsoiGw-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-690c19ee50bso2422136d6.0 for ; Wed, 27 Mar 2024 08:23:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711553029; x=1712157829; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gD68z8/n0HSMW69QF19tjjGBtDgz4n3uypdcneHmRPc=; b=cdhdF6PvJ1y14eGyABli776mNJMJOiEoj99Rr7/cQ0NHcQoIvaPjCM/zwhUH280HZ/ p8rduN+D5K/LFL/UiT3tCh+GOou4e3loWdu6+bjgZMfj0G1rbaXJpDiBfUZ9JcbQCM6Y GMJey6W8Km3QdakMez07A4lsNUsBGMvgp6SjzT16wxOiEogDzwwEiBYUOV9ymA76TVaU 94cQOs4b6Ro4sblFU7gZM2wyaM5saGvBptj0mVhr33GZTWZpuiMaFpNwRcGbTnijJt6q dmcVQINcqw/6wgzsWmvtPi/8e4b3mcMkiGQT7usiSXiAOhezwLYSv8+ga9bxOJshFnZi vWPA== X-Gm-Message-State: AOJu0YyDptpkU5qD7nSbJMJjTdWiNyM9QZa7PSfRIWFNfuQvGVZIFHli DFNRrU/msMrJJtVtsfgEQ/YoTGCaa386u63mB7sjdhjoQw5Qkck7N6oklqdXENMu6pTjO9PYrlS E3NiwcKybCWIk1g9xIJkTLuu8ieg4fvUxkDdWRy95O07RbGca14r8AbzU57ZgMyre083K8xoesb 0a5cM46t6lexmxLdTze8YEqj+Az4tKxw== X-Received: by 2002:a05:6214:3a01:b0:696:81b8:a462 with SMTP id nw1-20020a0562143a0100b0069681b8a462mr13234485qvb.0.1711553028878; Wed, 27 Mar 2024 08:23:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFaIIFSwEPr6utJECaPIJXCgmHTkHVcLUQEzRJpciko/79sjH/yOlRx7KIof08fJkHOKzrhqQ== X-Received: by 2002:a05:6214:3a01:b0:696:81b8:a462 with SMTP id nw1-20020a0562143a0100b0069681b8a462mr13234423qvb.0.1711553028305; Wed, 27 Mar 2024 08:23:48 -0700 (PDT) Received: from x1n.redhat.com ([99.254.121.117]) by smtp.gmail.com with ESMTPSA id hu4-20020a056214234400b00690dd47a41csm6412639qvb.86.2024.03.27.08.23.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 08:23:47 -0700 (PDT) From: peterx@redhat.com To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Yang Shi , "Kirill A . Shutemov" , Mike Kravetz , John Hubbard , Michael Ellerman , peterx@redhat.com, Andrew Jones , Muchun Song , linux-riscv@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, Christophe Leroy , Andrew Morton , Christoph Hellwig , Lorenzo Stoakes , Matthew Wilcox , Rik van Riel , linux-arm-kernel@lists.infradead.org, Andrea Arcangeli , David Hildenbrand , "Aneesh Kumar K . V" , Vlastimil Babka , James Houghton , Jason Gunthorpe , Mike Rapoport , Axel Rasmussen Subject: [PATCH v4 06/13] mm/gup: Drop folio_fast_pin_allowed() in hugepd processing Date: Wed, 27 Mar 2024 11:23:25 -0400 Message-ID: <20240327152332.950956-7-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240327152332.950956-1-peterx@redhat.com> References: <20240327152332.950956-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat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UUvmTkge0jpMmNZ9WCL 6J8FFNm3 XjXA12a2X5D4HzyWMKeyg+6msTmumKnQtjLPH660olp2n7O/SCzHdvCQFS2HYkfxux1Kua9ze6yTpOZpXH15t2xjApZAEbVPvyqsVrb+5l0oQc0SmIql/i6h+IB9RQd83pIw9POyq1T9T5zI= 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 e7510b6ce765..db35b056fc9a 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2832,11 +2832,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; @@ -2847,6 +2842,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)