aboutsummaryrefslogtreecommitdiff
path: root/sys/vm/vm_object.c
diff options
context:
space:
mode:
authorAlan Cox <alc@FreeBSD.org>2009-06-14 19:51:43 +0000
committerAlan Cox <alc@FreeBSD.org>2009-06-14 19:51:43 +0000
commit387aabc513d81aca8f7002739f97f0753cebb152 (patch)
tree214c086ff9f844087ff8e6bdf79cd628889e7393 /sys/vm/vm_object.c
parent00c49c7a2d70f786f2be9af61ffe4e0df6fb6aa4 (diff)
downloadsrc-387aabc513d81aca8f7002739f97f0753cebb152.tar.gz
src-387aabc513d81aca8f7002739f97f0753cebb152.zip
Long, long ago in r27464 special case code for mapping device-backed
memory with 4MB pages was added to pmap_object_init_pt(). This code assumes that the pages of a OBJT_DEVICE object are always physically contiguous. Unfortunately, this is not always the case. For example, jhb@ informs me that the recently introduced /dev/ksyms driver creates a OBJT_DEVICE object that violates this assumption. Thus, this revision modifies pmap_object_init_pt() to abort the mapping if the OBJT_DEVICE object's pages are not physically contiguous. This revision also changes some inconsistent if not buggy behavior. For example, the i386 version aborts if the first 4MB virtual page that would be mapped is already valid. However, it incorrectly replaces any subsequent 4MB virtual page mappings that it encounters, potentially leaking a page table page. The amd64 version has a bug of my own creation. It potentially busies the wrong page and always an insufficent number of pages if it blocks allocating a page table page. To my knowledge, there have been no reports of these bugs, hence, their persistance. I suspect that the existing restrictions that pmap_object_init_pt() placed on the OBJT_DEVICE objects that it would choose to map, for example, that the first page must be aligned on a 2 or 4MB physical boundary and that the size of the mapping must be a multiple of the large page size, were enough to avoid triggering the bug for drivers like ksyms. However, one side effect of testing the OBJT_DEVICE object's pages for physical contiguity is that a dubious difference between pmap_object_init_pt() and the standard path for mapping devices pages, i.e., vm_fault(), has been eliminated. Previously, pmap_object_init_pt() would only instantiate the first PG_FICTITOUS page being mapped because it never examined the rest. Now, however, pmap_object_init_pt() uses the new function vm_object_populate() to instantiate them all (in order to support testing their physical contiguity). These pages need to be instantiated for the mechanism that I have prototyped for automatically maintaining the consistency of the PAT settings across multiple mappings, particularly, amd64's direct mapping, to work. (Translation: This change is also being made to support jhb@'s work on the Nvidia feature requests.) Discussed with: jhb@
Notes
Notes: svn path=/head/; revision=194209
Diffstat (limited to 'sys/vm/vm_object.c')
-rw-r--r--sys/vm/vm_object.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/sys/vm/vm_object.c b/sys/vm/vm_object.c
index d98f944477ab..c73882c776b1 100644
--- a/sys/vm/vm_object.c
+++ b/sys/vm/vm_object.c
@@ -1931,6 +1931,55 @@ skipmemq:
}
/*
+ * Populate the specified range of the object with valid pages. Returns
+ * TRUE if the range is successfully populated and FALSE otherwise.
+ *
+ * Note: This function should be optimized to pass a larger array of
+ * pages to vm_pager_get_pages() before it is applied to a non-
+ * OBJT_DEVICE object.
+ *
+ * The object must be locked.
+ */
+boolean_t
+vm_object_populate(vm_object_t object, vm_pindex_t start, vm_pindex_t end)
+{
+ vm_page_t m, ma[1];
+ vm_pindex_t pindex;
+ int rv;
+
+ VM_OBJECT_LOCK_ASSERT(object, MA_OWNED);
+ for (pindex = start; pindex < end; pindex++) {
+ m = vm_page_grab(object, pindex, VM_ALLOC_NORMAL |
+ VM_ALLOC_RETRY);
+ if (m->valid != VM_PAGE_BITS_ALL) {
+ ma[0] = m;
+ rv = vm_pager_get_pages(object, ma, 1, 0);
+ m = vm_page_lookup(object, pindex);
+ if (m == NULL)
+ break;
+ if (rv != VM_PAGER_OK) {
+ vm_page_lock_queues();
+ vm_page_free(m);
+ vm_page_unlock_queues();
+ break;
+ }
+ }
+ /*
+ * Keep "m" busy because a subsequent iteration may unlock
+ * the object.
+ */
+ }
+ if (pindex > start) {
+ m = vm_page_lookup(object, start);
+ while (m != NULL && m->pindex < pindex) {
+ vm_page_wakeup(m);
+ m = TAILQ_NEXT(m, listq);
+ }
+ }
+ return (pindex == end);
+}
+
+/*
* Routine: vm_object_coalesce
* Function: Coalesces two objects backing up adjoining
* regions of memory into a single object.