Module Name:    src
Committed By:   martin
Date:           Thu Sep  3 13:45:24 UTC 2020

Modified Files:
        src/sys/arch/x86/x86 [netbsd-9]: pmap.c

Log Message:
Apply patch, requested by bouyer in ticket #1075:

        sys/arch/x86/x86/pmap.c (apply patch)

Fix double count on ptp entries in pmap_enter_gnt(), which causes a KASSERT
at pmap_destroy() time. Call pmap_free_ptp() if needed. We can have a 0 wire
count if we had an old mapping and grant map hypercall failed,
and this was the only page in this ptp.

while there remove ptp != NULL checks for gnt operations: we always have
a ptp here.


To generate a diff of this commit:
cvs rdiff -u -r1.334.2.4 -r1.334.2.5 src/sys/arch/x86/x86/pmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.334.2.4 src/sys/arch/x86/x86/pmap.c:1.334.2.5
--- src/sys/arch/x86/x86/pmap.c:1.334.2.4	Wed Sep  2 12:40:06 2020
+++ src/sys/arch/x86/x86/pmap.c	Thu Sep  3 13:45:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.334.2.4 2020/09/02 12:40:06 martin Exp $	*/
+/*	$NetBSD: pmap.c,v 1.334.2.5 2020/09/03 13:45:24 martin Exp $	*/
 
 /*
  * Copyright (c) 2008, 2010, 2016, 2017 The NetBSD Foundation, Inc.
@@ -130,7 +130,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.334.2.4 2020/09/02 12:40:06 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.334.2.5 2020/09/03 13:45:24 martin Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -4559,28 +4559,21 @@ pmap_enter_gnt(struct pmap *pmap, vaddr_
 	if (__predict_false(op->status != GNTST_okay)) {
 		printf("%s: GNTTABOP_map_grant_ref status: %d\n",
 		    __func__, op->status);
-		if (ptp != NULL) {
-			if (have_oldpa) {
-				ptp->wire_count--;
-			}
+		if (have_oldpa) {
+			ptp->wire_count--;
 		}
 	} else {
 		pgnt->pd_gnt_refs++;
-		if (ptp != NULL) {
-			if (!have_oldpa) {
-				ptp->wire_count++;
-			}
+		if (!have_oldpa) {
+			ptp->wire_count++;
 		}
+		KASSERT(ptp->wire_count > 1);
 	}
 
 	/*
 	 * Update statistics and PTP's reference count.
 	 */
 	pmap_stats_update_bypte(pmap, 0, opte);
-	if (ptp != NULL && !have_oldpa) {
-		ptp->wire_count++;
-	}
-	KASSERT(ptp == NULL || ptp->wire_count > 1);
 
 	/*
 	 * If old page is pv-tracked, remove pv_entry from its list.
@@ -4599,6 +4592,8 @@ pmap_enter_gnt(struct pmap *pmap, vaddr_
 		old_pve = pmap_remove_pv(old_pp, ptp, va);
 		old_pp->pp_attrs |= pmap_pte_to_pp_attrs(opte);
 	}
+	if (ptp->wire_count <= 1)
+		pmap_free_ptp(pmap, ptp, va, ptes, pdes);
 
 	pmap_unmap_ptes(pmap, pmap2);
 
@@ -4687,7 +4682,7 @@ pmap_remove_gnt(struct pmap *pmap, vaddr
 		 * being used, free it!
 		 */
 
-		if (ptp && ptp->wire_count <= 1)
+		if (ptp->wire_count <= 1)
 			pmap_free_ptp(pmap, ptp, va, ptes, pdes);
 	}
 	pmap_unmap_ptes(pmap, pmap2); /* unlock pmap */

Reply via email to