Fix couple of problems in compat code.
authorKanoj Sarcar' via Akaros <akaros@googlegroups.com>
Thu, 18 Feb 2016 22:11:00 +0000 (14:11 -0800)
committerBarret Rhoden <brho@cs.berkeley.edu>
Fri, 19 Feb 2016 15:50:54 +0000 (10:50 -0500)
While trying newer tests, the non-initialization logic of SGL's became
apparent. Also, newer tests invoke get_user_pages() without faulting in
corresponding pages, so we need to automatically allocate the pages.

Clean up to do reference counting in get_user_pages() etc will come later.

Signed-off-by: Kanoj Sarcar <kanoj@google.com>
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/drivers/net/udrvr/compat.c

index 436240f..93890d6 100644 (file)
@@ -77,9 +77,19 @@ int get_user_page(struct proc *p, unsigned long uvastart, int write, int force,
                goto err1;
 
        if (!pte_is_present(pte)) {
+               struct page *pp;
+               unsigned long prot = PTE_P | PTE_U | PTE_A | PTE_W | PTE_D;
+#if 0
                printk("[akaros]: get_user_page() uva=0x%llx pte absent\n",
                    uvastart);
-               goto err1;
+#endif
+               /*
+                * TODO: ok to allocate with pte_lock? "prot" needs to be
+                * based on VMR writability, refer to pgprot_noncached().
+                */
+               if (upage_alloc(p, &pp, 0))
+                       goto err1;
+               pte_write(pte, page2pa(pp), prot);
        }
 
        if (write && (!pte_has_perm_urw(pte))) {
@@ -100,6 +110,7 @@ int sg_alloc_table(struct sg_table *ptr, unsigned int npages, gfp_t mask)
 {
        ptr->sgl = kmalloc((sizeof(struct scatterlist) * npages), mask);
        ptr->nents = ptr->orig_nents = npages;
+       sg_init_table(ptr->sgl, npages);
        return 0;
 }