Skip to content

Commit

Permalink
kexec/i386: allocate page table pages dynamically
Browse files Browse the repository at this point in the history
Impact: save .text size when kexec is built in but not loaded

This patch adds an architecture specific struct kimage_arch into
struct kimage. The pointers to page table pages used by kexec are
added to struct kimage_arch. The page tables pages are dynamically
allocated in machine_kexec_prepare instead of statically from BSS
segment. This will save up to 20k memory when kexec image is not
loaded.

Signed-off-by: Huang Ying <ying.huang@intel.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Huang Ying authored and Ingo Molnar committed Oct 31, 2008
1 parent 31498a0 commit 92be3d6
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 21 deletions.
14 changes: 14 additions & 0 deletions arch/x86/include/asm/kexec.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,20 @@ relocate_kernel(unsigned long indirection_page,
unsigned long start_address) ATTRIB_NORET;
#endif

#ifdef CONFIG_X86_32
#define ARCH_HAS_KIMAGE_ARCH

struct kimage_arch {
pgd_t *pgd;
#ifdef CONFIG_X86_PAE
pmd_t *pmd0;
pmd_t *pmd1;
#endif
pte_t *pte0;
pte_t *pte1;
};
#endif

#endif /* __ASSEMBLY__ */

#endif /* _ASM_X86_KEXEC_H */
67 changes: 46 additions & 21 deletions arch/x86/kernel/machine_kexec_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <linux/numa.h>
#include <linux/ftrace.h>
#include <linux/suspend.h>
#include <linux/gfp.h>

#include <asm/pgtable.h>
#include <asm/pgalloc.h>
Expand All @@ -25,15 +26,6 @@
#include <asm/system.h>
#include <asm/cacheflush.h>

#define PAGE_ALIGNED __attribute__ ((__aligned__(PAGE_SIZE)))
static u32 kexec_pgd[1024] PAGE_ALIGNED;
#ifdef CONFIG_X86_PAE
static u32 kexec_pmd0[1024] PAGE_ALIGNED;
static u32 kexec_pmd1[1024] PAGE_ALIGNED;
#endif
static u32 kexec_pte0[1024] PAGE_ALIGNED;
static u32 kexec_pte1[1024] PAGE_ALIGNED;

static void set_idt(void *newidt, __u16 limit)
{
struct desc_ptr curidt;
Expand Down Expand Up @@ -76,6 +68,37 @@ static void load_segments(void)
#undef __STR
}

static void machine_kexec_free_page_tables(struct kimage *image)
{
free_page((unsigned long)image->arch.pgd);
#ifdef CONFIG_X86_PAE
free_page((unsigned long)image->arch.pmd0);
free_page((unsigned long)image->arch.pmd1);
#endif
free_page((unsigned long)image->arch.pte0);
free_page((unsigned long)image->arch.pte1);
}

static int machine_kexec_alloc_page_tables(struct kimage *image)
{
image->arch.pgd = (pgd_t *)get_zeroed_page(GFP_KERNEL);
#ifdef CONFIG_X86_PAE
image->arch.pmd0 = (pmd_t *)get_zeroed_page(GFP_KERNEL);
image->arch.pmd1 = (pmd_t *)get_zeroed_page(GFP_KERNEL);
#endif
image->arch.pte0 = (pte_t *)get_zeroed_page(GFP_KERNEL);
image->arch.pte1 = (pte_t *)get_zeroed_page(GFP_KERNEL);
if (!image->arch.pgd ||
#ifdef CONFIG_X86_PAE
!image->arch.pmd0 || !image->arch.pmd1 ||
#endif
!image->arch.pte0 || !image->arch.pte1) {
machine_kexec_free_page_tables(image);
return -ENOMEM;
}
return 0;
}

/*
* A architecture hook called to validate the
* proposed image and prepare the control pages
Expand All @@ -87,13 +110,14 @@ static void load_segments(void)
* reboot code buffer to allow us to avoid allocations
* later.
*
* Make control page executable.
* - Make control page executable.
* - Allocate page tables
*/
int machine_kexec_prepare(struct kimage *image)
{
if (nx_enabled)
set_pages_x(image->control_code_page, 1);
return 0;
return machine_kexec_alloc_page_tables(image);
}

/*
Expand All @@ -104,6 +128,7 @@ void machine_kexec_cleanup(struct kimage *image)
{
if (nx_enabled)
set_pages_nx(image->control_code_page, 1);
machine_kexec_free_page_tables(image);
}

/*
Expand Down Expand Up @@ -150,18 +175,18 @@ void machine_kexec(struct kimage *image)
relocate_kernel_ptr = control_page;
page_list[PA_CONTROL_PAGE] = __pa(control_page);
page_list[VA_CONTROL_PAGE] = (unsigned long)control_page;
page_list[PA_PGD] = __pa(kexec_pgd);
page_list[VA_PGD] = (unsigned long)kexec_pgd;
page_list[PA_PGD] = __pa(image->arch.pgd);
page_list[VA_PGD] = (unsigned long)image->arch.pgd;
#ifdef CONFIG_X86_PAE
page_list[PA_PMD_0] = __pa(kexec_pmd0);
page_list[VA_PMD_0] = (unsigned long)kexec_pmd0;
page_list[PA_PMD_1] = __pa(kexec_pmd1);
page_list[VA_PMD_1] = (unsigned long)kexec_pmd1;
page_list[PA_PMD_0] = __pa(image->arch.pmd0);
page_list[VA_PMD_0] = (unsigned long)image->arch.pmd0;
page_list[PA_PMD_1] = __pa(image->arch.pmd1);
page_list[VA_PMD_1] = (unsigned long)image->arch.pmd1;
#endif
page_list[PA_PTE_0] = __pa(kexec_pte0);
page_list[VA_PTE_0] = (unsigned long)kexec_pte0;
page_list[PA_PTE_1] = __pa(kexec_pte1);
page_list[VA_PTE_1] = (unsigned long)kexec_pte1;
page_list[PA_PTE_0] = __pa(image->arch.pte0);
page_list[VA_PTE_0] = (unsigned long)image->arch.pte0;
page_list[PA_PTE_1] = __pa(image->arch.pte1);
page_list[VA_PTE_1] = (unsigned long)image->arch.pte1;

if (image->type == KEXEC_TYPE_DEFAULT)
page_list[PA_SWAP_PAGE] = (page_to_pfn(image->swap_page)
Expand Down
4 changes: 4 additions & 0 deletions include/linux/kexec.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ struct kimage {
#define KEXEC_TYPE_DEFAULT 0
#define KEXEC_TYPE_CRASH 1
unsigned int preserve_context : 1;

#ifdef ARCH_HAS_KIMAGE_ARCH
struct kimage_arch arch;
#endif
};


Expand Down

0 comments on commit 92be3d6

Please sign in to comment.