From patchwork Thu Apr 10 03:57:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 14045855 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 A284FC3601E for ; Thu, 10 Apr 2025 03:57:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 569762800A6; Wed, 9 Apr 2025 23:57:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4EF9728009B; Wed, 9 Apr 2025 23:57:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 367A12800A6; Wed, 9 Apr 2025 23:57:46 -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 0C4EE28009B for ; Wed, 9 Apr 2025 23:57:46 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 7BBEF1CE27F for ; Thu, 10 Apr 2025 03:57:47 +0000 (UTC) X-FDA: 83316775374.16.ED1CFC9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf05.hostedemail.com (Postfix) with ESMTP id BF847100003 for ; Thu, 10 Apr 2025 03:57:45 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Cipe7Qtl; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf05.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1744257465; 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=f1N+YcIuKzs7QdLEHyEwZZ+GVIPuduBxUV08naMugGA=; b=T/gBKvb6AtdL3a9GnSUo30HDUVzpfc4js0kQno47AUUsgUAe6SGQ8MehKtI2D55jtLzyRW sQMk+Ix2MhFhPu4juf5Dj7jIzQs3fIeQH9GfNwjYh0tCOFw24zgLKI3nhv96+rVN+aZusY ltkeLPrEcJj2kBs/7bKwxixjFbx+RWo= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Cipe7Qtl; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf05.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1744257465; a=rsa-sha256; cv=none; b=2uazIH0+a3m7KcPe19FxbzXOCgThx9XOb9w2MuVPjh07jNYdgCWsost21p/c579MNG9oiJ uJNFi2ZEQfhFgk9ZWagYn4Eyjh/m2DTlizdl1X7ihcL75ZXomgckbkpHr+3REZcn3NVz0Z 4vGsFZRFxsXtgRfwgeOj3qoZYX1Eivo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744257465; 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=f1N+YcIuKzs7QdLEHyEwZZ+GVIPuduBxUV08naMugGA=; b=Cipe7QtllYSJ2oHJFP6dX84AW1RpJ3q6/QxMo68ddXzh1ottmeDLOZm7fYQhuW8A9csr1G YFmoEV/4OWb08uza/EBrOxex1pVyxpSPiexcntBihx4gMk3KGSUIJHZhM4DVGmop8FykMQ V+QoBp/tOhIqEwxQ3GFcUvqWZcq1RgQ= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-122-lqz1GyQENkqkExtdQptSDQ-1; Wed, 09 Apr 2025 23:57:41 -0400 X-MC-Unique: lqz1GyQENkqkExtdQptSDQ-1 X-Mimecast-MFC-AGG-ID: lqz1GyQENkqkExtdQptSDQ_1744257460 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5455218004A9; Thu, 10 Apr 2025 03:57:40 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.38]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7808219560AD; Thu, 10 Apr 2025 03:57:35 +0000 (UTC) From: Baoquan He To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, david@redhat.com, osalvador@suse.de, yanjun.zhu@linux.dev, linux-kernel@vger.kernel.org, Baoquan He Subject: [PATCH v4 3/4] mm/gup: remove gup_fast_pgd_leaf() and clean up the relevant codes Date: Thu, 10 Apr 2025 11:57:16 +0800 Message-ID: <20250410035717.473207-4-bhe@redhat.com> In-Reply-To: <20250410035717.473207-1-bhe@redhat.com> References: <20250410035717.473207-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Rspamd-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4jpZ6Xe3pAVokx 0mCpmu0z D9RsT7s5ndRAV9pbwqDjjgQS7pnEZqV2PSpFINE/0wQcoJCS69Lh3vNlvCAYAkor9W3s8d4DsDjVsYkkCMuUJplmP9lrop+r69EvD5j32WHtJSuGwj/dXniNQCUC5DmEWQ+LalDdhUuOhQgD9RhAJwflI4HSveBLvXmSfC0zZD438wNxMFF0dkfvvrOLh+KuIN63hR2ea1GnYBC3TnoGExuaZ3gJUjpShPRiQ2c6qFG40X1wL9AZSG9SQ+UeiDULcvwQtFtMOPpx19pv8EOilZY9qM+hDNxdLa0FXWDaXTpZMnQS/jFocSj2NJ2DYSGH5GMHygth9drY2hNYdksU8e6ZMm/ca2xe0Ppg3xgU4EptJZM+r2H16kgn9zKktjA+P/CYf 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: In the current kernel, only pud huge page is supported in some architectures. P4d and pgd huge pages haven't been supported yet. And in mm/gup.c, there's no pgd huge page handling in the follow_page_mask() code path. Hence it doesn't make sense to only have gup_fast_pgd_leaf() in gup_fast code path. Here remove gup_fast_pgd_leaf() and clean up the relevant codes. Signed-off-by: Baoquan He Reviewed-by: Oscar Salvador Acked-by: David Hildenbrand --- mm/gup.c | 49 +++---------------------------------------------- 1 file changed, 3 insertions(+), 46 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index eb668da933e1..77a5bc622567 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -3172,46 +3172,6 @@ static int gup_fast_pud_leaf(pud_t orig, pud_t *pudp, unsigned long addr, return 1; } -static int gup_fast_pgd_leaf(pgd_t orig, pgd_t *pgdp, unsigned long addr, - unsigned long end, unsigned int flags, struct page **pages, - int *nr) -{ - int refs; - struct page *page; - struct folio *folio; - - if (!pgd_access_permitted(orig, flags & FOLL_WRITE)) - return 0; - - BUILD_BUG_ON(pgd_devmap(orig)); - - page = pgd_page(orig); - refs = record_subpages(page, PGDIR_SIZE, addr, end, pages + *nr); - - folio = try_grab_folio_fast(page, refs, flags); - if (!folio) - return 0; - - if (unlikely(pgd_val(orig) != pgd_val(*pgdp))) { - gup_put_folio(folio, refs, flags); - return 0; - } - - if (!pgd_write(orig) && gup_must_unshare(NULL, flags, &folio->page)) { - gup_put_folio(folio, refs, flags); - return 0; - } - - if (!gup_fast_folio_allowed(folio, flags)) { - gup_put_folio(folio, refs, flags); - return 0; - } - - *nr += refs; - folio_set_referenced(folio); - return 1; -} - static int gup_fast_pmd_range(pud_t *pudp, pud_t pud, unsigned long addr, unsigned long end, unsigned int flags, struct page **pages, int *nr) @@ -3306,12 +3266,9 @@ static void gup_fast_pgd_range(unsigned long addr, unsigned long end, next = pgd_addr_end(addr, end); if (pgd_none(pgd)) return; - if (unlikely(pgd_leaf(pgd))) { - if (!gup_fast_pgd_leaf(pgd, pgdp, addr, next, flags, - pages, nr)) - return; - } else if (!gup_fast_p4d_range(pgdp, pgd, addr, next, flags, - pages, nr)) + BUILD_BUG_ON(pgd_leaf(pgd)); + if (!gup_fast_p4d_range(pgdp, pgd, addr, next, flags, + pages, nr)) return; } while (pgdp++, addr = next, addr != end); }