2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* X86-64 specific CPU setup.
|
|
|
|
* Copyright (C) 1995 Linus Torvalds
|
|
|
|
* Copyright 2001, 2002, 2003 SuSE Labs / Andi Kleen.
|
|
|
|
* See setup.c for older changelog.
|
|
|
|
*/
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/bootmem.h>
|
|
|
|
#include <linux/bitops.h>
|
2005-07-29 04:15:30 +00:00
|
|
|
#include <linux/module.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <asm/pda.h>
|
|
|
|
#include <asm/pgtable.h>
|
|
|
|
#include <asm/processor.h>
|
|
|
|
#include <asm/desc.h>
|
|
|
|
#include <asm/atomic.h>
|
|
|
|
#include <asm/mmu_context.h>
|
|
|
|
#include <asm/smp.h>
|
|
|
|
#include <asm/i387.h>
|
|
|
|
#include <asm/percpu.h>
|
|
|
|
#include <asm/proto.h>
|
2005-07-29 04:15:30 +00:00
|
|
|
#include <asm/sections.h>
|
2007-10-16 00:13:22 +00:00
|
|
|
#include <asm/setup.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-10-16 00:13:22 +00:00
|
|
|
struct boot_params __initdata boot_params;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
[PATCH] x86_64: Change init sections for CPU hotplug support
This patch adds __cpuinit and __cpuinitdata sections that need to exist past
boot to support cpu hotplug.
Caveat: This is done *only* for EM64T CPU Hotplug support, on request from
Andi Kleen. Much of the generic hotplug code in kernel, and none of the other
archs that support CPU hotplug today, i386, ia64, ppc64, s390 and parisc dont
mark sections with __cpuinit, but only mark them as __devinit, and
__devinitdata.
If someone is motivated to change generic code, we need to make sure all
existing hotplug code does not break, on other arch's that dont use __cpuinit,
and __cpudevinit.
Signed-off-by: Ashok Raj <ashok.raj@intel.com>
Acked-by: Andi Kleen <ak@muc.de>
Acked-by: Zwane Mwaikambo <zwane@arm.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-25 21:54:58 +00:00
|
|
|
cpumask_t cpu_initialized __cpuinitdata = CPU_MASK_NONE;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-01-11 21:45:42 +00:00
|
|
|
struct x8664_pda *_cpu_pda[NR_CPUS] __read_mostly;
|
2006-06-26 11:59:44 +00:00
|
|
|
EXPORT_SYMBOL(_cpu_pda);
|
2006-01-11 21:45:42 +00:00
|
|
|
struct x8664_pda boot_cpu_pda[NR_CPUS] __cacheline_aligned;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-03-25 15:30:01 +00:00
|
|
|
struct desc_ptr idt_descr = { 256 * 16 - 1, (unsigned long) idt_table };
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
char boot_cpu_stack[IRQSTACKSIZE] __attribute__((section(".bss.page_aligned")));
|
|
|
|
|
2005-09-06 22:17:45 +00:00
|
|
|
unsigned long __supported_pte_mask __read_mostly = ~0UL;
|
2006-01-16 00:56:48 +00:00
|
|
|
static int do_not_nx __cpuinitdata = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* noexec=on|off
|
|
|
|
Control non executable mappings for 64bit processes.
|
|
|
|
|
|
|
|
on Enable(default)
|
|
|
|
off Disable
|
|
|
|
*/
|
2006-09-26 08:52:32 +00:00
|
|
|
static int __init nonx_setup(char *str)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-09-26 08:52:32 +00:00
|
|
|
if (!str)
|
|
|
|
return -EINVAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!strncmp(str, "on", 2)) {
|
|
|
|
__supported_pte_mask |= _PAGE_NX;
|
|
|
|
do_not_nx = 0;
|
|
|
|
} else if (!strncmp(str, "off", 3)) {
|
|
|
|
do_not_nx = 1;
|
|
|
|
__supported_pte_mask &= ~_PAGE_NX;
|
|
|
|
}
|
2006-09-26 08:52:32 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2006-09-26 08:52:32 +00:00
|
|
|
early_param("noexec", nonx_setup);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-03-25 15:31:04 +00:00
|
|
|
int force_personality32 = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* noexec32=on|off
|
|
|
|
Control non executable heap for 32bit processes.
|
|
|
|
To control the stack too use noexec=off
|
|
|
|
|
|
|
|
on PROT_READ does not imply PROT_EXEC for 32bit processes
|
|
|
|
off PROT_READ implies PROT_EXEC (default)
|
|
|
|
*/
|
|
|
|
static int __init nonx32_setup(char *str)
|
|
|
|
{
|
|
|
|
if (!strcmp(str, "on"))
|
|
|
|
force_personality32 &= ~READ_IMPLIES_EXEC;
|
|
|
|
else if (!strcmp(str, "off"))
|
|
|
|
force_personality32 |= READ_IMPLIES_EXEC;
|
2006-03-31 10:30:33 +00:00
|
|
|
return 1;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
__setup("noexec32=", nonx32_setup);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Great future plan:
|
|
|
|
* Declare PDA itself and support (irqstack,tss,pgd) as per cpu data.
|
|
|
|
* Always point %gs to its beginning
|
|
|
|
*/
|
|
|
|
void __init setup_per_cpu_areas(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned long size;
|
|
|
|
|
2005-10-10 20:32:45 +00:00
|
|
|
#ifdef CONFIG_HOTPLUG_CPU
|
|
|
|
prefill_possible_map();
|
|
|
|
#endif
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Copy section for each CPU (we discard the original) */
|
2006-09-26 08:52:35 +00:00
|
|
|
size = PERCPU_ENOUGH_ROOM;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-09-26 08:52:35 +00:00
|
|
|
printk(KERN_INFO "PERCPU: Allocating %lu bytes of per cpu data\n", size);
|
2005-09-12 16:49:24 +00:00
|
|
|
for_each_cpu_mask (i, cpu_possible_map) {
|
2005-07-29 04:15:30 +00:00
|
|
|
char *ptr;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (!NODE_DATA(cpu_to_node(i))) {
|
|
|
|
printk("cpu with no node %d, num_online_nodes %d\n",
|
|
|
|
i, num_online_nodes());
|
2007-05-02 17:27:12 +00:00
|
|
|
ptr = alloc_bootmem_pages(size);
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
2007-05-02 17:27:12 +00:00
|
|
|
ptr = alloc_bootmem_pages_node(NODE_DATA(cpu_to_node(i)), size);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
if (!ptr)
|
|
|
|
panic("Cannot allocate cpu data for CPU %d\n", i);
|
2006-01-11 21:45:39 +00:00
|
|
|
cpu_pda(i)->data_offset = ptr - __per_cpu_start;
|
2005-04-16 22:20:36 +00:00
|
|
|
memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pda_init(int cpu)
|
|
|
|
{
|
2006-01-11 21:45:39 +00:00
|
|
|
struct x8664_pda *pda = cpu_pda(cpu);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Setup up data that may be needed in __get_free_pages early */
|
|
|
|
asm volatile("movl %0,%%fs ; movl %0,%%gs" :: "r" (0));
|
2006-09-26 08:52:38 +00:00
|
|
|
/* Memory clobbers used to order PDA accessed */
|
|
|
|
mb();
|
2006-01-11 21:45:39 +00:00
|
|
|
wrmsrl(MSR_GS_BASE, pda);
|
2006-09-26 08:52:38 +00:00
|
|
|
mb();
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
pda->cpunumber = cpu;
|
|
|
|
pda->irqcount = -1;
|
|
|
|
pda->kernelstack =
|
|
|
|
(unsigned long)stack_thread_info() - PDA_STACKOFFSET + THREAD_SIZE;
|
|
|
|
pda->active_mm = &init_mm;
|
|
|
|
pda->mmu_state = 0;
|
|
|
|
|
|
|
|
if (cpu == 0) {
|
|
|
|
/* others are initialized in smpboot.c */
|
|
|
|
pda->pcurrent = &init_task;
|
|
|
|
pda->irqstackptr = boot_cpu_stack;
|
|
|
|
} else {
|
|
|
|
pda->irqstackptr = (char *)
|
|
|
|
__get_free_pages(GFP_ATOMIC, IRQSTACK_ORDER);
|
|
|
|
if (!pda->irqstackptr)
|
|
|
|
panic("cannot allocate irqstack for cpu %d", cpu);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pda->irqstackptr += IRQSTACKSIZE-64;
|
|
|
|
}
|
|
|
|
|
2006-01-19 01:42:21 +00:00
|
|
|
char boot_exception_stacks[(N_EXCEPTION_STACKS - 1) * EXCEPTION_STKSZ + DEBUG_STKSZ]
|
2005-04-16 22:20:36 +00:00
|
|
|
__attribute__((section(".bss.page_aligned")));
|
|
|
|
|
2007-06-23 00:29:25 +00:00
|
|
|
extern asmlinkage void ignore_sysret(void);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* May not be marked __init: used by software suspend */
|
|
|
|
void syscall_init(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* LSTAR and STAR live in a bit strange symbiosis.
|
|
|
|
* They both write to the same internal register. STAR allows to set CS/DS
|
|
|
|
* but only a 32bit target. LSTAR sets the 64bit rip.
|
|
|
|
*/
|
|
|
|
wrmsrl(MSR_STAR, ((u64)__USER32_CS)<<48 | ((u64)__KERNEL_CS)<<32);
|
|
|
|
wrmsrl(MSR_LSTAR, system_call);
|
2007-06-23 00:29:25 +00:00
|
|
|
wrmsrl(MSR_CSTAR, ignore_sysret);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_IA32_EMULATION
|
|
|
|
syscall32_cpu_init ();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Flags to clear on syscall */
|
|
|
|
wrmsrl(MSR_SYSCALL_MASK, EF_TF|EF_DF|EF_IE|0x3000);
|
|
|
|
}
|
|
|
|
|
[PATCH] x86_64: Change init sections for CPU hotplug support
This patch adds __cpuinit and __cpuinitdata sections that need to exist past
boot to support cpu hotplug.
Caveat: This is done *only* for EM64T CPU Hotplug support, on request from
Andi Kleen. Much of the generic hotplug code in kernel, and none of the other
archs that support CPU hotplug today, i386, ia64, ppc64, s390 and parisc dont
mark sections with __cpuinit, but only mark them as __devinit, and
__devinitdata.
If someone is motivated to change generic code, we need to make sure all
existing hotplug code does not break, on other arch's that dont use __cpuinit,
and __cpudevinit.
Signed-off-by: Ashok Raj <ashok.raj@intel.com>
Acked-by: Andi Kleen <ak@muc.de>
Acked-by: Zwane Mwaikambo <zwane@arm.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-25 21:54:58 +00:00
|
|
|
void __cpuinit check_efer(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned long efer;
|
|
|
|
|
|
|
|
rdmsrl(MSR_EFER, efer);
|
|
|
|
if (!(efer & EFER_NX) || do_not_nx) {
|
|
|
|
__supported_pte_mask &= ~_PAGE_NX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-26 08:52:41 +00:00
|
|
|
unsigned long kernel_eflags;
|
|
|
|
|
2007-10-19 18:35:02 +00:00
|
|
|
/*
|
|
|
|
* Copies of the original ist values from the tss are only accessed during
|
|
|
|
* debugging, no special alignment required.
|
|
|
|
*/
|
|
|
|
DEFINE_PER_CPU(struct orig_ist, orig_ist);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* cpu_init() initializes state that is per-CPU. Some data is already
|
|
|
|
* initialized (naturally) in the bootstrap process, such as the GDT
|
|
|
|
* and IDT. We reload them nevertheless, this function acts as a
|
|
|
|
* 'CPU state barrier', nothing should get across.
|
|
|
|
* A lot of state is already set up in PDA init.
|
|
|
|
*/
|
[PATCH] x86_64: Change init sections for CPU hotplug support
This patch adds __cpuinit and __cpuinitdata sections that need to exist past
boot to support cpu hotplug.
Caveat: This is done *only* for EM64T CPU Hotplug support, on request from
Andi Kleen. Much of the generic hotplug code in kernel, and none of the other
archs that support CPU hotplug today, i386, ia64, ppc64, s390 and parisc dont
mark sections with __cpuinit, but only mark them as __devinit, and
__devinitdata.
If someone is motivated to change generic code, we need to make sure all
existing hotplug code does not break, on other arch's that dont use __cpuinit,
and __cpudevinit.
Signed-off-by: Ashok Raj <ashok.raj@intel.com>
Acked-by: Andi Kleen <ak@muc.de>
Acked-by: Zwane Mwaikambo <zwane@arm.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-25 21:54:58 +00:00
|
|
|
void __cpuinit cpu_init (void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int cpu = stack_smp_processor_id();
|
|
|
|
struct tss_struct *t = &per_cpu(init_tss, cpu);
|
2006-08-30 17:37:19 +00:00
|
|
|
struct orig_ist *orig_ist = &per_cpu(orig_ist, cpu);
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long v;
|
|
|
|
char *estacks = NULL;
|
|
|
|
struct task_struct *me;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* CPU 0 is initialised in head64.c */
|
|
|
|
if (cpu != 0) {
|
|
|
|
pda_init(cpu);
|
|
|
|
} else
|
|
|
|
estacks = boot_exception_stacks;
|
|
|
|
|
|
|
|
me = current;
|
|
|
|
|
|
|
|
if (cpu_test_and_set(cpu, cpu_initialized))
|
|
|
|
panic("CPU#%d already initialized!\n", cpu);
|
|
|
|
|
|
|
|
printk("Initializing CPU#%d\n", cpu);
|
|
|
|
|
2005-07-29 04:15:30 +00:00
|
|
|
clear_in_cr4(X86_CR4_VME|X86_CR4_PVI|X86_CR4_TSD|X86_CR4_DE);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the per-CPU GDT with the boot GDT,
|
|
|
|
* and set up the GDT descriptor:
|
|
|
|
*/
|
2006-01-11 21:43:57 +00:00
|
|
|
if (cpu)
|
|
|
|
memcpy(cpu_gdt(cpu), cpu_gdt_table, GDT_SIZE);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
cpu_gdt_descr[cpu].size = GDT_SIZE;
|
2007-10-19 18:35:03 +00:00
|
|
|
load_gdt((const struct desc_ptr *)&cpu_gdt_descr[cpu]);
|
|
|
|
load_idt((const struct desc_ptr *)&idt_descr);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-01-11 21:43:57 +00:00
|
|
|
memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
|
2005-04-16 22:20:36 +00:00
|
|
|
syscall_init();
|
|
|
|
|
|
|
|
wrmsrl(MSR_FS_BASE, 0);
|
|
|
|
wrmsrl(MSR_KERNEL_GS_BASE, 0);
|
|
|
|
barrier();
|
|
|
|
|
|
|
|
check_efer();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set up and load the per-CPU TSS
|
|
|
|
*/
|
|
|
|
for (v = 0; v < N_EXCEPTION_STACKS; v++) {
|
2006-09-26 08:52:38 +00:00
|
|
|
static const unsigned int order[N_EXCEPTION_STACKS] = {
|
|
|
|
[0 ... N_EXCEPTION_STACKS - 1] = EXCEPTION_STACK_ORDER,
|
|
|
|
[DEBUG_STACK - 1] = DEBUG_STACK_ORDER
|
|
|
|
};
|
2005-04-16 22:20:36 +00:00
|
|
|
if (cpu) {
|
2006-01-11 21:43:00 +00:00
|
|
|
estacks = (char *)__get_free_pages(GFP_ATOMIC, order[v]);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!estacks)
|
|
|
|
panic("Cannot allocate exception stack %ld %d\n",
|
|
|
|
v, cpu);
|
|
|
|
}
|
2006-09-26 08:52:38 +00:00
|
|
|
estacks += PAGE_SIZE << order[v];
|
2006-08-30 17:37:19 +00:00
|
|
|
orig_ist->ist[v] = t->ist[v] = (unsigned long)estacks;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
t->io_bitmap_base = offsetof(struct tss_struct, io_bitmap);
|
|
|
|
/*
|
|
|
|
* <= is required because the CPU will access up to
|
|
|
|
* 8 bits beyond the end of the IO permission bitmap.
|
|
|
|
*/
|
|
|
|
for (i = 0; i <= IO_BITMAP_LONGS; i++)
|
|
|
|
t->io_bitmap[i] = ~0UL;
|
|
|
|
|
|
|
|
atomic_inc(&init_mm.mm_count);
|
|
|
|
me->active_mm = &init_mm;
|
|
|
|
if (me->mm)
|
|
|
|
BUG();
|
|
|
|
enter_lazy_tlb(&init_mm, me);
|
|
|
|
|
|
|
|
set_tss_desc(cpu, t);
|
|
|
|
load_TR_desc();
|
|
|
|
load_LDT(&init_mm.context);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear all 6 debug registers:
|
|
|
|
*/
|
|
|
|
|
2006-03-25 15:29:22 +00:00
|
|
|
set_debugreg(0UL, 0);
|
|
|
|
set_debugreg(0UL, 1);
|
|
|
|
set_debugreg(0UL, 2);
|
|
|
|
set_debugreg(0UL, 3);
|
|
|
|
set_debugreg(0UL, 6);
|
|
|
|
set_debugreg(0UL, 7);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
fpu_init();
|
2006-09-26 08:52:41 +00:00
|
|
|
|
|
|
|
raw_local_save_flags(kernel_eflags);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|