diff options
author | alc <alc@FreeBSD.org> | 2009-06-14 19:51:43 +0000 |
---|---|---|
committer | alc <alc@FreeBSD.org> | 2009-06-14 19:51:43 +0000 |
commit | 07cfd3813e59357b4f158c780fa4518aa69c340d (patch) | |
tree | 214c086ff9f844087ff8e6bdf79cd628889e7393 /sys/vm | |
parent | c2624ed238285b10690b8008cd36e0d9aff09b0d (diff) | |
download | FreeBSD-src-07cfd3813e59357b4f158c780fa4518aa69c340d.zip FreeBSD-src-07cfd3813e59357b4f158c780fa4518aa69c340d.tar.gz |
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@
Diffstat (limited to 'sys/vm')
-rw-r--r-- | sys/vm/vm_object.c | 49 | ||||
-rw-r--r-- | sys/vm/vm_object.h | 1 |
2 files changed, 50 insertions, 0 deletions
diff --git a/sys/vm/vm_object.c b/sys/vm/vm_object.c index d98f944..c73882c 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. diff --git a/sys/vm/vm_object.h b/sys/vm/vm_object.h index 250dad8..99a2a58 100644 --- a/sys/vm/vm_object.h +++ b/sys/vm/vm_object.h @@ -207,6 +207,7 @@ void vm_object_set_writeable_dirty (vm_object_t); void vm_object_init (void); void vm_object_page_clean (vm_object_t, vm_pindex_t, vm_pindex_t, boolean_t); void vm_object_page_remove (vm_object_t, vm_pindex_t, vm_pindex_t, boolean_t); +boolean_t vm_object_populate(vm_object_t, vm_pindex_t, vm_pindex_t); void vm_object_reference (vm_object_t); void vm_object_reference_locked(vm_object_t); void vm_object_shadow (vm_object_t *, vm_ooffset_t *, vm_size_t); |