Skip to contentSkip to conversation

x86/trampoline for 2.6.37

GIT PULL In review H. Peter Anvin 4 participants 6 messages Oct 23, 2010 – Oct 26, 2010

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

Hi Linus,

This is a set of changes which completes the already-begun work of replacing the zap_low_mappings() with a 1:1 set of page tables which are kept around permanently, and then used for things like the SMP trampoline, suspend to RAM, and reboot.

Part of it has already been integrated in 2.6.36, because it also worked around an AMD hardware erratum; this patch completes the cleanup.

-hpa

The following changes since commit b5153163ed580e00c67bdfecb02b2e3843817b3e:

Merge branch 'devel' of master.kernel.org:/home/rmk/linux-2.6-arm (2010-10-21 16:42:32 -0700)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip.git x86-trampoline-for-linus

Borislav Petkov (1):
x86-32, mm: Add an initial page table for core bootstrapping

H. Peter Anvin (2):
Merge branch 'x86/vmware' into x86/trampoline Merge branch 'x86/cleanups' into x86/trampoline

 arch/x86/include/asm/pgtable_32.h |    2 +-
 arch/x86/include/asm/tlbflush.h   |    2 -
 arch/x86/include/asm/trampoline.h |    3 --
 arch/x86/kernel/acpi/sleep.c      |    7 ++++-
 arch/x86/kernel/head32.c          |    1 +
 arch/x86/kernel/head_32.S         |   55 +++++++++++++++++--------------------
 arch/x86/kernel/reboot.c          |   10 +-----
 arch/x86/kernel/setup.c           |   18 +++++++++++-
 arch/x86/kernel/smpboot.c         |   16 +++--------
 arch/x86/kernel/trampoline.c      |   16 -----------
 arch/x86/mm/init_32.c             |   45 ------------------------------
 11 files changed, 56 insertions(+), 119 deletions(-)
arch/x86/include/asm/pgtable_32.h +1 -1
index f686f49..8abde9e 100644
@@ -26,7 +26,7 @@ struct mm_struct;
 struct vm_area_struct;
 
 extern pgd_t swapper_pg_dir[1024];
-extern pgd_t trampoline_pg_dir[1024];
+extern pgd_t initial_page_table[1024];
 
 static inline void pgtable_cache_init(void) { }
 static inline void check_pgt_cache(void) { }
arch/x86/include/asm/tlbflush.h +0 -2
index 7f3eba0..169be89 100644
@@ -172,6 +172,4 @@ static inline void flush_tlb_kernel_range(unsigned long start,
 	flush_tlb_all();
 }
 
-extern void zap_low_mappings(bool early);
-
 #endif /* _ASM_X86_TLBFLUSH_H */
arch/x86/include/asm/trampoline.h +0 -3
index 4dde797..f4500fb 100644
@@ -13,16 +13,13 @@ extern unsigned char *trampoline_base;
 
 extern unsigned long init_rsp;
 extern unsigned long initial_code;
-extern unsigned long initial_page_table;
 extern unsigned long initial_gs;
 
 #define TRAMPOLINE_SIZE roundup(trampoline_end - trampoline_data, PAGE_SIZE)
 
 extern unsigned long setup_trampoline(void);
-extern void __init setup_trampoline_page_table(void);
 extern void __init reserve_trampoline_memory(void);
 #else
-static inline void setup_trampoline_page_table(void) {}
 static inline void reserve_trampoline_memory(void) {}
 #endif /* CONFIG_X86_TRAMPOLINE */
 
arch/x86/kernel/acpi/sleep.c +6 -1
index 33cec15..b35e1ab 100644
@@ -12,6 +12,11 @@
 #include <asm/segment.h>
 #include <asm/desc.h>
 
+#ifdef CONFIG_X86_32
+#include <asm/pgtable.h>
+#include <asm/pgtable_32.h>
+#endif
+
 #include "realmode/wakeup.h"
 #include "sleep.h"
 
