Subject: Not quite a fix for: port-xen/30635
To: None <gnats-bugs@NetBSD.org>
From: Jed Davis <jdev@panix.com>
List: port-xen
Date: 07/23/2005 00:23:01
--=-=-=


The attached patch changes IOCTL_PRIVCMD_MMAP such that it will
decline to replace a nonexistent mapping, and uses (abuses?) uvm_fault
to attempt to create a mapping if needed so that xend will still work.
The result is that the dom0 kernel no longer panics, but xend is still
as confused as before: on the first restart, it tries to destroy
domain 1 and then dies, and futher attempts to start it do nothing at
all.

In other words, the MI UVM structures are slightly less inconsistent
with the pmap than they used to be: assuming I understand what's going
on, there's now actually a vm_page corresponding to each foreign
machine page (notwithstanding that that vm_page's PA is a complete
fiction), so the mapping gets removed when the process exits.



--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment; filename=pr-30635_1.diff

--- xen/privcmd.c       18 Jun 2005 10:43:37 -0000      1.2.2.2
+++ xen/privcmd.c       23 Jul 2005 03:46:40 -0000
@@ -105,9 +105,12 @@
                vaddr_t va;
                u_long ma;
-               //printf("IOCTL_PRIVCMD_MMAP: %d entries\n", mcmd->num);
+               struct vm_map *vmm;
+               pmap_t pmap;
 
-               pmap_t pmap = vm_map_pmap(&ap->a_p->p_vmspace->vm_map);
+               vmm = &ap->a_p->p_vmspace->vm_map;
+               pmap = vm_map_pmap(vmm);
                for (i = 0; i < mcmd->num; i++) {
-                       error = copyin(mcmd->entry, &mentry, sizeof(mentry));
+                       error = copyin(&mcmd->entry[i], &mentry,
+                           sizeof(mentry));
                        if (error)
                                return error;
@@ -124,7 +127,15 @@
                        for (j = 0; j < mentry.npages; j++) {
                                //printf("remap va 0x%lx to 0x%lx\n", va, ma);
-#if 0
-                               if (!pmap_extract(pmap, va, NULL))
-                                       return EINVAL; /* XXX */
+#if 1
+                               /* XXXjld@panix.com */
+                               if (!pmap_extract(pmap, va, NULL)) {
+                                       (void)uvm_fault(vmm, va,
+                                           VM_FAULT_INVALID, UVM_PROT_NONE);
+                                       if (!pmap_extract(pmap, va, NULL)) {
+                                               printf("IOCTL_PRIVCMD_MMAP: "
+                                                   "no existing mapping\n");
+                                               return EINVAL;
+                                       }
+                               }
 #endif
                                if ((error = pmap_remap_pages(pmap, va, ma, 1,

--=-=-=--