Re: [PATCH -mm 2/2 -v2] kexec/i386: kexec page table code clean up - page table setup in C

2008-01-18 Thread Simon Horman
On Tue, Jan 15, 2008 at 02:05:49PM +0800, Huang, Ying wrote:
> This patch transforms the kexec page tables setup code from assembler
> code to C code in machine_kexec_prepare. This improves readability and
> reduces code line number.

This looks good to me.

Simon Horman <[EMAIL PROTECTED]>

> Signed-off-by: Huang Ying <[EMAIL PROTECTED]>

-- 
Horms

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


Re: [PATCH -mm 2/2 -v2] kexec/i386: kexec page table code clean up - page table setup in C

2008-01-18 Thread Simon Horman
On Tue, Jan 15, 2008 at 02:05:49PM +0800, Huang, Ying wrote:
 This patch transforms the kexec page tables setup code from assembler
 code to C code in machine_kexec_prepare. This improves readability and
 reduces code line number.

This looks good to me.

Simon Horman [EMAIL PROTECTED]

 Signed-off-by: Huang Ying [EMAIL PROTECTED]

-- 
Horms

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


Re: [PATCH -mm 2/2 -v2] kexec/i386: kexec page table code clean up - page table setup in C

2008-01-15 Thread Vivek Goyal
On Tue, Jan 15, 2008 at 02:05:49PM +0800, Huang, Ying wrote:
> This patch transforms the kexec page tables setup code from assembler
> code to C code in machine_kexec_prepare. This improves readability and
> reduces code line number.
> 
> Signed-off-by: Huang Ying <[EMAIL PROTECTED]>
> 

Looks good to me.

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


Re: [PATCH -mm 2/2 -v2] kexec/i386: kexec page table code clean up - page table setup in C

2008-01-15 Thread Vivek Goyal
On Tue, Jan 15, 2008 at 02:05:49PM +0800, Huang, Ying wrote:
 This patch transforms the kexec page tables setup code from assembler
 code to C code in machine_kexec_prepare. This improves readability and
 reduces code line number.
 
 Signed-off-by: Huang Ying [EMAIL PROTECTED]
 

Looks good to me.

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


[PATCH -mm 2/2 -v2] kexec/i386: kexec page table code clean up - page table setup in C

2008-01-14 Thread Huang, Ying
This patch transforms the kexec page tables setup code from assembler
code to C code in machine_kexec_prepare. This improves readability and
reduces code line number.

Signed-off-by: Huang Ying <[EMAIL PROTECTED]>

---
 arch/x86/kernel/machine_kexec_32.c   |   59 ++
 arch/x86/kernel/relocate_kernel_32.S |  114 ---
 include/asm-x86/kexec_32.h   |   18 -
 3 files changed, 48 insertions(+), 143 deletions(-)

--- a/arch/x86/kernel/machine_kexec_32.c
+++ b/arch/x86/kernel/machine_kexec_32.c
@@ -97,6 +97,45 @@ static int machine_kexec_alloc_page_tabl
return 0;
 }
 