@@ -90,7 +95,7 @@ int acpi_save_state_mem(void)
 
 #ifndef CONFIG_64BIT
 	header->pmode_entry = (u32)&wakeup_pmode_return;
-	header->pmode_cr3 = (u32)(swsusp_pg_dir - __PAGE_OFFSET);
+	header->pmode_cr3 = (u32)__pa(&initial_page_table);
 	saved_magic = 0x12345678;
 #else /* CONFIG_64BIT */
 	header->trampoline_segment = setup_trampoline() >> 4;
arch/x86/kernel/head32.c +1 -0
index 784360c..8b9c201 100644
@@ -17,6 +17,7 @@
 #include <asm/apic.h>
 #include <asm/io_apic.h>
 #include <asm/bios_ebda.h>
+#include <asm/tlbflush.h>
 
 static void __init i386_default_early_setup(void)
 {
arch/x86/kernel/head_32.S +25 -30

122 lines not on this page · raw message

arch/x86/kernel/reboot.c +2 -8
index 7a4cf14..f7f53dc 100644
@@ -371,16 +371,10 @@ void machine_real_restart(const unsigned char *code, int length)
 	CMOS_WRITE(0x00, 0x8f);
 	spin_unlock(&rtc_lock);
 
-	/* Remap the kernel at virtual address zero, as well as offset zero
-	   from the kernel segment.  This assumes the kernel segment starts at
-	   virtual address PAGE_OFFSET. */
-	memcpy(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
-		sizeof(swapper_pg_dir [0]) * KERNEL_PGD_PTRS);
-
 	/*
-	 * Use `swapper_pg_dir' as our page directory.
+	 * Switch back to the initial page table.
 	 */
-	load_cr3(swapper_pg_dir);
+	load_cr3(initial_page_table);
 
 	/* Write 0x1234 to absolute memory location 0x472.  The BIOS reads
 	   this on booting to tell it to "Bypass memory test (also warm
arch/x86/kernel/setup.c +17 -1
index 322b24f..af6cf2b 100644
@@ -728,6 +728,17 @@ void __init setup_arch(char **cmdline_p)
 #ifdef CONFIG_X86_32
 	memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
 	visws_early_detect();
+
+	/*
+	 * copy kernel address range established so far and switch
+	 * to the proper swapper page table
+	 */
+	clone_pgd_range(swapper_pg_dir     + KERNEL_PGD_BOUNDARY,
+			initial_page_table + KERNEL_PGD_BOUNDARY,
+			KERNEL_PGD_PTRS);
+
+	load_cr3(swapper_pg_dir);
+	__flush_tlb_all();
 #else
 	printk(KERN_INFO "Command line: %s\n", boot_command_line);
 #endif
@@ -1009,7 +1020,12 @@ void __init setup_arch(char **cmdline_p)
 	paging_init();
 	x86_init.paging.pagetable_setup_done(swapper_pg_dir);
 
-	setup_trampoline_page_table();
+#ifdef CONFIG_X86_32
+	/* sync back kernel address range */
+	clone_pgd_range(initial_page_table + KERNEL_PGD_BOUNDARY,
+			swapper_pg_dir     + KERNEL_PGD_BOUNDARY,
+			KERNEL_PGD_PTRS);
+#endif
 
 	tboot_probe();
 
arch/x86/kernel/smpboot.c +4 -12
index 63a1a55..e63bb51 100644
@@ -298,22 +298,16 @@ notrace static void __cpuinit start_secondary(void *unused)
 	 * fragile that we want to limit the things done here to the
 	 * most necessary things.
 	 */
+	cpu_init();
+	preempt_disable();
+	smp_callin();
 
 #ifdef CONFIG_X86_32
-	/*
-	 * Switch away from the trampoline page-table
-	 *
-	 * Do this before cpu_init() because it needs to access per-cpu
-	 * data which may not be mapped in the trampoline page-table.
-	 */
+	/* switch away from the initial page table */
 	load_cr3(swapper_pg_dir);
 	__flush_tlb_all();
 #endif
 
-	cpu_init();
-	preempt_disable();
-	smp_callin();
-
 	/* otherwise gcc will move up smp_processor_id before the cpu_init */
 	barrier();
 	/*
@@ -772,7 +766,6 @@ do_rest:
 #ifdef CONFIG_X86_32
 	/* Stack for startup_32 can be just as for start_secondary onwards */
 	irq_ctx_init(cpu);
-	initial_page_table = __pa(&trampoline_pg_dir);
 #else
 	clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
 	initial_gs = per_cpu_offset(cpu);
@@ -921,7 +914,6 @@ int __cpuinit native_cpu_up(unsigned int cpu)
 	per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
 
 	err = do_boot_cpu(apicid, cpu);
-
 	if (err) {
 		pr_debug("do_boot_cpu failed %d\n", err);
 		return -EIO;
arch/x86/kernel/trampoline.c +0 -16
index e2a5952..f1488a3 100644
@@ -38,19 +38,3 @@ unsigned long __trampinit setup_trampoline(void)
 	memcpy(trampoline_base, trampoline_data, TRAMPOLINE_SIZE);
 	return virt_to_phys(trampoline_base);
 }
-
-void __init setup_trampoline_page_table(void)
-{
-#ifdef CONFIG_X86_32
-	/* Copy kernel address range */
-	clone_pgd_range(trampoline_pg_dir + KERNEL_PGD_BOUNDARY,
-			swapper_pg_dir + KERNEL_PGD_BOUNDARY,
-			KERNEL_PGD_PTRS);
-
-	/* Initialize low mappings */
-	clone_pgd_range(trampoline_pg_dir,
-			swapper_pg_dir + KERNEL_PGD_BOUNDARY,
-			min_t(unsigned long, KERNEL_PGD_PTRS,
-			      KERNEL_PGD_BOUNDARY));
-#endif
-}
arch/x86/mm/init_32.c +0 -45

57 lines not on this page · raw message

#1 lore raw

Hello,

Quoted 11 lines · H. Peter Anvin

Borislav Petkov (1):
     x86-32, mm: Add an initial page table for core bootstrapping

H. Peter Anvin (2):
     Merge branch 'x86/vmware' into x86/trampoline Merge branch 'x86/cleanups' into x86/trampoline

arch/x86/kernel/acpi/sleep.c line 19

Quoted 8 lines
arch/x86/kernel/acpi/sleep.c +5 -0
@@ -12,6 +12,11 @@
  #include <asm/segment.h>
  #include <asm/desc.h>
 
+#ifdef CONFIG_X86_32
+#include <asm/pgtable.h>
+#include <asm/pgtable_32.h>
+#endif
+

pgtable.h will take care of pgtable_32.h, why you are doing this ?

Thanks,
--
Jaswinder Singh.

maintainer
#2 lore raw
Quoted 7 lines · Jaswinder Singh Rajput

Review

Quoted 5 lines
(quoted diff) +5 -0
+#ifdef CONFIG_X86_32
+#include <asm/pgtable.h>
+#include <asm/pgtable_32.h>
+#endif
+

pgtable.h will take care of pgtable_32.h, why you are doing this ?

Frankly, I don't remember. Here's an updated patch.

Linus, you could apply the following one instead of pulling from the branch, if hpa is ok with it. It is against your tree of the moment v2.6.36-1431-gf5d9d24.

--
From: Borislav Petkov <[email protected]>
Date: Sat, 28 Aug 2010 15:58:33 +0200
Subject: [PATCH] x86-32, mm: Add an initial page table for core bootstrapping

This patch adds an initial page table with low mappings used exclusively for booting APs/resuming after ACPI suspend/machine restart. After this, there's no need to add low mappings to swapper_pg_dir and zap them later or create own swsusp PGD page solely for ACPI sleep needs - we have initial_page_table for that.

[ v1.1 Fix suspend-to-ram ]
[ v1.2 Remove duplicated include ]

---
 arch/x86/include/asm/pgtable_32.h |    2 +-
 arch/x86/include/asm/tlbflush.h   |    2 -
 arch/x86/include/asm/trampoline.h |    3 --
 arch/x86/kernel/acpi/sleep.c      |    6 +++-
 arch/x86/kernel/head32.c          |    1 +
 arch/x86/kernel/head_32.S         |   55 +++++++++++++++++--------------------
 arch/x86/kernel/reboot.c          |   10 +-----
 arch/x86/kernel/setup.c           |   18 +++++++++++-
 arch/x86/kernel/smpboot.c         |   16 +++--------
 arch/x86/kernel/trampoline.c      |   16 -----------
 arch/x86/mm/init_32.c             |   45 ------------------------------
 11 files changed, 55 insertions(+), 119 deletions(-)
arch/x86/include/asm/pgtable_32.h +1 -1
index f686f49..8abde9e 100644
@@ -26,7 +26,7 @@ struct mm_struct;
 struct vm_area_struct;
 
 extern pgd_t swapper_pg_dir[1024];
-extern pgd_t trampoline_pg_dir[1024];
+extern pgd_t initial_page_table[1024];
 
 static inline void pgtable_cache_init(void) { }
 static inline void check_pgt_cache(void) { }
arch/x86/include/asm/tlbflush.h +0 -2
index 7f3eba0..169be89 100644
@@ -172,6 +172,4 @@ static inline void flush_tlb_kernel_range(unsigned long start,
 	flush_tlb_all();
 }
 
-extern void zap_low_mappings(bool early);
-
 #endif /* _ASM_X86_TLBFLUSH_H */
arch/x86/include/asm/trampoline.h +0 -3
index 4dde797..f4500fb 100644
@@ -13,16 +13,13 @@ extern unsigned char *trampoline_base;
 
 extern unsigned long init_rsp;
 extern unsigned long initial_code;
-extern unsigned long initial_page_table;
 extern unsigned long initial_gs;
 
 #define TRAMPOLINE_SIZE roundup(trampoline_end - trampoline_data, PAGE_SIZE)
 
 extern unsigned long setup_trampoline(void);
-extern void __init setup_trampoline_page_table(void);
 extern void __init reserve_trampoline_memory(void);
 #else
-static inline void setup_trampoline_page_table(void) {}
 static inline void reserve_trampoline_memory(void) {}
 #endif /* CONFIG_X86_TRAMPOLINE */
 
arch/x86/kernel/acpi/sleep.c +5 -1
index e125207..69fd72a 100644
@@ -13,6 +13,10 @@
 #include <asm/segment.h>
 #include <asm/desc.h>
 
+#ifdef CONFIG_X86_32
+#include <asm/pgtable.h>
+#endif
+
 #include "realmode/wakeup.h"
 #include "sleep.h"
 
@@ -91,7 +95,7 @@ int acpi_save_state_mem(void)
 
 #ifndef CONFIG_64BIT
 	header->pmode_entry = (u32)&wakeup_pmode_return;
-	header->pmode_cr3 = (u32)(swsusp_pg_dir - __PAGE_OFFSET);
+	header->pmode_cr3 = (u32)__pa(&initial_page_table);
 	saved_magic = 0x12345678;
 #else /* CONFIG_64BIT */
 	header->trampoline_segment = setup_trampoline() >> 4;
arch/x86/kernel/head32.c +1 -0
index 9a6ca23..7633101 100644
@@ -18,6 +18,7 @@
 #include <asm/apic.h>
 #include <asm/io_apic.h>
 #include <asm/bios_ebda.h>
+#include <asm/tlbflush.h>
 
 static void __init i386_default_early_setup(void)
 {
arch/x86/kernel/head_32.S +25 -30

122 lines not on this page · raw message

arch/x86/kernel/reboot.c +2 -8
index 7a4cf14..f7f53dc 100644
@@ -371,16 +371,10 @@ void machine_real_restart(const unsigned char *code, int length)
 	CMOS_WRITE(0x00, 0x8f);
 	spin_unlock(&rtc_lock);
 
-	/* Remap the kernel at virtual address zero, as well as offset zero
-	   from the kernel segment.  This assumes the kernel segment starts at
-	   virtual address PAGE_OFFSET. */
-	memcpy(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
-		sizeof(swapper_pg_dir [0]) * KERNEL_PGD_PTRS);
-
 	/*
-	 * Use `swapper_pg_dir' as our page directory.
+	 * Switch back to the initial page table.
 	 */
-	load_cr3(swapper_pg_dir);
+	load_cr3(initial_page_table);
 
 	/* Write 0x1234 to absolute memory location 0x472.  The BIOS reads
 	   this on booting to tell it to "Bypass memory test (also warm
arch/x86/kernel/setup.c +17 -1
index 420e641..95a3274 100644
@@ -700,6 +700,17 @@ void __init setup_arch(char **cmdline_p)
 #ifdef CONFIG_X86_32
 	memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
 	visws_early_detect();
+
+	/*
+	 * copy kernel address range established so far and switch
+	 * to the proper swapper page table
+	 */
+	clone_pgd_range(swapper_pg_dir     + KERNEL_PGD_BOUNDARY,
+			initial_page_table + KERNEL_PGD_BOUNDARY,
+			KERNEL_PGD_PTRS);
+
+	load_cr3(swapper_pg_dir);
+	__flush_tlb_all();
 #else
 	printk(KERN_INFO "Command line: %s\n", boot_command_line);
 #endif
@@ -985,7 +996,12 @@ void __init setup_arch(char **cmdline_p)
 	paging_init();
 	x86_init.paging.pagetable_setup_done(swapper_pg_dir);
 
-	setup_trampoline_page_table();
+#ifdef CONFIG_X86_32
+	/* sync back kernel address range */
+	clone_pgd_range(initial_page_table + KERNEL_PGD_BOUNDARY,
+			swapper_pg_dir     + KERNEL_PGD_BOUNDARY,
+			KERNEL_PGD_PTRS);
+#endif
 
 	tboot_probe();
 
arch/x86/kernel/smpboot.c +4 -12
index dfb5089..6af1185 100644
@@ -299,22 +299,16 @@ notrace static void __cpuinit start_secondary(void *unused)
 	 * fragile that we want to limit the things done here to the
 	 * most necessary things.
 	 */
+	cpu_init();
+	preempt_disable();
+	smp_callin();
 
 #ifdef CONFIG_X86_32
-	/*
-	 * Switch away from the trampoline page-table
-	 *
-	 * Do this before cpu_init() because it needs to access per-cpu
-	 * data which may not be mapped in the trampoline page-table.
-	 */
+	/* switch away from the initial page table */
 	load_cr3(swapper_pg_dir);
 	__flush_tlb_all();
 #endif
 
-	cpu_init();
-	preempt_disable();
-	smp_callin();
-
 	/* otherwise gcc will move up smp_processor_id before the cpu_init */
 	barrier();
 	/*
@@ -785,7 +779,6 @@ do_rest:
 #ifdef CONFIG_X86_32
 	/* Stack for startup_32 can be just as for start_secondary onwards */
 	irq_ctx_init(cpu);
-	initial_page_table = __pa(&trampoline_pg_dir);
 #else
 	clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
 	initial_gs = per_cpu_offset(cpu);
@@ -934,7 +927,6 @@ int __cpuinit native_cpu_up(unsigned int cpu)
 	per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
 
 	err = do_boot_cpu(apicid, cpu);
-
 	if (err) {
 		pr_debug("do_boot_cpu failed %d\n", err);
 		return -EIO;
arch/x86/kernel/trampoline.c +0 -16
index 4c3da56..a375616 100644
@@ -38,19 +38,3 @@ unsigned long __trampinit setup_trampoline(void)
 	memcpy(trampoline_base, trampoline_data, TRAMPOLINE_SIZE);
 	return virt_to_phys(trampoline_base);
 }
-
-void __init setup_trampoline_page_table(void)
-{
-#ifdef CONFIG_X86_32
-	/* Copy kernel address range */
-	clone_pgd_range(trampoline_pg_dir + KERNEL_PGD_BOUNDARY,
-			swapper_pg_dir + KERNEL_PGD_BOUNDARY,
-			KERNEL_PGD_PTRS);
-
-	/* Initialize low mappings */
-	clone_pgd_range(trampoline_pg_dir,
-			swapper_pg_dir + KERNEL_PGD_BOUNDARY,
-			min_t(unsigned long, KERNEL_PGD_PTRS,
-			      KERNEL_PGD_BOUNDARY));
-#endif
-}
arch/x86/mm/init_32.c +0 -45

57 lines not on this page · raw message

Signature · 5 lines
1.7.2.3

-- 
Regards/Gruss,
    Boris.
#3 lore raw
Quoted 9 lines · Borislav Petkov
Quoted 7 lines · Jaswinder Singh Rajput

arch/x86/kernel/acpi/sleep.c line 19

Quoted 5 lines
arch/x86/kernel/acpi/sleep.c +5 -0
+#ifdef CONFIG_X86_32
+#include <asm/pgtable.h>
+#include <asm/pgtable_32.h>
+#endif
+

pgtable.h will take care of pgtable_32.h, why you are doing this ?

Quoted 4 lines

Frankly, I don't remember. Here's an updated patch.

Linus, you could apply the following one instead of pulling from the branch, if hpa is ok with it. It is against your tree of the moment v2.6.36-1431-gf5d9d24.

Please send a delta patch and we can do any trivial changes via the usual channels. The tree hpa sent to Linus is tested and this is tricky code.

Thanks,

Ingo

maintainer
#4 lore raw

PATCH 1/1 x86-32, mm: Remove duplicated include

Quoted 3 lines · Ingo Molnar

Please send a delta patch and we can do any trivial changes via the usual channels. The tree hpa sent to Linus is tested and this is tricky code.

Ok, here it is, 32-bit randconfig tested for a day.

--
From: Borislav Petkov <[email protected]>
Date: Mon, 25 Oct 2010 18:15:22 +0200
Subject: [PATCH] x86-32, mm: Remove duplicated include

b40827fa7268fda8a62490728a61c2856f33830b added an include directive which is needless and is taken care of by a previous one. Remove it.

---
 arch/x86/kernel/acpi/sleep.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
arch/x86/kernel/acpi/sleep.c +0 -1
index 74a8478..69fd72a 100644
@@ -15,7 +15,6 @@
 
 #ifdef CONFIG_X86_32
 #include <asm/pgtable.h>
-#include <asm/pgtable_32.h>
 #endif
 
 #include "realmode/wakeup.h"
Signature · 6 lines
1.7.1


-- 
Regards/Gruss,
Boris.
#5 lore raw

[tip:x86/urgent] x86-32, mm: Remove duplicated #include

Commit-ID:  610470ce804f0326ca63fbcdc5be06b750debeb1
Gitweb:     http://git.kernel.org/tip/610470ce804f0326ca63fbcdc5be06b750debeb1
Author:     Borislav Petkov <[email protected]>
AuthorDate: Mon, 25 Oct 2010 18:25:23 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 25 Oct 2010 19:39:33 +0200

x86-32, mm: Remove duplicated #include

b40827fa7268fda8a62490728a61c2856f33830b added an include directive which is needless and is taken care of by a previous one. Remove it.

Cc Linus Torvalds <[email protected]>
Cc Jaswinder Singh Rajput <[email protected]>
Cc H. Peter Anvin <[email protected]>

LKML-Reference: <[email protected]>

---
 arch/x86/kernel/acpi/sleep.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
arch/x86/kernel/acpi/sleep.c +0 -1
index 74a8478..69fd72a 100644
@@ -15,7 +15,6 @@
 
 #ifdef CONFIG_X86_32
 #include <asm/pgtable.h>
-#include <asm/pgtable_32.h>
 #endif
 
 #include "realmode/wakeup.h"