diff options
author | Len Brown <len.brown@intel.com> | 2009-01-09 03:39:43 -0500 |
---|---|---|
committer | Len Brown <len.brown@intel.com> | 2009-01-09 03:39:43 -0500 |
commit | b2576e1d4408e134e2188c967b1f28af39cd79d4 (patch) | |
tree | 004f3c82faab760f304ce031d6d2f572e7746a50 /arch/x86/kernel | |
parent | 3cc8a5f4ba91f67bbdb81a43a99281a26aab8d77 (diff) | |
parent | 2150edc6c5cf00f7adb54538b9ea2a3e9cedca3f (diff) |
Merge branch 'linus' into release
Diffstat (limited to 'arch/x86/kernel')
109 files changed, 6577 insertions, 5190 deletions
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index b62a7667828e..d364df03c1d6 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile | |||
@@ -12,6 +12,7 @@ CFLAGS_REMOVE_tsc.o = -pg | |||
12 | CFLAGS_REMOVE_rtc.o = -pg | 12 | CFLAGS_REMOVE_rtc.o = -pg |
13 | CFLAGS_REMOVE_paravirt-spinlocks.o = -pg | 13 | CFLAGS_REMOVE_paravirt-spinlocks.o = -pg |
14 | CFLAGS_REMOVE_ftrace.o = -pg | 14 | CFLAGS_REMOVE_ftrace.o = -pg |
15 | CFLAGS_REMOVE_early_printk.o = -pg | ||
15 | endif | 16 | endif |
16 | 17 | ||
17 | # | 18 | # |
@@ -23,9 +24,9 @@ CFLAGS_vsyscall_64.o := $(PROFILING) -g0 $(nostackp) | |||
23 | CFLAGS_hpet.o := $(nostackp) | 24 | CFLAGS_hpet.o := $(nostackp) |
24 | CFLAGS_tsc.o := $(nostackp) | 25 | CFLAGS_tsc.o := $(nostackp) |
25 | 26 | ||
26 | obj-y := process_$(BITS).o signal_$(BITS).o entry_$(BITS).o | 27 | obj-y := process_$(BITS).o signal.o entry_$(BITS).o |
27 | obj-y += traps.o irq.o irq_$(BITS).o dumpstack_$(BITS).o | 28 | obj-y += traps.o irq.o irq_$(BITS).o dumpstack_$(BITS).o |
28 | obj-y += time_$(BITS).o ioport.o ldt.o | 29 | obj-y += time_$(BITS).o ioport.o ldt.o dumpstack.o |
29 | obj-y += setup.o i8259.o irqinit_$(BITS).o setup_percpu.o | 30 | obj-y += setup.o i8259.o irqinit_$(BITS).o setup_percpu.o |
30 | obj-$(CONFIG_X86_VISWS) += visws_quirks.o | 31 | obj-$(CONFIG_X86_VISWS) += visws_quirks.o |
31 | obj-$(CONFIG_X86_32) += probe_roms_32.o | 32 | obj-$(CONFIG_X86_32) += probe_roms_32.o |
@@ -65,6 +66,7 @@ obj-$(CONFIG_X86_LOCAL_APIC) += apic.o nmi.o | |||
65 | obj-$(CONFIG_X86_IO_APIC) += io_apic.o | 66 | obj-$(CONFIG_X86_IO_APIC) += io_apic.o |
66 | obj-$(CONFIG_X86_REBOOTFIXUPS) += reboot_fixups_32.o | 67 | obj-$(CONFIG_X86_REBOOTFIXUPS) += reboot_fixups_32.o |
67 | obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o | 68 | obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o |
69 | obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o | ||
68 | obj-$(CONFIG_KEXEC) += machine_kexec_$(BITS).o | 70 | obj-$(CONFIG_KEXEC) += machine_kexec_$(BITS).o |
69 | obj-$(CONFIG_KEXEC) += relocate_kernel_$(BITS).o crash.o | 71 | obj-$(CONFIG_KEXEC) += relocate_kernel_$(BITS).o crash.o |
70 | obj-$(CONFIG_CRASH_DUMP) += crash_dump_$(BITS).o | 72 | obj-$(CONFIG_CRASH_DUMP) += crash_dump_$(BITS).o |
@@ -105,6 +107,10 @@ microcode-$(CONFIG_MICROCODE_INTEL) += microcode_intel.o | |||
105 | microcode-$(CONFIG_MICROCODE_AMD) += microcode_amd.o | 107 | microcode-$(CONFIG_MICROCODE_AMD) += microcode_amd.o |
106 | obj-$(CONFIG_MICROCODE) += microcode.o | 108 | obj-$(CONFIG_MICROCODE) += microcode.o |
107 | 109 | ||
110 | obj-$(CONFIG_X86_CHECK_BIOS_CORRUPTION) += check.o | ||
111 | |||
112 | obj-$(CONFIG_SWIOTLB) += pci-swiotlb_64.o # NB rename without _64 | ||
113 | |||
108 | ### | 114 | ### |
109 | # 64 bit specific files | 115 | # 64 bit specific files |
110 | ifeq ($(CONFIG_X86_64),y) | 116 | ifeq ($(CONFIG_X86_64),y) |
@@ -118,7 +124,6 @@ ifeq ($(CONFIG_X86_64),y) | |||
118 | obj-$(CONFIG_GART_IOMMU) += pci-gart_64.o aperture_64.o | 124 | obj-$(CONFIG_GART_IOMMU) += pci-gart_64.o aperture_64.o |
119 | obj-$(CONFIG_CALGARY_IOMMU) += pci-calgary_64.o tce_64.o | 125 | obj-$(CONFIG_CALGARY_IOMMU) += pci-calgary_64.o tce_64.o |
120 | obj-$(CONFIG_AMD_IOMMU) += amd_iommu_init.o amd_iommu.o | 126 | obj-$(CONFIG_AMD_IOMMU) += amd_iommu_init.o amd_iommu.o |
121 | obj-$(CONFIG_SWIOTLB) += pci-swiotlb_64.o | ||
122 | 127 | ||
123 | obj-$(CONFIG_PCI_MMCONFIG) += mmconf-fam10h_64.o | 128 | obj-$(CONFIG_PCI_MMCONFIG) += mmconf-fam10h_64.o |
124 | endif | 129 | endif |
diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c index 39ae3d0e3a4a..d37593c2f438 100644 --- a/arch/x86/kernel/acpi/boot.c +++ b/arch/x86/kernel/acpi/boot.c | |||
@@ -538,9 +538,10 @@ static int __cpuinit _acpi_map_lsapic(acpi_handle handle, int *pcpu) | |||
538 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | 538 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
539 | union acpi_object *obj; | 539 | union acpi_object *obj; |
540 | struct acpi_madt_local_apic *lapic; | 540 | struct acpi_madt_local_apic *lapic; |
541 | cpumask_t tmp_map, new_map; | 541 | cpumask_var_t tmp_map, new_map; |
542 | u8 physid; | 542 | u8 physid; |
543 | int cpu; | 543 | int cpu; |
544 | int retval = -ENOMEM; | ||
544 | 545 | ||
545 | if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer))) | 546 | if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer))) |
546 | return -EINVAL; | 547 | return -EINVAL; |
@@ -569,23 +570,37 @@ static int __cpuinit _acpi_map_lsapic(acpi_handle handle, int *pcpu) | |||
569 | buffer.length = ACPI_ALLOCATE_BUFFER; | 570 | buffer.length = ACPI_ALLOCATE_BUFFER; |
570 | buffer.pointer = NULL; | 571 | buffer.pointer = NULL; |
571 | 572 | ||
572 | tmp_map = cpu_present_map; | 573 | if (!alloc_cpumask_var(&tmp_map, GFP_KERNEL)) |
574 | goto out; | ||
575 | |||
576 | if (!alloc_cpumask_var(&new_map, GFP_KERNEL)) | ||
577 | goto free_tmp_map; | ||
578 | |||
579 | cpumask_copy(tmp_map, cpu_present_mask); | ||
573 | acpi_register_lapic(physid, lapic->lapic_flags & ACPI_MADT_ENABLED); | 580 | acpi_register_lapic(physid, lapic->lapic_flags & ACPI_MADT_ENABLED); |
574 | 581 | ||
575 | /* | 582 | /* |
576 | * If mp_register_lapic successfully generates a new logical cpu | 583 | * If mp_register_lapic successfully generates a new logical cpu |
577 | * number, then the following will get us exactly what was mapped | 584 | * number, then the following will get us exactly what was mapped |
578 | */ | 585 | */ |
579 | cpus_andnot(new_map, cpu_present_map, tmp_map); | 586 | cpumask_andnot(new_map, cpu_present_mask, tmp_map); |
580 | if (cpus_empty(new_map)) { | 587 | if (cpumask_empty(new_map)) { |
581 | printk ("Unable to map lapic to logical cpu number\n"); | 588 | printk ("Unable to map lapic to logical cpu number\n"); |
582 | return -EINVAL; | 589 | retval = -EINVAL; |
590 | goto free_new_map; | ||
583 | } | 591 | } |
584 | 592 | ||
585 | cpu = first_cpu(new_map); | 593 | cpu = cpumask_first(new_map); |
586 | 594 | ||
587 | *pcpu = cpu; | 595 | *pcpu = cpu; |
588 | return 0; | 596 | retval = 0; |
597 | |||
598 | free_new_map: | ||
599 | free_cpumask_var(new_map); | ||
600 | free_tmp_map: | ||
601 | free_cpumask_var(tmp_map); | ||
602 | out: | ||
603 | return retval; | ||
589 | } | 604 | } |
590 | 605 | ||
591 | /* wrapper to silence section mismatch warning */ | 606 | /* wrapper to silence section mismatch warning */ |
@@ -598,7 +613,7 @@ EXPORT_SYMBOL(acpi_map_lsapic); | |||
598 | int acpi_unmap_lsapic(int cpu) | 613 | int acpi_unmap_lsapic(int cpu) |
599 | { | 614 | { |
600 | per_cpu(x86_cpu_to_apicid, cpu) = -1; | 615 | per_cpu(x86_cpu_to_apicid, cpu) = -1; |
601 | cpu_clear(cpu, cpu_present_map); | 616 | set_cpu_present(cpu, false); |
602 | num_processors--; | 617 | num_processors--; |
603 | 618 | ||
604 | return (0); | 619 | return (0); |
@@ -1371,6 +1386,17 @@ static void __init acpi_process_madt(void) | |||
1371 | smp_found_config = 0; | 1386 | smp_found_config = 0; |
1372 | } | 1387 | } |
1373 | } | 1388 | } |
1389 | |||
1390 | /* | ||
1391 | * ACPI supports both logical (e.g. Hyper-Threading) and physical | ||
1392 | * processors, where MPS only supports physical. | ||
1393 | */ | ||
1394 | if (acpi_lapic && acpi_ioapic) | ||
1395 | printk(KERN_INFO "Using ACPI (MADT) for SMP configuration " | ||
1396 | "information\n"); | ||
1397 | else if (acpi_lapic) | ||
1398 | printk(KERN_INFO "Using ACPI for processor (LAPIC) " | ||
1399 | "configuration information\n"); | ||
1374 | #endif | 1400 | #endif |
1375 | return; | 1401 | return; |
1376 | } | 1402 | } |
diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c index 0a60d60ed036..5113c080f0c4 100644 --- a/arch/x86/kernel/amd_iommu.c +++ b/arch/x86/kernel/amd_iommu.c | |||
@@ -20,10 +20,15 @@ | |||
20 | #include <linux/pci.h> | 20 | #include <linux/pci.h> |
21 | #include <linux/gfp.h> | 21 | #include <linux/gfp.h> |
22 | #include <linux/bitops.h> | 22 | #include <linux/bitops.h> |
23 | #include <linux/debugfs.h> | ||
23 | #include <linux/scatterlist.h> | 24 | #include <linux/scatterlist.h> |
24 | #include <linux/iommu-helper.h> | 25 | #include <linux/iommu-helper.h> |
26 | #ifdef CONFIG_IOMMU_API | ||
27 | #include <linux/iommu.h> | ||
28 | #endif | ||
25 | #include <asm/proto.h> | 29 | #include <asm/proto.h> |
26 | #include <asm/iommu.h> | 30 | #include <asm/iommu.h> |
31 | #include <asm/gart.h> | ||
27 | #include <asm/amd_iommu_types.h> | 32 | #include <asm/amd_iommu_types.h> |
28 | #include <asm/amd_iommu.h> | 33 | #include <asm/amd_iommu.h> |
29 | 34 | ||
@@ -37,6 +42,10 @@ static DEFINE_RWLOCK(amd_iommu_devtable_lock); | |||
37 | static LIST_HEAD(iommu_pd_list); | 42 | static LIST_HEAD(iommu_pd_list); |
38 | static DEFINE_SPINLOCK(iommu_pd_list_lock); | 43 | static DEFINE_SPINLOCK(iommu_pd_list_lock); |
39 | 44 | ||
45 | #ifdef CONFIG_IOMMU_API | ||
46 | static struct iommu_ops amd_iommu_ops; | ||
47 | #endif | ||
48 | |||
40 | /* | 49 | /* |
41 | * general struct to manage commands send to an IOMMU | 50 | * general struct to manage commands send to an IOMMU |
42 | */ | 51 | */ |
@@ -46,6 +55,68 @@ struct iommu_cmd { | |||
46 | 55 | ||
47 | static int dma_ops_unity_map(struct dma_ops_domain *dma_dom, | 56 | static int dma_ops_unity_map(struct dma_ops_domain *dma_dom, |
48 | struct unity_map_entry *e); | 57 | struct unity_map_entry *e); |
58 | static struct dma_ops_domain *find_protection_domain(u16 devid); | ||
59 | |||
60 | |||
61 | #ifdef CONFIG_AMD_IOMMU_STATS | ||
62 | |||
63 | /* | ||
64 | * Initialization code for statistics collection | ||
65 | */ | ||
66 | |||
67 | DECLARE_STATS_COUNTER(compl_wait); | ||
68 | DECLARE_STATS_COUNTER(cnt_map_single); | ||
69 | DECLARE_STATS_COUNTER(cnt_unmap_single); | ||
70 | DECLARE_STATS_COUNTER(cnt_map_sg); | ||
71 | DECLARE_STATS_COUNTER(cnt_unmap_sg); | ||
72 | DECLARE_STATS_COUNTER(cnt_alloc_coherent); | ||
73 | DECLARE_STATS_COUNTER(cnt_free_coherent); | ||
74 | DECLARE_STATS_COUNTER(cross_page); | ||
75 | DECLARE_STATS_COUNTER(domain_flush_single); | ||
76 | DECLARE_STATS_COUNTER(domain_flush_all); | ||
77 | DECLARE_STATS_COUNTER(alloced_io_mem); | ||
78 | DECLARE_STATS_COUNTER(total_map_requests); | ||
79 | |||
80 | static struct dentry *stats_dir; | ||
81 | static struct dentry *de_isolate; | ||
82 | static struct dentry *de_fflush; | ||
83 | |||
84 | static void amd_iommu_stats_add(struct __iommu_counter *cnt) | ||
85 | { | ||
86 | if (stats_dir == NULL) | ||
87 | return; | ||
88 | |||
89 | cnt->dent = debugfs_create_u64(cnt->name, 0444, stats_dir, | ||
90 | &cnt->value); | ||
91 | } | ||
92 | |||
93 | static void amd_iommu_stats_init(void) | ||
94 | { | ||
95 | stats_dir = debugfs_create_dir("amd-iommu", NULL); | ||
96 | if (stats_dir == NULL) | ||
97 | return; | ||
98 | |||
99 | de_isolate = debugfs_create_bool("isolation", 0444, stats_dir, | ||
100 | (u32 *)&amd_iommu_isolate); | ||
101 | |||
102 | de_fflush = debugfs_create_bool("fullflush", 0444, stats_dir, | ||
103 | (u32 *)&amd_iommu_unmap_flush); | ||
104 | |||
105 | amd_iommu_stats_add(&compl_wait); | ||
106 | amd_iommu_stats_add(&cnt_map_single); | ||
107 | amd_iommu_stats_add(&cnt_unmap_single); | ||
108 | amd_iommu_stats_add(&cnt_map_sg); | ||
109 | amd_iommu_stats_add(&cnt_unmap_sg); | ||
110 | amd_iommu_stats_add(&cnt_alloc_coherent); | ||
111 | amd_iommu_stats_add(&cnt_free_coherent); | ||
112 | amd_iommu_stats_add(&cross_page); | ||
113 | amd_iommu_stats_add(&domain_flush_single); | ||
114 | amd_iommu_stats_add(&domain_flush_all); | ||
115 | amd_iommu_stats_add(&alloced_io_mem); | ||
116 | amd_iommu_stats_add(&total_map_requests); | ||
117 | } | ||
118 | |||
119 | #endif | ||
49 | 120 | ||
50 | /* returns !0 if the IOMMU is caching non-present entries in its TLB */ | 121 | /* returns !0 if the IOMMU is caching non-present entries in its TLB */ |
51 | static int iommu_has_npcache(struct amd_iommu *iommu) | 122 | static int iommu_has_npcache(struct amd_iommu *iommu) |
@@ -188,13 +259,55 @@ static int iommu_queue_command(struct amd_iommu *iommu, struct iommu_cmd *cmd) | |||
188 | spin_lock_irqsave(&iommu->lock, flags); | 259 | spin_lock_irqsave(&iommu->lock, flags); |
189 | ret = __iommu_queue_command(iommu, cmd); | 260 | ret = __iommu_queue_command(iommu, cmd); |
190 | if (!ret) | 261 | if (!ret) |
191 | iommu->need_sync = 1; | 262 | iommu->need_sync = true; |
192 | spin_unlock_irqrestore(&iommu->lock, flags); | 263 | spin_unlock_irqrestore(&iommu->lock, flags); |
193 | 264 | ||
194 | return ret; | 265 | return ret; |
195 | } | 266 | } |
196 | 267 | ||
197 | /* | 268 | /* |
269 | * This function waits until an IOMMU has completed a completion | ||
270 | * wait command | ||
271 | */ | ||
272 | static void __iommu_wait_for_completion(struct amd_iommu *iommu) | ||
273 | { | ||
274 | int ready = 0; | ||
275 | unsigned status = 0; | ||
276 | unsigned long i = 0; | ||
277 | |||
278 | INC_STATS_COUNTER(compl_wait); | ||
279 | |||
280 | while (!ready && (i < EXIT_LOOP_COUNT)) { | ||
281 | ++i; | ||
282 | /* wait for the bit to become one */ | ||
283 | status = readl(iommu->mmio_base + MMIO_STATUS_OFFSET); | ||
284 | ready = status & MMIO_STATUS_COM_WAIT_INT_MASK; | ||
285 | } | ||
286 | |||
287 | /* set bit back to zero */ | ||
288 | status &= ~MMIO_STATUS_COM_WAIT_INT_MASK; | ||
289 | writel(status, iommu->mmio_base + MMIO_STATUS_OFFSET); | ||
290 | |||
291 | if (unlikely(i == EXIT_LOOP_COUNT)) | ||
292 | panic("AMD IOMMU: Completion wait loop failed\n"); | ||
293 | } | ||
294 | |||
295 | /* | ||
296 | * This function queues a completion wait command into the command | ||
297 | * buffer of an IOMMU | ||
298 | */ | ||
299 | static int __iommu_completion_wait(struct amd_iommu *iommu) | ||
300 | { | ||
301 | struct iommu_cmd cmd; | ||
302 | |||
303 | memset(&cmd, 0, sizeof(cmd)); | ||
304 | cmd.data[0] = CMD_COMPL_WAIT_INT_MASK; | ||
305 | CMD_SET_TYPE(&cmd, CMD_COMPL_WAIT); | ||
306 | |||
307 | return __iommu_queue_command(iommu, &cmd); | ||
308 | } | ||
309 | |||
310 | /* | ||
198 | * This function is called whenever we need to ensure that the IOMMU has | 311 | * This function is called whenever we need to ensure that the IOMMU has |
199 | * completed execution of all commands we sent. It sends a | 312 | * completed execution of all commands we sent. It sends a |
200 | * COMPLETION_WAIT command and waits for it to finish. The IOMMU informs | 313 | * COMPLETION_WAIT command and waits for it to finish. The IOMMU informs |
@@ -203,40 +316,22 @@ static int iommu_queue_command(struct amd_iommu *iommu, struct iommu_cmd *cmd) | |||
203 | */ | 316 | */ |
204 | static int iommu_completion_wait(struct amd_iommu *iommu) | 317 | static int iommu_completion_wait(struct amd_iommu *iommu) |
205 | { | 318 | { |
206 | int ret = 0, ready = 0; | 319 | int ret = 0; |
207 | unsigned status = 0; | 320 | unsigned long flags; |
208 | struct iommu_cmd cmd; | ||
209 | unsigned long flags, i = 0; | ||
210 | |||
211 | memset(&cmd, 0, sizeof(cmd)); | ||
212 | cmd.data[0] = CMD_COMPL_WAIT_INT_MASK; | ||
213 | CMD_SET_TYPE(&cmd, CMD_COMPL_WAIT); | ||
214 | 321 | ||
215 | spin_lock_irqsave(&iommu->lock, flags); | 322 | spin_lock_irqsave(&iommu->lock, flags); |
216 | 323 | ||
217 | if (!iommu->need_sync) | 324 | if (!iommu->need_sync) |
218 | goto out; | 325 | goto out; |
219 | 326 | ||
220 | iommu->need_sync = 0; | 327 | ret = __iommu_completion_wait(iommu); |
221 | 328 | ||
222 | ret = __iommu_queue_command(iommu, &cmd); | 329 | iommu->need_sync = false; |
223 | 330 | ||
224 | if (ret) | 331 | if (ret) |
225 | goto out; | 332 | goto out; |
226 | 333 | ||
227 | while (!ready && (i < EXIT_LOOP_COUNT)) { | 334 | __iommu_wait_for_completion(iommu); |
228 | ++i; | ||
229 | /* wait for the bit to become one */ | ||
230 | status = readl(iommu->mmio_base + MMIO_STATUS_OFFSET); | ||
231 | ready = status & MMIO_STATUS_COM_WAIT_INT_MASK; | ||
232 | } | ||
233 | |||
234 | /* set bit back to zero */ | ||
235 | status &= ~MMIO_STATUS_COM_WAIT_INT_MASK; | ||
236 | writel(status, iommu->mmio_base + MMIO_STATUS_OFFSET); | ||
237 | |||
238 | if (unlikely(i == EXIT_LOOP_COUNT)) | ||
239 | panic("AMD IOMMU: Completion wait loop failed\n"); | ||
240 | 335 | ||
241 | out: | 336 | out: |
242 | spin_unlock_irqrestore(&iommu->lock, flags); | 337 | spin_unlock_irqrestore(&iommu->lock, flags); |
@@ -263,6 +358,21 @@ static int iommu_queue_inv_dev_entry(struct amd_iommu *iommu, u16 devid) | |||
263 | return ret; | 358 | return ret; |
264 | } | 359 | } |
265 | 360 | ||
361 | static void __iommu_build_inv_iommu_pages(struct iommu_cmd *cmd, u64 address, | ||
362 | u16 domid, int pde, int s) | ||
363 | { | ||
364 | memset(cmd, 0, sizeof(*cmd)); | ||
365 | address &= PAGE_MASK; | ||
366 | CMD_SET_TYPE(cmd, CMD_INV_IOMMU_PAGES); | ||
367 | cmd->data[1] |= domid; | ||
368 | cmd->data[2] = lower_32_bits(address); | ||
369 | cmd->data[3] = upper_32_bits(address); | ||
370 | if (s) /* size bit - we flush more than one 4kb page */ | ||
371 | cmd->data[2] |= CMD_INV_IOMMU_PAGES_SIZE_MASK; | ||
372 | if (pde) /* PDE bit - we wan't flush everything not only the PTEs */ | ||
373 | cmd->data[2] |= CMD_INV_IOMMU_PAGES_PDE_MASK; | ||
374 | } | ||
375 | |||
266 | /* | 376 | /* |
267 | * Generic command send function for invalidaing TLB entries | 377 | * Generic command send function for invalidaing TLB entries |
268 | */ | 378 | */ |
@@ -272,16 +382,7 @@ static int iommu_queue_inv_iommu_pages(struct amd_iommu *iommu, | |||
272 | struct iommu_cmd cmd; | 382 | struct iommu_cmd cmd; |
273 | int ret; | 383 | int ret; |
274 | 384 | ||
275 | memset(&cmd, 0, sizeof(cmd)); | 385 | __iommu_build_inv_iommu_pages(&cmd, address, domid, pde, s); |
276 | address &= PAGE_MASK; | ||
277 | CMD_SET_TYPE(&cmd, CMD_INV_IOMMU_PAGES); | ||
278 | cmd.data[1] |= domid; | ||
279 | cmd.data[2] = lower_32_bits(address); | ||
280 | cmd.data[3] = upper_32_bits(address); | ||
281 | if (s) /* size bit - we flush more than one 4kb page */ | ||
282 | cmd.data[2] |= CMD_INV_IOMMU_PAGES_SIZE_MASK; | ||
283 | if (pde) /* PDE bit - we wan't flush everything not only the PTEs */ | ||
284 | cmd.data[2] |= CMD_INV_IOMMU_PAGES_PDE_MASK; | ||
285 | 386 | ||
286 | ret = iommu_queue_command(iommu, &cmd); | 387 | ret = iommu_queue_command(iommu, &cmd); |
287 | 388 | ||
@@ -320,9 +421,35 @@ static void iommu_flush_tlb(struct amd_iommu *iommu, u16 domid) | |||
320 | { | 421 | { |
321 | u64 address = CMD_INV_IOMMU_ALL_PAGES_ADDRESS; | 422 | u64 address = CMD_INV_IOMMU_ALL_PAGES_ADDRESS; |
322 | 423 | ||
424 | INC_STATS_COUNTER(domain_flush_single); | ||
425 | |||
323 | iommu_queue_inv_iommu_pages(iommu, address, domid, 0, 1); | 426 | iommu_queue_inv_iommu_pages(iommu, address, domid, 0, 1); |
324 | } | 427 | } |
325 | 428 | ||
429 | /* | ||
430 | * This function is used to flush the IO/TLB for a given protection domain | ||
431 | * on every IOMMU in the system | ||
432 | */ | ||
433 | static void iommu_flush_domain(u16 domid) | ||
434 | { | ||
435 | unsigned long flags; | ||
436 | struct amd_iommu *iommu; | ||
437 | struct iommu_cmd cmd; | ||
438 | |||
439 | INC_STATS_COUNTER(domain_flush_all); | ||
440 | |||
441 | __iommu_build_inv_iommu_pages(&cmd, CMD_INV_IOMMU_ALL_PAGES_ADDRESS, | ||
442 | domid, 1, 1); | ||
443 | |||
444 | list_for_each_entry(iommu, &amd_iommu_list, list) { | ||
445 | spin_lock_irqsave(&iommu->lock, flags); | ||
446 | __iommu_queue_command(iommu, &cmd); | ||
447 | __iommu_completion_wait(iommu); | ||
448 | __iommu_wait_for_completion(iommu); | ||
449 | spin_unlock_irqrestore(&iommu->lock, flags); | ||
450 | } | ||
451 | } | ||
452 | |||
326 | /**************************************************************************** | 453 | /**************************************************************************** |
327 | * | 454 | * |
328 | * The functions below are used the create the page table mappings for | 455 | * The functions below are used the create the page table mappings for |
@@ -337,10 +464,10 @@ static void iommu_flush_tlb(struct amd_iommu *iommu, u16 domid) | |||
337 | * supporting all features of AMD IOMMU page tables like level skipping | 464 | * supporting all features of AMD IOMMU page tables like level skipping |
338 | * and full 64 bit address spaces. | 465 | * and full 64 bit address spaces. |
339 | */ | 466 | */ |
340 | static int iommu_map(struct protection_domain *dom, | 467 | static int iommu_map_page(struct protection_domain *dom, |
341 | unsigned long bus_addr, | 468 | unsigned long bus_addr, |
342 | unsigned long phys_addr, | 469 | unsigned long phys_addr, |
343 | int prot) | 470 | int prot) |
344 | { | 471 | { |
345 | u64 __pte, *pte, *page; | 472 | u64 __pte, *pte, *page; |
346 | 473 | ||
@@ -387,6 +514,28 @@ static int iommu_map(struct protection_domain *dom, | |||
387 | return 0; | 514 | return 0; |
388 | } | 515 | } |
389 | 516 | ||
517 | static void iommu_unmap_page(struct protection_domain *dom, | ||
518 | unsigned long bus_addr) | ||
519 | { | ||
520 | u64 *pte; | ||
521 | |||
522 | pte = &dom->pt_root[IOMMU_PTE_L2_INDEX(bus_addr)]; | ||
523 | |||
524 | if (!IOMMU_PTE_PRESENT(*pte)) | ||
525 | return; | ||
526 | |||
527 | pte = IOMMU_PTE_PAGE(*pte); | ||
528 | pte = &pte[IOMMU_PTE_L1_INDEX(bus_addr)]; | ||
529 | |||
530 | if (!IOMMU_PTE_PRESENT(*pte)) | ||
531 | return; | ||
532 | |||
533 | pte = IOMMU_PTE_PAGE(*pte); | ||
534 | pte = &pte[IOMMU_PTE_L1_INDEX(bus_addr)]; | ||
535 | |||
536 | *pte = 0; | ||
537 | } | ||
538 | |||
390 | /* | 539 | /* |
391 | * This function checks if a specific unity mapping entry is needed for | 540 | * This function checks if a specific unity mapping entry is needed for |
392 | * this specific IOMMU. | 541 | * this specific IOMMU. |
@@ -439,7 +588,7 @@ static int dma_ops_unity_map(struct dma_ops_domain *dma_dom, | |||
439 | 588 | ||
440 | for (addr = e->address_start; addr < e->address_end; | 589 | for (addr = e->address_start; addr < e->address_end; |
441 | addr += PAGE_SIZE) { | 590 | addr += PAGE_SIZE) { |
442 | ret = iommu_map(&dma_dom->domain, addr, addr, e->prot); | 591 | ret = iommu_map_page(&dma_dom->domain, addr, addr, e->prot); |
443 | if (ret) | 592 | if (ret) |
444 | return ret; | 593 | return ret; |
445 | /* | 594 | /* |
@@ -570,6 +719,16 @@ static u16 domain_id_alloc(void) | |||
570 | return id; | 719 | return id; |
571 | } | 720 | } |
572 | 721 | ||
722 | static void domain_id_free(int id) | ||
723 | { | ||
724 | unsigned long flags; | ||
725 | |||
726 | write_lock_irqsave(&amd_iommu_devtable_lock, flags); | ||
727 | if (id > 0 && id < MAX_DOMAIN_ID) | ||
728 | __clear_bit(id, amd_iommu_pd_alloc_bitmap); | ||
729 | write_unlock_irqrestore(&amd_iommu_devtable_lock, flags); | ||
730 | } | ||
731 | |||
573 | /* | 732 | /* |
574 | * Used to reserve address ranges in the aperture (e.g. for exclusion | 733 | * Used to reserve address ranges in the aperture (e.g. for exclusion |
575 | * ranges. | 734 | * ranges. |
@@ -586,12 +745,12 @@ static void dma_ops_reserve_addresses(struct dma_ops_domain *dom, | |||
586 | iommu_area_reserve(dom->bitmap, start_page, pages); | 745 | iommu_area_reserve(dom->bitmap, start_page, pages); |
587 | } | 746 | } |
588 | 747 | ||
589 | static void dma_ops_free_pagetable(struct dma_ops_domain *dma_dom) | 748 | static void free_pagetable(struct protection_domain *domain) |
590 | { | 749 | { |
591 | int i, j; | 750 | int i, j; |
592 | u64 *p1, *p2, *p3; | 751 | u64 *p1, *p2, *p3; |
593 | 752 | ||
594 | p1 = dma_dom->domain.pt_root; | 753 | p1 = domain->pt_root; |
595 | 754 | ||
596 | if (!p1) | 755 | if (!p1) |
597 | return; | 756 | return; |
@@ -612,6 +771,8 @@ static void dma_ops_free_pagetable(struct dma_ops_domain *dma_dom) | |||
612 | } | 771 | } |
613 | 772 | ||
614 | free_page((unsigned long)p1); | 773 | free_page((unsigned long)p1); |
774 | |||
775 | domain->pt_root = NULL; | ||
615 | } | 776 | } |
616 | 777 | ||
617 | /* | 778 | /* |
@@ -623,7 +784,7 @@ static void dma_ops_domain_free(struct dma_ops_domain *dom) | |||
623 | if (!dom) | 784 | if (!dom) |
624 | return; | 785 | return; |
625 | 786 | ||
626 | dma_ops_free_pagetable(dom); | 787 | free_pagetable(&dom->domain); |
627 | 788 | ||
628 | kfree(dom->pte_pages); | 789 | kfree(dom->pte_pages); |
629 | 790 | ||
@@ -662,6 +823,7 @@ static struct dma_ops_domain *dma_ops_domain_alloc(struct amd_iommu *iommu, | |||
662 | goto free_dma_dom; | 823 | goto free_dma_dom; |
663 | dma_dom->domain.mode = PAGE_MODE_3_LEVEL; | 824 | dma_dom->domain.mode = PAGE_MODE_3_LEVEL; |
664 | dma_dom->domain.pt_root = (void *)get_zeroed_page(GFP_KERNEL); | 825 | dma_dom->domain.pt_root = (void *)get_zeroed_page(GFP_KERNEL); |
826 | dma_dom->domain.flags = PD_DMA_OPS_MASK; | ||
665 | dma_dom->domain.priv = dma_dom; | 827 | dma_dom->domain.priv = dma_dom; |
666 | if (!dma_dom->domain.pt_root) | 828 | if (!dma_dom->domain.pt_root) |
667 | goto free_dma_dom; | 829 | goto free_dma_dom; |
@@ -724,6 +886,15 @@ free_dma_dom: | |||
724 | } | 886 | } |
725 | 887 | ||
726 | /* | 888 | /* |
889 | * little helper function to check whether a given protection domain is a | ||
890 | * dma_ops domain | ||
891 | */ | ||
892 | static bool dma_ops_domain(struct protection_domain *domain) | ||
893 | { | ||
894 | return domain->flags & PD_DMA_OPS_MASK; | ||
895 | } | ||
896 | |||
897 | /* | ||
727 | * Find out the protection domain structure for a given PCI device. This | 898 | * Find out the protection domain structure for a given PCI device. This |
728 | * will give us the pointer to the page table root for example. | 899 | * will give us the pointer to the page table root for example. |
729 | */ | 900 | */ |
@@ -743,14 +914,15 @@ static struct protection_domain *domain_for_device(u16 devid) | |||
743 | * If a device is not yet associated with a domain, this function does | 914 | * If a device is not yet associated with a domain, this function does |
744 | * assigns it visible for the hardware | 915 | * assigns it visible for the hardware |
745 | */ | 916 | */ |
746 | static void set_device_domain(struct amd_iommu *iommu, | 917 | static void attach_device(struct amd_iommu *iommu, |
747 | struct protection_domain *domain, | 918 | struct protection_domain *domain, |
748 | u16 devid) | 919 | u16 devid) |
749 | { | 920 | { |
750 | unsigned long flags; | 921 | unsigned long flags; |
751 | |||
752 | u64 pte_root = virt_to_phys(domain->pt_root); | 922 | u64 pte_root = virt_to_phys(domain->pt_root); |
753 | 923 | ||
924 | domain->dev_cnt += 1; | ||
925 | |||
754 | pte_root |= (domain->mode & DEV_ENTRY_MODE_MASK) | 926 | pte_root |= (domain->mode & DEV_ENTRY_MODE_MASK) |
755 | << DEV_ENTRY_MODE_SHIFT; | 927 | << DEV_ENTRY_MODE_SHIFT; |
756 | pte_root |= IOMMU_PTE_IR | IOMMU_PTE_IW | IOMMU_PTE_P | IOMMU_PTE_TV; | 928 | pte_root |= IOMMU_PTE_IR | IOMMU_PTE_IW | IOMMU_PTE_P | IOMMU_PTE_TV; |
@@ -766,6 +938,116 @@ static void set_device_domain(struct amd_iommu *iommu, | |||
766 | iommu_queue_inv_dev_entry(iommu, devid); | 938 | iommu_queue_inv_dev_entry(iommu, devid); |
767 | } | 939 | } |
768 | 940 | ||
941 | /* | ||
942 | * Removes a device from a protection domain (unlocked) | ||
943 | */ | ||
944 | static void __detach_device(struct protection_domain *domain, u16 devid) | ||
945 | { | ||
946 | |||
947 | /* lock domain */ | ||
948 | spin_lock(&domain->lock); | ||
949 | |||
950 | /* remove domain from the lookup table */ | ||
951 | amd_iommu_pd_table[devid] = NULL; | ||
952 | |||
953 | /* remove entry from the device table seen by the hardware */ | ||
954 | amd_iommu_dev_table[devid].data[0] = IOMMU_PTE_P | IOMMU_PTE_TV; | ||
955 | amd_iommu_dev_table[devid].data[1] = 0; | ||
956 | amd_iommu_dev_table[devid].data[2] = 0; | ||
957 | |||
958 | /* decrease reference counter */ | ||
959 | domain->dev_cnt -= 1; | ||
960 | |||
961 | /* ready */ | ||
962 | spin_unlock(&domain->lock); | ||
963 | } | ||
964 | |||
965 | /* | ||
966 | * Removes a device from a protection domain (with devtable_lock held) | ||
967 | */ | ||
968 | static void detach_device(struct protection_domain *domain, u16 devid) | ||
969 | { | ||
970 | unsigned long flags; | ||
971 | |||
972 | /* lock device table */ | ||
973 | write_lock_irqsave(&amd_iommu_devtable_lock, flags); | ||
974 | __detach_device(domain, devid); | ||
975 | write_unlock_irqrestore(&amd_iommu_devtable_lock, flags); | ||
976 | } | ||
977 | |||
978 | static int device_change_notifier(struct notifier_block *nb, | ||
979 | unsigned long action, void *data) | ||
980 | { | ||
981 | struct device *dev = data; | ||
982 | struct pci_dev *pdev = to_pci_dev(dev); | ||
983 | u16 devid = calc_devid(pdev->bus->number, pdev->devfn); | ||
984 | struct protection_domain *domain; | ||
985 | struct dma_ops_domain *dma_domain; | ||
986 | struct amd_iommu *iommu; | ||
987 | int order = amd_iommu_aperture_order; | ||
988 | unsigned long flags; | ||
989 | |||
990 | if (devid > amd_iommu_last_bdf) | ||
991 | goto out; | ||
992 | |||
993 | devid = amd_iommu_alias_table[devid]; | ||
994 | |||
995 | iommu = amd_iommu_rlookup_table[devid]; | ||
996 | if (iommu == NULL) | ||
997 | goto out; | ||
998 | |||
999 | domain = domain_for_device(devid); | ||
1000 | |||
1001 | if (domain && !dma_ops_domain(domain)) | ||
1002 | WARN_ONCE(1, "AMD IOMMU WARNING: device %s already bound " | ||
1003 | "to a non-dma-ops domain\n", dev_name(dev)); | ||
1004 | |||
1005 | switch (action) { | ||
1006 | case BUS_NOTIFY_BOUND_DRIVER: | ||
1007 | if (domain) | ||
1008 | goto out; | ||
1009 | dma_domain = find_protection_domain(devid); | ||
1010 | if (!dma_domain) | ||
1011 | dma_domain = iommu->default_dom; | ||
1012 | attach_device(iommu, &dma_domain->domain, devid); | ||
1013 | printk(KERN_INFO "AMD IOMMU: Using protection domain %d for " | ||
1014 | "device %s\n", dma_domain->domain.id, dev_name(dev)); | ||
1015 | break; | ||
1016 | case BUS_NOTIFY_UNBIND_DRIVER: | ||
1017 | if (!domain) | ||
1018 | goto out; | ||
1019 | detach_device(domain, devid); | ||
1020 | break; | ||
1021 | case BUS_NOTIFY_ADD_DEVICE: | ||
1022 | /* allocate a protection domain if a device is added */ | ||
1023 | dma_domain = find_protection_domain(devid); | ||
1024 | if (dma_domain) | ||
1025 | goto out; | ||
1026 | dma_domain = dma_ops_domain_alloc(iommu, order); | ||
1027 | if (!dma_domain) | ||
1028 | goto out; | ||
1029 | dma_domain->target_dev = devid; | ||
1030 | |||
1031 | spin_lock_irqsave(&iommu_pd_list_lock, flags); | ||
1032 | list_add_tail(&dma_domain->list, &iommu_pd_list); | ||
1033 | spin_unlock_irqrestore(&iommu_pd_list_lock, flags); | ||
1034 | |||
1035 | break; | ||
1036 | default: | ||
1037 | goto out; | ||
1038 | } | ||
1039 | |||
1040 | iommu_queue_inv_dev_entry(iommu, devid); | ||
1041 | iommu_completion_wait(iommu); | ||
1042 | |||
1043 | out: | ||
1044 | return 0; | ||
1045 | } | ||
1046 | |||
1047 | struct notifier_block device_nb = { | ||
1048 | .notifier_call = device_change_notifier, | ||
1049 | }; | ||
1050 | |||
769 | /***************************************************************************** | 1051 | /***************************************************************************** |
770 | * | 1052 | * |
771 | * The next functions belong to the dma_ops mapping/unmapping code. | 1053 | * The next functions belong to the dma_ops mapping/unmapping code. |
@@ -801,7 +1083,6 @@ static struct dma_ops_domain *find_protection_domain(u16 devid) | |||
801 | list_for_each_entry(entry, &iommu_pd_list, list) { | 1083 | list_for_each_entry(entry, &iommu_pd_list, list) { |
802 | if (entry->target_dev == devid) { | 1084 | if (entry->target_dev == devid) { |
803 | ret = entry; | 1085 | ret = entry; |
804 | list_del(&ret->list); | ||
805 | break; | 1086 | break; |
806 | } | 1087 | } |
807 | } | 1088 | } |
@@ -852,14 +1133,13 @@ static int get_device_resources(struct device *dev, | |||
852 | if (!dma_dom) | 1133 | if (!dma_dom) |
853 | dma_dom = (*iommu)->default_dom; | 1134 | dma_dom = (*iommu)->default_dom; |
854 | *domain = &dma_dom->domain; | 1135 | *domain = &dma_dom->domain; |
855 | set_device_domain(*iommu, *domain, *bdf); | 1136 | attach_device(*iommu, *domain, *bdf); |
856 | printk(KERN_INFO "AMD IOMMU: Using protection domain %d for " | 1137 | printk(KERN_INFO "AMD IOMMU: Using protection domain %d for " |
857 | "device ", (*domain)->id); | 1138 | "device %s\n", (*domain)->id, dev_name(dev)); |
858 | print_devid(_bdf, 1); | ||
859 | } | 1139 | } |
860 | 1140 | ||
861 | if (domain_for_device(_bdf) == NULL) | 1141 | if (domain_for_device(_bdf) == NULL) |
862 | set_device_domain(*iommu, *domain, _bdf); | 1142 | attach_device(*iommu, *domain, _bdf); |
863 | 1143 | ||
864 | return 1; | 1144 | return 1; |
865 | } | 1145 | } |
@@ -945,6 +1225,11 @@ static dma_addr_t __map_single(struct device *dev, | |||
945 | pages = iommu_num_pages(paddr, size, PAGE_SIZE); | 1225 | pages = iommu_num_pages(paddr, size, PAGE_SIZE); |
946 | paddr &= PAGE_MASK; | 1226 | paddr &= PAGE_MASK; |
947 | 1227 | ||
1228 | INC_STATS_COUNTER(total_map_requests); | ||
1229 | |||
1230 | if (pages > 1) | ||
1231 | INC_STATS_COUNTER(cross_page); | ||
1232 | |||
948 | if (align) | 1233 | if (align) |
949 | align_mask = (1UL << get_order(size)) - 1; | 1234 | align_mask = (1UL << get_order(size)) - 1; |
950 | 1235 | ||
@@ -961,6 +1246,8 @@ static dma_addr_t __map_single(struct device *dev, | |||
961 | } | 1246 | } |
962 | address += offset; | 1247 | address += offset; |
963 | 1248 | ||
1249 | ADD_STATS_COUNTER(alloced_io_mem, size); | ||
1250 | |||
964 | if (unlikely(dma_dom->need_flush && !amd_iommu_unmap_flush)) { | 1251 | if (unlikely(dma_dom->need_flush && !amd_iommu_unmap_flush)) { |
965 | iommu_flush_tlb(iommu, dma_dom->domain.id); | 1252 | iommu_flush_tlb(iommu, dma_dom->domain.id); |
966 | dma_dom->need_flush = false; | 1253 | dma_dom->need_flush = false; |
@@ -997,6 +1284,8 @@ static void __unmap_single(struct amd_iommu *iommu, | |||
997 | start += PAGE_SIZE; | 1284 | start += PAGE_SIZE; |
998 | } | 1285 | } |
999 | 1286 | ||
1287 | SUB_STATS_COUNTER(alloced_io_mem, size); | ||
1288 | |||
1000 | dma_ops_free_addresses(dma_dom, dma_addr, pages); | 1289 | dma_ops_free_addresses(dma_dom, dma_addr, pages); |
1001 | 1290 | ||
1002 | if (amd_iommu_unmap_flush || dma_dom->need_flush) { | 1291 | if (amd_iommu_unmap_flush || dma_dom->need_flush) { |
@@ -1018,6 +1307,8 @@ static dma_addr_t map_single(struct device *dev, phys_addr_t paddr, | |||
1018 | dma_addr_t addr; | 1307 | dma_addr_t addr; |
1019 | u64 dma_mask; | 1308 | u64 dma_mask; |
1020 | 1309 | ||
1310 | INC_STATS_COUNTER(cnt_map_single); | ||
1311 | |||
1021 | if (!check_device(dev)) | 1312 | if (!check_device(dev)) |
1022 | return bad_dma_address; | 1313 | return bad_dma_address; |
1023 | 1314 | ||
@@ -1029,6 +1320,9 @@ static dma_addr_t map_single(struct device *dev, phys_addr_t paddr, | |||
1029 | /* device not handled by any AMD IOMMU */ | 1320 | /* device not handled by any AMD IOMMU */ |
1030 | return (dma_addr_t)paddr; | 1321 | return (dma_addr_t)paddr; |
1031 | 1322 | ||
1323 | if (!dma_ops_domain(domain)) | ||
1324 | return bad_dma_address; | ||
1325 | |||
1032 | spin_lock_irqsave(&domain->lock, flags); | 1326 | spin_lock_irqsave(&domain->lock, flags); |
1033 | addr = __map_single(dev, iommu, domain->priv, paddr, size, dir, false, | 1327 | addr = __map_single(dev, iommu, domain->priv, paddr, size, dir, false, |
1034 | dma_mask); | 1328 | dma_mask); |
@@ -1054,11 +1348,16 @@ static void unmap_single(struct device *dev, dma_addr_t dma_addr, | |||
1054 | struct protection_domain *domain; | 1348 | struct protection_domain *domain; |
1055 | u16 devid; | 1349 | u16 devid; |
1056 | 1350 | ||
1351 | INC_STATS_COUNTER(cnt_unmap_single); | ||
1352 | |||
1057 | if (!check_device(dev) || | 1353 | if (!check_device(dev) || |
1058 | !get_device_resources(dev, &iommu, &domain, &devid)) | 1354 | !get_device_resources(dev, &iommu, &domain, &devid)) |
1059 | /* device not handled by any AMD IOMMU */ | 1355 | /* device not handled by any AMD IOMMU */ |
1060 | return; | 1356 | return; |
1061 | 1357 | ||
1358 | if (!dma_ops_domain(domain)) | ||
1359 | return; | ||
1360 | |||
1062 | spin_lock_irqsave(&domain->lock, flags); | 1361 | spin_lock_irqsave(&domain->lock, flags); |
1063 | 1362 | ||
1064 | __unmap_single(iommu, domain->priv, dma_addr, size, dir); | 1363 | __unmap_single(iommu, domain->priv, dma_addr, size, dir); |
@@ -1103,6 +1402,8 @@ static int map_sg(struct device *dev, struct scatterlist *sglist, | |||
1103 | int mapped_elems = 0; | 1402 | int mapped_elems = 0; |
1104 | u64 dma_mask; | 1403 | u64 dma_mask; |
1105 | 1404 | ||
1405 | INC_STATS_COUNTER(cnt_map_sg); | ||
1406 | |||
1106 | if (!check_device(dev)) | 1407 | if (!check_device(dev)) |
1107 | return 0; | 1408 | return 0; |
1108 | 1409 | ||
@@ -1113,6 +1414,9 @@ static int map_sg(struct device *dev, struct scatterlist *sglist, | |||
1113 | if (!iommu || !domain) | 1414 | if (!iommu || !domain) |
1114 | return map_sg_no_iommu(dev, sglist, nelems, dir); | 1415 | return map_sg_no_iommu(dev, sglist, nelems, dir); |
1115 | 1416 | ||
1417 | if (!dma_ops_domain(domain)) | ||
1418 | return 0; | ||
1419 | |||
1116 | spin_lock_irqsave(&domain->lock, flags); | 1420 | spin_lock_irqsave(&domain->lock, flags); |
1117 | 1421 | ||
1118 | for_each_sg(sglist, s, nelems, i) { | 1422 | for_each_sg(sglist, s, nelems, i) { |
@@ -1162,10 +1466,15 @@ static void unmap_sg(struct device *dev, struct scatterlist *sglist, | |||
1162 | u16 devid; | 1466 | u16 devid; |
1163 | int i; | 1467 | int i; |
1164 | 1468 | ||
1469 | INC_STATS_COUNTER(cnt_unmap_sg); | ||
1470 | |||
1165 | if (!check_device(dev) || | 1471 | if (!check_device(dev) || |
1166 | !get_device_resources(dev, &iommu, &domain, &devid)) | 1472 | !get_device_resources(dev, &iommu, &domain, &devid)) |
1167 | return; | 1473 | return; |
1168 | 1474 | ||
1475 | if (!dma_ops_domain(domain)) | ||
1476 | return; | ||
1477 | |||
1169 | spin_lock_irqsave(&domain->lock, flags); | 1478 | spin_lock_irqsave(&domain->lock, flags); |
1170 | 1479 | ||
1171 | for_each_sg(sglist, s, nelems, i) { | 1480 | for_each_sg(sglist, s, nelems, i) { |
@@ -1193,6 +1502,8 @@ static void *alloc_coherent(struct device *dev, size_t size, | |||
1193 | phys_addr_t paddr; | 1502 | phys_addr_t paddr; |
1194 | u64 dma_mask = dev->coherent_dma_mask; | 1503 | u64 dma_mask = dev->coherent_dma_mask; |
1195 | 1504 | ||
1505 | INC_STATS_COUNTER(cnt_alloc_coherent); | ||
1506 | |||
1196 | if (!check_device(dev)) | 1507 | if (!check_device(dev)) |
1197 | return NULL; | 1508 | return NULL; |
1198 | 1509 | ||
@@ -1211,6 +1522,9 @@ static void *alloc_coherent(struct device *dev, size_t size, | |||
1211 | return virt_addr; | 1522 | return virt_addr; |
1212 | } | 1523 | } |
1213 | 1524 | ||
1525 | if (!dma_ops_domain(domain)) | ||
1526 | goto out_free; | ||
1527 | |||
1214 | if (!dma_mask) | 1528 | if (!dma_mask) |
1215 | dma_mask = *dev->dma_mask; | 1529 | dma_mask = *dev->dma_mask; |
1216 | 1530 | ||
@@ -1219,18 +1533,20 @@ static void *alloc_coherent(struct device *dev, size_t size, | |||
1219 | *dma_addr = __map_single(dev, iommu, domain->priv, paddr, | 1533 | *dma_addr = __map_single(dev, iommu, domain->priv, paddr, |
1220 | size, DMA_BIDIRECTIONAL, true, dma_mask); | 1534 | size, DMA_BIDIRECTIONAL, true, dma_mask); |
1221 | 1535 | ||
1222 | if (*dma_addr == bad_dma_address) { | 1536 | if (*dma_addr == bad_dma_address) |
1223 | free_pages((unsigned long)virt_addr, get_order(size)); | 1537 | goto out_free; |
1224 | virt_addr = NULL; | ||
1225 | goto out; | ||
1226 | } | ||
1227 | 1538 | ||
1228 | iommu_completion_wait(iommu); | 1539 | iommu_completion_wait(iommu); |
1229 | 1540 | ||
1230 | out: | ||
1231 | spin_unlock_irqrestore(&domain->lock, flags); | 1541 | spin_unlock_irqrestore(&domain->lock, flags); |
1232 | 1542 | ||
1233 | return virt_addr; | 1543 | return virt_addr; |
1544 | |||
1545 | out_free: | ||
1546 | |||
1547 | free_pages((unsigned long)virt_addr, get_order(size)); | ||
1548 | |||
1549 | return NULL; | ||
1234 | } | 1550 | } |
1235 | 1551 | ||
1236 | /* | 1552 | /* |
@@ -1244,6 +1560,8 @@ static void free_coherent(struct device *dev, size_t size, | |||
1244 | struct protection_domain *domain; | 1560 | struct protection_domain *domain; |
1245 | u16 devid; | 1561 | u16 devid; |
1246 | 1562 | ||
1563 | INC_STATS_COUNTER(cnt_free_coherent); | ||
1564 | |||
1247 | if (!check_device(dev)) | 1565 | if (!check_device(dev)) |
1248 | return; | 1566 | return; |
1249 | 1567 | ||
@@ -1252,6 +1570,9 @@ static void free_coherent(struct device *dev, size_t size, | |||
1252 | if (!iommu || !domain) | 1570 | if (!iommu || !domain) |
1253 | goto free_mem; | 1571 | goto free_mem; |
1254 | 1572 | ||
1573 | if (!dma_ops_domain(domain)) | ||
1574 | goto free_mem; | ||
1575 | |||
1255 | spin_lock_irqsave(&domain->lock, flags); | 1576 | spin_lock_irqsave(&domain->lock, flags); |
1256 | 1577 | ||
1257 | __unmap_single(iommu, domain->priv, dma_addr, size, DMA_BIDIRECTIONAL); | 1578 | __unmap_single(iommu, domain->priv, dma_addr, size, DMA_BIDIRECTIONAL); |
@@ -1295,7 +1616,7 @@ static int amd_iommu_dma_supported(struct device *dev, u64 mask) | |||
1295 | * we don't need to preallocate the protection domains anymore. | 1616 | * we don't need to preallocate the protection domains anymore. |
1296 | * For now we have to. | 1617 | * For now we have to. |
1297 | */ | 1618 | */ |
1298 | void prealloc_protection_domains(void) | 1619 | static void prealloc_protection_domains(void) |
1299 | { | 1620 | { |
1300 | struct pci_dev *dev = NULL; | 1621 | struct pci_dev *dev = NULL; |
1301 | struct dma_ops_domain *dma_dom; | 1622 | struct dma_ops_domain *dma_dom; |
@@ -1304,7 +1625,7 @@ void prealloc_protection_domains(void) | |||
1304 | u16 devid; | 1625 | u16 devid; |
1305 | 1626 | ||
1306 | while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { | 1627 | while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { |
1307 | devid = (dev->bus->number << 8) | dev->devfn; | 1628 | devid = calc_devid(dev->bus->number, dev->devfn); |
1308 | if (devid > amd_iommu_last_bdf) | 1629 | if (devid > amd_iommu_last_bdf) |
1309 | continue; | 1630 | continue; |
1310 | devid = amd_iommu_alias_table[devid]; | 1631 | devid = amd_iommu_alias_table[devid]; |
@@ -1351,6 +1672,7 @@ int __init amd_iommu_init_dma_ops(void) | |||
1351 | iommu->default_dom = dma_ops_domain_alloc(iommu, order); | 1672 | iommu->default_dom = dma_ops_domain_alloc(iommu, order); |
1352 | if (iommu->default_dom == NULL) | 1673 | if (iommu->default_dom == NULL) |
1353 | return -ENOMEM; | 1674 | return -ENOMEM; |
1675 | iommu->default_dom->domain.flags |= PD_DEFAULT_MASK; | ||
1354 | ret = iommu_init_unity_mappings(iommu); | 1676 | ret = iommu_init_unity_mappings(iommu); |
1355 | if (ret) | 1677 | if (ret) |
1356 | goto free_domains; | 1678 | goto free_domains; |
@@ -1374,6 +1696,12 @@ int __init amd_iommu_init_dma_ops(void) | |||
1374 | /* Make the driver finally visible to the drivers */ | 1696 | /* Make the driver finally visible to the drivers */ |
1375 | dma_ops = &amd_iommu_dma_ops; | 1697 | dma_ops = &amd_iommu_dma_ops; |
1376 | 1698 | ||
1699 | register_iommu(&amd_iommu_ops); | ||
1700 | |||
1701 | bus_register_notifier(&pci_bus_type, &device_nb); | ||
1702 | |||
1703 | amd_iommu_stats_init(); | ||
1704 | |||
1377 | return 0; | 1705 | return 0; |
1378 | 1706 | ||
1379 | free_domains: | 1707 | free_domains: |
@@ -1385,3 +1713,224 @@ free_domains: | |||
1385 | 1713 | ||
1386 | return ret; | 1714 | return ret; |
1387 | } | 1715 | } |
1716 | |||
1717 | /***************************************************************************** | ||
1718 | * | ||
1719 | * The following functions belong to the exported interface of AMD IOMMU | ||
1720 | * | ||
1721 | * This interface allows access to lower level functions of the IOMMU | ||
1722 | * like protection domain handling and assignement of devices to domains | ||
1723 | * which is not possible with the dma_ops interface. | ||
1724 | * | ||
1725 | *****************************************************************************/ | ||
1726 | |||
1727 | static void cleanup_domain(struct protection_domain *domain) | ||
1728 | { | ||
1729 | unsigned long flags; | ||
1730 | u16 devid; | ||
1731 | |||
1732 | write_lock_irqsave(&amd_iommu_devtable_lock, flags); | ||
1733 | |||
1734 | for (devid = 0; devid <= amd_iommu_last_bdf; ++devid) | ||
1735 | if (amd_iommu_pd_table[devid] == domain) | ||
1736 | __detach_device(domain, devid); | ||
1737 | |||
1738 | write_unlock_irqrestore(&amd_iommu_devtable_lock, flags); | ||
1739 | } | ||
1740 | |||
1741 | static int amd_iommu_domain_init(struct iommu_domain *dom) | ||
1742 | { | ||
1743 | struct protection_domain *domain; | ||
1744 | |||
1745 | domain = kzalloc(sizeof(*domain), GFP_KERNEL); | ||
1746 | if (!domain) | ||
1747 | return -ENOMEM; | ||
1748 | |||
1749 | spin_lock_init(&domain->lock); | ||
1750 | domain->mode = PAGE_MODE_3_LEVEL; | ||
1751 | domain->id = domain_id_alloc(); | ||
1752 | if (!domain->id) | ||
1753 | goto out_free; | ||
1754 | domain->pt_root = (void *)get_zeroed_page(GFP_KERNEL); | ||
1755 | if (!domain->pt_root) | ||
1756 | goto out_free; | ||
1757 | |||
1758 | dom->priv = domain; | ||
1759 | |||
1760 | return 0; | ||
1761 | |||
1762 | out_free: | ||
1763 | kfree(domain); | ||
1764 | |||
1765 | return -ENOMEM; | ||
1766 | } | ||
1767 | |||
1768 | static void amd_iommu_domain_destroy(struct iommu_domain *dom) | ||
1769 | { | ||
1770 | struct protection_domain *domain = dom->priv; | ||
1771 | |||
1772 | if (!domain) | ||
1773 | return; | ||
1774 | |||
1775 | if (domain->dev_cnt > 0) | ||
1776 | cleanup_domain(domain); | ||
1777 | |||
1778 | BUG_ON(domain->dev_cnt != 0); | ||
1779 | |||
1780 | free_pagetable(domain); | ||
1781 | |||
1782 | domain_id_free(domain->id); | ||
1783 | |||
1784 | kfree(domain); | ||
1785 | |||
1786 | dom->priv = NULL; | ||
1787 | } | ||
1788 | |||
1789 | static void amd_iommu_detach_device(struct iommu_domain *dom, | ||
1790 | struct device *dev) | ||
1791 | { | ||
1792 | struct protection_domain *domain = dom->priv; | ||
1793 | struct amd_iommu *iommu; | ||
1794 | struct pci_dev *pdev; | ||
1795 | u16 devid; | ||
1796 | |||
1797 | if (dev->bus != &pci_bus_type) | ||
1798 | return; | ||
1799 | |||
1800 | pdev = to_pci_dev(dev); | ||
1801 | |||
1802 | devid = calc_devid(pdev->bus->number, pdev->devfn); | ||
1803 | |||
1804 | if (devid > 0) | ||
1805 | detach_device(domain, devid); | ||
1806 | |||
1807 | iommu = amd_iommu_rlookup_table[devid]; | ||
1808 | if (!iommu) | ||
1809 | return; | ||
1810 | |||
1811 | iommu_queue_inv_dev_entry(iommu, devid); | ||
1812 | iommu_completion_wait(iommu); | ||
1813 | } | ||
1814 | |||
1815 | static int amd_iommu_attach_device(struct iommu_domain *dom, | ||
1816 | struct device *dev) | ||
1817 | { | ||
1818 | struct protection_domain *domain = dom->priv; | ||
1819 | struct protection_domain *old_domain; | ||
1820 | struct amd_iommu *iommu; | ||
1821 | struct pci_dev *pdev; | ||
1822 | u16 devid; | ||
1823 | |||
1824 | if (dev->bus != &pci_bus_type) | ||
1825 | return -EINVAL; | ||
1826 | |||
1827 | pdev = to_pci_dev(dev); | ||
1828 | |||
1829 | devid = calc_devid(pdev->bus->number, pdev->devfn); | ||
1830 | |||
1831 | if (devid >= amd_iommu_last_bdf || | ||
1832 | devid != amd_iommu_alias_table[devid]) | ||
1833 | return -EINVAL; | ||
1834 | |||
1835 | iommu = amd_iommu_rlookup_table[devid]; | ||
1836 | if (!iommu) | ||
1837 | return -EINVAL; | ||
1838 | |||
1839 | old_domain = domain_for_device(devid); | ||
1840 | if (old_domain) | ||
1841 | return -EBUSY; | ||
1842 | |||
1843 | attach_device(iommu, domain, devid); | ||
1844 | |||
1845 | iommu_completion_wait(iommu); | ||
1846 | |||
1847 | return 0; | ||
1848 | } | ||
1849 | |||
1850 | static int amd_iommu_map_range(struct iommu_domain *dom, | ||
1851 | unsigned long iova, phys_addr_t paddr, | ||
1852 | size_t size, int iommu_prot) | ||
1853 | { | ||
1854 | struct protection_domain *domain = dom->priv; | ||
1855 | unsigned long i, npages = iommu_num_pages(paddr, size, PAGE_SIZE); | ||
1856 | int prot = 0; | ||
1857 | int ret; | ||
1858 | |||
1859 | if (iommu_prot & IOMMU_READ) | ||
1860 | prot |= IOMMU_PROT_IR; | ||
1861 | if (iommu_prot & IOMMU_WRITE) | ||
1862 | prot |= IOMMU_PROT_IW; | ||
1863 | |||
1864 | iova &= PAGE_MASK; | ||
1865 | paddr &= PAGE_MASK; | ||
1866 | |||
1867 | for (i = 0; i < npages; ++i) { | ||
1868 | ret = iommu_map_page(domain, iova, paddr, prot); | ||
1869 | if (ret) | ||
1870 | return ret; | ||
1871 | |||
1872 | iova += PAGE_SIZE; | ||
1873 | paddr += PAGE_SIZE; | ||
1874 | } | ||
1875 | |||
1876 | return 0; | ||
1877 | } | ||
1878 | |||
1879 | static void amd_iommu_unmap_range(struct iommu_domain *dom, | ||
1880 | unsigned long iova, size_t size) | ||
1881 | { | ||
1882 | |||
1883 | struct protection_domain *domain = dom->priv; | ||
1884 | unsigned long i, npages = iommu_num_pages(iova, size, PAGE_SIZE); | ||
1885 | |||
1886 | iova &= PAGE_MASK; | ||
1887 | |||
1888 | for (i = 0; i < npages; ++i) { | ||
1889 | iommu_unmap_page(domain, iova); | ||
1890 | iova += PAGE_SIZE; | ||
1891 | } | ||
1892 | |||
1893 | iommu_flush_domain(domain->id); | ||
1894 | } | ||
1895 | |||
1896 | static phys_addr_t amd_iommu_iova_to_phys(struct iommu_domain *dom, | ||
1897 | unsigned long iova) | ||
1898 | { | ||
1899 | struct protection_domain *domain = dom->priv; | ||
1900 | unsigned long offset = iova & ~PAGE_MASK; | ||
1901 | phys_addr_t paddr; | ||
1902 | u64 *pte; | ||
1903 | |||
1904 | pte = &domain->pt_root[IOMMU_PTE_L2_INDEX(iova)]; | ||
1905 | |||
1906 | if (!IOMMU_PTE_PRESENT(*pte)) | ||
1907 | return 0; | ||
1908 | |||
1909 | pte = IOMMU_PTE_PAGE(*pte); | ||
1910 | pte = &pte[IOMMU_PTE_L1_INDEX(iova)]; | ||
1911 | |||
1912 | if (!IOMMU_PTE_PRESENT(*pte)) | ||
1913 | return 0; | ||
1914 | |||
1915 | pte = IOMMU_PTE_PAGE(*pte); | ||
1916 | pte = &pte[IOMMU_PTE_L0_INDEX(iova)]; | ||
1917 | |||
1918 | if (!IOMMU_PTE_PRESENT(*pte)) | ||
1919 | return 0; | ||
1920 | |||
1921 | paddr = *pte & IOMMU_PAGE_MASK; | ||
1922 | paddr |= offset; | ||
1923 | |||
1924 | return paddr; | ||
1925 | } | ||
1926 | |||
1927 | static struct iommu_ops amd_iommu_ops = { | ||
1928 | .domain_init = amd_iommu_domain_init, | ||
1929 | .domain_destroy = amd_iommu_domain_destroy, | ||
1930 | .attach_dev = amd_iommu_attach_device, | ||
1931 | .detach_dev = amd_iommu_detach_device, | ||
1932 | .map = amd_iommu_map_range, | ||
1933 | .unmap = amd_iommu_unmap_range, | ||
1934 | .iova_to_phys = amd_iommu_iova_to_phys, | ||
1935 | }; | ||
1936 | |||
diff --git a/arch/x86/kernel/amd_iommu_init.c b/arch/x86/kernel/amd_iommu_init.c index c6cc22815d35..42c33cebf00f 100644 --- a/arch/x86/kernel/amd_iommu_init.c +++ b/arch/x86/kernel/amd_iommu_init.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <asm/amd_iommu_types.h> | 28 | #include <asm/amd_iommu_types.h> |
29 | #include <asm/amd_iommu.h> | 29 | #include <asm/amd_iommu.h> |
30 | #include <asm/iommu.h> | 30 | #include <asm/iommu.h> |
31 | #include <asm/gart.h> | ||
31 | 32 | ||
32 | /* | 33 | /* |
33 | * definitions for the ACPI scanning code | 34 | * definitions for the ACPI scanning code |
@@ -121,7 +122,8 @@ u16 amd_iommu_last_bdf; /* largest PCI device id we have | |||
121 | LIST_HEAD(amd_iommu_unity_map); /* a list of required unity mappings | 122 | LIST_HEAD(amd_iommu_unity_map); /* a list of required unity mappings |
122 | we find in ACPI */ | 123 | we find in ACPI */ |
123 | unsigned amd_iommu_aperture_order = 26; /* size of aperture in power of 2 */ | 124 | unsigned amd_iommu_aperture_order = 26; /* size of aperture in power of 2 */ |
124 | int amd_iommu_isolate = 1; /* if 1, device isolation is enabled */ | 125 | bool amd_iommu_isolate = true; /* if true, device isolation is |
126 | enabled */ | ||
125 | bool amd_iommu_unmap_flush; /* if true, flush on every unmap */ | 127 | bool amd_iommu_unmap_flush; /* if true, flush on every unmap */ |
126 | 128 | ||
127 | LIST_HEAD(amd_iommu_list); /* list of all AMD IOMMUs in the | 129 | LIST_HEAD(amd_iommu_list); /* list of all AMD IOMMUs in the |
@@ -242,20 +244,16 @@ static void __init iommu_feature_disable(struct amd_iommu *iommu, u8 bit) | |||
242 | } | 244 | } |
243 | 245 | ||
244 | /* Function to enable the hardware */ | 246 | /* Function to enable the hardware */ |
245 | void __init iommu_enable(struct amd_iommu *iommu) | 247 | static void __init iommu_enable(struct amd_iommu *iommu) |
246 | { | 248 | { |
247 | printk(KERN_INFO "AMD IOMMU: Enabling IOMMU " | 249 | printk(KERN_INFO "AMD IOMMU: Enabling IOMMU at %s cap 0x%hx\n", |
248 | "at %02x:%02x.%x cap 0x%hx\n", | 250 | dev_name(&iommu->dev->dev), iommu->cap_ptr); |
249 | iommu->dev->bus->number, | ||
250 | PCI_SLOT(iommu->dev->devfn), | ||
251 | PCI_FUNC(iommu->dev->devfn), | ||
252 | iommu->cap_ptr); | ||
253 | 251 | ||
254 | iommu_feature_enable(iommu, CONTROL_IOMMU_EN); | 252 | iommu_feature_enable(iommu, CONTROL_IOMMU_EN); |
255 | } | 253 | } |
256 | 254 | ||
257 | /* Function to enable IOMMU event logging and event interrupts */ | 255 | /* Function to enable IOMMU event logging and event interrupts */ |
258 | void __init iommu_enable_event_logging(struct amd_iommu *iommu) | 256 | static void __init iommu_enable_event_logging(struct amd_iommu *iommu) |
259 | { | 257 | { |
260 | iommu_feature_enable(iommu, CONTROL_EVT_LOG_EN); | 258 | iommu_feature_enable(iommu, CONTROL_EVT_LOG_EN); |
261 | iommu_feature_enable(iommu, CONTROL_EVT_INT_EN); | 259 | iommu_feature_enable(iommu, CONTROL_EVT_INT_EN); |
@@ -1217,9 +1215,9 @@ static int __init parse_amd_iommu_options(char *str) | |||
1217 | { | 1215 | { |
1218 | for (; *str; ++str) { | 1216 | for (; *str; ++str) { |
1219 | if (strncmp(str, "isolate", 7) == 0) | 1217 | if (strncmp(str, "isolate", 7) == 0) |
1220 | amd_iommu_isolate = 1; | 1218 | amd_iommu_isolate = true; |
1221 | if (strncmp(str, "share", 5) == 0) | 1219 | if (strncmp(str, "share", 5) == 0) |
1222 | amd_iommu_isolate = 0; | 1220 | amd_iommu_isolate = false; |
1223 | if (strncmp(str, "fullflush", 9) == 0) | 1221 | if (strncmp(str, "fullflush", 9) == 0) |
1224 | amd_iommu_unmap_flush = true; | 1222 | amd_iommu_unmap_flush = true; |
1225 | } | 1223 | } |
diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c index 9a32b37ee2ee..676debfc1702 100644 --- a/arch/x86/kernel/aperture_64.c +++ b/arch/x86/kernel/aperture_64.c | |||
@@ -1,8 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * Firmware replacement code. | 2 | * Firmware replacement code. |
3 | * | 3 | * |
4 | * Work around broken BIOSes that don't set an aperture or only set the | 4 | * Work around broken BIOSes that don't set an aperture, only set the |
5 | * aperture in the AGP bridge. | 5 | * aperture in the AGP bridge, or set too small aperture. |
6 | * | ||
6 | * If all fails map the aperture over some low memory. This is cheaper than | 7 | * If all fails map the aperture over some low memory. This is cheaper than |
7 | * doing bounce buffering. The memory is lost. This is done at early boot | 8 | * doing bounce buffering. The memory is lost. This is done at early boot |
8 | * because only the bootmem allocator can allocate 32+MB. | 9 | * because only the bootmem allocator can allocate 32+MB. |
diff --git a/arch/x86/kernel/apic.c b/arch/x86/kernel/apic.c index 16f94879b525..b13d3c4dbd42 100644 --- a/arch/x86/kernel/apic.c +++ b/arch/x86/kernel/apic.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/module.h> | 30 | #include <linux/module.h> |
31 | #include <linux/dmi.h> | 31 | #include <linux/dmi.h> |
32 | #include <linux/dmar.h> | 32 | #include <linux/dmar.h> |
33 | #include <linux/ftrace.h> | ||
33 | 34 | ||
34 | #include <asm/atomic.h> | 35 | #include <asm/atomic.h> |
35 | #include <asm/smp.h> | 36 | #include <asm/smp.h> |
@@ -97,8 +98,8 @@ __setup("apicpmtimer", setup_apicpmtimer); | |||
97 | #ifdef HAVE_X2APIC | 98 | #ifdef HAVE_X2APIC |
98 | int x2apic; | 99 | int x2apic; |
99 | /* x2apic enabled before OS handover */ | 100 | /* x2apic enabled before OS handover */ |
100 | int x2apic_preenabled; | 101 | static int x2apic_preenabled; |
101 | int disable_x2apic; | 102 | static int disable_x2apic; |
102 | static __init int setup_nox2apic(char *str) | 103 | static __init int setup_nox2apic(char *str) |
103 | { | 104 | { |
104 | disable_x2apic = 1; | 105 | disable_x2apic = 1; |
@@ -118,8 +119,6 @@ EXPORT_SYMBOL_GPL(local_apic_timer_c2_ok); | |||
118 | 119 | ||
119 | int first_system_vector = 0xfe; | 120 | int first_system_vector = 0xfe; |
120 | 121 | ||
121 | char system_vectors[NR_VECTORS] = { [0 ... NR_VECTORS-1] = SYS_VECTOR_FREE}; | ||
122 | |||
123 | /* | 122 | /* |
124 | * Debug level, exported for io_apic.c | 123 | * Debug level, exported for io_apic.c |
125 | */ | 124 | */ |
@@ -141,7 +140,7 @@ static int lapic_next_event(unsigned long delta, | |||
141 | struct clock_event_device *evt); | 140 | struct clock_event_device *evt); |
142 | static void lapic_timer_setup(enum clock_event_mode mode, | 141 | static void lapic_timer_setup(enum clock_event_mode mode, |
143 | struct clock_event_device *evt); | 142 | struct clock_event_device *evt); |
144 | static void lapic_timer_broadcast(cpumask_t mask); | 143 | static void lapic_timer_broadcast(const struct cpumask *mask); |
145 | static void apic_pm_activate(void); | 144 | static void apic_pm_activate(void); |
146 | 145 | ||
147 | /* | 146 | /* |
@@ -227,7 +226,7 @@ void xapic_icr_write(u32 low, u32 id) | |||
227 | apic_write(APIC_ICR, low); | 226 | apic_write(APIC_ICR, low); |
228 | } | 227 | } |
229 | 228 | ||
230 | u64 xapic_icr_read(void) | 229 | static u64 xapic_icr_read(void) |
231 | { | 230 | { |
232 | u32 icr1, icr2; | 231 | u32 icr1, icr2; |
233 | 232 | ||
@@ -267,7 +266,7 @@ void x2apic_icr_write(u32 low, u32 id) | |||
267 | wrmsrl(APIC_BASE_MSR + (APIC_ICR >> 4), ((__u64) id) << 32 | low); | 266 | wrmsrl(APIC_BASE_MSR + (APIC_ICR >> 4), ((__u64) id) << 32 | low); |
268 | } | 267 | } |
269 | 268 | ||
270 | u64 x2apic_icr_read(void) | 269 | static u64 x2apic_icr_read(void) |
271 | { | 270 | { |
272 | unsigned long val; | 271 | unsigned long val; |
273 | 272 | ||
@@ -441,6 +440,7 @@ static void lapic_timer_setup(enum clock_event_mode mode, | |||
441 | v = apic_read(APIC_LVTT); | 440 | v = apic_read(APIC_LVTT); |
442 | v |= (APIC_LVT_MASKED | LOCAL_TIMER_VECTOR); | 441 | v |= (APIC_LVT_MASKED | LOCAL_TIMER_VECTOR); |
443 | apic_write(APIC_LVTT, v); | 442 | apic_write(APIC_LVTT, v); |
443 | apic_write(APIC_TMICT, 0xffffffff); | ||
444 | break; | 444 | break; |
445 | case CLOCK_EVT_MODE_RESUME: | 445 | case CLOCK_EVT_MODE_RESUME: |
446 | /* Nothing to do here */ | 446 | /* Nothing to do here */ |
@@ -453,7 +453,7 @@ static void lapic_timer_setup(enum clock_event_mode mode, | |||
453 | /* | 453 | /* |
454 | * Local APIC timer broadcast function | 454 | * Local APIC timer broadcast function |
455 | */ | 455 | */ |
456 | static void lapic_timer_broadcast(cpumask_t mask) | 456 | static void lapic_timer_broadcast(const struct cpumask *mask) |
457 | { | 457 | { |
458 | #ifdef CONFIG_SMP | 458 | #ifdef CONFIG_SMP |
459 | send_IPI_mask(mask, LOCAL_TIMER_VECTOR); | 459 | send_IPI_mask(mask, LOCAL_TIMER_VECTOR); |
@@ -469,7 +469,7 @@ static void __cpuinit setup_APIC_timer(void) | |||
469 | struct clock_event_device *levt = &__get_cpu_var(lapic_events); | 469 | struct clock_event_device *levt = &__get_cpu_var(lapic_events); |
470 | 470 | ||
471 | memcpy(levt, &lapic_clockevent, sizeof(*levt)); | 471 | memcpy(levt, &lapic_clockevent, sizeof(*levt)); |
472 | levt->cpumask = cpumask_of_cpu(smp_processor_id()); | 472 | levt->cpumask = cpumask_of(smp_processor_id()); |
473 | 473 | ||
474 | clockevents_register_device(levt); | 474 | clockevents_register_device(levt); |
475 | } | 475 | } |
@@ -559,13 +559,13 @@ static int __init calibrate_by_pmtimer(long deltapm, long *delta) | |||
559 | } else { | 559 | } else { |
560 | res = (((u64)deltapm) * mult) >> 22; | 560 | res = (((u64)deltapm) * mult) >> 22; |
561 | do_div(res, 1000000); | 561 | do_div(res, 1000000); |
562 | printk(KERN_WARNING "APIC calibration not consistent " | 562 | pr_warning("APIC calibration not consistent " |
563 | "with PM Timer: %ldms instead of 100ms\n", | 563 | "with PM Timer: %ldms instead of 100ms\n", |
564 | (long)res); | 564 | (long)res); |
565 | /* Correct the lapic counter value */ | 565 | /* Correct the lapic counter value */ |
566 | res = (((u64)(*delta)) * pm_100ms); | 566 | res = (((u64)(*delta)) * pm_100ms); |
567 | do_div(res, deltapm); | 567 | do_div(res, deltapm); |
568 | printk(KERN_INFO "APIC delta adjusted to PM-Timer: " | 568 | pr_info("APIC delta adjusted to PM-Timer: " |
569 | "%lu (%ld)\n", (unsigned long)res, *delta); | 569 | "%lu (%ld)\n", (unsigned long)res, *delta); |
570 | *delta = (long)res; | 570 | *delta = (long)res; |
571 | } | 571 | } |
@@ -645,8 +645,7 @@ static int __init calibrate_APIC_clock(void) | |||
645 | */ | 645 | */ |
646 | if (calibration_result < (1000000 / HZ)) { | 646 | if (calibration_result < (1000000 / HZ)) { |
647 | local_irq_enable(); | 647 | local_irq_enable(); |
648 | printk(KERN_WARNING | 648 | pr_warning("APIC frequency too slow, disabling apic timer\n"); |
649 | "APIC frequency too slow, disabling apic timer\n"); | ||
650 | return -1; | 649 | return -1; |
651 | } | 650 | } |
652 | 651 | ||
@@ -672,13 +671,9 @@ static int __init calibrate_APIC_clock(void) | |||
672 | while (lapic_cal_loops <= LAPIC_CAL_LOOPS) | 671 | while (lapic_cal_loops <= LAPIC_CAL_LOOPS) |
673 | cpu_relax(); | 672 | cpu_relax(); |
674 | 673 | ||
675 | local_irq_disable(); | ||
676 | |||
677 | /* Stop the lapic timer */ | 674 | /* Stop the lapic timer */ |
678 | lapic_timer_setup(CLOCK_EVT_MODE_SHUTDOWN, levt); | 675 | lapic_timer_setup(CLOCK_EVT_MODE_SHUTDOWN, levt); |
679 | 676 | ||
680 | local_irq_enable(); | ||
681 | |||
682 | /* Jiffies delta */ | 677 | /* Jiffies delta */ |
683 | deltaj = lapic_cal_j2 - lapic_cal_j1; | 678 | deltaj = lapic_cal_j2 - lapic_cal_j1; |
684 | apic_printk(APIC_VERBOSE, "... jiffies delta = %lu\n", deltaj); | 679 | apic_printk(APIC_VERBOSE, "... jiffies delta = %lu\n", deltaj); |
@@ -692,8 +687,7 @@ static int __init calibrate_APIC_clock(void) | |||
692 | local_irq_enable(); | 687 | local_irq_enable(); |
693 | 688 | ||
694 | if (levt->features & CLOCK_EVT_FEAT_DUMMY) { | 689 | if (levt->features & CLOCK_EVT_FEAT_DUMMY) { |
695 | printk(KERN_WARNING | 690 | pr_warning("APIC timer disabled due to verification failure.\n"); |
696 | "APIC timer disabled due to verification failure.\n"); | ||
697 | return -1; | 691 | return -1; |
698 | } | 692 | } |
699 | 693 | ||
@@ -714,7 +708,7 @@ void __init setup_boot_APIC_clock(void) | |||
714 | * broadcast mechanism is used. On UP systems simply ignore it. | 708 | * broadcast mechanism is used. On UP systems simply ignore it. |
715 | */ | 709 | */ |
716 | if (disable_apic_timer) { | 710 | if (disable_apic_timer) { |
717 | printk(KERN_INFO "Disabling APIC timer\n"); | 711 | pr_info("Disabling APIC timer\n"); |
718 | /* No broadcast on UP ! */ | 712 | /* No broadcast on UP ! */ |
719 | if (num_possible_cpus() > 1) { | 713 | if (num_possible_cpus() > 1) { |
720 | lapic_clockevent.mult = 1; | 714 | lapic_clockevent.mult = 1; |
@@ -741,7 +735,7 @@ void __init setup_boot_APIC_clock(void) | |||
741 | if (nmi_watchdog != NMI_IO_APIC) | 735 | if (nmi_watchdog != NMI_IO_APIC) |
742 | lapic_clockevent.features &= ~CLOCK_EVT_FEAT_DUMMY; | 736 | lapic_clockevent.features &= ~CLOCK_EVT_FEAT_DUMMY; |
743 | else | 737 | else |
744 | printk(KERN_WARNING "APIC timer registered as dummy," | 738 | pr_warning("APIC timer registered as dummy," |
745 | " due to nmi_watchdog=%d!\n", nmi_watchdog); | 739 | " due to nmi_watchdog=%d!\n", nmi_watchdog); |
746 | 740 | ||
747 | /* Setup the lapic or request the broadcast */ | 741 | /* Setup the lapic or request the broadcast */ |
@@ -773,8 +767,7 @@ static void local_apic_timer_interrupt(void) | |||
773 | * spurious. | 767 | * spurious. |
774 | */ | 768 | */ |
775 | if (!evt->event_handler) { | 769 | if (!evt->event_handler) { |
776 | printk(KERN_WARNING | 770 | pr_warning("Spurious LAPIC timer interrupt on cpu %d\n", cpu); |
777 | "Spurious LAPIC timer interrupt on cpu %d\n", cpu); | ||
778 | /* Switch it off */ | 771 | /* Switch it off */ |
779 | lapic_timer_setup(CLOCK_EVT_MODE_SHUTDOWN, evt); | 772 | lapic_timer_setup(CLOCK_EVT_MODE_SHUTDOWN, evt); |
780 | return; | 773 | return; |
@@ -783,11 +776,7 @@ static void local_apic_timer_interrupt(void) | |||
783 | /* | 776 | /* |
784 | * the NMI deadlock-detector uses this. | 777 | * the NMI deadlock-detector uses this. |
785 | */ | 778 | */ |
786 | #ifdef CONFIG_X86_64 | 779 | inc_irq_stat(apic_timer_irqs); |
787 | add_pda(apic_timer_irqs, 1); | ||
788 | #else | ||
789 | per_cpu(irq_stat, cpu).apic_timer_irqs++; | ||
790 | #endif | ||
791 | 780 | ||
792 | evt->event_handler(evt); | 781 | evt->event_handler(evt); |
793 | } | 782 | } |
@@ -800,7 +789,7 @@ static void local_apic_timer_interrupt(void) | |||
800 | * [ if a single-CPU system runs an SMP kernel then we call the local | 789 | * [ if a single-CPU system runs an SMP kernel then we call the local |
801 | * interrupt as well. Thus we cannot inline the local irq ... ] | 790 | * interrupt as well. Thus we cannot inline the local irq ... ] |
802 | */ | 791 | */ |
803 | void smp_apic_timer_interrupt(struct pt_regs *regs) | 792 | void __irq_entry smp_apic_timer_interrupt(struct pt_regs *regs) |
804 | { | 793 | { |
805 | struct pt_regs *old_regs = set_irq_regs(regs); | 794 | struct pt_regs *old_regs = set_irq_regs(regs); |
806 | 795 | ||
@@ -814,9 +803,7 @@ void smp_apic_timer_interrupt(struct pt_regs *regs) | |||
814 | * Besides, if we don't timer interrupts ignore the global | 803 | * Besides, if we don't timer interrupts ignore the global |
815 | * interrupt lock, which is the WrongThing (tm) to do. | 804 | * interrupt lock, which is the WrongThing (tm) to do. |
816 | */ | 805 | */ |
817 | #ifdef CONFIG_X86_64 | ||
818 | exit_idle(); | 806 | exit_idle(); |
819 | #endif | ||
820 | irq_enter(); | 807 | irq_enter(); |
821 | local_apic_timer_interrupt(); | 808 | local_apic_timer_interrupt(); |
822 | irq_exit(); | 809 | irq_exit(); |
@@ -1093,7 +1080,7 @@ static void __cpuinit lapic_setup_esr(void) | |||
1093 | unsigned int oldvalue, value, maxlvt; | 1080 | unsigned int oldvalue, value, maxlvt; |
1094 | 1081 | ||
1095 | if (!lapic_is_integrated()) { | 1082 | if (!lapic_is_integrated()) { |
1096 | printk(KERN_INFO "No ESR for 82489DX.\n"); | 1083 | pr_info("No ESR for 82489DX.\n"); |
1097 | return; | 1084 | return; |
1098 | } | 1085 | } |
1099 | 1086 | ||
@@ -1104,7 +1091,7 @@ static void __cpuinit lapic_setup_esr(void) | |||
1104 | * ESR disabled - we can't do anything useful with the | 1091 | * ESR disabled - we can't do anything useful with the |
1105 | * errors anyway - mbligh | 1092 | * errors anyway - mbligh |
1106 | */ | 1093 | */ |
1107 | printk(KERN_INFO "Leaving ESR disabled.\n"); | 1094 | pr_info("Leaving ESR disabled.\n"); |
1108 | return; | 1095 | return; |
1109 | } | 1096 | } |
1110 | 1097 | ||
@@ -1298,7 +1285,7 @@ void check_x2apic(void) | |||
1298 | rdmsr(MSR_IA32_APICBASE, msr, msr2); | 1285 | rdmsr(MSR_IA32_APICBASE, msr, msr2); |
1299 | 1286 | ||
1300 | if (msr & X2APIC_ENABLE) { | 1287 | if (msr & X2APIC_ENABLE) { |
1301 | printk("x2apic enabled by BIOS, switching to x2apic ops\n"); | 1288 | pr_info("x2apic enabled by BIOS, switching to x2apic ops\n"); |
1302 | x2apic_preenabled = x2apic = 1; | 1289 | x2apic_preenabled = x2apic = 1; |
1303 | apic_ops = &x2apic_ops; | 1290 | apic_ops = &x2apic_ops; |
1304 | } | 1291 | } |
@@ -1310,7 +1297,7 @@ void enable_x2apic(void) | |||
1310 | 1297 | ||
1311 | rdmsr(MSR_IA32_APICBASE, msr, msr2); | 1298 | rdmsr(MSR_IA32_APICBASE, msr, msr2); |
1312 | if (!(msr & X2APIC_ENABLE)) { | 1299 | if (!(msr & X2APIC_ENABLE)) { |
1313 | printk("Enabling x2apic\n"); | 1300 | pr_info("Enabling x2apic\n"); |
1314 | wrmsr(MSR_IA32_APICBASE, msr | X2APIC_ENABLE, 0); | 1301 | wrmsr(MSR_IA32_APICBASE, msr | X2APIC_ENABLE, 0); |
1315 | } | 1302 | } |
1316 | } | 1303 | } |
@@ -1325,9 +1312,8 @@ void __init enable_IR_x2apic(void) | |||
1325 | return; | 1312 | return; |
1326 | 1313 | ||
1327 | if (!x2apic_preenabled && disable_x2apic) { | 1314 | if (!x2apic_preenabled && disable_x2apic) { |
1328 | printk(KERN_INFO | 1315 | pr_info("Skipped enabling x2apic and Interrupt-remapping " |
1329 | "Skipped enabling x2apic and Interrupt-remapping " | 1316 | "because of nox2apic\n"); |
1330 | "because of nox2apic\n"); | ||
1331 | return; | 1317 | return; |
1332 | } | 1318 | } |
1333 | 1319 | ||
@@ -1335,22 +1321,19 @@ void __init enable_IR_x2apic(void) | |||
1335 | panic("Bios already enabled x2apic, can't enforce nox2apic"); | 1321 | panic("Bios already enabled x2apic, can't enforce nox2apic"); |
1336 | 1322 | ||
1337 | if (!x2apic_preenabled && skip_ioapic_setup) { | 1323 | if (!x2apic_preenabled && skip_ioapic_setup) { |
1338 | printk(KERN_INFO | 1324 | pr_info("Skipped enabling x2apic and Interrupt-remapping " |
1339 | "Skipped enabling x2apic and Interrupt-remapping " | 1325 | "because of skipping io-apic setup\n"); |
1340 | "because of skipping io-apic setup\n"); | ||
1341 | return; | 1326 | return; |
1342 | } | 1327 | } |
1343 | 1328 | ||
1344 | ret = dmar_table_init(); | 1329 | ret = dmar_table_init(); |
1345 | if (ret) { | 1330 | if (ret) { |
1346 | printk(KERN_INFO | 1331 | pr_info("dmar_table_init() failed with %d:\n", ret); |
1347 | "dmar_table_init() failed with %d:\n", ret); | ||
1348 | 1332 | ||
1349 | if (x2apic_preenabled) | 1333 | if (x2apic_preenabled) |
1350 | panic("x2apic enabled by bios. But IR enabling failed"); | 1334 | panic("x2apic enabled by bios. But IR enabling failed"); |
1351 | else | 1335 | else |
1352 | printk(KERN_INFO | 1336 | pr_info("Not enabling x2apic,Intr-remapping\n"); |
1353 | "Not enabling x2apic,Intr-remapping\n"); | ||
1354 | return; | 1337 | return; |
1355 | } | 1338 | } |
1356 | 1339 | ||
@@ -1359,7 +1342,7 @@ void __init enable_IR_x2apic(void) | |||
1359 | 1342 | ||
1360 | ret = save_mask_IO_APIC_setup(); | 1343 | ret = save_mask_IO_APIC_setup(); |
1361 | if (ret) { | 1344 | if (ret) { |
1362 | printk(KERN_INFO "Saving IO-APIC state failed: %d\n", ret); | 1345 | pr_info("Saving IO-APIC state failed: %d\n", ret); |
1363 | goto end; | 1346 | goto end; |
1364 | } | 1347 | } |
1365 | 1348 | ||
@@ -1394,14 +1377,11 @@ end: | |||
1394 | 1377 | ||
1395 | if (!ret) { | 1378 | if (!ret) { |
1396 | if (!x2apic_preenabled) | 1379 | if (!x2apic_preenabled) |
1397 | printk(KERN_INFO | 1380 | pr_info("Enabled x2apic and interrupt-remapping\n"); |
1398 | "Enabled x2apic and interrupt-remapping\n"); | ||
1399 | else | 1381 | else |
1400 | printk(KERN_INFO | 1382 | pr_info("Enabled Interrupt-remapping\n"); |
1401 | "Enabled Interrupt-remapping\n"); | ||
1402 | } else | 1383 | } else |
1403 | printk(KERN_ERR | 1384 | pr_err("Failed to enable Interrupt-remapping and x2apic\n"); |
1404 | "Failed to enable Interrupt-remapping and x2apic\n"); | ||
1405 | #else | 1385 | #else |
1406 | if (!cpu_has_x2apic) | 1386 | if (!cpu_has_x2apic) |
1407 | return; | 1387 | return; |
@@ -1410,8 +1390,8 @@ end: | |||
1410 | panic("x2apic enabled prior OS handover," | 1390 | panic("x2apic enabled prior OS handover," |
1411 | " enable CONFIG_INTR_REMAP"); | 1391 | " enable CONFIG_INTR_REMAP"); |
1412 | 1392 | ||
1413 | printk(KERN_INFO "Enable CONFIG_INTR_REMAP for enabling intr-remapping " | 1393 | pr_info("Enable CONFIG_INTR_REMAP for enabling intr-remapping " |
1414 | " and x2apic\n"); | 1394 | " and x2apic\n"); |
1415 | #endif | 1395 | #endif |
1416 | 1396 | ||
1417 | return; | 1397 | return; |
@@ -1428,7 +1408,7 @@ end: | |||
1428 | static int __init detect_init_APIC(void) | 1408 | static int __init detect_init_APIC(void) |
1429 | { | 1409 | { |
1430 | if (!cpu_has_apic) { | 1410 | if (!cpu_has_apic) { |
1431 | printk(KERN_INFO "No local APIC present\n"); | 1411 | pr_info("No local APIC present\n"); |
1432 | return -1; | 1412 | return -1; |
1433 | } | 1413 | } |
1434 | 1414 | ||
@@ -1469,8 +1449,8 @@ static int __init detect_init_APIC(void) | |||
1469 | * "lapic" specified. | 1449 | * "lapic" specified. |
1470 | */ | 1450 | */ |
1471 | if (!force_enable_local_apic) { | 1451 | if (!force_enable_local_apic) { |
1472 | printk(KERN_INFO "Local APIC disabled by BIOS -- " | 1452 | pr_info("Local APIC disabled by BIOS -- " |
1473 | "you can enable it with \"lapic\"\n"); | 1453 | "you can enable it with \"lapic\"\n"); |
1474 | return -1; | 1454 | return -1; |
1475 | } | 1455 | } |
1476 | /* | 1456 | /* |
@@ -1480,8 +1460,7 @@ static int __init detect_init_APIC(void) | |||
1480 | */ | 1460 | */ |
1481 | rdmsr(MSR_IA32_APICBASE, l, h); | 1461 | rdmsr(MSR_IA32_APICBASE, l, h); |
1482 | if (!(l & MSR_IA32_APICBASE_ENABLE)) { | 1462 | if (!(l & MSR_IA32_APICBASE_ENABLE)) { |
1483 | printk(KERN_INFO | 1463 | pr_info("Local APIC disabled by BIOS -- reenabling.\n"); |
1484 | "Local APIC disabled by BIOS -- reenabling.\n"); | ||
1485 | l &= ~MSR_IA32_APICBASE_BASE; | 1464 | l &= ~MSR_IA32_APICBASE_BASE; |
1486 | l |= MSR_IA32_APICBASE_ENABLE | APIC_DEFAULT_PHYS_BASE; | 1465 | l |= MSR_IA32_APICBASE_ENABLE | APIC_DEFAULT_PHYS_BASE; |
1487 | wrmsr(MSR_IA32_APICBASE, l, h); | 1466 | wrmsr(MSR_IA32_APICBASE, l, h); |
@@ -1494,7 +1473,7 @@ static int __init detect_init_APIC(void) | |||
1494 | */ | 1473 | */ |
1495 | features = cpuid_edx(1); | 1474 | features = cpuid_edx(1); |
1496 | if (!(features & (1 << X86_FEATURE_APIC))) { | 1475 | if (!(features & (1 << X86_FEATURE_APIC))) { |
1497 | printk(KERN_WARNING "Could not enable APIC!\n"); | 1476 | pr_warning("Could not enable APIC!\n"); |
1498 | return -1; | 1477 | return -1; |
1499 | } | 1478 | } |
1500 | set_cpu_cap(&boot_cpu_data, X86_FEATURE_APIC); | 1479 | set_cpu_cap(&boot_cpu_data, X86_FEATURE_APIC); |
@@ -1505,14 +1484,14 @@ static int __init detect_init_APIC(void) | |||
1505 | if (l & MSR_IA32_APICBASE_ENABLE) | 1484 | if (l & MSR_IA32_APICBASE_ENABLE) |
1506 | mp_lapic_addr = l & MSR_IA32_APICBASE_BASE; | 1485 | mp_lapic_addr = l & MSR_IA32_APICBASE_BASE; |
1507 | 1486 | ||
1508 | printk(KERN_INFO "Found and enabled local APIC!\n"); | 1487 | pr_info("Found and enabled local APIC!\n"); |
1509 | 1488 | ||
1510 | apic_pm_activate(); | 1489 | apic_pm_activate(); |
1511 | 1490 | ||
1512 | return 0; | 1491 | return 0; |
1513 | 1492 | ||
1514 | no_apic: | 1493 | no_apic: |
1515 | printk(KERN_INFO "No local APIC present or hardware disabled\n"); | 1494 | pr_info("No local APIC present or hardware disabled\n"); |
1516 | return -1; | 1495 | return -1; |
1517 | } | 1496 | } |
1518 | #endif | 1497 | #endif |
@@ -1588,12 +1567,12 @@ int __init APIC_init_uniprocessor(void) | |||
1588 | { | 1567 | { |
1589 | #ifdef CONFIG_X86_64 | 1568 | #ifdef CONFIG_X86_64 |
1590 | if (disable_apic) { | 1569 | if (disable_apic) { |
1591 | printk(KERN_INFO "Apic disabled\n"); | 1570 | pr_info("Apic disabled\n"); |
1592 | return -1; | 1571 | return -1; |
1593 | } | 1572 | } |
1594 | if (!cpu_has_apic) { | 1573 | if (!cpu_has_apic) { |
1595 | disable_apic = 1; | 1574 | disable_apic = 1; |
1596 | printk(KERN_INFO "Apic disabled by BIOS\n"); | 1575 | pr_info("Apic disabled by BIOS\n"); |
1597 | return -1; | 1576 | return -1; |
1598 | } | 1577 | } |
1599 | #else | 1578 | #else |
@@ -1605,8 +1584,8 @@ int __init APIC_init_uniprocessor(void) | |||
1605 | */ | 1584 | */ |
1606 | if (!cpu_has_apic && | 1585 | if (!cpu_has_apic && |
1607 | APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid])) { | 1586 | APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid])) { |
1608 | printk(KERN_ERR "BIOS bug, local APIC 0x%x not detected!...\n", | 1587 | pr_err("BIOS bug, local APIC 0x%x not detected!...\n", |
1609 | boot_cpu_physical_apicid); | 1588 | boot_cpu_physical_apicid); |
1610 | clear_cpu_cap(&boot_cpu_data, X86_FEATURE_APIC); | 1589 | clear_cpu_cap(&boot_cpu_data, X86_FEATURE_APIC); |
1611 | return -1; | 1590 | return -1; |
1612 | } | 1591 | } |
@@ -1682,9 +1661,7 @@ void smp_spurious_interrupt(struct pt_regs *regs) | |||
1682 | { | 1661 | { |
1683 | u32 v; | 1662 | u32 v; |
1684 | 1663 | ||
1685 | #ifdef CONFIG_X86_64 | ||
1686 | exit_idle(); | 1664 | exit_idle(); |
1687 | #endif | ||
1688 | irq_enter(); | 1665 | irq_enter(); |
1689 | /* | 1666 | /* |
1690 | * Check if this really is a spurious interrupt and ACK it | 1667 | * Check if this really is a spurious interrupt and ACK it |
@@ -1695,14 +1672,11 @@ void smp_spurious_interrupt(struct pt_regs *regs) | |||
1695 | if (v & (1 << (SPURIOUS_APIC_VECTOR & 0x1f))) | 1672 | if (v & (1 << (SPURIOUS_APIC_VECTOR & 0x1f))) |
1696 | ack_APIC_irq(); | 1673 | ack_APIC_irq(); |
1697 | 1674 | ||
1698 | #ifdef CONFIG_X86_64 | 1675 | inc_irq_stat(irq_spurious_count); |
1699 | add_pda(irq_spurious_count, 1); | 1676 | |
1700 | #else | ||
1701 | /* see sw-dev-man vol 3, chapter 7.4.13.5 */ | 1677 | /* see sw-dev-man vol 3, chapter 7.4.13.5 */ |
1702 | printk(KERN_INFO "spurious APIC interrupt on CPU#%d, " | 1678 | pr_info("spurious APIC interrupt on CPU#%d, " |
1703 | "should never happen.\n", smp_processor_id()); | 1679 | "should never happen.\n", smp_processor_id()); |
1704 | __get_cpu_var(irq_stat).irq_spurious_count++; | ||
1705 | #endif | ||
1706 | irq_exit(); | 1680 | irq_exit(); |
1707 | } | 1681 | } |
1708 | 1682 | ||
@@ -1713,9 +1687,7 @@ void smp_error_interrupt(struct pt_regs *regs) | |||
1713 | { | 1687 | { |
1714 | u32 v, v1; | 1688 | u32 v, v1; |
1715 | 1689 | ||
1716 | #ifdef CONFIG_X86_64 | ||
1717 | exit_idle(); | 1690 | exit_idle(); |
1718 | #endif | ||
1719 | irq_enter(); | 1691 | irq_enter(); |
1720 | /* First tickle the hardware, only then report what went on. -- REW */ | 1692 | /* First tickle the hardware, only then report what went on. -- REW */ |
1721 | v = apic_read(APIC_ESR); | 1693 | v = apic_read(APIC_ESR); |
@@ -1724,17 +1696,18 @@ void smp_error_interrupt(struct pt_regs *regs) | |||
1724 | ack_APIC_irq(); | 1696 | ack_APIC_irq(); |
1725 | atomic_inc(&irq_err_count); | 1697 | atomic_inc(&irq_err_count); |
1726 | 1698 | ||
1727 | /* Here is what the APIC error bits mean: | 1699 | /* |
1728 | 0: Send CS error | 1700 | * Here is what the APIC error bits mean: |
1729 | 1: Receive CS error | 1701 | * 0: Send CS error |
1730 | 2: Send accept error | 1702 | * 1: Receive CS error |
1731 | 3: Receive accept error | 1703 | * 2: Send accept error |
1732 | 4: Reserved | 1704 | * 3: Receive accept error |
1733 | 5: Send illegal vector | 1705 | * 4: Reserved |
1734 | 6: Received illegal vector | 1706 | * 5: Send illegal vector |
1735 | 7: Illegal register address | 1707 | * 6: Received illegal vector |
1736 | */ | 1708 | * 7: Illegal register address |
1737 | printk(KERN_DEBUG "APIC error on CPU%d: %02x(%02x)\n", | 1709 | */ |
1710 | pr_debug("APIC error on CPU%d: %02x(%02x)\n", | ||
1738 | smp_processor_id(), v , v1); | 1711 | smp_processor_id(), v , v1); |
1739 | irq_exit(); | 1712 | irq_exit(); |
1740 | } | 1713 | } |
@@ -1832,28 +1805,32 @@ void disconnect_bsp_APIC(int virt_wire_setup) | |||
1832 | void __cpuinit generic_processor_info(int apicid, int version) | 1805 | void __cpuinit generic_processor_info(int apicid, int version) |
1833 | { | 1806 | { |
1834 | int cpu; | 1807 | int cpu; |
1835 | cpumask_t tmp_map; | ||
1836 | 1808 | ||
1837 | /* | 1809 | /* |
1838 | * Validate version | 1810 | * Validate version |
1839 | */ | 1811 | */ |
1840 | if (version == 0x0) { | 1812 | if (version == 0x0) { |
1841 | printk(KERN_WARNING "BIOS bug, APIC version is 0 for CPU#%d! " | 1813 | pr_warning("BIOS bug, APIC version is 0 for CPU#%d! " |
1842 | "fixing up to 0x10. (tell your hw vendor)\n", | 1814 | "fixing up to 0x10. (tell your hw vendor)\n", |
1843 | version); | 1815 | version); |
1844 | version = 0x10; | 1816 | version = 0x10; |
1845 | } | 1817 | } |
1846 | apic_version[apicid] = version; | 1818 | apic_version[apicid] = version; |
1847 | 1819 | ||
1848 | if (num_processors >= NR_CPUS) { | 1820 | if (num_processors >= nr_cpu_ids) { |
1849 | printk(KERN_WARNING "WARNING: NR_CPUS limit of %i reached." | 1821 | int max = nr_cpu_ids; |
1850 | " Processor ignored.\n", NR_CPUS); | 1822 | int thiscpu = max + disabled_cpus; |
1823 | |||
1824 | pr_warning( | ||
1825 | "ACPI: NR_CPUS/possible_cpus limit of %i reached." | ||
1826 | " Processor %d/0x%x ignored.\n", max, thiscpu, apicid); | ||
1827 | |||
1828 | disabled_cpus++; | ||
1851 | return; | 1829 | return; |
1852 | } | 1830 | } |
1853 | 1831 | ||
1854 | num_processors++; | 1832 | num_processors++; |
1855 | cpus_complement(tmp_map, cpu_present_map); | 1833 | cpu = cpumask_next_zero(-1, cpu_present_mask); |
1856 | cpu = first_cpu(tmp_map); | ||
1857 | 1834 | ||
1858 | physid_set(apicid, phys_cpu_present_map); | 1835 | physid_set(apicid, phys_cpu_present_map); |
1859 | if (apicid == boot_cpu_physical_apicid) { | 1836 | if (apicid == boot_cpu_physical_apicid) { |
@@ -1903,8 +1880,8 @@ void __cpuinit generic_processor_info(int apicid, int version) | |||
1903 | } | 1880 | } |
1904 | #endif | 1881 | #endif |
1905 | 1882 | ||
1906 | cpu_set(cpu, cpu_possible_map); | 1883 | set_cpu_possible(cpu, true); |
1907 | cpu_set(cpu, cpu_present_map); | 1884 | set_cpu_present(cpu, true); |
1908 | } | 1885 | } |
1909 | 1886 | ||
1910 | #ifdef CONFIG_X86_64 | 1887 | #ifdef CONFIG_X86_64 |
@@ -2106,7 +2083,7 @@ __cpuinit int apic_is_clustered_box(void) | |||
2106 | bios_cpu_apicid = early_per_cpu_ptr(x86_bios_cpu_apicid); | 2083 | bios_cpu_apicid = early_per_cpu_ptr(x86_bios_cpu_apicid); |
2107 | bitmap_zero(clustermap, NUM_APIC_CLUSTERS); | 2084 | bitmap_zero(clustermap, NUM_APIC_CLUSTERS); |
2108 | 2085 | ||
2109 | for (i = 0; i < NR_CPUS; i++) { | 2086 | for (i = 0; i < nr_cpu_ids; i++) { |
2110 | /* are we being called early in kernel startup? */ | 2087 | /* are we being called early in kernel startup? */ |
2111 | if (bios_cpu_apicid) { | 2088 | if (bios_cpu_apicid) { |
2112 | id = bios_cpu_apicid[i]; | 2089 | id = bios_cpu_apicid[i]; |
@@ -2209,7 +2186,7 @@ static int __init apic_set_verbosity(char *arg) | |||
2209 | else if (strcmp("verbose", arg) == 0) | 2186 | else if (strcmp("verbose", arg) == 0) |
2210 | apic_verbosity = APIC_VERBOSE; | 2187 | apic_verbosity = APIC_VERBOSE; |
2211 | else { | 2188 | else { |
2212 | printk(KERN_WARNING "APIC Verbosity level %s not recognised" | 2189 | pr_warning("APIC Verbosity level %s not recognised" |
2213 | " use apic=verbose or apic=debug\n", arg); | 2190 | " use apic=verbose or apic=debug\n", arg); |
2214 | return -EINVAL; | 2191 | return -EINVAL; |
2215 | } | 2192 | } |
diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c index 5145a6e72bbb..3a26525a3f31 100644 --- a/arch/x86/kernel/apm_32.c +++ b/arch/x86/kernel/apm_32.c | |||
@@ -391,11 +391,7 @@ static int power_off; | |||
391 | #else | 391 | #else |
392 | static int power_off = 1; | 392 | static int power_off = 1; |
393 | #endif | 393 | #endif |
394 | #ifdef CONFIG_APM_REAL_MODE_POWER_OFF | ||
395 | static int realmode_power_off = 1; | ||
396 | #else | ||
397 | static int realmode_power_off; | 394 | static int realmode_power_off; |
398 | #endif | ||
399 | #ifdef CONFIG_APM_ALLOW_INTS | 395 | #ifdef CONFIG_APM_ALLOW_INTS |
400 | static int allow_ints = 1; | 396 | static int allow_ints = 1; |
401 | #else | 397 | #else |
diff --git a/arch/x86/kernel/asm-offsets_32.c b/arch/x86/kernel/asm-offsets_32.c index 6649d09ad88f..ee4df08feee6 100644 --- a/arch/x86/kernel/asm-offsets_32.c +++ b/arch/x86/kernel/asm-offsets_32.c | |||
@@ -11,7 +11,7 @@ | |||
11 | #include <linux/suspend.h> | 11 | #include <linux/suspend.h> |
12 | #include <linux/kbuild.h> | 12 | #include <linux/kbuild.h> |
13 | #include <asm/ucontext.h> | 13 | #include <asm/ucontext.h> |
14 | #include "sigframe.h" | 14 | #include <asm/sigframe.h> |
15 | #include <asm/pgtable.h> | 15 | #include <asm/pgtable.h> |
16 | #include <asm/fixmap.h> | 16 | #include <asm/fixmap.h> |
17 | #include <asm/processor.h> | 17 | #include <asm/processor.h> |
diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c index 7fcf63d22f8b..1d41d3f1edbc 100644 --- a/arch/x86/kernel/asm-offsets_64.c +++ b/arch/x86/kernel/asm-offsets_64.c | |||
@@ -20,6 +20,8 @@ | |||
20 | 20 | ||
21 | #include <xen/interface/xen.h> | 21 | #include <xen/interface/xen.h> |
22 | 22 | ||
23 | #include <asm/sigframe.h> | ||
24 | |||
23 | #define __NO_STUBS 1 | 25 | #define __NO_STUBS 1 |
24 | #undef __SYSCALL | 26 | #undef __SYSCALL |
25 | #undef _ASM_X86_UNISTD_64_H | 27 | #undef _ASM_X86_UNISTD_64_H |
@@ -87,7 +89,7 @@ int main(void) | |||
87 | BLANK(); | 89 | BLANK(); |
88 | #undef ENTRY | 90 | #undef ENTRY |
89 | DEFINE(IA32_RT_SIGFRAME_sigcontext, | 91 | DEFINE(IA32_RT_SIGFRAME_sigcontext, |
90 | offsetof (struct rt_sigframe32, uc.uc_mcontext)); | 92 | offsetof (struct rt_sigframe_ia32, uc.uc_mcontext)); |
91 | BLANK(); | 93 | BLANK(); |
92 | #endif | 94 | #endif |
93 | DEFINE(pbe_address, offsetof(struct pbe, address)); | 95 | DEFINE(pbe_address, offsetof(struct pbe, address)); |
diff --git a/arch/x86/kernel/bios_uv.c b/arch/x86/kernel/bios_uv.c index f0dfe6f17e7e..f63882728d91 100644 --- a/arch/x86/kernel/bios_uv.c +++ b/arch/x86/kernel/bios_uv.c | |||
@@ -25,7 +25,7 @@ | |||
25 | #include <asm/uv/bios.h> | 25 | #include <asm/uv/bios.h> |
26 | #include <asm/uv/uv_hub.h> | 26 | #include <asm/uv/uv_hub.h> |
27 | 27 | ||
28 | struct uv_systab uv_systab; | 28 | static struct uv_systab uv_systab; |
29 | 29 | ||
30 | s64 uv_bios_call(enum uv_bios_cmd which, u64 a1, u64 a2, u64 a3, u64 a4, u64 a5) | 30 | s64 uv_bios_call(enum uv_bios_cmd which, u64 a1, u64 a2, u64 a3, u64 a4, u64 a5) |
31 | { | 31 | { |
@@ -69,10 +69,10 @@ s64 uv_bios_call_reentrant(enum uv_bios_cmd which, u64 a1, u64 a2, u64 a3, | |||
69 | 69 | ||
70 | long sn_partition_id; | 70 | long sn_partition_id; |
71 | EXPORT_SYMBOL_GPL(sn_partition_id); | 71 | EXPORT_SYMBOL_GPL(sn_partition_id); |
72 | long uv_coherency_id; | 72 | long sn_coherency_id; |
73 | EXPORT_SYMBOL_GPL(uv_coherency_id); | 73 | EXPORT_SYMBOL_GPL(sn_coherency_id); |
74 | long uv_region_size; | 74 | long sn_region_size; |
75 | EXPORT_SYMBOL_GPL(uv_region_size); | 75 | EXPORT_SYMBOL_GPL(sn_region_size); |
76 | int uv_type; | 76 | int uv_type; |
77 | 77 | ||
78 | 78 | ||
@@ -100,6 +100,56 @@ s64 uv_bios_get_sn_info(int fc, int *uvtype, long *partid, long *coher, | |||
100 | return ret; | 100 | return ret; |
101 | } | 101 | } |
102 | 102 | ||
103 | int | ||
104 | uv_bios_mq_watchlist_alloc(int blade, unsigned long addr, unsigned int mq_size, | ||
105 | unsigned long *intr_mmr_offset) | ||
106 | { | ||
107 | union uv_watchlist_u size_blade; | ||
108 | u64 watchlist; | ||
109 | s64 ret; | ||
110 | |||
111 | size_blade.size = mq_size; | ||
112 | size_blade.blade = blade; | ||
113 | |||
114 | /* | ||
115 | * bios returns watchlist number or negative error number. | ||
116 | */ | ||
117 | ret = (int)uv_bios_call_irqsave(UV_BIOS_WATCHLIST_ALLOC, addr, | ||
118 | size_blade.val, (u64)intr_mmr_offset, | ||
119 | (u64)&watchlist, 0); | ||
120 | if (ret < BIOS_STATUS_SUCCESS) | ||
121 | return ret; | ||
122 | |||
123 | return watchlist; | ||
124 | } | ||
125 | EXPORT_SYMBOL_GPL(uv_bios_mq_watchlist_alloc); | ||
126 | |||
127 | int | ||
128 | uv_bios_mq_watchlist_free(int blade, int watchlist_num) | ||
129 | { | ||
130 | return (int)uv_bios_call_irqsave(UV_BIOS_WATCHLIST_FREE, | ||
131 | blade, watchlist_num, 0, 0, 0); | ||
132 | } | ||
133 | EXPORT_SYMBOL_GPL(uv_bios_mq_watchlist_free); | ||
134 | |||
135 | s64 | ||
136 | uv_bios_change_memprotect(u64 paddr, u64 len, enum uv_memprotect perms) | ||
137 | { | ||
138 | return uv_bios_call_irqsave(UV_BIOS_MEMPROTECT, paddr, len, | ||
139 | perms, 0, 0); | ||
140 | } | ||
141 | EXPORT_SYMBOL_GPL(uv_bios_change_memprotect); | ||
142 | |||
143 | s64 | ||
144 | uv_bios_reserved_page_pa(u64 buf, u64 *cookie, u64 *addr, u64 *len) | ||
145 | { | ||
146 | s64 ret; | ||
147 | |||
148 | ret = uv_bios_call_irqsave(UV_BIOS_GET_PARTITION_ADDR, (u64)cookie, | ||
149 | (u64)addr, buf, (u64)len, 0); | ||
150 | return ret; | ||
151 | } | ||
152 | EXPORT_SYMBOL_GPL(uv_bios_reserved_page_pa); | ||
103 | 153 | ||
104 | s64 uv_bios_freq_base(u64 clock_type, u64 *ticks_per_second) | 154 | s64 uv_bios_freq_base(u64 clock_type, u64 *ticks_per_second) |
105 | { | 155 | { |
diff --git a/arch/x86/kernel/check.c b/arch/x86/kernel/check.c new file mode 100644 index 000000000000..2ac0ab71412a --- /dev/null +++ b/arch/x86/kernel/check.c | |||
@@ -0,0 +1,161 @@ | |||
1 | #include <linux/module.h> | ||
2 | #include <linux/sched.h> | ||
3 | #include <linux/kthread.h> | ||
4 | #include <linux/workqueue.h> | ||
5 | #include <asm/e820.h> | ||
6 | #include <asm/proto.h> | ||
7 | |||
8 | /* | ||
9 | * Some BIOSes seem to corrupt the low 64k of memory during events | ||
10 | * like suspend/resume and unplugging an HDMI cable. Reserve all | ||
11 | * remaining free memory in that area and fill it with a distinct | ||
12 | * pattern. | ||
13 | */ | ||
14 | #define MAX_SCAN_AREAS 8 | ||
15 | |||
16 | static int __read_mostly memory_corruption_check = -1; | ||
17 | |||
18 | static unsigned __read_mostly corruption_check_size = 64*1024; | ||
19 | static unsigned __read_mostly corruption_check_period = 60; /* seconds */ | ||
20 | |||
21 | static struct e820entry scan_areas[MAX_SCAN_AREAS]; | ||
22 | static int num_scan_areas; | ||
23 | |||
24 | |||
25 | static __init int set_corruption_check(char *arg) | ||
26 | { | ||
27 | char *end; | ||
28 | |||
29 | memory_corruption_check = simple_strtol(arg, &end, 10); | ||
30 | |||
31 | return (*end == 0) ? 0 : -EINVAL; | ||
32 | } | ||
33 | early_param("memory_corruption_check", set_corruption_check); | ||
34 | |||
35 | static __init int set_corruption_check_period(char *arg) | ||
36 | { | ||
37 | char *end; | ||
38 | |||
39 | corruption_check_period = simple_strtoul(arg, &end, 10); | ||
40 | |||
41 | return (*end == 0) ? 0 : -EINVAL; | ||
42 | } | ||
43 | early_param("memory_corruption_check_period", set_corruption_check_period); | ||
44 | |||
45 | static __init int set_corruption_check_size(char *arg) | ||
46 | { | ||
47 | char *end; | ||
48 | unsigned size; | ||
49 | |||
50 | size = memparse(arg, &end); | ||
51 | |||
52 | if (*end == '\0') | ||
53 | corruption_check_size = size; | ||
54 | |||
55 | return (size == corruption_check_size) ? 0 : -EINVAL; | ||
56 | } | ||
57 | early_param("memory_corruption_check_size", set_corruption_check_size); | ||
58 | |||
59 | |||
60 | void __init setup_bios_corruption_check(void) | ||
61 | { | ||
62 | u64 addr = PAGE_SIZE; /* assume first page is reserved anyway */ | ||
63 | |||
64 | if (memory_corruption_check == -1) { | ||
65 | memory_corruption_check = | ||
66 | #ifdef CONFIG_X86_BOOTPARAM_MEMORY_CORRUPTION_CHECK | ||
67 | 1 | ||
68 | #else | ||
69 | 0 | ||
70 | #endif | ||
71 | ; | ||
72 | } | ||
73 | |||
74 | if (corruption_check_size == 0) | ||
75 | memory_corruption_check = 0; | ||
76 | |||
77 | if (!memory_corruption_check) | ||
78 | return; | ||
79 | |||
80 | corruption_check_size = round_up(corruption_check_size, PAGE_SIZE); | ||
81 | |||
82 | while (addr < corruption_check_size && num_scan_areas < MAX_SCAN_AREAS) { | ||
83 | u64 size; | ||
84 | addr = find_e820_area_size(addr, &size, PAGE_SIZE); | ||
85 | |||
86 | if (addr == 0) | ||
87 | break; | ||
88 | |||
89 | if ((addr + size) > corruption_check_size) | ||
90 | size = corruption_check_size - addr; | ||
91 | |||
92 | if (size == 0) | ||
93 | break; | ||
94 | |||
95 | e820_update_range(addr, size, E820_RAM, E820_RESERVED); | ||
96 | scan_areas[num_scan_areas].addr = addr; | ||
97 | scan_areas[num_scan_areas].size = size; | ||
98 | num_scan_areas++; | ||
99 | |||
100 | /* Assume we've already mapped this early memory */ | ||
101 | memset(__va(addr), 0, size); | ||
102 | |||
103 | addr += size; | ||
104 | } | ||
105 | |||
106 | printk(KERN_INFO "Scanning %d areas for low memory corruption\n", | ||
107 | num_scan_areas); | ||
108 | update_e820(); | ||
109 | } | ||
110 | |||
111 | |||
112 | void check_for_bios_corruption(void) | ||
113 | { | ||
114 | int i; | ||
115 | int corruption = 0; | ||
116 | |||
117 | if (!memory_corruption_check) | ||
118 | return; | ||
119 | |||
120 | for (i = 0; i < num_scan_areas; i++) { | ||
121 | unsigned long *addr = __va(scan_areas[i].addr); | ||
122 | unsigned long size = scan_areas[i].size; | ||
123 | |||
124 | for (; size; addr++, size -= sizeof(unsigned long)) { | ||
125 | if (!*addr) | ||
126 | continue; | ||
127 | printk(KERN_ERR "Corrupted low memory at %p (%lx phys) = %08lx\n", | ||
128 | addr, __pa(addr), *addr); | ||
129 | corruption = 1; | ||
130 | *addr = 0; | ||
131 | } | ||
132 | } | ||
133 | |||
134 | WARN_ONCE(corruption, KERN_ERR "Memory corruption detected in low memory\n"); | ||
135 | } | ||
136 | |||
137 | static void check_corruption(struct work_struct *dummy); | ||
138 | static DECLARE_DELAYED_WORK(bios_check_work, check_corruption); | ||
139 | |||
140 | static void check_corruption(struct work_struct *dummy) | ||
141 | { | ||
142 | check_for_bios_corruption(); | ||
143 | schedule_delayed_work(&bios_check_work, | ||
144 | round_jiffies_relative(corruption_check_period*HZ)); | ||
145 | } | ||
146 | |||
147 | static int start_periodic_check_for_corruption(void) | ||
148 | { | ||
149 | if (!memory_corruption_check || corruption_check_period == 0) | ||
150 | return 0; | ||
151 | |||
152 | printk(KERN_INFO "Scanning for low memory corruption every %d seconds\n", | ||
153 | corruption_check_period); | ||
154 | |||
155 | /* First time we run the checks right away */ | ||
156 | schedule_delayed_work(&bios_check_work, 0); | ||
157 | return 0; | ||
158 | } | ||
159 | |||
160 | module_init(start_periodic_check_for_corruption); | ||
161 | |||
diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile index 82ec6075c057..82db7f45e2de 100644 --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile | |||
@@ -2,8 +2,14 @@ | |||
2 | # Makefile for x86-compatible CPU details and quirks | 2 | # Makefile for x86-compatible CPU details and quirks |
3 | # | 3 | # |
4 | 4 | ||
5 | # Don't trace early stages of a secondary CPU boot | ||
6 | ifdef CONFIG_FUNCTION_TRACER | ||
7 | CFLAGS_REMOVE_common.o = -pg | ||
8 | endif | ||
9 | |||
5 | obj-y := intel_cacheinfo.o addon_cpuid_features.o | 10 | obj-y := intel_cacheinfo.o addon_cpuid_features.o |
6 | obj-y += proc.o capflags.o powerflags.o common.o | 11 | obj-y += proc.o capflags.o powerflags.o common.o |
12 | obj-y += vmware.o hypervisor.o | ||
7 | 13 | ||
8 | obj-$(CONFIG_X86_32) += bugs.o cmpxchg.o | 14 | obj-$(CONFIG_X86_32) += bugs.o cmpxchg.o |
9 | obj-$(CONFIG_X86_64) += bugs_64.o | 15 | obj-$(CONFIG_X86_64) += bugs_64.o |
diff --git a/arch/x86/kernel/cpu/addon_cpuid_features.c b/arch/x86/kernel/cpu/addon_cpuid_features.c index ef8f831af823..2cf23634b6d9 100644 --- a/arch/x86/kernel/cpu/addon_cpuid_features.c +++ b/arch/x86/kernel/cpu/addon_cpuid_features.c | |||
@@ -120,9 +120,17 @@ void __cpuinit detect_extended_topology(struct cpuinfo_x86 *c) | |||
120 | c->cpu_core_id = phys_pkg_id(c->initial_apicid, ht_mask_width) | 120 | c->cpu_core_id = phys_pkg_id(c->initial_apicid, ht_mask_width) |
121 | & core_select_mask; | 121 | & core_select_mask; |
122 | c->phys_proc_id = phys_pkg_id(c->initial_apicid, core_plus_mask_width); | 122 | c->phys_proc_id = phys_pkg_id(c->initial_apicid, core_plus_mask_width); |
123 | /* | ||
124 | * Reinit the apicid, now that we have extended initial_apicid. | ||
125 | */ | ||
126 | c->apicid = phys_pkg_id(c->initial_apicid, 0); | ||
123 | #else | 127 | #else |
124 | c->cpu_core_id = phys_pkg_id(ht_mask_width) & core_select_mask; | 128 | c->cpu_core_id = phys_pkg_id(ht_mask_width) & core_select_mask; |
125 | c->phys_proc_id = phys_pkg_id(core_plus_mask_width); | 129 | c->phys_proc_id = phys_pkg_id(core_plus_mask_width); |
130 | /* | ||
131 | * Reinit the apicid, now that we have extended initial_apicid. | ||
132 | */ | ||
133 | c->apicid = phys_pkg_id(0); | ||
126 | #endif | 134 | #endif |
127 | c->x86_max_cores = (core_level_siblings / smp_num_siblings); | 135 | c->x86_max_cores = (core_level_siblings / smp_num_siblings); |
128 | 136 | ||
diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index 8f1e31db2ad5..7c878f6aa919 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c | |||
@@ -283,9 +283,14 @@ static void __cpuinit early_init_amd(struct cpuinfo_x86 *c) | |||
283 | { | 283 | { |
284 | early_init_amd_mc(c); | 284 | early_init_amd_mc(c); |
285 | 285 | ||
286 | /* c->x86_power is 8000_0007 edx. Bit 8 is constant TSC */ | 286 | /* |
287 | if (c->x86_power & (1<<8)) | 287 | * c->x86_power is 8000_0007 edx. Bit 8 is TSC runs at constant rate |
288 | * with P/T states and does not stop in deep C-states | ||
289 | */ | ||
290 | if (c->x86_power & (1 << 8)) { | ||
288 | set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC); | 291 | set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC); |
292 | set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC); | ||
293 | } | ||
289 | 294 | ||
290 | #ifdef CONFIG_X86_64 | 295 | #ifdef CONFIG_X86_64 |
291 | set_cpu_cap(c, X86_FEATURE_SYSCALL32); | 296 | set_cpu_cap(c, X86_FEATURE_SYSCALL32); |
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index b9c9ea0217a9..3f95a40f718a 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c | |||
@@ -36,6 +36,7 @@ | |||
36 | #include <asm/proto.h> | 36 | #include <asm/proto.h> |
37 | #include <asm/sections.h> | 37 | #include <asm/sections.h> |
38 | #include <asm/setup.h> | 38 | #include <asm/setup.h> |
39 | #include <asm/hypervisor.h> | ||
39 | 40 | ||
40 | #include "cpu.h" | 41 | #include "cpu.h" |
41 | 42 | ||
@@ -354,7 +355,7 @@ void __cpuinit detect_ht(struct cpuinfo_x86 *c) | |||
354 | printk(KERN_INFO "CPU: Hyper-Threading is disabled\n"); | 355 | printk(KERN_INFO "CPU: Hyper-Threading is disabled\n"); |
355 | } else if (smp_num_siblings > 1) { | 356 | } else if (smp_num_siblings > 1) { |
356 | 357 | ||
357 | if (smp_num_siblings > NR_CPUS) { | 358 | if (smp_num_siblings > nr_cpu_ids) { |
358 | printk(KERN_WARNING "CPU: Unsupported number of siblings %d", | 359 | printk(KERN_WARNING "CPU: Unsupported number of siblings %d", |
359 | smp_num_siblings); | 360 | smp_num_siblings); |
360 | smp_num_siblings = 1; | 361 | smp_num_siblings = 1; |
@@ -703,6 +704,7 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c) | |||
703 | detect_ht(c); | 704 | detect_ht(c); |
704 | #endif | 705 | #endif |
705 | 706 | ||
707 | init_hypervisor(c); | ||
706 | /* | 708 | /* |
707 | * On SMP, boot_cpu_data holds the common feature set between | 709 | * On SMP, boot_cpu_data holds the common feature set between |
708 | * all CPUs; so make sure that we indicate which features are | 710 | * all CPUs; so make sure that we indicate which features are |
@@ -862,7 +864,7 @@ EXPORT_SYMBOL(_cpu_pda); | |||
862 | 864 | ||
863 | struct desc_ptr idt_descr = { 256 * 16 - 1, (unsigned long) idt_table }; | 865 | struct desc_ptr idt_descr = { 256 * 16 - 1, (unsigned long) idt_table }; |
864 | 866 | ||
865 | char boot_cpu_stack[IRQSTACKSIZE] __page_aligned_bss; | 867 | static char boot_cpu_stack[IRQSTACKSIZE] __page_aligned_bss; |
866 | 868 | ||
867 | void __cpuinit pda_init(int cpu) | 869 | void __cpuinit pda_init(int cpu) |
868 | { | 870 | { |
@@ -903,8 +905,8 @@ void __cpuinit pda_init(int cpu) | |||
903 | } | 905 | } |
904 | } | 906 | } |
905 | 907 | ||
906 | char boot_exception_stacks[(N_EXCEPTION_STACKS - 1) * EXCEPTION_STKSZ + | 908 | static char boot_exception_stacks[(N_EXCEPTION_STACKS - 1) * EXCEPTION_STKSZ + |
907 | DEBUG_STKSZ] __page_aligned_bss; | 909 | DEBUG_STKSZ] __page_aligned_bss; |
908 | 910 | ||
909 | extern asmlinkage void ignore_sysret(void); | 911 | extern asmlinkage void ignore_sysret(void); |
910 | 912 | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c b/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c index 8e48c5d4467d..28102ad1a363 100644 --- a/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c +++ b/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/cpufreq.h> | 33 | #include <linux/cpufreq.h> |
34 | #include <linux/compiler.h> | 34 | #include <linux/compiler.h> |
35 | #include <linux/dmi.h> | 35 | #include <linux/dmi.h> |
36 | #include <linux/ftrace.h> | ||
36 | 37 | ||
37 | #include <linux/acpi.h> | 38 | #include <linux/acpi.h> |
38 | #include <acpi/processor.h> | 39 | #include <acpi/processor.h> |
@@ -391,6 +392,7 @@ static int acpi_cpufreq_target(struct cpufreq_policy *policy, | |||
391 | unsigned int next_perf_state = 0; /* Index into perf table */ | 392 | unsigned int next_perf_state = 0; /* Index into perf table */ |
392 | unsigned int i; | 393 | unsigned int i; |
393 | int result = 0; | 394 | int result = 0; |
395 | struct power_trace it; | ||
394 | 396 | ||
395 | dprintk("acpi_cpufreq_target %d (%d)\n", target_freq, policy->cpu); | 397 | dprintk("acpi_cpufreq_target %d (%d)\n", target_freq, policy->cpu); |
396 | 398 | ||
@@ -427,6 +429,8 @@ static int acpi_cpufreq_target(struct cpufreq_policy *policy, | |||
427 | } | 429 | } |
428 | } | 430 | } |
429 | 431 | ||
432 | trace_power_mark(&it, POWER_PSTATE, next_perf_state); | ||
433 | |||
430 | switch (data->cpu_feature) { | 434 | switch (data->cpu_feature) { |
431 | case SYSTEM_INTEL_MSR_CAPABLE: | 435 | case SYSTEM_INTEL_MSR_CAPABLE: |
432 | cmd.type = SYSTEM_INTEL_MSR_CAPABLE; | 436 | cmd.type = SYSTEM_INTEL_MSR_CAPABLE; |
@@ -513,6 +517,17 @@ acpi_cpufreq_guess_freq(struct acpi_cpufreq_data *data, unsigned int cpu) | |||
513 | } | 517 | } |
514 | } | 518 | } |
515 | 519 | ||
520 | static void free_acpi_perf_data(void) | ||
521 | { | ||
522 | unsigned int i; | ||
523 | |||
524 | /* Freeing a NULL pointer is OK, and alloc_percpu zeroes. */ | ||
525 | for_each_possible_cpu(i) | ||
526 | free_cpumask_var(per_cpu_ptr(acpi_perf_data, i) | ||
527 | ->shared_cpu_map); | ||
528 | free_percpu(acpi_perf_data); | ||
529 | } | ||
530 | |||
516 | /* | 531 | /* |
517 | * acpi_cpufreq_early_init - initialize ACPI P-States library | 532 | * acpi_cpufreq_early_init - initialize ACPI P-States library |
518 | * | 533 | * |
@@ -523,6 +538,7 @@ acpi_cpufreq_guess_freq(struct acpi_cpufreq_data *data, unsigned int cpu) | |||
523 | */ | 538 | */ |
524 | static int __init acpi_cpufreq_early_init(void) | 539 | static int __init acpi_cpufreq_early_init(void) |
525 | { | 540 | { |
541 | unsigned int i; | ||
526 | dprintk("acpi_cpufreq_early_init\n"); | 542 | dprintk("acpi_cpufreq_early_init\n"); |
527 | 543 | ||
528 | acpi_perf_data = alloc_percpu(struct acpi_processor_performance); | 544 | acpi_perf_data = alloc_percpu(struct acpi_processor_performance); |
@@ -530,6 +546,16 @@ static int __init acpi_cpufreq_early_init(void) | |||
530 | dprintk("Memory allocation error for acpi_perf_data.\n"); | 546 | dprintk("Memory allocation error for acpi_perf_data.\n"); |
531 | return -ENOMEM; | 547 | return -ENOMEM; |
532 | } | 548 | } |
549 | for_each_possible_cpu(i) { | ||
550 | if (!alloc_cpumask_var_node( | ||
551 | &per_cpu_ptr(acpi_perf_data, i)->shared_cpu_map, | ||
552 | GFP_KERNEL, cpu_to_node(i))) { | ||
553 | |||
554 | /* Freeing a NULL pointer is OK: alloc_percpu zeroes. */ | ||
555 | free_acpi_perf_data(); | ||
556 | return -ENOMEM; | ||
557 | } | ||
558 | } | ||
533 | 559 | ||
534 | /* Do initialization in ACPI core */ | 560 | /* Do initialization in ACPI core */ |
535 | acpi_processor_preregister_performance(acpi_perf_data); | 561 | acpi_processor_preregister_performance(acpi_perf_data); |
@@ -600,9 +626,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy) | |||
600 | */ | 626 | */ |
601 | if (policy->shared_type == CPUFREQ_SHARED_TYPE_ALL || | 627 | if (policy->shared_type == CPUFREQ_SHARED_TYPE_ALL || |
602 | policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) { | 628 | policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) { |
603 | policy->cpus = perf->shared_cpu_map; | 629 | cpumask_copy(&policy->cpus, perf->shared_cpu_map); |
604 | } | 630 | } |
605 | policy->related_cpus = perf->shared_cpu_map; | 631 | cpumask_copy(&policy->related_cpus, perf->shared_cpu_map); |
606 | 632 | ||
607 | #ifdef CONFIG_SMP | 633 | #ifdef CONFIG_SMP |
608 | dmi_check_system(sw_any_bug_dmi_table); | 634 | dmi_check_system(sw_any_bug_dmi_table); |
@@ -791,7 +817,7 @@ static int __init acpi_cpufreq_init(void) | |||
791 | 817 | ||
792 | ret = cpufreq_register_driver(&acpi_cpufreq_driver); | 818 | ret = cpufreq_register_driver(&acpi_cpufreq_driver); |
793 | if (ret) | 819 | if (ret) |
794 | free_percpu(acpi_perf_data); | 820 | free_acpi_perf_data(); |
795 | 821 | ||
796 | return ret; | 822 | return ret; |
797 | } | 823 | } |
diff --git a/arch/x86/kernel/cpu/cpufreq/longhaul.c b/arch/x86/kernel/cpu/cpufreq/longhaul.c index b0461856acfb..a4cff5d6e380 100644 --- a/arch/x86/kernel/cpu/cpufreq/longhaul.c +++ b/arch/x86/kernel/cpu/cpufreq/longhaul.c | |||
@@ -982,7 +982,7 @@ static int __init longhaul_init(void) | |||
982 | case 10: | 982 | case 10: |
983 | printk(KERN_ERR PFX "Use acpi-cpufreq driver for VIA C7\n"); | 983 | printk(KERN_ERR PFX "Use acpi-cpufreq driver for VIA C7\n"); |
984 | default: | 984 | default: |
985 | ;; | 985 | ; |
986 | } | 986 | } |
987 | 987 | ||
988 | return -ENODEV; | 988 | return -ENODEV; |
diff --git a/arch/x86/kernel/cpu/cpufreq/p4-clockmod.c b/arch/x86/kernel/cpu/cpufreq/p4-clockmod.c index b8e05ee4f736..beea4466b063 100644 --- a/arch/x86/kernel/cpu/cpufreq/p4-clockmod.c +++ b/arch/x86/kernel/cpu/cpufreq/p4-clockmod.c | |||
@@ -160,6 +160,7 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c) | |||
160 | switch (c->x86_model) { | 160 | switch (c->x86_model) { |
161 | case 0x0E: /* Core */ | 161 | case 0x0E: /* Core */ |
162 | case 0x0F: /* Core Duo */ | 162 | case 0x0F: /* Core Duo */ |
163 | case 0x16: /* Celeron Core */ | ||
163 | p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS; | 164 | p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS; |
164 | return speedstep_get_processor_frequency(SPEEDSTEP_PROCESSOR_PCORE); | 165 | return speedstep_get_processor_frequency(SPEEDSTEP_PROCESSOR_PCORE); |
165 | case 0x0D: /* Pentium M (Dothan) */ | 166 | case 0x0D: /* Pentium M (Dothan) */ |
@@ -171,7 +172,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c) | |||
171 | } | 172 | } |
172 | 173 | ||
173 | if (c->x86 != 0xF) { | 174 | if (c->x86 != 0xF) { |
174 | printk(KERN_WARNING PFX "Unknown p4-clockmod-capable CPU. Please send an e-mail to <cpufreq@vger.kernel.org>\n"); | 175 | if (!cpu_has(c, X86_FEATURE_EST)) |
176 | printk(KERN_WARNING PFX "Unknown p4-clockmod-capable CPU. " | ||
177 | "Please send an e-mail to <cpufreq@vger.kernel.org>\n"); | ||
175 | return 0; | 178 | return 0; |
176 | } | 179 | } |
177 | 180 | ||
@@ -274,6 +277,7 @@ static struct cpufreq_driver p4clockmod_driver = { | |||
274 | .name = "p4-clockmod", | 277 | .name = "p4-clockmod", |
275 | .owner = THIS_MODULE, | 278 | .owner = THIS_MODULE, |
276 | .attr = p4clockmod_attr, | 279 | .attr = p4clockmod_attr, |
280 | .hide_interface = 1, | ||
277 | }; | 281 | }; |
278 | 282 | ||
279 | 283 | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/powernow-k7.c b/arch/x86/kernel/cpu/cpufreq/powernow-k7.c index 7c7d56b43136..1b446d79a8fd 100644 --- a/arch/x86/kernel/cpu/cpufreq/powernow-k7.c +++ b/arch/x86/kernel/cpu/cpufreq/powernow-k7.c | |||
@@ -310,6 +310,12 @@ static int powernow_acpi_init(void) | |||
310 | goto err0; | 310 | goto err0; |
311 | } | 311 | } |
312 | 312 | ||
313 | if (!alloc_cpumask_var(&acpi_processor_perf->shared_cpu_map, | ||
314 | GFP_KERNEL)) { | ||
315 | retval = -ENOMEM; | ||
316 | goto err05; | ||
317 | } | ||
318 | |||
313 | if (acpi_processor_register_performance(acpi_processor_perf, 0)) { | 319 | if (acpi_processor_register_performance(acpi_processor_perf, 0)) { |
314 | retval = -EIO; | 320 | retval = -EIO; |
315 | goto err1; | 321 | goto err1; |
@@ -412,6 +418,8 @@ static int powernow_acpi_init(void) | |||
412 | err2: | 418 | err2: |
413 | acpi_processor_unregister_performance(acpi_processor_perf, 0); | 419 | acpi_processor_unregister_performance(acpi_processor_perf, 0); |
414 | err1: | 420 | err1: |
421 | free_cpumask_var(acpi_processor_perf->shared_cpu_map); | ||
422 | err05: | ||
415 | kfree(acpi_processor_perf); | 423 | kfree(acpi_processor_perf); |
416 | err0: | 424 | err0: |
417 | printk(KERN_WARNING PFX "ACPI perflib can not be used in this platform\n"); | 425 | printk(KERN_WARNING PFX "ACPI perflib can not be used in this platform\n"); |
@@ -652,6 +660,7 @@ static int powernow_cpu_exit (struct cpufreq_policy *policy) { | |||
652 | #ifdef CONFIG_X86_POWERNOW_K7_ACPI | 660 | #ifdef CONFIG_X86_POWERNOW_K7_ACPI |
653 | if (acpi_processor_perf) { | 661 | if (acpi_processor_perf) { |
654 | acpi_processor_unregister_performance(acpi_processor_perf, 0); | 662 | acpi_processor_unregister_performance(acpi_processor_perf, 0); |
663 | free_cpumask_var(acpi_processor_perf->shared_cpu_map); | ||
655 | kfree(acpi_processor_perf); | 664 | kfree(acpi_processor_perf); |
656 | } | 665 | } |
657 | #endif | 666 | #endif |
diff --git a/arch/x86/kernel/cpu/cpufreq/powernow-k8.c b/arch/x86/kernel/cpu/cpufreq/powernow-k8.c index 7f05f44b97e9..c3c9adbaa26f 100644 --- a/arch/x86/kernel/cpu/cpufreq/powernow-k8.c +++ b/arch/x86/kernel/cpu/cpufreq/powernow-k8.c | |||
@@ -766,7 +766,7 @@ static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned | |||
766 | static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data) | 766 | static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data) |
767 | { | 767 | { |
768 | struct cpufreq_frequency_table *powernow_table; | 768 | struct cpufreq_frequency_table *powernow_table; |
769 | int ret_val; | 769 | int ret_val = -ENODEV; |
770 | 770 | ||
771 | if (acpi_processor_register_performance(&data->acpi_data, data->cpu)) { | 771 | if (acpi_processor_register_performance(&data->acpi_data, data->cpu)) { |
772 | dprintk("register performance failed: bad ACPI data\n"); | 772 | dprintk("register performance failed: bad ACPI data\n"); |
@@ -815,6 +815,13 @@ static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data) | |||
815 | /* notify BIOS that we exist */ | 815 | /* notify BIOS that we exist */ |
816 | acpi_processor_notify_smm(THIS_MODULE); | 816 | acpi_processor_notify_smm(THIS_MODULE); |
817 | 817 | ||
818 | if (!alloc_cpumask_var(&data->acpi_data.shared_cpu_map, GFP_KERNEL)) { | ||
819 | printk(KERN_ERR PFX | ||
820 | "unable to alloc powernow_k8_data cpumask\n"); | ||
821 | ret_val = -ENOMEM; | ||
822 | goto err_out_mem; | ||
823 | } | ||
824 | |||
818 | return 0; | 825 | return 0; |
819 | 826 | ||
820 | err_out_mem: | 827 | err_out_mem: |
@@ -826,7 +833,7 @@ err_out: | |||
826 | /* data->acpi_data.state_count informs us at ->exit() whether ACPI was used */ | 833 | /* data->acpi_data.state_count informs us at ->exit() whether ACPI was used */ |
827 | data->acpi_data.state_count = 0; | 834 | data->acpi_data.state_count = 0; |
828 | 835 | ||
829 | return -ENODEV; | 836 | return ret_val; |
830 | } | 837 | } |
831 | 838 | ||
832 | static int fill_powernow_table_pstate(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table) | 839 | static int fill_powernow_table_pstate(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table) |
@@ -929,6 +936,7 @@ static void powernow_k8_cpu_exit_acpi(struct powernow_k8_data *data) | |||
929 | { | 936 | { |
930 | if (data->acpi_data.state_count) | 937 | if (data->acpi_data.state_count) |
931 | acpi_processor_unregister_performance(&data->acpi_data, data->cpu); | 938 | acpi_processor_unregister_performance(&data->acpi_data, data->cpu); |
939 | free_cpumask_var(data->acpi_data.shared_cpu_map); | ||
932 | } | 940 | } |
933 | 941 | ||
934 | #else | 942 | #else |
@@ -1134,7 +1142,8 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol) | |||
1134 | data->cpu = pol->cpu; | 1142 | data->cpu = pol->cpu; |
1135 | data->currpstate = HW_PSTATE_INVALID; | 1143 | data->currpstate = HW_PSTATE_INVALID; |
1136 | 1144 | ||
1137 | if (powernow_k8_cpu_init_acpi(data)) { | 1145 | rc = powernow_k8_cpu_init_acpi(data); |
1146 | if (rc) { | ||
1138 | /* | 1147 | /* |
1139 | * Use the PSB BIOS structure. This is only availabe on | 1148 | * Use the PSB BIOS structure. This is only availabe on |
1140 | * an UP version, and is deprecated by AMD. | 1149 | * an UP version, and is deprecated by AMD. |
@@ -1152,20 +1161,17 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol) | |||
1152 | "ACPI maintainers and complain to your BIOS " | 1161 | "ACPI maintainers and complain to your BIOS " |
1153 | "vendor.\n"); | 1162 | "vendor.\n"); |
1154 | #endif | 1163 | #endif |
1155 | kfree(data); | 1164 | goto err_out; |
1156 | return -ENODEV; | ||
1157 | } | 1165 | } |
1158 | if (pol->cpu != 0) { | 1166 | if (pol->cpu != 0) { |
1159 | printk(KERN_ERR FW_BUG PFX "No ACPI _PSS objects for " | 1167 | printk(KERN_ERR FW_BUG PFX "No ACPI _PSS objects for " |
1160 | "CPU other than CPU0. Complain to your BIOS " | 1168 | "CPU other than CPU0. Complain to your BIOS " |
1161 | "vendor.\n"); | 1169 | "vendor.\n"); |
1162 | kfree(data); | 1170 | goto err_out; |
1163 | return -ENODEV; | ||
1164 | } | 1171 | } |
1165 | rc = find_psb_table(data); | 1172 | rc = find_psb_table(data); |
1166 | if (rc) { | 1173 | if (rc) { |
1167 | kfree(data); | 1174 | goto err_out; |
1168 | return -ENODEV; | ||
1169 | } | 1175 | } |
1170 | } | 1176 | } |
1171 | 1177 | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c b/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c index 3b5f06423e77..f0ea6fa2f53c 100644 --- a/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c +++ b/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c | |||
@@ -459,9 +459,7 @@ static int centrino_verify (struct cpufreq_policy *policy) | |||
459 | * Sets a new CPUFreq policy. | 459 | * Sets a new CPUFreq policy. |
460 | */ | 460 | */ |
461 | struct allmasks { | 461 | struct allmasks { |
462 | cpumask_t online_policy_cpus; | ||
463 | cpumask_t saved_mask; | 462 | cpumask_t saved_mask; |
464 | cpumask_t set_mask; | ||
465 | cpumask_t covered_cpus; | 463 | cpumask_t covered_cpus; |
466 | }; | 464 | }; |
467 | 465 | ||
@@ -475,9 +473,7 @@ static int centrino_target (struct cpufreq_policy *policy, | |||
475 | int retval = 0; | 473 | int retval = 0; |
476 | unsigned int j, k, first_cpu, tmp; | 474 | unsigned int j, k, first_cpu, tmp; |
477 | CPUMASK_ALLOC(allmasks); | 475 | CPUMASK_ALLOC(allmasks); |
478 | CPUMASK_PTR(online_policy_cpus, allmasks); | ||
479 | CPUMASK_PTR(saved_mask, allmasks); | 476 | CPUMASK_PTR(saved_mask, allmasks); |
480 | CPUMASK_PTR(set_mask, allmasks); | ||
481 | CPUMASK_PTR(covered_cpus, allmasks); | 477 | CPUMASK_PTR(covered_cpus, allmasks); |
482 | 478 | ||
483 | if (unlikely(allmasks == NULL)) | 479 | if (unlikely(allmasks == NULL)) |
@@ -497,30 +493,28 @@ static int centrino_target (struct cpufreq_policy *policy, | |||
497 | goto out; | 493 | goto out; |
498 | } | 494 | } |
499 | 495 | ||
500 | #ifdef CONFIG_HOTPLUG_CPU | ||
501 | /* cpufreq holds the hotplug lock, so we are safe from here on */ | ||
502 | cpus_and(*online_policy_cpus, cpu_online_map, policy->cpus); | ||
503 | #else | ||
504 | *online_policy_cpus = policy->cpus; | ||
505 | #endif | ||
506 | |||
507 | *saved_mask = current->cpus_allowed; | 496 | *saved_mask = current->cpus_allowed; |
508 | first_cpu = 1; | 497 | first_cpu = 1; |
509 | cpus_clear(*covered_cpus); | 498 | cpus_clear(*covered_cpus); |
510 | for_each_cpu_mask_nr(j, *online_policy_cpus) { | 499 | for_each_cpu_mask_nr(j, policy->cpus) { |
500 | const cpumask_t *mask; | ||
501 | |||
502 | /* cpufreq holds the hotplug lock, so we are safe here */ | ||
503 | if (!cpu_online(j)) | ||
504 | continue; | ||
505 | |||
511 | /* | 506 | /* |
512 | * Support for SMP systems. | 507 | * Support for SMP systems. |
513 | * Make sure we are running on CPU that wants to change freq | 508 | * Make sure we are running on CPU that wants to change freq |
514 | */ | 509 | */ |
515 | cpus_clear(*set_mask); | ||
516 | if (policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) | 510 | if (policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) |
517 | cpus_or(*set_mask, *set_mask, *online_policy_cpus); | 511 | mask = &policy->cpus; |
518 | else | 512 | else |
519 | cpu_set(j, *set_mask); | 513 | mask = &cpumask_of_cpu(j); |
520 | 514 | ||
521 | set_cpus_allowed_ptr(current, set_mask); | 515 | set_cpus_allowed_ptr(current, mask); |
522 | preempt_disable(); | 516 | preempt_disable(); |
523 | if (unlikely(!cpu_isset(smp_processor_id(), *set_mask))) { | 517 | if (unlikely(!cpu_isset(smp_processor_id(), *mask))) { |
524 | dprintk("couldn't limit to CPUs in this domain\n"); | 518 | dprintk("couldn't limit to CPUs in this domain\n"); |
525 | retval = -EAGAIN; | 519 | retval = -EAGAIN; |
526 | if (first_cpu) { | 520 | if (first_cpu) { |
@@ -548,7 +542,9 @@ static int centrino_target (struct cpufreq_policy *policy, | |||
548 | dprintk("target=%dkHz old=%d new=%d msr=%04x\n", | 542 | dprintk("target=%dkHz old=%d new=%d msr=%04x\n", |
549 | target_freq, freqs.old, freqs.new, msr); | 543 | target_freq, freqs.old, freqs.new, msr); |
550 | 544 | ||
551 | for_each_cpu_mask_nr(k, *online_policy_cpus) { | 545 | for_each_cpu_mask_nr(k, policy->cpus) { |
546 | if (!cpu_online(k)) | ||
547 | continue; | ||
552 | freqs.cpu = k; | 548 | freqs.cpu = k; |
553 | cpufreq_notify_transition(&freqs, | 549 | cpufreq_notify_transition(&freqs, |
554 | CPUFREQ_PRECHANGE); | 550 | CPUFREQ_PRECHANGE); |
@@ -571,7 +567,9 @@ static int centrino_target (struct cpufreq_policy *policy, | |||
571 | preempt_enable(); | 567 | preempt_enable(); |
572 | } | 568 | } |
573 | 569 | ||
574 | for_each_cpu_mask_nr(k, *online_policy_cpus) { | 570 | for_each_cpu_mask_nr(k, policy->cpus) { |
571 | if (!cpu_online(k)) | ||
572 | continue; | ||
575 | freqs.cpu = k; | 573 | freqs.cpu = k; |
576 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | 574 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); |
577 | } | 575 | } |
@@ -584,18 +582,17 @@ static int centrino_target (struct cpufreq_policy *policy, | |||
584 | * Best effort undo.. | 582 | * Best effort undo.. |
585 | */ | 583 | */ |
586 | 584 | ||
587 | if (!cpus_empty(*covered_cpus)) | 585 | for_each_cpu_mask_nr(j, *covered_cpus) { |
588 | for_each_cpu_mask_nr(j, *covered_cpus) { | 586 | set_cpus_allowed_ptr(current, &cpumask_of_cpu(j)); |
589 | set_cpus_allowed_ptr(current, | 587 | wrmsr(MSR_IA32_PERF_CTL, oldmsr, h); |
590 | &cpumask_of_cpu(j)); | 588 | } |
591 | wrmsr(MSR_IA32_PERF_CTL, oldmsr, h); | ||
592 | } | ||
593 | 589 | ||
594 | tmp = freqs.new; | 590 | tmp = freqs.new; |
595 | freqs.new = freqs.old; | 591 | freqs.new = freqs.old; |
596 | freqs.old = tmp; | 592 | freqs.old = tmp; |
597 | for_each_cpu_mask_nr(j, *online_policy_cpus) { | 593 | for_each_cpu_mask_nr(j, policy->cpus) { |
598 | freqs.cpu = j; | 594 | if (!cpu_online(j)) |
595 | continue; | ||
599 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | 596 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); |
600 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | 597 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); |
601 | } | 598 | } |
diff --git a/arch/x86/kernel/cpu/cpufreq/speedstep-lib.c b/arch/x86/kernel/cpu/cpufreq/speedstep-lib.c index 98d4fdb7dc04..cdac7d62369b 100644 --- a/arch/x86/kernel/cpu/cpufreq/speedstep-lib.c +++ b/arch/x86/kernel/cpu/cpufreq/speedstep-lib.c | |||
@@ -139,6 +139,15 @@ static unsigned int pentium_core_get_frequency(void) | |||
139 | case 3: | 139 | case 3: |
140 | fsb = 166667; | 140 | fsb = 166667; |
141 | break; | 141 | break; |
142 | case 2: | ||
143 | fsb = 200000; | ||
144 | break; | ||
145 | case 0: | ||
146 | fsb = 266667; | ||
147 | break; | ||
148 | case 4: | ||
149 | fsb = 333333; | ||
150 | break; | ||
142 | default: | 151 | default: |
143 | printk(KERN_ERR "PCORE - MSR_FSB_FREQ undefined value"); | 152 | printk(KERN_ERR "PCORE - MSR_FSB_FREQ undefined value"); |
144 | } | 153 | } |
diff --git a/arch/x86/kernel/cpu/hypervisor.c b/arch/x86/kernel/cpu/hypervisor.c new file mode 100644 index 000000000000..fb5b86af0b01 --- /dev/null +++ b/arch/x86/kernel/cpu/hypervisor.c | |||
@@ -0,0 +1,58 @@ | |||
1 | /* | ||
2 | * Common hypervisor code | ||
3 | * | ||
4 | * Copyright (C) 2008, VMware, Inc. | ||
5 | * Author : Alok N Kataria <akataria@vmware.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, but | ||
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or | ||
15 | * NON INFRINGEMENT. See the GNU General Public License for more | ||
16 | * details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
21 | * | ||
22 | */ | ||
23 | |||
24 | #include <asm/processor.h> | ||
25 | #include <asm/vmware.h> | ||
26 | #include <asm/hypervisor.h> | ||
27 | |||
28 | static inline void __cpuinit | ||
29 | detect_hypervisor_vendor(struct cpuinfo_x86 *c) | ||
30 | { | ||
31 | if (vmware_platform()) { | ||
32 | c->x86_hyper_vendor = X86_HYPER_VENDOR_VMWARE; | ||
33 | } else { | ||
34 | c->x86_hyper_vendor = X86_HYPER_VENDOR_NONE; | ||
35 | } | ||
36 | } | ||
37 | |||
38 | unsigned long get_hypervisor_tsc_freq(void) | ||
39 | { | ||
40 | if (boot_cpu_data.x86_hyper_vendor == X86_HYPER_VENDOR_VMWARE) | ||
41 | return vmware_get_tsc_khz(); | ||
42 | return 0; | ||
43 | } | ||
44 | |||
45 | static inline void __cpuinit | ||
46 | hypervisor_set_feature_bits(struct cpuinfo_x86 *c) | ||
47 | { | ||
48 | if (boot_cpu_data.x86_hyper_vendor == X86_HYPER_VENDOR_VMWARE) { | ||
49 | vmware_set_feature_bits(c); | ||
50 | return; | ||
51 | } | ||
52 | } | ||
53 | |||
54 | void __cpuinit init_hypervisor(struct cpuinfo_x86 *c) | ||
55 | { | ||
56 | detect_hypervisor_vendor(c); | ||
57 | hypervisor_set_feature_bits(c); | ||
58 | } | ||
diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index cce0b6118d55..8ea6929e974c 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c | |||
@@ -11,7 +11,6 @@ | |||
11 | #include <asm/pgtable.h> | 11 | #include <asm/pgtable.h> |
12 | #include <asm/msr.h> | 12 | #include <asm/msr.h> |
13 | #include <asm/uaccess.h> | 13 | #include <asm/uaccess.h> |
14 | #include <asm/ptrace.h> | ||
15 | #include <asm/ds.h> | 14 | #include <asm/ds.h> |
16 | #include <asm/bugs.h> | 15 | #include <asm/bugs.h> |
17 | 16 | ||
@@ -41,6 +40,16 @@ static void __cpuinit early_init_intel(struct cpuinfo_x86 *c) | |||
41 | if (c->x86 == 15 && c->x86_cache_alignment == 64) | 40 | if (c->x86 == 15 && c->x86_cache_alignment == 64) |
42 | c->x86_cache_alignment = 128; | 41 | c->x86_cache_alignment = 128; |
43 | #endif | 42 | #endif |
43 | |||
44 | /* | ||
45 | * c->x86_power is 8000_0007 edx. Bit 8 is TSC runs at constant rate | ||
46 | * with P/T states and does not stop in deep C-states | ||
47 | */ | ||
48 | if (c->x86_power & (1 << 8)) { | ||
49 | set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC); | ||
50 | set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC); | ||
51 | } | ||
52 | |||
44 | } | 53 | } |
45 | 54 | ||
46 | #ifdef CONFIG_X86_32 | 55 | #ifdef CONFIG_X86_32 |
@@ -242,6 +251,13 @@ static void __cpuinit init_intel(struct cpuinfo_x86 *c) | |||
242 | 251 | ||
243 | intel_workarounds(c); | 252 | intel_workarounds(c); |
244 | 253 | ||
254 | /* | ||
255 | * Detect the extended topology information if available. This | ||
256 | * will reinitialise the initial_apicid which will be used | ||
257 | * in init_intel_cacheinfo() | ||
258 | */ | ||
259 | detect_extended_topology(c); | ||
260 | |||
245 | l2 = init_intel_cacheinfo(c); | 261 | l2 = init_intel_cacheinfo(c); |
246 | if (c->cpuid_level > 9) { | 262 | if (c->cpuid_level > 9) { |
247 | unsigned eax = cpuid_eax(10); | 263 | unsigned eax = cpuid_eax(10); |
@@ -307,13 +323,8 @@ static void __cpuinit init_intel(struct cpuinfo_x86 *c) | |||
307 | set_cpu_cap(c, X86_FEATURE_P4); | 323 | set_cpu_cap(c, X86_FEATURE_P4); |
308 | if (c->x86 == 6) | 324 | if (c->x86 == 6) |
309 | set_cpu_cap(c, X86_FEATURE_P3); | 325 | set_cpu_cap(c, X86_FEATURE_P3); |
310 | |||
311 | if (cpu_has_bts) | ||
312 | ptrace_bts_init_intel(c); | ||
313 | |||
314 | #endif | 326 | #endif |
315 | 327 | ||
316 | detect_extended_topology(c); | ||
317 | if (!cpu_has(c, X86_FEATURE_XTOPOLOGY)) { | 328 | if (!cpu_has(c, X86_FEATURE_XTOPOLOGY)) { |
318 | /* | 329 | /* |
319 | * let's use the legacy cpuid vector 0x1 and 0x4 for topology | 330 | * let's use the legacy cpuid vector 0x1 and 0x4 for topology |
diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c index 3f46afbb1cf1..48533d77be78 100644 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c | |||
@@ -534,31 +534,16 @@ static void __cpuinit free_cache_attributes(unsigned int cpu) | |||
534 | per_cpu(cpuid4_info, cpu) = NULL; | 534 | per_cpu(cpuid4_info, cpu) = NULL; |
535 | } | 535 | } |
536 | 536 | ||
537 | static int __cpuinit detect_cache_attributes(unsigned int cpu) | 537 | static void __cpuinit get_cpu_leaves(void *_retval) |
538 | { | 538 | { |
539 | struct _cpuid4_info *this_leaf; | 539 | int j, *retval = _retval, cpu = smp_processor_id(); |
540 | unsigned long j; | ||
541 | int retval; | ||
542 | cpumask_t oldmask; | ||
543 | |||
544 | if (num_cache_leaves == 0) | ||
545 | return -ENOENT; | ||
546 | |||
547 | per_cpu(cpuid4_info, cpu) = kzalloc( | ||
548 | sizeof(struct _cpuid4_info) * num_cache_leaves, GFP_KERNEL); | ||
549 | if (per_cpu(cpuid4_info, cpu) == NULL) | ||
550 | return -ENOMEM; | ||
551 | |||
552 | oldmask = current->cpus_allowed; | ||
553 | retval = set_cpus_allowed_ptr(current, &cpumask_of_cpu(cpu)); | ||
554 | if (retval) | ||
555 | goto out; | ||
556 | 540 | ||
557 | /* Do cpuid and store the results */ | 541 | /* Do cpuid and store the results */ |
558 | for (j = 0; j < num_cache_leaves; j++) { | 542 | for (j = 0; j < num_cache_leaves; j++) { |
543 | struct _cpuid4_info *this_leaf; | ||
559 | this_leaf = CPUID4_INFO_IDX(cpu, j); | 544 | this_leaf = CPUID4_INFO_IDX(cpu, j); |
560 | retval = cpuid4_cache_lookup(j, this_leaf); | 545 | *retval = cpuid4_cache_lookup(j, this_leaf); |
561 | if (unlikely(retval < 0)) { | 546 | if (unlikely(*retval < 0)) { |
562 | int i; | 547 | int i; |
563 | 548 | ||
564 | for (i = 0; i < j; i++) | 549 | for (i = 0; i < j; i++) |
@@ -567,9 +552,21 @@ static int __cpuinit detect_cache_attributes(unsigned int cpu) | |||
567 | } | 552 | } |
568 | cache_shared_cpu_map_setup(cpu, j); | 553 | cache_shared_cpu_map_setup(cpu, j); |
569 | } | 554 | } |
570 | set_cpus_allowed_ptr(current, &oldmask); | 555 | } |
556 | |||
557 | static int __cpuinit detect_cache_attributes(unsigned int cpu) | ||
558 | { | ||
559 | int retval; | ||
560 | |||
561 | if (num_cache_leaves == 0) | ||
562 | return -ENOENT; | ||
571 | 563 | ||
572 | out: | 564 | per_cpu(cpuid4_info, cpu) = kzalloc( |
565 | sizeof(struct _cpuid4_info) * num_cache_leaves, GFP_KERNEL); | ||
566 | if (per_cpu(cpuid4_info, cpu) == NULL) | ||
567 | return -ENOMEM; | ||
568 | |||
569 | smp_call_function_single(cpu, get_cpu_leaves, &retval, true); | ||
573 | if (retval) { | 570 | if (retval) { |
574 | kfree(per_cpu(cpuid4_info, cpu)); | 571 | kfree(per_cpu(cpuid4_info, cpu)); |
575 | per_cpu(cpuid4_info, cpu) = NULL; | 572 | per_cpu(cpuid4_info, cpu) = NULL; |
@@ -626,8 +623,8 @@ static ssize_t show_shared_cpu_map_func(struct _cpuid4_info *this_leaf, | |||
626 | cpumask_t *mask = &this_leaf->shared_cpu_map; | 623 | cpumask_t *mask = &this_leaf->shared_cpu_map; |
627 | 624 | ||
628 | n = type? | 625 | n = type? |
629 | cpulist_scnprintf(buf, len-2, *mask): | 626 | cpulist_scnprintf(buf, len-2, mask) : |
630 | cpumask_scnprintf(buf, len-2, *mask); | 627 | cpumask_scnprintf(buf, len-2, mask); |
631 | buf[n++] = '\n'; | 628 | buf[n++] = '\n'; |
632 | buf[n] = '\0'; | 629 | buf[n] = '\0'; |
633 | } | 630 | } |
@@ -644,20 +641,17 @@ static inline ssize_t show_shared_cpu_list(struct _cpuid4_info *leaf, char *buf) | |||
644 | return show_shared_cpu_map_func(leaf, 1, buf); | 641 | return show_shared_cpu_map_func(leaf, 1, buf); |
645 | } | 642 | } |
646 | 643 | ||
647 | static ssize_t show_type(struct _cpuid4_info *this_leaf, char *buf) { | 644 | static ssize_t show_type(struct _cpuid4_info *this_leaf, char *buf) |
648 | switch(this_leaf->eax.split.type) { | 645 | { |
649 | case CACHE_TYPE_DATA: | 646 | switch (this_leaf->eax.split.type) { |
647 | case CACHE_TYPE_DATA: | ||
650 | return sprintf(buf, "Data\n"); | 648 | return sprintf(buf, "Data\n"); |
651 | break; | 649 | case CACHE_TYPE_INST: |
652 | case CACHE_TYPE_INST: | ||
653 | return sprintf(buf, "Instruction\n"); | 650 | return sprintf(buf, "Instruction\n"); |
654 | break; | 651 | case CACHE_TYPE_UNIFIED: |
655 | case CACHE_TYPE_UNIFIED: | ||
656 | return sprintf(buf, "Unified\n"); | 652 | return sprintf(buf, "Unified\n"); |
657 | break; | 653 | default: |
658 | default: | ||
659 | return sprintf(buf, "Unknown\n"); | 654 | return sprintf(buf, "Unknown\n"); |
660 | break; | ||
661 | } | 655 | } |
662 | } | 656 | } |
663 | 657 | ||
diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd_64.c b/arch/x86/kernel/cpu/mcheck/mce_amd_64.c index 5eb390a4b2e9..a5a5e0530370 100644 --- a/arch/x86/kernel/cpu/mcheck/mce_amd_64.c +++ b/arch/x86/kernel/cpu/mcheck/mce_amd_64.c | |||
@@ -83,34 +83,41 @@ static DEFINE_PER_CPU(unsigned char, bank_map); /* see which banks are on */ | |||
83 | * CPU Initialization | 83 | * CPU Initialization |
84 | */ | 84 | */ |
85 | 85 | ||
86 | struct thresh_restart { | ||
87 | struct threshold_block *b; | ||
88 | int reset; | ||
89 | u16 old_limit; | ||
90 | }; | ||
91 | |||
86 | /* must be called with correct cpu affinity */ | 92 | /* must be called with correct cpu affinity */ |
87 | static void threshold_restart_bank(struct threshold_block *b, | 93 | static long threshold_restart_bank(void *_tr) |
88 | int reset, u16 old_limit) | ||
89 | { | 94 | { |
95 | struct thresh_restart *tr = _tr; | ||
90 | u32 mci_misc_hi, mci_misc_lo; | 96 | u32 mci_misc_hi, mci_misc_lo; |
91 | 97 | ||
92 | rdmsr(b->address, mci_misc_lo, mci_misc_hi); | 98 | rdmsr(tr->b->address, mci_misc_lo, mci_misc_hi); |
93 | 99 | ||
94 | if (b->threshold_limit < (mci_misc_hi & THRESHOLD_MAX)) | 100 | if (tr->b->threshold_limit < (mci_misc_hi & THRESHOLD_MAX)) |
95 | reset = 1; /* limit cannot be lower than err count */ | 101 | tr->reset = 1; /* limit cannot be lower than err count */ |
96 | 102 | ||
97 | if (reset) { /* reset err count and overflow bit */ | 103 | if (tr->reset) { /* reset err count and overflow bit */ |
98 | mci_misc_hi = | 104 | mci_misc_hi = |
99 | (mci_misc_hi & ~(MASK_ERR_COUNT_HI | MASK_OVERFLOW_HI)) | | 105 | (mci_misc_hi & ~(MASK_ERR_COUNT_HI | MASK_OVERFLOW_HI)) | |
100 | (THRESHOLD_MAX - b->threshold_limit); | 106 | (THRESHOLD_MAX - tr->b->threshold_limit); |
101 | } else if (old_limit) { /* change limit w/o reset */ | 107 | } else if (tr->old_limit) { /* change limit w/o reset */ |
102 | int new_count = (mci_misc_hi & THRESHOLD_MAX) + | 108 | int new_count = (mci_misc_hi & THRESHOLD_MAX) + |
103 | (old_limit - b->threshold_limit); | 109 | (tr->old_limit - tr->b->threshold_limit); |
104 | mci_misc_hi = (mci_misc_hi & ~MASK_ERR_COUNT_HI) | | 110 | mci_misc_hi = (mci_misc_hi & ~MASK_ERR_COUNT_HI) | |
105 | (new_count & THRESHOLD_MAX); | 111 | (new_count & THRESHOLD_MAX); |
106 | } | 112 | } |
107 | 113 | ||
108 | b->interrupt_enable ? | 114 | tr->b->interrupt_enable ? |
109 | (mci_misc_hi = (mci_misc_hi & ~MASK_INT_TYPE_HI) | INT_TYPE_APIC) : | 115 | (mci_misc_hi = (mci_misc_hi & ~MASK_INT_TYPE_HI) | INT_TYPE_APIC) : |
110 | (mci_misc_hi &= ~MASK_INT_TYPE_HI); | 116 | (mci_misc_hi &= ~MASK_INT_TYPE_HI); |
111 | 117 | ||
112 | mci_misc_hi |= MASK_COUNT_EN_HI; | 118 | mci_misc_hi |= MASK_COUNT_EN_HI; |
113 | wrmsr(b->address, mci_misc_lo, mci_misc_hi); | 119 | wrmsr(tr->b->address, mci_misc_lo, mci_misc_hi); |
120 | return 0; | ||
114 | } | 121 | } |
115 | 122 | ||
116 | /* cpu init entry point, called from mce.c with preempt off */ | 123 | /* cpu init entry point, called from mce.c with preempt off */ |
@@ -120,6 +127,7 @@ void __cpuinit mce_amd_feature_init(struct cpuinfo_x86 *c) | |||
120 | unsigned int cpu = smp_processor_id(); | 127 | unsigned int cpu = smp_processor_id(); |
121 | u8 lvt_off; | 128 | u8 lvt_off; |
122 | u32 low = 0, high = 0, address = 0; | 129 | u32 low = 0, high = 0, address = 0; |
130 | struct thresh_restart tr; | ||
123 | 131 | ||
124 | for (bank = 0; bank < NR_BANKS; ++bank) { | 132 | for (bank = 0; bank < NR_BANKS; ++bank) { |
125 | for (block = 0; block < NR_BLOCKS; ++block) { | 133 | for (block = 0; block < NR_BLOCKS; ++block) { |
@@ -162,7 +170,10 @@ void __cpuinit mce_amd_feature_init(struct cpuinfo_x86 *c) | |||
162 | wrmsr(address, low, high); | 170 | wrmsr(address, low, high); |
163 | 171 | ||
164 | threshold_defaults.address = address; | 172 | threshold_defaults.address = address; |
165 | threshold_restart_bank(&threshold_defaults, 0, 0); | 173 | tr.b = &threshold_defaults; |
174 | tr.reset = 0; | ||
175 | tr.old_limit = 0; | ||
176 | threshold_restart_bank(&tr); | ||
166 | } | 177 | } |
167 | } | 178 | } |
168 | } | 179 | } |
@@ -237,7 +248,7 @@ asmlinkage void mce_threshold_interrupt(void) | |||
237 | } | 248 | } |
238 | } | 249 | } |
239 | out: | 250 | out: |
240 | add_pda(irq_threshold_count, 1); | 251 | inc_irq_stat(irq_threshold_count); |
241 | irq_exit(); | 252 | irq_exit(); |
242 | } | 253 | } |
243 | 254 | ||
@@ -251,20 +262,6 @@ struct threshold_attr { | |||
251 | ssize_t(*store) (struct threshold_block *, const char *, size_t count); | 262 | ssize_t(*store) (struct threshold_block *, const char *, size_t count); |
252 | }; | 263 | }; |
253 | 264 | ||
254 | static void affinity_set(unsigned int cpu, cpumask_t *oldmask, | ||
255 | cpumask_t *newmask) | ||
256 | { | ||
257 | *oldmask = current->cpus_allowed; | ||
258 | cpus_clear(*newmask); | ||
259 | cpu_set(cpu, *newmask); | ||
260 | set_cpus_allowed_ptr(current, newmask); | ||
261 | } | ||
262 | |||
263 | static void affinity_restore(const cpumask_t *oldmask) | ||
264 | { | ||
265 | set_cpus_allowed_ptr(current, oldmask); | ||
266 | } | ||
267 | |||
268 | #define SHOW_FIELDS(name) \ | 265 | #define SHOW_FIELDS(name) \ |
269 | static ssize_t show_ ## name(struct threshold_block * b, char *buf) \ | 266 | static ssize_t show_ ## name(struct threshold_block * b, char *buf) \ |
270 | { \ | 267 | { \ |
@@ -277,15 +274,16 @@ static ssize_t store_interrupt_enable(struct threshold_block *b, | |||
277 | const char *buf, size_t count) | 274 | const char *buf, size_t count) |
278 | { | 275 | { |
279 | char *end; | 276 | char *end; |
280 | cpumask_t oldmask, newmask; | 277 | struct thresh_restart tr; |
281 | unsigned long new = simple_strtoul(buf, &end, 0); | 278 | unsigned long new = simple_strtoul(buf, &end, 0); |
282 | if (end == buf) | 279 | if (end == buf) |
283 | return -EINVAL; | 280 | return -EINVAL; |
284 | b->interrupt_enable = !!new; | 281 | b->interrupt_enable = !!new; |
285 | 282 | ||
286 | affinity_set(b->cpu, &oldmask, &newmask); | 283 | tr.b = b; |
287 | threshold_restart_bank(b, 0, 0); | 284 | tr.reset = 0; |
288 | affinity_restore(&oldmask); | 285 | tr.old_limit = 0; |
286 | work_on_cpu(b->cpu, threshold_restart_bank, &tr); | ||
289 | 287 | ||
290 | return end - buf; | 288 | return end - buf; |
291 | } | 289 | } |
@@ -294,8 +292,7 @@ static ssize_t store_threshold_limit(struct threshold_block *b, | |||
294 | const char *buf, size_t count) | 292 | const char *buf, size_t count) |
295 | { | 293 | { |
296 | char *end; | 294 | char *end; |
297 | cpumask_t oldmask, newmask; | 295 | struct thresh_restart tr; |
298 | u16 old; | ||
299 | unsigned long new = simple_strtoul(buf, &end, 0); | 296 | unsigned long new = simple_strtoul(buf, &end, 0); |
300 | if (end == buf) | 297 | if (end == buf) |
301 | return -EINVAL; | 298 | return -EINVAL; |
@@ -303,34 +300,36 @@ static ssize_t store_threshold_limit(struct threshold_block *b, | |||
303 | new = THRESHOLD_MAX; | 300 | new = THRESHOLD_MAX; |
304 | if (new < 1) | 301 | if (new < 1) |
305 | new = 1; | 302 | new = 1; |
306 | old = b->threshold_limit; | 303 | tr.old_limit = b->threshold_limit; |
307 | b->threshold_limit = new; | 304 | b->threshold_limit = new; |
305 | tr.b = b; | ||
306 | tr.reset = 0; | ||
308 | 307 | ||
309 | affinity_set(b->cpu, &oldmask, &newmask); | 308 | work_on_cpu(b->cpu, threshold_restart_bank, &tr); |
310 | threshold_restart_bank(b, 0, old); | ||
311 | affinity_restore(&oldmask); | ||
312 | 309 | ||
313 | return end - buf; | 310 | return end - buf; |
314 | } | 311 | } |
315 | 312 | ||
316 | static ssize_t show_error_count(struct threshold_block *b, char *buf) | 313 | static long local_error_count(void *_b) |
317 | { | 314 | { |
318 | u32 high, low; | 315 | struct threshold_block *b = _b; |
319 | cpumask_t oldmask, newmask; | 316 | u32 low, high; |
320 | affinity_set(b->cpu, &oldmask, &newmask); | 317 | |
321 | rdmsr(b->address, low, high); | 318 | rdmsr(b->address, low, high); |
322 | affinity_restore(&oldmask); | 319 | return (high & 0xFFF) - (THRESHOLD_MAX - b->threshold_limit); |
323 | return sprintf(buf, "%x\n", | 320 | } |
324 | (high & 0xFFF) - (THRESHOLD_MAX - b->threshold_limit)); | 321 | |
322 | static ssize_t show_error_count(struct threshold_block *b, char *buf) | ||
323 | { | ||
324 | return sprintf(buf, "%lx\n", work_on_cpu(b->cpu, local_error_count, b)); | ||
325 | } | 325 | } |
326 | 326 | ||
327 | static ssize_t store_error_count(struct threshold_block *b, | 327 | static ssize_t store_error_count(struct threshold_block *b, |
328 | const char *buf, size_t count) | 328 | const char *buf, size_t count) |
329 | { | 329 | { |
330 | cpumask_t oldmask, newmask; | 330 | struct thresh_restart tr = { .b = b, .reset = 1, .old_limit = 0 }; |
331 | affinity_set(b->cpu, &oldmask, &newmask); | 331 | |
332 | threshold_restart_bank(b, 1, 0); | 332 | work_on_cpu(b->cpu, threshold_restart_bank, &tr); |
333 | affinity_restore(&oldmask); | ||
334 | return 1; | 333 | return 1; |
335 | } | 334 | } |
336 | 335 | ||
@@ -463,12 +462,19 @@ out_free: | |||
463 | return err; | 462 | return err; |
464 | } | 463 | } |
465 | 464 | ||
465 | static long local_allocate_threshold_blocks(void *_bank) | ||
466 | { | ||
467 | unsigned int *bank = _bank; | ||
468 | |||
469 | return allocate_threshold_blocks(smp_processor_id(), *bank, 0, | ||
470 | MSR_IA32_MC0_MISC + *bank * 4); | ||
471 | } | ||
472 | |||
466 | /* symlinks sibling shared banks to first core. first core owns dir/files. */ | 473 | /* symlinks sibling shared banks to first core. first core owns dir/files. */ |
467 | static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank) | 474 | static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank) |
468 | { | 475 | { |
469 | int i, err = 0; | 476 | int i, err = 0; |
470 | struct threshold_bank *b = NULL; | 477 | struct threshold_bank *b = NULL; |
471 | cpumask_t oldmask, newmask; | ||
472 | char name[32]; | 478 | char name[32]; |
473 | 479 | ||
474 | sprintf(name, "threshold_bank%i", bank); | 480 | sprintf(name, "threshold_bank%i", bank); |
@@ -519,11 +525,7 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank) | |||
519 | 525 | ||
520 | per_cpu(threshold_banks, cpu)[bank] = b; | 526 | per_cpu(threshold_banks, cpu)[bank] = b; |
521 | 527 | ||
522 | affinity_set(cpu, &oldmask, &newmask); | 528 | err = work_on_cpu(cpu, local_allocate_threshold_blocks, &bank); |
523 | err = allocate_threshold_blocks(cpu, bank, 0, | ||
524 | MSR_IA32_MC0_MISC + bank * 4); | ||
525 | affinity_restore(&oldmask); | ||
526 | |||
527 | if (err) | 529 | if (err) |
528 | goto out_free; | 530 | goto out_free; |
529 | 531 | ||
diff --git a/arch/x86/kernel/cpu/mcheck/mce_intel_64.c b/arch/x86/kernel/cpu/mcheck/mce_intel_64.c index c17eaf5dd6dd..4b48f251fd39 100644 --- a/arch/x86/kernel/cpu/mcheck/mce_intel_64.c +++ b/arch/x86/kernel/cpu/mcheck/mce_intel_64.c | |||
@@ -26,7 +26,7 @@ asmlinkage void smp_thermal_interrupt(void) | |||
26 | if (therm_throt_process(msr_val & 1)) | 26 | if (therm_throt_process(msr_val & 1)) |
27 | mce_log_therm_throt_event(smp_processor_id(), msr_val); | 27 | mce_log_therm_throt_event(smp_processor_id(), msr_val); |
28 | 28 | ||
29 | add_pda(irq_thermal_count, 1); | 29 | inc_irq_stat(irq_thermal_count); |
30 | irq_exit(); | 30 | irq_exit(); |
31 | } | 31 | } |
32 | 32 | ||
diff --git a/arch/x86/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/generic.c index 4e8d77f01eeb..b59ddcc88cd8 100644 --- a/arch/x86/kernel/cpu/mtrr/generic.c +++ b/arch/x86/kernel/cpu/mtrr/generic.c | |||
@@ -14,14 +14,6 @@ | |||
14 | #include <asm/pat.h> | 14 | #include <asm/pat.h> |
15 | #include "mtrr.h" | 15 | #include "mtrr.h" |
16 | 16 | ||
17 | struct mtrr_state { | ||
18 | struct mtrr_var_range var_ranges[MAX_VAR_RANGES]; | ||
19 | mtrr_type fixed_ranges[NUM_FIXED_RANGES]; | ||
20 | unsigned char enabled; | ||
21 | unsigned char have_fixed; | ||
22 | mtrr_type def_type; | ||
23 | }; | ||
24 | |||
25 | struct fixed_range_block { | 17 | struct fixed_range_block { |
26 | int base_msr; /* start address of an MTRR block */ | 18 | int base_msr; /* start address of an MTRR block */ |
27 | int ranges; /* number of MTRRs in this block */ | 19 | int ranges; /* number of MTRRs in this block */ |
@@ -35,10 +27,12 @@ static struct fixed_range_block fixed_range_blocks[] = { | |||
35 | }; | 27 | }; |
36 | 28 | ||
37 | static unsigned long smp_changes_mask; | 29 | static unsigned long smp_changes_mask; |
38 | static struct mtrr_state mtrr_state = {}; | ||
39 | static int mtrr_state_set; | 30 | static int mtrr_state_set; |
40 | u64 mtrr_tom2; | 31 | u64 mtrr_tom2; |
41 | 32 | ||
33 | struct mtrr_state_type mtrr_state = {}; | ||
34 | EXPORT_SYMBOL_GPL(mtrr_state); | ||
35 | |||
42 | #undef MODULE_PARAM_PREFIX | 36 | #undef MODULE_PARAM_PREFIX |
43 | #define MODULE_PARAM_PREFIX "mtrr." | 37 | #define MODULE_PARAM_PREFIX "mtrr." |
44 | 38 | ||
diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c index c78c04821ea1..d259e5d2e054 100644 --- a/arch/x86/kernel/cpu/mtrr/main.c +++ b/arch/x86/kernel/cpu/mtrr/main.c | |||
@@ -49,7 +49,7 @@ | |||
49 | 49 | ||
50 | u32 num_var_ranges = 0; | 50 | u32 num_var_ranges = 0; |
51 | 51 | ||
52 | unsigned int mtrr_usage_table[MAX_VAR_RANGES]; | 52 | unsigned int mtrr_usage_table[MTRR_MAX_VAR_RANGES]; |
53 | static DEFINE_MUTEX(mtrr_mutex); | 53 | static DEFINE_MUTEX(mtrr_mutex); |
54 | 54 | ||
55 | u64 size_or_mask, size_and_mask; | 55 | u64 size_or_mask, size_and_mask; |
@@ -574,7 +574,7 @@ struct mtrr_value { | |||
574 | unsigned long lsize; | 574 | unsigned long lsize; |
575 | }; | 575 | }; |
576 | 576 | ||
577 | static struct mtrr_value mtrr_state[MAX_VAR_RANGES]; | 577 | static struct mtrr_value mtrr_state[MTRR_MAX_VAR_RANGES]; |
578 | 578 | ||
579 | static int mtrr_save(struct sys_device * sysdev, pm_message_t state) | 579 | static int mtrr_save(struct sys_device * sysdev, pm_message_t state) |
580 | { | 580 | { |
@@ -803,6 +803,7 @@ x86_get_mtrr_mem_range(struct res_range *range, int nr_range, | |||
803 | } | 803 | } |
804 | 804 | ||
805 | static struct res_range __initdata range[RANGE_NUM]; | 805 | static struct res_range __initdata range[RANGE_NUM]; |
806 | static int __initdata nr_range; | ||
806 | 807 | ||
807 | #ifdef CONFIG_MTRR_SANITIZER | 808 | #ifdef CONFIG_MTRR_SANITIZER |
808 | 809 | ||
@@ -823,16 +824,14 @@ static int enable_mtrr_cleanup __initdata = | |||
823 | 824 | ||
824 | static int __init disable_mtrr_cleanup_setup(char *str) | 825 | static int __init disable_mtrr_cleanup_setup(char *str) |
825 | { | 826 | { |
826 | if (enable_mtrr_cleanup != -1) | 827 | enable_mtrr_cleanup = 0; |
827 | enable_mtrr_cleanup = 0; | ||
828 | return 0; | 828 | return 0; |
829 | } | 829 | } |
830 | early_param("disable_mtrr_cleanup", disable_mtrr_cleanup_setup); | 830 | early_param("disable_mtrr_cleanup", disable_mtrr_cleanup_setup); |
831 | 831 | ||
832 | static int __init enable_mtrr_cleanup_setup(char *str) | 832 | static int __init enable_mtrr_cleanup_setup(char *str) |
833 | { | 833 | { |
834 | if (enable_mtrr_cleanup != -1) | 834 | enable_mtrr_cleanup = 1; |
835 | enable_mtrr_cleanup = 1; | ||
836 | return 0; | 835 | return 0; |
837 | } | 836 | } |
838 | early_param("enable_mtrr_cleanup", enable_mtrr_cleanup_setup); | 837 | early_param("enable_mtrr_cleanup", enable_mtrr_cleanup_setup); |
@@ -1206,39 +1205,43 @@ struct mtrr_cleanup_result { | |||
1206 | #define PSHIFT (PAGE_SHIFT - 10) | 1205 | #define PSHIFT (PAGE_SHIFT - 10) |
1207 | 1206 | ||
1208 | static struct mtrr_cleanup_result __initdata result[NUM_RESULT]; | 1207 | static struct mtrr_cleanup_result __initdata result[NUM_RESULT]; |
1209 | static struct res_range __initdata range_new[RANGE_NUM]; | ||
1210 | static unsigned long __initdata min_loss_pfn[RANGE_NUM]; | 1208 | static unsigned long __initdata min_loss_pfn[RANGE_NUM]; |
1211 | 1209 | ||
1212 | static int __init mtrr_cleanup(unsigned address_bits) | 1210 | static void __init print_out_mtrr_range_state(void) |
1213 | { | 1211 | { |
1214 | unsigned long extra_remove_base, extra_remove_size; | ||
1215 | unsigned long base, size, def, dummy; | ||
1216 | mtrr_type type; | ||
1217 | int nr_range, nr_range_new; | ||
1218 | u64 chunk_size, gran_size; | ||
1219 | unsigned long range_sums, range_sums_new; | ||
1220 | int index_good; | ||
1221 | int num_reg_good; | ||
1222 | int i; | 1212 | int i; |
1213 | char start_factor = 'K', size_factor = 'K'; | ||
1214 | unsigned long start_base, size_base; | ||
1215 | mtrr_type type; | ||
1223 | 1216 | ||
1224 | /* extra one for all 0 */ | 1217 | for (i = 0; i < num_var_ranges; i++) { |
1225 | int num[MTRR_NUM_TYPES + 1]; | ||
1226 | 1218 | ||
1227 | if (!is_cpu(INTEL) || enable_mtrr_cleanup < 1) | 1219 | size_base = range_state[i].size_pfn << (PAGE_SHIFT - 10); |
1228 | return 0; | 1220 | if (!size_base) |
1229 | rdmsr(MTRRdefType_MSR, def, dummy); | 1221 | continue; |
1230 | def &= 0xff; | ||
1231 | if (def != MTRR_TYPE_UNCACHABLE) | ||
1232 | return 0; | ||
1233 | 1222 | ||
1234 | /* get it and store it aside */ | 1223 | size_base = to_size_factor(size_base, &size_factor), |
1235 | memset(range_state, 0, sizeof(range_state)); | 1224 | start_base = range_state[i].base_pfn << (PAGE_SHIFT - 10); |
1236 | for (i = 0; i < num_var_ranges; i++) { | 1225 | start_base = to_size_factor(start_base, &start_factor), |
1237 | mtrr_if->get(i, &base, &size, &type); | 1226 | type = range_state[i].type; |
1238 | range_state[i].base_pfn = base; | 1227 | |
1239 | range_state[i].size_pfn = size; | 1228 | printk(KERN_DEBUG "reg %d, base: %ld%cB, range: %ld%cB, type %s\n", |
1240 | range_state[i].type = type; | 1229 | i, start_base, start_factor, |
1230 | size_base, size_factor, | ||
1231 | (type == MTRR_TYPE_UNCACHABLE) ? "UC" : | ||
1232 | ((type == MTRR_TYPE_WRPROT) ? "WP" : | ||
1233 | ((type == MTRR_TYPE_WRBACK) ? "WB" : "Other")) | ||
1234 | ); | ||
1241 | } | 1235 | } |
1236 | } | ||
1237 | |||
1238 | static int __init mtrr_need_cleanup(void) | ||
1239 | { | ||
1240 | int i; | ||
1241 | mtrr_type type; | ||
1242 | unsigned long size; | ||
1243 | /* extra one for all 0 */ | ||
1244 | int num[MTRR_NUM_TYPES + 1]; | ||
1242 | 1245 | ||
1243 | /* check entries number */ | 1246 | /* check entries number */ |
1244 | memset(num, 0, sizeof(num)); | 1247 | memset(num, 0, sizeof(num)); |
@@ -1263,29 +1266,133 @@ static int __init mtrr_cleanup(unsigned address_bits) | |||
1263 | num_var_ranges - num[MTRR_NUM_TYPES]) | 1266 | num_var_ranges - num[MTRR_NUM_TYPES]) |
1264 | return 0; | 1267 | return 0; |
1265 | 1268 | ||
1266 | /* print original var MTRRs at first, for debugging: */ | 1269 | return 1; |
1267 | printk(KERN_DEBUG "original variable MTRRs\n"); | 1270 | } |
1268 | for (i = 0; i < num_var_ranges; i++) { | ||
1269 | char start_factor = 'K', size_factor = 'K'; | ||
1270 | unsigned long start_base, size_base; | ||
1271 | 1271 | ||
1272 | size_base = range_state[i].size_pfn << (PAGE_SHIFT - 10); | 1272 | static unsigned long __initdata range_sums; |
1273 | if (!size_base) | 1273 | static void __init mtrr_calc_range_state(u64 chunk_size, u64 gran_size, |
1274 | continue; | 1274 | unsigned long extra_remove_base, |
1275 | unsigned long extra_remove_size, | ||
1276 | int i) | ||
1277 | { | ||
1278 | int num_reg; | ||
1279 | static struct res_range range_new[RANGE_NUM]; | ||
1280 | static int nr_range_new; | ||
1281 | unsigned long range_sums_new; | ||
1282 | |||
1283 | /* convert ranges to var ranges state */ | ||
1284 | num_reg = x86_setup_var_mtrrs(range, nr_range, | ||
1285 | chunk_size, gran_size); | ||
1286 | |||
1287 | /* we got new setting in range_state, check it */ | ||
1288 | memset(range_new, 0, sizeof(range_new)); | ||
1289 | nr_range_new = x86_get_mtrr_mem_range(range_new, 0, | ||
1290 | extra_remove_base, extra_remove_size); | ||
1291 | range_sums_new = sum_ranges(range_new, nr_range_new); | ||
1292 | |||
1293 | result[i].chunk_sizek = chunk_size >> 10; | ||
1294 | result[i].gran_sizek = gran_size >> 10; | ||
1295 | result[i].num_reg = num_reg; | ||
1296 | if (range_sums < range_sums_new) { | ||
1297 | result[i].lose_cover_sizek = | ||
1298 | (range_sums_new - range_sums) << PSHIFT; | ||
1299 | result[i].bad = 1; | ||
1300 | } else | ||
1301 | result[i].lose_cover_sizek = | ||
1302 | (range_sums - range_sums_new) << PSHIFT; | ||
1275 | 1303 | ||
1276 | size_base = to_size_factor(size_base, &size_factor), | 1304 | /* double check it */ |
1277 | start_base = range_state[i].base_pfn << (PAGE_SHIFT - 10); | 1305 | if (!result[i].bad && !result[i].lose_cover_sizek) { |
1278 | start_base = to_size_factor(start_base, &start_factor), | 1306 | if (nr_range_new != nr_range || |
1279 | type = range_state[i].type; | 1307 | memcmp(range, range_new, sizeof(range))) |
1308 | result[i].bad = 1; | ||
1309 | } | ||
1280 | 1310 | ||
1281 | printk(KERN_DEBUG "reg %d, base: %ld%cB, range: %ld%cB, type %s\n", | 1311 | if (!result[i].bad && (range_sums - range_sums_new < |
1282 | i, start_base, start_factor, | 1312 | min_loss_pfn[num_reg])) { |
1283 | size_base, size_factor, | 1313 | min_loss_pfn[num_reg] = |
1284 | (type == MTRR_TYPE_UNCACHABLE) ? "UC" : | 1314 | range_sums - range_sums_new; |
1285 | ((type == MTRR_TYPE_WRPROT) ? "WP" : | ||
1286 | ((type == MTRR_TYPE_WRBACK) ? "WB" : "Other")) | ||
1287 | ); | ||
1288 | } | 1315 | } |
1316 | } | ||
1317 | |||
1318 | static void __init mtrr_print_out_one_result(int i) | ||
1319 | { | ||
1320 | char gran_factor, chunk_factor, lose_factor; | ||
1321 | unsigned long gran_base, chunk_base, lose_base; | ||
1322 | |||
1323 | gran_base = to_size_factor(result[i].gran_sizek, &gran_factor), | ||
1324 | chunk_base = to_size_factor(result[i].chunk_sizek, &chunk_factor), | ||
1325 | lose_base = to_size_factor(result[i].lose_cover_sizek, &lose_factor), | ||
1326 | printk(KERN_INFO "%sgran_size: %ld%c \tchunk_size: %ld%c \t", | ||
1327 | result[i].bad ? "*BAD*" : " ", | ||
1328 | gran_base, gran_factor, chunk_base, chunk_factor); | ||
1329 | printk(KERN_CONT "num_reg: %d \tlose cover RAM: %s%ld%c\n", | ||
1330 | result[i].num_reg, result[i].bad ? "-" : "", | ||
1331 | lose_base, lose_factor); | ||
1332 | } | ||
1333 | |||
1334 | static int __init mtrr_search_optimal_index(void) | ||
1335 | { | ||
1336 | int i; | ||
1337 | int num_reg_good; | ||
1338 | int index_good; | ||
1339 | |||
1340 | if (nr_mtrr_spare_reg >= num_var_ranges) | ||
1341 | nr_mtrr_spare_reg = num_var_ranges - 1; | ||
1342 | num_reg_good = -1; | ||
1343 | for (i = num_var_ranges - nr_mtrr_spare_reg; i > 0; i--) { | ||
1344 | if (!min_loss_pfn[i]) | ||
1345 | num_reg_good = i; | ||
1346 | } | ||
1347 | |||
1348 | index_good = -1; | ||
1349 | if (num_reg_good != -1) { | ||
1350 | for (i = 0; i < NUM_RESULT; i++) { | ||
1351 | if (!result[i].bad && | ||
1352 | result[i].num_reg == num_reg_good && | ||
1353 | !result[i].lose_cover_sizek) { | ||
1354 | index_good = i; | ||
1355 | break; | ||
1356 | } | ||
1357 | } | ||
1358 | } | ||
1359 | |||
1360 | return index_good; | ||
1361 | } | ||
1362 | |||
1363 | |||
1364 | static int __init mtrr_cleanup(unsigned address_bits) | ||
1365 | { | ||
1366 | unsigned long extra_remove_base, extra_remove_size; | ||
1367 | unsigned long base, size, def, dummy; | ||
1368 | mtrr_type type; | ||
1369 | u64 chunk_size, gran_size; | ||
1370 | int index_good; | ||
1371 | int i; | ||
1372 | |||
1373 | if (!is_cpu(INTEL) || enable_mtrr_cleanup < 1) | ||
1374 | return 0; | ||
1375 | rdmsr(MTRRdefType_MSR, def, dummy); | ||
1376 | def &= 0xff; | ||
1377 | if (def != MTRR_TYPE_UNCACHABLE) | ||
1378 | return 0; | ||
1379 | |||
1380 | /* get it and store it aside */ | ||
1381 | memset(range_state, 0, sizeof(range_state)); | ||
1382 | for (i = 0; i < num_var_ranges; i++) { | ||
1383 | mtrr_if->get(i, &base, &size, &type); | ||
1384 | range_state[i].base_pfn = base; | ||
1385 | range_state[i].size_pfn = size; | ||
1386 | range_state[i].type = type; | ||
1387 | } | ||
1388 | |||
1389 | /* check if we need handle it and can handle it */ | ||
1390 | if (!mtrr_need_cleanup()) | ||
1391 | return 0; | ||
1392 | |||
1393 | /* print original var MTRRs at first, for debugging: */ | ||
1394 | printk(KERN_DEBUG "original variable MTRRs\n"); | ||
1395 | print_out_mtrr_range_state(); | ||
1289 | 1396 | ||
1290 | memset(range, 0, sizeof(range)); | 1397 | memset(range, 0, sizeof(range)); |
1291 | extra_remove_size = 0; | 1398 | extra_remove_size = 0; |
@@ -1309,176 +1416,64 @@ static int __init mtrr_cleanup(unsigned address_bits) | |||
1309 | range_sums >> (20 - PAGE_SHIFT)); | 1416 | range_sums >> (20 - PAGE_SHIFT)); |
1310 | 1417 | ||
1311 | if (mtrr_chunk_size && mtrr_gran_size) { | 1418 | if (mtrr_chunk_size && mtrr_gran_size) { |
1312 | int num_reg; | 1419 | i = 0; |
1313 | char gran_factor, chunk_factor, lose_factor; | 1420 | mtrr_calc_range_state(mtrr_chunk_size, mtrr_gran_size, |
1314 | unsigned long gran_base, chunk_base, lose_base; | 1421 | extra_remove_base, extra_remove_size, i); |
1315 | |||
1316 | debug_print++; | ||
1317 | /* convert ranges to var ranges state */ | ||
1318 | num_reg = x86_setup_var_mtrrs(range, nr_range, mtrr_chunk_size, | ||
1319 | mtrr_gran_size); | ||
1320 | 1422 | ||
1321 | /* we got new setting in range_state, check it */ | 1423 | mtrr_print_out_one_result(i); |
1322 | memset(range_new, 0, sizeof(range_new)); | ||
1323 | nr_range_new = x86_get_mtrr_mem_range(range_new, 0, | ||
1324 | extra_remove_base, | ||
1325 | extra_remove_size); | ||
1326 | range_sums_new = sum_ranges(range_new, nr_range_new); | ||
1327 | 1424 | ||
1328 | i = 0; | ||
1329 | result[i].chunk_sizek = mtrr_chunk_size >> 10; | ||
1330 | result[i].gran_sizek = mtrr_gran_size >> 10; | ||
1331 | result[i].num_reg = num_reg; | ||
1332 | if (range_sums < range_sums_new) { | ||
1333 | result[i].lose_cover_sizek = | ||
1334 | (range_sums_new - range_sums) << PSHIFT; | ||
1335 | result[i].bad = 1; | ||
1336 | } else | ||
1337 | result[i].lose_cover_sizek = | ||
1338 | (range_sums - range_sums_new) << PSHIFT; | ||
1339 | |||
1340 | gran_base = to_size_factor(result[i].gran_sizek, &gran_factor), | ||
1341 | chunk_base = to_size_factor(result[i].chunk_sizek, &chunk_factor), | ||
1342 | lose_base = to_size_factor(result[i].lose_cover_sizek, &lose_factor), | ||
1343 | printk(KERN_INFO "%sgran_size: %ld%c \tchunk_size: %ld%c \t", | ||
1344 | result[i].bad?"*BAD*":" ", | ||
1345 | gran_base, gran_factor, chunk_base, chunk_factor); | ||
1346 | printk(KERN_CONT "num_reg: %d \tlose cover RAM: %s%ld%c\n", | ||
1347 | result[i].num_reg, result[i].bad?"-":"", | ||
1348 | lose_base, lose_factor); | ||
1349 | if (!result[i].bad) { | 1425 | if (!result[i].bad) { |
1350 | set_var_mtrr_all(address_bits); | 1426 | set_var_mtrr_all(address_bits); |
1351 | return 1; | 1427 | return 1; |
1352 | } | 1428 | } |
1353 | printk(KERN_INFO "invalid mtrr_gran_size or mtrr_chunk_size, " | 1429 | printk(KERN_INFO "invalid mtrr_gran_size or mtrr_chunk_size, " |
1354 | "will find optimal one\n"); | 1430 | "will find optimal one\n"); |
1355 | debug_print--; | ||
1356 | memset(result, 0, sizeof(result[0])); | ||
1357 | } | 1431 | } |
1358 | 1432 | ||
1359 | i = 0; | 1433 | i = 0; |
1360 | memset(min_loss_pfn, 0xff, sizeof(min_loss_pfn)); | 1434 | memset(min_loss_pfn, 0xff, sizeof(min_loss_pfn)); |
1361 | memset(result, 0, sizeof(result)); | 1435 | memset(result, 0, sizeof(result)); |
1362 | for (gran_size = (1ULL<<16); gran_size < (1ULL<<32); gran_size <<= 1) { | 1436 | for (gran_size = (1ULL<<16); gran_size < (1ULL<<32); gran_size <<= 1) { |
1363 | char gran_factor; | ||
1364 | unsigned long gran_base; | ||
1365 | |||
1366 | if (debug_print) | ||
1367 | gran_base = to_size_factor(gran_size >> 10, &gran_factor); | ||
1368 | 1437 | ||
1369 | for (chunk_size = gran_size; chunk_size < (1ULL<<32); | 1438 | for (chunk_size = gran_size; chunk_size < (1ULL<<32); |
1370 | chunk_size <<= 1) { | 1439 | chunk_size <<= 1) { |
1371 | int num_reg; | ||
1372 | 1440 | ||
1373 | if (debug_print) { | ||
1374 | char chunk_factor; | ||
1375 | unsigned long chunk_base; | ||
1376 | |||
1377 | chunk_base = to_size_factor(chunk_size>>10, &chunk_factor), | ||
1378 | printk(KERN_INFO "\n"); | ||
1379 | printk(KERN_INFO "gran_size: %ld%c chunk_size: %ld%c \n", | ||
1380 | gran_base, gran_factor, chunk_base, chunk_factor); | ||
1381 | } | ||
1382 | if (i >= NUM_RESULT) | 1441 | if (i >= NUM_RESULT) |
1383 | continue; | 1442 | continue; |
1384 | 1443 | ||
1385 | /* convert ranges to var ranges state */ | 1444 | mtrr_calc_range_state(chunk_size, gran_size, |
1386 | num_reg = x86_setup_var_mtrrs(range, nr_range, | 1445 | extra_remove_base, extra_remove_size, i); |
1387 | chunk_size, gran_size); | 1446 | if (debug_print) { |
1388 | 1447 | mtrr_print_out_one_result(i); | |
1389 | /* we got new setting in range_state, check it */ | 1448 | printk(KERN_INFO "\n"); |
1390 | memset(range_new, 0, sizeof(range_new)); | ||
1391 | nr_range_new = x86_get_mtrr_mem_range(range_new, 0, | ||
1392 | extra_remove_base, extra_remove_size); | ||
1393 | range_sums_new = sum_ranges(range_new, nr_range_new); | ||
1394 | |||
1395 | result[i].chunk_sizek = chunk_size >> 10; | ||
1396 | result[i].gran_sizek = gran_size >> 10; | ||
1397 | result[i].num_reg = num_reg; | ||
1398 | if (range_sums < range_sums_new) { | ||
1399 | result[i].lose_cover_sizek = | ||
1400 | (range_sums_new - range_sums) << PSHIFT; | ||
1401 | result[i].bad = 1; | ||
1402 | } else | ||
1403 | result[i].lose_cover_sizek = | ||
1404 | (range_sums - range_sums_new) << PSHIFT; | ||
1405 | |||
1406 | /* double check it */ | ||
1407 | if (!result[i].bad && !result[i].lose_cover_sizek) { | ||
1408 | if (nr_range_new != nr_range || | ||
1409 | memcmp(range, range_new, sizeof(range))) | ||
1410 | result[i].bad = 1; | ||
1411 | } | 1449 | } |
1412 | 1450 | ||
1413 | if (!result[i].bad && (range_sums - range_sums_new < | ||
1414 | min_loss_pfn[num_reg])) { | ||
1415 | min_loss_pfn[num_reg] = | ||
1416 | range_sums - range_sums_new; | ||
1417 | } | ||
1418 | i++; | 1451 | i++; |
1419 | } | 1452 | } |
1420 | } | 1453 | } |
1421 | 1454 | ||
1422 | /* print out all */ | ||
1423 | for (i = 0; i < NUM_RESULT; i++) { | ||
1424 | char gran_factor, chunk_factor, lose_factor; | ||
1425 | unsigned long gran_base, chunk_base, lose_base; | ||
1426 | |||
1427 | gran_base = to_size_factor(result[i].gran_sizek, &gran_factor), | ||
1428 | chunk_base = to_size_factor(result[i].chunk_sizek, &chunk_factor), | ||
1429 | lose_base = to_size_factor(result[i].lose_cover_sizek, &lose_factor), | ||
1430 | printk(KERN_INFO "%sgran_size: %ld%c \tchunk_size: %ld%c \t", | ||
1431 | result[i].bad?"*BAD*":" ", | ||
1432 | gran_base, gran_factor, chunk_base, chunk_factor); | ||
1433 | printk(KERN_CONT "num_reg: %d \tlose cover RAM: %s%ld%c\n", | ||
1434 | result[i].num_reg, result[i].bad?"-":"", | ||
1435 | lose_base, lose_factor); | ||
1436 | } | ||
1437 | |||
1438 | /* try to find the optimal index */ | 1455 | /* try to find the optimal index */ |
1439 | if (nr_mtrr_spare_reg >= num_var_ranges) | 1456 | index_good = mtrr_search_optimal_index(); |
1440 | nr_mtrr_spare_reg = num_var_ranges - 1; | ||
1441 | num_reg_good = -1; | ||
1442 | for (i = num_var_ranges - nr_mtrr_spare_reg; i > 0; i--) { | ||
1443 | if (!min_loss_pfn[i]) | ||
1444 | num_reg_good = i; | ||
1445 | } | ||
1446 | |||
1447 | index_good = -1; | ||
1448 | if (num_reg_good != -1) { | ||
1449 | for (i = 0; i < NUM_RESULT; i++) { | ||
1450 | if (!result[i].bad && | ||
1451 | result[i].num_reg == num_reg_good && | ||
1452 | !result[i].lose_cover_sizek) { | ||
1453 | index_good = i; | ||
1454 | break; | ||
1455 | } | ||
1456 | } | ||
1457 | } | ||
1458 | 1457 | ||
1459 | if (index_good != -1) { | 1458 | if (index_good != -1) { |
1460 | char gran_factor, chunk_factor, lose_factor; | ||
1461 | unsigned long gran_base, chunk_base, lose_base; | ||
1462 | |||
1463 | printk(KERN_INFO "Found optimal setting for mtrr clean up\n"); | 1459 | printk(KERN_INFO "Found optimal setting for mtrr clean up\n"); |
1464 | i = index_good; | 1460 | i = index_good; |
1465 | gran_base = to_size_factor(result[i].gran_sizek, &gran_factor), | 1461 | mtrr_print_out_one_result(i); |
1466 | chunk_base = to_size_factor(result[i].chunk_sizek, &chunk_factor), | 1462 | |
1467 | lose_base = to_size_factor(result[i].lose_cover_sizek, &lose_factor), | ||
1468 | printk(KERN_INFO "gran_size: %ld%c \tchunk_size: %ld%c \t", | ||
1469 | gran_base, gran_factor, chunk_base, chunk_factor); | ||
1470 | printk(KERN_CONT "num_reg: %d \tlose RAM: %ld%c\n", | ||
1471 | result[i].num_reg, lose_base, lose_factor); | ||
1472 | /* convert ranges to var ranges state */ | 1463 | /* convert ranges to var ranges state */ |
1473 | chunk_size = result[i].chunk_sizek; | 1464 | chunk_size = result[i].chunk_sizek; |
1474 | chunk_size <<= 10; | 1465 | chunk_size <<= 10; |
1475 | gran_size = result[i].gran_sizek; | 1466 | gran_size = result[i].gran_sizek; |
1476 | gran_size <<= 10; | 1467 | gran_size <<= 10; |
1477 | debug_print++; | ||
1478 | x86_setup_var_mtrrs(range, nr_range, chunk_size, gran_size); | 1468 | x86_setup_var_mtrrs(range, nr_range, chunk_size, gran_size); |
1479 | debug_print--; | ||
1480 | set_var_mtrr_all(address_bits); | 1469 | set_var_mtrr_all(address_bits); |
1470 | printk(KERN_DEBUG "New variable MTRRs\n"); | ||
1471 | print_out_mtrr_range_state(); | ||
1481 | return 1; | 1472 | return 1; |
1473 | } else { | ||
1474 | /* print out all */ | ||
1475 | for (i = 0; i < NUM_RESULT; i++) | ||
1476 | mtrr_print_out_one_result(i); | ||
1482 | } | 1477 | } |
1483 | 1478 | ||
1484 | printk(KERN_INFO "mtrr_cleanup: can not find optimal value\n"); | 1479 | printk(KERN_INFO "mtrr_cleanup: can not find optimal value\n"); |
@@ -1562,7 +1557,6 @@ int __init mtrr_trim_uncached_memory(unsigned long end_pfn) | |||
1562 | { | 1557 | { |
1563 | unsigned long i, base, size, highest_pfn = 0, def, dummy; | 1558 | unsigned long i, base, size, highest_pfn = 0, def, dummy; |
1564 | mtrr_type type; | 1559 | mtrr_type type; |
1565 | int nr_range; | ||
1566 | u64 total_trim_size; | 1560 | u64 total_trim_size; |
1567 | 1561 | ||
1568 | /* extra one for all 0 */ | 1562 | /* extra one for all 0 */ |
diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h index 2dc4ec656b23..ffd60409cc6d 100644 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h | |||
@@ -8,11 +8,6 @@ | |||
8 | #define MTRRcap_MSR 0x0fe | 8 | #define MTRRcap_MSR 0x0fe |
9 | #define MTRRdefType_MSR 0x2ff | 9 | #define MTRRdefType_MSR 0x2ff |
10 | 10 | ||
11 | #define MTRRphysBase_MSR(reg) (0x200 + 2 * (reg)) | ||
12 | #define MTRRphysMask_MSR(reg) (0x200 + 2 * (reg) + 1) | ||
13 | |||
14 | #define NUM_FIXED_RANGES 88 | ||
15 | #define MAX_VAR_RANGES 256 | ||
16 | #define MTRRfix64K_00000_MSR 0x250 | 11 | #define MTRRfix64K_00000_MSR 0x250 |
17 | #define MTRRfix16K_80000_MSR 0x258 | 12 | #define MTRRfix16K_80000_MSR 0x258 |
18 | #define MTRRfix16K_A0000_MSR 0x259 | 13 | #define MTRRfix16K_A0000_MSR 0x259 |
@@ -29,11 +24,7 @@ | |||
29 | #define MTRR_CHANGE_MASK_VARIABLE 0x02 | 24 | #define MTRR_CHANGE_MASK_VARIABLE 0x02 |
30 | #define MTRR_CHANGE_MASK_DEFTYPE 0x04 | 25 | #define MTRR_CHANGE_MASK_DEFTYPE 0x04 |
31 | 26 | ||
32 | /* In the Intel processor's MTRR interface, the MTRR type is always held in | 27 | extern unsigned int mtrr_usage_table[MTRR_MAX_VAR_RANGES]; |
33 | an 8 bit field: */ | ||
34 | typedef u8 mtrr_type; | ||
35 | |||
36 | extern unsigned int mtrr_usage_table[MAX_VAR_RANGES]; | ||
37 | 28 | ||
38 | struct mtrr_ops { | 29 | struct mtrr_ops { |
39 | u32 vendor; | 30 | u32 vendor; |
@@ -70,13 +61,6 @@ struct set_mtrr_context { | |||
70 | u32 ccr3; | 61 | u32 ccr3; |
71 | }; | 62 | }; |
72 | 63 | ||
73 | struct mtrr_var_range { | ||
74 | u32 base_lo; | ||
75 | u32 base_hi; | ||
76 | u32 mask_lo; | ||
77 | u32 mask_hi; | ||
78 | }; | ||
79 | |||
80 | void set_mtrr_done(struct set_mtrr_context *ctxt); | 64 | void set_mtrr_done(struct set_mtrr_context *ctxt); |
81 | void set_mtrr_cache_disable(struct set_mtrr_context *ctxt); | 65 | void set_mtrr_cache_disable(struct set_mtrr_context *ctxt); |
82 | void set_mtrr_prepare_save(struct set_mtrr_context *ctxt); | 66 | void set_mtrr_prepare_save(struct set_mtrr_context *ctxt); |
diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c new file mode 100644 index 000000000000..284c399e3234 --- /dev/null +++ b/arch/x86/kernel/cpu/vmware.c | |||
@@ -0,0 +1,112 @@ | |||
1 | /* | ||
2 | * VMware Detection code. | ||
3 | * | ||
4 | * Copyright (C) 2008, VMware, Inc. | ||
5 | * Author : Alok N Kataria <akataria@vmware.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, but | ||
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or | ||
15 | * NON INFRINGEMENT. See the GNU General Public License for more | ||
16 | * details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
21 | * | ||
22 | */ | ||
23 | |||
24 | #include <linux/dmi.h> | ||
25 | #include <asm/div64.h> | ||
26 | #include <asm/vmware.h> | ||
27 | |||
28 | #define CPUID_VMWARE_INFO_LEAF 0x40000000 | ||
29 | #define VMWARE_HYPERVISOR_MAGIC 0x564D5868 | ||
30 | #define VMWARE_HYPERVISOR_PORT 0x5658 | ||
31 | |||
32 | #define VMWARE_PORT_CMD_GETVERSION 10 | ||
33 | #define VMWARE_PORT_CMD_GETHZ 45 | ||
34 | |||
35 | #define VMWARE_PORT(cmd, eax, ebx, ecx, edx) \ | ||
36 | __asm__("inl (%%dx)" : \ | ||
37 | "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ | ||
38 | "0"(VMWARE_HYPERVISOR_MAGIC), \ | ||
39 | "1"(VMWARE_PORT_CMD_##cmd), \ | ||
40 | "2"(VMWARE_HYPERVISOR_PORT), "3"(UINT_MAX) : \ | ||
41 | "memory"); | ||
42 | |||
43 | static inline int __vmware_platform(void) | ||
44 | { | ||
45 | uint32_t eax, ebx, ecx, edx; | ||
46 | VMWARE_PORT(GETVERSION, eax, ebx, ecx, edx); | ||
47 | return eax != (uint32_t)-1 && ebx == VMWARE_HYPERVISOR_MAGIC; | ||
48 | } | ||
49 | |||
50 | static unsigned long __vmware_get_tsc_khz(void) | ||
51 | { | ||
52 | uint64_t tsc_hz; | ||
53 | uint32_t eax, ebx, ecx, edx; | ||
54 | |||
55 | VMWARE_PORT(GETHZ, eax, ebx, ecx, edx); | ||
56 | |||
57 | if (ebx == UINT_MAX) | ||
58 | return 0; | ||
59 | tsc_hz = eax | (((uint64_t)ebx) << 32); | ||
60 | do_div(tsc_hz, 1000); | ||
61 | BUG_ON(tsc_hz >> 32); | ||
62 | return tsc_hz; | ||
63 | } | ||
64 | |||
65 | /* | ||
66 | * While checking the dmi string infomation, just checking the product | ||
67 | * serial key should be enough, as this will always have a VMware | ||
68 | * specific string when running under VMware hypervisor. | ||
69 | */ | ||
70 | int vmware_platform(void) | ||
71 | { | ||
72 | if (cpu_has_hypervisor) { | ||
73 | unsigned int eax, ebx, ecx, edx; | ||
74 | char hyper_vendor_id[13]; | ||
75 | |||
76 | cpuid(CPUID_VMWARE_INFO_LEAF, &eax, &ebx, &ecx, &edx); | ||
77 | memcpy(hyper_vendor_id + 0, &ebx, 4); | ||
78 | memcpy(hyper_vendor_id + 4, &ecx, 4); | ||
79 | memcpy(hyper_vendor_id + 8, &edx, 4); | ||
80 | hyper_vendor_id[12] = '\0'; | ||
81 | if (!strcmp(hyper_vendor_id, "VMwareVMware")) | ||
82 | return 1; | ||
83 | } else if (dmi_available && dmi_name_in_serial("VMware") && | ||
84 | __vmware_platform()) | ||
85 | return 1; | ||
86 | |||
87 | return 0; | ||
88 | } | ||
89 | |||
90 | unsigned long vmware_get_tsc_khz(void) | ||
91 | { | ||
92 | BUG_ON(!vmware_platform()); | ||
93 | return __vmware_get_tsc_khz(); | ||
94 | } | ||
95 | |||
96 | /* | ||
97 | * VMware hypervisor takes care of exporting a reliable TSC to the guest. | ||
98 | * Still, due to timing difference when running on virtual cpus, the TSC can | ||
99 | * be marked as unstable in some cases. For example, the TSC sync check at | ||
100 | * bootup can fail due to a marginal offset between vcpus' TSCs (though the | ||
101 | * TSCs do not drift from each other). Also, the ACPI PM timer clocksource | ||
102 | * is not suitable as a watchdog when running on a hypervisor because the | ||
103 | * kernel may miss a wrap of the counter if the vcpu is descheduled for a | ||
104 | * long time. To skip these checks at runtime we set these capability bits, | ||
105 | * so that the kernel could just trust the hypervisor with providing a | ||
106 | * reliable virtual TSC that is suitable for timekeeping. | ||
107 | */ | ||
108 | void __cpuinit vmware_set_feature_bits(struct cpuinfo_x86 *c) | ||
109 | { | ||
110 | set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC); | ||
111 | set_cpu_cap(c, X86_FEATURE_TSC_RELIABLE); | ||
112 | } | ||
diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c index 72cefd1e649b..2ac1f0c2beb3 100644 --- a/arch/x86/kernel/cpuid.c +++ b/arch/x86/kernel/cpuid.c | |||
@@ -39,10 +39,10 @@ | |||
39 | #include <linux/device.h> | 39 | #include <linux/device.h> |
40 | #include <linux/cpu.h> | 40 | #include <linux/cpu.h> |
41 | #include <linux/notifier.h> | 41 | #include <linux/notifier.h> |
42 | #include <linux/uaccess.h> | ||
42 | 43 | ||
43 | #include <asm/processor.h> | 44 | #include <asm/processor.h> |
44 | #include <asm/msr.h> | 45 | #include <asm/msr.h> |
45 | #include <asm/uaccess.h> | ||
46 | #include <asm/system.h> | 46 | #include <asm/system.h> |
47 | 47 | ||
48 | static struct class *cpuid_class; | 48 | static struct class *cpuid_class; |
@@ -82,7 +82,7 @@ static loff_t cpuid_seek(struct file *file, loff_t offset, int orig) | |||
82 | } | 82 | } |
83 | 83 | ||
84 | static ssize_t cpuid_read(struct file *file, char __user *buf, | 84 | static ssize_t cpuid_read(struct file *file, char __user *buf, |
85 | size_t count, loff_t * ppos) | 85 | size_t count, loff_t *ppos) |
86 | { | 86 | { |
87 | char __user *tmp = buf; | 87 | char __user *tmp = buf; |
88 | struct cpuid_regs cmd; | 88 | struct cpuid_regs cmd; |
@@ -117,11 +117,11 @@ static int cpuid_open(struct inode *inode, struct file *file) | |||
117 | unsigned int cpu; | 117 | unsigned int cpu; |
118 | struct cpuinfo_x86 *c; | 118 | struct cpuinfo_x86 *c; |
119 | int ret = 0; | 119 | int ret = 0; |
120 | 120 | ||
121 | lock_kernel(); | 121 | lock_kernel(); |
122 | 122 | ||
123 | cpu = iminor(file->f_path.dentry->d_inode); | 123 | cpu = iminor(file->f_path.dentry->d_inode); |
124 | if (cpu >= NR_CPUS || !cpu_online(cpu)) { | 124 | if (cpu >= nr_cpu_ids || !cpu_online(cpu)) { |
125 | ret = -ENXIO; /* No such CPU */ | 125 | ret = -ENXIO; /* No such CPU */ |
126 | goto out; | 126 | goto out; |
127 | } | 127 | } |
diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c index 268553817909..c689d19e35ab 100644 --- a/arch/x86/kernel/crash.c +++ b/arch/x86/kernel/crash.c | |||
@@ -26,37 +26,21 @@ | |||
26 | #include <linux/kdebug.h> | 26 | #include <linux/kdebug.h> |
27 | #include <asm/smp.h> | 27 | #include <asm/smp.h> |
28 | #include <asm/reboot.h> | 28 | #include <asm/reboot.h> |
29 | #include <asm/virtext.h> | ||
29 | 30 | ||
30 | #include <mach_ipi.h> | 31 | #include <mach_ipi.h> |
31 | 32 | ||
32 | /* This keeps a track of which one is crashing cpu. */ | ||
33 | static int crashing_cpu; | ||
34 | 33 | ||
35 | #if defined(CONFIG_SMP) && defined(CONFIG_X86_LOCAL_APIC) | 34 | #if defined(CONFIG_SMP) && defined(CONFIG_X86_LOCAL_APIC) |
36 | static atomic_t waiting_for_crash_ipi; | ||
37 | 35 | ||
38 | static int crash_nmi_callback(struct notifier_block *self, | 36 | static void kdump_nmi_callback(int cpu, struct die_args *args) |
39 | unsigned long val, void *data) | ||
40 | { | 37 | { |
41 | struct pt_regs *regs; | 38 | struct pt_regs *regs; |
42 | #ifdef CONFIG_X86_32 | 39 | #ifdef CONFIG_X86_32 |
43 | struct pt_regs fixed_regs; | 40 | struct pt_regs fixed_regs; |
44 | #endif | 41 | #endif |
45 | int cpu; | ||
46 | 42 | ||
47 | if (val != DIE_NMI_IPI) | 43 | regs = args->regs; |
48 | return NOTIFY_OK; | ||
49 | |||
50 | regs = ((struct die_args *)data)->regs; | ||
51 | cpu = raw_smp_processor_id(); | ||
52 | |||
53 | /* Don't do anything if this handler is invoked on crashing cpu. | ||
54 | * Otherwise, system will completely hang. Crashing cpu can get | ||
55 | * an NMI if system was initially booted with nmi_watchdog parameter. | ||
56 | */ | ||
57 | if (cpu == crashing_cpu) | ||
58 | return NOTIFY_STOP; | ||
59 | local_irq_disable(); | ||
60 | 44 | ||
61 | #ifdef CONFIG_X86_32 | 45 | #ifdef CONFIG_X86_32 |
62 | if (!user_mode_vm(regs)) { | 46 | if (!user_mode_vm(regs)) { |
@@ -65,54 +49,28 @@ static int crash_nmi_callback(struct notifier_block *self, | |||
65 | } | 49 | } |
66 | #endif | 50 | #endif |
67 | crash_save_cpu(regs, cpu); | 51 | crash_save_cpu(regs, cpu); |
68 | disable_local_APIC(); | ||
69 | atomic_dec(&waiting_for_crash_ipi); | ||
70 | /* Assume hlt works */ | ||
71 | halt(); | ||
72 | for (;;) | ||
73 | cpu_relax(); | ||
74 | 52 | ||
75 | return 1; | 53 | /* Disable VMX or SVM if needed. |
76 | } | 54 | * |
55 | * We need to disable virtualization on all CPUs. | ||
56 | * Having VMX or SVM enabled on any CPU may break rebooting | ||
57 | * after the kdump kernel has finished its task. | ||
58 | */ | ||
59 | cpu_emergency_vmxoff(); | ||
60 | cpu_emergency_svm_disable(); | ||
77 | 61 | ||
78 | static void smp_send_nmi_allbutself(void) | 62 | disable_local_APIC(); |
79 | { | ||
80 | cpumask_t mask = cpu_online_map; | ||
81 | cpu_clear(safe_smp_processor_id(), mask); | ||
82 | if (!cpus_empty(mask)) | ||
83 | send_IPI_mask(mask, NMI_VECTOR); | ||
84 | } | 63 | } |
85 | 64 | ||
86 | static struct notifier_block crash_nmi_nb = { | 65 | static void kdump_nmi_shootdown_cpus(void) |
87 | .notifier_call = crash_nmi_callback, | ||
88 | }; | ||
89 | |||
90 | static void nmi_shootdown_cpus(void) | ||
91 | { | 66 | { |
92 | unsigned long msecs; | 67 | nmi_shootdown_cpus(kdump_nmi_callback); |
93 | |||
94 | atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1); | ||
95 | /* Would it be better to replace the trap vector here? */ | ||
96 | if (register_die_notifier(&crash_nmi_nb)) | ||
97 | return; /* return what? */ | ||
98 | /* Ensure the new callback function is set before sending | ||
99 | * out the NMI | ||
100 | */ | ||
101 | wmb(); | ||
102 | |||
103 | smp_send_nmi_allbutself(); | ||
104 | |||
105 | msecs = 1000; /* Wait at most a second for the other cpus to stop */ | ||
106 | while ((atomic_read(&waiting_for_crash_ipi) > 0) && msecs) { | ||
107 | mdelay(1); | ||
108 | msecs--; | ||
109 | } | ||
110 | 68 | ||
111 | /* Leave the nmi callback set */ | ||
112 | disable_local_APIC(); | 69 | disable_local_APIC(); |
113 | } | 70 | } |
71 | |||
114 | #else | 72 | #else |
115 | static void nmi_shootdown_cpus(void) | 73 | static void kdump_nmi_shootdown_cpus(void) |
116 | { | 74 | { |
117 | /* There are no cpus to shootdown */ | 75 | /* There are no cpus to shootdown */ |
118 | } | 76 | } |
@@ -131,9 +89,15 @@ void native_machine_crash_shutdown(struct pt_regs *regs) | |||
131 | /* The kernel is broken so disable interrupts */ | 89 | /* The kernel is broken so disable interrupts */ |
132 | local_irq_disable(); | 90 | local_irq_disable(); |
133 | 91 | ||
134 | /* Make a note of crashing cpu. Will be used in NMI callback.*/ | 92 | kdump_nmi_shootdown_cpus(); |
135 | crashing_cpu = safe_smp_processor_id(); | 93 | |
136 | nmi_shootdown_cpus(); | 94 | /* Booting kdump kernel with VMX or SVM enabled won't work, |
95 | * because (among other limitations) we can't disable paging | ||
96 | * with the virt flags. | ||
97 | */ | ||
98 | cpu_emergency_vmxoff(); | ||
99 | cpu_emergency_svm_disable(); | ||
100 | |||
137 | lapic_shutdown(); | 101 | lapic_shutdown(); |
138 | #if defined(CONFIG_X86_IO_APIC) | 102 | #if defined(CONFIG_X86_IO_APIC) |
139 | disable_IO_APIC(); | 103 | disable_IO_APIC(); |
diff --git a/arch/x86/kernel/ds.c b/arch/x86/kernel/ds.c index a2d1176c38ee..da91701a2348 100644 --- a/arch/x86/kernel/ds.c +++ b/arch/x86/kernel/ds.c | |||
@@ -6,14 +6,13 @@ | |||
6 | * precise-event based sampling (PEBS). | 6 | * precise-event based sampling (PEBS). |
7 | * | 7 | * |
8 | * It manages: | 8 | * It manages: |
9 | * - per-thread and per-cpu allocation of BTS and PEBS | 9 | * - DS and BTS hardware configuration |
10 | * - buffer memory allocation (optional) | 10 | * - buffer overflow handling (to be done) |
11 | * - buffer overflow handling | ||
12 | * - buffer access | 11 | * - buffer access |
13 | * | 12 | * |
14 | * It assumes: | 13 | * It does not do: |
15 | * - get_task_struct on all parameter tasks | 14 | * - security checking (is the caller allowed to trace the task) |
16 | * - current is allowed to trace parameter tasks | 15 | * - buffer allocation (memory accounting) |
17 | * | 16 | * |
18 | * | 17 | * |
19 | * Copyright (C) 2007-2008 Intel Corporation. | 18 | * Copyright (C) 2007-2008 Intel Corporation. |
@@ -28,22 +27,69 @@ | |||
28 | #include <linux/slab.h> | 27 | #include <linux/slab.h> |
29 | #include <linux/sched.h> | 28 | #include <linux/sched.h> |
30 | #include <linux/mm.h> | 29 | #include <linux/mm.h> |
30 | #include <linux/kernel.h> | ||
31 | 31 | ||
32 | 32 | ||
33 | /* | 33 | /* |
34 | * The configuration for a particular DS hardware implementation. | 34 | * The configuration for a particular DS hardware implementation. |
35 | */ | 35 | */ |
36 | struct ds_configuration { | 36 | struct ds_configuration { |
37 | /* the size of the DS structure in bytes */ | 37 | /* the name of the configuration */ |
38 | unsigned char sizeof_ds; | 38 | const char *name; |
39 | /* the size of one pointer-typed field in the DS structure in bytes; | 39 | /* the size of one pointer-typed field in the DS structure and |
40 | this covers the first 8 fields related to buffer management. */ | 40 | in the BTS and PEBS buffers in bytes; |
41 | this covers the first 8 DS fields related to buffer management. */ | ||
41 | unsigned char sizeof_field; | 42 | unsigned char sizeof_field; |
42 | /* the size of a BTS/PEBS record in bytes */ | 43 | /* the size of a BTS/PEBS record in bytes */ |
43 | unsigned char sizeof_rec[2]; | 44 | unsigned char sizeof_rec[2]; |
45 | /* a series of bit-masks to control various features indexed | ||
46 | * by enum ds_feature */ | ||
47 | unsigned long ctl[dsf_ctl_max]; | ||
44 | }; | 48 | }; |
45 | static struct ds_configuration ds_cfg; | 49 | static DEFINE_PER_CPU(struct ds_configuration, ds_cfg_array); |
46 | 50 | ||
51 | #define ds_cfg per_cpu(ds_cfg_array, smp_processor_id()) | ||
52 | |||
53 | #define MAX_SIZEOF_DS (12 * 8) /* maximal size of a DS configuration */ | ||
54 | #define MAX_SIZEOF_BTS (3 * 8) /* maximal size of a BTS record */ | ||
55 | #define DS_ALIGNMENT (1 << 3) /* BTS and PEBS buffer alignment */ | ||
56 | |||
57 | #define BTS_CONTROL \ | ||
58 | (ds_cfg.ctl[dsf_bts] | ds_cfg.ctl[dsf_bts_kernel] | ds_cfg.ctl[dsf_bts_user] |\ | ||
59 | ds_cfg.ctl[dsf_bts_overflow]) | ||
60 | |||
61 | |||
62 | /* | ||
63 | * A BTS or PEBS tracer. | ||
64 | * | ||
65 | * This holds the configuration of the tracer and serves as a handle | ||
66 | * to identify tracers. | ||
67 | */ | ||
68 | struct ds_tracer { | ||
69 | /* the DS context (partially) owned by this tracer */ | ||
70 | struct ds_context *context; | ||
71 | /* the buffer provided on ds_request() and its size in bytes */ | ||
72 | void *buffer; | ||
73 | size_t size; | ||
74 | }; | ||
75 | |||
76 | struct bts_tracer { | ||
77 | /* the common DS part */ | ||
78 | struct ds_tracer ds; | ||
79 | /* the trace including the DS configuration */ | ||
80 | struct bts_trace trace; | ||
81 | /* buffer overflow notification function */ | ||
82 | bts_ovfl_callback_t ovfl; | ||
83 | }; | ||
84 | |||
85 | struct pebs_tracer { | ||
86 | /* the common DS part */ | ||
87 | struct ds_tracer ds; | ||
88 | /* the trace including the DS configuration */ | ||
89 | struct pebs_trace trace; | ||
90 | /* buffer overflow notification function */ | ||
91 | pebs_ovfl_callback_t ovfl; | ||
92 | }; | ||
47 | 93 | ||
48 | /* | 94 | /* |
49 | * Debug Store (DS) save area configuration (see Intel64 and IA32 | 95 | * Debug Store (DS) save area configuration (see Intel64 and IA32 |
@@ -109,32 +155,9 @@ static inline void ds_set(unsigned char *base, enum ds_qualifier qual, | |||
109 | 155 | ||
110 | 156 | ||
111 | /* | 157 | /* |
112 | * Locking is done only for allocating BTS or PEBS resources and for | 158 | * Locking is done only for allocating BTS or PEBS resources. |
113 | * guarding context and buffer memory allocation. | ||
114 | * | ||
115 | * Most functions require the current task to own the ds context part | ||
116 | * they are going to access. All the locking is done when validating | ||
117 | * access to the context. | ||
118 | */ | 159 | */ |
119 | static spinlock_t ds_lock = __SPIN_LOCK_UNLOCKED(ds_lock); | 160 | static DEFINE_SPINLOCK(ds_lock); |
120 | |||
121 | /* | ||
122 | * Validate that the current task is allowed to access the BTS/PEBS | ||
123 | * buffer of the parameter task. | ||
124 | * | ||
125 | * Returns 0, if access is granted; -Eerrno, otherwise. | ||
126 | */ | ||
127 | static inline int ds_validate_access(struct ds_context *context, | ||
128 | enum ds_qualifier qual) | ||
129 | { | ||
130 | if (!context) | ||
131 | return -EPERM; | ||
132 | |||
133 | if (context->owner[qual] == current) | ||
134 | return 0; | ||
135 | |||
136 | return -EPERM; | ||
137 | } | ||
138 | 161 | ||
139 | 162 | ||
140 | /* | 163 | /* |
@@ -150,27 +173,32 @@ static inline int ds_validate_access(struct ds_context *context, | |||
150 | * >0 number of per-thread tracers | 173 | * >0 number of per-thread tracers |
151 | * <0 number of per-cpu tracers | 174 | * <0 number of per-cpu tracers |
152 | * | 175 | * |
153 | * The below functions to get and put tracers and to check the | ||
154 | * allocation type require the ds_lock to be held by the caller. | ||
155 | * | ||
156 | * Tracers essentially gives the number of ds contexts for a certain | 176 | * Tracers essentially gives the number of ds contexts for a certain |
157 | * type of allocation. | 177 | * type of allocation. |
158 | */ | 178 | */ |
159 | static long tracers; | 179 | static atomic_t tracers = ATOMIC_INIT(0); |
160 | 180 | ||
161 | static inline void get_tracer(struct task_struct *task) | 181 | static inline void get_tracer(struct task_struct *task) |
162 | { | 182 | { |
163 | tracers += (task ? 1 : -1); | 183 | if (task) |
184 | atomic_inc(&tracers); | ||
185 | else | ||
186 | atomic_dec(&tracers); | ||
164 | } | 187 | } |
165 | 188 | ||
166 | static inline void put_tracer(struct task_struct *task) | 189 | static inline void put_tracer(struct task_struct *task) |
167 | { | 190 | { |
168 | tracers -= (task ? 1 : -1); | 191 | if (task) |
192 | atomic_dec(&tracers); | ||
193 | else | ||
194 | atomic_inc(&tracers); | ||
169 | } | 195 | } |
170 | 196 | ||
171 | static inline int check_tracer(struct task_struct *task) | 197 | static inline int check_tracer(struct task_struct *task) |
172 | { | 198 | { |
173 | return (task ? (tracers >= 0) : (tracers <= 0)); | 199 | return task ? |
200 | (atomic_read(&tracers) >= 0) : | ||
201 | (atomic_read(&tracers) <= 0); | ||
174 | } | 202 | } |
175 | 203 | ||
176 | 204 | ||
@@ -183,99 +211,70 @@ static inline int check_tracer(struct task_struct *task) | |||
183 | * | 211 | * |
184 | * Contexts are use-counted. They are allocated on first access and | 212 | * Contexts are use-counted. They are allocated on first access and |
185 | * deallocated when the last user puts the context. | 213 | * deallocated when the last user puts the context. |
186 | * | ||
187 | * We distinguish between an allocating and a non-allocating get of a | ||
188 | * context: | ||
189 | * - the allocating get is used for requesting BTS/PEBS resources. It | ||
190 | * requires the caller to hold the global ds_lock. | ||
191 | * - the non-allocating get is used for all other cases. A | ||
192 | * non-existing context indicates an error. It acquires and releases | ||
193 | * the ds_lock itself for obtaining the context. | ||
194 | * | ||
195 | * A context and its DS configuration are allocated and deallocated | ||
196 | * together. A context always has a DS configuration of the | ||
197 | * appropriate size. | ||
198 | */ | ||
199 | static DEFINE_PER_CPU(struct ds_context *, system_context); | ||
200 | |||
201 | #define this_system_context per_cpu(system_context, smp_processor_id()) | ||
202 | |||
203 | /* | ||
204 | * Returns the pointer to the parameter task's context or to the | ||
205 | * system-wide context, if task is NULL. | ||
206 | * | ||
207 | * Increases the use count of the returned context, if not NULL. | ||
208 | */ | 214 | */ |
209 | static inline struct ds_context *ds_get_context(struct task_struct *task) | 215 | struct ds_context { |
210 | { | 216 | /* pointer to the DS configuration; goes into MSR_IA32_DS_AREA */ |
211 | struct ds_context *context; | 217 | unsigned char ds[MAX_SIZEOF_DS]; |
212 | unsigned long irq; | 218 | /* the owner of the BTS and PEBS configuration, respectively */ |
219 | struct bts_tracer *bts_master; | ||
220 | struct pebs_tracer *pebs_master; | ||
221 | /* use count */ | ||
222 | unsigned long count; | ||
223 | /* a pointer to the context location inside the thread_struct | ||
224 | * or the per_cpu context array */ | ||
225 | struct ds_context **this; | ||
226 | /* a pointer to the task owning this context, or NULL, if the | ||
227 | * context is owned by a cpu */ | ||
228 | struct task_struct *task; | ||
229 | }; | ||
213 | 230 | ||
214 | spin_lock_irqsave(&ds_lock, irq); | 231 | static DEFINE_PER_CPU(struct ds_context *, system_context_array); |
215 | 232 | ||
216 | context = (task ? task->thread.ds_ctx : this_system_context); | 233 | #define system_context per_cpu(system_context_array, smp_processor_id()) |
217 | if (context) | ||
218 | context->count++; | ||
219 | 234 | ||
220 | spin_unlock_irqrestore(&ds_lock, irq); | ||
221 | |||
222 | return context; | ||
223 | } | ||
224 | 235 | ||
225 | /* | 236 | static inline struct ds_context *ds_get_context(struct task_struct *task) |
226 | * Same as ds_get_context, but allocates the context and it's DS | ||
227 | * structure, if necessary; returns NULL; if out of memory. | ||
228 | */ | ||
229 | static inline struct ds_context *ds_alloc_context(struct task_struct *task) | ||
230 | { | 237 | { |
231 | struct ds_context **p_context = | 238 | struct ds_context **p_context = |
232 | (task ? &task->thread.ds_ctx : &this_system_context); | 239 | (task ? &task->thread.ds_ctx : &system_context); |
233 | struct ds_context *context = *p_context; | 240 | struct ds_context *context = NULL; |
241 | struct ds_context *new_context = NULL; | ||
234 | unsigned long irq; | 242 | unsigned long irq; |
235 | 243 | ||
236 | if (!context) { | 244 | /* Chances are small that we already have a context. */ |
237 | context = kzalloc(sizeof(*context), GFP_KERNEL); | 245 | new_context = kzalloc(sizeof(*new_context), GFP_KERNEL); |
238 | if (!context) | 246 | if (!new_context) |
239 | return NULL; | 247 | return NULL; |
240 | |||
241 | context->ds = kzalloc(ds_cfg.sizeof_ds, GFP_KERNEL); | ||
242 | if (!context->ds) { | ||
243 | kfree(context); | ||
244 | return NULL; | ||
245 | } | ||
246 | 248 | ||
247 | spin_lock_irqsave(&ds_lock, irq); | 249 | spin_lock_irqsave(&ds_lock, irq); |
248 | 250 | ||
249 | if (*p_context) { | 251 | context = *p_context; |
250 | kfree(context->ds); | 252 | if (!context) { |
251 | kfree(context); | 253 | context = new_context; |
252 | 254 | ||
253 | context = *p_context; | 255 | context->this = p_context; |
254 | } else { | 256 | context->task = task; |
255 | *p_context = context; | 257 | context->count = 0; |
256 | 258 | ||
257 | context->this = p_context; | 259 | if (task) |
258 | context->task = task; | 260 | set_tsk_thread_flag(task, TIF_DS_AREA_MSR); |
259 | 261 | ||
260 | if (task) | 262 | if (!task || (task == current)) |
261 | set_tsk_thread_flag(task, TIF_DS_AREA_MSR); | 263 | wrmsrl(MSR_IA32_DS_AREA, (unsigned long)context->ds); |
262 | 264 | ||
263 | if (!task || (task == current)) | 265 | *p_context = context; |
264 | wrmsrl(MSR_IA32_DS_AREA, | ||
265 | (unsigned long)context->ds); | ||
266 | } | ||
267 | spin_unlock_irqrestore(&ds_lock, irq); | ||
268 | } | 266 | } |
269 | 267 | ||
270 | context->count++; | 268 | context->count++; |
271 | 269 | ||
270 | spin_unlock_irqrestore(&ds_lock, irq); | ||
271 | |||
272 | if (context != new_context) | ||
273 | kfree(new_context); | ||
274 | |||
272 | return context; | 275 | return context; |
273 | } | 276 | } |
274 | 277 | ||
275 | /* | ||
276 | * Decreases the use count of the parameter context, if not NULL. | ||
277 | * Deallocates the context, if the use count reaches zero. | ||
278 | */ | ||
279 | static inline void ds_put_context(struct ds_context *context) | 278 | static inline void ds_put_context(struct ds_context *context) |
280 | { | 279 | { |
281 | unsigned long irq; | 280 | unsigned long irq; |
@@ -285,8 +284,10 @@ static inline void ds_put_context(struct ds_context *context) | |||
285 | 284 | ||
286 | spin_lock_irqsave(&ds_lock, irq); | 285 | spin_lock_irqsave(&ds_lock, irq); |
287 | 286 | ||
288 | if (--context->count) | 287 | if (--context->count) { |
289 | goto out; | 288 | spin_unlock_irqrestore(&ds_lock, irq); |
289 | return; | ||
290 | } | ||
290 | 291 | ||
291 | *(context->this) = NULL; | 292 | *(context->this) = NULL; |
292 | 293 | ||
@@ -296,135 +297,263 @@ static inline void ds_put_context(struct ds_context *context) | |||
296 | if (!context->task || (context->task == current)) | 297 | if (!context->task || (context->task == current)) |
297 | wrmsrl(MSR_IA32_DS_AREA, 0); | 298 | wrmsrl(MSR_IA32_DS_AREA, 0); |
298 | 299 | ||
299 | put_tracer(context->task); | 300 | spin_unlock_irqrestore(&ds_lock, irq); |
300 | 301 | ||
301 | /* free any leftover buffers from tracers that did not | ||
302 | * deallocate them properly. */ | ||
303 | kfree(context->buffer[ds_bts]); | ||
304 | kfree(context->buffer[ds_pebs]); | ||
305 | kfree(context->ds); | ||
306 | kfree(context); | 302 | kfree(context); |
307 | out: | ||
308 | spin_unlock_irqrestore(&ds_lock, irq); | ||
309 | } | 303 | } |
310 | 304 | ||
311 | 305 | ||
312 | /* | 306 | /* |
313 | * Handle a buffer overflow | 307 | * Call the tracer's callback on a buffer overflow. |
314 | * | 308 | * |
315 | * task: the task whose buffers are overflowing; | ||
316 | * NULL for a buffer overflow on the current cpu | ||
317 | * context: the ds context | 309 | * context: the ds context |
318 | * qual: the buffer type | 310 | * qual: the buffer type |
319 | */ | 311 | */ |
320 | static void ds_overflow(struct task_struct *task, struct ds_context *context, | 312 | static void ds_overflow(struct ds_context *context, enum ds_qualifier qual) |
321 | enum ds_qualifier qual) | ||
322 | { | 313 | { |
323 | if (!context) | 314 | switch (qual) { |
324 | return; | 315 | case ds_bts: |
325 | 316 | if (context->bts_master && | |
326 | if (context->callback[qual]) | 317 | context->bts_master->ovfl) |
327 | (*context->callback[qual])(task); | 318 | context->bts_master->ovfl(context->bts_master); |
328 | 319 | break; | |
329 | /* todo: do some more overflow handling */ | 320 | case ds_pebs: |
321 | if (context->pebs_master && | ||
322 | context->pebs_master->ovfl) | ||
323 | context->pebs_master->ovfl(context->pebs_master); | ||
324 | break; | ||
325 | } | ||
330 | } | 326 | } |
331 | 327 | ||
332 | 328 | ||
333 | /* | 329 | /* |
334 | * Allocate a non-pageable buffer of the parameter size. | 330 | * Write raw data into the BTS or PEBS buffer. |
335 | * Checks the memory and the locked memory rlimit. | ||
336 | * | 331 | * |
337 | * Returns the buffer, if successful; | 332 | * The remainder of any partially written record is zeroed out. |
338 | * NULL, if out of memory or rlimit exceeded. | ||
339 | * | 333 | * |
340 | * size: the requested buffer size in bytes | 334 | * context: the DS context |
341 | * pages (out): if not NULL, contains the number of pages reserved | 335 | * qual: the buffer type |
336 | * record: the data to write | ||
337 | * size: the size of the data | ||
342 | */ | 338 | */ |
343 | static inline void *ds_allocate_buffer(size_t size, unsigned int *pages) | 339 | static int ds_write(struct ds_context *context, enum ds_qualifier qual, |
340 | const void *record, size_t size) | ||
344 | { | 341 | { |
345 | unsigned long rlim, vm, pgsz; | 342 | int bytes_written = 0; |
346 | void *buffer; | ||
347 | 343 | ||
348 | pgsz = PAGE_ALIGN(size) >> PAGE_SHIFT; | 344 | if (!record) |
345 | return -EINVAL; | ||
349 | 346 | ||
350 | rlim = current->signal->rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT; | 347 | while (size) { |
351 | vm = current->mm->total_vm + pgsz; | 348 | unsigned long base, index, end, write_end, int_th; |
352 | if (rlim < vm) | 349 | unsigned long write_size, adj_write_size; |
353 | return NULL; | ||
354 | 350 | ||
355 | rlim = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur >> PAGE_SHIFT; | 351 | /* |
356 | vm = current->mm->locked_vm + pgsz; | 352 | * write as much as possible without producing an |
357 | if (rlim < vm) | 353 | * overflow interrupt. |
358 | return NULL; | 354 | * |
355 | * interrupt_threshold must either be | ||
356 | * - bigger than absolute_maximum or | ||
357 | * - point to a record between buffer_base and absolute_maximum | ||
358 | * | ||
359 | * index points to a valid record. | ||
360 | */ | ||
361 | base = ds_get(context->ds, qual, ds_buffer_base); | ||
362 | index = ds_get(context->ds, qual, ds_index); | ||
363 | end = ds_get(context->ds, qual, ds_absolute_maximum); | ||
364 | int_th = ds_get(context->ds, qual, ds_interrupt_threshold); | ||
359 | 365 | ||
360 | buffer = kzalloc(size, GFP_KERNEL); | 366 | write_end = min(end, int_th); |
361 | if (!buffer) | ||
362 | return NULL; | ||
363 | 367 | ||
364 | current->mm->total_vm += pgsz; | 368 | /* if we are already beyond the interrupt threshold, |
365 | current->mm->locked_vm += pgsz; | 369 | * we fill the entire buffer */ |
370 | if (write_end <= index) | ||
371 | write_end = end; | ||
366 | 372 | ||
367 | if (pages) | 373 | if (write_end <= index) |
368 | *pages = pgsz; | 374 | break; |
375 | |||
376 | write_size = min((unsigned long) size, write_end - index); | ||
377 | memcpy((void *)index, record, write_size); | ||
369 | 378 | ||
370 | return buffer; | 379 | record = (const char *)record + write_size; |
380 | size -= write_size; | ||
381 | bytes_written += write_size; | ||
382 | |||
383 | adj_write_size = write_size / ds_cfg.sizeof_rec[qual]; | ||
384 | adj_write_size *= ds_cfg.sizeof_rec[qual]; | ||
385 | |||
386 | /* zero out trailing bytes */ | ||
387 | memset((char *)index + write_size, 0, | ||
388 | adj_write_size - write_size); | ||
389 | index += adj_write_size; | ||
390 | |||
391 | if (index >= end) | ||
392 | index = base; | ||
393 | ds_set(context->ds, qual, ds_index, index); | ||
394 | |||
395 | if (index >= int_th) | ||
396 | ds_overflow(context, qual); | ||
397 | } | ||
398 | |||
399 | return bytes_written; | ||
371 | } | 400 | } |
372 | 401 | ||
373 | static int ds_request(struct task_struct *task, void *base, size_t size, | 402 | |
374 | ds_ovfl_callback_t ovfl, enum ds_qualifier qual) | 403 | /* |
404 | * Branch Trace Store (BTS) uses the following format. Different | ||
405 | * architectures vary in the size of those fields. | ||
406 | * - source linear address | ||
407 | * - destination linear address | ||
408 | * - flags | ||
409 | * | ||
410 | * Later architectures use 64bit pointers throughout, whereas earlier | ||
411 | * architectures use 32bit pointers in 32bit mode. | ||
412 | * | ||
413 | * We compute the base address for the first 8 fields based on: | ||
414 | * - the field size stored in the DS configuration | ||
415 | * - the relative field position | ||
416 | * | ||
417 | * In order to store additional information in the BTS buffer, we use | ||
418 | * a special source address to indicate that the record requires | ||
419 | * special interpretation. | ||
420 | * | ||
421 | * Netburst indicated via a bit in the flags field whether the branch | ||
422 | * was predicted; this is ignored. | ||
423 | * | ||
424 | * We use two levels of abstraction: | ||
425 | * - the raw data level defined here | ||
426 | * - an arch-independent level defined in ds.h | ||
427 | */ | ||
428 | |||
429 | enum bts_field { | ||
430 | bts_from, | ||
431 | bts_to, | ||
432 | bts_flags, | ||
433 | |||
434 | bts_qual = bts_from, | ||
435 | bts_jiffies = bts_to, | ||
436 | bts_pid = bts_flags, | ||
437 | |||
438 | bts_qual_mask = (bts_qual_max - 1), | ||
439 | bts_escape = ((unsigned long)-1 & ~bts_qual_mask) | ||
440 | }; | ||
441 | |||
442 | static inline unsigned long bts_get(const char *base, enum bts_field field) | ||
375 | { | 443 | { |
376 | struct ds_context *context; | 444 | base += (ds_cfg.sizeof_field * field); |
377 | unsigned long buffer, adj; | 445 | return *(unsigned long *)base; |
378 | const unsigned long alignment = (1 << 3); | 446 | } |
379 | unsigned long irq; | 447 | |
380 | int error = 0; | 448 | static inline void bts_set(char *base, enum bts_field field, unsigned long val) |
449 | { | ||
450 | base += (ds_cfg.sizeof_field * field);; | ||
451 | (*(unsigned long *)base) = val; | ||
452 | } | ||
381 | 453 | ||
382 | if (!ds_cfg.sizeof_ds) | ||
383 | return -EOPNOTSUPP; | ||
384 | 454 | ||
385 | /* we require some space to do alignment adjustments below */ | 455 | /* |
386 | if (size < (alignment + ds_cfg.sizeof_rec[qual])) | 456 | * The raw BTS data is architecture dependent. |
457 | * | ||
458 | * For higher-level users, we give an arch-independent view. | ||
459 | * - ds.h defines struct bts_struct | ||
460 | * - bts_read translates one raw bts record into a bts_struct | ||
461 | * - bts_write translates one bts_struct into the raw format and | ||
462 | * writes it into the top of the parameter tracer's buffer. | ||
463 | * | ||
464 | * return: bytes read/written on success; -Eerrno, otherwise | ||
465 | */ | ||
466 | static int bts_read(struct bts_tracer *tracer, const void *at, | ||
467 | struct bts_struct *out) | ||
468 | { | ||
469 | if (!tracer) | ||
387 | return -EINVAL; | 470 | return -EINVAL; |
388 | 471 | ||
389 | /* buffer overflow notification is not yet implemented */ | 472 | if (at < tracer->trace.ds.begin) |
390 | if (ovfl) | 473 | return -EINVAL; |
391 | return -EOPNOTSUPP; | ||
392 | 474 | ||
475 | if (tracer->trace.ds.end < (at + tracer->trace.ds.size)) | ||
476 | return -EINVAL; | ||
393 | 477 | ||
394 | context = ds_alloc_context(task); | 478 | memset(out, 0, sizeof(*out)); |
395 | if (!context) | 479 | if ((bts_get(at, bts_qual) & ~bts_qual_mask) == bts_escape) { |
396 | return -ENOMEM; | 480 | out->qualifier = (bts_get(at, bts_qual) & bts_qual_mask); |
481 | out->variant.timestamp.jiffies = bts_get(at, bts_jiffies); | ||
482 | out->variant.timestamp.pid = bts_get(at, bts_pid); | ||
483 | } else { | ||
484 | out->qualifier = bts_branch; | ||
485 | out->variant.lbr.from = bts_get(at, bts_from); | ||
486 | out->variant.lbr.to = bts_get(at, bts_to); | ||
487 | |||
488 | if (!out->variant.lbr.from && !out->variant.lbr.to) | ||
489 | out->qualifier = bts_invalid; | ||
490 | } | ||
397 | 491 | ||
398 | spin_lock_irqsave(&ds_lock, irq); | 492 | return ds_cfg.sizeof_rec[ds_bts]; |
493 | } | ||
399 | 494 | ||
400 | error = -EPERM; | 495 | static int bts_write(struct bts_tracer *tracer, const struct bts_struct *in) |
401 | if (!check_tracer(task)) | 496 | { |
402 | goto out_unlock; | 497 | unsigned char raw[MAX_SIZEOF_BTS]; |
403 | 498 | ||
404 | get_tracer(task); | 499 | if (!tracer) |
500 | return -EINVAL; | ||
405 | 501 | ||
406 | error = -EALREADY; | 502 | if (MAX_SIZEOF_BTS < ds_cfg.sizeof_rec[ds_bts]) |
407 | if (context->owner[qual] == current) | 503 | return -EOVERFLOW; |
408 | goto out_put_tracer; | ||
409 | error = -EPERM; | ||
410 | if (context->owner[qual] != NULL) | ||
411 | goto out_put_tracer; | ||
412 | context->owner[qual] = current; | ||
413 | 504 | ||
414 | spin_unlock_irqrestore(&ds_lock, irq); | 505 | switch (in->qualifier) { |
506 | case bts_invalid: | ||
507 | bts_set(raw, bts_from, 0); | ||
508 | bts_set(raw, bts_to, 0); | ||
509 | bts_set(raw, bts_flags, 0); | ||
510 | break; | ||
511 | case bts_branch: | ||
512 | bts_set(raw, bts_from, in->variant.lbr.from); | ||
513 | bts_set(raw, bts_to, in->variant.lbr.to); | ||
514 | bts_set(raw, bts_flags, 0); | ||
515 | break; | ||
516 | case bts_task_arrives: | ||
517 | case bts_task_departs: | ||
518 | bts_set(raw, bts_qual, (bts_escape | in->qualifier)); | ||
519 | bts_set(raw, bts_jiffies, in->variant.timestamp.jiffies); | ||
520 | bts_set(raw, bts_pid, in->variant.timestamp.pid); | ||
521 | break; | ||
522 | default: | ||
523 | return -EINVAL; | ||
524 | } | ||
415 | 525 | ||
526 | return ds_write(tracer->ds.context, ds_bts, raw, | ||
527 | ds_cfg.sizeof_rec[ds_bts]); | ||
528 | } | ||
416 | 529 | ||
417 | error = -ENOMEM; | ||
418 | if (!base) { | ||
419 | base = ds_allocate_buffer(size, &context->pages[qual]); | ||
420 | if (!base) | ||
421 | goto out_release; | ||
422 | 530 | ||
423 | context->buffer[qual] = base; | 531 | static void ds_write_config(struct ds_context *context, |
424 | } | 532 | struct ds_trace *cfg, enum ds_qualifier qual) |
425 | error = 0; | 533 | { |
534 | unsigned char *ds = context->ds; | ||
535 | |||
536 | ds_set(ds, qual, ds_buffer_base, (unsigned long)cfg->begin); | ||
537 | ds_set(ds, qual, ds_index, (unsigned long)cfg->top); | ||
538 | ds_set(ds, qual, ds_absolute_maximum, (unsigned long)cfg->end); | ||
539 | ds_set(ds, qual, ds_interrupt_threshold, (unsigned long)cfg->ith); | ||
540 | } | ||
541 | |||
542 | static void ds_read_config(struct ds_context *context, | ||
543 | struct ds_trace *cfg, enum ds_qualifier qual) | ||
544 | { | ||
545 | unsigned char *ds = context->ds; | ||
426 | 546 | ||
427 | context->callback[qual] = ovfl; | 547 | cfg->begin = (void *)ds_get(ds, qual, ds_buffer_base); |
548 | cfg->top = (void *)ds_get(ds, qual, ds_index); | ||
549 | cfg->end = (void *)ds_get(ds, qual, ds_absolute_maximum); | ||
550 | cfg->ith = (void *)ds_get(ds, qual, ds_interrupt_threshold); | ||
551 | } | ||
552 | |||
553 | static void ds_init_ds_trace(struct ds_trace *trace, enum ds_qualifier qual, | ||
554 | void *base, size_t size, size_t ith, | ||
555 | unsigned int flags) { | ||
556 | unsigned long buffer, adj; | ||
428 | 557 | ||
429 | /* adjust the buffer address and size to meet alignment | 558 | /* adjust the buffer address and size to meet alignment |
430 | * constraints: | 559 | * constraints: |
@@ -436,410 +565,383 @@ static int ds_request(struct task_struct *task, void *base, size_t size, | |||
436 | */ | 565 | */ |
437 | buffer = (unsigned long)base; | 566 | buffer = (unsigned long)base; |
438 | 567 | ||
439 | adj = ALIGN(buffer, alignment) - buffer; | 568 | adj = ALIGN(buffer, DS_ALIGNMENT) - buffer; |
440 | buffer += adj; | 569 | buffer += adj; |
441 | size -= adj; | 570 | size -= adj; |
442 | 571 | ||
443 | size /= ds_cfg.sizeof_rec[qual]; | 572 | trace->n = size / ds_cfg.sizeof_rec[qual]; |
444 | size *= ds_cfg.sizeof_rec[qual]; | 573 | trace->size = ds_cfg.sizeof_rec[qual]; |
445 | |||
446 | ds_set(context->ds, qual, ds_buffer_base, buffer); | ||
447 | ds_set(context->ds, qual, ds_index, buffer); | ||
448 | ds_set(context->ds, qual, ds_absolute_maximum, buffer + size); | ||
449 | 574 | ||
450 | if (ovfl) { | 575 | size = (trace->n * trace->size); |
451 | /* todo: select a suitable interrupt threshold */ | ||
452 | } else | ||
453 | ds_set(context->ds, qual, | ||
454 | ds_interrupt_threshold, buffer + size + 1); | ||
455 | 576 | ||
456 | /* we keep the context until ds_release */ | 577 | trace->begin = (void *)buffer; |
457 | return error; | 578 | trace->top = trace->begin; |
458 | 579 | trace->end = (void *)(buffer + size); | |
459 | out_release: | 580 | /* The value for 'no threshold' is -1, which will set the |
460 | context->owner[qual] = NULL; | 581 | * threshold outside of the buffer, just like we want it. |
461 | ds_put_context(context); | 582 | */ |
462 | put_tracer(task); | 583 | trace->ith = (void *)(buffer + size - ith); |
463 | return error; | ||
464 | |||
465 | out_put_tracer: | ||
466 | spin_unlock_irqrestore(&ds_lock, irq); | ||
467 | ds_put_context(context); | ||
468 | put_tracer(task); | ||
469 | return error; | ||
470 | 584 | ||
471 | out_unlock: | 585 | trace->flags = flags; |
472 | spin_unlock_irqrestore(&ds_lock, irq); | ||
473 | ds_put_context(context); | ||
474 | return error; | ||
475 | } | 586 | } |
476 | 587 | ||
477 | int ds_request_bts(struct task_struct *task, void *base, size_t size, | ||
478 | ds_ovfl_callback_t ovfl) | ||
479 | { | ||
480 | return ds_request(task, base, size, ovfl, ds_bts); | ||
481 | } | ||
482 | 588 | ||
483 | int ds_request_pebs(struct task_struct *task, void *base, size_t size, | 589 | static int ds_request(struct ds_tracer *tracer, struct ds_trace *trace, |
484 | ds_ovfl_callback_t ovfl) | 590 | enum ds_qualifier qual, struct task_struct *task, |
485 | { | 591 | void *base, size_t size, size_t th, unsigned int flags) |
486 | return ds_request(task, base, size, ovfl, ds_pebs); | ||
487 | } | ||
488 | |||
489 | static int ds_release(struct task_struct *task, enum ds_qualifier qual) | ||
490 | { | 592 | { |
491 | struct ds_context *context; | 593 | struct ds_context *context; |
492 | int error; | 594 | int error; |
493 | 595 | ||
494 | context = ds_get_context(task); | 596 | error = -EINVAL; |
495 | error = ds_validate_access(context, qual); | 597 | if (!base) |
496 | if (error < 0) | ||
497 | goto out; | 598 | goto out; |
498 | 599 | ||
499 | kfree(context->buffer[qual]); | 600 | /* we require some space to do alignment adjustments below */ |
500 | context->buffer[qual] = NULL; | 601 | error = -EINVAL; |
501 | 602 | if (size < (DS_ALIGNMENT + ds_cfg.sizeof_rec[qual])) | |
502 | current->mm->total_vm -= context->pages[qual]; | 603 | goto out; |
503 | current->mm->locked_vm -= context->pages[qual]; | ||
504 | context->pages[qual] = 0; | ||
505 | context->owner[qual] = NULL; | ||
506 | |||
507 | /* | ||
508 | * we put the context twice: | ||
509 | * once for the ds_get_context | ||
510 | * once for the corresponding ds_request | ||
511 | */ | ||
512 | ds_put_context(context); | ||
513 | out: | ||
514 | ds_put_context(context); | ||
515 | return error; | ||
516 | } | ||
517 | 604 | ||
518 | int ds_release_bts(struct task_struct *task) | 605 | if (th != (size_t)-1) { |
519 | { | 606 | th *= ds_cfg.sizeof_rec[qual]; |
520 | return ds_release(task, ds_bts); | ||
521 | } | ||
522 | 607 | ||
523 | int ds_release_pebs(struct task_struct *task) | 608 | error = -EINVAL; |
524 | { | 609 | if (size <= th) |
525 | return ds_release(task, ds_pebs); | 610 | goto out; |
526 | } | 611 | } |
527 | 612 | ||
528 | static int ds_get_index(struct task_struct *task, size_t *pos, | 613 | tracer->buffer = base; |
529 | enum ds_qualifier qual) | 614 | tracer->size = size; |
530 | { | ||
531 | struct ds_context *context; | ||
532 | unsigned long base, index; | ||
533 | int error; | ||
534 | 615 | ||
616 | error = -ENOMEM; | ||
535 | context = ds_get_context(task); | 617 | context = ds_get_context(task); |
536 | error = ds_validate_access(context, qual); | 618 | if (!context) |
537 | if (error < 0) | ||
538 | goto out; | 619 | goto out; |
620 | tracer->context = context; | ||
539 | 621 | ||
540 | base = ds_get(context->ds, qual, ds_buffer_base); | 622 | ds_init_ds_trace(trace, qual, base, size, th, flags); |
541 | index = ds_get(context->ds, qual, ds_index); | ||
542 | 623 | ||
543 | error = ((index - base) / ds_cfg.sizeof_rec[qual]); | 624 | error = 0; |
544 | if (pos) | ||
545 | *pos = error; | ||
546 | out: | 625 | out: |
547 | ds_put_context(context); | ||
548 | return error; | 626 | return error; |
549 | } | 627 | } |
550 | 628 | ||
551 | int ds_get_bts_index(struct task_struct *task, size_t *pos) | 629 | struct bts_tracer *ds_request_bts(struct task_struct *task, |
552 | { | 630 | void *base, size_t size, |
553 | return ds_get_index(task, pos, ds_bts); | 631 | bts_ovfl_callback_t ovfl, size_t th, |
554 | } | 632 | unsigned int flags) |
555 | |||
556 | int ds_get_pebs_index(struct task_struct *task, size_t *pos) | ||
557 | { | 633 | { |
558 | return ds_get_index(task, pos, ds_pebs); | 634 | struct bts_tracer *tracer; |
559 | } | 635 | unsigned long irq; |
560 | |||
561 | static int ds_get_end(struct task_struct *task, size_t *pos, | ||
562 | enum ds_qualifier qual) | ||
563 | { | ||
564 | struct ds_context *context; | ||
565 | unsigned long base, end; | ||
566 | int error; | 636 | int error; |
567 | 637 | ||
568 | context = ds_get_context(task); | 638 | error = -EOPNOTSUPP; |
569 | error = ds_validate_access(context, qual); | 639 | if (!ds_cfg.ctl[dsf_bts]) |
570 | if (error < 0) | ||
571 | goto out; | 640 | goto out; |
572 | 641 | ||
573 | base = ds_get(context->ds, qual, ds_buffer_base); | 642 | /* buffer overflow notification is not yet implemented */ |
574 | end = ds_get(context->ds, qual, ds_absolute_maximum); | 643 | error = -EOPNOTSUPP; |
644 | if (ovfl) | ||
645 | goto out; | ||
575 | 646 | ||
576 | error = ((end - base) / ds_cfg.sizeof_rec[qual]); | 647 | error = -ENOMEM; |
577 | if (pos) | 648 | tracer = kzalloc(sizeof(*tracer), GFP_KERNEL); |
578 | *pos = error; | 649 | if (!tracer) |
579 | out: | 650 | goto out; |
580 | ds_put_context(context); | 651 | tracer->ovfl = ovfl; |
581 | return error; | ||
582 | } | ||
583 | 652 | ||
584 | int ds_get_bts_end(struct task_struct *task, size_t *pos) | 653 | error = ds_request(&tracer->ds, &tracer->trace.ds, |
585 | { | 654 | ds_bts, task, base, size, th, flags); |
586 | return ds_get_end(task, pos, ds_bts); | 655 | if (error < 0) |
587 | } | 656 | goto out_tracer; |
588 | 657 | ||
589 | int ds_get_pebs_end(struct task_struct *task, size_t *pos) | ||
590 | { | ||
591 | return ds_get_end(task, pos, ds_pebs); | ||
592 | } | ||
593 | 658 | ||
594 | static int ds_access(struct task_struct *task, size_t index, | 659 | spin_lock_irqsave(&ds_lock, irq); |
595 | const void **record, enum ds_qualifier qual) | ||
596 | { | ||
597 | struct ds_context *context; | ||
598 | unsigned long base, idx; | ||
599 | int error; | ||
600 | 660 | ||
601 | if (!record) | 661 | error = -EPERM; |
602 | return -EINVAL; | 662 | if (!check_tracer(task)) |
663 | goto out_unlock; | ||
664 | get_tracer(task); | ||
603 | 665 | ||
604 | context = ds_get_context(task); | 666 | error = -EPERM; |
605 | error = ds_validate_access(context, qual); | 667 | if (tracer->ds.context->bts_master) |
606 | if (error < 0) | 668 | goto out_put_tracer; |
607 | goto out; | 669 | tracer->ds.context->bts_master = tracer; |
608 | 670 | ||
609 | base = ds_get(context->ds, qual, ds_buffer_base); | 671 | spin_unlock_irqrestore(&ds_lock, irq); |
610 | idx = base + (index * ds_cfg.sizeof_rec[qual]); | ||
611 | 672 | ||
612 | error = -EINVAL; | ||
613 | if (idx > ds_get(context->ds, qual, ds_absolute_maximum)) | ||
614 | goto out; | ||
615 | 673 | ||
616 | *record = (const void *)idx; | 674 | tracer->trace.read = bts_read; |
617 | error = ds_cfg.sizeof_rec[qual]; | 675 | tracer->trace.write = bts_write; |
618 | out: | ||
619 | ds_put_context(context); | ||
620 | return error; | ||
621 | } | ||
622 | 676 | ||
623 | int ds_access_bts(struct task_struct *task, size_t index, const void **record) | 677 | ds_write_config(tracer->ds.context, &tracer->trace.ds, ds_bts); |
624 | { | 678 | ds_resume_bts(tracer); |
625 | return ds_access(task, index, record, ds_bts); | ||
626 | } | ||
627 | 679 | ||
628 | int ds_access_pebs(struct task_struct *task, size_t index, const void **record) | 680 | return tracer; |
629 | { | 681 | |
630 | return ds_access(task, index, record, ds_pebs); | 682 | out_put_tracer: |
683 | put_tracer(task); | ||
684 | out_unlock: | ||
685 | spin_unlock_irqrestore(&ds_lock, irq); | ||
686 | ds_put_context(tracer->ds.context); | ||
687 | out_tracer: | ||
688 | kfree(tracer); | ||
689 | out: | ||
690 | return ERR_PTR(error); | ||
631 | } | 691 | } |
632 | 692 | ||
633 | static int ds_write(struct task_struct *task, const void *record, size_t size, | 693 | struct pebs_tracer *ds_request_pebs(struct task_struct *task, |
634 | enum ds_qualifier qual, int force) | 694 | void *base, size_t size, |
695 | pebs_ovfl_callback_t ovfl, size_t th, | ||
696 | unsigned int flags) | ||
635 | { | 697 | { |
636 | struct ds_context *context; | 698 | struct pebs_tracer *tracer; |
699 | unsigned long irq; | ||
637 | int error; | 700 | int error; |
638 | 701 | ||
639 | if (!record) | 702 | /* buffer overflow notification is not yet implemented */ |
640 | return -EINVAL; | 703 | error = -EOPNOTSUPP; |
704 | if (ovfl) | ||
705 | goto out; | ||
641 | 706 | ||
642 | error = -EPERM; | 707 | error = -ENOMEM; |
643 | context = ds_get_context(task); | 708 | tracer = kzalloc(sizeof(*tracer), GFP_KERNEL); |
644 | if (!context) | 709 | if (!tracer) |
645 | goto out; | 710 | goto out; |
711 | tracer->ovfl = ovfl; | ||
646 | 712 | ||
647 | if (!force) { | 713 | error = ds_request(&tracer->ds, &tracer->trace.ds, |
648 | error = ds_validate_access(context, qual); | 714 | ds_pebs, task, base, size, th, flags); |
649 | if (error < 0) | 715 | if (error < 0) |
650 | goto out; | 716 | goto out_tracer; |
651 | } | ||
652 | 717 | ||
653 | error = 0; | 718 | spin_lock_irqsave(&ds_lock, irq); |
654 | while (size) { | ||
655 | unsigned long base, index, end, write_end, int_th; | ||
656 | unsigned long write_size, adj_write_size; | ||
657 | 719 | ||
658 | /* | 720 | error = -EPERM; |
659 | * write as much as possible without producing an | 721 | if (!check_tracer(task)) |
660 | * overflow interrupt. | 722 | goto out_unlock; |
661 | * | 723 | get_tracer(task); |
662 | * interrupt_threshold must either be | ||
663 | * - bigger than absolute_maximum or | ||
664 | * - point to a record between buffer_base and absolute_maximum | ||
665 | * | ||
666 | * index points to a valid record. | ||
667 | */ | ||
668 | base = ds_get(context->ds, qual, ds_buffer_base); | ||
669 | index = ds_get(context->ds, qual, ds_index); | ||
670 | end = ds_get(context->ds, qual, ds_absolute_maximum); | ||
671 | int_th = ds_get(context->ds, qual, ds_interrupt_threshold); | ||
672 | 724 | ||
673 | write_end = min(end, int_th); | 725 | error = -EPERM; |
726 | if (tracer->ds.context->pebs_master) | ||
727 | goto out_put_tracer; | ||
728 | tracer->ds.context->pebs_master = tracer; | ||
674 | 729 | ||
675 | /* if we are already beyond the interrupt threshold, | 730 | spin_unlock_irqrestore(&ds_lock, irq); |
676 | * we fill the entire buffer */ | ||
677 | if (write_end <= index) | ||
678 | write_end = end; | ||
679 | 731 | ||
680 | if (write_end <= index) | 732 | ds_write_config(tracer->ds.context, &tracer->trace.ds, ds_bts); |
681 | goto out; | 733 | ds_resume_pebs(tracer); |
682 | 734 | ||
683 | write_size = min((unsigned long) size, write_end - index); | 735 | return tracer; |
684 | memcpy((void *)index, record, write_size); | ||
685 | 736 | ||
686 | record = (const char *)record + write_size; | 737 | out_put_tracer: |
687 | size -= write_size; | 738 | put_tracer(task); |
688 | error += write_size; | 739 | out_unlock: |
740 | spin_unlock_irqrestore(&ds_lock, irq); | ||
741 | ds_put_context(tracer->ds.context); | ||
742 | out_tracer: | ||
743 | kfree(tracer); | ||
744 | out: | ||
745 | return ERR_PTR(error); | ||
746 | } | ||
689 | 747 | ||
690 | adj_write_size = write_size / ds_cfg.sizeof_rec[qual]; | 748 | void ds_release_bts(struct bts_tracer *tracer) |
691 | adj_write_size *= ds_cfg.sizeof_rec[qual]; | 749 | { |
750 | if (!tracer) | ||
751 | return; | ||
692 | 752 | ||
693 | /* zero out trailing bytes */ | 753 | ds_suspend_bts(tracer); |
694 | memset((char *)index + write_size, 0, | ||
695 | adj_write_size - write_size); | ||
696 | index += adj_write_size; | ||
697 | 754 | ||
698 | if (index >= end) | 755 | WARN_ON_ONCE(tracer->ds.context->bts_master != tracer); |
699 | index = base; | 756 | tracer->ds.context->bts_master = NULL; |
700 | ds_set(context->ds, qual, ds_index, index); | ||
701 | 757 | ||
702 | if (index >= int_th) | 758 | put_tracer(tracer->ds.context->task); |
703 | ds_overflow(task, context, qual); | 759 | ds_put_context(tracer->ds.context); |
704 | } | ||
705 | 760 | ||
706 | out: | 761 | kfree(tracer); |
707 | ds_put_context(context); | ||
708 | return error; | ||
709 | } | 762 | } |
710 | 763 | ||
711 | int ds_write_bts(struct task_struct *task, const void *record, size_t size) | 764 | void ds_suspend_bts(struct bts_tracer *tracer) |
712 | { | 765 | { |
713 | return ds_write(task, record, size, ds_bts, /* force = */ 0); | 766 | struct task_struct *task; |
714 | } | ||
715 | 767 | ||
716 | int ds_write_pebs(struct task_struct *task, const void *record, size_t size) | 768 | if (!tracer) |
717 | { | 769 | return; |
718 | return ds_write(task, record, size, ds_pebs, /* force = */ 0); | ||
719 | } | ||
720 | 770 | ||
721 | int ds_unchecked_write_bts(struct task_struct *task, | 771 | task = tracer->ds.context->task; |
722 | const void *record, size_t size) | ||
723 | { | ||
724 | return ds_write(task, record, size, ds_bts, /* force = */ 1); | ||
725 | } | ||
726 | 772 | ||
727 | int ds_unchecked_write_pebs(struct task_struct *task, | 773 | if (!task || (task == current)) |
728 | const void *record, size_t size) | 774 | update_debugctlmsr(get_debugctlmsr() & ~BTS_CONTROL); |
729 | { | 775 | |
730 | return ds_write(task, record, size, ds_pebs, /* force = */ 1); | 776 | if (task) { |
777 | task->thread.debugctlmsr &= ~BTS_CONTROL; | ||
778 | |||
779 | if (!task->thread.debugctlmsr) | ||
780 | clear_tsk_thread_flag(task, TIF_DEBUGCTLMSR); | ||
781 | } | ||
731 | } | 782 | } |
732 | 783 | ||
733 | static int ds_reset_or_clear(struct task_struct *task, | 784 | void ds_resume_bts(struct bts_tracer *tracer) |
734 | enum ds_qualifier qual, int clear) | ||
735 | { | 785 | { |
736 | struct ds_context *context; | 786 | struct task_struct *task; |
737 | unsigned long base, end; | 787 | unsigned long control; |
738 | int error; | ||
739 | 788 | ||
740 | context = ds_get_context(task); | 789 | if (!tracer) |
741 | error = ds_validate_access(context, qual); | 790 | return; |
742 | if (error < 0) | ||
743 | goto out; | ||
744 | 791 | ||
745 | base = ds_get(context->ds, qual, ds_buffer_base); | 792 | task = tracer->ds.context->task; |
746 | end = ds_get(context->ds, qual, ds_absolute_maximum); | ||
747 | 793 | ||
748 | if (clear) | 794 | control = ds_cfg.ctl[dsf_bts]; |
749 | memset((void *)base, 0, end - base); | 795 | if (!(tracer->trace.ds.flags & BTS_KERNEL)) |
796 | control |= ds_cfg.ctl[dsf_bts_kernel]; | ||
797 | if (!(tracer->trace.ds.flags & BTS_USER)) | ||
798 | control |= ds_cfg.ctl[dsf_bts_user]; | ||
750 | 799 | ||
751 | ds_set(context->ds, qual, ds_index, base); | 800 | if (task) { |
801 | task->thread.debugctlmsr |= control; | ||
802 | set_tsk_thread_flag(task, TIF_DEBUGCTLMSR); | ||
803 | } | ||
752 | 804 | ||
753 | error = 0; | 805 | if (!task || (task == current)) |
754 | out: | 806 | update_debugctlmsr(get_debugctlmsr() | control); |
755 | ds_put_context(context); | ||
756 | return error; | ||
757 | } | 807 | } |
758 | 808 | ||
759 | int ds_reset_bts(struct task_struct *task) | 809 | void ds_release_pebs(struct pebs_tracer *tracer) |
760 | { | 810 | { |
761 | return ds_reset_or_clear(task, ds_bts, /* clear = */ 0); | 811 | if (!tracer) |
812 | return; | ||
813 | |||
814 | ds_suspend_pebs(tracer); | ||
815 | |||
816 | WARN_ON_ONCE(tracer->ds.context->pebs_master != tracer); | ||
817 | tracer->ds.context->pebs_master = NULL; | ||
818 | |||
819 | put_tracer(tracer->ds.context->task); | ||
820 | ds_put_context(tracer->ds.context); | ||
821 | |||
822 | kfree(tracer); | ||
762 | } | 823 | } |
763 | 824 | ||
764 | int ds_reset_pebs(struct task_struct *task) | 825 | void ds_suspend_pebs(struct pebs_tracer *tracer) |
765 | { | 826 | { |
766 | return ds_reset_or_clear(task, ds_pebs, /* clear = */ 0); | 827 | |
767 | } | 828 | } |
768 | 829 | ||
769 | int ds_clear_bts(struct task_struct *task) | 830 | void ds_resume_pebs(struct pebs_tracer *tracer) |
770 | { | 831 | { |
771 | return ds_reset_or_clear(task, ds_bts, /* clear = */ 1); | 832 | |
772 | } | 833 | } |
773 | 834 | ||
774 | int ds_clear_pebs(struct task_struct *task) | 835 | const struct bts_trace *ds_read_bts(struct bts_tracer *tracer) |
775 | { | 836 | { |
776 | return ds_reset_or_clear(task, ds_pebs, /* clear = */ 1); | 837 | if (!tracer) |
838 | return NULL; | ||
839 | |||
840 | ds_read_config(tracer->ds.context, &tracer->trace.ds, ds_bts); | ||
841 | return &tracer->trace; | ||
777 | } | 842 | } |
778 | 843 | ||
779 | int ds_get_pebs_reset(struct task_struct *task, u64 *value) | 844 | const struct pebs_trace *ds_read_pebs(struct pebs_tracer *tracer) |
780 | { | 845 | { |
781 | struct ds_context *context; | 846 | if (!tracer) |
782 | int error; | 847 | return NULL; |
848 | |||
849 | ds_read_config(tracer->ds.context, &tracer->trace.ds, ds_pebs); | ||
850 | tracer->trace.reset_value = | ||
851 | *(u64 *)(tracer->ds.context->ds + (ds_cfg.sizeof_field * 8)); | ||
783 | 852 | ||
784 | if (!value) | 853 | return &tracer->trace; |
854 | } | ||
855 | |||
856 | int ds_reset_bts(struct bts_tracer *tracer) | ||
857 | { | ||
858 | if (!tracer) | ||
785 | return -EINVAL; | 859 | return -EINVAL; |
786 | 860 | ||
787 | context = ds_get_context(task); | 861 | tracer->trace.ds.top = tracer->trace.ds.begin; |
788 | error = ds_validate_access(context, ds_pebs); | ||
789 | if (error < 0) | ||
790 | goto out; | ||
791 | 862 | ||
792 | *value = *(u64 *)(context->ds + (ds_cfg.sizeof_field * 8)); | 863 | ds_set(tracer->ds.context->ds, ds_bts, ds_index, |
864 | (unsigned long)tracer->trace.ds.top); | ||
793 | 865 | ||
794 | error = 0; | 866 | return 0; |
795 | out: | ||
796 | ds_put_context(context); | ||
797 | return error; | ||
798 | } | 867 | } |
799 | 868 | ||
800 | int ds_set_pebs_reset(struct task_struct *task, u64 value) | 869 | int ds_reset_pebs(struct pebs_tracer *tracer) |
801 | { | 870 | { |
802 | struct ds_context *context; | 871 | if (!tracer) |
803 | int error; | 872 | return -EINVAL; |
804 | 873 | ||
805 | context = ds_get_context(task); | 874 | tracer->trace.ds.top = tracer->trace.ds.begin; |
806 | error = ds_validate_access(context, ds_pebs); | ||
807 | if (error < 0) | ||
808 | goto out; | ||
809 | 875 | ||
810 | *(u64 *)(context->ds + (ds_cfg.sizeof_field * 8)) = value; | 876 | ds_set(tracer->ds.context->ds, ds_bts, ds_index, |
877 | (unsigned long)tracer->trace.ds.top); | ||
811 | 878 | ||
812 | error = 0; | 879 | return 0; |
813 | out: | 880 | } |
814 | ds_put_context(context); | 881 | |
815 | return error; | 882 | int ds_set_pebs_reset(struct pebs_tracer *tracer, u64 value) |
883 | { | ||
884 | if (!tracer) | ||
885 | return -EINVAL; | ||
886 | |||
887 | *(u64 *)(tracer->ds.context->ds + (ds_cfg.sizeof_field * 8)) = value; | ||
888 | |||
889 | return 0; | ||
816 | } | 890 | } |
817 | 891 | ||
818 | static const struct ds_configuration ds_cfg_var = { | 892 | static const struct ds_configuration ds_cfg_netburst = { |
819 | .sizeof_ds = sizeof(long) * 12, | 893 | .name = "netburst", |
820 | .sizeof_field = sizeof(long), | 894 | .ctl[dsf_bts] = (1 << 2) | (1 << 3), |
821 | .sizeof_rec[ds_bts] = sizeof(long) * 3, | 895 | .ctl[dsf_bts_kernel] = (1 << 5), |
896 | .ctl[dsf_bts_user] = (1 << 6), | ||
897 | |||
898 | .sizeof_field = sizeof(long), | ||
899 | .sizeof_rec[ds_bts] = sizeof(long) * 3, | ||
822 | #ifdef __i386__ | 900 | #ifdef __i386__ |
823 | .sizeof_rec[ds_pebs] = sizeof(long) * 10 | 901 | .sizeof_rec[ds_pebs] = sizeof(long) * 10, |
824 | #else | 902 | #else |
825 | .sizeof_rec[ds_pebs] = sizeof(long) * 18 | 903 | .sizeof_rec[ds_pebs] = sizeof(long) * 18, |
826 | #endif | 904 | #endif |
827 | }; | 905 | }; |
828 | static const struct ds_configuration ds_cfg_64 = { | 906 | static const struct ds_configuration ds_cfg_pentium_m = { |
829 | .sizeof_ds = 8 * 12, | 907 | .name = "pentium m", |
830 | .sizeof_field = 8, | 908 | .ctl[dsf_bts] = (1 << 6) | (1 << 7), |
831 | .sizeof_rec[ds_bts] = 8 * 3, | 909 | |
910 | .sizeof_field = sizeof(long), | ||
911 | .sizeof_rec[ds_bts] = sizeof(long) * 3, | ||
832 | #ifdef __i386__ | 912 | #ifdef __i386__ |
833 | .sizeof_rec[ds_pebs] = 8 * 10 | 913 | .sizeof_rec[ds_pebs] = sizeof(long) * 10, |
834 | #else | 914 | #else |
835 | .sizeof_rec[ds_pebs] = 8 * 18 | 915 | .sizeof_rec[ds_pebs] = sizeof(long) * 18, |
836 | #endif | 916 | #endif |
837 | }; | 917 | }; |
918 | static const struct ds_configuration ds_cfg_core2 = { | ||
919 | .name = "core 2", | ||
920 | .ctl[dsf_bts] = (1 << 6) | (1 << 7), | ||
921 | .ctl[dsf_bts_kernel] = (1 << 9), | ||
922 | .ctl[dsf_bts_user] = (1 << 10), | ||
923 | |||
924 | .sizeof_field = 8, | ||
925 | .sizeof_rec[ds_bts] = 8 * 3, | ||
926 | .sizeof_rec[ds_pebs] = 8 * 18, | ||
927 | }; | ||
838 | 928 | ||
839 | static inline void | 929 | static void |
840 | ds_configure(const struct ds_configuration *cfg) | 930 | ds_configure(const struct ds_configuration *cfg) |
841 | { | 931 | { |
932 | memset(&ds_cfg, 0, sizeof(ds_cfg)); | ||
842 | ds_cfg = *cfg; | 933 | ds_cfg = *cfg; |
934 | |||
935 | printk(KERN_INFO "[ds] using %s configuration\n", ds_cfg.name); | ||
936 | |||
937 | if (!cpu_has_bts) { | ||
938 | ds_cfg.ctl[dsf_bts] = 0; | ||
939 | printk(KERN_INFO "[ds] bts not available\n"); | ||
940 | } | ||
941 | if (!cpu_has_pebs) | ||
942 | printk(KERN_INFO "[ds] pebs not available\n"); | ||
943 | |||
944 | WARN_ON_ONCE(MAX_SIZEOF_DS < (12 * ds_cfg.sizeof_field)); | ||
843 | } | 945 | } |
844 | 946 | ||
845 | void __cpuinit ds_init_intel(struct cpuinfo_x86 *c) | 947 | void __cpuinit ds_init_intel(struct cpuinfo_x86 *c) |
@@ -847,16 +949,15 @@ void __cpuinit ds_init_intel(struct cpuinfo_x86 *c) | |||
847 | switch (c->x86) { | 949 | switch (c->x86) { |
848 | case 0x6: | 950 | case 0x6: |
849 | switch (c->x86_model) { | 951 | switch (c->x86_model) { |
952 | case 0 ... 0xC: | ||
953 | /* sorry, don't know about them */ | ||
954 | break; | ||
850 | case 0xD: | 955 | case 0xD: |
851 | case 0xE: /* Pentium M */ | 956 | case 0xE: /* Pentium M */ |
852 | ds_configure(&ds_cfg_var); | 957 | ds_configure(&ds_cfg_pentium_m); |
853 | break; | 958 | break; |
854 | case 0xF: /* Core2 */ | 959 | default: /* Core2, Atom, ... */ |
855 | case 0x1C: /* Atom */ | 960 | ds_configure(&ds_cfg_core2); |
856 | ds_configure(&ds_cfg_64); | ||
857 | break; | ||
858 | default: | ||
859 | /* sorry, don't know about them */ | ||
860 | break; | 961 | break; |
861 | } | 962 | } |
862 | break; | 963 | break; |
@@ -865,7 +966,7 @@ void __cpuinit ds_init_intel(struct cpuinfo_x86 *c) | |||
865 | case 0x0: | 966 | case 0x0: |
866 | case 0x1: | 967 | case 0x1: |
867 | case 0x2: /* Netburst */ | 968 | case 0x2: /* Netburst */ |
868 | ds_configure(&ds_cfg_var); | 969 | ds_configure(&ds_cfg_netburst); |
869 | break; | 970 | break; |
870 | default: | 971 | default: |
871 | /* sorry, don't know about them */ | 972 | /* sorry, don't know about them */ |
@@ -878,12 +979,52 @@ void __cpuinit ds_init_intel(struct cpuinfo_x86 *c) | |||
878 | } | 979 | } |
879 | } | 980 | } |
880 | 981 | ||
881 | void ds_free(struct ds_context *context) | 982 | /* |
983 | * Change the DS configuration from tracing prev to tracing next. | ||
984 | */ | ||
985 | void ds_switch_to(struct task_struct *prev, struct task_struct *next) | ||
986 | { | ||
987 | struct ds_context *prev_ctx = prev->thread.ds_ctx; | ||
988 | struct ds_context *next_ctx = next->thread.ds_ctx; | ||
989 | |||
990 | if (prev_ctx) { | ||
991 | update_debugctlmsr(0); | ||
992 | |||
993 | if (prev_ctx->bts_master && | ||
994 | (prev_ctx->bts_master->trace.ds.flags & BTS_TIMESTAMPS)) { | ||
995 | struct bts_struct ts = { | ||
996 | .qualifier = bts_task_departs, | ||
997 | .variant.timestamp.jiffies = jiffies_64, | ||
998 | .variant.timestamp.pid = prev->pid | ||
999 | }; | ||
1000 | bts_write(prev_ctx->bts_master, &ts); | ||
1001 | } | ||
1002 | } | ||
1003 | |||
1004 | if (next_ctx) { | ||
1005 | if (next_ctx->bts_master && | ||
1006 | (next_ctx->bts_master->trace.ds.flags & BTS_TIMESTAMPS)) { | ||
1007 | struct bts_struct ts = { | ||
1008 | .qualifier = bts_task_arrives, | ||
1009 | .variant.timestamp.jiffies = jiffies_64, | ||
1010 | .variant.timestamp.pid = next->pid | ||
1011 | }; | ||
1012 | bts_write(next_ctx->bts_master, &ts); | ||
1013 | } | ||
1014 | |||
1015 | wrmsrl(MSR_IA32_DS_AREA, (unsigned long)next_ctx->ds); | ||
1016 | } | ||
1017 | |||
1018 | update_debugctlmsr(next->thread.debugctlmsr); | ||
1019 | } | ||
1020 | |||
1021 | void ds_copy_thread(struct task_struct *tsk, struct task_struct *father) | ||
1022 | { | ||
1023 | clear_tsk_thread_flag(tsk, TIF_DS_AREA_MSR); | ||
1024 | tsk->thread.ds_ctx = NULL; | ||
1025 | } | ||
1026 | |||
1027 | void ds_exit_thread(struct task_struct *tsk) | ||
882 | { | 1028 | { |
883 | /* This is called when the task owning the parameter context | 1029 | WARN_ON(tsk->thread.ds_ctx); |
884 | * is dying. There should not be any user of that context left | ||
885 | * to disturb us, anymore. */ | ||
886 | unsigned long leftovers = context->count; | ||
887 | while (leftovers--) | ||
888 | ds_put_context(context); | ||
889 | } | 1030 | } |
diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c new file mode 100644 index 000000000000..6b1f6f6f8661 --- /dev/null +++ b/arch/x86/kernel/dumpstack.c | |||
@@ -0,0 +1,351 @@ | |||
1 | /* | ||
2 | * Copyright (C) 1991, 1992 Linus Torvalds | ||
3 | * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs | ||
4 | */ | ||
5 | #include <linux/kallsyms.h> | ||
6 | #include <linux/kprobes.h> | ||
7 | #include <linux/uaccess.h> | ||
8 | #include <linux/utsname.h> | ||
9 | #include <linux/hardirq.h> | ||
10 | #include <linux/kdebug.h> | ||
11 | #include <linux/module.h> | ||
12 | #include <linux/ptrace.h> | ||
13 | #include <linux/kexec.h> | ||
14 | #include <linux/bug.h> | ||
15 | #include <linux/nmi.h> | ||
16 | #include <linux/sysfs.h> | ||
17 | |||
18 | #include <asm/stacktrace.h> | ||
19 | |||
20 | #include "dumpstack.h" | ||
21 | |||
22 | int panic_on_unrecovered_nmi; | ||
23 | unsigned int code_bytes = 64; | ||
24 | int kstack_depth_to_print = 3 * STACKSLOTS_PER_LINE; | ||
25 | static int die_counter; | ||
26 | |||
27 | void printk_address(unsigned long address, int reliable) | ||
28 | { | ||
29 | printk(" [<%p>] %s%pS\n", (void *) address, | ||
30 | reliable ? "" : "? ", (void *) address); | ||
31 | } | ||
32 | |||
33 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | ||
34 | static void | ||
35 | print_ftrace_graph_addr(unsigned long addr, void *data, | ||
36 | const struct stacktrace_ops *ops, | ||
37 | struct thread_info *tinfo, int *graph) | ||
38 | { | ||
39 | struct task_struct *task = tinfo->task; | ||
40 | unsigned long ret_addr; | ||
41 | int index = task->curr_ret_stack; | ||
42 | |||
43 | if (addr != (unsigned long)return_to_handler) | ||
44 | return; | ||
45 | |||
46 | if (!task->ret_stack || index < *graph) | ||
47 | return; | ||
48 | |||
49 | index -= *graph; | ||
50 | ret_addr = task->ret_stack[index].ret; | ||
51 | |||
52 | ops->address(data, ret_addr, 1); | ||
53 | |||
54 | (*graph)++; | ||
55 | } | ||
56 | #else | ||
57 | static inline void | ||
58 | print_ftrace_graph_addr(unsigned long addr, void *data, | ||
59 | const struct stacktrace_ops *ops, | ||
60 | struct thread_info *tinfo, int *graph) | ||
61 | { } | ||
62 | #endif | ||
63 | |||
64 | /* | ||
65 | * x86-64 can have up to three kernel stacks: | ||
66 | * process stack | ||
67 | * interrupt stack | ||
68 | * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack | ||
69 | */ | ||
70 | |||
71 | static inline int valid_stack_ptr(struct thread_info *tinfo, | ||
72 | void *p, unsigned int size, void *end) | ||
73 | { | ||
74 | void *t = tinfo; | ||
75 | if (end) { | ||
76 | if (p < end && p >= (end-THREAD_SIZE)) | ||
77 | return 1; | ||
78 | else | ||
79 | return 0; | ||
80 | } | ||
81 | return p > t && p < t + THREAD_SIZE - size; | ||
82 | } | ||
83 | |||
84 | unsigned long | ||
85 | print_context_stack(struct thread_info *tinfo, | ||
86 | unsigned long *stack, unsigned long bp, | ||
87 | const struct stacktrace_ops *ops, void *data, | ||
88 | unsigned long *end, int *graph) | ||
89 | { | ||
90 | struct stack_frame *frame = (struct stack_frame *)bp; | ||
91 | |||
92 | while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) { | ||
93 | unsigned long addr; | ||
94 | |||
95 | addr = *stack; | ||
96 | if (__kernel_text_address(addr)) { | ||
97 | if ((unsigned long) stack == bp + sizeof(long)) { | ||
98 | ops->address(data, addr, 1); | ||
99 | frame = frame->next_frame; | ||
100 | bp = (unsigned long) frame; | ||
101 | } else { | ||
102 | ops->address(data, addr, bp == 0); | ||
103 | } | ||
104 | print_ftrace_graph_addr(addr, data, ops, tinfo, graph); | ||
105 | } | ||
106 | stack++; | ||
107 | } | ||
108 | return bp; | ||
109 | } | ||
110 | |||
111 | |||
112 | static void | ||
113 | print_trace_warning_symbol(void *data, char *msg, unsigned long symbol) | ||
114 | { | ||
115 | printk(data); | ||
116 | print_symbol(msg, symbol); | ||
117 | printk("\n"); | ||
118 | } | ||
119 | |||
120 | static void print_trace_warning(void *data, char *msg) | ||
121 | { | ||
122 | printk("%s%s\n", (char *)data, msg); | ||
123 | } | ||
124 | |||
125 | static int print_trace_stack(void *data, char *name) | ||
126 | { | ||
127 | printk("%s <%s> ", (char *)data, name); | ||
128 | return 0; | ||
129 | } | ||
130 | |||
131 | /* | ||
132 | * Print one address/symbol entries per line. | ||
133 | */ | ||
134 | static void print_trace_address(void *data, unsigned long addr, int reliable) | ||
135 | { | ||
136 | touch_nmi_watchdog(); | ||
137 | printk(data); | ||
138 | printk_address(addr, reliable); | ||
139 | } | ||
140 | |||
141 | static const struct stacktrace_ops print_trace_ops = { | ||
142 | .warning = print_trace_warning, | ||
143 | .warning_symbol = print_trace_warning_symbol, | ||
144 | .stack = print_trace_stack, | ||
145 | .address = print_trace_address, | ||
146 | }; | ||
147 | |||
148 | void | ||
149 | show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs, | ||
150 | unsigned long *stack, unsigned long bp, char *log_lvl) | ||
151 | { | ||
152 | printk("%sCall Trace:\n", log_lvl); | ||
153 | dump_trace(task, regs, stack, bp, &print_trace_ops, log_lvl); | ||
154 | } | ||
155 | |||
156 | void show_trace(struct task_struct *task, struct pt_regs *regs, | ||
157 | unsigned long *stack, unsigned long bp) | ||
158 | { | ||
159 | show_trace_log_lvl(task, regs, stack, bp, ""); | ||
160 | } | ||
161 | |||
162 | void show_stack(struct task_struct *task, unsigned long *sp) | ||
163 | { | ||
164 | show_stack_log_lvl(task, NULL, sp, 0, ""); | ||
165 | } | ||
166 | |||
167 | /* | ||
168 | * The architecture-independent dump_stack generator | ||
169 | */ | ||
170 | void dump_stack(void) | ||
171 | { | ||
172 | unsigned long bp = 0; | ||
173 | unsigned long stack; | ||
174 | |||
175 | #ifdef CONFIG_FRAME_POINTER | ||
176 | if (!bp) | ||
177 | get_bp(bp); | ||
178 | #endif | ||
179 | |||
180 | printk("Pid: %d, comm: %.20s %s %s %.*s\n", | ||
181 | current->pid, current->comm, print_tainted(), | ||
182 | init_utsname()->release, | ||
183 | (int)strcspn(init_utsname()->version, " "), | ||
184 | init_utsname()->version); | ||
185 | show_trace(NULL, NULL, &stack, bp); | ||
186 | } | ||
187 | EXPORT_SYMBOL(dump_stack); | ||
188 | |||
189 | static raw_spinlock_t die_lock = __RAW_SPIN_LOCK_UNLOCKED; | ||
190 | static int die_owner = -1; | ||
191 | static unsigned int die_nest_count; | ||
192 | |||
193 | unsigned __kprobes long oops_begin(void) | ||
194 | { | ||
195 | int cpu; | ||
196 | unsigned long flags; | ||
197 | |||
198 | oops_enter(); | ||
199 | |||
200 | /* racy, but better than risking deadlock. */ | ||
201 | raw_local_irq_save(flags); | ||
202 | cpu = smp_processor_id(); | ||
203 | if (!__raw_spin_trylock(&die_lock)) { | ||
204 | if (cpu == die_owner) | ||
205 | /* nested oops. should stop eventually */; | ||
206 | else | ||
207 | __raw_spin_lock(&die_lock); | ||
208 | } | ||
209 | die_nest_count++; | ||
210 | die_owner = cpu; | ||
211 | console_verbose(); | ||
212 | bust_spinlocks(1); | ||
213 | return flags; | ||
214 | } | ||
215 | |||
216 | void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr) | ||
217 | { | ||
218 | if (regs && kexec_should_crash(current)) | ||
219 | crash_kexec(regs); | ||
220 | |||
221 | bust_spinlocks(0); | ||
222 | die_owner = -1; | ||
223 | add_taint(TAINT_DIE); | ||
224 | die_nest_count--; | ||
225 | if (!die_nest_count) | ||
226 | /* Nest count reaches zero, release the lock. */ | ||
227 | __raw_spin_unlock(&die_lock); | ||
228 | raw_local_irq_restore(flags); | ||
229 | oops_exit(); | ||
230 | |||
231 | if (!signr) | ||
232 | return; | ||
233 | if (in_interrupt()) | ||
234 | panic("Fatal exception in interrupt"); | ||
235 | if (panic_on_oops) | ||
236 | panic("Fatal exception"); | ||
237 | do_exit(signr); | ||
238 | } | ||
239 | |||
240 | int __kprobes __die(const char *str, struct pt_regs *regs, long err) | ||
241 | { | ||
242 | #ifdef CONFIG_X86_32 | ||
243 | unsigned short ss; | ||
244 | unsigned long sp; | ||
245 | #endif | ||
246 | printk(KERN_EMERG "%s: %04lx [#%d] ", str, err & 0xffff, ++die_counter); | ||
247 | #ifdef CONFIG_PREEMPT | ||
248 | printk("PREEMPT "); | ||
249 | #endif | ||
250 | #ifdef CONFIG_SMP | ||
251 | printk("SMP "); | ||
252 | #endif | ||
253 | #ifdef CONFIG_DEBUG_PAGEALLOC | ||
254 | printk("DEBUG_PAGEALLOC"); | ||
255 | #endif | ||
256 | printk("\n"); | ||
257 | sysfs_printk_last_file(); | ||
258 | if (notify_die(DIE_OOPS, str, regs, err, | ||
259 | current->thread.trap_no, SIGSEGV) == NOTIFY_STOP) | ||
260 | return 1; | ||
261 | |||
262 | show_registers(regs); | ||
263 | #ifdef CONFIG_X86_32 | ||
264 | sp = (unsigned long) (®s->sp); | ||
265 | savesegment(ss, ss); | ||
266 | if (user_mode(regs)) { | ||
267 | sp = regs->sp; | ||
268 | ss = regs->ss & 0xffff; | ||
269 | } | ||
270 | printk(KERN_EMERG "EIP: [<%08lx>] ", regs->ip); | ||
271 | print_symbol("%s", regs->ip); | ||
272 | printk(" SS:ESP %04x:%08lx\n", ss, sp); | ||
273 | #else | ||
274 | /* Executive summary in case the oops scrolled away */ | ||
275 | printk(KERN_ALERT "RIP "); | ||
276 | printk_address(regs->ip, 1); | ||
277 | printk(" RSP <%016lx>\n", regs->sp); | ||
278 | #endif | ||
279 | return 0; | ||
280 | } | ||
281 | |||
282 | /* | ||
283 | * This is gone through when something in the kernel has done something bad | ||
284 | * and is about to be terminated: | ||
285 | */ | ||
286 | void die(const char *str, struct pt_regs *regs, long err) | ||
287 | { | ||
288 | unsigned long flags = oops_begin(); | ||
289 | int sig = SIGSEGV; | ||
290 | |||
291 | if (!user_mode_vm(regs)) | ||
292 | report_bug(regs->ip, regs); | ||
293 | |||
294 | if (__die(str, regs, err)) | ||
295 | sig = 0; | ||
296 | oops_end(flags, regs, sig); | ||
297 | } | ||
298 | |||
299 | void notrace __kprobes | ||
300 | die_nmi(char *str, struct pt_regs *regs, int do_panic) | ||
301 | { | ||
302 | unsigned long flags; | ||
303 | |||
304 | if (notify_die(DIE_NMIWATCHDOG, str, regs, 0, 2, SIGINT) == NOTIFY_STOP) | ||
305 | return; | ||
306 | |||
307 | /* | ||
308 | * We are in trouble anyway, lets at least try | ||
309 | * to get a message out. | ||
310 | */ | ||
311 | flags = oops_begin(); | ||
312 | printk(KERN_EMERG "%s", str); | ||
313 | printk(" on CPU%d, ip %08lx, registers:\n", | ||
314 | smp_processor_id(), regs->ip); | ||
315 | show_registers(regs); | ||
316 | oops_end(flags, regs, 0); | ||
317 | if (do_panic || panic_on_oops) | ||
318 | panic("Non maskable interrupt"); | ||
319 | nmi_exit(); | ||
320 | local_irq_enable(); | ||
321 | do_exit(SIGBUS); | ||
322 | } | ||
323 | |||
324 | static int __init oops_setup(char *s) | ||
325 | { | ||
326 | if (!s) | ||
327 | return -EINVAL; | ||
328 | if (!strcmp(s, "panic")) | ||
329 | panic_on_oops = 1; | ||
330 | return 0; | ||
331 | } | ||
332 | early_param("oops", oops_setup); | ||
333 | |||
334 | static int __init kstack_setup(char *s) | ||
335 | { | ||
336 | if (!s) | ||
337 | return -EINVAL; | ||
338 | kstack_depth_to_print = simple_strtoul(s, NULL, 0); | ||
339 | return 0; | ||
340 | } | ||
341 | early_param("kstack", kstack_setup); | ||
342 | |||
343 | static int __init code_bytes_setup(char *s) | ||
344 | { | ||
345 | code_bytes = simple_strtoul(s, NULL, 0); | ||
346 | if (code_bytes > 8192) | ||
347 | code_bytes = 8192; | ||
348 | |||
349 | return 1; | ||
350 | } | ||
351 | __setup("code_bytes=", code_bytes_setup); | ||
diff --git a/arch/x86/kernel/dumpstack.h b/arch/x86/kernel/dumpstack.h new file mode 100644 index 000000000000..da87590b8698 --- /dev/null +++ b/arch/x86/kernel/dumpstack.h | |||
@@ -0,0 +1,39 @@ | |||
1 | /* | ||
2 | * Copyright (C) 1991, 1992 Linus Torvalds | ||
3 | * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs | ||
4 | */ | ||
5 | |||
6 | #ifndef DUMPSTACK_H | ||
7 | #define DUMPSTACK_H | ||
8 | |||
9 | #ifdef CONFIG_X86_32 | ||
10 | #define STACKSLOTS_PER_LINE 8 | ||
11 | #define get_bp(bp) asm("movl %%ebp, %0" : "=r" (bp) :) | ||
12 | #else | ||
13 | #define STACKSLOTS_PER_LINE 4 | ||
14 | #define get_bp(bp) asm("movq %%rbp, %0" : "=r" (bp) :) | ||
15 | #endif | ||
16 | |||
17 | extern unsigned long | ||
18 | print_context_stack(struct thread_info *tinfo, | ||
19 | unsigned long *stack, unsigned long bp, | ||
20 | const struct stacktrace_ops *ops, void *data, | ||
21 | unsigned long *end, int *graph); | ||
22 | |||
23 | extern void | ||
24 | show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs, | ||
25 | unsigned long *stack, unsigned long bp, char *log_lvl); | ||
26 | |||
27 | extern void | ||
28 | show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, | ||
29 | unsigned long *sp, unsigned long bp, char *log_lvl); | ||
30 | |||
31 | extern unsigned int code_bytes; | ||
32 | extern int kstack_depth_to_print; | ||
33 | |||
34 | /* The form of the top of the frame on the stack */ | ||
35 | struct stack_frame { | ||
36 | struct stack_frame *next_frame; | ||
37 | unsigned long return_address; | ||
38 | }; | ||
39 | #endif | ||
diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c index b3614752197b..d593cd1f58dc 100644 --- a/arch/x86/kernel/dumpstack_32.c +++ b/arch/x86/kernel/dumpstack_32.c | |||
@@ -17,69 +17,14 @@ | |||
17 | 17 | ||
18 | #include <asm/stacktrace.h> | 18 | #include <asm/stacktrace.h> |
19 | 19 | ||
20 | #define STACKSLOTS_PER_LINE 8 | 20 | #include "dumpstack.h" |
21 | #define get_bp(bp) asm("movl %%ebp, %0" : "=r" (bp) :) | ||
22 | |||
23 | int panic_on_unrecovered_nmi; | ||
24 | int kstack_depth_to_print = 3 * STACKSLOTS_PER_LINE; | ||
25 | static unsigned int code_bytes = 64; | ||
26 | static int die_counter; | ||
27 | |||
28 | void printk_address(unsigned long address, int reliable) | ||
29 | { | ||
30 | printk(" [<%p>] %s%pS\n", (void *) address, | ||
31 | reliable ? "" : "? ", (void *) address); | ||
32 | } | ||
33 | |||
34 | static inline int valid_stack_ptr(struct thread_info *tinfo, | ||
35 | void *p, unsigned int size, void *end) | ||
36 | { | ||
37 | void *t = tinfo; | ||
38 | if (end) { | ||
39 | if (p < end && p >= (end-THREAD_SIZE)) | ||
40 | return 1; | ||
41 | else | ||
42 | return 0; | ||
43 | } | ||
44 | return p > t && p < t + THREAD_SIZE - size; | ||
45 | } | ||
46 | |||
47 | /* The form of the top of the frame on the stack */ | ||
48 | struct stack_frame { | ||
49 | struct stack_frame *next_frame; | ||
50 | unsigned long return_address; | ||
51 | }; | ||
52 | |||
53 | static inline unsigned long | ||
54 | print_context_stack(struct thread_info *tinfo, | ||
55 | unsigned long *stack, unsigned long bp, | ||
56 | const struct stacktrace_ops *ops, void *data, | ||
57 | unsigned long *end) | ||
58 | { | ||
59 | struct stack_frame *frame = (struct stack_frame *)bp; | ||
60 | |||
61 | while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) { | ||
62 | unsigned long addr; | ||
63 | |||
64 | addr = *stack; | ||
65 | if (__kernel_text_address(addr)) { | ||
66 | if ((unsigned long) stack == bp + sizeof(long)) { | ||
67 | ops->address(data, addr, 1); | ||
68 | frame = frame->next_frame; | ||
69 | bp = (unsigned long) frame; | ||
70 | } else { | ||
71 | ops->address(data, addr, bp == 0); | ||
72 | } | ||
73 | } | ||
74 | stack++; | ||
75 | } | ||
76 | return bp; | ||
77 | } | ||
78 | 21 | ||
79 | void dump_trace(struct task_struct *task, struct pt_regs *regs, | 22 | void dump_trace(struct task_struct *task, struct pt_regs *regs, |
80 | unsigned long *stack, unsigned long bp, | 23 | unsigned long *stack, unsigned long bp, |
81 | const struct stacktrace_ops *ops, void *data) | 24 | const struct stacktrace_ops *ops, void *data) |
82 | { | 25 | { |
26 | int graph = 0; | ||
27 | |||
83 | if (!task) | 28 | if (!task) |
84 | task = current; | 29 | task = current; |
85 | 30 | ||
@@ -107,7 +52,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs, | |||
107 | 52 | ||
108 | context = (struct thread_info *) | 53 | context = (struct thread_info *) |
109 | ((unsigned long)stack & (~(THREAD_SIZE - 1))); | 54 | ((unsigned long)stack & (~(THREAD_SIZE - 1))); |
110 | bp = print_context_stack(context, stack, bp, ops, data, NULL); | 55 | bp = print_context_stack(context, stack, bp, ops, |
56 | data, NULL, &graph); | ||
111 | 57 | ||
112 | stack = (unsigned long *)context->previous_esp; | 58 | stack = (unsigned long *)context->previous_esp; |
113 | if (!stack) | 59 | if (!stack) |
@@ -119,57 +65,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs, | |||
119 | } | 65 | } |
120 | EXPORT_SYMBOL(dump_trace); | 66 | EXPORT_SYMBOL(dump_trace); |
121 | 67 | ||
122 | static void | 68 | void |
123 | print_trace_warning_symbol(void *data, char *msg, unsigned long symbol) | ||
124 | { | ||
125 | printk(data); | ||
126 | print_symbol(msg, symbol); | ||
127 | printk("\n"); | ||
128 | } | ||
129 | |||
130 | static void print_trace_warning(void *data, char *msg) | ||
131 | { | ||
132 | printk("%s%s\n", (char *)data, msg); | ||
133 | } | ||
134 | |||
135 | static int print_trace_stack(void *data, char *name) | ||
136 | { | ||
137 | printk("%s <%s> ", (char *)data, name); | ||
138 | return 0; | ||
139 | } | ||
140 | |||
141 | /* | ||
142 | * Print one address/symbol entries per line. | ||
143 | */ | ||
144 | static void print_trace_address(void *data, unsigned long addr, int reliable) | ||
145 | { | ||
146 | touch_nmi_watchdog(); | ||
147 | printk(data); | ||
148 | printk_address(addr, reliable); | ||
149 | } | ||
150 | |||
151 | static const struct stacktrace_ops print_trace_ops = { | ||
152 | .warning = print_trace_warning, | ||
153 | .warning_symbol = print_trace_warning_symbol, | ||
154 | .stack = print_trace_stack, | ||
155 | .address = print_trace_address, | ||
156 | }; | ||
157 | |||
158 | static void | ||
159 | show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs, | ||
160 | unsigned long *stack, unsigned long bp, char *log_lvl) | ||
161 | { | ||
162 | printk("%sCall Trace:\n", log_lvl); | ||
163 | dump_trace(task, regs, stack, bp, &print_trace_ops, log_lvl); | ||
164 | } | ||
165 | |||
166 | void show_trace(struct task_struct *task, struct pt_regs *regs, | ||
167 | unsigned long *stack, unsigned long bp) | ||
168 | { | ||
169 | show_trace_log_lvl(task, regs, stack, bp, ""); | ||
170 | } | ||
171 | |||
172 | static void | ||
173 | show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, | 69 | show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, |
174 | unsigned long *sp, unsigned long bp, char *log_lvl) | 70 | unsigned long *sp, unsigned long bp, char *log_lvl) |
175 | { | 71 | { |
@@ -196,33 +92,6 @@ show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, | |||
196 | show_trace_log_lvl(task, regs, sp, bp, log_lvl); | 92 | show_trace_log_lvl(task, regs, sp, bp, log_lvl); |
197 | } | 93 | } |
198 | 94 | ||
199 | void show_stack(struct task_struct *task, unsigned long *sp) | ||
200 | { | ||
201 | show_stack_log_lvl(task, NULL, sp, 0, ""); | ||
202 | } | ||
203 | |||
204 | /* | ||
205 | * The architecture-independent dump_stack generator | ||
206 | */ | ||
207 | void dump_stack(void) | ||
208 | { | ||
209 | unsigned long bp = 0; | ||
210 | unsigned long stack; | ||
211 | |||
212 | #ifdef CONFIG_FRAME_POINTER | ||
213 | if (!bp) | ||
214 | get_bp(bp); | ||
215 | #endif | ||
216 | |||
217 | printk("Pid: %d, comm: %.20s %s %s %.*s\n", | ||
218 | current->pid, current->comm, print_tainted(), | ||
219 | init_utsname()->release, | ||
220 | (int)strcspn(init_utsname()->version, " "), | ||
221 | init_utsname()->version); | ||
222 | show_trace(NULL, NULL, &stack, bp); | ||
223 | } | ||
224 | |||
225 | EXPORT_SYMBOL(dump_stack); | ||
226 | 95 | ||
227 | void show_registers(struct pt_regs *regs) | 96 | void show_registers(struct pt_regs *regs) |
228 | { | 97 | { |
@@ -283,167 +152,3 @@ int is_valid_bugaddr(unsigned long ip) | |||
283 | return ud2 == 0x0b0f; | 152 | return ud2 == 0x0b0f; |
284 | } | 153 | } |
285 | 154 | ||
286 | static raw_spinlock_t die_lock = __RAW_SPIN_LOCK_UNLOCKED; | ||
287 | static int die_owner = -1; | ||
288 | static unsigned int die_nest_count; | ||
289 | |||
290 | unsigned __kprobes long oops_begin(void) | ||
291 | { | ||
292 | unsigned long flags; | ||
293 | |||
294 | oops_enter(); | ||
295 | |||
296 | if (die_owner != raw_smp_processor_id()) { | ||
297 | console_verbose(); | ||
298 | raw_local_irq_save(flags); | ||
299 | __raw_spin_lock(&die_lock); | ||
300 | die_owner = smp_processor_id(); | ||
301 | die_nest_count = 0; | ||
302 | bust_spinlocks(1); | ||
303 | } else { | ||
304 | raw_local_irq_save(flags); | ||
305 | } | ||
306 | die_nest_count++; | ||
307 | return flags; | ||
308 | } | ||
309 | |||
310 | void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr) | ||
311 | { | ||
312 | bust_spinlocks(0); | ||
313 | die_owner = -1; | ||
314 | add_taint(TAINT_DIE); | ||
315 | __raw_spin_unlock(&die_lock); | ||
316 | raw_local_irq_restore(flags); | ||
317 | |||
318 | if (!regs) | ||
319 | return; | ||
320 | |||
321 | if (kexec_should_crash(current)) | ||
322 | crash_kexec(regs); | ||
323 | if (in_interrupt()) | ||
324 | panic("Fatal exception in interrupt"); | ||
325 | if (panic_on_oops) | ||
326 | panic("Fatal exception"); | ||
327 | oops_exit(); | ||
328 | do_exit(signr); | ||
329 | } | ||
330 | |||
331 | int __kprobes __die(const char *str, struct pt_regs *regs, long err) | ||
332 | { | ||
333 | unsigned short ss; | ||
334 | unsigned long sp; | ||
335 | |||
336 | printk(KERN_EMERG "%s: %04lx [#%d] ", str, err & 0xffff, ++die_counter); | ||
337 | #ifdef CONFIG_PREEMPT | ||
338 | printk("PREEMPT "); | ||
339 | #endif | ||
340 | #ifdef CONFIG_SMP | ||
341 | printk("SMP "); | ||
342 | #endif | ||
343 | #ifdef CONFIG_DEBUG_PAGEALLOC | ||
344 | printk("DEBUG_PAGEALLOC"); | ||
345 | #endif | ||
346 | printk("\n"); | ||
347 | sysfs_printk_last_file(); | ||
348 | if (notify_die(DIE_OOPS, str, regs, err, | ||
349 | current->thread.trap_no, SIGSEGV) == NOTIFY_STOP) | ||
350 | return 1; | ||
351 | |||
352 | show_registers(regs); | ||
353 | /* Executive summary in case the oops scrolled away */ | ||
354 | sp = (unsigned long) (®s->sp); | ||
355 | savesegment(ss, ss); | ||
356 | if (user_mode(regs)) { | ||
357 | sp = regs->sp; | ||
358 | ss = regs->ss & 0xffff; | ||
359 | } | ||
360 | printk(KERN_EMERG "EIP: [<%08lx>] ", regs->ip); | ||
361 | print_symbol("%s", regs->ip); | ||
362 | printk(" SS:ESP %04x:%08lx\n", ss, sp); | ||
363 | return 0; | ||
364 | } | ||
365 | |||
366 | /* | ||
367 | * This is gone through when something in the kernel has done something bad | ||
368 | * and is about to be terminated: | ||
369 | */ | ||
370 | void die(const char *str, struct pt_regs *regs, long err) | ||
371 | { | ||
372 | unsigned long flags = oops_begin(); | ||
373 | |||
374 | if (die_nest_count < 3) { | ||
375 | report_bug(regs->ip, regs); | ||
376 | |||
377 | if (__die(str, regs, err)) | ||
378 | regs = NULL; | ||
379 | } else { | ||
380 | printk(KERN_EMERG "Recursive die() failure, output suppressed\n"); | ||
381 | } | ||
382 | |||
383 | oops_end(flags, regs, SIGSEGV); | ||
384 | } | ||
385 | |||
386 | static DEFINE_SPINLOCK(nmi_print_lock); | ||
387 | |||
388 | void notrace __kprobes | ||
389 | die_nmi(char *str, struct pt_regs *regs, int do_panic) | ||
390 | { | ||
391 | if (notify_die(DIE_NMIWATCHDOG, str, regs, 0, 2, SIGINT) == NOTIFY_STOP) | ||
392 | return; | ||
393 | |||
394 | spin_lock(&nmi_print_lock); | ||
395 | /* | ||
396 | * We are in trouble anyway, lets at least try | ||
397 | * to get a message out: | ||
398 | */ | ||
399 | bust_spinlocks(1); | ||
400 | printk(KERN_EMERG "%s", str); | ||
401 | printk(" on CPU%d, ip %08lx, registers:\n", | ||
402 | smp_processor_id(), regs->ip); | ||
403 | show_registers(regs); | ||
404 | if (do_panic) | ||
405 | panic("Non maskable interrupt"); | ||
406 | console_silent(); | ||
407 | spin_unlock(&nmi_print_lock); | ||
408 | |||
409 | /* | ||
410 | * If we are in kernel we are probably nested up pretty bad | ||
411 | * and might aswell get out now while we still can: | ||
412 | */ | ||
413 | if (!user_mode_vm(regs)) { | ||
414 | current->thread.trap_no = 2; | ||
415 | crash_kexec(regs); | ||
416 | } | ||
417 | |||
418 | bust_spinlocks(0); | ||
419 | do_exit(SIGSEGV); | ||
420 | } | ||
421 | |||
422 | static int __init oops_setup(char *s) | ||
423 | { | ||
424 | if (!s) | ||
425 | return -EINVAL; | ||
426 | if (!strcmp(s, "panic")) | ||
427 | panic_on_oops = 1; | ||
428 | return 0; | ||
429 | } | ||
430 | early_param("oops", oops_setup); | ||
431 | |||
432 | static int __init kstack_setup(char *s) | ||
433 | { | ||
434 | if (!s) | ||
435 | return -EINVAL; | ||
436 | kstack_depth_to_print = simple_strtoul(s, NULL, 0); | ||
437 | return 0; | ||
438 | } | ||
439 | early_param("kstack", kstack_setup); | ||
440 | |||
441 | static int __init code_bytes_setup(char *s) | ||
442 | { | ||
443 | code_bytes = simple_strtoul(s, NULL, 0); | ||
444 | if (code_bytes > 8192) | ||
445 | code_bytes = 8192; | ||
446 | |||
447 | return 1; | ||
448 | } | ||
449 | __setup("code_bytes=", code_bytes_setup); | ||
diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c index 96a5db7da8a7..c302d0707048 100644 --- a/arch/x86/kernel/dumpstack_64.c +++ b/arch/x86/kernel/dumpstack_64.c | |||
@@ -17,19 +17,7 @@ | |||
17 | 17 | ||
18 | #include <asm/stacktrace.h> | 18 | #include <asm/stacktrace.h> |
19 | 19 | ||
20 | #define STACKSLOTS_PER_LINE 4 | 20 | #include "dumpstack.h" |
21 | #define get_bp(bp) asm("movq %%rbp, %0" : "=r" (bp) :) | ||
22 | |||
23 | int panic_on_unrecovered_nmi; | ||
24 | int kstack_depth_to_print = 3 * STACKSLOTS_PER_LINE; | ||
25 | static unsigned int code_bytes = 64; | ||
26 | static int die_counter; | ||
27 | |||
28 | void printk_address(unsigned long address, int reliable) | ||
29 | { | ||
30 | printk(" [<%p>] %s%pS\n", (void *) address, | ||
31 | reliable ? "" : "? ", (void *) address); | ||
32 | } | ||
33 | 21 | ||
34 | static unsigned long *in_exception_stack(unsigned cpu, unsigned long stack, | 22 | static unsigned long *in_exception_stack(unsigned cpu, unsigned long stack, |
35 | unsigned *usedp, char **idp) | 23 | unsigned *usedp, char **idp) |
@@ -113,51 +101,6 @@ static unsigned long *in_exception_stack(unsigned cpu, unsigned long stack, | |||
113 | * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack | 101 | * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack |
114 | */ | 102 | */ |
115 | 103 | ||
116 | static inline int valid_stack_ptr(struct thread_info *tinfo, | ||
117 | void *p, unsigned int size, void *end) | ||
118 | { | ||
119 | void *t = tinfo; | ||
120 | if (end) { | ||
121 | if (p < end && p >= (end-THREAD_SIZE)) | ||
122 | return 1; | ||
123 | else | ||
124 | return 0; | ||
125 | } | ||
126 | return p > t && p < t + THREAD_SIZE - size; | ||
127 | } | ||
128 | |||
129 | /* The form of the top of the frame on the stack */ | ||
130 | struct stack_frame { | ||
131 | struct stack_frame *next_frame; | ||
132 | unsigned long return_address; | ||
133 | }; | ||
134 | |||
135 | static inline unsigned long | ||
136 | print_context_stack(struct thread_info *tinfo, | ||
137 | unsigned long *stack, unsigned long bp, | ||
138 | const struct stacktrace_ops *ops, void *data, | ||
139 | unsigned long *end) | ||
140 | { | ||
141 | struct stack_frame *frame = (struct stack_frame *)bp; | ||
142 | |||
143 | while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) { | ||
144 | unsigned long addr; | ||
145 | |||
146 | addr = *stack; | ||
147 | if (__kernel_text_address(addr)) { | ||
148 | if ((unsigned long) stack == bp + sizeof(long)) { | ||
149 | ops->address(data, addr, 1); | ||
150 | frame = frame->next_frame; | ||
151 | bp = (unsigned long) frame; | ||
152 | } else { | ||
153 | ops->address(data, addr, bp == 0); | ||
154 | } | ||
155 | } | ||
156 | stack++; | ||
157 | } | ||
158 | return bp; | ||
159 | } | ||
160 | |||
161 | void dump_trace(struct task_struct *task, struct pt_regs *regs, | 104 | void dump_trace(struct task_struct *task, struct pt_regs *regs, |
162 | unsigned long *stack, unsigned long bp, | 105 | unsigned long *stack, unsigned long bp, |
163 | const struct stacktrace_ops *ops, void *data) | 106 | const struct stacktrace_ops *ops, void *data) |
@@ -166,6 +109,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs, | |||
166 | unsigned long *irqstack_end = (unsigned long *)cpu_pda(cpu)->irqstackptr; | 109 | unsigned long *irqstack_end = (unsigned long *)cpu_pda(cpu)->irqstackptr; |
167 | unsigned used = 0; | 110 | unsigned used = 0; |
168 | struct thread_info *tinfo; | 111 | struct thread_info *tinfo; |
112 | int graph = 0; | ||
169 | 113 | ||
170 | if (!task) | 114 | if (!task) |
171 | task = current; | 115 | task = current; |
@@ -206,7 +150,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs, | |||
206 | break; | 150 | break; |
207 | 151 | ||
208 | bp = print_context_stack(tinfo, stack, bp, ops, | 152 | bp = print_context_stack(tinfo, stack, bp, ops, |
209 | data, estack_end); | 153 | data, estack_end, &graph); |
210 | ops->stack(data, "<EOE>"); | 154 | ops->stack(data, "<EOE>"); |
211 | /* | 155 | /* |
212 | * We link to the next stack via the | 156 | * We link to the next stack via the |
@@ -225,7 +169,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs, | |||
225 | if (ops->stack(data, "IRQ") < 0) | 169 | if (ops->stack(data, "IRQ") < 0) |
226 | break; | 170 | break; |
227 | bp = print_context_stack(tinfo, stack, bp, | 171 | bp = print_context_stack(tinfo, stack, bp, |
228 | ops, data, irqstack_end); | 172 | ops, data, irqstack_end, &graph); |
229 | /* | 173 | /* |
230 | * We link to the next stack (which would be | 174 | * We link to the next stack (which would be |
231 | * the process stack normally) the last | 175 | * the process stack normally) the last |
@@ -243,62 +187,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs, | |||
243 | /* | 187 | /* |
244 | * This handles the process stack: | 188 | * This handles the process stack: |
245 | */ | 189 | */ |
246 | bp = print_context_stack(tinfo, stack, bp, ops, data, NULL); | 190 | bp = print_context_stack(tinfo, stack, bp, ops, data, NULL, &graph); |
247 | put_cpu(); | 191 | put_cpu(); |
248 | } | 192 | } |
249 | EXPORT_SYMBOL(dump_trace); | 193 | EXPORT_SYMBOL(dump_trace); |
250 | 194 | ||
251 | static void | 195 | void |
252 | print_trace_warning_symbol(void *data, char *msg, unsigned long symbol) | ||
253 | { | ||
254 | printk(data); | ||
255 | print_symbol(msg, symbol); | ||
256 | printk("\n"); | ||
257 | } | ||
258 | |||
259 | static void print_trace_warning(void *data, char *msg) | ||
260 | { | ||
261 | printk("%s%s\n", (char *)data, msg); | ||
262 | } | ||
263 | |||
264 | static int print_trace_stack(void *data, char *name) | ||
265 | { | ||
266 | printk("%s <%s> ", (char *)data, name); | ||
267 | return 0; | ||
268 | } | ||
269 | |||
270 | /* | ||
271 | * Print one address/symbol entries per line. | ||
272 | */ | ||
273 | static void print_trace_address(void *data, unsigned long addr, int reliable) | ||
274 | { | ||
275 | touch_nmi_watchdog(); | ||
276 | printk(data); | ||
277 | printk_address(addr, reliable); | ||
278 | } | ||
279 | |||
280 | static const struct stacktrace_ops print_trace_ops = { | ||
281 | .warning = print_trace_warning, | ||
282 | .warning_symbol = print_trace_warning_symbol, | ||
283 | .stack = print_trace_stack, | ||
284 | .address = print_trace_address, | ||
285 | }; | ||
286 | |||
287 | static void | ||
288 | show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs, | ||
289 | unsigned long *stack, unsigned long bp, char *log_lvl) | ||
290 | { | ||
291 | printk("%sCall Trace:\n", log_lvl); | ||
292 | dump_trace(task, regs, stack, bp, &print_trace_ops, log_lvl); | ||
293 | } | ||
294 | |||
295 | void show_trace(struct task_struct *task, struct pt_regs *regs, | ||
296 | unsigned long *stack, unsigned long bp) | ||
297 | { | ||
298 | show_trace_log_lvl(task, regs, stack, bp, ""); | ||
299 | } | ||
300 | |||
301 | static void | ||
302 | show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, | 196 | show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, |
303 | unsigned long *sp, unsigned long bp, char *log_lvl) | 197 | unsigned long *sp, unsigned long bp, char *log_lvl) |
304 | { | 198 | { |
@@ -342,33 +236,6 @@ show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, | |||
342 | show_trace_log_lvl(task, regs, sp, bp, log_lvl); | 236 | show_trace_log_lvl(task, regs, sp, bp, log_lvl); |
343 | } | 237 | } |
344 | 238 | ||
345 | void show_stack(struct task_struct *task, unsigned long *sp) | ||
346 | { | ||
347 | show_stack_log_lvl(task, NULL, sp, 0, ""); | ||
348 | } | ||
349 | |||
350 | /* | ||
351 | * The architecture-independent dump_stack generator | ||
352 | */ | ||
353 | void dump_stack(void) | ||
354 | { | ||
355 | unsigned long bp = 0; | ||
356 | unsigned long stack; | ||
357 | |||
358 | #ifdef CONFIG_FRAME_POINTER | ||
359 | if (!bp) | ||
360 | get_bp(bp); | ||
361 | #endif | ||
362 | |||
363 | printk("Pid: %d, comm: %.20s %s %s %.*s\n", | ||
364 | current->pid, current->comm, print_tainted(), | ||
365 | init_utsname()->release, | ||
366 | (int)strcspn(init_utsname()->version, " "), | ||
367 | init_utsname()->version); | ||
368 | show_trace(NULL, NULL, &stack, bp); | ||
369 | } | ||
370 | EXPORT_SYMBOL(dump_stack); | ||
371 | |||
372 | void show_registers(struct pt_regs *regs) | 239 | void show_registers(struct pt_regs *regs) |
373 | { | 240 | { |
374 | int i; | 241 | int i; |
@@ -429,147 +296,3 @@ int is_valid_bugaddr(unsigned long ip) | |||
429 | return ud2 == 0x0b0f; | 296 | return ud2 == 0x0b0f; |
430 | } | 297 | } |
431 | 298 | ||
432 | static raw_spinlock_t die_lock = __RAW_SPIN_LOCK_UNLOCKED; | ||
433 | static int die_owner = -1; | ||
434 | static unsigned int die_nest_count; | ||
435 | |||
436 | unsigned __kprobes long oops_begin(void) | ||
437 | { | ||
438 | int cpu; | ||
439 | unsigned long flags; | ||
440 | |||
441 | oops_enter(); | ||
442 | |||
443 | /* racy, but better than risking deadlock. */ | ||
444 | raw_local_irq_save(flags); | ||
445 | cpu = smp_processor_id(); | ||
446 | if (!__raw_spin_trylock(&die_lock)) { | ||
447 | if (cpu == die_owner) | ||
448 | /* nested oops. should stop eventually */; | ||
449 | else | ||
450 | __raw_spin_lock(&die_lock); | ||
451 | } | ||
452 | die_nest_count++; | ||
453 | die_owner = cpu; | ||
454 | console_verbose(); | ||
455 | bust_spinlocks(1); | ||
456 | return flags; | ||
457 | } | ||
458 | |||
459 | void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr) | ||
460 | { | ||
461 | die_owner = -1; | ||
462 | bust_spinlocks(0); | ||
463 | die_nest_count--; | ||
464 | if (!die_nest_count) | ||
465 | /* Nest count reaches zero, release the lock. */ | ||
466 | __raw_spin_unlock(&die_lock); | ||
467 | raw_local_irq_restore(flags); | ||
468 | if (!regs) { | ||
469 | oops_exit(); | ||
470 | return; | ||
471 | } | ||
472 | if (in_interrupt()) | ||
473 | panic("Fatal exception in interrupt"); | ||
474 | if (panic_on_oops) | ||
475 | panic("Fatal exception"); | ||
476 | oops_exit(); | ||
477 | do_exit(signr); | ||
478 | } | ||
479 | |||
480 | int __kprobes __die(const char *str, struct pt_regs *regs, long err) | ||
481 | { | ||
482 | printk(KERN_EMERG "%s: %04lx [#%d] ", str, err & 0xffff, ++die_counter); | ||
483 | #ifdef CONFIG_PREEMPT | ||
484 | printk("PREEMPT "); | ||
485 | #endif | ||
486 | #ifdef CONFIG_SMP | ||
487 | printk("SMP "); | ||
488 | #endif | ||
489 | #ifdef CONFIG_DEBUG_PAGEALLOC | ||
490 | printk("DEBUG_PAGEALLOC"); | ||
491 | #endif | ||
492 | printk("\n"); | ||
493 | sysfs_printk_last_file(); | ||
494 | if (notify_die(DIE_OOPS, str, regs, err, | ||
495 | current->thread.trap_no, SIGSEGV) == NOTIFY_STOP) | ||
496 | return 1; | ||
497 | |||
498 | show_registers(regs); | ||
499 | add_taint(TAINT_DIE); | ||
500 | /* Executive summary in case the oops scrolled away */ | ||
501 | printk(KERN_ALERT "RIP "); | ||
502 | printk_address(regs->ip, 1); | ||
503 | printk(" RSP <%016lx>\n", regs->sp); | ||
504 | if (kexec_should_crash(current)) | ||
505 | crash_kexec(regs); | ||
506 | return 0; | ||
507 | } | ||
508 | |||
509 | void die(const char *str, struct pt_regs *regs, long err) | ||
510 | { | ||
511 | unsigned long flags = oops_begin(); | ||
512 | |||
513 | if (!user_mode(regs)) | ||
514 | report_bug(regs->ip, regs); | ||
515 | |||
516 | if (__die(str, regs, err)) | ||
517 | regs = NULL; | ||
518 | oops_end(flags, regs, SIGSEGV); | ||
519 | } | ||
520 | |||
521 | notrace __kprobes void | ||
522 | die_nmi(char *str, struct pt_regs *regs, int do_panic) | ||
523 | { | ||
524 | unsigned long flags; | ||
525 | |||
526 | if (notify_die(DIE_NMIWATCHDOG, str, regs, 0, 2, SIGINT) == NOTIFY_STOP) | ||
527 | return; | ||
528 | |||
529 | flags = oops_begin(); | ||
530 | /* | ||
531 | * We are in trouble anyway, lets at least try | ||
532 | * to get a message out. | ||
533 | */ | ||
534 | printk(KERN_EMERG "%s", str); | ||
535 | printk(" on CPU%d, ip %08lx, registers:\n", | ||
536 | smp_processor_id(), regs->ip); | ||
537 | show_registers(regs); | ||
538 | if (kexec_should_crash(current)) | ||
539 | crash_kexec(regs); | ||
540 | if (do_panic || panic_on_oops) | ||
541 | panic("Non maskable interrupt"); | ||
542 | oops_end(flags, NULL, SIGBUS); | ||
543 | nmi_exit(); | ||
544 | local_irq_enable(); | ||
545 | do_exit(SIGBUS); | ||
546 | } | ||
547 | |||
548 | static int __init oops_setup(char *s) | ||
549 | { | ||
550 | if (!s) | ||
551 | return -EINVAL; | ||
552 | if (!strcmp(s, "panic")) | ||
553 | panic_on_oops = 1; | ||
554 | return 0; | ||
555 | } | ||
556 | early_param("oops", oops_setup); | ||
557 | |||
558 | static int __init kstack_setup(char *s) | ||
559 | { | ||
560 | if (!s) | ||
561 | return -EINVAL; | ||
562 | kstack_depth_to_print = simple_strtoul(s, NULL, 0); | ||
563 | return 0; | ||
564 | } | ||
565 | early_param("kstack", kstack_setup); | ||
566 | |||
567 | static int __init code_bytes_setup(char *s) | ||
568 | { | ||
569 | code_bytes = simple_strtoul(s, NULL, 0); | ||
570 | if (code_bytes > 8192) | ||
571 | code_bytes = 8192; | ||
572 | |||
573 | return 1; | ||
574 | } | ||
575 | __setup("code_bytes=", code_bytes_setup); | ||
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c index 74c6a21fdc8c..e85826829cf2 100644 --- a/arch/x86/kernel/e820.c +++ b/arch/x86/kernel/e820.c | |||
@@ -698,22 +698,6 @@ struct early_res { | |||
698 | }; | 698 | }; |
699 | static struct early_res early_res[MAX_EARLY_RES] __initdata = { | 699 | static struct early_res early_res[MAX_EARLY_RES] __initdata = { |
700 | { 0, PAGE_SIZE, "BIOS data page" }, /* BIOS data page */ | 700 | { 0, PAGE_SIZE, "BIOS data page" }, /* BIOS data page */ |
701 | #if defined(CONFIG_X86_64) && defined(CONFIG_X86_TRAMPOLINE) | ||
702 | { TRAMPOLINE_BASE, TRAMPOLINE_BASE + 2 * PAGE_SIZE, "TRAMPOLINE" }, | ||
703 | #endif | ||
704 | #if defined(CONFIG_X86_32) && defined(CONFIG_SMP) | ||
705 | /* | ||
706 | * But first pinch a few for the stack/trampoline stuff | ||
707 | * FIXME: Don't need the extra page at 4K, but need to fix | ||
708 | * trampoline before removing it. (see the GDT stuff) | ||
709 | */ | ||
710 | { PAGE_SIZE, PAGE_SIZE + PAGE_SIZE, "EX TRAMPOLINE" }, | ||
711 | /* | ||
712 | * Has to be in very low memory so we can execute | ||
713 | * real-mode AP code. | ||
714 | */ | ||
715 | { TRAMPOLINE_BASE, TRAMPOLINE_BASE + PAGE_SIZE, "TRAMPOLINE" }, | ||
716 | #endif | ||
717 | {} | 701 | {} |
718 | }; | 702 | }; |
719 | 703 | ||
diff --git a/arch/x86/kernel/early-quirks.c b/arch/x86/kernel/early-quirks.c index 1b894b72c0f5..744aa7fc49d5 100644 --- a/arch/x86/kernel/early-quirks.c +++ b/arch/x86/kernel/early-quirks.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <asm/io_apic.h> | 17 | #include <asm/io_apic.h> |
18 | #include <asm/apic.h> | 18 | #include <asm/apic.h> |
19 | #include <asm/iommu.h> | 19 | #include <asm/iommu.h> |
20 | #include <asm/gart.h> | ||
20 | 21 | ||
21 | static void __init fix_hypertransport_config(int num, int slot, int func) | 22 | static void __init fix_hypertransport_config(int num, int slot, int func) |
22 | { | 23 | { |
diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c index 34ad997d3834..504ad198e4ad 100644 --- a/arch/x86/kernel/early_printk.c +++ b/arch/x86/kernel/early_printk.c | |||
@@ -875,49 +875,6 @@ static struct console early_dbgp_console = { | |||
875 | }; | 875 | }; |
876 | #endif | 876 | #endif |
877 | 877 | ||
878 | /* Console interface to a host file on AMD's SimNow! */ | ||
879 | |||
880 | static int simnow_fd; | ||
881 | |||
882 | enum { | ||
883 | MAGIC1 = 0xBACCD00A, | ||
884 | MAGIC2 = 0xCA110000, | ||
885 | XOPEN = 5, | ||
886 | XWRITE = 4, | ||
887 | }; | ||
888 | |||
889 | static noinline long simnow(long cmd, long a, long b, long c) | ||
890 | { | ||
891 | long ret; | ||
892 | |||
893 | asm volatile("cpuid" : | ||
894 | "=a" (ret) : | ||
895 | "b" (a), "c" (b), "d" (c), "0" (MAGIC1), "D" (cmd + MAGIC2)); | ||
896 | return ret; | ||
897 | } | ||
898 | |||
899 | static void __init simnow_init(char *str) | ||
900 | { | ||
901 | char *fn = "klog"; | ||
902 | |||
903 | if (*str == '=') | ||
904 | fn = ++str; | ||
905 | /* error ignored */ | ||
906 | simnow_fd = simnow(XOPEN, (unsigned long)fn, O_WRONLY|O_APPEND|O_CREAT, 0644); | ||
907 | } | ||
908 | |||
909 | static void simnow_write(struct console *con, const char *s, unsigned n) | ||
910 | { | ||
911 | simnow(XWRITE, simnow_fd, (unsigned long)s, n); | ||
912 | } | ||
913 | |||
914 | static struct console simnow_console = { | ||
915 | .name = "simnow", | ||
916 | .write = simnow_write, | ||
917 | .flags = CON_PRINTBUFFER, | ||
918 | .index = -1, | ||
919 | }; | ||
920 | |||
921 | /* Direct interface for emergencies */ | 878 | /* Direct interface for emergencies */ |
922 | static struct console *early_console = &early_vga_console; | 879 | static struct console *early_console = &early_vga_console; |
923 | static int __initdata early_console_initialized; | 880 | static int __initdata early_console_initialized; |
@@ -929,7 +886,7 @@ asmlinkage void early_printk(const char *fmt, ...) | |||
929 | va_list ap; | 886 | va_list ap; |
930 | 887 | ||
931 | va_start(ap, fmt); | 888 | va_start(ap, fmt); |
932 | n = vscnprintf(buf, 512, fmt, ap); | 889 | n = vscnprintf(buf, sizeof(buf), fmt, ap); |
933 | early_console->write(early_console, buf, n); | 890 | early_console->write(early_console, buf, n); |
934 | va_end(ap); | 891 | va_end(ap); |
935 | } | 892 | } |
@@ -960,10 +917,6 @@ static int __init setup_early_printk(char *buf) | |||
960 | max_ypos = boot_params.screen_info.orig_video_lines; | 917 | max_ypos = boot_params.screen_info.orig_video_lines; |
961 | current_ypos = boot_params.screen_info.orig_y; | 918 | current_ypos = boot_params.screen_info.orig_y; |
962 | early_console = &early_vga_console; | 919 | early_console = &early_vga_console; |
963 | } else if (!strncmp(buf, "simnow", 6)) { | ||
964 | simnow_init(buf + 6); | ||
965 | early_console = &simnow_console; | ||
966 | keep_early = 1; | ||
967 | #ifdef CONFIG_EARLY_PRINTK_DBGP | 920 | #ifdef CONFIG_EARLY_PRINTK_DBGP |
968 | } else if (!strncmp(buf, "dbgp", 4)) { | 921 | } else if (!strncmp(buf, "dbgp", 4)) { |
969 | if (early_dbgp_init(buf+4) < 0) | 922 | if (early_dbgp_init(buf+4) < 0) |
diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S index 28b597ef9ca1..d6f0490a7391 100644 --- a/arch/x86/kernel/entry_32.S +++ b/arch/x86/kernel/entry_32.S | |||
@@ -619,28 +619,37 @@ END(syscall_badsys) | |||
619 | 27:; | 619 | 27:; |
620 | 620 | ||
621 | /* | 621 | /* |
622 | * Build the entry stubs and pointer table with | 622 | * Build the entry stubs and pointer table with some assembler magic. |
623 | * some assembler magic. | 623 | * We pack 7 stubs into a single 32-byte chunk, which will fit in a |
624 | * single cache line on all modern x86 implementations. | ||
624 | */ | 625 | */ |
625 | .section .rodata,"a" | 626 | .section .init.rodata,"a" |
626 | ENTRY(interrupt) | 627 | ENTRY(interrupt) |
627 | .text | 628 | .text |
628 | 629 | .p2align 5 | |
630 | .p2align CONFIG_X86_L1_CACHE_SHIFT | ||
629 | ENTRY(irq_entries_start) | 631 | ENTRY(irq_entries_start) |
630 | RING0_INT_FRAME | 632 | RING0_INT_FRAME |
631 | vector=0 | 633 | vector=FIRST_EXTERNAL_VECTOR |
632 | .rept NR_VECTORS | 634 | .rept (NR_VECTORS-FIRST_EXTERNAL_VECTOR+6)/7 |
633 | ALIGN | 635 | .balign 32 |
634 | .if vector | 636 | .rept 7 |
637 | .if vector < NR_VECTORS | ||
638 | .if vector <> FIRST_EXTERNAL_VECTOR | ||
635 | CFI_ADJUST_CFA_OFFSET -4 | 639 | CFI_ADJUST_CFA_OFFSET -4 |
636 | .endif | 640 | .endif |
637 | 1: pushl $~(vector) | 641 | 1: pushl $(~vector+0x80) /* Note: always in signed byte range */ |
638 | CFI_ADJUST_CFA_OFFSET 4 | 642 | CFI_ADJUST_CFA_OFFSET 4 |
639 | jmp common_interrupt | 643 | .if ((vector-FIRST_EXTERNAL_VECTOR)%7) <> 6 |
640 | .previous | 644 | jmp 2f |
645 | .endif | ||
646 | .previous | ||
641 | .long 1b | 647 | .long 1b |
642 | .text | 648 | .text |
643 | vector=vector+1 | 649 | vector=vector+1 |
650 | .endif | ||
651 | .endr | ||
652 | 2: jmp common_interrupt | ||
644 | .endr | 653 | .endr |
645 | END(irq_entries_start) | 654 | END(irq_entries_start) |
646 | 655 | ||
@@ -652,8 +661,9 @@ END(interrupt) | |||
652 | * the CPU automatically disables interrupts when executing an IRQ vector, | 661 | * the CPU automatically disables interrupts when executing an IRQ vector, |
653 | * so IRQ-flags tracing has to follow that: | 662 | * so IRQ-flags tracing has to follow that: |
654 | */ | 663 | */ |
655 | ALIGN | 664 | .p2align CONFIG_X86_L1_CACHE_SHIFT |
656 | common_interrupt: | 665 | common_interrupt: |
666 | addl $-0x80,(%esp) /* Adjust vector into the [-256,-1] range */ | ||
657 | SAVE_ALL | 667 | SAVE_ALL |
658 | TRACE_IRQS_OFF | 668 | TRACE_IRQS_OFF |
659 | movl %esp,%eax | 669 | movl %esp,%eax |
@@ -678,65 +688,6 @@ ENDPROC(name) | |||
678 | /* The include is where all of the SMP etc. interrupts come from */ | 688 | /* The include is where all of the SMP etc. interrupts come from */ |
679 | #include "entry_arch.h" | 689 | #include "entry_arch.h" |
680 | 690 | ||
681 | KPROBE_ENTRY(page_fault) | ||
682 | RING0_EC_FRAME | ||
683 | pushl $do_page_fault | ||
684 | CFI_ADJUST_CFA_OFFSET 4 | ||
685 | ALIGN | ||
686 | error_code: | ||
687 | /* the function address is in %fs's slot on the stack */ | ||
688 | pushl %es | ||
689 | CFI_ADJUST_CFA_OFFSET 4 | ||
690 | /*CFI_REL_OFFSET es, 0*/ | ||
691 | pushl %ds | ||
692 | CFI_ADJUST_CFA_OFFSET 4 | ||
693 | /*CFI_REL_OFFSET ds, 0*/ | ||
694 | pushl %eax | ||
695 | CFI_ADJUST_CFA_OFFSET 4 | ||
696 | CFI_REL_OFFSET eax, 0 | ||
697 | pushl %ebp | ||
698 | CFI_ADJUST_CFA_OFFSET 4 | ||
699 | CFI_REL_OFFSET ebp, 0 | ||
700 | pushl %edi | ||
701 | CFI_ADJUST_CFA_OFFSET 4 | ||
702 | CFI_REL_OFFSET edi, 0 | ||
703 | pushl %esi | ||
704 | CFI_ADJUST_CFA_OFFSET 4 | ||
705 | CFI_REL_OFFSET esi, 0 | ||
706 | pushl %edx | ||
707 | CFI_ADJUST_CFA_OFFSET 4 | ||
708 | CFI_REL_OFFSET edx, 0 | ||
709 | pushl %ecx | ||
710 | CFI_ADJUST_CFA_OFFSET 4 | ||
711 | CFI_REL_OFFSET ecx, 0 | ||
712 | pushl %ebx | ||
713 | CFI_ADJUST_CFA_OFFSET 4 | ||
714 | CFI_REL_OFFSET ebx, 0 | ||
715 | cld | ||
716 | pushl %fs | ||
717 | CFI_ADJUST_CFA_OFFSET 4 | ||
718 | /*CFI_REL_OFFSET fs, 0*/ | ||
719 | movl $(__KERNEL_PERCPU), %ecx | ||
720 | movl %ecx, %fs | ||
721 | UNWIND_ESPFIX_STACK | ||
722 | popl %ecx | ||
723 | CFI_ADJUST_CFA_OFFSET -4 | ||
724 | /*CFI_REGISTER es, ecx*/ | ||
725 | movl PT_FS(%esp), %edi # get the function address | ||
726 | movl PT_ORIG_EAX(%esp), %edx # get the error code | ||
727 | movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart | ||
728 | mov %ecx, PT_FS(%esp) | ||
729 | /*CFI_REL_OFFSET fs, ES*/ | ||
730 | movl $(__USER_DS), %ecx | ||
731 | movl %ecx, %ds | ||
732 | movl %ecx, %es | ||
733 | TRACE_IRQS_OFF | ||
734 | movl %esp,%eax # pt_regs pointer | ||
735 | call *%edi | ||
736 | jmp ret_from_exception | ||
737 | CFI_ENDPROC | ||
738 | KPROBE_END(page_fault) | ||
739 | |||
740 | ENTRY(coprocessor_error) | 691 | ENTRY(coprocessor_error) |
741 | RING0_INT_FRAME | 692 | RING0_INT_FRAME |
742 | pushl $0 | 693 | pushl $0 |
@@ -767,140 +718,6 @@ ENTRY(device_not_available) | |||
767 | CFI_ENDPROC | 718 | CFI_ENDPROC |
768 | END(device_not_available) | 719 | END(device_not_available) |
769 | 720 | ||
770 | /* | ||
771 | * Debug traps and NMI can happen at the one SYSENTER instruction | ||
772 | * that sets up the real kernel stack. Check here, since we can't | ||
773 | * allow the wrong stack to be used. | ||
774 | * | ||
775 | * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have | ||
776 | * already pushed 3 words if it hits on the sysenter instruction: | ||
777 | * eflags, cs and eip. | ||
778 | * | ||
779 | * We just load the right stack, and push the three (known) values | ||
780 | * by hand onto the new stack - while updating the return eip past | ||
781 | * the instruction that would have done it for sysenter. | ||
782 | */ | ||
783 | #define FIX_STACK(offset, ok, label) \ | ||
784 | cmpw $__KERNEL_CS,4(%esp); \ | ||
785 | jne ok; \ | ||
786 | label: \ | ||
787 | movl TSS_sysenter_sp0+offset(%esp),%esp; \ | ||
788 | CFI_DEF_CFA esp, 0; \ | ||
789 | CFI_UNDEFINED eip; \ | ||
790 | pushfl; \ | ||
791 | CFI_ADJUST_CFA_OFFSET 4; \ | ||
792 | pushl $__KERNEL_CS; \ | ||
793 | CFI_ADJUST_CFA_OFFSET 4; \ | ||
794 | pushl $sysenter_past_esp; \ | ||
795 | CFI_ADJUST_CFA_OFFSET 4; \ | ||
796 | CFI_REL_OFFSET eip, 0 | ||
797 | |||
798 | KPROBE_ENTRY(debug) | ||
799 | RING0_INT_FRAME | ||
800 | cmpl $ia32_sysenter_target,(%esp) | ||
801 | jne debug_stack_correct | ||
802 | FIX_STACK(12, debug_stack_correct, debug_esp_fix_insn) | ||
803 | debug_stack_correct: | ||
804 | pushl $-1 # mark this as an int | ||
805 | CFI_ADJUST_CFA_OFFSET 4 | ||
806 | SAVE_ALL | ||
807 | TRACE_IRQS_OFF | ||
808 | xorl %edx,%edx # error code 0 | ||
809 | movl %esp,%eax # pt_regs pointer | ||
810 | call do_debug | ||
811 | jmp ret_from_exception | ||
812 | CFI_ENDPROC | ||
813 | KPROBE_END(debug) | ||
814 | |||
815 | /* | ||
816 | * NMI is doubly nasty. It can happen _while_ we're handling | ||
817 | * a debug fault, and the debug fault hasn't yet been able to | ||
818 | * clear up the stack. So we first check whether we got an | ||
819 | * NMI on the sysenter entry path, but after that we need to | ||
820 | * check whether we got an NMI on the debug path where the debug | ||
821 | * fault happened on the sysenter path. | ||
822 | */ | ||
823 | KPROBE_ENTRY(nmi) | ||
824 | RING0_INT_FRAME | ||
825 | pushl %eax | ||
826 | CFI_ADJUST_CFA_OFFSET 4 | ||
827 | movl %ss, %eax | ||
828 | cmpw $__ESPFIX_SS, %ax | ||
829 | popl %eax | ||
830 | CFI_ADJUST_CFA_OFFSET -4 | ||
831 | je nmi_espfix_stack | ||
832 | cmpl $ia32_sysenter_target,(%esp) | ||
833 | je nmi_stack_fixup | ||
834 | pushl %eax | ||
835 | CFI_ADJUST_CFA_OFFSET 4 | ||
836 | movl %esp,%eax | ||
837 | /* Do not access memory above the end of our stack page, | ||
838 | * it might not exist. | ||
839 | */ | ||
840 | andl $(THREAD_SIZE-1),%eax | ||
841 | cmpl $(THREAD_SIZE-20),%eax | ||
842 | popl %eax | ||
843 | CFI_ADJUST_CFA_OFFSET -4 | ||
844 | jae nmi_stack_correct | ||
845 | cmpl $ia32_sysenter_target,12(%esp) | ||
846 | je nmi_debug_stack_check | ||
847 | nmi_stack_correct: | ||
848 | /* We have a RING0_INT_FRAME here */ | ||
849 | pushl %eax | ||
850 | CFI_ADJUST_CFA_OFFSET 4 | ||
851 | SAVE_ALL | ||
852 | TRACE_IRQS_OFF | ||
853 | xorl %edx,%edx # zero error code | ||
854 | movl %esp,%eax # pt_regs pointer | ||
855 | call do_nmi | ||
856 | jmp restore_nocheck_notrace | ||
857 | CFI_ENDPROC | ||
858 | |||
859 | nmi_stack_fixup: | ||
860 | RING0_INT_FRAME | ||
861 | FIX_STACK(12,nmi_stack_correct, 1) | ||
862 | jmp nmi_stack_correct | ||
863 | |||
864 | nmi_debug_stack_check: | ||
865 | /* We have a RING0_INT_FRAME here */ | ||
866 | cmpw $__KERNEL_CS,16(%esp) | ||
867 | jne nmi_stack_correct | ||
868 | cmpl $debug,(%esp) | ||
869 | jb nmi_stack_correct | ||
870 | cmpl $debug_esp_fix_insn,(%esp) | ||
871 | ja nmi_stack_correct | ||
872 | FIX_STACK(24,nmi_stack_correct, 1) | ||
873 | jmp nmi_stack_correct | ||
874 | |||
875 | nmi_espfix_stack: | ||
876 | /* We have a RING0_INT_FRAME here. | ||
877 | * | ||
878 | * create the pointer to lss back | ||
879 | */ | ||
880 | pushl %ss | ||
881 | CFI_ADJUST_CFA_OFFSET 4 | ||
882 | pushl %esp | ||
883 | CFI_ADJUST_CFA_OFFSET 4 | ||
884 | addw $4, (%esp) | ||
885 | /* copy the iret frame of 12 bytes */ | ||
886 | .rept 3 | ||
887 | pushl 16(%esp) | ||
888 | CFI_ADJUST_CFA_OFFSET 4 | ||
889 | .endr | ||
890 | pushl %eax | ||
891 | CFI_ADJUST_CFA_OFFSET 4 | ||
892 | SAVE_ALL | ||
893 | TRACE_IRQS_OFF | ||
894 | FIXUP_ESPFIX_STACK # %eax == %esp | ||
895 | xorl %edx,%edx # zero error code | ||
896 | call do_nmi | ||
897 | RESTORE_REGS | ||
898 | lss 12+4(%esp), %esp # back to espfix stack | ||
899 | CFI_ADJUST_CFA_OFFSET -24 | ||
900 | jmp irq_return | ||
901 | CFI_ENDPROC | ||
902 | KPROBE_END(nmi) | ||
903 | |||
904 | #ifdef CONFIG_PARAVIRT | 721 | #ifdef CONFIG_PARAVIRT |
905 | ENTRY(native_iret) | 722 | ENTRY(native_iret) |
906 | iret | 723 | iret |
@@ -916,19 +733,6 @@ ENTRY(native_irq_enable_sysexit) | |||
916 | END(native_irq_enable_sysexit) | 733 | END(native_irq_enable_sysexit) |
917 | #endif | 734 | #endif |
918 | 735 | ||
919 | KPROBE_ENTRY(int3) | ||
920 | RING0_INT_FRAME | ||
921 | pushl $-1 # mark this as an int | ||
922 | CFI_ADJUST_CFA_OFFSET 4 | ||
923 | SAVE_ALL | ||
924 | TRACE_IRQS_OFF | ||
925 | xorl %edx,%edx # zero error code | ||
926 | movl %esp,%eax # pt_regs pointer | ||
927 | call do_int3 | ||
928 | jmp ret_from_exception | ||
929 | CFI_ENDPROC | ||
930 | KPROBE_END(int3) | ||
931 | |||
932 | ENTRY(overflow) | 736 | ENTRY(overflow) |
933 | RING0_INT_FRAME | 737 | RING0_INT_FRAME |
934 | pushl $0 | 738 | pushl $0 |
@@ -993,14 +797,6 @@ ENTRY(stack_segment) | |||
993 | CFI_ENDPROC | 797 | CFI_ENDPROC |
994 | END(stack_segment) | 798 | END(stack_segment) |
995 | 799 | ||
996 | KPROBE_ENTRY(general_protection) | ||
997 | RING0_EC_FRAME | ||
998 | pushl $do_general_protection | ||
999 | CFI_ADJUST_CFA_OFFSET 4 | ||
1000 | jmp error_code | ||
1001 | CFI_ENDPROC | ||
1002 | KPROBE_END(general_protection) | ||
1003 | |||
1004 | ENTRY(alignment_check) | 800 | ENTRY(alignment_check) |
1005 | RING0_EC_FRAME | 801 | RING0_EC_FRAME |
1006 | pushl $do_alignment_check | 802 | pushl $do_alignment_check |
@@ -1051,6 +847,7 @@ ENTRY(kernel_thread_helper) | |||
1051 | push %eax | 847 | push %eax |
1052 | CFI_ADJUST_CFA_OFFSET 4 | 848 | CFI_ADJUST_CFA_OFFSET 4 |
1053 | call do_exit | 849 | call do_exit |
850 | ud2 # padding for call trace | ||
1054 | CFI_ENDPROC | 851 | CFI_ENDPROC |
1055 | ENDPROC(kernel_thread_helper) | 852 | ENDPROC(kernel_thread_helper) |
1056 | 853 | ||
@@ -1157,6 +954,9 @@ ENTRY(mcount) | |||
1157 | END(mcount) | 954 | END(mcount) |
1158 | 955 | ||
1159 | ENTRY(ftrace_caller) | 956 | ENTRY(ftrace_caller) |
957 | cmpl $0, function_trace_stop | ||
958 | jne ftrace_stub | ||
959 | |||
1160 | pushl %eax | 960 | pushl %eax |
1161 | pushl %ecx | 961 | pushl %ecx |
1162 | pushl %edx | 962 | pushl %edx |
@@ -1171,6 +971,11 @@ ftrace_call: | |||
1171 | popl %edx | 971 | popl %edx |
1172 | popl %ecx | 972 | popl %ecx |
1173 | popl %eax | 973 | popl %eax |
974 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | ||
975 | .globl ftrace_graph_call | ||
976 | ftrace_graph_call: | ||
977 | jmp ftrace_stub | ||
978 | #endif | ||
1174 | 979 | ||
1175 | .globl ftrace_stub | 980 | .globl ftrace_stub |
1176 | ftrace_stub: | 981 | ftrace_stub: |
@@ -1180,8 +985,18 @@ END(ftrace_caller) | |||
1180 | #else /* ! CONFIG_DYNAMIC_FTRACE */ | 985 | #else /* ! CONFIG_DYNAMIC_FTRACE */ |
1181 | 986 | ||
1182 | ENTRY(mcount) | 987 | ENTRY(mcount) |
988 | cmpl $0, function_trace_stop | ||
989 | jne ftrace_stub | ||
990 | |||
1183 | cmpl $ftrace_stub, ftrace_trace_function | 991 | cmpl $ftrace_stub, ftrace_trace_function |
1184 | jnz trace | 992 | jnz trace |
993 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | ||
994 | cmpl $ftrace_stub, ftrace_graph_return | ||
995 | jnz ftrace_graph_caller | ||
996 | |||
997 | cmpl $ftrace_graph_entry_stub, ftrace_graph_entry | ||
998 | jnz ftrace_graph_caller | ||
999 | #endif | ||
1185 | .globl ftrace_stub | 1000 | .globl ftrace_stub |
1186 | ftrace_stub: | 1001 | ftrace_stub: |
1187 | ret | 1002 | ret |
@@ -1200,13 +1015,268 @@ trace: | |||
1200 | popl %edx | 1015 | popl %edx |
1201 | popl %ecx | 1016 | popl %ecx |
1202 | popl %eax | 1017 | popl %eax |
1203 | |||
1204 | jmp ftrace_stub | 1018 | jmp ftrace_stub |
1205 | END(mcount) | 1019 | END(mcount) |
1206 | #endif /* CONFIG_DYNAMIC_FTRACE */ | 1020 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
1207 | #endif /* CONFIG_FUNCTION_TRACER */ | 1021 | #endif /* CONFIG_FUNCTION_TRACER */ |
1208 | 1022 | ||
1023 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | ||
1024 | ENTRY(ftrace_graph_caller) | ||
1025 | cmpl $0, function_trace_stop | ||
1026 | jne ftrace_stub | ||
1027 | |||
1028 | pushl %eax | ||
1029 | pushl %ecx | ||
1030 | pushl %edx | ||
1031 | movl 0xc(%esp), %edx | ||
1032 | lea 0x4(%ebp), %eax | ||
1033 | subl $MCOUNT_INSN_SIZE, %edx | ||
1034 | call prepare_ftrace_return | ||
1035 | popl %edx | ||
1036 | popl %ecx | ||
1037 | popl %eax | ||
1038 | ret | ||
1039 | END(ftrace_graph_caller) | ||
1040 | |||
1041 | .globl return_to_handler | ||
1042 | return_to_handler: | ||
1043 | pushl $0 | ||
1044 | pushl %eax | ||
1045 | pushl %ecx | ||
1046 | pushl %edx | ||
1047 | call ftrace_return_to_handler | ||
1048 | movl %eax, 0xc(%esp) | ||
1049 | popl %edx | ||
1050 | popl %ecx | ||
1051 | popl %eax | ||
1052 | ret | ||
1053 | #endif | ||
1054 | |||
1209 | .section .rodata,"a" | 1055 | .section .rodata,"a" |
1210 | #include "syscall_table_32.S" | 1056 | #include "syscall_table_32.S" |
1211 | 1057 | ||
1212 | syscall_table_size=(.-sys_call_table) | 1058 | syscall_table_size=(.-sys_call_table) |
1059 | |||
1060 | /* | ||
1061 | * Some functions should be protected against kprobes | ||
1062 | */ | ||
1063 | .pushsection .kprobes.text, "ax" | ||
1064 | |||
1065 | ENTRY(page_fault) | ||
1066 | RING0_EC_FRAME | ||
1067 | pushl $do_page_fault | ||
1068 | CFI_ADJUST_CFA_OFFSET 4 | ||
1069 | ALIGN | ||
1070 | error_code: | ||
1071 | /* the function address is in %fs's slot on the stack */ | ||
1072 | pushl %es | ||
1073 | CFI_ADJUST_CFA_OFFSET 4 | ||
1074 | /*CFI_REL_OFFSET es, 0*/ | ||
1075 | pushl %ds | ||
1076 | CFI_ADJUST_CFA_OFFSET 4 | ||
1077 | /*CFI_REL_OFFSET ds, 0*/ | ||
1078 | pushl %eax | ||
1079 | CFI_ADJUST_CFA_OFFSET 4 | ||
1080 | CFI_REL_OFFSET eax, 0 | ||
1081 | pushl %ebp | ||
1082 | CFI_ADJUST_CFA_OFFSET 4 | ||
1083 | CFI_REL_OFFSET ebp, 0 | ||
1084 | pushl %edi | ||
1085 | CFI_ADJUST_CFA_OFFSET 4 | ||
1086 | CFI_REL_OFFSET edi, 0 | ||
1087 | pushl %esi | ||
1088 | CFI_ADJUST_CFA_OFFSET 4 | ||
1089 | CFI_REL_OFFSET esi, 0 | ||
1090 | pushl %edx | ||
1091 | CFI_ADJUST_CFA_OFFSET 4 | ||
1092 | CFI_REL_OFFSET edx, 0 | ||
1093 | pushl %ecx | ||
1094 | CFI_ADJUST_CFA_OFFSET 4 | ||
1095 | CFI_REL_OFFSET ecx, 0 | ||
1096 | pushl %ebx | ||
1097 | CFI_ADJUST_CFA_OFFSET 4 | ||
1098 | CFI_REL_OFFSET ebx, 0 | ||
1099 | cld | ||
1100 | pushl %fs | ||
1101 | CFI_ADJUST_CFA_OFFSET 4 | ||
1102 | /*CFI_REL_OFFSET fs, 0*/ | ||
1103 | movl $(__KERNEL_PERCPU), %ecx | ||
1104 | movl %ecx, %fs | ||
1105 | UNWIND_ESPFIX_STACK | ||
1106 | popl %ecx | ||
1107 | CFI_ADJUST_CFA_OFFSET -4 | ||
1108 | /*CFI_REGISTER es, ecx*/ | ||
1109 | movl PT_FS(%esp), %edi # get the function address | ||
1110 | movl PT_ORIG_EAX(%esp), %edx # get the error code | ||
1111 | movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart | ||
1112 | mov %ecx, PT_FS(%esp) | ||
1113 | /*CFI_REL_OFFSET fs, ES*/ | ||
1114 | movl $(__USER_DS), %ecx | ||
1115 | movl %ecx, %ds | ||
1116 | movl %ecx, %es | ||
1117 | TRACE_IRQS_OFF | ||
1118 | movl %esp,%eax # pt_regs pointer | ||
1119 | call *%edi | ||
1120 | jmp ret_from_exception | ||
1121 | CFI_ENDPROC | ||
1122 | END(page_fault) | ||
1123 | |||
1124 | /* | ||
1125 | * Debug traps and NMI can happen at the one SYSENTER instruction | ||
1126 | * that sets up the real kernel stack. Check here, since we can't | ||
1127 | * allow the wrong stack to be used. | ||
1128 | * | ||
1129 | * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have | ||
1130 | * already pushed 3 words if it hits on the sysenter instruction: | ||
1131 | * eflags, cs and eip. | ||
1132 | * | ||
1133 | * We just load the right stack, and push the three (known) values | ||
1134 | * by hand onto the new stack - while updating the return eip past | ||
1135 | * the instruction that would have done it for sysenter. | ||
1136 | */ | ||
1137 | #define FIX_STACK(offset, ok, label) \ | ||
1138 | cmpw $__KERNEL_CS,4(%esp); \ | ||
1139 | jne ok; \ | ||
1140 | label: \ | ||
1141 | movl TSS_sysenter_sp0+offset(%esp),%esp; \ | ||
1142 | CFI_DEF_CFA esp, 0; \ | ||
1143 | CFI_UNDEFINED eip; \ | ||
1144 | pushfl; \ | ||
1145 | CFI_ADJUST_CFA_OFFSET 4; \ | ||
1146 | pushl $__KERNEL_CS; \ | ||
1147 | CFI_ADJUST_CFA_OFFSET 4; \ | ||
1148 | pushl $sysenter_past_esp; \ | ||
1149 | CFI_ADJUST_CFA_OFFSET 4; \ | ||
1150 | CFI_REL_OFFSET eip, 0 | ||
1151 | |||
1152 | ENTRY(debug) | ||
1153 | RING0_INT_FRAME | ||
1154 | cmpl $ia32_sysenter_target,(%esp) | ||
1155 | jne debug_stack_correct | ||
1156 | FIX_STACK(12, debug_stack_correct, debug_esp_fix_insn) | ||
1157 | debug_stack_correct: | ||
1158 | pushl $-1 # mark this as an int | ||
1159 | CFI_ADJUST_CFA_OFFSET 4 | ||
1160 | SAVE_ALL | ||
1161 | TRACE_IRQS_OFF | ||
1162 | xorl %edx,%edx # error code 0 | ||
1163 | movl %esp,%eax # pt_regs pointer | ||
1164 | call do_debug | ||
1165 | jmp ret_from_exception | ||
1166 | CFI_ENDPROC | ||
1167 | END(debug) | ||
1168 | |||
1169 | /* | ||
1170 | * NMI is doubly nasty. It can happen _while_ we're handling | ||
1171 | * a debug fault, and the debug fault hasn't yet been able to | ||
1172 | * clear up the stack. So we first check whether we got an | ||
1173 | * NMI on the sysenter entry path, but after that we need to | ||
1174 | * check whether we got an NMI on the debug path where the debug | ||
1175 | * fault happened on the sysenter path. | ||
1176 | */ | ||
1177 | ENTRY(nmi) | ||
1178 | RING0_INT_FRAME | ||
1179 | pushl %eax | ||
1180 | CFI_ADJUST_CFA_OFFSET 4 | ||
1181 | movl %ss, %eax | ||
1182 | cmpw $__ESPFIX_SS, %ax | ||
1183 | popl %eax | ||
1184 | CFI_ADJUST_CFA_OFFSET -4 | ||
1185 | je nmi_espfix_stack | ||
1186 | cmpl $ia32_sysenter_target,(%esp) | ||
1187 | je nmi_stack_fixup | ||
1188 | pushl %eax | ||
1189 | CFI_ADJUST_CFA_OFFSET 4 | ||
1190 | movl %esp,%eax | ||
1191 | /* Do not access memory above the end of our stack page, | ||
1192 | * it might not exist. | ||
1193 | */ | ||
1194 | andl $(THREAD_SIZE-1),%eax | ||
1195 | cmpl $(THREAD_SIZE-20),%eax | ||
1196 | popl %eax | ||
1197 | CFI_ADJUST_CFA_OFFSET -4 | ||
1198 | jae nmi_stack_correct | ||
1199 | cmpl $ia32_sysenter_target,12(%esp) | ||
1200 | je nmi_debug_stack_check | ||
1201 | nmi_stack_correct: | ||
1202 | /* We have a RING0_INT_FRAME here */ | ||
1203 | pushl %eax | ||
1204 | CFI_ADJUST_CFA_OFFSET 4 | ||
1205 | SAVE_ALL | ||
1206 | TRACE_IRQS_OFF | ||
1207 | xorl %edx,%edx # zero error code | ||
1208 | movl %esp,%eax # pt_regs pointer | ||
1209 | call do_nmi | ||
1210 | jmp restore_nocheck_notrace | ||
1211 | CFI_ENDPROC | ||
1212 | |||
1213 | nmi_stack_fixup: | ||
1214 | RING0_INT_FRAME | ||
1215 | FIX_STACK(12,nmi_stack_correct, 1) | ||
1216 | jmp nmi_stack_correct | ||
1217 | |||
1218 | nmi_debug_stack_check: | ||
1219 | /* We have a RING0_INT_FRAME here */ | ||
1220 | cmpw $__KERNEL_CS,16(%esp) | ||
1221 | jne nmi_stack_correct | ||
1222 | cmpl $debug,(%esp) | ||
1223 | jb nmi_stack_correct | ||
1224 | cmpl $debug_esp_fix_insn,(%esp) | ||
1225 | ja nmi_stack_correct | ||
1226 | FIX_STACK(24,nmi_stack_correct, 1) | ||
1227 | jmp nmi_stack_correct | ||
1228 | |||
1229 | nmi_espfix_stack: | ||
1230 | /* We have a RING0_INT_FRAME here. | ||
1231 | * | ||
1232 | * create the pointer to lss back | ||
1233 | */ | ||
1234 | pushl %ss | ||
1235 | CFI_ADJUST_CFA_OFFSET 4 | ||
1236 | pushl %esp | ||
1237 | CFI_ADJUST_CFA_OFFSET 4 | ||
1238 | addw $4, (%esp) | ||
1239 | /* copy the iret frame of 12 bytes */ | ||
1240 | .rept 3 | ||
1241 | pushl 16(%esp) | ||
1242 | CFI_ADJUST_CFA_OFFSET 4 | ||
1243 | .endr | ||
1244 | pushl %eax | ||
1245 | CFI_ADJUST_CFA_OFFSET 4 | ||
1246 | SAVE_ALL | ||
1247 | TRACE_IRQS_OFF | ||
1248 | FIXUP_ESPFIX_STACK # %eax == %esp | ||
1249 | xorl %edx,%edx # zero error code | ||
1250 | call do_nmi | ||
1251 | RESTORE_REGS | ||
1252 | lss 12+4(%esp), %esp # back to espfix stack | ||
1253 | CFI_ADJUST_CFA_OFFSET -24 | ||
1254 | jmp irq_return | ||
1255 | CFI_ENDPROC | ||
1256 | END(nmi) | ||
1257 | |||
1258 | ENTRY(int3) | ||
1259 | RING0_INT_FRAME | ||
1260 | pushl $-1 # mark this as an int | ||
1261 | CFI_ADJUST_CFA_OFFSET 4 | ||
1262 | SAVE_ALL | ||
1263 | TRACE_IRQS_OFF | ||
1264 | xorl %edx,%edx # zero error code | ||
1265 | movl %esp,%eax # pt_regs pointer | ||
1266 | call do_int3 | ||
1267 | jmp ret_from_exception | ||
1268 | CFI_ENDPROC | ||
1269 | END(int3) | ||
1270 | |||
1271 | ENTRY(general_protection) | ||
1272 | RING0_EC_FRAME | ||
1273 | pushl $do_general_protection | ||
1274 | CFI_ADJUST_CFA_OFFSET 4 | ||
1275 | jmp error_code | ||
1276 | CFI_ENDPROC | ||
1277 | END(general_protection) | ||
1278 | |||
1279 | /* | ||
1280 | * End of kprobes section | ||
1281 | */ | ||
1282 | .popsection | ||
diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S index b86f332c96a6..e28c7a987793 100644 --- a/arch/x86/kernel/entry_64.S +++ b/arch/x86/kernel/entry_64.S | |||
@@ -11,15 +11,15 @@ | |||
11 | * | 11 | * |
12 | * NOTE: This code handles signal-recognition, which happens every time | 12 | * NOTE: This code handles signal-recognition, which happens every time |
13 | * after an interrupt and after each system call. | 13 | * after an interrupt and after each system call. |
14 | * | 14 | * |
15 | * Normal syscalls and interrupts don't save a full stack frame, this is | 15 | * Normal syscalls and interrupts don't save a full stack frame, this is |
16 | * only done for syscall tracing, signals or fork/exec et.al. | 16 | * only done for syscall tracing, signals or fork/exec et.al. |
17 | * | 17 | * |
18 | * A note on terminology: | 18 | * A note on terminology: |
19 | * - top of stack: Architecture defined interrupt frame from SS to RIP | 19 | * - top of stack: Architecture defined interrupt frame from SS to RIP |
20 | * at the top of the kernel process stack. | 20 | * at the top of the kernel process stack. |
21 | * - partial stack frame: partially saved registers upto R11. | 21 | * - partial stack frame: partially saved registers upto R11. |
22 | * - full stack frame: Like partial stack frame, but all register saved. | 22 | * - full stack frame: Like partial stack frame, but all register saved. |
23 | * | 23 | * |
24 | * Some macro usage: | 24 | * Some macro usage: |
25 | * - CFI macros are used to generate dwarf2 unwind information for better | 25 | * - CFI macros are used to generate dwarf2 unwind information for better |
@@ -60,7 +60,6 @@ | |||
60 | #define __AUDIT_ARCH_LE 0x40000000 | 60 | #define __AUDIT_ARCH_LE 0x40000000 |
61 | 61 | ||
62 | .code64 | 62 | .code64 |
63 | |||
64 | #ifdef CONFIG_FUNCTION_TRACER | 63 | #ifdef CONFIG_FUNCTION_TRACER |
65 | #ifdef CONFIG_DYNAMIC_FTRACE | 64 | #ifdef CONFIG_DYNAMIC_FTRACE |
66 | ENTRY(mcount) | 65 | ENTRY(mcount) |
@@ -68,16 +67,10 @@ ENTRY(mcount) | |||
68 | END(mcount) | 67 | END(mcount) |
69 | 68 | ||
70 | ENTRY(ftrace_caller) | 69 | ENTRY(ftrace_caller) |
70 | cmpl $0, function_trace_stop | ||
71 | jne ftrace_stub | ||
71 | 72 | ||
72 | /* taken from glibc */ | 73 | MCOUNT_SAVE_FRAME |
73 | subq $0x38, %rsp | ||
74 | movq %rax, (%rsp) | ||
75 | movq %rcx, 8(%rsp) | ||
76 | movq %rdx, 16(%rsp) | ||
77 | movq %rsi, 24(%rsp) | ||
78 | movq %rdi, 32(%rsp) | ||
79 | movq %r8, 40(%rsp) | ||
80 | movq %r9, 48(%rsp) | ||
81 | 74 | ||
82 | movq 0x38(%rsp), %rdi | 75 | movq 0x38(%rsp), %rdi |
83 | movq 8(%rbp), %rsi | 76 | movq 8(%rbp), %rsi |
@@ -87,14 +80,13 @@ ENTRY(ftrace_caller) | |||
87 | ftrace_call: | 80 | ftrace_call: |
88 | call ftrace_stub | 81 | call ftrace_stub |
89 | 82 | ||
90 | movq 48(%rsp), %r9 | 83 | MCOUNT_RESTORE_FRAME |
91 | movq 40(%rsp), %r8 | 84 | |
92 | movq 32(%rsp), %rdi | 85 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
93 | movq 24(%rsp), %rsi | 86 | .globl ftrace_graph_call |
94 | movq 16(%rsp), %rdx | 87 | ftrace_graph_call: |
95 | movq 8(%rsp), %rcx | 88 | jmp ftrace_stub |
96 | movq (%rsp), %rax | 89 | #endif |
97 | addq $0x38, %rsp | ||
98 | 90 | ||
99 | .globl ftrace_stub | 91 | .globl ftrace_stub |
100 | ftrace_stub: | 92 | ftrace_stub: |
@@ -103,15 +95,63 @@ END(ftrace_caller) | |||
103 | 95 | ||
104 | #else /* ! CONFIG_DYNAMIC_FTRACE */ | 96 | #else /* ! CONFIG_DYNAMIC_FTRACE */ |
105 | ENTRY(mcount) | 97 | ENTRY(mcount) |
98 | cmpl $0, function_trace_stop | ||
99 | jne ftrace_stub | ||
100 | |||
106 | cmpq $ftrace_stub, ftrace_trace_function | 101 | cmpq $ftrace_stub, ftrace_trace_function |
107 | jnz trace | 102 | jnz trace |
103 | |||
104 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | ||
105 | cmpq $ftrace_stub, ftrace_graph_return | ||
106 | jnz ftrace_graph_caller | ||
107 | |||
108 | cmpq $ftrace_graph_entry_stub, ftrace_graph_entry | ||
109 | jnz ftrace_graph_caller | ||
110 | #endif | ||
111 | |||
108 | .globl ftrace_stub | 112 | .globl ftrace_stub |
109 | ftrace_stub: | 113 | ftrace_stub: |
110 | retq | 114 | retq |
111 | 115 | ||
112 | trace: | 116 | trace: |
113 | /* taken from glibc */ | 117 | MCOUNT_SAVE_FRAME |
114 | subq $0x38, %rsp | 118 | |
119 | movq 0x38(%rsp), %rdi | ||
120 | movq 8(%rbp), %rsi | ||
121 | subq $MCOUNT_INSN_SIZE, %rdi | ||
122 | |||
123 | call *ftrace_trace_function | ||
124 | |||
125 | MCOUNT_RESTORE_FRAME | ||
126 | |||
127 | jmp ftrace_stub | ||
128 | END(mcount) | ||
129 | #endif /* CONFIG_DYNAMIC_FTRACE */ | ||
130 | #endif /* CONFIG_FUNCTION_TRACER */ | ||
131 | |||
132 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | ||
133 | ENTRY(ftrace_graph_caller) | ||
134 | cmpl $0, function_trace_stop | ||
135 | jne ftrace_stub | ||
136 | |||
137 | MCOUNT_SAVE_FRAME | ||
138 | |||
139 | leaq 8(%rbp), %rdi | ||
140 | movq 0x38(%rsp), %rsi | ||
141 | subq $MCOUNT_INSN_SIZE, %rsi | ||
142 | |||
143 | call prepare_ftrace_return | ||
144 | |||
145 | MCOUNT_RESTORE_FRAME | ||
146 | |||
147 | retq | ||
148 | END(ftrace_graph_caller) | ||
149 | |||
150 | |||
151 | .globl return_to_handler | ||
152 | return_to_handler: | ||
153 | subq $80, %rsp | ||
154 | |||
115 | movq %rax, (%rsp) | 155 | movq %rax, (%rsp) |
116 | movq %rcx, 8(%rsp) | 156 | movq %rcx, 8(%rsp) |
117 | movq %rdx, 16(%rsp) | 157 | movq %rdx, 16(%rsp) |
@@ -119,13 +159,14 @@ trace: | |||
119 | movq %rdi, 32(%rsp) | 159 | movq %rdi, 32(%rsp) |
120 | movq %r8, 40(%rsp) | 160 | movq %r8, 40(%rsp) |
121 | movq %r9, 48(%rsp) | 161 | movq %r9, 48(%rsp) |
162 | movq %r10, 56(%rsp) | ||
163 | movq %r11, 64(%rsp) | ||
122 | 164 | ||
123 | movq 0x38(%rsp), %rdi | 165 | call ftrace_return_to_handler |
124 | movq 8(%rbp), %rsi | ||
125 | subq $MCOUNT_INSN_SIZE, %rdi | ||
126 | |||
127 | call *ftrace_trace_function | ||
128 | 166 | ||
167 | movq %rax, 72(%rsp) | ||
168 | movq 64(%rsp), %r11 | ||
169 | movq 56(%rsp), %r10 | ||
129 | movq 48(%rsp), %r9 | 170 | movq 48(%rsp), %r9 |
130 | movq 40(%rsp), %r8 | 171 | movq 40(%rsp), %r8 |
131 | movq 32(%rsp), %rdi | 172 | movq 32(%rsp), %rdi |
@@ -133,16 +174,14 @@ trace: | |||
133 | movq 16(%rsp), %rdx | 174 | movq 16(%rsp), %rdx |
134 | movq 8(%rsp), %rcx | 175 | movq 8(%rsp), %rcx |
135 | movq (%rsp), %rax | 176 | movq (%rsp), %rax |
136 | addq $0x38, %rsp | 177 | addq $72, %rsp |
178 | retq | ||
179 | #endif | ||
137 | 180 | ||
138 | jmp ftrace_stub | ||
139 | END(mcount) | ||
140 | #endif /* CONFIG_DYNAMIC_FTRACE */ | ||
141 | #endif /* CONFIG_FUNCTION_TRACER */ | ||
142 | 181 | ||
143 | #ifndef CONFIG_PREEMPT | 182 | #ifndef CONFIG_PREEMPT |
144 | #define retint_kernel retint_restore_args | 183 | #define retint_kernel retint_restore_args |
145 | #endif | 184 | #endif |
146 | 185 | ||
147 | #ifdef CONFIG_PARAVIRT | 186 | #ifdef CONFIG_PARAVIRT |
148 | ENTRY(native_usergs_sysret64) | 187 | ENTRY(native_usergs_sysret64) |
@@ -161,29 +200,29 @@ ENTRY(native_usergs_sysret64) | |||
161 | .endm | 200 | .endm |
162 | 201 | ||
163 | /* | 202 | /* |
164 | * C code is not supposed to know about undefined top of stack. Every time | 203 | * C code is not supposed to know about undefined top of stack. Every time |
165 | * a C function with an pt_regs argument is called from the SYSCALL based | 204 | * a C function with an pt_regs argument is called from the SYSCALL based |
166 | * fast path FIXUP_TOP_OF_STACK is needed. | 205 | * fast path FIXUP_TOP_OF_STACK is needed. |
167 | * RESTORE_TOP_OF_STACK syncs the syscall state after any possible ptregs | 206 | * RESTORE_TOP_OF_STACK syncs the syscall state after any possible ptregs |
168 | * manipulation. | 207 | * manipulation. |
169 | */ | 208 | */ |
170 | 209 | ||
171 | /* %rsp:at FRAMEEND */ | 210 | /* %rsp:at FRAMEEND */ |
172 | .macro FIXUP_TOP_OF_STACK tmp | 211 | .macro FIXUP_TOP_OF_STACK tmp offset=0 |
173 | movq %gs:pda_oldrsp,\tmp | 212 | movq %gs:pda_oldrsp,\tmp |
174 | movq \tmp,RSP(%rsp) | 213 | movq \tmp,RSP+\offset(%rsp) |
175 | movq $__USER_DS,SS(%rsp) | 214 | movq $__USER_DS,SS+\offset(%rsp) |
176 | movq $__USER_CS,CS(%rsp) | 215 | movq $__USER_CS,CS+\offset(%rsp) |
177 | movq $-1,RCX(%rsp) | 216 | movq $-1,RCX+\offset(%rsp) |
178 | movq R11(%rsp),\tmp /* get eflags */ | 217 | movq R11+\offset(%rsp),\tmp /* get eflags */ |
179 | movq \tmp,EFLAGS(%rsp) | 218 | movq \tmp,EFLAGS+\offset(%rsp) |
180 | .endm | 219 | .endm |
181 | 220 | ||
182 | .macro RESTORE_TOP_OF_STACK tmp,offset=0 | 221 | .macro RESTORE_TOP_OF_STACK tmp offset=0 |
183 | movq RSP-\offset(%rsp),\tmp | 222 | movq RSP+\offset(%rsp),\tmp |
184 | movq \tmp,%gs:pda_oldrsp | 223 | movq \tmp,%gs:pda_oldrsp |
185 | movq EFLAGS-\offset(%rsp),\tmp | 224 | movq EFLAGS+\offset(%rsp),\tmp |
186 | movq \tmp,R11-\offset(%rsp) | 225 | movq \tmp,R11+\offset(%rsp) |
187 | .endm | 226 | .endm |
188 | 227 | ||
189 | .macro FAKE_STACK_FRAME child_rip | 228 | .macro FAKE_STACK_FRAME child_rip |
@@ -195,7 +234,7 @@ ENTRY(native_usergs_sysret64) | |||
195 | pushq %rax /* rsp */ | 234 | pushq %rax /* rsp */ |
196 | CFI_ADJUST_CFA_OFFSET 8 | 235 | CFI_ADJUST_CFA_OFFSET 8 |
197 | CFI_REL_OFFSET rsp,0 | 236 | CFI_REL_OFFSET rsp,0 |
198 | pushq $(1<<9) /* eflags - interrupts on */ | 237 | pushq $X86_EFLAGS_IF /* eflags - interrupts on */ |
199 | CFI_ADJUST_CFA_OFFSET 8 | 238 | CFI_ADJUST_CFA_OFFSET 8 |
200 | /*CFI_REL_OFFSET rflags,0*/ | 239 | /*CFI_REL_OFFSET rflags,0*/ |
201 | pushq $__KERNEL_CS /* cs */ | 240 | pushq $__KERNEL_CS /* cs */ |
@@ -213,62 +252,184 @@ ENTRY(native_usergs_sysret64) | |||
213 | CFI_ADJUST_CFA_OFFSET -(6*8) | 252 | CFI_ADJUST_CFA_OFFSET -(6*8) |
214 | .endm | 253 | .endm |
215 | 254 | ||
216 | .macro CFI_DEFAULT_STACK start=1 | 255 | /* |
256 | * initial frame state for interrupts (and exceptions without error code) | ||
257 | */ | ||
258 | .macro EMPTY_FRAME start=1 offset=0 | ||
217 | .if \start | 259 | .if \start |
218 | CFI_STARTPROC simple | 260 | CFI_STARTPROC simple |
219 | CFI_SIGNAL_FRAME | 261 | CFI_SIGNAL_FRAME |
220 | CFI_DEF_CFA rsp,SS+8 | 262 | CFI_DEF_CFA rsp,8+\offset |
221 | .else | 263 | .else |
222 | CFI_DEF_CFA_OFFSET SS+8 | 264 | CFI_DEF_CFA_OFFSET 8+\offset |
223 | .endif | 265 | .endif |
224 | CFI_REL_OFFSET r15,R15 | ||
225 | CFI_REL_OFFSET r14,R14 | ||
226 | CFI_REL_OFFSET r13,R13 | ||
227 | CFI_REL_OFFSET r12,R12 | ||
228 | CFI_REL_OFFSET rbp,RBP | ||
229 | CFI_REL_OFFSET rbx,RBX | ||
230 | CFI_REL_OFFSET r11,R11 | ||
231 | CFI_REL_OFFSET r10,R10 | ||
232 | CFI_REL_OFFSET r9,R9 | ||
233 | CFI_REL_OFFSET r8,R8 | ||
234 | CFI_REL_OFFSET rax,RAX | ||
235 | CFI_REL_OFFSET rcx,RCX | ||
236 | CFI_REL_OFFSET rdx,RDX | ||
237 | CFI_REL_OFFSET rsi,RSI | ||
238 | CFI_REL_OFFSET rdi,RDI | ||
239 | CFI_REL_OFFSET rip,RIP | ||
240 | /*CFI_REL_OFFSET cs,CS*/ | ||
241 | /*CFI_REL_OFFSET rflags,EFLAGS*/ | ||
242 | CFI_REL_OFFSET rsp,RSP | ||
243 | /*CFI_REL_OFFSET ss,SS*/ | ||
244 | .endm | 266 | .endm |
267 | |||
268 | /* | ||
269 | * initial frame state for interrupts (and exceptions without error code) | ||
270 | */ | ||
271 | .macro INTR_FRAME start=1 offset=0 | ||
272 | EMPTY_FRAME \start, SS+8+\offset-RIP | ||
273 | /*CFI_REL_OFFSET ss, SS+\offset-RIP*/ | ||
274 | CFI_REL_OFFSET rsp, RSP+\offset-RIP | ||
275 | /*CFI_REL_OFFSET rflags, EFLAGS+\offset-RIP*/ | ||
276 | /*CFI_REL_OFFSET cs, CS+\offset-RIP*/ | ||
277 | CFI_REL_OFFSET rip, RIP+\offset-RIP | ||
278 | .endm | ||
279 | |||
280 | /* | ||
281 | * initial frame state for exceptions with error code (and interrupts | ||
282 | * with vector already pushed) | ||
283 | */ | ||
284 | .macro XCPT_FRAME start=1 offset=0 | ||
285 | INTR_FRAME \start, RIP+\offset-ORIG_RAX | ||
286 | /*CFI_REL_OFFSET orig_rax, ORIG_RAX-ORIG_RAX*/ | ||
287 | .endm | ||
288 | |||
245 | /* | 289 | /* |
246 | * A newly forked process directly context switches into this. | 290 | * frame that enables calling into C. |
247 | */ | 291 | */ |
248 | /* rdi: prev */ | 292 | .macro PARTIAL_FRAME start=1 offset=0 |
293 | XCPT_FRAME \start, ORIG_RAX+\offset-ARGOFFSET | ||
294 | CFI_REL_OFFSET rdi, RDI+\offset-ARGOFFSET | ||
295 | CFI_REL_OFFSET rsi, RSI+\offset-ARGOFFSET | ||
296 | CFI_REL_OFFSET rdx, RDX+\offset-ARGOFFSET | ||
297 | CFI_REL_OFFSET rcx, RCX+\offset-ARGOFFSET | ||
298 | CFI_REL_OFFSET rax, RAX+\offset-ARGOFFSET | ||
299 | CFI_REL_OFFSET r8, R8+\offset-ARGOFFSET | ||
300 | CFI_REL_OFFSET r9, R9+\offset-ARGOFFSET | ||
301 | CFI_REL_OFFSET r10, R10+\offset-ARGOFFSET | ||
302 | CFI_REL_OFFSET r11, R11+\offset-ARGOFFSET | ||
303 | .endm | ||
304 | |||
305 | /* | ||
306 | * frame that enables passing a complete pt_regs to a C function. | ||
307 | */ | ||
308 | .macro DEFAULT_FRAME start=1 offset=0 | ||
309 | PARTIAL_FRAME \start, R11+\offset-R15 | ||
310 | CFI_REL_OFFSET rbx, RBX+\offset | ||
311 | CFI_REL_OFFSET rbp, RBP+\offset | ||
312 | CFI_REL_OFFSET r12, R12+\offset | ||
313 | CFI_REL_OFFSET r13, R13+\offset | ||
314 | CFI_REL_OFFSET r14, R14+\offset | ||
315 | CFI_REL_OFFSET r15, R15+\offset | ||
316 | .endm | ||
317 | |||
318 | /* save partial stack frame */ | ||
319 | ENTRY(save_args) | ||
320 | XCPT_FRAME | ||
321 | cld | ||
322 | movq_cfi rdi, RDI+16-ARGOFFSET | ||
323 | movq_cfi rsi, RSI+16-ARGOFFSET | ||
324 | movq_cfi rdx, RDX+16-ARGOFFSET | ||
325 | movq_cfi rcx, RCX+16-ARGOFFSET | ||
326 | movq_cfi rax, RAX+16-ARGOFFSET | ||
327 | movq_cfi r8, R8+16-ARGOFFSET | ||
328 | movq_cfi r9, R9+16-ARGOFFSET | ||
329 | movq_cfi r10, R10+16-ARGOFFSET | ||
330 | movq_cfi r11, R11+16-ARGOFFSET | ||
331 | |||
332 | leaq -ARGOFFSET+16(%rsp),%rdi /* arg1 for handler */ | ||
333 | movq_cfi rbp, 8 /* push %rbp */ | ||
334 | leaq 8(%rsp), %rbp /* mov %rsp, %ebp */ | ||
335 | testl $3, CS(%rdi) | ||
336 | je 1f | ||
337 | SWAPGS | ||
338 | /* | ||
339 | * irqcount is used to check if a CPU is already on an interrupt stack | ||
340 | * or not. While this is essentially redundant with preempt_count it is | ||
341 | * a little cheaper to use a separate counter in the PDA (short of | ||
342 | * moving irq_enter into assembly, which would be too much work) | ||
343 | */ | ||
344 | 1: incl %gs:pda_irqcount | ||
345 | jne 2f | ||
346 | popq_cfi %rax /* move return address... */ | ||
347 | mov %gs:pda_irqstackptr,%rsp | ||
348 | EMPTY_FRAME 0 | ||
349 | pushq_cfi %rax /* ... to the new stack */ | ||
350 | /* | ||
351 | * We entered an interrupt context - irqs are off: | ||
352 | */ | ||
353 | 2: TRACE_IRQS_OFF | ||
354 | ret | ||
355 | CFI_ENDPROC | ||
356 | END(save_args) | ||
357 | |||
358 | ENTRY(save_rest) | ||
359 | PARTIAL_FRAME 1 REST_SKIP+8 | ||
360 | movq 5*8+16(%rsp), %r11 /* save return address */ | ||
361 | movq_cfi rbx, RBX+16 | ||
362 | movq_cfi rbp, RBP+16 | ||
363 | movq_cfi r12, R12+16 | ||
364 | movq_cfi r13, R13+16 | ||
365 | movq_cfi r14, R14+16 | ||
366 | movq_cfi r15, R15+16 | ||
367 | movq %r11, 8(%rsp) /* return address */ | ||
368 | FIXUP_TOP_OF_STACK %r11, 16 | ||
369 | ret | ||
370 | CFI_ENDPROC | ||
371 | END(save_rest) | ||
372 | |||
373 | /* save complete stack frame */ | ||
374 | ENTRY(save_paranoid) | ||
375 | XCPT_FRAME 1 RDI+8 | ||
376 | cld | ||
377 | movq_cfi rdi, RDI+8 | ||
378 | movq_cfi rsi, RSI+8 | ||
379 | movq_cfi rdx, RDX+8 | ||
380 | movq_cfi rcx, RCX+8 | ||
381 | movq_cfi rax, RAX+8 | ||
382 | movq_cfi r8, R8+8 | ||
383 | movq_cfi r9, R9+8 | ||
384 | movq_cfi r10, R10+8 | ||
385 | movq_cfi r11, R11+8 | ||
386 | movq_cfi rbx, RBX+8 | ||
387 | movq_cfi rbp, RBP+8 | ||
388 | movq_cfi r12, R12+8 | ||
389 | movq_cfi r13, R13+8 | ||
390 | movq_cfi r14, R14+8 | ||
391 | movq_cfi r15, R15+8 | ||
392 | movl $1,%ebx | ||
393 | movl $MSR_GS_BASE,%ecx | ||
394 | rdmsr | ||
395 | testl %edx,%edx | ||
396 | js 1f /* negative -> in kernel */ | ||
397 | SWAPGS | ||
398 | xorl %ebx,%ebx | ||
399 | 1: ret | ||
400 | CFI_ENDPROC | ||
401 | END(save_paranoid) | ||
402 | |||
403 | /* | ||
404 | * A newly forked process directly context switches into this address. | ||
405 | * | ||
406 | * rdi: prev task we switched from | ||
407 | */ | ||
249 | ENTRY(ret_from_fork) | 408 | ENTRY(ret_from_fork) |
250 | CFI_DEFAULT_STACK | 409 | DEFAULT_FRAME |
410 | |||
251 | push kernel_eflags(%rip) | 411 | push kernel_eflags(%rip) |
252 | CFI_ADJUST_CFA_OFFSET 8 | 412 | CFI_ADJUST_CFA_OFFSET 8 |
253 | popf # reset kernel eflags | 413 | popf # reset kernel eflags |
254 | CFI_ADJUST_CFA_OFFSET -8 | 414 | CFI_ADJUST_CFA_OFFSET -8 |
255 | call schedule_tail | 415 | |
416 | call schedule_tail # rdi: 'prev' task parameter | ||
417 | |||
256 | GET_THREAD_INFO(%rcx) | 418 | GET_THREAD_INFO(%rcx) |
257 | testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT),TI_flags(%rcx) | 419 | |
258 | jnz rff_trace | 420 | CFI_REMEMBER_STATE |
259 | rff_action: | ||
260 | RESTORE_REST | 421 | RESTORE_REST |
261 | testl $3,CS-ARGOFFSET(%rsp) # from kernel_thread? | 422 | |
423 | testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread? | ||
262 | je int_ret_from_sys_call | 424 | je int_ret_from_sys_call |
263 | testl $_TIF_IA32,TI_flags(%rcx) | 425 | |
426 | testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET | ||
264 | jnz int_ret_from_sys_call | 427 | jnz int_ret_from_sys_call |
265 | RESTORE_TOP_OF_STACK %rdi,ARGOFFSET | 428 | |
266 | jmp ret_from_sys_call | 429 | RESTORE_TOP_OF_STACK %rdi, -ARGOFFSET |
267 | rff_trace: | 430 | jmp ret_from_sys_call # go to the SYSRET fastpath |
268 | movq %rsp,%rdi | 431 | |
269 | call syscall_trace_leave | 432 | CFI_RESTORE_STATE |
270 | GET_THREAD_INFO(%rcx) | ||
271 | jmp rff_action | ||
272 | CFI_ENDPROC | 433 | CFI_ENDPROC |
273 | END(ret_from_fork) | 434 | END(ret_from_fork) |
274 | 435 | ||
@@ -278,20 +439,20 @@ END(ret_from_fork) | |||
278 | * SYSCALL does not save anything on the stack and does not change the | 439 | * SYSCALL does not save anything on the stack and does not change the |
279 | * stack pointer. | 440 | * stack pointer. |
280 | */ | 441 | */ |
281 | 442 | ||
282 | /* | 443 | /* |
283 | * Register setup: | 444 | * Register setup: |
284 | * rax system call number | 445 | * rax system call number |
285 | * rdi arg0 | 446 | * rdi arg0 |
286 | * rcx return address for syscall/sysret, C arg3 | 447 | * rcx return address for syscall/sysret, C arg3 |
287 | * rsi arg1 | 448 | * rsi arg1 |
288 | * rdx arg2 | 449 | * rdx arg2 |
289 | * r10 arg3 (--> moved to rcx for C) | 450 | * r10 arg3 (--> moved to rcx for C) |
290 | * r8 arg4 | 451 | * r8 arg4 |
291 | * r9 arg5 | 452 | * r9 arg5 |
292 | * r11 eflags for syscall/sysret, temporary for C | 453 | * r11 eflags for syscall/sysret, temporary for C |
293 | * r12-r15,rbp,rbx saved by C code, not touched. | 454 | * r12-r15,rbp,rbx saved by C code, not touched. |
294 | * | 455 | * |
295 | * Interrupts are off on entry. | 456 | * Interrupts are off on entry. |
296 | * Only called from user space. | 457 | * Only called from user space. |
297 | * | 458 | * |
@@ -301,7 +462,7 @@ END(ret_from_fork) | |||
301 | * When user can change the frames always force IRET. That is because | 462 | * When user can change the frames always force IRET. That is because |
302 | * it deals with uncanonical addresses better. SYSRET has trouble | 463 | * it deals with uncanonical addresses better. SYSRET has trouble |
303 | * with them due to bugs in both AMD and Intel CPUs. | 464 | * with them due to bugs in both AMD and Intel CPUs. |
304 | */ | 465 | */ |
305 | 466 | ||
306 | ENTRY(system_call) | 467 | ENTRY(system_call) |
307 | CFI_STARTPROC simple | 468 | CFI_STARTPROC simple |
@@ -317,7 +478,7 @@ ENTRY(system_call) | |||
317 | */ | 478 | */ |
318 | ENTRY(system_call_after_swapgs) | 479 | ENTRY(system_call_after_swapgs) |
319 | 480 | ||
320 | movq %rsp,%gs:pda_oldrsp | 481 | movq %rsp,%gs:pda_oldrsp |
321 | movq %gs:pda_kernelstack,%rsp | 482 | movq %gs:pda_kernelstack,%rsp |
322 | /* | 483 | /* |
323 | * No need to follow this irqs off/on section - it's straight | 484 | * No need to follow this irqs off/on section - it's straight |
@@ -325,7 +486,7 @@ ENTRY(system_call_after_swapgs) | |||
325 | */ | 486 | */ |
326 | ENABLE_INTERRUPTS(CLBR_NONE) | 487 | ENABLE_INTERRUPTS(CLBR_NONE) |
327 | SAVE_ARGS 8,1 | 488 | SAVE_ARGS 8,1 |
328 | movq %rax,ORIG_RAX-ARGOFFSET(%rsp) | 489 | movq %rax,ORIG_RAX-ARGOFFSET(%rsp) |
329 | movq %rcx,RIP-ARGOFFSET(%rsp) | 490 | movq %rcx,RIP-ARGOFFSET(%rsp) |
330 | CFI_REL_OFFSET rip,RIP-ARGOFFSET | 491 | CFI_REL_OFFSET rip,RIP-ARGOFFSET |
331 | GET_THREAD_INFO(%rcx) | 492 | GET_THREAD_INFO(%rcx) |
@@ -339,19 +500,19 @@ system_call_fastpath: | |||
339 | movq %rax,RAX-ARGOFFSET(%rsp) | 500 | movq %rax,RAX-ARGOFFSET(%rsp) |
340 | /* | 501 | /* |
341 | * Syscall return path ending with SYSRET (fast path) | 502 | * Syscall return path ending with SYSRET (fast path) |
342 | * Has incomplete stack frame and undefined top of stack. | 503 | * Has incomplete stack frame and undefined top of stack. |
343 | */ | 504 | */ |
344 | ret_from_sys_call: | 505 | ret_from_sys_call: |
345 | movl $_TIF_ALLWORK_MASK,%edi | 506 | movl $_TIF_ALLWORK_MASK,%edi |
346 | /* edi: flagmask */ | 507 | /* edi: flagmask */ |
347 | sysret_check: | 508 | sysret_check: |
348 | LOCKDEP_SYS_EXIT | 509 | LOCKDEP_SYS_EXIT |
349 | GET_THREAD_INFO(%rcx) | 510 | GET_THREAD_INFO(%rcx) |
350 | DISABLE_INTERRUPTS(CLBR_NONE) | 511 | DISABLE_INTERRUPTS(CLBR_NONE) |
351 | TRACE_IRQS_OFF | 512 | TRACE_IRQS_OFF |
352 | movl TI_flags(%rcx),%edx | 513 | movl TI_flags(%rcx),%edx |
353 | andl %edi,%edx | 514 | andl %edi,%edx |
354 | jnz sysret_careful | 515 | jnz sysret_careful |
355 | CFI_REMEMBER_STATE | 516 | CFI_REMEMBER_STATE |
356 | /* | 517 | /* |
357 | * sysretq will re-enable interrupts: | 518 | * sysretq will re-enable interrupts: |
@@ -366,7 +527,7 @@ sysret_check: | |||
366 | 527 | ||
367 | CFI_RESTORE_STATE | 528 | CFI_RESTORE_STATE |
368 | /* Handle reschedules */ | 529 | /* Handle reschedules */ |
369 | /* edx: work, edi: workmask */ | 530 | /* edx: work, edi: workmask */ |
370 | sysret_careful: | 531 | sysret_careful: |
371 | bt $TIF_NEED_RESCHED,%edx | 532 | bt $TIF_NEED_RESCHED,%edx |
372 | jnc sysret_signal | 533 | jnc sysret_signal |
@@ -379,7 +540,7 @@ sysret_careful: | |||
379 | CFI_ADJUST_CFA_OFFSET -8 | 540 | CFI_ADJUST_CFA_OFFSET -8 |
380 | jmp sysret_check | 541 | jmp sysret_check |
381 | 542 | ||
382 | /* Handle a signal */ | 543 | /* Handle a signal */ |
383 | sysret_signal: | 544 | sysret_signal: |
384 | TRACE_IRQS_ON | 545 | TRACE_IRQS_ON |
385 | ENABLE_INTERRUPTS(CLBR_NONE) | 546 | ENABLE_INTERRUPTS(CLBR_NONE) |
@@ -388,17 +549,20 @@ sysret_signal: | |||
388 | jc sysret_audit | 549 | jc sysret_audit |
389 | #endif | 550 | #endif |
390 | /* edx: work flags (arg3) */ | 551 | /* edx: work flags (arg3) */ |
391 | leaq do_notify_resume(%rip),%rax | ||
392 | leaq -ARGOFFSET(%rsp),%rdi # &pt_regs -> arg1 | 552 | leaq -ARGOFFSET(%rsp),%rdi # &pt_regs -> arg1 |
393 | xorl %esi,%esi # oldset -> arg2 | 553 | xorl %esi,%esi # oldset -> arg2 |
394 | call ptregscall_common | 554 | SAVE_REST |
555 | FIXUP_TOP_OF_STACK %r11 | ||
556 | call do_notify_resume | ||
557 | RESTORE_TOP_OF_STACK %r11 | ||
558 | RESTORE_REST | ||
395 | movl $_TIF_WORK_MASK,%edi | 559 | movl $_TIF_WORK_MASK,%edi |
396 | /* Use IRET because user could have changed frame. This | 560 | /* Use IRET because user could have changed frame. This |
397 | works because ptregscall_common has called FIXUP_TOP_OF_STACK. */ | 561 | works because ptregscall_common has called FIXUP_TOP_OF_STACK. */ |
398 | DISABLE_INTERRUPTS(CLBR_NONE) | 562 | DISABLE_INTERRUPTS(CLBR_NONE) |
399 | TRACE_IRQS_OFF | 563 | TRACE_IRQS_OFF |
400 | jmp int_with_check | 564 | jmp int_with_check |
401 | 565 | ||
402 | badsys: | 566 | badsys: |
403 | movq $-ENOSYS,RAX-ARGOFFSET(%rsp) | 567 | movq $-ENOSYS,RAX-ARGOFFSET(%rsp) |
404 | jmp ret_from_sys_call | 568 | jmp ret_from_sys_call |
@@ -437,7 +601,7 @@ sysret_audit: | |||
437 | #endif /* CONFIG_AUDITSYSCALL */ | 601 | #endif /* CONFIG_AUDITSYSCALL */ |
438 | 602 | ||
439 | /* Do syscall tracing */ | 603 | /* Do syscall tracing */ |
440 | tracesys: | 604 | tracesys: |
441 | #ifdef CONFIG_AUDITSYSCALL | 605 | #ifdef CONFIG_AUDITSYSCALL |
442 | testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx) | 606 | testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx) |
443 | jz auditsys | 607 | jz auditsys |
@@ -460,8 +624,8 @@ tracesys: | |||
460 | call *sys_call_table(,%rax,8) | 624 | call *sys_call_table(,%rax,8) |
461 | movq %rax,RAX-ARGOFFSET(%rsp) | 625 | movq %rax,RAX-ARGOFFSET(%rsp) |
462 | /* Use IRET because user could have changed frame */ | 626 | /* Use IRET because user could have changed frame */ |
463 | 627 | ||
464 | /* | 628 | /* |
465 | * Syscall return path ending with IRET. | 629 | * Syscall return path ending with IRET. |
466 | * Has correct top of stack, but partial stack frame. | 630 | * Has correct top of stack, but partial stack frame. |
467 | */ | 631 | */ |
@@ -505,18 +669,18 @@ int_very_careful: | |||
505 | TRACE_IRQS_ON | 669 | TRACE_IRQS_ON |
506 | ENABLE_INTERRUPTS(CLBR_NONE) | 670 | ENABLE_INTERRUPTS(CLBR_NONE) |
507 | SAVE_REST | 671 | SAVE_REST |
508 | /* Check for syscall exit trace */ | 672 | /* Check for syscall exit trace */ |
509 | testl $_TIF_WORK_SYSCALL_EXIT,%edx | 673 | testl $_TIF_WORK_SYSCALL_EXIT,%edx |
510 | jz int_signal | 674 | jz int_signal |
511 | pushq %rdi | 675 | pushq %rdi |
512 | CFI_ADJUST_CFA_OFFSET 8 | 676 | CFI_ADJUST_CFA_OFFSET 8 |
513 | leaq 8(%rsp),%rdi # &ptregs -> arg1 | 677 | leaq 8(%rsp),%rdi # &ptregs -> arg1 |
514 | call syscall_trace_leave | 678 | call syscall_trace_leave |
515 | popq %rdi | 679 | popq %rdi |
516 | CFI_ADJUST_CFA_OFFSET -8 | 680 | CFI_ADJUST_CFA_OFFSET -8 |
517 | andl $~(_TIF_WORK_SYSCALL_EXIT|_TIF_SYSCALL_EMU),%edi | 681 | andl $~(_TIF_WORK_SYSCALL_EXIT|_TIF_SYSCALL_EMU),%edi |
518 | jmp int_restore_rest | 682 | jmp int_restore_rest |
519 | 683 | ||
520 | int_signal: | 684 | int_signal: |
521 | testl $_TIF_DO_NOTIFY_MASK,%edx | 685 | testl $_TIF_DO_NOTIFY_MASK,%edx |
522 | jz 1f | 686 | jz 1f |
@@ -531,22 +695,24 @@ int_restore_rest: | |||
531 | jmp int_with_check | 695 | jmp int_with_check |
532 | CFI_ENDPROC | 696 | CFI_ENDPROC |
533 | END(system_call) | 697 | END(system_call) |
534 | 698 | ||
535 | /* | 699 | /* |
536 | * Certain special system calls that need to save a complete full stack frame. | 700 | * Certain special system calls that need to save a complete full stack frame. |
537 | */ | 701 | */ |
538 | |||
539 | .macro PTREGSCALL label,func,arg | 702 | .macro PTREGSCALL label,func,arg |
540 | .globl \label | 703 | ENTRY(\label) |
541 | \label: | 704 | PARTIAL_FRAME 1 8 /* offset 8: return address */ |
542 | leaq \func(%rip),%rax | 705 | subq $REST_SKIP, %rsp |
543 | leaq -ARGOFFSET+8(%rsp),\arg /* 8 for return address */ | 706 | CFI_ADJUST_CFA_OFFSET REST_SKIP |
544 | jmp ptregscall_common | 707 | call save_rest |
708 | DEFAULT_FRAME 0 8 /* offset 8: return address */ | ||
709 | leaq 8(%rsp), \arg /* pt_regs pointer */ | ||
710 | call \func | ||
711 | jmp ptregscall_common | ||
712 | CFI_ENDPROC | ||
545 | END(\label) | 713 | END(\label) |
546 | .endm | 714 | .endm |
547 | 715 | ||
548 | CFI_STARTPROC | ||
549 | |||
550 | PTREGSCALL stub_clone, sys_clone, %r8 | 716 | PTREGSCALL stub_clone, sys_clone, %r8 |
551 | PTREGSCALL stub_fork, sys_fork, %rdi | 717 | PTREGSCALL stub_fork, sys_fork, %rdi |
552 | PTREGSCALL stub_vfork, sys_vfork, %rdi | 718 | PTREGSCALL stub_vfork, sys_vfork, %rdi |
@@ -554,25 +720,18 @@ END(\label) | |||
554 | PTREGSCALL stub_iopl, sys_iopl, %rsi | 720 | PTREGSCALL stub_iopl, sys_iopl, %rsi |
555 | 721 | ||
556 | ENTRY(ptregscall_common) | 722 | ENTRY(ptregscall_common) |
557 | popq %r11 | 723 | DEFAULT_FRAME 1 8 /* offset 8: return address */ |
558 | CFI_ADJUST_CFA_OFFSET -8 | 724 | RESTORE_TOP_OF_STACK %r11, 8 |
559 | CFI_REGISTER rip, r11 | 725 | movq_cfi_restore R15+8, r15 |
560 | SAVE_REST | 726 | movq_cfi_restore R14+8, r14 |
561 | movq %r11, %r15 | 727 | movq_cfi_restore R13+8, r13 |
562 | CFI_REGISTER rip, r15 | 728 | movq_cfi_restore R12+8, r12 |
563 | FIXUP_TOP_OF_STACK %r11 | 729 | movq_cfi_restore RBP+8, rbp |
564 | call *%rax | 730 | movq_cfi_restore RBX+8, rbx |
565 | RESTORE_TOP_OF_STACK %r11 | 731 | ret $REST_SKIP /* pop extended registers */ |
566 | movq %r15, %r11 | ||
567 | CFI_REGISTER rip, r11 | ||
568 | RESTORE_REST | ||
569 | pushq %r11 | ||
570 | CFI_ADJUST_CFA_OFFSET 8 | ||
571 | CFI_REL_OFFSET rip, 0 | ||
572 | ret | ||
573 | CFI_ENDPROC | 732 | CFI_ENDPROC |
574 | END(ptregscall_common) | 733 | END(ptregscall_common) |
575 | 734 | ||
576 | ENTRY(stub_execve) | 735 | ENTRY(stub_execve) |
577 | CFI_STARTPROC | 736 | CFI_STARTPROC |
578 | popq %r11 | 737 | popq %r11 |
@@ -588,11 +747,11 @@ ENTRY(stub_execve) | |||
588 | jmp int_ret_from_sys_call | 747 | jmp int_ret_from_sys_call |
589 | CFI_ENDPROC | 748 | CFI_ENDPROC |
590 | END(stub_execve) | 749 | END(stub_execve) |
591 | 750 | ||
592 | /* | 751 | /* |
593 | * sigreturn is special because it needs to restore all registers on return. | 752 | * sigreturn is special because it needs to restore all registers on return. |
594 | * This cannot be done with SYSRET, so use the IRET return path instead. | 753 | * This cannot be done with SYSRET, so use the IRET return path instead. |
595 | */ | 754 | */ |
596 | ENTRY(stub_rt_sigreturn) | 755 | ENTRY(stub_rt_sigreturn) |
597 | CFI_STARTPROC | 756 | CFI_STARTPROC |
598 | addq $8, %rsp | 757 | addq $8, %rsp |
@@ -608,70 +767,70 @@ ENTRY(stub_rt_sigreturn) | |||
608 | END(stub_rt_sigreturn) | 767 | END(stub_rt_sigreturn) |
609 | 768 | ||
610 | /* | 769 | /* |
611 | * initial frame state for interrupts and exceptions | 770 | * Build the entry stubs and pointer table with some assembler magic. |
771 | * We pack 7 stubs into a single 32-byte chunk, which will fit in a | ||
772 | * single cache line on all modern x86 implementations. | ||
612 | */ | 773 | */ |
613 | .macro _frame ref | 774 | .section .init.rodata,"a" |
614 | CFI_STARTPROC simple | 775 | ENTRY(interrupt) |
615 | CFI_SIGNAL_FRAME | 776 | .text |
616 | CFI_DEF_CFA rsp,SS+8-\ref | 777 | .p2align 5 |
617 | /*CFI_REL_OFFSET ss,SS-\ref*/ | 778 | .p2align CONFIG_X86_L1_CACHE_SHIFT |
618 | CFI_REL_OFFSET rsp,RSP-\ref | 779 | ENTRY(irq_entries_start) |
619 | /*CFI_REL_OFFSET rflags,EFLAGS-\ref*/ | 780 | INTR_FRAME |
620 | /*CFI_REL_OFFSET cs,CS-\ref*/ | 781 | vector=FIRST_EXTERNAL_VECTOR |
621 | CFI_REL_OFFSET rip,RIP-\ref | 782 | .rept (NR_VECTORS-FIRST_EXTERNAL_VECTOR+6)/7 |
622 | .endm | 783 | .balign 32 |
784 | .rept 7 | ||
785 | .if vector < NR_VECTORS | ||
786 | .if vector <> FIRST_EXTERNAL_VECTOR | ||
787 | CFI_ADJUST_CFA_OFFSET -8 | ||
788 | .endif | ||
789 | 1: pushq $(~vector+0x80) /* Note: always in signed byte range */ | ||
790 | CFI_ADJUST_CFA_OFFSET 8 | ||
791 | .if ((vector-FIRST_EXTERNAL_VECTOR)%7) <> 6 | ||
792 | jmp 2f | ||
793 | .endif | ||
794 | .previous | ||
795 | .quad 1b | ||
796 | .text | ||
797 | vector=vector+1 | ||
798 | .endif | ||
799 | .endr | ||
800 | 2: jmp common_interrupt | ||
801 | .endr | ||
802 | CFI_ENDPROC | ||
803 | END(irq_entries_start) | ||
623 | 804 | ||
624 | /* initial frame state for interrupts (and exceptions without error code) */ | 805 | .previous |
625 | #define INTR_FRAME _frame RIP | 806 | END(interrupt) |
626 | /* initial frame state for exceptions with error code (and interrupts with | 807 | .previous |
627 | vector already pushed) */ | ||
628 | #define XCPT_FRAME _frame ORIG_RAX | ||
629 | 808 | ||
630 | /* | 809 | /* |
631 | * Interrupt entry/exit. | 810 | * Interrupt entry/exit. |
632 | * | 811 | * |
633 | * Interrupt entry points save only callee clobbered registers in fast path. | 812 | * Interrupt entry points save only callee clobbered registers in fast path. |
634 | * | 813 | * |
635 | * Entry runs with interrupts off. | 814 | * Entry runs with interrupts off. |
636 | */ | 815 | */ |
637 | 816 | ||
638 | /* 0(%rsp): interrupt number */ | 817 | /* 0(%rsp): ~(interrupt number) */ |
639 | .macro interrupt func | 818 | .macro interrupt func |
640 | cld | 819 | subq $10*8, %rsp |
641 | SAVE_ARGS | 820 | CFI_ADJUST_CFA_OFFSET 10*8 |
642 | leaq -ARGOFFSET(%rsp),%rdi # arg1 for handler | 821 | call save_args |
643 | pushq %rbp | 822 | PARTIAL_FRAME 0 |
644 | /* | ||
645 | * Save rbp twice: One is for marking the stack frame, as usual, and the | ||
646 | * other, to fill pt_regs properly. This is because bx comes right | ||
647 | * before the last saved register in that structure, and not bp. If the | ||
648 | * base pointer were in the place bx is today, this would not be needed. | ||
649 | */ | ||
650 | movq %rbp, -8(%rsp) | ||
651 | CFI_ADJUST_CFA_OFFSET 8 | ||
652 | CFI_REL_OFFSET rbp, 0 | ||
653 | movq %rsp,%rbp | ||
654 | CFI_DEF_CFA_REGISTER rbp | ||
655 | testl $3,CS(%rdi) | ||
656 | je 1f | ||
657 | SWAPGS | ||
658 | /* irqcount is used to check if a CPU is already on an interrupt | ||
659 | stack or not. While this is essentially redundant with preempt_count | ||
660 | it is a little cheaper to use a separate counter in the PDA | ||
661 | (short of moving irq_enter into assembly, which would be too | ||
662 | much work) */ | ||
663 | 1: incl %gs:pda_irqcount | ||
664 | cmoveq %gs:pda_irqstackptr,%rsp | ||
665 | push %rbp # backlink for old unwinder | ||
666 | /* | ||
667 | * We entered an interrupt context - irqs are off: | ||
668 | */ | ||
669 | TRACE_IRQS_OFF | ||
670 | call \func | 823 | call \func |
671 | .endm | 824 | .endm |
672 | 825 | ||
673 | ENTRY(common_interrupt) | 826 | /* |
827 | * The interrupt stubs push (~vector+0x80) onto the stack and | ||
828 | * then jump to common_interrupt. | ||
829 | */ | ||
830 | .p2align CONFIG_X86_L1_CACHE_SHIFT | ||
831 | common_interrupt: | ||
674 | XCPT_FRAME | 832 | XCPT_FRAME |
833 | addq $-0x80,(%rsp) /* Adjust vector to [-256,-1] range */ | ||
675 | interrupt do_IRQ | 834 | interrupt do_IRQ |
676 | /* 0(%rsp): oldrsp-ARGOFFSET */ | 835 | /* 0(%rsp): oldrsp-ARGOFFSET */ |
677 | ret_from_intr: | 836 | ret_from_intr: |
@@ -685,12 +844,12 @@ exit_intr: | |||
685 | GET_THREAD_INFO(%rcx) | 844 | GET_THREAD_INFO(%rcx) |
686 | testl $3,CS-ARGOFFSET(%rsp) | 845 | testl $3,CS-ARGOFFSET(%rsp) |
687 | je retint_kernel | 846 | je retint_kernel |
688 | 847 | ||
689 | /* Interrupt came from user space */ | 848 | /* Interrupt came from user space */ |
690 | /* | 849 | /* |
691 | * Has a correct top of stack, but a partial stack frame | 850 | * Has a correct top of stack, but a partial stack frame |
692 | * %rcx: thread info. Interrupts off. | 851 | * %rcx: thread info. Interrupts off. |
693 | */ | 852 | */ |
694 | retint_with_reschedule: | 853 | retint_with_reschedule: |
695 | movl $_TIF_WORK_MASK,%edi | 854 | movl $_TIF_WORK_MASK,%edi |
696 | retint_check: | 855 | retint_check: |
@@ -763,20 +922,20 @@ retint_careful: | |||
763 | pushq %rdi | 922 | pushq %rdi |
764 | CFI_ADJUST_CFA_OFFSET 8 | 923 | CFI_ADJUST_CFA_OFFSET 8 |
765 | call schedule | 924 | call schedule |
766 | popq %rdi | 925 | popq %rdi |
767 | CFI_ADJUST_CFA_OFFSET -8 | 926 | CFI_ADJUST_CFA_OFFSET -8 |
768 | GET_THREAD_INFO(%rcx) | 927 | GET_THREAD_INFO(%rcx) |
769 | DISABLE_INTERRUPTS(CLBR_NONE) | 928 | DISABLE_INTERRUPTS(CLBR_NONE) |
770 | TRACE_IRQS_OFF | 929 | TRACE_IRQS_OFF |
771 | jmp retint_check | 930 | jmp retint_check |
772 | 931 | ||
773 | retint_signal: | 932 | retint_signal: |
774 | testl $_TIF_DO_NOTIFY_MASK,%edx | 933 | testl $_TIF_DO_NOTIFY_MASK,%edx |
775 | jz retint_swapgs | 934 | jz retint_swapgs |
776 | TRACE_IRQS_ON | 935 | TRACE_IRQS_ON |
777 | ENABLE_INTERRUPTS(CLBR_NONE) | 936 | ENABLE_INTERRUPTS(CLBR_NONE) |
778 | SAVE_REST | 937 | SAVE_REST |
779 | movq $-1,ORIG_RAX(%rsp) | 938 | movq $-1,ORIG_RAX(%rsp) |
780 | xorl %esi,%esi # oldset | 939 | xorl %esi,%esi # oldset |
781 | movq %rsp,%rdi # &pt_regs | 940 | movq %rsp,%rdi # &pt_regs |
782 | call do_notify_resume | 941 | call do_notify_resume |
@@ -798,324 +957,211 @@ ENTRY(retint_kernel) | |||
798 | jnc retint_restore_args | 957 | jnc retint_restore_args |
799 | call preempt_schedule_irq | 958 | call preempt_schedule_irq |
800 | jmp exit_intr | 959 | jmp exit_intr |
801 | #endif | 960 | #endif |
802 | 961 | ||
803 | CFI_ENDPROC | 962 | CFI_ENDPROC |
804 | END(common_interrupt) | 963 | END(common_interrupt) |
805 | 964 | ||
806 | /* | 965 | /* |
807 | * APIC interrupts. | 966 | * APIC interrupts. |
808 | */ | 967 | */ |
809 | .macro apicinterrupt num,func | 968 | .macro apicinterrupt num sym do_sym |
969 | ENTRY(\sym) | ||
810 | INTR_FRAME | 970 | INTR_FRAME |
811 | pushq $~(\num) | 971 | pushq $~(\num) |
812 | CFI_ADJUST_CFA_OFFSET 8 | 972 | CFI_ADJUST_CFA_OFFSET 8 |
813 | interrupt \func | 973 | interrupt \do_sym |
814 | jmp ret_from_intr | 974 | jmp ret_from_intr |
815 | CFI_ENDPROC | 975 | CFI_ENDPROC |
816 | .endm | 976 | END(\sym) |
817 | 977 | .endm | |
818 | ENTRY(thermal_interrupt) | ||
819 | apicinterrupt THERMAL_APIC_VECTOR,smp_thermal_interrupt | ||
820 | END(thermal_interrupt) | ||
821 | |||
822 | ENTRY(threshold_interrupt) | ||
823 | apicinterrupt THRESHOLD_APIC_VECTOR,mce_threshold_interrupt | ||
824 | END(threshold_interrupt) | ||
825 | |||
826 | #ifdef CONFIG_SMP | ||
827 | ENTRY(reschedule_interrupt) | ||
828 | apicinterrupt RESCHEDULE_VECTOR,smp_reschedule_interrupt | ||
829 | END(reschedule_interrupt) | ||
830 | |||
831 | .macro INVALIDATE_ENTRY num | ||
832 | ENTRY(invalidate_interrupt\num) | ||
833 | apicinterrupt INVALIDATE_TLB_VECTOR_START+\num,smp_invalidate_interrupt | ||
834 | END(invalidate_interrupt\num) | ||
835 | .endm | ||
836 | 978 | ||
837 | INVALIDATE_ENTRY 0 | 979 | #ifdef CONFIG_SMP |
838 | INVALIDATE_ENTRY 1 | 980 | apicinterrupt IRQ_MOVE_CLEANUP_VECTOR \ |
839 | INVALIDATE_ENTRY 2 | 981 | irq_move_cleanup_interrupt smp_irq_move_cleanup_interrupt |
840 | INVALIDATE_ENTRY 3 | ||
841 | INVALIDATE_ENTRY 4 | ||
842 | INVALIDATE_ENTRY 5 | ||
843 | INVALIDATE_ENTRY 6 | ||
844 | INVALIDATE_ENTRY 7 | ||
845 | |||
846 | ENTRY(call_function_interrupt) | ||
847 | apicinterrupt CALL_FUNCTION_VECTOR,smp_call_function_interrupt | ||
848 | END(call_function_interrupt) | ||
849 | ENTRY(call_function_single_interrupt) | ||
850 | apicinterrupt CALL_FUNCTION_SINGLE_VECTOR,smp_call_function_single_interrupt | ||
851 | END(call_function_single_interrupt) | ||
852 | ENTRY(irq_move_cleanup_interrupt) | ||
853 | apicinterrupt IRQ_MOVE_CLEANUP_VECTOR,smp_irq_move_cleanup_interrupt | ||
854 | END(irq_move_cleanup_interrupt) | ||
855 | #endif | 982 | #endif |
856 | 983 | ||
857 | ENTRY(apic_timer_interrupt) | 984 | apicinterrupt UV_BAU_MESSAGE \ |
858 | apicinterrupt LOCAL_TIMER_VECTOR,smp_apic_timer_interrupt | 985 | uv_bau_message_intr1 uv_bau_message_interrupt |
859 | END(apic_timer_interrupt) | 986 | apicinterrupt LOCAL_TIMER_VECTOR \ |
987 | apic_timer_interrupt smp_apic_timer_interrupt | ||
988 | |||
989 | #ifdef CONFIG_SMP | ||
990 | apicinterrupt INVALIDATE_TLB_VECTOR_START+0 \ | ||
991 | invalidate_interrupt0 smp_invalidate_interrupt | ||
992 | apicinterrupt INVALIDATE_TLB_VECTOR_START+1 \ | ||
993 | invalidate_interrupt1 smp_invalidate_interrupt | ||
994 | apicinterrupt INVALIDATE_TLB_VECTOR_START+2 \ | ||
995 | invalidate_interrupt2 smp_invalidate_interrupt | ||
996 | apicinterrupt INVALIDATE_TLB_VECTOR_START+3 \ | ||
997 | invalidate_interrupt3 smp_invalidate_interrupt | ||
998 | apicinterrupt INVALIDATE_TLB_VECTOR_START+4 \ | ||
999 | invalidate_interrupt4 smp_invalidate_interrupt | ||
1000 | apicinterrupt INVALIDATE_TLB_VECTOR_START+5 \ | ||
1001 | invalidate_interrupt5 smp_invalidate_interrupt | ||
1002 | apicinterrupt INVALIDATE_TLB_VECTOR_START+6 \ | ||
1003 | invalidate_interrupt6 smp_invalidate_interrupt | ||
1004 | apicinterrupt INVALIDATE_TLB_VECTOR_START+7 \ | ||
1005 | invalidate_interrupt7 smp_invalidate_interrupt | ||
1006 | #endif | ||
860 | 1007 | ||
861 | ENTRY(uv_bau_message_intr1) | 1008 | apicinterrupt THRESHOLD_APIC_VECTOR \ |
862 | apicinterrupt 220,uv_bau_message_interrupt | 1009 | threshold_interrupt mce_threshold_interrupt |
863 | END(uv_bau_message_intr1) | 1010 | apicinterrupt THERMAL_APIC_VECTOR \ |
1011 | thermal_interrupt smp_thermal_interrupt | ||
1012 | |||
1013 | #ifdef CONFIG_SMP | ||
1014 | apicinterrupt CALL_FUNCTION_SINGLE_VECTOR \ | ||
1015 | call_function_single_interrupt smp_call_function_single_interrupt | ||
1016 | apicinterrupt CALL_FUNCTION_VECTOR \ | ||
1017 | call_function_interrupt smp_call_function_interrupt | ||
1018 | apicinterrupt RESCHEDULE_VECTOR \ | ||
1019 | reschedule_interrupt smp_reschedule_interrupt | ||
1020 | #endif | ||
864 | 1021 | ||
865 | ENTRY(error_interrupt) | 1022 | apicinterrupt ERROR_APIC_VECTOR \ |
866 | apicinterrupt ERROR_APIC_VECTOR,smp_error_interrupt | 1023 | error_interrupt smp_error_interrupt |
867 | END(error_interrupt) | 1024 | apicinterrupt SPURIOUS_APIC_VECTOR \ |
1025 | spurious_interrupt smp_spurious_interrupt | ||
868 | 1026 | ||
869 | ENTRY(spurious_interrupt) | ||
870 | apicinterrupt SPURIOUS_APIC_VECTOR,smp_spurious_interrupt | ||
871 | END(spurious_interrupt) | ||
872 | |||
873 | /* | 1027 | /* |
874 | * Exception entry points. | 1028 | * Exception entry points. |
875 | */ | 1029 | */ |
876 | .macro zeroentry sym | 1030 | .macro zeroentry sym do_sym |
1031 | ENTRY(\sym) | ||
877 | INTR_FRAME | 1032 | INTR_FRAME |
878 | PARAVIRT_ADJUST_EXCEPTION_FRAME | 1033 | PARAVIRT_ADJUST_EXCEPTION_FRAME |
879 | pushq $0 /* push error code/oldrax */ | 1034 | pushq_cfi $-1 /* ORIG_RAX: no syscall to restart */ |
880 | CFI_ADJUST_CFA_OFFSET 8 | 1035 | subq $15*8,%rsp |
881 | pushq %rax /* push real oldrax to the rdi slot */ | 1036 | CFI_ADJUST_CFA_OFFSET 15*8 |
882 | CFI_ADJUST_CFA_OFFSET 8 | 1037 | call error_entry |
883 | CFI_REL_OFFSET rax,0 | 1038 | DEFAULT_FRAME 0 |
884 | leaq \sym(%rip),%rax | 1039 | movq %rsp,%rdi /* pt_regs pointer */ |
885 | jmp error_entry | 1040 | xorl %esi,%esi /* no error code */ |
1041 | call \do_sym | ||
1042 | jmp error_exit /* %ebx: no swapgs flag */ | ||
886 | CFI_ENDPROC | 1043 | CFI_ENDPROC |
887 | .endm | 1044 | END(\sym) |
1045 | .endm | ||
888 | 1046 | ||
889 | .macro errorentry sym | 1047 | .macro paranoidzeroentry sym do_sym |
890 | XCPT_FRAME | 1048 | ENTRY(\sym) |
1049 | INTR_FRAME | ||
891 | PARAVIRT_ADJUST_EXCEPTION_FRAME | 1050 | PARAVIRT_ADJUST_EXCEPTION_FRAME |
892 | pushq %rax | 1051 | pushq $-1 /* ORIG_RAX: no syscall to restart */ |
893 | CFI_ADJUST_CFA_OFFSET 8 | 1052 | CFI_ADJUST_CFA_OFFSET 8 |
894 | CFI_REL_OFFSET rax,0 | 1053 | subq $15*8, %rsp |
895 | leaq \sym(%rip),%rax | 1054 | call save_paranoid |
896 | jmp error_entry | 1055 | TRACE_IRQS_OFF |
1056 | movq %rsp,%rdi /* pt_regs pointer */ | ||
1057 | xorl %esi,%esi /* no error code */ | ||
1058 | call \do_sym | ||
1059 | jmp paranoid_exit /* %ebx: no swapgs flag */ | ||
897 | CFI_ENDPROC | 1060 | CFI_ENDPROC |
898 | .endm | 1061 | END(\sym) |
1062 | .endm | ||
899 | 1063 | ||
900 | /* error code is on the stack already */ | 1064 | .macro paranoidzeroentry_ist sym do_sym ist |
901 | /* handle NMI like exceptions that can happen everywhere */ | 1065 | ENTRY(\sym) |
902 | .macro paranoidentry sym, ist=0, irqtrace=1 | 1066 | INTR_FRAME |
903 | SAVE_ALL | 1067 | PARAVIRT_ADJUST_EXCEPTION_FRAME |
904 | cld | 1068 | pushq $-1 /* ORIG_RAX: no syscall to restart */ |
905 | movl $1,%ebx | 1069 | CFI_ADJUST_CFA_OFFSET 8 |
906 | movl $MSR_GS_BASE,%ecx | 1070 | subq $15*8, %rsp |
907 | rdmsr | 1071 | call save_paranoid |
908 | testl %edx,%edx | ||
909 | js 1f | ||
910 | SWAPGS | ||
911 | xorl %ebx,%ebx | ||
912 | 1: | ||
913 | .if \ist | ||
914 | movq %gs:pda_data_offset, %rbp | ||
915 | .endif | ||
916 | .if \irqtrace | ||
917 | TRACE_IRQS_OFF | ||
918 | .endif | ||
919 | movq %rsp,%rdi | ||
920 | movq ORIG_RAX(%rsp),%rsi | ||
921 | movq $-1,ORIG_RAX(%rsp) | ||
922 | .if \ist | ||
923 | subq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp) | ||
924 | .endif | ||
925 | call \sym | ||
926 | .if \ist | ||
927 | addq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp) | ||
928 | .endif | ||
929 | DISABLE_INTERRUPTS(CLBR_NONE) | ||
930 | .if \irqtrace | ||
931 | TRACE_IRQS_OFF | 1072 | TRACE_IRQS_OFF |
932 | .endif | 1073 | movq %rsp,%rdi /* pt_regs pointer */ |
933 | .endm | 1074 | xorl %esi,%esi /* no error code */ |
1075 | movq %gs:pda_data_offset, %rbp | ||
1076 | subq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp) | ||
1077 | call \do_sym | ||
1078 | addq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp) | ||
1079 | jmp paranoid_exit /* %ebx: no swapgs flag */ | ||
1080 | CFI_ENDPROC | ||
1081 | END(\sym) | ||
1082 | .endm | ||
934 | 1083 | ||
935 | /* | 1084 | .macro errorentry sym do_sym |
936 | * "Paranoid" exit path from exception stack. | 1085 | ENTRY(\sym) |
937 | * Paranoid because this is used by NMIs and cannot take | 1086 | XCPT_FRAME |
938 | * any kernel state for granted. | 1087 | PARAVIRT_ADJUST_EXCEPTION_FRAME |
939 | * We don't do kernel preemption checks here, because only | 1088 | subq $15*8,%rsp |
940 | * NMI should be common and it does not enable IRQs and | 1089 | CFI_ADJUST_CFA_OFFSET 15*8 |
941 | * cannot get reschedule ticks. | 1090 | call error_entry |
942 | * | 1091 | DEFAULT_FRAME 0 |
943 | * "trace" is 0 for the NMI handler only, because irq-tracing | 1092 | movq %rsp,%rdi /* pt_regs pointer */ |
944 | * is fundamentally NMI-unsafe. (we cannot change the soft and | 1093 | movq ORIG_RAX(%rsp),%rsi /* get error code */ |
945 | * hard flags at once, atomically) | 1094 | movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */ |
946 | */ | 1095 | call \do_sym |
947 | .macro paranoidexit trace=1 | 1096 | jmp error_exit /* %ebx: no swapgs flag */ |
948 | /* ebx: no swapgs flag */ | ||
949 | paranoid_exit\trace: | ||
950 | testl %ebx,%ebx /* swapgs needed? */ | ||
951 | jnz paranoid_restore\trace | ||
952 | testl $3,CS(%rsp) | ||
953 | jnz paranoid_userspace\trace | ||
954 | paranoid_swapgs\trace: | ||
955 | .if \trace | ||
956 | TRACE_IRQS_IRETQ 0 | ||
957 | .endif | ||
958 | SWAPGS_UNSAFE_STACK | ||
959 | paranoid_restore\trace: | ||
960 | RESTORE_ALL 8 | ||
961 | jmp irq_return | ||
962 | paranoid_userspace\trace: | ||
963 | GET_THREAD_INFO(%rcx) | ||
964 | movl TI_flags(%rcx),%ebx | ||
965 | andl $_TIF_WORK_MASK,%ebx | ||
966 | jz paranoid_swapgs\trace | ||
967 | movq %rsp,%rdi /* &pt_regs */ | ||
968 | call sync_regs | ||
969 | movq %rax,%rsp /* switch stack for scheduling */ | ||
970 | testl $_TIF_NEED_RESCHED,%ebx | ||
971 | jnz paranoid_schedule\trace | ||
972 | movl %ebx,%edx /* arg3: thread flags */ | ||
973 | .if \trace | ||
974 | TRACE_IRQS_ON | ||
975 | .endif | ||
976 | ENABLE_INTERRUPTS(CLBR_NONE) | ||
977 | xorl %esi,%esi /* arg2: oldset */ | ||
978 | movq %rsp,%rdi /* arg1: &pt_regs */ | ||
979 | call do_notify_resume | ||
980 | DISABLE_INTERRUPTS(CLBR_NONE) | ||
981 | .if \trace | ||
982 | TRACE_IRQS_OFF | ||
983 | .endif | ||
984 | jmp paranoid_userspace\trace | ||
985 | paranoid_schedule\trace: | ||
986 | .if \trace | ||
987 | TRACE_IRQS_ON | ||
988 | .endif | ||
989 | ENABLE_INTERRUPTS(CLBR_ANY) | ||
990 | call schedule | ||
991 | DISABLE_INTERRUPTS(CLBR_ANY) | ||
992 | .if \trace | ||
993 | TRACE_IRQS_OFF | ||
994 | .endif | ||
995 | jmp paranoid_userspace\trace | ||
996 | CFI_ENDPROC | 1097 | CFI_ENDPROC |
997 | .endm | 1098 | END(\sym) |
1099 | .endm | ||
998 | 1100 | ||
999 | /* | 1101 | /* error code is on the stack already */ |
1000 | * Exception entry point. This expects an error code/orig_rax on the stack | 1102 | .macro paranoiderrorentry sym do_sym |
1001 | * and the exception handler in %rax. | 1103 | ENTRY(\sym) |
1002 | */ | 1104 | XCPT_FRAME |
1003 | KPROBE_ENTRY(error_entry) | 1105 | PARAVIRT_ADJUST_EXCEPTION_FRAME |
1004 | _frame RDI | 1106 | subq $15*8,%rsp |
1005 | CFI_REL_OFFSET rax,0 | 1107 | CFI_ADJUST_CFA_OFFSET 15*8 |
1006 | /* rdi slot contains rax, oldrax contains error code */ | 1108 | call save_paranoid |
1007 | cld | 1109 | DEFAULT_FRAME 0 |
1008 | subq $14*8,%rsp | ||
1009 | CFI_ADJUST_CFA_OFFSET (14*8) | ||
1010 | movq %rsi,13*8(%rsp) | ||
1011 | CFI_REL_OFFSET rsi,RSI | ||
1012 | movq 14*8(%rsp),%rsi /* load rax from rdi slot */ | ||
1013 | CFI_REGISTER rax,rsi | ||
1014 | movq %rdx,12*8(%rsp) | ||
1015 | CFI_REL_OFFSET rdx,RDX | ||
1016 | movq %rcx,11*8(%rsp) | ||
1017 | CFI_REL_OFFSET rcx,RCX | ||
1018 | movq %rsi,10*8(%rsp) /* store rax */ | ||
1019 | CFI_REL_OFFSET rax,RAX | ||
1020 | movq %r8, 9*8(%rsp) | ||
1021 | CFI_REL_OFFSET r8,R8 | ||
1022 | movq %r9, 8*8(%rsp) | ||
1023 | CFI_REL_OFFSET r9,R9 | ||
1024 | movq %r10,7*8(%rsp) | ||
1025 | CFI_REL_OFFSET r10,R10 | ||
1026 | movq %r11,6*8(%rsp) | ||
1027 | CFI_REL_OFFSET r11,R11 | ||
1028 | movq %rbx,5*8(%rsp) | ||
1029 | CFI_REL_OFFSET rbx,RBX | ||
1030 | movq %rbp,4*8(%rsp) | ||
1031 | CFI_REL_OFFSET rbp,RBP | ||
1032 | movq %r12,3*8(%rsp) | ||
1033 | CFI_REL_OFFSET r12,R12 | ||
1034 | movq %r13,2*8(%rsp) | ||
1035 | CFI_REL_OFFSET r13,R13 | ||
1036 | movq %r14,1*8(%rsp) | ||
1037 | CFI_REL_OFFSET r14,R14 | ||
1038 | movq %r15,(%rsp) | ||
1039 | CFI_REL_OFFSET r15,R15 | ||
1040 | xorl %ebx,%ebx | ||
1041 | testl $3,CS(%rsp) | ||
1042 | je error_kernelspace | ||
1043 | error_swapgs: | ||
1044 | SWAPGS | ||
1045 | error_sti: | ||
1046 | TRACE_IRQS_OFF | ||
1047 | movq %rdi,RDI(%rsp) | ||
1048 | CFI_REL_OFFSET rdi,RDI | ||
1049 | movq %rsp,%rdi | ||
1050 | movq ORIG_RAX(%rsp),%rsi /* get error code */ | ||
1051 | movq $-1,ORIG_RAX(%rsp) | ||
1052 | call *%rax | ||
1053 | /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */ | ||
1054 | error_exit: | ||
1055 | movl %ebx,%eax | ||
1056 | RESTORE_REST | ||
1057 | DISABLE_INTERRUPTS(CLBR_NONE) | ||
1058 | TRACE_IRQS_OFF | 1110 | TRACE_IRQS_OFF |
1059 | GET_THREAD_INFO(%rcx) | 1111 | movq %rsp,%rdi /* pt_regs pointer */ |
1060 | testl %eax,%eax | 1112 | movq ORIG_RAX(%rsp),%rsi /* get error code */ |
1061 | jne retint_kernel | 1113 | movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */ |
1062 | LOCKDEP_SYS_EXIT_IRQ | 1114 | call \do_sym |
1063 | movl TI_flags(%rcx),%edx | 1115 | jmp paranoid_exit /* %ebx: no swapgs flag */ |
1064 | movl $_TIF_WORK_MASK,%edi | ||
1065 | andl %edi,%edx | ||
1066 | jnz retint_careful | ||
1067 | jmp retint_swapgs | ||
1068 | CFI_ENDPROC | 1116 | CFI_ENDPROC |
1117 | END(\sym) | ||
1118 | .endm | ||
1069 | 1119 | ||
1070 | error_kernelspace: | 1120 | zeroentry divide_error do_divide_error |
1071 | incl %ebx | 1121 | zeroentry overflow do_overflow |
1072 | /* There are two places in the kernel that can potentially fault with | 1122 | zeroentry bounds do_bounds |
1073 | usergs. Handle them here. The exception handlers after | 1123 | zeroentry invalid_op do_invalid_op |
1074 | iret run with kernel gs again, so don't set the user space flag. | 1124 | zeroentry device_not_available do_device_not_available |
1075 | B stepping K8s sometimes report an truncated RIP for IRET | 1125 | paranoiderrorentry double_fault do_double_fault |
1076 | exceptions returning to compat mode. Check for these here too. */ | 1126 | zeroentry coprocessor_segment_overrun do_coprocessor_segment_overrun |
1077 | leaq irq_return(%rip),%rcx | 1127 | errorentry invalid_TSS do_invalid_TSS |
1078 | cmpq %rcx,RIP(%rsp) | 1128 | errorentry segment_not_present do_segment_not_present |
1079 | je error_swapgs | 1129 | zeroentry spurious_interrupt_bug do_spurious_interrupt_bug |
1080 | movl %ecx,%ecx /* zero extend */ | 1130 | zeroentry coprocessor_error do_coprocessor_error |
1081 | cmpq %rcx,RIP(%rsp) | 1131 | errorentry alignment_check do_alignment_check |
1082 | je error_swapgs | 1132 | zeroentry simd_coprocessor_error do_simd_coprocessor_error |
1083 | cmpq $gs_change,RIP(%rsp) | 1133 | |
1084 | je error_swapgs | 1134 | /* Reload gs selector with exception handling */ |
1085 | jmp error_sti | 1135 | /* edi: new selector */ |
1086 | KPROBE_END(error_entry) | ||
1087 | |||
1088 | /* Reload gs selector with exception handling */ | ||
1089 | /* edi: new selector */ | ||
1090 | ENTRY(native_load_gs_index) | 1136 | ENTRY(native_load_gs_index) |
1091 | CFI_STARTPROC | 1137 | CFI_STARTPROC |
1092 | pushf | 1138 | pushf |
1093 | CFI_ADJUST_CFA_OFFSET 8 | 1139 | CFI_ADJUST_CFA_OFFSET 8 |
1094 | DISABLE_INTERRUPTS(CLBR_ANY | ~(CLBR_RDI)) | 1140 | DISABLE_INTERRUPTS(CLBR_ANY | ~(CLBR_RDI)) |
1095 | SWAPGS | 1141 | SWAPGS |
1096 | gs_change: | 1142 | gs_change: |
1097 | movl %edi,%gs | 1143 | movl %edi,%gs |
1098 | 2: mfence /* workaround */ | 1144 | 2: mfence /* workaround */ |
1099 | SWAPGS | 1145 | SWAPGS |
1100 | popf | 1146 | popf |
1101 | CFI_ADJUST_CFA_OFFSET -8 | 1147 | CFI_ADJUST_CFA_OFFSET -8 |
1102 | ret | 1148 | ret |
1103 | CFI_ENDPROC | 1149 | CFI_ENDPROC |
1104 | ENDPROC(native_load_gs_index) | 1150 | END(native_load_gs_index) |
1105 | 1151 | ||
1106 | .section __ex_table,"a" | 1152 | .section __ex_table,"a" |
1107 | .align 8 | 1153 | .align 8 |
1108 | .quad gs_change,bad_gs | 1154 | .quad gs_change,bad_gs |
1109 | .previous | 1155 | .previous |
1110 | .section .fixup,"ax" | 1156 | .section .fixup,"ax" |
1111 | /* running with kernelgs */ | 1157 | /* running with kernelgs */ |
1112 | bad_gs: | 1158 | bad_gs: |
1113 | SWAPGS /* switch back to user gs */ | 1159 | SWAPGS /* switch back to user gs */ |
1114 | xorl %eax,%eax | 1160 | xorl %eax,%eax |
1115 | movl %eax,%gs | 1161 | movl %eax,%gs |
1116 | jmp 2b | 1162 | jmp 2b |
1117 | .previous | 1163 | .previous |
1118 | 1164 | ||
1119 | /* | 1165 | /* |
1120 | * Create a kernel thread. | 1166 | * Create a kernel thread. |
1121 | * | 1167 | * |
@@ -1138,7 +1184,7 @@ ENTRY(kernel_thread) | |||
1138 | 1184 | ||
1139 | xorl %r8d,%r8d | 1185 | xorl %r8d,%r8d |
1140 | xorl %r9d,%r9d | 1186 | xorl %r9d,%r9d |
1141 | 1187 | ||
1142 | # clone now | 1188 | # clone now |
1143 | call do_fork | 1189 | call do_fork |
1144 | movq %rax,RAX(%rsp) | 1190 | movq %rax,RAX(%rsp) |
@@ -1149,15 +1195,15 @@ ENTRY(kernel_thread) | |||
1149 | * so internally to the x86_64 port you can rely on kernel_thread() | 1195 | * so internally to the x86_64 port you can rely on kernel_thread() |
1150 | * not to reschedule the child before returning, this avoids the need | 1196 | * not to reschedule the child before returning, this avoids the need |
1151 | * of hacks for example to fork off the per-CPU idle tasks. | 1197 | * of hacks for example to fork off the per-CPU idle tasks. |
1152 | * [Hopefully no generic code relies on the reschedule -AK] | 1198 | * [Hopefully no generic code relies on the reschedule -AK] |
1153 | */ | 1199 | */ |
1154 | RESTORE_ALL | 1200 | RESTORE_ALL |
1155 | UNFAKE_STACK_FRAME | 1201 | UNFAKE_STACK_FRAME |
1156 | ret | 1202 | ret |
1157 | CFI_ENDPROC | 1203 | CFI_ENDPROC |
1158 | ENDPROC(kernel_thread) | 1204 | END(kernel_thread) |
1159 | 1205 | ||
1160 | child_rip: | 1206 | ENTRY(child_rip) |
1161 | pushq $0 # fake return address | 1207 | pushq $0 # fake return address |
1162 | CFI_STARTPROC | 1208 | CFI_STARTPROC |
1163 | /* | 1209 | /* |
@@ -1170,8 +1216,9 @@ child_rip: | |||
1170 | # exit | 1216 | # exit |
1171 | mov %eax, %edi | 1217 | mov %eax, %edi |
1172 | call do_exit | 1218 | call do_exit |
1219 | ud2 # padding for call trace | ||
1173 | CFI_ENDPROC | 1220 | CFI_ENDPROC |
1174 | ENDPROC(child_rip) | 1221 | END(child_rip) |
1175 | 1222 | ||
1176 | /* | 1223 | /* |
1177 | * execve(). This function needs to use IRET, not SYSRET, to set up all state properly. | 1224 | * execve(). This function needs to use IRET, not SYSRET, to set up all state properly. |
@@ -1191,10 +1238,10 @@ ENDPROC(child_rip) | |||
1191 | ENTRY(kernel_execve) | 1238 | ENTRY(kernel_execve) |
1192 | CFI_STARTPROC | 1239 | CFI_STARTPROC |
1193 | FAKE_STACK_FRAME $0 | 1240 | FAKE_STACK_FRAME $0 |
1194 | SAVE_ALL | 1241 | SAVE_ALL |
1195 | movq %rsp,%rcx | 1242 | movq %rsp,%rcx |
1196 | call sys_execve | 1243 | call sys_execve |
1197 | movq %rax, RAX(%rsp) | 1244 | movq %rax, RAX(%rsp) |
1198 | RESTORE_REST | 1245 | RESTORE_REST |
1199 | testq %rax,%rax | 1246 | testq %rax,%rax |
1200 | je int_ret_from_sys_call | 1247 | je int_ret_from_sys_call |
@@ -1202,129 +1249,7 @@ ENTRY(kernel_execve) | |||
1202 | UNFAKE_STACK_FRAME | 1249 | UNFAKE_STACK_FRAME |
1203 | ret | 1250 | ret |
1204 | CFI_ENDPROC | 1251 | CFI_ENDPROC |
1205 | ENDPROC(kernel_execve) | 1252 | END(kernel_execve) |
1206 | |||
1207 | KPROBE_ENTRY(page_fault) | ||
1208 | errorentry do_page_fault | ||
1209 | KPROBE_END(page_fault) | ||
1210 | |||
1211 | ENTRY(coprocessor_error) | ||
1212 | zeroentry do_coprocessor_error | ||
1213 | END(coprocessor_error) | ||
1214 | |||
1215 | ENTRY(simd_coprocessor_error) | ||
1216 | zeroentry do_simd_coprocessor_error | ||
1217 | END(simd_coprocessor_error) | ||
1218 | |||
1219 | ENTRY(device_not_available) | ||
1220 | zeroentry do_device_not_available | ||
1221 | END(device_not_available) | ||
1222 | |||
1223 | /* runs on exception stack */ | ||
1224 | KPROBE_ENTRY(debug) | ||
1225 | INTR_FRAME | ||
1226 | PARAVIRT_ADJUST_EXCEPTION_FRAME | ||
1227 | pushq $0 | ||
1228 | CFI_ADJUST_CFA_OFFSET 8 | ||
1229 | paranoidentry do_debug, DEBUG_STACK | ||
1230 | paranoidexit | ||
1231 | KPROBE_END(debug) | ||
1232 | |||
1233 | /* runs on exception stack */ | ||
1234 | KPROBE_ENTRY(nmi) | ||
1235 | INTR_FRAME | ||
1236 | PARAVIRT_ADJUST_EXCEPTION_FRAME | ||
1237 | pushq $-1 | ||
1238 | CFI_ADJUST_CFA_OFFSET 8 | ||
1239 | paranoidentry do_nmi, 0, 0 | ||
1240 | #ifdef CONFIG_TRACE_IRQFLAGS | ||
1241 | paranoidexit 0 | ||
1242 | #else | ||
1243 | jmp paranoid_exit1 | ||
1244 | CFI_ENDPROC | ||
1245 | #endif | ||
1246 | KPROBE_END(nmi) | ||
1247 | |||
1248 | KPROBE_ENTRY(int3) | ||
1249 | INTR_FRAME | ||
1250 | PARAVIRT_ADJUST_EXCEPTION_FRAME | ||
1251 | pushq $0 | ||
1252 | CFI_ADJUST_CFA_OFFSET 8 | ||
1253 | paranoidentry do_int3, DEBUG_STACK | ||
1254 | jmp paranoid_exit1 | ||
1255 | CFI_ENDPROC | ||
1256 | KPROBE_END(int3) | ||
1257 | |||
1258 | ENTRY(overflow) | ||
1259 | zeroentry do_overflow | ||
1260 | END(overflow) | ||
1261 | |||
1262 | ENTRY(bounds) | ||
1263 | zeroentry do_bounds | ||
1264 | END(bounds) | ||
1265 | |||
1266 | ENTRY(invalid_op) | ||
1267 | zeroentry do_invalid_op | ||
1268 | END(invalid_op) | ||
1269 | |||
1270 | ENTRY(coprocessor_segment_overrun) | ||
1271 | zeroentry do_coprocessor_segment_overrun | ||
1272 | END(coprocessor_segment_overrun) | ||
1273 | |||
1274 | /* runs on exception stack */ | ||
1275 | ENTRY(double_fault) | ||
1276 | XCPT_FRAME | ||
1277 | PARAVIRT_ADJUST_EXCEPTION_FRAME | ||
1278 | paranoidentry do_double_fault | ||
1279 | jmp paranoid_exit1 | ||
1280 | CFI_ENDPROC | ||
1281 | END(double_fault) | ||
1282 | |||
1283 | ENTRY(invalid_TSS) | ||
1284 | errorentry do_invalid_TSS | ||
1285 | END(invalid_TSS) | ||
1286 | |||
1287 | ENTRY(segment_not_present) | ||
1288 | errorentry do_segment_not_present | ||
1289 | END(segment_not_present) | ||
1290 | |||
1291 | /* runs on exception stack */ | ||
1292 | ENTRY(stack_segment) | ||
1293 | XCPT_FRAME | ||
1294 | PARAVIRT_ADJUST_EXCEPTION_FRAME | ||
1295 | paranoidentry do_stack_segment | ||
1296 | jmp paranoid_exit1 | ||
1297 | CFI_ENDPROC | ||
1298 | END(stack_segment) | ||
1299 | |||
1300 | KPROBE_ENTRY(general_protection) | ||
1301 | errorentry do_general_protection | ||
1302 | KPROBE_END(general_protection) | ||
1303 | |||
1304 | ENTRY(alignment_check) | ||
1305 | errorentry do_alignment_check | ||
1306 | END(alignment_check) | ||
1307 | |||
1308 | ENTRY(divide_error) | ||
1309 | zeroentry do_divide_error | ||
1310 | END(divide_error) | ||
1311 | |||
1312 | ENTRY(spurious_interrupt_bug) | ||
1313 | zeroentry do_spurious_interrupt_bug | ||
1314 | END(spurious_interrupt_bug) | ||
1315 | |||
1316 | #ifdef CONFIG_X86_MCE | ||
1317 | /* runs on exception stack */ | ||
1318 | ENTRY(machine_check) | ||
1319 | INTR_FRAME | ||
1320 | PARAVIRT_ADJUST_EXCEPTION_FRAME | ||
1321 | pushq $0 | ||
1322 | CFI_ADJUST_CFA_OFFSET 8 | ||
1323 | paranoidentry do_machine_check | ||
1324 | jmp paranoid_exit1 | ||
1325 | CFI_ENDPROC | ||
1326 | END(machine_check) | ||
1327 | #endif | ||
1328 | 1253 | ||
1329 | /* Call softirq on interrupt stack. Interrupts are off. */ | 1254 | /* Call softirq on interrupt stack. Interrupts are off. */ |
1330 | ENTRY(call_softirq) | 1255 | ENTRY(call_softirq) |
@@ -1344,40 +1269,33 @@ ENTRY(call_softirq) | |||
1344 | decl %gs:pda_irqcount | 1269 | decl %gs:pda_irqcount |
1345 | ret | 1270 | ret |
1346 | CFI_ENDPROC | 1271 | CFI_ENDPROC |
1347 | ENDPROC(call_softirq) | 1272 | END(call_softirq) |
1348 | |||
1349 | KPROBE_ENTRY(ignore_sysret) | ||
1350 | CFI_STARTPROC | ||
1351 | mov $-ENOSYS,%eax | ||
1352 | sysret | ||
1353 | CFI_ENDPROC | ||
1354 | ENDPROC(ignore_sysret) | ||
1355 | 1273 | ||
1356 | #ifdef CONFIG_XEN | 1274 | #ifdef CONFIG_XEN |
1357 | ENTRY(xen_hypervisor_callback) | 1275 | zeroentry xen_hypervisor_callback xen_do_hypervisor_callback |
1358 | zeroentry xen_do_hypervisor_callback | ||
1359 | END(xen_hypervisor_callback) | ||
1360 | 1276 | ||
1361 | /* | 1277 | /* |
1362 | # A note on the "critical region" in our callback handler. | 1278 | * A note on the "critical region" in our callback handler. |
1363 | # We want to avoid stacking callback handlers due to events occurring | 1279 | * We want to avoid stacking callback handlers due to events occurring |
1364 | # during handling of the last event. To do this, we keep events disabled | 1280 | * during handling of the last event. To do this, we keep events disabled |
1365 | # until we've done all processing. HOWEVER, we must enable events before | 1281 | * until we've done all processing. HOWEVER, we must enable events before |
1366 | # popping the stack frame (can't be done atomically) and so it would still | 1282 | * popping the stack frame (can't be done atomically) and so it would still |
1367 | # be possible to get enough handler activations to overflow the stack. | 1283 | * be possible to get enough handler activations to overflow the stack. |
1368 | # Although unlikely, bugs of that kind are hard to track down, so we'd | 1284 | * Although unlikely, bugs of that kind are hard to track down, so we'd |
1369 | # like to avoid the possibility. | 1285 | * like to avoid the possibility. |
1370 | # So, on entry to the handler we detect whether we interrupted an | 1286 | * So, on entry to the handler we detect whether we interrupted an |
1371 | # existing activation in its critical region -- if so, we pop the current | 1287 | * existing activation in its critical region -- if so, we pop the current |
1372 | # activation and restart the handler using the previous one. | 1288 | * activation and restart the handler using the previous one. |
1373 | */ | 1289 | */ |
1374 | ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs) | 1290 | ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs) |
1375 | CFI_STARTPROC | 1291 | CFI_STARTPROC |
1376 | /* Since we don't modify %rdi, evtchn_do_upall(struct *pt_regs) will | 1292 | /* |
1377 | see the correct pointer to the pt_regs */ | 1293 | * Since we don't modify %rdi, evtchn_do_upall(struct *pt_regs) will |
1294 | * see the correct pointer to the pt_regs | ||
1295 | */ | ||
1378 | movq %rdi, %rsp # we don't return, adjust the stack frame | 1296 | movq %rdi, %rsp # we don't return, adjust the stack frame |
1379 | CFI_ENDPROC | 1297 | CFI_ENDPROC |
1380 | CFI_DEFAULT_STACK | 1298 | DEFAULT_FRAME |
1381 | 11: incl %gs:pda_irqcount | 1299 | 11: incl %gs:pda_irqcount |
1382 | movq %rsp,%rbp | 1300 | movq %rsp,%rbp |
1383 | CFI_DEF_CFA_REGISTER rbp | 1301 | CFI_DEF_CFA_REGISTER rbp |
@@ -1392,23 +1310,26 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs) | |||
1392 | END(do_hypervisor_callback) | 1310 | END(do_hypervisor_callback) |
1393 | 1311 | ||
1394 | /* | 1312 | /* |
1395 | # Hypervisor uses this for application faults while it executes. | 1313 | * Hypervisor uses this for application faults while it executes. |
1396 | # We get here for two reasons: | 1314 | * We get here for two reasons: |
1397 | # 1. Fault while reloading DS, ES, FS or GS | 1315 | * 1. Fault while reloading DS, ES, FS or GS |
1398 | # 2. Fault while executing IRET | 1316 | * 2. Fault while executing IRET |
1399 | # Category 1 we do not need to fix up as Xen has already reloaded all segment | 1317 | * Category 1 we do not need to fix up as Xen has already reloaded all segment |
1400 | # registers that could be reloaded and zeroed the others. | 1318 | * registers that could be reloaded and zeroed the others. |
1401 | # Category 2 we fix up by killing the current process. We cannot use the | 1319 | * Category 2 we fix up by killing the current process. We cannot use the |
1402 | # normal Linux return path in this case because if we use the IRET hypercall | 1320 | * normal Linux return path in this case because if we use the IRET hypercall |
1403 | # to pop the stack frame we end up in an infinite loop of failsafe callbacks. | 1321 | * to pop the stack frame we end up in an infinite loop of failsafe callbacks. |
1404 | # We distinguish between categories by comparing each saved segment register | 1322 | * We distinguish between categories by comparing each saved segment register |
1405 | # with its current contents: any discrepancy means we in category 1. | 1323 | * with its current contents: any discrepancy means we in category 1. |
1406 | */ | 1324 | */ |
1407 | ENTRY(xen_failsafe_callback) | 1325 | ENTRY(xen_failsafe_callback) |
1408 | framesz = (RIP-0x30) /* workaround buggy gas */ | 1326 | INTR_FRAME 1 (6*8) |
1409 | _frame framesz | 1327 | /*CFI_REL_OFFSET gs,GS*/ |
1410 | CFI_REL_OFFSET rcx, 0 | 1328 | /*CFI_REL_OFFSET fs,FS*/ |
1411 | CFI_REL_OFFSET r11, 8 | 1329 | /*CFI_REL_OFFSET es,ES*/ |
1330 | /*CFI_REL_OFFSET ds,DS*/ | ||
1331 | CFI_REL_OFFSET r11,8 | ||
1332 | CFI_REL_OFFSET rcx,0 | ||
1412 | movw %ds,%cx | 1333 | movw %ds,%cx |
1413 | cmpw %cx,0x10(%rsp) | 1334 | cmpw %cx,0x10(%rsp) |
1414 | CFI_REMEMBER_STATE | 1335 | CFI_REMEMBER_STATE |
@@ -1429,12 +1350,9 @@ ENTRY(xen_failsafe_callback) | |||
1429 | CFI_RESTORE r11 | 1350 | CFI_RESTORE r11 |
1430 | addq $0x30,%rsp | 1351 | addq $0x30,%rsp |
1431 | CFI_ADJUST_CFA_OFFSET -0x30 | 1352 | CFI_ADJUST_CFA_OFFSET -0x30 |
1432 | pushq $0 | 1353 | pushq_cfi $0 /* RIP */ |
1433 | CFI_ADJUST_CFA_OFFSET 8 | 1354 | pushq_cfi %r11 |
1434 | pushq %r11 | 1355 | pushq_cfi %rcx |
1435 | CFI_ADJUST_CFA_OFFSET 8 | ||
1436 | pushq %rcx | ||
1437 | CFI_ADJUST_CFA_OFFSET 8 | ||
1438 | jmp general_protection | 1356 | jmp general_protection |
1439 | CFI_RESTORE_STATE | 1357 | CFI_RESTORE_STATE |
1440 | 1: /* Segment mismatch => Category 1 (Bad segment). Retry the IRET. */ | 1358 | 1: /* Segment mismatch => Category 1 (Bad segment). Retry the IRET. */ |
@@ -1444,11 +1362,223 @@ ENTRY(xen_failsafe_callback) | |||
1444 | CFI_RESTORE r11 | 1362 | CFI_RESTORE r11 |
1445 | addq $0x30,%rsp | 1363 | addq $0x30,%rsp |
1446 | CFI_ADJUST_CFA_OFFSET -0x30 | 1364 | CFI_ADJUST_CFA_OFFSET -0x30 |
1447 | pushq $0 | 1365 | pushq_cfi $0 |
1448 | CFI_ADJUST_CFA_OFFSET 8 | ||
1449 | SAVE_ALL | 1366 | SAVE_ALL |
1450 | jmp error_exit | 1367 | jmp error_exit |
1451 | CFI_ENDPROC | 1368 | CFI_ENDPROC |
1452 | END(xen_failsafe_callback) | 1369 | END(xen_failsafe_callback) |
1453 | 1370 | ||
1454 | #endif /* CONFIG_XEN */ | 1371 | #endif /* CONFIG_XEN */ |
1372 | |||
1373 | /* | ||
1374 | * Some functions should be protected against kprobes | ||
1375 | */ | ||
1376 | .pushsection .kprobes.text, "ax" | ||
1377 | |||
1378 | paranoidzeroentry_ist debug do_debug DEBUG_STACK | ||
1379 | paranoidzeroentry_ist int3 do_int3 DEBUG_STACK | ||
1380 | paranoiderrorentry stack_segment do_stack_segment | ||
1381 | errorentry general_protection do_general_protection | ||
1382 | errorentry page_fault do_page_fault | ||
1383 | #ifdef CONFIG_X86_MCE | ||
1384 | paranoidzeroentry machine_check do_machine_check | ||
1385 | #endif | ||
1386 | |||
1387 | /* | ||
1388 | * "Paranoid" exit path from exception stack. | ||
1389 | * Paranoid because this is used by NMIs and cannot take | ||
1390 | * any kernel state for granted. | ||
1391 | * We don't do kernel preemption checks here, because only | ||
1392 | * NMI should be common and it does not enable IRQs and | ||
1393 | * cannot get reschedule ticks. | ||
1394 | * | ||
1395 | * "trace" is 0 for the NMI handler only, because irq-tracing | ||
1396 | * is fundamentally NMI-unsafe. (we cannot change the soft and | ||
1397 | * hard flags at once, atomically) | ||
1398 | */ | ||
1399 | |||
1400 | /* ebx: no swapgs flag */ | ||
1401 | ENTRY(paranoid_exit) | ||
1402 | INTR_FRAME | ||
1403 | DISABLE_INTERRUPTS(CLBR_NONE) | ||
1404 | TRACE_IRQS_OFF | ||
1405 | testl %ebx,%ebx /* swapgs needed? */ | ||
1406 | jnz paranoid_restore | ||
1407 | testl $3,CS(%rsp) | ||
1408 | jnz paranoid_userspace | ||
1409 | paranoid_swapgs: | ||
1410 | TRACE_IRQS_IRETQ 0 | ||
1411 | SWAPGS_UNSAFE_STACK | ||
1412 | paranoid_restore: | ||
1413 | RESTORE_ALL 8 | ||
1414 | jmp irq_return | ||
1415 | paranoid_userspace: | ||
1416 | GET_THREAD_INFO(%rcx) | ||
1417 | movl TI_flags(%rcx),%ebx | ||
1418 | andl $_TIF_WORK_MASK,%ebx | ||
1419 | jz paranoid_swapgs | ||
1420 | movq %rsp,%rdi /* &pt_regs */ | ||
1421 | call sync_regs | ||
1422 | movq %rax,%rsp /* switch stack for scheduling */ | ||
1423 | testl $_TIF_NEED_RESCHED,%ebx | ||
1424 | jnz paranoid_schedule | ||
1425 | movl %ebx,%edx /* arg3: thread flags */ | ||
1426 | TRACE_IRQS_ON | ||
1427 | ENABLE_INTERRUPTS(CLBR_NONE) | ||
1428 | xorl %esi,%esi /* arg2: oldset */ | ||
1429 | movq %rsp,%rdi /* arg1: &pt_regs */ | ||
1430 | call do_notify_resume | ||
1431 | DISABLE_INTERRUPTS(CLBR_NONE) | ||
1432 | TRACE_IRQS_OFF | ||
1433 | jmp paranoid_userspace | ||
1434 | paranoid_schedule: | ||
1435 | TRACE_IRQS_ON | ||
1436 | ENABLE_INTERRUPTS(CLBR_ANY) | ||
1437 | call schedule | ||
1438 | DISABLE_INTERRUPTS(CLBR_ANY) | ||
1439 | TRACE_IRQS_OFF | ||
1440 | jmp paranoid_userspace | ||
1441 | CFI_ENDPROC | ||
1442 | END(paranoid_exit) | ||
1443 | |||
1444 | /* | ||
1445 | * Exception entry point. This expects an error code/orig_rax on the stack. | ||
1446 | * returns in "no swapgs flag" in %ebx. | ||
1447 | */ | ||
1448 | ENTRY(error_entry) | ||
1449 | XCPT_FRAME | ||
1450 | CFI_ADJUST_CFA_OFFSET 15*8 | ||
1451 | /* oldrax contains error code */ | ||
1452 | cld | ||
1453 | movq_cfi rdi, RDI+8 | ||
1454 | movq_cfi rsi, RSI+8 | ||
1455 | movq_cfi rdx, RDX+8 | ||
1456 | movq_cfi rcx, RCX+8 | ||
1457 | movq_cfi rax, RAX+8 | ||
1458 | movq_cfi r8, R8+8 | ||
1459 | movq_cfi r9, R9+8 | ||
1460 | movq_cfi r10, R10+8 | ||
1461 | movq_cfi r11, R11+8 | ||
1462 | movq_cfi rbx, RBX+8 | ||
1463 | movq_cfi rbp, RBP+8 | ||
1464 | movq_cfi r12, R12+8 | ||
1465 | movq_cfi r13, R13+8 | ||
1466 | movq_cfi r14, R14+8 | ||
1467 | movq_cfi r15, R15+8 | ||
1468 | xorl %ebx,%ebx | ||
1469 | testl $3,CS+8(%rsp) | ||
1470 | je error_kernelspace | ||
1471 | error_swapgs: | ||
1472 | SWAPGS | ||
1473 | error_sti: | ||
1474 | TRACE_IRQS_OFF | ||
1475 | ret | ||
1476 | CFI_ENDPROC | ||
1477 | |||
1478 | /* | ||
1479 | * There are two places in the kernel that can potentially fault with | ||
1480 | * usergs. Handle them here. The exception handlers after iret run with | ||
1481 | * kernel gs again, so don't set the user space flag. B stepping K8s | ||
1482 | * sometimes report an truncated RIP for IRET exceptions returning to | ||
1483 | * compat mode. Check for these here too. | ||
1484 | */ | ||
1485 | error_kernelspace: | ||
1486 | incl %ebx | ||
1487 | leaq irq_return(%rip),%rcx | ||
1488 | cmpq %rcx,RIP+8(%rsp) | ||
1489 | je error_swapgs | ||
1490 | movl %ecx,%ecx /* zero extend */ | ||
1491 | cmpq %rcx,RIP+8(%rsp) | ||
1492 | je error_swapgs | ||
1493 | cmpq $gs_change,RIP+8(%rsp) | ||
1494 | je error_swapgs | ||
1495 | jmp error_sti | ||
1496 | END(error_entry) | ||
1497 | |||
1498 | |||
1499 | /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */ | ||
1500 | ENTRY(error_exit) | ||
1501 | DEFAULT_FRAME | ||
1502 | movl %ebx,%eax | ||
1503 | RESTORE_REST | ||
1504 | DISABLE_INTERRUPTS(CLBR_NONE) | ||
1505 | TRACE_IRQS_OFF | ||
1506 | GET_THREAD_INFO(%rcx) | ||
1507 | testl %eax,%eax | ||
1508 | jne retint_kernel | ||
1509 | LOCKDEP_SYS_EXIT_IRQ | ||
1510 | movl TI_flags(%rcx),%edx | ||
1511 | movl $_TIF_WORK_MASK,%edi | ||
1512 | andl %edi,%edx | ||
1513 | jnz retint_careful | ||
1514 | jmp retint_swapgs | ||
1515 | CFI_ENDPROC | ||
1516 | END(error_exit) | ||
1517 | |||
1518 | |||
1519 | /* runs on exception stack */ | ||
1520 | ENTRY(nmi) | ||
1521 | INTR_FRAME | ||
1522 | PARAVIRT_ADJUST_EXCEPTION_FRAME | ||
1523 | pushq_cfi $-1 | ||
1524 | subq $15*8, %rsp | ||
1525 | CFI_ADJUST_CFA_OFFSET 15*8 | ||
1526 | call save_paranoid | ||
1527 | DEFAULT_FRAME 0 | ||
1528 | /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */ | ||
1529 | movq %rsp,%rdi | ||
1530 | movq $-1,%rsi | ||
1531 | call do_nmi | ||
1532 | #ifdef CONFIG_TRACE_IRQFLAGS | ||
1533 | /* paranoidexit; without TRACE_IRQS_OFF */ | ||
1534 | /* ebx: no swapgs flag */ | ||
1535 | DISABLE_INTERRUPTS(CLBR_NONE) | ||
1536 | testl %ebx,%ebx /* swapgs needed? */ | ||
1537 | jnz nmi_restore | ||
1538 | testl $3,CS(%rsp) | ||
1539 | jnz nmi_userspace | ||
1540 | nmi_swapgs: | ||
1541 | SWAPGS_UNSAFE_STACK | ||
1542 | nmi_restore: | ||
1543 | RESTORE_ALL 8 | ||
1544 | jmp irq_return | ||
1545 | nmi_userspace: | ||
1546 | GET_THREAD_INFO(%rcx) | ||
1547 | movl TI_flags(%rcx),%ebx | ||
1548 | andl $_TIF_WORK_MASK,%ebx | ||
1549 | jz nmi_swapgs | ||
1550 | movq %rsp,%rdi /* &pt_regs */ | ||
1551 | call sync_regs | ||
1552 | movq %rax,%rsp /* switch stack for scheduling */ | ||
1553 | testl $_TIF_NEED_RESCHED,%ebx | ||
1554 | jnz nmi_schedule | ||
1555 | movl %ebx,%edx /* arg3: thread flags */ | ||
1556 | ENABLE_INTERRUPTS(CLBR_NONE) | ||
1557 | xorl %esi,%esi /* arg2: oldset */ | ||
1558 | movq %rsp,%rdi /* arg1: &pt_regs */ | ||
1559 | call do_notify_resume | ||
1560 | DISABLE_INTERRUPTS(CLBR_NONE) | ||
1561 | jmp nmi_userspace | ||
1562 | nmi_schedule: | ||
1563 | ENABLE_INTERRUPTS(CLBR_ANY) | ||
1564 | call schedule | ||
1565 | DISABLE_INTERRUPTS(CLBR_ANY) | ||
1566 | jmp nmi_userspace | ||
1567 | CFI_ENDPROC | ||
1568 | #else | ||
1569 | jmp paranoid_exit | ||
1570 | CFI_ENDPROC | ||
1571 | #endif | ||
1572 | END(nmi) | ||
1573 | |||
1574 | ENTRY(ignore_sysret) | ||
1575 | CFI_STARTPROC | ||
1576 | mov $-ENOSYS,%eax | ||
1577 | sysret | ||
1578 | CFI_ENDPROC | ||
1579 | END(ignore_sysret) | ||
1580 | |||
1581 | /* | ||
1582 | * End of kprobes section | ||
1583 | */ | ||
1584 | .popsection | ||
diff --git a/arch/x86/kernel/es7000_32.c b/arch/x86/kernel/es7000_32.c index 0aa2c443d600..53699c931ad4 100644 --- a/arch/x86/kernel/es7000_32.c +++ b/arch/x86/kernel/es7000_32.c | |||
@@ -38,8 +38,11 @@ | |||
38 | #include <asm/io.h> | 38 | #include <asm/io.h> |
39 | #include <asm/nmi.h> | 39 | #include <asm/nmi.h> |
40 | #include <asm/smp.h> | 40 | #include <asm/smp.h> |
41 | #include <asm/atomic.h> | ||
41 | #include <asm/apicdef.h> | 42 | #include <asm/apicdef.h> |
42 | #include <mach_mpparse.h> | 43 | #include <mach_mpparse.h> |
44 | #include <asm/genapic.h> | ||
45 | #include <asm/setup.h> | ||
43 | 46 | ||
44 | /* | 47 | /* |
45 | * ES7000 chipsets | 48 | * ES7000 chipsets |
@@ -161,6 +164,43 @@ es7000_rename_gsi(int ioapic, int gsi) | |||
161 | return gsi; | 164 | return gsi; |
162 | } | 165 | } |
163 | 166 | ||
167 | static int wakeup_secondary_cpu_via_mip(int cpu, unsigned long eip) | ||
168 | { | ||
169 | unsigned long vect = 0, psaival = 0; | ||
170 | |||
171 | if (psai == NULL) | ||
172 | return -1; | ||
173 | |||
174 | vect = ((unsigned long)__pa(eip)/0x1000) << 16; | ||
175 | psaival = (0x1000000 | vect | cpu); | ||
176 | |||
177 | while (*psai & 0x1000000) | ||
178 | ; | ||
179 | |||
180 | *psai = psaival; | ||
181 | |||
182 | return 0; | ||
183 | } | ||
184 | |||
185 | static void noop_wait_for_deassert(atomic_t *deassert_not_used) | ||
186 | { | ||
187 | } | ||
188 | |||
189 | static int __init es7000_update_genapic(void) | ||
190 | { | ||
191 | genapic->wakeup_cpu = wakeup_secondary_cpu_via_mip; | ||
192 | |||
193 | /* MPENTIUMIII */ | ||
194 | if (boot_cpu_data.x86 == 6 && | ||
195 | (boot_cpu_data.x86_model >= 7 || boot_cpu_data.x86_model <= 11)) { | ||
196 | es7000_update_genapic_to_cluster(); | ||
197 | genapic->wait_for_init_deassert = noop_wait_for_deassert; | ||
198 | genapic->wakeup_cpu = wakeup_secondary_cpu_via_mip; | ||
199 | } | ||
200 | |||
201 | return 0; | ||
202 | } | ||
203 | |||
164 | void __init | 204 | void __init |
165 | setup_unisys(void) | 205 | setup_unisys(void) |
166 | { | 206 | { |
@@ -176,6 +216,8 @@ setup_unisys(void) | |||
176 | else | 216 | else |
177 | es7000_plat = ES7000_CLASSIC; | 217 | es7000_plat = ES7000_CLASSIC; |
178 | ioapic_renumber_irq = es7000_rename_gsi; | 218 | ioapic_renumber_irq = es7000_rename_gsi; |
219 | |||
220 | x86_quirks->update_genapic = es7000_update_genapic; | ||
179 | } | 221 | } |
180 | 222 | ||
181 | /* | 223 | /* |
@@ -317,26 +359,6 @@ es7000_mip_write(struct mip_reg *mip_reg) | |||
317 | return status; | 359 | return status; |
318 | } | 360 | } |
319 | 361 | ||
320 | int | ||
321 | es7000_start_cpu(int cpu, unsigned long eip) | ||
322 | { | ||
323 | unsigned long vect = 0, psaival = 0; | ||
324 | |||
325 | if (psai == NULL) | ||
326 | return -1; | ||
327 | |||
328 | vect = ((unsigned long)__pa(eip)/0x1000) << 16; | ||
329 | psaival = (0x1000000 | vect | cpu); | ||
330 | |||
331 | while (*psai & 0x1000000) | ||
332 | ; | ||
333 | |||
334 | *psai = psaival; | ||
335 | |||
336 | return 0; | ||
337 | |||
338 | } | ||
339 | |||
340 | void __init | 362 | void __init |
341 | es7000_sw_apic(void) | 363 | es7000_sw_apic(void) |
342 | { | 364 | { |
diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c index 50ea0ac8c9bf..1b43086b097a 100644 --- a/arch/x86/kernel/ftrace.c +++ b/arch/x86/kernel/ftrace.c | |||
@@ -14,14 +14,17 @@ | |||
14 | #include <linux/uaccess.h> | 14 | #include <linux/uaccess.h> |
15 | #include <linux/ftrace.h> | 15 | #include <linux/ftrace.h> |
16 | #include <linux/percpu.h> | 16 | #include <linux/percpu.h> |
17 | #include <linux/sched.h> | ||
17 | #include <linux/init.h> | 18 | #include <linux/init.h> |
18 | #include <linux/list.h> | 19 | #include <linux/list.h> |
19 | 20 | ||
20 | #include <asm/ftrace.h> | 21 | #include <asm/ftrace.h> |
22 | #include <linux/ftrace.h> | ||
21 | #include <asm/nops.h> | 23 | #include <asm/nops.h> |
24 | #include <asm/nmi.h> | ||
22 | 25 | ||
23 | 26 | ||
24 | static unsigned char ftrace_nop[MCOUNT_INSN_SIZE]; | 27 | #ifdef CONFIG_DYNAMIC_FTRACE |
25 | 28 | ||
26 | union ftrace_code_union { | 29 | union ftrace_code_union { |
27 | char code[MCOUNT_INSN_SIZE]; | 30 | char code[MCOUNT_INSN_SIZE]; |
@@ -31,18 +34,12 @@ union ftrace_code_union { | |||
31 | } __attribute__((packed)); | 34 | } __attribute__((packed)); |
32 | }; | 35 | }; |
33 | 36 | ||
34 | |||
35 | static int ftrace_calc_offset(long ip, long addr) | 37 | static int ftrace_calc_offset(long ip, long addr) |
36 | { | 38 | { |
37 | return (int)(addr - ip); | 39 | return (int)(addr - ip); |
38 | } | 40 | } |
39 | 41 | ||
40 | unsigned char *ftrace_nop_replace(void) | 42 | static unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr) |
41 | { | ||
42 | return ftrace_nop; | ||
43 | } | ||
44 | |||
45 | unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr) | ||
46 | { | 43 | { |
47 | static union ftrace_code_union calc; | 44 | static union ftrace_code_union calc; |
48 | 45 | ||
@@ -56,7 +53,142 @@ unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr) | |||
56 | return calc.code; | 53 | return calc.code; |
57 | } | 54 | } |
58 | 55 | ||
59 | int | 56 | /* |
57 | * Modifying code must take extra care. On an SMP machine, if | ||
58 | * the code being modified is also being executed on another CPU | ||
59 | * that CPU will have undefined results and possibly take a GPF. | ||
60 | * We use kstop_machine to stop other CPUS from exectuing code. | ||
61 | * But this does not stop NMIs from happening. We still need | ||
62 | * to protect against that. We separate out the modification of | ||
63 | * the code to take care of this. | ||
64 | * | ||
65 | * Two buffers are added: An IP buffer and a "code" buffer. | ||
66 | * | ||
67 | * 1) Put the instruction pointer into the IP buffer | ||
68 | * and the new code into the "code" buffer. | ||
69 | * 2) Set a flag that says we are modifying code | ||
70 | * 3) Wait for any running NMIs to finish. | ||
71 | * 4) Write the code | ||
72 | * 5) clear the flag. | ||
73 | * 6) Wait for any running NMIs to finish. | ||
74 | * | ||
75 | * If an NMI is executed, the first thing it does is to call | ||
76 | * "ftrace_nmi_enter". This will check if the flag is set to write | ||
77 | * and if it is, it will write what is in the IP and "code" buffers. | ||
78 | * | ||
79 | * The trick is, it does not matter if everyone is writing the same | ||
80 | * content to the code location. Also, if a CPU is executing code | ||
81 | * it is OK to write to that code location if the contents being written | ||
82 | * are the same as what exists. | ||
83 | */ | ||
84 | |||
85 | static atomic_t in_nmi = ATOMIC_INIT(0); | ||
86 | static int mod_code_status; /* holds return value of text write */ | ||
87 | static int mod_code_write; /* set when NMI should do the write */ | ||
88 | static void *mod_code_ip; /* holds the IP to write to */ | ||
89 | static void *mod_code_newcode; /* holds the text to write to the IP */ | ||
90 | |||
91 | static unsigned nmi_wait_count; | ||
92 | static atomic_t nmi_update_count = ATOMIC_INIT(0); | ||
93 | |||
94 | int ftrace_arch_read_dyn_info(char *buf, int size) | ||
95 | { | ||
96 | int r; | ||
97 | |||
98 | r = snprintf(buf, size, "%u %u", | ||
99 | nmi_wait_count, | ||
100 | atomic_read(&nmi_update_count)); | ||
101 | return r; | ||
102 | } | ||
103 | |||
104 | static void ftrace_mod_code(void) | ||
105 | { | ||
106 | /* | ||
107 | * Yes, more than one CPU process can be writing to mod_code_status. | ||
108 | * (and the code itself) | ||
109 | * But if one were to fail, then they all should, and if one were | ||
110 | * to succeed, then they all should. | ||
111 | */ | ||
112 | mod_code_status = probe_kernel_write(mod_code_ip, mod_code_newcode, | ||
113 | MCOUNT_INSN_SIZE); | ||
114 | } | ||
115 | |||
116 | void ftrace_nmi_enter(void) | ||
117 | { | ||
118 | atomic_inc(&in_nmi); | ||
119 | /* Must have in_nmi seen before reading write flag */ | ||
120 | smp_mb(); | ||
121 | if (mod_code_write) { | ||
122 | ftrace_mod_code(); | ||
123 | atomic_inc(&nmi_update_count); | ||
124 | } | ||
125 | } | ||
126 | |||
127 | void ftrace_nmi_exit(void) | ||
128 | { | ||
129 | /* Finish all executions before clearing in_nmi */ | ||
130 | smp_wmb(); | ||
131 | atomic_dec(&in_nmi); | ||
132 | } | ||
133 | |||
134 | static void wait_for_nmi(void) | ||
135 | { | ||
136 | int waited = 0; | ||
137 | |||
138 | while (atomic_read(&in_nmi)) { | ||
139 | waited = 1; | ||
140 | cpu_relax(); | ||
141 | } | ||
142 | |||
143 | if (waited) | ||
144 | nmi_wait_count++; | ||
145 | } | ||
146 | |||
147 | static int | ||
148 | do_ftrace_mod_code(unsigned long ip, void *new_code) | ||
149 | { | ||
150 | mod_code_ip = (void *)ip; | ||
151 | mod_code_newcode = new_code; | ||
152 | |||
153 | /* The buffers need to be visible before we let NMIs write them */ | ||
154 | smp_wmb(); | ||
155 | |||
156 | mod_code_write = 1; | ||
157 | |||
158 | /* Make sure write bit is visible before we wait on NMIs */ | ||
159 | smp_mb(); | ||
160 | |||
161 | wait_for_nmi(); | ||
162 | |||
163 | /* Make sure all running NMIs have finished before we write the code */ | ||
164 | smp_mb(); | ||
165 | |||
166 | ftrace_mod_code(); | ||
167 | |||
168 | /* Make sure the write happens before clearing the bit */ | ||
169 | smp_wmb(); | ||
170 | |||
171 | mod_code_write = 0; | ||
172 | |||
173 | /* make sure NMIs see the cleared bit */ | ||
174 | smp_mb(); | ||
175 | |||
176 | wait_for_nmi(); | ||
177 | |||
178 | return mod_code_status; | ||
179 | } | ||
180 | |||
181 | |||
182 | |||
183 | |||
184 | static unsigned char ftrace_nop[MCOUNT_INSN_SIZE]; | ||
185 | |||
186 | static unsigned char *ftrace_nop_replace(void) | ||
187 | { | ||
188 | return ftrace_nop; | ||
189 | } | ||
190 | |||
191 | static int | ||
60 | ftrace_modify_code(unsigned long ip, unsigned char *old_code, | 192 | ftrace_modify_code(unsigned long ip, unsigned char *old_code, |
61 | unsigned char *new_code) | 193 | unsigned char *new_code) |
62 | { | 194 | { |
@@ -81,7 +213,7 @@ ftrace_modify_code(unsigned long ip, unsigned char *old_code, | |||
81 | return -EINVAL; | 213 | return -EINVAL; |
82 | 214 | ||
83 | /* replace the text with the new text */ | 215 | /* replace the text with the new text */ |
84 | if (probe_kernel_write((void *)ip, new_code, MCOUNT_INSN_SIZE)) | 216 | if (do_ftrace_mod_code(ip, new_code)) |
85 | return -EPERM; | 217 | return -EPERM; |
86 | 218 | ||
87 | sync_core(); | 219 | sync_core(); |
@@ -89,6 +221,29 @@ ftrace_modify_code(unsigned long ip, unsigned char *old_code, | |||
89 | return 0; | 221 | return 0; |
90 | } | 222 | } |
91 | 223 | ||
224 | int ftrace_make_nop(struct module *mod, | ||
225 | struct dyn_ftrace *rec, unsigned long addr) | ||
226 | { | ||
227 | unsigned char *new, *old; | ||
228 | unsigned long ip = rec->ip; | ||
229 | |||
230 | old = ftrace_call_replace(ip, addr); | ||
231 | new = ftrace_nop_replace(); | ||
232 | |||
233 | return ftrace_modify_code(rec->ip, old, new); | ||
234 | } | ||
235 | |||
236 | int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr) | ||
237 | { | ||
238 | unsigned char *new, *old; | ||
239 | unsigned long ip = rec->ip; | ||
240 | |||
241 | old = ftrace_nop_replace(); | ||
242 | new = ftrace_call_replace(ip, addr); | ||
243 | |||
244 | return ftrace_modify_code(rec->ip, old, new); | ||
245 | } | ||
246 | |||
92 | int ftrace_update_ftrace_func(ftrace_func_t func) | 247 | int ftrace_update_ftrace_func(ftrace_func_t func) |
93 | { | 248 | { |
94 | unsigned long ip = (unsigned long)(&ftrace_call); | 249 | unsigned long ip = (unsigned long)(&ftrace_call); |
@@ -165,3 +320,218 @@ int __init ftrace_dyn_arch_init(void *data) | |||
165 | 320 | ||
166 | return 0; | 321 | return 0; |
167 | } | 322 | } |
323 | #endif | ||
324 | |||
325 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | ||
326 | |||
327 | #ifdef CONFIG_DYNAMIC_FTRACE | ||
328 | extern void ftrace_graph_call(void); | ||
329 | |||
330 | static int ftrace_mod_jmp(unsigned long ip, | ||
331 | int old_offset, int new_offset) | ||
332 | { | ||
333 | unsigned char code[MCOUNT_INSN_SIZE]; | ||
334 | |||
335 | if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE)) | ||
336 | return -EFAULT; | ||
337 | |||
338 | if (code[0] != 0xe9 || old_offset != *(int *)(&code[1])) | ||
339 | return -EINVAL; | ||
340 | |||
341 | *(int *)(&code[1]) = new_offset; | ||
342 | |||
343 | if (do_ftrace_mod_code(ip, &code)) | ||
344 | return -EPERM; | ||
345 | |||
346 | return 0; | ||
347 | } | ||
348 | |||
349 | int ftrace_enable_ftrace_graph_caller(void) | ||
350 | { | ||
351 | unsigned long ip = (unsigned long)(&ftrace_graph_call); | ||
352 | int old_offset, new_offset; | ||
353 | |||
354 | old_offset = (unsigned long)(&ftrace_stub) - (ip + MCOUNT_INSN_SIZE); | ||
355 | new_offset = (unsigned long)(&ftrace_graph_caller) - (ip + MCOUNT_INSN_SIZE); | ||
356 | |||
357 | return ftrace_mod_jmp(ip, old_offset, new_offset); | ||
358 | } | ||
359 | |||
360 | int ftrace_disable_ftrace_graph_caller(void) | ||
361 | { | ||
362 | unsigned long ip = (unsigned long)(&ftrace_graph_call); | ||
363 | int old_offset, new_offset; | ||
364 | |||
365 | old_offset = (unsigned long)(&ftrace_graph_caller) - (ip + MCOUNT_INSN_SIZE); | ||
366 | new_offset = (unsigned long)(&ftrace_stub) - (ip + MCOUNT_INSN_SIZE); | ||
367 | |||
368 | return ftrace_mod_jmp(ip, old_offset, new_offset); | ||
369 | } | ||
370 | |||
371 | #else /* CONFIG_DYNAMIC_FTRACE */ | ||
372 | |||
373 | /* | ||
374 | * These functions are picked from those used on | ||
375 | * this page for dynamic ftrace. They have been | ||
376 | * simplified to ignore all traces in NMI context. | ||
377 | */ | ||
378 | static atomic_t in_nmi; | ||
379 | |||
380 | void ftrace_nmi_enter(void) | ||
381 | { | ||
382 | atomic_inc(&in_nmi); | ||
383 | } | ||
384 | |||
385 | void ftrace_nmi_exit(void) | ||
386 | { | ||
387 | atomic_dec(&in_nmi); | ||
388 | } | ||
389 | |||
390 | #endif /* !CONFIG_DYNAMIC_FTRACE */ | ||
391 | |||
392 | /* Add a function return address to the trace stack on thread info.*/ | ||
393 | static int push_return_trace(unsigned long ret, unsigned long long time, | ||
394 | unsigned long func, int *depth) | ||
395 | { | ||
396 | int index; | ||
397 | |||
398 | if (!current->ret_stack) | ||
399 | return -EBUSY; | ||
400 | |||
401 | /* The return trace stack is full */ | ||
402 | if (current->curr_ret_stack == FTRACE_RETFUNC_DEPTH - 1) { | ||
403 | atomic_inc(¤t->trace_overrun); | ||
404 | return -EBUSY; | ||
405 | } | ||
406 | |||
407 | index = ++current->curr_ret_stack; | ||
408 | barrier(); | ||
409 | current->ret_stack[index].ret = ret; | ||
410 | current->ret_stack[index].func = func; | ||
411 | current->ret_stack[index].calltime = time; | ||
412 | *depth = index; | ||
413 | |||
414 | return 0; | ||
415 | } | ||
416 | |||
417 | /* Retrieve a function return address to the trace stack on thread info.*/ | ||
418 | static void pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret) | ||
419 | { | ||
420 | int index; | ||
421 | |||
422 | index = current->curr_ret_stack; | ||
423 | |||
424 | if (unlikely(index < 0)) { | ||
425 | ftrace_graph_stop(); | ||
426 | WARN_ON(1); | ||
427 | /* Might as well panic, otherwise we have no where to go */ | ||
428 | *ret = (unsigned long)panic; | ||
429 | return; | ||
430 | } | ||
431 | |||
432 | *ret = current->ret_stack[index].ret; | ||
433 | trace->func = current->ret_stack[index].func; | ||
434 | trace->calltime = current->ret_stack[index].calltime; | ||
435 | trace->overrun = atomic_read(¤t->trace_overrun); | ||
436 | trace->depth = index; | ||
437 | barrier(); | ||
438 | current->curr_ret_stack--; | ||
439 | |||
440 | } | ||
441 | |||
442 | /* | ||
443 | * Send the trace to the ring-buffer. | ||
444 | * @return the original return address. | ||
445 | */ | ||
446 | unsigned long ftrace_return_to_handler(void) | ||
447 | { | ||
448 | struct ftrace_graph_ret trace; | ||
449 | unsigned long ret; | ||
450 | |||
451 | pop_return_trace(&trace, &ret); | ||
452 | trace.rettime = cpu_clock(raw_smp_processor_id()); | ||
453 | ftrace_graph_return(&trace); | ||
454 | |||
455 | if (unlikely(!ret)) { | ||
456 | ftrace_graph_stop(); | ||
457 | WARN_ON(1); | ||
458 | /* Might as well panic. What else to do? */ | ||
459 | ret = (unsigned long)panic; | ||
460 | } | ||
461 | |||
462 | return ret; | ||
463 | } | ||
464 | |||
465 | /* | ||
466 | * Hook the return address and push it in the stack of return addrs | ||
467 | * in current thread info. | ||
468 | */ | ||
469 | void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr) | ||
470 | { | ||
471 | unsigned long old; | ||
472 | unsigned long long calltime; | ||
473 | int faulted; | ||
474 | struct ftrace_graph_ent trace; | ||
475 | unsigned long return_hooker = (unsigned long) | ||
476 | &return_to_handler; | ||
477 | |||
478 | /* Nmi's are currently unsupported */ | ||
479 | if (unlikely(atomic_read(&in_nmi))) | ||
480 | return; | ||
481 | |||
482 | if (unlikely(atomic_read(¤t->tracing_graph_pause))) | ||
483 | return; | ||
484 | |||
485 | /* | ||
486 | * Protect against fault, even if it shouldn't | ||
487 | * happen. This tool is too much intrusive to | ||
488 | * ignore such a protection. | ||
489 | */ | ||
490 | asm volatile( | ||
491 | "1: " _ASM_MOV " (%[parent_old]), %[old]\n" | ||
492 | "2: " _ASM_MOV " %[return_hooker], (%[parent_replaced])\n" | ||
493 | " movl $0, %[faulted]\n" | ||
494 | |||
495 | ".section .fixup, \"ax\"\n" | ||
496 | "3: movl $1, %[faulted]\n" | ||
497 | ".previous\n" | ||
498 | |||
499 | _ASM_EXTABLE(1b, 3b) | ||
500 | _ASM_EXTABLE(2b, 3b) | ||
501 | |||
502 | : [parent_replaced] "=r" (parent), [old] "=r" (old), | ||
503 | [faulted] "=r" (faulted) | ||
504 | : [parent_old] "0" (parent), [return_hooker] "r" (return_hooker) | ||
505 | : "memory" | ||
506 | ); | ||
507 | |||
508 | if (unlikely(faulted)) { | ||
509 | ftrace_graph_stop(); | ||
510 | WARN_ON(1); | ||
511 | return; | ||
512 | } | ||
513 | |||
514 | if (unlikely(!__kernel_text_address(old))) { | ||
515 | ftrace_graph_stop(); | ||
516 | *parent = old; | ||
517 | WARN_ON(1); | ||
518 | return; | ||
519 | } | ||
520 | |||
521 | calltime = cpu_clock(raw_smp_processor_id()); | ||
522 | |||
523 | if (push_return_trace(old, calltime, | ||
524 | self_addr, &trace.depth) == -EBUSY) { | ||
525 | *parent = old; | ||
526 | return; | ||
527 | } | ||
528 | |||
529 | trace.func = self_addr; | ||
530 | |||
531 | /* Only trace if the calling function expects to */ | ||
532 | if (!ftrace_graph_entry(&trace)) { | ||
533 | current->curr_ret_stack--; | ||
534 | *parent = old; | ||
535 | } | ||
536 | } | ||
537 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ | ||
diff --git a/arch/x86/kernel/genapic_64.c b/arch/x86/kernel/genapic_64.c index 6c9bfc9e1e95..2bced78b0b8e 100644 --- a/arch/x86/kernel/genapic_64.c +++ b/arch/x86/kernel/genapic_64.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <asm/smp.h> | 21 | #include <asm/smp.h> |
22 | #include <asm/ipi.h> | 22 | #include <asm/ipi.h> |
23 | #include <asm/genapic.h> | 23 | #include <asm/genapic.h> |
24 | #include <asm/setup.h> | ||
24 | 25 | ||
25 | extern struct genapic apic_flat; | 26 | extern struct genapic apic_flat; |
26 | extern struct genapic apic_physflat; | 27 | extern struct genapic apic_physflat; |
@@ -53,6 +54,9 @@ void __init setup_apic_routing(void) | |||
53 | genapic = &apic_physflat; | 54 | genapic = &apic_physflat; |
54 | printk(KERN_INFO "Setting APIC routing to %s\n", genapic->name); | 55 | printk(KERN_INFO "Setting APIC routing to %s\n", genapic->name); |
55 | } | 56 | } |
57 | |||
58 | if (x86_quirks->update_genapic) | ||
59 | x86_quirks->update_genapic(); | ||
56 | } | 60 | } |
57 | 61 | ||
58 | /* Same for both flat and physical. */ | 62 | /* Same for both flat and physical. */ |
diff --git a/arch/x86/kernel/genapic_flat_64.c b/arch/x86/kernel/genapic_flat_64.c index c0262791bda4..34185488e4fb 100644 --- a/arch/x86/kernel/genapic_flat_64.c +++ b/arch/x86/kernel/genapic_flat_64.c | |||
@@ -30,12 +30,12 @@ static int flat_acpi_madt_oem_check(char *oem_id, char *oem_table_id) | |||
30 | return 1; | 30 | return 1; |
31 | } | 31 | } |
32 | 32 | ||
33 | static cpumask_t flat_target_cpus(void) | 33 | static const struct cpumask *flat_target_cpus(void) |
34 | { | 34 | { |
35 | return cpu_online_map; | 35 | return cpu_online_mask; |
36 | } | 36 | } |
37 | 37 | ||
38 | static cpumask_t flat_vector_allocation_domain(int cpu) | 38 | static void flat_vector_allocation_domain(int cpu, struct cpumask *retmask) |
39 | { | 39 | { |
40 | /* Careful. Some cpus do not strictly honor the set of cpus | 40 | /* Careful. Some cpus do not strictly honor the set of cpus |
41 | * specified in the interrupt destination when using lowest | 41 | * specified in the interrupt destination when using lowest |
@@ -45,8 +45,8 @@ static cpumask_t flat_vector_allocation_domain(int cpu) | |||
45 | * deliver interrupts to the wrong hyperthread when only one | 45 | * deliver interrupts to the wrong hyperthread when only one |
46 | * hyperthread was specified in the interrupt desitination. | 46 | * hyperthread was specified in the interrupt desitination. |
47 | */ | 47 | */ |
48 | cpumask_t domain = { { [0] = APIC_ALL_CPUS, } }; | 48 | cpumask_clear(retmask); |
49 | return domain; | 49 | cpumask_bits(retmask)[0] = APIC_ALL_CPUS; |
50 | } | 50 | } |
51 | 51 | ||
52 | /* | 52 | /* |
@@ -69,9 +69,8 @@ static void flat_init_apic_ldr(void) | |||
69 | apic_write(APIC_LDR, val); | 69 | apic_write(APIC_LDR, val); |
70 | } | 70 | } |
71 | 71 | ||
72 | static void flat_send_IPI_mask(cpumask_t cpumask, int vector) | 72 | static inline void _flat_send_IPI_mask(unsigned long mask, int vector) |
73 | { | 73 | { |
74 | unsigned long mask = cpus_addr(cpumask)[0]; | ||
75 | unsigned long flags; | 74 | unsigned long flags; |
76 | 75 | ||
77 | local_irq_save(flags); | 76 | local_irq_save(flags); |
@@ -79,20 +78,41 @@ static void flat_send_IPI_mask(cpumask_t cpumask, int vector) | |||
79 | local_irq_restore(flags); | 78 | local_irq_restore(flags); |
80 | } | 79 | } |
81 | 80 | ||
81 | static void flat_send_IPI_mask(const struct cpumask *cpumask, int vector) | ||
82 | { | ||
83 | unsigned long mask = cpumask_bits(cpumask)[0]; | ||
84 | |||
85 | _flat_send_IPI_mask(mask, vector); | ||
86 | } | ||
87 | |||
88 | static void flat_send_IPI_mask_allbutself(const struct cpumask *cpumask, | ||
89 | int vector) | ||
90 | { | ||
91 | unsigned long mask = cpumask_bits(cpumask)[0]; | ||
92 | int cpu = smp_processor_id(); | ||
93 | |||
94 | if (cpu < BITS_PER_LONG) | ||
95 | clear_bit(cpu, &mask); | ||
96 | _flat_send_IPI_mask(mask, vector); | ||
97 | } | ||
98 | |||
82 | static void flat_send_IPI_allbutself(int vector) | 99 | static void flat_send_IPI_allbutself(int vector) |
83 | { | 100 | { |
101 | int cpu = smp_processor_id(); | ||
84 | #ifdef CONFIG_HOTPLUG_CPU | 102 | #ifdef CONFIG_HOTPLUG_CPU |
85 | int hotplug = 1; | 103 | int hotplug = 1; |
86 | #else | 104 | #else |
87 | int hotplug = 0; | 105 | int hotplug = 0; |
88 | #endif | 106 | #endif |
89 | if (hotplug || vector == NMI_VECTOR) { | 107 | if (hotplug || vector == NMI_VECTOR) { |
90 | cpumask_t allbutme = cpu_online_map; | 108 | if (!cpumask_equal(cpu_online_mask, cpumask_of(cpu))) { |
109 | unsigned long mask = cpumask_bits(cpu_online_mask)[0]; | ||
91 | 110 | ||
92 | cpu_clear(smp_processor_id(), allbutme); | 111 | if (cpu < BITS_PER_LONG) |
112 | clear_bit(cpu, &mask); | ||
93 | 113 | ||
94 | if (!cpus_empty(allbutme)) | 114 | _flat_send_IPI_mask(mask, vector); |
95 | flat_send_IPI_mask(allbutme, vector); | 115 | } |
96 | } else if (num_online_cpus() > 1) { | 116 | } else if (num_online_cpus() > 1) { |
97 | __send_IPI_shortcut(APIC_DEST_ALLBUT, vector,APIC_DEST_LOGICAL); | 117 | __send_IPI_shortcut(APIC_DEST_ALLBUT, vector,APIC_DEST_LOGICAL); |
98 | } | 118 | } |
@@ -101,7 +121,7 @@ static void flat_send_IPI_allbutself(int vector) | |||
101 | static void flat_send_IPI_all(int vector) | 121 | static void flat_send_IPI_all(int vector) |
102 | { | 122 | { |
103 | if (vector == NMI_VECTOR) | 123 | if (vector == NMI_VECTOR) |
104 | flat_send_IPI_mask(cpu_online_map, vector); | 124 | flat_send_IPI_mask(cpu_online_mask, vector); |
105 | else | 125 | else |
106 | __send_IPI_shortcut(APIC_DEST_ALLINC, vector, APIC_DEST_LOGICAL); | 126 | __send_IPI_shortcut(APIC_DEST_ALLINC, vector, APIC_DEST_LOGICAL); |
107 | } | 127 | } |
@@ -135,9 +155,18 @@ static int flat_apic_id_registered(void) | |||
135 | return physid_isset(read_xapic_id(), phys_cpu_present_map); | 155 | return physid_isset(read_xapic_id(), phys_cpu_present_map); |
136 | } | 156 | } |
137 | 157 | ||
138 | static unsigned int flat_cpu_mask_to_apicid(cpumask_t cpumask) | 158 | static unsigned int flat_cpu_mask_to_apicid(const struct cpumask *cpumask) |
159 | { | ||
160 | return cpumask_bits(cpumask)[0] & APIC_ALL_CPUS; | ||
161 | } | ||
162 | |||
163 | static unsigned int flat_cpu_mask_to_apicid_and(const struct cpumask *cpumask, | ||
164 | const struct cpumask *andmask) | ||
139 | { | 165 | { |
140 | return cpus_addr(cpumask)[0] & APIC_ALL_CPUS; | 166 | unsigned long mask1 = cpumask_bits(cpumask)[0] & APIC_ALL_CPUS; |
167 | unsigned long mask2 = cpumask_bits(andmask)[0] & APIC_ALL_CPUS; | ||
168 | |||
169 | return mask1 & mask2; | ||
141 | } | 170 | } |
142 | 171 | ||
143 | static unsigned int phys_pkg_id(int index_msb) | 172 | static unsigned int phys_pkg_id(int index_msb) |
@@ -157,8 +186,10 @@ struct genapic apic_flat = { | |||
157 | .send_IPI_all = flat_send_IPI_all, | 186 | .send_IPI_all = flat_send_IPI_all, |
158 | .send_IPI_allbutself = flat_send_IPI_allbutself, | 187 | .send_IPI_allbutself = flat_send_IPI_allbutself, |
159 | .send_IPI_mask = flat_send_IPI_mask, | 188 | .send_IPI_mask = flat_send_IPI_mask, |
189 | .send_IPI_mask_allbutself = flat_send_IPI_mask_allbutself, | ||
160 | .send_IPI_self = apic_send_IPI_self, | 190 | .send_IPI_self = apic_send_IPI_self, |
161 | .cpu_mask_to_apicid = flat_cpu_mask_to_apicid, | 191 | .cpu_mask_to_apicid = flat_cpu_mask_to_apicid, |
192 | .cpu_mask_to_apicid_and = flat_cpu_mask_to_apicid_and, | ||
162 | .phys_pkg_id = phys_pkg_id, | 193 | .phys_pkg_id = phys_pkg_id, |
163 | .get_apic_id = get_apic_id, | 194 | .get_apic_id = get_apic_id, |
164 | .set_apic_id = set_apic_id, | 195 | .set_apic_id = set_apic_id, |
@@ -188,35 +219,39 @@ static int physflat_acpi_madt_oem_check(char *oem_id, char *oem_table_id) | |||
188 | return 0; | 219 | return 0; |
189 | } | 220 | } |
190 | 221 | ||
191 | static cpumask_t physflat_target_cpus(void) | 222 | static const struct cpumask *physflat_target_cpus(void) |
192 | { | 223 | { |
193 | return cpu_online_map; | 224 | return cpu_online_mask; |
194 | } | 225 | } |
195 | 226 | ||
196 | static cpumask_t physflat_vector_allocation_domain(int cpu) | 227 | static void physflat_vector_allocation_domain(int cpu, struct cpumask *retmask) |
197 | { | 228 | { |
198 | return cpumask_of_cpu(cpu); | 229 | cpumask_clear(retmask); |
230 | cpumask_set_cpu(cpu, retmask); | ||
199 | } | 231 | } |
200 | 232 | ||
201 | static void physflat_send_IPI_mask(cpumask_t cpumask, int vector) | 233 | static void physflat_send_IPI_mask(const struct cpumask *cpumask, int vector) |
202 | { | 234 | { |
203 | send_IPI_mask_sequence(cpumask, vector); | 235 | send_IPI_mask_sequence(cpumask, vector); |
204 | } | 236 | } |
205 | 237 | ||
206 | static void physflat_send_IPI_allbutself(int vector) | 238 | static void physflat_send_IPI_mask_allbutself(const struct cpumask *cpumask, |
239 | int vector) | ||
207 | { | 240 | { |
208 | cpumask_t allbutme = cpu_online_map; | 241 | send_IPI_mask_allbutself(cpumask, vector); |
242 | } | ||
209 | 243 | ||
210 | cpu_clear(smp_processor_id(), allbutme); | 244 | static void physflat_send_IPI_allbutself(int vector) |
211 | physflat_send_IPI_mask(allbutme, vector); | 245 | { |
246 | send_IPI_mask_allbutself(cpu_online_mask, vector); | ||
212 | } | 247 | } |
213 | 248 | ||
214 | static void physflat_send_IPI_all(int vector) | 249 | static void physflat_send_IPI_all(int vector) |
215 | { | 250 | { |
216 | physflat_send_IPI_mask(cpu_online_map, vector); | 251 | physflat_send_IPI_mask(cpu_online_mask, vector); |
217 | } | 252 | } |
218 | 253 | ||
219 | static unsigned int physflat_cpu_mask_to_apicid(cpumask_t cpumask) | 254 | static unsigned int physflat_cpu_mask_to_apicid(const struct cpumask *cpumask) |
220 | { | 255 | { |
221 | int cpu; | 256 | int cpu; |
222 | 257 | ||
@@ -224,13 +259,31 @@ static unsigned int physflat_cpu_mask_to_apicid(cpumask_t cpumask) | |||
224 | * We're using fixed IRQ delivery, can only return one phys APIC ID. | 259 | * We're using fixed IRQ delivery, can only return one phys APIC ID. |
225 | * May as well be the first. | 260 | * May as well be the first. |
226 | */ | 261 | */ |
227 | cpu = first_cpu(cpumask); | 262 | cpu = cpumask_first(cpumask); |
228 | if ((unsigned)cpu < nr_cpu_ids) | 263 | if ((unsigned)cpu < nr_cpu_ids) |
229 | return per_cpu(x86_cpu_to_apicid, cpu); | 264 | return per_cpu(x86_cpu_to_apicid, cpu); |
230 | else | 265 | else |
231 | return BAD_APICID; | 266 | return BAD_APICID; |
232 | } | 267 | } |
233 | 268 | ||
269 | static unsigned int | ||
270 | physflat_cpu_mask_to_apicid_and(const struct cpumask *cpumask, | ||
271 | const struct cpumask *andmask) | ||
272 | { | ||
273 | int cpu; | ||
274 | |||
275 | /* | ||
276 | * We're using fixed IRQ delivery, can only return one phys APIC ID. | ||
277 | * May as well be the first. | ||
278 | */ | ||
279 | for_each_cpu_and(cpu, cpumask, andmask) | ||
280 | if (cpumask_test_cpu(cpu, cpu_online_mask)) | ||
281 | break; | ||
282 | if (cpu < nr_cpu_ids) | ||
283 | return per_cpu(x86_cpu_to_apicid, cpu); | ||
284 | return BAD_APICID; | ||
285 | } | ||
286 | |||
234 | struct genapic apic_physflat = { | 287 | struct genapic apic_physflat = { |
235 | .name = "physical flat", | 288 | .name = "physical flat", |
236 | .acpi_madt_oem_check = physflat_acpi_madt_oem_check, | 289 | .acpi_madt_oem_check = physflat_acpi_madt_oem_check, |
@@ -243,8 +296,10 @@ struct genapic apic_physflat = { | |||
243 | .send_IPI_all = physflat_send_IPI_all, | 296 | .send_IPI_all = physflat_send_IPI_all, |
244 | .send_IPI_allbutself = physflat_send_IPI_allbutself, | 297 | .send_IPI_allbutself = physflat_send_IPI_allbutself, |
245 | .send_IPI_mask = physflat_send_IPI_mask, | 298 | .send_IPI_mask = physflat_send_IPI_mask, |
299 | .send_IPI_mask_allbutself = physflat_send_IPI_mask_allbutself, | ||
246 | .send_IPI_self = apic_send_IPI_self, | 300 | .send_IPI_self = apic_send_IPI_self, |
247 | .cpu_mask_to_apicid = physflat_cpu_mask_to_apicid, | 301 | .cpu_mask_to_apicid = physflat_cpu_mask_to_apicid, |
302 | .cpu_mask_to_apicid_and = physflat_cpu_mask_to_apicid_and, | ||
248 | .phys_pkg_id = phys_pkg_id, | 303 | .phys_pkg_id = phys_pkg_id, |
249 | .get_apic_id = get_apic_id, | 304 | .get_apic_id = get_apic_id, |
250 | .set_apic_id = set_apic_id, | 305 | .set_apic_id = set_apic_id, |
diff --git a/arch/x86/kernel/genx2apic_cluster.c b/arch/x86/kernel/genx2apic_cluster.c index f6a2c8eb48a6..6ce497cc372d 100644 --- a/arch/x86/kernel/genx2apic_cluster.c +++ b/arch/x86/kernel/genx2apic_cluster.c | |||
@@ -22,19 +22,18 @@ static int x2apic_acpi_madt_oem_check(char *oem_id, char *oem_table_id) | |||
22 | 22 | ||
23 | /* Start with all IRQs pointing to boot CPU. IRQ balancing will shift them. */ | 23 | /* Start with all IRQs pointing to boot CPU. IRQ balancing will shift them. */ |
24 | 24 | ||
25 | static cpumask_t x2apic_target_cpus(void) | 25 | static const struct cpumask *x2apic_target_cpus(void) |
26 | { | 26 | { |
27 | return cpumask_of_cpu(0); | 27 | return cpumask_of(0); |
28 | } | 28 | } |
29 | 29 | ||
30 | /* | 30 | /* |
31 | * for now each logical cpu is in its own vector allocation domain. | 31 | * for now each logical cpu is in its own vector allocation domain. |
32 | */ | 32 | */ |
33 | static cpumask_t x2apic_vector_allocation_domain(int cpu) | 33 | static void x2apic_vector_allocation_domain(int cpu, struct cpumask *retmask) |
34 | { | 34 | { |
35 | cpumask_t domain = CPU_MASK_NONE; | 35 | cpumask_clear(retmask); |
36 | cpu_set(cpu, domain); | 36 | cpumask_set_cpu(cpu, retmask); |
37 | return domain; | ||
38 | } | 37 | } |
39 | 38 | ||
40 | static void __x2apic_send_IPI_dest(unsigned int apicid, int vector, | 39 | static void __x2apic_send_IPI_dest(unsigned int apicid, int vector, |
@@ -56,32 +55,53 @@ static void __x2apic_send_IPI_dest(unsigned int apicid, int vector, | |||
56 | * at once. We have 16 cpu's in a cluster. This will minimize IPI register | 55 | * at once. We have 16 cpu's in a cluster. This will minimize IPI register |
57 | * writes. | 56 | * writes. |
58 | */ | 57 | */ |
59 | static void x2apic_send_IPI_mask(cpumask_t mask, int vector) | 58 | static void x2apic_send_IPI_mask(const struct cpumask *mask, int vector) |
60 | { | 59 | { |
61 | unsigned long flags; | 60 | unsigned long flags; |
62 | unsigned long query_cpu; | 61 | unsigned long query_cpu; |
63 | 62 | ||
64 | local_irq_save(flags); | 63 | local_irq_save(flags); |
65 | for_each_cpu_mask(query_cpu, mask) { | 64 | for_each_cpu(query_cpu, mask) |
66 | __x2apic_send_IPI_dest(per_cpu(x86_cpu_to_logical_apicid, query_cpu), | 65 | __x2apic_send_IPI_dest( |
67 | vector, APIC_DEST_LOGICAL); | 66 | per_cpu(x86_cpu_to_logical_apicid, query_cpu), |
68 | } | 67 | vector, APIC_DEST_LOGICAL); |
69 | local_irq_restore(flags); | 68 | local_irq_restore(flags); |
70 | } | 69 | } |
71 | 70 | ||
72 | static void x2apic_send_IPI_allbutself(int vector) | 71 | static void x2apic_send_IPI_mask_allbutself(const struct cpumask *mask, |
72 | int vector) | ||
73 | { | 73 | { |
74 | cpumask_t mask = cpu_online_map; | 74 | unsigned long flags; |
75 | unsigned long query_cpu; | ||
76 | unsigned long this_cpu = smp_processor_id(); | ||
75 | 77 | ||
76 | cpu_clear(smp_processor_id(), mask); | 78 | local_irq_save(flags); |
79 | for_each_cpu(query_cpu, mask) | ||
80 | if (query_cpu != this_cpu) | ||
81 | __x2apic_send_IPI_dest( | ||
82 | per_cpu(x86_cpu_to_logical_apicid, query_cpu), | ||
83 | vector, APIC_DEST_LOGICAL); | ||
84 | local_irq_restore(flags); | ||
85 | } | ||
86 | |||
87 | static void x2apic_send_IPI_allbutself(int vector) | ||
88 | { | ||
89 | unsigned long flags; | ||
90 | unsigned long query_cpu; | ||
91 | unsigned long this_cpu = smp_processor_id(); | ||
77 | 92 | ||
78 | if (!cpus_empty(mask)) | 93 | local_irq_save(flags); |
79 | x2apic_send_IPI_mask(mask, vector); | 94 | for_each_online_cpu(query_cpu) |
95 | if (query_cpu != this_cpu) | ||
96 | __x2apic_send_IPI_dest( | ||
97 | per_cpu(x86_cpu_to_logical_apicid, query_cpu), | ||
98 | vector, APIC_DEST_LOGICAL); | ||
99 | local_irq_restore(flags); | ||
80 | } | 100 | } |
81 | 101 | ||
82 | static void x2apic_send_IPI_all(int vector) | 102 | static void x2apic_send_IPI_all(int vector) |
83 | { | 103 | { |
84 | x2apic_send_IPI_mask(cpu_online_map, vector); | 104 | x2apic_send_IPI_mask(cpu_online_mask, vector); |
85 | } | 105 | } |
86 | 106 | ||
87 | static int x2apic_apic_id_registered(void) | 107 | static int x2apic_apic_id_registered(void) |
@@ -89,21 +109,38 @@ static int x2apic_apic_id_registered(void) | |||
89 | return 1; | 109 | return 1; |
90 | } | 110 | } |
91 | 111 | ||
92 | static unsigned int x2apic_cpu_mask_to_apicid(cpumask_t cpumask) | 112 | static unsigned int x2apic_cpu_mask_to_apicid(const struct cpumask *cpumask) |
93 | { | 113 | { |
94 | int cpu; | 114 | int cpu; |
95 | 115 | ||
96 | /* | 116 | /* |
97 | * We're using fixed IRQ delivery, can only return one phys APIC ID. | 117 | * We're using fixed IRQ delivery, can only return one logical APIC ID. |
98 | * May as well be the first. | 118 | * May as well be the first. |
99 | */ | 119 | */ |
100 | cpu = first_cpu(cpumask); | 120 | cpu = cpumask_first(cpumask); |
101 | if ((unsigned)cpu < NR_CPUS) | 121 | if ((unsigned)cpu < nr_cpu_ids) |
102 | return per_cpu(x86_cpu_to_logical_apicid, cpu); | 122 | return per_cpu(x86_cpu_to_logical_apicid, cpu); |
103 | else | 123 | else |
104 | return BAD_APICID; | 124 | return BAD_APICID; |
105 | } | 125 | } |
106 | 126 | ||
127 | static unsigned int x2apic_cpu_mask_to_apicid_and(const struct cpumask *cpumask, | ||
128 | const struct cpumask *andmask) | ||
129 | { | ||
130 | int cpu; | ||
131 | |||
132 | /* | ||
133 | * We're using fixed IRQ delivery, can only return one logical APIC ID. | ||
134 | * May as well be the first. | ||
135 | */ | ||
136 | for_each_cpu_and(cpu, cpumask, andmask) | ||
137 | if (cpumask_test_cpu(cpu, cpu_online_mask)) | ||
138 | break; | ||
139 | if (cpu < nr_cpu_ids) | ||
140 | return per_cpu(x86_cpu_to_logical_apicid, cpu); | ||
141 | return BAD_APICID; | ||
142 | } | ||
143 | |||
107 | static unsigned int get_apic_id(unsigned long x) | 144 | static unsigned int get_apic_id(unsigned long x) |
108 | { | 145 | { |
109 | unsigned int id; | 146 | unsigned int id; |
@@ -150,8 +187,10 @@ struct genapic apic_x2apic_cluster = { | |||
150 | .send_IPI_all = x2apic_send_IPI_all, | 187 | .send_IPI_all = x2apic_send_IPI_all, |
151 | .send_IPI_allbutself = x2apic_send_IPI_allbutself, | 188 | .send_IPI_allbutself = x2apic_send_IPI_allbutself, |
152 | .send_IPI_mask = x2apic_send_IPI_mask, | 189 | .send_IPI_mask = x2apic_send_IPI_mask, |
190 | .send_IPI_mask_allbutself = x2apic_send_IPI_mask_allbutself, | ||
153 | .send_IPI_self = x2apic_send_IPI_self, | 191 | .send_IPI_self = x2apic_send_IPI_self, |
154 | .cpu_mask_to_apicid = x2apic_cpu_mask_to_apicid, | 192 | .cpu_mask_to_apicid = x2apic_cpu_mask_to_apicid, |
193 | .cpu_mask_to_apicid_and = x2apic_cpu_mask_to_apicid_and, | ||
155 | .phys_pkg_id = phys_pkg_id, | 194 | .phys_pkg_id = phys_pkg_id, |
156 | .get_apic_id = get_apic_id, | 195 | .get_apic_id = get_apic_id, |
157 | .set_apic_id = set_apic_id, | 196 | .set_apic_id = set_apic_id, |
diff --git a/arch/x86/kernel/genx2apic_phys.c b/arch/x86/kernel/genx2apic_phys.c index d042211768b7..21bcc0e098ba 100644 --- a/arch/x86/kernel/genx2apic_phys.c +++ b/arch/x86/kernel/genx2apic_phys.c | |||
@@ -29,16 +29,15 @@ static int x2apic_acpi_madt_oem_check(char *oem_id, char *oem_table_id) | |||
29 | 29 | ||
30 | /* Start with all IRQs pointing to boot CPU. IRQ balancing will shift them. */ | 30 | /* Start with all IRQs pointing to boot CPU. IRQ balancing will shift them. */ |
31 | 31 | ||
32 | static cpumask_t x2apic_target_cpus(void) | 32 | static const struct cpumask *x2apic_target_cpus(void) |
33 | { | 33 | { |
34 | return cpumask_of_cpu(0); | 34 | return cpumask_of(0); |
35 | } | 35 | } |
36 | 36 | ||
37 | static cpumask_t x2apic_vector_allocation_domain(int cpu) | 37 | static void x2apic_vector_allocation_domain(int cpu, struct cpumask *retmask) |
38 | { | 38 | { |
39 | cpumask_t domain = CPU_MASK_NONE; | 39 | cpumask_clear(retmask); |
40 | cpu_set(cpu, domain); | 40 | cpumask_set_cpu(cpu, retmask); |
41 | return domain; | ||
42 | } | 41 | } |
43 | 42 | ||
44 | static void __x2apic_send_IPI_dest(unsigned int apicid, int vector, | 43 | static void __x2apic_send_IPI_dest(unsigned int apicid, int vector, |
@@ -54,32 +53,54 @@ static void __x2apic_send_IPI_dest(unsigned int apicid, int vector, | |||
54 | x2apic_icr_write(cfg, apicid); | 53 | x2apic_icr_write(cfg, apicid); |
55 | } | 54 | } |
56 | 55 | ||
57 | static void x2apic_send_IPI_mask(cpumask_t mask, int vector) | 56 | static void x2apic_send_IPI_mask(const struct cpumask *mask, int vector) |
58 | { | 57 | { |
59 | unsigned long flags; | 58 | unsigned long flags; |
60 | unsigned long query_cpu; | 59 | unsigned long query_cpu; |
61 | 60 | ||
62 | local_irq_save(flags); | 61 | local_irq_save(flags); |
63 | for_each_cpu_mask(query_cpu, mask) { | 62 | for_each_cpu(query_cpu, mask) { |
64 | __x2apic_send_IPI_dest(per_cpu(x86_cpu_to_apicid, query_cpu), | 63 | __x2apic_send_IPI_dest(per_cpu(x86_cpu_to_apicid, query_cpu), |
65 | vector, APIC_DEST_PHYSICAL); | 64 | vector, APIC_DEST_PHYSICAL); |
66 | } | 65 | } |
67 | local_irq_restore(flags); | 66 | local_irq_restore(flags); |
68 | } | 67 | } |
69 | 68 | ||
70 | static void x2apic_send_IPI_allbutself(int vector) | 69 | static void x2apic_send_IPI_mask_allbutself(const struct cpumask *mask, |
70 | int vector) | ||
71 | { | 71 | { |
72 | cpumask_t mask = cpu_online_map; | 72 | unsigned long flags; |
73 | unsigned long query_cpu; | ||
74 | unsigned long this_cpu = smp_processor_id(); | ||
75 | |||
76 | local_irq_save(flags); | ||
77 | for_each_cpu(query_cpu, mask) { | ||
78 | if (query_cpu != this_cpu) | ||
79 | __x2apic_send_IPI_dest( | ||
80 | per_cpu(x86_cpu_to_apicid, query_cpu), | ||
81 | vector, APIC_DEST_PHYSICAL); | ||
82 | } | ||
83 | local_irq_restore(flags); | ||
84 | } | ||
73 | 85 | ||
74 | cpu_clear(smp_processor_id(), mask); | 86 | static void x2apic_send_IPI_allbutself(int vector) |
87 | { | ||
88 | unsigned long flags; | ||
89 | unsigned long query_cpu; | ||
90 | unsigned long this_cpu = smp_processor_id(); | ||
75 | 91 | ||
76 | if (!cpus_empty(mask)) | 92 | local_irq_save(flags); |
77 | x2apic_send_IPI_mask(mask, vector); | 93 | for_each_online_cpu(query_cpu) |
94 | if (query_cpu != this_cpu) | ||
95 | __x2apic_send_IPI_dest( | ||
96 | per_cpu(x86_cpu_to_apicid, query_cpu), | ||
97 | vector, APIC_DEST_PHYSICAL); | ||
98 | local_irq_restore(flags); | ||
78 | } | 99 | } |
79 | 100 | ||
80 | static void x2apic_send_IPI_all(int vector) | 101 | static void x2apic_send_IPI_all(int vector) |
81 | { | 102 | { |
82 | x2apic_send_IPI_mask(cpu_online_map, vector); | 103 | x2apic_send_IPI_mask(cpu_online_mask, vector); |
83 | } | 104 | } |
84 | 105 | ||
85 | static int x2apic_apic_id_registered(void) | 106 | static int x2apic_apic_id_registered(void) |
@@ -87,7 +108,7 @@ static int x2apic_apic_id_registered(void) | |||
87 | return 1; | 108 | return 1; |
88 | } | 109 | } |
89 | 110 | ||
90 | static unsigned int x2apic_cpu_mask_to_apicid(cpumask_t cpumask) | 111 | static unsigned int x2apic_cpu_mask_to_apicid(const struct cpumask *cpumask) |
91 | { | 112 | { |
92 | int cpu; | 113 | int cpu; |
93 | 114 | ||
@@ -95,13 +116,30 @@ static unsigned int x2apic_cpu_mask_to_apicid(cpumask_t cpumask) | |||
95 | * We're using fixed IRQ delivery, can only return one phys APIC ID. | 116 | * We're using fixed IRQ delivery, can only return one phys APIC ID. |
96 | * May as well be the first. | 117 | * May as well be the first. |
97 | */ | 118 | */ |
98 | cpu = first_cpu(cpumask); | 119 | cpu = cpumask_first(cpumask); |
99 | if ((unsigned)cpu < NR_CPUS) | 120 | if ((unsigned)cpu < nr_cpu_ids) |
100 | return per_cpu(x86_cpu_to_apicid, cpu); | 121 | return per_cpu(x86_cpu_to_apicid, cpu); |
101 | else | 122 | else |
102 | return BAD_APICID; | 123 | return BAD_APICID; |
103 | } | 124 | } |
104 | 125 | ||
126 | static unsigned int x2apic_cpu_mask_to_apicid_and(const struct cpumask *cpumask, | ||
127 | const struct cpumask *andmask) | ||
128 | { | ||
129 | int cpu; | ||
130 | |||
131 | /* | ||
132 | * We're using fixed IRQ delivery, can only return one phys APIC ID. | ||
133 | * May as well be the first. | ||
134 | */ | ||
135 | for_each_cpu_and(cpu, cpumask, andmask) | ||
136 | if (cpumask_test_cpu(cpu, cpu_online_mask)) | ||
137 | break; | ||
138 | if (cpu < nr_cpu_ids) | ||
139 | return per_cpu(x86_cpu_to_apicid, cpu); | ||
140 | return BAD_APICID; | ||
141 | } | ||
142 | |||
105 | static unsigned int get_apic_id(unsigned long x) | 143 | static unsigned int get_apic_id(unsigned long x) |
106 | { | 144 | { |
107 | unsigned int id; | 145 | unsigned int id; |
@@ -123,12 +161,12 @@ static unsigned int phys_pkg_id(int index_msb) | |||
123 | return current_cpu_data.initial_apicid >> index_msb; | 161 | return current_cpu_data.initial_apicid >> index_msb; |
124 | } | 162 | } |
125 | 163 | ||
126 | void x2apic_send_IPI_self(int vector) | 164 | static void x2apic_send_IPI_self(int vector) |
127 | { | 165 | { |
128 | apic_write(APIC_SELF_IPI, vector); | 166 | apic_write(APIC_SELF_IPI, vector); |
129 | } | 167 | } |
130 | 168 | ||
131 | void init_x2apic_ldr(void) | 169 | static void init_x2apic_ldr(void) |
132 | { | 170 | { |
133 | return; | 171 | return; |
134 | } | 172 | } |
@@ -145,8 +183,10 @@ struct genapic apic_x2apic_phys = { | |||
145 | .send_IPI_all = x2apic_send_IPI_all, | 183 | .send_IPI_all = x2apic_send_IPI_all, |
146 | .send_IPI_allbutself = x2apic_send_IPI_allbutself, | 184 | .send_IPI_allbutself = x2apic_send_IPI_allbutself, |
147 | .send_IPI_mask = x2apic_send_IPI_mask, | 185 | .send_IPI_mask = x2apic_send_IPI_mask, |
186 | .send_IPI_mask_allbutself = x2apic_send_IPI_mask_allbutself, | ||
148 | .send_IPI_self = x2apic_send_IPI_self, | 187 | .send_IPI_self = x2apic_send_IPI_self, |
149 | .cpu_mask_to_apicid = x2apic_cpu_mask_to_apicid, | 188 | .cpu_mask_to_apicid = x2apic_cpu_mask_to_apicid, |
189 | .cpu_mask_to_apicid_and = x2apic_cpu_mask_to_apicid_and, | ||
150 | .phys_pkg_id = phys_pkg_id, | 190 | .phys_pkg_id = phys_pkg_id, |
151 | .get_apic_id = get_apic_id, | 191 | .get_apic_id = get_apic_id, |
152 | .set_apic_id = set_apic_id, | 192 | .set_apic_id = set_apic_id, |
diff --git a/arch/x86/kernel/genx2apic_uv_x.c b/arch/x86/kernel/genx2apic_uv_x.c index 2c7dbdb98278..b193e082f6ce 100644 --- a/arch/x86/kernel/genx2apic_uv_x.c +++ b/arch/x86/kernel/genx2apic_uv_x.c | |||
@@ -10,6 +10,7 @@ | |||
10 | 10 | ||
11 | #include <linux/kernel.h> | 11 | #include <linux/kernel.h> |
12 | #include <linux/threads.h> | 12 | #include <linux/threads.h> |
13 | #include <linux/cpu.h> | ||
13 | #include <linux/cpumask.h> | 14 | #include <linux/cpumask.h> |
14 | #include <linux/string.h> | 15 | #include <linux/string.h> |
15 | #include <linux/ctype.h> | 16 | #include <linux/ctype.h> |
@@ -17,6 +18,9 @@ | |||
17 | #include <linux/sched.h> | 18 | #include <linux/sched.h> |
18 | #include <linux/module.h> | 19 | #include <linux/module.h> |
19 | #include <linux/hardirq.h> | 20 | #include <linux/hardirq.h> |
21 | #include <linux/timer.h> | ||
22 | #include <linux/proc_fs.h> | ||
23 | #include <asm/current.h> | ||
20 | #include <asm/smp.h> | 24 | #include <asm/smp.h> |
21 | #include <asm/ipi.h> | 25 | #include <asm/ipi.h> |
22 | #include <asm/genapic.h> | 26 | #include <asm/genapic.h> |
@@ -75,16 +79,15 @@ EXPORT_SYMBOL(sn_rtc_cycles_per_second); | |||
75 | 79 | ||
76 | /* Start with all IRQs pointing to boot CPU. IRQ balancing will shift them. */ | 80 | /* Start with all IRQs pointing to boot CPU. IRQ balancing will shift them. */ |
77 | 81 | ||
78 | static cpumask_t uv_target_cpus(void) | 82 | static const struct cpumask *uv_target_cpus(void) |
79 | { | 83 | { |
80 | return cpumask_of_cpu(0); | 84 | return cpumask_of(0); |
81 | } | 85 | } |
82 | 86 | ||
83 | static cpumask_t uv_vector_allocation_domain(int cpu) | 87 | static void uv_vector_allocation_domain(int cpu, struct cpumask *retmask) |
84 | { | 88 | { |
85 | cpumask_t domain = CPU_MASK_NONE; | 89 | cpumask_clear(retmask); |
86 | cpu_set(cpu, domain); | 90 | cpumask_set_cpu(cpu, retmask); |
87 | return domain; | ||
88 | } | 91 | } |
89 | 92 | ||
90 | int uv_wakeup_secondary(int phys_apicid, unsigned int start_rip) | 93 | int uv_wakeup_secondary(int phys_apicid, unsigned int start_rip) |
@@ -123,28 +126,37 @@ static void uv_send_IPI_one(int cpu, int vector) | |||
123 | uv_write_global_mmr64(pnode, UVH_IPI_INT, val); | 126 | uv_write_global_mmr64(pnode, UVH_IPI_INT, val); |
124 | } | 127 | } |
125 | 128 | ||
126 | static void uv_send_IPI_mask(cpumask_t mask, int vector) | 129 | static void uv_send_IPI_mask(const struct cpumask *mask, int vector) |
127 | { | 130 | { |
128 | unsigned int cpu; | 131 | unsigned int cpu; |
129 | 132 | ||
130 | for_each_possible_cpu(cpu) | 133 | for_each_cpu(cpu, mask) |
131 | if (cpu_isset(cpu, mask)) | 134 | uv_send_IPI_one(cpu, vector); |
135 | } | ||
136 | |||
137 | static void uv_send_IPI_mask_allbutself(const struct cpumask *mask, int vector) | ||
138 | { | ||
139 | unsigned int cpu; | ||
140 | unsigned int this_cpu = smp_processor_id(); | ||
141 | |||
142 | for_each_cpu(cpu, mask) | ||
143 | if (cpu != this_cpu) | ||
132 | uv_send_IPI_one(cpu, vector); | 144 | uv_send_IPI_one(cpu, vector); |
133 | } | 145 | } |
134 | 146 | ||
135 | static void uv_send_IPI_allbutself(int vector) | 147 | static void uv_send_IPI_allbutself(int vector) |
136 | { | 148 | { |
137 | cpumask_t mask = cpu_online_map; | 149 | unsigned int cpu; |
138 | 150 | unsigned int this_cpu = smp_processor_id(); | |
139 | cpu_clear(smp_processor_id(), mask); | ||
140 | 151 | ||
141 | if (!cpus_empty(mask)) | 152 | for_each_online_cpu(cpu) |
142 | uv_send_IPI_mask(mask, vector); | 153 | if (cpu != this_cpu) |
154 | uv_send_IPI_one(cpu, vector); | ||
143 | } | 155 | } |
144 | 156 | ||
145 | static void uv_send_IPI_all(int vector) | 157 | static void uv_send_IPI_all(int vector) |
146 | { | 158 | { |
147 | uv_send_IPI_mask(cpu_online_map, vector); | 159 | uv_send_IPI_mask(cpu_online_mask, vector); |
148 | } | 160 | } |
149 | 161 | ||
150 | static int uv_apic_id_registered(void) | 162 | static int uv_apic_id_registered(void) |
@@ -156,7 +168,7 @@ static void uv_init_apic_ldr(void) | |||
156 | { | 168 | { |
157 | } | 169 | } |
158 | 170 | ||
159 | static unsigned int uv_cpu_mask_to_apicid(cpumask_t cpumask) | 171 | static unsigned int uv_cpu_mask_to_apicid(const struct cpumask *cpumask) |
160 | { | 172 | { |
161 | int cpu; | 173 | int cpu; |
162 | 174 | ||
@@ -164,13 +176,30 @@ static unsigned int uv_cpu_mask_to_apicid(cpumask_t cpumask) | |||
164 | * We're using fixed IRQ delivery, can only return one phys APIC ID. | 176 | * We're using fixed IRQ delivery, can only return one phys APIC ID. |
165 | * May as well be the first. | 177 | * May as well be the first. |
166 | */ | 178 | */ |
167 | cpu = first_cpu(cpumask); | 179 | cpu = cpumask_first(cpumask); |
168 | if ((unsigned)cpu < nr_cpu_ids) | 180 | if ((unsigned)cpu < nr_cpu_ids) |
169 | return per_cpu(x86_cpu_to_apicid, cpu); | 181 | return per_cpu(x86_cpu_to_apicid, cpu); |
170 | else | 182 | else |
171 | return BAD_APICID; | 183 | return BAD_APICID; |
172 | } | 184 | } |
173 | 185 | ||
186 | static unsigned int uv_cpu_mask_to_apicid_and(const struct cpumask *cpumask, | ||
187 | const struct cpumask *andmask) | ||
188 | { | ||
189 | int cpu; | ||
190 | |||
191 | /* | ||
192 | * We're using fixed IRQ delivery, can only return one phys APIC ID. | ||
193 | * May as well be the first. | ||
194 | */ | ||
195 | for_each_cpu_and(cpu, cpumask, andmask) | ||
196 | if (cpumask_test_cpu(cpu, cpu_online_mask)) | ||
197 | break; | ||
198 | if (cpu < nr_cpu_ids) | ||
199 | return per_cpu(x86_cpu_to_apicid, cpu); | ||
200 | return BAD_APICID; | ||
201 | } | ||
202 | |||
174 | static unsigned int get_apic_id(unsigned long x) | 203 | static unsigned int get_apic_id(unsigned long x) |
175 | { | 204 | { |
176 | unsigned int id; | 205 | unsigned int id; |
@@ -218,8 +247,10 @@ struct genapic apic_x2apic_uv_x = { | |||
218 | .send_IPI_all = uv_send_IPI_all, | 247 | .send_IPI_all = uv_send_IPI_all, |
219 | .send_IPI_allbutself = uv_send_IPI_allbutself, | 248 | .send_IPI_allbutself = uv_send_IPI_allbutself, |
220 | .send_IPI_mask = uv_send_IPI_mask, | 249 | .send_IPI_mask = uv_send_IPI_mask, |
250 | .send_IPI_mask_allbutself = uv_send_IPI_mask_allbutself, | ||
221 | .send_IPI_self = uv_send_IPI_self, | 251 | .send_IPI_self = uv_send_IPI_self, |
222 | .cpu_mask_to_apicid = uv_cpu_mask_to_apicid, | 252 | .cpu_mask_to_apicid = uv_cpu_mask_to_apicid, |
253 | .cpu_mask_to_apicid_and = uv_cpu_mask_to_apicid_and, | ||
223 | .phys_pkg_id = phys_pkg_id, | 254 | .phys_pkg_id = phys_pkg_id, |
224 | .get_apic_id = get_apic_id, | 255 | .get_apic_id = get_apic_id, |
225 | .set_apic_id = set_apic_id, | 256 | .set_apic_id = set_apic_id, |
@@ -356,6 +387,103 @@ static __init void uv_rtc_init(void) | |||
356 | } | 387 | } |
357 | 388 | ||
358 | /* | 389 | /* |
390 | * percpu heartbeat timer | ||
391 | */ | ||
392 | static void uv_heartbeat(unsigned long ignored) | ||
393 | { | ||
394 | struct timer_list *timer = &uv_hub_info->scir.timer; | ||
395 | unsigned char bits = uv_hub_info->scir.state; | ||
396 | |||
397 | /* flip heartbeat bit */ | ||
398 | bits ^= SCIR_CPU_HEARTBEAT; | ||
399 | |||
400 | /* is this cpu idle? */ | ||
401 | if (idle_cpu(raw_smp_processor_id())) | ||
402 | bits &= ~SCIR_CPU_ACTIVITY; | ||
403 | else | ||
404 | bits |= SCIR_CPU_ACTIVITY; | ||
405 | |||
406 | /* update system controller interface reg */ | ||
407 | uv_set_scir_bits(bits); | ||
408 | |||
409 | /* enable next timer period */ | ||
410 | mod_timer(timer, jiffies + SCIR_CPU_HB_INTERVAL); | ||
411 | } | ||
412 | |||
413 | static void __cpuinit uv_heartbeat_enable(int cpu) | ||
414 | { | ||
415 | if (!uv_cpu_hub_info(cpu)->scir.enabled) { | ||
416 | struct timer_list *timer = &uv_cpu_hub_info(cpu)->scir.timer; | ||
417 | |||
418 | uv_set_cpu_scir_bits(cpu, SCIR_CPU_HEARTBEAT|SCIR_CPU_ACTIVITY); | ||
419 | setup_timer(timer, uv_heartbeat, cpu); | ||
420 | timer->expires = jiffies + SCIR_CPU_HB_INTERVAL; | ||
421 | add_timer_on(timer, cpu); | ||
422 | uv_cpu_hub_info(cpu)->scir.enabled = 1; | ||
423 | } | ||
424 | |||
425 | /* check boot cpu */ | ||
426 | if (!uv_cpu_hub_info(0)->scir.enabled) | ||
427 | uv_heartbeat_enable(0); | ||
428 | } | ||
429 | |||
430 | #ifdef CONFIG_HOTPLUG_CPU | ||
431 | static void __cpuinit uv_heartbeat_disable(int cpu) | ||
432 | { | ||
433 | if (uv_cpu_hub_info(cpu)->scir.enabled) { | ||
434 | uv_cpu_hub_info(cpu)->scir.enabled = 0; | ||
435 | del_timer(&uv_cpu_hub_info(cpu)->scir.timer); | ||
436 | } | ||
437 | uv_set_cpu_scir_bits(cpu, 0xff); | ||
438 | } | ||
439 | |||
440 | /* | ||
441 | * cpu hotplug notifier | ||
442 | */ | ||
443 | static __cpuinit int uv_scir_cpu_notify(struct notifier_block *self, | ||
444 | unsigned long action, void *hcpu) | ||
445 | { | ||
446 | long cpu = (long)hcpu; | ||
447 | |||
448 | switch (action) { | ||
449 | case CPU_ONLINE: | ||
450 | uv_heartbeat_enable(cpu); | ||
451 | break; | ||
452 | case CPU_DOWN_PREPARE: | ||
453 | uv_heartbeat_disable(cpu); | ||
454 | break; | ||
455 | default: | ||
456 | break; | ||
457 | } | ||
458 | return NOTIFY_OK; | ||
459 | } | ||
460 | |||
461 | static __init void uv_scir_register_cpu_notifier(void) | ||
462 | { | ||
463 | hotcpu_notifier(uv_scir_cpu_notify, 0); | ||
464 | } | ||
465 | |||
466 | #else /* !CONFIG_HOTPLUG_CPU */ | ||
467 | |||
468 | static __init void uv_scir_register_cpu_notifier(void) | ||
469 | { | ||
470 | } | ||
471 | |||
472 | static __init int uv_init_heartbeat(void) | ||
473 | { | ||
474 | int cpu; | ||
475 | |||
476 | if (is_uv_system()) | ||
477 | for_each_online_cpu(cpu) | ||
478 | uv_heartbeat_enable(cpu); | ||
479 | return 0; | ||
480 | } | ||
481 | |||
482 | late_initcall(uv_init_heartbeat); | ||
483 | |||
484 | #endif /* !CONFIG_HOTPLUG_CPU */ | ||
485 | |||
486 | /* | ||
359 | * Called on each cpu to initialize the per_cpu UV data area. | 487 | * Called on each cpu to initialize the per_cpu UV data area. |
360 | * ZZZ hotplug not supported yet | 488 | * ZZZ hotplug not supported yet |
361 | */ | 489 | */ |
@@ -428,7 +556,7 @@ void __init uv_system_init(void) | |||
428 | 556 | ||
429 | uv_bios_init(); | 557 | uv_bios_init(); |
430 | uv_bios_get_sn_info(0, &uv_type, &sn_partition_id, | 558 | uv_bios_get_sn_info(0, &uv_type, &sn_partition_id, |
431 | &uv_coherency_id, &uv_region_size); | 559 | &sn_coherency_id, &sn_region_size); |
432 | uv_rtc_init(); | 560 | uv_rtc_init(); |
433 | 561 | ||
434 | for_each_present_cpu(cpu) { | 562 | for_each_present_cpu(cpu) { |
@@ -439,8 +567,7 @@ void __init uv_system_init(void) | |||
439 | uv_blade_info[blade].nr_possible_cpus++; | 567 | uv_blade_info[blade].nr_possible_cpus++; |
440 | 568 | ||
441 | uv_cpu_hub_info(cpu)->lowmem_remap_base = lowmem_redir_base; | 569 | uv_cpu_hub_info(cpu)->lowmem_remap_base = lowmem_redir_base; |
442 | uv_cpu_hub_info(cpu)->lowmem_remap_top = | 570 | uv_cpu_hub_info(cpu)->lowmem_remap_top = lowmem_redir_size; |
443 | lowmem_redir_base + lowmem_redir_size; | ||
444 | uv_cpu_hub_info(cpu)->m_val = m_val; | 571 | uv_cpu_hub_info(cpu)->m_val = m_val; |
445 | uv_cpu_hub_info(cpu)->n_val = m_val; | 572 | uv_cpu_hub_info(cpu)->n_val = m_val; |
446 | uv_cpu_hub_info(cpu)->numa_blade_id = blade; | 573 | uv_cpu_hub_info(cpu)->numa_blade_id = blade; |
@@ -450,7 +577,8 @@ void __init uv_system_init(void) | |||
450 | uv_cpu_hub_info(cpu)->gpa_mask = (1 << (m_val + n_val)) - 1; | 577 | uv_cpu_hub_info(cpu)->gpa_mask = (1 << (m_val + n_val)) - 1; |
451 | uv_cpu_hub_info(cpu)->gnode_upper = gnode_upper; | 578 | uv_cpu_hub_info(cpu)->gnode_upper = gnode_upper; |
452 | uv_cpu_hub_info(cpu)->global_mmr_base = mmr_base; | 579 | uv_cpu_hub_info(cpu)->global_mmr_base = mmr_base; |
453 | uv_cpu_hub_info(cpu)->coherency_domain_number = uv_coherency_id; | 580 | uv_cpu_hub_info(cpu)->coherency_domain_number = sn_coherency_id; |
581 | uv_cpu_hub_info(cpu)->scir.offset = SCIR_LOCAL_MMR_BASE + lcpu; | ||
454 | uv_node_to_blade[nid] = blade; | 582 | uv_node_to_blade[nid] = blade; |
455 | uv_cpu_to_blade[cpu] = blade; | 583 | uv_cpu_to_blade[cpu] = blade; |
456 | max_pnode = max(pnode, max_pnode); | 584 | max_pnode = max(pnode, max_pnode); |
@@ -467,4 +595,6 @@ void __init uv_system_init(void) | |||
467 | map_mmioh_high(max_pnode); | 595 | map_mmioh_high(max_pnode); |
468 | 596 | ||
469 | uv_cpu_init(); | 597 | uv_cpu_init(); |
598 | uv_scir_register_cpu_notifier(); | ||
599 | proc_mkdir("sgi_uv", NULL); | ||
470 | } | 600 | } |
diff --git a/arch/x86/kernel/head.c b/arch/x86/kernel/head.c index 1dcb0f13897e..3e66bd364a9d 100644 --- a/arch/x86/kernel/head.c +++ b/arch/x86/kernel/head.c | |||
@@ -35,7 +35,6 @@ void __init reserve_ebda_region(void) | |||
35 | 35 | ||
36 | /* start of EBDA area */ | 36 | /* start of EBDA area */ |
37 | ebda_addr = get_bios_ebda(); | 37 | ebda_addr = get_bios_ebda(); |
38 | printk(KERN_INFO "BIOS EBDA/lowmem at: %08x/%08x\n", ebda_addr, lowmem); | ||
39 | 38 | ||
40 | /* Fixup: bios puts an EBDA in the top 64K segment */ | 39 | /* Fixup: bios puts an EBDA in the top 64K segment */ |
41 | /* of conventional memory, but does not adjust lowmem. */ | 40 | /* of conventional memory, but does not adjust lowmem. */ |
diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c index fa1d25dd83e3..ac108d1fe182 100644 --- a/arch/x86/kernel/head32.c +++ b/arch/x86/kernel/head32.c | |||
@@ -12,9 +12,12 @@ | |||
12 | #include <asm/sections.h> | 12 | #include <asm/sections.h> |
13 | #include <asm/e820.h> | 13 | #include <asm/e820.h> |
14 | #include <asm/bios_ebda.h> | 14 | #include <asm/bios_ebda.h> |
15 | #include <asm/trampoline.h> | ||
15 | 16 | ||
16 | void __init i386_start_kernel(void) | 17 | void __init i386_start_kernel(void) |
17 | { | 18 | { |
19 | reserve_trampoline_memory(); | ||
20 | |||
18 | reserve_early(__pa_symbol(&_text), __pa_symbol(&_end), "TEXT DATA BSS"); | 21 | reserve_early(__pa_symbol(&_text), __pa_symbol(&_end), "TEXT DATA BSS"); |
19 | 22 | ||
20 | #ifdef CONFIG_BLK_DEV_INITRD | 23 | #ifdef CONFIG_BLK_DEV_INITRD |
diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index d16084f90649..b9a4d8c4b935 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c | |||
@@ -24,9 +24,10 @@ | |||
24 | #include <asm/kdebug.h> | 24 | #include <asm/kdebug.h> |
25 | #include <asm/e820.h> | 25 | #include <asm/e820.h> |
26 | #include <asm/bios_ebda.h> | 26 | #include <asm/bios_ebda.h> |
27 | #include <asm/trampoline.h> | ||
27 | 28 | ||
28 | /* boot cpu pda */ | 29 | /* boot cpu pda */ |
29 | static struct x8664_pda _boot_cpu_pda __read_mostly; | 30 | static struct x8664_pda _boot_cpu_pda; |
30 | 31 | ||
31 | #ifdef CONFIG_SMP | 32 | #ifdef CONFIG_SMP |
32 | /* | 33 | /* |
@@ -120,6 +121,8 @@ void __init x86_64_start_reservations(char *real_mode_data) | |||
120 | { | 121 | { |
121 | copy_bootdata(__va(real_mode_data)); | 122 | copy_bootdata(__va(real_mode_data)); |
122 | 123 | ||
124 | reserve_trampoline_memory(); | ||
125 | |||
123 | reserve_early(__pa_symbol(&_text), __pa_symbol(&_end), "TEXT DATA BSS"); | 126 | reserve_early(__pa_symbol(&_text), __pa_symbol(&_end), "TEXT DATA BSS"); |
124 | 127 | ||
125 | #ifdef CONFIG_BLK_DEV_INITRD | 128 | #ifdef CONFIG_BLK_DEV_INITRD |
diff --git a/arch/x86/kernel/hpet.c b/arch/x86/kernel/hpet.c index 067d8de913f6..cd759ad90690 100644 --- a/arch/x86/kernel/hpet.c +++ b/arch/x86/kernel/hpet.c | |||
@@ -33,7 +33,9 @@ | |||
33 | * HPET address is set in acpi/boot.c, when an ACPI entry exists | 33 | * HPET address is set in acpi/boot.c, when an ACPI entry exists |
34 | */ | 34 | */ |
35 | unsigned long hpet_address; | 35 | unsigned long hpet_address; |
36 | unsigned long hpet_num_timers; | 36 | #ifdef CONFIG_PCI_MSI |
37 | static unsigned long hpet_num_timers; | ||
38 | #endif | ||
37 | static void __iomem *hpet_virt_address; | 39 | static void __iomem *hpet_virt_address; |
38 | 40 | ||
39 | struct hpet_dev { | 41 | struct hpet_dev { |
@@ -246,7 +248,7 @@ static void hpet_legacy_clockevent_register(void) | |||
246 | * Start hpet with the boot cpu mask and make it | 248 | * Start hpet with the boot cpu mask and make it |
247 | * global after the IO_APIC has been initialized. | 249 | * global after the IO_APIC has been initialized. |
248 | */ | 250 | */ |
249 | hpet_clockevent.cpumask = cpumask_of_cpu(smp_processor_id()); | 251 | hpet_clockevent.cpumask = cpumask_of(smp_processor_id()); |
250 | clockevents_register_device(&hpet_clockevent); | 252 | clockevents_register_device(&hpet_clockevent); |
251 | global_clock_event = &hpet_clockevent; | 253 | global_clock_event = &hpet_clockevent; |
252 | printk(KERN_DEBUG "hpet clockevent registered\n"); | 254 | printk(KERN_DEBUG "hpet clockevent registered\n"); |
@@ -301,7 +303,7 @@ static void hpet_set_mode(enum clock_event_mode mode, | |||
301 | struct hpet_dev *hdev = EVT_TO_HPET_DEV(evt); | 303 | struct hpet_dev *hdev = EVT_TO_HPET_DEV(evt); |
302 | hpet_setup_msi_irq(hdev->irq); | 304 | hpet_setup_msi_irq(hdev->irq); |
303 | disable_irq(hdev->irq); | 305 | disable_irq(hdev->irq); |
304 | irq_set_affinity(hdev->irq, cpumask_of_cpu(hdev->cpu)); | 306 | irq_set_affinity(hdev->irq, cpumask_of(hdev->cpu)); |
305 | enable_irq(hdev->irq); | 307 | enable_irq(hdev->irq); |
306 | } | 308 | } |
307 | break; | 309 | break; |
@@ -449,7 +451,7 @@ static int hpet_setup_irq(struct hpet_dev *dev) | |||
449 | return -1; | 451 | return -1; |
450 | 452 | ||
451 | disable_irq(dev->irq); | 453 | disable_irq(dev->irq); |
452 | irq_set_affinity(dev->irq, cpumask_of_cpu(dev->cpu)); | 454 | irq_set_affinity(dev->irq, cpumask_of(dev->cpu)); |
453 | enable_irq(dev->irq); | 455 | enable_irq(dev->irq); |
454 | 456 | ||
455 | printk(KERN_DEBUG "hpet: %s irq %d for MSI\n", | 457 | printk(KERN_DEBUG "hpet: %s irq %d for MSI\n", |
@@ -500,7 +502,7 @@ static void init_one_hpet_msi_clockevent(struct hpet_dev *hdev, int cpu) | |||
500 | /* 5 usec minimum reprogramming delta. */ | 502 | /* 5 usec minimum reprogramming delta. */ |
501 | evt->min_delta_ns = 5000; | 503 | evt->min_delta_ns = 5000; |
502 | 504 | ||
503 | evt->cpumask = cpumask_of_cpu(hdev->cpu); | 505 | evt->cpumask = cpumask_of(hdev->cpu); |
504 | clockevents_register_device(evt); | 506 | clockevents_register_device(evt); |
505 | } | 507 | } |
506 | 508 | ||
@@ -811,7 +813,7 @@ int __init hpet_enable(void) | |||
811 | 813 | ||
812 | out_nohpet: | 814 | out_nohpet: |
813 | hpet_clear_mapping(); | 815 | hpet_clear_mapping(); |
814 | boot_hpet_disable = 1; | 816 | hpet_address = 0; |
815 | return 0; | 817 | return 0; |
816 | } | 818 | } |
817 | 819 | ||
@@ -834,10 +836,11 @@ static __init int hpet_late_init(void) | |||
834 | 836 | ||
835 | hpet_address = force_hpet_address; | 837 | hpet_address = force_hpet_address; |
836 | hpet_enable(); | 838 | hpet_enable(); |
837 | if (!hpet_virt_address) | ||
838 | return -ENODEV; | ||
839 | } | 839 | } |
840 | 840 | ||
841 | if (!hpet_virt_address) | ||
842 | return -ENODEV; | ||
843 | |||
841 | hpet_reserve_platform_timers(hpet_readl(HPET_ID)); | 844 | hpet_reserve_platform_timers(hpet_readl(HPET_ID)); |
842 | 845 | ||
843 | for_each_online_cpu(cpu) { | 846 | for_each_online_cpu(cpu) { |
diff --git a/arch/x86/kernel/i8253.c b/arch/x86/kernel/i8253.c index c1b5e3ece1f2..10f92fb532f3 100644 --- a/arch/x86/kernel/i8253.c +++ b/arch/x86/kernel/i8253.c | |||
@@ -114,7 +114,7 @@ void __init setup_pit_timer(void) | |||
114 | * Start pit with the boot cpu mask and make it global after the | 114 | * Start pit with the boot cpu mask and make it global after the |
115 | * IO_APIC has been initialized. | 115 | * IO_APIC has been initialized. |
116 | */ | 116 | */ |
117 | pit_clockevent.cpumask = cpumask_of_cpu(smp_processor_id()); | 117 | pit_clockevent.cpumask = cpumask_of(smp_processor_id()); |
118 | pit_clockevent.mult = div_sc(CLOCK_TICK_RATE, NSEC_PER_SEC, | 118 | pit_clockevent.mult = div_sc(CLOCK_TICK_RATE, NSEC_PER_SEC, |
119 | pit_clockevent.shift); | 119 | pit_clockevent.shift); |
120 | pit_clockevent.max_delta_ns = | 120 | pit_clockevent.max_delta_ns = |
diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c index a4f93b4120c1..df3bf269beab 100644 --- a/arch/x86/kernel/init_task.c +++ b/arch/x86/kernel/init_task.c | |||
@@ -10,11 +10,9 @@ | |||
10 | #include <asm/pgtable.h> | 10 | #include <asm/pgtable.h> |
11 | #include <asm/desc.h> | 11 | #include <asm/desc.h> |
12 | 12 | ||
13 | static struct fs_struct init_fs = INIT_FS; | ||
14 | static struct signal_struct init_signals = INIT_SIGNALS(init_signals); | 13 | static struct signal_struct init_signals = INIT_SIGNALS(init_signals); |
15 | static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand); | 14 | static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand); |
16 | struct mm_struct init_mm = INIT_MM(init_mm); | 15 | struct mm_struct init_mm = INIT_MM(init_mm); |
17 | EXPORT_UNUSED_SYMBOL(init_mm); /* will be removed in 2.6.26 */ | ||
18 | 16 | ||
19 | /* | 17 | /* |
20 | * Initial thread structure. | 18 | * Initial thread structure. |
diff --git a/arch/x86/kernel/io_apic.c b/arch/x86/kernel/io_apic.c index 9043251210fb..3639442aa7a4 100644 --- a/arch/x86/kernel/io_apic.c +++ b/arch/x86/kernel/io_apic.c | |||
@@ -108,93 +108,276 @@ static int __init parse_noapic(char *str) | |||
108 | early_param("noapic", parse_noapic); | 108 | early_param("noapic", parse_noapic); |
109 | 109 | ||
110 | struct irq_pin_list; | 110 | struct irq_pin_list; |
111 | |||
112 | /* | ||
113 | * This is performance-critical, we want to do it O(1) | ||
114 | * | ||
115 | * the indexing order of this array favors 1:1 mappings | ||
116 | * between pins and IRQs. | ||
117 | */ | ||
118 | |||
119 | struct irq_pin_list { | ||
120 | int apic, pin; | ||
121 | struct irq_pin_list *next; | ||
122 | }; | ||
123 | |||
124 | static struct irq_pin_list *get_one_free_irq_2_pin(int cpu) | ||
125 | { | ||
126 | struct irq_pin_list *pin; | ||
127 | int node; | ||
128 | |||
129 | node = cpu_to_node(cpu); | ||
130 | |||
131 | pin = kzalloc_node(sizeof(*pin), GFP_ATOMIC, node); | ||
132 | printk(KERN_DEBUG " alloc irq_2_pin on cpu %d node %d\n", cpu, node); | ||
133 | |||
134 | return pin; | ||
135 | } | ||
136 | |||
111 | struct irq_cfg { | 137 | struct irq_cfg { |
112 | unsigned int irq; | ||
113 | struct irq_pin_list *irq_2_pin; | 138 | struct irq_pin_list *irq_2_pin; |
114 | cpumask_t domain; | 139 | cpumask_var_t domain; |
115 | cpumask_t old_domain; | 140 | cpumask_var_t old_domain; |
116 | unsigned move_cleanup_count; | 141 | unsigned move_cleanup_count; |
117 | u8 vector; | 142 | u8 vector; |
118 | u8 move_in_progress : 1; | 143 | u8 move_in_progress : 1; |
144 | #ifdef CONFIG_NUMA_MIGRATE_IRQ_DESC | ||
145 | u8 move_desc_pending : 1; | ||
146 | #endif | ||
119 | }; | 147 | }; |
120 | 148 | ||
121 | /* irq_cfg is indexed by the sum of all RTEs in all I/O APICs. */ | 149 | /* irq_cfg is indexed by the sum of all RTEs in all I/O APICs. */ |
150 | #ifdef CONFIG_SPARSE_IRQ | ||
151 | static struct irq_cfg irq_cfgx[] = { | ||
152 | #else | ||
122 | static struct irq_cfg irq_cfgx[NR_IRQS] = { | 153 | static struct irq_cfg irq_cfgx[NR_IRQS] = { |
123 | [0] = { .irq = 0, .domain = CPU_MASK_ALL, .vector = IRQ0_VECTOR, }, | 154 | #endif |
124 | [1] = { .irq = 1, .domain = CPU_MASK_ALL, .vector = IRQ1_VECTOR, }, | 155 | [0] = { .vector = IRQ0_VECTOR, }, |
125 | [2] = { .irq = 2, .domain = CPU_MASK_ALL, .vector = IRQ2_VECTOR, }, | 156 | [1] = { .vector = IRQ1_VECTOR, }, |
126 | [3] = { .irq = 3, .domain = CPU_MASK_ALL, .vector = IRQ3_VECTOR, }, | 157 | [2] = { .vector = IRQ2_VECTOR, }, |
127 | [4] = { .irq = 4, .domain = CPU_MASK_ALL, .vector = IRQ4_VECTOR, }, | 158 | [3] = { .vector = IRQ3_VECTOR, }, |
128 | [5] = { .irq = 5, .domain = CPU_MASK_ALL, .vector = IRQ5_VECTOR, }, | 159 | [4] = { .vector = IRQ4_VECTOR, }, |
129 | [6] = { .irq = 6, .domain = CPU_MASK_ALL, .vector = IRQ6_VECTOR, }, | 160 | [5] = { .vector = IRQ5_VECTOR, }, |
130 | [7] = { .irq = 7, .domain = CPU_MASK_ALL, .vector = IRQ7_VECTOR, }, | 161 | [6] = { .vector = IRQ6_VECTOR, }, |
131 | [8] = { .irq = 8, .domain = CPU_MASK_ALL, .vector = IRQ8_VECTOR, }, | 162 | [7] = { .vector = IRQ7_VECTOR, }, |
132 | [9] = { .irq = 9, .domain = CPU_MASK_ALL, .vector = IRQ9_VECTOR, }, | 163 | [8] = { .vector = IRQ8_VECTOR, }, |
133 | [10] = { .irq = 10, .domain = CPU_MASK_ALL, .vector = IRQ10_VECTOR, }, | 164 | [9] = { .vector = IRQ9_VECTOR, }, |
134 | [11] = { .irq = 11, .domain = CPU_MASK_ALL, .vector = IRQ11_VECTOR, }, | 165 | [10] = { .vector = IRQ10_VECTOR, }, |
135 | [12] = { .irq = 12, .domain = CPU_MASK_ALL, .vector = IRQ12_VECTOR, }, | 166 | [11] = { .vector = IRQ11_VECTOR, }, |
136 | [13] = { .irq = 13, .domain = CPU_MASK_ALL, .vector = IRQ13_VECTOR, }, | 167 | [12] = { .vector = IRQ12_VECTOR, }, |
137 | [14] = { .irq = 14, .domain = CPU_MASK_ALL, .vector = IRQ14_VECTOR, }, | 168 | [13] = { .vector = IRQ13_VECTOR, }, |
138 | [15] = { .irq = 15, .domain = CPU_MASK_ALL, .vector = IRQ15_VECTOR, }, | 169 | [14] = { .vector = IRQ14_VECTOR, }, |
170 | [15] = { .vector = IRQ15_VECTOR, }, | ||
139 | }; | 171 | }; |
140 | 172 | ||
141 | #define for_each_irq_cfg(irq, cfg) \ | 173 | int __init arch_early_irq_init(void) |
142 | for (irq = 0, cfg = irq_cfgx; irq < nr_irqs; irq++, cfg++) | 174 | { |
175 | struct irq_cfg *cfg; | ||
176 | struct irq_desc *desc; | ||
177 | int count; | ||
178 | int i; | ||
179 | |||
180 | cfg = irq_cfgx; | ||
181 | count = ARRAY_SIZE(irq_cfgx); | ||
143 | 182 | ||
183 | for (i = 0; i < count; i++) { | ||
184 | desc = irq_to_desc(i); | ||
185 | desc->chip_data = &cfg[i]; | ||
186 | alloc_bootmem_cpumask_var(&cfg[i].domain); | ||
187 | alloc_bootmem_cpumask_var(&cfg[i].old_domain); | ||
188 | if (i < NR_IRQS_LEGACY) | ||
189 | cpumask_setall(cfg[i].domain); | ||
190 | } | ||
191 | |||
192 | return 0; | ||
193 | } | ||
194 | |||
195 | #ifdef CONFIG_SPARSE_IRQ | ||
144 | static struct irq_cfg *irq_cfg(unsigned int irq) | 196 | static struct irq_cfg *irq_cfg(unsigned int irq) |
145 | { | 197 | { |
146 | return irq < nr_irqs ? irq_cfgx + irq : NULL; | 198 | struct irq_cfg *cfg = NULL; |
199 | struct irq_desc *desc; | ||
200 | |||
201 | desc = irq_to_desc(irq); | ||
202 | if (desc) | ||
203 | cfg = desc->chip_data; | ||
204 | |||
205 | return cfg; | ||
147 | } | 206 | } |
148 | 207 | ||
149 | static struct irq_cfg *irq_cfg_alloc(unsigned int irq) | 208 | static struct irq_cfg *get_one_free_irq_cfg(int cpu) |
150 | { | 209 | { |
151 | return irq_cfg(irq); | 210 | struct irq_cfg *cfg; |
211 | int node; | ||
212 | |||
213 | node = cpu_to_node(cpu); | ||
214 | |||
215 | cfg = kzalloc_node(sizeof(*cfg), GFP_ATOMIC, node); | ||
216 | if (cfg) { | ||
217 | if (!alloc_cpumask_var_node(&cfg->domain, GFP_ATOMIC, node)) { | ||
218 | kfree(cfg); | ||
219 | cfg = NULL; | ||
220 | } else if (!alloc_cpumask_var_node(&cfg->old_domain, | ||
221 | GFP_ATOMIC, node)) { | ||
222 | free_cpumask_var(cfg->domain); | ||
223 | kfree(cfg); | ||
224 | cfg = NULL; | ||
225 | } else { | ||
226 | cpumask_clear(cfg->domain); | ||
227 | cpumask_clear(cfg->old_domain); | ||
228 | } | ||
229 | } | ||
230 | printk(KERN_DEBUG " alloc irq_cfg on cpu %d node %d\n", cpu, node); | ||
231 | |||
232 | return cfg; | ||
152 | } | 233 | } |
153 | 234 | ||
154 | /* | 235 | int arch_init_chip_data(struct irq_desc *desc, int cpu) |
155 | * Rough estimation of how many shared IRQs there are, can be changed | 236 | { |
156 | * anytime. | 237 | struct irq_cfg *cfg; |
157 | */ | ||
158 | #define MAX_PLUS_SHARED_IRQS NR_IRQS | ||
159 | #define PIN_MAP_SIZE (MAX_PLUS_SHARED_IRQS + NR_IRQS) | ||
160 | 238 | ||
161 | /* | 239 | cfg = desc->chip_data; |
162 | * This is performance-critical, we want to do it O(1) | 240 | if (!cfg) { |
163 | * | 241 | desc->chip_data = get_one_free_irq_cfg(cpu); |
164 | * the indexing order of this array favors 1:1 mappings | 242 | if (!desc->chip_data) { |
165 | * between pins and IRQs. | 243 | printk(KERN_ERR "can not alloc irq_cfg\n"); |
166 | */ | 244 | BUG_ON(1); |
245 | } | ||
246 | } | ||
167 | 247 | ||
168 | struct irq_pin_list { | 248 | return 0; |
169 | int apic, pin; | 249 | } |
170 | struct irq_pin_list *next; | ||
171 | }; | ||
172 | 250 | ||
173 | static struct irq_pin_list irq_2_pin_head[PIN_MAP_SIZE]; | 251 | #ifdef CONFIG_NUMA_MIGRATE_IRQ_DESC |
174 | static struct irq_pin_list *irq_2_pin_ptr; | ||
175 | 252 | ||
176 | static void __init irq_2_pin_init(void) | 253 | static void |
254 | init_copy_irq_2_pin(struct irq_cfg *old_cfg, struct irq_cfg *cfg, int cpu) | ||
177 | { | 255 | { |
178 | struct irq_pin_list *pin = irq_2_pin_head; | 256 | struct irq_pin_list *old_entry, *head, *tail, *entry; |
179 | int i; | 257 | |
258 | cfg->irq_2_pin = NULL; | ||
259 | old_entry = old_cfg->irq_2_pin; | ||
260 | if (!old_entry) | ||
261 | return; | ||
262 | |||
263 | entry = get_one_free_irq_2_pin(cpu); | ||
264 | if (!entry) | ||
265 | return; | ||
266 | |||
267 | entry->apic = old_entry->apic; | ||
268 | entry->pin = old_entry->pin; | ||
269 | head = entry; | ||
270 | tail = entry; | ||
271 | old_entry = old_entry->next; | ||
272 | while (old_entry) { | ||
273 | entry = get_one_free_irq_2_pin(cpu); | ||
274 | if (!entry) { | ||
275 | entry = head; | ||
276 | while (entry) { | ||
277 | head = entry->next; | ||
278 | kfree(entry); | ||
279 | entry = head; | ||
280 | } | ||
281 | /* still use the old one */ | ||
282 | return; | ||
283 | } | ||
284 | entry->apic = old_entry->apic; | ||
285 | entry->pin = old_entry->pin; | ||
286 | tail->next = entry; | ||
287 | tail = entry; | ||
288 | old_entry = old_entry->next; | ||
289 | } | ||
180 | 290 | ||
181 | for (i = 1; i < PIN_MAP_SIZE; i++) | 291 | tail->next = NULL; |
182 | pin[i-1].next = &pin[i]; | 292 | cfg->irq_2_pin = head; |
293 | } | ||
294 | |||
295 | static void free_irq_2_pin(struct irq_cfg *old_cfg, struct irq_cfg *cfg) | ||
296 | { | ||
297 | struct irq_pin_list *entry, *next; | ||
298 | |||
299 | if (old_cfg->irq_2_pin == cfg->irq_2_pin) | ||
300 | return; | ||
183 | 301 | ||
184 | irq_2_pin_ptr = &pin[0]; | 302 | entry = old_cfg->irq_2_pin; |
303 | |||
304 | while (entry) { | ||
305 | next = entry->next; | ||
306 | kfree(entry); | ||
307 | entry = next; | ||
308 | } | ||
309 | old_cfg->irq_2_pin = NULL; | ||
185 | } | 310 | } |
186 | 311 | ||
187 | static struct irq_pin_list *get_one_free_irq_2_pin(void) | 312 | void arch_init_copy_chip_data(struct irq_desc *old_desc, |
313 | struct irq_desc *desc, int cpu) | ||
188 | { | 314 | { |
189 | struct irq_pin_list *pin = irq_2_pin_ptr; | 315 | struct irq_cfg *cfg; |
316 | struct irq_cfg *old_cfg; | ||
190 | 317 | ||
191 | if (!pin) | 318 | cfg = get_one_free_irq_cfg(cpu); |
192 | panic("can not get more irq_2_pin\n"); | ||
193 | 319 | ||
194 | irq_2_pin_ptr = pin->next; | 320 | if (!cfg) |
195 | pin->next = NULL; | 321 | return; |
196 | return pin; | 322 | |
323 | desc->chip_data = cfg; | ||
324 | |||
325 | old_cfg = old_desc->chip_data; | ||
326 | |||
327 | memcpy(cfg, old_cfg, sizeof(struct irq_cfg)); | ||
328 | |||
329 | init_copy_irq_2_pin(old_cfg, cfg, cpu); | ||
330 | } | ||
331 | |||
332 | static void free_irq_cfg(struct irq_cfg *old_cfg) | ||
333 | { | ||
334 | kfree(old_cfg); | ||
335 | } | ||
336 | |||
337 | void arch_free_chip_data(struct irq_desc *old_desc, struct irq_desc *desc) | ||
338 | { | ||
339 | struct irq_cfg *old_cfg, *cfg; | ||
340 | |||
341 | old_cfg = old_desc->chip_data; | ||
342 | cfg = desc->chip_data; | ||
343 | |||
344 | if (old_cfg == cfg) | ||
345 | return; | ||
346 | |||
347 | if (old_cfg) { | ||
348 | free_irq_2_pin(old_cfg, cfg); | ||
349 | free_irq_cfg(old_cfg); | ||
350 | old_desc->chip_data = NULL; | ||
351 | } | ||
352 | } | ||
353 | |||
354 | static void | ||
355 | set_extra_move_desc(struct irq_desc *desc, const struct cpumask *mask) | ||
356 | { | ||
357 | struct irq_cfg *cfg = desc->chip_data; | ||
358 | |||
359 | if (!cfg->move_in_progress) { | ||
360 | /* it means that domain is not changed */ | ||
361 | if (!cpumask_intersects(&desc->affinity, mask)) | ||
362 | cfg->move_desc_pending = 1; | ||
363 | } | ||
197 | } | 364 | } |
365 | #endif | ||
366 | |||
367 | #else | ||
368 | static struct irq_cfg *irq_cfg(unsigned int irq) | ||
369 | { | ||
370 | return irq < nr_irqs ? irq_cfgx + irq : NULL; | ||
371 | } | ||
372 | |||
373 | #endif | ||
374 | |||
375 | #ifndef CONFIG_NUMA_MIGRATE_IRQ_DESC | ||
376 | static inline void | ||
377 | set_extra_move_desc(struct irq_desc *desc, const struct cpumask *mask) | ||
378 | { | ||
379 | } | ||
380 | #endif | ||
198 | 381 | ||
199 | struct io_apic { | 382 | struct io_apic { |
200 | unsigned int index; | 383 | unsigned int index; |
@@ -237,11 +420,10 @@ static inline void io_apic_modify(unsigned int apic, unsigned int reg, unsigned | |||
237 | writel(value, &io_apic->data); | 420 | writel(value, &io_apic->data); |
238 | } | 421 | } |
239 | 422 | ||
240 | static bool io_apic_level_ack_pending(unsigned int irq) | 423 | static bool io_apic_level_ack_pending(struct irq_cfg *cfg) |
241 | { | 424 | { |
242 | struct irq_pin_list *entry; | 425 | struct irq_pin_list *entry; |
243 | unsigned long flags; | 426 | unsigned long flags; |
244 | struct irq_cfg *cfg = irq_cfg(irq); | ||
245 | 427 | ||
246 | spin_lock_irqsave(&ioapic_lock, flags); | 428 | spin_lock_irqsave(&ioapic_lock, flags); |
247 | entry = cfg->irq_2_pin; | 429 | entry = cfg->irq_2_pin; |
@@ -323,13 +505,32 @@ static void ioapic_mask_entry(int apic, int pin) | |||
323 | } | 505 | } |
324 | 506 | ||
325 | #ifdef CONFIG_SMP | 507 | #ifdef CONFIG_SMP |
326 | static void __target_IO_APIC_irq(unsigned int irq, unsigned int dest, u8 vector) | 508 | static void send_cleanup_vector(struct irq_cfg *cfg) |
509 | { | ||
510 | cpumask_var_t cleanup_mask; | ||
511 | |||
512 | if (unlikely(!alloc_cpumask_var(&cleanup_mask, GFP_ATOMIC))) { | ||
513 | unsigned int i; | ||
514 | cfg->move_cleanup_count = 0; | ||
515 | for_each_cpu_and(i, cfg->old_domain, cpu_online_mask) | ||
516 | cfg->move_cleanup_count++; | ||
517 | for_each_cpu_and(i, cfg->old_domain, cpu_online_mask) | ||
518 | send_IPI_mask(cpumask_of(i), IRQ_MOVE_CLEANUP_VECTOR); | ||
519 | } else { | ||
520 | cpumask_and(cleanup_mask, cfg->old_domain, cpu_online_mask); | ||
521 | cfg->move_cleanup_count = cpumask_weight(cleanup_mask); | ||
522 | send_IPI_mask(cleanup_mask, IRQ_MOVE_CLEANUP_VECTOR); | ||
523 | free_cpumask_var(cleanup_mask); | ||
524 | } | ||
525 | cfg->move_in_progress = 0; | ||
526 | } | ||
527 | |||
528 | static void __target_IO_APIC_irq(unsigned int irq, unsigned int dest, struct irq_cfg *cfg) | ||
327 | { | 529 | { |
328 | int apic, pin; | 530 | int apic, pin; |
329 | struct irq_cfg *cfg; | ||
330 | struct irq_pin_list *entry; | 531 | struct irq_pin_list *entry; |
532 | u8 vector = cfg->vector; | ||
331 | 533 | ||
332 | cfg = irq_cfg(irq); | ||
333 | entry = cfg->irq_2_pin; | 534 | entry = cfg->irq_2_pin; |
334 | for (;;) { | 535 | for (;;) { |
335 | unsigned int reg; | 536 | unsigned int reg; |
@@ -359,36 +560,61 @@ static void __target_IO_APIC_irq(unsigned int irq, unsigned int dest, u8 vector) | |||
359 | } | 560 | } |
360 | } | 561 | } |
361 | 562 | ||
362 | static int assign_irq_vector(int irq, cpumask_t mask); | 563 | static int |
564 | assign_irq_vector(int irq, struct irq_cfg *cfg, const struct cpumask *mask); | ||
363 | 565 | ||
364 | static void set_ioapic_affinity_irq(unsigned int irq, cpumask_t mask) | 566 | /* |
567 | * Either sets desc->affinity to a valid value, and returns cpu_mask_to_apicid | ||
568 | * of that, or returns BAD_APICID and leaves desc->affinity untouched. | ||
569 | */ | ||
570 | static unsigned int | ||
571 | set_desc_affinity(struct irq_desc *desc, const struct cpumask *mask) | ||
572 | { | ||
573 | struct irq_cfg *cfg; | ||
574 | unsigned int irq; | ||
575 | |||
576 | if (!cpumask_intersects(mask, cpu_online_mask)) | ||
577 | return BAD_APICID; | ||
578 | |||
579 | irq = desc->irq; | ||
580 | cfg = desc->chip_data; | ||
581 | if (assign_irq_vector(irq, cfg, mask)) | ||
582 | return BAD_APICID; | ||
583 | |||
584 | cpumask_and(&desc->affinity, cfg->domain, mask); | ||
585 | set_extra_move_desc(desc, mask); | ||
586 | return cpu_mask_to_apicid_and(&desc->affinity, cpu_online_mask); | ||
587 | } | ||
588 | |||
589 | static void | ||
590 | set_ioapic_affinity_irq_desc(struct irq_desc *desc, const struct cpumask *mask) | ||
365 | { | 591 | { |
366 | struct irq_cfg *cfg; | 592 | struct irq_cfg *cfg; |
367 | unsigned long flags; | 593 | unsigned long flags; |
368 | unsigned int dest; | 594 | unsigned int dest; |
369 | cpumask_t tmp; | 595 | unsigned int irq; |
370 | struct irq_desc *desc; | ||
371 | 596 | ||
372 | cpus_and(tmp, mask, cpu_online_map); | 597 | irq = desc->irq; |
373 | if (cpus_empty(tmp)) | 598 | cfg = desc->chip_data; |
374 | return; | ||
375 | 599 | ||
376 | cfg = irq_cfg(irq); | 600 | spin_lock_irqsave(&ioapic_lock, flags); |
377 | if (assign_irq_vector(irq, mask)) | 601 | dest = set_desc_affinity(desc, mask); |
378 | return; | 602 | if (dest != BAD_APICID) { |
603 | /* Only the high 8 bits are valid. */ | ||
604 | dest = SET_APIC_LOGICAL_ID(dest); | ||
605 | __target_IO_APIC_irq(irq, dest, cfg); | ||
606 | } | ||
607 | spin_unlock_irqrestore(&ioapic_lock, flags); | ||
608 | } | ||
379 | 609 | ||
380 | cpus_and(tmp, cfg->domain, mask); | 610 | static void |
381 | dest = cpu_mask_to_apicid(tmp); | 611 | set_ioapic_affinity_irq(unsigned int irq, const struct cpumask *mask) |
382 | /* | 612 | { |
383 | * Only the high 8 bits are valid. | 613 | struct irq_desc *desc; |
384 | */ | ||
385 | dest = SET_APIC_LOGICAL_ID(dest); | ||
386 | 614 | ||
387 | desc = irq_to_desc(irq); | 615 | desc = irq_to_desc(irq); |
388 | spin_lock_irqsave(&ioapic_lock, flags); | 616 | |
389 | __target_IO_APIC_irq(irq, dest, cfg->vector); | 617 | set_ioapic_affinity_irq_desc(desc, mask); |
390 | desc->affinity = mask; | ||
391 | spin_unlock_irqrestore(&ioapic_lock, flags); | ||
392 | } | 618 | } |
393 | #endif /* CONFIG_SMP */ | 619 | #endif /* CONFIG_SMP */ |
394 | 620 | ||
@@ -397,16 +623,18 @@ static void set_ioapic_affinity_irq(unsigned int irq, cpumask_t mask) | |||
397 | * shared ISA-space IRQs, so we have to support them. We are super | 623 | * shared ISA-space IRQs, so we have to support them. We are super |
398 | * fast in the common case, and fast for shared ISA-space IRQs. | 624 | * fast in the common case, and fast for shared ISA-space IRQs. |
399 | */ | 625 | */ |
400 | static void add_pin_to_irq(unsigned int irq, int apic, int pin) | 626 | static void add_pin_to_irq_cpu(struct irq_cfg *cfg, int cpu, int apic, int pin) |
401 | { | 627 | { |
402 | struct irq_cfg *cfg; | ||
403 | struct irq_pin_list *entry; | 628 | struct irq_pin_list *entry; |
404 | 629 | ||
405 | /* first time to refer irq_cfg, so with new */ | ||
406 | cfg = irq_cfg_alloc(irq); | ||
407 | entry = cfg->irq_2_pin; | 630 | entry = cfg->irq_2_pin; |
408 | if (!entry) { | 631 | if (!entry) { |
409 | entry = get_one_free_irq_2_pin(); | 632 | entry = get_one_free_irq_2_pin(cpu); |
633 | if (!entry) { | ||
634 | printk(KERN_ERR "can not alloc irq_2_pin to add %d - %d\n", | ||
635 | apic, pin); | ||
636 | return; | ||
637 | } | ||
410 | cfg->irq_2_pin = entry; | 638 | cfg->irq_2_pin = entry; |
411 | entry->apic = apic; | 639 | entry->apic = apic; |
412 | entry->pin = pin; | 640 | entry->pin = pin; |
@@ -421,7 +649,7 @@ static void add_pin_to_irq(unsigned int irq, int apic, int pin) | |||
421 | entry = entry->next; | 649 | entry = entry->next; |
422 | } | 650 | } |
423 | 651 | ||
424 | entry->next = get_one_free_irq_2_pin(); | 652 | entry->next = get_one_free_irq_2_pin(cpu); |
425 | entry = entry->next; | 653 | entry = entry->next; |
426 | entry->apic = apic; | 654 | entry->apic = apic; |
427 | entry->pin = pin; | 655 | entry->pin = pin; |
@@ -430,11 +658,10 @@ static void add_pin_to_irq(unsigned int irq, int apic, int pin) | |||
430 | /* | 658 | /* |
431 | * Reroute an IRQ to a different pin. | 659 | * Reroute an IRQ to a different pin. |
432 | */ | 660 | */ |
433 | static void __init replace_pin_at_irq(unsigned int irq, | 661 | static void __init replace_pin_at_irq_cpu(struct irq_cfg *cfg, int cpu, |
434 | int oldapic, int oldpin, | 662 | int oldapic, int oldpin, |
435 | int newapic, int newpin) | 663 | int newapic, int newpin) |
436 | { | 664 | { |
437 | struct irq_cfg *cfg = irq_cfg(irq); | ||
438 | struct irq_pin_list *entry = cfg->irq_2_pin; | 665 | struct irq_pin_list *entry = cfg->irq_2_pin; |
439 | int replaced = 0; | 666 | int replaced = 0; |
440 | 667 | ||
@@ -451,18 +678,16 @@ static void __init replace_pin_at_irq(unsigned int irq, | |||
451 | 678 | ||
452 | /* why? call replace before add? */ | 679 | /* why? call replace before add? */ |
453 | if (!replaced) | 680 | if (!replaced) |
454 | add_pin_to_irq(irq, newapic, newpin); | 681 | add_pin_to_irq_cpu(cfg, cpu, newapic, newpin); |
455 | } | 682 | } |
456 | 683 | ||
457 | static inline void io_apic_modify_irq(unsigned int irq, | 684 | static inline void io_apic_modify_irq(struct irq_cfg *cfg, |
458 | int mask_and, int mask_or, | 685 | int mask_and, int mask_or, |
459 | void (*final)(struct irq_pin_list *entry)) | 686 | void (*final)(struct irq_pin_list *entry)) |
460 | { | 687 | { |
461 | int pin; | 688 | int pin; |
462 | struct irq_cfg *cfg; | ||
463 | struct irq_pin_list *entry; | 689 | struct irq_pin_list *entry; |
464 | 690 | ||
465 | cfg = irq_cfg(irq); | ||
466 | for (entry = cfg->irq_2_pin; entry != NULL; entry = entry->next) { | 691 | for (entry = cfg->irq_2_pin; entry != NULL; entry = entry->next) { |
467 | unsigned int reg; | 692 | unsigned int reg; |
468 | pin = entry->pin; | 693 | pin = entry->pin; |
@@ -475,13 +700,13 @@ static inline void io_apic_modify_irq(unsigned int irq, | |||
475 | } | 700 | } |
476 | } | 701 | } |
477 | 702 | ||
478 | static void __unmask_IO_APIC_irq(unsigned int irq) | 703 | static void __unmask_IO_APIC_irq(struct irq_cfg *cfg) |
479 | { | 704 | { |
480 | io_apic_modify_irq(irq, ~IO_APIC_REDIR_MASKED, 0, NULL); | 705 | io_apic_modify_irq(cfg, ~IO_APIC_REDIR_MASKED, 0, NULL); |
481 | } | 706 | } |
482 | 707 | ||
483 | #ifdef CONFIG_X86_64 | 708 | #ifdef CONFIG_X86_64 |
484 | void io_apic_sync(struct irq_pin_list *entry) | 709 | static void io_apic_sync(struct irq_pin_list *entry) |
485 | { | 710 | { |
486 | /* | 711 | /* |
487 | * Synchronize the IO-APIC and the CPU by doing | 712 | * Synchronize the IO-APIC and the CPU by doing |
@@ -492,47 +717,64 @@ void io_apic_sync(struct irq_pin_list *entry) | |||
492 | readl(&io_apic->data); | 717 | readl(&io_apic->data); |
493 | } | 718 | } |
494 | 719 | ||
495 | static void __mask_IO_APIC_irq(unsigned int irq) | 720 | static void __mask_IO_APIC_irq(struct irq_cfg *cfg) |
496 | { | 721 | { |
497 | io_apic_modify_irq(irq, ~0, IO_APIC_REDIR_MASKED, &io_apic_sync); | 722 | io_apic_modify_irq(cfg, ~0, IO_APIC_REDIR_MASKED, &io_apic_sync); |
498 | } | 723 | } |
499 | #else /* CONFIG_X86_32 */ | 724 | #else /* CONFIG_X86_32 */ |
500 | static void __mask_IO_APIC_irq(unsigned int irq) | 725 | static void __mask_IO_APIC_irq(struct irq_cfg *cfg) |
501 | { | 726 | { |
502 | io_apic_modify_irq(irq, ~0, IO_APIC_REDIR_MASKED, NULL); | 727 | io_apic_modify_irq(cfg, ~0, IO_APIC_REDIR_MASKED, NULL); |
503 | } | 728 | } |
504 | 729 | ||
505 | static void __mask_and_edge_IO_APIC_irq(unsigned int irq) | 730 | static void __mask_and_edge_IO_APIC_irq(struct irq_cfg *cfg) |
506 | { | 731 | { |
507 | io_apic_modify_irq(irq, ~IO_APIC_REDIR_LEVEL_TRIGGER, | 732 | io_apic_modify_irq(cfg, ~IO_APIC_REDIR_LEVEL_TRIGGER, |
508 | IO_APIC_REDIR_MASKED, NULL); | 733 | IO_APIC_REDIR_MASKED, NULL); |
509 | } | 734 | } |
510 | 735 | ||
511 | static void __unmask_and_level_IO_APIC_irq(unsigned int irq) | 736 | static void __unmask_and_level_IO_APIC_irq(struct irq_cfg *cfg) |
512 | { | 737 | { |
513 | io_apic_modify_irq(irq, ~IO_APIC_REDIR_MASKED, | 738 | io_apic_modify_irq(cfg, ~IO_APIC_REDIR_MASKED, |
514 | IO_APIC_REDIR_LEVEL_TRIGGER, NULL); | 739 | IO_APIC_REDIR_LEVEL_TRIGGER, NULL); |
515 | } | 740 | } |
516 | #endif /* CONFIG_X86_32 */ | 741 | #endif /* CONFIG_X86_32 */ |
517 | 742 | ||
518 | static void mask_IO_APIC_irq (unsigned int irq) | 743 | static void mask_IO_APIC_irq_desc(struct irq_desc *desc) |
519 | { | 744 | { |
745 | struct irq_cfg *cfg = desc->chip_data; | ||
520 | unsigned long flags; | 746 | unsigned long flags; |
521 | 747 | ||
748 | BUG_ON(!cfg); | ||
749 | |||
522 | spin_lock_irqsave(&ioapic_lock, flags); | 750 | spin_lock_irqsave(&ioapic_lock, flags); |
523 | __mask_IO_APIC_irq(irq); | 751 | __mask_IO_APIC_irq(cfg); |
524 | spin_unlock_irqrestore(&ioapic_lock, flags); | 752 | spin_unlock_irqrestore(&ioapic_lock, flags); |
525 | } | 753 | } |
526 | 754 | ||
527 | static void unmask_IO_APIC_irq (unsigned int irq) | 755 | static void unmask_IO_APIC_irq_desc(struct irq_desc *desc) |
528 | { | 756 | { |
757 | struct irq_cfg *cfg = desc->chip_data; | ||
529 | unsigned long flags; | 758 | unsigned long flags; |
530 | 759 | ||
531 | spin_lock_irqsave(&ioapic_lock, flags); | 760 | spin_lock_irqsave(&ioapic_lock, flags); |
532 | __unmask_IO_APIC_irq(irq); | 761 | __unmask_IO_APIC_irq(cfg); |
533 | spin_unlock_irqrestore(&ioapic_lock, flags); | 762 | spin_unlock_irqrestore(&ioapic_lock, flags); |
534 | } | 763 | } |
535 | 764 | ||
765 | static void mask_IO_APIC_irq(unsigned int irq) | ||
766 | { | ||
767 | struct irq_desc *desc = irq_to_desc(irq); | ||
768 | |||
769 | mask_IO_APIC_irq_desc(desc); | ||
770 | } | ||
771 | static void unmask_IO_APIC_irq(unsigned int irq) | ||
772 | { | ||
773 | struct irq_desc *desc = irq_to_desc(irq); | ||
774 | |||
775 | unmask_IO_APIC_irq_desc(desc); | ||
776 | } | ||
777 | |||
536 | static void clear_IO_APIC_pin(unsigned int apic, unsigned int pin) | 778 | static void clear_IO_APIC_pin(unsigned int apic, unsigned int pin) |
537 | { | 779 | { |
538 | struct IO_APIC_route_entry entry; | 780 | struct IO_APIC_route_entry entry; |
@@ -809,7 +1051,7 @@ EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector); | |||
809 | */ | 1051 | */ |
810 | static int EISA_ELCR(unsigned int irq) | 1052 | static int EISA_ELCR(unsigned int irq) |
811 | { | 1053 | { |
812 | if (irq < 16) { | 1054 | if (irq < NR_IRQS_LEGACY) { |
813 | unsigned int port = 0x4d0 + (irq >> 3); | 1055 | unsigned int port = 0x4d0 + (irq >> 3); |
814 | return (inb(port) >> (irq & 7)) & 1; | 1056 | return (inb(port) >> (irq & 7)) & 1; |
815 | } | 1057 | } |
@@ -1034,7 +1276,8 @@ void unlock_vector_lock(void) | |||
1034 | spin_unlock(&vector_lock); | 1276 | spin_unlock(&vector_lock); |
1035 | } | 1277 | } |
1036 | 1278 | ||
1037 | static int __assign_irq_vector(int irq, cpumask_t mask) | 1279 | static int |
1280 | __assign_irq_vector(int irq, struct irq_cfg *cfg, const struct cpumask *mask) | ||
1038 | { | 1281 | { |
1039 | /* | 1282 | /* |
1040 | * NOTE! The local APIC isn't very good at handling | 1283 | * NOTE! The local APIC isn't very good at handling |
@@ -1049,52 +1292,49 @@ static int __assign_irq_vector(int irq, cpumask_t mask) | |||
1049 | */ | 1292 | */ |
1050 | static int current_vector = FIRST_DEVICE_VECTOR, current_offset = 0; | 1293 | static int current_vector = FIRST_DEVICE_VECTOR, current_offset = 0; |
1051 | unsigned int old_vector; | 1294 | unsigned int old_vector; |
1052 | int cpu; | 1295 | int cpu, err; |
1053 | struct irq_cfg *cfg; | 1296 | cpumask_var_t tmp_mask; |
1054 | |||
1055 | cfg = irq_cfg(irq); | ||
1056 | |||
1057 | /* Only try and allocate irqs on cpus that are present */ | ||
1058 | cpus_and(mask, mask, cpu_online_map); | ||
1059 | 1297 | ||
1060 | if ((cfg->move_in_progress) || cfg->move_cleanup_count) | 1298 | if ((cfg->move_in_progress) || cfg->move_cleanup_count) |
1061 | return -EBUSY; | 1299 | return -EBUSY; |
1062 | 1300 | ||
1301 | if (!alloc_cpumask_var(&tmp_mask, GFP_ATOMIC)) | ||
1302 | return -ENOMEM; | ||
1303 | |||
1063 | old_vector = cfg->vector; | 1304 | old_vector = cfg->vector; |
1064 | if (old_vector) { | 1305 | if (old_vector) { |
1065 | cpumask_t tmp; | 1306 | cpumask_and(tmp_mask, mask, cpu_online_mask); |
1066 | cpus_and(tmp, cfg->domain, mask); | 1307 | cpumask_and(tmp_mask, cfg->domain, tmp_mask); |
1067 | if (!cpus_empty(tmp)) | 1308 | if (!cpumask_empty(tmp_mask)) { |
1309 | free_cpumask_var(tmp_mask); | ||
1068 | return 0; | 1310 | return 0; |
1311 | } | ||
1069 | } | 1312 | } |
1070 | 1313 | ||
1071 | for_each_cpu_mask_nr(cpu, mask) { | 1314 | /* Only try and allocate irqs on cpus that are present */ |
1072 | cpumask_t domain, new_mask; | 1315 | err = -ENOSPC; |
1316 | for_each_cpu_and(cpu, mask, cpu_online_mask) { | ||
1073 | int new_cpu; | 1317 | int new_cpu; |
1074 | int vector, offset; | 1318 | int vector, offset; |
1075 | 1319 | ||
1076 | domain = vector_allocation_domain(cpu); | 1320 | vector_allocation_domain(cpu, tmp_mask); |
1077 | cpus_and(new_mask, domain, cpu_online_map); | ||
1078 | 1321 | ||
1079 | vector = current_vector; | 1322 | vector = current_vector; |
1080 | offset = current_offset; | 1323 | offset = current_offset; |
1081 | next: | 1324 | next: |
1082 | vector += 8; | 1325 | vector += 8; |
1083 | if (vector >= first_system_vector) { | 1326 | if (vector >= first_system_vector) { |
1084 | /* If we run out of vectors on large boxen, must share them. */ | 1327 | /* If out of vectors on large boxen, must share them. */ |
1085 | offset = (offset + 1) % 8; | 1328 | offset = (offset + 1) % 8; |
1086 | vector = FIRST_DEVICE_VECTOR + offset; | 1329 | vector = FIRST_DEVICE_VECTOR + offset; |
1087 | } | 1330 | } |
1088 | if (unlikely(current_vector == vector)) | 1331 | if (unlikely(current_vector == vector)) |
1089 | continue; | 1332 | continue; |
1090 | #ifdef CONFIG_X86_64 | 1333 | |
1091 | if (vector == IA32_SYSCALL_VECTOR) | 1334 | if (test_bit(vector, used_vectors)) |
1092 | goto next; | ||
1093 | #else | ||
1094 | if (vector == SYSCALL_VECTOR) | ||
1095 | goto next; | 1335 | goto next; |
1096 | #endif | 1336 | |
1097 | for_each_cpu_mask_nr(new_cpu, new_mask) | 1337 | for_each_cpu_and(new_cpu, tmp_mask, cpu_online_mask) |
1098 | if (per_cpu(vector_irq, new_cpu)[vector] != -1) | 1338 | if (per_cpu(vector_irq, new_cpu)[vector] != -1) |
1099 | goto next; | 1339 | goto next; |
1100 | /* Found one! */ | 1340 | /* Found one! */ |
@@ -1102,49 +1342,47 @@ next: | |||
1102 | current_offset = offset; | 1342 | current_offset = offset; |
1103 | if (old_vector) { | 1343 | if (old_vector) { |
1104 | cfg->move_in_progress = 1; | 1344 | cfg->move_in_progress = 1; |
1105 | cfg->old_domain = cfg->domain; | 1345 | cpumask_copy(cfg->old_domain, cfg->domain); |
1106 | } | 1346 | } |
1107 | for_each_cpu_mask_nr(new_cpu, new_mask) | 1347 | for_each_cpu_and(new_cpu, tmp_mask, cpu_online_mask) |
1108 | per_cpu(vector_irq, new_cpu)[vector] = irq; | 1348 | per_cpu(vector_irq, new_cpu)[vector] = irq; |
1109 | cfg->vector = vector; | 1349 | cfg->vector = vector; |
1110 | cfg->domain = domain; | 1350 | cpumask_copy(cfg->domain, tmp_mask); |
1111 | return 0; | 1351 | err = 0; |
1352 | break; | ||
1112 | } | 1353 | } |
1113 | return -ENOSPC; | 1354 | free_cpumask_var(tmp_mask); |
1355 | return err; | ||
1114 | } | 1356 | } |
1115 | 1357 | ||
1116 | static int assign_irq_vector(int irq, cpumask_t mask) | 1358 | static int |
1359 | assign_irq_vector(int irq, struct irq_cfg *cfg, const struct cpumask *mask) | ||
1117 | { | 1360 | { |
1118 | int err; | 1361 | int err; |
1119 | unsigned long flags; | 1362 | unsigned long flags; |
1120 | 1363 | ||
1121 | spin_lock_irqsave(&vector_lock, flags); | 1364 | spin_lock_irqsave(&vector_lock, flags); |
1122 | err = __assign_irq_vector(irq, mask); | 1365 | err = __assign_irq_vector(irq, cfg, mask); |
1123 | spin_unlock_irqrestore(&vector_lock, flags); | 1366 | spin_unlock_irqrestore(&vector_lock, flags); |
1124 | return err; | 1367 | return err; |
1125 | } | 1368 | } |
1126 | 1369 | ||
1127 | static void __clear_irq_vector(int irq) | 1370 | static void __clear_irq_vector(int irq, struct irq_cfg *cfg) |
1128 | { | 1371 | { |
1129 | struct irq_cfg *cfg; | ||
1130 | cpumask_t mask; | ||
1131 | int cpu, vector; | 1372 | int cpu, vector; |
1132 | 1373 | ||
1133 | cfg = irq_cfg(irq); | ||
1134 | BUG_ON(!cfg->vector); | 1374 | BUG_ON(!cfg->vector); |
1135 | 1375 | ||
1136 | vector = cfg->vector; | 1376 | vector = cfg->vector; |
1137 | cpus_and(mask, cfg->domain, cpu_online_map); | 1377 | for_each_cpu_and(cpu, cfg->domain, cpu_online_mask) |
1138 | for_each_cpu_mask_nr(cpu, mask) | ||
1139 | per_cpu(vector_irq, cpu)[vector] = -1; | 1378 | per_cpu(vector_irq, cpu)[vector] = -1; |
1140 | 1379 | ||
1141 | cfg->vector = 0; | 1380 | cfg->vector = 0; |
1142 | cpus_clear(cfg->domain); | 1381 | cpumask_clear(cfg->domain); |
1143 | 1382 | ||
1144 | if (likely(!cfg->move_in_progress)) | 1383 | if (likely(!cfg->move_in_progress)) |
1145 | return; | 1384 | return; |
1146 | cpus_and(mask, cfg->old_domain, cpu_online_map); | 1385 | for_each_cpu_and(cpu, cfg->old_domain, cpu_online_mask) { |
1147 | for_each_cpu_mask_nr(cpu, mask) { | ||
1148 | for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; | 1386 | for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; |
1149 | vector++) { | 1387 | vector++) { |
1150 | if (per_cpu(vector_irq, cpu)[vector] != irq) | 1388 | if (per_cpu(vector_irq, cpu)[vector] != irq) |
@@ -1162,10 +1400,12 @@ void __setup_vector_irq(int cpu) | |||
1162 | /* This function must be called with vector_lock held */ | 1400 | /* This function must be called with vector_lock held */ |
1163 | int irq, vector; | 1401 | int irq, vector; |
1164 | struct irq_cfg *cfg; | 1402 | struct irq_cfg *cfg; |
1403 | struct irq_desc *desc; | ||
1165 | 1404 | ||
1166 | /* Mark the inuse vectors */ | 1405 | /* Mark the inuse vectors */ |
1167 | for_each_irq_cfg(irq, cfg) { | 1406 | for_each_irq_desc(irq, desc) { |
1168 | if (!cpu_isset(cpu, cfg->domain)) | 1407 | cfg = desc->chip_data; |
1408 | if (!cpumask_test_cpu(cpu, cfg->domain)) | ||
1169 | continue; | 1409 | continue; |
1170 | vector = cfg->vector; | 1410 | vector = cfg->vector; |
1171 | per_cpu(vector_irq, cpu)[vector] = irq; | 1411 | per_cpu(vector_irq, cpu)[vector] = irq; |
@@ -1177,7 +1417,7 @@ void __setup_vector_irq(int cpu) | |||
1177 | continue; | 1417 | continue; |
1178 | 1418 | ||
1179 | cfg = irq_cfg(irq); | 1419 | cfg = irq_cfg(irq); |
1180 | if (!cpu_isset(cpu, cfg->domain)) | 1420 | if (!cpumask_test_cpu(cpu, cfg->domain)) |
1181 | per_cpu(vector_irq, cpu)[vector] = -1; | 1421 | per_cpu(vector_irq, cpu)[vector] = -1; |
1182 | } | 1422 | } |
1183 | } | 1423 | } |
@@ -1215,11 +1455,8 @@ static inline int IO_APIC_irq_trigger(int irq) | |||
1215 | } | 1455 | } |
1216 | #endif | 1456 | #endif |
1217 | 1457 | ||
1218 | static void ioapic_register_intr(int irq, unsigned long trigger) | 1458 | static void ioapic_register_intr(int irq, struct irq_desc *desc, unsigned long trigger) |
1219 | { | 1459 | { |
1220 | struct irq_desc *desc; | ||
1221 | |||
1222 | desc = irq_to_desc(irq); | ||
1223 | 1460 | ||
1224 | if ((trigger == IOAPIC_AUTO && IO_APIC_irq_trigger(irq)) || | 1461 | if ((trigger == IOAPIC_AUTO && IO_APIC_irq_trigger(irq)) || |
1225 | trigger == IOAPIC_LEVEL) | 1462 | trigger == IOAPIC_LEVEL) |
@@ -1311,23 +1548,22 @@ static int setup_ioapic_entry(int apic, int irq, | |||
1311 | return 0; | 1548 | return 0; |
1312 | } | 1549 | } |
1313 | 1550 | ||
1314 | static void setup_IO_APIC_irq(int apic, int pin, unsigned int irq, | 1551 | static void setup_IO_APIC_irq(int apic, int pin, unsigned int irq, struct irq_desc *desc, |
1315 | int trigger, int polarity) | 1552 | int trigger, int polarity) |
1316 | { | 1553 | { |
1317 | struct irq_cfg *cfg; | 1554 | struct irq_cfg *cfg; |
1318 | struct IO_APIC_route_entry entry; | 1555 | struct IO_APIC_route_entry entry; |
1319 | cpumask_t mask; | 1556 | unsigned int dest; |
1320 | 1557 | ||
1321 | if (!IO_APIC_IRQ(irq)) | 1558 | if (!IO_APIC_IRQ(irq)) |
1322 | return; | 1559 | return; |
1323 | 1560 | ||
1324 | cfg = irq_cfg(irq); | 1561 | cfg = desc->chip_data; |
1325 | 1562 | ||
1326 | mask = TARGET_CPUS; | 1563 | if (assign_irq_vector(irq, cfg, TARGET_CPUS)) |
1327 | if (assign_irq_vector(irq, mask)) | ||
1328 | return; | 1564 | return; |
1329 | 1565 | ||
1330 | cpus_and(mask, cfg->domain, mask); | 1566 | dest = cpu_mask_to_apicid_and(cfg->domain, TARGET_CPUS); |
1331 | 1567 | ||
1332 | apic_printk(APIC_VERBOSE,KERN_DEBUG | 1568 | apic_printk(APIC_VERBOSE,KERN_DEBUG |
1333 | "IOAPIC[%d]: Set routing entry (%d-%d -> 0x%x -> " | 1569 | "IOAPIC[%d]: Set routing entry (%d-%d -> 0x%x -> " |
@@ -1337,16 +1573,15 @@ static void setup_IO_APIC_irq(int apic, int pin, unsigned int irq, | |||
1337 | 1573 | ||
1338 | 1574 | ||
1339 | if (setup_ioapic_entry(mp_ioapics[apic].mp_apicid, irq, &entry, | 1575 | if (setup_ioapic_entry(mp_ioapics[apic].mp_apicid, irq, &entry, |
1340 | cpu_mask_to_apicid(mask), trigger, polarity, | 1576 | dest, trigger, polarity, cfg->vector)) { |
1341 | cfg->vector)) { | ||
1342 | printk("Failed to setup ioapic entry for ioapic %d, pin %d\n", | 1577 | printk("Failed to setup ioapic entry for ioapic %d, pin %d\n", |
1343 | mp_ioapics[apic].mp_apicid, pin); | 1578 | mp_ioapics[apic].mp_apicid, pin); |
1344 | __clear_irq_vector(irq); | 1579 | __clear_irq_vector(irq, cfg); |
1345 | return; | 1580 | return; |
1346 | } | 1581 | } |
1347 | 1582 | ||
1348 | ioapic_register_intr(irq, trigger); | 1583 | ioapic_register_intr(irq, desc, trigger); |
1349 | if (irq < 16) | 1584 | if (irq < NR_IRQS_LEGACY) |
1350 | disable_8259A_irq(irq); | 1585 | disable_8259A_irq(irq); |
1351 | 1586 | ||
1352 | ioapic_write_entry(apic, pin, entry); | 1587 | ioapic_write_entry(apic, pin, entry); |
@@ -1356,6 +1591,9 @@ static void __init setup_IO_APIC_irqs(void) | |||
1356 | { | 1591 | { |
1357 | int apic, pin, idx, irq; | 1592 | int apic, pin, idx, irq; |
1358 | int notcon = 0; | 1593 | int notcon = 0; |
1594 | struct irq_desc *desc; | ||
1595 | struct irq_cfg *cfg; | ||
1596 | int cpu = boot_cpu_id; | ||
1359 | 1597 | ||
1360 | apic_printk(APIC_VERBOSE, KERN_DEBUG "init IO_APIC IRQs\n"); | 1598 | apic_printk(APIC_VERBOSE, KERN_DEBUG "init IO_APIC IRQs\n"); |
1361 | 1599 | ||
@@ -1387,9 +1625,15 @@ static void __init setup_IO_APIC_irqs(void) | |||
1387 | if (multi_timer_check(apic, irq)) | 1625 | if (multi_timer_check(apic, irq)) |
1388 | continue; | 1626 | continue; |
1389 | #endif | 1627 | #endif |
1390 | add_pin_to_irq(irq, apic, pin); | 1628 | desc = irq_to_desc_alloc_cpu(irq, cpu); |
1629 | if (!desc) { | ||
1630 | printk(KERN_INFO "can not get irq_desc for %d\n", irq); | ||
1631 | continue; | ||
1632 | } | ||
1633 | cfg = desc->chip_data; | ||
1634 | add_pin_to_irq_cpu(cfg, cpu, apic, pin); | ||
1391 | 1635 | ||
1392 | setup_IO_APIC_irq(apic, pin, irq, | 1636 | setup_IO_APIC_irq(apic, pin, irq, desc, |
1393 | irq_trigger(idx), irq_polarity(idx)); | 1637 | irq_trigger(idx), irq_polarity(idx)); |
1394 | } | 1638 | } |
1395 | } | 1639 | } |
@@ -1448,6 +1692,7 @@ __apicdebuginit(void) print_IO_APIC(void) | |||
1448 | union IO_APIC_reg_03 reg_03; | 1692 | union IO_APIC_reg_03 reg_03; |
1449 | unsigned long flags; | 1693 | unsigned long flags; |
1450 | struct irq_cfg *cfg; | 1694 | struct irq_cfg *cfg; |
1695 | struct irq_desc *desc; | ||
1451 | unsigned int irq; | 1696 | unsigned int irq; |
1452 | 1697 | ||
1453 | if (apic_verbosity == APIC_QUIET) | 1698 | if (apic_verbosity == APIC_QUIET) |
@@ -1537,8 +1782,11 @@ __apicdebuginit(void) print_IO_APIC(void) | |||
1537 | } | 1782 | } |
1538 | } | 1783 | } |
1539 | printk(KERN_DEBUG "IRQ to pin mappings:\n"); | 1784 | printk(KERN_DEBUG "IRQ to pin mappings:\n"); |
1540 | for_each_irq_cfg(irq, cfg) { | 1785 | for_each_irq_desc(irq, desc) { |
1541 | struct irq_pin_list *entry = cfg->irq_2_pin; | 1786 | struct irq_pin_list *entry; |
1787 | |||
1788 | cfg = desc->chip_data; | ||
1789 | entry = cfg->irq_2_pin; | ||
1542 | if (!entry) | 1790 | if (!entry) |
1543 | continue; | 1791 | continue; |
1544 | printk(KERN_DEBUG "IRQ%d ", irq); | 1792 | printk(KERN_DEBUG "IRQ%d ", irq); |
@@ -2022,14 +2270,16 @@ static unsigned int startup_ioapic_irq(unsigned int irq) | |||
2022 | { | 2270 | { |
2023 | int was_pending = 0; | 2271 | int was_pending = 0; |
2024 | unsigned long flags; | 2272 | unsigned long flags; |
2273 | struct irq_cfg *cfg; | ||
2025 | 2274 | ||
2026 | spin_lock_irqsave(&ioapic_lock, flags); | 2275 | spin_lock_irqsave(&ioapic_lock, flags); |
2027 | if (irq < 16) { | 2276 | if (irq < NR_IRQS_LEGACY) { |
2028 | disable_8259A_irq(irq); | 2277 | disable_8259A_irq(irq); |
2029 | if (i8259A_irq_pending(irq)) | 2278 | if (i8259A_irq_pending(irq)) |
2030 | was_pending = 1; | 2279 | was_pending = 1; |
2031 | } | 2280 | } |
2032 | __unmask_IO_APIC_irq(irq); | 2281 | cfg = irq_cfg(irq); |
2282 | __unmask_IO_APIC_irq(cfg); | ||
2033 | spin_unlock_irqrestore(&ioapic_lock, flags); | 2283 | spin_unlock_irqrestore(&ioapic_lock, flags); |
2034 | 2284 | ||
2035 | return was_pending; | 2285 | return was_pending; |
@@ -2043,7 +2293,7 @@ static int ioapic_retrigger_irq(unsigned int irq) | |||
2043 | unsigned long flags; | 2293 | unsigned long flags; |
2044 | 2294 | ||
2045 | spin_lock_irqsave(&vector_lock, flags); | 2295 | spin_lock_irqsave(&vector_lock, flags); |
2046 | send_IPI_mask(cpumask_of_cpu(first_cpu(cfg->domain)), cfg->vector); | 2296 | send_IPI_mask(cpumask_of(cpumask_first(cfg->domain)), cfg->vector); |
2047 | spin_unlock_irqrestore(&vector_lock, flags); | 2297 | spin_unlock_irqrestore(&vector_lock, flags); |
2048 | 2298 | ||
2049 | return 1; | 2299 | return 1; |
@@ -2092,35 +2342,35 @@ static DECLARE_DELAYED_WORK(ir_migration_work, ir_irq_migration); | |||
2092 | * as simple as edge triggered migration and we can do the irq migration | 2342 | * as simple as edge triggered migration and we can do the irq migration |
2093 | * with a simple atomic update to IO-APIC RTE. | 2343 | * with a simple atomic update to IO-APIC RTE. |
2094 | */ | 2344 | */ |
2095 | static void migrate_ioapic_irq(int irq, cpumask_t mask) | 2345 | static void |
2346 | migrate_ioapic_irq_desc(struct irq_desc *desc, const struct cpumask *mask) | ||
2096 | { | 2347 | { |
2097 | struct irq_cfg *cfg; | 2348 | struct irq_cfg *cfg; |
2098 | struct irq_desc *desc; | ||
2099 | cpumask_t tmp, cleanup_mask; | ||
2100 | struct irte irte; | 2349 | struct irte irte; |
2101 | int modify_ioapic_rte; | 2350 | int modify_ioapic_rte; |
2102 | unsigned int dest; | 2351 | unsigned int dest; |
2103 | unsigned long flags; | 2352 | unsigned long flags; |
2353 | unsigned int irq; | ||
2104 | 2354 | ||
2105 | cpus_and(tmp, mask, cpu_online_map); | 2355 | if (!cpumask_intersects(mask, cpu_online_mask)) |
2106 | if (cpus_empty(tmp)) | ||
2107 | return; | 2356 | return; |
2108 | 2357 | ||
2358 | irq = desc->irq; | ||
2109 | if (get_irte(irq, &irte)) | 2359 | if (get_irte(irq, &irte)) |
2110 | return; | 2360 | return; |
2111 | 2361 | ||
2112 | if (assign_irq_vector(irq, mask)) | 2362 | cfg = desc->chip_data; |
2363 | if (assign_irq_vector(irq, cfg, mask)) | ||
2113 | return; | 2364 | return; |
2114 | 2365 | ||
2115 | cfg = irq_cfg(irq); | 2366 | set_extra_move_desc(desc, mask); |
2116 | cpus_and(tmp, cfg->domain, mask); | 2367 | |
2117 | dest = cpu_mask_to_apicid(tmp); | 2368 | dest = cpu_mask_to_apicid_and(cfg->domain, mask); |
2118 | 2369 | ||
2119 | desc = irq_to_desc(irq); | ||
2120 | modify_ioapic_rte = desc->status & IRQ_LEVEL; | 2370 | modify_ioapic_rte = desc->status & IRQ_LEVEL; |
2121 | if (modify_ioapic_rte) { | 2371 | if (modify_ioapic_rte) { |
2122 | spin_lock_irqsave(&ioapic_lock, flags); | 2372 | spin_lock_irqsave(&ioapic_lock, flags); |
2123 | __target_IO_APIC_irq(irq, dest, cfg->vector); | 2373 | __target_IO_APIC_irq(irq, dest, cfg); |
2124 | spin_unlock_irqrestore(&ioapic_lock, flags); | 2374 | spin_unlock_irqrestore(&ioapic_lock, flags); |
2125 | } | 2375 | } |
2126 | 2376 | ||
@@ -2132,24 +2382,20 @@ static void migrate_ioapic_irq(int irq, cpumask_t mask) | |||
2132 | */ | 2382 | */ |
2133 | modify_irte(irq, &irte); | 2383 | modify_irte(irq, &irte); |
2134 | 2384 | ||
2135 | if (cfg->move_in_progress) { | 2385 | if (cfg->move_in_progress) |
2136 | cpus_and(cleanup_mask, cfg->old_domain, cpu_online_map); | 2386 | send_cleanup_vector(cfg); |
2137 | cfg->move_cleanup_count = cpus_weight(cleanup_mask); | ||
2138 | send_IPI_mask(cleanup_mask, IRQ_MOVE_CLEANUP_VECTOR); | ||
2139 | cfg->move_in_progress = 0; | ||
2140 | } | ||
2141 | 2387 | ||
2142 | desc->affinity = mask; | 2388 | cpumask_copy(&desc->affinity, mask); |
2143 | } | 2389 | } |
2144 | 2390 | ||
2145 | static int migrate_irq_remapped_level(int irq) | 2391 | static int migrate_irq_remapped_level_desc(struct irq_desc *desc) |
2146 | { | 2392 | { |
2147 | int ret = -1; | 2393 | int ret = -1; |
2148 | struct irq_desc *desc = irq_to_desc(irq); | 2394 | struct irq_cfg *cfg = desc->chip_data; |
2149 | 2395 | ||
2150 | mask_IO_APIC_irq(irq); | 2396 | mask_IO_APIC_irq_desc(desc); |
2151 | 2397 | ||
2152 | if (io_apic_level_ack_pending(irq)) { | 2398 | if (io_apic_level_ack_pending(cfg)) { |
2153 | /* | 2399 | /* |
2154 | * Interrupt in progress. Migrating irq now will change the | 2400 | * Interrupt in progress. Migrating irq now will change the |
2155 | * vector information in the IO-APIC RTE and that will confuse | 2401 | * vector information in the IO-APIC RTE and that will confuse |
@@ -2161,14 +2407,15 @@ static int migrate_irq_remapped_level(int irq) | |||
2161 | } | 2407 | } |
2162 | 2408 | ||
2163 | /* everthing is clear. we have right of way */ | 2409 | /* everthing is clear. we have right of way */ |
2164 | migrate_ioapic_irq(irq, desc->pending_mask); | 2410 | migrate_ioapic_irq_desc(desc, &desc->pending_mask); |
2165 | 2411 | ||
2166 | ret = 0; | 2412 | ret = 0; |
2167 | desc->status &= ~IRQ_MOVE_PENDING; | 2413 | desc->status &= ~IRQ_MOVE_PENDING; |
2168 | cpus_clear(desc->pending_mask); | 2414 | cpumask_clear(&desc->pending_mask); |
2169 | 2415 | ||
2170 | unmask: | 2416 | unmask: |
2171 | unmask_IO_APIC_irq(irq); | 2417 | unmask_IO_APIC_irq_desc(desc); |
2418 | |||
2172 | return ret; | 2419 | return ret; |
2173 | } | 2420 | } |
2174 | 2421 | ||
@@ -2189,7 +2436,7 @@ static void ir_irq_migration(struct work_struct *work) | |||
2189 | continue; | 2436 | continue; |
2190 | } | 2437 | } |
2191 | 2438 | ||
2192 | desc->chip->set_affinity(irq, desc->pending_mask); | 2439 | desc->chip->set_affinity(irq, &desc->pending_mask); |
2193 | spin_unlock_irqrestore(&desc->lock, flags); | 2440 | spin_unlock_irqrestore(&desc->lock, flags); |
2194 | } | 2441 | } |
2195 | } | 2442 | } |
@@ -2198,28 +2445,33 @@ static void ir_irq_migration(struct work_struct *work) | |||
2198 | /* | 2445 | /* |
2199 | * Migrates the IRQ destination in the process context. | 2446 | * Migrates the IRQ destination in the process context. |
2200 | */ | 2447 | */ |
2201 | static void set_ir_ioapic_affinity_irq(unsigned int irq, cpumask_t mask) | 2448 | static void set_ir_ioapic_affinity_irq_desc(struct irq_desc *desc, |
2449 | const struct cpumask *mask) | ||
2202 | { | 2450 | { |
2203 | struct irq_desc *desc = irq_to_desc(irq); | ||
2204 | |||
2205 | if (desc->status & IRQ_LEVEL) { | 2451 | if (desc->status & IRQ_LEVEL) { |
2206 | desc->status |= IRQ_MOVE_PENDING; | 2452 | desc->status |= IRQ_MOVE_PENDING; |
2207 | desc->pending_mask = mask; | 2453 | cpumask_copy(&desc->pending_mask, mask); |
2208 | migrate_irq_remapped_level(irq); | 2454 | migrate_irq_remapped_level_desc(desc); |
2209 | return; | 2455 | return; |
2210 | } | 2456 | } |
2211 | 2457 | ||
2212 | migrate_ioapic_irq(irq, mask); | 2458 | migrate_ioapic_irq_desc(desc, mask); |
2459 | } | ||
2460 | static void set_ir_ioapic_affinity_irq(unsigned int irq, | ||
2461 | const struct cpumask *mask) | ||
2462 | { | ||
2463 | struct irq_desc *desc = irq_to_desc(irq); | ||
2464 | |||
2465 | set_ir_ioapic_affinity_irq_desc(desc, mask); | ||
2213 | } | 2466 | } |
2214 | #endif | 2467 | #endif |
2215 | 2468 | ||
2216 | asmlinkage void smp_irq_move_cleanup_interrupt(void) | 2469 | asmlinkage void smp_irq_move_cleanup_interrupt(void) |
2217 | { | 2470 | { |
2218 | unsigned vector, me; | 2471 | unsigned vector, me; |
2472 | |||
2219 | ack_APIC_irq(); | 2473 | ack_APIC_irq(); |
2220 | #ifdef CONFIG_X86_64 | ||
2221 | exit_idle(); | 2474 | exit_idle(); |
2222 | #endif | ||
2223 | irq_enter(); | 2475 | irq_enter(); |
2224 | 2476 | ||
2225 | me = smp_processor_id(); | 2477 | me = smp_processor_id(); |
@@ -2229,6 +2481,9 @@ asmlinkage void smp_irq_move_cleanup_interrupt(void) | |||
2229 | struct irq_cfg *cfg; | 2481 | struct irq_cfg *cfg; |
2230 | irq = __get_cpu_var(vector_irq)[vector]; | 2482 | irq = __get_cpu_var(vector_irq)[vector]; |
2231 | 2483 | ||
2484 | if (irq == -1) | ||
2485 | continue; | ||
2486 | |||
2232 | desc = irq_to_desc(irq); | 2487 | desc = irq_to_desc(irq); |
2233 | if (!desc) | 2488 | if (!desc) |
2234 | continue; | 2489 | continue; |
@@ -2238,7 +2493,7 @@ asmlinkage void smp_irq_move_cleanup_interrupt(void) | |||
2238 | if (!cfg->move_cleanup_count) | 2493 | if (!cfg->move_cleanup_count) |
2239 | goto unlock; | 2494 | goto unlock; |
2240 | 2495 | ||
2241 | if ((vector == cfg->vector) && cpu_isset(me, cfg->domain)) | 2496 | if (vector == cfg->vector && cpumask_test_cpu(me, cfg->domain)) |
2242 | goto unlock; | 2497 | goto unlock; |
2243 | 2498 | ||
2244 | __get_cpu_var(vector_irq)[vector] = -1; | 2499 | __get_cpu_var(vector_irq)[vector] = -1; |
@@ -2250,28 +2505,44 @@ unlock: | |||
2250 | irq_exit(); | 2505 | irq_exit(); |
2251 | } | 2506 | } |
2252 | 2507 | ||
2253 | static void irq_complete_move(unsigned int irq) | 2508 | static void irq_complete_move(struct irq_desc **descp) |
2254 | { | 2509 | { |
2255 | struct irq_cfg *cfg = irq_cfg(irq); | 2510 | struct irq_desc *desc = *descp; |
2511 | struct irq_cfg *cfg = desc->chip_data; | ||
2256 | unsigned vector, me; | 2512 | unsigned vector, me; |
2257 | 2513 | ||
2258 | if (likely(!cfg->move_in_progress)) | 2514 | if (likely(!cfg->move_in_progress)) { |
2515 | #ifdef CONFIG_NUMA_MIGRATE_IRQ_DESC | ||
2516 | if (likely(!cfg->move_desc_pending)) | ||
2517 | return; | ||
2518 | |||
2519 | /* domain has not changed, but affinity did */ | ||
2520 | me = smp_processor_id(); | ||
2521 | if (cpu_isset(me, desc->affinity)) { | ||
2522 | *descp = desc = move_irq_desc(desc, me); | ||
2523 | /* get the new one */ | ||
2524 | cfg = desc->chip_data; | ||
2525 | cfg->move_desc_pending = 0; | ||
2526 | } | ||
2527 | #endif | ||
2259 | return; | 2528 | return; |
2529 | } | ||
2260 | 2530 | ||
2261 | vector = ~get_irq_regs()->orig_ax; | 2531 | vector = ~get_irq_regs()->orig_ax; |
2262 | me = smp_processor_id(); | 2532 | me = smp_processor_id(); |
2263 | if ((vector == cfg->vector) && cpu_isset(me, cfg->domain)) { | 2533 | #ifdef CONFIG_NUMA_MIGRATE_IRQ_DESC |
2264 | cpumask_t cleanup_mask; | 2534 | *descp = desc = move_irq_desc(desc, me); |
2535 | /* get the new one */ | ||
2536 | cfg = desc->chip_data; | ||
2537 | #endif | ||
2265 | 2538 | ||
2266 | cpus_and(cleanup_mask, cfg->old_domain, cpu_online_map); | 2539 | if (vector == cfg->vector && cpumask_test_cpu(me, cfg->domain)) |
2267 | cfg->move_cleanup_count = cpus_weight(cleanup_mask); | 2540 | send_cleanup_vector(cfg); |
2268 | send_IPI_mask(cleanup_mask, IRQ_MOVE_CLEANUP_VECTOR); | ||
2269 | cfg->move_in_progress = 0; | ||
2270 | } | ||
2271 | } | 2541 | } |
2272 | #else | 2542 | #else |
2273 | static inline void irq_complete_move(unsigned int irq) {} | 2543 | static inline void irq_complete_move(struct irq_desc **descp) {} |
2274 | #endif | 2544 | #endif |
2545 | |||
2275 | #ifdef CONFIG_INTR_REMAP | 2546 | #ifdef CONFIG_INTR_REMAP |
2276 | static void ack_x2apic_level(unsigned int irq) | 2547 | static void ack_x2apic_level(unsigned int irq) |
2277 | { | 2548 | { |
@@ -2282,11 +2553,14 @@ static void ack_x2apic_edge(unsigned int irq) | |||
2282 | { | 2553 | { |
2283 | ack_x2APIC_irq(); | 2554 | ack_x2APIC_irq(); |
2284 | } | 2555 | } |
2556 | |||
2285 | #endif | 2557 | #endif |
2286 | 2558 | ||
2287 | static void ack_apic_edge(unsigned int irq) | 2559 | static void ack_apic_edge(unsigned int irq) |
2288 | { | 2560 | { |
2289 | irq_complete_move(irq); | 2561 | struct irq_desc *desc = irq_to_desc(irq); |
2562 | |||
2563 | irq_complete_move(&desc); | ||
2290 | move_native_irq(irq); | 2564 | move_native_irq(irq); |
2291 | ack_APIC_irq(); | 2565 | ack_APIC_irq(); |
2292 | } | 2566 | } |
@@ -2295,18 +2569,21 @@ atomic_t irq_mis_count; | |||
2295 | 2569 | ||
2296 | static void ack_apic_level(unsigned int irq) | 2570 | static void ack_apic_level(unsigned int irq) |
2297 | { | 2571 | { |
2572 | struct irq_desc *desc = irq_to_desc(irq); | ||
2573 | |||
2298 | #ifdef CONFIG_X86_32 | 2574 | #ifdef CONFIG_X86_32 |
2299 | unsigned long v; | 2575 | unsigned long v; |
2300 | int i; | 2576 | int i; |
2301 | #endif | 2577 | #endif |
2578 | struct irq_cfg *cfg; | ||
2302 | int do_unmask_irq = 0; | 2579 | int do_unmask_irq = 0; |
2303 | 2580 | ||
2304 | irq_complete_move(irq); | 2581 | irq_complete_move(&desc); |
2305 | #ifdef CONFIG_GENERIC_PENDING_IRQ | 2582 | #ifdef CONFIG_GENERIC_PENDING_IRQ |
2306 | /* If we are moving the irq we need to mask it */ | 2583 | /* If we are moving the irq we need to mask it */ |
2307 | if (unlikely(irq_to_desc(irq)->status & IRQ_MOVE_PENDING)) { | 2584 | if (unlikely(desc->status & IRQ_MOVE_PENDING)) { |
2308 | do_unmask_irq = 1; | 2585 | do_unmask_irq = 1; |
2309 | mask_IO_APIC_irq(irq); | 2586 | mask_IO_APIC_irq_desc(desc); |
2310 | } | 2587 | } |
2311 | #endif | 2588 | #endif |
2312 | 2589 | ||
@@ -2330,7 +2607,8 @@ static void ack_apic_level(unsigned int irq) | |||
2330 | * operation to prevent an edge-triggered interrupt escaping meanwhile. | 2607 | * operation to prevent an edge-triggered interrupt escaping meanwhile. |
2331 | * The idea is from Manfred Spraul. --macro | 2608 | * The idea is from Manfred Spraul. --macro |
2332 | */ | 2609 | */ |
2333 | i = irq_cfg(irq)->vector; | 2610 | cfg = desc->chip_data; |
2611 | i = cfg->vector; | ||
2334 | 2612 | ||
2335 | v = apic_read(APIC_TMR + ((i & ~0x1f) >> 1)); | 2613 | v = apic_read(APIC_TMR + ((i & ~0x1f) >> 1)); |
2336 | #endif | 2614 | #endif |
@@ -2369,17 +2647,18 @@ static void ack_apic_level(unsigned int irq) | |||
2369 | * accurate and is causing problems then it is a hardware bug | 2647 | * accurate and is causing problems then it is a hardware bug |
2370 | * and you can go talk to the chipset vendor about it. | 2648 | * and you can go talk to the chipset vendor about it. |
2371 | */ | 2649 | */ |
2372 | if (!io_apic_level_ack_pending(irq)) | 2650 | cfg = desc->chip_data; |
2651 | if (!io_apic_level_ack_pending(cfg)) | ||
2373 | move_masked_irq(irq); | 2652 | move_masked_irq(irq); |
2374 | unmask_IO_APIC_irq(irq); | 2653 | unmask_IO_APIC_irq_desc(desc); |
2375 | } | 2654 | } |
2376 | 2655 | ||
2377 | #ifdef CONFIG_X86_32 | 2656 | #ifdef CONFIG_X86_32 |
2378 | if (!(v & (1 << (i & 0x1f)))) { | 2657 | if (!(v & (1 << (i & 0x1f)))) { |
2379 | atomic_inc(&irq_mis_count); | 2658 | atomic_inc(&irq_mis_count); |
2380 | spin_lock(&ioapic_lock); | 2659 | spin_lock(&ioapic_lock); |
2381 | __mask_and_edge_IO_APIC_irq(irq); | 2660 | __mask_and_edge_IO_APIC_irq(cfg); |
2382 | __unmask_and_level_IO_APIC_irq(irq); | 2661 | __unmask_and_level_IO_APIC_irq(cfg); |
2383 | spin_unlock(&ioapic_lock); | 2662 | spin_unlock(&ioapic_lock); |
2384 | } | 2663 | } |
2385 | #endif | 2664 | #endif |
@@ -2430,20 +2709,19 @@ static inline void init_IO_APIC_traps(void) | |||
2430 | * Also, we've got to be careful not to trash gate | 2709 | * Also, we've got to be careful not to trash gate |
2431 | * 0x80, because int 0x80 is hm, kind of importantish. ;) | 2710 | * 0x80, because int 0x80 is hm, kind of importantish. ;) |
2432 | */ | 2711 | */ |
2433 | for_each_irq_cfg(irq, cfg) { | 2712 | for_each_irq_desc(irq, desc) { |
2434 | if (IO_APIC_IRQ(irq) && !cfg->vector) { | 2713 | cfg = desc->chip_data; |
2714 | if (IO_APIC_IRQ(irq) && cfg && !cfg->vector) { | ||
2435 | /* | 2715 | /* |
2436 | * Hmm.. We don't have an entry for this, | 2716 | * Hmm.. We don't have an entry for this, |
2437 | * so default to an old-fashioned 8259 | 2717 | * so default to an old-fashioned 8259 |
2438 | * interrupt if we can.. | 2718 | * interrupt if we can.. |
2439 | */ | 2719 | */ |
2440 | if (irq < 16) | 2720 | if (irq < NR_IRQS_LEGACY) |
2441 | make_8259A_irq(irq); | 2721 | make_8259A_irq(irq); |
2442 | else { | 2722 | else |
2443 | desc = irq_to_desc(irq); | ||
2444 | /* Strange. Oh, well.. */ | 2723 | /* Strange. Oh, well.. */ |
2445 | desc->chip = &no_irq_chip; | 2724 | desc->chip = &no_irq_chip; |
2446 | } | ||
2447 | } | 2725 | } |
2448 | } | 2726 | } |
2449 | } | 2727 | } |
@@ -2468,7 +2746,7 @@ static void unmask_lapic_irq(unsigned int irq) | |||
2468 | apic_write(APIC_LVT0, v & ~APIC_LVT_MASKED); | 2746 | apic_write(APIC_LVT0, v & ~APIC_LVT_MASKED); |
2469 | } | 2747 | } |
2470 | 2748 | ||
2471 | static void ack_lapic_irq (unsigned int irq) | 2749 | static void ack_lapic_irq(unsigned int irq) |
2472 | { | 2750 | { |
2473 | ack_APIC_irq(); | 2751 | ack_APIC_irq(); |
2474 | } | 2752 | } |
@@ -2480,11 +2758,8 @@ static struct irq_chip lapic_chip __read_mostly = { | |||
2480 | .ack = ack_lapic_irq, | 2758 | .ack = ack_lapic_irq, |
2481 | }; | 2759 | }; |
2482 | 2760 | ||
2483 | static void lapic_register_intr(int irq) | 2761 | static void lapic_register_intr(int irq, struct irq_desc *desc) |
2484 | { | 2762 | { |
2485 | struct irq_desc *desc; | ||
2486 | |||
2487 | desc = irq_to_desc(irq); | ||
2488 | desc->status &= ~IRQ_LEVEL; | 2763 | desc->status &= ~IRQ_LEVEL; |
2489 | set_irq_chip_and_handler_name(irq, &lapic_chip, handle_edge_irq, | 2764 | set_irq_chip_and_handler_name(irq, &lapic_chip, handle_edge_irq, |
2490 | "edge"); | 2765 | "edge"); |
@@ -2588,7 +2863,9 @@ int timer_through_8259 __initdata; | |||
2588 | */ | 2863 | */ |
2589 | static inline void __init check_timer(void) | 2864 | static inline void __init check_timer(void) |
2590 | { | 2865 | { |
2591 | struct irq_cfg *cfg = irq_cfg(0); | 2866 | struct irq_desc *desc = irq_to_desc(0); |
2867 | struct irq_cfg *cfg = desc->chip_data; | ||
2868 | int cpu = boot_cpu_id; | ||
2592 | int apic1, pin1, apic2, pin2; | 2869 | int apic1, pin1, apic2, pin2; |
2593 | unsigned long flags; | 2870 | unsigned long flags; |
2594 | unsigned int ver; | 2871 | unsigned int ver; |
@@ -2603,7 +2880,7 @@ static inline void __init check_timer(void) | |||
2603 | * get/set the timer IRQ vector: | 2880 | * get/set the timer IRQ vector: |
2604 | */ | 2881 | */ |
2605 | disable_8259A_irq(0); | 2882 | disable_8259A_irq(0); |
2606 | assign_irq_vector(0, TARGET_CPUS); | 2883 | assign_irq_vector(0, cfg, TARGET_CPUS); |
2607 | 2884 | ||
2608 | /* | 2885 | /* |
2609 | * As IRQ0 is to be enabled in the 8259A, the virtual | 2886 | * As IRQ0 is to be enabled in the 8259A, the virtual |
@@ -2654,10 +2931,10 @@ static inline void __init check_timer(void) | |||
2654 | * Ok, does IRQ0 through the IOAPIC work? | 2931 | * Ok, does IRQ0 through the IOAPIC work? |
2655 | */ | 2932 | */ |
2656 | if (no_pin1) { | 2933 | if (no_pin1) { |
2657 | add_pin_to_irq(0, apic1, pin1); | 2934 | add_pin_to_irq_cpu(cfg, cpu, apic1, pin1); |
2658 | setup_timer_IRQ0_pin(apic1, pin1, cfg->vector); | 2935 | setup_timer_IRQ0_pin(apic1, pin1, cfg->vector); |
2659 | } | 2936 | } |
2660 | unmask_IO_APIC_irq(0); | 2937 | unmask_IO_APIC_irq_desc(desc); |
2661 | if (timer_irq_works()) { | 2938 | if (timer_irq_works()) { |
2662 | if (nmi_watchdog == NMI_IO_APIC) { | 2939 | if (nmi_watchdog == NMI_IO_APIC) { |
2663 | setup_nmi(); | 2940 | setup_nmi(); |
@@ -2683,9 +2960,9 @@ static inline void __init check_timer(void) | |||
2683 | /* | 2960 | /* |
2684 | * legacy devices should be connected to IO APIC #0 | 2961 | * legacy devices should be connected to IO APIC #0 |
2685 | */ | 2962 | */ |
2686 | replace_pin_at_irq(0, apic1, pin1, apic2, pin2); | 2963 | replace_pin_at_irq_cpu(cfg, cpu, apic1, pin1, apic2, pin2); |
2687 | setup_timer_IRQ0_pin(apic2, pin2, cfg->vector); | 2964 | setup_timer_IRQ0_pin(apic2, pin2, cfg->vector); |
2688 | unmask_IO_APIC_irq(0); | 2965 | unmask_IO_APIC_irq_desc(desc); |
2689 | enable_8259A_irq(0); | 2966 | enable_8259A_irq(0); |
2690 | if (timer_irq_works()) { | 2967 | if (timer_irq_works()) { |
2691 | apic_printk(APIC_QUIET, KERN_INFO "....... works.\n"); | 2968 | apic_printk(APIC_QUIET, KERN_INFO "....... works.\n"); |
@@ -2717,7 +2994,7 @@ static inline void __init check_timer(void) | |||
2717 | apic_printk(APIC_QUIET, KERN_INFO | 2994 | apic_printk(APIC_QUIET, KERN_INFO |
2718 | "...trying to set up timer as Virtual Wire IRQ...\n"); | 2995 | "...trying to set up timer as Virtual Wire IRQ...\n"); |
2719 | 2996 | ||
2720 | lapic_register_intr(0); | 2997 | lapic_register_intr(0, desc); |
2721 | apic_write(APIC_LVT0, APIC_DM_FIXED | cfg->vector); /* Fixed mode */ | 2998 | apic_write(APIC_LVT0, APIC_DM_FIXED | cfg->vector); /* Fixed mode */ |
2722 | enable_8259A_irq(0); | 2999 | enable_8259A_irq(0); |
2723 | 3000 | ||
@@ -2902,22 +3179,26 @@ unsigned int create_irq_nr(unsigned int irq_want) | |||
2902 | unsigned int irq; | 3179 | unsigned int irq; |
2903 | unsigned int new; | 3180 | unsigned int new; |
2904 | unsigned long flags; | 3181 | unsigned long flags; |
2905 | struct irq_cfg *cfg_new; | 3182 | struct irq_cfg *cfg_new = NULL; |
2906 | 3183 | int cpu = boot_cpu_id; | |
2907 | irq_want = nr_irqs - 1; | 3184 | struct irq_desc *desc_new = NULL; |
2908 | 3185 | ||
2909 | irq = 0; | 3186 | irq = 0; |
2910 | spin_lock_irqsave(&vector_lock, flags); | 3187 | spin_lock_irqsave(&vector_lock, flags); |
2911 | for (new = irq_want; new > 0; new--) { | 3188 | for (new = irq_want; new < NR_IRQS; new++) { |
2912 | if (platform_legacy_irq(new)) | 3189 | if (platform_legacy_irq(new)) |
2913 | continue; | 3190 | continue; |
2914 | cfg_new = irq_cfg(new); | 3191 | |
2915 | if (cfg_new && cfg_new->vector != 0) | 3192 | desc_new = irq_to_desc_alloc_cpu(new, cpu); |
3193 | if (!desc_new) { | ||
3194 | printk(KERN_INFO "can not get irq_desc for %d\n", new); | ||
2916 | continue; | 3195 | continue; |
2917 | /* check if need to create one */ | 3196 | } |
2918 | if (!cfg_new) | 3197 | cfg_new = desc_new->chip_data; |
2919 | cfg_new = irq_cfg_alloc(new); | 3198 | |
2920 | if (__assign_irq_vector(new, TARGET_CPUS) == 0) | 3199 | if (cfg_new->vector != 0) |
3200 | continue; | ||
3201 | if (__assign_irq_vector(new, cfg_new, TARGET_CPUS) == 0) | ||
2921 | irq = new; | 3202 | irq = new; |
2922 | break; | 3203 | break; |
2923 | } | 3204 | } |
@@ -2925,15 +3206,21 @@ unsigned int create_irq_nr(unsigned int irq_want) | |||
2925 | 3206 | ||
2926 | if (irq > 0) { | 3207 | if (irq > 0) { |
2927 | dynamic_irq_init(irq); | 3208 | dynamic_irq_init(irq); |
3209 | /* restore it, in case dynamic_irq_init clear it */ | ||
3210 | if (desc_new) | ||
3211 | desc_new->chip_data = cfg_new; | ||
2928 | } | 3212 | } |
2929 | return irq; | 3213 | return irq; |
2930 | } | 3214 | } |
2931 | 3215 | ||
3216 | static int nr_irqs_gsi = NR_IRQS_LEGACY; | ||
2932 | int create_irq(void) | 3217 | int create_irq(void) |
2933 | { | 3218 | { |
3219 | unsigned int irq_want; | ||
2934 | int irq; | 3220 | int irq; |
2935 | 3221 | ||
2936 | irq = create_irq_nr(nr_irqs - 1); | 3222 | irq_want = nr_irqs_gsi; |
3223 | irq = create_irq_nr(irq_want); | ||
2937 | 3224 | ||
2938 | if (irq == 0) | 3225 | if (irq == 0) |
2939 | irq = -1; | 3226 | irq = -1; |
@@ -2944,14 +3231,22 @@ int create_irq(void) | |||
2944 | void destroy_irq(unsigned int irq) | 3231 | void destroy_irq(unsigned int irq) |
2945 | { | 3232 | { |
2946 | unsigned long flags; | 3233 | unsigned long flags; |
3234 | struct irq_cfg *cfg; | ||
3235 | struct irq_desc *desc; | ||
2947 | 3236 | ||
3237 | /* store it, in case dynamic_irq_cleanup clear it */ | ||
3238 | desc = irq_to_desc(irq); | ||
3239 | cfg = desc->chip_data; | ||
2948 | dynamic_irq_cleanup(irq); | 3240 | dynamic_irq_cleanup(irq); |
3241 | /* connect back irq_cfg */ | ||
3242 | if (desc) | ||
3243 | desc->chip_data = cfg; | ||
2949 | 3244 | ||
2950 | #ifdef CONFIG_INTR_REMAP | 3245 | #ifdef CONFIG_INTR_REMAP |
2951 | free_irte(irq); | 3246 | free_irte(irq); |
2952 | #endif | 3247 | #endif |
2953 | spin_lock_irqsave(&vector_lock, flags); | 3248 | spin_lock_irqsave(&vector_lock, flags); |
2954 | __clear_irq_vector(irq); | 3249 | __clear_irq_vector(irq, cfg); |
2955 | spin_unlock_irqrestore(&vector_lock, flags); | 3250 | spin_unlock_irqrestore(&vector_lock, flags); |
2956 | } | 3251 | } |
2957 | 3252 | ||
@@ -2964,16 +3259,13 @@ static int msi_compose_msg(struct pci_dev *pdev, unsigned int irq, struct msi_ms | |||
2964 | struct irq_cfg *cfg; | 3259 | struct irq_cfg *cfg; |
2965 | int err; | 3260 | int err; |
2966 | unsigned dest; | 3261 | unsigned dest; |
2967 | cpumask_t tmp; | ||
2968 | 3262 | ||
2969 | tmp = TARGET_CPUS; | 3263 | cfg = irq_cfg(irq); |
2970 | err = assign_irq_vector(irq, tmp); | 3264 | err = assign_irq_vector(irq, cfg, TARGET_CPUS); |
2971 | if (err) | 3265 | if (err) |
2972 | return err; | 3266 | return err; |
2973 | 3267 | ||
2974 | cfg = irq_cfg(irq); | 3268 | dest = cpu_mask_to_apicid_and(cfg->domain, TARGET_CPUS); |
2975 | cpus_and(tmp, cfg->domain, tmp); | ||
2976 | dest = cpu_mask_to_apicid(tmp); | ||
2977 | 3269 | ||
2978 | #ifdef CONFIG_INTR_REMAP | 3270 | #ifdef CONFIG_INTR_REMAP |
2979 | if (irq_remapped(irq)) { | 3271 | if (irq_remapped(irq)) { |
@@ -3027,64 +3319,48 @@ static int msi_compose_msg(struct pci_dev *pdev, unsigned int irq, struct msi_ms | |||
3027 | } | 3319 | } |
3028 | 3320 | ||
3029 | #ifdef CONFIG_SMP | 3321 | #ifdef CONFIG_SMP |
3030 | static void set_msi_irq_affinity(unsigned int irq, cpumask_t mask) | 3322 | static void set_msi_irq_affinity(unsigned int irq, const struct cpumask *mask) |
3031 | { | 3323 | { |
3324 | struct irq_desc *desc = irq_to_desc(irq); | ||
3032 | struct irq_cfg *cfg; | 3325 | struct irq_cfg *cfg; |
3033 | struct msi_msg msg; | 3326 | struct msi_msg msg; |
3034 | unsigned int dest; | 3327 | unsigned int dest; |
3035 | cpumask_t tmp; | ||
3036 | struct irq_desc *desc; | ||
3037 | 3328 | ||
3038 | cpus_and(tmp, mask, cpu_online_map); | 3329 | dest = set_desc_affinity(desc, mask); |
3039 | if (cpus_empty(tmp)) | 3330 | if (dest == BAD_APICID) |
3040 | return; | 3331 | return; |
3041 | 3332 | ||
3042 | if (assign_irq_vector(irq, mask)) | 3333 | cfg = desc->chip_data; |
3043 | return; | ||
3044 | 3334 | ||
3045 | cfg = irq_cfg(irq); | 3335 | read_msi_msg_desc(desc, &msg); |
3046 | cpus_and(tmp, cfg->domain, mask); | ||
3047 | dest = cpu_mask_to_apicid(tmp); | ||
3048 | |||
3049 | read_msi_msg(irq, &msg); | ||
3050 | 3336 | ||
3051 | msg.data &= ~MSI_DATA_VECTOR_MASK; | 3337 | msg.data &= ~MSI_DATA_VECTOR_MASK; |
3052 | msg.data |= MSI_DATA_VECTOR(cfg->vector); | 3338 | msg.data |= MSI_DATA_VECTOR(cfg->vector); |
3053 | msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK; | 3339 | msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK; |
3054 | msg.address_lo |= MSI_ADDR_DEST_ID(dest); | 3340 | msg.address_lo |= MSI_ADDR_DEST_ID(dest); |
3055 | 3341 | ||
3056 | write_msi_msg(irq, &msg); | 3342 | write_msi_msg_desc(desc, &msg); |
3057 | desc = irq_to_desc(irq); | ||
3058 | desc->affinity = mask; | ||
3059 | } | 3343 | } |
3060 | |||
3061 | #ifdef CONFIG_INTR_REMAP | 3344 | #ifdef CONFIG_INTR_REMAP |
3062 | /* | 3345 | /* |
3063 | * Migrate the MSI irq to another cpumask. This migration is | 3346 | * Migrate the MSI irq to another cpumask. This migration is |
3064 | * done in the process context using interrupt-remapping hardware. | 3347 | * done in the process context using interrupt-remapping hardware. |
3065 | */ | 3348 | */ |
3066 | static void ir_set_msi_irq_affinity(unsigned int irq, cpumask_t mask) | 3349 | static void |
3350 | ir_set_msi_irq_affinity(unsigned int irq, const struct cpumask *mask) | ||
3067 | { | 3351 | { |
3068 | struct irq_cfg *cfg; | 3352 | struct irq_desc *desc = irq_to_desc(irq); |
3353 | struct irq_cfg *cfg = desc->chip_data; | ||
3069 | unsigned int dest; | 3354 | unsigned int dest; |
3070 | cpumask_t tmp, cleanup_mask; | ||
3071 | struct irte irte; | 3355 | struct irte irte; |
3072 | struct irq_desc *desc; | ||
3073 | |||
3074 | cpus_and(tmp, mask, cpu_online_map); | ||
3075 | if (cpus_empty(tmp)) | ||
3076 | return; | ||
3077 | 3356 | ||
3078 | if (get_irte(irq, &irte)) | 3357 | if (get_irte(irq, &irte)) |
3079 | return; | 3358 | return; |
3080 | 3359 | ||
3081 | if (assign_irq_vector(irq, mask)) | 3360 | dest = set_desc_affinity(desc, mask); |
3361 | if (dest == BAD_APICID) | ||
3082 | return; | 3362 | return; |
3083 | 3363 | ||
3084 | cfg = irq_cfg(irq); | ||
3085 | cpus_and(tmp, cfg->domain, mask); | ||
3086 | dest = cpu_mask_to_apicid(tmp); | ||
3087 | |||
3088 | irte.vector = cfg->vector; | 3364 | irte.vector = cfg->vector; |
3089 | irte.dest_id = IRTE_DEST(dest); | 3365 | irte.dest_id = IRTE_DEST(dest); |
3090 | 3366 | ||
@@ -3098,16 +3374,10 @@ static void ir_set_msi_irq_affinity(unsigned int irq, cpumask_t mask) | |||
3098 | * at the new destination. So, time to cleanup the previous | 3374 | * at the new destination. So, time to cleanup the previous |
3099 | * vector allocation. | 3375 | * vector allocation. |
3100 | */ | 3376 | */ |
3101 | if (cfg->move_in_progress) { | 3377 | if (cfg->move_in_progress) |
3102 | cpus_and(cleanup_mask, cfg->old_domain, cpu_online_map); | 3378 | send_cleanup_vector(cfg); |
3103 | cfg->move_cleanup_count = cpus_weight(cleanup_mask); | ||
3104 | send_IPI_mask(cleanup_mask, IRQ_MOVE_CLEANUP_VECTOR); | ||
3105 | cfg->move_in_progress = 0; | ||
3106 | } | ||
3107 | |||
3108 | desc = irq_to_desc(irq); | ||
3109 | desc->affinity = mask; | ||
3110 | } | 3379 | } |
3380 | |||
3111 | #endif | 3381 | #endif |
3112 | #endif /* CONFIG_SMP */ | 3382 | #endif /* CONFIG_SMP */ |
3113 | 3383 | ||
@@ -3166,7 +3436,7 @@ static int msi_alloc_irte(struct pci_dev *dev, int irq, int nvec) | |||
3166 | } | 3436 | } |
3167 | #endif | 3437 | #endif |
3168 | 3438 | ||
3169 | static int setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc, int irq) | 3439 | static int setup_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc, int irq) |
3170 | { | 3440 | { |
3171 | int ret; | 3441 | int ret; |
3172 | struct msi_msg msg; | 3442 | struct msi_msg msg; |
@@ -3175,7 +3445,7 @@ static int setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc, int irq) | |||
3175 | if (ret < 0) | 3445 | if (ret < 0) |
3176 | return ret; | 3446 | return ret; |
3177 | 3447 | ||
3178 | set_irq_msi(irq, desc); | 3448 | set_irq_msi(irq, msidesc); |
3179 | write_msi_msg(irq, &msg); | 3449 | write_msi_msg(irq, &msg); |
3180 | 3450 | ||
3181 | #ifdef CONFIG_INTR_REMAP | 3451 | #ifdef CONFIG_INTR_REMAP |
@@ -3195,26 +3465,13 @@ static int setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc, int irq) | |||
3195 | return 0; | 3465 | return 0; |
3196 | } | 3466 | } |
3197 | 3467 | ||
3198 | static unsigned int build_irq_for_pci_dev(struct pci_dev *dev) | 3468 | int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc) |
3199 | { | ||
3200 | unsigned int irq; | ||
3201 | |||
3202 | irq = dev->bus->number; | ||
3203 | irq <<= 8; | ||
3204 | irq |= dev->devfn; | ||
3205 | irq <<= 12; | ||
3206 | |||
3207 | return irq; | ||
3208 | } | ||
3209 | |||
3210 | int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc) | ||
3211 | { | 3469 | { |
3212 | unsigned int irq; | 3470 | unsigned int irq; |
3213 | int ret; | 3471 | int ret; |
3214 | unsigned int irq_want; | 3472 | unsigned int irq_want; |
3215 | 3473 | ||
3216 | irq_want = build_irq_for_pci_dev(dev) + 0x100; | 3474 | irq_want = nr_irqs_gsi; |
3217 | |||
3218 | irq = create_irq_nr(irq_want); | 3475 | irq = create_irq_nr(irq_want); |
3219 | if (irq == 0) | 3476 | if (irq == 0) |
3220 | return -1; | 3477 | return -1; |
@@ -3228,7 +3485,7 @@ int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc) | |||
3228 | goto error; | 3485 | goto error; |
3229 | no_ir: | 3486 | no_ir: |
3230 | #endif | 3487 | #endif |
3231 | ret = setup_msi_irq(dev, desc, irq); | 3488 | ret = setup_msi_irq(dev, msidesc, irq); |
3232 | if (ret < 0) { | 3489 | if (ret < 0) { |
3233 | destroy_irq(irq); | 3490 | destroy_irq(irq); |
3234 | return ret; | 3491 | return ret; |
@@ -3246,7 +3503,7 @@ int arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) | |||
3246 | { | 3503 | { |
3247 | unsigned int irq; | 3504 | unsigned int irq; |
3248 | int ret, sub_handle; | 3505 | int ret, sub_handle; |
3249 | struct msi_desc *desc; | 3506 | struct msi_desc *msidesc; |
3250 | unsigned int irq_want; | 3507 | unsigned int irq_want; |
3251 | 3508 | ||
3252 | #ifdef CONFIG_INTR_REMAP | 3509 | #ifdef CONFIG_INTR_REMAP |
@@ -3254,10 +3511,11 @@ int arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) | |||
3254 | int index = 0; | 3511 | int index = 0; |
3255 | #endif | 3512 | #endif |
3256 | 3513 | ||
3257 | irq_want = build_irq_for_pci_dev(dev) + 0x100; | 3514 | irq_want = nr_irqs_gsi; |
3258 | sub_handle = 0; | 3515 | sub_handle = 0; |
3259 | list_for_each_entry(desc, &dev->msi_list, list) { | 3516 | list_for_each_entry(msidesc, &dev->msi_list, list) { |
3260 | irq = create_irq_nr(irq_want--); | 3517 | irq = create_irq_nr(irq_want); |
3518 | irq_want++; | ||
3261 | if (irq == 0) | 3519 | if (irq == 0) |
3262 | return -1; | 3520 | return -1; |
3263 | #ifdef CONFIG_INTR_REMAP | 3521 | #ifdef CONFIG_INTR_REMAP |
@@ -3289,7 +3547,7 @@ int arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) | |||
3289 | } | 3547 | } |
3290 | no_ir: | 3548 | no_ir: |
3291 | #endif | 3549 | #endif |
3292 | ret = setup_msi_irq(dev, desc, irq); | 3550 | ret = setup_msi_irq(dev, msidesc, irq); |
3293 | if (ret < 0) | 3551 | if (ret < 0) |
3294 | goto error; | 3552 | goto error; |
3295 | sub_handle++; | 3553 | sub_handle++; |
@@ -3308,24 +3566,18 @@ void arch_teardown_msi_irq(unsigned int irq) | |||
3308 | 3566 | ||
3309 | #ifdef CONFIG_DMAR | 3567 | #ifdef CONFIG_DMAR |
3310 | #ifdef CONFIG_SMP | 3568 | #ifdef CONFIG_SMP |
3311 | static void dmar_msi_set_affinity(unsigned int irq, cpumask_t mask) | 3569 | static void dmar_msi_set_affinity(unsigned int irq, const struct cpumask *mask) |
3312 | { | 3570 | { |
3571 | struct irq_desc *desc = irq_to_desc(irq); | ||
3313 | struct irq_cfg *cfg; | 3572 | struct irq_cfg *cfg; |
3314 | struct msi_msg msg; | 3573 | struct msi_msg msg; |
3315 | unsigned int dest; | 3574 | unsigned int dest; |
3316 | cpumask_t tmp; | ||
3317 | struct irq_desc *desc; | ||
3318 | 3575 | ||
3319 | cpus_and(tmp, mask, cpu_online_map); | 3576 | dest = set_desc_affinity(desc, mask); |
3320 | if (cpus_empty(tmp)) | 3577 | if (dest == BAD_APICID) |
3321 | return; | 3578 | return; |
3322 | 3579 | ||
3323 | if (assign_irq_vector(irq, mask)) | 3580 | cfg = desc->chip_data; |
3324 | return; | ||
3325 | |||
3326 | cfg = irq_cfg(irq); | ||
3327 | cpus_and(tmp, cfg->domain, mask); | ||
3328 | dest = cpu_mask_to_apicid(tmp); | ||
3329 | 3581 | ||
3330 | dmar_msi_read(irq, &msg); | 3582 | dmar_msi_read(irq, &msg); |
3331 | 3583 | ||
@@ -3335,9 +3587,8 @@ static void dmar_msi_set_affinity(unsigned int irq, cpumask_t mask) | |||
3335 | msg.address_lo |= MSI_ADDR_DEST_ID(dest); | 3587 | msg.address_lo |= MSI_ADDR_DEST_ID(dest); |
3336 | 3588 | ||
3337 | dmar_msi_write(irq, &msg); | 3589 | dmar_msi_write(irq, &msg); |
3338 | desc = irq_to_desc(irq); | ||
3339 | desc->affinity = mask; | ||
3340 | } | 3590 | } |
3591 | |||
3341 | #endif /* CONFIG_SMP */ | 3592 | #endif /* CONFIG_SMP */ |
3342 | 3593 | ||
3343 | struct irq_chip dmar_msi_type = { | 3594 | struct irq_chip dmar_msi_type = { |
@@ -3369,24 +3620,18 @@ int arch_setup_dmar_msi(unsigned int irq) | |||
3369 | #ifdef CONFIG_HPET_TIMER | 3620 | #ifdef CONFIG_HPET_TIMER |
3370 | 3621 | ||
3371 | #ifdef CONFIG_SMP | 3622 | #ifdef CONFIG_SMP |
3372 | static void hpet_msi_set_affinity(unsigned int irq, cpumask_t mask) | 3623 | static void hpet_msi_set_affinity(unsigned int irq, const struct cpumask *mask) |
3373 | { | 3624 | { |
3625 | struct irq_desc *desc = irq_to_desc(irq); | ||
3374 | struct irq_cfg *cfg; | 3626 | struct irq_cfg *cfg; |
3375 | struct irq_desc *desc; | ||
3376 | struct msi_msg msg; | 3627 | struct msi_msg msg; |
3377 | unsigned int dest; | 3628 | unsigned int dest; |
3378 | cpumask_t tmp; | ||
3379 | 3629 | ||
3380 | cpus_and(tmp, mask, cpu_online_map); | 3630 | dest = set_desc_affinity(desc, mask); |
3381 | if (cpus_empty(tmp)) | 3631 | if (dest == BAD_APICID) |
3382 | return; | 3632 | return; |
3383 | 3633 | ||
3384 | if (assign_irq_vector(irq, mask)) | 3634 | cfg = desc->chip_data; |
3385 | return; | ||
3386 | |||
3387 | cfg = irq_cfg(irq); | ||
3388 | cpus_and(tmp, cfg->domain, mask); | ||
3389 | dest = cpu_mask_to_apicid(tmp); | ||
3390 | 3635 | ||
3391 | hpet_msi_read(irq, &msg); | 3636 | hpet_msi_read(irq, &msg); |
3392 | 3637 | ||
@@ -3396,9 +3641,8 @@ static void hpet_msi_set_affinity(unsigned int irq, cpumask_t mask) | |||
3396 | msg.address_lo |= MSI_ADDR_DEST_ID(dest); | 3641 | msg.address_lo |= MSI_ADDR_DEST_ID(dest); |
3397 | 3642 | ||
3398 | hpet_msi_write(irq, &msg); | 3643 | hpet_msi_write(irq, &msg); |
3399 | desc = irq_to_desc(irq); | ||
3400 | desc->affinity = mask; | ||
3401 | } | 3644 | } |
3645 | |||
3402 | #endif /* CONFIG_SMP */ | 3646 | #endif /* CONFIG_SMP */ |
3403 | 3647 | ||
3404 | struct irq_chip hpet_msi_type = { | 3648 | struct irq_chip hpet_msi_type = { |
@@ -3451,28 +3695,21 @@ static void target_ht_irq(unsigned int irq, unsigned int dest, u8 vector) | |||
3451 | write_ht_irq_msg(irq, &msg); | 3695 | write_ht_irq_msg(irq, &msg); |
3452 | } | 3696 | } |
3453 | 3697 | ||
3454 | static void set_ht_irq_affinity(unsigned int irq, cpumask_t mask) | 3698 | static void set_ht_irq_affinity(unsigned int irq, const struct cpumask *mask) |
3455 | { | 3699 | { |
3700 | struct irq_desc *desc = irq_to_desc(irq); | ||
3456 | struct irq_cfg *cfg; | 3701 | struct irq_cfg *cfg; |
3457 | unsigned int dest; | 3702 | unsigned int dest; |
3458 | cpumask_t tmp; | ||
3459 | struct irq_desc *desc; | ||
3460 | 3703 | ||
3461 | cpus_and(tmp, mask, cpu_online_map); | 3704 | dest = set_desc_affinity(desc, mask); |
3462 | if (cpus_empty(tmp)) | 3705 | if (dest == BAD_APICID) |
3463 | return; | 3706 | return; |
3464 | 3707 | ||
3465 | if (assign_irq_vector(irq, mask)) | 3708 | cfg = desc->chip_data; |
3466 | return; | ||
3467 | |||
3468 | cfg = irq_cfg(irq); | ||
3469 | cpus_and(tmp, cfg->domain, mask); | ||
3470 | dest = cpu_mask_to_apicid(tmp); | ||
3471 | 3709 | ||
3472 | target_ht_irq(irq, dest, cfg->vector); | 3710 | target_ht_irq(irq, dest, cfg->vector); |
3473 | desc = irq_to_desc(irq); | ||
3474 | desc->affinity = mask; | ||
3475 | } | 3711 | } |
3712 | |||
3476 | #endif | 3713 | #endif |
3477 | 3714 | ||
3478 | static struct irq_chip ht_irq_chip = { | 3715 | static struct irq_chip ht_irq_chip = { |
@@ -3490,17 +3727,14 @@ int arch_setup_ht_irq(unsigned int irq, struct pci_dev *dev) | |||
3490 | { | 3727 | { |
3491 | struct irq_cfg *cfg; | 3728 | struct irq_cfg *cfg; |
3492 | int err; | 3729 | int err; |
3493 | cpumask_t tmp; | ||
3494 | 3730 | ||
3495 | tmp = TARGET_CPUS; | 3731 | cfg = irq_cfg(irq); |
3496 | err = assign_irq_vector(irq, tmp); | 3732 | err = assign_irq_vector(irq, cfg, TARGET_CPUS); |
3497 | if (!err) { | 3733 | if (!err) { |
3498 | struct ht_irq_msg msg; | 3734 | struct ht_irq_msg msg; |
3499 | unsigned dest; | 3735 | unsigned dest; |
3500 | 3736 | ||
3501 | cfg = irq_cfg(irq); | 3737 | dest = cpu_mask_to_apicid_and(cfg->domain, TARGET_CPUS); |
3502 | cpus_and(tmp, cfg->domain, tmp); | ||
3503 | dest = cpu_mask_to_apicid(tmp); | ||
3504 | 3738 | ||
3505 | msg.address_hi = HT_IRQ_HIGH_DEST_ID(dest); | 3739 | msg.address_hi = HT_IRQ_HIGH_DEST_ID(dest); |
3506 | 3740 | ||
@@ -3536,7 +3770,7 @@ int arch_setup_ht_irq(unsigned int irq, struct pci_dev *dev) | |||
3536 | int arch_enable_uv_irq(char *irq_name, unsigned int irq, int cpu, int mmr_blade, | 3770 | int arch_enable_uv_irq(char *irq_name, unsigned int irq, int cpu, int mmr_blade, |
3537 | unsigned long mmr_offset) | 3771 | unsigned long mmr_offset) |
3538 | { | 3772 | { |
3539 | const cpumask_t *eligible_cpu = get_cpu_mask(cpu); | 3773 | const struct cpumask *eligible_cpu = cpumask_of(cpu); |
3540 | struct irq_cfg *cfg; | 3774 | struct irq_cfg *cfg; |
3541 | int mmr_pnode; | 3775 | int mmr_pnode; |
3542 | unsigned long mmr_value; | 3776 | unsigned long mmr_value; |
@@ -3544,7 +3778,9 @@ int arch_enable_uv_irq(char *irq_name, unsigned int irq, int cpu, int mmr_blade, | |||
3544 | unsigned long flags; | 3778 | unsigned long flags; |
3545 | int err; | 3779 | int err; |
3546 | 3780 | ||
3547 | err = assign_irq_vector(irq, *eligible_cpu); | 3781 | cfg = irq_cfg(irq); |
3782 | |||
3783 | err = assign_irq_vector(irq, cfg, eligible_cpu); | ||
3548 | if (err != 0) | 3784 | if (err != 0) |
3549 | return err; | 3785 | return err; |
3550 | 3786 | ||
@@ -3553,8 +3789,6 @@ int arch_enable_uv_irq(char *irq_name, unsigned int irq, int cpu, int mmr_blade, | |||
3553 | irq_name); | 3789 | irq_name); |
3554 | spin_unlock_irqrestore(&vector_lock, flags); | 3790 | spin_unlock_irqrestore(&vector_lock, flags); |
3555 | 3791 | ||
3556 | cfg = irq_cfg(irq); | ||
3557 | |||
3558 | mmr_value = 0; | 3792 | mmr_value = 0; |
3559 | entry = (struct uv_IO_APIC_route_entry *)&mmr_value; | 3793 | entry = (struct uv_IO_APIC_route_entry *)&mmr_value; |
3560 | BUG_ON(sizeof(struct uv_IO_APIC_route_entry) != sizeof(unsigned long)); | 3794 | BUG_ON(sizeof(struct uv_IO_APIC_route_entry) != sizeof(unsigned long)); |
@@ -3565,7 +3799,7 @@ int arch_enable_uv_irq(char *irq_name, unsigned int irq, int cpu, int mmr_blade, | |||
3565 | entry->polarity = 0; | 3799 | entry->polarity = 0; |
3566 | entry->trigger = 0; | 3800 | entry->trigger = 0; |
3567 | entry->mask = 0; | 3801 | entry->mask = 0; |
3568 | entry->dest = cpu_mask_to_apicid(*eligible_cpu); | 3802 | entry->dest = cpu_mask_to_apicid(eligible_cpu); |
3569 | 3803 | ||
3570 | mmr_pnode = uv_blade_to_pnode(mmr_blade); | 3804 | mmr_pnode = uv_blade_to_pnode(mmr_blade); |
3571 | uv_write_global_mmr64(mmr_pnode, mmr_offset, mmr_value); | 3805 | uv_write_global_mmr64(mmr_pnode, mmr_offset, mmr_value); |
@@ -3606,9 +3840,16 @@ int __init io_apic_get_redir_entries (int ioapic) | |||
3606 | return reg_01.bits.entries; | 3840 | return reg_01.bits.entries; |
3607 | } | 3841 | } |
3608 | 3842 | ||
3609 | int __init probe_nr_irqs(void) | 3843 | void __init probe_nr_irqs_gsi(void) |
3610 | { | 3844 | { |
3611 | return NR_IRQS; | 3845 | int idx; |
3846 | int nr = 0; | ||
3847 | |||
3848 | for (idx = 0; idx < nr_ioapics; idx++) | ||
3849 | nr += io_apic_get_redir_entries(idx) + 1; | ||
3850 | |||
3851 | if (nr > nr_irqs_gsi) | ||
3852 | nr_irqs_gsi = nr; | ||
3612 | } | 3853 | } |
3613 | 3854 | ||
3614 | /* -------------------------------------------------------------------------- | 3855 | /* -------------------------------------------------------------------------- |
@@ -3707,19 +3948,31 @@ int __init io_apic_get_version(int ioapic) | |||
3707 | 3948 | ||
3708 | int io_apic_set_pci_routing (int ioapic, int pin, int irq, int triggering, int polarity) | 3949 | int io_apic_set_pci_routing (int ioapic, int pin, int irq, int triggering, int polarity) |
3709 | { | 3950 | { |
3951 | struct irq_desc *desc; | ||
3952 | struct irq_cfg *cfg; | ||
3953 | int cpu = boot_cpu_id; | ||
3954 | |||
3710 | if (!IO_APIC_IRQ(irq)) { | 3955 | if (!IO_APIC_IRQ(irq)) { |
3711 | apic_printk(APIC_QUIET,KERN_ERR "IOAPIC[%d]: Invalid reference to IRQ 0\n", | 3956 | apic_printk(APIC_QUIET,KERN_ERR "IOAPIC[%d]: Invalid reference to IRQ 0\n", |
3712 | ioapic); | 3957 | ioapic); |
3713 | return -EINVAL; | 3958 | return -EINVAL; |
3714 | } | 3959 | } |
3715 | 3960 | ||
3961 | desc = irq_to_desc_alloc_cpu(irq, cpu); | ||
3962 | if (!desc) { | ||
3963 | printk(KERN_INFO "can not get irq_desc %d\n", irq); | ||
3964 | return 0; | ||
3965 | } | ||
3966 | |||
3716 | /* | 3967 | /* |
3717 | * IRQs < 16 are already in the irq_2_pin[] map | 3968 | * IRQs < 16 are already in the irq_2_pin[] map |
3718 | */ | 3969 | */ |
3719 | if (irq >= 16) | 3970 | if (irq >= NR_IRQS_LEGACY) { |
3720 | add_pin_to_irq(irq, ioapic, pin); | 3971 | cfg = desc->chip_data; |
3972 | add_pin_to_irq_cpu(cfg, cpu, ioapic, pin); | ||
3973 | } | ||
3721 | 3974 | ||
3722 | setup_IO_APIC_irq(ioapic, pin, irq, triggering, polarity); | 3975 | setup_IO_APIC_irq(ioapic, pin, irq, desc, triggering, polarity); |
3723 | 3976 | ||
3724 | return 0; | 3977 | return 0; |
3725 | } | 3978 | } |
@@ -3757,7 +4010,7 @@ void __init setup_ioapic_dest(void) | |||
3757 | int pin, ioapic, irq, irq_entry; | 4010 | int pin, ioapic, irq, irq_entry; |
3758 | struct irq_desc *desc; | 4011 | struct irq_desc *desc; |
3759 | struct irq_cfg *cfg; | 4012 | struct irq_cfg *cfg; |
3760 | cpumask_t mask; | 4013 | const struct cpumask *mask; |
3761 | 4014 | ||
3762 | if (skip_ioapic_setup == 1) | 4015 | if (skip_ioapic_setup == 1) |
3763 | return; | 4016 | return; |
@@ -3773,9 +4026,10 @@ void __init setup_ioapic_dest(void) | |||
3773 | * when you have too many devices, because at that time only boot | 4026 | * when you have too many devices, because at that time only boot |
3774 | * cpu is online. | 4027 | * cpu is online. |
3775 | */ | 4028 | */ |
3776 | cfg = irq_cfg(irq); | 4029 | desc = irq_to_desc(irq); |
4030 | cfg = desc->chip_data; | ||
3777 | if (!cfg->vector) { | 4031 | if (!cfg->vector) { |
3778 | setup_IO_APIC_irq(ioapic, pin, irq, | 4032 | setup_IO_APIC_irq(ioapic, pin, irq, desc, |
3779 | irq_trigger(irq_entry), | 4033 | irq_trigger(irq_entry), |
3780 | irq_polarity(irq_entry)); | 4034 | irq_polarity(irq_entry)); |
3781 | continue; | 4035 | continue; |
@@ -3785,19 +4039,18 @@ void __init setup_ioapic_dest(void) | |||
3785 | /* | 4039 | /* |
3786 | * Honour affinities which have been set in early boot | 4040 | * Honour affinities which have been set in early boot |
3787 | */ | 4041 | */ |
3788 | desc = irq_to_desc(irq); | ||
3789 | if (desc->status & | 4042 | if (desc->status & |
3790 | (IRQ_NO_BALANCING | IRQ_AFFINITY_SET)) | 4043 | (IRQ_NO_BALANCING | IRQ_AFFINITY_SET)) |
3791 | mask = desc->affinity; | 4044 | mask = &desc->affinity; |
3792 | else | 4045 | else |
3793 | mask = TARGET_CPUS; | 4046 | mask = TARGET_CPUS; |
3794 | 4047 | ||
3795 | #ifdef CONFIG_INTR_REMAP | 4048 | #ifdef CONFIG_INTR_REMAP |
3796 | if (intr_remapping_enabled) | 4049 | if (intr_remapping_enabled) |
3797 | set_ir_ioapic_affinity_irq(irq, mask); | 4050 | set_ir_ioapic_affinity_irq_desc(desc, mask); |
3798 | else | 4051 | else |
3799 | #endif | 4052 | #endif |
3800 | set_ioapic_affinity_irq(irq, mask); | 4053 | set_ioapic_affinity_irq_desc(desc, mask); |
3801 | } | 4054 | } |
3802 | 4055 | ||
3803 | } | 4056 | } |
@@ -3846,7 +4099,6 @@ void __init ioapic_init_mappings(void) | |||
3846 | struct resource *ioapic_res; | 4099 | struct resource *ioapic_res; |
3847 | int i; | 4100 | int i; |
3848 | 4101 | ||
3849 | irq_2_pin_init(); | ||
3850 | ioapic_res = ioapic_setup_resources(); | 4102 | ioapic_res = ioapic_setup_resources(); |
3851 | for (i = 0; i < nr_ioapics; i++) { | 4103 | for (i = 0; i < nr_ioapics; i++) { |
3852 | if (smp_found_config) { | 4104 | if (smp_found_config) { |
diff --git a/arch/x86/kernel/ipi.c b/arch/x86/kernel/ipi.c index f1c688e46f35..285bbf8831fa 100644 --- a/arch/x86/kernel/ipi.c +++ b/arch/x86/kernel/ipi.c | |||
@@ -116,18 +116,18 @@ static inline void __send_IPI_dest_field(unsigned long mask, int vector) | |||
116 | /* | 116 | /* |
117 | * This is only used on smaller machines. | 117 | * This is only used on smaller machines. |
118 | */ | 118 | */ |
119 | void send_IPI_mask_bitmask(cpumask_t cpumask, int vector) | 119 | void send_IPI_mask_bitmask(const struct cpumask *cpumask, int vector) |
120 | { | 120 | { |
121 | unsigned long mask = cpus_addr(cpumask)[0]; | 121 | unsigned long mask = cpumask_bits(cpumask)[0]; |
122 | unsigned long flags; | 122 | unsigned long flags; |
123 | 123 | ||
124 | local_irq_save(flags); | 124 | local_irq_save(flags); |
125 | WARN_ON(mask & ~cpus_addr(cpu_online_map)[0]); | 125 | WARN_ON(mask & ~cpumask_bits(cpu_online_mask)[0]); |
126 | __send_IPI_dest_field(mask, vector); | 126 | __send_IPI_dest_field(mask, vector); |
127 | local_irq_restore(flags); | 127 | local_irq_restore(flags); |
128 | } | 128 | } |
129 | 129 | ||
130 | void send_IPI_mask_sequence(cpumask_t mask, int vector) | 130 | void send_IPI_mask_sequence(const struct cpumask *mask, int vector) |
131 | { | 131 | { |
132 | unsigned long flags; | 132 | unsigned long flags; |
133 | unsigned int query_cpu; | 133 | unsigned int query_cpu; |
@@ -139,12 +139,24 @@ void send_IPI_mask_sequence(cpumask_t mask, int vector) | |||
139 | */ | 139 | */ |
140 | 140 | ||
141 | local_irq_save(flags); | 141 | local_irq_save(flags); |
142 | for_each_possible_cpu(query_cpu) { | 142 | for_each_cpu(query_cpu, mask) |
143 | if (cpu_isset(query_cpu, mask)) { | 143 | __send_IPI_dest_field(cpu_to_logical_apicid(query_cpu), vector); |
144 | local_irq_restore(flags); | ||
145 | } | ||
146 | |||
147 | void send_IPI_mask_allbutself(const struct cpumask *mask, int vector) | ||
148 | { | ||
149 | unsigned long flags; | ||
150 | unsigned int query_cpu; | ||
151 | unsigned int this_cpu = smp_processor_id(); | ||
152 | |||
153 | /* See Hack comment above */ | ||
154 | |||
155 | local_irq_save(flags); | ||
156 | for_each_cpu(query_cpu, mask) | ||
157 | if (query_cpu != this_cpu) | ||
144 | __send_IPI_dest_field(cpu_to_logical_apicid(query_cpu), | 158 | __send_IPI_dest_field(cpu_to_logical_apicid(query_cpu), |
145 | vector); | 159 | vector); |
146 | } | ||
147 | } | ||
148 | local_irq_restore(flags); | 160 | local_irq_restore(flags); |
149 | } | 161 | } |
150 | 162 | ||
diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c index d1d4dc52f649..bce53e1352a0 100644 --- a/arch/x86/kernel/irq.c +++ b/arch/x86/kernel/irq.c | |||
@@ -9,6 +9,7 @@ | |||
9 | #include <asm/apic.h> | 9 | #include <asm/apic.h> |
10 | #include <asm/io_apic.h> | 10 | #include <asm/io_apic.h> |
11 | #include <asm/smp.h> | 11 | #include <asm/smp.h> |
12 | #include <asm/irq.h> | ||
12 | 13 | ||
13 | atomic_t irq_err_count; | 14 | atomic_t irq_err_count; |
14 | 15 | ||
@@ -118,6 +119,9 @@ int show_interrupts(struct seq_file *p, void *v) | |||
118 | } | 119 | } |
119 | 120 | ||
120 | desc = irq_to_desc(i); | 121 | desc = irq_to_desc(i); |
122 | if (!desc) | ||
123 | return 0; | ||
124 | |||
121 | spin_lock_irqsave(&desc->lock, flags); | 125 | spin_lock_irqsave(&desc->lock, flags); |
122 | #ifndef CONFIG_SMP | 126 | #ifndef CONFIG_SMP |
123 | any_count = kstat_irqs(i); | 127 | any_count = kstat_irqs(i); |
@@ -187,3 +191,5 @@ u64 arch_irq_stat(void) | |||
187 | #endif | 191 | #endif |
188 | return sum; | 192 | return sum; |
189 | } | 193 | } |
194 | |||
195 | EXPORT_SYMBOL_GPL(vector_used_by_percpu_irq); | ||
diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c index a51382672de0..9dc5588f336a 100644 --- a/arch/x86/kernel/irq_32.c +++ b/arch/x86/kernel/irq_32.c | |||
@@ -233,25 +233,28 @@ unsigned int do_IRQ(struct pt_regs *regs) | |||
233 | #ifdef CONFIG_HOTPLUG_CPU | 233 | #ifdef CONFIG_HOTPLUG_CPU |
234 | #include <mach_apic.h> | 234 | #include <mach_apic.h> |
235 | 235 | ||
236 | void fixup_irqs(cpumask_t map) | 236 | /* A cpu has been removed from cpu_online_mask. Reset irq affinities. */ |
237 | void fixup_irqs(void) | ||
237 | { | 238 | { |
238 | unsigned int irq; | 239 | unsigned int irq; |
239 | static int warned; | 240 | static int warned; |
240 | struct irq_desc *desc; | 241 | struct irq_desc *desc; |
241 | 242 | ||
242 | for_each_irq_desc(irq, desc) { | 243 | for_each_irq_desc(irq, desc) { |
243 | cpumask_t mask; | 244 | const struct cpumask *affinity; |
244 | 245 | ||
246 | if (!desc) | ||
247 | continue; | ||
245 | if (irq == 2) | 248 | if (irq == 2) |
246 | continue; | 249 | continue; |
247 | 250 | ||
248 | cpus_and(mask, desc->affinity, map); | 251 | affinity = &desc->affinity; |
249 | if (any_online_cpu(mask) == NR_CPUS) { | 252 | if (cpumask_any_and(affinity, cpu_online_mask) >= nr_cpu_ids) { |
250 | printk("Breaking affinity for irq %i\n", irq); | 253 | printk("Breaking affinity for irq %i\n", irq); |
251 | mask = map; | 254 | affinity = cpu_all_mask; |
252 | } | 255 | } |
253 | if (desc->chip->set_affinity) | 256 | if (desc->chip->set_affinity) |
254 | desc->chip->set_affinity(irq, mask); | 257 | desc->chip->set_affinity(irq, affinity); |
255 | else if (desc->action && !(warned++)) | 258 | else if (desc->action && !(warned++)) |
256 | printk("Cannot set affinity for irq %i\n", irq); | 259 | printk("Cannot set affinity for irq %i\n", irq); |
257 | } | 260 | } |
diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c index 60eb84eb77a0..6383d50f82ea 100644 --- a/arch/x86/kernel/irq_64.c +++ b/arch/x86/kernel/irq_64.c | |||
@@ -13,12 +13,12 @@ | |||
13 | #include <linux/seq_file.h> | 13 | #include <linux/seq_file.h> |
14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
15 | #include <linux/delay.h> | 15 | #include <linux/delay.h> |
16 | #include <linux/ftrace.h> | ||
16 | #include <asm/uaccess.h> | 17 | #include <asm/uaccess.h> |
17 | #include <asm/io_apic.h> | 18 | #include <asm/io_apic.h> |
18 | #include <asm/idle.h> | 19 | #include <asm/idle.h> |
19 | #include <asm/smp.h> | 20 | #include <asm/smp.h> |
20 | 21 | ||
21 | #ifdef CONFIG_DEBUG_STACKOVERFLOW | ||
22 | /* | 22 | /* |
23 | * Probabilistic stack overflow check: | 23 | * Probabilistic stack overflow check: |
24 | * | 24 | * |
@@ -28,26 +28,25 @@ | |||
28 | */ | 28 | */ |
29 | static inline void stack_overflow_check(struct pt_regs *regs) | 29 | static inline void stack_overflow_check(struct pt_regs *regs) |
30 | { | 30 | { |
31 | #ifdef CONFIG_DEBUG_STACKOVERFLOW | ||
31 | u64 curbase = (u64)task_stack_page(current); | 32 | u64 curbase = (u64)task_stack_page(current); |
32 | static unsigned long warned = -60*HZ; | 33 | |
33 | 34 | WARN_ONCE(regs->sp >= curbase && | |
34 | if (regs->sp >= curbase && regs->sp <= curbase + THREAD_SIZE && | 35 | regs->sp <= curbase + THREAD_SIZE && |
35 | regs->sp < curbase + sizeof(struct thread_info) + 128 && | 36 | regs->sp < curbase + sizeof(struct thread_info) + |
36 | time_after(jiffies, warned + 60*HZ)) { | 37 | sizeof(struct pt_regs) + 128, |
37 | printk("do_IRQ: %s near stack overflow (cur:%Lx,sp:%lx)\n", | 38 | |
38 | current->comm, curbase, regs->sp); | 39 | "do_IRQ: %s near stack overflow (cur:%Lx,sp:%lx)\n", |
39 | show_stack(NULL,NULL); | 40 | current->comm, curbase, regs->sp); |
40 | warned = jiffies; | ||
41 | } | ||
42 | } | ||
43 | #endif | 41 | #endif |
42 | } | ||
44 | 43 | ||
45 | /* | 44 | /* |
46 | * do_IRQ handles all normal device IRQ's (the special | 45 | * do_IRQ handles all normal device IRQ's (the special |
47 | * SMP cross-CPU interrupts have their own specific | 46 | * SMP cross-CPU interrupts have their own specific |
48 | * handlers). | 47 | * handlers). |
49 | */ | 48 | */ |
50 | asmlinkage unsigned int do_IRQ(struct pt_regs *regs) | 49 | asmlinkage unsigned int __irq_entry do_IRQ(struct pt_regs *regs) |
51 | { | 50 | { |
52 | struct pt_regs *old_regs = set_irq_regs(regs); | 51 | struct pt_regs *old_regs = set_irq_regs(regs); |
53 | struct irq_desc *desc; | 52 | struct irq_desc *desc; |
@@ -60,9 +59,7 @@ asmlinkage unsigned int do_IRQ(struct pt_regs *regs) | |||
60 | irq_enter(); | 59 | irq_enter(); |
61 | irq = __get_cpu_var(vector_irq)[vector]; | 60 | irq = __get_cpu_var(vector_irq)[vector]; |
62 | 61 | ||
63 | #ifdef CONFIG_DEBUG_STACKOVERFLOW | ||
64 | stack_overflow_check(regs); | 62 | stack_overflow_check(regs); |
65 | #endif | ||
66 | 63 | ||
67 | desc = irq_to_desc(irq); | 64 | desc = irq_to_desc(irq); |
68 | if (likely(desc)) | 65 | if (likely(desc)) |
@@ -83,40 +80,43 @@ asmlinkage unsigned int do_IRQ(struct pt_regs *regs) | |||
83 | } | 80 | } |
84 | 81 | ||
85 | #ifdef CONFIG_HOTPLUG_CPU | 82 | #ifdef CONFIG_HOTPLUG_CPU |
86 | void fixup_irqs(cpumask_t map) | 83 | /* A cpu has been removed from cpu_online_mask. Reset irq affinities. */ |
84 | void fixup_irqs(void) | ||
87 | { | 85 | { |
88 | unsigned int irq; | 86 | unsigned int irq; |
89 | static int warned; | 87 | static int warned; |
90 | struct irq_desc *desc; | 88 | struct irq_desc *desc; |
91 | 89 | ||
92 | for_each_irq_desc(irq, desc) { | 90 | for_each_irq_desc(irq, desc) { |
93 | cpumask_t mask; | ||
94 | int break_affinity = 0; | 91 | int break_affinity = 0; |
95 | int set_affinity = 1; | 92 | int set_affinity = 1; |
93 | const struct cpumask *affinity; | ||
96 | 94 | ||
95 | if (!desc) | ||
96 | continue; | ||
97 | if (irq == 2) | 97 | if (irq == 2) |
98 | continue; | 98 | continue; |
99 | 99 | ||
100 | /* interrupt's are disabled at this point */ | 100 | /* interrupt's are disabled at this point */ |
101 | spin_lock(&desc->lock); | 101 | spin_lock(&desc->lock); |
102 | 102 | ||
103 | affinity = &desc->affinity; | ||
103 | if (!irq_has_action(irq) || | 104 | if (!irq_has_action(irq) || |
104 | cpus_equal(desc->affinity, map)) { | 105 | cpumask_equal(affinity, cpu_online_mask)) { |
105 | spin_unlock(&desc->lock); | 106 | spin_unlock(&desc->lock); |
106 | continue; | 107 | continue; |
107 | } | 108 | } |
108 | 109 | ||
109 | cpus_and(mask, desc->affinity, map); | 110 | if (cpumask_any_and(affinity, cpu_online_mask) >= nr_cpu_ids) { |
110 | if (cpus_empty(mask)) { | ||
111 | break_affinity = 1; | 111 | break_affinity = 1; |
112 | mask = map; | 112 | affinity = cpu_all_mask; |
113 | } | 113 | } |
114 | 114 | ||
115 | if (desc->chip->mask) | 115 | if (desc->chip->mask) |
116 | desc->chip->mask(irq); | 116 | desc->chip->mask(irq); |
117 | 117 | ||
118 | if (desc->chip->set_affinity) | 118 | if (desc->chip->set_affinity) |
119 | desc->chip->set_affinity(irq, mask); | 119 | desc->chip->set_affinity(irq, affinity); |
120 | else if (!(warned++)) | 120 | else if (!(warned++)) |
121 | set_affinity = 0; | 121 | set_affinity = 0; |
122 | 122 | ||
diff --git a/arch/x86/kernel/irqinit_32.c b/arch/x86/kernel/irqinit_32.c index 845aa9803e80..84723295f88a 100644 --- a/arch/x86/kernel/irqinit_32.c +++ b/arch/x86/kernel/irqinit_32.c | |||
@@ -68,8 +68,7 @@ void __init init_ISA_irqs (void) | |||
68 | /* | 68 | /* |
69 | * 16 old-style INTA-cycle interrupts: | 69 | * 16 old-style INTA-cycle interrupts: |
70 | */ | 70 | */ |
71 | for (i = 0; i < 16; i++) { | 71 | for (i = 0; i < NR_IRQS_LEGACY; i++) { |
72 | /* first time call this irq_desc */ | ||
73 | struct irq_desc *desc = irq_to_desc(i); | 72 | struct irq_desc *desc = irq_to_desc(i); |
74 | 73 | ||
75 | desc->status = IRQ_DISABLED; | 74 | desc->status = IRQ_DISABLED; |
@@ -111,6 +110,18 @@ DEFINE_PER_CPU(vector_irq_t, vector_irq) = { | |||
111 | [IRQ15_VECTOR + 1 ... NR_VECTORS - 1] = -1 | 110 | [IRQ15_VECTOR + 1 ... NR_VECTORS - 1] = -1 |
112 | }; | 111 | }; |
113 | 112 | ||
113 | int vector_used_by_percpu_irq(unsigned int vector) | ||
114 | { | ||
115 | int cpu; | ||
116 | |||
117 | for_each_online_cpu(cpu) { | ||
118 | if (per_cpu(vector_irq, cpu)[vector] != -1) | ||
119 | return 1; | ||
120 | } | ||
121 | |||
122 | return 0; | ||
123 | } | ||
124 | |||
114 | /* Overridden in paravirt.c */ | 125 | /* Overridden in paravirt.c */ |
115 | void init_IRQ(void) __attribute__((weak, alias("native_init_IRQ"))); | 126 | void init_IRQ(void) __attribute__((weak, alias("native_init_IRQ"))); |
116 | 127 | ||
@@ -129,7 +140,7 @@ void __init native_init_IRQ(void) | |||
129 | for (i = FIRST_EXTERNAL_VECTOR; i < NR_VECTORS; i++) { | 140 | for (i = FIRST_EXTERNAL_VECTOR; i < NR_VECTORS; i++) { |
130 | /* SYSCALL_VECTOR was reserved in trap_init. */ | 141 | /* SYSCALL_VECTOR was reserved in trap_init. */ |
131 | if (i != SYSCALL_VECTOR) | 142 | if (i != SYSCALL_VECTOR) |
132 | set_intr_gate(i, interrupt[i]); | 143 | set_intr_gate(i, interrupt[i-FIRST_EXTERNAL_VECTOR]); |
133 | } | 144 | } |
134 | 145 | ||
135 | 146 | ||
@@ -147,10 +158,12 @@ void __init native_init_IRQ(void) | |||
147 | alloc_intr_gate(CALL_FUNCTION_VECTOR, call_function_interrupt); | 158 | alloc_intr_gate(CALL_FUNCTION_VECTOR, call_function_interrupt); |
148 | 159 | ||
149 | /* IPI for single call function */ | 160 | /* IPI for single call function */ |
150 | set_intr_gate(CALL_FUNCTION_SINGLE_VECTOR, call_function_single_interrupt); | 161 | alloc_intr_gate(CALL_FUNCTION_SINGLE_VECTOR, |
162 | call_function_single_interrupt); | ||
151 | 163 | ||
152 | /* Low priority IPI to cleanup after moving an irq */ | 164 | /* Low priority IPI to cleanup after moving an irq */ |
153 | set_intr_gate(IRQ_MOVE_CLEANUP_VECTOR, irq_move_cleanup_interrupt); | 165 | set_intr_gate(IRQ_MOVE_CLEANUP_VECTOR, irq_move_cleanup_interrupt); |
166 | set_bit(IRQ_MOVE_CLEANUP_VECTOR, used_vectors); | ||
154 | #endif | 167 | #endif |
155 | 168 | ||
156 | #ifdef CONFIG_X86_LOCAL_APIC | 169 | #ifdef CONFIG_X86_LOCAL_APIC |
diff --git a/arch/x86/kernel/irqinit_64.c b/arch/x86/kernel/irqinit_64.c index ff0235391285..31ebfe38e96c 100644 --- a/arch/x86/kernel/irqinit_64.c +++ b/arch/x86/kernel/irqinit_64.c | |||
@@ -24,41 +24,6 @@ | |||
24 | #include <asm/i8259.h> | 24 | #include <asm/i8259.h> |
25 | 25 | ||
26 | /* | 26 | /* |
27 | * Common place to define all x86 IRQ vectors | ||
28 | * | ||
29 | * This builds up the IRQ handler stubs using some ugly macros in irq.h | ||
30 | * | ||
31 | * These macros create the low-level assembly IRQ routines that save | ||
32 | * register context and call do_IRQ(). do_IRQ() then does all the | ||
33 | * operations that are needed to keep the AT (or SMP IOAPIC) | ||
34 | * interrupt-controller happy. | ||
35 | */ | ||
36 | |||
37 | #define IRQ_NAME2(nr) nr##_interrupt(void) | ||
38 | #define IRQ_NAME(nr) IRQ_NAME2(IRQ##nr) | ||
39 | |||
40 | /* | ||
41 | * SMP has a few special interrupts for IPI messages | ||
42 | */ | ||
43 | |||
44 | #define BUILD_IRQ(nr) \ | ||
45 | asmlinkage void IRQ_NAME(nr); \ | ||
46 | asm("\n.text\n.p2align\n" \ | ||
47 | "IRQ" #nr "_interrupt:\n\t" \ | ||
48 | "push $~(" #nr ") ; " \ | ||
49 | "jmp common_interrupt\n" \ | ||
50 | ".previous"); | ||
51 | |||
52 | #define BI(x,y) \ | ||
53 | BUILD_IRQ(x##y) | ||
54 | |||
55 | #define BUILD_16_IRQS(x) \ | ||
56 | BI(x,0) BI(x,1) BI(x,2) BI(x,3) \ | ||
57 | BI(x,4) BI(x,5) BI(x,6) BI(x,7) \ | ||
58 | BI(x,8) BI(x,9) BI(x,a) BI(x,b) \ | ||
59 | BI(x,c) BI(x,d) BI(x,e) BI(x,f) | ||
60 | |||
61 | /* | ||
62 | * ISA PIC or low IO-APIC triggered (INTA-cycle or APIC) interrupts: | 27 | * ISA PIC or low IO-APIC triggered (INTA-cycle or APIC) interrupts: |
63 | * (these are usually mapped to vectors 0x30-0x3f) | 28 | * (these are usually mapped to vectors 0x30-0x3f) |
64 | */ | 29 | */ |
@@ -73,37 +38,6 @@ | |||
73 | * | 38 | * |
74 | * (these are usually mapped into the 0x30-0xff vector range) | 39 | * (these are usually mapped into the 0x30-0xff vector range) |
75 | */ | 40 | */ |
76 | BUILD_16_IRQS(0x2) BUILD_16_IRQS(0x3) | ||
77 | BUILD_16_IRQS(0x4) BUILD_16_IRQS(0x5) BUILD_16_IRQS(0x6) BUILD_16_IRQS(0x7) | ||
78 | BUILD_16_IRQS(0x8) BUILD_16_IRQS(0x9) BUILD_16_IRQS(0xa) BUILD_16_IRQS(0xb) | ||
79 | BUILD_16_IRQS(0xc) BUILD_16_IRQS(0xd) BUILD_16_IRQS(0xe) BUILD_16_IRQS(0xf) | ||
80 | |||
81 | #undef BUILD_16_IRQS | ||
82 | #undef BI | ||
83 | |||
84 | |||
85 | #define IRQ(x,y) \ | ||
86 | IRQ##x##y##_interrupt | ||
87 | |||
88 | #define IRQLIST_16(x) \ | ||
89 | IRQ(x,0), IRQ(x,1), IRQ(x,2), IRQ(x,3), \ | ||
90 | IRQ(x,4), IRQ(x,5), IRQ(x,6), IRQ(x,7), \ | ||
91 | IRQ(x,8), IRQ(x,9), IRQ(x,a), IRQ(x,b), \ | ||
92 | IRQ(x,c), IRQ(x,d), IRQ(x,e), IRQ(x,f) | ||
93 | |||
94 | /* for the irq vectors */ | ||
95 | static void (*__initdata interrupt[NR_VECTORS - FIRST_EXTERNAL_VECTOR])(void) = { | ||
96 | IRQLIST_16(0x2), IRQLIST_16(0x3), | ||
97 | IRQLIST_16(0x4), IRQLIST_16(0x5), IRQLIST_16(0x6), IRQLIST_16(0x7), | ||
98 | IRQLIST_16(0x8), IRQLIST_16(0x9), IRQLIST_16(0xa), IRQLIST_16(0xb), | ||
99 | IRQLIST_16(0xc), IRQLIST_16(0xd), IRQLIST_16(0xe), IRQLIST_16(0xf) | ||
100 | }; | ||
101 | |||
102 | #undef IRQ | ||
103 | #undef IRQLIST_16 | ||
104 | |||
105 | |||
106 | |||
107 | 41 | ||
108 | /* | 42 | /* |
109 | * IRQ2 is cascade interrupt to second interrupt controller | 43 | * IRQ2 is cascade interrupt to second interrupt controller |
@@ -135,6 +69,18 @@ DEFINE_PER_CPU(vector_irq_t, vector_irq) = { | |||
135 | [IRQ15_VECTOR + 1 ... NR_VECTORS - 1] = -1 | 69 | [IRQ15_VECTOR + 1 ... NR_VECTORS - 1] = -1 |
136 | }; | 70 | }; |
137 | 71 | ||
72 | int vector_used_by_percpu_irq(unsigned int vector) | ||
73 | { | ||
74 | int cpu; | ||
75 | |||
76 | for_each_online_cpu(cpu) { | ||
77 | if (per_cpu(vector_irq, cpu)[vector] != -1) | ||
78 | return 1; | ||
79 | } | ||
80 | |||
81 | return 0; | ||
82 | } | ||
83 | |||
138 | void __init init_ISA_irqs(void) | 84 | void __init init_ISA_irqs(void) |
139 | { | 85 | { |
140 | int i; | 86 | int i; |
@@ -142,8 +88,7 @@ void __init init_ISA_irqs(void) | |||
142 | init_bsp_APIC(); | 88 | init_bsp_APIC(); |
143 | init_8259A(0); | 89 | init_8259A(0); |
144 | 90 | ||
145 | for (i = 0; i < 16; i++) { | 91 | for (i = 0; i < NR_IRQS_LEGACY; i++) { |
146 | /* first time call this irq_desc */ | ||
147 | struct irq_desc *desc = irq_to_desc(i); | 92 | struct irq_desc *desc = irq_to_desc(i); |
148 | 93 | ||
149 | desc->status = IRQ_DISABLED; | 94 | desc->status = IRQ_DISABLED; |
@@ -188,6 +133,7 @@ static void __init smp_intr_init(void) | |||
188 | 133 | ||
189 | /* Low priority IPI to cleanup after moving an irq */ | 134 | /* Low priority IPI to cleanup after moving an irq */ |
190 | set_intr_gate(IRQ_MOVE_CLEANUP_VECTOR, irq_move_cleanup_interrupt); | 135 | set_intr_gate(IRQ_MOVE_CLEANUP_VECTOR, irq_move_cleanup_interrupt); |
136 | set_bit(IRQ_MOVE_CLEANUP_VECTOR, used_vectors); | ||
191 | #endif | 137 | #endif |
192 | } | 138 | } |
193 | 139 | ||
diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c index 6c27679ec6aa..884d985b8b82 100644 --- a/arch/x86/kernel/kprobes.c +++ b/arch/x86/kernel/kprobes.c | |||
@@ -376,9 +376,10 @@ void __kprobes arch_disarm_kprobe(struct kprobe *p) | |||
376 | 376 | ||
377 | void __kprobes arch_remove_kprobe(struct kprobe *p) | 377 | void __kprobes arch_remove_kprobe(struct kprobe *p) |
378 | { | 378 | { |
379 | mutex_lock(&kprobe_mutex); | 379 | if (p->ainsn.insn) { |
380 | free_insn_slot(p->ainsn.insn, (p->ainsn.boostable == 1)); | 380 | free_insn_slot(p->ainsn.insn, (p->ainsn.boostable == 1)); |
381 | mutex_unlock(&kprobe_mutex); | 381 | p->ainsn.insn = NULL; |
382 | } | ||
382 | } | 383 | } |
383 | 384 | ||
384 | static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb) | 385 | static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb) |
@@ -694,7 +695,7 @@ static __used __kprobes void *trampoline_handler(struct pt_regs *regs) | |||
694 | /* | 695 | /* |
695 | * It is possible to have multiple instances associated with a given | 696 | * It is possible to have multiple instances associated with a given |
696 | * task either because multiple functions in the call path have | 697 | * task either because multiple functions in the call path have |
697 | * return probes installed on them, and/or more then one | 698 | * return probes installed on them, and/or more than one |
698 | * return probe was registered for a target function. | 699 | * return probe was registered for a target function. |
699 | * | 700 | * |
700 | * We can handle this because: | 701 | * We can handle this because: |
diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c index e169ae9b6a62..652fce6d2cce 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c | |||
@@ -89,17 +89,17 @@ static cycle_t kvm_clock_read(void) | |||
89 | */ | 89 | */ |
90 | static unsigned long kvm_get_tsc_khz(void) | 90 | static unsigned long kvm_get_tsc_khz(void) |
91 | { | 91 | { |
92 | return preset_lpj; | 92 | struct pvclock_vcpu_time_info *src; |
93 | src = &per_cpu(hv_clock, 0); | ||
94 | return pvclock_tsc_khz(src); | ||
93 | } | 95 | } |
94 | 96 | ||
95 | static void kvm_get_preset_lpj(void) | 97 | static void kvm_get_preset_lpj(void) |
96 | { | 98 | { |
97 | struct pvclock_vcpu_time_info *src; | ||
98 | unsigned long khz; | 99 | unsigned long khz; |
99 | u64 lpj; | 100 | u64 lpj; |
100 | 101 | ||
101 | src = &per_cpu(hv_clock, 0); | 102 | khz = kvm_get_tsc_khz(); |
102 | khz = pvclock_tsc_khz(src); | ||
103 | 103 | ||
104 | lpj = ((u64)khz * 1000); | 104 | lpj = ((u64)khz * 1000); |
105 | do_div(lpj, HZ); | 105 | do_div(lpj, HZ); |
@@ -194,5 +194,7 @@ void __init kvmclock_init(void) | |||
194 | #endif | 194 | #endif |
195 | kvm_get_preset_lpj(); | 195 | kvm_get_preset_lpj(); |
196 | clocksource_register(&kvm_clock); | 196 | clocksource_register(&kvm_clock); |
197 | pv_info.paravirt_enabled = 1; | ||
198 | pv_info.name = "KVM"; | ||
197 | } | 199 | } |
198 | } | 200 | } |
diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c index eee32b43fee3..71f1d99a635d 100644 --- a/arch/x86/kernel/ldt.c +++ b/arch/x86/kernel/ldt.c | |||
@@ -12,8 +12,8 @@ | |||
12 | #include <linux/mm.h> | 12 | #include <linux/mm.h> |
13 | #include <linux/smp.h> | 13 | #include <linux/smp.h> |
14 | #include <linux/vmalloc.h> | 14 | #include <linux/vmalloc.h> |
15 | #include <linux/uaccess.h> | ||
15 | 16 | ||
16 | #include <asm/uaccess.h> | ||
17 | #include <asm/system.h> | 17 | #include <asm/system.h> |
18 | #include <asm/ldt.h> | 18 | #include <asm/ldt.h> |
19 | #include <asm/desc.h> | 19 | #include <asm/desc.h> |
@@ -93,7 +93,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old) | |||
93 | if (err < 0) | 93 | if (err < 0) |
94 | return err; | 94 | return err; |
95 | 95 | ||
96 | for(i = 0; i < old->size; i++) | 96 | for (i = 0; i < old->size; i++) |
97 | write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE); | 97 | write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE); |
98 | return 0; | 98 | return 0; |
99 | } | 99 | } |
diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c index 7a385746509a..37f420018a41 100644 --- a/arch/x86/kernel/machine_kexec_32.c +++ b/arch/x86/kernel/machine_kexec_32.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/numa.h> | 13 | #include <linux/numa.h> |
14 | #include <linux/ftrace.h> | 14 | #include <linux/ftrace.h> |
15 | #include <linux/suspend.h> | 15 | #include <linux/suspend.h> |
16 | #include <linux/gfp.h> | ||
16 | 17 | ||
17 | #include <asm/pgtable.h> | 18 | #include <asm/pgtable.h> |
18 | #include <asm/pgalloc.h> | 19 | #include <asm/pgalloc.h> |
@@ -25,15 +26,6 @@ | |||
25 | #include <asm/system.h> | 26 | #include <asm/system.h> |
26 | #include <asm/cacheflush.h> | 27 | #include <asm/cacheflush.h> |
27 | 28 | ||
28 | #define PAGE_ALIGNED __attribute__ ((__aligned__(PAGE_SIZE))) | ||
29 | static u32 kexec_pgd[1024] PAGE_ALIGNED; | ||
30 | #ifdef CONFIG_X86_PAE | ||
31 | static u32 kexec_pmd0[1024] PAGE_ALIGNED; | ||
32 | static u32 kexec_pmd1[1024] PAGE_ALIGNED; | ||
33 | #endif | ||
34 | static u32 kexec_pte0[1024] PAGE_ALIGNED; | ||
35 | static u32 kexec_pte1[1024] PAGE_ALIGNED; | ||
36 | |||
37 | static void set_idt(void *newidt, __u16 limit) | 29 | static void set_idt(void *newidt, __u16 limit) |
38 | { | 30 | { |
39 | struct desc_ptr curidt; | 31 | struct desc_ptr curidt; |
@@ -76,6 +68,76 @@ static void load_segments(void) | |||
76 | #undef __STR | 68 | #undef __STR |
77 | } | 69 | } |
78 | 70 | ||
71 | static void machine_kexec_free_page_tables(struct kimage *image) | ||
72 | { | ||
73 | free_page((unsigned long)image->arch.pgd); | ||
74 | #ifdef CONFIG_X86_PAE | ||
75 | free_page((unsigned long)image->arch.pmd0); | ||
76 | free_page((unsigned long)image->arch.pmd1); | ||
77 | #endif | ||
78 | free_page((unsigned long)image->arch.pte0); | ||
79 | free_page((unsigned long)image->arch.pte1); | ||
80 | } | ||
81 | |||
82 | static int machine_kexec_alloc_page_tables(struct kimage *image) | ||
83 | { | ||
84 | image->arch.pgd = (pgd_t *)get_zeroed_page(GFP_KERNEL); | ||
85 | #ifdef CONFIG_X86_PAE | ||
86 | image->arch.pmd0 = (pmd_t *)get_zeroed_page(GFP_KERNEL); | ||
87 | image->arch.pmd1 = (pmd_t *)get_zeroed_page(GFP_KERNEL); | ||
88 | #endif | ||
89 | image->arch.pte0 = (pte_t *)get_zeroed_page(GFP_KERNEL); | ||
90 | image->arch.pte1 = (pte_t *)get_zeroed_page(GFP_KERNEL); | ||
91 | if (!image->arch.pgd || | ||
92 | #ifdef CONFIG_X86_PAE | ||
93 | !image->arch.pmd0 || !image->arch.pmd1 || | ||
94 | #endif | ||
95 | !image->arch.pte0 || !image->arch.pte1) { | ||
96 | machine_kexec_free_page_tables(image); | ||
97 | return -ENOMEM; | ||
98 | } | ||
99 | return 0; | ||
100 | } | ||
101 | |||
102 | static void machine_kexec_page_table_set_one( | ||
103 | pgd_t *pgd, pmd_t *pmd, pte_t *pte, | ||
104 | unsigned long vaddr, unsigned long paddr) | ||
105 | { | ||
106 | pud_t *pud; | ||
107 | |||
108 | pgd += pgd_index(vaddr); | ||
109 | #ifdef CONFIG_X86_PAE | ||
110 | if (!(pgd_val(*pgd) & _PAGE_PRESENT)) | ||
111 | set_pgd(pgd, __pgd(__pa(pmd) | _PAGE_PRESENT)); | ||
112 | #endif | ||
113 | pud = pud_offset(pgd, vaddr); | ||
114 | pmd = pmd_offset(pud, vaddr); | ||
115 | if (!(pmd_val(*pmd) & _PAGE_PRESENT)) | ||
116 | set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE)); | ||
117 | pte = pte_offset_kernel(pmd, vaddr); | ||
118 | set_pte(pte, pfn_pte(paddr >> PAGE_SHIFT, PAGE_KERNEL_EXEC)); | ||
119 | } | ||
120 | |||
121 | static void machine_kexec_prepare_page_tables(struct kimage *image) | ||
122 | { | ||
123 | void *control_page; | ||
124 | pmd_t *pmd = 0; | ||
125 | |||
126 | control_page = page_address(image->control_code_page); | ||
127 | #ifdef CONFIG_X86_PAE | ||
128 | pmd = image->arch.pmd0; | ||
129 | #endif | ||
130 | machine_kexec_page_table_set_one( | ||
131 | image->arch.pgd, pmd, image->arch.pte0, | ||
132 | (unsigned long)control_page, __pa(control_page)); | ||
133 | #ifdef CONFIG_X86_PAE | ||
134 | pmd = image->arch.pmd1; | ||
135 | #endif | ||
136 | machine_kexec_page_table_set_one( | ||
137 | image->arch.pgd, pmd, image->arch.pte1, | ||
138 | __pa(control_page), __pa(control_page)); | ||
139 | } | ||
140 | |||
79 | /* | 141 | /* |
80 | * A architecture hook called to validate the | 142 | * A architecture hook called to validate the |
81 | * proposed image and prepare the control pages | 143 | * proposed image and prepare the control pages |
@@ -87,12 +149,20 @@ static void load_segments(void) | |||
87 | * reboot code buffer to allow us to avoid allocations | 149 | * reboot code buffer to allow us to avoid allocations |
88 | * later. | 150 | * later. |
89 | * | 151 | * |
90 | * Make control page executable. | 152 | * - Make control page executable. |
153 | * - Allocate page tables | ||
154 | * - Setup page tables | ||
91 | */ | 155 | */ |
92 | int machine_kexec_prepare(struct kimage *image) | 156 | int machine_kexec_prepare(struct kimage *image) |
93 | { | 157 | { |
158 | int error; | ||
159 | |||
94 | if (nx_enabled) | 160 | if (nx_enabled) |
95 | set_pages_x(image->control_code_page, 1); | 161 | set_pages_x(image->control_code_page, 1); |
162 | error = machine_kexec_alloc_page_tables(image); | ||
163 | if (error) | ||
164 | return error; | ||
165 | machine_kexec_prepare_page_tables(image); | ||
96 | return 0; | 166 | return 0; |
97 | } | 167 | } |
98 | 168 | ||
@@ -104,6 +174,7 @@ void machine_kexec_cleanup(struct kimage *image) | |||
104 | { | 174 | { |
105 | if (nx_enabled) | 175 | if (nx_enabled) |
106 | set_pages_nx(image->control_code_page, 1); | 176 | set_pages_nx(image->control_code_page, 1); |
177 | machine_kexec_free_page_tables(image); | ||
107 | } | 178 | } |
108 | 179 | ||
109 | /* | 180 | /* |
@@ -150,18 +221,7 @@ void machine_kexec(struct kimage *image) | |||
150 | relocate_kernel_ptr = control_page; | 221 | relocate_kernel_ptr = control_page; |
151 | page_list[PA_CONTROL_PAGE] = __pa(control_page); | 222 | page_list[PA_CONTROL_PAGE] = __pa(control_page); |
152 | page_list[VA_CONTROL_PAGE] = (unsigned long)control_page; | 223 | page_list[VA_CONTROL_PAGE] = (unsigned long)control_page; |
153 | page_list[PA_PGD] = __pa(kexec_pgd); | 224 | page_list[PA_PGD] = __pa(image->arch.pgd); |
154 | page_list[VA_PGD] = (unsigned long)kexec_pgd; | ||
155 | #ifdef CONFIG_X86_PAE | ||
156 | page_list[PA_PMD_0] = __pa(kexec_pmd0); | ||
157 | page_list[VA_PMD_0] = (unsigned long)kexec_pmd0; | ||
158 | page_list[PA_PMD_1] = __pa(kexec_pmd1); | ||
159 | page_list[VA_PMD_1] = (unsigned long)kexec_pmd1; | ||
160 | #endif | ||
161 | page_list[PA_PTE_0] = __pa(kexec_pte0); | ||
162 | page_list[VA_PTE_0] = (unsigned long)kexec_pte0; | ||
163 | page_list[PA_PTE_1] = __pa(kexec_pte1); | ||
164 | page_list[VA_PTE_1] = (unsigned long)kexec_pte1; | ||
165 | 225 | ||
166 | if (image->type == KEXEC_TYPE_DEFAULT) | 226 | if (image->type == KEXEC_TYPE_DEFAULT) |
167 | page_list[PA_SWAP_PAGE] = (page_to_pfn(image->swap_page) | 227 | page_list[PA_SWAP_PAGE] = (page_to_pfn(image->swap_page) |
diff --git a/arch/x86/kernel/mfgpt_32.c b/arch/x86/kernel/mfgpt_32.c index 3b599518c322..8815f3c7fec7 100644 --- a/arch/x86/kernel/mfgpt_32.c +++ b/arch/x86/kernel/mfgpt_32.c | |||
@@ -252,7 +252,7 @@ EXPORT_SYMBOL_GPL(geode_mfgpt_alloc_timer); | |||
252 | /* | 252 | /* |
253 | * The MFPGT timers on the CS5536 provide us with suitable timers to use | 253 | * The MFPGT timers on the CS5536 provide us with suitable timers to use |
254 | * as clock event sources - not as good as a HPET or APIC, but certainly | 254 | * as clock event sources - not as good as a HPET or APIC, but certainly |
255 | * better then the PIT. This isn't a general purpose MFGPT driver, but | 255 | * better than the PIT. This isn't a general purpose MFGPT driver, but |
256 | * a simplified one designed specifically to act as a clock event source. | 256 | * a simplified one designed specifically to act as a clock event source. |
257 | * For full details about the MFGPT, please consult the CS5536 data sheet. | 257 | * For full details about the MFGPT, please consult the CS5536 data sheet. |
258 | */ | 258 | */ |
@@ -287,7 +287,7 @@ static struct clock_event_device mfgpt_clockevent = { | |||
287 | .set_mode = mfgpt_set_mode, | 287 | .set_mode = mfgpt_set_mode, |
288 | .set_next_event = mfgpt_next_event, | 288 | .set_next_event = mfgpt_next_event, |
289 | .rating = 250, | 289 | .rating = 250, |
290 | .cpumask = CPU_MASK_ALL, | 290 | .cpumask = cpu_all_mask, |
291 | .shift = 32 | 291 | .shift = 32 |
292 | }; | 292 | }; |
293 | 293 | ||
diff --git a/arch/x86/kernel/microcode_amd.c b/arch/x86/kernel/microcode_amd.c index 5f8e5d75a254..c25fdb382292 100644 --- a/arch/x86/kernel/microcode_amd.c +++ b/arch/x86/kernel/microcode_amd.c | |||
@@ -10,7 +10,7 @@ | |||
10 | * This driver allows to upgrade microcode on AMD | 10 | * This driver allows to upgrade microcode on AMD |
11 | * family 0x10 and 0x11 processors. | 11 | * family 0x10 and 0x11 processors. |
12 | * | 12 | * |
13 | * Licensed unter the terms of the GNU General Public | 13 | * Licensed under the terms of the GNU General Public |
14 | * License version 2. See file COPYING for details. | 14 | * License version 2. See file COPYING for details. |
15 | */ | 15 | */ |
16 | 16 | ||
@@ -32,9 +32,9 @@ | |||
32 | #include <linux/platform_device.h> | 32 | #include <linux/platform_device.h> |
33 | #include <linux/pci.h> | 33 | #include <linux/pci.h> |
34 | #include <linux/pci_ids.h> | 34 | #include <linux/pci_ids.h> |
35 | #include <linux/uaccess.h> | ||
35 | 36 | ||
36 | #include <asm/msr.h> | 37 | #include <asm/msr.h> |
37 | #include <asm/uaccess.h> | ||
38 | #include <asm/processor.h> | 38 | #include <asm/processor.h> |
39 | #include <asm/microcode.h> | 39 | #include <asm/microcode.h> |
40 | 40 | ||
@@ -47,43 +47,38 @@ MODULE_LICENSE("GPL v2"); | |||
47 | #define UCODE_UCODE_TYPE 0x00000001 | 47 | #define UCODE_UCODE_TYPE 0x00000001 |
48 | 48 | ||
49 | struct equiv_cpu_entry { | 49 | struct equiv_cpu_entry { |
50 | unsigned int installed_cpu; | 50 | u32 installed_cpu; |
51 | unsigned int fixed_errata_mask; | 51 | u32 fixed_errata_mask; |
52 | unsigned int fixed_errata_compare; | 52 | u32 fixed_errata_compare; |
53 | unsigned int equiv_cpu; | 53 | u16 equiv_cpu; |
54 | }; | 54 | u16 res; |
55 | } __attribute__((packed)); | ||
55 | 56 | ||
56 | struct microcode_header_amd { | 57 | struct microcode_header_amd { |
57 | unsigned int data_code; | 58 | u32 data_code; |
58 | unsigned int patch_id; | 59 | u32 patch_id; |
59 | unsigned char mc_patch_data_id[2]; | 60 | u16 mc_patch_data_id; |
60 | unsigned char mc_patch_data_len; | 61 | u8 mc_patch_data_len; |
61 | unsigned char init_flag; | 62 | u8 init_flag; |
62 | unsigned int mc_patch_data_checksum; | 63 | u32 mc_patch_data_checksum; |
63 | unsigned int nb_dev_id; | 64 | u32 nb_dev_id; |
64 | unsigned int sb_dev_id; | 65 | u32 sb_dev_id; |
65 | unsigned char processor_rev_id[2]; | 66 | u16 processor_rev_id; |
66 | unsigned char nb_rev_id; | 67 | u8 nb_rev_id; |
67 | unsigned char sb_rev_id; | 68 | u8 sb_rev_id; |
68 | unsigned char bios_api_rev; | 69 | u8 bios_api_rev; |
69 | unsigned char reserved1[3]; | 70 | u8 reserved1[3]; |
70 | unsigned int match_reg[8]; | 71 | u32 match_reg[8]; |
71 | }; | 72 | } __attribute__((packed)); |
72 | 73 | ||
73 | struct microcode_amd { | 74 | struct microcode_amd { |
74 | struct microcode_header_amd hdr; | 75 | struct microcode_header_amd hdr; |
75 | unsigned int mpb[0]; | 76 | unsigned int mpb[0]; |
76 | }; | 77 | }; |
77 | 78 | ||
78 | #define UCODE_MAX_SIZE (2048) | 79 | #define UCODE_MAX_SIZE 2048 |
79 | #define DEFAULT_UCODE_DATASIZE (896) | 80 | #define UCODE_CONTAINER_SECTION_HDR 8 |
80 | #define MC_HEADER_SIZE (sizeof(struct microcode_header_amd)) | 81 | #define UCODE_CONTAINER_HEADER_SIZE 12 |
81 | #define DEFAULT_UCODE_TOTALSIZE (DEFAULT_UCODE_DATASIZE + MC_HEADER_SIZE) | ||
82 | #define DWSIZE (sizeof(u32)) | ||
83 | /* For now we support a fixed ucode total size only */ | ||
84 | #define get_totalsize(mc) \ | ||
85 | ((((struct microcode_amd *)mc)->hdr.mc_patch_data_len * 28) \ | ||
86 | + MC_HEADER_SIZE) | ||
87 | 82 | ||
88 | /* serialize access to the physical write */ | 83 | /* serialize access to the physical write */ |
89 | static DEFINE_SPINLOCK(microcode_update_lock); | 84 | static DEFINE_SPINLOCK(microcode_update_lock); |
@@ -93,31 +88,24 @@ static struct equiv_cpu_entry *equiv_cpu_table; | |||
93 | static int collect_cpu_info_amd(int cpu, struct cpu_signature *csig) | 88 | static int collect_cpu_info_amd(int cpu, struct cpu_signature *csig) |
94 | { | 89 | { |
95 | struct cpuinfo_x86 *c = &cpu_data(cpu); | 90 | struct cpuinfo_x86 *c = &cpu_data(cpu); |
91 | u32 dummy; | ||
96 | 92 | ||
97 | memset(csig, 0, sizeof(*csig)); | 93 | memset(csig, 0, sizeof(*csig)); |
98 | |||
99 | if (c->x86_vendor != X86_VENDOR_AMD || c->x86 < 0x10) { | 94 | if (c->x86_vendor != X86_VENDOR_AMD || c->x86 < 0x10) { |
100 | printk(KERN_ERR "microcode: CPU%d not a capable AMD processor\n", | 95 | printk(KERN_WARNING "microcode: CPU%d: AMD CPU family 0x%x not " |
101 | cpu); | 96 | "supported\n", cpu, c->x86); |
102 | return -1; | 97 | return -1; |
103 | } | 98 | } |
104 | 99 | rdmsr(MSR_AMD64_PATCH_LEVEL, csig->rev, dummy); | |
105 | asm volatile("movl %1, %%ecx; rdmsr" | 100 | printk(KERN_INFO "microcode: CPU%d: patch_level=0x%x\n", cpu, csig->rev); |
106 | : "=a" (csig->rev) | ||
107 | : "i" (0x0000008B) : "ecx"); | ||
108 | |||
109 | printk(KERN_INFO "microcode: collect_cpu_info_amd : patch_id=0x%x\n", | ||
110 | csig->rev); | ||
111 | |||
112 | return 0; | 101 | return 0; |
113 | } | 102 | } |
114 | 103 | ||
115 | static int get_matching_microcode(int cpu, void *mc, int rev) | 104 | static int get_matching_microcode(int cpu, void *mc, int rev) |
116 | { | 105 | { |
117 | struct microcode_header_amd *mc_header = mc; | 106 | struct microcode_header_amd *mc_header = mc; |
118 | struct pci_dev *nb_pci_dev, *sb_pci_dev; | ||
119 | unsigned int current_cpu_id; | 107 | unsigned int current_cpu_id; |
120 | unsigned int equiv_cpu_id = 0x00; | 108 | u16 equiv_cpu_id = 0; |
121 | unsigned int i = 0; | 109 | unsigned int i = 0; |
122 | 110 | ||
123 | BUG_ON(equiv_cpu_table == NULL); | 111 | BUG_ON(equiv_cpu_table == NULL); |
@@ -132,57 +120,25 @@ static int get_matching_microcode(int cpu, void *mc, int rev) | |||
132 | } | 120 | } |
133 | 121 | ||
134 | if (!equiv_cpu_id) { | 122 | if (!equiv_cpu_id) { |
135 | printk(KERN_ERR "microcode: CPU%d cpu_id " | 123 | printk(KERN_WARNING "microcode: CPU%d: cpu revision " |
136 | "not found in equivalent cpu table \n", cpu); | 124 | "not listed in equivalent cpu table\n", cpu); |
137 | return 0; | 125 | return 0; |
138 | } | 126 | } |
139 | 127 | ||
140 | if ((mc_header->processor_rev_id[0]) != (equiv_cpu_id & 0xff)) { | 128 | if (mc_header->processor_rev_id != equiv_cpu_id) { |
141 | printk(KERN_ERR | 129 | printk(KERN_ERR "microcode: CPU%d: patch mismatch " |
142 | "microcode: CPU%d patch does not match " | 130 | "(processor_rev_id: %x, equiv_cpu_id: %x)\n", |
143 | "(patch is %x, cpu extended is %x) \n", | 131 | cpu, mc_header->processor_rev_id, equiv_cpu_id); |
144 | cpu, mc_header->processor_rev_id[0], | ||
145 | (equiv_cpu_id & 0xff)); | ||
146 | return 0; | 132 | return 0; |
147 | } | 133 | } |
148 | 134 | ||
149 | if ((mc_header->processor_rev_id[1]) != ((equiv_cpu_id >> 16) & 0xff)) { | 135 | /* ucode might be chipset specific -- currently we don't support this */ |
150 | printk(KERN_ERR "microcode: CPU%d patch does not match " | 136 | if (mc_header->nb_dev_id || mc_header->sb_dev_id) { |
151 | "(patch is %x, cpu base id is %x) \n", | 137 | printk(KERN_ERR "microcode: CPU%d: loading of chipset " |
152 | cpu, mc_header->processor_rev_id[1], | 138 | "specific code not yet supported\n", cpu); |
153 | ((equiv_cpu_id >> 16) & 0xff)); | ||
154 | |||
155 | return 0; | 139 | return 0; |
156 | } | 140 | } |
157 | 141 | ||
158 | /* ucode may be northbridge specific */ | ||
159 | if (mc_header->nb_dev_id) { | ||
160 | nb_pci_dev = pci_get_device(PCI_VENDOR_ID_AMD, | ||
161 | (mc_header->nb_dev_id & 0xff), | ||
162 | NULL); | ||
163 | if ((!nb_pci_dev) || | ||
164 | (mc_header->nb_rev_id != nb_pci_dev->revision)) { | ||
165 | printk(KERN_ERR "microcode: CPU%d NB mismatch \n", cpu); | ||
166 | pci_dev_put(nb_pci_dev); | ||
167 | return 0; | ||
168 | } | ||
169 | pci_dev_put(nb_pci_dev); | ||
170 | } | ||
171 | |||
172 | /* ucode may be southbridge specific */ | ||
173 | if (mc_header->sb_dev_id) { | ||
174 | sb_pci_dev = pci_get_device(PCI_VENDOR_ID_AMD, | ||
175 | (mc_header->sb_dev_id & 0xff), | ||
176 | NULL); | ||
177 | if ((!sb_pci_dev) || | ||
178 | (mc_header->sb_rev_id != sb_pci_dev->revision)) { | ||
179 | printk(KERN_ERR "microcode: CPU%d SB mismatch \n", cpu); | ||
180 | pci_dev_put(sb_pci_dev); | ||
181 | return 0; | ||
182 | } | ||
183 | pci_dev_put(sb_pci_dev); | ||
184 | } | ||
185 | |||
186 | if (mc_header->patch_id <= rev) | 142 | if (mc_header->patch_id <= rev) |
187 | return 0; | 143 | return 0; |
188 | 144 | ||
@@ -192,12 +148,10 @@ static int get_matching_microcode(int cpu, void *mc, int rev) | |||
192 | static void apply_microcode_amd(int cpu) | 148 | static void apply_microcode_amd(int cpu) |
193 | { | 149 | { |
194 | unsigned long flags; | 150 | unsigned long flags; |
195 | unsigned int eax, edx; | 151 | u32 rev, dummy; |
196 | unsigned int rev; | ||
197 | int cpu_num = raw_smp_processor_id(); | 152 | int cpu_num = raw_smp_processor_id(); |
198 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu_num; | 153 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu_num; |
199 | struct microcode_amd *mc_amd = uci->mc; | 154 | struct microcode_amd *mc_amd = uci->mc; |
200 | unsigned long addr; | ||
201 | 155 | ||
202 | /* We should bind the task to the CPU */ | 156 | /* We should bind the task to the CPU */ |
203 | BUG_ON(cpu_num != cpu); | 157 | BUG_ON(cpu_num != cpu); |
@@ -206,42 +160,34 @@ static void apply_microcode_amd(int cpu) | |||
206 | return; | 160 | return; |
207 | 161 | ||
208 | spin_lock_irqsave(µcode_update_lock, flags); | 162 | spin_lock_irqsave(µcode_update_lock, flags); |
209 | 163 | wrmsrl(MSR_AMD64_PATCH_LOADER, (u64)(long)&mc_amd->hdr.data_code); | |
210 | addr = (unsigned long)&mc_amd->hdr.data_code; | ||
211 | edx = (unsigned int)(((unsigned long)upper_32_bits(addr))); | ||
212 | eax = (unsigned int)(((unsigned long)lower_32_bits(addr))); | ||
213 | |||
214 | asm volatile("movl %0, %%ecx; wrmsr" : | ||
215 | : "i" (0xc0010020), "a" (eax), "d" (edx) : "ecx"); | ||
216 | |||
217 | /* get patch id after patching */ | 164 | /* get patch id after patching */ |
218 | asm volatile("movl %1, %%ecx; rdmsr" | 165 | rdmsr(MSR_AMD64_PATCH_LEVEL, rev, dummy); |
219 | : "=a" (rev) | ||
220 | : "i" (0x0000008B) : "ecx"); | ||
221 | |||
222 | spin_unlock_irqrestore(µcode_update_lock, flags); | 166 | spin_unlock_irqrestore(µcode_update_lock, flags); |
223 | 167 | ||
224 | /* check current patch id and patch's id for match */ | 168 | /* check current patch id and patch's id for match */ |
225 | if (rev != mc_amd->hdr.patch_id) { | 169 | if (rev != mc_amd->hdr.patch_id) { |
226 | printk(KERN_ERR "microcode: CPU%d update from revision " | 170 | printk(KERN_ERR "microcode: CPU%d: update failed " |
227 | "0x%x to 0x%x failed\n", cpu_num, | 171 | "(for patch_level=0x%x)\n", cpu, mc_amd->hdr.patch_id); |
228 | mc_amd->hdr.patch_id, rev); | ||
229 | return; | 172 | return; |
230 | } | 173 | } |
231 | 174 | ||
232 | printk(KERN_INFO "microcode: CPU%d updated from revision " | 175 | printk(KERN_INFO "microcode: CPU%d: updated (new patch_level=0x%x)\n", |
233 | "0x%x to 0x%x \n", | 176 | cpu, rev); |
234 | cpu_num, uci->cpu_sig.rev, mc_amd->hdr.patch_id); | ||
235 | 177 | ||
236 | uci->cpu_sig.rev = rev; | 178 | uci->cpu_sig.rev = rev; |
237 | } | 179 | } |
238 | 180 | ||
239 | static void * get_next_ucode(u8 *buf, unsigned int size, | 181 | static int get_ucode_data(void *to, const u8 *from, size_t n) |
240 | int (*get_ucode_data)(void *, const void *, size_t), | 182 | { |
241 | unsigned int *mc_size) | 183 | memcpy(to, from, n); |
184 | return 0; | ||
185 | } | ||
186 | |||
187 | static void *get_next_ucode(const u8 *buf, unsigned int size, | ||
188 | unsigned int *mc_size) | ||
242 | { | 189 | { |
243 | unsigned int total_size; | 190 | unsigned int total_size; |
244 | #define UCODE_CONTAINER_SECTION_HDR 8 | ||
245 | u8 section_hdr[UCODE_CONTAINER_SECTION_HDR]; | 191 | u8 section_hdr[UCODE_CONTAINER_SECTION_HDR]; |
246 | void *mc; | 192 | void *mc; |
247 | 193 | ||
@@ -249,39 +195,37 @@ static void * get_next_ucode(u8 *buf, unsigned int size, | |||
249 | return NULL; | 195 | return NULL; |
250 | 196 | ||
251 | if (section_hdr[0] != UCODE_UCODE_TYPE) { | 197 | if (section_hdr[0] != UCODE_UCODE_TYPE) { |
252 | printk(KERN_ERR "microcode: error! " | 198 | printk(KERN_ERR "microcode: error: invalid type field in " |
253 | "Wrong microcode payload type field\n"); | 199 | "container file section header\n"); |
254 | return NULL; | 200 | return NULL; |
255 | } | 201 | } |
256 | 202 | ||
257 | total_size = (unsigned long) (section_hdr[4] + (section_hdr[5] << 8)); | 203 | total_size = (unsigned long) (section_hdr[4] + (section_hdr[5] << 8)); |
258 | 204 | ||
259 | printk(KERN_INFO "microcode: size %u, total_size %u\n", | 205 | printk(KERN_DEBUG "microcode: size %u, total_size %u\n", |
260 | size, total_size); | 206 | size, total_size); |
261 | 207 | ||
262 | if (total_size > size || total_size > UCODE_MAX_SIZE) { | 208 | if (total_size > size || total_size > UCODE_MAX_SIZE) { |
263 | printk(KERN_ERR "microcode: error! Bad data in microcode data file\n"); | 209 | printk(KERN_ERR "microcode: error: size mismatch\n"); |
264 | return NULL; | 210 | return NULL; |
265 | } | 211 | } |
266 | 212 | ||
267 | mc = vmalloc(UCODE_MAX_SIZE); | 213 | mc = vmalloc(UCODE_MAX_SIZE); |
268 | if (mc) { | 214 | if (mc) { |
269 | memset(mc, 0, UCODE_MAX_SIZE); | 215 | memset(mc, 0, UCODE_MAX_SIZE); |
270 | if (get_ucode_data(mc, buf + UCODE_CONTAINER_SECTION_HDR, total_size)) { | 216 | if (get_ucode_data(mc, buf + UCODE_CONTAINER_SECTION_HDR, |
217 | total_size)) { | ||
271 | vfree(mc); | 218 | vfree(mc); |
272 | mc = NULL; | 219 | mc = NULL; |
273 | } else | 220 | } else |
274 | *mc_size = total_size + UCODE_CONTAINER_SECTION_HDR; | 221 | *mc_size = total_size + UCODE_CONTAINER_SECTION_HDR; |
275 | } | 222 | } |
276 | #undef UCODE_CONTAINER_SECTION_HDR | ||
277 | return mc; | 223 | return mc; |
278 | } | 224 | } |
279 | 225 | ||
280 | 226 | ||
281 | static int install_equiv_cpu_table(u8 *buf, | 227 | static int install_equiv_cpu_table(const u8 *buf) |
282 | int (*get_ucode_data)(void *, const void *, size_t)) | ||
283 | { | 228 | { |
284 | #define UCODE_CONTAINER_HEADER_SIZE 12 | ||
285 | u8 *container_hdr[UCODE_CONTAINER_HEADER_SIZE]; | 229 | u8 *container_hdr[UCODE_CONTAINER_HEADER_SIZE]; |
286 | unsigned int *buf_pos = (unsigned int *)container_hdr; | 230 | unsigned int *buf_pos = (unsigned int *)container_hdr; |
287 | unsigned long size; | 231 | unsigned long size; |
@@ -292,14 +236,15 @@ static int install_equiv_cpu_table(u8 *buf, | |||
292 | size = buf_pos[2]; | 236 | size = buf_pos[2]; |
293 | 237 | ||
294 | if (buf_pos[1] != UCODE_EQUIV_CPU_TABLE_TYPE || !size) { | 238 | if (buf_pos[1] != UCODE_EQUIV_CPU_TABLE_TYPE || !size) { |
295 | printk(KERN_ERR "microcode: error! " | 239 | printk(KERN_ERR "microcode: error: invalid type field in " |
296 | "Wrong microcode equivalnet cpu table\n"); | 240 | "container file section header\n"); |
297 | return 0; | 241 | return 0; |
298 | } | 242 | } |
299 | 243 | ||
300 | equiv_cpu_table = (struct equiv_cpu_entry *) vmalloc(size); | 244 | equiv_cpu_table = (struct equiv_cpu_entry *) vmalloc(size); |
301 | if (!equiv_cpu_table) { | 245 | if (!equiv_cpu_table) { |
302 | printk(KERN_ERR "microcode: error, can't allocate memory for equiv CPU table\n"); | 246 | printk(KERN_ERR "microcode: failed to allocate " |
247 | "equivalent CPU table\n"); | ||
303 | return 0; | 248 | return 0; |
304 | } | 249 | } |
305 | 250 | ||
@@ -310,7 +255,6 @@ static int install_equiv_cpu_table(u8 *buf, | |||
310 | } | 255 | } |
311 | 256 | ||
312 | return size + UCODE_CONTAINER_HEADER_SIZE; /* add header length */ | 257 | return size + UCODE_CONTAINER_HEADER_SIZE; /* add header length */ |
313 | #undef UCODE_CONTAINER_HEADER_SIZE | ||
314 | } | 258 | } |
315 | 259 | ||
316 | static void free_equiv_cpu_table(void) | 260 | static void free_equiv_cpu_table(void) |
@@ -321,18 +265,20 @@ static void free_equiv_cpu_table(void) | |||
321 | } | 265 | } |
322 | } | 266 | } |
323 | 267 | ||
324 | static int generic_load_microcode(int cpu, void *data, size_t size, | 268 | static int generic_load_microcode(int cpu, const u8 *data, size_t size) |
325 | int (*get_ucode_data)(void *, const void *, size_t)) | ||
326 | { | 269 | { |
327 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu; | 270 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu; |
328 | u8 *ucode_ptr = data, *new_mc = NULL, *mc; | 271 | const u8 *ucode_ptr = data; |
272 | void *new_mc = NULL; | ||
273 | void *mc; | ||
329 | int new_rev = uci->cpu_sig.rev; | 274 | int new_rev = uci->cpu_sig.rev; |
330 | unsigned int leftover; | 275 | unsigned int leftover; |
331 | unsigned long offset; | 276 | unsigned long offset; |
332 | 277 | ||
333 | offset = install_equiv_cpu_table(ucode_ptr, get_ucode_data); | 278 | offset = install_equiv_cpu_table(ucode_ptr); |
334 | if (!offset) { | 279 | if (!offset) { |
335 | printk(KERN_ERR "microcode: installing equivalent cpu table failed\n"); | 280 | printk(KERN_ERR "microcode: failed to create " |
281 | "equivalent cpu table\n"); | ||
336 | return -EINVAL; | 282 | return -EINVAL; |
337 | } | 283 | } |
338 | 284 | ||
@@ -343,7 +289,7 @@ static int generic_load_microcode(int cpu, void *data, size_t size, | |||
343 | unsigned int uninitialized_var(mc_size); | 289 | unsigned int uninitialized_var(mc_size); |
344 | struct microcode_header_amd *mc_header; | 290 | struct microcode_header_amd *mc_header; |
345 | 291 | ||
346 | mc = get_next_ucode(ucode_ptr, leftover, get_ucode_data, &mc_size); | 292 | mc = get_next_ucode(ucode_ptr, leftover, &mc_size); |
347 | if (!mc) | 293 | if (!mc) |
348 | break; | 294 | break; |
349 | 295 | ||
@@ -353,7 +299,7 @@ static int generic_load_microcode(int cpu, void *data, size_t size, | |||
353 | vfree(new_mc); | 299 | vfree(new_mc); |
354 | new_rev = mc_header->patch_id; | 300 | new_rev = mc_header->patch_id; |
355 | new_mc = mc; | 301 | new_mc = mc; |
356 | } else | 302 | } else |
357 | vfree(mc); | 303 | vfree(mc); |
358 | 304 | ||
359 | ucode_ptr += mc_size; | 305 | ucode_ptr += mc_size; |
@@ -365,9 +311,9 @@ static int generic_load_microcode(int cpu, void *data, size_t size, | |||
365 | if (uci->mc) | 311 | if (uci->mc) |
366 | vfree(uci->mc); | 312 | vfree(uci->mc); |
367 | uci->mc = new_mc; | 313 | uci->mc = new_mc; |
368 | pr_debug("microcode: CPU%d found a matching microcode update with" | 314 | pr_debug("microcode: CPU%d found a matching microcode " |
369 | " version 0x%x (current=0x%x)\n", | 315 | "update with version 0x%x (current=0x%x)\n", |
370 | cpu, new_rev, uci->cpu_sig.rev); | 316 | cpu, new_rev, uci->cpu_sig.rev); |
371 | } else | 317 | } else |
372 | vfree(new_mc); | 318 | vfree(new_mc); |
373 | } | 319 | } |
@@ -377,12 +323,6 @@ static int generic_load_microcode(int cpu, void *data, size_t size, | |||
377 | return (int)leftover; | 323 | return (int)leftover; |
378 | } | 324 | } |
379 | 325 | ||
380 | static int get_ucode_fw(void *to, const void *from, size_t n) | ||
381 | { | ||
382 | memcpy(to, from, n); | ||
383 | return 0; | ||
384 | } | ||
385 | |||
386 | static int request_microcode_fw(int cpu, struct device *device) | 326 | static int request_microcode_fw(int cpu, struct device *device) |
387 | { | 327 | { |
388 | const char *fw_name = "amd-ucode/microcode_amd.bin"; | 328 | const char *fw_name = "amd-ucode/microcode_amd.bin"; |
@@ -394,12 +334,11 @@ static int request_microcode_fw(int cpu, struct device *device) | |||
394 | 334 | ||
395 | ret = request_firmware(&firmware, fw_name, device); | 335 | ret = request_firmware(&firmware, fw_name, device); |
396 | if (ret) { | 336 | if (ret) { |
397 | printk(KERN_ERR "microcode: ucode data file %s load failed\n", fw_name); | 337 | printk(KERN_ERR "microcode: failed to load file %s\n", fw_name); |
398 | return ret; | 338 | return ret; |
399 | } | 339 | } |
400 | 340 | ||
401 | ret = generic_load_microcode(cpu, (void*)firmware->data, firmware->size, | 341 | ret = generic_load_microcode(cpu, firmware->data, firmware->size); |
402 | &get_ucode_fw); | ||
403 | 342 | ||
404 | release_firmware(firmware); | 343 | release_firmware(firmware); |
405 | 344 | ||
@@ -408,8 +347,8 @@ static int request_microcode_fw(int cpu, struct device *device) | |||
408 | 347 | ||
409 | static int request_microcode_user(int cpu, const void __user *buf, size_t size) | 348 | static int request_microcode_user(int cpu, const void __user *buf, size_t size) |
410 | { | 349 | { |
411 | printk(KERN_WARNING "microcode: AMD microcode update via /dev/cpu/microcode" | 350 | printk(KERN_INFO "microcode: AMD microcode update via " |
412 | "is not supported\n"); | 351 | "/dev/cpu/microcode not supported\n"); |
413 | return -1; | 352 | return -1; |
414 | } | 353 | } |
415 | 354 | ||
@@ -433,3 +372,4 @@ struct microcode_ops * __init init_amd_microcode(void) | |||
433 | { | 372 | { |
434 | return µcode_amd_ops; | 373 | return µcode_amd_ops; |
435 | } | 374 | } |
375 | |||
diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c index c4b5b24e0217..c9b721ba968c 100644 --- a/arch/x86/kernel/microcode_core.c +++ b/arch/x86/kernel/microcode_core.c | |||
@@ -99,7 +99,7 @@ MODULE_LICENSE("GPL"); | |||
99 | 99 | ||
100 | #define MICROCODE_VERSION "2.00" | 100 | #define MICROCODE_VERSION "2.00" |
101 | 101 | ||
102 | struct microcode_ops *microcode_ops; | 102 | static struct microcode_ops *microcode_ops; |
103 | 103 | ||
104 | /* no concurrent ->write()s are allowed on /dev/cpu/microcode */ | 104 | /* no concurrent ->write()s are allowed on /dev/cpu/microcode */ |
105 | static DEFINE_MUTEX(microcode_mutex); | 105 | static DEFINE_MUTEX(microcode_mutex); |
@@ -203,7 +203,7 @@ MODULE_ALIAS_MISCDEV(MICROCODE_MINOR); | |||
203 | #endif | 203 | #endif |
204 | 204 | ||
205 | /* fake device for request_firmware */ | 205 | /* fake device for request_firmware */ |
206 | struct platform_device *microcode_pdev; | 206 | static struct platform_device *microcode_pdev; |
207 | 207 | ||
208 | static ssize_t reload_store(struct sys_device *dev, | 208 | static ssize_t reload_store(struct sys_device *dev, |
209 | struct sysdev_attribute *attr, | 209 | struct sysdev_attribute *attr, |
@@ -328,7 +328,7 @@ static int microcode_resume_cpu(int cpu) | |||
328 | return 0; | 328 | return 0; |
329 | } | 329 | } |
330 | 330 | ||
331 | void microcode_update_cpu(int cpu) | 331 | static void microcode_update_cpu(int cpu) |
332 | { | 332 | { |
333 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu; | 333 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu; |
334 | int err = 0; | 334 | int err = 0; |
diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c index a8e62792d171..b7f4c929e615 100644 --- a/arch/x86/kernel/microcode_intel.c +++ b/arch/x86/kernel/microcode_intel.c | |||
@@ -471,7 +471,7 @@ static void microcode_fini_cpu(int cpu) | |||
471 | uci->mc = NULL; | 471 | uci->mc = NULL; |
472 | } | 472 | } |
473 | 473 | ||
474 | struct microcode_ops microcode_intel_ops = { | 474 | static struct microcode_ops microcode_intel_ops = { |
475 | .request_microcode_user = request_microcode_user, | 475 | .request_microcode_user = request_microcode_user, |
476 | .request_microcode_fw = request_microcode_fw, | 476 | .request_microcode_fw = request_microcode_fw, |
477 | .collect_cpu_info = collect_cpu_info, | 477 | .collect_cpu_info = collect_cpu_info, |
diff --git a/arch/x86/kernel/mmconf-fam10h_64.c b/arch/x86/kernel/mmconf-fam10h_64.c index efc2f361fe85..666e43df51f9 100644 --- a/arch/x86/kernel/mmconf-fam10h_64.c +++ b/arch/x86/kernel/mmconf-fam10h_64.c | |||
@@ -13,8 +13,7 @@ | |||
13 | #include <asm/msr.h> | 13 | #include <asm/msr.h> |
14 | #include <asm/acpi.h> | 14 | #include <asm/acpi.h> |
15 | #include <asm/mmconfig.h> | 15 | #include <asm/mmconfig.h> |
16 | 16 | #include <asm/pci_x86.h> | |
17 | #include "../pci/pci.h" | ||
18 | 17 | ||
19 | struct pci_hostbridge_probe { | 18 | struct pci_hostbridge_probe { |
20 | u32 bus; | 19 | u32 bus; |
diff --git a/arch/x86/kernel/mpparse.c b/arch/x86/kernel/mpparse.c index 0f4c1fd5a1f4..c5c5b8df1dbc 100644 --- a/arch/x86/kernel/mpparse.c +++ b/arch/x86/kernel/mpparse.c | |||
@@ -16,14 +16,14 @@ | |||
16 | #include <linux/bitops.h> | 16 | #include <linux/bitops.h> |
17 | #include <linux/acpi.h> | 17 | #include <linux/acpi.h> |
18 | #include <linux/module.h> | 18 | #include <linux/module.h> |
19 | #include <linux/smp.h> | ||
20 | #include <linux/acpi.h> | ||
19 | 21 | ||
20 | #include <asm/smp.h> | ||
21 | #include <asm/mtrr.h> | 22 | #include <asm/mtrr.h> |
22 | #include <asm/mpspec.h> | 23 | #include <asm/mpspec.h> |
23 | #include <asm/pgalloc.h> | 24 | #include <asm/pgalloc.h> |
24 | #include <asm/io_apic.h> | 25 | #include <asm/io_apic.h> |
25 | #include <asm/proto.h> | 26 | #include <asm/proto.h> |
26 | #include <asm/acpi.h> | ||
27 | #include <asm/bios_ebda.h> | 27 | #include <asm/bios_ebda.h> |
28 | #include <asm/e820.h> | 28 | #include <asm/e820.h> |
29 | #include <asm/trampoline.h> | 29 | #include <asm/trampoline.h> |
@@ -95,8 +95,8 @@ static void __init MP_bus_info(struct mpc_config_bus *m) | |||
95 | #endif | 95 | #endif |
96 | 96 | ||
97 | if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) { | 97 | if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) { |
98 | set_bit(m->mpc_busid, mp_bus_not_pci); | 98 | set_bit(m->mpc_busid, mp_bus_not_pci); |
99 | #if defined(CONFIG_EISA) || defined (CONFIG_MCA) | 99 | #if defined(CONFIG_EISA) || defined(CONFIG_MCA) |
100 | mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA; | 100 | mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA; |
101 | #endif | 101 | #endif |
102 | } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) { | 102 | } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) { |
@@ -104,7 +104,7 @@ static void __init MP_bus_info(struct mpc_config_bus *m) | |||
104 | x86_quirks->mpc_oem_pci_bus(m); | 104 | x86_quirks->mpc_oem_pci_bus(m); |
105 | 105 | ||
106 | clear_bit(m->mpc_busid, mp_bus_not_pci); | 106 | clear_bit(m->mpc_busid, mp_bus_not_pci); |
107 | #if defined(CONFIG_EISA) || defined (CONFIG_MCA) | 107 | #if defined(CONFIG_EISA) || defined(CONFIG_MCA) |
108 | mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI; | 108 | mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI; |
109 | } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) { | 109 | } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) { |
110 | mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA; | 110 | mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA; |
@@ -586,26 +586,23 @@ static void __init __get_smp_config(unsigned int early) | |||
586 | { | 586 | { |
587 | struct intel_mp_floating *mpf = mpf_found; | 587 | struct intel_mp_floating *mpf = mpf_found; |
588 | 588 | ||
589 | if (x86_quirks->mach_get_smp_config) { | 589 | if (!mpf) |
590 | if (x86_quirks->mach_get_smp_config(early)) | 590 | return; |
591 | return; | 591 | |
592 | } | ||
593 | if (acpi_lapic && early) | 592 | if (acpi_lapic && early) |
594 | return; | 593 | return; |
594 | |||
595 | /* | 595 | /* |
596 | * ACPI supports both logical (e.g. Hyper-Threading) and physical | 596 | * MPS doesn't support hyperthreading, aka only have |
597 | * processors, where MPS only supports physical. | 597 | * thread 0 apic id in MPS table |
598 | */ | 598 | */ |
599 | if (acpi_lapic && acpi_ioapic) { | 599 | if (acpi_lapic && acpi_ioapic) |
600 | printk(KERN_INFO "Using ACPI (MADT) for SMP configuration " | ||
601 | "information\n"); | ||
602 | return; | 600 | return; |
603 | } else if (acpi_lapic) | ||
604 | printk(KERN_INFO "Using ACPI for processor (LAPIC) " | ||
605 | "configuration information\n"); | ||
606 | 601 | ||
607 | if (!mpf) | 602 | if (x86_quirks->mach_get_smp_config) { |
608 | return; | 603 | if (x86_quirks->mach_get_smp_config(early)) |
604 | return; | ||
605 | } | ||
609 | 606 | ||
610 | printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n", | 607 | printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n", |
611 | mpf->mpf_specification); | 608 | mpf->mpf_specification); |
diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c index 82a7c7ed6d45..726266695b2c 100644 --- a/arch/x86/kernel/msr.c +++ b/arch/x86/kernel/msr.c | |||
@@ -136,7 +136,7 @@ static int msr_open(struct inode *inode, struct file *file) | |||
136 | lock_kernel(); | 136 | lock_kernel(); |
137 | cpu = iminor(file->f_path.dentry->d_inode); | 137 | cpu = iminor(file->f_path.dentry->d_inode); |
138 | 138 | ||
139 | if (cpu >= NR_CPUS || !cpu_online(cpu)) { | 139 | if (cpu >= nr_cpu_ids || !cpu_online(cpu)) { |
140 | ret = -ENXIO; /* No such CPU */ | 140 | ret = -ENXIO; /* No such CPU */ |
141 | goto out; | 141 | goto out; |
142 | } | 142 | } |
diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c index 2c97f07f1c2c..45a09ccdc214 100644 --- a/arch/x86/kernel/nmi.c +++ b/arch/x86/kernel/nmi.c | |||
@@ -26,11 +26,10 @@ | |||
26 | #include <linux/kernel_stat.h> | 26 | #include <linux/kernel_stat.h> |
27 | #include <linux/kdebug.h> | 27 | #include <linux/kdebug.h> |
28 | #include <linux/smp.h> | 28 | #include <linux/smp.h> |
29 | #include <linux/nmi.h> | ||
29 | 30 | ||
30 | #include <asm/i8259.h> | 31 | #include <asm/i8259.h> |
31 | #include <asm/io_apic.h> | 32 | #include <asm/io_apic.h> |
32 | #include <asm/smp.h> | ||
33 | #include <asm/nmi.h> | ||
34 | #include <asm/proto.h> | 33 | #include <asm/proto.h> |
35 | #include <asm/timer.h> | 34 | #include <asm/timer.h> |
36 | 35 | ||
@@ -131,6 +130,11 @@ static void report_broken_nmi(int cpu, int *prev_nmi_count) | |||
131 | atomic_dec(&nmi_active); | 130 | atomic_dec(&nmi_active); |
132 | } | 131 | } |
133 | 132 | ||
133 | static void __acpi_nmi_disable(void *__unused) | ||
134 | { | ||
135 | apic_write(APIC_LVT0, APIC_DM_NMI | APIC_LVT_MASKED); | ||
136 | } | ||
137 | |||
134 | int __init check_nmi_watchdog(void) | 138 | int __init check_nmi_watchdog(void) |
135 | { | 139 | { |
136 | unsigned int *prev_nmi_count; | 140 | unsigned int *prev_nmi_count; |
@@ -179,8 +183,12 @@ int __init check_nmi_watchdog(void) | |||
179 | kfree(prev_nmi_count); | 183 | kfree(prev_nmi_count); |
180 | return 0; | 184 | return 0; |
181 | error: | 185 | error: |
182 | if (nmi_watchdog == NMI_IO_APIC && !timer_through_8259) | 186 | if (nmi_watchdog == NMI_IO_APIC) { |
183 | disable_8259A_irq(0); | 187 | if (!timer_through_8259) |
188 | disable_8259A_irq(0); | ||
189 | on_each_cpu(__acpi_nmi_disable, NULL, 1); | ||
190 | } | ||
191 | |||
184 | #ifdef CONFIG_X86_32 | 192 | #ifdef CONFIG_X86_32 |
185 | timer_ack = 0; | 193 | timer_ack = 0; |
186 | #endif | 194 | #endif |
@@ -199,12 +207,17 @@ static int __init setup_nmi_watchdog(char *str) | |||
199 | ++str; | 207 | ++str; |
200 | } | 208 | } |
201 | 209 | ||
202 | get_option(&str, &nmi); | 210 | if (!strncmp(str, "lapic", 5)) |
203 | 211 | nmi_watchdog = NMI_LOCAL_APIC; | |
204 | if (nmi >= NMI_INVALID) | 212 | else if (!strncmp(str, "ioapic", 6)) |
205 | return 0; | 213 | nmi_watchdog = NMI_IO_APIC; |
214 | else { | ||
215 | get_option(&str, &nmi); | ||
216 | if (nmi >= NMI_INVALID) | ||
217 | return 0; | ||
218 | nmi_watchdog = nmi; | ||
219 | } | ||
206 | 220 | ||
207 | nmi_watchdog = nmi; | ||
208 | return 1; | 221 | return 1; |
209 | } | 222 | } |
210 | __setup("nmi_watchdog=", setup_nmi_watchdog); | 223 | __setup("nmi_watchdog=", setup_nmi_watchdog); |
@@ -285,11 +298,6 @@ void acpi_nmi_enable(void) | |||
285 | on_each_cpu(__acpi_nmi_enable, NULL, 1); | 298 | on_each_cpu(__acpi_nmi_enable, NULL, 1); |
286 | } | 299 | } |
287 | 300 | ||
288 | static void __acpi_nmi_disable(void *__unused) | ||
289 | { | ||
290 | apic_write(APIC_LVT0, APIC_DM_NMI | APIC_LVT_MASKED); | ||
291 | } | ||
292 | |||
293 | /* | 301 | /* |
294 | * Disable timer based NMIs on all CPUs: | 302 | * Disable timer based NMIs on all CPUs: |
295 | */ | 303 | */ |
@@ -340,6 +348,8 @@ void stop_apic_nmi_watchdog(void *unused) | |||
340 | return; | 348 | return; |
341 | if (nmi_watchdog == NMI_LOCAL_APIC) | 349 | if (nmi_watchdog == NMI_LOCAL_APIC) |
342 | lapic_watchdog_stop(); | 350 | lapic_watchdog_stop(); |
351 | else | ||
352 | __acpi_nmi_disable(NULL); | ||
343 | __get_cpu_var(wd_enabled) = 0; | 353 | __get_cpu_var(wd_enabled) = 0; |
344 | atomic_dec(&nmi_active); | 354 | atomic_dec(&nmi_active); |
345 | } | 355 | } |
@@ -465,6 +475,24 @@ nmi_watchdog_tick(struct pt_regs *regs, unsigned reason) | |||
465 | 475 | ||
466 | #ifdef CONFIG_SYSCTL | 476 | #ifdef CONFIG_SYSCTL |
467 | 477 | ||
478 | static void enable_ioapic_nmi_watchdog_single(void *unused) | ||
479 | { | ||
480 | __get_cpu_var(wd_enabled) = 1; | ||
481 | atomic_inc(&nmi_active); | ||
482 | __acpi_nmi_enable(NULL); | ||
483 | } | ||
484 | |||
485 | static void enable_ioapic_nmi_watchdog(void) | ||
486 | { | ||
487 | on_each_cpu(enable_ioapic_nmi_watchdog_single, NULL, 1); | ||
488 | touch_nmi_watchdog(); | ||
489 | } | ||
490 | |||
491 | static void disable_ioapic_nmi_watchdog(void) | ||
492 | { | ||
493 | on_each_cpu(stop_apic_nmi_watchdog, NULL, 1); | ||
494 | } | ||
495 | |||
468 | static int __init setup_unknown_nmi_panic(char *str) | 496 | static int __init setup_unknown_nmi_panic(char *str) |
469 | { | 497 | { |
470 | unknown_nmi_panic = 1; | 498 | unknown_nmi_panic = 1; |
@@ -507,6 +535,11 @@ int proc_nmi_enabled(struct ctl_table *table, int write, struct file *file, | |||
507 | enable_lapic_nmi_watchdog(); | 535 | enable_lapic_nmi_watchdog(); |
508 | else | 536 | else |
509 | disable_lapic_nmi_watchdog(); | 537 | disable_lapic_nmi_watchdog(); |
538 | } else if (nmi_watchdog == NMI_IO_APIC) { | ||
539 | if (nmi_watchdog_enabled) | ||
540 | enable_ioapic_nmi_watchdog(); | ||
541 | else | ||
542 | disable_ioapic_nmi_watchdog(); | ||
510 | } else { | 543 | } else { |
511 | printk(KERN_WARNING | 544 | printk(KERN_WARNING |
512 | "NMI watchdog doesn't know what hardware to touch\n"); | 545 | "NMI watchdog doesn't know what hardware to touch\n"); |
diff --git a/arch/x86/kernel/numaq_32.c b/arch/x86/kernel/numaq_32.c index 4caff39078e0..0deea37a53cf 100644 --- a/arch/x86/kernel/numaq_32.c +++ b/arch/x86/kernel/numaq_32.c | |||
@@ -31,7 +31,7 @@ | |||
31 | #include <asm/numaq.h> | 31 | #include <asm/numaq.h> |
32 | #include <asm/topology.h> | 32 | #include <asm/topology.h> |
33 | #include <asm/processor.h> | 33 | #include <asm/processor.h> |
34 | #include <asm/mpspec.h> | 34 | #include <asm/genapic.h> |
35 | #include <asm/e820.h> | 35 | #include <asm/e820.h> |
36 | #include <asm/setup.h> | 36 | #include <asm/setup.h> |
37 | 37 | ||
@@ -235,6 +235,13 @@ static int __init numaq_setup_ioapic_ids(void) | |||
235 | return 1; | 235 | return 1; |
236 | } | 236 | } |
237 | 237 | ||
238 | static int __init numaq_update_genapic(void) | ||
239 | { | ||
240 | genapic->wakeup_cpu = wakeup_secondary_cpu_via_nmi; | ||
241 | |||
242 | return 0; | ||
243 | } | ||
244 | |||
238 | static struct x86_quirks numaq_x86_quirks __initdata = { | 245 | static struct x86_quirks numaq_x86_quirks __initdata = { |
239 | .arch_pre_time_init = numaq_pre_time_init, | 246 | .arch_pre_time_init = numaq_pre_time_init, |
240 | .arch_time_init = NULL, | 247 | .arch_time_init = NULL, |
@@ -250,6 +257,7 @@ static struct x86_quirks numaq_x86_quirks __initdata = { | |||
250 | .mpc_oem_pci_bus = mpc_oem_pci_bus, | 257 | .mpc_oem_pci_bus = mpc_oem_pci_bus, |
251 | .smp_read_mpc_oem = smp_read_mpc_oem, | 258 | .smp_read_mpc_oem = smp_read_mpc_oem, |
252 | .setup_ioapic_ids = numaq_setup_ioapic_ids, | 259 | .setup_ioapic_ids = numaq_setup_ioapic_ids, |
260 | .update_genapic = numaq_update_genapic, | ||
253 | }; | 261 | }; |
254 | 262 | ||
255 | void numaq_mps_oem_check(struct mp_config_table *mpc, char *oem, | 263 | void numaq_mps_oem_check(struct mp_config_table *mpc, char *oem, |
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c index 192624820217..b25428533141 100644 --- a/arch/x86/kernel/pci-dma.c +++ b/arch/x86/kernel/pci-dma.c | |||
@@ -6,6 +6,7 @@ | |||
6 | #include <asm/proto.h> | 6 | #include <asm/proto.h> |
7 | #include <asm/dma.h> | 7 | #include <asm/dma.h> |
8 | #include <asm/iommu.h> | 8 | #include <asm/iommu.h> |
9 | #include <asm/gart.h> | ||
9 | #include <asm/calgary.h> | 10 | #include <asm/calgary.h> |
10 | #include <asm/amd_iommu.h> | 11 | #include <asm/amd_iommu.h> |
11 | 12 | ||
@@ -30,11 +31,6 @@ int no_iommu __read_mostly; | |||
30 | /* Set this to 1 if there is a HW IOMMU in the system */ | 31 | /* Set this to 1 if there is a HW IOMMU in the system */ |
31 | int iommu_detected __read_mostly = 0; | 32 | int iommu_detected __read_mostly = 0; |
32 | 33 | ||
33 | /* This tells the BIO block layer to assume merging. Default to off | ||
34 | because we cannot guarantee merging later. */ | ||
35 | int iommu_bio_merge __read_mostly = 0; | ||
36 | EXPORT_SYMBOL(iommu_bio_merge); | ||
37 | |||
38 | dma_addr_t bad_dma_address __read_mostly = 0; | 34 | dma_addr_t bad_dma_address __read_mostly = 0; |
39 | EXPORT_SYMBOL(bad_dma_address); | 35 | EXPORT_SYMBOL(bad_dma_address); |
40 | 36 | ||
@@ -42,7 +38,7 @@ EXPORT_SYMBOL(bad_dma_address); | |||
42 | be probably a smaller DMA mask, but this is bug-to-bug compatible | 38 | be probably a smaller DMA mask, but this is bug-to-bug compatible |
43 | to older i386. */ | 39 | to older i386. */ |
44 | struct device x86_dma_fallback_dev = { | 40 | struct device x86_dma_fallback_dev = { |
45 | .bus_id = "fallback device", | 41 | .init_name = "fallback device", |
46 | .coherent_dma_mask = DMA_32BIT_MASK, | 42 | .coherent_dma_mask = DMA_32BIT_MASK, |
47 | .dma_mask = &x86_dma_fallback_dev.coherent_dma_mask, | 43 | .dma_mask = &x86_dma_fallback_dev.coherent_dma_mask, |
48 | }; | 44 | }; |
@@ -105,11 +101,15 @@ static void __init dma32_free_bootmem(void) | |||
105 | dma32_bootmem_ptr = NULL; | 101 | dma32_bootmem_ptr = NULL; |
106 | dma32_bootmem_size = 0; | 102 | dma32_bootmem_size = 0; |
107 | } | 103 | } |
104 | #endif | ||
108 | 105 | ||
109 | void __init pci_iommu_alloc(void) | 106 | void __init pci_iommu_alloc(void) |
110 | { | 107 | { |
108 | #ifdef CONFIG_X86_64 | ||
111 | /* free the range so iommu could get some range less than 4G */ | 109 | /* free the range so iommu could get some range less than 4G */ |
112 | dma32_free_bootmem(); | 110 | dma32_free_bootmem(); |
111 | #endif | ||
112 | |||
113 | /* | 113 | /* |
114 | * The order of these functions is important for | 114 | * The order of these functions is important for |
115 | * fall-back/fail-over reasons | 115 | * fall-back/fail-over reasons |
@@ -125,15 +125,6 @@ void __init pci_iommu_alloc(void) | |||
125 | pci_swiotlb_init(); | 125 | pci_swiotlb_init(); |
126 | } | 126 | } |
127 | 127 | ||
128 | unsigned long iommu_nr_pages(unsigned long addr, unsigned long len) | ||
129 | { | ||
130 | unsigned long size = roundup((addr & ~PAGE_MASK) + len, PAGE_SIZE); | ||
131 | |||
132 | return size >> PAGE_SHIFT; | ||
133 | } | ||
134 | EXPORT_SYMBOL(iommu_nr_pages); | ||
135 | #endif | ||
136 | |||
137 | void *dma_generic_alloc_coherent(struct device *dev, size_t size, | 128 | void *dma_generic_alloc_coherent(struct device *dev, size_t size, |
138 | dma_addr_t *dma_addr, gfp_t flag) | 129 | dma_addr_t *dma_addr, gfp_t flag) |
139 | { | 130 | { |
@@ -188,7 +179,6 @@ static __init int iommu_setup(char *p) | |||
188 | } | 179 | } |
189 | 180 | ||
190 | if (!strncmp(p, "biomerge", 8)) { | 181 | if (!strncmp(p, "biomerge", 8)) { |
191 | iommu_bio_merge = 4096; | ||
192 | iommu_merge = 1; | 182 | iommu_merge = 1; |
193 | force_iommu = 1; | 183 | force_iommu = 1; |
194 | } | 184 | } |
@@ -300,8 +290,8 @@ fs_initcall(pci_iommu_init); | |||
300 | static __devinit void via_no_dac(struct pci_dev *dev) | 290 | static __devinit void via_no_dac(struct pci_dev *dev) |
301 | { | 291 | { |
302 | if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI && forbid_dac == 0) { | 292 | if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI && forbid_dac == 0) { |
303 | printk(KERN_INFO "PCI: VIA PCI bridge detected." | 293 | printk(KERN_INFO |
304 | "Disabling DAC.\n"); | 294 | "PCI: VIA PCI bridge detected. Disabling DAC.\n"); |
305 | forbid_dac = 1; | 295 | forbid_dac = 1; |
306 | } | 296 | } |
307 | } | 297 | } |
diff --git a/arch/x86/kernel/pci-gart_64.c b/arch/x86/kernel/pci-gart_64.c index a35eaa379ff6..00c2bcd41463 100644 --- a/arch/x86/kernel/pci-gart_64.c +++ b/arch/x86/kernel/pci-gart_64.c | |||
@@ -52,7 +52,7 @@ static u32 *iommu_gatt_base; /* Remapping table */ | |||
52 | * to trigger bugs with some popular PCI cards, in particular 3ware (but | 52 | * to trigger bugs with some popular PCI cards, in particular 3ware (but |
53 | * has been also also seen with Qlogic at least). | 53 | * has been also also seen with Qlogic at least). |
54 | */ | 54 | */ |
55 | int iommu_fullflush = 1; | 55 | static int iommu_fullflush = 1; |
56 | 56 | ||
57 | /* Allocation bitmap for the remapping area: */ | 57 | /* Allocation bitmap for the remapping area: */ |
58 | static DEFINE_SPINLOCK(iommu_bitmap_lock); | 58 | static DEFINE_SPINLOCK(iommu_bitmap_lock); |
diff --git a/arch/x86/kernel/pci-swiotlb_64.c b/arch/x86/kernel/pci-swiotlb_64.c index 3c539d111abb..d59c91747665 100644 --- a/arch/x86/kernel/pci-swiotlb_64.c +++ b/arch/x86/kernel/pci-swiotlb_64.c | |||
@@ -3,6 +3,8 @@ | |||
3 | #include <linux/pci.h> | 3 | #include <linux/pci.h> |
4 | #include <linux/cache.h> | 4 | #include <linux/cache.h> |
5 | #include <linux/module.h> | 5 | #include <linux/module.h> |
6 | #include <linux/swiotlb.h> | ||
7 | #include <linux/bootmem.h> | ||
6 | #include <linux/dma-mapping.h> | 8 | #include <linux/dma-mapping.h> |
7 | 9 | ||
8 | #include <asm/iommu.h> | 10 | #include <asm/iommu.h> |
@@ -11,6 +13,31 @@ | |||
11 | 13 | ||
12 | int swiotlb __read_mostly; | 14 | int swiotlb __read_mostly; |
13 | 15 | ||
16 | void * __init swiotlb_alloc_boot(size_t size, unsigned long nslabs) | ||
17 | { | ||
18 | return alloc_bootmem_low_pages(size); | ||
19 | } | ||
20 | |||
21 | void *swiotlb_alloc(unsigned order, unsigned long nslabs) | ||
22 | { | ||
23 | return (void *)__get_free_pages(GFP_DMA | __GFP_NOWARN, order); | ||
24 | } | ||
25 | |||
26 | dma_addr_t swiotlb_phys_to_bus(struct device *hwdev, phys_addr_t paddr) | ||
27 | { | ||
28 | return paddr; | ||
29 | } | ||
30 | |||
31 | phys_addr_t swiotlb_bus_to_phys(dma_addr_t baddr) | ||
32 | { | ||
33 | return baddr; | ||
34 | } | ||
35 | |||
36 | int __weak swiotlb_arch_range_needs_mapping(void *ptr, size_t size) | ||
37 | { | ||
38 | return 0; | ||
39 | } | ||
40 | |||
14 | static dma_addr_t | 41 | static dma_addr_t |
15 | swiotlb_map_single_phys(struct device *hwdev, phys_addr_t paddr, size_t size, | 42 | swiotlb_map_single_phys(struct device *hwdev, phys_addr_t paddr, size_t size, |
16 | int direction) | 43 | int direction) |
@@ -50,8 +77,10 @@ struct dma_mapping_ops swiotlb_dma_ops = { | |||
50 | void __init pci_swiotlb_init(void) | 77 | void __init pci_swiotlb_init(void) |
51 | { | 78 | { |
52 | /* don't initialize swiotlb if iommu=off (no_iommu=1) */ | 79 | /* don't initialize swiotlb if iommu=off (no_iommu=1) */ |
80 | #ifdef CONFIG_X86_64 | ||
53 | if (!iommu_detected && !no_iommu && max_pfn > MAX_DMA32_PFN) | 81 | if (!iommu_detected && !no_iommu && max_pfn > MAX_DMA32_PFN) |
54 | swiotlb = 1; | 82 | swiotlb = 1; |
83 | #endif | ||
55 | if (swiotlb_force) | 84 | if (swiotlb_force) |
56 | swiotlb = 1; | 85 | swiotlb = 1; |
57 | if (swiotlb) { | 86 | if (swiotlb) { |
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index c622772744d8..e68bb9e30864 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c | |||
@@ -1,13 +1,16 @@ | |||
1 | #include <linux/errno.h> | 1 | #include <linux/errno.h> |
2 | #include <linux/kernel.h> | 2 | #include <linux/kernel.h> |
3 | #include <linux/mm.h> | 3 | #include <linux/mm.h> |
4 | #include <asm/idle.h> | ||
4 | #include <linux/smp.h> | 5 | #include <linux/smp.h> |
5 | #include <linux/slab.h> | 6 | #include <linux/slab.h> |
6 | #include <linux/sched.h> | 7 | #include <linux/sched.h> |
7 | #include <linux/module.h> | 8 | #include <linux/module.h> |
8 | #include <linux/pm.h> | 9 | #include <linux/pm.h> |
9 | #include <linux/clockchips.h> | 10 | #include <linux/clockchips.h> |
11 | #include <linux/ftrace.h> | ||
10 | #include <asm/system.h> | 12 | #include <asm/system.h> |
13 | #include <asm/apic.h> | ||
11 | 14 | ||
12 | unsigned long idle_halt; | 15 | unsigned long idle_halt; |
13 | EXPORT_SYMBOL(idle_halt); | 16 | EXPORT_SYMBOL(idle_halt); |
@@ -100,6 +103,9 @@ static inline int hlt_use_halt(void) | |||
100 | void default_idle(void) | 103 | void default_idle(void) |
101 | { | 104 | { |
102 | if (hlt_use_halt()) { | 105 | if (hlt_use_halt()) { |
106 | struct power_trace it; | ||
107 | |||
108 | trace_power_start(&it, POWER_CSTATE, 1); | ||
103 | current_thread_info()->status &= ~TS_POLLING; | 109 | current_thread_info()->status &= ~TS_POLLING; |
104 | /* | 110 | /* |
105 | * TS_POLLING-cleared state must be visible before we | 111 | * TS_POLLING-cleared state must be visible before we |
@@ -112,6 +118,7 @@ void default_idle(void) | |||
112 | else | 118 | else |
113 | local_irq_enable(); | 119 | local_irq_enable(); |
114 | current_thread_info()->status |= TS_POLLING; | 120 | current_thread_info()->status |= TS_POLLING; |
121 | trace_power_end(&it); | ||
115 | } else { | 122 | } else { |
116 | local_irq_enable(); | 123 | local_irq_enable(); |
117 | /* loop is done by the caller */ | 124 | /* loop is done by the caller */ |
@@ -122,6 +129,21 @@ void default_idle(void) | |||
122 | EXPORT_SYMBOL(default_idle); | 129 | EXPORT_SYMBOL(default_idle); |
123 | #endif | 130 | #endif |
124 | 131 | ||
132 | void stop_this_cpu(void *dummy) | ||
133 | { | ||
134 | local_irq_disable(); | ||
135 | /* | ||
136 | * Remove this CPU: | ||
137 | */ | ||
138 | cpu_clear(smp_processor_id(), cpu_online_map); | ||
139 | disable_local_APIC(); | ||
140 | |||
141 | for (;;) { | ||
142 | if (hlt_works(smp_processor_id())) | ||
143 | halt(); | ||
144 | } | ||
145 | } | ||
146 | |||
125 | static void do_nothing(void *unused) | 147 | static void do_nothing(void *unused) |
126 | { | 148 | { |
127 | } | 149 | } |
@@ -154,24 +176,31 @@ EXPORT_SYMBOL_GPL(cpu_idle_wait); | |||
154 | */ | 176 | */ |
155 | void mwait_idle_with_hints(unsigned long ax, unsigned long cx) | 177 | void mwait_idle_with_hints(unsigned long ax, unsigned long cx) |
156 | { | 178 | { |
179 | struct power_trace it; | ||
180 | |||
181 | trace_power_start(&it, POWER_CSTATE, (ax>>4)+1); | ||
157 | if (!need_resched()) { | 182 | if (!need_resched()) { |
158 | __monitor((void *)¤t_thread_info()->flags, 0, 0); | 183 | __monitor((void *)¤t_thread_info()->flags, 0, 0); |
159 | smp_mb(); | 184 | smp_mb(); |
160 | if (!need_resched()) | 185 | if (!need_resched()) |
161 | __mwait(ax, cx); | 186 | __mwait(ax, cx); |
162 | } | 187 | } |
188 | trace_power_end(&it); | ||
163 | } | 189 | } |
164 | 190 | ||
165 | /* Default MONITOR/MWAIT with no hints, used for default C1 state */ | 191 | /* Default MONITOR/MWAIT with no hints, used for default C1 state */ |
166 | static void mwait_idle(void) | 192 | static void mwait_idle(void) |
167 | { | 193 | { |
194 | struct power_trace it; | ||
168 | if (!need_resched()) { | 195 | if (!need_resched()) { |
196 | trace_power_start(&it, POWER_CSTATE, 1); | ||
169 | __monitor((void *)¤t_thread_info()->flags, 0, 0); | 197 | __monitor((void *)¤t_thread_info()->flags, 0, 0); |
170 | smp_mb(); | 198 | smp_mb(); |
171 | if (!need_resched()) | 199 | if (!need_resched()) |
172 | __sti_mwait(0, 0); | 200 | __sti_mwait(0, 0); |
173 | else | 201 | else |
174 | local_irq_enable(); | 202 | local_irq_enable(); |
203 | trace_power_end(&it); | ||
175 | } else | 204 | } else |
176 | local_irq_enable(); | 205 | local_irq_enable(); |
177 | } | 206 | } |
@@ -183,9 +212,13 @@ static void mwait_idle(void) | |||
183 | */ | 212 | */ |
184 | static void poll_idle(void) | 213 | static void poll_idle(void) |
185 | { | 214 | { |
215 | struct power_trace it; | ||
216 | |||
217 | trace_power_start(&it, POWER_CSTATE, 0); | ||
186 | local_irq_enable(); | 218 | local_irq_enable(); |
187 | while (!need_resched()) | 219 | while (!need_resched()) |
188 | cpu_relax(); | 220 | cpu_relax(); |
221 | trace_power_end(&it); | ||
189 | } | 222 | } |
190 | 223 | ||
191 | /* | 224 | /* |
@@ -270,7 +303,7 @@ static void c1e_idle(void) | |||
270 | rdmsr(MSR_K8_INT_PENDING_MSG, lo, hi); | 303 | rdmsr(MSR_K8_INT_PENDING_MSG, lo, hi); |
271 | if (lo & K8_INTP_C1E_ACTIVE_MASK) { | 304 | if (lo & K8_INTP_C1E_ACTIVE_MASK) { |
272 | c1e_detected = 1; | 305 | c1e_detected = 1; |
273 | if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC)) | 306 | if (!boot_cpu_has(X86_FEATURE_NONSTOP_TSC)) |
274 | mark_tsc_unstable("TSC halt in AMD C1E"); | 307 | mark_tsc_unstable("TSC halt in AMD C1E"); |
275 | printk(KERN_INFO "System has AMD C1E enabled\n"); | 308 | printk(KERN_INFO "System has AMD C1E enabled\n"); |
276 | set_cpu_cap(&boot_cpu_data, X86_FEATURE_AMDC1E); | 309 | set_cpu_cap(&boot_cpu_data, X86_FEATURE_AMDC1E); |
diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c index 0a1302fe6d45..3ba155d24884 100644 --- a/arch/x86/kernel/process_32.c +++ b/arch/x86/kernel/process_32.c | |||
@@ -38,6 +38,7 @@ | |||
38 | #include <linux/percpu.h> | 38 | #include <linux/percpu.h> |
39 | #include <linux/prctl.h> | 39 | #include <linux/prctl.h> |
40 | #include <linux/dmi.h> | 40 | #include <linux/dmi.h> |
41 | #include <linux/ftrace.h> | ||
41 | 42 | ||
42 | #include <asm/uaccess.h> | 43 | #include <asm/uaccess.h> |
43 | #include <asm/pgtable.h> | 44 | #include <asm/pgtable.h> |
@@ -59,6 +60,7 @@ | |||
59 | #include <asm/idle.h> | 60 | #include <asm/idle.h> |
60 | #include <asm/syscalls.h> | 61 | #include <asm/syscalls.h> |
61 | #include <asm/smp.h> | 62 | #include <asm/smp.h> |
63 | #include <asm/ds.h> | ||
62 | 64 | ||
63 | asmlinkage void ret_from_fork(void) __asm__("ret_from_fork"); | 65 | asmlinkage void ret_from_fork(void) __asm__("ret_from_fork"); |
64 | 66 | ||
@@ -250,14 +252,8 @@ void exit_thread(void) | |||
250 | tss->x86_tss.io_bitmap_base = INVALID_IO_BITMAP_OFFSET; | 252 | tss->x86_tss.io_bitmap_base = INVALID_IO_BITMAP_OFFSET; |
251 | put_cpu(); | 253 | put_cpu(); |
252 | } | 254 | } |
253 | #ifdef CONFIG_X86_DS | 255 | |
254 | /* Free any DS contexts that have not been properly released. */ | 256 | ds_exit_thread(current); |
255 | if (unlikely(current->thread.ds_ctx)) { | ||
256 | /* we clear debugctl to make sure DS is not used. */ | ||
257 | update_debugctlmsr(0); | ||
258 | ds_free(current->thread.ds_ctx); | ||
259 | } | ||
260 | #endif /* CONFIG_X86_DS */ | ||
261 | } | 257 | } |
262 | 258 | ||
263 | void flush_thread(void) | 259 | void flush_thread(void) |
@@ -339,6 +335,12 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long sp, | |||
339 | kfree(p->thread.io_bitmap_ptr); | 335 | kfree(p->thread.io_bitmap_ptr); |
340 | p->thread.io_bitmap_max = 0; | 336 | p->thread.io_bitmap_max = 0; |
341 | } | 337 | } |
338 | |||
339 | ds_copy_thread(p, current); | ||
340 | |||
341 | clear_tsk_thread_flag(p, TIF_DEBUGCTLMSR); | ||
342 | p->thread.debugctlmsr = 0; | ||
343 | |||
342 | return err; | 344 | return err; |
343 | } | 345 | } |
344 | 346 | ||
@@ -419,48 +421,19 @@ int set_tsc_mode(unsigned int val) | |||
419 | return 0; | 421 | return 0; |
420 | } | 422 | } |
421 | 423 | ||
422 | #ifdef CONFIG_X86_DS | ||
423 | static int update_debugctl(struct thread_struct *prev, | ||
424 | struct thread_struct *next, unsigned long debugctl) | ||
425 | { | ||
426 | unsigned long ds_prev = 0; | ||
427 | unsigned long ds_next = 0; | ||
428 | |||
429 | if (prev->ds_ctx) | ||
430 | ds_prev = (unsigned long)prev->ds_ctx->ds; | ||
431 | if (next->ds_ctx) | ||
432 | ds_next = (unsigned long)next->ds_ctx->ds; | ||
433 | |||
434 | if (ds_next != ds_prev) { | ||
435 | /* we clear debugctl to make sure DS | ||
436 | * is not in use when we change it */ | ||
437 | debugctl = 0; | ||
438 | update_debugctlmsr(0); | ||
439 | wrmsr(MSR_IA32_DS_AREA, ds_next, 0); | ||
440 | } | ||
441 | return debugctl; | ||
442 | } | ||
443 | #else | ||
444 | static int update_debugctl(struct thread_struct *prev, | ||
445 | struct thread_struct *next, unsigned long debugctl) | ||
446 | { | ||
447 | return debugctl; | ||
448 | } | ||
449 | #endif /* CONFIG_X86_DS */ | ||
450 | |||
451 | static noinline void | 424 | static noinline void |
452 | __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p, | 425 | __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p, |
453 | struct tss_struct *tss) | 426 | struct tss_struct *tss) |
454 | { | 427 | { |
455 | struct thread_struct *prev, *next; | 428 | struct thread_struct *prev, *next; |
456 | unsigned long debugctl; | ||
457 | 429 | ||
458 | prev = &prev_p->thread; | 430 | prev = &prev_p->thread; |
459 | next = &next_p->thread; | 431 | next = &next_p->thread; |
460 | 432 | ||
461 | debugctl = update_debugctl(prev, next, prev->debugctlmsr); | 433 | if (test_tsk_thread_flag(next_p, TIF_DS_AREA_MSR) || |
462 | 434 | test_tsk_thread_flag(prev_p, TIF_DS_AREA_MSR)) | |
463 | if (next->debugctlmsr != debugctl) | 435 | ds_switch_to(prev_p, next_p); |
436 | else if (next->debugctlmsr != prev->debugctlmsr) | ||
464 | update_debugctlmsr(next->debugctlmsr); | 437 | update_debugctlmsr(next->debugctlmsr); |
465 | 438 | ||
466 | if (test_tsk_thread_flag(next_p, TIF_DEBUG)) { | 439 | if (test_tsk_thread_flag(next_p, TIF_DEBUG)) { |
@@ -482,15 +455,6 @@ __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p, | |||
482 | hard_enable_TSC(); | 455 | hard_enable_TSC(); |
483 | } | 456 | } |
484 | 457 | ||
485 | #ifdef CONFIG_X86_PTRACE_BTS | ||
486 | if (test_tsk_thread_flag(prev_p, TIF_BTS_TRACE_TS)) | ||
487 | ptrace_bts_take_timestamp(prev_p, BTS_TASK_DEPARTS); | ||
488 | |||
489 | if (test_tsk_thread_flag(next_p, TIF_BTS_TRACE_TS)) | ||
490 | ptrace_bts_take_timestamp(next_p, BTS_TASK_ARRIVES); | ||
491 | #endif /* CONFIG_X86_PTRACE_BTS */ | ||
492 | |||
493 | |||
494 | if (!test_tsk_thread_flag(next_p, TIF_IO_BITMAP)) { | 458 | if (!test_tsk_thread_flag(next_p, TIF_IO_BITMAP)) { |
495 | /* | 459 | /* |
496 | * Disable the bitmap via an invalid offset. We still cache | 460 | * Disable the bitmap via an invalid offset. We still cache |
@@ -548,7 +512,8 @@ __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p, | |||
548 | * the task-switch, and shows up in ret_from_fork in entry.S, | 512 | * the task-switch, and shows up in ret_from_fork in entry.S, |
549 | * for example. | 513 | * for example. |
550 | */ | 514 | */ |
551 | struct task_struct * __switch_to(struct task_struct *prev_p, struct task_struct *next_p) | 515 | __notrace_funcgraph struct task_struct * |
516 | __switch_to(struct task_struct *prev_p, struct task_struct *next_p) | ||
552 | { | 517 | { |
553 | struct thread_struct *prev = &prev_p->thread, | 518 | struct thread_struct *prev = &prev_p->thread, |
554 | *next = &next_p->thread; | 519 | *next = &next_p->thread; |
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index c958120fb1b6..416fb9282f4f 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c | |||
@@ -39,6 +39,7 @@ | |||
39 | #include <linux/prctl.h> | 39 | #include <linux/prctl.h> |
40 | #include <linux/uaccess.h> | 40 | #include <linux/uaccess.h> |
41 | #include <linux/io.h> | 41 | #include <linux/io.h> |
42 | #include <linux/ftrace.h> | ||
42 | 43 | ||
43 | #include <asm/pgtable.h> | 44 | #include <asm/pgtable.h> |
44 | #include <asm/system.h> | 45 | #include <asm/system.h> |
@@ -52,6 +53,7 @@ | |||
52 | #include <asm/ia32.h> | 53 | #include <asm/ia32.h> |
53 | #include <asm/idle.h> | 54 | #include <asm/idle.h> |
54 | #include <asm/syscalls.h> | 55 | #include <asm/syscalls.h> |
56 | #include <asm/ds.h> | ||
55 | 57 | ||
56 | asmlinkage extern void ret_from_fork(void); | 58 | asmlinkage extern void ret_from_fork(void); |
57 | 59 | ||
@@ -235,14 +237,8 @@ void exit_thread(void) | |||
235 | t->io_bitmap_max = 0; | 237 | t->io_bitmap_max = 0; |
236 | put_cpu(); | 238 | put_cpu(); |
237 | } | 239 | } |
238 | #ifdef CONFIG_X86_DS | 240 | |
239 | /* Free any DS contexts that have not been properly released. */ | 241 | ds_exit_thread(current); |
240 | if (unlikely(t->ds_ctx)) { | ||
241 | /* we clear debugctl to make sure DS is not used. */ | ||
242 | update_debugctlmsr(0); | ||
243 | ds_free(t->ds_ctx); | ||
244 | } | ||
245 | #endif /* CONFIG_X86_DS */ | ||
246 | } | 242 | } |
247 | 243 | ||
248 | void flush_thread(void) | 244 | void flush_thread(void) |
@@ -372,6 +368,12 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long sp, | |||
372 | if (err) | 368 | if (err) |
373 | goto out; | 369 | goto out; |
374 | } | 370 | } |
371 | |||
372 | ds_copy_thread(p, me); | ||
373 | |||
374 | clear_tsk_thread_flag(p, TIF_DEBUGCTLMSR); | ||
375 | p->thread.debugctlmsr = 0; | ||
376 | |||
375 | err = 0; | 377 | err = 0; |
376 | out: | 378 | out: |
377 | if (err && p->thread.io_bitmap_ptr) { | 379 | if (err && p->thread.io_bitmap_ptr) { |
@@ -470,35 +472,14 @@ static inline void __switch_to_xtra(struct task_struct *prev_p, | |||
470 | struct tss_struct *tss) | 472 | struct tss_struct *tss) |
471 | { | 473 | { |
472 | struct thread_struct *prev, *next; | 474 | struct thread_struct *prev, *next; |
473 | unsigned long debugctl; | ||
474 | 475 | ||
475 | prev = &prev_p->thread, | 476 | prev = &prev_p->thread, |
476 | next = &next_p->thread; | 477 | next = &next_p->thread; |
477 | 478 | ||
478 | debugctl = prev->debugctlmsr; | 479 | if (test_tsk_thread_flag(next_p, TIF_DS_AREA_MSR) || |
479 | 480 | test_tsk_thread_flag(prev_p, TIF_DS_AREA_MSR)) | |
480 | #ifdef CONFIG_X86_DS | 481 | ds_switch_to(prev_p, next_p); |
481 | { | 482 | else if (next->debugctlmsr != prev->debugctlmsr) |
482 | unsigned long ds_prev = 0, ds_next = 0; | ||
483 | |||
484 | if (prev->ds_ctx) | ||
485 | ds_prev = (unsigned long)prev->ds_ctx->ds; | ||
486 | if (next->ds_ctx) | ||
487 | ds_next = (unsigned long)next->ds_ctx->ds; | ||
488 | |||
489 | if (ds_next != ds_prev) { | ||
490 | /* | ||
491 | * We clear debugctl to make sure DS | ||
492 | * is not in use when we change it: | ||
493 | */ | ||
494 | debugctl = 0; | ||
495 | update_debugctlmsr(0); | ||
496 | wrmsrl(MSR_IA32_DS_AREA, ds_next); | ||
497 | } | ||
498 | } | ||
499 | #endif /* CONFIG_X86_DS */ | ||
500 | |||
501 | if (next->debugctlmsr != debugctl) | ||
502 | update_debugctlmsr(next->debugctlmsr); | 483 | update_debugctlmsr(next->debugctlmsr); |
503 | 484 | ||
504 | if (test_tsk_thread_flag(next_p, TIF_DEBUG)) { | 485 | if (test_tsk_thread_flag(next_p, TIF_DEBUG)) { |
@@ -533,14 +514,6 @@ static inline void __switch_to_xtra(struct task_struct *prev_p, | |||
533 | */ | 514 | */ |
534 | memset(tss->io_bitmap, 0xff, prev->io_bitmap_max); | 515 | memset(tss->io_bitmap, 0xff, prev->io_bitmap_max); |
535 | } | 516 | } |
536 | |||
537 | #ifdef CONFIG_X86_PTRACE_BTS | ||
538 | if (test_tsk_thread_flag(prev_p, TIF_BTS_TRACE_TS)) | ||
539 | ptrace_bts_take_timestamp(prev_p, BTS_TASK_DEPARTS); | ||
540 | |||
541 | if (test_tsk_thread_flag(next_p, TIF_BTS_TRACE_TS)) | ||
542 | ptrace_bts_take_timestamp(next_p, BTS_TASK_ARRIVES); | ||
543 | #endif /* CONFIG_X86_PTRACE_BTS */ | ||
544 | } | 517 | } |
545 | 518 | ||
546 | /* | 519 | /* |
@@ -551,8 +524,9 @@ static inline void __switch_to_xtra(struct task_struct *prev_p, | |||
551 | * - could test fs/gs bitsliced | 524 | * - could test fs/gs bitsliced |
552 | * | 525 | * |
553 | * Kprobes not supported here. Set the probe on schedule instead. | 526 | * Kprobes not supported here. Set the probe on schedule instead. |
527 | * Function graph tracer not supported too. | ||
554 | */ | 528 | */ |
555 | struct task_struct * | 529 | __notrace_funcgraph struct task_struct * |
556 | __switch_to(struct task_struct *prev_p, struct task_struct *next_p) | 530 | __switch_to(struct task_struct *prev_p, struct task_struct *next_p) |
557 | { | 531 | { |
558 | struct thread_struct *prev = &prev_p->thread; | 532 | struct thread_struct *prev = &prev_p->thread; |
diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c index 0a6d8c12e10d..0a5df5f82fb9 100644 --- a/arch/x86/kernel/ptrace.c +++ b/arch/x86/kernel/ptrace.c | |||
@@ -581,158 +581,91 @@ static int ioperm_get(struct task_struct *target, | |||
581 | } | 581 | } |
582 | 582 | ||
583 | #ifdef CONFIG_X86_PTRACE_BTS | 583 | #ifdef CONFIG_X86_PTRACE_BTS |
584 | /* | ||
585 | * The configuration for a particular BTS hardware implementation. | ||
586 | */ | ||
587 | struct bts_configuration { | ||
588 | /* the size of a BTS record in bytes; at most BTS_MAX_RECORD_SIZE */ | ||
589 | unsigned char sizeof_bts; | ||
590 | /* the size of a field in the BTS record in bytes */ | ||
591 | unsigned char sizeof_field; | ||
592 | /* a bitmask to enable/disable BTS in DEBUGCTL MSR */ | ||
593 | unsigned long debugctl_mask; | ||
594 | }; | ||
595 | static struct bts_configuration bts_cfg; | ||
596 | |||
597 | #define BTS_MAX_RECORD_SIZE (8 * 3) | ||
598 | |||
599 | |||
600 | /* | ||
601 | * Branch Trace Store (BTS) uses the following format. Different | ||
602 | * architectures vary in the size of those fields. | ||
603 | * - source linear address | ||
604 | * - destination linear address | ||
605 | * - flags | ||
606 | * | ||
607 | * Later architectures use 64bit pointers throughout, whereas earlier | ||
608 | * architectures use 32bit pointers in 32bit mode. | ||
609 | * | ||
610 | * We compute the base address for the first 8 fields based on: | ||
611 | * - the field size stored in the DS configuration | ||
612 | * - the relative field position | ||
613 | * | ||
614 | * In order to store additional information in the BTS buffer, we use | ||
615 | * a special source address to indicate that the record requires | ||
616 | * special interpretation. | ||
617 | * | ||
618 | * Netburst indicated via a bit in the flags field whether the branch | ||
619 | * was predicted; this is ignored. | ||
620 | */ | ||
621 | |||
622 | enum bts_field { | ||
623 | bts_from = 0, | ||
624 | bts_to, | ||
625 | bts_flags, | ||
626 | |||
627 | bts_escape = (unsigned long)-1, | ||
628 | bts_qual = bts_to, | ||
629 | bts_jiffies = bts_flags | ||
630 | }; | ||
631 | |||
632 | static inline unsigned long bts_get(const char *base, enum bts_field field) | ||
633 | { | ||
634 | base += (bts_cfg.sizeof_field * field); | ||
635 | return *(unsigned long *)base; | ||
636 | } | ||
637 | |||
638 | static inline void bts_set(char *base, enum bts_field field, unsigned long val) | ||
639 | { | ||
640 | base += (bts_cfg.sizeof_field * field);; | ||
641 | (*(unsigned long *)base) = val; | ||
642 | } | ||
643 | |||
644 | /* | ||
645 | * Translate a BTS record from the raw format into the bts_struct format | ||
646 | * | ||
647 | * out (out): bts_struct interpretation | ||
648 | * raw: raw BTS record | ||
649 | */ | ||
650 | static void ptrace_bts_translate_record(struct bts_struct *out, const void *raw) | ||
651 | { | ||
652 | memset(out, 0, sizeof(*out)); | ||
653 | if (bts_get(raw, bts_from) == bts_escape) { | ||
654 | out->qualifier = bts_get(raw, bts_qual); | ||
655 | out->variant.jiffies = bts_get(raw, bts_jiffies); | ||
656 | } else { | ||
657 | out->qualifier = BTS_BRANCH; | ||
658 | out->variant.lbr.from_ip = bts_get(raw, bts_from); | ||
659 | out->variant.lbr.to_ip = bts_get(raw, bts_to); | ||
660 | } | ||
661 | } | ||
662 | |||
663 | static int ptrace_bts_read_record(struct task_struct *child, size_t index, | 584 | static int ptrace_bts_read_record(struct task_struct *child, size_t index, |
664 | struct bts_struct __user *out) | 585 | struct bts_struct __user *out) |
665 | { | 586 | { |
666 | struct bts_struct ret; | 587 | const struct bts_trace *trace; |
667 | const void *bts_record; | 588 | struct bts_struct bts; |
668 | size_t bts_index, bts_end; | 589 | const unsigned char *at; |
669 | int error; | 590 | int error; |
670 | 591 | ||
671 | error = ds_get_bts_end(child, &bts_end); | 592 | trace = ds_read_bts(child->bts); |
672 | if (error < 0) | 593 | if (!trace) |
673 | return error; | 594 | return -EPERM; |
674 | |||
675 | if (bts_end <= index) | ||
676 | return -EINVAL; | ||
677 | 595 | ||
678 | error = ds_get_bts_index(child, &bts_index); | 596 | at = trace->ds.top - ((index + 1) * trace->ds.size); |
679 | if (error < 0) | 597 | if ((void *)at < trace->ds.begin) |
680 | return error; | 598 | at += (trace->ds.n * trace->ds.size); |
681 | 599 | ||
682 | /* translate the ptrace bts index into the ds bts index */ | 600 | if (!trace->read) |
683 | bts_index += bts_end - (index + 1); | 601 | return -EOPNOTSUPP; |
684 | if (bts_end <= bts_index) | ||
685 | bts_index -= bts_end; | ||
686 | 602 | ||
687 | error = ds_access_bts(child, bts_index, &bts_record); | 603 | error = trace->read(child->bts, at, &bts); |
688 | if (error < 0) | 604 | if (error < 0) |
689 | return error; | 605 | return error; |
690 | 606 | ||
691 | ptrace_bts_translate_record(&ret, bts_record); | 607 | if (copy_to_user(out, &bts, sizeof(bts))) |
692 | |||
693 | if (copy_to_user(out, &ret, sizeof(ret))) | ||
694 | return -EFAULT; | 608 | return -EFAULT; |
695 | 609 | ||
696 | return sizeof(ret); | 610 | return sizeof(bts); |
697 | } | 611 | } |
698 | 612 | ||
699 | static int ptrace_bts_drain(struct task_struct *child, | 613 | static int ptrace_bts_drain(struct task_struct *child, |
700 | long size, | 614 | long size, |
701 | struct bts_struct __user *out) | 615 | struct bts_struct __user *out) |
702 | { | 616 | { |
703 | struct bts_struct ret; | 617 | const struct bts_trace *trace; |
704 | const unsigned char *raw; | 618 | const unsigned char *at; |
705 | size_t end, i; | 619 | int error, drained = 0; |
706 | int error; | ||
707 | 620 | ||
708 | error = ds_get_bts_index(child, &end); | 621 | trace = ds_read_bts(child->bts); |
709 | if (error < 0) | 622 | if (!trace) |
710 | return error; | 623 | return -EPERM; |
711 | 624 | ||
712 | if (size < (end * sizeof(struct bts_struct))) | 625 | if (!trace->read) |
626 | return -EOPNOTSUPP; | ||
627 | |||
628 | if (size < (trace->ds.top - trace->ds.begin)) | ||
713 | return -EIO; | 629 | return -EIO; |
714 | 630 | ||
715 | error = ds_access_bts(child, 0, (const void **)&raw); | 631 | for (at = trace->ds.begin; (void *)at < trace->ds.top; |
716 | if (error < 0) | 632 | out++, drained++, at += trace->ds.size) { |
717 | return error; | 633 | struct bts_struct bts; |
634 | int error; | ||
718 | 635 | ||
719 | for (i = 0; i < end; i++, out++, raw += bts_cfg.sizeof_bts) { | 636 | error = trace->read(child->bts, at, &bts); |
720 | ptrace_bts_translate_record(&ret, raw); | 637 | if (error < 0) |
638 | return error; | ||
721 | 639 | ||
722 | if (copy_to_user(out, &ret, sizeof(ret))) | 640 | if (copy_to_user(out, &bts, sizeof(bts))) |
723 | return -EFAULT; | 641 | return -EFAULT; |
724 | } | 642 | } |
725 | 643 | ||
726 | error = ds_clear_bts(child); | 644 | memset(trace->ds.begin, 0, trace->ds.n * trace->ds.size); |
645 | |||
646 | error = ds_reset_bts(child->bts); | ||
727 | if (error < 0) | 647 | if (error < 0) |
728 | return error; | 648 | return error; |
729 | 649 | ||
730 | return end; | 650 | return drained; |
731 | } | 651 | } |
732 | 652 | ||
733 | static void ptrace_bts_ovfl(struct task_struct *child) | 653 | static int ptrace_bts_allocate_buffer(struct task_struct *child, size_t size) |
734 | { | 654 | { |
735 | send_sig(child->thread.bts_ovfl_signal, child, 0); | 655 | child->bts_buffer = alloc_locked_buffer(size); |
656 | if (!child->bts_buffer) | ||
657 | return -ENOMEM; | ||
658 | |||
659 | child->bts_size = size; | ||
660 | |||
661 | return 0; | ||
662 | } | ||
663 | |||
664 | static void ptrace_bts_free_buffer(struct task_struct *child) | ||
665 | { | ||
666 | free_locked_buffer(child->bts_buffer, child->bts_size); | ||
667 | child->bts_buffer = NULL; | ||
668 | child->bts_size = 0; | ||
736 | } | 669 | } |
737 | 670 | ||
738 | static int ptrace_bts_config(struct task_struct *child, | 671 | static int ptrace_bts_config(struct task_struct *child, |
@@ -740,114 +673,86 @@ static int ptrace_bts_config(struct task_struct *child, | |||
740 | const struct ptrace_bts_config __user *ucfg) | 673 | const struct ptrace_bts_config __user *ucfg) |
741 | { | 674 | { |
742 | struct ptrace_bts_config cfg; | 675 | struct ptrace_bts_config cfg; |
743 | int error = 0; | 676 | unsigned int flags = 0; |
744 | |||
745 | error = -EOPNOTSUPP; | ||
746 | if (!bts_cfg.sizeof_bts) | ||
747 | goto errout; | ||
748 | 677 | ||
749 | error = -EIO; | ||
750 | if (cfg_size < sizeof(cfg)) | 678 | if (cfg_size < sizeof(cfg)) |
751 | goto errout; | 679 | return -EIO; |
752 | 680 | ||
753 | error = -EFAULT; | ||
754 | if (copy_from_user(&cfg, ucfg, sizeof(cfg))) | 681 | if (copy_from_user(&cfg, ucfg, sizeof(cfg))) |
755 | goto errout; | 682 | return -EFAULT; |
756 | 683 | ||
757 | error = -EINVAL; | 684 | if (child->bts) { |
758 | if ((cfg.flags & PTRACE_BTS_O_SIGNAL) && | 685 | ds_release_bts(child->bts); |
759 | !(cfg.flags & PTRACE_BTS_O_ALLOC)) | 686 | child->bts = NULL; |
760 | goto errout; | 687 | } |
761 | 688 | ||
762 | if (cfg.flags & PTRACE_BTS_O_ALLOC) { | 689 | if (cfg.flags & PTRACE_BTS_O_SIGNAL) { |
763 | ds_ovfl_callback_t ovfl = NULL; | 690 | if (!cfg.signal) |
764 | unsigned int sig = 0; | 691 | return -EINVAL; |
765 | 692 | ||
766 | /* we ignore the error in case we were not tracing child */ | 693 | return -EOPNOTSUPP; |
767 | (void)ds_release_bts(child); | ||
768 | 694 | ||
769 | if (cfg.flags & PTRACE_BTS_O_SIGNAL) { | 695 | child->thread.bts_ovfl_signal = cfg.signal; |
770 | if (!cfg.signal) | 696 | } |
771 | goto errout; | ||
772 | 697 | ||
773 | sig = cfg.signal; | 698 | if ((cfg.flags & PTRACE_BTS_O_ALLOC) && |
774 | ovfl = ptrace_bts_ovfl; | 699 | (cfg.size != child->bts_size)) { |
775 | } | 700 | int error; |
776 | 701 | ||
777 | error = ds_request_bts(child, /* base = */ NULL, cfg.size, ovfl); | 702 | ptrace_bts_free_buffer(child); |
778 | if (error < 0) | ||
779 | goto errout; | ||
780 | 703 | ||
781 | child->thread.bts_ovfl_signal = sig; | 704 | error = ptrace_bts_allocate_buffer(child, cfg.size); |
705 | if (error < 0) | ||
706 | return error; | ||
782 | } | 707 | } |
783 | 708 | ||
784 | error = -EINVAL; | ||
785 | if (!child->thread.ds_ctx && cfg.flags) | ||
786 | goto errout; | ||
787 | |||
788 | if (cfg.flags & PTRACE_BTS_O_TRACE) | 709 | if (cfg.flags & PTRACE_BTS_O_TRACE) |
789 | child->thread.debugctlmsr |= bts_cfg.debugctl_mask; | 710 | flags |= BTS_USER; |
790 | else | ||
791 | child->thread.debugctlmsr &= ~bts_cfg.debugctl_mask; | ||
792 | 711 | ||
793 | if (cfg.flags & PTRACE_BTS_O_SCHED) | 712 | if (cfg.flags & PTRACE_BTS_O_SCHED) |
794 | set_tsk_thread_flag(child, TIF_BTS_TRACE_TS); | 713 | flags |= BTS_TIMESTAMPS; |
795 | else | ||
796 | clear_tsk_thread_flag(child, TIF_BTS_TRACE_TS); | ||
797 | 714 | ||
798 | error = sizeof(cfg); | 715 | child->bts = ds_request_bts(child, child->bts_buffer, child->bts_size, |
716 | /* ovfl = */ NULL, /* th = */ (size_t)-1, | ||
717 | flags); | ||
718 | if (IS_ERR(child->bts)) { | ||
719 | int error = PTR_ERR(child->bts); | ||
799 | 720 | ||
800 | out: | 721 | ptrace_bts_free_buffer(child); |
801 | if (child->thread.debugctlmsr) | 722 | child->bts = NULL; |
802 | set_tsk_thread_flag(child, TIF_DEBUGCTLMSR); | ||
803 | else | ||
804 | clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR); | ||
805 | 723 | ||
806 | return error; | 724 | return error; |
725 | } | ||
807 | 726 | ||
808 | errout: | 727 | return sizeof(cfg); |
809 | child->thread.debugctlmsr &= ~bts_cfg.debugctl_mask; | ||
810 | clear_tsk_thread_flag(child, TIF_BTS_TRACE_TS); | ||
811 | goto out; | ||
812 | } | 728 | } |
813 | 729 | ||
814 | static int ptrace_bts_status(struct task_struct *child, | 730 | static int ptrace_bts_status(struct task_struct *child, |
815 | long cfg_size, | 731 | long cfg_size, |
816 | struct ptrace_bts_config __user *ucfg) | 732 | struct ptrace_bts_config __user *ucfg) |
817 | { | 733 | { |
734 | const struct bts_trace *trace; | ||
818 | struct ptrace_bts_config cfg; | 735 | struct ptrace_bts_config cfg; |
819 | size_t end; | ||
820 | const void *base, *max; | ||
821 | int error; | ||
822 | 736 | ||
823 | if (cfg_size < sizeof(cfg)) | 737 | if (cfg_size < sizeof(cfg)) |
824 | return -EIO; | 738 | return -EIO; |
825 | 739 | ||
826 | error = ds_get_bts_end(child, &end); | 740 | trace = ds_read_bts(child->bts); |
827 | if (error < 0) | 741 | if (!trace) |
828 | return error; | 742 | return -EPERM; |
829 | |||
830 | error = ds_access_bts(child, /* index = */ 0, &base); | ||
831 | if (error < 0) | ||
832 | return error; | ||
833 | |||
834 | error = ds_access_bts(child, /* index = */ end, &max); | ||
835 | if (error < 0) | ||
836 | return error; | ||
837 | 743 | ||
838 | memset(&cfg, 0, sizeof(cfg)); | 744 | memset(&cfg, 0, sizeof(cfg)); |
839 | cfg.size = (max - base); | 745 | cfg.size = trace->ds.end - trace->ds.begin; |
840 | cfg.signal = child->thread.bts_ovfl_signal; | 746 | cfg.signal = child->thread.bts_ovfl_signal; |
841 | cfg.bts_size = sizeof(struct bts_struct); | 747 | cfg.bts_size = sizeof(struct bts_struct); |
842 | 748 | ||
843 | if (cfg.signal) | 749 | if (cfg.signal) |
844 | cfg.flags |= PTRACE_BTS_O_SIGNAL; | 750 | cfg.flags |= PTRACE_BTS_O_SIGNAL; |
845 | 751 | ||
846 | if (test_tsk_thread_flag(child, TIF_DEBUGCTLMSR) && | 752 | if (trace->ds.flags & BTS_USER) |
847 | child->thread.debugctlmsr & bts_cfg.debugctl_mask) | ||
848 | cfg.flags |= PTRACE_BTS_O_TRACE; | 753 | cfg.flags |= PTRACE_BTS_O_TRACE; |
849 | 754 | ||
850 | if (test_tsk_thread_flag(child, TIF_BTS_TRACE_TS)) | 755 | if (trace->ds.flags & BTS_TIMESTAMPS) |
851 | cfg.flags |= PTRACE_BTS_O_SCHED; | 756 | cfg.flags |= PTRACE_BTS_O_SCHED; |
852 | 757 | ||
853 | if (copy_to_user(ucfg, &cfg, sizeof(cfg))) | 758 | if (copy_to_user(ucfg, &cfg, sizeof(cfg))) |
@@ -856,110 +761,77 @@ static int ptrace_bts_status(struct task_struct *child, | |||
856 | return sizeof(cfg); | 761 | return sizeof(cfg); |
857 | } | 762 | } |
858 | 763 | ||
859 | static int ptrace_bts_write_record(struct task_struct *child, | 764 | static int ptrace_bts_clear(struct task_struct *child) |
860 | const struct bts_struct *in) | ||
861 | { | 765 | { |
862 | unsigned char bts_record[BTS_MAX_RECORD_SIZE]; | 766 | const struct bts_trace *trace; |
863 | 767 | ||
864 | BUG_ON(BTS_MAX_RECORD_SIZE < bts_cfg.sizeof_bts); | 768 | trace = ds_read_bts(child->bts); |
769 | if (!trace) | ||
770 | return -EPERM; | ||
865 | 771 | ||
866 | memset(bts_record, 0, bts_cfg.sizeof_bts); | 772 | memset(trace->ds.begin, 0, trace->ds.n * trace->ds.size); |
867 | switch (in->qualifier) { | ||
868 | case BTS_INVALID: | ||
869 | break; | ||
870 | 773 | ||
871 | case BTS_BRANCH: | 774 | return ds_reset_bts(child->bts); |
872 | bts_set(bts_record, bts_from, in->variant.lbr.from_ip); | 775 | } |
873 | bts_set(bts_record, bts_to, in->variant.lbr.to_ip); | ||
874 | break; | ||
875 | 776 | ||
876 | case BTS_TASK_ARRIVES: | 777 | static int ptrace_bts_size(struct task_struct *child) |
877 | case BTS_TASK_DEPARTS: | 778 | { |
878 | bts_set(bts_record, bts_from, bts_escape); | 779 | const struct bts_trace *trace; |
879 | bts_set(bts_record, bts_qual, in->qualifier); | ||
880 | bts_set(bts_record, bts_jiffies, in->variant.jiffies); | ||
881 | break; | ||
882 | 780 | ||
883 | default: | 781 | trace = ds_read_bts(child->bts); |
884 | return -EINVAL; | 782 | if (!trace) |
885 | } | 783 | return -EPERM; |
886 | 784 | ||
887 | /* The writing task will be the switched-to task on a context | 785 | return (trace->ds.top - trace->ds.begin) / trace->ds.size; |
888 | * switch. It needs to write into the switched-from task's BTS | ||
889 | * buffer. */ | ||
890 | return ds_unchecked_write_bts(child, bts_record, bts_cfg.sizeof_bts); | ||
891 | } | 786 | } |
892 | 787 | ||
893 | void ptrace_bts_take_timestamp(struct task_struct *tsk, | 788 | static void ptrace_bts_fork(struct task_struct *tsk) |
894 | enum bts_qualifier qualifier) | ||
895 | { | 789 | { |
896 | struct bts_struct rec = { | 790 | tsk->bts = NULL; |
897 | .qualifier = qualifier, | 791 | tsk->bts_buffer = NULL; |
898 | .variant.jiffies = jiffies_64 | 792 | tsk->bts_size = 0; |
899 | }; | 793 | tsk->thread.bts_ovfl_signal = 0; |
900 | |||
901 | ptrace_bts_write_record(tsk, &rec); | ||
902 | } | 794 | } |
903 | 795 | ||
904 | static const struct bts_configuration bts_cfg_netburst = { | 796 | static void ptrace_bts_untrace(struct task_struct *child) |
905 | .sizeof_bts = sizeof(long) * 3, | 797 | { |
906 | .sizeof_field = sizeof(long), | 798 | if (unlikely(child->bts)) { |
907 | .debugctl_mask = (1<<2)|(1<<3)|(1<<5) | 799 | ds_release_bts(child->bts); |
908 | }; | 800 | child->bts = NULL; |
801 | |||
802 | /* We cannot update total_vm and locked_vm since | ||
803 | child's mm is already gone. But we can reclaim the | ||
804 | memory. */ | ||
805 | kfree(child->bts_buffer); | ||
806 | child->bts_buffer = NULL; | ||
807 | child->bts_size = 0; | ||
808 | } | ||
809 | } | ||
909 | 810 | ||
910 | static const struct bts_configuration bts_cfg_pentium_m = { | 811 | static void ptrace_bts_detach(struct task_struct *child) |
911 | .sizeof_bts = sizeof(long) * 3, | 812 | { |
912 | .sizeof_field = sizeof(long), | 813 | if (unlikely(child->bts)) { |
913 | .debugctl_mask = (1<<6)|(1<<7) | 814 | ds_release_bts(child->bts); |
914 | }; | 815 | child->bts = NULL; |
915 | 816 | ||
916 | static const struct bts_configuration bts_cfg_core2 = { | 817 | ptrace_bts_free_buffer(child); |
917 | .sizeof_bts = 8 * 3, | 818 | } |
918 | .sizeof_field = 8, | 819 | } |
919 | .debugctl_mask = (1<<6)|(1<<7)|(1<<9) | 820 | #else |
920 | }; | 821 | static inline void ptrace_bts_fork(struct task_struct *tsk) {} |
822 | static inline void ptrace_bts_detach(struct task_struct *child) {} | ||
823 | static inline void ptrace_bts_untrace(struct task_struct *child) {} | ||
824 | #endif /* CONFIG_X86_PTRACE_BTS */ | ||
921 | 825 | ||
922 | static inline void bts_configure(const struct bts_configuration *cfg) | 826 | void x86_ptrace_fork(struct task_struct *child, unsigned long clone_flags) |
923 | { | 827 | { |
924 | bts_cfg = *cfg; | 828 | ptrace_bts_fork(child); |
925 | } | 829 | } |
926 | 830 | ||
927 | void __cpuinit ptrace_bts_init_intel(struct cpuinfo_x86 *c) | 831 | void x86_ptrace_untrace(struct task_struct *child) |
928 | { | 832 | { |
929 | switch (c->x86) { | 833 | ptrace_bts_untrace(child); |
930 | case 0x6: | ||
931 | switch (c->x86_model) { | ||
932 | case 0xD: | ||
933 | case 0xE: /* Pentium M */ | ||
934 | bts_configure(&bts_cfg_pentium_m); | ||
935 | break; | ||
936 | case 0xF: /* Core2 */ | ||
937 | case 0x1C: /* Atom */ | ||
938 | bts_configure(&bts_cfg_core2); | ||
939 | break; | ||
940 | default: | ||
941 | /* sorry, don't know about them */ | ||
942 | break; | ||
943 | } | ||
944 | break; | ||
945 | case 0xF: | ||
946 | switch (c->x86_model) { | ||
947 | case 0x0: | ||
948 | case 0x1: | ||
949 | case 0x2: /* Netburst */ | ||
950 | bts_configure(&bts_cfg_netburst); | ||
951 | break; | ||
952 | default: | ||
953 | /* sorry, don't know about them */ | ||
954 | break; | ||
955 | } | ||
956 | break; | ||
957 | default: | ||
958 | /* sorry, don't know about them */ | ||
959 | break; | ||
960 | } | ||
961 | } | 834 | } |
962 | #endif /* CONFIG_X86_PTRACE_BTS */ | ||
963 | 835 | ||
964 | /* | 836 | /* |
965 | * Called by kernel/ptrace.c when detaching.. | 837 | * Called by kernel/ptrace.c when detaching.. |
@@ -972,15 +844,7 @@ void ptrace_disable(struct task_struct *child) | |||
972 | #ifdef TIF_SYSCALL_EMU | 844 | #ifdef TIF_SYSCALL_EMU |
973 | clear_tsk_thread_flag(child, TIF_SYSCALL_EMU); | 845 | clear_tsk_thread_flag(child, TIF_SYSCALL_EMU); |
974 | #endif | 846 | #endif |
975 | #ifdef CONFIG_X86_PTRACE_BTS | 847 | ptrace_bts_detach(child); |
976 | (void)ds_release_bts(child); | ||
977 | |||
978 | child->thread.debugctlmsr &= ~bts_cfg.debugctl_mask; | ||
979 | if (!child->thread.debugctlmsr) | ||
980 | clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR); | ||
981 | |||
982 | clear_tsk_thread_flag(child, TIF_BTS_TRACE_TS); | ||
983 | #endif /* CONFIG_X86_PTRACE_BTS */ | ||
984 | } | 848 | } |
985 | 849 | ||
986 | #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION | 850 | #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION |
@@ -1112,7 +976,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data) | |||
1112 | break; | 976 | break; |
1113 | 977 | ||
1114 | case PTRACE_BTS_SIZE: | 978 | case PTRACE_BTS_SIZE: |
1115 | ret = ds_get_bts_index(child, /* pos = */ NULL); | 979 | ret = ptrace_bts_size(child); |
1116 | break; | 980 | break; |
1117 | 981 | ||
1118 | case PTRACE_BTS_GET: | 982 | case PTRACE_BTS_GET: |
@@ -1121,7 +985,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data) | |||
1121 | break; | 985 | break; |
1122 | 986 | ||
1123 | case PTRACE_BTS_CLEAR: | 987 | case PTRACE_BTS_CLEAR: |
1124 | ret = ds_clear_bts(child); | 988 | ret = ptrace_bts_clear(child); |
1125 | break; | 989 | break; |
1126 | 990 | ||
1127 | case PTRACE_BTS_DRAIN: | 991 | case PTRACE_BTS_DRAIN: |
@@ -1384,6 +1248,14 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request, | |||
1384 | 1248 | ||
1385 | case PTRACE_GET_THREAD_AREA: | 1249 | case PTRACE_GET_THREAD_AREA: |
1386 | case PTRACE_SET_THREAD_AREA: | 1250 | case PTRACE_SET_THREAD_AREA: |
1251 | #ifdef CONFIG_X86_PTRACE_BTS | ||
1252 | case PTRACE_BTS_CONFIG: | ||
1253 | case PTRACE_BTS_STATUS: | ||
1254 | case PTRACE_BTS_SIZE: | ||
1255 | case PTRACE_BTS_GET: | ||
1256 | case PTRACE_BTS_CLEAR: | ||
1257 | case PTRACE_BTS_DRAIN: | ||
1258 | #endif /* CONFIG_X86_PTRACE_BTS */ | ||
1387 | return arch_ptrace(child, request, addr, data); | 1259 | return arch_ptrace(child, request, addr, data); |
1388 | 1260 | ||
1389 | default: | 1261 | default: |
diff --git a/arch/x86/kernel/quirks.c b/arch/x86/kernel/quirks.c index 67465ed89310..309949e9e1c1 100644 --- a/arch/x86/kernel/quirks.c +++ b/arch/x86/kernel/quirks.c | |||
@@ -168,6 +168,8 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_31, | |||
168 | ich_force_enable_hpet); | 168 | ich_force_enable_hpet); |
169 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_1, | 169 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_1, |
170 | ich_force_enable_hpet); | 170 | ich_force_enable_hpet); |
171 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_4, | ||
172 | ich_force_enable_hpet); | ||
171 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_7, | 173 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_7, |
172 | ich_force_enable_hpet); | 174 | ich_force_enable_hpet); |
173 | 175 | ||
diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c index cc5a2545dd41..2b46eb41643b 100644 --- a/arch/x86/kernel/reboot.c +++ b/arch/x86/kernel/reboot.c | |||
@@ -12,6 +12,8 @@ | |||
12 | #include <asm/proto.h> | 12 | #include <asm/proto.h> |
13 | #include <asm/reboot_fixups.h> | 13 | #include <asm/reboot_fixups.h> |
14 | #include <asm/reboot.h> | 14 | #include <asm/reboot.h> |
15 | #include <asm/pci_x86.h> | ||
16 | #include <asm/virtext.h> | ||
15 | 17 | ||
16 | #ifdef CONFIG_X86_32 | 18 | #ifdef CONFIG_X86_32 |
17 | # include <linux/dmi.h> | 19 | # include <linux/dmi.h> |
@@ -21,6 +23,8 @@ | |||
21 | # include <asm/iommu.h> | 23 | # include <asm/iommu.h> |
22 | #endif | 24 | #endif |
23 | 25 | ||
26 | #include <mach_ipi.h> | ||
27 | |||
24 | /* | 28 | /* |
25 | * Power off function, if any | 29 | * Power off function, if any |
26 | */ | 30 | */ |
@@ -36,7 +40,16 @@ int reboot_force; | |||
36 | static int reboot_cpu = -1; | 40 | static int reboot_cpu = -1; |
37 | #endif | 41 | #endif |
38 | 42 | ||
39 | /* reboot=b[ios] | s[mp] | t[riple] | k[bd] | e[fi] [, [w]arm | [c]old] | 43 | /* This is set if we need to go through the 'emergency' path. |
44 | * When machine_emergency_restart() is called, we may be on | ||
45 | * an inconsistent state and won't be able to do a clean cleanup | ||
46 | */ | ||
47 | static int reboot_emergency; | ||
48 | |||
49 | /* This is set by the PCI code if either type 1 or type 2 PCI is detected */ | ||
50 | bool port_cf9_safe = false; | ||
51 | |||
52 | /* reboot=b[ios] | s[mp] | t[riple] | k[bd] | e[fi] [, [w]arm | [c]old] | p[ci] | ||
40 | warm Don't set the cold reboot flag | 53 | warm Don't set the cold reboot flag |
41 | cold Set the cold reboot flag | 54 | cold Set the cold reboot flag |
42 | bios Reboot by jumping through the BIOS (only for X86_32) | 55 | bios Reboot by jumping through the BIOS (only for X86_32) |
@@ -45,6 +58,7 @@ static int reboot_cpu = -1; | |||
45 | kbd Use the keyboard controller. cold reset (default) | 58 | kbd Use the keyboard controller. cold reset (default) |
46 | acpi Use the RESET_REG in the FADT | 59 | acpi Use the RESET_REG in the FADT |
47 | efi Use efi reset_system runtime service | 60 | efi Use efi reset_system runtime service |
61 | pci Use the so-called "PCI reset register", CF9 | ||
48 | force Avoid anything that could hang. | 62 | force Avoid anything that could hang. |
49 | */ | 63 | */ |
50 | static int __init reboot_setup(char *str) | 64 | static int __init reboot_setup(char *str) |
@@ -79,6 +93,7 @@ static int __init reboot_setup(char *str) | |||
79 | case 'k': | 93 | case 'k': |
80 | case 't': | 94 | case 't': |
81 | case 'e': | 95 | case 'e': |
96 | case 'p': | ||
82 | reboot_type = *str; | 97 | reboot_type = *str; |
83 | break; | 98 | break; |
84 | 99 | ||
@@ -360,6 +375,48 @@ static inline void kb_wait(void) | |||
360 | } | 375 | } |
361 | } | 376 | } |
362 | 377 | ||
378 | static void vmxoff_nmi(int cpu, struct die_args *args) | ||
379 | { | ||
380 | cpu_emergency_vmxoff(); | ||
381 | } | ||
382 | |||
383 | /* Use NMIs as IPIs to tell all CPUs to disable virtualization | ||
384 | */ | ||
385 | static void emergency_vmx_disable_all(void) | ||
386 | { | ||
387 | /* Just make sure we won't change CPUs while doing this */ | ||
388 | local_irq_disable(); | ||
389 | |||
390 | /* We need to disable VMX on all CPUs before rebooting, otherwise | ||
391 | * we risk hanging up the machine, because the CPU ignore INIT | ||
392 | * signals when VMX is enabled. | ||
393 | * | ||
394 | * We can't take any locks and we may be on an inconsistent | ||
395 | * state, so we use NMIs as IPIs to tell the other CPUs to disable | ||
396 | * VMX and halt. | ||
397 | * | ||
398 | * For safety, we will avoid running the nmi_shootdown_cpus() | ||
399 | * stuff unnecessarily, but we don't have a way to check | ||
400 | * if other CPUs have VMX enabled. So we will call it only if the | ||
401 | * CPU we are running on has VMX enabled. | ||
402 | * | ||
403 | * We will miss cases where VMX is not enabled on all CPUs. This | ||
404 | * shouldn't do much harm because KVM always enable VMX on all | ||
405 | * CPUs anyway. But we can miss it on the small window where KVM | ||
406 | * is still enabling VMX. | ||
407 | */ | ||
408 | if (cpu_has_vmx() && cpu_vmx_enabled()) { | ||
409 | /* Disable VMX on this CPU. | ||
410 | */ | ||
411 | cpu_vmxoff(); | ||
412 | |||
413 | /* Halt and disable VMX on the other CPUs */ | ||
414 | nmi_shootdown_cpus(vmxoff_nmi); | ||
415 | |||
416 | } | ||
417 | } | ||
418 | |||
419 | |||
363 | void __attribute__((weak)) mach_reboot_fixups(void) | 420 | void __attribute__((weak)) mach_reboot_fixups(void) |
364 | { | 421 | { |
365 | } | 422 | } |
@@ -368,6 +425,9 @@ static void native_machine_emergency_restart(void) | |||
368 | { | 425 | { |
369 | int i; | 426 | int i; |
370 | 427 | ||
428 | if (reboot_emergency) | ||
429 | emergency_vmx_disable_all(); | ||
430 | |||
371 | /* Tell the BIOS if we want cold or warm reboot */ | 431 | /* Tell the BIOS if we want cold or warm reboot */ |
372 | *((unsigned short *)__va(0x472)) = reboot_mode; | 432 | *((unsigned short *)__va(0x472)) = reboot_mode; |
373 | 433 | ||
@@ -404,12 +464,27 @@ static void native_machine_emergency_restart(void) | |||
404 | reboot_type = BOOT_KBD; | 464 | reboot_type = BOOT_KBD; |
405 | break; | 465 | break; |
406 | 466 | ||
407 | |||
408 | case BOOT_EFI: | 467 | case BOOT_EFI: |
409 | if (efi_enabled) | 468 | if (efi_enabled) |
410 | efi.reset_system(reboot_mode ? EFI_RESET_WARM : EFI_RESET_COLD, | 469 | efi.reset_system(reboot_mode ? |
470 | EFI_RESET_WARM : | ||
471 | EFI_RESET_COLD, | ||
411 | EFI_SUCCESS, 0, NULL); | 472 | EFI_SUCCESS, 0, NULL); |
473 | reboot_type = BOOT_KBD; | ||
474 | break; | ||
475 | |||
476 | case BOOT_CF9: | ||
477 | port_cf9_safe = true; | ||
478 | /* fall through */ | ||
412 | 479 | ||
480 | case BOOT_CF9_COND: | ||
481 | if (port_cf9_safe) { | ||
482 | u8 cf9 = inb(0xcf9) & ~6; | ||
483 | outb(cf9|2, 0xcf9); /* Request hard reset */ | ||
484 | udelay(50); | ||
485 | outb(cf9|6, 0xcf9); /* Actually do the reset */ | ||
486 | udelay(50); | ||
487 | } | ||
413 | reboot_type = BOOT_KBD; | 488 | reboot_type = BOOT_KBD; |
414 | break; | 489 | break; |
415 | } | 490 | } |
@@ -426,7 +501,7 @@ void native_machine_shutdown(void) | |||
426 | 501 | ||
427 | #ifdef CONFIG_X86_32 | 502 | #ifdef CONFIG_X86_32 |
428 | /* See if there has been given a command line override */ | 503 | /* See if there has been given a command line override */ |
429 | if ((reboot_cpu != -1) && (reboot_cpu < NR_CPUS) && | 504 | if ((reboot_cpu != -1) && (reboot_cpu < nr_cpu_ids) && |
430 | cpu_online(reboot_cpu)) | 505 | cpu_online(reboot_cpu)) |
431 | reboot_cpu_id = reboot_cpu; | 506 | reboot_cpu_id = reboot_cpu; |
432 | #endif | 507 | #endif |
@@ -436,7 +511,7 @@ void native_machine_shutdown(void) | |||
436 | reboot_cpu_id = smp_processor_id(); | 511 | reboot_cpu_id = smp_processor_id(); |
437 | 512 | ||
438 | /* Make certain I only run on the appropriate processor */ | 513 | /* Make certain I only run on the appropriate processor */ |
439 | set_cpus_allowed_ptr(current, &cpumask_of_cpu(reboot_cpu_id)); | 514 | set_cpus_allowed_ptr(current, cpumask_of(reboot_cpu_id)); |
440 | 515 | ||
441 | /* O.K Now that I'm on the appropriate processor, | 516 | /* O.K Now that I'm on the appropriate processor, |
442 | * stop all of the others. | 517 | * stop all of the others. |
@@ -459,17 +534,28 @@ void native_machine_shutdown(void) | |||
459 | #endif | 534 | #endif |
460 | } | 535 | } |
461 | 536 | ||
537 | static void __machine_emergency_restart(int emergency) | ||
538 | { | ||
539 | reboot_emergency = emergency; | ||
540 | machine_ops.emergency_restart(); | ||
541 | } | ||
542 | |||
462 | static void native_machine_restart(char *__unused) | 543 | static void native_machine_restart(char *__unused) |
463 | { | 544 | { |
464 | printk("machine restart\n"); | 545 | printk("machine restart\n"); |
465 | 546 | ||
466 | if (!reboot_force) | 547 | if (!reboot_force) |
467 | machine_shutdown(); | 548 | machine_shutdown(); |
468 | machine_emergency_restart(); | 549 | __machine_emergency_restart(0); |
469 | } | 550 | } |
470 | 551 | ||
471 | static void native_machine_halt(void) | 552 | static void native_machine_halt(void) |
472 | { | 553 | { |
554 | /* stop other cpus and apics */ | ||
555 | machine_shutdown(); | ||
556 | |||
557 | /* stop this cpu */ | ||
558 | stop_this_cpu(NULL); | ||
473 | } | 559 | } |
474 | 560 | ||
475 | static void native_machine_power_off(void) | 561 | static void native_machine_power_off(void) |
@@ -504,7 +590,7 @@ void machine_shutdown(void) | |||
504 | 590 | ||
505 | void machine_emergency_restart(void) | 591 | void machine_emergency_restart(void) |
506 | { | 592 | { |
507 | machine_ops.emergency_restart(); | 593 | __machine_emergency_restart(1); |
508 | } | 594 | } |
509 | 595 | ||
510 | void machine_restart(char *cmd) | 596 | void machine_restart(char *cmd) |
@@ -523,3 +609,92 @@ void machine_crash_shutdown(struct pt_regs *regs) | |||
523 | machine_ops.crash_shutdown(regs); | 609 | machine_ops.crash_shutdown(regs); |
524 | } | 610 | } |
525 | #endif | 611 | #endif |
612 | |||
613 | |||
614 | #if defined(CONFIG_SMP) | ||
615 | |||
616 | /* This keeps a track of which one is crashing cpu. */ | ||
617 | static int crashing_cpu; | ||
618 | static nmi_shootdown_cb shootdown_callback; | ||
619 | |||
620 | static atomic_t waiting_for_crash_ipi; | ||
621 | |||
622 | static int crash_nmi_callback(struct notifier_block *self, | ||
623 | unsigned long val, void *data) | ||
624 | { | ||
625 | int cpu; | ||
626 | |||
627 | if (val != DIE_NMI_IPI) | ||
628 | return NOTIFY_OK; | ||
629 | |||
630 | cpu = raw_smp_processor_id(); | ||
631 | |||
632 | /* Don't do anything if this handler is invoked on crashing cpu. | ||
633 | * Otherwise, system will completely hang. Crashing cpu can get | ||
634 | * an NMI if system was initially booted with nmi_watchdog parameter. | ||
635 | */ | ||
636 | if (cpu == crashing_cpu) | ||
637 | return NOTIFY_STOP; | ||
638 | local_irq_disable(); | ||
639 | |||
640 | shootdown_callback(cpu, (struct die_args *)data); | ||
641 | |||
642 | atomic_dec(&waiting_for_crash_ipi); | ||
643 | /* Assume hlt works */ | ||
644 | halt(); | ||
645 | for (;;) | ||
646 | cpu_relax(); | ||
647 | |||
648 | return 1; | ||
649 | } | ||
650 | |||
651 | static void smp_send_nmi_allbutself(void) | ||
652 | { | ||
653 | send_IPI_allbutself(NMI_VECTOR); | ||
654 | } | ||
655 | |||
656 | static struct notifier_block crash_nmi_nb = { | ||
657 | .notifier_call = crash_nmi_callback, | ||
658 | }; | ||
659 | |||
660 | /* Halt all other CPUs, calling the specified function on each of them | ||
661 | * | ||
662 | * This function can be used to halt all other CPUs on crash | ||
663 | * or emergency reboot time. The function passed as parameter | ||
664 | * will be called inside a NMI handler on all CPUs. | ||
665 | */ | ||
666 | void nmi_shootdown_cpus(nmi_shootdown_cb callback) | ||
667 | { | ||
668 | unsigned long msecs; | ||
669 | local_irq_disable(); | ||
670 | |||
671 | /* Make a note of crashing cpu. Will be used in NMI callback.*/ | ||
672 | crashing_cpu = safe_smp_processor_id(); | ||
673 | |||
674 | shootdown_callback = callback; | ||
675 | |||
676 | atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1); | ||
677 | /* Would it be better to replace the trap vector here? */ | ||
678 | if (register_die_notifier(&crash_nmi_nb)) | ||
679 | return; /* return what? */ | ||
680 | /* Ensure the new callback function is set before sending | ||
681 | * out the NMI | ||
682 | */ | ||
683 | wmb(); | ||
684 | |||
685 | smp_send_nmi_allbutself(); | ||
686 | |||
687 | msecs = 1000; /* Wait at most a second for the other cpus to stop */ | ||
688 | while ((atomic_read(&waiting_for_crash_ipi) > 0) && msecs) { | ||
689 | mdelay(1); | ||
690 | msecs--; | ||
691 | } | ||
692 | |||
693 | /* Leave the nmi callback set */ | ||
694 | } | ||
695 | #else /* !CONFIG_SMP */ | ||
696 | void nmi_shootdown_cpus(nmi_shootdown_cb callback) | ||
697 | { | ||
698 | /* No other CPUs to shoot down */ | ||
699 | } | ||
700 | #endif | ||
diff --git a/arch/x86/kernel/relocate_kernel_32.S b/arch/x86/kernel/relocate_kernel_32.S index 6f50664b2ba5..a160f3119725 100644 --- a/arch/x86/kernel/relocate_kernel_32.S +++ b/arch/x86/kernel/relocate_kernel_32.S | |||
@@ -10,15 +10,12 @@ | |||
10 | #include <asm/page.h> | 10 | #include <asm/page.h> |
11 | #include <asm/kexec.h> | 11 | #include <asm/kexec.h> |
12 | #include <asm/processor-flags.h> | 12 | #include <asm/processor-flags.h> |
13 | #include <asm/pgtable.h> | ||
14 | 13 | ||
15 | /* | 14 | /* |
16 | * Must be relocatable PIC code callable as a C function | 15 | * Must be relocatable PIC code callable as a C function |
17 | */ | 16 | */ |
18 | 17 | ||
19 | #define PTR(x) (x << 2) | 18 | #define PTR(x) (x << 2) |
20 | #define PAGE_ATTR (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_DIRTY) | ||
21 | #define PAE_PGD_ATTR (_PAGE_PRESENT) | ||
22 | 19 | ||
23 | /* control_page + KEXEC_CONTROL_CODE_MAX_SIZE | 20 | /* control_page + KEXEC_CONTROL_CODE_MAX_SIZE |
24 | * ~ control_page + PAGE_SIZE are used as data storage and stack for | 21 | * ~ control_page + PAGE_SIZE are used as data storage and stack for |
@@ -39,7 +36,6 @@ | |||
39 | #define CP_PA_BACKUP_PAGES_MAP DATA(0x1c) | 36 | #define CP_PA_BACKUP_PAGES_MAP DATA(0x1c) |
40 | 37 | ||
41 | .text | 38 | .text |
42 | .align PAGE_SIZE | ||
43 | .globl relocate_kernel | 39 | .globl relocate_kernel |
44 | relocate_kernel: | 40 | relocate_kernel: |
45 | /* Save the CPU context, used for jumping back */ | 41 | /* Save the CPU context, used for jumping back */ |
@@ -60,117 +56,6 @@ relocate_kernel: | |||
60 | movl %cr4, %eax | 56 | movl %cr4, %eax |
61 | movl %eax, CR4(%edi) | 57 | movl %eax, CR4(%edi) |
62 | 58 | ||
63 | #ifdef CONFIG_X86_PAE | ||
64 | /* map the control page at its virtual address */ | ||
65 | |||
66 | movl PTR(VA_PGD)(%ebp), %edi | ||
67 | movl PTR(VA_CONTROL_PAGE)(%ebp), %eax | ||
68 | andl $0xc0000000, %eax | ||
69 | shrl $27, %eax | ||
70 | addl %edi, %eax | ||
71 | |||
72 | movl PTR(PA_PMD_0)(%ebp), %edx | ||
73 | orl $PAE_PGD_ATTR, %edx | ||
74 | movl %edx, (%eax) | ||
75 | |||
76 | movl PTR(VA_PMD_0)(%ebp), %edi | ||
77 | movl PTR(VA_CONTROL_PAGE)(%ebp), %eax | ||
78 | andl $0x3fe00000, %eax | ||
79 | shrl $18, %eax | ||
80 | addl %edi, %eax | ||
81 | |||
82 | movl PTR(PA_PTE_0)(%ebp), %edx | ||
83 | orl $PAGE_ATTR, %edx | ||
84 | movl %edx, (%eax) | ||
85 | |||
86 | movl PTR(VA_PTE_0)(%ebp), %edi | ||
87 | movl PTR(VA_CONTROL_PAGE)(%ebp), %eax | ||
88 | andl $0x001ff000, %eax | ||
89 | shrl $9, %eax | ||
90 | addl %edi, %eax | ||
91 | |||
92 | movl PTR(PA_CONTROL_PAGE)(%ebp), %edx | ||
93 | orl $PAGE_ATTR, %edx | ||
94 | movl %edx, (%eax) | ||
95 | |||
96 | /* identity map the control page at its physical address */ | ||
97 | |||
98 | movl PTR(VA_PGD)(%ebp), %edi | ||
99 | movl PTR(PA_CONTROL_PAGE)(%ebp), %eax | ||
100 | andl $0xc0000000, %eax | ||
101 | shrl $27, %eax | ||
102 | addl %edi, %eax | ||
103 | |||
104 | movl PTR(PA_PMD_1)(%ebp), %edx | ||
105 | orl $PAE_PGD_ATTR, %edx | ||
106 | movl %edx, (%eax) | ||
107 | |||
108 | movl PTR(VA_PMD_1)(%ebp), %edi | ||
109 | movl PTR(PA_CONTROL_PAGE)(%ebp), %eax | ||
110 | andl $0x3fe00000, %eax | ||
111 | shrl $18, %eax | ||
112 | addl %edi, %eax | ||
113 | |||
114 | movl PTR(PA_PTE_1)(%ebp), %edx | ||
115 | orl $PAGE_ATTR, %edx | ||
116 | movl %edx, (%eax) | ||
117 | |||
118 | movl PTR(VA_PTE_1)(%ebp), %edi | ||
119 | movl PTR(PA_CONTROL_PAGE)(%ebp), %eax | ||
120 | andl $0x001ff000, %eax | ||
121 | shrl $9, %eax | ||
122 | addl %edi, %eax | ||
123 | |||
124 | movl PTR(PA_CONTROL_PAGE)(%ebp), %edx | ||
125 | orl $PAGE_ATTR, %edx | ||
126 | movl %edx, (%eax) | ||
127 | #else | ||
128 | /* map the control page at its virtual address */ | ||
129 | |||
130 | movl PTR(VA_PGD)(%ebp), %edi | ||
131 | movl PTR(VA_CONTROL_PAGE)(%ebp), %eax | ||
132 | andl $0xffc00000, %eax | ||
133 | shrl $20, %eax | ||
134 | addl %edi, %eax | ||
135 | |||
136 | movl PTR(PA_PTE_0)(%ebp), %edx | ||
137 | orl $PAGE_ATTR, %edx | ||
138 | movl %edx, (%eax) | ||
139 | |||
140 | movl PTR(VA_PTE_0)(%ebp), %edi | ||
141 | movl PTR(VA_CONTROL_PAGE)(%ebp), %eax | ||
142 | andl $0x003ff000, %eax | ||
143 | shrl $10, %eax | ||
144 | addl %edi, %eax | ||
145 | |||
146 | movl PTR(PA_CONTROL_PAGE)(%ebp), %edx | ||
147 | orl $PAGE_ATTR, %edx | ||
148 | movl %edx, (%eax) | ||
149 | |||
150 | /* identity map the control page at its physical address */ | ||
151 | |||
152 | movl PTR(VA_PGD)(%ebp), %edi | ||
153 | movl PTR(PA_CONTROL_PAGE)(%ebp), %eax | ||
154 | andl $0xffc00000, %eax | ||
155 | shrl $20, %eax | ||
156 | addl %edi, %eax | ||
157 | |||
158 | movl PTR(PA_PTE_1)(%ebp), %edx | ||
159 | orl $PAGE_ATTR, %edx | ||
160 | movl %edx, (%eax) | ||
161 | |||
162 | movl PTR(VA_PTE_1)(%ebp), %edi | ||
163 | movl PTR(PA_CONTROL_PAGE)(%ebp), %eax | ||
164 | andl $0x003ff000, %eax | ||
165 | shrl $10, %eax | ||
166 | addl %edi, %eax | ||
167 | |||
168 | movl PTR(PA_CONTROL_PAGE)(%ebp), %edx | ||
169 | orl $PAGE_ATTR, %edx | ||
170 | movl %edx, (%eax) | ||
171 | #endif | ||
172 | |||
173 | relocate_new_kernel: | ||
174 | /* read the arguments and say goodbye to the stack */ | 59 | /* read the arguments and say goodbye to the stack */ |
175 | movl 20+4(%esp), %ebx /* page_list */ | 60 | movl 20+4(%esp), %ebx /* page_list */ |
176 | movl 20+8(%esp), %ebp /* list of pages */ | 61 | movl 20+8(%esp), %ebp /* list of pages */ |
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index bdec76e55594..ae0d8042cf69 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c | |||
@@ -93,11 +93,13 @@ | |||
93 | #include <asm/desc.h> | 93 | #include <asm/desc.h> |
94 | #include <asm/dma.h> | 94 | #include <asm/dma.h> |
95 | #include <asm/iommu.h> | 95 | #include <asm/iommu.h> |
96 | #include <asm/gart.h> | ||
96 | #include <asm/mmu_context.h> | 97 | #include <asm/mmu_context.h> |
97 | #include <asm/proto.h> | 98 | #include <asm/proto.h> |
98 | 99 | ||
99 | #include <mach_apic.h> | 100 | #include <mach_apic.h> |
100 | #include <asm/paravirt.h> | 101 | #include <asm/paravirt.h> |
102 | #include <asm/hypervisor.h> | ||
101 | 103 | ||
102 | #include <asm/percpu.h> | 104 | #include <asm/percpu.h> |
103 | #include <asm/topology.h> | 105 | #include <asm/topology.h> |
@@ -448,6 +450,7 @@ static void __init reserve_early_setup_data(void) | |||
448 | * @size: Size of the crashkernel memory to reserve. | 450 | * @size: Size of the crashkernel memory to reserve. |
449 | * Returns the base address on success, and -1ULL on failure. | 451 | * Returns the base address on success, and -1ULL on failure. |
450 | */ | 452 | */ |
453 | static | ||
451 | unsigned long long __init find_and_reserve_crashkernel(unsigned long long size) | 454 | unsigned long long __init find_and_reserve_crashkernel(unsigned long long size) |
452 | { | 455 | { |
453 | const unsigned long long alignment = 16<<20; /* 16M */ | 456 | const unsigned long long alignment = 16<<20; /* 16M */ |
@@ -583,161 +586,24 @@ static int __init setup_elfcorehdr(char *arg) | |||
583 | early_param("elfcorehdr", setup_elfcorehdr); | 586 | early_param("elfcorehdr", setup_elfcorehdr); |
584 | #endif | 587 | #endif |
585 | 588 | ||
586 | static struct x86_quirks default_x86_quirks __initdata; | 589 | static int __init default_update_genapic(void) |
587 | |||
588 | struct x86_quirks *x86_quirks __initdata = &default_x86_quirks; | ||
589 | |||
590 | /* | ||
591 | * Some BIOSes seem to corrupt the low 64k of memory during events | ||
592 | * like suspend/resume and unplugging an HDMI cable. Reserve all | ||
593 | * remaining free memory in that area and fill it with a distinct | ||
594 | * pattern. | ||
595 | */ | ||
596 | #ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION | ||
597 | #define MAX_SCAN_AREAS 8 | ||
598 | |||
599 | static int __read_mostly memory_corruption_check = -1; | ||
600 | |||
601 | static unsigned __read_mostly corruption_check_size = 64*1024; | ||
602 | static unsigned __read_mostly corruption_check_period = 60; /* seconds */ | ||
603 | |||
604 | static struct e820entry scan_areas[MAX_SCAN_AREAS]; | ||
605 | static int num_scan_areas; | ||
606 | |||
607 | |||
608 | static int set_corruption_check(char *arg) | ||
609 | { | ||
610 | char *end; | ||
611 | |||
612 | memory_corruption_check = simple_strtol(arg, &end, 10); | ||
613 | |||
614 | return (*end == 0) ? 0 : -EINVAL; | ||
615 | } | ||
616 | early_param("memory_corruption_check", set_corruption_check); | ||
617 | |||
618 | static int set_corruption_check_period(char *arg) | ||
619 | { | ||
620 | char *end; | ||
621 | |||
622 | corruption_check_period = simple_strtoul(arg, &end, 10); | ||
623 | |||
624 | return (*end == 0) ? 0 : -EINVAL; | ||
625 | } | ||
626 | early_param("memory_corruption_check_period", set_corruption_check_period); | ||
627 | |||
628 | static int set_corruption_check_size(char *arg) | ||
629 | { | 590 | { |
630 | char *end; | 591 | #ifdef CONFIG_X86_SMP |
631 | unsigned size; | 592 | # if defined(CONFIG_X86_GENERICARCH) || defined(CONFIG_X86_64) |
632 | 593 | genapic->wakeup_cpu = wakeup_secondary_cpu_via_init; | |
633 | size = memparse(arg, &end); | 594 | # endif |
634 | |||
635 | if (*end == '\0') | ||
636 | corruption_check_size = size; | ||
637 | |||
638 | return (size == corruption_check_size) ? 0 : -EINVAL; | ||
639 | } | ||
640 | early_param("memory_corruption_check_size", set_corruption_check_size); | ||
641 | |||
642 | |||
643 | static void __init setup_bios_corruption_check(void) | ||
644 | { | ||
645 | u64 addr = PAGE_SIZE; /* assume first page is reserved anyway */ | ||
646 | |||
647 | if (memory_corruption_check == -1) { | ||
648 | memory_corruption_check = | ||
649 | #ifdef CONFIG_X86_BOOTPARAM_MEMORY_CORRUPTION_CHECK | ||
650 | 1 | ||
651 | #else | ||
652 | 0 | ||
653 | #endif | 595 | #endif |
654 | ; | ||
655 | } | ||
656 | |||
657 | if (corruption_check_size == 0) | ||
658 | memory_corruption_check = 0; | ||
659 | |||
660 | if (!memory_corruption_check) | ||
661 | return; | ||
662 | |||
663 | corruption_check_size = round_up(corruption_check_size, PAGE_SIZE); | ||
664 | 596 | ||
665 | while(addr < corruption_check_size && num_scan_areas < MAX_SCAN_AREAS) { | 597 | return 0; |
666 | u64 size; | ||
667 | addr = find_e820_area_size(addr, &size, PAGE_SIZE); | ||
668 | |||
669 | if (addr == 0) | ||
670 | break; | ||
671 | |||
672 | if ((addr + size) > corruption_check_size) | ||
673 | size = corruption_check_size - addr; | ||
674 | |||
675 | if (size == 0) | ||
676 | break; | ||
677 | |||
678 | e820_update_range(addr, size, E820_RAM, E820_RESERVED); | ||
679 | scan_areas[num_scan_areas].addr = addr; | ||
680 | scan_areas[num_scan_areas].size = size; | ||
681 | num_scan_areas++; | ||
682 | |||
683 | /* Assume we've already mapped this early memory */ | ||
684 | memset(__va(addr), 0, size); | ||
685 | |||
686 | addr += size; | ||
687 | } | ||
688 | |||
689 | printk(KERN_INFO "Scanning %d areas for low memory corruption\n", | ||
690 | num_scan_areas); | ||
691 | update_e820(); | ||
692 | } | ||
693 | |||
694 | static struct timer_list periodic_check_timer; | ||
695 | |||
696 | void check_for_bios_corruption(void) | ||
697 | { | ||
698 | int i; | ||
699 | int corruption = 0; | ||
700 | |||
701 | if (!memory_corruption_check) | ||
702 | return; | ||
703 | |||
704 | for(i = 0; i < num_scan_areas; i++) { | ||
705 | unsigned long *addr = __va(scan_areas[i].addr); | ||
706 | unsigned long size = scan_areas[i].size; | ||
707 | |||
708 | for(; size; addr++, size -= sizeof(unsigned long)) { | ||
709 | if (!*addr) | ||
710 | continue; | ||
711 | printk(KERN_ERR "Corrupted low memory at %p (%lx phys) = %08lx\n", | ||
712 | addr, __pa(addr), *addr); | ||
713 | corruption = 1; | ||
714 | *addr = 0; | ||
715 | } | ||
716 | } | ||
717 | |||
718 | WARN(corruption, KERN_ERR "Memory corruption detected in low memory\n"); | ||
719 | } | ||
720 | |||
721 | static void periodic_check_for_corruption(unsigned long data) | ||
722 | { | ||
723 | check_for_bios_corruption(); | ||
724 | mod_timer(&periodic_check_timer, round_jiffies(jiffies + corruption_check_period*HZ)); | ||
725 | } | 598 | } |
726 | 599 | ||
727 | void start_periodic_check_for_corruption(void) | 600 | static struct x86_quirks default_x86_quirks __initdata = { |
728 | { | 601 | .update_genapic = default_update_genapic, |
729 | if (!memory_corruption_check || corruption_check_period == 0) | 602 | }; |
730 | return; | ||
731 | |||
732 | printk(KERN_INFO "Scanning for low memory corruption every %d seconds\n", | ||
733 | corruption_check_period); | ||
734 | 603 | ||
735 | init_timer(&periodic_check_timer); | 604 | struct x86_quirks *x86_quirks __initdata = &default_x86_quirks; |
736 | periodic_check_timer.function = &periodic_check_for_corruption; | ||
737 | periodic_check_for_corruption(0); | ||
738 | } | ||
739 | #endif | ||
740 | 605 | ||
606 | #ifdef CONFIG_X86_RESERVE_LOW_64K | ||
741 | static int __init dmi_low_memory_corruption(const struct dmi_system_id *d) | 607 | static int __init dmi_low_memory_corruption(const struct dmi_system_id *d) |
742 | { | 608 | { |
743 | printk(KERN_NOTICE | 609 | printk(KERN_NOTICE |
@@ -749,6 +615,7 @@ static int __init dmi_low_memory_corruption(const struct dmi_system_id *d) | |||
749 | 615 | ||
750 | return 0; | 616 | return 0; |
751 | } | 617 | } |
618 | #endif | ||
752 | 619 | ||
753 | /* List of systems that have known low memory corruption BIOS problems */ | 620 | /* List of systems that have known low memory corruption BIOS problems */ |
754 | static struct dmi_system_id __initdata bad_bios_dmi_table[] = { | 621 | static struct dmi_system_id __initdata bad_bios_dmi_table[] = { |
@@ -907,6 +774,12 @@ void __init setup_arch(char **cmdline_p) | |||
907 | 774 | ||
908 | dmi_check_system(bad_bios_dmi_table); | 775 | dmi_check_system(bad_bios_dmi_table); |
909 | 776 | ||
777 | /* | ||
778 | * VMware detection requires dmi to be available, so this | ||
779 | * needs to be done after dmi_scan_machine, for the BP. | ||
780 | */ | ||
781 | init_hypervisor(&boot_cpu_data); | ||
782 | |||
910 | #ifdef CONFIG_X86_32 | 783 | #ifdef CONFIG_X86_32 |
911 | probe_roms(); | 784 | probe_roms(); |
912 | #endif | 785 | #endif |
@@ -1080,7 +953,7 @@ void __init setup_arch(char **cmdline_p) | |||
1080 | ioapic_init_mappings(); | 953 | ioapic_init_mappings(); |
1081 | 954 | ||
1082 | /* need to wait for io_apic is mapped */ | 955 | /* need to wait for io_apic is mapped */ |
1083 | nr_irqs = probe_nr_irqs(); | 956 | probe_nr_irqs_gsi(); |
1084 | 957 | ||
1085 | kvm_guest_init(); | 958 | kvm_guest_init(); |
1086 | 959 | ||
diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c index ae0c0d3bb770..a4b619c33106 100644 --- a/arch/x86/kernel/setup_percpu.c +++ b/arch/x86/kernel/setup_percpu.c | |||
@@ -152,8 +152,11 @@ void __init setup_per_cpu_areas(void) | |||
152 | old_size = PERCPU_ENOUGH_ROOM; | 152 | old_size = PERCPU_ENOUGH_ROOM; |
153 | align = max_t(unsigned long, PAGE_SIZE, align); | 153 | align = max_t(unsigned long, PAGE_SIZE, align); |
154 | size = roundup(old_size, align); | 154 | size = roundup(old_size, align); |
155 | printk(KERN_INFO "PERCPU: Allocating %zd bytes of per cpu data\n", | 155 | |
156 | size); | 156 | pr_info("NR_CPUS:%d nr_cpumask_bits:%d nr_cpu_ids:%d nr_node_ids:%d\n", |
157 | NR_CPUS, nr_cpumask_bits, nr_cpu_ids, nr_node_ids); | ||
158 | |||
159 | pr_info("PERCPU: Allocating %zd bytes of per cpu data\n", size); | ||
157 | 160 | ||
158 | for_each_possible_cpu(cpu) { | 161 | for_each_possible_cpu(cpu) { |
159 | #ifndef CONFIG_NEED_MULTIPLE_NODES | 162 | #ifndef CONFIG_NEED_MULTIPLE_NODES |
@@ -164,28 +167,21 @@ void __init setup_per_cpu_areas(void) | |||
164 | if (!node_online(node) || !NODE_DATA(node)) { | 167 | if (!node_online(node) || !NODE_DATA(node)) { |
165 | ptr = __alloc_bootmem(size, align, | 168 | ptr = __alloc_bootmem(size, align, |
166 | __pa(MAX_DMA_ADDRESS)); | 169 | __pa(MAX_DMA_ADDRESS)); |
167 | printk(KERN_INFO | 170 | pr_info("cpu %d has no node %d or node-local memory\n", |
168 | "cpu %d has no node %d or node-local memory\n", | ||
169 | cpu, node); | 171 | cpu, node); |
170 | if (ptr) | 172 | pr_debug("per cpu data for cpu%d at %016lx\n", |
171 | printk(KERN_DEBUG "per cpu data for cpu%d at %016lx\n", | 173 | cpu, __pa(ptr)); |
172 | cpu, __pa(ptr)); | 174 | } else { |
173 | } | ||
174 | else { | ||
175 | ptr = __alloc_bootmem_node(NODE_DATA(node), size, align, | 175 | ptr = __alloc_bootmem_node(NODE_DATA(node), size, align, |
176 | __pa(MAX_DMA_ADDRESS)); | 176 | __pa(MAX_DMA_ADDRESS)); |
177 | if (ptr) | 177 | pr_debug("per cpu data for cpu%d on node%d at %016lx\n", |
178 | printk(KERN_DEBUG "per cpu data for cpu%d on node%d at %016lx\n", | 178 | cpu, node, __pa(ptr)); |
179 | cpu, node, __pa(ptr)); | ||
180 | } | 179 | } |
181 | #endif | 180 | #endif |
182 | per_cpu_offset(cpu) = ptr - __per_cpu_start; | 181 | per_cpu_offset(cpu) = ptr - __per_cpu_start; |
183 | memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start); | 182 | memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start); |
184 | } | 183 | } |
185 | 184 | ||
186 | printk(KERN_DEBUG "NR_CPUS: %d, nr_cpu_ids: %d, nr_node_ids %d\n", | ||
187 | NR_CPUS, nr_cpu_ids, nr_node_ids); | ||
188 | |||
189 | /* Setup percpu data maps */ | 185 | /* Setup percpu data maps */ |
190 | setup_per_cpu_maps(); | 186 | setup_per_cpu_maps(); |
191 | 187 | ||
@@ -282,7 +278,7 @@ static void __cpuinit numa_set_cpumask(int cpu, int enable) | |||
282 | else | 278 | else |
283 | cpu_clear(cpu, *mask); | 279 | cpu_clear(cpu, *mask); |
284 | 280 | ||
285 | cpulist_scnprintf(buf, sizeof(buf), *mask); | 281 | cpulist_scnprintf(buf, sizeof(buf), mask); |
286 | printk(KERN_DEBUG "%s cpu %d node %d: mask now %s\n", | 282 | printk(KERN_DEBUG "%s cpu %d node %d: mask now %s\n", |
287 | enable? "numa_add_cpu":"numa_remove_cpu", cpu, node, buf); | 283 | enable? "numa_add_cpu":"numa_remove_cpu", cpu, node, buf); |
288 | } | 284 | } |
@@ -334,25 +330,25 @@ static const cpumask_t cpu_mask_none; | |||
334 | /* | 330 | /* |
335 | * Returns a pointer to the bitmask of CPUs on Node 'node'. | 331 | * Returns a pointer to the bitmask of CPUs on Node 'node'. |
336 | */ | 332 | */ |
337 | const cpumask_t *_node_to_cpumask_ptr(int node) | 333 | const cpumask_t *cpumask_of_node(int node) |
338 | { | 334 | { |
339 | if (node_to_cpumask_map == NULL) { | 335 | if (node_to_cpumask_map == NULL) { |
340 | printk(KERN_WARNING | 336 | printk(KERN_WARNING |
341 | "_node_to_cpumask_ptr(%d): no node_to_cpumask_map!\n", | 337 | "cpumask_of_node(%d): no node_to_cpumask_map!\n", |
342 | node); | 338 | node); |
343 | dump_stack(); | 339 | dump_stack(); |
344 | return (const cpumask_t *)&cpu_online_map; | 340 | return (const cpumask_t *)&cpu_online_map; |
345 | } | 341 | } |
346 | if (node >= nr_node_ids) { | 342 | if (node >= nr_node_ids) { |
347 | printk(KERN_WARNING | 343 | printk(KERN_WARNING |
348 | "_node_to_cpumask_ptr(%d): node > nr_node_ids(%d)\n", | 344 | "cpumask_of_node(%d): node > nr_node_ids(%d)\n", |
349 | node, nr_node_ids); | 345 | node, nr_node_ids); |
350 | dump_stack(); | 346 | dump_stack(); |
351 | return &cpu_mask_none; | 347 | return &cpu_mask_none; |
352 | } | 348 | } |
353 | return &node_to_cpumask_map[node]; | 349 | return &node_to_cpumask_map[node]; |
354 | } | 350 | } |
355 | EXPORT_SYMBOL(_node_to_cpumask_ptr); | 351 | EXPORT_SYMBOL(cpumask_of_node); |
356 | 352 | ||
357 | /* | 353 | /* |
358 | * Returns a bitmask of CPUs on Node 'node'. | 354 | * Returns a bitmask of CPUs on Node 'node'. |
diff --git a/arch/x86/kernel/sigframe.h b/arch/x86/kernel/sigframe.h deleted file mode 100644 index cc673aa55ce4..000000000000 --- a/arch/x86/kernel/sigframe.h +++ /dev/null | |||
@@ -1,42 +0,0 @@ | |||
1 | #ifdef CONFIG_X86_32 | ||
2 | struct sigframe { | ||
3 | char __user *pretcode; | ||
4 | int sig; | ||
5 | struct sigcontext sc; | ||
6 | /* | ||
7 | * fpstate is unused. fpstate is moved/allocated after | ||
8 | * retcode[] below. This movement allows to have the FP state and the | ||
9 | * future state extensions (xsave) stay together. | ||
10 | * And at the same time retaining the unused fpstate, prevents changing | ||
11 | * the offset of extramask[] in the sigframe and thus prevent any | ||
12 | * legacy application accessing/modifying it. | ||
13 | */ | ||
14 | struct _fpstate fpstate_unused; | ||
15 | unsigned long extramask[_NSIG_WORDS-1]; | ||
16 | char retcode[8]; | ||
17 | /* fp state follows here */ | ||
18 | }; | ||
19 | |||
20 | struct rt_sigframe { | ||
21 | char __user *pretcode; | ||
22 | int sig; | ||
23 | struct siginfo __user *pinfo; | ||
24 | void __user *puc; | ||
25 | struct siginfo info; | ||
26 | struct ucontext uc; | ||
27 | char retcode[8]; | ||
28 | /* fp state follows here */ | ||
29 | }; | ||
30 | #else | ||
31 | struct rt_sigframe { | ||
32 | char __user *pretcode; | ||
33 | struct ucontext uc; | ||
34 | struct siginfo info; | ||
35 | /* fp state follows here */ | ||
36 | }; | ||
37 | |||
38 | int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, | ||
39 | sigset_t *set, struct pt_regs *regs); | ||
40 | int ia32_setup_frame(int sig, struct k_sigaction *ka, | ||
41 | sigset_t *set, struct pt_regs *regs); | ||
42 | #endif | ||
diff --git a/arch/x86/kernel/signal_32.c b/arch/x86/kernel/signal.c index d6dd057d0f22..89bb7668041d 100644 --- a/arch/x86/kernel/signal_32.c +++ b/arch/x86/kernel/signal.c | |||
@@ -1,36 +1,41 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 1991, 1992 Linus Torvalds | 2 | * Copyright (C) 1991, 1992 Linus Torvalds |
3 | * Copyright (C) 2000, 2001, 2002 Andi Kleen SuSE Labs | ||
3 | * | 4 | * |
4 | * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson | 5 | * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson |
5 | * 2000-06-20 Pentium III FXSR, SSE support by Gareth Hughes | 6 | * 2000-06-20 Pentium III FXSR, SSE support by Gareth Hughes |
7 | * 2000-2002 x86-64 support by Andi Kleen | ||
6 | */ | 8 | */ |
7 | #include <linux/list.h> | ||
8 | 9 | ||
9 | #include <linux/personality.h> | 10 | #include <linux/sched.h> |
10 | #include <linux/binfmts.h> | 11 | #include <linux/mm.h> |
11 | #include <linux/suspend.h> | 12 | #include <linux/smp.h> |
12 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
13 | #include <linux/ptrace.h> | ||
14 | #include <linux/signal.h> | 14 | #include <linux/signal.h> |
15 | #include <linux/stddef.h> | ||
16 | #include <linux/unistd.h> | ||
17 | #include <linux/errno.h> | 15 | #include <linux/errno.h> |
18 | #include <linux/sched.h> | ||
19 | #include <linux/wait.h> | 16 | #include <linux/wait.h> |
17 | #include <linux/ptrace.h> | ||
20 | #include <linux/tracehook.h> | 18 | #include <linux/tracehook.h> |
21 | #include <linux/elf.h> | 19 | #include <linux/unistd.h> |
22 | #include <linux/smp.h> | 20 | #include <linux/stddef.h> |
23 | #include <linux/mm.h> | 21 | #include <linux/personality.h> |
22 | #include <linux/uaccess.h> | ||
24 | 23 | ||
25 | #include <asm/processor.h> | 24 | #include <asm/processor.h> |
26 | #include <asm/ucontext.h> | 25 | #include <asm/ucontext.h> |
27 | #include <asm/uaccess.h> | ||
28 | #include <asm/i387.h> | 26 | #include <asm/i387.h> |
29 | #include <asm/vdso.h> | 27 | #include <asm/vdso.h> |
28 | |||
29 | #ifdef CONFIG_X86_64 | ||
30 | #include <asm/proto.h> | ||
31 | #include <asm/ia32_unistd.h> | ||
32 | #include <asm/mce.h> | ||
33 | #endif /* CONFIG_X86_64 */ | ||
34 | |||
30 | #include <asm/syscall.h> | 35 | #include <asm/syscall.h> |
31 | #include <asm/syscalls.h> | 36 | #include <asm/syscalls.h> |
32 | 37 | ||
33 | #include "sigframe.h" | 38 | #include <asm/sigframe.h> |
34 | 39 | ||
35 | #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) | 40 | #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) |
36 | 41 | ||
@@ -45,74 +50,6 @@ | |||
45 | # define FIX_EFLAGS __FIX_EFLAGS | 50 | # define FIX_EFLAGS __FIX_EFLAGS |
46 | #endif | 51 | #endif |
47 | 52 | ||
48 | /* | ||
49 | * Atomically swap in the new signal mask, and wait for a signal. | ||
50 | */ | ||
51 | asmlinkage int | ||
52 | sys_sigsuspend(int history0, int history1, old_sigset_t mask) | ||
53 | { | ||
54 | mask &= _BLOCKABLE; | ||
55 | spin_lock_irq(¤t->sighand->siglock); | ||
56 | current->saved_sigmask = current->blocked; | ||
57 | siginitset(¤t->blocked, mask); | ||
58 | recalc_sigpending(); | ||
59 | spin_unlock_irq(¤t->sighand->siglock); | ||
60 | |||
61 | current->state = TASK_INTERRUPTIBLE; | ||
62 | schedule(); | ||
63 | set_restore_sigmask(); | ||
64 | |||
65 | return -ERESTARTNOHAND; | ||
66 | } | ||
67 | |||
68 | asmlinkage int | ||
69 | sys_sigaction(int sig, const struct old_sigaction __user *act, | ||
70 | struct old_sigaction __user *oact) | ||
71 | { | ||
72 | struct k_sigaction new_ka, old_ka; | ||
73 | int ret; | ||
74 | |||
75 | if (act) { | ||
76 | old_sigset_t mask; | ||
77 | |||
78 | if (!access_ok(VERIFY_READ, act, sizeof(*act)) || | ||
79 | __get_user(new_ka.sa.sa_handler, &act->sa_handler) || | ||
80 | __get_user(new_ka.sa.sa_restorer, &act->sa_restorer)) | ||
81 | return -EFAULT; | ||
82 | |||
83 | __get_user(new_ka.sa.sa_flags, &act->sa_flags); | ||
84 | __get_user(mask, &act->sa_mask); | ||
85 | siginitset(&new_ka.sa.sa_mask, mask); | ||
86 | } | ||
87 | |||
88 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); | ||
89 | |||
90 | if (!ret && oact) { | ||
91 | if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) || | ||
92 | __put_user(old_ka.sa.sa_handler, &oact->sa_handler) || | ||
93 | __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer)) | ||
94 | return -EFAULT; | ||
95 | |||
96 | __put_user(old_ka.sa.sa_flags, &oact->sa_flags); | ||
97 | __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask); | ||
98 | } | ||
99 | |||
100 | return ret; | ||
101 | } | ||
102 | |||
103 | asmlinkage int sys_sigaltstack(unsigned long bx) | ||
104 | { | ||
105 | /* | ||
106 | * This is needed to make gcc realize it doesn't own the | ||
107 | * "struct pt_regs" | ||
108 | */ | ||
109 | struct pt_regs *regs = (struct pt_regs *)&bx; | ||
110 | const stack_t __user *uss = (const stack_t __user *)bx; | ||
111 | stack_t __user *uoss = (stack_t __user *)regs->cx; | ||
112 | |||
113 | return do_sigaltstack(uss, uoss, regs->sp); | ||
114 | } | ||
115 | |||
116 | #define COPY(x) { \ | 53 | #define COPY(x) { \ |
117 | err |= __get_user(regs->x, &sc->x); \ | 54 | err |= __get_user(regs->x, &sc->x); \ |
118 | } | 55 | } |
@@ -123,7 +60,7 @@ asmlinkage int sys_sigaltstack(unsigned long bx) | |||
123 | regs->seg = tmp; \ | 60 | regs->seg = tmp; \ |
124 | } | 61 | } |
125 | 62 | ||
126 | #define COPY_SEG_STRICT(seg) { \ | 63 | #define COPY_SEG_CPL3(seg) { \ |
127 | unsigned short tmp; \ | 64 | unsigned short tmp; \ |
128 | err |= __get_user(tmp, &sc->seg); \ | 65 | err |= __get_user(tmp, &sc->seg); \ |
129 | regs->seg = tmp | 3; \ | 66 | regs->seg = tmp | 3; \ |
@@ -135,9 +72,6 @@ asmlinkage int sys_sigaltstack(unsigned long bx) | |||
135 | loadsegment(seg, tmp); \ | 72 | loadsegment(seg, tmp); \ |
136 | } | 73 | } |
137 | 74 | ||
138 | /* | ||
139 | * Do a signal return; undo the signal stack. | ||
140 | */ | ||
141 | static int | 75 | static int |
142 | restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, | 76 | restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, |
143 | unsigned long *pax) | 77 | unsigned long *pax) |
@@ -149,14 +83,36 @@ restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, | |||
149 | /* Always make any pending restarted system calls return -EINTR */ | 83 | /* Always make any pending restarted system calls return -EINTR */ |
150 | current_thread_info()->restart_block.fn = do_no_restart_syscall; | 84 | current_thread_info()->restart_block.fn = do_no_restart_syscall; |
151 | 85 | ||
86 | #ifdef CONFIG_X86_32 | ||
152 | GET_SEG(gs); | 87 | GET_SEG(gs); |
153 | COPY_SEG(fs); | 88 | COPY_SEG(fs); |
154 | COPY_SEG(es); | 89 | COPY_SEG(es); |
155 | COPY_SEG(ds); | 90 | COPY_SEG(ds); |
91 | #endif /* CONFIG_X86_32 */ | ||
92 | |||
156 | COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx); | 93 | COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx); |
157 | COPY(dx); COPY(cx); COPY(ip); | 94 | COPY(dx); COPY(cx); COPY(ip); |
158 | COPY_SEG_STRICT(cs); | 95 | |
159 | COPY_SEG_STRICT(ss); | 96 | #ifdef CONFIG_X86_64 |
97 | COPY(r8); | ||
98 | COPY(r9); | ||
99 | COPY(r10); | ||
100 | COPY(r11); | ||
101 | COPY(r12); | ||
102 | COPY(r13); | ||
103 | COPY(r14); | ||
104 | COPY(r15); | ||
105 | #endif /* CONFIG_X86_64 */ | ||
106 | |||
107 | #ifdef CONFIG_X86_32 | ||
108 | COPY_SEG_CPL3(cs); | ||
109 | COPY_SEG_CPL3(ss); | ||
110 | #else /* !CONFIG_X86_32 */ | ||
111 | /* Kernel saves and restores only the CS segment register on signals, | ||
112 | * which is the bare minimum needed to allow mixed 32/64-bit code. | ||
113 | * App's signal handler can save/restore other segments if needed. */ | ||
114 | COPY_SEG_CPL3(cs); | ||
115 | #endif /* CONFIG_X86_32 */ | ||
160 | 116 | ||
161 | err |= __get_user(tmpflags, &sc->flags); | 117 | err |= __get_user(tmpflags, &sc->flags); |
162 | regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS); | 118 | regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS); |
@@ -169,102 +125,24 @@ restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, | |||
169 | return err; | 125 | return err; |
170 | } | 126 | } |
171 | 127 | ||
172 | asmlinkage unsigned long sys_sigreturn(unsigned long __unused) | ||
173 | { | ||
174 | struct sigframe __user *frame; | ||
175 | struct pt_regs *regs; | ||
176 | unsigned long ax; | ||
177 | sigset_t set; | ||
178 | |||
179 | regs = (struct pt_regs *) &__unused; | ||
180 | frame = (struct sigframe __user *)(regs->sp - 8); | ||
181 | |||
182 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) | ||
183 | goto badframe; | ||
184 | if (__get_user(set.sig[0], &frame->sc.oldmask) || (_NSIG_WORDS > 1 | ||
185 | && __copy_from_user(&set.sig[1], &frame->extramask, | ||
186 | sizeof(frame->extramask)))) | ||
187 | goto badframe; | ||
188 | |||
189 | sigdelsetmask(&set, ~_BLOCKABLE); | ||
190 | spin_lock_irq(¤t->sighand->siglock); | ||
191 | current->blocked = set; | ||
192 | recalc_sigpending(); | ||
193 | spin_unlock_irq(¤t->sighand->siglock); | ||
194 | |||
195 | if (restore_sigcontext(regs, &frame->sc, &ax)) | ||
196 | goto badframe; | ||
197 | return ax; | ||
198 | |||
199 | badframe: | ||
200 | if (show_unhandled_signals && printk_ratelimit()) { | ||
201 | printk("%s%s[%d] bad frame in sigreturn frame:" | ||
202 | "%p ip:%lx sp:%lx oeax:%lx", | ||
203 | task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG, | ||
204 | current->comm, task_pid_nr(current), frame, regs->ip, | ||
205 | regs->sp, regs->orig_ax); | ||
206 | print_vma_addr(" in ", regs->ip); | ||
207 | printk(KERN_CONT "\n"); | ||
208 | } | ||
209 | |||
210 | force_sig(SIGSEGV, current); | ||
211 | |||
212 | return 0; | ||
213 | } | ||
214 | |||
215 | static long do_rt_sigreturn(struct pt_regs *regs) | ||
216 | { | ||
217 | struct rt_sigframe __user *frame; | ||
218 | unsigned long ax; | ||
219 | sigset_t set; | ||
220 | |||
221 | frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long)); | ||
222 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) | ||
223 | goto badframe; | ||
224 | if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) | ||
225 | goto badframe; | ||
226 | |||
227 | sigdelsetmask(&set, ~_BLOCKABLE); | ||
228 | spin_lock_irq(¤t->sighand->siglock); | ||
229 | current->blocked = set; | ||
230 | recalc_sigpending(); | ||
231 | spin_unlock_irq(¤t->sighand->siglock); | ||
232 | |||
233 | if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax)) | ||
234 | goto badframe; | ||
235 | |||
236 | if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT) | ||
237 | goto badframe; | ||
238 | |||
239 | return ax; | ||
240 | |||
241 | badframe: | ||
242 | signal_fault(regs, frame, "rt_sigreturn"); | ||
243 | return 0; | ||
244 | } | ||
245 | |||
246 | asmlinkage int sys_rt_sigreturn(unsigned long __unused) | ||
247 | { | ||
248 | struct pt_regs *regs = (struct pt_regs *)&__unused; | ||
249 | |||
250 | return do_rt_sigreturn(regs); | ||
251 | } | ||
252 | |||
253 | /* | ||
254 | * Set up a signal frame. | ||
255 | */ | ||
256 | static int | 128 | static int |
257 | setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate, | 129 | setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate, |
258 | struct pt_regs *regs, unsigned long mask) | 130 | struct pt_regs *regs, unsigned long mask) |
259 | { | 131 | { |
260 | int tmp, err = 0; | 132 | int err = 0; |
261 | 133 | ||
262 | err |= __put_user(regs->fs, (unsigned int __user *)&sc->fs); | 134 | #ifdef CONFIG_X86_32 |
263 | savesegment(gs, tmp); | 135 | { |
264 | err |= __put_user(tmp, (unsigned int __user *)&sc->gs); | 136 | unsigned int tmp; |
265 | 137 | ||
138 | savesegment(gs, tmp); | ||
139 | err |= __put_user(tmp, (unsigned int __user *)&sc->gs); | ||
140 | } | ||
141 | err |= __put_user(regs->fs, (unsigned int __user *)&sc->fs); | ||
266 | err |= __put_user(regs->es, (unsigned int __user *)&sc->es); | 142 | err |= __put_user(regs->es, (unsigned int __user *)&sc->es); |
267 | err |= __put_user(regs->ds, (unsigned int __user *)&sc->ds); | 143 | err |= __put_user(regs->ds, (unsigned int __user *)&sc->ds); |
144 | #endif /* CONFIG_X86_32 */ | ||
145 | |||
268 | err |= __put_user(regs->di, &sc->di); | 146 | err |= __put_user(regs->di, &sc->di); |
269 | err |= __put_user(regs->si, &sc->si); | 147 | err |= __put_user(regs->si, &sc->si); |
270 | err |= __put_user(regs->bp, &sc->bp); | 148 | err |= __put_user(regs->bp, &sc->bp); |
@@ -273,19 +151,33 @@ setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate, | |||
273 | err |= __put_user(regs->dx, &sc->dx); | 151 | err |= __put_user(regs->dx, &sc->dx); |
274 | err |= __put_user(regs->cx, &sc->cx); | 152 | err |= __put_user(regs->cx, &sc->cx); |
275 | err |= __put_user(regs->ax, &sc->ax); | 153 | err |= __put_user(regs->ax, &sc->ax); |
154 | #ifdef CONFIG_X86_64 | ||
155 | err |= __put_user(regs->r8, &sc->r8); | ||
156 | err |= __put_user(regs->r9, &sc->r9); | ||
157 | err |= __put_user(regs->r10, &sc->r10); | ||
158 | err |= __put_user(regs->r11, &sc->r11); | ||
159 | err |= __put_user(regs->r12, &sc->r12); | ||
160 | err |= __put_user(regs->r13, &sc->r13); | ||
161 | err |= __put_user(regs->r14, &sc->r14); | ||
162 | err |= __put_user(regs->r15, &sc->r15); | ||
163 | #endif /* CONFIG_X86_64 */ | ||
164 | |||
276 | err |= __put_user(current->thread.trap_no, &sc->trapno); | 165 | err |= __put_user(current->thread.trap_no, &sc->trapno); |
277 | err |= __put_user(current->thread.error_code, &sc->err); | 166 | err |= __put_user(current->thread.error_code, &sc->err); |
278 | err |= __put_user(regs->ip, &sc->ip); | 167 | err |= __put_user(regs->ip, &sc->ip); |
168 | #ifdef CONFIG_X86_32 | ||
279 | err |= __put_user(regs->cs, (unsigned int __user *)&sc->cs); | 169 | err |= __put_user(regs->cs, (unsigned int __user *)&sc->cs); |
280 | err |= __put_user(regs->flags, &sc->flags); | 170 | err |= __put_user(regs->flags, &sc->flags); |
281 | err |= __put_user(regs->sp, &sc->sp_at_signal); | 171 | err |= __put_user(regs->sp, &sc->sp_at_signal); |
282 | err |= __put_user(regs->ss, (unsigned int __user *)&sc->ss); | 172 | err |= __put_user(regs->ss, (unsigned int __user *)&sc->ss); |
173 | #else /* !CONFIG_X86_32 */ | ||
174 | err |= __put_user(regs->flags, &sc->flags); | ||
175 | err |= __put_user(regs->cs, &sc->cs); | ||
176 | err |= __put_user(0, &sc->gs); | ||
177 | err |= __put_user(0, &sc->fs); | ||
178 | #endif /* CONFIG_X86_32 */ | ||
283 | 179 | ||
284 | tmp = save_i387_xstate(fpstate); | 180 | err |= __put_user(fpstate, &sc->fpstate); |
285 | if (tmp < 0) | ||
286 | err = 1; | ||
287 | else | ||
288 | err |= __put_user(tmp ? fpstate : NULL, &sc->fpstate); | ||
289 | 181 | ||
290 | /* non-iBCS2 extensions.. */ | 182 | /* non-iBCS2 extensions.. */ |
291 | err |= __put_user(mask, &sc->oldmask); | 183 | err |= __put_user(mask, &sc->oldmask); |
@@ -295,6 +187,32 @@ setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate, | |||
295 | } | 187 | } |
296 | 188 | ||
297 | /* | 189 | /* |
190 | * Set up a signal frame. | ||
191 | */ | ||
192 | #ifdef CONFIG_X86_32 | ||
193 | static const struct { | ||
194 | u16 poplmovl; | ||
195 | u32 val; | ||
196 | u16 int80; | ||
197 | } __attribute__((packed)) retcode = { | ||
198 | 0xb858, /* popl %eax; movl $..., %eax */ | ||
199 | __NR_sigreturn, | ||
200 | 0x80cd, /* int $0x80 */ | ||
201 | }; | ||
202 | |||
203 | static const struct { | ||
204 | u8 movl; | ||
205 | u32 val; | ||
206 | u16 int80; | ||
207 | u8 pad; | ||
208 | } __attribute__((packed)) rt_retcode = { | ||
209 | 0xb8, /* movl $..., %eax */ | ||
210 | __NR_rt_sigreturn, | ||
211 | 0x80cd, /* int $0x80 */ | ||
212 | 0 | ||
213 | }; | ||
214 | |||
215 | /* | ||
298 | * Determine which stack to use.. | 216 | * Determine which stack to use.. |
299 | */ | 217 | */ |
300 | static inline void __user * | 218 | static inline void __user * |
@@ -328,6 +246,8 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size, | |||
328 | if (used_math()) { | 246 | if (used_math()) { |
329 | sp = sp - sig_xstate_size; | 247 | sp = sp - sig_xstate_size; |
330 | *fpstate = (struct _fpstate *) sp; | 248 | *fpstate = (struct _fpstate *) sp; |
249 | if (save_i387_xstate(*fpstate) < 0) | ||
250 | return (void __user *)-1L; | ||
331 | } | 251 | } |
332 | 252 | ||
333 | sp -= frame_size; | 253 | sp -= frame_size; |
@@ -383,9 +303,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set, | |||
383 | * reasons and because gdb uses it as a signature to notice | 303 | * reasons and because gdb uses it as a signature to notice |
384 | * signal handler stack frames. | 304 | * signal handler stack frames. |
385 | */ | 305 | */ |
386 | err |= __put_user(0xb858, (short __user *)(frame->retcode+0)); | 306 | err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode); |
387 | err |= __put_user(__NR_sigreturn, (int __user *)(frame->retcode+2)); | ||
388 | err |= __put_user(0x80cd, (short __user *)(frame->retcode+6)); | ||
389 | 307 | ||
390 | if (err) | 308 | if (err) |
391 | return -EFAULT; | 309 | return -EFAULT; |
@@ -454,9 +372,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, | |||
454 | * reasons and because gdb uses it as a signature to notice | 372 | * reasons and because gdb uses it as a signature to notice |
455 | * signal handler stack frames. | 373 | * signal handler stack frames. |
456 | */ | 374 | */ |
457 | err |= __put_user(0xb8, (char __user *)(frame->retcode+0)); | 375 | err |= __put_user(*((u64 *)&rt_retcode), (u64 *)frame->retcode); |
458 | err |= __put_user(__NR_rt_sigreturn, (int __user *)(frame->retcode+1)); | ||
459 | err |= __put_user(0x80cd, (short __user *)(frame->retcode+5)); | ||
460 | 376 | ||
461 | if (err) | 377 | if (err) |
462 | return -EFAULT; | 378 | return -EFAULT; |
@@ -475,23 +391,293 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, | |||
475 | 391 | ||
476 | return 0; | 392 | return 0; |
477 | } | 393 | } |
394 | #else /* !CONFIG_X86_32 */ | ||
395 | /* | ||
396 | * Determine which stack to use.. | ||
397 | */ | ||
398 | static void __user * | ||
399 | get_stack(struct k_sigaction *ka, unsigned long sp, unsigned long size) | ||
400 | { | ||
401 | /* Default to using normal stack - redzone*/ | ||
402 | sp -= 128; | ||
403 | |||
404 | /* This is the X/Open sanctioned signal stack switching. */ | ||
405 | if (ka->sa.sa_flags & SA_ONSTACK) { | ||
406 | if (sas_ss_flags(sp) == 0) | ||
407 | sp = current->sas_ss_sp + current->sas_ss_size; | ||
408 | } | ||
409 | |||
410 | return (void __user *)round_down(sp - size, 64); | ||
411 | } | ||
412 | |||
413 | static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, | ||
414 | sigset_t *set, struct pt_regs *regs) | ||
415 | { | ||
416 | struct rt_sigframe __user *frame; | ||
417 | void __user *fp = NULL; | ||
418 | int err = 0; | ||
419 | struct task_struct *me = current; | ||
420 | |||
421 | if (used_math()) { | ||
422 | fp = get_stack(ka, regs->sp, sig_xstate_size); | ||
423 | frame = (void __user *)round_down( | ||
424 | (unsigned long)fp - sizeof(struct rt_sigframe), 16) - 8; | ||
425 | |||
426 | if (save_i387_xstate(fp) < 0) | ||
427 | return -EFAULT; | ||
428 | } else | ||
429 | frame = get_stack(ka, regs->sp, sizeof(struct rt_sigframe)) - 8; | ||
430 | |||
431 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) | ||
432 | return -EFAULT; | ||
433 | |||
434 | if (ka->sa.sa_flags & SA_SIGINFO) { | ||
435 | if (copy_siginfo_to_user(&frame->info, info)) | ||
436 | return -EFAULT; | ||
437 | } | ||
438 | |||
439 | /* Create the ucontext. */ | ||
440 | if (cpu_has_xsave) | ||
441 | err |= __put_user(UC_FP_XSTATE, &frame->uc.uc_flags); | ||
442 | else | ||
443 | err |= __put_user(0, &frame->uc.uc_flags); | ||
444 | err |= __put_user(0, &frame->uc.uc_link); | ||
445 | err |= __put_user(me->sas_ss_sp, &frame->uc.uc_stack.ss_sp); | ||
446 | err |= __put_user(sas_ss_flags(regs->sp), | ||
447 | &frame->uc.uc_stack.ss_flags); | ||
448 | err |= __put_user(me->sas_ss_size, &frame->uc.uc_stack.ss_size); | ||
449 | err |= setup_sigcontext(&frame->uc.uc_mcontext, fp, regs, set->sig[0]); | ||
450 | err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); | ||
451 | |||
452 | /* Set up to return from userspace. If provided, use a stub | ||
453 | already in userspace. */ | ||
454 | /* x86-64 should always use SA_RESTORER. */ | ||
455 | if (ka->sa.sa_flags & SA_RESTORER) { | ||
456 | err |= __put_user(ka->sa.sa_restorer, &frame->pretcode); | ||
457 | } else { | ||
458 | /* could use a vstub here */ | ||
459 | return -EFAULT; | ||
460 | } | ||
461 | |||
462 | if (err) | ||
463 | return -EFAULT; | ||
464 | |||
465 | /* Set up registers for signal handler */ | ||
466 | regs->di = sig; | ||
467 | /* In case the signal handler was declared without prototypes */ | ||
468 | regs->ax = 0; | ||
469 | |||
470 | /* This also works for non SA_SIGINFO handlers because they expect the | ||
471 | next argument after the signal number on the stack. */ | ||
472 | regs->si = (unsigned long)&frame->info; | ||
473 | regs->dx = (unsigned long)&frame->uc; | ||
474 | regs->ip = (unsigned long) ka->sa.sa_handler; | ||
475 | |||
476 | regs->sp = (unsigned long)frame; | ||
477 | |||
478 | /* Set up the CS register to run signal handlers in 64-bit mode, | ||
479 | even if the handler happens to be interrupting 32-bit code. */ | ||
480 | regs->cs = __USER_CS; | ||
481 | |||
482 | return 0; | ||
483 | } | ||
484 | #endif /* CONFIG_X86_32 */ | ||
485 | |||
486 | #ifdef CONFIG_X86_32 | ||
487 | /* | ||
488 | * Atomically swap in the new signal mask, and wait for a signal. | ||
489 | */ | ||
490 | asmlinkage int | ||
491 | sys_sigsuspend(int history0, int history1, old_sigset_t mask) | ||
492 | { | ||
493 | mask &= _BLOCKABLE; | ||
494 | spin_lock_irq(¤t->sighand->siglock); | ||
495 | current->saved_sigmask = current->blocked; | ||
496 | siginitset(¤t->blocked, mask); | ||
497 | recalc_sigpending(); | ||
498 | spin_unlock_irq(¤t->sighand->siglock); | ||
499 | |||
500 | current->state = TASK_INTERRUPTIBLE; | ||
501 | schedule(); | ||
502 | set_restore_sigmask(); | ||
503 | |||
504 | return -ERESTARTNOHAND; | ||
505 | } | ||
506 | |||
507 | asmlinkage int | ||
508 | sys_sigaction(int sig, const struct old_sigaction __user *act, | ||
509 | struct old_sigaction __user *oact) | ||
510 | { | ||
511 | struct k_sigaction new_ka, old_ka; | ||
512 | int ret; | ||
513 | |||
514 | if (act) { | ||
515 | old_sigset_t mask; | ||
516 | |||
517 | if (!access_ok(VERIFY_READ, act, sizeof(*act)) || | ||
518 | __get_user(new_ka.sa.sa_handler, &act->sa_handler) || | ||
519 | __get_user(new_ka.sa.sa_restorer, &act->sa_restorer)) | ||
520 | return -EFAULT; | ||
521 | |||
522 | __get_user(new_ka.sa.sa_flags, &act->sa_flags); | ||
523 | __get_user(mask, &act->sa_mask); | ||
524 | siginitset(&new_ka.sa.sa_mask, mask); | ||
525 | } | ||
526 | |||
527 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); | ||
528 | |||
529 | if (!ret && oact) { | ||
530 | if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) || | ||
531 | __put_user(old_ka.sa.sa_handler, &oact->sa_handler) || | ||
532 | __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer)) | ||
533 | return -EFAULT; | ||
534 | |||
535 | __put_user(old_ka.sa.sa_flags, &oact->sa_flags); | ||
536 | __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask); | ||
537 | } | ||
538 | |||
539 | return ret; | ||
540 | } | ||
541 | #endif /* CONFIG_X86_32 */ | ||
542 | |||
543 | #ifdef CONFIG_X86_32 | ||
544 | asmlinkage int sys_sigaltstack(unsigned long bx) | ||
545 | { | ||
546 | /* | ||
547 | * This is needed to make gcc realize it doesn't own the | ||
548 | * "struct pt_regs" | ||
549 | */ | ||
550 | struct pt_regs *regs = (struct pt_regs *)&bx; | ||
551 | const stack_t __user *uss = (const stack_t __user *)bx; | ||
552 | stack_t __user *uoss = (stack_t __user *)regs->cx; | ||
553 | |||
554 | return do_sigaltstack(uss, uoss, regs->sp); | ||
555 | } | ||
556 | #else /* !CONFIG_X86_32 */ | ||
557 | asmlinkage long | ||
558 | sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss, | ||
559 | struct pt_regs *regs) | ||
560 | { | ||
561 | return do_sigaltstack(uss, uoss, regs->sp); | ||
562 | } | ||
563 | #endif /* CONFIG_X86_32 */ | ||
564 | |||
565 | /* | ||
566 | * Do a signal return; undo the signal stack. | ||
567 | */ | ||
568 | #ifdef CONFIG_X86_32 | ||
569 | asmlinkage unsigned long sys_sigreturn(unsigned long __unused) | ||
570 | { | ||
571 | struct sigframe __user *frame; | ||
572 | struct pt_regs *regs; | ||
573 | unsigned long ax; | ||
574 | sigset_t set; | ||
575 | |||
576 | regs = (struct pt_regs *) &__unused; | ||
577 | frame = (struct sigframe __user *)(regs->sp - 8); | ||
578 | |||
579 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) | ||
580 | goto badframe; | ||
581 | if (__get_user(set.sig[0], &frame->sc.oldmask) || (_NSIG_WORDS > 1 | ||
582 | && __copy_from_user(&set.sig[1], &frame->extramask, | ||
583 | sizeof(frame->extramask)))) | ||
584 | goto badframe; | ||
585 | |||
586 | sigdelsetmask(&set, ~_BLOCKABLE); | ||
587 | spin_lock_irq(¤t->sighand->siglock); | ||
588 | current->blocked = set; | ||
589 | recalc_sigpending(); | ||
590 | spin_unlock_irq(¤t->sighand->siglock); | ||
591 | |||
592 | if (restore_sigcontext(regs, &frame->sc, &ax)) | ||
593 | goto badframe; | ||
594 | return ax; | ||
595 | |||
596 | badframe: | ||
597 | signal_fault(regs, frame, "sigreturn"); | ||
598 | |||
599 | return 0; | ||
600 | } | ||
601 | #endif /* CONFIG_X86_32 */ | ||
602 | |||
603 | static long do_rt_sigreturn(struct pt_regs *regs) | ||
604 | { | ||
605 | struct rt_sigframe __user *frame; | ||
606 | unsigned long ax; | ||
607 | sigset_t set; | ||
608 | |||
609 | frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long)); | ||
610 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) | ||
611 | goto badframe; | ||
612 | if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) | ||
613 | goto badframe; | ||
614 | |||
615 | sigdelsetmask(&set, ~_BLOCKABLE); | ||
616 | spin_lock_irq(¤t->sighand->siglock); | ||
617 | current->blocked = set; | ||
618 | recalc_sigpending(); | ||
619 | spin_unlock_irq(¤t->sighand->siglock); | ||
620 | |||
621 | if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax)) | ||
622 | goto badframe; | ||
623 | |||
624 | if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT) | ||
625 | goto badframe; | ||
626 | |||
627 | return ax; | ||
628 | |||
629 | badframe: | ||
630 | signal_fault(regs, frame, "rt_sigreturn"); | ||
631 | return 0; | ||
632 | } | ||
633 | |||
634 | #ifdef CONFIG_X86_32 | ||
635 | asmlinkage int sys_rt_sigreturn(struct pt_regs regs) | ||
636 | { | ||
637 | return do_rt_sigreturn(®s); | ||
638 | } | ||
639 | #else /* !CONFIG_X86_32 */ | ||
640 | asmlinkage long sys_rt_sigreturn(struct pt_regs *regs) | ||
641 | { | ||
642 | return do_rt_sigreturn(regs); | ||
643 | } | ||
644 | #endif /* CONFIG_X86_32 */ | ||
478 | 645 | ||
479 | /* | 646 | /* |
480 | * OK, we're invoking a handler: | 647 | * OK, we're invoking a handler: |
481 | */ | 648 | */ |
482 | static int signr_convert(int sig) | 649 | static int signr_convert(int sig) |
483 | { | 650 | { |
651 | #ifdef CONFIG_X86_32 | ||
484 | struct thread_info *info = current_thread_info(); | 652 | struct thread_info *info = current_thread_info(); |
485 | 653 | ||
486 | if (info->exec_domain && info->exec_domain->signal_invmap && sig < 32) | 654 | if (info->exec_domain && info->exec_domain->signal_invmap && sig < 32) |
487 | return info->exec_domain->signal_invmap[sig]; | 655 | return info->exec_domain->signal_invmap[sig]; |
656 | #endif /* CONFIG_X86_32 */ | ||
488 | return sig; | 657 | return sig; |
489 | } | 658 | } |
490 | 659 | ||
660 | #ifdef CONFIG_X86_32 | ||
661 | |||
491 | #define is_ia32 1 | 662 | #define is_ia32 1 |
492 | #define ia32_setup_frame __setup_frame | 663 | #define ia32_setup_frame __setup_frame |
493 | #define ia32_setup_rt_frame __setup_rt_frame | 664 | #define ia32_setup_rt_frame __setup_rt_frame |
494 | 665 | ||
666 | #else /* !CONFIG_X86_32 */ | ||
667 | |||
668 | #ifdef CONFIG_IA32_EMULATION | ||
669 | #define is_ia32 test_thread_flag(TIF_IA32) | ||
670 | #else /* !CONFIG_IA32_EMULATION */ | ||
671 | #define is_ia32 0 | ||
672 | #endif /* CONFIG_IA32_EMULATION */ | ||
673 | |||
674 | int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, | ||
675 | sigset_t *set, struct pt_regs *regs); | ||
676 | int ia32_setup_frame(int sig, struct k_sigaction *ka, | ||
677 | sigset_t *set, struct pt_regs *regs); | ||
678 | |||
679 | #endif /* CONFIG_X86_32 */ | ||
680 | |||
495 | static int | 681 | static int |
496 | setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, | 682 | setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, |
497 | sigset_t *set, struct pt_regs *regs) | 683 | sigset_t *set, struct pt_regs *regs) |
@@ -592,7 +778,13 @@ handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka, | |||
592 | return 0; | 778 | return 0; |
593 | } | 779 | } |
594 | 780 | ||
781 | #ifdef CONFIG_X86_32 | ||
595 | #define NR_restart_syscall __NR_restart_syscall | 782 | #define NR_restart_syscall __NR_restart_syscall |
783 | #else /* !CONFIG_X86_32 */ | ||
784 | #define NR_restart_syscall \ | ||
785 | test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall : __NR_restart_syscall | ||
786 | #endif /* CONFIG_X86_32 */ | ||
787 | |||
596 | /* | 788 | /* |
597 | * Note that 'init' is a special process: it doesn't get signals it doesn't | 789 | * Note that 'init' is a special process: it doesn't get signals it doesn't |
598 | * want to handle. Thus you cannot kill init even with a SIGKILL even by | 790 | * want to handle. Thus you cannot kill init even with a SIGKILL even by |
@@ -704,8 +896,9 @@ void signal_fault(struct pt_regs *regs, void __user *frame, char *where) | |||
704 | struct task_struct *me = current; | 896 | struct task_struct *me = current; |
705 | 897 | ||
706 | if (show_unhandled_signals && printk_ratelimit()) { | 898 | if (show_unhandled_signals && printk_ratelimit()) { |
707 | printk(KERN_INFO | 899 | printk("%s" |
708 | "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx", | 900 | "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx", |
901 | task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG, | ||
709 | me->comm, me->pid, where, frame, | 902 | me->comm, me->pid, where, frame, |
710 | regs->ip, regs->sp, regs->orig_ax); | 903 | regs->ip, regs->sp, regs->orig_ax); |
711 | print_vma_addr(" in ", regs->ip); | 904 | print_vma_addr(" in ", regs->ip); |
diff --git a/arch/x86/kernel/signal_64.c b/arch/x86/kernel/signal_64.c deleted file mode 100644 index a5c9627f4db9..000000000000 --- a/arch/x86/kernel/signal_64.c +++ /dev/null | |||
@@ -1,516 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 1991, 1992 Linus Torvalds | ||
3 | * Copyright (C) 2000, 2001, 2002 Andi Kleen SuSE Labs | ||
4 | * | ||
5 | * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson | ||
6 | * 2000-06-20 Pentium III FXSR, SSE support by Gareth Hughes | ||
7 | * 2000-2002 x86-64 support by Andi Kleen | ||
8 | */ | ||
9 | |||
10 | #include <linux/sched.h> | ||
11 | #include <linux/mm.h> | ||
12 | #include <linux/smp.h> | ||
13 | #include <linux/kernel.h> | ||
14 | #include <linux/signal.h> | ||
15 | #include <linux/errno.h> | ||
16 | #include <linux/wait.h> | ||
17 | #include <linux/ptrace.h> | ||
18 | #include <linux/tracehook.h> | ||
19 | #include <linux/unistd.h> | ||
20 | #include <linux/stddef.h> | ||
21 | #include <linux/personality.h> | ||
22 | #include <linux/compiler.h> | ||
23 | #include <linux/uaccess.h> | ||
24 | |||
25 | #include <asm/processor.h> | ||
26 | #include <asm/ucontext.h> | ||
27 | #include <asm/i387.h> | ||
28 | #include <asm/proto.h> | ||
29 | #include <asm/ia32_unistd.h> | ||
30 | #include <asm/mce.h> | ||
31 | #include <asm/syscall.h> | ||
32 | #include <asm/syscalls.h> | ||
33 | #include "sigframe.h" | ||
34 | |||
35 | #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) | ||
36 | |||
37 | #define __FIX_EFLAGS (X86_EFLAGS_AC | X86_EFLAGS_OF | \ | ||
38 | X86_EFLAGS_DF | X86_EFLAGS_TF | X86_EFLAGS_SF | \ | ||
39 | X86_EFLAGS_ZF | X86_EFLAGS_AF | X86_EFLAGS_PF | \ | ||
40 | X86_EFLAGS_CF) | ||
41 | |||
42 | #ifdef CONFIG_X86_32 | ||
43 | # define FIX_EFLAGS (__FIX_EFLAGS | X86_EFLAGS_RF) | ||
44 | #else | ||
45 | # define FIX_EFLAGS __FIX_EFLAGS | ||
46 | #endif | ||
47 | |||
48 | asmlinkage long | ||
49 | sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss, | ||
50 | struct pt_regs *regs) | ||
51 | { | ||
52 | return do_sigaltstack(uss, uoss, regs->sp); | ||
53 | } | ||
54 | |||
55 | #define COPY(x) { \ | ||
56 | err |= __get_user(regs->x, &sc->x); \ | ||
57 | } | ||
58 | |||
59 | #define COPY_SEG_STRICT(seg) { \ | ||
60 | unsigned short tmp; \ | ||
61 | err |= __get_user(tmp, &sc->seg); \ | ||
62 | regs->seg = tmp | 3; \ | ||
63 | } | ||
64 | |||
65 | /* | ||
66 | * Do a signal return; undo the signal stack. | ||
67 | */ | ||
68 | static int | ||
69 | restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, | ||
70 | unsigned long *pax) | ||
71 | { | ||
72 | void __user *buf; | ||
73 | unsigned int tmpflags; | ||
74 | unsigned int err = 0; | ||
75 | |||
76 | /* Always make any pending restarted system calls return -EINTR */ | ||
77 | current_thread_info()->restart_block.fn = do_no_restart_syscall; | ||
78 | |||
79 | COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx); | ||
80 | COPY(dx); COPY(cx); COPY(ip); | ||
81 | COPY(r8); | ||
82 | COPY(r9); | ||
83 | COPY(r10); | ||
84 | COPY(r11); | ||
85 | COPY(r12); | ||
86 | COPY(r13); | ||
87 | COPY(r14); | ||
88 | COPY(r15); | ||
89 | |||
90 | /* Kernel saves and restores only the CS segment register on signals, | ||
91 | * which is the bare minimum needed to allow mixed 32/64-bit code. | ||
92 | * App's signal handler can save/restore other segments if needed. */ | ||
93 | COPY_SEG_STRICT(cs); | ||
94 | |||
95 | err |= __get_user(tmpflags, &sc->flags); | ||
96 | regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS); | ||
97 | regs->orig_ax = -1; /* disable syscall checks */ | ||
98 | |||
99 | err |= __get_user(buf, &sc->fpstate); | ||
100 | err |= restore_i387_xstate(buf); | ||
101 | |||
102 | err |= __get_user(*pax, &sc->ax); | ||
103 | return err; | ||
104 | } | ||
105 | |||
106 | static long do_rt_sigreturn(struct pt_regs *regs) | ||
107 | { | ||
108 | struct rt_sigframe __user *frame; | ||
109 | unsigned long ax; | ||
110 | sigset_t set; | ||
111 | |||
112 | frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long)); | ||
113 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) | ||
114 | goto badframe; | ||
115 | if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) | ||
116 | goto badframe; | ||
117 | |||
118 | sigdelsetmask(&set, ~_BLOCKABLE); | ||
119 | spin_lock_irq(¤t->sighand->siglock); | ||
120 | current->blocked = set; | ||
121 | recalc_sigpending(); | ||
122 | spin_unlock_irq(¤t->sighand->siglock); | ||
123 | |||
124 | if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax)) | ||
125 | goto badframe; | ||
126 | |||
127 | if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT) | ||
128 | goto badframe; | ||
129 | |||
130 | return ax; | ||
131 | |||
132 | badframe: | ||
133 | signal_fault(regs, frame, "rt_sigreturn"); | ||
134 | return 0; | ||
135 | } | ||
136 | |||
137 | asmlinkage long sys_rt_sigreturn(struct pt_regs *regs) | ||
138 | { | ||
139 | return do_rt_sigreturn(regs); | ||
140 | } | ||
141 | |||
142 | /* | ||
143 | * Set up a signal frame. | ||
144 | */ | ||
145 | |||
146 | static inline int | ||
147 | setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs, | ||
148 | unsigned long mask, struct task_struct *me) | ||
149 | { | ||
150 | int err = 0; | ||
151 | |||
152 | err |= __put_user(regs->cs, &sc->cs); | ||
153 | err |= __put_user(0, &sc->gs); | ||
154 | err |= __put_user(0, &sc->fs); | ||
155 | |||
156 | err |= __put_user(regs->di, &sc->di); | ||
157 | err |= __put_user(regs->si, &sc->si); | ||
158 | err |= __put_user(regs->bp, &sc->bp); | ||
159 | err |= __put_user(regs->sp, &sc->sp); | ||
160 | err |= __put_user(regs->bx, &sc->bx); | ||
161 | err |= __put_user(regs->dx, &sc->dx); | ||
162 | err |= __put_user(regs->cx, &sc->cx); | ||
163 | err |= __put_user(regs->ax, &sc->ax); | ||
164 | err |= __put_user(regs->r8, &sc->r8); | ||
165 | err |= __put_user(regs->r9, &sc->r9); | ||
166 | err |= __put_user(regs->r10, &sc->r10); | ||
167 | err |= __put_user(regs->r11, &sc->r11); | ||
168 | err |= __put_user(regs->r12, &sc->r12); | ||
169 | err |= __put_user(regs->r13, &sc->r13); | ||
170 | err |= __put_user(regs->r14, &sc->r14); | ||
171 | err |= __put_user(regs->r15, &sc->r15); | ||
172 | err |= __put_user(me->thread.trap_no, &sc->trapno); | ||
173 | err |= __put_user(me->thread.error_code, &sc->err); | ||
174 | err |= __put_user(regs->ip, &sc->ip); | ||
175 | err |= __put_user(regs->flags, &sc->flags); | ||
176 | err |= __put_user(mask, &sc->oldmask); | ||
177 | err |= __put_user(me->thread.cr2, &sc->cr2); | ||
178 | |||
179 | return err; | ||
180 | } | ||
181 | |||
182 | /* | ||
183 | * Determine which stack to use.. | ||
184 | */ | ||
185 | |||
186 | static void __user * | ||
187 | get_stack(struct k_sigaction *ka, struct pt_regs *regs, unsigned long size) | ||
188 | { | ||
189 | unsigned long sp; | ||
190 | |||
191 | /* Default to using normal stack - redzone*/ | ||
192 | sp = regs->sp - 128; | ||
193 | |||
194 | /* This is the X/Open sanctioned signal stack switching. */ | ||
195 | if (ka->sa.sa_flags & SA_ONSTACK) { | ||
196 | if (sas_ss_flags(sp) == 0) | ||
197 | sp = current->sas_ss_sp + current->sas_ss_size; | ||
198 | } | ||
199 | |||
200 | return (void __user *)round_down(sp - size, 64); | ||
201 | } | ||
202 | |||
203 | static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, | ||
204 | sigset_t *set, struct pt_regs *regs) | ||
205 | { | ||
206 | struct rt_sigframe __user *frame; | ||
207 | void __user *fp = NULL; | ||
208 | int err = 0; | ||
209 | struct task_struct *me = current; | ||
210 | |||
211 | if (used_math()) { | ||
212 | fp = get_stack(ka, regs, sig_xstate_size); | ||
213 | frame = (void __user *)round_down( | ||
214 | (unsigned long)fp - sizeof(struct rt_sigframe), 16) - 8; | ||
215 | |||
216 | if (save_i387_xstate(fp) < 0) | ||
217 | return -EFAULT; | ||
218 | } else | ||
219 | frame = get_stack(ka, regs, sizeof(struct rt_sigframe)) - 8; | ||
220 | |||
221 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) | ||
222 | return -EFAULT; | ||
223 | |||
224 | if (ka->sa.sa_flags & SA_SIGINFO) { | ||
225 | if (copy_siginfo_to_user(&frame->info, info)) | ||
226 | return -EFAULT; | ||
227 | } | ||
228 | |||
229 | /* Create the ucontext. */ | ||
230 | if (cpu_has_xsave) | ||
231 | err |= __put_user(UC_FP_XSTATE, &frame->uc.uc_flags); | ||
232 | else | ||
233 | err |= __put_user(0, &frame->uc.uc_flags); | ||
234 | err |= __put_user(0, &frame->uc.uc_link); | ||
235 | err |= __put_user(me->sas_ss_sp, &frame->uc.uc_stack.ss_sp); | ||
236 | err |= __put_user(sas_ss_flags(regs->sp), | ||
237 | &frame->uc.uc_stack.ss_flags); | ||
238 | err |= __put_user(me->sas_ss_size, &frame->uc.uc_stack.ss_size); | ||
239 | err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, set->sig[0], me); | ||
240 | err |= __put_user(fp, &frame->uc.uc_mcontext.fpstate); | ||
241 | if (sizeof(*set) == 16) { | ||
242 | __put_user(set->sig[0], &frame->uc.uc_sigmask.sig[0]); | ||
243 | __put_user(set->sig[1], &frame->uc.uc_sigmask.sig[1]); | ||
244 | } else | ||
245 | err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); | ||
246 | |||
247 | /* Set up to return from userspace. If provided, use a stub | ||
248 | already in userspace. */ | ||
249 | /* x86-64 should always use SA_RESTORER. */ | ||
250 | if (ka->sa.sa_flags & SA_RESTORER) { | ||
251 | err |= __put_user(ka->sa.sa_restorer, &frame->pretcode); | ||
252 | } else { | ||
253 | /* could use a vstub here */ | ||
254 | return -EFAULT; | ||
255 | } | ||
256 | |||
257 | if (err) | ||
258 | return -EFAULT; | ||
259 | |||
260 | /* Set up registers for signal handler */ | ||
261 | regs->di = sig; | ||
262 | /* In case the signal handler was declared without prototypes */ | ||
263 | regs->ax = 0; | ||
264 | |||
265 | /* This also works for non SA_SIGINFO handlers because they expect the | ||
266 | next argument after the signal number on the stack. */ | ||
267 | regs->si = (unsigned long)&frame->info; | ||
268 | regs->dx = (unsigned long)&frame->uc; | ||
269 | regs->ip = (unsigned long) ka->sa.sa_handler; | ||
270 | |||
271 | regs->sp = (unsigned long)frame; | ||
272 | |||
273 | /* Set up the CS register to run signal handlers in 64-bit mode, | ||
274 | even if the handler happens to be interrupting 32-bit code. */ | ||
275 | regs->cs = __USER_CS; | ||
276 | |||
277 | return 0; | ||
278 | } | ||
279 | |||
280 | /* | ||
281 | * OK, we're invoking a handler | ||
282 | */ | ||
283 | static int signr_convert(int sig) | ||
284 | { | ||
285 | return sig; | ||
286 | } | ||
287 | |||
288 | #ifdef CONFIG_IA32_EMULATION | ||
289 | #define is_ia32 test_thread_flag(TIF_IA32) | ||
290 | #else | ||
291 | #define is_ia32 0 | ||
292 | #endif | ||
293 | |||
294 | static int | ||
295 | setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, | ||
296 | sigset_t *set, struct pt_regs *regs) | ||
297 | { | ||
298 | int usig = signr_convert(sig); | ||
299 | int ret; | ||
300 | |||
301 | /* Set up the stack frame */ | ||
302 | if (is_ia32) { | ||
303 | if (ka->sa.sa_flags & SA_SIGINFO) | ||
304 | ret = ia32_setup_rt_frame(usig, ka, info, set, regs); | ||
305 | else | ||
306 | ret = ia32_setup_frame(usig, ka, set, regs); | ||
307 | } else | ||
308 | ret = __setup_rt_frame(sig, ka, info, set, regs); | ||
309 | |||
310 | if (ret) { | ||
311 | force_sigsegv(sig, current); | ||
312 | return -EFAULT; | ||
313 | } | ||
314 | |||
315 | return ret; | ||
316 | } | ||
317 | |||
318 | static int | ||
319 | handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka, | ||
320 | sigset_t *oldset, struct pt_regs *regs) | ||
321 | { | ||
322 | int ret; | ||
323 | |||
324 | /* Are we from a system call? */ | ||
325 | if (syscall_get_nr(current, regs) >= 0) { | ||
326 | /* If so, check system call restarting.. */ | ||
327 | switch (syscall_get_error(current, regs)) { | ||
328 | case -ERESTART_RESTARTBLOCK: | ||
329 | case -ERESTARTNOHAND: | ||
330 | regs->ax = -EINTR; | ||
331 | break; | ||
332 | |||
333 | case -ERESTARTSYS: | ||
334 | if (!(ka->sa.sa_flags & SA_RESTART)) { | ||
335 | regs->ax = -EINTR; | ||
336 | break; | ||
337 | } | ||
338 | /* fallthrough */ | ||
339 | case -ERESTARTNOINTR: | ||
340 | regs->ax = regs->orig_ax; | ||
341 | regs->ip -= 2; | ||
342 | break; | ||
343 | } | ||
344 | } | ||
345 | |||
346 | /* | ||
347 | * If TF is set due to a debugger (TIF_FORCED_TF), clear the TF | ||
348 | * flag so that register information in the sigcontext is correct. | ||
349 | */ | ||
350 | if (unlikely(regs->flags & X86_EFLAGS_TF) && | ||
351 | likely(test_and_clear_thread_flag(TIF_FORCED_TF))) | ||
352 | regs->flags &= ~X86_EFLAGS_TF; | ||
353 | |||
354 | ret = setup_rt_frame(sig, ka, info, oldset, regs); | ||
355 | |||
356 | if (ret) | ||
357 | return ret; | ||
358 | |||
359 | #ifdef CONFIG_X86_64 | ||
360 | /* | ||
361 | * This has nothing to do with segment registers, | ||
362 | * despite the name. This magic affects uaccess.h | ||
363 | * macros' behavior. Reset it to the normal setting. | ||
364 | */ | ||
365 | set_fs(USER_DS); | ||
366 | #endif | ||
367 | |||
368 | /* | ||
369 | * Clear the direction flag as per the ABI for function entry. | ||
370 | */ | ||
371 | regs->flags &= ~X86_EFLAGS_DF; | ||
372 | |||
373 | /* | ||
374 | * Clear TF when entering the signal handler, but | ||
375 | * notify any tracer that was single-stepping it. | ||
376 | * The tracer may want to single-step inside the | ||
377 | * handler too. | ||
378 | */ | ||
379 | regs->flags &= ~X86_EFLAGS_TF; | ||
380 | |||
381 | spin_lock_irq(¤t->sighand->siglock); | ||
382 | sigorsets(¤t->blocked, ¤t->blocked, &ka->sa.sa_mask); | ||
383 | if (!(ka->sa.sa_flags & SA_NODEFER)) | ||
384 | sigaddset(¤t->blocked, sig); | ||
385 | recalc_sigpending(); | ||
386 | spin_unlock_irq(¤t->sighand->siglock); | ||
387 | |||
388 | tracehook_signal_handler(sig, info, ka, regs, | ||
389 | test_thread_flag(TIF_SINGLESTEP)); | ||
390 | |||
391 | return 0; | ||
392 | } | ||
393 | |||
394 | #define NR_restart_syscall \ | ||
395 | test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall : __NR_restart_syscall | ||
396 | /* | ||
397 | * Note that 'init' is a special process: it doesn't get signals it doesn't | ||
398 | * want to handle. Thus you cannot kill init even with a SIGKILL even by | ||
399 | * mistake. | ||
400 | */ | ||
401 | static void do_signal(struct pt_regs *regs) | ||
402 | { | ||
403 | struct k_sigaction ka; | ||
404 | siginfo_t info; | ||
405 | int signr; | ||
406 | sigset_t *oldset; | ||
407 | |||
408 | /* | ||
409 | * We want the common case to go fast, which is why we may in certain | ||
410 | * cases get here from kernel mode. Just return without doing anything | ||
411 | * if so. | ||
412 | * X86_32: vm86 regs switched out by assembly code before reaching | ||
413 | * here, so testing against kernel CS suffices. | ||
414 | */ | ||
415 | if (!user_mode(regs)) | ||
416 | return; | ||
417 | |||
418 | if (current_thread_info()->status & TS_RESTORE_SIGMASK) | ||
419 | oldset = ¤t->saved_sigmask; | ||
420 | else | ||
421 | oldset = ¤t->blocked; | ||
422 | |||
423 | signr = get_signal_to_deliver(&info, &ka, regs, NULL); | ||
424 | if (signr > 0) { | ||
425 | /* | ||
426 | * Re-enable any watchpoints before delivering the | ||
427 | * signal to user space. The processor register will | ||
428 | * have been cleared if the watchpoint triggered | ||
429 | * inside the kernel. | ||
430 | */ | ||
431 | if (current->thread.debugreg7) | ||
432 | set_debugreg(current->thread.debugreg7, 7); | ||
433 | |||
434 | /* Whee! Actually deliver the signal. */ | ||
435 | if (handle_signal(signr, &info, &ka, oldset, regs) == 0) { | ||
436 | /* | ||
437 | * A signal was successfully delivered; the saved | ||
438 | * sigmask will have been stored in the signal frame, | ||
439 | * and will be restored by sigreturn, so we can simply | ||
440 | * clear the TS_RESTORE_SIGMASK flag. | ||
441 | */ | ||
442 | current_thread_info()->status &= ~TS_RESTORE_SIGMASK; | ||
443 | } | ||
444 | return; | ||
445 | } | ||
446 | |||
447 | /* Did we come from a system call? */ | ||
448 | if (syscall_get_nr(current, regs) >= 0) { | ||
449 | /* Restart the system call - no handlers present */ | ||
450 | switch (syscall_get_error(current, regs)) { | ||
451 | case -ERESTARTNOHAND: | ||
452 | case -ERESTARTSYS: | ||
453 | case -ERESTARTNOINTR: | ||
454 | regs->ax = regs->orig_ax; | ||
455 | regs->ip -= 2; | ||
456 | break; | ||
457 | |||
458 | case -ERESTART_RESTARTBLOCK: | ||
459 | regs->ax = NR_restart_syscall; | ||
460 | regs->ip -= 2; | ||
461 | break; | ||
462 | } | ||
463 | } | ||
464 | |||
465 | /* | ||
466 | * If there's no signal to deliver, we just put the saved sigmask | ||
467 | * back. | ||
468 | */ | ||
469 | if (current_thread_info()->status & TS_RESTORE_SIGMASK) { | ||
470 | current_thread_info()->status &= ~TS_RESTORE_SIGMASK; | ||
471 | sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL); | ||
472 | } | ||
473 | } | ||
474 | |||
475 | /* | ||
476 | * notification of userspace execution resumption | ||
477 | * - triggered by the TIF_WORK_MASK flags | ||
478 | */ | ||
479 | void | ||
480 | do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags) | ||
481 | { | ||
482 | #if defined(CONFIG_X86_64) && defined(CONFIG_X86_MCE) | ||
483 | /* notify userspace of pending MCEs */ | ||
484 | if (thread_info_flags & _TIF_MCE_NOTIFY) | ||
485 | mce_notify_user(); | ||
486 | #endif /* CONFIG_X86_64 && CONFIG_X86_MCE */ | ||
487 | |||
488 | /* deal with pending signal delivery */ | ||
489 | if (thread_info_flags & _TIF_SIGPENDING) | ||
490 | do_signal(regs); | ||
491 | |||
492 | if (thread_info_flags & _TIF_NOTIFY_RESUME) { | ||
493 | clear_thread_flag(TIF_NOTIFY_RESUME); | ||
494 | tracehook_notify_resume(regs); | ||
495 | } | ||
496 | |||
497 | #ifdef CONFIG_X86_32 | ||
498 | clear_thread_flag(TIF_IRET); | ||
499 | #endif /* CONFIG_X86_32 */ | ||
500 | } | ||
501 | |||
502 | void signal_fault(struct pt_regs *regs, void __user *frame, char *where) | ||
503 | { | ||
504 | struct task_struct *me = current; | ||
505 | |||
506 | if (show_unhandled_signals && printk_ratelimit()) { | ||
507 | printk(KERN_INFO | ||
508 | "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx", | ||
509 | me->comm, me->pid, where, frame, | ||
510 | regs->ip, regs->sp, regs->orig_ax); | ||
511 | print_vma_addr(" in ", regs->ip); | ||
512 | printk(KERN_CONT "\n"); | ||
513 | } | ||
514 | |||
515 | force_sig(SIGSEGV, me); | ||
516 | } | ||
diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c index 18f9b19f5f8f..beea2649a240 100644 --- a/arch/x86/kernel/smp.c +++ b/arch/x86/kernel/smp.c | |||
@@ -118,41 +118,28 @@ static void native_smp_send_reschedule(int cpu) | |||
118 | WARN_ON(1); | 118 | WARN_ON(1); |
119 | return; | 119 | return; |
120 | } | 120 | } |
121 | send_IPI_mask(cpumask_of_cpu(cpu), RESCHEDULE_VECTOR); | 121 | send_IPI_mask(cpumask_of(cpu), RESCHEDULE_VECTOR); |
122 | } | 122 | } |
123 | 123 | ||
124 | void native_send_call_func_single_ipi(int cpu) | 124 | void native_send_call_func_single_ipi(int cpu) |
125 | { | 125 | { |
126 | send_IPI_mask(cpumask_of_cpu(cpu), CALL_FUNCTION_SINGLE_VECTOR); | 126 | send_IPI_mask(cpumask_of(cpu), CALL_FUNCTION_SINGLE_VECTOR); |
127 | } | 127 | } |
128 | 128 | ||
129 | void native_send_call_func_ipi(cpumask_t mask) | 129 | void native_send_call_func_ipi(const struct cpumask *mask) |
130 | { | 130 | { |
131 | cpumask_t allbutself; | 131 | cpumask_t allbutself; |
132 | 132 | ||
133 | allbutself = cpu_online_map; | 133 | allbutself = cpu_online_map; |
134 | cpu_clear(smp_processor_id(), allbutself); | 134 | cpu_clear(smp_processor_id(), allbutself); |
135 | 135 | ||
136 | if (cpus_equal(mask, allbutself) && | 136 | if (cpus_equal(*mask, allbutself) && |
137 | cpus_equal(cpu_online_map, cpu_callout_map)) | 137 | cpus_equal(cpu_online_map, cpu_callout_map)) |
138 | send_IPI_allbutself(CALL_FUNCTION_VECTOR); | 138 | send_IPI_allbutself(CALL_FUNCTION_VECTOR); |
139 | else | 139 | else |
140 | send_IPI_mask(mask, CALL_FUNCTION_VECTOR); | 140 | send_IPI_mask(mask, CALL_FUNCTION_VECTOR); |
141 | } | 141 | } |
142 | 142 | ||
143 | static void stop_this_cpu(void *dummy) | ||
144 | { | ||
145 | local_irq_disable(); | ||
146 | /* | ||
147 | * Remove this CPU: | ||
148 | */ | ||
149 | cpu_clear(smp_processor_id(), cpu_online_map); | ||
150 | disable_local_APIC(); | ||
151 | if (hlt_works(smp_processor_id())) | ||
152 | for (;;) halt(); | ||
153 | for (;;); | ||
154 | } | ||
155 | |||
156 | /* | 143 | /* |
157 | * this function calls the 'stop' function on all other CPUs in the system. | 144 | * this function calls the 'stop' function on all other CPUs in the system. |
158 | */ | 145 | */ |
@@ -178,11 +165,7 @@ static void native_smp_send_stop(void) | |||
178 | void smp_reschedule_interrupt(struct pt_regs *regs) | 165 | void smp_reschedule_interrupt(struct pt_regs *regs) |
179 | { | 166 | { |
180 | ack_APIC_irq(); | 167 | ack_APIC_irq(); |
181 | #ifdef CONFIG_X86_32 | 168 | inc_irq_stat(irq_resched_count); |
182 | __get_cpu_var(irq_stat).irq_resched_count++; | ||
183 | #else | ||
184 | add_pda(irq_resched_count, 1); | ||
185 | #endif | ||
186 | } | 169 | } |
187 | 170 | ||
188 | void smp_call_function_interrupt(struct pt_regs *regs) | 171 | void smp_call_function_interrupt(struct pt_regs *regs) |
@@ -190,11 +173,7 @@ void smp_call_function_interrupt(struct pt_regs *regs) | |||
190 | ack_APIC_irq(); | 173 | ack_APIC_irq(); |
191 | irq_enter(); | 174 | irq_enter(); |
192 | generic_smp_call_function_interrupt(); | 175 | generic_smp_call_function_interrupt(); |
193 | #ifdef CONFIG_X86_32 | 176 | inc_irq_stat(irq_call_count); |
194 | __get_cpu_var(irq_stat).irq_call_count++; | ||
195 | #else | ||
196 | add_pda(irq_call_count, 1); | ||
197 | #endif | ||
198 | irq_exit(); | 177 | irq_exit(); |
199 | } | 178 | } |
200 | 179 | ||
@@ -203,11 +182,7 @@ void smp_call_function_single_interrupt(struct pt_regs *regs) | |||
203 | ack_APIC_irq(); | 182 | ack_APIC_irq(); |
204 | irq_enter(); | 183 | irq_enter(); |
205 | generic_smp_call_function_single_interrupt(); | 184 | generic_smp_call_function_single_interrupt(); |
206 | #ifdef CONFIG_X86_32 | 185 | inc_irq_stat(irq_call_count); |
207 | __get_cpu_var(irq_stat).irq_call_count++; | ||
208 | #else | ||
209 | add_pda(irq_call_count, 1); | ||
210 | #endif | ||
211 | irq_exit(); | 186 | irq_exit(); |
212 | } | 187 | } |
213 | 188 | ||
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index f71f96fc9e62..6bd4d9b73870 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c | |||
@@ -62,6 +62,7 @@ | |||
62 | #include <asm/mtrr.h> | 62 | #include <asm/mtrr.h> |
63 | #include <asm/vmi.h> | 63 | #include <asm/vmi.h> |
64 | #include <asm/genapic.h> | 64 | #include <asm/genapic.h> |
65 | #include <asm/setup.h> | ||
65 | #include <linux/mc146818rtc.h> | 66 | #include <linux/mc146818rtc.h> |
66 | 67 | ||
67 | #include <mach_apic.h> | 68 | #include <mach_apic.h> |
@@ -101,14 +102,8 @@ EXPORT_SYMBOL(smp_num_siblings); | |||
101 | /* Last level cache ID of each logical CPU */ | 102 | /* Last level cache ID of each logical CPU */ |
102 | DEFINE_PER_CPU(u16, cpu_llc_id) = BAD_APICID; | 103 | DEFINE_PER_CPU(u16, cpu_llc_id) = BAD_APICID; |
103 | 104 | ||
104 | /* bitmap of online cpus */ | ||
105 | cpumask_t cpu_online_map __read_mostly; | ||
106 | EXPORT_SYMBOL(cpu_online_map); | ||
107 | |||
108 | cpumask_t cpu_callin_map; | 105 | cpumask_t cpu_callin_map; |
109 | cpumask_t cpu_callout_map; | 106 | cpumask_t cpu_callout_map; |
110 | cpumask_t cpu_possible_map; | ||
111 | EXPORT_SYMBOL(cpu_possible_map); | ||
112 | 107 | ||
113 | /* representing HT siblings of each logical CPU */ | 108 | /* representing HT siblings of each logical CPU */ |
114 | DEFINE_PER_CPU(cpumask_t, cpu_sibling_map); | 109 | DEFINE_PER_CPU(cpumask_t, cpu_sibling_map); |
@@ -287,7 +282,7 @@ static int __cpuinitdata unsafe_smp; | |||
287 | /* | 282 | /* |
288 | * Activate a secondary processor. | 283 | * Activate a secondary processor. |
289 | */ | 284 | */ |
290 | static void __cpuinit start_secondary(void *unused) | 285 | notrace static void __cpuinit start_secondary(void *unused) |
291 | { | 286 | { |
292 | /* | 287 | /* |
293 | * Don't put *anything* before cpu_init(), SMP booting is too | 288 | * Don't put *anything* before cpu_init(), SMP booting is too |
@@ -501,7 +496,7 @@ void __cpuinit set_cpu_sibling_map(int cpu) | |||
501 | } | 496 | } |
502 | 497 | ||
503 | /* maps the cpu to the sched domain representing multi-core */ | 498 | /* maps the cpu to the sched domain representing multi-core */ |
504 | cpumask_t cpu_coregroup_map(int cpu) | 499 | const struct cpumask *cpu_coregroup_mask(int cpu) |
505 | { | 500 | { |
506 | struct cpuinfo_x86 *c = &cpu_data(cpu); | 501 | struct cpuinfo_x86 *c = &cpu_data(cpu); |
507 | /* | 502 | /* |
@@ -509,9 +504,14 @@ cpumask_t cpu_coregroup_map(int cpu) | |||
509 | * And for power savings, we return cpu_core_map | 504 | * And for power savings, we return cpu_core_map |
510 | */ | 505 | */ |
511 | if (sched_mc_power_savings || sched_smt_power_savings) | 506 | if (sched_mc_power_savings || sched_smt_power_savings) |
512 | return per_cpu(cpu_core_map, cpu); | 507 | return &per_cpu(cpu_core_map, cpu); |
513 | else | 508 | else |
514 | return c->llc_shared_map; | 509 | return &c->llc_shared_map; |
510 | } | ||
511 | |||
512 | cpumask_t cpu_coregroup_map(int cpu) | ||
513 | { | ||
514 | return *cpu_coregroup_mask(cpu); | ||
515 | } | 515 | } |
516 | 516 | ||
517 | static void impress_friends(void) | 517 | static void impress_friends(void) |
@@ -534,7 +534,7 @@ static void impress_friends(void) | |||
534 | pr_debug("Before bogocount - setting activated=1.\n"); | 534 | pr_debug("Before bogocount - setting activated=1.\n"); |
535 | } | 535 | } |
536 | 536 | ||
537 | static inline void __inquire_remote_apic(int apicid) | 537 | void __inquire_remote_apic(int apicid) |
538 | { | 538 | { |
539 | unsigned i, regs[] = { APIC_ID >> 4, APIC_LVR >> 4, APIC_SPIV >> 4 }; | 539 | unsigned i, regs[] = { APIC_ID >> 4, APIC_LVR >> 4, APIC_SPIV >> 4 }; |
540 | char *names[] = { "ID", "VERSION", "SPIV" }; | 540 | char *names[] = { "ID", "VERSION", "SPIV" }; |
@@ -573,14 +573,13 @@ static inline void __inquire_remote_apic(int apicid) | |||
573 | } | 573 | } |
574 | } | 574 | } |
575 | 575 | ||
576 | #ifdef WAKE_SECONDARY_VIA_NMI | ||
577 | /* | 576 | /* |
578 | * Poke the other CPU in the eye via NMI to wake it up. Remember that the normal | 577 | * Poke the other CPU in the eye via NMI to wake it up. Remember that the normal |
579 | * INIT, INIT, STARTUP sequence will reset the chip hard for us, and this | 578 | * INIT, INIT, STARTUP sequence will reset the chip hard for us, and this |
580 | * won't ... remember to clear down the APIC, etc later. | 579 | * won't ... remember to clear down the APIC, etc later. |
581 | */ | 580 | */ |
582 | static int __devinit | 581 | int __devinit |
583 | wakeup_secondary_cpu(int logical_apicid, unsigned long start_eip) | 582 | wakeup_secondary_cpu_via_nmi(int logical_apicid, unsigned long start_eip) |
584 | { | 583 | { |
585 | unsigned long send_status, accept_status = 0; | 584 | unsigned long send_status, accept_status = 0; |
586 | int maxlvt; | 585 | int maxlvt; |
@@ -597,7 +596,7 @@ wakeup_secondary_cpu(int logical_apicid, unsigned long start_eip) | |||
597 | * Give the other CPU some time to accept the IPI. | 596 | * Give the other CPU some time to accept the IPI. |
598 | */ | 597 | */ |
599 | udelay(200); | 598 | udelay(200); |
600 | if (APIC_INTEGRATED(apic_version[phys_apicid])) { | 599 | if (APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid])) { |
601 | maxlvt = lapic_get_maxlvt(); | 600 | maxlvt = lapic_get_maxlvt(); |
602 | if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */ | 601 | if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */ |
603 | apic_write(APIC_ESR, 0); | 602 | apic_write(APIC_ESR, 0); |
@@ -612,11 +611,9 @@ wakeup_secondary_cpu(int logical_apicid, unsigned long start_eip) | |||
612 | 611 | ||
613 | return (send_status | accept_status); | 612 | return (send_status | accept_status); |
614 | } | 613 | } |
615 | #endif /* WAKE_SECONDARY_VIA_NMI */ | ||
616 | 614 | ||
617 | #ifdef WAKE_SECONDARY_VIA_INIT | 615 | int __devinit |
618 | static int __devinit | 616 | wakeup_secondary_cpu_via_init(int phys_apicid, unsigned long start_eip) |
619 | wakeup_secondary_cpu(int phys_apicid, unsigned long start_eip) | ||
620 | { | 617 | { |
621 | unsigned long send_status, accept_status = 0; | 618 | unsigned long send_status, accept_status = 0; |
622 | int maxlvt, num_starts, j; | 619 | int maxlvt, num_starts, j; |
@@ -735,7 +732,6 @@ wakeup_secondary_cpu(int phys_apicid, unsigned long start_eip) | |||
735 | 732 | ||
736 | return (send_status | accept_status); | 733 | return (send_status | accept_status); |
737 | } | 734 | } |
738 | #endif /* WAKE_SECONDARY_VIA_INIT */ | ||
739 | 735 | ||
740 | struct create_idle { | 736 | struct create_idle { |
741 | struct work_struct work; | 737 | struct work_struct work; |
@@ -1084,8 +1080,10 @@ static int __init smp_sanity_check(unsigned max_cpus) | |||
1084 | #endif | 1080 | #endif |
1085 | 1081 | ||
1086 | if (!physid_isset(hard_smp_processor_id(), phys_cpu_present_map)) { | 1082 | if (!physid_isset(hard_smp_processor_id(), phys_cpu_present_map)) { |
1087 | printk(KERN_WARNING "weird, boot CPU (#%d) not listed" | 1083 | printk(KERN_WARNING |
1088 | "by the BIOS.\n", hard_smp_processor_id()); | 1084 | "weird, boot CPU (#%d) not listed by the BIOS.\n", |
1085 | hard_smp_processor_id()); | ||
1086 | |||
1089 | physid_set(hard_smp_processor_id(), phys_cpu_present_map); | 1087 | physid_set(hard_smp_processor_id(), phys_cpu_present_map); |
1090 | } | 1088 | } |
1091 | 1089 | ||
@@ -1156,7 +1154,7 @@ static void __init smp_cpu_index_default(void) | |||
1156 | for_each_possible_cpu(i) { | 1154 | for_each_possible_cpu(i) { |
1157 | c = &cpu_data(i); | 1155 | c = &cpu_data(i); |
1158 | /* mark all to hotplug */ | 1156 | /* mark all to hotplug */ |
1159 | c->cpu_index = NR_CPUS; | 1157 | c->cpu_index = nr_cpu_ids; |
1160 | } | 1158 | } |
1161 | } | 1159 | } |
1162 | 1160 | ||
@@ -1261,6 +1259,15 @@ void __init native_smp_cpus_done(unsigned int max_cpus) | |||
1261 | check_nmi_watchdog(); | 1259 | check_nmi_watchdog(); |
1262 | } | 1260 | } |
1263 | 1261 | ||
1262 | static int __initdata setup_possible_cpus = -1; | ||
1263 | static int __init _setup_possible_cpus(char *str) | ||
1264 | { | ||
1265 | get_option(&str, &setup_possible_cpus); | ||
1266 | return 0; | ||
1267 | } | ||
1268 | early_param("possible_cpus", _setup_possible_cpus); | ||
1269 | |||
1270 | |||
1264 | /* | 1271 | /* |
1265 | * cpu_possible_map should be static, it cannot change as cpu's | 1272 | * cpu_possible_map should be static, it cannot change as cpu's |
1266 | * are onlined, or offlined. The reason is per-cpu data-structures | 1273 | * are onlined, or offlined. The reason is per-cpu data-structures |
@@ -1273,7 +1280,7 @@ void __init native_smp_cpus_done(unsigned int max_cpus) | |||
1273 | * | 1280 | * |
1274 | * Three ways to find out the number of additional hotplug CPUs: | 1281 | * Three ways to find out the number of additional hotplug CPUs: |
1275 | * - If the BIOS specified disabled CPUs in ACPI/mptables use that. | 1282 | * - If the BIOS specified disabled CPUs in ACPI/mptables use that. |
1276 | * - The user can overwrite it with additional_cpus=NUM | 1283 | * - The user can overwrite it with possible_cpus=NUM |
1277 | * - Otherwise don't reserve additional CPUs. | 1284 | * - Otherwise don't reserve additional CPUs. |
1278 | * We do this because additional CPUs waste a lot of memory. | 1285 | * We do this because additional CPUs waste a lot of memory. |
1279 | * -AK | 1286 | * -AK |
@@ -1286,9 +1293,19 @@ __init void prefill_possible_map(void) | |||
1286 | if (!num_processors) | 1293 | if (!num_processors) |
1287 | num_processors = 1; | 1294 | num_processors = 1; |
1288 | 1295 | ||
1289 | possible = num_processors + disabled_cpus; | 1296 | if (setup_possible_cpus == -1) |
1290 | if (possible > NR_CPUS) | 1297 | possible = num_processors + disabled_cpus; |
1291 | possible = NR_CPUS; | 1298 | else |
1299 | possible = setup_possible_cpus; | ||
1300 | |||
1301 | total_cpus = max_t(int, possible, num_processors + disabled_cpus); | ||
1302 | |||
1303 | if (possible > CONFIG_NR_CPUS) { | ||
1304 | printk(KERN_WARNING | ||
1305 | "%d Processors exceeds NR_CPUS limit of %d\n", | ||
1306 | possible, CONFIG_NR_CPUS); | ||
1307 | possible = CONFIG_NR_CPUS; | ||
1308 | } | ||
1292 | 1309 | ||
1293 | printk(KERN_INFO "SMP: Allowing %d CPUs, %d hotplug CPUs\n", | 1310 | printk(KERN_INFO "SMP: Allowing %d CPUs, %d hotplug CPUs\n", |
1294 | possible, max_t(int, possible - num_processors, 0)); | 1311 | possible, max_t(int, possible - num_processors, 0)); |
@@ -1353,7 +1370,7 @@ void cpu_disable_common(void) | |||
1353 | lock_vector_lock(); | 1370 | lock_vector_lock(); |
1354 | remove_cpu_from_maps(cpu); | 1371 | remove_cpu_from_maps(cpu); |
1355 | unlock_vector_lock(); | 1372 | unlock_vector_lock(); |
1356 | fixup_irqs(cpu_online_map); | 1373 | fixup_irqs(); |
1357 | } | 1374 | } |
1358 | 1375 | ||
1359 | int native_cpu_disable(void) | 1376 | int native_cpu_disable(void) |
diff --git a/arch/x86/kernel/stacktrace.c b/arch/x86/kernel/stacktrace.c index a03e7f6d90c3..10786af95545 100644 --- a/arch/x86/kernel/stacktrace.c +++ b/arch/x86/kernel/stacktrace.c | |||
@@ -6,6 +6,7 @@ | |||
6 | #include <linux/sched.h> | 6 | #include <linux/sched.h> |
7 | #include <linux/stacktrace.h> | 7 | #include <linux/stacktrace.h> |
8 | #include <linux/module.h> | 8 | #include <linux/module.h> |
9 | #include <linux/uaccess.h> | ||
9 | #include <asm/stacktrace.h> | 10 | #include <asm/stacktrace.h> |
10 | 11 | ||
11 | static void save_stack_warning(void *data, char *msg) | 12 | static void save_stack_warning(void *data, char *msg) |
@@ -83,3 +84,66 @@ void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace) | |||
83 | trace->entries[trace->nr_entries++] = ULONG_MAX; | 84 | trace->entries[trace->nr_entries++] = ULONG_MAX; |
84 | } | 85 | } |
85 | EXPORT_SYMBOL_GPL(save_stack_trace_tsk); | 86 | EXPORT_SYMBOL_GPL(save_stack_trace_tsk); |
87 | |||
88 | /* Userspace stacktrace - based on kernel/trace/trace_sysprof.c */ | ||
89 | |||
90 | struct stack_frame { | ||
91 | const void __user *next_fp; | ||
92 | unsigned long ret_addr; | ||
93 | }; | ||
94 | |||
95 | static int copy_stack_frame(const void __user *fp, struct stack_frame *frame) | ||
96 | { | ||
97 | int ret; | ||
98 | |||
99 | if (!access_ok(VERIFY_READ, fp, sizeof(*frame))) | ||
100 | return 0; | ||
101 | |||
102 | ret = 1; | ||
103 | pagefault_disable(); | ||
104 | if (__copy_from_user_inatomic(frame, fp, sizeof(*frame))) | ||
105 | ret = 0; | ||
106 | pagefault_enable(); | ||
107 | |||
108 | return ret; | ||
109 | } | ||
110 | |||
111 | static inline void __save_stack_trace_user(struct stack_trace *trace) | ||
112 | { | ||
113 | const struct pt_regs *regs = task_pt_regs(current); | ||
114 | const void __user *fp = (const void __user *)regs->bp; | ||
115 | |||
116 | if (trace->nr_entries < trace->max_entries) | ||
117 | trace->entries[trace->nr_entries++] = regs->ip; | ||
118 | |||
119 | while (trace->nr_entries < trace->max_entries) { | ||
120 | struct stack_frame frame; | ||
121 | |||
122 | frame.next_fp = NULL; | ||
123 | frame.ret_addr = 0; | ||
124 | if (!copy_stack_frame(fp, &frame)) | ||
125 | break; | ||
126 | if ((unsigned long)fp < regs->sp) | ||
127 | break; | ||
128 | if (frame.ret_addr) { | ||
129 | trace->entries[trace->nr_entries++] = | ||
130 | frame.ret_addr; | ||
131 | } | ||
132 | if (fp == frame.next_fp) | ||
133 | break; | ||
134 | fp = frame.next_fp; | ||
135 | } | ||
136 | } | ||
137 | |||
138 | void save_stack_trace_user(struct stack_trace *trace) | ||
139 | { | ||
140 | /* | ||
141 | * Trace user stack if we are not a kernel thread | ||
142 | */ | ||
143 | if (current->mm) { | ||
144 | __save_stack_trace_user(trace); | ||
145 | } | ||
146 | if (trace->nr_entries < trace->max_entries) | ||
147 | trace->entries[trace->nr_entries++] = ULONG_MAX; | ||
148 | } | ||
149 | |||
diff --git a/arch/x86/kernel/time_32.c b/arch/x86/kernel/time_32.c index 77b400f06ea2..65309e4cb1c0 100644 --- a/arch/x86/kernel/time_32.c +++ b/arch/x86/kernel/time_32.c | |||
@@ -75,7 +75,7 @@ EXPORT_SYMBOL(profile_pc); | |||
75 | irqreturn_t timer_interrupt(int irq, void *dev_id) | 75 | irqreturn_t timer_interrupt(int irq, void *dev_id) |
76 | { | 76 | { |
77 | /* Keep nmi watchdog up to date */ | 77 | /* Keep nmi watchdog up to date */ |
78 | per_cpu(irq_stat, smp_processor_id()).irq0_irqs++; | 78 | inc_irq_stat(irq0_irqs); |
79 | 79 | ||
80 | #ifdef CONFIG_X86_IO_APIC | 80 | #ifdef CONFIG_X86_IO_APIC |
81 | if (timer_ack) { | 81 | if (timer_ack) { |
diff --git a/arch/x86/kernel/time_64.c b/arch/x86/kernel/time_64.c index cb19d650c216..891e7a7c4334 100644 --- a/arch/x86/kernel/time_64.c +++ b/arch/x86/kernel/time_64.c | |||
@@ -49,9 +49,9 @@ unsigned long profile_pc(struct pt_regs *regs) | |||
49 | } | 49 | } |
50 | EXPORT_SYMBOL(profile_pc); | 50 | EXPORT_SYMBOL(profile_pc); |
51 | 51 | ||
52 | irqreturn_t timer_interrupt(int irq, void *dev_id) | 52 | static irqreturn_t timer_interrupt(int irq, void *dev_id) |
53 | { | 53 | { |
54 | add_pda(irq0_irqs, 1); | 54 | inc_irq_stat(irq0_irqs); |
55 | 55 | ||
56 | global_clock_event->event_handler(global_clock_event); | 56 | global_clock_event->event_handler(global_clock_event); |
57 | 57 | ||
@@ -80,6 +80,8 @@ unsigned long __init calibrate_cpu(void) | |||
80 | break; | 80 | break; |
81 | no_ctr_free = (i == 4); | 81 | no_ctr_free = (i == 4); |
82 | if (no_ctr_free) { | 82 | if (no_ctr_free) { |
83 | WARN(1, KERN_WARNING "Warning: AMD perfctrs busy ... " | ||
84 | "cpu_khz value may be incorrect.\n"); | ||
83 | i = 3; | 85 | i = 3; |
84 | rdmsrl(MSR_K7_EVNTSEL3, evntsel3); | 86 | rdmsrl(MSR_K7_EVNTSEL3, evntsel3); |
85 | wrmsrl(MSR_K7_EVNTSEL3, 0); | 87 | wrmsrl(MSR_K7_EVNTSEL3, 0); |
diff --git a/arch/x86/kernel/tlb_32.c b/arch/x86/kernel/tlb_32.c index f4049f3513b6..ce5054642247 100644 --- a/arch/x86/kernel/tlb_32.c +++ b/arch/x86/kernel/tlb_32.c | |||
@@ -34,9 +34,8 @@ static DEFINE_SPINLOCK(tlbstate_lock); | |||
34 | */ | 34 | */ |
35 | void leave_mm(int cpu) | 35 | void leave_mm(int cpu) |
36 | { | 36 | { |
37 | if (per_cpu(cpu_tlbstate, cpu).state == TLBSTATE_OK) | 37 | BUG_ON(x86_read_percpu(cpu_tlbstate.state) == TLBSTATE_OK); |
38 | BUG(); | 38 | cpu_clear(cpu, x86_read_percpu(cpu_tlbstate.active_mm)->cpu_vm_mask); |
39 | cpu_clear(cpu, per_cpu(cpu_tlbstate, cpu).active_mm->cpu_vm_mask); | ||
40 | load_cr3(swapper_pg_dir); | 39 | load_cr3(swapper_pg_dir); |
41 | } | 40 | } |
42 | EXPORT_SYMBOL_GPL(leave_mm); | 41 | EXPORT_SYMBOL_GPL(leave_mm); |
@@ -104,8 +103,8 @@ void smp_invalidate_interrupt(struct pt_regs *regs) | |||
104 | * BUG(); | 103 | * BUG(); |
105 | */ | 104 | */ |
106 | 105 | ||
107 | if (flush_mm == per_cpu(cpu_tlbstate, cpu).active_mm) { | 106 | if (flush_mm == x86_read_percpu(cpu_tlbstate.active_mm)) { |
108 | if (per_cpu(cpu_tlbstate, cpu).state == TLBSTATE_OK) { | 107 | if (x86_read_percpu(cpu_tlbstate.state) == TLBSTATE_OK) { |
109 | if (flush_va == TLB_FLUSH_ALL) | 108 | if (flush_va == TLB_FLUSH_ALL) |
110 | local_flush_tlb(); | 109 | local_flush_tlb(); |
111 | else | 110 | else |
@@ -119,7 +118,7 @@ void smp_invalidate_interrupt(struct pt_regs *regs) | |||
119 | smp_mb__after_clear_bit(); | 118 | smp_mb__after_clear_bit(); |
120 | out: | 119 | out: |
121 | put_cpu_no_resched(); | 120 | put_cpu_no_resched(); |
122 | __get_cpu_var(irq_stat).irq_tlb_count++; | 121 | inc_irq_stat(irq_tlb_count); |
123 | } | 122 | } |
124 | 123 | ||
125 | void native_flush_tlb_others(const cpumask_t *cpumaskp, struct mm_struct *mm, | 124 | void native_flush_tlb_others(const cpumask_t *cpumaskp, struct mm_struct *mm, |
@@ -164,7 +163,7 @@ void native_flush_tlb_others(const cpumask_t *cpumaskp, struct mm_struct *mm, | |||
164 | * We have to send the IPI only to | 163 | * We have to send the IPI only to |
165 | * CPUs affected. | 164 | * CPUs affected. |
166 | */ | 165 | */ |
167 | send_IPI_mask(cpumask, INVALIDATE_TLB_VECTOR); | 166 | send_IPI_mask(&cpumask, INVALIDATE_TLB_VECTOR); |
168 | 167 | ||
169 | while (!cpus_empty(flush_cpumask)) | 168 | while (!cpus_empty(flush_cpumask)) |
170 | /* nothing. lockup detection does not belong here */ | 169 | /* nothing. lockup detection does not belong here */ |
@@ -238,7 +237,7 @@ static void do_flush_tlb_all(void *info) | |||
238 | unsigned long cpu = smp_processor_id(); | 237 | unsigned long cpu = smp_processor_id(); |
239 | 238 | ||
240 | __flush_tlb_all(); | 239 | __flush_tlb_all(); |
241 | if (per_cpu(cpu_tlbstate, cpu).state == TLBSTATE_LAZY) | 240 | if (x86_read_percpu(cpu_tlbstate.state) == TLBSTATE_LAZY) |
242 | leave_mm(cpu); | 241 | leave_mm(cpu); |
243 | } | 242 | } |
244 | 243 | ||
diff --git a/arch/x86/kernel/tlb_64.c b/arch/x86/kernel/tlb_64.c index 8f919ca69494..f8be6f1d2e48 100644 --- a/arch/x86/kernel/tlb_64.c +++ b/arch/x86/kernel/tlb_64.c | |||
@@ -154,7 +154,7 @@ asmlinkage void smp_invalidate_interrupt(struct pt_regs *regs) | |||
154 | out: | 154 | out: |
155 | ack_APIC_irq(); | 155 | ack_APIC_irq(); |
156 | cpu_clear(cpu, f->flush_cpumask); | 156 | cpu_clear(cpu, f->flush_cpumask); |
157 | add_pda(irq_tlb_count, 1); | 157 | inc_irq_stat(irq_tlb_count); |
158 | } | 158 | } |
159 | 159 | ||
160 | void native_flush_tlb_others(const cpumask_t *cpumaskp, struct mm_struct *mm, | 160 | void native_flush_tlb_others(const cpumask_t *cpumaskp, struct mm_struct *mm, |
@@ -191,7 +191,7 @@ void native_flush_tlb_others(const cpumask_t *cpumaskp, struct mm_struct *mm, | |||
191 | * We have to send the IPI only to | 191 | * We have to send the IPI only to |
192 | * CPUs affected. | 192 | * CPUs affected. |
193 | */ | 193 | */ |
194 | send_IPI_mask(cpumask, INVALIDATE_TLB_VECTOR_START + sender); | 194 | send_IPI_mask(&cpumask, INVALIDATE_TLB_VECTOR_START + sender); |
195 | 195 | ||
196 | while (!cpus_empty(f->flush_cpumask)) | 196 | while (!cpus_empty(f->flush_cpumask)) |
197 | cpu_relax(); | 197 | cpu_relax(); |
diff --git a/arch/x86/kernel/tlb_uv.c b/arch/x86/kernel/tlb_uv.c index 04431f34fd16..f885023167e0 100644 --- a/arch/x86/kernel/tlb_uv.c +++ b/arch/x86/kernel/tlb_uv.c | |||
@@ -566,14 +566,10 @@ static int __init uv_ptc_init(void) | |||
566 | if (!is_uv_system()) | 566 | if (!is_uv_system()) |
567 | return 0; | 567 | return 0; |
568 | 568 | ||
569 | if (!proc_mkdir("sgi_uv", NULL)) | ||
570 | return -EINVAL; | ||
571 | |||
572 | proc_uv_ptc = create_proc_entry(UV_PTC_BASENAME, 0444, NULL); | 569 | proc_uv_ptc = create_proc_entry(UV_PTC_BASENAME, 0444, NULL); |
573 | if (!proc_uv_ptc) { | 570 | if (!proc_uv_ptc) { |
574 | printk(KERN_ERR "unable to create %s proc entry\n", | 571 | printk(KERN_ERR "unable to create %s proc entry\n", |
575 | UV_PTC_BASENAME); | 572 | UV_PTC_BASENAME); |
576 | remove_proc_entry("sgi_uv", NULL); | ||
577 | return -EINVAL; | 573 | return -EINVAL; |
578 | } | 574 | } |
579 | proc_uv_ptc->proc_fops = &proc_uv_ptc_operations; | 575 | proc_uv_ptc->proc_fops = &proc_uv_ptc_operations; |
@@ -586,7 +582,6 @@ static int __init uv_ptc_init(void) | |||
586 | static struct bau_control * __init uv_table_bases_init(int blade, int node) | 582 | static struct bau_control * __init uv_table_bases_init(int blade, int node) |
587 | { | 583 | { |
588 | int i; | 584 | int i; |
589 | int *ip; | ||
590 | struct bau_msg_status *msp; | 585 | struct bau_msg_status *msp; |
591 | struct bau_control *bau_tabp; | 586 | struct bau_control *bau_tabp; |
592 | 587 | ||
@@ -603,13 +598,6 @@ static struct bau_control * __init uv_table_bases_init(int blade, int node) | |||
603 | bau_cpubits_clear(&msp->seen_by, (int) | 598 | bau_cpubits_clear(&msp->seen_by, (int) |
604 | uv_blade_nr_possible_cpus(blade)); | 599 | uv_blade_nr_possible_cpus(blade)); |
605 | 600 | ||
606 | bau_tabp->watching = | ||
607 | kmalloc_node(sizeof(int) * DEST_NUM_RESOURCES, GFP_KERNEL, node); | ||
608 | BUG_ON(!bau_tabp->watching); | ||
609 | |||
610 | for (i = 0, ip = bau_tabp->watching; i < DEST_Q_SIZE; i++, ip++) | ||
611 | *ip = 0; | ||
612 | |||
613 | uv_bau_table_bases[blade] = bau_tabp; | 601 | uv_bau_table_bases[blade] = bau_tabp; |
614 | 602 | ||
615 | return bau_tabp; | 603 | return bau_tabp; |
@@ -632,7 +620,6 @@ uv_table_bases_finish(int blade, int node, int cur_cpu, | |||
632 | bcp->bau_msg_head = bau_tablesp->va_queue_first; | 620 | bcp->bau_msg_head = bau_tablesp->va_queue_first; |
633 | bcp->va_queue_first = bau_tablesp->va_queue_first; | 621 | bcp->va_queue_first = bau_tablesp->va_queue_first; |
634 | bcp->va_queue_last = bau_tablesp->va_queue_last; | 622 | bcp->va_queue_last = bau_tablesp->va_queue_last; |
635 | bcp->watching = bau_tablesp->watching; | ||
636 | bcp->msg_statuses = bau_tablesp->msg_statuses; | 623 | bcp->msg_statuses = bau_tablesp->msg_statuses; |
637 | bcp->descriptor_base = adp; | 624 | bcp->descriptor_base = adp; |
638 | } | 625 | } |
diff --git a/arch/x86/kernel/trampoline.c b/arch/x86/kernel/trampoline.c index 1106fac6024d..808031a5ba19 100644 --- a/arch/x86/kernel/trampoline.c +++ b/arch/x86/kernel/trampoline.c | |||
@@ -1,10 +1,26 @@ | |||
1 | #include <linux/io.h> | 1 | #include <linux/io.h> |
2 | 2 | ||
3 | #include <asm/trampoline.h> | 3 | #include <asm/trampoline.h> |
4 | #include <asm/e820.h> | ||
4 | 5 | ||
5 | /* ready for x86_64 and x86 */ | 6 | /* ready for x86_64 and x86 */ |
6 | unsigned char *trampoline_base = __va(TRAMPOLINE_BASE); | 7 | unsigned char *trampoline_base = __va(TRAMPOLINE_BASE); |
7 | 8 | ||
9 | void __init reserve_trampoline_memory(void) | ||
10 | { | ||
11 | #ifdef CONFIG_X86_32 | ||
12 | /* | ||
13 | * But first pinch a few for the stack/trampoline stuff | ||
14 | * FIXME: Don't need the extra page at 4K, but need to fix | ||
15 | * trampoline before removing it. (see the GDT stuff) | ||
16 | */ | ||
17 | reserve_early(PAGE_SIZE, PAGE_SIZE + PAGE_SIZE, "EX TRAMPOLINE"); | ||
18 | #endif | ||
19 | /* Has to be in very low memory so we can execute real-mode AP code. */ | ||
20 | reserve_early(TRAMPOLINE_BASE, TRAMPOLINE_BASE + TRAMPOLINE_SIZE, | ||
21 | "TRAMPOLINE"); | ||
22 | } | ||
23 | |||
8 | /* | 24 | /* |
9 | * Currently trivial. Write the real->protected mode | 25 | * Currently trivial. Write the real->protected mode |
10 | * bootstrap into the page concerned. The caller | 26 | * bootstrap into the page concerned. The caller |
@@ -12,7 +28,6 @@ unsigned char *trampoline_base = __va(TRAMPOLINE_BASE); | |||
12 | */ | 28 | */ |
13 | unsigned long setup_trampoline(void) | 29 | unsigned long setup_trampoline(void) |
14 | { | 30 | { |
15 | memcpy(trampoline_base, trampoline_data, | 31 | memcpy(trampoline_base, trampoline_data, TRAMPOLINE_SIZE); |
16 | trampoline_end - trampoline_data); | ||
17 | return virt_to_phys(trampoline_base); | 32 | return virt_to_phys(trampoline_base); |
18 | } | 33 | } |
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 04d242ab0161..c9a666cdd3db 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c | |||
@@ -20,7 +20,6 @@ | |||
20 | #include <linux/module.h> | 20 | #include <linux/module.h> |
21 | #include <linux/ptrace.h> | 21 | #include <linux/ptrace.h> |
22 | #include <linux/string.h> | 22 | #include <linux/string.h> |
23 | #include <linux/unwind.h> | ||
24 | #include <linux/delay.h> | 23 | #include <linux/delay.h> |
25 | #include <linux/errno.h> | 24 | #include <linux/errno.h> |
26 | #include <linux/kexec.h> | 25 | #include <linux/kexec.h> |
@@ -51,7 +50,6 @@ | |||
51 | #include <asm/debugreg.h> | 50 | #include <asm/debugreg.h> |
52 | #include <asm/atomic.h> | 51 | #include <asm/atomic.h> |
53 | #include <asm/system.h> | 52 | #include <asm/system.h> |
54 | #include <asm/unwind.h> | ||
55 | #include <asm/traps.h> | 53 | #include <asm/traps.h> |
56 | #include <asm/desc.h> | 54 | #include <asm/desc.h> |
57 | #include <asm/i387.h> | 55 | #include <asm/i387.h> |
@@ -72,9 +70,6 @@ | |||
72 | 70 | ||
73 | #include "cpu/mcheck/mce.h" | 71 | #include "cpu/mcheck/mce.h" |
74 | 72 | ||
75 | DECLARE_BITMAP(used_vectors, NR_VECTORS); | ||
76 | EXPORT_SYMBOL_GPL(used_vectors); | ||
77 | |||
78 | asmlinkage int system_call(void); | 73 | asmlinkage int system_call(void); |
79 | 74 | ||
80 | /* Do we ignore FPU interrupts ? */ | 75 | /* Do we ignore FPU interrupts ? */ |
@@ -89,6 +84,9 @@ gate_desc idt_table[256] | |||
89 | __attribute__((__section__(".data.idt"))) = { { { { 0, 0 } } }, }; | 84 | __attribute__((__section__(".data.idt"))) = { { { { 0, 0 } } }, }; |
90 | #endif | 85 | #endif |
91 | 86 | ||
87 | DECLARE_BITMAP(used_vectors, NR_VECTORS); | ||
88 | EXPORT_SYMBOL_GPL(used_vectors); | ||
89 | |||
92 | static int ignore_nmis; | 90 | static int ignore_nmis; |
93 | 91 | ||
94 | static inline void conditional_sti(struct pt_regs *regs) | 92 | static inline void conditional_sti(struct pt_regs *regs) |
@@ -292,8 +290,10 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code) | |||
292 | tsk->thread.error_code = error_code; | 290 | tsk->thread.error_code = error_code; |
293 | tsk->thread.trap_no = 8; | 291 | tsk->thread.trap_no = 8; |
294 | 292 | ||
295 | /* This is always a kernel trap and never fixable (and thus must | 293 | /* |
296 | never return). */ | 294 | * This is always a kernel trap and never fixable (and thus must |
295 | * never return). | ||
296 | */ | ||
297 | for (;;) | 297 | for (;;) |
298 | die(str, regs, error_code); | 298 | die(str, regs, error_code); |
299 | } | 299 | } |
@@ -481,11 +481,7 @@ do_nmi(struct pt_regs *regs, long error_code) | |||
481 | { | 481 | { |
482 | nmi_enter(); | 482 | nmi_enter(); |
483 | 483 | ||
484 | #ifdef CONFIG_X86_32 | 484 | inc_irq_stat(__nmi_count); |
485 | { int cpu; cpu = smp_processor_id(); ++nmi_count(cpu); } | ||
486 | #else | ||
487 | add_pda(__nmi_count, 1); | ||
488 | #endif | ||
489 | 485 | ||
490 | if (!ignore_nmis) | 486 | if (!ignore_nmis) |
491 | default_do_nmi(regs); | 487 | default_do_nmi(regs); |
@@ -524,9 +520,11 @@ dotraplinkage void __kprobes do_int3(struct pt_regs *regs, long error_code) | |||
524 | } | 520 | } |
525 | 521 | ||
526 | #ifdef CONFIG_X86_64 | 522 | #ifdef CONFIG_X86_64 |
527 | /* Help handler running on IST stack to switch back to user stack | 523 | /* |
528 | for scheduling or signal handling. The actual stack switch is done in | 524 | * Help handler running on IST stack to switch back to user stack |
529 | entry.S */ | 525 | * for scheduling or signal handling. The actual stack switch is done in |
526 | * entry.S | ||
527 | */ | ||
530 | asmlinkage __kprobes struct pt_regs *sync_regs(struct pt_regs *eregs) | 528 | asmlinkage __kprobes struct pt_regs *sync_regs(struct pt_regs *eregs) |
531 | { | 529 | { |
532 | struct pt_regs *regs = eregs; | 530 | struct pt_regs *regs = eregs; |
@@ -536,8 +534,10 @@ asmlinkage __kprobes struct pt_regs *sync_regs(struct pt_regs *eregs) | |||
536 | /* Exception from user space */ | 534 | /* Exception from user space */ |
537 | else if (user_mode(eregs)) | 535 | else if (user_mode(eregs)) |
538 | regs = task_pt_regs(current); | 536 | regs = task_pt_regs(current); |
539 | /* Exception from kernel and interrupts are enabled. Move to | 537 | /* |
540 | kernel process stack. */ | 538 | * Exception from kernel and interrupts are enabled. Move to |
539 | * kernel process stack. | ||
540 | */ | ||
541 | else if (eregs->flags & X86_EFLAGS_IF) | 541 | else if (eregs->flags & X86_EFLAGS_IF) |
542 | regs = (struct pt_regs *)(eregs->sp -= sizeof(struct pt_regs)); | 542 | regs = (struct pt_regs *)(eregs->sp -= sizeof(struct pt_regs)); |
543 | if (eregs != regs) | 543 | if (eregs != regs) |
@@ -664,7 +664,7 @@ void math_error(void __user *ip) | |||
664 | { | 664 | { |
665 | struct task_struct *task; | 665 | struct task_struct *task; |
666 | siginfo_t info; | 666 | siginfo_t info; |
667 | unsigned short cwd, swd; | 667 | unsigned short cwd, swd, err; |
668 | 668 | ||
669 | /* | 669 | /* |
670 | * Save the info for the exception handler and clear the error. | 670 | * Save the info for the exception handler and clear the error. |
@@ -675,7 +675,6 @@ void math_error(void __user *ip) | |||
675 | task->thread.error_code = 0; | 675 | task->thread.error_code = 0; |
676 | info.si_signo = SIGFPE; | 676 | info.si_signo = SIGFPE; |
677 | info.si_errno = 0; | 677 | info.si_errno = 0; |
678 | info.si_code = __SI_FAULT; | ||
679 | info.si_addr = ip; | 678 | info.si_addr = ip; |
680 | /* | 679 | /* |
681 | * (~cwd & swd) will mask out exceptions that are not set to unmasked | 680 | * (~cwd & swd) will mask out exceptions that are not set to unmasked |
@@ -689,34 +688,30 @@ void math_error(void __user *ip) | |||
689 | */ | 688 | */ |
690 | cwd = get_fpu_cwd(task); | 689 | cwd = get_fpu_cwd(task); |
691 | swd = get_fpu_swd(task); | 690 | swd = get_fpu_swd(task); |
692 | switch (swd & ~cwd & 0x3f) { | 691 | |
693 | case 0x000: /* No unmasked exception */ | 692 | err = swd & ~cwd; |
694 | #ifdef CONFIG_X86_32 | 693 | |
695 | return; | 694 | if (err & 0x001) { /* Invalid op */ |
696 | #endif | ||
697 | default: /* Multiple exceptions */ | ||
698 | break; | ||
699 | case 0x001: /* Invalid Op */ | ||
700 | /* | 695 | /* |
701 | * swd & 0x240 == 0x040: Stack Underflow | 696 | * swd & 0x240 == 0x040: Stack Underflow |
702 | * swd & 0x240 == 0x240: Stack Overflow | 697 | * swd & 0x240 == 0x240: Stack Overflow |
703 | * User must clear the SF bit (0x40) if set | 698 | * User must clear the SF bit (0x40) if set |
704 | */ | 699 | */ |
705 | info.si_code = FPE_FLTINV; | 700 | info.si_code = FPE_FLTINV; |
706 | break; | 701 | } else if (err & 0x004) { /* Divide by Zero */ |
707 | case 0x002: /* Denormalize */ | ||
708 | case 0x010: /* Underflow */ | ||
709 | info.si_code = FPE_FLTUND; | ||
710 | break; | ||
711 | case 0x004: /* Zero Divide */ | ||
712 | info.si_code = FPE_FLTDIV; | 702 | info.si_code = FPE_FLTDIV; |
713 | break; | 703 | } else if (err & 0x008) { /* Overflow */ |
714 | case 0x008: /* Overflow */ | ||
715 | info.si_code = FPE_FLTOVF; | 704 | info.si_code = FPE_FLTOVF; |
716 | break; | 705 | } else if (err & 0x012) { /* Denormal, Underflow */ |
717 | case 0x020: /* Precision */ | 706 | info.si_code = FPE_FLTUND; |
707 | } else if (err & 0x020) { /* Precision */ | ||
718 | info.si_code = FPE_FLTRES; | 708 | info.si_code = FPE_FLTRES; |
719 | break; | 709 | } else { |
710 | /* | ||
711 | * If we're using IRQ 13, or supposedly even some trap 16 | ||
712 | * implementations, it's possible we get a spurious trap... | ||
713 | */ | ||
714 | return; /* Spurious trap, no error */ | ||
720 | } | 715 | } |
721 | force_sig_info(SIGFPE, &info, task); | 716 | force_sig_info(SIGFPE, &info, task); |
722 | } | 717 | } |
@@ -949,9 +944,7 @@ dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code) | |||
949 | 944 | ||
950 | void __init trap_init(void) | 945 | void __init trap_init(void) |
951 | { | 946 | { |
952 | #ifdef CONFIG_X86_32 | ||
953 | int i; | 947 | int i; |
954 | #endif | ||
955 | 948 | ||
956 | #ifdef CONFIG_EISA | 949 | #ifdef CONFIG_EISA |
957 | void __iomem *p = early_ioremap(0x0FFFD9, 4); | 950 | void __iomem *p = early_ioremap(0x0FFFD9, 4); |
@@ -1008,11 +1001,15 @@ void __init trap_init(void) | |||
1008 | } | 1001 | } |
1009 | 1002 | ||
1010 | set_system_trap_gate(SYSCALL_VECTOR, &system_call); | 1003 | set_system_trap_gate(SYSCALL_VECTOR, &system_call); |
1004 | #endif | ||
1011 | 1005 | ||
1012 | /* Reserve all the builtin and the syscall vector: */ | 1006 | /* Reserve all the builtin and the syscall vector: */ |
1013 | for (i = 0; i < FIRST_EXTERNAL_VECTOR; i++) | 1007 | for (i = 0; i < FIRST_EXTERNAL_VECTOR; i++) |
1014 | set_bit(i, used_vectors); | 1008 | set_bit(i, used_vectors); |
1015 | 1009 | ||
1010 | #ifdef CONFIG_X86_64 | ||
1011 | set_bit(IA32_SYSCALL_VECTOR, used_vectors); | ||
1012 | #else | ||
1016 | set_bit(SYSCALL_VECTOR, used_vectors); | 1013 | set_bit(SYSCALL_VECTOR, used_vectors); |
1017 | #endif | 1014 | #endif |
1018 | /* | 1015 | /* |
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 424093b157d3..599e58168631 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <asm/vgtod.h> | 15 | #include <asm/vgtod.h> |
16 | #include <asm/time.h> | 16 | #include <asm/time.h> |
17 | #include <asm/delay.h> | 17 | #include <asm/delay.h> |
18 | #include <asm/hypervisor.h> | ||
18 | 19 | ||
19 | unsigned int cpu_khz; /* TSC clocks / usec, not used here */ | 20 | unsigned int cpu_khz; /* TSC clocks / usec, not used here */ |
20 | EXPORT_SYMBOL(cpu_khz); | 21 | EXPORT_SYMBOL(cpu_khz); |
@@ -31,6 +32,7 @@ static int tsc_unstable; | |||
31 | erroneous rdtsc usage on !cpu_has_tsc processors */ | 32 | erroneous rdtsc usage on !cpu_has_tsc processors */ |
32 | static int tsc_disabled = -1; | 33 | static int tsc_disabled = -1; |
33 | 34 | ||
35 | static int tsc_clocksource_reliable; | ||
34 | /* | 36 | /* |
35 | * Scheduler clock - returns current time in nanosec units. | 37 | * Scheduler clock - returns current time in nanosec units. |
36 | */ | 38 | */ |
@@ -98,6 +100,15 @@ int __init notsc_setup(char *str) | |||
98 | 100 | ||
99 | __setup("notsc", notsc_setup); | 101 | __setup("notsc", notsc_setup); |
100 | 102 | ||
103 | static int __init tsc_setup(char *str) | ||
104 | { | ||
105 | if (!strcmp(str, "reliable")) | ||
106 | tsc_clocksource_reliable = 1; | ||
107 | return 1; | ||
108 | } | ||
109 | |||
110 | __setup("tsc=", tsc_setup); | ||
111 | |||
101 | #define MAX_RETRIES 5 | 112 | #define MAX_RETRIES 5 |
102 | #define SMI_TRESHOLD 50000 | 113 | #define SMI_TRESHOLD 50000 |
103 | 114 | ||
@@ -352,9 +363,15 @@ unsigned long native_calibrate_tsc(void) | |||
352 | { | 363 | { |
353 | u64 tsc1, tsc2, delta, ref1, ref2; | 364 | u64 tsc1, tsc2, delta, ref1, ref2; |
354 | unsigned long tsc_pit_min = ULONG_MAX, tsc_ref_min = ULONG_MAX; | 365 | unsigned long tsc_pit_min = ULONG_MAX, tsc_ref_min = ULONG_MAX; |
355 | unsigned long flags, latch, ms, fast_calibrate; | 366 | unsigned long flags, latch, ms, fast_calibrate, tsc_khz; |
356 | int hpet = is_hpet_enabled(), i, loopmin; | 367 | int hpet = is_hpet_enabled(), i, loopmin; |
357 | 368 | ||
369 | tsc_khz = get_hypervisor_tsc_freq(); | ||
370 | if (tsc_khz) { | ||
371 | printk(KERN_INFO "TSC: Frequency read from the hypervisor\n"); | ||
372 | return tsc_khz; | ||
373 | } | ||
374 | |||
358 | local_irq_save(flags); | 375 | local_irq_save(flags); |
359 | fast_calibrate = quick_pit_calibrate(); | 376 | fast_calibrate = quick_pit_calibrate(); |
360 | local_irq_restore(flags); | 377 | local_irq_restore(flags); |
@@ -731,24 +748,21 @@ static struct dmi_system_id __initdata bad_tsc_dmi_table[] = { | |||
731 | {} | 748 | {} |
732 | }; | 749 | }; |
733 | 750 | ||
734 | /* | 751 | static void __init check_system_tsc_reliable(void) |
735 | * Geode_LX - the OLPC CPU has a possibly a very reliable TSC | 752 | { |
736 | */ | ||
737 | #ifdef CONFIG_MGEODE_LX | 753 | #ifdef CONFIG_MGEODE_LX |
738 | /* RTSC counts during suspend */ | 754 | /* RTSC counts during suspend */ |
739 | #define RTSC_SUSP 0x100 | 755 | #define RTSC_SUSP 0x100 |
740 | |||
741 | static void __init check_geode_tsc_reliable(void) | ||
742 | { | ||
743 | unsigned long res_low, res_high; | 756 | unsigned long res_low, res_high; |
744 | 757 | ||
745 | rdmsr_safe(MSR_GEODE_BUSCONT_CONF0, &res_low, &res_high); | 758 | rdmsr_safe(MSR_GEODE_BUSCONT_CONF0, &res_low, &res_high); |
759 | /* Geode_LX - the OLPC CPU has a possibly a very reliable TSC */ | ||
746 | if (res_low & RTSC_SUSP) | 760 | if (res_low & RTSC_SUSP) |
747 | clocksource_tsc.flags &= ~CLOCK_SOURCE_MUST_VERIFY; | 761 | tsc_clocksource_reliable = 1; |
748 | } | ||
749 | #else | ||
750 | static inline void check_geode_tsc_reliable(void) { } | ||
751 | #endif | 762 | #endif |
763 | if (boot_cpu_has(X86_FEATURE_TSC_RELIABLE)) | ||
764 | tsc_clocksource_reliable = 1; | ||
765 | } | ||
752 | 766 | ||
753 | /* | 767 | /* |
754 | * Make an educated guess if the TSC is trustworthy and synchronized | 768 | * Make an educated guess if the TSC is trustworthy and synchronized |
@@ -783,6 +797,8 @@ static void __init init_tsc_clocksource(void) | |||
783 | { | 797 | { |
784 | clocksource_tsc.mult = clocksource_khz2mult(tsc_khz, | 798 | clocksource_tsc.mult = clocksource_khz2mult(tsc_khz, |
785 | clocksource_tsc.shift); | 799 | clocksource_tsc.shift); |
800 | if (tsc_clocksource_reliable) | ||
801 | clocksource_tsc.flags &= ~CLOCK_SOURCE_MUST_VERIFY; | ||
786 | /* lower the rating if we already know its unstable: */ | 802 | /* lower the rating if we already know its unstable: */ |
787 | if (check_tsc_unstable()) { | 803 | if (check_tsc_unstable()) { |
788 | clocksource_tsc.rating = 0; | 804 | clocksource_tsc.rating = 0; |
@@ -843,7 +859,7 @@ void __init tsc_init(void) | |||
843 | if (unsynchronized_tsc()) | 859 | if (unsynchronized_tsc()) |
844 | mark_tsc_unstable("TSCs unsynchronized"); | 860 | mark_tsc_unstable("TSCs unsynchronized"); |
845 | 861 | ||
846 | check_geode_tsc_reliable(); | 862 | check_system_tsc_reliable(); |
847 | init_tsc_clocksource(); | 863 | init_tsc_clocksource(); |
848 | } | 864 | } |
849 | 865 | ||
diff --git a/arch/x86/kernel/tsc_sync.c b/arch/x86/kernel/tsc_sync.c index 1c0dfbca87c1..bf36328f6ef9 100644 --- a/arch/x86/kernel/tsc_sync.c +++ b/arch/x86/kernel/tsc_sync.c | |||
@@ -112,6 +112,12 @@ void __cpuinit check_tsc_sync_source(int cpu) | |||
112 | if (unsynchronized_tsc()) | 112 | if (unsynchronized_tsc()) |
113 | return; | 113 | return; |
114 | 114 | ||
115 | if (boot_cpu_has(X86_FEATURE_TSC_RELIABLE)) { | ||
116 | printk(KERN_INFO | ||
117 | "Skipping synchronization checks as TSC is reliable.\n"); | ||
118 | return; | ||
119 | } | ||
120 | |||
115 | printk(KERN_INFO "checking TSC synchronization [CPU#%d -> CPU#%d]:", | 121 | printk(KERN_INFO "checking TSC synchronization [CPU#%d -> CPU#%d]:", |
116 | smp_processor_id(), cpu); | 122 | smp_processor_id(), cpu); |
117 | 123 | ||
@@ -165,7 +171,7 @@ void __cpuinit check_tsc_sync_target(void) | |||
165 | { | 171 | { |
166 | int cpus = 2; | 172 | int cpus = 2; |
167 | 173 | ||
168 | if (unsynchronized_tsc()) | 174 | if (unsynchronized_tsc() || boot_cpu_has(X86_FEATURE_TSC_RELIABLE)) |
169 | return; | 175 | return; |
170 | 176 | ||
171 | /* | 177 | /* |
diff --git a/arch/x86/kernel/vmi_32.c b/arch/x86/kernel/vmi_32.c index 22fd6577156a..23206ba16874 100644 --- a/arch/x86/kernel/vmi_32.c +++ b/arch/x86/kernel/vmi_32.c | |||
@@ -266,109 +266,6 @@ static void vmi_nop(void) | |||
266 | { | 266 | { |
267 | } | 267 | } |
268 | 268 | ||
269 | #ifdef CONFIG_DEBUG_PAGE_TYPE | ||
270 | |||
271 | #ifdef CONFIG_X86_PAE | ||
272 | #define MAX_BOOT_PTS (2048+4+1) | ||
273 | #else | ||
274 | #define MAX_BOOT_PTS (1024+1) | ||
275 | #endif | ||
276 | |||
277 | /* | ||
278 | * During boot, mem_map is not yet available in paging_init, so stash | ||
279 | * all the boot page allocations here. | ||
280 | */ | ||
281 | static struct { | ||
282 | u32 pfn; | ||
283 | int type; | ||
284 | } boot_page_allocations[MAX_BOOT_PTS]; | ||
285 | static int num_boot_page_allocations; | ||
286 | static int boot_allocations_applied; | ||
287 | |||
288 | void vmi_apply_boot_page_allocations(void) | ||
289 | { | ||
290 | int i; | ||
291 | BUG_ON(!mem_map); | ||
292 | for (i = 0; i < num_boot_page_allocations; i++) { | ||
293 | struct page *page = pfn_to_page(boot_page_allocations[i].pfn); | ||
294 | page->type = boot_page_allocations[i].type; | ||
295 | page->type = boot_page_allocations[i].type & | ||
296 | ~(VMI_PAGE_ZEROED | VMI_PAGE_CLONE); | ||
297 | } | ||
298 | boot_allocations_applied = 1; | ||
299 | } | ||
300 | |||
301 | static void record_page_type(u32 pfn, int type) | ||
302 | { | ||
303 | BUG_ON(num_boot_page_allocations >= MAX_BOOT_PTS); | ||
304 | boot_page_allocations[num_boot_page_allocations].pfn = pfn; | ||
305 | boot_page_allocations[num_boot_page_allocations].type = type; | ||
306 | num_boot_page_allocations++; | ||
307 | } | ||
308 | |||
309 | static void check_zeroed_page(u32 pfn, int type, struct page *page) | ||
310 | { | ||
311 | u32 *ptr; | ||
312 | int i; | ||
313 | int limit = PAGE_SIZE / sizeof(int); | ||
314 | |||
315 | if (page_address(page)) | ||
316 | ptr = (u32 *)page_address(page); | ||
317 | else | ||
318 | ptr = (u32 *)__va(pfn << PAGE_SHIFT); | ||
319 | /* | ||
320 | * When cloning the root in non-PAE mode, only the userspace | ||
321 | * pdes need to be zeroed. | ||
322 | */ | ||
323 | if (type & VMI_PAGE_CLONE) | ||
324 | limit = KERNEL_PGD_BOUNDARY; | ||
325 | for (i = 0; i < limit; i++) | ||
326 | BUG_ON(ptr[i]); | ||
327 | } | ||
328 | |||
329 | /* | ||
330 | * We stash the page type into struct page so we can verify the page | ||
331 | * types are used properly. | ||
332 | */ | ||
333 | static void vmi_set_page_type(u32 pfn, int type) | ||
334 | { | ||
335 | /* PAE can have multiple roots per page - don't track */ | ||
336 | if (PTRS_PER_PMD > 1 && (type & VMI_PAGE_PDP)) | ||
337 | return; | ||
338 | |||
339 | if (boot_allocations_applied) { | ||
340 | struct page *page = pfn_to_page(pfn); | ||
341 | if (type != VMI_PAGE_NORMAL) | ||
342 | BUG_ON(page->type); | ||
343 | else | ||
344 | BUG_ON(page->type == VMI_PAGE_NORMAL); | ||
345 | page->type = type & ~(VMI_PAGE_ZEROED | VMI_PAGE_CLONE); | ||
346 | if (type & VMI_PAGE_ZEROED) | ||
347 | check_zeroed_page(pfn, type, page); | ||
348 | } else { | ||
349 | record_page_type(pfn, type); | ||
350 | } | ||
351 | } | ||
352 | |||
353 | static void vmi_check_page_type(u32 pfn, int type) | ||
354 | { | ||
355 | /* PAE can have multiple roots per page - skip checks */ | ||
356 | if (PTRS_PER_PMD > 1 && (type & VMI_PAGE_PDP)) | ||
357 | return; | ||
358 | |||
359 | type &= ~(VMI_PAGE_ZEROED | VMI_PAGE_CLONE); | ||
360 | if (boot_allocations_applied) { | ||
361 | struct page *page = pfn_to_page(pfn); | ||
362 | BUG_ON((page->type ^ type) & VMI_PAGE_PAE); | ||
363 | BUG_ON(type == VMI_PAGE_NORMAL && page->type); | ||
364 | BUG_ON((type & page->type) == 0); | ||
365 | } | ||
366 | } | ||
367 | #else | ||
368 | #define vmi_set_page_type(p,t) do { } while (0) | ||
369 | #define vmi_check_page_type(p,t) do { } while (0) | ||
370 | #endif | ||
371 | |||
372 | #ifdef CONFIG_HIGHPTE | 269 | #ifdef CONFIG_HIGHPTE |
373 | static void *vmi_kmap_atomic_pte(struct page *page, enum km_type type) | 270 | static void *vmi_kmap_atomic_pte(struct page *page, enum km_type type) |
374 | { | 271 | { |
@@ -395,7 +292,6 @@ static void *vmi_kmap_atomic_pte(struct page *page, enum km_type type) | |||
395 | 292 | ||
396 | static void vmi_allocate_pte(struct mm_struct *mm, unsigned long pfn) | 293 | static void vmi_allocate_pte(struct mm_struct *mm, unsigned long pfn) |
397 | { | 294 | { |
398 | vmi_set_page_type(pfn, VMI_PAGE_L1); | ||
399 | vmi_ops.allocate_page(pfn, VMI_PAGE_L1, 0, 0, 0); | 295 | vmi_ops.allocate_page(pfn, VMI_PAGE_L1, 0, 0, 0); |
400 | } | 296 | } |
401 | 297 | ||
@@ -406,27 +302,22 @@ static void vmi_allocate_pmd(struct mm_struct *mm, unsigned long pfn) | |||
406 | * It is called only for swapper_pg_dir, which already has | 302 | * It is called only for swapper_pg_dir, which already has |
407 | * data on it. | 303 | * data on it. |
408 | */ | 304 | */ |
409 | vmi_set_page_type(pfn, VMI_PAGE_L2); | ||
410 | vmi_ops.allocate_page(pfn, VMI_PAGE_L2, 0, 0, 0); | 305 | vmi_ops.allocate_page(pfn, VMI_PAGE_L2, 0, 0, 0); |
411 | } | 306 | } |
412 | 307 | ||
413 | static void vmi_allocate_pmd_clone(unsigned long pfn, unsigned long clonepfn, unsigned long start, unsigned long count) | 308 | static void vmi_allocate_pmd_clone(unsigned long pfn, unsigned long clonepfn, unsigned long start, unsigned long count) |
414 | { | 309 | { |
415 | vmi_set_page_type(pfn, VMI_PAGE_L2 | VMI_PAGE_CLONE); | ||
416 | vmi_check_page_type(clonepfn, VMI_PAGE_L2); | ||
417 | vmi_ops.allocate_page(pfn, VMI_PAGE_L2 | VMI_PAGE_CLONE, clonepfn, start, count); | 310 | vmi_ops.allocate_page(pfn, VMI_PAGE_L2 | VMI_PAGE_CLONE, clonepfn, start, count); |
418 | } | 311 | } |
419 | 312 | ||
420 | static void vmi_release_pte(unsigned long pfn) | 313 | static void vmi_release_pte(unsigned long pfn) |
421 | { | 314 | { |
422 | vmi_ops.release_page(pfn, VMI_PAGE_L1); | 315 | vmi_ops.release_page(pfn, VMI_PAGE_L1); |
423 | vmi_set_page_type(pfn, VMI_PAGE_NORMAL); | ||
424 | } | 316 | } |
425 | 317 | ||
426 | static void vmi_release_pmd(unsigned long pfn) | 318 | static void vmi_release_pmd(unsigned long pfn) |
427 | { | 319 | { |
428 | vmi_ops.release_page(pfn, VMI_PAGE_L2); | 320 | vmi_ops.release_page(pfn, VMI_PAGE_L2); |
429 | vmi_set_page_type(pfn, VMI_PAGE_NORMAL); | ||
430 | } | 321 | } |
431 | 322 | ||
432 | /* | 323 | /* |
@@ -450,26 +341,22 @@ static void vmi_release_pmd(unsigned long pfn) | |||
450 | 341 | ||
451 | static void vmi_update_pte(struct mm_struct *mm, unsigned long addr, pte_t *ptep) | 342 | static void vmi_update_pte(struct mm_struct *mm, unsigned long addr, pte_t *ptep) |
452 | { | 343 | { |
453 | vmi_check_page_type(__pa(ptep) >> PAGE_SHIFT, VMI_PAGE_PTE); | ||
454 | vmi_ops.update_pte(ptep, vmi_flags_addr(mm, addr, VMI_PAGE_PT, 0)); | 344 | vmi_ops.update_pte(ptep, vmi_flags_addr(mm, addr, VMI_PAGE_PT, 0)); |
455 | } | 345 | } |
456 | 346 | ||
457 | static void vmi_update_pte_defer(struct mm_struct *mm, unsigned long addr, pte_t *ptep) | 347 | static void vmi_update_pte_defer(struct mm_struct *mm, unsigned long addr, pte_t *ptep) |
458 | { | 348 | { |
459 | vmi_check_page_type(__pa(ptep) >> PAGE_SHIFT, VMI_PAGE_PTE); | ||
460 | vmi_ops.update_pte(ptep, vmi_flags_addr_defer(mm, addr, VMI_PAGE_PT, 0)); | 349 | vmi_ops.update_pte(ptep, vmi_flags_addr_defer(mm, addr, VMI_PAGE_PT, 0)); |
461 | } | 350 | } |
462 | 351 | ||
463 | static void vmi_set_pte(pte_t *ptep, pte_t pte) | 352 | static void vmi_set_pte(pte_t *ptep, pte_t pte) |
464 | { | 353 | { |
465 | /* XXX because of set_pmd_pte, this can be called on PT or PD layers */ | 354 | /* XXX because of set_pmd_pte, this can be called on PT or PD layers */ |
466 | vmi_check_page_type(__pa(ptep) >> PAGE_SHIFT, VMI_PAGE_PTE | VMI_PAGE_PD); | ||
467 | vmi_ops.set_pte(pte, ptep, VMI_PAGE_PT); | 355 | vmi_ops.set_pte(pte, ptep, VMI_PAGE_PT); |
468 | } | 356 | } |
469 | 357 | ||
470 | static void vmi_set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte) | 358 | static void vmi_set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte) |
471 | { | 359 | { |
472 | vmi_check_page_type(__pa(ptep) >> PAGE_SHIFT, VMI_PAGE_PTE); | ||
473 | vmi_ops.set_pte(pte, ptep, vmi_flags_addr(mm, addr, VMI_PAGE_PT, 0)); | 360 | vmi_ops.set_pte(pte, ptep, vmi_flags_addr(mm, addr, VMI_PAGE_PT, 0)); |
474 | } | 361 | } |
475 | 362 | ||
@@ -477,10 +364,8 @@ static void vmi_set_pmd(pmd_t *pmdp, pmd_t pmdval) | |||
477 | { | 364 | { |
478 | #ifdef CONFIG_X86_PAE | 365 | #ifdef CONFIG_X86_PAE |
479 | const pte_t pte = { .pte = pmdval.pmd }; | 366 | const pte_t pte = { .pte = pmdval.pmd }; |
480 | vmi_check_page_type(__pa(pmdp) >> PAGE_SHIFT, VMI_PAGE_PMD); | ||
481 | #else | 367 | #else |
482 | const pte_t pte = { pmdval.pud.pgd.pgd }; | 368 | const pte_t pte = { pmdval.pud.pgd.pgd }; |
483 | vmi_check_page_type(__pa(pmdp) >> PAGE_SHIFT, VMI_PAGE_PGD); | ||
484 | #endif | 369 | #endif |
485 | vmi_ops.set_pte(pte, (pte_t *)pmdp, VMI_PAGE_PD); | 370 | vmi_ops.set_pte(pte, (pte_t *)pmdp, VMI_PAGE_PD); |
486 | } | 371 | } |
@@ -502,7 +387,6 @@ static void vmi_set_pte_atomic(pte_t *ptep, pte_t pteval) | |||
502 | 387 | ||
503 | static void vmi_set_pte_present(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte) | 388 | static void vmi_set_pte_present(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte) |
504 | { | 389 | { |
505 | vmi_check_page_type(__pa(ptep) >> PAGE_SHIFT, VMI_PAGE_PTE); | ||
506 | vmi_ops.set_pte(pte, ptep, vmi_flags_addr_defer(mm, addr, VMI_PAGE_PT, 1)); | 390 | vmi_ops.set_pte(pte, ptep, vmi_flags_addr_defer(mm, addr, VMI_PAGE_PT, 1)); |
507 | } | 391 | } |
508 | 392 | ||
@@ -510,21 +394,18 @@ static void vmi_set_pud(pud_t *pudp, pud_t pudval) | |||
510 | { | 394 | { |
511 | /* Um, eww */ | 395 | /* Um, eww */ |
512 | const pte_t pte = { .pte = pudval.pgd.pgd }; | 396 | const pte_t pte = { .pte = pudval.pgd.pgd }; |
513 | vmi_check_page_type(__pa(pudp) >> PAGE_SHIFT, VMI_PAGE_PGD); | ||
514 | vmi_ops.set_pte(pte, (pte_t *)pudp, VMI_PAGE_PDP); | 397 | vmi_ops.set_pte(pte, (pte_t *)pudp, VMI_PAGE_PDP); |
515 | } | 398 | } |
516 | 399 | ||
517 | static void vmi_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep) | 400 | static void vmi_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep) |
518 | { | 401 | { |
519 | const pte_t pte = { .pte = 0 }; | 402 | const pte_t pte = { .pte = 0 }; |
520 | vmi_check_page_type(__pa(ptep) >> PAGE_SHIFT, VMI_PAGE_PTE); | ||
521 | vmi_ops.set_pte(pte, ptep, vmi_flags_addr(mm, addr, VMI_PAGE_PT, 0)); | 403 | vmi_ops.set_pte(pte, ptep, vmi_flags_addr(mm, addr, VMI_PAGE_PT, 0)); |
522 | } | 404 | } |
523 | 405 | ||
524 | static void vmi_pmd_clear(pmd_t *pmd) | 406 | static void vmi_pmd_clear(pmd_t *pmd) |
525 | { | 407 | { |
526 | const pte_t pte = { .pte = 0 }; | 408 | const pte_t pte = { .pte = 0 }; |
527 | vmi_check_page_type(__pa(pmd) >> PAGE_SHIFT, VMI_PAGE_PMD); | ||
528 | vmi_ops.set_pte(pte, (pte_t *)pmd, VMI_PAGE_PD); | 409 | vmi_ops.set_pte(pte, (pte_t *)pmd, VMI_PAGE_PD); |
529 | } | 410 | } |
530 | #endif | 411 | #endif |
diff --git a/arch/x86/kernel/vmiclock_32.c b/arch/x86/kernel/vmiclock_32.c index 254ee07f8635..c4c1f9e09402 100644 --- a/arch/x86/kernel/vmiclock_32.c +++ b/arch/x86/kernel/vmiclock_32.c | |||
@@ -226,7 +226,7 @@ static void __devinit vmi_time_init_clockevent(void) | |||
226 | /* Upper bound is clockevent's use of ulong for cycle deltas. */ | 226 | /* Upper bound is clockevent's use of ulong for cycle deltas. */ |
227 | evt->max_delta_ns = clockevent_delta2ns(ULONG_MAX, evt); | 227 | evt->max_delta_ns = clockevent_delta2ns(ULONG_MAX, evt); |
228 | evt->min_delta_ns = clockevent_delta2ns(1, evt); | 228 | evt->min_delta_ns = clockevent_delta2ns(1, evt); |
229 | evt->cpumask = cpumask_of_cpu(cpu); | 229 | evt->cpumask = cpumask_of(cpu); |
230 | 230 | ||
231 | printk(KERN_WARNING "vmi: registering clock event %s. mult=%lu shift=%u\n", | 231 | printk(KERN_WARNING "vmi: registering clock event %s. mult=%lu shift=%u\n", |
232 | evt->name, evt->mult, evt->shift); | 232 | evt->name, evt->mult, evt->shift); |
diff --git a/arch/x86/kernel/vmlinux_32.lds.S b/arch/x86/kernel/vmlinux_32.lds.S index a9b8560adbc2..82c67559dde7 100644 --- a/arch/x86/kernel/vmlinux_32.lds.S +++ b/arch/x86/kernel/vmlinux_32.lds.S | |||
@@ -44,6 +44,7 @@ SECTIONS | |||
44 | SCHED_TEXT | 44 | SCHED_TEXT |
45 | LOCK_TEXT | 45 | LOCK_TEXT |
46 | KPROBES_TEXT | 46 | KPROBES_TEXT |
47 | IRQENTRY_TEXT | ||
47 | *(.fixup) | 48 | *(.fixup) |
48 | *(.gnu.warning) | 49 | *(.gnu.warning) |
49 | _etext = .; /* End of text section */ | 50 | _etext = .; /* End of text section */ |
diff --git a/arch/x86/kernel/vmlinux_64.lds.S b/arch/x86/kernel/vmlinux_64.lds.S index 46e05447405b..1a614c0e6bef 100644 --- a/arch/x86/kernel/vmlinux_64.lds.S +++ b/arch/x86/kernel/vmlinux_64.lds.S | |||
@@ -35,6 +35,7 @@ SECTIONS | |||
35 | SCHED_TEXT | 35 | SCHED_TEXT |
36 | LOCK_TEXT | 36 | LOCK_TEXT |
37 | KPROBES_TEXT | 37 | KPROBES_TEXT |
38 | IRQENTRY_TEXT | ||
38 | *(.fixup) | 39 | *(.fixup) |
39 | *(.gnu.warning) | 40 | *(.gnu.warning) |
40 | _etext = .; /* End of text section */ | 41 | _etext = .; /* End of text section */ |
diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c index 0b8b6690a86d..44153afc9067 100644 --- a/arch/x86/kernel/vsyscall_64.c +++ b/arch/x86/kernel/vsyscall_64.c | |||
@@ -17,6 +17,9 @@ | |||
17 | * want per guest time just set the kernel.vsyscall64 sysctl to 0. | 17 | * want per guest time just set the kernel.vsyscall64 sysctl to 0. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | /* Disable profiling for userspace code: */ | ||
21 | #define DISABLE_BRANCH_PROFILING | ||
22 | |||
20 | #include <linux/time.h> | 23 | #include <linux/time.h> |
21 | #include <linux/init.h> | 24 | #include <linux/init.h> |
22 | #include <linux/kernel.h> | 25 | #include <linux/kernel.h> |
@@ -128,7 +131,16 @@ static __always_inline void do_vgettimeofday(struct timeval * tv) | |||
128 | gettimeofday(tv,NULL); | 131 | gettimeofday(tv,NULL); |
129 | return; | 132 | return; |
130 | } | 133 | } |
134 | |||
135 | /* | ||
136 | * Surround the RDTSC by barriers, to make sure it's not | ||
137 | * speculated to outside the seqlock critical section and | ||
138 | * does not cause time warps: | ||
139 | */ | ||
140 | rdtsc_barrier(); | ||
131 | now = vread(); | 141 | now = vread(); |
142 | rdtsc_barrier(); | ||
143 | |||
132 | base = __vsyscall_gtod_data.clock.cycle_last; | 144 | base = __vsyscall_gtod_data.clock.cycle_last; |
133 | mask = __vsyscall_gtod_data.clock.mask; | 145 | mask = __vsyscall_gtod_data.clock.mask; |
134 | mult = __vsyscall_gtod_data.clock.mult; | 146 | mult = __vsyscall_gtod_data.clock.mult; |
diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c index 15c3e6999182..2b54fe002e94 100644 --- a/arch/x86/kernel/xsave.c +++ b/arch/x86/kernel/xsave.c | |||
@@ -159,7 +159,7 @@ int save_i387_xstate(void __user *buf) | |||
159 | * Restore the extended state if present. Otherwise, restore the FP/SSE | 159 | * Restore the extended state if present. Otherwise, restore the FP/SSE |
160 | * state. | 160 | * state. |
161 | */ | 161 | */ |
162 | int restore_user_xstate(void __user *buf) | 162 | static int restore_user_xstate(void __user *buf) |
163 | { | 163 | { |
164 | struct _fpx_sw_bytes fx_sw_user; | 164 | struct _fpx_sw_bytes fx_sw_user; |
165 | u64 mask; | 165 | u64 mask; |