Re: [patch, feature] nonlinear mappings, prefaulting support, 2.5.42-F8

William Lee Irwin III (wli@holomorphy.com)
Mon, 14 Oct 2002 14:02:34 -0700


On Mon, Oct 14, 2002 at 06:02:30PM +0200, Ingo Molnar wrote:
>> if this is really an issue then we could force vma->vm_page_prot to
>> PROT_NONE within remap_file_pages(), so at least all subsequent faults
>> will be PROT_NONE and the user would have to explicitly re-mprotect()
>> the vma again to change this.
> i've added this to the -G1 patch at:
> http://redhat.com/~mingo/remap-file-pages-patches/
> Ingo

Okay, if PROT_NONE is in there, my last remaining concern would be
solved by invalidating the pte's of failed nonblocking prefaults.

A nonblocking remapping done "over the top" of a preexisting mapping
(such as would occur with MAP_LOCKED) may fail at unpredictable times,
which is fine from the kernel point of view but leaves userspace with
no way of telling which pages that it requested to be prefaulted
actually made it in, and which pages are residue from the prior mapping.

Basically something like this would solve this API semantics issue
(totally untested). Against mpopulate-2.5.42-G1

diff -urpN mpop-2.5.42/include/linux/mm.h wlipop-2.5.42/include/linux/mm.h
--- mpop-2.5.42/include/linux/mm.h 2002-10-14 11:43:03.000000000 -0700
+++ wlipop-2.5.42/include/linux/mm.h 2002-10-14 12:26:27.000000000 -0700
@@ -424,6 +424,7 @@ static inline pmd_t *pmd_alloc(struct mm
return pmd_offset(pgd, address);
}

+extern void zap_pte(struct mm_struct *, pte_t *);
extern void free_area_init(unsigned long * zones_size);
extern void free_area_init_node(int nid, pg_data_t *pgdat, struct page *pmap,
unsigned long * zones_size, unsigned long zone_start_pfn,
diff -urpN mpop-2.5.42/mm/filemap.c wlipop-2.5.42/mm/filemap.c
--- mpop-2.5.42/mm/filemap.c 2002-10-14 11:43:03.000000000 -0700
+++ wlipop-2.5.42/mm/filemap.c 2002-10-14 12:12:08.000000000 -0700
@@ -1286,9 +1286,27 @@ repeat:
return -EINVAL;

page = filemap_getpage(file, pgoff, nonblock);
- if (!page && !nonblock)
- return -ENOMEM;
- if (page) {
+
+ if (!page) {
+ pgd_t *pgd;
+
+ if (!nonblock)
+ return -ENOMEM;
+
+ spin_lock(&mm->page_table_lock);
+ pgd = pgd_offset(mm, addr);
+ if (!pgd_none(*pgd) && !pgd_bad(*pgd)) {
+ pmd_t *pmd = pmd_offset(pgd, addr);
+ if (!pmd_none(*pmd) && !pmd_bad(*pmd)) {
+ pte_t *pte = pte_offset_map(pmd, addr);
+ if (pte) {
+ zap_pte(mm, pte);
+ pte_unmap(pte);
+ }
+ }
+ }
+ spin_unlock(&mm->page_table_lock);
+ } else {
err = install_page(mm, vma, addr, page, prot);
if (err)
return err;
diff -urpN mpop-2.5.42/mm/fremap.c wlipop-2.5.42/mm/fremap.c
--- mpop-2.5.42/mm/fremap.c 2002-10-14 11:43:03.000000000 -0700
+++ wlipop-2.5.42/mm/fremap.c 2002-10-14 12:26:37.000000000 -0700
@@ -13,7 +13,7 @@
#include <linux/swapops.h>
#include <asm/mmu_context.h>

-static inline void zap_pte(struct mm_struct *mm, pte_t *ptep)
+void zap_pte(struct mm_struct *mm, pte_t *ptep)
{
pte_t pte = *ptep;

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/