Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 Jun 2019 15:11:14 +0000 (UTC)
From:      Ruslan Bukin <br@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r348613 - stable/12/sys/riscv/riscv
Message-ID:  <201906041511.x54FBExp024906@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: br
Date: Tue Jun  4 15:11:14 2019
New Revision: 348613
URL: https://svnweb.freebsd.org/changeset/base/348613

Log:
  MFC 339774:
  
  o Add pmap lock around pmap_fault_fixup() to ensure other thread will not
    modify l3 pte after we loaded old value and before we stored new value.
  o Preset A(accessed), D(dirty) bits for kernel mappings.
  
  Sponsored by:	DARPA, AFRL

Modified:
  stable/12/sys/riscv/riscv/pmap.c

Modified: stable/12/sys/riscv/riscv/pmap.c
==============================================================================
--- stable/12/sys/riscv/riscv/pmap.c	Tue Jun  4 13:45:30 2019	(r348612)
+++ stable/12/sys/riscv/riscv/pmap.c	Tue Jun  4 15:11:14 2019	(r348613)
@@ -1923,16 +1923,21 @@ pmap_fault_fixup(pmap_t pmap, vm_offset_t va, vm_prot_
 	pt_entry_t orig_l3;
 	pt_entry_t new_l3;
 	pt_entry_t *l3;
+	int rv;
 
+	rv = 0;
+
+	PMAP_LOCK(pmap);
+
 	l3 = pmap_l3(pmap, va);
 	if (l3 == NULL)
-		return (0);
+		goto done;
 
 	orig_l3 = pmap_load(l3);
 	if ((orig_l3 & PTE_V) == 0 ||
 	    ((prot & VM_PROT_WRITE) != 0 && (orig_l3 & PTE_W) == 0) ||
 	    ((prot & VM_PROT_READ) != 0 && (orig_l3 & PTE_R) == 0))
-		return (0);
+		goto done;
 
 	new_l3 = orig_l3 | PTE_A;
 	if ((prot & VM_PROT_WRITE) != 0)
@@ -1941,7 +1946,8 @@ pmap_fault_fixup(pmap_t pmap, vm_offset_t va, vm_prot_
 	if (orig_l3 != new_l3) {
 		pmap_load_store(l3, new_l3);
 		pmap_invalidate_page(pmap, va);
-		return (1);
+		rv = 1;
+		goto done;
 	}
 
 	/*	
@@ -1949,7 +1955,10 @@ pmap_fault_fixup(pmap_t pmap, vm_offset_t va, vm_prot_
 	 * the PTE shouldn't have resulted in a fault.
 	 */
 
-	return (0);
+done:
+	PMAP_UNLOCK(pmap);
+
+	return (rv);
 }
 
 /*
@@ -1992,6 +2001,8 @@ pmap_enter(pmap_t pmap, vm_offset_t va, vm_page_t m, v
 		new_l3 |= PTE_W;
 	if ((va >> 63) == 0)
 		new_l3 |= PTE_U;
+	else
+		new_l3 |= PTE_A | PTE_D;
 
 	new_l3 |= (pn << PTE_PPN0_S);
 	if ((flags & PMAP_ENTER_WIRED) != 0)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201906041511.x54FBExp024906>