WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [patch] pgtable.c cleanups

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [patch] pgtable.c cleanups
From: Gerd Knorr <kraxel@xxxxxxxxxxx>
Date: Fri, 29 Apr 2005 13:20:53 +0200
Delivery-date: Fri, 29 Apr 2005 11:24:44 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.9i
  Hi guys,

The new mm_(un)pin stuff is certainly a nice optimization.

But can we take care a bit more about coding style issues
and write code not *that* hackish please?  Casts, code
duplication, "unsigned long" for page table entries *again*.
And a few more variables also make the code more readable
(and gcc should be clever enougth that this isn't a
performance hit).  We want to have that merged some day in
mainline, don't we?

The patch below cleans up the pin/unpin code in pgtable.c
I've created two helper functions to factor out common code,
the page table walk is basically the same for both pin and
unpin, it's just different page flags.  Also fixed up the
walk code to correcly walk through all 4 levels linux has,
so it works correctly for the PAE case.  For x86_64 it
should work fine as well (untested though).

please apply,

  Gerd

Index: linux-2.6.11/arch/xen/i386/mm/pgtable.c
===================================================================
--- linux-2.6.11.orig/arch/xen/i386/mm/pgtable.c        2005-04-29 
13:01:34.000000000 +0200
+++ linux-2.6.11/arch/xen/i386/mm/pgtable.c     2005-04-29 13:00:49.000000000 
+0200
@@ -444,30 +432,58 @@ void make_pages_writable(void *va, unsig
 }
 #endif /* CONFIG_XEN_SHADOW_MODE */
 
-void mm_pin(struct mm_struct *mm)
+static inline void mm_walk_set_prot(void *pt, pgprot_t flags)
 {
-    pgd_t       *pgd;
-    struct page *page;
-    int          i;
+       struct page *page = virt_to_page(pt);
+       unsigned long pfn = page_to_pfn(page);
 
-    spin_lock(&mm->page_table_lock);
+       if (PageHighMem(page))
+               return;
+       HYPERVISOR_update_va_mapping(
+               (unsigned long)__va(pfn << PAGE_SHIFT),
+               pfn_pte(pfn, flags), 0);
+}
 
-    for ( i = 0, pgd = mm->pgd; i < USER_PTRS_PER_PGD; i++, pgd++ )
-    {
-        if ( *(unsigned long *)pgd == 0 )
-            continue;
-        page = pmd_page(*(pmd_t *)pgd);
-        if ( !PageHighMem(page) )
-            HYPERVISOR_update_va_mapping(
-                (unsigned long)__va(page_to_pfn(page)<<PAGE_SHIFT),
-                pfn_pte(page_to_pfn(page), PAGE_KERNEL_RO), 0);
-    }
+static void mm_walk(struct mm_struct *mm, pgprot_t flags)
+{
+       pgd_t       *pgd;
+       pud_t       *pud;
+       pmd_t       *pmd;
+       pte_t       *pte;
+       int          g,u,m;
 
+       pgd = mm->pgd;
+       for (g = 0; g < USER_PTRS_PER_PGD; g++, pgd++) {
+               if (pgd_none(*pgd))
+                       continue;
+               pud = pud_offset(pgd, 0);
+               if (PTRS_PER_PUD > 1) /* not folded */
+                       mm_walk_set_prot(pud,flags);
+               for (u = 0; u < PTRS_PER_PUD; u++, pud++) {
+                       if (pud_none(*pud))
+                               continue;
+                       pmd = pmd_offset(pud, 0);
+                       if (PTRS_PER_PMD > 1) /* not folded */
+                               mm_walk_set_prot(pmd,flags);
+                       for (m = 0; m < PTRS_PER_PMD; m++, pmd++) {
+                               if (pmd_none(*pmd))
+                                       continue;
+                               pte = pte_offset_kernel(pmd,0);
+                               mm_walk_set_prot(pte,flags);
+                       }
+               }
+       }
+}
+
+void mm_pin(struct mm_struct *mm)
+{
+    spin_lock(&mm->page_table_lock);
+
+    mm_walk(mm, PAGE_KERNEL_RO);
     HYPERVISOR_update_va_mapping(
         (unsigned long)mm->pgd,
         pfn_pte(virt_to_phys(mm->pgd)>>PAGE_SHIFT, PAGE_KERNEL_RO), 0);
     xen_pgd_pin(__pa(mm->pgd));
-
     mm->context.pinned = 1;
 
     spin_unlock(&mm->page_table_lock);
@@ -475,28 +491,13 @@ void mm_pin(struct mm_struct *mm)
 
 void mm_unpin(struct mm_struct *mm)
 {
-    pgd_t       *pgd;
-    struct page *page;
-    int          i;
-
     spin_lock(&mm->page_table_lock);
 
     xen_pgd_unpin(__pa(mm->pgd));
     HYPERVISOR_update_va_mapping(
         (unsigned long)mm->pgd,
         pfn_pte(virt_to_phys(mm->pgd)>>PAGE_SHIFT, PAGE_KERNEL), 0);
-
-    for ( i = 0, pgd = mm->pgd; i < USER_PTRS_PER_PGD; i++, pgd++ )
-    {
-        if ( *(unsigned long *)pgd == 0 )
-            continue;
-        page = pmd_page(*(pmd_t *)pgd);
-        if ( !PageHighMem(page) )
-            HYPERVISOR_update_va_mapping(
-                (unsigned long)__va(page_to_pfn(page)<<PAGE_SHIFT),
-                pfn_pte(page_to_pfn(page), PAGE_KERNEL), 0);
-    }
-
+    mm_walk(mm, PAGE_KERNEL);
     mm->context.pinned = 0;
 
     spin_unlock(&mm->page_table_lock);

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [patch] pgtable.c cleanups, Gerd Knorr <=