diff options
Diffstat (limited to 'arch/x86/power')
| -rw-r--r-- | arch/x86/power/cpu.c | 126 | ||||
| -rw-r--r-- | arch/x86/power/hibernate_32.c | 3 | ||||
| -rw-r--r-- | arch/x86/power/hibernate_64.c | 78 | ||||
| -rw-r--r-- | arch/x86/power/hibernate_asm_32.S | 4 | ||||
| -rw-r--r-- | arch/x86/power/hibernate_asm_64.S | 3 | 
5 files changed, 144 insertions, 70 deletions
diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c index 87bb35e34ef..424f4c97a44 100644 --- a/arch/x86/power/cpu.c +++ b/arch/x86/power/cpu.c @@ -9,7 +9,9 @@   */  #include <linux/suspend.h> +#include <linux/export.h>  #include <linux/smp.h> +#include <linux/perf_event.h>  #include <asm/pgtable.h>  #include <asm/proto.h> @@ -19,18 +21,16 @@  #include <asm/xcr.h>  #include <asm/suspend.h>  #include <asm/debugreg.h> +#include <asm/fpu-internal.h> /* pcntxt_mask */ +#include <asm/cpu.h>  #ifdef CONFIG_X86_32 -static struct saved_context saved_context; - -unsigned long saved_context_ebx; -unsigned long saved_context_esp, saved_context_ebp; -unsigned long saved_context_esi, saved_context_edi; -unsigned long saved_context_eflags; -#else -/* CONFIG_X86_64 */ -struct saved_context saved_context; +__visible unsigned long saved_context_ebx; +__visible unsigned long saved_context_esp, saved_context_ebp; +__visible unsigned long saved_context_esi, saved_context_edi; +__visible unsigned long saved_context_eflags;  #endif +struct saved_context saved_context;  /**   *	__save_processor_state - save CPU registers before creating a @@ -58,13 +58,20 @@ static void __save_processor_state(struct saved_context *ctxt)  	 * descriptor tables  	 */  #ifdef CONFIG_X86_32 -	store_gdt(&ctxt->gdt);  	store_idt(&ctxt->idt);  #else  /* CONFIG_X86_64 */ -	store_gdt((struct desc_ptr *)&ctxt->gdt_limit);  	store_idt((struct desc_ptr *)&ctxt->idt_limit);  #endif +	/* +	 * We save it here, but restore it only in the hibernate case. +	 * For ACPI S3 resume, this is loaded via 'early_gdt_desc' in 64-bit +	 * mode in "secondary_startup_64". In 32-bit mode it is done via +	 * 'pmode_gdt' in wakeup_start. +	 */ +	ctxt->gdt_desc.size = GDT_SIZE - 1; +	ctxt->gdt_desc.address = (unsigned long)get_cpu_gdt_table(smp_processor_id()); +  	store_tr(ctxt->tr);  	/* XMM0..XMM15 should be handled by kernel_fpu_begin(). */ @@ -113,7 +120,7 @@ static void __save_processor_state(struct saved_context *ctxt)  void save_processor_state(void)  {  	__save_processor_state(&saved_context); -	save_sched_clock_state(); +	x86_platform.save_sched_clock_state();  }  #ifdef CONFIG_X86_32  EXPORT_SYMBOL(save_processor_state); @@ -131,7 +138,10 @@ static void fix_processor_context(void)  {  	int cpu = smp_processor_id();  	struct tss_struct *t = &per_cpu(init_tss, cpu); - +#ifdef CONFIG_X86_64 +	struct desc_struct *desc = get_cpu_gdt_table(cpu); +	tss_desc tss; +#endif  	set_tss_desc(cpu, t);	/*  				 * This just modifies memory; should not be  				 * necessary. But... This is necessary, because @@ -140,7 +150,9 @@ static void fix_processor_context(void)  				 */  #ifdef CONFIG_X86_64 -	get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9; +	memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc)); +	tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */ +	write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);  	syscall_init();				/* This sets MSR_*STAR and related */  #endif @@ -179,11 +191,9 @@ static void __restore_processor_state(struct saved_context *ctxt)  	 * ltr is done i fix_processor_context().  	 */  #ifdef CONFIG_X86_32 -	load_gdt(&ctxt->gdt);  	load_idt(&ctxt->idt);  #else  /* CONFIG_X86_64 */ -	load_gdt((const struct desc_ptr *)&ctxt->gdt_limit);  	load_idt((const struct desc_ptr *)&ctxt->idt_limit);  #endif @@ -223,15 +233,97 @@ static void __restore_processor_state(struct saved_context *ctxt)  	fix_processor_context();  	do_fpu_end(); +	x86_platform.restore_sched_clock_state();  	mtrr_bp_restore(); +	perf_restore_debug_store();  }  /* Needed by apm.c */  void restore_processor_state(void)  {  	__restore_processor_state(&saved_context); -	restore_sched_clock_state();  }  #ifdef CONFIG_X86_32  EXPORT_SYMBOL(restore_processor_state);  #endif + +/* + * When bsp_check() is called in hibernate and suspend, cpu hotplug + * is disabled already. So it's unnessary to handle race condition between + * cpumask query and cpu hotplug. + */ +static int bsp_check(void) +{ +	if (cpumask_first(cpu_online_mask) != 0) { +		pr_warn("CPU0 is offline.\n"); +		return -ENODEV; +	} + +	return 0; +} + +static int bsp_pm_callback(struct notifier_block *nb, unsigned long action, +			   void *ptr) +{ +	int ret = 0; + +	switch (action) { +	case PM_SUSPEND_PREPARE: +	case PM_HIBERNATION_PREPARE: +		ret = bsp_check(); +		break; +#ifdef CONFIG_DEBUG_HOTPLUG_CPU0 +	case PM_RESTORE_PREPARE: +		/* +		 * When system resumes from hibernation, online CPU0 because +		 * 1. it's required for resume and +		 * 2. the CPU was online before hibernation +		 */ +		if (!cpu_online(0)) +			_debug_hotplug_cpu(0, 1); +		break; +	case PM_POST_RESTORE: +		/* +		 * When a resume really happens, this code won't be called. +		 * +		 * This code is called only when user space hibernation software +		 * prepares for snapshot device during boot time. So we just +		 * call _debug_hotplug_cpu() to restore to CPU0's state prior to +		 * preparing the snapshot device. +		 * +		 * This works for normal boot case in our CPU0 hotplug debug +		 * mode, i.e. CPU0 is offline and user mode hibernation +		 * software initializes during boot time. +		 * +		 * If CPU0 is online and user application accesses snapshot +		 * device after boot time, this will offline CPU0 and user may +		 * see different CPU0 state before and after accessing +		 * the snapshot device. But hopefully this is not a case when +		 * user debugging CPU0 hotplug. Even if users hit this case, +		 * they can easily online CPU0 back. +		 * +		 * To simplify this debug code, we only consider normal boot +		 * case. Otherwise we need to remember CPU0's state and restore +		 * to that state and resolve racy conditions etc. +		 */ +		_debug_hotplug_cpu(0, 0); +		break; +#endif +	default: +		break; +	} +	return notifier_from_errno(ret); +} + +static int __init bsp_pm_check_init(void) +{ +	/* +	 * Set this bsp_pm_callback as lower priority than +	 * cpu_hotplug_pm_callback. So cpu_hotplug_pm_callback will be called +	 * earlier to disable cpu hotplug before bsp online check. +	 */ +	pm_notifier(bsp_pm_callback, -INT_MAX); +	return 0; +} + +core_initcall(bsp_pm_check_init); diff --git a/arch/x86/power/hibernate_32.c b/arch/x86/power/hibernate_32.c index 3769079874d..7d28c885d23 100644 --- a/arch/x86/power/hibernate_32.c +++ b/arch/x86/power/hibernate_32.c @@ -10,7 +10,6 @@  #include <linux/suspend.h>  #include <linux/bootmem.h> -#include <asm/system.h>  #include <asm/page.h>  #include <asm/pgtable.h>  #include <asm/mmzone.h> @@ -130,8 +129,6 @@ static int resume_physical_mapping_init(pgd_t *pgd_base)  		}  	} -	resume_map_numa_kva(pgd_base); -  	return 0;  } diff --git a/arch/x86/power/hibernate_64.c b/arch/x86/power/hibernate_64.c index 460f314d13e..35e2bb6c0f3 100644 --- a/arch/x86/power/hibernate_64.c +++ b/arch/x86/power/hibernate_64.c @@ -11,6 +11,8 @@  #include <linux/gfp.h>  #include <linux/smp.h>  #include <linux/suspend.h> + +#include <asm/init.h>  #include <asm/proto.h>  #include <asm/page.h>  #include <asm/pgtable.h> @@ -18,62 +20,42 @@  #include <asm/suspend.h>  /* References to section boundaries */ -extern const void __nosave_begin, __nosave_end; +extern __visible const void __nosave_begin, __nosave_end;  /* Defined in hibernate_asm_64.S */ -extern int restore_image(void); +extern asmlinkage __visible int restore_image(void);  /*   * Address to jump to in the last phase of restore in order to get to the image   * kernel's text (this value is passed in the image header).   */ -unsigned long restore_jump_address; +unsigned long restore_jump_address __visible;  /*   * Value of the cr3 register from before the hibernation (this value is passed   * in the image header).   */ -unsigned long restore_cr3; +unsigned long restore_cr3 __visible; -pgd_t *temp_level4_pgt; +pgd_t *temp_level4_pgt __visible; -void *relocated_restore_code; +void *relocated_restore_code __visible; -static int res_phys_pud_init(pud_t *pud, unsigned long address, unsigned long end) +static void *alloc_pgt_page(void *context)  { -	long i, j; - -	i = pud_index(address); -	pud = pud + i; -	for (; i < PTRS_PER_PUD; pud++, i++) { -		unsigned long paddr; -		pmd_t *pmd; - -		paddr = address + i*PUD_SIZE; -		if (paddr >= end) -			break; - -		pmd = (pmd_t *)get_safe_page(GFP_ATOMIC); -		if (!pmd) -			return -ENOMEM; -		set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE)); -		for (j = 0; j < PTRS_PER_PMD; pmd++, j++, paddr += PMD_SIZE) { -			unsigned long pe; - -			if (paddr >= end) -				break; -			pe = __PAGE_KERNEL_LARGE_EXEC | paddr; -			pe &= __supported_pte_mask; -			set_pmd(pmd, __pmd(pe)); -		} -	} -	return 0; +	return (void *)get_safe_page(GFP_ATOMIC);  }  static int set_up_temporary_mappings(void)  { -	unsigned long start, end, next; -	int error; +	struct x86_mapping_info info = { +		.alloc_pgt_page	= alloc_pgt_page, +		.pmd_flag	= __PAGE_KERNEL_LARGE_EXEC, +		.kernel_mapping = true, +	}; +	unsigned long mstart, mend; +	int result; +	int i;  	temp_level4_pgt = (pgd_t *)get_safe_page(GFP_ATOMIC);  	if (!temp_level4_pgt) @@ -84,21 +66,17 @@ static int set_up_temporary_mappings(void)  		init_level4_pgt[pgd_index(__START_KERNEL_map)]);  	/* Set up the direct mapping from scratch */ -	start = (unsigned long)pfn_to_kaddr(0); -	end = (unsigned long)pfn_to_kaddr(max_pfn); - -	for (; start < end; start = next) { -		pud_t *pud = (pud_t *)get_safe_page(GFP_ATOMIC); -		if (!pud) -			return -ENOMEM; -		next = start + PGDIR_SIZE; -		if (next > end) -			next = end; -		if ((error = res_phys_pud_init(pud, __pa(start), __pa(next)))) -			return error; -		set_pgd(temp_level4_pgt + pgd_index(start), -			mk_kernel_pgd(__pa(pud))); +	for (i = 0; i < nr_pfn_mapped; i++) { +		mstart = pfn_mapped[i].start << PAGE_SHIFT; +		mend   = pfn_mapped[i].end << PAGE_SHIFT; + +		result = kernel_ident_mapping_init(&info, temp_level4_pgt, +						   mstart, mend); + +		if (result) +			return result;  	} +  	return 0;  } diff --git a/arch/x86/power/hibernate_asm_32.S b/arch/x86/power/hibernate_asm_32.S index ad47daeafa4..1d0fa0e2407 100644 --- a/arch/x86/power/hibernate_asm_32.S +++ b/arch/x86/power/hibernate_asm_32.S @@ -75,6 +75,10 @@ done:  	pushl saved_context_eflags  	popfl +	/* Saved in save_processor_state. */ +	movl $saved_context, %eax +	lgdt saved_context_gdt_desc(%eax) +  	xorl	%eax, %eax  	ret diff --git a/arch/x86/power/hibernate_asm_64.S b/arch/x86/power/hibernate_asm_64.S index 9356547d8c0..3c4469a7a92 100644 --- a/arch/x86/power/hibernate_asm_64.S +++ b/arch/x86/power/hibernate_asm_64.S @@ -139,6 +139,9 @@ ENTRY(restore_registers)  	pushq	pt_regs_flags(%rax)  	popfq +	/* Saved in save_processor_state. */ +	lgdt	saved_context_gdt_desc(%rax) +  	xorq	%rax, %rax  	/* tell the hibernation core that we've just restored the memory */  | 
