Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 1 Apr 2013 10:45:35 +0000 (UTC)
From:      "Cherry G. Mathew" <cherry@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r248970 - projects/amd64_xen_pv/sys/amd64/xen
Message-ID:  <201304011045.r31AjZCV029846@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: cherry
Date: Mon Apr  1 10:45:35 2013
New Revision: 248970
URL: http://svnweb.freebsd.org/changeset/base/248970

Log:
  Use memcchr(9) instead of homebrew (and slow) memrchr(3) (incorrectly
  used here). This implements the current semantics of searching for
  zero-ed out backing lower page table, before zapping its higher level
  table entry.
  
  Approved by: gibbs(implicit)

Modified:
  projects/amd64_xen_pv/sys/amd64/xen/mmu_map.c

Modified: projects/amd64_xen_pv/sys/amd64/xen/mmu_map.c
==============================================================================
--- projects/amd64_xen_pv/sys/amd64/xen/mmu_map.c	Mon Apr  1 09:59:38 2013	(r248969)
+++ projects/amd64_xen_pv/sys/amd64/xen/mmu_map.c	Mon Apr  1 10:45:35 2013	(r248970)
@@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$");
 #include "opt_smp.h"
 
 
+#include <sys/libkern.h>
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/types.h>
@@ -383,30 +384,6 @@ mmu_map_hold_va(struct pmap *pm, void *a
 	return alloced;
 }
 
-/*$FreeBSD: head/lib/libc/string/memrchr.c 178051 2008-04-10 00:12:44Z delphij $*/
-/*
- * Reverse memchr()
- * Find the last occurrence of 'c' in the buffer 's' of size 'n'.
- */
-
-static const void * memrchr(const void *, int, size_t);
-
-static const void *
-memrchr(const void *s, int c, size_t n)
-{
-	const unsigned char *cp;
-
-	if (n != 0) {
-		cp = (const unsigned char *)s + n;
-		do {
-			if (*(--cp) == (unsigned char)c)
-				return((const void *)cp);
-		} while (--n != 0);
-	}
-	return(NULL);
-}
-
-
 void
 mmu_map_release_va(struct pmap *pm, void *addr, uintptr_t va)
 {
@@ -461,7 +438,7 @@ mmu_map_release_va(struct pmap *pm, void
 			}
 
 			/* We can free the PT only after the PDT entry is zapped */
-			if (memrchr(pti->pt, 0, PAGE_SIZE) == ((char *)pti->pt + PAGE_SIZE - 1)) {
+			if (memcchr(pti->pt, 0, PAGE_SIZE) == NULL) {
 				/* Zap the backing PDT entry */
 				pdtep_ma = xpmap_ptom(pti->ptmb.vtop((uintptr_t)pdtep));
 				xen_queue_pt_update(pdtep_ma, 0);
@@ -509,7 +486,7 @@ mmu_map_release_va(struct pmap *pm, void
 		}
 
 		/* We can free the PDT only after the PDPT entry is zapped */
-		if (memrchr(pti->pdt, 0, PAGE_SIZE) == ((char *)pti->pdt + PAGE_SIZE - 1)) {
+		if (memcchr(pti->pt, 0, PAGE_SIZE) == NULL) {
 			pdptep_ma = xpmap_ptom(pti->ptmb.vtop((uintptr_t)pdptep));
 			xen_queue_pt_update(pdptep_ma, 0);
 			xen_flush_queue();
@@ -551,7 +528,7 @@ mmu_map_release_va(struct pmap *pm, void
 			return;
 		}
 
-		if (memrchr(pti->pdpt, 0, PAGE_SIZE) == ((char *)pti->pdpt + PAGE_SIZE - 1)) {
+		if (memcchr(pti->pt, 0, PAGE_SIZE) == NULL) {
 			pml4tep_ma = xpmap_ptom(pti->ptmb.vtop((uintptr_t)pml4tep)
 );
 			xen_queue_pt_update(pml4tep_ma, 0);



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