Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] x86: add an accessor function for getting the per-CPU gdt

Add an accessor function for getting the per-CPU gdt. Callee must already
have the CPU.

Signed-off-by: Zachary Amsden <zach@vmware.com>
Acked-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Zachary Amsden and committed by
Linus Torvalds
251e6912 72e12b76

+32 -27
+22 -18
arch/i386/kernel/apm.c
··· 597 597 cpumask_t cpus; 598 598 int cpu; 599 599 struct desc_struct save_desc_40; 600 + struct desc_struct *gdt; 600 601 601 602 cpus = apm_save_cpus(); 602 603 603 604 cpu = get_cpu(); 604 - save_desc_40 = per_cpu(cpu_gdt_table, cpu)[0x40 / 8]; 605 - per_cpu(cpu_gdt_table, cpu)[0x40 / 8] = bad_bios_desc; 605 + gdt = get_cpu_gdt_table(cpu); 606 + save_desc_40 = gdt[0x40 / 8]; 607 + gdt[0x40 / 8] = bad_bios_desc; 606 608 607 609 local_save_flags(flags); 608 610 APM_DO_CLI; ··· 612 610 apm_bios_call_asm(func, ebx_in, ecx_in, eax, ebx, ecx, edx, esi); 613 611 APM_DO_RESTORE_SEGS; 614 612 local_irq_restore(flags); 615 - per_cpu(cpu_gdt_table, cpu)[0x40 / 8] = save_desc_40; 613 + gdt[0x40 / 8] = save_desc_40; 616 614 put_cpu(); 617 615 apm_restore_cpus(cpus); 618 616 ··· 641 639 cpumask_t cpus; 642 640 int cpu; 643 641 struct desc_struct save_desc_40; 644 - 642 + struct desc_struct *gdt; 645 643 646 644 cpus = apm_save_cpus(); 647 645 648 646 cpu = get_cpu(); 649 - save_desc_40 = per_cpu(cpu_gdt_table, cpu)[0x40 / 8]; 650 - per_cpu(cpu_gdt_table, cpu)[0x40 / 8] = bad_bios_desc; 647 + gdt = get_cpu_gdt_table(cpu); 648 + save_desc_40 = gdt[0x40 / 8]; 649 + gdt[0x40 / 8] = bad_bios_desc; 651 650 652 651 local_save_flags(flags); 653 652 APM_DO_CLI; ··· 656 653 error = apm_bios_call_simple_asm(func, ebx_in, ecx_in, eax); 657 654 APM_DO_RESTORE_SEGS; 658 655 local_irq_restore(flags); 659 - __get_cpu_var(cpu_gdt_table)[0x40 / 8] = save_desc_40; 656 + gdt[0x40 / 8] = save_desc_40; 660 657 put_cpu(); 661 658 apm_restore_cpus(cpus); 662 659 return error; ··· 2298 2295 apm_bios_entry.segment = APM_CS; 2299 2296 2300 2297 for (i = 0; i < NR_CPUS; i++) { 2301 - set_base(per_cpu(cpu_gdt_table, i)[APM_CS >> 3], 2298 + struct desc_struct *gdt = get_cpu_gdt_table(i); 2299 + set_base(gdt[APM_CS >> 3], 2302 2300 __va((unsigned long)apm_info.bios.cseg << 4)); 2303 - set_base(per_cpu(cpu_gdt_table, i)[APM_CS_16 >> 3], 2301 + set_base(gdt[APM_CS_16 >> 3], 2304 2302 __va((unsigned long)apm_info.bios.cseg_16 << 4)); 2305 - set_base(per_cpu(cpu_gdt_table, i)[APM_DS >> 3], 2303 + set_base(gdt[APM_DS >> 3], 2306 2304 __va((unsigned long)apm_info.bios.dseg << 4)); 2307 2305 #ifndef APM_RELAX_SEGMENTS 2308 2306 if (apm_info.bios.version == 0x100) { 2309 2307 #endif 2310 2308 /* For ASUS motherboard, Award BIOS rev 110 (and others?) */ 2311 - _set_limit((char *)&per_cpu(cpu_gdt_table, i)[APM_CS >> 3], 64 * 1024 - 1); 2309 + _set_limit((char *)&gdt[APM_CS >> 3], 64 * 1024 - 1); 2312 2310 /* For some unknown machine. */ 2313 - _set_limit((char *)&per_cpu(cpu_gdt_table, i)[APM_CS_16 >> 3], 64 * 1024 - 1); 2311 + _set_limit((char *)&gdt[APM_CS_16 >> 3], 64 * 1024 - 1); 2314 2312 /* For the DEC Hinote Ultra CT475 (and others?) */ 2315 - _set_limit((char *)&per_cpu(cpu_gdt_table, i)[APM_DS >> 3], 64 * 1024 - 1); 2313 + _set_limit((char *)&gdt[APM_DS >> 3], 64 * 1024 - 1); 2316 2314 #ifndef APM_RELAX_SEGMENTS 2317 2315 } else { 2318 - _set_limit((char *)&per_cpu(cpu_gdt_table, i)[APM_CS >> 3], 2316 + _set_limit((char *)&gdt[APM_CS >> 3], 2319 2317 (apm_info.bios.cseg_len - 1) & 0xffff); 2320 - _set_limit((char *)&per_cpu(cpu_gdt_table, i)[APM_CS_16 >> 3], 2318 + _set_limit((char *)&gdt[APM_CS_16 >> 3], 2321 2319 (apm_info.bios.cseg_16_len - 1) & 0xffff); 2322 - _set_limit((char *)&per_cpu(cpu_gdt_table, i)[APM_DS >> 3], 2320 + _set_limit((char *)&gdt[APM_DS >> 3], 2323 2321 (apm_info.bios.dseg_len - 1) & 0xffff); 2324 2322 /* workaround for broken BIOSes */ 2325 2323 if (apm_info.bios.cseg_len <= apm_info.bios.offset) 2326 - _set_limit((char *)&per_cpu(cpu_gdt_table, i)[APM_CS >> 3], 64 * 1024 -1); 2324 + _set_limit((char *)&gdt[APM_CS >> 3], 64 * 1024 -1); 2327 2325 if (apm_info.bios.dseg_len <= 0x40) { /* 0x40 * 4kB == 64kB */ 2328 2326 /* for the BIOS that assumes granularity = 1 */ 2329 - per_cpu(cpu_gdt_table, i)[APM_DS >> 3].b |= 0x800000; 2327 + gdt[APM_DS >> 3].b |= 0x800000; 2330 2328 printk(KERN_NOTICE "apm: we set the granularity of dseg.\n"); 2331 2329 } 2332 2330 }
+4 -5
arch/i386/kernel/cpu/common.c
··· 573 573 int cpu = smp_processor_id(); 574 574 struct tss_struct * t = &per_cpu(init_tss, cpu); 575 575 struct thread_struct *thread = &current->thread; 576 + struct desc_struct *gdt = get_cpu_gdt_table(cpu); 576 577 __u32 stk16_off = (__u32)&per_cpu(cpu_16bit_stack, cpu); 577 578 578 579 if (cpu_test_and_set(cpu, cpu_initialized)) { ··· 595 594 * Initialize the per-CPU GDT with the boot GDT, 596 595 * and set up the GDT descriptor: 597 596 */ 598 - memcpy(&per_cpu(cpu_gdt_table, cpu), cpu_gdt_table, 599 - GDT_SIZE); 597 + memcpy(gdt, cpu_gdt_table, GDT_SIZE); 600 598 601 599 /* Set up GDT entry for 16bit stack */ 602 - *(__u64 *)&(per_cpu(cpu_gdt_table, cpu)[GDT_ENTRY_ESPFIX_SS]) |= 600 + *(__u64 *)(&gdt[GDT_ENTRY_ESPFIX_SS]) |= 603 601 ((((__u64)stk16_off) << 16) & 0x000000ffffff0000ULL) | 604 602 ((((__u64)stk16_off) << 32) & 0xff00000000000000ULL) | 605 603 (CPU_16BIT_STACK_SIZE - 1); 606 604 607 605 cpu_gdt_descr[cpu].size = GDT_SIZE - 1; 608 - cpu_gdt_descr[cpu].address = 609 - (unsigned long)&per_cpu(cpu_gdt_table, cpu); 606 + cpu_gdt_descr[cpu].address = (unsigned long)gdt; 610 607 611 608 load_gdt(&cpu_gdt_descr[cpu]); 612 609 load_idt(&idt_descr);
+1 -1
arch/i386/mm/fault.c
··· 108 108 desc = (void *)desc + (seg & ~7); 109 109 } else { 110 110 /* Must disable preemption while reading the GDT. */ 111 - desc = (u32 *)&per_cpu(cpu_gdt_table, get_cpu()); 111 + desc = (u32 *)get_cpu_gdt_table(get_cpu()); 112 112 desc = (void *)desc + (seg & ~7); 113 113 } 114 114
+5 -3
include/asm-i386/desc.h
··· 17 17 extern struct desc_struct cpu_gdt_table[GDT_ENTRIES]; 18 18 DECLARE_PER_CPU(struct desc_struct, cpu_gdt_table[GDT_ENTRIES]); 19 19 20 + #define get_cpu_gdt_table(_cpu) (per_cpu(cpu_gdt_table,_cpu)) 21 + 20 22 DECLARE_PER_CPU(unsigned char, cpu_16bit_stack[CPU_16BIT_STACK_SIZE]); 21 23 22 24 struct Xgt_desc_struct { ··· 62 60 63 61 static inline void __set_tss_desc(unsigned int cpu, unsigned int entry, void *addr) 64 62 { 65 - _set_tssldt_desc(&per_cpu(cpu_gdt_table, cpu)[entry], (int)addr, 63 + _set_tssldt_desc(&get_cpu_gdt_table(cpu)[entry], (int)addr, 66 64 offsetof(struct tss_struct, __cacheline_filler) - 1, 0x89); 67 65 } 68 66 ··· 70 68 71 69 static inline void set_ldt_desc(unsigned int cpu, void *addr, unsigned int size) 72 70 { 73 - _set_tssldt_desc(&per_cpu(cpu_gdt_table, cpu)[GDT_ENTRY_LDT], (int)addr, ((size << 3)-1), 0x82); 71 + _set_tssldt_desc(&get_cpu_gdt_table(cpu)[GDT_ENTRY_LDT], (int)addr, ((size << 3)-1), 0x82); 74 72 } 75 73 76 74 #define LDT_entry_a(info) \ ··· 111 109 112 110 static inline void load_TLS(struct thread_struct *t, unsigned int cpu) 113 111 { 114 - #define C(i) per_cpu(cpu_gdt_table, cpu)[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i] 112 + #define C(i) get_cpu_gdt_table(cpu)[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i] 115 113 C(0); C(1); C(2); 116 114 #undef C 117 115 }