aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel/cpu/common.c
diff options
context:
space:
mode:
authorYinghai Lu <yhlu.kernel@gmail.com>2008-09-04 23:09:03 -0400
committerIngo Molnar <mingo@elte.hu>2008-09-05 03:40:48 -0400
commitd5494d4f517158b1d2eea1ae33f6c264eb12675f (patch)
tree26990f4c8dfcd4b66041d71378e8074ff8ba982c /arch/x86/kernel/cpu/common.c
parentba51dced0b55eb62874e1646d5eeff344c3d4e67 (diff)
x86: cpu/common*.c, make 32-bit have 64-bit only functions
Signed-off-by: Yinghai Lu <yhlu.kernel@gmail.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'arch/x86/kernel/cpu/common.c')
-rw-r--r--arch/x86/kernel/cpu/common.c138
1 files changed, 138 insertions, 0 deletions
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 9128ba0c8d33..dcd3ebd5ba62 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -750,6 +750,143 @@ __setup("clearcpuid=", setup_disablecpuid);
750 750
751cpumask_t cpu_initialized __cpuinitdata = CPU_MASK_NONE; 751cpumask_t cpu_initialized __cpuinitdata = CPU_MASK_NONE;
752 752
753#ifdef CONFIG_X86_64
754struct x8664_pda **_cpu_pda __read_mostly;
755EXPORT_SYMBOL(_cpu_pda);
756
757struct desc_ptr idt_descr = { 256 * 16 - 1, (unsigned long) idt_table };
758
759char boot_cpu_stack[IRQSTACKSIZE] __page_aligned_bss;
760
761unsigned long __supported_pte_mask __read_mostly = ~0UL;
762EXPORT_SYMBOL_GPL(__supported_pte_mask);
763
764static int do_not_nx __cpuinitdata;
765
766/* noexec=on|off
767Control non executable mappings for 64bit processes.
768
769on Enable(default)
770off Disable
771*/
772static int __init nonx_setup(char *str)
773{
774 if (!str)
775 return -EINVAL;
776 if (!strncmp(str, "on", 2)) {
777 __supported_pte_mask |= _PAGE_NX;
778 do_not_nx = 0;
779 } else if (!strncmp(str, "off", 3)) {
780 do_not_nx = 1;
781 __supported_pte_mask &= ~_PAGE_NX;
782 }
783 return 0;
784}
785early_param("noexec", nonx_setup);
786
787int force_personality32;
788
789/* noexec32=on|off
790Control non executable heap for 32bit processes.
791To control the stack too use noexec=off
792
793on PROT_READ does not imply PROT_EXEC for 32bit processes (default)
794off PROT_READ implies PROT_EXEC
795*/
796static int __init nonx32_setup(char *str)
797{
798 if (!strcmp(str, "on"))
799 force_personality32 &= ~READ_IMPLIES_EXEC;
800 else if (!strcmp(str, "off"))
801 force_personality32 |= READ_IMPLIES_EXEC;
802 return 1;
803}
804__setup("noexec32=", nonx32_setup);
805
806void pda_init(int cpu)
807{
808 struct x8664_pda *pda = cpu_pda(cpu);
809
810 /* Setup up data that may be needed in __get_free_pages early */
811 loadsegment(fs, 0);
812 loadsegment(gs, 0);
813 /* Memory clobbers used to order PDA accessed */
814 mb();
815 wrmsrl(MSR_GS_BASE, pda);
816 mb();
817
818 pda->cpunumber = cpu;
819 pda->irqcount = -1;
820 pda->kernelstack = (unsigned long)stack_thread_info() -
821 PDA_STACKOFFSET + THREAD_SIZE;
822 pda->active_mm = &init_mm;
823 pda->mmu_state = 0;
824
825 if (cpu == 0) {
826 /* others are initialized in smpboot.c */
827 pda->pcurrent = &init_task;
828 pda->irqstackptr = boot_cpu_stack;
829 pda->irqstackptr += IRQSTACKSIZE - 64;
830 } else {
831 if (!pda->irqstackptr) {
832 pda->irqstackptr = (char *)
833 __get_free_pages(GFP_ATOMIC, IRQSTACK_ORDER);
834 if (!pda->irqstackptr)
835 panic("cannot allocate irqstack for cpu %d",
836 cpu);
837 pda->irqstackptr += IRQSTACKSIZE - 64;
838 }
839
840 if (pda->nodenumber == 0 && cpu_to_node(cpu) != NUMA_NO_NODE)
841 pda->nodenumber = cpu_to_node(cpu);
842 }
843}
844
845char boot_exception_stacks[(N_EXCEPTION_STACKS - 1) * EXCEPTION_STKSZ +
846 DEBUG_STKSZ] __page_aligned_bss;
847
848extern asmlinkage void ignore_sysret(void);
849
850/* May not be marked __init: used by software suspend */
851void syscall_init(void)
852{
853 /*
854 * LSTAR and STAR live in a bit strange symbiosis.
855 * They both write to the same internal register. STAR allows to
856 * set CS/DS but only a 32bit target. LSTAR sets the 64bit rip.
857 */
858 wrmsrl(MSR_STAR, ((u64)__USER32_CS)<<48 | ((u64)__KERNEL_CS)<<32);
859 wrmsrl(MSR_LSTAR, system_call);
860 wrmsrl(MSR_CSTAR, ignore_sysret);
861
862#ifdef CONFIG_IA32_EMULATION
863 syscall32_cpu_init();
864#endif
865
866 /* Flags to clear on syscall */
867 wrmsrl(MSR_SYSCALL_MASK,
868 X86_EFLAGS_TF|X86_EFLAGS_DF|X86_EFLAGS_IF|X86_EFLAGS_IOPL);
869}
870
871void __cpuinit check_efer(void)
872{
873 unsigned long efer;
874
875 rdmsrl(MSR_EFER, efer);
876 if (!(efer & EFER_NX) || do_not_nx)
877 __supported_pte_mask &= ~_PAGE_NX;
878}
879
880unsigned long kernel_eflags;
881
882/*
883 * Copies of the original ist values from the tss are only accessed during
884 * debugging, no special alignment required.
885 */
886DEFINE_PER_CPU(struct orig_ist, orig_ist);
887
888#else
889
753/* Make sure %fs is initialized properly in idle threads */ 890/* Make sure %fs is initialized properly in idle threads */
754struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs) 891struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
755{ 892{
@@ -757,6 +894,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
757 regs->fs = __KERNEL_PERCPU; 894 regs->fs = __KERNEL_PERCPU;
758 return regs; 895 return regs;
759} 896}
897#endif
760 898
761/* 899/*
762 * cpu_init() initializes state that is per-CPU. Some data is already 900 * cpu_init() initializes state that is per-CPU. Some data is already