]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
[PATCH] i386: encapsulate copying of pgd entries
authorZachary Amsden <zach@vmware.com>
Sat, 3 Sep 2005 22:56:50 +0000 (15:56 -0700)
committerLinus Torvalds <torvalds@evo.osdl.org>
Mon, 5 Sep 2005 07:06:13 +0000 (00:06 -0700)
Add a clone operation for pgd updates.

This helps complete the encapsulation of updates to page tables (or pages
about to become page tables) into accessor functions rather than using
memcpy() to duplicate them.  This is both generally good for consistency
and also necessary for running in a hypervisor which requires explicit
updates to page table entries.

The new function is:

clone_pgd_range(pgd_t *dst, pgd_t *src, int count);

   dst - pointer to pgd range anwhere on a pgd page
   src - ""
   count - the number of pgds to copy.

   dst and src can be on the same page, but the range must not overlap
   and must not cross a page boundary.

Note that I ommitted using this call to copy pgd entries into the
software suspend page root, since this is not technically a live paging
structure, rather it is used on resume from suspend.  CC'ing Pavel in case
he has any feedback on this.

Thanks to Chris Wright for noticing that this could be more optimal in
PAE compiles by eliminating the memset.

Signed-off-by: Zachary Amsden <zach@vmware.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
arch/i386/kernel/smpboot.c
arch/i386/mm/pgtable.c
include/asm-i386/pgtable.h

index 8ac8e9fd5614fa10237dc58fa6620d52cff8e5e3..8e950cdff1a0e76718777614da3fe4fe15df4c73 100644 (file)
@@ -1017,8 +1017,8 @@ int __devinit smp_prepare_cpu(int cpu)
        tsc_sync_disabled = 1;
 
        /* init low mem mapping */
-       memcpy(swapper_pg_dir, swapper_pg_dir + USER_PGD_PTRS,
-                       sizeof(swapper_pg_dir[0]) * KERNEL_PGD_PTRS);
+       clone_pgd_range(swapper_pg_dir, swapper_pg_dir + USER_PGD_PTRS,
+                       KERNEL_PGD_PTRS);
        flush_tlb_all();
        schedule_work(&task);
        wait_for_completion(&done);
index bd2f7afc7a2a5d6726b14a35bdf48492bf4730a1..dcdce2c6c53239ad1ba747319ea6aecefa6d7a1a 100644 (file)
@@ -207,19 +207,19 @@ void pgd_ctor(void *pgd, kmem_cache_t *cache, unsigned long unused)
 {
        unsigned long flags;
 
-       if (PTRS_PER_PMD == 1)
+       if (PTRS_PER_PMD == 1) {
+               memset(pgd, 0, USER_PTRS_PER_PGD*sizeof(pgd_t));
                spin_lock_irqsave(&pgd_lock, flags);
+       }
 
-       memcpy((pgd_t *)pgd + USER_PTRS_PER_PGD,
+       clone_pgd_range((pgd_t *)pgd + USER_PTRS_PER_PGD,
                        swapper_pg_dir + USER_PTRS_PER_PGD,
-                       (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
-
+                       KERNEL_PGD_PTRS);
        if (PTRS_PER_PMD > 1)
                return;
 
        pgd_list_add(pgd);
        spin_unlock_irqrestore(&pgd_lock, flags);
-       memset(pgd, 0, USER_PTRS_PER_PGD*sizeof(pgd_t));
 }
 
 /* never called when PTRS_PER_PMD > 1 */
index d74185aee15b798d7e38ddea5cf3b3d5535ccec8..47bc1ffa3d4cfb42321cec3bf25d9da23ccc8486 100644 (file)
@@ -277,6 +277,21 @@ static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr,
        clear_bit(_PAGE_BIT_RW, &ptep->pte_low);
 }
 
+/*
+ * clone_pgd_range(pgd_t *dst, pgd_t *src, int count);
+ *
+ *  dst - pointer to pgd range anwhere on a pgd page
+ *  src - ""
+ *  count - the number of pgds to copy.
+ *
+ * dst and src can be on the same page, but the range must not overlap,
+ * and must not cross a page boundary.
+ */
+static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
+{
+       memcpy(dst, src, count * sizeof(pgd_t));
+}
+
 /*
  * Macro to mark a page protection value as "uncacheable".  On processors which do not support
  * it, this is a no-op.