From patchwork Fri Jan 24 21:37:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 13949945 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 7577BC0218B for ; Fri, 24 Jan 2025 21:38:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 618D06B00B1; Fri, 24 Jan 2025 16:38:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5C9EF280079; Fri, 24 Jan 2025 16:38:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 469BE280077; Fri, 24 Jan 2025 16:38:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2B0506B00B1 for ; Fri, 24 Jan 2025 16:38:15 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D129816192D for ; Fri, 24 Jan 2025 21:38:14 +0000 (UTC) X-FDA: 83043658908.21.B705E91 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 1F05140010 for ; Fri, 24 Jan 2025 21:38:12 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JewSsHSh; spf=pass (imf01.hostedemail.com: domain of luizcap@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=luizcap@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=1737754693; 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=upr7vHxw+moDnUyoNmdOrdtldZZRztXFPosSk1iZLLs=; b=IxQFpaFJIz3+fzEU4c4s/CrA18jT4l4nA5zlu7cDTkGTjbji4+7TraXrJToLILoJ/fyuQe rZ/D9cmwxO0nTgJJ18LAH0NmqJ32L2tbGgaB4zEmm+HeXz0djF7CRin/Zlg2yC4itCN/+l r79FgdeYCG4Zpb7LLv83dkRFcPG+B/k= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JewSsHSh; spf=pass (imf01.hostedemail.com: domain of luizcap@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=luizcap@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737754693; a=rsa-sha256; cv=none; b=G8t3jdxNi8dRUURKXvXPyvQQiyq9DUhR1LsLV1JBGmFxzYnvdgtYLu7GY0pPtnlFqn28Uy ztxoMX7b9IQD257Vakaen3ZyvDk66TanhSxZToL3DX5xPh+6FFlt+RnzVZRuMEhduPkOyE uCJNrU0P0fX/PYyTBrYcWOoZukc1Yr0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737754692; 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=upr7vHxw+moDnUyoNmdOrdtldZZRztXFPosSk1iZLLs=; b=JewSsHShS9pEh8yKkuIpfHsLz4pdK4+qnrW0glElcKOro4NxZCCYT1UIh575nnaoO3n0Dz wZmLoE5TjLgEwJUcyKYrYC6Y/zc0JoUk1xPs351lFGKdrFGlomcm6G/+bb6bto5VddBVd7 3Bnvhq49wiX2udJQ2pfqL6eckuSL2mM= Received: from mx-prod-mc-06.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-320-TwaOxa-OPeiDnT_sg6coXw-1; Fri, 24 Jan 2025 16:38:10 -0500 X-MC-Unique: TwaOxa-OPeiDnT_sg6coXw-1 X-Mimecast-MFC-AGG-ID: TwaOxa-OPeiDnT_sg6coXw Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 901FB180036E; Fri, 24 Jan 2025 21:38:08 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.81.148]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7E739180035F; Fri, 24 Jan 2025 21:38:06 +0000 (UTC) From: Luiz Capitulino To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, david@redhat.com, yuzhao@google.com Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, muchun.song@linux.dev, lcapitulino@gmail.com, luizcap@redhat.com Subject: [RFC 1/4] mm: page_ext: add an iteration API for page extensions Date: Fri, 24 Jan 2025 16:37:51 -0500 Message-ID: <70bc5513e599d3386533fcc25dfe33685d2ca1bb.1737754625.git.luizcap@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Rspamd-Queue-Id: 1F05140010 X-Stat-Signature: he8dw95hn3pyc6cc1b1kk5npbihpqy56 X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jEWfJMoJrIcdXVMp7zOYXkDh2BXYxC0aGAMNrJa2Gi4g41ccjq8x7RytycljGu0v1Tl8J9eYAzQQ754VI4fIlO7fYTEgtsui6NqXZEab3cE0pXJaYROnNF4EWzGC98sWgrDHtdUgqW8Y5sCg/yPI6/nsSn0cf6uChA5+5sfLJefom85wIvqo2QQlNUCJP5nn7Abs5n+3NqHKwOb8ogLixeiuFEcgN6MBkYiGyB/0ZBNnrPP9+WyqeSaPjSpLCOIF1gvYkC2E73MMGKrtZvRliQtwB5AM3DIpmkwGElHqbhN/bc6gcY4/c1I4yJ2qmO7k3VH1T3bBWgSYxx/dqn19V2U90kvwetWUU+6Q== 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: The page extension implementation assumes that all page extensions of a given page order are stored in the same memory section. The function page_ext_next() relies on this assumption by adding an offset to the current object to return the next adjacent page extension. This behavior works as expected for flatmem but fails for sparsemem when using 1G pages. Commit e98337d11bbd ("mm/contig_alloc: support __GFP_COMP") exposes this issue, making it possible for a crash when using page_owner or page_table_check page extensions. The problem is that for 1G pages, the page extensions may span memory section boundaries and be stored in different memory sections. This issue was not visible before commit e98337d11bbd ("mm/contig_alloc: support __GFP_COMP") because alloc_contig_pages() never passed more than MAX_PAGE_ORDER to post_alloc_hook(). However, the mentioned commit changed this behavior allowing the full 1G page order to be passed. Reproducer: 1. Build the kernel with CONFIG_SPARSEMEM=y and the table extensions 2. Pass 'default_hugepagesz=1 page_owner=on' in the kernel command-line 3. Reserve one 1G page at run-time, this should crash (backtrace below) To address this issue, this commit introduces a new API for iterating through page extensions. In page_ext_iter_next(), we always go through page_ext_get() to guarantee that we do a new memory section lookup for the next page extension. In the future, this API could be used as a basis to implement for_each_page_ext() type of macro. Thanks to David Hildenbrand for helping identify the root cause and providing suggestions on how to fix it (final implementation and bugs are all mine though). Here's the backtrace, without kasan you can get random crashes: [ 76.052526] BUG: KASAN: slab-out-of-bounds in __update_page_owner_handle+0x238/0x298 [ 76.060283] Write of size 4 at addr ffff07ff96240038 by task tee/3598 [ 76.066714] [ 76.068203] CPU: 88 UID: 0 PID: 3598 Comm: tee Kdump: loaded Not tainted 6.13.0-rep1 #3 [ 76.076202] Hardware name: WIWYNN Mt.Jade Server System B81.030Z1.0007/Mt.Jade Motherboard, BIOS 2.10.20220810 (SCP: 2.10.20220810) 2022/08/10 [ 76.088972] Call trace: [ 76.091411] show_stack+0x20/0x38 (C) [ 76.095073] dump_stack_lvl+0x80/0xf8 [ 76.098733] print_address_description.constprop.0+0x88/0x398 [ 76.104476] print_report+0xa8/0x278 [ 76.108041] kasan_report+0xa8/0xf8 [ 76.111520] __asan_report_store4_noabort+0x20/0x30 [ 76.116391] __update_page_owner_handle+0x238/0x298 [ 76.121259] __set_page_owner+0xdc/0x140 [ 76.125173] post_alloc_hook+0x190/0x1d8 [ 76.129090] alloc_contig_range_noprof+0x54c/0x890 [ 76.133874] alloc_contig_pages_noprof+0x35c/0x4a8 [ 76.138656] alloc_gigantic_folio.isra.0+0x2c0/0x368 [ 76.143616] only_alloc_fresh_hugetlb_folio.isra.0+0x24/0x150 [ 76.149353] alloc_pool_huge_folio+0x11c/0x1f8 [ 76.153787] set_max_huge_pages+0x364/0xca8 [ 76.157961] __nr_hugepages_store_common+0xb0/0x1a0 [ 76.162829] nr_hugepages_store+0x108/0x118 [ 76.167003] kobj_attr_store+0x3c/0x70 [ 76.170745] sysfs_kf_write+0xfc/0x188 [ 76.174492] kernfs_fop_write_iter+0x274/0x3e0 [ 76.178927] vfs_write+0x64c/0x8e0 [ 76.182323] ksys_write+0xf8/0x1f0 [ 76.185716] __arm64_sys_write+0x74/0xb0 [ 76.189630] invoke_syscall.constprop.0+0xd8/0x1e0 [ 76.194412] do_el0_svc+0x164/0x1e0 [ 76.197891] el0_svc+0x40/0xe0 [ 76.200939] el0t_64_sync_handler+0x144/0x168 [ 76.205287] el0t_64_sync+0x1ac/0x1b0 Fixes: e98337d11bbd ("mm/contig_alloc: support __GFP_COMP") Signed-off-by: Luiz Capitulino --- include/linux/page_ext.h | 10 ++++++++ mm/page_ext.c | 55 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/include/linux/page_ext.h b/include/linux/page_ext.h index e4b48a0dda244..df904544d3fac 100644 --- a/include/linux/page_ext.h +++ b/include/linux/page_ext.h @@ -93,6 +93,16 @@ static inline struct page_ext *page_ext_next(struct page_ext *curr) return next; } +struct page_ext_iter { + unsigned long pfn; + struct page_ext *page_ext; +}; + +struct page_ext *page_ext_iter_begin(struct page_ext_iter *iter, struct page *page); +struct page_ext *page_ext_iter_get(const struct page_ext_iter *iter); +struct page_ext *page_ext_iter_next(struct page_ext_iter *iter); +void page_ext_iter_end(struct page_ext_iter *iter); + #else /* !CONFIG_PAGE_EXTENSION */ struct page_ext; diff --git a/mm/page_ext.c b/mm/page_ext.c index 641d93f6af4c1..0b6eb5524cb2c 100644 --- a/mm/page_ext.c +++ b/mm/page_ext.c @@ -549,3 +549,58 @@ void page_ext_put(struct page_ext *page_ext) rcu_read_unlock(); } + +/** + * page_ext_iter_begin() - Prepare for iterating through page extensions. + * @iter: page extension iterator. + * @page: The page we're interested in. + * + * Return: NULL if no page_ext exists for this page. + */ +struct page_ext *page_ext_iter_begin(struct page_ext_iter *iter, struct page *page) +{ + iter->pfn = page_to_pfn(page); + iter->page_ext = page_ext_get(page); + + return iter->page_ext; +} + +/** + * page_ext_iter_get() - Get current page extension + * @iter: page extension iterator. + * + * Return: NULL if no page_ext exists for this iterator. + */ +struct page_ext *page_ext_iter_get(const struct page_ext_iter *iter) +{ + return iter->page_ext; +} + +/** + * page_ext_iter_next() - Get next page extension + * @iter: page extension iterator. + * + * Return: NULL if no next page_ext exists. + */ +struct page_ext *page_ext_iter_next(struct page_ext_iter *iter) +{ + if (!iter->page_ext) + return NULL; + + page_ext_put(iter->page_ext); + + iter->pfn++; + iter->page_ext = page_ext_get(pfn_to_page(iter->pfn)); + + return iter->page_ext; +} + +/** + * page_ext_iter_end() - End iteration through page extensions. + * @iter: page extension iterator. + */ +void page_ext_iter_end(struct page_ext_iter *iter) +{ + page_ext_put(iter->page_ext); + iter->page_ext = NULL; +} From patchwork Fri Jan 24 21:37:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 13949947 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 CA5E7C0218B for ; Fri, 24 Jan 2025 21:38:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D6E36280079; Fri, 24 Jan 2025 16:38:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D2191280077; Fri, 24 Jan 2025 16:38:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A10FF28008E; Fri, 24 Jan 2025 16:38:21 -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 7550E280079 for ; Fri, 24 Jan 2025 16:38:21 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2A182A151A for ; Fri, 24 Jan 2025 21:38:21 +0000 (UTC) X-FDA: 83043659202.06.02DBEE8 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 620D0A0004 for ; Fri, 24 Jan 2025 21:38:19 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=F+k2J+Cb; spf=pass (imf15.hostedemail.com: domain of luizcap@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=luizcap@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=1737754699; 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=mpq60malTbL1a0tgUfkQY0dx9GoNhyxzjB2FnEhg2RU=; b=ijiWic9k8iQw3RBuNIqicKxtpWBTp6XRM4CfgI2OgT0I7S409MHlHmJJIKqhWMrh5bTJqY 5POOPPosU5hSJFREOpd1On+toDNX6EW21f2cFVXEF52T1metKOp6O8nVvk+YVgiVoRnXfO OCXRlaLZfqd8ml+wPMB0LhA8nKOdRvM= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=F+k2J+Cb; spf=pass (imf15.hostedemail.com: domain of luizcap@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=luizcap@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737754699; a=rsa-sha256; cv=none; b=Q4DKXCaykOYTso/sSdaeYOEuVsdg06Rgj0qDW6XDd4jTPCYX7mXnH89FcItpoViWqL/bn2 t1r927E57r5VINWbm9XPkRJ+lF7hES9Ecq85IdupiAfoBdbI839gfxdjv92QXLKszEb5g+ Y2/pqmErjwXVAGGYhGOegeGFGRo0Lgg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737754698; 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=mpq60malTbL1a0tgUfkQY0dx9GoNhyxzjB2FnEhg2RU=; b=F+k2J+Cb00yhHHXH3nPQvyxSKNzLNMJ4CtT7MchyrmZwSTjtWJV5cy3fgOuQYVh/Zwxdpk sTE+yAJMNr1k/2LHHmu5U2cH1I9aMBThYij91xcgCpWsA6AhwuJQYp36gkh/WyK6F3sdY8 bRFcoT9imw0VI5UWsstrZNLMEozhIEo= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-658-OcIZJC7zOteXDG1lMPmgNg-1; Fri, 24 Jan 2025 16:38:12 -0500 X-MC-Unique: OcIZJC7zOteXDG1lMPmgNg-1 X-Mimecast-MFC-AGG-ID: OcIZJC7zOteXDG1lMPmgNg Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E74F4195608B; Fri, 24 Jan 2025 21:38:10 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.81.148]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D2B121800348; Fri, 24 Jan 2025 21:38:08 +0000 (UTC) From: Luiz Capitulino To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, david@redhat.com, yuzhao@google.com Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, muchun.song@linux.dev, lcapitulino@gmail.com, luizcap@redhat.com Subject: [RFC 2/4] mm: page_owner: use new iteration API Date: Fri, 24 Jan 2025 16:37:52 -0500 Message-ID: <712c1e058c58ba0d4c407089fbcc45c55ceb8efc.1737754625.git.luizcap@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 620D0A0004 X-Stat-Signature: 5x6bouzw38fcy5xff1wmicy91xkm8dxd X-Rspam-User: X-HE-Tag: 1737754699-658715 X-HE-Meta: U2FsdGVkX19+DQoaYP76xCy+hR4rrUk508Wvg12R/D+LvjxXM/JFDQS5H0YD8PF8Qc9GKZdc4hIx0OPv2cpxvDqNcIljBFhB04pn0Bkn9MixgLluy9zcDAxEx3UMgojKYcwWHcOsyyqcMbKrVxQG8OkEM4wbo97w5KotubZb+f1IZa0PQVgMF6RIg7dCSJKkKzYgE/fZoSwM7w2It7smhGb/UBIXSp2GmATd/FVurORy4MiXOUIaV+GPdDej443W4JAcIGhcRvWkc17iCOCs5AmgQbCVW5cS3wNq4gKsz3Q6AN38ZRjJ5wIxdkEOZSLkyKsOj33tAvxP2oOIlu0hVYPB08fwaqAzhP7kRM1M6VemzOq5W76UkV5n3C3IRCQFTc45g3m40pDDqAlNoUrvb9Fi42+cjdKHZmoyYvQuJtKMmCxe+GYJNszvUzngE8lWdNzXe054OGVzySR9T+C5TklI7jAEpSCJq9DYCRCVGDqjgj9pZCjrjtMiWbIY3CrVrgcMB2Zy8/Y9s7ykT1sGKZmIb70msI6+IJB26q0lv4BNBh461eYNOwX05GEbZOOioexmaAxr2/k7J/h5lz1m+VPxMGrkvyoPR43vhbaTts/p9ZdKKwEtQEsigYAEaM5E83s92Lq8e+VJZ+uV27SXNDsHm+CixGmIBIi7p+PVDj+IseUDDIA3oVLW394Pmkv9HhjnIvjdKj8KYikFlGn1//LWzAtqeGNhOGyOc5dW5bj+CAi0srqQdyDEYzIAdNmh0Z2f4+TlyUfilpZGKg2uImQY4unTejjV6otpf1oZye1tlUoprltxEp3N48OzDX3QfAGA+mHlySDTX61QhIMK96j9C5pTbwhxjZWnoWaHu3xhwc2ARZesmpOc28yiNER9cldp6s6Gu5ZWbxcc6hVJcArhXl4gFveN480t41BPqKsaYxUMnvW5t54b4dg9pYcO+Fv8O5jSyL4kEhgIxQi wR/4bwWR DrMUD0v83the992CkwQsR5IKGdo4GaJurJLPjKOYZLDwhsjXT0BlcjbvOHPYxDn4NXBGogoZbRqheSRDRS5NrbqpItuNz2crOGGuFmJ+OEP8HQO3uwlPV8dz3b9Hw8Xo6VrlMRdkiPJzImy81h4w7tnPixuBAPfCMDnmyGYtIRwGiyq6jA2gKrmxeHeUU9lKo/5fqP7IC494mbiXryyNB6ImrnQgmbpESnpBNZm0UYxw1FJIfPFX/N8mFq9HqOPeJak9BaS4eVVI8RPaajAsftwTgHZy2QRy+q5UQ4aSkStzvk6R1VJeQXpCBv+aJNqREHX9eV15K3XzTcprgLNDOKxZPDmg9B8plw/gn727bWnG6IWWgOuh5/d8YrA== 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: The page_ext_next() function assumes that page extension objects for a page order allocation always reside in the same memory section, which may not be true and could lead to crashes. Use the page_ext_iter API instead. Fixes: e98337d11bbd ("mm/contig_alloc: support __GFP_COMP") Signed-off-by: Luiz Capitulino --- mm/page_owner.c | 68 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/mm/page_owner.c b/mm/page_owner.c index 2d6360eaccbb6..14b4ec8ceb83e 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -229,7 +229,7 @@ static void dec_stack_record_count(depot_stack_handle_t handle, handle); } -static inline void __update_page_owner_handle(struct page_ext *page_ext, +static inline void __update_page_owner_handle(struct page_ext_iter *iter, depot_stack_handle_t handle, unsigned short order, gfp_t gfp_mask, @@ -237,8 +237,11 @@ static inline void __update_page_owner_handle(struct page_ext *page_ext, pid_t pid, pid_t tgid, char *comm) { int i; + struct page_ext *page_ext; struct page_owner *page_owner; + page_ext = page_ext_iter_get(iter); + for (i = 0; i < (1 << order); i++) { page_owner = get_page_owner(page_ext); page_owner->handle = handle; @@ -252,19 +255,22 @@ static inline void __update_page_owner_handle(struct page_ext *page_ext, sizeof(page_owner->comm)); __set_bit(PAGE_EXT_OWNER, &page_ext->flags); __set_bit(PAGE_EXT_OWNER_ALLOCATED, &page_ext->flags); - page_ext = page_ext_next(page_ext); + page_ext = page_ext_iter_next(iter); } } -static inline void __update_page_owner_free_handle(struct page_ext *page_ext, +static inline void __update_page_owner_free_handle(struct page_ext_iter *iter, depot_stack_handle_t handle, unsigned short order, pid_t pid, pid_t tgid, u64 free_ts_nsec) { int i; + struct page_ext *page_ext; struct page_owner *page_owner; + page_ext = page_ext_iter_get(iter); + for (i = 0; i < (1 << order); i++) { page_owner = get_page_owner(page_ext); /* Only __reset_page_owner() wants to clear the bit */ @@ -275,7 +281,7 @@ static inline void __update_page_owner_free_handle(struct page_ext *page_ext, page_owner->free_ts_nsec = free_ts_nsec; page_owner->free_pid = current->pid; page_owner->free_tgid = current->tgid; - page_ext = page_ext_next(page_ext); + page_ext = page_ext_iter_next(iter); } } @@ -286,8 +292,9 @@ void __reset_page_owner(struct page *page, unsigned short order) depot_stack_handle_t alloc_handle; struct page_owner *page_owner; u64 free_ts_nsec = local_clock(); + struct page_ext_iter iter; - page_ext = page_ext_get(page); + page_ext = page_ext_iter_begin(&iter, page); if (unlikely(!page_ext)) return; @@ -295,9 +302,10 @@ void __reset_page_owner(struct page *page, unsigned short order) alloc_handle = page_owner->handle; handle = save_stack(GFP_NOWAIT | __GFP_NOWARN); - __update_page_owner_free_handle(page_ext, handle, order, current->pid, + __update_page_owner_free_handle(&iter, handle, order, current->pid, current->tgid, free_ts_nsec); - page_ext_put(page_ext); + + page_ext_iter_end(&iter); if (alloc_handle != early_handle) /* @@ -314,18 +322,19 @@ noinline void __set_page_owner(struct page *page, unsigned short order, gfp_t gfp_mask) { struct page_ext *page_ext; + struct page_ext_iter iter; u64 ts_nsec = local_clock(); depot_stack_handle_t handle; handle = save_stack(gfp_mask); - page_ext = page_ext_get(page); + page_ext = page_ext_iter_begin(&iter, page); if (unlikely(!page_ext)) return; - __update_page_owner_handle(page_ext, handle, order, gfp_mask, -1, + __update_page_owner_handle(&iter, handle, order, gfp_mask, -1, ts_nsec, current->pid, current->tgid, current->comm); - page_ext_put(page_ext); + page_ext_iter_end(&iter); inc_stack_record_count(handle, gfp_mask, 1 << order); } @@ -345,18 +354,21 @@ void __set_page_owner_migrate_reason(struct page *page, int reason) void __split_page_owner(struct page *page, int old_order, int new_order) { int i; - struct page_ext *page_ext = page_ext_get(page); + struct page_ext *page_ext; + struct page_ext_iter iter; struct page_owner *page_owner; + page_ext = page_ext_iter_begin(&iter, page); if (unlikely(!page_ext)) return; for (i = 0; i < (1 << old_order); i++) { page_owner = get_page_owner(page_ext); page_owner->order = new_order; - page_ext = page_ext_next(page_ext); + page_ext = page_ext_iter_next(&iter); } - page_ext_put(page_ext); + + page_ext_iter_end(&iter); } void __folio_copy_owner(struct folio *newfolio, struct folio *old) @@ -364,24 +376,26 @@ void __folio_copy_owner(struct folio *newfolio, struct folio *old) int i; struct page_ext *old_ext; struct page_ext *new_ext; + struct page_ext_iter old_iter; + struct page_ext_iter new_iter; struct page_owner *old_page_owner; struct page_owner *new_page_owner; depot_stack_handle_t migrate_handle; - old_ext = page_ext_get(&old->page); + old_ext = page_ext_iter_begin(&old_iter, &old->page); if (unlikely(!old_ext)) return; - new_ext = page_ext_get(&newfolio->page); + new_ext = page_ext_iter_begin(&new_iter, &newfolio->page); if (unlikely(!new_ext)) { - page_ext_put(old_ext); + page_ext_iter_end(&old_iter); return; } old_page_owner = get_page_owner(old_ext); new_page_owner = get_page_owner(new_ext); migrate_handle = new_page_owner->handle; - __update_page_owner_handle(new_ext, old_page_owner->handle, + __update_page_owner_handle(&new_iter, old_page_owner->handle, old_page_owner->order, old_page_owner->gfp_mask, old_page_owner->last_migrate_reason, old_page_owner->ts_nsec, old_page_owner->pid, @@ -390,8 +404,13 @@ void __folio_copy_owner(struct folio *newfolio, struct folio *old) * Do not proactively clear PAGE_EXT_OWNER{_ALLOCATED} bits as the folio * will be freed after migration. Keep them until then as they may be * useful. + * + * Note that we need to re-grab the page_ext iterator since + * __update_page_owner_handle changed it. */ - __update_page_owner_free_handle(new_ext, 0, old_page_owner->order, + page_ext_iter_end(&new_iter); + page_ext_iter_begin(&new_iter, &newfolio->page); + __update_page_owner_free_handle(&new_iter, 0, old_page_owner->order, old_page_owner->free_pid, old_page_owner->free_tgid, old_page_owner->free_ts_nsec); @@ -402,12 +421,12 @@ void __folio_copy_owner(struct folio *newfolio, struct folio *old) */ for (i = 0; i < (1 << new_page_owner->order); i++) { old_page_owner->handle = migrate_handle; - old_ext = page_ext_next(old_ext); + old_ext = page_ext_iter_next(&old_iter); old_page_owner = get_page_owner(old_ext); } - page_ext_put(new_ext); - page_ext_put(old_ext); + page_ext_iter_end(&new_iter); + page_ext_iter_end(&old_iter); } void pagetypeinfo_showmixedcount_print(struct seq_file *m, @@ -782,6 +801,7 @@ static void init_pages_in_zone(pg_data_t *pgdat, struct zone *zone) for (; pfn < block_end_pfn; pfn++) { struct page *page = pfn_to_page(pfn); struct page_ext *page_ext; + struct page_ext_iter iter; if (page_zone(page) != zone) continue; @@ -804,7 +824,7 @@ static void init_pages_in_zone(pg_data_t *pgdat, struct zone *zone) if (PageReserved(page)) continue; - page_ext = page_ext_get(page); + page_ext = page_ext_iter_begin(&iter, page); if (unlikely(!page_ext)) continue; @@ -813,12 +833,12 @@ static void init_pages_in_zone(pg_data_t *pgdat, struct zone *zone) goto ext_put_continue; /* Found early allocated page */ - __update_page_owner_handle(page_ext, early_handle, 0, 0, + __update_page_owner_handle(&iter, early_handle, 0, 0, -1, local_clock(), current->pid, current->tgid, current->comm); count++; ext_put_continue: - page_ext_put(page_ext); + page_ext_iter_end(&iter); } cond_resched(); } From patchwork Fri Jan 24 21:37:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 13949946 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 36109C02181 for ; Fri, 24 Jan 2025 21:38:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A14E3280090; Fri, 24 Jan 2025 16:38:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C898280077; Fri, 24 Jan 2025 16:38:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8634328008E; Fri, 24 Jan 2025 16:38:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 64ED4280077 for ; Fri, 24 Jan 2025 16:38:21 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 10FB0161930 for ; Fri, 24 Jan 2025 21:38:21 +0000 (UTC) X-FDA: 83043659202.11.4604337 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf22.hostedemail.com (Postfix) with ESMTP id 6A94FC0002 for ; Fri, 24 Jan 2025 21:38:19 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=S5XKRyb9; spf=pass (imf22.hostedemail.com: domain of luizcap@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=luizcap@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=1737754699; 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=dHZen3jASZAcDKP1E/9kqmJ6ro+oBIs3mr0xQsHdQRw=; b=zm/joDfkjyfs9D24wKcqiQTzHyzhCIwwhSgCGDAMRnel89Y07OVXHrgu1XYkpxV3nImaGC FIuJjZkOtHLFoP6H8uLKNA27D0qDjdtwyO07Oa3vvEnB2zjZcF5kkrp8sUd7mnpmVk9OJh Y76GLszV/iokn6OQnwqfDmpOCyyvbgw= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=S5XKRyb9; spf=pass (imf22.hostedemail.com: domain of luizcap@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=luizcap@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737754699; a=rsa-sha256; cv=none; b=aBxKIX9u/iqMkU/N7yEaW4VIXOnGd7IXhFsWL821haKfJ6rje+NsAQGAdWGKvavqC31MJS hSRgfNKwl4L6+8m97edPNwWyM0kNcCwsrap6ef71NnN5LeuBzlfhhw3F/PytI6nmMGPBUK qoqzj51ifbzQNZgbRJp/CutQyu/JXNg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737754698; 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=dHZen3jASZAcDKP1E/9kqmJ6ro+oBIs3mr0xQsHdQRw=; b=S5XKRyb9sLcOEp/qWWCXkAs9oHiGvTNXowZk/6d76nFVaNk3oyavptDZzwNE9yf1d05CF8 zfyGgc026JD+mbZJqwa49YMlpTC1EP9I5xAOyCtMdGuJVhkq6XPkfnvbPEW0DlVPe7Lpn2 tCq/EvkyidJiaXBWfCr7roYyIPJcFXg= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-586-ozohZGrwMVyQaWMVpeJFqw-1; Fri, 24 Jan 2025 16:38:14 -0500 X-MC-Unique: ozohZGrwMVyQaWMVpeJFqw-1 X-Mimecast-MFC-AGG-ID: ozohZGrwMVyQaWMVpeJFqw Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D5C001956048; Fri, 24 Jan 2025 21:38:12 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.81.148]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 146E41800358; Fri, 24 Jan 2025 21:38:10 +0000 (UTC) From: Luiz Capitulino To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, david@redhat.com, yuzhao@google.com Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, muchun.song@linux.dev, lcapitulino@gmail.com, luizcap@redhat.com Subject: [RFC 3/4] mm: page_table_check: use new iteration API Date: Fri, 24 Jan 2025 16:37:53 -0500 Message-ID: <1a661d3c94890df06dc82583f883ee5cc6346d75.1737754625.git.luizcap@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Rspamd-Queue-Id: 6A94FC0002 X-Stat-Signature: yzzah3tcfk4dgguz6zy3iqy7oczwkrb4 X-Rspamd-Server: rspam08 X-Rspam-User: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kq+EE8p/DT8Ir69Nguh3K9STRhZ8gnxB9YCM9mign/gl4gejOanZSK66Fl6nduoC79884sqb6niZZfVxjX+/JmJvyFW4CvcPuiIjJeO8xx2tK7oAh1wnI70GtsVuaTAvRQaz2wMpfQf2G0ci+a53ZMs5JIzDQZWuB28c9glmROYBUL9vVBGgCNv58aYAx14P1TeTVtGYgiicRybOS7r1CxZTgbMBW1xB0TrEoq6NZzGTh990oAhHyz6c9r9PDtrw+kZLfzWMQPLIF9QVQ/ohtNjBZnYZmPmoyc9hCyA+fmSGw== 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: The page_ext_next() function assumes that page extension objects for a page order allocation always reside in the same memory section, which may not be true and could lead to crashes. Use the page_ext_iter API instead. Fixes: e98337d11bbd ("mm/contig_alloc: support __GFP_COMP") Signed-off-by: Luiz Capitulino --- mm/page_table_check.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/mm/page_table_check.c b/mm/page_table_check.c index 509c6ef8de400..361322a5bc7ab 100644 --- a/mm/page_table_check.c +++ b/mm/page_table_check.c @@ -63,6 +63,7 @@ static struct page_table_check *get_page_table_check(struct page_ext *page_ext) static void page_table_check_clear(unsigned long pfn, unsigned long pgcnt) { struct page_ext *page_ext; + struct page_ext_iter iter; struct page *page; unsigned long i; bool anon; @@ -71,7 +72,7 @@ static void page_table_check_clear(unsigned long pfn, unsigned long pgcnt) return; page = pfn_to_page(pfn); - page_ext = page_ext_get(page); + page_ext = page_ext_iter_begin(&iter, page); if (!page_ext) return; @@ -89,9 +90,9 @@ static void page_table_check_clear(unsigned long pfn, unsigned long pgcnt) BUG_ON(atomic_read(&ptc->anon_map_count)); BUG_ON(atomic_dec_return(&ptc->file_map_count) < 0); } - page_ext = page_ext_next(page_ext); + page_ext = page_ext_iter_next(&iter); } - page_ext_put(page_ext); + page_ext_iter_end(&iter); } /* @@ -103,6 +104,7 @@ static void page_table_check_set(unsigned long pfn, unsigned long pgcnt, bool rw) { struct page_ext *page_ext; + struct page_ext_iter iter; struct page *page; unsigned long i; bool anon; @@ -111,7 +113,7 @@ static void page_table_check_set(unsigned long pfn, unsigned long pgcnt, return; page = pfn_to_page(pfn); - page_ext = page_ext_get(page); + page_ext = page_ext_iter_begin(&iter, page); if (!page_ext) return; @@ -129,9 +131,9 @@ static void page_table_check_set(unsigned long pfn, unsigned long pgcnt, BUG_ON(atomic_read(&ptc->anon_map_count)); BUG_ON(atomic_inc_return(&ptc->file_map_count) < 0); } - page_ext = page_ext_next(page_ext); + page_ext = page_ext_iter_next(&iter); } - page_ext_put(page_ext); + page_ext_iter_end(&iter); } /* @@ -141,11 +143,12 @@ static void page_table_check_set(unsigned long pfn, unsigned long pgcnt, void __page_table_check_zero(struct page *page, unsigned int order) { struct page_ext *page_ext; + struct page_ext_iter iter; unsigned long i; BUG_ON(PageSlab(page)); - page_ext = page_ext_get(page); + page_ext = page_ext_iter_begin(&iter, page); if (!page_ext) return; @@ -155,9 +158,9 @@ void __page_table_check_zero(struct page *page, unsigned int order) BUG_ON(atomic_read(&ptc->anon_map_count)); BUG_ON(atomic_read(&ptc->file_map_count)); - page_ext = page_ext_next(page_ext); + page_ext = page_ext_iter_next(&iter); } - page_ext_put(page_ext); + page_ext_iter_end(&iter); } void __page_table_check_pte_clear(struct mm_struct *mm, pte_t pte) From patchwork Fri Jan 24 21:37:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 13949948 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 8C0F2C02181 for ; Fri, 24 Jan 2025 21:38:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1FDCC28008E; Fri, 24 Jan 2025 16:38:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 112EC280077; Fri, 24 Jan 2025 16:38:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E7F7528008E; Fri, 24 Jan 2025 16:38:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C5DC3280077 for ; Fri, 24 Jan 2025 16:38:24 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 79DA3141838 for ; Fri, 24 Jan 2025 21:38:24 +0000 (UTC) X-FDA: 83043659328.05.77BDF40 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf08.hostedemail.com (Postfix) with ESMTP id B789316001D for ; Fri, 24 Jan 2025 21:38:22 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aMpARsqF; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of luizcap@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=luizcap@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737754702; a=rsa-sha256; cv=none; b=kz4I2C5mDRLlz5hoXq2YD2jPUmaCsXOHBOO3pn29TFGNfl6amO6Aqc/trNvb90qI2k/ktt Qg2OQrKIKjLqfwiwzuw2u6Xeqd8lU/vAbmUXuysYZyW5LTcs70PwBy7SWvp87Yyx3hlpkf ToTs2nPZYzGgzgwAux4WFm5GNPJknuw= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aMpARsqF; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of luizcap@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=luizcap@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737754702; 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=f0R/RjNUfg0XRwtqhdLZpjGZZp5v7kFJ6of5fRAQFs8=; b=8GD96rMd4n4cF2HXBDZFOkIPLSLKU489mHZlSXDwgPVlMQtO6Qlu4kP1LB7zbBS/J8W2qA PgqngKFtYtvr4p4E3z5G/T7g0cR10jtihGG+q0bmooiK69M/AOy6/4Q8gF3a8B4JjCQOZj ktDeZCPyVjLvBS5WDdgYku3DjueyuQI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737754702; 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=f0R/RjNUfg0XRwtqhdLZpjGZZp5v7kFJ6of5fRAQFs8=; b=aMpARsqFZp6LA2OrzJzPu0A3yp0ZWdZpfXCRCNkOry1aKt6cTV1jxppYlydy4xxT6yfMvu ++EVmCceDVuahpD01bBIEId/PIVcrM7c2K/OeXkg2IPRMyxXLDmwYijuRRJh02OxH25uu+ 3iIguOmvyJbqPAHTgvl8k9koJbYma6M= Received: from mx-prod-mc-06.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-614-2E4ptrrdPoGF2gRstTT0zw-1; Fri, 24 Jan 2025 16:38:17 -0500 X-MC-Unique: 2E4ptrrdPoGF2gRstTT0zw-1 X-Mimecast-MFC-AGG-ID: 2E4ptrrdPoGF2gRstTT0zw Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D42F6180034D; Fri, 24 Jan 2025 21:38:14 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.81.148]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 244AD1800348; Fri, 24 Jan 2025 21:38:13 +0000 (UTC) From: Luiz Capitulino To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, david@redhat.com, yuzhao@google.com Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, muchun.song@linux.dev, lcapitulino@gmail.com, luizcap@redhat.com Subject: [RFC 4/4] mm: page_ext: drop page_ext_next() Date: Fri, 24 Jan 2025 16:37:54 -0500 Message-ID: <3604c0ceeb0942b25ef645f4b74154c0122149f4.1737754625.git.luizcap@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: B789316001D X-Stat-Signature: bdyxd3xy1sbug9iqo8rzprp75y6zjh4w X-HE-Tag: 1737754702-786456 X-HE-Meta: U2FsdGVkX1/Lelob0ujOcmPjInAz95KrLwNEoFQ+nkWQQkesVY5vof4WFiDovufm9LstaF+1hli6NMW6gsuMYJsYPezdqMrN9c37Ly8u4W0BY+EaIUgEhkP8sEB0qhjRWVW8UcHtut8JSYF9osrHuDauRgWAnX3Z6WC69xBj8mx+4uQ5AQ60UEXDeTu0DOmenNtNiPTg7Zl1zr0SZiuk+pdJEo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yD5ZP2aPHL50KgTev1J6bC+utLBm6VpvuCH47nSMTHIckATRy0lqqEcUuerg9lvJCM9E5tSFxGf9HZrDA== 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: Previous commits converted users to the new page extension iteration API. TODO: We can use this implementation for flatmem. Fixes: e98337d11bbd ("mm/contig_alloc: support __GFP_COMP") Signed-off-by: Luiz Capitulino --- include/linux/page_ext.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/include/linux/page_ext.h b/include/linux/page_ext.h index df904544d3fac..4bbc6638fe14f 100644 --- a/include/linux/page_ext.h +++ b/include/linux/page_ext.h @@ -86,13 +86,6 @@ static inline void *page_ext_data(struct page_ext *page_ext, return (void *)(page_ext) + ops->offset; } -static inline struct page_ext *page_ext_next(struct page_ext *curr) -{ - void *next = curr; - next += page_ext_size; - return next; -} - struct page_ext_iter { unsigned long pfn; struct page_ext *page_ext;