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-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CwOeqPsVC6slqpQeM0QfLw4Kq+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)