Re: Major 2.1.x problem index

Savochkin Andrey Vladimirovich (saw@msu.ru)
Tue, 23 Jun 1998 22:06:04 +0400


--ikeVEW9yuYc//A+q
Content-Type: text/plain; charset=us-ascii

> On Fri, 19 Jun 1998, Alan Cox wrote:
>
> > http://roadrunner.swansea.uk.linux.org/jobs.shtml holds the major showstopper
> > items for a 2.2 release, and a few other bugs indexed on a web page.

I've written a piece of code to solve mlock problem.
I'm certainly not a mm guru so the code may be wrong.
Do people agree with the implemented approach to fix the problem?

Best wishes
Andrey V.
Savochkin

--ikeVEW9yuYc//A+q
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="mlock.1"

--- linux.orig/mm/mlock.c Wed Jun 17 14:57:33 1998
+++ linux/mm/mlock.c Sun Jun 21 20:00:32 1998
@@ -126,26 +126,7 @@
if (!(newflags & VM_LOCKED))
pages = -pages;
vma->vm_mm->locked_vm += pages;
-
-#if 0
-/*
- * This is horribly broken. See the comment on the same
- * brokenness in mm/mmap.c (essentially, this doesn't
- * work anyway for PROT_NONE and writable pages, and now
- * that we properly get the mmap semaphore it would just
- * lock up on us).
- *
- * Fix the same way.
- */
- if (newflags & VM_LOCKED) {
- while (start < end) {
- int c;
- get_user(c,(int *) start);
- __asm__ __volatile__("": :"r" (c));
- start += PAGE_SIZE;
- }
- }
-#endif
+ make_pages_present(start, end);
}
return retval;
}
--- linux.orig/mm/memory.c Wed Jun 17 14:57:33 1998
+++ linux/mm/memory.c Tue Jun 23 19:06:55 1998
@@ -918,6 +918,72 @@
oom(tsk);
}

+/*
+ * mm semaphore and global kernel lock should be held,
+ * pages should belong to the same vma.
+ */
+void make_pages_present(unsigned long addr, unsigned long end)
+{
+ struct vm_area_struct * vma;
+ pgd_t *pgd;
+ pmd_t *pmd;
+ pte_t *pte;
+ pte_t origentry;
+ int writable, needfix;
+
+ vma = find_vma(current->mm, addr);
+ pgd = pgd_offset(current->mm, addr);
+
+ while (1) {
+ pmd = pmd_alloc(pgd, addr);
+ if (!pmd)
+ goto no_memory;
+ pte = pte_alloc(pmd, addr);
+ if (!pte)
+ goto no_memory;
+
+ writable = vma->vm_flags & VM_MAYWRITE;
+ needfix = writable;
+ flush_cache_page(vma, addr);
+ origentry = *pte;
+ if (pte_none(origentry) || !pte_present(origentry))
+ do_no_page(current, vma, addr, writable, pte,
+ origentry);
+ else if (writable && !pte_write(origentry))
+ do_wp_page(current, vma, addr, writable, pte);
+ else
+ needfix = 0;
+
+ /* do_xxx_page() can make the page writtable when it
+ * isn't. Now we fix the protection. The page can't
+ * be accessed before the fix because:
+ * 1) the code hasn't blocked
+ * 2) global kernel lock is held
+ * 3) user space pages can't be accessed from
+ * interrupts.
+ */
+ if (needfix) {
+ pte_t entry;
+ flush_cache_page(vma, addr);
+ entry = pte_modify(*pte, vma->vm_page_prot);
+ if (vma->vm_flags & VM_WRITE)
+ entry = pte_mkwrite(entry);
+ if (!pte_dirty(origentry))
+ entry = pte_mkclean(entry);
+ set_pte(pte, entry);
+ flush_tlb_page(vma, addr);
+ }
+ update_mmu_cache(vma, addr, *pte);
+
+ addr += PAGE_SIZE;
+ if (addr >= end)
+ break;
+ }
+ return;
+no_memory:
+ oom(current);
+}
+
/* Low and high watermarks for page table cache.
The system should try to have pgt_water[0] <= cache elements <= pgt_water[1]
*/
--- linux.orig/include/linux/mm.h Wed Jun 17 14:49:08 1998
+++ linux/include/linux/mm.h Sun Jun 21 20:27:45 1998
@@ -292,6 +292,7 @@
extern void vmtruncate(struct inode * inode, unsigned long offset);
extern void handle_mm_fault(struct task_struct *tsk,struct vm_area_struct *vma, unsigned long address, int write_access);
extern void check_pgt_cache(void);
+extern void make_pages_present(unsigned long addr, unsigned long end);

extern unsigned long paging_init(unsigned long start_mem, unsigned long end_mem);
extern void mem_init(unsigned long start_mem, unsigned long end_mem);

--ikeVEW9yuYc//A+q
Content-Type: application/x-gunzip
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="memlock-test.c.gz"

H4sICATqjzUCA21lbWxvY2suYwCtVm1v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PHG2NIDRS/0ZOmuRT3VU8W0Mu3hVPsOzxPERyZ6UYFFxi9lNkGbGPu+q0fRcr9pxnjVzOyd
Ym6Z0+aZvzn/AFM7yuqiCQAA

--ikeVEW9yuYc//A+q--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu