From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-182.mta1.migadu.com (mta1.migadu.com [37.59.57.117]) (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 367E745FFBA for ; Wed, 5 Aug 2026 12:23:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=37.59.57.117 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785932601; cv=none; b=df970cKAk5uDboC/thQIdnABsvQHWazK4YuKQTwebQwhj59hWcKZfZsNxJE4wiqxSaakqtEEVw7PEzV+MbYso60//PuVsop8w9hhuQrh+w7K4Hpes/hhTKP1dHvK9NF0lhX/vrYa5B/AxV/8mlp/zcVWoULBvkIY7lafRY9gwLw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785932601; c=relaxed/simple; bh=3S5O+WmFCYTlfNAAGG8hR3gIY7XgRoq+MHcx43aEOyU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YJ7Ve2q389HXpHE/o95lWpEF1roKYIEzIYOacpPGFh63ovk/bQVT3T2IOniKlR9MbNi1fqhDuVO50l5FRzxwseciFBXicX5k625ULyyLkApXwaCX+23O9o6qrcvXbSXz2uFN9tk235wJ9Kg4EALdgPSQIoxCCWga4xQX393h5Ao= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=xS7J7OwZ; arc=none smtp.client-ip=37.59.57.117 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="xS7J7OwZ" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1785932597; 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=vQmUlerGIfmDflb91fg4O+jH4m7vxFQJPaUYGL93Kk0=; b=xS7J7OwZJD+fopQAeje3U74tdRqgJB0AsWNpoHGJEkzgWqKwf9qFkIygHIlawMkK3VMtQs u5f18HsMO9MK2G+Q6OxF+tF9DI2si68Cux79IGL0Xwpl0YmQ171WSmn8jQMDJu47YhzGmJ YtcXsWB+HpdtuBGNPUqdPQlxviLuYWs= From: Ye Liu To: Pasha Tatashin , Andrew Morton , Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: Ye Liu , Alexandre Ghiti , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH] mm/page_table_check: add explicit pmd_none check in pte_clear_range Date: Wed, 5 Aug 2026 20:22:24 +0800 Message-Id: <20260805122224.2512983-2-ye.liu@linux.dev> In-Reply-To: <20260805122224.2512983-1-ye.liu@linux.dev> References: <20260805122224.2512983-1-ye.liu@linux.dev> 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-Migadu-Flow: FLOW_OUT From: Ye Liu In __page_table_check_pte_clear_range(), the condition to determine whether to iterate over PTEs only checked pmd_bad() and pmd_leaf(). This relies on the implicit assumption that pmd_none() is always a subset of pmd_bad() on all architectures supporting PAGE_TABLE_CHECK. While this assumption currently holds for x86_64, arm64, s390, riscv, and powerpc, it is an architecture-dependent behavior that may not hold for future architectures. Add an explicit pmd_none() check to make the intent clear and avoid calling pte_offset_map() on an empty PMD, which could lead to undefined behavior. Signed-off-by: Ye Liu --- mm/page_table_check.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/page_table_check.c b/mm/page_table_check.c index 6ffc536359cd..ed3e1a76f266 100644 --- a/mm/page_table_check.c +++ b/mm/page_table_check.c @@ -278,7 +278,7 @@ void __page_table_check_pte_clear_range(struct mm_struct *mm, if (&init_mm == mm) return; - if (!pmd_bad(pmd) && !pmd_leaf(pmd)) { + if (!pmd_none(pmd) && !pmd_bad(pmd) && !pmd_leaf(pmd)) { pte_t *ptep = pte_offset_map(&pmd, addr); unsigned long i; -- 2.25.1