From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 A643838836C; Fri, 22 May 2026 23:09:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779491386; cv=none; b=JbIPAfpOGVHl41uNOoenEQxTy2niG46DVjYhi4/s4NvbytZASzjzrBuK+ZqVnoIVLyrJ4lxYOqa7BNiDe5C+xu4qm2yF+wJOnNG3feO+j+0QnDh4mIXBiMYSYBW9DK7vijSGdXp98hnCk/+kd4fz12ksmJN3R/OykBZ1N4uz408= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779491386; c=relaxed/simple; bh=uutmPtII2EQBL6vO0i0jqU5bYG0r+6vcKdT2D54nMBo=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=YhVDWYMg94yOMXjJiqeaq/FtwPcKSqleBRX1rWyqt7dMbtqKTtUbFkt0a6xcP2YPhQ0e9Ym6XmN/Ai9Exx+CohwREBy9qdvCTH9p/6yhWtGJ1j2h/s41UbIUbGj4AQBBFi6mvGp+3trKosXwn8mcf3VVusLAkeg25II93CxQzGU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YQZ8sveZ; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YQZ8sveZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9A7E1F000E9; Fri, 22 May 2026 23:09:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779491385; bh=SRNn+HK5PU4+WE2ZZvd2N1n519hA+9ALeyWVGg6XpfE=; h=Date:From:To:cc:Subject:In-Reply-To:References; b=YQZ8sveZ9qkjOvzrCCwjNmTRffNqCV1nLGIZzxyv54dBXtlgt7rvXhODy8FN2533q MiVnn1IVJEGDSSU7p/j2Pi1GyQ96ld3MVOKwlwEttGQc1E21+q0IvvFrl7Xo3XQQcS dOGAXA/PgwYeW3EotaFQSw76Pf7wl0KFW4sCNYdaxZQGlqo3tRgADMs0BFV/BcpfHK /0EElHRH15ECtSUPOPkOn7wVe384hNyH51ICHbG6Y8G1pQZksSjo/VZRhwEjFbRRfU RHDiqavjnifHfaVdLo0CCtWLTeIJmmOsKAlRfq7V+PXP9ZFQpj6gY+KrO2poLmzqZS I4YzsIhKjOfAw== Date: Fri, 22 May 2026 17:09:40 -0600 (MDT) From: Paul Walmsley To: Yunhui Cui cc: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, tongtiangen@huawei.com, akpm@linux-foundation.org, pasha.tatashin@soleen.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] riscv: mm: exclude invalid THP PMDs from page table check In-Reply-To: <20260515065048.94564-1-cuiyunhui@bytedance.com> Message-ID: <252be770-4d9f-954a-9388-8f7b52a92d90@kernel.org> References: <20260515065048.94564-1-cuiyunhui@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII On Fri, 15 May 2026, Yunhui Cui wrote: > RISC-V THP splitting uses a temporary invalid PMD state where > pmd_mkinvalid() clears _PAGE_PRESENT and _PAGE_PROT_NONE but leaves > _PAGE_LEAF set so the MM code can still recognize the PMD as a THP split > in-progress entry. > > That temporary state no longer describes a user-accessible mapping, but > page_table_check currently treats it as one because the RISC-V PMD > user-accessibility test only checks whether the PMD is a leaf and has > user permissions. > > As a result, when a PMD-sized anonymous THP is split during a COW fault, > page_table_check can account the invalid intermediate PMD as a live PMD > mapping, and then account the replacement PTE mappings again when the > split installs the PTE table. This leaves stale PMD accounting behind and > later triggers page_table_check failures such as a non-zero > anon_map_count when the folio is freed. > > Fix this by tightening pmd_user_accessible_page() so PMD page-table-check > accounting only considers leaf PMDs that still carry either > _PAGE_PRESENT or _PAGE_PROT_NONE. This preserves the THP split semantics > required by the MM code while preventing page_table_check from treating > invalid split PMDs as live user mappings. > > With CONFIG_PAGE_TABLE_CHECK=y and CONFIG_PAGE_TABLE_CHECK_ENFORCED=y, > tools/testing/selftests/mm/cow completes successfully on RISC-V after > this change. > > Fixes: 3fee229a8eb9 ("riscv/mm: enable ARCH_SUPPORTS_PAGE_TABLE_CHECK") > Cc: stable@vger.kernel.org > Signed-off-by: Yunhui Cui Thanks for the patch, but it doesn't apply as-is. Could you fix it and resend? - Paul