NetBSD Problem Report #59707

From www@netbsd.org  Wed Oct 15 01:39:09 2025
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits)
	 client-signature RSA-PSS (2048 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id CFBDA1A923A
	for <gnats-bugs@gnats.NetBSD.org>; Wed, 15 Oct 2025 01:39:09 +0000 (UTC)
Message-Id: <20251015013908.89EF21A923C@mollari.NetBSD.org>
Date: Wed, 15 Oct 2025 01:39:08 +0000 (UTC)
From: thorpej@me.com
Reply-To: thorpej@me.com
To: gnats-bugs@NetBSD.org
Subject: pte_make_enter() appears to have bug vis a vis already-modified managed pages
X-Send-Pr-Version: www-1.0

>Number:         59707
>Category:       port-riscv
>Synopsis:       pte_make_enter() appears to have bug vis a vis already-modified managed pages
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    port-riscv-maintainer
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Oct 15 01:40:01 +0000 2025
>Closed-Date:    Wed Oct 15 05:05:42 +0000 2025
>Last-Modified:  Wed Oct 15 05:05:42 +0000 2025
>Originator:     Jason Thorpe
>Release:        NetBSD-current as of 20251006
>Organization:
RISCy Business
>Environment:
N/A
>Description:
pmap_make_enter() has the following block of code to skip mod/ref emulation for managed pages that are already modified and/or referenced:

                if ((prot & VM_PROT_WRITE) != 0 &&
                    ((flags & VM_PROT_WRITE) != 0 || VM_PAGEMD_MODIFIED_P(mdpg))) {
                        /*
                        * This is a writable mapping, and the page's mod state
                        * indicates it has already been modified.  No need for
                        * modified emulation.
                        */
                        pte |= PTE_A;
                } else if ((flags & VM_PROT_ALL) || VM_PAGEMD_REFERENCED_P(mdpg)) {             
                        /*
                        * - The access type indicates that we don't need to do
                        *   referenced emulation.
                        * OR
                        * - The physical page has already been referenced so no need    
                        *   to re-do referenced emulation here.
                        */
                        pte |= PTE_A;
                }

In the first block, handling the VM_PAGEMD_MODIFIED_P(), the new PTE does not get the Dirty bit, meaning that a write fault will have to be processed.  That line should almost certainly be:

                        pte |= PTE_A | PTE_D;

>How-To-Repeat:
Code observation.
>Fix:
See above.

>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->closed
State-Changed-By: skrll@NetBSD.org
State-Changed-When: Wed, 15 Oct 2025 05:05:42 +0000
State-Changed-Why:
duplicate of 59696


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.