Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 5 Jul 2019 05:23:23 +0000 (UTC)
From:      Alan Cox <alc@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r349760 - head/sys/riscv/riscv
Message-ID:  <201907050523.x655NNKn037291@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: alc
Date: Fri Jul  5 05:23:23 2019
New Revision: 349760
URL: https://svnweb.freebsd.org/changeset/base/349760

Log:
  Merge r349526 from amd64.  When we protect an L3 entry, we only call
  vm_page_dirty() when, in fact, we are write protecting the page and the L3
  entry has PTE_D set.  However, pmap_protect() was always calling
  vm_page_dirty() when an L2 entry has PTE_D set.  Handle L2 entries the
  same as L3 entries so that we won't perform unnecessary calls to
  vm_page_dirty().
  
  Simplify the loop calling vm_page_dirty() on L2 entries.

Modified:
  head/sys/riscv/riscv/pmap.c

Modified: head/sys/riscv/riscv/pmap.c
==============================================================================
--- head/sys/riscv/riscv/pmap.c	Fri Jul  5 04:24:09 2019	(r349759)
+++ head/sys/riscv/riscv/pmap.c	Fri Jul  5 05:23:23 2019	(r349760)
@@ -2298,9 +2298,9 @@ pmap_protect(pmap_t pmap, vm_offset_t sva, vm_offset_t
 {
 	pd_entry_t *l1, *l2, l2e;
 	pt_entry_t *l3, l3e, mask;
-	vm_page_t m;
+	vm_page_t m, mt;
 	vm_paddr_t pa;
-	vm_offset_t va, va_next;
+	vm_offset_t va_next;
 	bool anychanged, pv_lists_locked;
 
 	if ((prot & VM_PROT_READ) == VM_PROT_NONE) {
@@ -2340,12 +2340,13 @@ resume:
 		if ((l2e & PTE_RWX) != 0) {
 			if (sva + L2_SIZE == va_next && eva >= va_next) {
 retryl2:
-				if ((l2e & (PTE_SW_MANAGED | PTE_D)) ==
+				if ((prot & VM_PROT_WRITE) == 0 &&
+				    (l2e & (PTE_SW_MANAGED | PTE_D)) ==
 				    (PTE_SW_MANAGED | PTE_D)) {
 					pa = PTE_TO_PHYS(l2e);
-					for (va = sva, m = PHYS_TO_VM_PAGE(pa);
-					    va < va_next; m++, va += PAGE_SIZE)
-						vm_page_dirty(m);
+					m = PHYS_TO_VM_PAGE(pa);
+					for (mt = m; mt < &m[Ln_ENTRIES]; mt++)
+						vm_page_dirty(mt);
 				}
 				if (!atomic_fcmpset_long(l2, &l2e, l2e & ~mask))
 					goto retryl2;



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