+static void machine_kexec_page_table_set_one(
+   pgd_t *pgd, pmd_t *pmd, pte_t *pte,
+   unsigned long vaddr, unsigned long paddr)
+{
+   pud_t *pud;
+
+   pgd += pgd_index(vaddr);
+#ifdef CONFIG_X86_PAE
+   if (!(pgd_val(*pgd) & _PAGE_PRESENT))
+   set_pgd(pgd, __pgd(__pa(pmd) | _PAGE_PRESENT));
+#endif
+   pud = pud_offset(pgd, vaddr);
+   pmd = pmd_offset(pud, vaddr);
+   if (!(pmd_val(*pmd) & _PAGE_PRESENT))
+   set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
+   pte = pte_offset_kernel(pmd, vaddr);
+   set_pte(pte, pfn_pte(paddr >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
+}
+
+static void machine_kexec_prepare_page_tables(struct kimage *image)
+{
+   void *control_page;
+   pmd_t *pmd = 0;
+
+   control_page = page_address(image->control_code_page);
+#ifdef CONFIG_X86_PAE
+   pmd = image->arch_kimage.pmd0;
+#endif
+   machine_kexec_page_table_set_one(
+   image->arch_kimage.pgd, pmd, image->arch_kimage.pte0,
+   (unsigned long)relocate_kernel, __pa(control_page));
+#ifdef CONFIG_X86_PAE
+   pmd = image->arch_kimage.pmd1;
+#endif
+   machine_kexec_page_table_set_one(
+   image->arch_kimage.pgd, pmd, image->arch_kimage.pte1,
+   __pa(control_page), __pa(control_page));
+}
+
 /*
  * A architecture hook called to validate the
  * proposed image and prepare the control pages
@@ -109,10 +148,16 @@ static int machine_kexec_alloc_page_tabl
  * later.
  *
  * - Allocate page tables
+ * - Setup page tables
  */
 int machine_kexec_prepare(struct kimage *image)
 {
-   return machine_kexec_alloc_page_tables(image);
+   int error;
+   error = machine_kexec_alloc_page_tables(image);
+   if (error)
+   return error;
+   machine_kexec_prepare_page_tables(image);
+   return 0;
 }
 
 /*
@@ -140,19 +185,7 @@ NORET_TYPE void machine_kexec(struct kim
memcpy(control_page, relocate_kernel, PAGE_SIZE);
 
page_list[PA_CONTROL_PAGE] = __pa(control_page);
-   page_list[VA_CONTROL_PAGE] = (unsigned long)relocate_kernel;
page_list[PA_PGD] = __pa(image->arch_kimage.pgd);
-   page_list[VA_PGD] = (unsigned long)image->arch_kimage.pgd;
-#ifdef CONFIG_X86_PAE
-   page_list[PA_PMD_0] = __pa(image->arch_kimage.pmd0);
-   page_list[VA_PMD_0] = (unsigned long)image->arch_kimage.pmd0;
-   page_list[PA_PMD_1] = __pa(image->arch_kimage.pmd1);
-   page_list[VA_PMD_1] = (unsigned long)image->arch_kimage.pmd1;
-#endif
-   page_list[PA_PTE_0] = __pa(image->arch_kimage.pte0);
-   page_list[VA_PTE_0] = (unsigned long)image->arch_kimage.pte0;
-   page_list[PA_PTE_1] = __pa(image->arch_kimage.pte1);
-   page_list[VA_PTE_1] = (unsigned long)image->arch_kimage.pte1;
 
/* The segment registers are funny things, they have both a
 * visible and an invisible part.  Whenever the visible part is
--- a/arch/x86/kernel/relocate_kernel_32.S
+++ b/arch/x86/kernel/relocate_kernel_32.S
@@ -16,126 +16,12 @@
 
 #define PTR(x) (x << 2)
 #define PAGE_ALIGNED (1 << PAGE_SHIFT)
-#define PAGE_ATTR 0x63 /* _PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY */
-#define PAE_PGD_ATTR 0x01 /* _PAGE_PRESENT */
 
.text
.align PAGE_ALIGNED
.globl relocate_kernel
 relocate_kernel:
movl8(%esp), %ebp /* list of pages */
-
-#ifdef CONFIG_X86_PAE
-   /* map the control page at its virtual address */
-
-   movlPTR(VA_PGD)(%ebp), %edi
-   movlPTR(VA_CONTROL_PAGE)(%ebp), %eax
-   andl$0xc000, %eax
-   shrl$27, %eax
-   addl%edi, %eax
-
-   movlPTR(PA_PMD_0)(%ebp), %edx
-   orl $PAE_PGD_ATTR, %edx
-   movl%edx, (%eax)
-
-   movlPTR(VA_PMD_0)(%ebp), %edi
-   movlPTR(VA_CONTROL_PAGE)(%ebp), %eax
-   andl$0x3fe0, %eax
-   shrl$18, %eax
-   addl%edi, %eax
-
-   movlPTR(PA_PTE_0)(%ebp), %edx
-   orl $PAGE_ATTR, %edx
-   movl%edx, (%eax)
-
-   movlPTR(VA_PTE_0)(%ebp), %edi
-   movlPTR(VA_CONTROL_PAGE)(%ebp), %eax
-   andl$0x001ff000, %eax
-   shrl$9, %eax
-   addl%edi, %eax
-
-   movlPTR(PA_CONTROL_PAGE)(%ebp), %edx
-   orl $PAGE_ATTR, %edx
-   movl%edx, (%eax)
-
-   /* identity map the 

[PATCH -mm 2/2 -v2] kexec/i386: kexec page table code clean up - page table setup in C

2008-01-14 Thread Huang, Ying
This patch transforms the kexec page tables setup code from assembler
code to C code in machine_kexec_prepare. This improves readability and
reduces code line number.

Signed-off-by: Huang Ying [EMAIL PROTECTED]

---
 arch/x86/kernel/machine_kexec_32.c   |   59 ++
 arch/x86/kernel/relocate_kernel_32.S |  114 ---
 include/asm-x86/kexec_32.h   |   18 -
 3 files changed, 48 insertions(+), 143 deletions(-)

--- a/arch/x86/kernel/machine_kexec_32.c
+++ b/arch/x86/kernel/machine_kexec_32.c
@@ -97,6 +97,45 @@ static int machine_kexec_alloc_page_tabl
return 0;
 }
 
+static void machine_kexec_page_table_set_one(
+   pgd_t *pgd, pmd_t *pmd, pte_t *pte,
+   unsigned long vaddr, unsigned long paddr)
+{
+   pud_t *pud;
+
+   pgd += pgd_index(vaddr);
+#ifdef CONFIG_X86_PAE
+   if (!(pgd_val(*pgd)  _PAGE_PRESENT))
+   set_pgd(pgd, __pgd(__pa(pmd) | _PAGE_PRESENT));
+#endif
+   pud = pud_offset(pgd, vaddr);
+   pmd = pmd_offset(pud, vaddr);
+   if (!(pmd_val(*pmd)  _PAGE_PRESENT))
+   set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
+   pte = pte_offset_kernel(pmd, vaddr);
+   set_pte(pte, pfn_pte(paddr  PAGE_SHIFT, PAGE_KERNEL_EXEC));
+}
+
+static void machine_kexec_prepare_page_tables(struct kimage *image)
+{
+   void *control_page;
+   pmd_t *pmd = 0;
+
+   control_page = page_address(image-control_code_page);
+#ifdef CONFIG_X86_PAE
+   pmd = image-arch_kimage.pmd0;
+#endif
+   machine_kexec_page_table_set_one(
+   image-arch_kimage.pgd, pmd, image-arch_kimage.pte0,
+   (unsigned long)relocate_kernel, __pa(control_page));
+#ifdef CONFIG_X86_PAE
+   pmd = image-arch_kimage.pmd1;
+#endif
+   machine_kexec_page_table_set_one(
+   image-arch_kimage.pgd, pmd, image-arch_kimage.pte1,
+   __pa(control_page), __pa(control_page));
+}
+
 /*
  * A architecture hook called to validate the
  * proposed image and prepare the control pages
@@ -109,10 +148,16 @@ static int machine_kexec_alloc_page_tabl
  * later.
  *
  * - Allocate page tables
+ * - Setup page tables
  */
 int machine_kexec_prepare(struct kimage *image)
 {
-   return machine_kexec_alloc_page_tables(image);
+   int error;
+   error = machine_kexec_alloc_page_tables(image);
+   if (error)
+   return error;
+   machine_kexec_prepare_page_tables(image);
+   return 0;
 }
 
 /*
@@ -140,19 +185,7 @@ NORET_TYPE void machine_kexec(struct kim
memcpy(control_page, relocate_kernel, PAGE_SIZE);
 
page_list[PA_CONTROL_PAGE] = __pa(control_page);
-   page_list[VA_CONTROL_PAGE] = (unsigned long)relocate_kernel;
page_list[PA_PGD] = __pa(image-arch_kimage.pgd);
-   page_list[VA_PGD] = (unsigned long)image-arch_kimage.pgd;
-#ifdef CONFIG_X86_PAE
-   page_list[PA_PMD_0] = __pa(image-arch_kimage.pmd0);
-   page_list[VA_PMD_0] = (unsigned long)image-arch_kimage.pmd0;
-   page_list[PA_PMD_1] = __pa(image-arch_kimage.pmd1);
-   page_list[VA_PMD_1] = (unsigned long)image-arch_kimage.pmd1;
-#endif
-   page_list[PA_PTE_0] = __pa(image-arch_kimage.pte0);
-   page_list[VA_PTE_0] = (unsigned long)image-arch_kimage.pte0;
-   page_list[PA_PTE_1] = __pa(image-arch_kimage.pte1);
-   page_list[VA_PTE_1] = (unsigned long)image-arch_kimage.pte1;
 
/* The segment registers are funny things, they have both a
 * visible and an invisible part.  Whenever the visible part is
--- a/arch/x86/kernel/relocate_kernel_32.S
+++ b/arch/x86/kernel/relocate_kernel_32.S
@@ -16,126 +16,12 @@
 
 #define PTR(x) (x  2)
 #define PAGE_ALIGNED (1  PAGE_SHIFT)
-#define PAGE_ATTR 0x63 /* _PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY */
-#define PAE_PGD_ATTR 0x01 /* _PAGE_PRESENT */
 
.text
.align PAGE_ALIGNED
.globl relocate_kernel
 relocate_kernel:
movl8(%esp), %ebp /* list of pages */
-
-#ifdef CONFIG_X86_PAE
-   /* map the control page at its virtual address */
-
-   movlPTR(VA_PGD)(%ebp), %edi
-   movlPTR(VA_CONTROL_PAGE)(%ebp), %eax
-   andl$0xc000, %eax
-   shrl$27, %eax
-   addl%edi, %eax
-
-   movlPTR(PA_PMD_0)(%ebp), %edx
-   orl $PAE_PGD_ATTR, %edx
-   movl%edx, (%eax)
-
-   movlPTR(VA_PMD_0)(%ebp), %edi
-   movlPTR(VA_CONTROL_PAGE)(%ebp), %eax
-   andl$0x3fe0, %eax
-   shrl$18, %eax
-   addl%edi, %eax
-
-   movlPTR(PA_PTE_0)(%ebp), %edx
-   orl $PAGE_ATTR, %edx
-   movl%edx, (%eax)
-
-   movlPTR(VA_PTE_0)(%ebp), %edi
-   movlPTR(VA_CONTROL_PAGE)(%ebp), %eax
-   andl$0x001ff000, %eax
-   shrl$9, %eax
-   addl%edi, %eax
-
-   movlPTR(PA_CONTROL_PAGE)(%ebp), %edx
-   orl $PAGE_ATTR, %edx
-   movl%edx, (%eax)
-
-   /* identity map the control page at its physical