From nobody Fri Apr 3 07:59:11 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2D1692C21FE for ; Thu, 19 Feb 2026 05:49:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771480184; cv=none; b=hw4Mwf7RraTGJG6r4n+okI9KCgigNf+kxazvm3u1FLcWVBkvlRqs44j+sO+mmCYazRsXRx6ZtcmtsNTcRX8P+ECKCd481DiXO+C+qjGeNqrPCLywgshJrDOnujgoRDN7x051ug7/UaEBYiglqR6kxMmgfB3aPaDKfMU6H2AlQ3E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771480184; c=relaxed/simple; bh=pe+YNdIxZsX+XILjYWdZv7wdOfA//8tVwOe+jYO5JAY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=ne4M8mQfrdicQP5mxwnD4ommJLxfUniR6usltw0OypyudtBiCxvdOzAK2DT0kFiWtFlqCC2L7JqmyeNdlNoE6ep3eHQsuVQYchtsViIWGvNPdCauSdX7sfHvwPub7pRVugblltZrmw2ZVprzJNWSVZNl0bQdo3153vzCqNeGVMU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B2ABD339; Wed, 18 Feb 2026 21:49:34 -0800 (PST) Received: from a080796.blr.arm.com (a080796.arm.com [10.164.21.51]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 593673F632; Wed, 18 Feb 2026 21:49:37 -0800 (PST) From: Dev Jain To: akpm@linux-foundation.org, david@kernel.org, lorenzo.stoakes@oracle.com Cc: ziy@nvidia.com, baolin.wang@linux.alibaba.com, Liam.Howlett@oracle.com, npache@redhat.com, ryan.roberts@arm.com, baohua@kernel.org, lance.yang@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Dev Jain Subject: [PATCH] khugepaged: convert redundant check to WARN_ON Date: Thu, 19 Feb 2026 11:18:27 +0530 Message-Id: <20260219054827.4111334-1-dev.jain@arm.com> X-Mailer: git-send-email 2.34.1 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 Content-Type: text/plain; charset="utf-8" Claim: folio_order(folio) =3D=3D HPAGE_PMD_ORDER =3D> folio->index =3D=3D s= tart. Proof: Both loops in hpage_collapse_scan_file and collapse_file, which iterate on the xarray, have the invariant that start <=3D folio->index < start + HPAGE_PMD_NR ... (i) A folio is always naturally aligned in the pagecache, therefore folio_order =3D=3D HPAGE_PMD_ORDER =3D> IS_ALIGNED(folio->index, HPAGE_PMD_= NR) =3D=3D true ... (ii) thp_vma_allowable_order -> thp_vma_suitable_order requires that the virtual offsets in the VMA are aligned to the order, =3D> IS_ALIGNED(start, HPAGE_PMD_NR) =3D=3D true ... (iii) Combining (i), (ii) and (iii), the claim is proven. Therefore, convert this to a VM_WARN_ON. Signed-off-by: Dev Jain Reviewed-by: Baolin Wang Reviewed-by: Lance Yang --- Based on mm-unstable (d9982f38eb6e). mm-selftests pass. mm/khugepaged.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index fa1e57fd2c469..f27cbb4d1f62c 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2000,8 +2000,9 @@ static enum scan_result collapse_file(struct mm_struc= t *mm, unsigned long addr, * we locked the first folio, then a THP might be there already. * This will be discovered on the first iteration. */ - if (folio_order(folio) =3D=3D HPAGE_PMD_ORDER && - folio->index =3D=3D start) { + if (folio_order(folio) =3D=3D HPAGE_PMD_ORDER) { + VM_WARN_ON(folio->index !=3D start); + /* Maybe PMD-mapped */ result =3D SCAN_PTE_MAPPED_HUGEPAGE; goto out_unlock; @@ -2329,8 +2330,9 @@ static enum scan_result hpage_collapse_scan_file(stru= ct mm_struct *mm, unsigned continue; } =20 - if (folio_order(folio) =3D=3D HPAGE_PMD_ORDER && - folio->index =3D=3D start) { + if (folio_order(folio) =3D=3D HPAGE_PMD_ORDER) { + VM_WARN_ON(folio->index !=3D start); + /* Maybe PMD-mapped */ result =3D SCAN_PTE_MAPPED_HUGEPAGE; /* --=20 2.34.1