From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AC391E7C3C for ; Fri, 24 Jan 2025 21:38:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737754701; cv=none; b=nNNCBMcMB1rXIiLbOSlUQz9WljF4xk75ZwpyPu2xItCBpz1D1X+Ua/gC7Jb+NfO6cSxRg0D1vRcc5P51GvVIc5YossNVvRJ1tTFkiCYskdfhE5GyF1GwtVfFGz18MUya9KJmwb0TcPGCBRnwSLHLkELP3HeP5x8QsYh2gq1VMHk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737754701; c=relaxed/simple; bh=o9ML6VFML/Gd+NwyGOyutOdI0Ql83xW/Jq/ZGnSTDUM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fSalyrAXqdX5qL58m3qFPN5TMb5QrgDSMtIAgnXZhDAz4ZWKt28nBejEAiJNkXnyJaGH/kolvi5wq2FO26V9qVo+6m6cbtuuqDpfPym/GMPNquQzHyDtWWWpQHQahNkypBc9FpNaI0G4PiyFbtpGb72OC3y8bdOslXcGVO5UC9w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=S5XKRyb9; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="S5XKRyb9" 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: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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) -- 2.47.1