From nobody Fri Dec 19 07:00:42 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 A4FE5170A11 for ; Wed, 19 Feb 2025 02:18:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739931505; cv=none; b=DiEulGSQoM0MzFe9+0GfThfvVCqJgK0D6XDAntEHuXxF2dznnR6sPUlKS9IKx+mDgTdKOskN9ObdVjaa/P/3Es9BYRAkZjaqvhxvhLsawbLWBZAiJBcbaXTd4YYSp8gG7W+dYExNZUteploJ4OZ8CoAJPOfzY0zoqPz6JRx+yjE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739931505; c=relaxed/simple; bh=3iPOGv3PQchbB18B4ZinqtqeDFAmJ/DFZI2T+f/LAWE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UOZGbZ+C7nqHAVeYAlxCvgn7kyvZa+NvFGtPflLoxKm39i3OpfmsTeo8xWoJaQVF8FoP9VRBbdVpkeg0Su0OfIYLEoRvsHklV/H2v9TK2drP586twWHiOLpPmQUiW0G4+jfRrItlej/xJrj055CCcm6bfFA+P0MfEZUNGLJzYnk= 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=Knw+qpNx; arc=none smtp.client-ip=170.10.129.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="Knw+qpNx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739931502; 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=NsF2KsmlxImjdJhL9OxCFldmZagOaePVCluv2R2e7Ow=; b=Knw+qpNxgRvMjeqsj9VC3CziaVDA/YL/QNAYKug2K77UUPuV46CTzSAecSFSOCA3GcKPGj HG7262+L5DrwN3nxEkZu8c4ci9LQ3BGAeOEJ9LnNvMDh+Gb4lXHP9ibvqI5aWFa1vtmmrO 20W7oJvBF+/x8v7KJMD91lLdwCDn0hY= Received: from mx-prod-mc-02.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-599-8odB42S2OHSsiU1HfMlZmg-1; Tue, 18 Feb 2025 21:18:19 -0500 X-MC-Unique: 8odB42S2OHSsiU1HfMlZmg-1 X-Mimecast-MFC-AGG-ID: 8odB42S2OHSsiU1HfMlZmg_1739931498 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A6C1818EB2CF; Wed, 19 Feb 2025 02:18:17 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.65.50]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 59B1D19560B9; Wed, 19 Feb 2025 02:18:15 +0000 (UTC) From: Luiz Capitulino To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, david@redhat.com, yuzhao@google.com, pasha.tatashin@soleen.com Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, muchun.song@linux.dev, luizcap@redhat.com Subject: [PATCH 2/4] mm: page_table_check: use new iteration API Date: Tue, 18 Feb 2025 21:17:48 -0500 Message-ID: <85f11743d259d5e4a1f47456fbcda82ff6db9ab3.1739931468.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: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Content-Type: text/plain; charset="utf-8" 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 new page_ext iteration API instead. Fixes: cf54f310d0d3 ("mm/hugetlb: use __GFP_COMP for gigantic folios") Signed-off-by: Luiz Capitulino Acked-by: David Hildenbrand --- mm/page_table_check.c | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/mm/page_table_check.c b/mm/page_table_check.c index 509c6ef8de400..b52e04d31c809 100644 --- a/mm/page_table_check.c +++ b/mm/page_table_check.c @@ -62,24 +62,20 @@ static struct page_table_check *get_page_table_check(st= ruct page_ext *page_ext) */ static void page_table_check_clear(unsigned long pfn, unsigned long pgcnt) { + struct page_ext_iter iter; struct page_ext *page_ext; struct page *page; - unsigned long i; bool anon; =20 if (!pfn_valid(pfn)) return; =20 page =3D pfn_to_page(pfn); - page_ext =3D page_ext_get(page); - - if (!page_ext) - return; - BUG_ON(PageSlab(page)); anon =3D PageAnon(page); =20 - for (i =3D 0; i < pgcnt; i++) { + rcu_read_lock(); + for_each_page_ext(page, pgcnt, page_ext, iter) { struct page_table_check *ptc =3D get_page_table_check(page_ext); =20 if (anon) { @@ -89,9 +85,8 @@ static void page_table_check_clear(unsigned long pfn, uns= igned long pgcnt) BUG_ON(atomic_read(&ptc->anon_map_count)); BUG_ON(atomic_dec_return(&ptc->file_map_count) < 0); } - page_ext =3D page_ext_next(page_ext); } - page_ext_put(page_ext); + rcu_read_unlock(); } =20 /* @@ -102,24 +97,20 @@ static void page_table_check_clear(unsigned long pfn, = unsigned long pgcnt) static void page_table_check_set(unsigned long pfn, unsigned long pgcnt, bool rw) { + struct page_ext_iter iter; struct page_ext *page_ext; struct page *page; - unsigned long i; bool anon; =20 if (!pfn_valid(pfn)) return; =20 page =3D pfn_to_page(pfn); - page_ext =3D page_ext_get(page); - - if (!page_ext) - return; - BUG_ON(PageSlab(page)); anon =3D PageAnon(page); =20 - for (i =3D 0; i < pgcnt; i++) { + rcu_read_lock(); + for_each_page_ext(page, pgcnt, page_ext, iter) { struct page_table_check *ptc =3D get_page_table_check(page_ext); =20 if (anon) { @@ -129,9 +120,8 @@ static void page_table_check_set(unsigned long pfn, uns= igned long pgcnt, BUG_ON(atomic_read(&ptc->anon_map_count)); BUG_ON(atomic_inc_return(&ptc->file_map_count) < 0); } - page_ext =3D page_ext_next(page_ext); } - page_ext_put(page_ext); + rcu_read_unlock(); } =20 /* @@ -140,24 +130,19 @@ static void page_table_check_set(unsigned long pfn, u= nsigned long pgcnt, */ void __page_table_check_zero(struct page *page, unsigned int order) { + struct page_ext_iter iter; struct page_ext *page_ext; - unsigned long i; =20 BUG_ON(PageSlab(page)); =20 - page_ext =3D page_ext_get(page); - - if (!page_ext) - return; - - for (i =3D 0; i < (1ul << order); i++) { + rcu_read_lock(); + for_each_page_ext_order(page, order, page_ext, iter) { struct page_table_check *ptc =3D get_page_table_check(page_ext); =20 BUG_ON(atomic_read(&ptc->anon_map_count)); BUG_ON(atomic_read(&ptc->file_map_count)); - page_ext =3D page_ext_next(page_ext); } - page_ext_put(page_ext); + rcu_read_unlock(); } =20 void __page_table_check_pte_clear(struct mm_struct *mm, pte_t pte) --=20 2.48.1