svn commit: r252868 - in projects/bhyve_npt_pmap/sys: amd64/vmm/intel vm
Neel Natu
neel at FreeBSD.org
Sat Jul 6 08:16:18 UTC 2013
Author: neel
Date: Sat Jul 6 08:16:17 2013
New Revision: 252868
URL: http://svnweb.freebsd.org/changeset/base/252868
Log:
Add a function pointer argument to 'vmspace_alloc()' that will be used to
initialize the embedded pmap. This will be used by callers that want to
create a pmap that is different than the one initialized by 'pmap_pinit()'.
For e.g. bhyve will use this function pointer to create a nested pmap of
type PT_EPT.
Discussed with: kib
Modified:
projects/bhyve_npt_pmap/sys/amd64/vmm/intel/ept.c
projects/bhyve_npt_pmap/sys/vm/vm_extern.h
projects/bhyve_npt_pmap/sys/vm/vm_map.c
Modified: projects/bhyve_npt_pmap/sys/amd64/vmm/intel/ept.c
==============================================================================
--- projects/bhyve_npt_pmap/sys/amd64/vmm/intel/ept.c Sat Jul 6 07:49:41 2013 (r252867)
+++ projects/bhyve_npt_pmap/sys/amd64/vmm/intel/ept.c Sat Jul 6 08:16:17 2013 (r252868)
@@ -393,25 +393,18 @@ ept_invalidate_mappings(u_long pml4ept)
smp_rendezvous(NULL, invept_single_context, NULL, &invept_desc);
}
+static int
+ept_pinit(pmap_t pmap)
+{
+
+ return (pmap_pinit_type(pmap, PT_EPT));
+}
+
struct vmspace *
ept_vmspace_alloc(vm_offset_t min, vm_offset_t max)
{
- pmap_t pmap;
- int success;
- struct vmspace *vmspace;
-
- vmspace = vmspace_alloc(min, max);
- if (vmspace != NULL) {
- /*
- * Change the type of the pmap to PT_EPT.
- */
- pmap = vmspace_pmap(vmspace);
- pmap_release(pmap);
- success = pmap_pinit_type(pmap, PT_EPT);
- if (!success)
- panic("ept_vmspace_alloc: pmap_pinit_type() failed!");
- }
- return (vmspace);
+
+ return (vmspace_alloc(min, max, ept_pinit));
}
void
Modified: projects/bhyve_npt_pmap/sys/vm/vm_extern.h
==============================================================================
--- projects/bhyve_npt_pmap/sys/vm/vm_extern.h Sat Jul 6 07:49:41 2013 (r252867)
+++ projects/bhyve_npt_pmap/sys/vm/vm_extern.h Sat Jul 6 08:16:17 2013 (r252868)
@@ -33,6 +33,7 @@
#ifndef _VM_EXTERN_H_
#define _VM_EXTERN_H_
+struct pmap;
struct proc;
struct vmspace;
struct vnode;
@@ -75,7 +76,8 @@ int vm_mmap(vm_map_t, vm_offset_t *, vm_
int vm_mmap_to_errno(int rv);
void vm_set_page_size(void);
void vm_sync_icache(vm_map_t, vm_offset_t, vm_size_t);
-struct vmspace *vmspace_alloc(vm_offset_t, vm_offset_t);
+typedef int (*pmap_pinit_t)(struct pmap *pmap);
+struct vmspace *vmspace_alloc(vm_offset_t, vm_offset_t, pmap_pinit_t);
struct vmspace *vmspace_fork(struct vmspace *, vm_ooffset_t *);
int vmspace_exec(struct proc *, vm_offset_t, vm_offset_t);
int vmspace_unshare(struct proc *);
Modified: projects/bhyve_npt_pmap/sys/vm/vm_map.c
==============================================================================
--- projects/bhyve_npt_pmap/sys/vm/vm_map.c Sat Jul 6 07:49:41 2013 (r252867)
+++ projects/bhyve_npt_pmap/sys/vm/vm_map.c Sat Jul 6 08:16:17 2013 (r252868)
@@ -274,15 +274,22 @@ vm_map_zdtor(void *mem, int size, void *
/*
* Allocate a vmspace structure, including a vm_map and pmap,
* and initialize those structures. The refcnt is set to 1.
+ *
+ * If 'pinit' is NULL then the embedded pmap is initialized via pmap_pinit().
*/
struct vmspace *
-vmspace_alloc(min, max)
- vm_offset_t min, max;
+vmspace_alloc(vm_offset_t min, vm_offset_t max, pmap_pinit_t pinit)
{
struct vmspace *vm;
vm = uma_zalloc(vmspace_zone, M_WAITOK);
- if (vm->vm_map.pmap == NULL && !pmap_pinit(vmspace_pmap(vm))) {
+
+ KASSERT(vm->vm_map.pmap == NULL, ("vm_map.pmap must be NULL"));
+
+ if (pinit == NULL)
+ pinit = &pmap_pinit;
+
+ if (!pinit(vmspace_pmap(vm))) {
uma_zfree(vmspace_zone, vm);
return (NULL);
}
@@ -3097,7 +3104,7 @@ vmspace_fork(struct vmspace *vm1, vm_oof
old_map = &vm1->vm_map;
/* Copy immutable fields of vm1 to vm2. */
- vm2 = vmspace_alloc(old_map->min_offset, old_map->max_offset);
+ vm2 = vmspace_alloc(old_map->min_offset, old_map->max_offset, NULL);
if (vm2 == NULL)
return (NULL);
vm2->vm_taddr = vm1->vm_taddr;
@@ -3677,7 +3684,7 @@ vmspace_exec(struct proc *p, vm_offset_t
struct vmspace *oldvmspace = p->p_vmspace;
struct vmspace *newvmspace;
- newvmspace = vmspace_alloc(minuser, maxuser);
+ newvmspace = vmspace_alloc(minuser, maxuser, NULL);
if (newvmspace == NULL)
return (ENOMEM);
newvmspace->vm_swrss = oldvmspace->vm_swrss;
More information about the svn-src-projects
mailing list