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

Merge branch 'x86-core-v2-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip

This merges in:

x86/build, x86/microcode, x86/spinlocks, x86/memory-corruption-check,
x86/early-printk, x86/xsave, x86/quirks, x86/setup, x86/signal,
core/signal, x86/urgent, x86/xen

* 'x86-core-v2-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: (142 commits)
x86: make processor type select depend on CONFIG_EMBEDDED
x86: extend processor type select help text
x86, amd-iommu: propagate PCI device enabling error
warnings: fix arch/x86/kernel/io_apic_64.c
warnings: fix arch/x86/kernel/early_printk.c
x86, fpu: check __clear_user() return value
x86: memory corruption check - cleanup
x86: ioperm user_regset
xen: do not reserve 2 pages of padding between hypervisor and fixmap.
xen: use spin_lock_nest_lock when pinning a pagetable
x86: xsave: set FP, SSE bits in the xsave header in the user sigcontext
x86: xsave: fix error condition in save_i387_xstate()
x86: SB450: deprioritize DMI quirks
x86: SB450: skip IRQ0 override if it is not routed to INT2 of IOAPIC
x86: replace a magic number with a named constant in the VESA boot code
x86 setup: remove IMAGE_OFFSET
x86 setup: remove DEF_INITSEG and DEF_SETUPSEG
Revert "x86: fix ghost EDD devices in /sys again"
x86 setup: fix ghost entries under /sys/firmware/edd take 3
x86: signal: remove indent in restore_sigcontext()
...

+5026 -2202
+25 -1
Documentation/kernel-parameters.txt
··· 658 658 earlyprintk= [X86-32,X86-64,SH,BLACKFIN] 659 659 earlyprintk=vga 660 660 earlyprintk=serial[,ttySn[,baudrate]] 661 + earlyprintk=dbgp 661 662 662 663 Append ",keep" to not disable it when the real console 663 664 takes over. 664 665 665 - Only vga or serial at a time, not both. 666 + Only vga or serial or usb debug port at a time. 666 667 667 668 Currently only ttyS0 and ttyS1 are supported. 668 669 ··· 1231 1230 memmap=64K$0x18690000 1232 1231 or 1233 1232 memmap=0x10000$0x18690000 1233 + 1234 + memory_corruption_check=0/1 [X86] 1235 + Some BIOSes seem to corrupt the first 64k of 1236 + memory when doing things like suspend/resume. 1237 + Setting this option will scan the memory 1238 + looking for corruption. Enabling this will 1239 + both detect corruption and prevent the kernel 1240 + from using the memory being corrupted. 1241 + However, its intended as a diagnostic tool; if 1242 + repeatable BIOS-originated corruption always 1243 + affects the same memory, you can use memmap= 1244 + to prevent the kernel from using that memory. 1245 + 1246 + memory_corruption_check_size=size [X86] 1247 + By default it checks for corruption in the low 1248 + 64k, making this memory unavailable for normal 1249 + use. Use this parameter to scan for 1250 + corruption in more or less memory. 1251 + 1252 + memory_corruption_check_period=seconds [X86] 1253 + By default it checks for corruption every 60 1254 + seconds. Use this parameter to check at some 1255 + other rate. 0 disables periodic checking. 1234 1256 1235 1257 memtest= [KNL,X86] Enable memtest 1236 1258 Format: <integer>
+5
MAINTAINERS
··· 390 390 T: git://git.kernel.org/pub/scm/linux/kernel/git/joro/linux-2.6-iommu.git 391 391 S: Supported 392 392 393 + AMD MICROCODE UPDATE SUPPORT 394 + P: Peter Oruba 395 + M: peter.oruba@amd.com 396 + S: Supported 397 + 393 398 AMS (Apple Motion Sensor) DRIVER 394 399 P: Stelian Pop 395 400 M: stelian@popies.net
-5
arch/ia64/include/asm/siginfo.h
··· 113 113 #undef NSIGSEGV 114 114 #define NSIGSEGV 3 115 115 116 - /* 117 - * SIGTRAP si_codes 118 - */ 119 - #define TRAP_BRANCH (__SI_FAULT|3) /* process taken branch trap */ 120 - #define TRAP_HWBKPT (__SI_FAULT|4) /* hardware breakpoint or watchpoint */ 121 116 #undef NSIGTRAP 122 117 #define NSIGTRAP 4 123 118
-5
arch/powerpc/include/asm/siginfo.h
··· 15 15 16 16 #include <asm-generic/siginfo.h> 17 17 18 - /* 19 - * SIGTRAP si_codes 20 - */ 21 - #define TRAP_BRANCH (__SI_FAULT|3) /* process taken branch trap */ 22 - #define TRAP_HWBKPT (__SI_FAULT|4) /* hardware breakpoint or watchpoint */ 23 18 #undef NSIGTRAP 24 19 #define NSIGTRAP 4 25 20
+81 -9
arch/x86/Kconfig
··· 778 778 Say N otherwise. 779 779 780 780 config MICROCODE 781 - tristate "/dev/cpu/microcode - Intel IA32 CPU microcode support" 781 + tristate "/dev/cpu/microcode - microcode support" 782 782 select FW_LOADER 783 783 ---help--- 784 784 If you say Y here, you will be able to update the microcode on 785 - Intel processors in the IA32 family, e.g. Pentium Pro, Pentium II, 786 - Pentium III, Pentium 4, Xeon etc. You will obviously need the 787 - actual microcode binary data itself which is not shipped with the 788 - Linux kernel. 785 + certain Intel and AMD processors. The Intel support is for the 786 + IA32 family, e.g. Pentium Pro, Pentium II, Pentium III, 787 + Pentium 4, Xeon etc. The AMD support is for family 0x10 and 788 + 0x11 processors, e.g. Opteron, Phenom and Turion 64 Ultra. 789 + You will obviously need the actual microcode binary data itself 790 + which is not shipped with the Linux kernel. 789 791 790 - For latest news and information on obtaining all the required 791 - ingredients for this driver, check: 792 - <http://www.urbanmyth.org/microcode/>. 792 + This option selects the general module only, you need to select 793 + at least one vendor specific module as well. 793 794 794 795 To compile this driver as a module, choose M here: the 795 796 module will be called microcode. 796 797 797 - config MICROCODE_OLD_INTERFACE 798 + config MICROCODE_INTEL 799 + bool "Intel microcode patch loading support" 800 + depends on MICROCODE 801 + default MICROCODE 802 + select FW_LOADER 803 + --help--- 804 + This options enables microcode patch loading support for Intel 805 + processors. 806 + 807 + For latest news and information on obtaining all the required 808 + Intel ingredients for this driver, check: 809 + <http://www.urbanmyth.org/microcode/>. 810 + 811 + config MICROCODE_AMD 812 + bool "AMD microcode patch loading support" 813 + depends on MICROCODE 814 + select FW_LOADER 815 + --help--- 816 + If you select this option, microcode patch loading support for AMD 817 + processors will be enabled. 818 + 819 + config MICROCODE_OLD_INTERFACE 798 820 def_bool y 799 821 depends on MICROCODE 800 822 ··· 1082 1060 For systems with a lot of RAM, this can be wasteful of precious 1083 1061 low memory. Setting this option will put user-space page table 1084 1062 entries in high memory. 1063 + 1064 + config X86_CHECK_BIOS_CORRUPTION 1065 + bool "Check for low memory corruption" 1066 + help 1067 + Periodically check for memory corruption in low memory, which 1068 + is suspected to be caused by BIOS. Even when enabled in the 1069 + configuration, it is disabled at runtime. Enable it by 1070 + setting "memory_corruption_check=1" on the kernel command 1071 + line. By default it scans the low 64k of memory every 60 1072 + seconds; see the memory_corruption_check_size and 1073 + memory_corruption_check_period parameters in 1074 + Documentation/kernel-parameters.txt to adjust this. 1075 + 1076 + When enabled with the default parameters, this option has 1077 + almost no overhead, as it reserves a relatively small amount 1078 + of memory and scans it infrequently. It both detects corruption 1079 + and prevents it from affecting the running system. 1080 + 1081 + It is, however, intended as a diagnostic tool; if repeatable 1082 + BIOS-originated corruption always affects the same memory, 1083 + you can use memmap= to prevent the kernel from using that 1084 + memory. 1085 + 1086 + config X86_BOOTPARAM_MEMORY_CORRUPTION_CHECK 1087 + bool "Set the default setting of memory_corruption_check" 1088 + depends on X86_CHECK_BIOS_CORRUPTION 1089 + default y 1090 + help 1091 + Set whether the default state of memory_corruption_check is 1092 + on or off. 1093 + 1094 + config X86_RESERVE_LOW_64K 1095 + bool "Reserve low 64K of RAM on AMI/Phoenix BIOSen" 1096 + default y 1097 + help 1098 + Reserve the first 64K of physical RAM on BIOSes that are known 1099 + to potentially corrupt that memory range. A numbers of BIOSes are 1100 + known to utilize this area during suspend/resume, so it must not 1101 + be used by the kernel. 1102 + 1103 + Set this to N if you are absolutely sure that you trust the BIOS 1104 + to get all its memory reservations and usages right. 1105 + 1106 + If you have doubts about the BIOS (e.g. suspend/resume does not 1107 + work or there's kernel crashes after certain hardware hotplug 1108 + events) and it's not AMI or Phoenix, then you might want to enable 1109 + X86_CHECK_BIOS_CORRUPTION=y to allow the kernel to check typical 1110 + corruption patterns. 1111 + 1112 + Say Y if unsure. 1085 1113 1086 1114 config MATH_EMULATION 1087 1115 bool
+56 -8
arch/x86/Kconfig.cpu
··· 420 420 depends on !(MK6 || MWINCHIPC6 || MWINCHIP2 || MWINCHIP3D || MCYRIXIII || M586MMX || M586TSC || M586 || M486 || M386) 421 421 422 422 menuconfig PROCESSOR_SELECT 423 - default y 424 423 bool "Supported processor vendors" if EMBEDDED 425 424 help 426 425 This lets you choose what x86 vendor support code your kernel ··· 429 430 default y 430 431 bool "Support Intel processors" if PROCESSOR_SELECT 431 432 help 432 - This enables extended support for Intel processors 433 + This enables detection, tunings and quirks for Intel processors 434 + 435 + You need this enabled if you want your kernel to run on an 436 + Intel CPU. Disabling this option on other types of CPUs 437 + makes the kernel a tiny bit smaller. Disabling it on an Intel 438 + CPU might render the kernel unbootable. 439 + 440 + If unsure, say N. 433 441 434 442 config CPU_SUP_CYRIX_32 435 443 default y 436 444 bool "Support Cyrix processors" if PROCESSOR_SELECT 437 445 depends on !64BIT 438 446 help 439 - This enables extended support for Cyrix processors 447 + This enables detection, tunings and quirks for Cyrix processors 448 + 449 + You need this enabled if you want your kernel to run on a 450 + Cyrix CPU. Disabling this option on other types of CPUs 451 + makes the kernel a tiny bit smaller. Disabling it on a Cyrix 452 + CPU might render the kernel unbootable. 453 + 454 + If unsure, say N. 440 455 441 456 config CPU_SUP_AMD 442 457 default y 443 458 bool "Support AMD processors" if PROCESSOR_SELECT 444 459 help 445 - This enables extended support for AMD processors 460 + This enables detection, tunings and quirks for AMD processors 461 + 462 + You need this enabled if you want your kernel to run on an 463 + AMD CPU. Disabling this option on other types of CPUs 464 + makes the kernel a tiny bit smaller. Disabling it on an AMD 465 + CPU might render the kernel unbootable. 466 + 467 + If unsure, say N. 446 468 447 469 config CPU_SUP_CENTAUR_32 448 470 default y 449 471 bool "Support Centaur processors" if PROCESSOR_SELECT 450 472 depends on !64BIT 451 473 help 452 - This enables extended support for Centaur processors 474 + This enables detection, tunings and quirks for Centaur processors 475 + 476 + You need this enabled if you want your kernel to run on a 477 + Centaur CPU. Disabling this option on other types of CPUs 478 + makes the kernel a tiny bit smaller. Disabling it on a Centaur 479 + CPU might render the kernel unbootable. 480 + 481 + If unsure, say N. 453 482 454 483 config CPU_SUP_CENTAUR_64 455 484 default y 456 485 bool "Support Centaur processors" if PROCESSOR_SELECT 457 486 depends on 64BIT 458 487 help 459 - This enables extended support for Centaur processors 488 + This enables detection, tunings and quirks for Centaur processors 489 + 490 + You need this enabled if you want your kernel to run on a 491 + Centaur CPU. Disabling this option on other types of CPUs 492 + makes the kernel a tiny bit smaller. Disabling it on a Centaur 493 + CPU might render the kernel unbootable. 494 + 495 + If unsure, say N. 460 496 461 497 config CPU_SUP_TRANSMETA_32 462 498 default y 463 499 bool "Support Transmeta processors" if PROCESSOR_SELECT 464 500 depends on !64BIT 465 501 help 466 - This enables extended support for Transmeta processors 502 + This enables detection, tunings and quirks for Transmeta processors 503 + 504 + You need this enabled if you want your kernel to run on a 505 + Transmeta CPU. Disabling this option on other types of CPUs 506 + makes the kernel a tiny bit smaller. Disabling it on a Transmeta 507 + CPU might render the kernel unbootable. 508 + 509 + If unsure, say N. 467 510 468 511 config CPU_SUP_UMC_32 469 512 default y 470 513 bool "Support UMC processors" if PROCESSOR_SELECT 471 514 depends on !64BIT 472 515 help 473 - This enables extended support for UMC processors 516 + This enables detection, tunings and quirks for UMC processors 517 + 518 + You need this enabled if you want your kernel to run on a 519 + UMC CPU. Disabling this option on other types of CPUs 520 + makes the kernel a tiny bit smaller. Disabling it on a UMC 521 + CPU might render the kernel unbootable. 522 + 523 + If unsure, say N. 474 524 475 525 config X86_DS 476 526 bool "Debug Store support"
+13
arch/x86/Kconfig.debug
··· 43 43 with klogd/syslogd or the X server. You should normally N here, 44 44 unless you want to debug such a crash. 45 45 46 + config EARLY_PRINTK_DBGP 47 + bool "Early printk via EHCI debug port" 48 + default n 49 + depends on EARLY_PRINTK && PCI 50 + help 51 + Write kernel log output directly into the EHCI debug port. 52 + 53 + This is useful for kernel debugging when your machine crashes very 54 + early before the console code is initialized. For normal operation 55 + it is not recommended because it looks ugly and doesn't cooperate 56 + with klogd/syslogd or the X server. You should normally N here, 57 + unless you want to debug such a crash. You need usb debug device. 58 + 46 59 config DEBUG_STACKOVERFLOW 47 60 bool "Check for stack overflows" 48 61 depends on DEBUG_KERNEL
+5
arch/x86/Makefile_32.cpu
··· 45 45 # cpu entries 46 46 cflags-$(CONFIG_X86_GENERIC) += $(call tune,generic,$(call tune,i686)) 47 47 48 + # Bug fix for binutils: this option is required in order to keep 49 + # binutils from generating NOPL instructions against our will. 50 + ifneq ($(CONFIG_X86_P6_NOP),y) 51 + cflags-y += $(call cc-option,-Wa$(comma)-mtune=generic32,) 52 + endif
+2 -3
arch/x86/boot/Makefile
··· 72 72 KBUILD_CFLAGS += $(call cc-option,-m32) 73 73 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ 74 74 75 - $(obj)/zImage: IMAGE_OFFSET := 0x1000 76 75 $(obj)/zImage: asflags-y := $(SVGA_MODE) $(RAMDISK) 77 - $(obj)/bzImage: IMAGE_OFFSET := 0x100000 78 76 $(obj)/bzImage: ccflags-y := -D__BIG_KERNEL__ 79 77 $(obj)/bzImage: asflags-y := $(SVGA_MODE) $(RAMDISK) -D__BIG_KERNEL__ 80 78 $(obj)/bzImage: BUILDFLAGS := -b ··· 115 117 $(call if_changed,objcopy) 116 118 117 119 $(obj)/compressed/vmlinux: FORCE 118 - $(Q)$(MAKE) $(build)=$(obj)/compressed IMAGE_OFFSET=$(IMAGE_OFFSET) $@ 120 + $(Q)$(MAKE) $(build)=$(obj)/compressed $@ 119 121 120 122 # Set this if you want to pass append arguments to the zdisk/fdimage/isoimage kernel 121 123 FDARGS = ··· 179 181 mkisofs -J -r -o $(obj)/image.iso -b isolinux.bin -c boot.cat \ 180 182 -no-emul-boot -boot-load-size 4 -boot-info-table \ 181 183 $(obj)/isoimage 184 + isohybrid $(obj)/image.iso 2>/dev/null || true 182 185 rm -rf $(obj)/isoimage 183 186 184 187 zlilo: $(BOOTIMAGE)
+4 -4
arch/x86/boot/compressed/Makefile
··· 27 27 $(call if_changed,objcopy) 28 28 29 29 30 - ifeq ($(CONFIG_X86_32),y) 31 - targets += vmlinux.bin.all vmlinux.relocs 32 - hostprogs-y := relocs 30 + targets += vmlinux.bin.all vmlinux.relocs relocs 31 + hostprogs-$(CONFIG_X86_32) += relocs 33 32 34 33 quiet_cmd_relocs = RELOCS $@ 35 34 cmd_relocs = $(obj)/relocs $< > $@;$(obj)/relocs --abs-relocs $< ··· 41 42 cmd_relocbin = cat $(filter-out FORCE,$^) > $@ 42 43 $(obj)/vmlinux.bin.all: $(vmlinux.bin.all-y) FORCE 43 44 $(call if_changed,relocbin) 45 + 46 + ifeq ($(CONFIG_X86_32),y) 44 47 45 48 ifdef CONFIG_RELOCATABLE 46 49 $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin.all FORCE ··· 59 58 60 59 LDFLAGS_piggy.o := -r --format binary --oformat elf64-x86-64 -T 61 60 endif 62 - 63 61 64 62 $(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.gz FORCE 65 63 $(call if_changed,ld)
+6 -1
arch/x86/boot/edd.c
··· 41 41 char *mbrbuf_ptr, *mbrbuf_end; 42 42 u32 buf_base, mbr_base; 43 43 extern char _end[]; 44 + u16 mbr_magic; 44 45 45 46 sector_size = ei->params.bytes_per_sector; 46 47 if (!sector_size) ··· 59 58 if (mbrbuf_end > (char *)(size_t)boot_params.hdr.heap_end_ptr) 60 59 return -1; 61 60 61 + memset(mbrbuf_ptr, 0, sector_size); 62 62 if (read_mbr(devno, mbrbuf_ptr)) 63 63 return -1; 64 64 65 65 *mbrsig = *(u32 *)&mbrbuf_ptr[EDD_MBR_SIG_OFFSET]; 66 - return 0; 66 + mbr_magic = *(u16 *)&mbrbuf_ptr[510]; 67 + 68 + /* check for valid MBR magic */ 69 + return mbr_magic == 0xAA55 ? 0 : -1; 67 70 } 68 71 69 72 static int get_edd_info(u8 devno, struct edd_info *ei)
+1 -1
arch/x86/boot/video-vesa.c
··· 224 224 static void vesa_store_mode_params_graphics(void) 225 225 { 226 226 /* Tell the kernel we're in VESA graphics mode */ 227 - boot_params.screen_info.orig_video_isVGA = 0x23; 227 + boot_params.screen_info.orig_video_isVGA = VIDEO_TYPE_VLFB; 228 228 229 229 /* Mode parameters */ 230 230 boot_params.screen_info.vesa_attributes = vminfo.mode_attr;
-1
arch/x86/configs/i386_defconfig
··· 1535 1535 CONFIG_VGA_CONSOLE=y 1536 1536 CONFIG_VGACON_SOFT_SCROLLBACK=y 1537 1537 CONFIG_VGACON_SOFT_SCROLLBACK_SIZE=64 1538 - CONFIG_VIDEO_SELECT=y 1539 1538 CONFIG_DUMMY_CONSOLE=y 1540 1539 # CONFIG_FRAMEBUFFER_CONSOLE is not set 1541 1540 CONFIG_LOGO=y
-1
arch/x86/configs/x86_64_defconfig
··· 1505 1505 CONFIG_VGA_CONSOLE=y 1506 1506 CONFIG_VGACON_SOFT_SCROLLBACK=y 1507 1507 CONFIG_VGACON_SOFT_SCROLLBACK_SIZE=64 1508 - CONFIG_VIDEO_SELECT=y 1509 1508 CONFIG_DUMMY_CONSOLE=y 1510 1509 # CONFIG_FRAMEBUFFER_CONSOLE is not set 1511 1510 CONFIG_LOGO=y
+27 -41
arch/x86/ia32/ia32_signal.c
··· 351 351 savesegment(es, tmp); 352 352 err |= __put_user(tmp, (unsigned int __user *)&sc->es); 353 353 354 - err |= __put_user((u32)regs->di, &sc->di); 355 - err |= __put_user((u32)regs->si, &sc->si); 356 - err |= __put_user((u32)regs->bp, &sc->bp); 357 - err |= __put_user((u32)regs->sp, &sc->sp); 358 - err |= __put_user((u32)regs->bx, &sc->bx); 359 - err |= __put_user((u32)regs->dx, &sc->dx); 360 - err |= __put_user((u32)regs->cx, &sc->cx); 361 - err |= __put_user((u32)regs->ax, &sc->ax); 362 - err |= __put_user((u32)regs->cs, &sc->cs); 363 - err |= __put_user((u32)regs->ss, &sc->ss); 354 + err |= __put_user(regs->di, &sc->di); 355 + err |= __put_user(regs->si, &sc->si); 356 + err |= __put_user(regs->bp, &sc->bp); 357 + err |= __put_user(regs->sp, &sc->sp); 358 + err |= __put_user(regs->bx, &sc->bx); 359 + err |= __put_user(regs->dx, &sc->dx); 360 + err |= __put_user(regs->cx, &sc->cx); 361 + err |= __put_user(regs->ax, &sc->ax); 362 + err |= __put_user(regs->cs, &sc->cs); 363 + err |= __put_user(regs->ss, &sc->ss); 364 364 err |= __put_user(current->thread.trap_no, &sc->trapno); 365 365 err |= __put_user(current->thread.error_code, &sc->err); 366 - err |= __put_user((u32)regs->ip, &sc->ip); 367 - err |= __put_user((u32)regs->flags, &sc->flags); 368 - err |= __put_user((u32)regs->sp, &sc->sp_at_signal); 366 + err |= __put_user(regs->ip, &sc->ip); 367 + err |= __put_user(regs->flags, &sc->flags); 368 + err |= __put_user(regs->sp, &sc->sp_at_signal); 369 369 370 370 tmp = save_i387_xstate_ia32(fpstate); 371 371 if (tmp < 0) 372 372 err = -EFAULT; 373 - else { 374 - clear_used_math(); 375 - stts(); 373 + else 376 374 err |= __put_user(ptr_to_compat(tmp ? fpstate : NULL), 377 375 &sc->fpstate); 378 - } 379 376 380 377 /* non-iBCS2 extensions.. */ 381 378 err |= __put_user(mask, &sc->oldmask); ··· 441 444 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate); 442 445 443 446 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) 444 - goto give_sigsegv; 447 + return -EFAULT; 445 448 446 - err |= __put_user(sig, &frame->sig); 447 - if (err) 448 - goto give_sigsegv; 449 + if (__put_user(sig, &frame->sig)) 450 + return -EFAULT; 449 451 450 - err |= ia32_setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0]); 451 - if (err) 452 - goto give_sigsegv; 452 + if (ia32_setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0])) 453 + return -EFAULT; 453 454 454 455 if (_COMPAT_NSIG_WORDS > 1) { 455 - err |= __copy_to_user(frame->extramask, &set->sig[1], 456 - sizeof(frame->extramask)); 457 - if (err) 458 - goto give_sigsegv; 456 + if (__copy_to_user(frame->extramask, &set->sig[1], 457 + sizeof(frame->extramask))) 458 + return -EFAULT; 459 459 } 460 460 461 461 if (ka->sa.sa_flags & SA_RESTORER) { ··· 473 479 */ 474 480 err |= __copy_to_user(frame->retcode, &code, 8); 475 481 if (err) 476 - goto give_sigsegv; 482 + return -EFAULT; 477 483 478 484 /* Set up registers for signal handler */ 479 485 regs->sp = (unsigned long) frame; ··· 496 502 #endif 497 503 498 504 return 0; 499 - 500 - give_sigsegv: 501 - force_sigsegv(sig, current); 502 - return -EFAULT; 503 505 } 504 506 505 507 int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, ··· 523 533 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate); 524 534 525 535 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) 526 - goto give_sigsegv; 536 + return -EFAULT; 527 537 528 538 err |= __put_user(sig, &frame->sig); 529 539 err |= __put_user(ptr_to_compat(&frame->info), &frame->pinfo); 530 540 err |= __put_user(ptr_to_compat(&frame->uc), &frame->puc); 531 541 err |= copy_siginfo_to_user32(&frame->info, info); 532 542 if (err) 533 - goto give_sigsegv; 543 + return -EFAULT; 534 544 535 545 /* Create the ucontext. */ 536 546 if (cpu_has_xsave) ··· 546 556 regs, set->sig[0]); 547 557 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); 548 558 if (err) 549 - goto give_sigsegv; 559 + return -EFAULT; 550 560 551 561 if (ka->sa.sa_flags & SA_RESTORER) 552 562 restorer = ka->sa.sa_restorer; ··· 561 571 */ 562 572 err |= __copy_to_user(frame->retcode, &code, 8); 563 573 if (err) 564 - goto give_sigsegv; 574 + return -EFAULT; 565 575 566 576 /* Set up registers for signal handler */ 567 577 regs->sp = (unsigned long) frame; ··· 589 599 #endif 590 600 591 601 return 0; 592 - 593 - give_sigsegv: 594 - force_sigsegv(sig, current); 595 - return -EFAULT; 596 602 }
+7 -3
arch/x86/kernel/Makefile
··· 10 10 # Do not profile debug and lowlevel utilities 11 11 CFLAGS_REMOVE_tsc.o = -pg 12 12 CFLAGS_REMOVE_rtc.o = -pg 13 - CFLAGS_REMOVE_paravirt.o = -pg 13 + CFLAGS_REMOVE_paravirt-spinlocks.o = -pg 14 14 endif 15 15 16 16 # ··· 51 51 obj-$(CONFIG_MCA) += mca_32.o 52 52 obj-$(CONFIG_X86_MSR) += msr.o 53 53 obj-$(CONFIG_X86_CPUID) += cpuid.o 54 - obj-$(CONFIG_MICROCODE) += microcode.o 55 54 obj-$(CONFIG_PCI) += early-quirks.o 56 55 apm-y := apm_32.o 57 56 obj-$(CONFIG_APM) += apm.o ··· 89 90 obj-$(CONFIG_VMI) += vmi_32.o vmiclock_32.o 90 91 obj-$(CONFIG_KVM_GUEST) += kvm.o 91 92 obj-$(CONFIG_KVM_CLOCK) += kvmclock.o 92 - obj-$(CONFIG_PARAVIRT) += paravirt.o paravirt_patch_$(BITS).o 93 + obj-$(CONFIG_PARAVIRT) += paravirt.o paravirt_patch_$(BITS).o paravirt-spinlocks.o 93 94 obj-$(CONFIG_PARAVIRT_CLOCK) += pvclock.o 94 95 95 96 obj-$(CONFIG_PCSPKR_PLATFORM) += pcspeaker.o ··· 98 99 scx200-y += scx200_32.o 99 100 100 101 obj-$(CONFIG_OLPC) += olpc.o 102 + 103 + microcode-y := microcode_core.o 104 + microcode-$(CONFIG_MICROCODE_INTEL) += microcode_intel.o 105 + microcode-$(CONFIG_MICROCODE_AMD) += microcode_amd.o 106 + obj-$(CONFIG_MICROCODE) += microcode.o 101 107 102 108 ### 103 109 # 64 bit specific files
+10 -2
arch/x86/kernel/acpi/boot.c
··· 1418 1418 */ 1419 1419 static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d) 1420 1420 { 1421 - pr_notice("%s detected: Ignoring BIOS IRQ0 pin2 override\n", d->ident); 1422 - acpi_skip_timer_override = 1; 1421 + /* 1422 + * The ati_ixp4x0_rev() early PCI quirk should have set 1423 + * the acpi_skip_timer_override flag already: 1424 + */ 1425 + if (!acpi_skip_timer_override) { 1426 + WARN(1, KERN_ERR "ati_ixp4x0 quirk not complete.\n"); 1427 + pr_notice("%s detected: Ignoring BIOS IRQ0 pin2 override\n", 1428 + d->ident); 1429 + acpi_skip_timer_override = 1; 1430 + } 1423 1431 return 0; 1424 1432 } 1425 1433
+1 -3
arch/x86/kernel/amd_iommu_init.c
··· 723 723 init_iommu_from_acpi(iommu, h); 724 724 init_iommu_devices(iommu); 725 725 726 - pci_enable_device(iommu->dev); 727 - 728 - return 0; 726 + return pci_enable_device(iommu->dev); 729 727 } 730 728 731 729 /*
-11
arch/x86/kernel/cpu/common.c
··· 1121 1121 xsave_init(); 1122 1122 } 1123 1123 1124 - #ifdef CONFIG_HOTPLUG_CPU 1125 - void __cpuinit cpu_uninit(void) 1126 - { 1127 - int cpu = raw_smp_processor_id(); 1128 - cpu_clear(cpu, cpu_initialized); 1129 - 1130 - /* lazy TLB state */ 1131 - per_cpu(cpu_tlbstate, cpu).state = 0; 1132 - per_cpu(cpu_tlbstate, cpu).active_mm = &init_mm; 1133 - } 1134 - #endif 1135 1124 1136 1125 #endif
+1 -1
arch/x86/kernel/doublefault_32.c
··· 66 66 .ds = __USER_DS, 67 67 .fs = __KERNEL_PERCPU, 68 68 69 - .__cr3 = __pa(swapper_pg_dir) 69 + .__cr3 = __phys_addr_const((unsigned long)swapper_pg_dir) 70 70 } 71 71 };
+48
arch/x86/kernel/early-quirks.c
··· 95 95 96 96 } 97 97 98 + static u32 ati_ixp4x0_rev(int num, int slot, int func) 99 + { 100 + u32 d; 101 + u8 b; 102 + 103 + b = read_pci_config_byte(num, slot, func, 0xac); 104 + b &= ~(1<<5); 105 + write_pci_config_byte(num, slot, func, 0xac, b); 106 + 107 + d = read_pci_config(num, slot, func, 0x70); 108 + d |= 1<<8; 109 + write_pci_config(num, slot, func, 0x70, d); 110 + 111 + d = read_pci_config(num, slot, func, 0x8); 112 + d &= 0xff; 113 + return d; 114 + } 115 + 116 + static void __init ati_bugs(int num, int slot, int func) 117 + { 118 + #if defined(CONFIG_ACPI) && defined (CONFIG_X86_IO_APIC) 119 + u32 d; 120 + u8 b; 121 + 122 + if (acpi_use_timer_override) 123 + return; 124 + 125 + d = ati_ixp4x0_rev(num, slot, func); 126 + if (d < 0x82) 127 + acpi_skip_timer_override = 1; 128 + else { 129 + /* check for IRQ0 interrupt swap */ 130 + outb(0x72, 0xcd6); b = inb(0xcd7); 131 + if (!(b & 0x2)) 132 + acpi_skip_timer_override = 1; 133 + } 134 + 135 + if (acpi_skip_timer_override) { 136 + printk(KERN_INFO "SB4X0 revision 0x%x\n", d); 137 + printk(KERN_INFO "Ignoring ACPI timer override.\n"); 138 + printk(KERN_INFO "If you got timer trouble " 139 + "try acpi_use_timer_override\n"); 140 + } 141 + #endif 142 + } 143 + 98 144 #ifdef CONFIG_DMAR 99 145 static void __init intel_g33_dmar(int num, int slot, int func) 100 146 { ··· 174 128 PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, via_bugs }, 175 129 { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB, 176 130 PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, fix_hypertransport_config }, 131 + { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS, 132 + PCI_CLASS_SERIAL_SMBUS, PCI_ANY_ID, 0, ati_bugs }, 177 133 #ifdef CONFIG_DMAR 178 134 { PCI_VENDOR_ID_INTEL, 0x29c0, 179 135 PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, intel_g33_dmar },
+743 -5
arch/x86/kernel/early_printk.c
··· 3 3 #include <linux/init.h> 4 4 #include <linux/string.h> 5 5 #include <linux/screen_info.h> 6 + #include <linux/usb/ch9.h> 7 + #include <linux/pci_regs.h> 8 + #include <linux/pci_ids.h> 9 + #include <linux/errno.h> 6 10 #include <asm/io.h> 7 11 #include <asm/processor.h> 8 12 #include <asm/fcntl.h> 9 13 #include <asm/setup.h> 10 14 #include <xen/hvc-console.h> 15 + #include <asm/pci-direct.h> 16 + #include <asm/pgtable.h> 17 + #include <asm/fixmap.h> 18 + #include <linux/usb/ehci_def.h> 11 19 12 20 /* Simple VGA output */ 13 21 #define VGABASE (__ISA_IO_base + 0xb8000) ··· 86 78 static int early_serial_putc(unsigned char ch) 87 79 { 88 80 unsigned timeout = 0xffff; 81 + 89 82 while ((inb(early_serial_base + LSR) & XMTRDY) == 0 && --timeout) 90 83 cpu_relax(); 91 84 outb(ch, early_serial_base + TXR); ··· 120 111 if (!strncmp(s, "0x", 2)) { 121 112 early_serial_base = simple_strtoul(s, &e, 16); 122 113 } else { 123 - static int bases[] = { 0x3f8, 0x2f8 }; 114 + static const int __initconst bases[] = { 0x3f8, 0x2f8 }; 124 115 125 116 if (!strncmp(s, "ttyS", 4)) 126 117 s += 4; ··· 160 151 .index = -1, 161 152 }; 162 153 154 + #ifdef CONFIG_EARLY_PRINTK_DBGP 155 + 156 + static struct ehci_caps __iomem *ehci_caps; 157 + static struct ehci_regs __iomem *ehci_regs; 158 + static struct ehci_dbg_port __iomem *ehci_debug; 159 + static unsigned int dbgp_endpoint_out; 160 + 161 + struct ehci_dev { 162 + u32 bus; 163 + u32 slot; 164 + u32 func; 165 + }; 166 + 167 + static struct ehci_dev ehci_dev; 168 + 169 + #define USB_DEBUG_DEVNUM 127 170 + 171 + #define DBGP_DATA_TOGGLE 0x8800 172 + 173 + static inline u32 dbgp_pid_update(u32 x, u32 tok) 174 + { 175 + return ((x ^ DBGP_DATA_TOGGLE) & 0xffff00) | (tok & 0xff); 176 + } 177 + 178 + static inline u32 dbgp_len_update(u32 x, u32 len) 179 + { 180 + return (x & ~0x0f) | (len & 0x0f); 181 + } 182 + 183 + /* 184 + * USB Packet IDs (PIDs) 185 + */ 186 + 187 + /* token */ 188 + #define USB_PID_OUT 0xe1 189 + #define USB_PID_IN 0x69 190 + #define USB_PID_SOF 0xa5 191 + #define USB_PID_SETUP 0x2d 192 + /* handshake */ 193 + #define USB_PID_ACK 0xd2 194 + #define USB_PID_NAK 0x5a 195 + #define USB_PID_STALL 0x1e 196 + #define USB_PID_NYET 0x96 197 + /* data */ 198 + #define USB_PID_DATA0 0xc3 199 + #define USB_PID_DATA1 0x4b 200 + #define USB_PID_DATA2 0x87 201 + #define USB_PID_MDATA 0x0f 202 + /* Special */ 203 + #define USB_PID_PREAMBLE 0x3c 204 + #define USB_PID_ERR 0x3c 205 + #define USB_PID_SPLIT 0x78 206 + #define USB_PID_PING 0xb4 207 + #define USB_PID_UNDEF_0 0xf0 208 + 209 + #define USB_PID_DATA_TOGGLE 0x88 210 + #define DBGP_CLAIM (DBGP_OWNER | DBGP_ENABLED | DBGP_INUSE) 211 + 212 + #define PCI_CAP_ID_EHCI_DEBUG 0xa 213 + 214 + #define HUB_ROOT_RESET_TIME 50 /* times are in msec */ 215 + #define HUB_SHORT_RESET_TIME 10 216 + #define HUB_LONG_RESET_TIME 200 217 + #define HUB_RESET_TIMEOUT 500 218 + 219 + #define DBGP_MAX_PACKET 8 220 + 221 + static int dbgp_wait_until_complete(void) 222 + { 223 + u32 ctrl; 224 + int loop = 0x100000; 225 + 226 + do { 227 + ctrl = readl(&ehci_debug->control); 228 + /* Stop when the transaction is finished */ 229 + if (ctrl & DBGP_DONE) 230 + break; 231 + } while (--loop > 0); 232 + 233 + if (!loop) 234 + return -1; 235 + 236 + /* 237 + * Now that we have observed the completed transaction, 238 + * clear the done bit. 239 + */ 240 + writel(ctrl | DBGP_DONE, &ehci_debug->control); 241 + return (ctrl & DBGP_ERROR) ? -DBGP_ERRCODE(ctrl) : DBGP_LEN(ctrl); 242 + } 243 + 244 + static void dbgp_mdelay(int ms) 245 + { 246 + int i; 247 + 248 + while (ms--) { 249 + for (i = 0; i < 1000; i++) 250 + outb(0x1, 0x80); 251 + } 252 + } 253 + 254 + static void dbgp_breath(void) 255 + { 256 + /* Sleep to give the debug port a chance to breathe */ 257 + } 258 + 259 + static int dbgp_wait_until_done(unsigned ctrl) 260 + { 261 + u32 pids, lpid; 262 + int ret; 263 + int loop = 3; 264 + 265 + retry: 266 + writel(ctrl | DBGP_GO, &ehci_debug->control); 267 + ret = dbgp_wait_until_complete(); 268 + pids = readl(&ehci_debug->pids); 269 + lpid = DBGP_PID_GET(pids); 270 + 271 + if (ret < 0) 272 + return ret; 273 + 274 + /* 275 + * If the port is getting full or it has dropped data 276 + * start pacing ourselves, not necessary but it's friendly. 277 + */ 278 + if ((lpid == USB_PID_NAK) || (lpid == USB_PID_NYET)) 279 + dbgp_breath(); 280 + 281 + /* If I get a NACK reissue the transmission */ 282 + if (lpid == USB_PID_NAK) { 283 + if (--loop > 0) 284 + goto retry; 285 + } 286 + 287 + return ret; 288 + } 289 + 290 + static void dbgp_set_data(const void *buf, int size) 291 + { 292 + const unsigned char *bytes = buf; 293 + u32 lo, hi; 294 + int i; 295 + 296 + lo = hi = 0; 297 + for (i = 0; i < 4 && i < size; i++) 298 + lo |= bytes[i] << (8*i); 299 + for (; i < 8 && i < size; i++) 300 + hi |= bytes[i] << (8*(i - 4)); 301 + writel(lo, &ehci_debug->data03); 302 + writel(hi, &ehci_debug->data47); 303 + } 304 + 305 + static void dbgp_get_data(void *buf, int size) 306 + { 307 + unsigned char *bytes = buf; 308 + u32 lo, hi; 309 + int i; 310 + 311 + lo = readl(&ehci_debug->data03); 312 + hi = readl(&ehci_debug->data47); 313 + for (i = 0; i < 4 && i < size; i++) 314 + bytes[i] = (lo >> (8*i)) & 0xff; 315 + for (; i < 8 && i < size; i++) 316 + bytes[i] = (hi >> (8*(i - 4))) & 0xff; 317 + } 318 + 319 + static int dbgp_bulk_write(unsigned devnum, unsigned endpoint, 320 + const char *bytes, int size) 321 + { 322 + u32 pids, addr, ctrl; 323 + int ret; 324 + 325 + if (size > DBGP_MAX_PACKET) 326 + return -1; 327 + 328 + addr = DBGP_EPADDR(devnum, endpoint); 329 + 330 + pids = readl(&ehci_debug->pids); 331 + pids = dbgp_pid_update(pids, USB_PID_OUT); 332 + 333 + ctrl = readl(&ehci_debug->control); 334 + ctrl = dbgp_len_update(ctrl, size); 335 + ctrl |= DBGP_OUT; 336 + ctrl |= DBGP_GO; 337 + 338 + dbgp_set_data(bytes, size); 339 + writel(addr, &ehci_debug->address); 340 + writel(pids, &ehci_debug->pids); 341 + 342 + ret = dbgp_wait_until_done(ctrl); 343 + if (ret < 0) 344 + return ret; 345 + 346 + return ret; 347 + } 348 + 349 + static int dbgp_bulk_read(unsigned devnum, unsigned endpoint, void *data, 350 + int size) 351 + { 352 + u32 pids, addr, ctrl; 353 + int ret; 354 + 355 + if (size > DBGP_MAX_PACKET) 356 + return -1; 357 + 358 + addr = DBGP_EPADDR(devnum, endpoint); 359 + 360 + pids = readl(&ehci_debug->pids); 361 + pids = dbgp_pid_update(pids, USB_PID_IN); 362 + 363 + ctrl = readl(&ehci_debug->control); 364 + ctrl = dbgp_len_update(ctrl, size); 365 + ctrl &= ~DBGP_OUT; 366 + ctrl |= DBGP_GO; 367 + 368 + writel(addr, &ehci_debug->address); 369 + writel(pids, &ehci_debug->pids); 370 + ret = dbgp_wait_until_done(ctrl); 371 + if (ret < 0) 372 + return ret; 373 + 374 + if (size > ret) 375 + size = ret; 376 + dbgp_get_data(data, size); 377 + return ret; 378 + } 379 + 380 + static int dbgp_control_msg(unsigned devnum, int requesttype, int request, 381 + int value, int index, void *data, int size) 382 + { 383 + u32 pids, addr, ctrl; 384 + struct usb_ctrlrequest req; 385 + int read; 386 + int ret; 387 + 388 + read = (requesttype & USB_DIR_IN) != 0; 389 + if (size > (read ? DBGP_MAX_PACKET:0)) 390 + return -1; 391 + 392 + /* Compute the control message */ 393 + req.bRequestType = requesttype; 394 + req.bRequest = request; 395 + req.wValue = cpu_to_le16(value); 396 + req.wIndex = cpu_to_le16(index); 397 + req.wLength = cpu_to_le16(size); 398 + 399 + pids = DBGP_PID_SET(USB_PID_DATA0, USB_PID_SETUP); 400 + addr = DBGP_EPADDR(devnum, 0); 401 + 402 + ctrl = readl(&ehci_debug->control); 403 + ctrl = dbgp_len_update(ctrl, sizeof(req)); 404 + ctrl |= DBGP_OUT; 405 + ctrl |= DBGP_GO; 406 + 407 + /* Send the setup message */ 408 + dbgp_set_data(&req, sizeof(req)); 409 + writel(addr, &ehci_debug->address); 410 + writel(pids, &ehci_debug->pids); 411 + ret = dbgp_wait_until_done(ctrl); 412 + if (ret < 0) 413 + return ret; 414 + 415 + /* Read the result */ 416 + return dbgp_bulk_read(devnum, 0, data, size); 417 + } 418 + 419 + 420 + /* Find a PCI capability */ 421 + static u32 __init find_cap(u32 num, u32 slot, u32 func, int cap) 422 + { 423 + u8 pos; 424 + int bytes; 425 + 426 + if (!(read_pci_config_16(num, slot, func, PCI_STATUS) & 427 + PCI_STATUS_CAP_LIST)) 428 + return 0; 429 + 430 + pos = read_pci_config_byte(num, slot, func, PCI_CAPABILITY_LIST); 431 + for (bytes = 0; bytes < 48 && pos >= 0x40; bytes++) { 432 + u8 id; 433 + 434 + pos &= ~3; 435 + id = read_pci_config_byte(num, slot, func, pos+PCI_CAP_LIST_ID); 436 + if (id == 0xff) 437 + break; 438 + if (id == cap) 439 + return pos; 440 + 441 + pos = read_pci_config_byte(num, slot, func, 442 + pos+PCI_CAP_LIST_NEXT); 443 + } 444 + return 0; 445 + } 446 + 447 + static u32 __init __find_dbgp(u32 bus, u32 slot, u32 func) 448 + { 449 + u32 class; 450 + 451 + class = read_pci_config(bus, slot, func, PCI_CLASS_REVISION); 452 + if ((class >> 8) != PCI_CLASS_SERIAL_USB_EHCI) 453 + return 0; 454 + 455 + return find_cap(bus, slot, func, PCI_CAP_ID_EHCI_DEBUG); 456 + } 457 + 458 + static u32 __init find_dbgp(int ehci_num, u32 *rbus, u32 *rslot, u32 *rfunc) 459 + { 460 + u32 bus, slot, func; 461 + 462 + for (bus = 0; bus < 256; bus++) { 463 + for (slot = 0; slot < 32; slot++) { 464 + for (func = 0; func < 8; func++) { 465 + unsigned cap; 466 + 467 + cap = __find_dbgp(bus, slot, func); 468 + 469 + if (!cap) 470 + continue; 471 + if (ehci_num-- != 0) 472 + continue; 473 + *rbus = bus; 474 + *rslot = slot; 475 + *rfunc = func; 476 + return cap; 477 + } 478 + } 479 + } 480 + return 0; 481 + } 482 + 483 + static int ehci_reset_port(int port) 484 + { 485 + u32 portsc; 486 + u32 delay_time, delay; 487 + int loop; 488 + 489 + /* Reset the usb debug port */ 490 + portsc = readl(&ehci_regs->port_status[port - 1]); 491 + portsc &= ~PORT_PE; 492 + portsc |= PORT_RESET; 493 + writel(portsc, &ehci_regs->port_status[port - 1]); 494 + 495 + delay = HUB_ROOT_RESET_TIME; 496 + for (delay_time = 0; delay_time < HUB_RESET_TIMEOUT; 497 + delay_time += delay) { 498 + dbgp_mdelay(delay); 499 + 500 + portsc = readl(&ehci_regs->port_status[port - 1]); 501 + if (portsc & PORT_RESET) { 502 + /* force reset to complete */ 503 + loop = 2; 504 + writel(portsc & ~(PORT_RWC_BITS | PORT_RESET), 505 + &ehci_regs->port_status[port - 1]); 506 + do { 507 + portsc = readl(&ehci_regs->port_status[port-1]); 508 + } while ((portsc & PORT_RESET) && (--loop > 0)); 509 + } 510 + 511 + /* Device went away? */ 512 + if (!(portsc & PORT_CONNECT)) 513 + return -ENOTCONN; 514 + 515 + /* bomb out completely if something weird happend */ 516 + if ((portsc & PORT_CSC)) 517 + return -EINVAL; 518 + 519 + /* If we've finished resetting, then break out of the loop */ 520 + if (!(portsc & PORT_RESET) && (portsc & PORT_PE)) 521 + return 0; 522 + } 523 + return -EBUSY; 524 + } 525 + 526 + static int ehci_wait_for_port(int port) 527 + { 528 + u32 status; 529 + int ret, reps; 530 + 531 + for (reps = 0; reps < 3; reps++) { 532 + dbgp_mdelay(100); 533 + status = readl(&ehci_regs->status); 534 + if (status & STS_PCD) { 535 + ret = ehci_reset_port(port); 536 + if (ret == 0) 537 + return 0; 538 + } 539 + } 540 + return -ENOTCONN; 541 + } 542 + 543 + #ifdef DBGP_DEBUG 544 + # define dbgp_printk early_printk 545 + #else 546 + static inline void dbgp_printk(const char *fmt, ...) { } 547 + #endif 548 + 549 + typedef void (*set_debug_port_t)(int port); 550 + 551 + static void default_set_debug_port(int port) 552 + { 553 + } 554 + 555 + static set_debug_port_t set_debug_port = default_set_debug_port; 556 + 557 + static void nvidia_set_debug_port(int port) 558 + { 559 + u32 dword; 560 + dword = read_pci_config(ehci_dev.bus, ehci_dev.slot, ehci_dev.func, 561 + 0x74); 562 + dword &= ~(0x0f<<12); 563 + dword |= ((port & 0x0f)<<12); 564 + write_pci_config(ehci_dev.bus, ehci_dev.slot, ehci_dev.func, 0x74, 565 + dword); 566 + dbgp_printk("set debug port to %d\n", port); 567 + } 568 + 569 + static void __init detect_set_debug_port(void) 570 + { 571 + u32 vendorid; 572 + 573 + vendorid = read_pci_config(ehci_dev.bus, ehci_dev.slot, ehci_dev.func, 574 + 0x00); 575 + 576 + if ((vendorid & 0xffff) == 0x10de) { 577 + dbgp_printk("using nvidia set_debug_port\n"); 578 + set_debug_port = nvidia_set_debug_port; 579 + } 580 + } 581 + 582 + static int __init ehci_setup(void) 583 + { 584 + struct usb_debug_descriptor dbgp_desc; 585 + u32 cmd, ctrl, status, portsc, hcs_params; 586 + u32 debug_port, new_debug_port = 0, n_ports; 587 + u32 devnum; 588 + int ret, i; 589 + int loop; 590 + int port_map_tried; 591 + int playtimes = 3; 592 + 593 + try_next_time: 594 + port_map_tried = 0; 595 + 596 + try_next_port: 597 + 598 + hcs_params = readl(&ehci_caps->hcs_params); 599 + debug_port = HCS_DEBUG_PORT(hcs_params); 600 + n_ports = HCS_N_PORTS(hcs_params); 601 + 602 + dbgp_printk("debug_port: %d\n", debug_port); 603 + dbgp_printk("n_ports: %d\n", n_ports); 604 + 605 + for (i = 1; i <= n_ports; i++) { 606 + portsc = readl(&ehci_regs->port_status[i-1]); 607 + dbgp_printk("portstatus%d: %08x\n", i, portsc); 608 + } 609 + 610 + if (port_map_tried && (new_debug_port != debug_port)) { 611 + if (--playtimes) { 612 + set_debug_port(new_debug_port); 613 + goto try_next_time; 614 + } 615 + return -1; 616 + } 617 + 618 + loop = 10; 619 + /* Reset the EHCI controller */ 620 + cmd = readl(&ehci_regs->command); 621 + cmd |= CMD_RESET; 622 + writel(cmd, &ehci_regs->command); 623 + do { 624 + cmd = readl(&ehci_regs->command); 625 + } while ((cmd & CMD_RESET) && (--loop > 0)); 626 + 627 + if (!loop) { 628 + dbgp_printk("can not reset ehci\n"); 629 + return -1; 630 + } 631 + dbgp_printk("ehci reset done\n"); 632 + 633 + /* Claim ownership, but do not enable yet */ 634 + ctrl = readl(&ehci_debug->control); 635 + ctrl |= DBGP_OWNER; 636 + ctrl &= ~(DBGP_ENABLED | DBGP_INUSE); 637 + writel(ctrl, &ehci_debug->control); 638 + 639 + /* Start the ehci running */ 640 + cmd = readl(&ehci_regs->command); 641 + cmd &= ~(CMD_LRESET | CMD_IAAD | CMD_PSE | CMD_ASE | CMD_RESET); 642 + cmd |= CMD_RUN; 643 + writel(cmd, &ehci_regs->command); 644 + 645 + /* Ensure everything is routed to the EHCI */ 646 + writel(FLAG_CF, &ehci_regs->configured_flag); 647 + 648 + /* Wait until the controller is no longer halted */ 649 + loop = 10; 650 + do { 651 + status = readl(&ehci_regs->status); 652 + } while ((status & STS_HALT) && (--loop > 0)); 653 + 654 + if (!loop) { 655 + dbgp_printk("ehci can be started\n"); 656 + return -1; 657 + } 658 + dbgp_printk("ehci started\n"); 659 + 660 + /* Wait for a device to show up in the debug port */ 661 + ret = ehci_wait_for_port(debug_port); 662 + if (ret < 0) { 663 + dbgp_printk("No device found in debug port\n"); 664 + goto next_debug_port; 665 + } 666 + dbgp_printk("ehci wait for port done\n"); 667 + 668 + /* Enable the debug port */ 669 + ctrl = readl(&ehci_debug->control); 670 + ctrl |= DBGP_CLAIM; 671 + writel(ctrl, &ehci_debug->control); 672 + ctrl = readl(&ehci_debug->control); 673 + if ((ctrl & DBGP_CLAIM) != DBGP_CLAIM) { 674 + dbgp_printk("No device in debug port\n"); 675 + writel(ctrl & ~DBGP_CLAIM, &ehci_debug->control); 676 + goto err; 677 + } 678 + dbgp_printk("debug ported enabled\n"); 679 + 680 + /* Completely transfer the debug device to the debug controller */ 681 + portsc = readl(&ehci_regs->port_status[debug_port - 1]); 682 + portsc &= ~PORT_PE; 683 + writel(portsc, &ehci_regs->port_status[debug_port - 1]); 684 + 685 + dbgp_mdelay(100); 686 + 687 + /* Find the debug device and make it device number 127 */ 688 + for (devnum = 0; devnum <= 127; devnum++) { 689 + ret = dbgp_control_msg(devnum, 690 + USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE, 691 + USB_REQ_GET_DESCRIPTOR, (USB_DT_DEBUG << 8), 0, 692 + &dbgp_desc, sizeof(dbgp_desc)); 693 + if (ret > 0) 694 + break; 695 + } 696 + if (devnum > 127) { 697 + dbgp_printk("Could not find attached debug device\n"); 698 + goto err; 699 + } 700 + if (ret < 0) { 701 + dbgp_printk("Attached device is not a debug device\n"); 702 + goto err; 703 + } 704 + dbgp_endpoint_out = dbgp_desc.bDebugOutEndpoint; 705 + 706 + /* Move the device to 127 if it isn't already there */ 707 + if (devnum != USB_DEBUG_DEVNUM) { 708 + ret = dbgp_control_msg(devnum, 709 + USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE, 710 + USB_REQ_SET_ADDRESS, USB_DEBUG_DEVNUM, 0, NULL, 0); 711 + if (ret < 0) { 712 + dbgp_printk("Could not move attached device to %d\n", 713 + USB_DEBUG_DEVNUM); 714 + goto err; 715 + } 716 + devnum = USB_DEBUG_DEVNUM; 717 + dbgp_printk("debug device renamed to 127\n"); 718 + } 719 + 720 + /* Enable the debug interface */ 721 + ret = dbgp_control_msg(USB_DEBUG_DEVNUM, 722 + USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE, 723 + USB_REQ_SET_FEATURE, USB_DEVICE_DEBUG_MODE, 0, NULL, 0); 724 + if (ret < 0) { 725 + dbgp_printk(" Could not enable the debug device\n"); 726 + goto err; 727 + } 728 + dbgp_printk("debug interface enabled\n"); 729 + 730 + /* Perform a small write to get the even/odd data state in sync 731 + */ 732 + ret = dbgp_bulk_write(USB_DEBUG_DEVNUM, dbgp_endpoint_out, " ", 1); 733 + if (ret < 0) { 734 + dbgp_printk("dbgp_bulk_write failed: %d\n", ret); 735 + goto err; 736 + } 737 + dbgp_printk("small write doned\n"); 738 + 739 + return 0; 740 + err: 741 + /* Things didn't work so remove my claim */ 742 + ctrl = readl(&ehci_debug->control); 743 + ctrl &= ~(DBGP_CLAIM | DBGP_OUT); 744 + writel(ctrl, &ehci_debug->control); 745 + return -1; 746 + 747 + next_debug_port: 748 + port_map_tried |= (1<<(debug_port - 1)); 749 + new_debug_port = ((debug_port-1+1)%n_ports) + 1; 750 + if (port_map_tried != ((1<<n_ports) - 1)) { 751 + set_debug_port(new_debug_port); 752 + goto try_next_port; 753 + } 754 + if (--playtimes) { 755 + set_debug_port(new_debug_port); 756 + goto try_next_time; 757 + } 758 + 759 + return -1; 760 + } 761 + 762 + static int __init early_dbgp_init(char *s) 763 + { 764 + u32 debug_port, bar, offset; 765 + u32 bus, slot, func, cap; 766 + void __iomem *ehci_bar; 767 + u32 dbgp_num; 768 + u32 bar_val; 769 + char *e; 770 + int ret; 771 + u8 byte; 772 + 773 + if (!early_pci_allowed()) 774 + return -1; 775 + 776 + dbgp_num = 0; 777 + if (*s) 778 + dbgp_num = simple_strtoul(s, &e, 10); 779 + dbgp_printk("dbgp_num: %d\n", dbgp_num); 780 + 781 + cap = find_dbgp(dbgp_num, &bus, &slot, &func); 782 + if (!cap) 783 + return -1; 784 + 785 + dbgp_printk("Found EHCI debug port on %02x:%02x.%1x\n", bus, slot, 786 + func); 787 + 788 + debug_port = read_pci_config(bus, slot, func, cap); 789 + bar = (debug_port >> 29) & 0x7; 790 + bar = (bar * 4) + 0xc; 791 + offset = (debug_port >> 16) & 0xfff; 792 + dbgp_printk("bar: %02x offset: %03x\n", bar, offset); 793 + if (bar != PCI_BASE_ADDRESS_0) { 794 + dbgp_printk("only debug ports on bar 1 handled.\n"); 795 + 796 + return -1; 797 + } 798 + 799 + bar_val = read_pci_config(bus, slot, func, PCI_BASE_ADDRESS_0); 800 + dbgp_printk("bar_val: %02x offset: %03x\n", bar_val, offset); 801 + if (bar_val & ~PCI_BASE_ADDRESS_MEM_MASK) { 802 + dbgp_printk("only simple 32bit mmio bars supported\n"); 803 + 804 + return -1; 805 + } 806 + 807 + /* double check if the mem space is enabled */ 808 + byte = read_pci_config_byte(bus, slot, func, 0x04); 809 + if (!(byte & 0x2)) { 810 + byte |= 0x02; 811 + write_pci_config_byte(bus, slot, func, 0x04, byte); 812 + dbgp_printk("mmio for ehci enabled\n"); 813 + } 814 + 815 + /* 816 + * FIXME I don't have the bar size so just guess PAGE_SIZE is more 817 + * than enough. 1K is the biggest I have seen. 818 + */ 819 + set_fixmap_nocache(FIX_DBGP_BASE, bar_val & PAGE_MASK); 820 + ehci_bar = (void __iomem *)__fix_to_virt(FIX_DBGP_BASE); 821 + ehci_bar += bar_val & ~PAGE_MASK; 822 + dbgp_printk("ehci_bar: %p\n", ehci_bar); 823 + 824 + ehci_caps = ehci_bar; 825 + ehci_regs = ehci_bar + HC_LENGTH(readl(&ehci_caps->hc_capbase)); 826 + ehci_debug = ehci_bar + offset; 827 + ehci_dev.bus = bus; 828 + ehci_dev.slot = slot; 829 + ehci_dev.func = func; 830 + 831 + detect_set_debug_port(); 832 + 833 + ret = ehci_setup(); 834 + if (ret < 0) { 835 + dbgp_printk("ehci_setup failed\n"); 836 + ehci_debug = NULL; 837 + 838 + return -1; 839 + } 840 + 841 + return 0; 842 + } 843 + 844 + static void early_dbgp_write(struct console *con, const char *str, u32 n) 845 + { 846 + int chunk, ret; 847 + 848 + if (!ehci_debug) 849 + return; 850 + while (n > 0) { 851 + chunk = n; 852 + if (chunk > DBGP_MAX_PACKET) 853 + chunk = DBGP_MAX_PACKET; 854 + ret = dbgp_bulk_write(USB_DEBUG_DEVNUM, 855 + dbgp_endpoint_out, str, chunk); 856 + str += chunk; 857 + n -= chunk; 858 + } 859 + } 860 + 861 + static struct console early_dbgp_console = { 862 + .name = "earlydbg", 863 + .write = early_dbgp_write, 864 + .flags = CON_PRINTBUFFER, 865 + .index = -1, 866 + }; 867 + #endif 868 + 163 869 /* Console interface to a host file on AMD's SimNow! */ 164 870 165 871 static int simnow_fd; ··· 889 165 static noinline long simnow(long cmd, long a, long b, long c) 890 166 { 891 167 long ret; 168 + 892 169 asm volatile("cpuid" : 893 170 "=a" (ret) : 894 171 "b" (a), "c" (b), "d" (c), "0" (MAGIC1), "D" (cmd + MAGIC2)); ··· 899 174 static void __init simnow_init(char *str) 900 175 { 901 176 char *fn = "klog"; 177 + 902 178 if (*str == '=') 903 179 fn = ++str; 904 180 /* error ignored */ ··· 920 194 921 195 /* Direct interface for emergencies */ 922 196 static struct console *early_console = &early_vga_console; 923 - static int early_console_initialized; 197 + static int __initdata early_console_initialized; 924 198 925 199 asmlinkage void early_printk(const char *fmt, ...) 926 200 { ··· 934 208 va_end(ap); 935 209 } 936 210 937 - static int __initdata keep_early; 938 211 939 212 static int __init setup_early_printk(char *buf) 940 213 { 214 + int keep_early; 215 + 941 216 if (!buf) 942 217 return 0; 943 218 ··· 946 219 return 0; 947 220 early_console_initialized = 1; 948 221 949 - if (strstr(buf, "keep")) 950 - keep_early = 1; 222 + keep_early = (strstr(buf, "keep") != NULL); 951 223 952 224 if (!strncmp(buf, "serial", 6)) { 953 225 early_serial_init(buf + 6); ··· 964 238 simnow_init(buf + 6); 965 239 early_console = &simnow_console; 966 240 keep_early = 1; 241 + #ifdef CONFIG_EARLY_PRINTK_DBGP 242 + } else if (!strncmp(buf, "dbgp", 4)) { 243 + if (early_dbgp_init(buf+4) < 0) 244 + return 0; 245 + early_console = &early_dbgp_console; 246 + /* 247 + * usb subsys will reset ehci controller, so don't keep 248 + * that early console 249 + */ 250 + keep_early = 0; 251 + #endif 967 252 #ifdef CONFIG_HVC_XEN 968 253 } else if (!strncmp(buf, "xen", 3)) { 969 254 early_console = &xenboot_console; ··· 988 251 register_console(early_console); 989 252 return 0; 990 253 } 254 + 991 255 early_param("earlyprintk", setup_early_printk);
+14
arch/x86/kernel/i387.c
··· 468 468 469 469 static int save_i387_xsave(void __user *buf) 470 470 { 471 + struct task_struct *tsk = current; 471 472 struct _fpstate_ia32 __user *fx = buf; 472 473 int err = 0; 474 + 475 + /* 476 + * For legacy compatible, we always set FP/SSE bits in the bit 477 + * vector while saving the state to the user context. 478 + * This will enable us capturing any changes(during sigreturn) to 479 + * the FP/SSE bits by the legacy applications which don't touch 480 + * xstate_bv in the xsave header. 481 + * 482 + * xsave aware applications can change the xstate_bv in the xsave 483 + * header as well as change any contents in the memory layout. 484 + * xrestore as part of sigreturn will capture all the changes. 485 + */ 486 + tsk->thread.xstate->xsave.xsave_hdr.xstate_bv |= XSTATE_FPSSE; 473 487 474 488 if (save_i387_fxsave(fx) < 0) 475 489 return -1;
+2 -2
arch/x86/kernel/io_apic_64.c
··· 1281 1281 printk(KERN_DEBUG "... APIC ESR: %08x\n", v); 1282 1282 1283 1283 icr = apic_icr_read(); 1284 - printk(KERN_DEBUG "... APIC ICR: %08x\n", icr); 1285 - printk(KERN_DEBUG "... APIC ICR2: %08x\n", icr >> 32); 1284 + printk(KERN_DEBUG "... APIC ICR: %08x\n", (u32)icr); 1285 + printk(KERN_DEBUG "... APIC ICR2: %08x\n", (u32)(icr >> 32)); 1286 1286 1287 1287 v = apic_read(APIC_LVTT); 1288 1288 printk(KERN_DEBUG "... APIC LVTT: %08x\n", v);
+8 -1
arch/x86/kernel/ldt.c
··· 52 52 memset(newldt + oldsize * LDT_ENTRY_SIZE, 0, 53 53 (mincount - oldsize) * LDT_ENTRY_SIZE); 54 54 55 + paravirt_alloc_ldt(newldt, mincount); 56 + 55 57 #ifdef CONFIG_X86_64 56 58 /* CHECKME: Do we really need this ? */ 57 59 wmb(); ··· 76 74 #endif 77 75 } 78 76 if (oldsize) { 77 + paravirt_free_ldt(oldldt, oldsize); 79 78 if (oldsize * LDT_ENTRY_SIZE > PAGE_SIZE) 80 79 vfree(oldldt); 81 80 else ··· 88 85 static inline int copy_ldt(mm_context_t *new, mm_context_t *old) 89 86 { 90 87 int err = alloc_ldt(new, old->size, 0); 88 + int i; 91 89 92 90 if (err < 0) 93 91 return err; 94 - memcpy(new->ldt, old->ldt, old->size * LDT_ENTRY_SIZE); 92 + 93 + for(i = 0; i < old->size; i++) 94 + write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE); 95 95 return 0; 96 96 } 97 97 ··· 131 125 if (mm == current->active_mm) 132 126 clear_LDT(); 133 127 #endif 128 + paravirt_free_ldt(mm->context.ldt, mm->context.size); 134 129 if (mm->context.size * LDT_ENTRY_SIZE > PAGE_SIZE) 135 130 vfree(mm->context.ldt); 136 131 else
-853
arch/x86/kernel/microcode.c
··· 1 - /* 2 - * Intel CPU Microcode Update Driver for Linux 3 - * 4 - * Copyright (C) 2000-2006 Tigran Aivazian <tigran@aivazian.fsnet.co.uk> 5 - * 2006 Shaohua Li <shaohua.li@intel.com> 6 - * 7 - * This driver allows to upgrade microcode on Intel processors 8 - * belonging to IA-32 family - PentiumPro, Pentium II, 9 - * Pentium III, Xeon, Pentium 4, etc. 10 - * 11 - * Reference: Section 8.11 of Volume 3a, IA-32 Intel? Architecture 12 - * Software Developer's Manual 13 - * Order Number 253668 or free download from: 14 - * 15 - * http://developer.intel.com/design/pentium4/manuals/253668.htm 16 - * 17 - * For more information, go to http://www.urbanmyth.org/microcode 18 - * 19 - * This program is free software; you can redistribute it and/or 20 - * modify it under the terms of the GNU General Public License 21 - * as published by the Free Software Foundation; either version 22 - * 2 of the License, or (at your option) any later version. 23 - * 24 - * 1.0 16 Feb 2000, Tigran Aivazian <tigran@sco.com> 25 - * Initial release. 26 - * 1.01 18 Feb 2000, Tigran Aivazian <tigran@sco.com> 27 - * Added read() support + cleanups. 28 - * 1.02 21 Feb 2000, Tigran Aivazian <tigran@sco.com> 29 - * Added 'device trimming' support. open(O_WRONLY) zeroes 30 - * and frees the saved copy of applied microcode. 31 - * 1.03 29 Feb 2000, Tigran Aivazian <tigran@sco.com> 32 - * Made to use devfs (/dev/cpu/microcode) + cleanups. 33 - * 1.04 06 Jun 2000, Simon Trimmer <simon@veritas.com> 34 - * Added misc device support (now uses both devfs and misc). 35 - * Added MICROCODE_IOCFREE ioctl to clear memory. 36 - * 1.05 09 Jun 2000, Simon Trimmer <simon@veritas.com> 37 - * Messages for error cases (non Intel & no suitable microcode). 38 - * 1.06 03 Aug 2000, Tigran Aivazian <tigran@veritas.com> 39 - * Removed ->release(). Removed exclusive open and status bitmap. 40 - * Added microcode_rwsem to serialize read()/write()/ioctl(). 41 - * Removed global kernel lock usage. 42 - * 1.07 07 Sep 2000, Tigran Aivazian <tigran@veritas.com> 43 - * Write 0 to 0x8B msr and then cpuid before reading revision, 44 - * so that it works even if there were no update done by the 45 - * BIOS. Otherwise, reading from 0x8B gives junk (which happened 46 - * to be 0 on my machine which is why it worked even when I 47 - * disabled update by the BIOS) 48 - * Thanks to Eric W. Biederman <ebiederman@lnxi.com> for the fix. 49 - * 1.08 11 Dec 2000, Richard Schaal <richard.schaal@intel.com> and 50 - * Tigran Aivazian <tigran@veritas.com> 51 - * Intel Pentium 4 processor support and bugfixes. 52 - * 1.09 30 Oct 2001, Tigran Aivazian <tigran@veritas.com> 53 - * Bugfix for HT (Hyper-Threading) enabled processors 54 - * whereby processor resources are shared by all logical processors 55 - * in a single CPU package. 56 - * 1.10 28 Feb 2002 Asit K Mallick <asit.k.mallick@intel.com> and 57 - * Tigran Aivazian <tigran@veritas.com>, 58 - * Serialize updates as required on HT processors due to speculative 59 - * nature of implementation. 60 - * 1.11 22 Mar 2002 Tigran Aivazian <tigran@veritas.com> 61 - * Fix the panic when writing zero-length microcode chunk. 62 - * 1.12 29 Sep 2003 Nitin Kamble <nitin.a.kamble@intel.com>, 63 - * Jun Nakajima <jun.nakajima@intel.com> 64 - * Support for the microcode updates in the new format. 65 - * 1.13 10 Oct 2003 Tigran Aivazian <tigran@veritas.com> 66 - * Removed ->read() method and obsoleted MICROCODE_IOCFREE ioctl 67 - * because we no longer hold a copy of applied microcode 68 - * in kernel memory. 69 - * 1.14 25 Jun 2004 Tigran Aivazian <tigran@veritas.com> 70 - * Fix sigmatch() macro to handle old CPUs with pf == 0. 71 - * Thanks to Stuart Swales for pointing out this bug. 72 - */ 73 - 74 - //#define DEBUG /* pr_debug */ 75 - #include <linux/capability.h> 76 - #include <linux/kernel.h> 77 - #include <linux/init.h> 78 - #include <linux/sched.h> 79 - #include <linux/smp_lock.h> 80 - #include <linux/cpumask.h> 81 - #include <linux/module.h> 82 - #include <linux/slab.h> 83 - #include <linux/vmalloc.h> 84 - #include <linux/miscdevice.h> 85 - #include <linux/spinlock.h> 86 - #include <linux/mm.h> 87 - #include <linux/fs.h> 88 - #include <linux/mutex.h> 89 - #include <linux/cpu.h> 90 - #include <linux/firmware.h> 91 - #include <linux/platform_device.h> 92 - 93 - #include <asm/msr.h> 94 - #include <asm/uaccess.h> 95 - #include <asm/processor.h> 96 - 97 - MODULE_DESCRIPTION("Intel CPU (IA-32) Microcode Update Driver"); 98 - MODULE_AUTHOR("Tigran Aivazian <tigran@aivazian.fsnet.co.uk>"); 99 - MODULE_LICENSE("GPL"); 100 - 101 - #define MICROCODE_VERSION "1.14a" 102 - 103 - #define DEFAULT_UCODE_DATASIZE (2000) /* 2000 bytes */ 104 - #define MC_HEADER_SIZE (sizeof (microcode_header_t)) /* 48 bytes */ 105 - #define DEFAULT_UCODE_TOTALSIZE (DEFAULT_UCODE_DATASIZE + MC_HEADER_SIZE) /* 2048 bytes */ 106 - #define EXT_HEADER_SIZE (sizeof (struct extended_sigtable)) /* 20 bytes */ 107 - #define EXT_SIGNATURE_SIZE (sizeof (struct extended_signature)) /* 12 bytes */ 108 - #define DWSIZE (sizeof (u32)) 109 - #define get_totalsize(mc) \ 110 - (((microcode_t *)mc)->hdr.totalsize ? \ 111 - ((microcode_t *)mc)->hdr.totalsize : DEFAULT_UCODE_TOTALSIZE) 112 - #define get_datasize(mc) \ 113 - (((microcode_t *)mc)->hdr.datasize ? \ 114 - ((microcode_t *)mc)->hdr.datasize : DEFAULT_UCODE_DATASIZE) 115 - 116 - #define sigmatch(s1, s2, p1, p2) \ 117 - (((s1) == (s2)) && (((p1) & (p2)) || (((p1) == 0) && ((p2) == 0)))) 118 - 119 - #define exttable_size(et) ((et)->count * EXT_SIGNATURE_SIZE + EXT_HEADER_SIZE) 120 - 121 - /* serialize access to the physical write to MSR 0x79 */ 122 - static DEFINE_SPINLOCK(microcode_update_lock); 123 - 124 - /* no concurrent ->write()s are allowed on /dev/cpu/microcode */ 125 - static DEFINE_MUTEX(microcode_mutex); 126 - 127 - static struct ucode_cpu_info { 128 - int valid; 129 - unsigned int sig; 130 - unsigned int pf; 131 - unsigned int rev; 132 - microcode_t *mc; 133 - } ucode_cpu_info[NR_CPUS]; 134 - 135 - static void collect_cpu_info(int cpu_num) 136 - { 137 - struct cpuinfo_x86 *c = &cpu_data(cpu_num); 138 - struct ucode_cpu_info *uci = ucode_cpu_info + cpu_num; 139 - unsigned int val[2]; 140 - 141 - /* We should bind the task to the CPU */ 142 - BUG_ON(raw_smp_processor_id() != cpu_num); 143 - uci->pf = uci->rev = 0; 144 - uci->mc = NULL; 145 - uci->valid = 1; 146 - 147 - if (c->x86_vendor != X86_VENDOR_INTEL || c->x86 < 6 || 148 - cpu_has(c, X86_FEATURE_IA64)) { 149 - printk(KERN_ERR "microcode: CPU%d not a capable Intel " 150 - "processor\n", cpu_num); 151 - uci->valid = 0; 152 - return; 153 - } 154 - 155 - uci->sig = cpuid_eax(0x00000001); 156 - 157 - if ((c->x86_model >= 5) || (c->x86 > 6)) { 158 - /* get processor flags from MSR 0x17 */ 159 - rdmsr(MSR_IA32_PLATFORM_ID, val[0], val[1]); 160 - uci->pf = 1 << ((val[1] >> 18) & 7); 161 - } 162 - 163 - wrmsr(MSR_IA32_UCODE_REV, 0, 0); 164 - /* see notes above for revision 1.07. Apparent chip bug */ 165 - sync_core(); 166 - /* get the current revision from MSR 0x8B */ 167 - rdmsr(MSR_IA32_UCODE_REV, val[0], uci->rev); 168 - pr_debug("microcode: collect_cpu_info : sig=0x%x, pf=0x%x, rev=0x%x\n", 169 - uci->sig, uci->pf, uci->rev); 170 - } 171 - 172 - static inline int microcode_update_match(int cpu_num, 173 - microcode_header_t *mc_header, int sig, int pf) 174 - { 175 - struct ucode_cpu_info *uci = ucode_cpu_info + cpu_num; 176 - 177 - if (!sigmatch(sig, uci->sig, pf, uci->pf) 178 - || mc_header->rev <= uci->rev) 179 - return 0; 180 - return 1; 181 - } 182 - 183 - static int microcode_sanity_check(void *mc) 184 - { 185 - microcode_header_t *mc_header = mc; 186 - struct extended_sigtable *ext_header = NULL; 187 - struct extended_signature *ext_sig; 188 - unsigned long total_size, data_size, ext_table_size; 189 - int sum, orig_sum, ext_sigcount = 0, i; 190 - 191 - total_size = get_totalsize(mc_header); 192 - data_size = get_datasize(mc_header); 193 - if (data_size + MC_HEADER_SIZE > total_size) { 194 - printk(KERN_ERR "microcode: error! " 195 - "Bad data size in microcode data file\n"); 196 - return -EINVAL; 197 - } 198 - 199 - if (mc_header->ldrver != 1 || mc_header->hdrver != 1) { 200 - printk(KERN_ERR "microcode: error! " 201 - "Unknown microcode update format\n"); 202 - return -EINVAL; 203 - } 204 - ext_table_size = total_size - (MC_HEADER_SIZE + data_size); 205 - if (ext_table_size) { 206 - if ((ext_table_size < EXT_HEADER_SIZE) 207 - || ((ext_table_size - EXT_HEADER_SIZE) % EXT_SIGNATURE_SIZE)) { 208 - printk(KERN_ERR "microcode: error! " 209 - "Small exttable size in microcode data file\n"); 210 - return -EINVAL; 211 - } 212 - ext_header = mc + MC_HEADER_SIZE + data_size; 213 - if (ext_table_size != exttable_size(ext_header)) { 214 - printk(KERN_ERR "microcode: error! " 215 - "Bad exttable size in microcode data file\n"); 216 - return -EFAULT; 217 - } 218 - ext_sigcount = ext_header->count; 219 - } 220 - 221 - /* check extended table checksum */ 222 - if (ext_table_size) { 223 - int ext_table_sum = 0; 224 - int *ext_tablep = (int *)ext_header; 225 - 226 - i = ext_table_size / DWSIZE; 227 - while (i--) 228 - ext_table_sum += ext_tablep[i]; 229 - if (ext_table_sum) { 230 - printk(KERN_WARNING "microcode: aborting, " 231 - "bad extended signature table checksum\n"); 232 - return -EINVAL; 233 - } 234 - } 235 - 236 - /* calculate the checksum */ 237 - orig_sum = 0; 238 - i = (MC_HEADER_SIZE + data_size) / DWSIZE; 239 - while (i--) 240 - orig_sum += ((int *)mc)[i]; 241 - if (orig_sum) { 242 - printk(KERN_ERR "microcode: aborting, bad checksum\n"); 243 - return -EINVAL; 244 - } 245 - if (!ext_table_size) 246 - return 0; 247 - /* check extended signature checksum */ 248 - for (i = 0; i < ext_sigcount; i++) { 249 - ext_sig = (void *)ext_header + EXT_HEADER_SIZE + 250 - EXT_SIGNATURE_SIZE * i; 251 - sum = orig_sum 252 - - (mc_header->sig + mc_header->pf + mc_header->cksum) 253 - + (ext_sig->sig + ext_sig->pf + ext_sig->cksum); 254 - if (sum) { 255 - printk(KERN_ERR "microcode: aborting, bad checksum\n"); 256 - return -EINVAL; 257 - } 258 - } 259 - return 0; 260 - } 261 - 262 - /* 263 - * return 0 - no update found 264 - * return 1 - found update 265 - * return < 0 - error 266 - */ 267 - static int get_maching_microcode(void *mc, int cpu) 268 - { 269 - struct ucode_cpu_info *uci = ucode_cpu_info + cpu; 270 - microcode_header_t *mc_header = mc; 271 - struct extended_sigtable *ext_header; 272 - unsigned long total_size = get_totalsize(mc_header); 273 - int ext_sigcount, i; 274 - struct extended_signature *ext_sig; 275 - void *new_mc; 276 - 277 - if (microcode_update_match(cpu, mc_header, 278 - mc_header->sig, mc_header->pf)) 279 - goto find; 280 - 281 - if (total_size <= get_datasize(mc_header) + MC_HEADER_SIZE) 282 - return 0; 283 - 284 - ext_header = mc + get_datasize(mc_header) + MC_HEADER_SIZE; 285 - ext_sigcount = ext_header->count; 286 - ext_sig = (void *)ext_header + EXT_HEADER_SIZE; 287 - for (i = 0; i < ext_sigcount; i++) { 288 - if (microcode_update_match(cpu, mc_header, 289 - ext_sig->sig, ext_sig->pf)) 290 - goto find; 291 - ext_sig++; 292 - } 293 - return 0; 294 - find: 295 - pr_debug("microcode: CPU%d found a matching microcode update with" 296 - " version 0x%x (current=0x%x)\n", cpu, mc_header->rev,uci->rev); 297 - new_mc = vmalloc(total_size); 298 - if (!new_mc) { 299 - printk(KERN_ERR "microcode: error! Can not allocate memory\n"); 300 - return -ENOMEM; 301 - } 302 - 303 - /* free previous update file */ 304 - vfree(uci->mc); 305 - 306 - memcpy(new_mc, mc, total_size); 307 - uci->mc = new_mc; 308 - return 1; 309 - } 310 - 311 - static void apply_microcode(int cpu) 312 - { 313 - unsigned long flags; 314 - unsigned int val[2]; 315 - int cpu_num = raw_smp_processor_id(); 316 - struct ucode_cpu_info *uci = ucode_cpu_info + cpu_num; 317 - 318 - /* We should bind the task to the CPU */ 319 - BUG_ON(cpu_num != cpu); 320 - 321 - if (uci->mc == NULL) 322 - return; 323 - 324 - /* serialize access to the physical write to MSR 0x79 */ 325 - spin_lock_irqsave(&microcode_update_lock, flags); 326 - 327 - /* write microcode via MSR 0x79 */ 328 - wrmsr(MSR_IA32_UCODE_WRITE, 329 - (unsigned long) uci->mc->bits, 330 - (unsigned long) uci->mc->bits >> 16 >> 16); 331 - wrmsr(MSR_IA32_UCODE_REV, 0, 0); 332 - 333 - /* see notes above for revision 1.07. Apparent chip bug */ 334 - sync_core(); 335 - 336 - /* get the current revision from MSR 0x8B */ 337 - rdmsr(MSR_IA32_UCODE_REV, val[0], val[1]); 338 - 339 - spin_unlock_irqrestore(&microcode_update_lock, flags); 340 - if (val[1] != uci->mc->hdr.rev) { 341 - printk(KERN_ERR "microcode: CPU%d update from revision " 342 - "0x%x to 0x%x failed\n", cpu_num, uci->rev, val[1]); 343 - return; 344 - } 345 - printk(KERN_INFO "microcode: CPU%d updated from revision " 346 - "0x%x to 0x%x, date = %08x \n", 347 - cpu_num, uci->rev, val[1], uci->mc->hdr.date); 348 - uci->rev = val[1]; 349 - } 350 - 351 - #ifdef CONFIG_MICROCODE_OLD_INTERFACE 352 - static void __user *user_buffer; /* user area microcode data buffer */ 353 - static unsigned int user_buffer_size; /* it's size */ 354 - 355 - static long get_next_ucode(void **mc, long offset) 356 - { 357 - microcode_header_t mc_header; 358 - unsigned long total_size; 359 - 360 - /* No more data */ 361 - if (offset >= user_buffer_size) 362 - return 0; 363 - if (copy_from_user(&mc_header, user_buffer + offset, MC_HEADER_SIZE)) { 364 - printk(KERN_ERR "microcode: error! Can not read user data\n"); 365 - return -EFAULT; 366 - } 367 - total_size = get_totalsize(&mc_header); 368 - if (offset + total_size > user_buffer_size) { 369 - printk(KERN_ERR "microcode: error! Bad total size in microcode " 370 - "data file\n"); 371 - return -EINVAL; 372 - } 373 - *mc = vmalloc(total_size); 374 - if (!*mc) 375 - return -ENOMEM; 376 - if (copy_from_user(*mc, user_buffer + offset, total_size)) { 377 - printk(KERN_ERR "microcode: error! Can not read user data\n"); 378 - vfree(*mc); 379 - return -EFAULT; 380 - } 381 - return offset + total_size; 382 - } 383 - 384 - static int do_microcode_update (void) 385 - { 386 - long cursor = 0; 387 - int error = 0; 388 - void *new_mc = NULL; 389 - int cpu; 390 - cpumask_t old; 391 - 392 - old = current->cpus_allowed; 393 - 394 - while ((cursor = get_next_ucode(&new_mc, cursor)) > 0) { 395 - error = microcode_sanity_check(new_mc); 396 - if (error) 397 - goto out; 398 - /* 399 - * It's possible the data file has multiple matching ucode, 400 - * lets keep searching till the latest version 401 - */ 402 - for_each_online_cpu(cpu) { 403 - struct ucode_cpu_info *uci = ucode_cpu_info + cpu; 404 - 405 - if (!uci->valid) 406 - continue; 407 - set_cpus_allowed_ptr(current, &cpumask_of_cpu(cpu)); 408 - error = get_maching_microcode(new_mc, cpu); 409 - if (error < 0) 410 - goto out; 411 - if (error == 1) 412 - apply_microcode(cpu); 413 - } 414 - vfree(new_mc); 415 - } 416 - out: 417 - if (cursor > 0) 418 - vfree(new_mc); 419 - if (cursor < 0) 420 - error = cursor; 421 - set_cpus_allowed_ptr(current, &old); 422 - return error; 423 - } 424 - 425 - static int microcode_open (struct inode *unused1, struct file *unused2) 426 - { 427 - cycle_kernel_lock(); 428 - return capable(CAP_SYS_RAWIO) ? 0 : -EPERM; 429 - } 430 - 431 - static ssize_t microcode_write (struct file *file, const char __user *buf, size_t len, loff_t *ppos) 432 - { 433 - ssize_t ret; 434 - 435 - if ((len >> PAGE_SHIFT) > num_physpages) { 436 - printk(KERN_ERR "microcode: too much data (max %ld pages)\n", num_physpages); 437 - return -EINVAL; 438 - } 439 - 440 - get_online_cpus(); 441 - mutex_lock(&microcode_mutex); 442 - 443 - user_buffer = (void __user *) buf; 444 - user_buffer_size = (int) len; 445 - 446 - ret = do_microcode_update(); 447 - if (!ret) 448 - ret = (ssize_t)len; 449 - 450 - mutex_unlock(&microcode_mutex); 451 - put_online_cpus(); 452 - 453 - return ret; 454 - } 455 - 456 - static const struct file_operations microcode_fops = { 457 - .owner = THIS_MODULE, 458 - .write = microcode_write, 459 - .open = microcode_open, 460 - }; 461 - 462 - static struct miscdevice microcode_dev = { 463 - .minor = MICROCODE_MINOR, 464 - .name = "microcode", 465 - .fops = &microcode_fops, 466 - }; 467 - 468 - static int __init microcode_dev_init (void) 469 - { 470 - int error; 471 - 472 - error = misc_register(&microcode_dev); 473 - if (error) { 474 - printk(KERN_ERR 475 - "microcode: can't misc_register on minor=%d\n", 476 - MICROCODE_MINOR); 477 - return error; 478 - } 479 - 480 - return 0; 481 - } 482 - 483 - static void microcode_dev_exit (void) 484 - { 485 - misc_deregister(&microcode_dev); 486 - } 487 - 488 - MODULE_ALIAS_MISCDEV(MICROCODE_MINOR); 489 - #else 490 - #define microcode_dev_init() 0 491 - #define microcode_dev_exit() do { } while(0) 492 - #endif 493 - 494 - static long get_next_ucode_from_buffer(void **mc, const u8 *buf, 495 - unsigned long size, long offset) 496 - { 497 - microcode_header_t *mc_header; 498 - unsigned long total_size; 499 - 500 - /* No more data */ 501 - if (offset >= size) 502 - return 0; 503 - mc_header = (microcode_header_t *)(buf + offset); 504 - total_size = get_totalsize(mc_header); 505 - 506 - if (offset + total_size > size) { 507 - printk(KERN_ERR "microcode: error! Bad data in microcode data file\n"); 508 - return -EINVAL; 509 - } 510 - 511 - *mc = vmalloc(total_size); 512 - if (!*mc) { 513 - printk(KERN_ERR "microcode: error! Can not allocate memory\n"); 514 - return -ENOMEM; 515 - } 516 - memcpy(*mc, buf + offset, total_size); 517 - return offset + total_size; 518 - } 519 - 520 - /* fake device for request_firmware */ 521 - static struct platform_device *microcode_pdev; 522 - 523 - static int cpu_request_microcode(int cpu) 524 - { 525 - char name[30]; 526 - struct cpuinfo_x86 *c = &cpu_data(cpu); 527 - const struct firmware *firmware; 528 - const u8 *buf; 529 - unsigned long size; 530 - long offset = 0; 531 - int error; 532 - void *mc; 533 - 534 - /* We should bind the task to the CPU */ 535 - BUG_ON(cpu != raw_smp_processor_id()); 536 - sprintf(name,"intel-ucode/%02x-%02x-%02x", 537 - c->x86, c->x86_model, c->x86_mask); 538 - error = request_firmware(&firmware, name, &microcode_pdev->dev); 539 - if (error) { 540 - pr_debug("microcode: data file %s load failed\n", name); 541 - return error; 542 - } 543 - buf = firmware->data; 544 - size = firmware->size; 545 - while ((offset = get_next_ucode_from_buffer(&mc, buf, size, offset)) 546 - > 0) { 547 - error = microcode_sanity_check(mc); 548 - if (error) 549 - break; 550 - error = get_maching_microcode(mc, cpu); 551 - if (error < 0) 552 - break; 553 - /* 554 - * It's possible the data file has multiple matching ucode, 555 - * lets keep searching till the latest version 556 - */ 557 - if (error == 1) { 558 - apply_microcode(cpu); 559 - error = 0; 560 - } 561 - vfree(mc); 562 - } 563 - if (offset > 0) 564 - vfree(mc); 565 - if (offset < 0) 566 - error = offset; 567 - release_firmware(firmware); 568 - 569 - return error; 570 - } 571 - 572 - static int apply_microcode_check_cpu(int cpu) 573 - { 574 - struct cpuinfo_x86 *c = &cpu_data(cpu); 575 - struct ucode_cpu_info *uci = ucode_cpu_info + cpu; 576 - cpumask_t old; 577 - unsigned int val[2]; 578 - int err = 0; 579 - 580 - /* Check if the microcode is available */ 581 - if (!uci->mc) 582 - return 0; 583 - 584 - old = current->cpus_allowed; 585 - set_cpus_allowed_ptr(current, &cpumask_of_cpu(cpu)); 586 - 587 - /* Check if the microcode we have in memory matches the CPU */ 588 - if (c->x86_vendor != X86_VENDOR_INTEL || c->x86 < 6 || 589 - cpu_has(c, X86_FEATURE_IA64) || uci->sig != cpuid_eax(0x00000001)) 590 - err = -EINVAL; 591 - 592 - if (!err && ((c->x86_model >= 5) || (c->x86 > 6))) { 593 - /* get processor flags from MSR 0x17 */ 594 - rdmsr(MSR_IA32_PLATFORM_ID, val[0], val[1]); 595 - if (uci->pf != (1 << ((val[1] >> 18) & 7))) 596 - err = -EINVAL; 597 - } 598 - 599 - if (!err) { 600 - wrmsr(MSR_IA32_UCODE_REV, 0, 0); 601 - /* see notes above for revision 1.07. Apparent chip bug */ 602 - sync_core(); 603 - /* get the current revision from MSR 0x8B */ 604 - rdmsr(MSR_IA32_UCODE_REV, val[0], val[1]); 605 - if (uci->rev != val[1]) 606 - err = -EINVAL; 607 - } 608 - 609 - if (!err) 610 - apply_microcode(cpu); 611 - else 612 - printk(KERN_ERR "microcode: Could not apply microcode to CPU%d:" 613 - " sig=0x%x, pf=0x%x, rev=0x%x\n", 614 - cpu, uci->sig, uci->pf, uci->rev); 615 - 616 - set_cpus_allowed_ptr(current, &old); 617 - return err; 618 - } 619 - 620 - static void microcode_init_cpu(int cpu, int resume) 621 - { 622 - cpumask_t old; 623 - struct ucode_cpu_info *uci = ucode_cpu_info + cpu; 624 - 625 - old = current->cpus_allowed; 626 - 627 - set_cpus_allowed_ptr(current, &cpumask_of_cpu(cpu)); 628 - mutex_lock(&microcode_mutex); 629 - collect_cpu_info(cpu); 630 - if (uci->valid && system_state == SYSTEM_RUNNING && !resume) 631 - cpu_request_microcode(cpu); 632 - mutex_unlock(&microcode_mutex); 633 - set_cpus_allowed_ptr(current, &old); 634 - } 635 - 636 - static void microcode_fini_cpu(int cpu) 637 - { 638 - struct ucode_cpu_info *uci = ucode_cpu_info + cpu; 639 - 640 - mutex_lock(&microcode_mutex); 641 - uci->valid = 0; 642 - vfree(uci->mc); 643 - uci->mc = NULL; 644 - mutex_unlock(&microcode_mutex); 645 - } 646 - 647 - static ssize_t reload_store(struct sys_device *dev, 648 - struct sysdev_attribute *attr, 649 - const char *buf, size_t sz) 650 - { 651 - struct ucode_cpu_info *uci = ucode_cpu_info + dev->id; 652 - char *end; 653 - unsigned long val = simple_strtoul(buf, &end, 0); 654 - int err = 0; 655 - int cpu = dev->id; 656 - 657 - if (end == buf) 658 - return -EINVAL; 659 - if (val == 1) { 660 - cpumask_t old = current->cpus_allowed; 661 - 662 - get_online_cpus(); 663 - set_cpus_allowed_ptr(current, &cpumask_of_cpu(cpu)); 664 - 665 - mutex_lock(&microcode_mutex); 666 - if (uci->valid) 667 - err = cpu_request_microcode(cpu); 668 - mutex_unlock(&microcode_mutex); 669 - put_online_cpus(); 670 - set_cpus_allowed_ptr(current, &old); 671 - } 672 - if (err) 673 - return err; 674 - return sz; 675 - } 676 - 677 - static ssize_t version_show(struct sys_device *dev, 678 - struct sysdev_attribute *attr, char *buf) 679 - { 680 - struct ucode_cpu_info *uci = ucode_cpu_info + dev->id; 681 - 682 - return sprintf(buf, "0x%x\n", uci->rev); 683 - } 684 - 685 - static ssize_t pf_show(struct sys_device *dev, 686 - struct sysdev_attribute *attr, char *buf) 687 - { 688 - struct ucode_cpu_info *uci = ucode_cpu_info + dev->id; 689 - 690 - return sprintf(buf, "0x%x\n", uci->pf); 691 - } 692 - 693 - static SYSDEV_ATTR(reload, 0200, NULL, reload_store); 694 - static SYSDEV_ATTR(version, 0400, version_show, NULL); 695 - static SYSDEV_ATTR(processor_flags, 0400, pf_show, NULL); 696 - 697 - static struct attribute *mc_default_attrs[] = { 698 - &attr_reload.attr, 699 - &attr_version.attr, 700 - &attr_processor_flags.attr, 701 - NULL 702 - }; 703 - 704 - static struct attribute_group mc_attr_group = { 705 - .attrs = mc_default_attrs, 706 - .name = "microcode", 707 - }; 708 - 709 - static int __mc_sysdev_add(struct sys_device *sys_dev, int resume) 710 - { 711 - int err, cpu = sys_dev->id; 712 - struct ucode_cpu_info *uci = ucode_cpu_info + cpu; 713 - 714 - if (!cpu_online(cpu)) 715 - return 0; 716 - 717 - pr_debug("microcode: CPU%d added\n", cpu); 718 - memset(uci, 0, sizeof(*uci)); 719 - 720 - err = sysfs_create_group(&sys_dev->kobj, &mc_attr_group); 721 - if (err) 722 - return err; 723 - 724 - microcode_init_cpu(cpu, resume); 725 - 726 - return 0; 727 - } 728 - 729 - static int mc_sysdev_add(struct sys_device *sys_dev) 730 - { 731 - return __mc_sysdev_add(sys_dev, 0); 732 - } 733 - 734 - static int mc_sysdev_remove(struct sys_device *sys_dev) 735 - { 736 - int cpu = sys_dev->id; 737 - 738 - if (!cpu_online(cpu)) 739 - return 0; 740 - 741 - pr_debug("microcode: CPU%d removed\n", cpu); 742 - microcode_fini_cpu(cpu); 743 - sysfs_remove_group(&sys_dev->kobj, &mc_attr_group); 744 - return 0; 745 - } 746 - 747 - static int mc_sysdev_resume(struct sys_device *dev) 748 - { 749 - int cpu = dev->id; 750 - 751 - if (!cpu_online(cpu)) 752 - return 0; 753 - pr_debug("microcode: CPU%d resumed\n", cpu); 754 - /* only CPU 0 will apply ucode here */ 755 - apply_microcode(0); 756 - return 0; 757 - } 758 - 759 - static struct sysdev_driver mc_sysdev_driver = { 760 - .add = mc_sysdev_add, 761 - .remove = mc_sysdev_remove, 762 - .resume = mc_sysdev_resume, 763 - }; 764 - 765 - static __cpuinit int 766 - mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu) 767 - { 768 - unsigned int cpu = (unsigned long)hcpu; 769 - struct sys_device *sys_dev; 770 - 771 - sys_dev = get_cpu_sysdev(cpu); 772 - switch (action) { 773 - case CPU_UP_CANCELED_FROZEN: 774 - /* The CPU refused to come up during a system resume */ 775 - microcode_fini_cpu(cpu); 776 - break; 777 - case CPU_ONLINE: 778 - case CPU_DOWN_FAILED: 779 - mc_sysdev_add(sys_dev); 780 - break; 781 - case CPU_ONLINE_FROZEN: 782 - /* System-wide resume is in progress, try to apply microcode */ 783 - if (apply_microcode_check_cpu(cpu)) { 784 - /* The application of microcode failed */ 785 - microcode_fini_cpu(cpu); 786 - __mc_sysdev_add(sys_dev, 1); 787 - break; 788 - } 789 - case CPU_DOWN_FAILED_FROZEN: 790 - if (sysfs_create_group(&sys_dev->kobj, &mc_attr_group)) 791 - printk(KERN_ERR "microcode: Failed to create the sysfs " 792 - "group for CPU%d\n", cpu); 793 - break; 794 - case CPU_DOWN_PREPARE: 795 - mc_sysdev_remove(sys_dev); 796 - break; 797 - case CPU_DOWN_PREPARE_FROZEN: 798 - /* Suspend is in progress, only remove the interface */ 799 - sysfs_remove_group(&sys_dev->kobj, &mc_attr_group); 800 - break; 801 - } 802 - return NOTIFY_OK; 803 - } 804 - 805 - static struct notifier_block __refdata mc_cpu_notifier = { 806 - .notifier_call = mc_cpu_callback, 807 - }; 808 - 809 - static int __init microcode_init (void) 810 - { 811 - int error; 812 - 813 - printk(KERN_INFO 814 - "IA-32 Microcode Update Driver: v" MICROCODE_VERSION " <tigran@aivazian.fsnet.co.uk>\n"); 815 - 816 - error = microcode_dev_init(); 817 - if (error) 818 - return error; 819 - microcode_pdev = platform_device_register_simple("microcode", -1, 820 - NULL, 0); 821 - if (IS_ERR(microcode_pdev)) { 822 - microcode_dev_exit(); 823 - return PTR_ERR(microcode_pdev); 824 - } 825 - 826 - get_online_cpus(); 827 - error = sysdev_driver_register(&cpu_sysdev_class, &mc_sysdev_driver); 828 - put_online_cpus(); 829 - if (error) { 830 - microcode_dev_exit(); 831 - platform_device_unregister(microcode_pdev); 832 - return error; 833 - } 834 - 835 - register_hotcpu_notifier(&mc_cpu_notifier); 836 - return 0; 837 - } 838 - 839 - static void __exit microcode_exit (void) 840 - { 841 - microcode_dev_exit(); 842 - 843 - unregister_hotcpu_notifier(&mc_cpu_notifier); 844 - 845 - get_online_cpus(); 846 - sysdev_driver_unregister(&cpu_sysdev_class, &mc_sysdev_driver); 847 - put_online_cpus(); 848 - 849 - platform_device_unregister(microcode_pdev); 850 - } 851 - 852 - module_init(microcode_init) 853 - module_exit(microcode_exit)
+435
arch/x86/kernel/microcode_amd.c
··· 1 + /* 2 + * AMD CPU Microcode Update Driver for Linux 3 + * Copyright (C) 2008 Advanced Micro Devices Inc. 4 + * 5 + * Author: Peter Oruba <peter.oruba@amd.com> 6 + * 7 + * Based on work by: 8 + * Tigran Aivazian <tigran@aivazian.fsnet.co.uk> 9 + * 10 + * This driver allows to upgrade microcode on AMD 11 + * family 0x10 and 0x11 processors. 12 + * 13 + * Licensed unter the terms of the GNU General Public 14 + * License version 2. See file COPYING for details. 15 + */ 16 + 17 + #include <linux/capability.h> 18 + #include <linux/kernel.h> 19 + #include <linux/init.h> 20 + #include <linux/sched.h> 21 + #include <linux/cpumask.h> 22 + #include <linux/module.h> 23 + #include <linux/slab.h> 24 + #include <linux/vmalloc.h> 25 + #include <linux/miscdevice.h> 26 + #include <linux/spinlock.h> 27 + #include <linux/mm.h> 28 + #include <linux/fs.h> 29 + #include <linux/mutex.h> 30 + #include <linux/cpu.h> 31 + #include <linux/firmware.h> 32 + #include <linux/platform_device.h> 33 + #include <linux/pci.h> 34 + #include <linux/pci_ids.h> 35 + 36 + #include <asm/msr.h> 37 + #include <asm/uaccess.h> 38 + #include <asm/processor.h> 39 + #include <asm/microcode.h> 40 + 41 + MODULE_DESCRIPTION("AMD Microcode Update Driver"); 42 + MODULE_AUTHOR("Peter Oruba <peter.oruba@amd.com>"); 43 + MODULE_LICENSE("GPL v2"); 44 + 45 + #define UCODE_MAGIC 0x00414d44 46 + #define UCODE_EQUIV_CPU_TABLE_TYPE 0x00000000 47 + #define UCODE_UCODE_TYPE 0x00000001 48 + 49 + struct equiv_cpu_entry { 50 + unsigned int installed_cpu; 51 + unsigned int fixed_errata_mask; 52 + unsigned int fixed_errata_compare; 53 + unsigned int equiv_cpu; 54 + }; 55 + 56 + struct microcode_header_amd { 57 + unsigned int data_code; 58 + unsigned int patch_id; 59 + unsigned char mc_patch_data_id[2]; 60 + unsigned char mc_patch_data_len; 61 + unsigned char init_flag; 62 + unsigned int mc_patch_data_checksum; 63 + unsigned int nb_dev_id; 64 + unsigned int sb_dev_id; 65 + unsigned char processor_rev_id[2]; 66 + unsigned char nb_rev_id; 67 + unsigned char sb_rev_id; 68 + unsigned char bios_api_rev; 69 + unsigned char reserved1[3]; 70 + unsigned int match_reg[8]; 71 + }; 72 + 73 + struct microcode_amd { 74 + struct microcode_header_amd hdr; 75 + unsigned int mpb[0]; 76 + }; 77 + 78 + #define UCODE_MAX_SIZE (2048) 79 + #define DEFAULT_UCODE_DATASIZE (896) 80 + #define MC_HEADER_SIZE (sizeof(struct microcode_header_amd)) 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 + 88 + /* serialize access to the physical write */ 89 + static DEFINE_SPINLOCK(microcode_update_lock); 90 + 91 + static struct equiv_cpu_entry *equiv_cpu_table; 92 + 93 + static int collect_cpu_info_amd(int cpu, struct cpu_signature *csig) 94 + { 95 + struct cpuinfo_x86 *c = &cpu_data(cpu); 96 + 97 + memset(csig, 0, sizeof(*csig)); 98 + 99 + if (c->x86_vendor != X86_VENDOR_AMD || c->x86 < 0x10) { 100 + printk(KERN_ERR "microcode: CPU%d not a capable AMD processor\n", 101 + cpu); 102 + return -1; 103 + } 104 + 105 + asm volatile("movl %1, %%ecx; rdmsr" 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; 113 + } 114 + 115 + static int get_matching_microcode(int cpu, void *mc, int rev) 116 + { 117 + struct microcode_header_amd *mc_header = mc; 118 + struct pci_dev *nb_pci_dev, *sb_pci_dev; 119 + unsigned int current_cpu_id; 120 + unsigned int equiv_cpu_id = 0x00; 121 + unsigned int i = 0; 122 + 123 + BUG_ON(equiv_cpu_table == NULL); 124 + current_cpu_id = cpuid_eax(0x00000001); 125 + 126 + while (equiv_cpu_table[i].installed_cpu != 0) { 127 + if (current_cpu_id == equiv_cpu_table[i].installed_cpu) { 128 + equiv_cpu_id = equiv_cpu_table[i].equiv_cpu; 129 + break; 130 + } 131 + i++; 132 + } 133 + 134 + if (!equiv_cpu_id) { 135 + printk(KERN_ERR "microcode: CPU%d cpu_id " 136 + "not found in equivalent cpu table \n", cpu); 137 + return 0; 138 + } 139 + 140 + if ((mc_header->processor_rev_id[0]) != (equiv_cpu_id & 0xff)) { 141 + printk(KERN_ERR 142 + "microcode: CPU%d patch does not match " 143 + "(patch is %x, cpu extended is %x) \n", 144 + cpu, mc_header->processor_rev_id[0], 145 + (equiv_cpu_id & 0xff)); 146 + return 0; 147 + } 148 + 149 + if ((mc_header->processor_rev_id[1]) != ((equiv_cpu_id >> 16) & 0xff)) { 150 + printk(KERN_ERR "microcode: CPU%d patch does not match " 151 + "(patch is %x, cpu base id is %x) \n", 152 + cpu, mc_header->processor_rev_id[1], 153 + ((equiv_cpu_id >> 16) & 0xff)); 154 + 155 + return 0; 156 + } 157 + 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) 187 + return 0; 188 + 189 + return 1; 190 + } 191 + 192 + static void apply_microcode_amd(int cpu) 193 + { 194 + unsigned long flags; 195 + unsigned int eax, edx; 196 + unsigned int rev; 197 + int cpu_num = raw_smp_processor_id(); 198 + struct ucode_cpu_info *uci = ucode_cpu_info + cpu_num; 199 + struct microcode_amd *mc_amd = uci->mc; 200 + unsigned long addr; 201 + 202 + /* We should bind the task to the CPU */ 203 + BUG_ON(cpu_num != cpu); 204 + 205 + if (mc_amd == NULL) 206 + return; 207 + 208 + spin_lock_irqsave(&microcode_update_lock, flags); 209 + 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 */ 218 + asm volatile("movl %1, %%ecx; rdmsr" 219 + : "=a" (rev) 220 + : "i" (0x0000008B) : "ecx"); 221 + 222 + spin_unlock_irqrestore(&microcode_update_lock, flags); 223 + 224 + /* check current patch id and patch's id for match */ 225 + if (rev != mc_amd->hdr.patch_id) { 226 + printk(KERN_ERR "microcode: CPU%d update from revision " 227 + "0x%x to 0x%x failed\n", cpu_num, 228 + mc_amd->hdr.patch_id, rev); 229 + return; 230 + } 231 + 232 + printk(KERN_INFO "microcode: CPU%d updated from revision " 233 + "0x%x to 0x%x \n", 234 + cpu_num, uci->cpu_sig.rev, mc_amd->hdr.patch_id); 235 + 236 + uci->cpu_sig.rev = rev; 237 + } 238 + 239 + static void * get_next_ucode(u8 *buf, unsigned int size, 240 + int (*get_ucode_data)(void *, const void *, size_t), 241 + unsigned int *mc_size) 242 + { 243 + unsigned int total_size; 244 + #define UCODE_CONTAINER_SECTION_HDR 8 245 + u8 section_hdr[UCODE_CONTAINER_SECTION_HDR]; 246 + void *mc; 247 + 248 + if (get_ucode_data(section_hdr, buf, UCODE_CONTAINER_SECTION_HDR)) 249 + return NULL; 250 + 251 + if (section_hdr[0] != UCODE_UCODE_TYPE) { 252 + printk(KERN_ERR "microcode: error! " 253 + "Wrong microcode payload type field\n"); 254 + return NULL; 255 + } 256 + 257 + total_size = (unsigned long) (section_hdr[4] + (section_hdr[5] << 8)); 258 + 259 + printk(KERN_INFO "microcode: size %u, total_size %u\n", 260 + size, total_size); 261 + 262 + if (total_size > size || total_size > UCODE_MAX_SIZE) { 263 + printk(KERN_ERR "microcode: error! Bad data in microcode data file\n"); 264 + return NULL; 265 + } 266 + 267 + mc = vmalloc(UCODE_MAX_SIZE); 268 + if (mc) { 269 + memset(mc, 0, UCODE_MAX_SIZE); 270 + if (get_ucode_data(mc, buf + UCODE_CONTAINER_SECTION_HDR, total_size)) { 271 + vfree(mc); 272 + mc = NULL; 273 + } else 274 + *mc_size = total_size + UCODE_CONTAINER_SECTION_HDR; 275 + } 276 + #undef UCODE_CONTAINER_SECTION_HDR 277 + return mc; 278 + } 279 + 280 + 281 + static int install_equiv_cpu_table(u8 *buf, 282 + int (*get_ucode_data)(void *, const void *, size_t)) 283 + { 284 + #define UCODE_CONTAINER_HEADER_SIZE 12 285 + u8 *container_hdr[UCODE_CONTAINER_HEADER_SIZE]; 286 + unsigned int *buf_pos = (unsigned int *)container_hdr; 287 + unsigned long size; 288 + 289 + if (get_ucode_data(&container_hdr, buf, UCODE_CONTAINER_HEADER_SIZE)) 290 + return 0; 291 + 292 + size = buf_pos[2]; 293 + 294 + if (buf_pos[1] != UCODE_EQUIV_CPU_TABLE_TYPE || !size) { 295 + printk(KERN_ERR "microcode: error! " 296 + "Wrong microcode equivalnet cpu table\n"); 297 + return 0; 298 + } 299 + 300 + equiv_cpu_table = (struct equiv_cpu_entry *) vmalloc(size); 301 + if (!equiv_cpu_table) { 302 + printk(KERN_ERR "microcode: error, can't allocate memory for equiv CPU table\n"); 303 + return 0; 304 + } 305 + 306 + buf += UCODE_CONTAINER_HEADER_SIZE; 307 + if (get_ucode_data(equiv_cpu_table, buf, size)) { 308 + vfree(equiv_cpu_table); 309 + return 0; 310 + } 311 + 312 + return size + UCODE_CONTAINER_HEADER_SIZE; /* add header length */ 313 + #undef UCODE_CONTAINER_HEADER_SIZE 314 + } 315 + 316 + static void free_equiv_cpu_table(void) 317 + { 318 + if (equiv_cpu_table) { 319 + vfree(equiv_cpu_table); 320 + equiv_cpu_table = NULL; 321 + } 322 + } 323 + 324 + static int generic_load_microcode(int cpu, void *data, size_t size, 325 + int (*get_ucode_data)(void *, const void *, size_t)) 326 + { 327 + struct ucode_cpu_info *uci = ucode_cpu_info + cpu; 328 + u8 *ucode_ptr = data, *new_mc = NULL, *mc; 329 + int new_rev = uci->cpu_sig.rev; 330 + unsigned int leftover; 331 + unsigned long offset; 332 + 333 + offset = install_equiv_cpu_table(ucode_ptr, get_ucode_data); 334 + if (!offset) { 335 + printk(KERN_ERR "microcode: installing equivalent cpu table failed\n"); 336 + return -EINVAL; 337 + } 338 + 339 + ucode_ptr += offset; 340 + leftover = size - offset; 341 + 342 + while (leftover) { 343 + unsigned int uninitialized_var(mc_size); 344 + struct microcode_header_amd *mc_header; 345 + 346 + mc = get_next_ucode(ucode_ptr, leftover, get_ucode_data, &mc_size); 347 + if (!mc) 348 + break; 349 + 350 + mc_header = (struct microcode_header_amd *)mc; 351 + if (get_matching_microcode(cpu, mc, new_rev)) { 352 + if (new_mc) 353 + vfree(new_mc); 354 + new_rev = mc_header->patch_id; 355 + new_mc = mc; 356 + } else 357 + vfree(mc); 358 + 359 + ucode_ptr += mc_size; 360 + leftover -= mc_size; 361 + } 362 + 363 + if (new_mc) { 364 + if (!leftover) { 365 + if (uci->mc) 366 + vfree(uci->mc); 367 + uci->mc = new_mc; 368 + pr_debug("microcode: CPU%d found a matching microcode update with" 369 + " version 0x%x (current=0x%x)\n", 370 + cpu, new_rev, uci->cpu_sig.rev); 371 + } else 372 + vfree(new_mc); 373 + } 374 + 375 + free_equiv_cpu_table(); 376 + 377 + return (int)leftover; 378 + } 379 + 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) 387 + { 388 + const char *fw_name = "amd-ucode/microcode_amd.bin"; 389 + const struct firmware *firmware; 390 + int ret; 391 + 392 + /* We should bind the task to the CPU */ 393 + BUG_ON(cpu != raw_smp_processor_id()); 394 + 395 + ret = request_firmware(&firmware, fw_name, device); 396 + if (ret) { 397 + printk(KERN_ERR "microcode: ucode data file %s load failed\n", fw_name); 398 + return ret; 399 + } 400 + 401 + ret = generic_load_microcode(cpu, (void*)firmware->data, firmware->size, 402 + &get_ucode_fw); 403 + 404 + release_firmware(firmware); 405 + 406 + return ret; 407 + } 408 + 409 + static int request_microcode_user(int cpu, const void __user *buf, size_t size) 410 + { 411 + printk(KERN_WARNING "microcode: AMD microcode update via /dev/cpu/microcode" 412 + "is not supported\n"); 413 + return -1; 414 + } 415 + 416 + static void microcode_fini_cpu_amd(int cpu) 417 + { 418 + struct ucode_cpu_info *uci = ucode_cpu_info + cpu; 419 + 420 + vfree(uci->mc); 421 + uci->mc = NULL; 422 + } 423 + 424 + static struct microcode_ops microcode_amd_ops = { 425 + .request_microcode_user = request_microcode_user, 426 + .request_microcode_fw = request_microcode_fw, 427 + .collect_cpu_info = collect_cpu_info_amd, 428 + .apply_microcode = apply_microcode_amd, 429 + .microcode_fini_cpu = microcode_fini_cpu_amd, 430 + }; 431 + 432 + struct microcode_ops * __init init_amd_microcode(void) 433 + { 434 + return &microcode_amd_ops; 435 + }
+508
arch/x86/kernel/microcode_core.c
··· 1 + /* 2 + * Intel CPU Microcode Update Driver for Linux 3 + * 4 + * Copyright (C) 2000-2006 Tigran Aivazian <tigran@aivazian.fsnet.co.uk> 5 + * 2006 Shaohua Li <shaohua.li@intel.com> 6 + * 7 + * This driver allows to upgrade microcode on Intel processors 8 + * belonging to IA-32 family - PentiumPro, Pentium II, 9 + * Pentium III, Xeon, Pentium 4, etc. 10 + * 11 + * Reference: Section 8.11 of Volume 3a, IA-32 Intel? Architecture 12 + * Software Developer's Manual 13 + * Order Number 253668 or free download from: 14 + * 15 + * http://developer.intel.com/design/pentium4/manuals/253668.htm 16 + * 17 + * For more information, go to http://www.urbanmyth.org/microcode 18 + * 19 + * This program is free software; you can redistribute it and/or 20 + * modify it under the terms of the GNU General Public License 21 + * as published by the Free Software Foundation; either version 22 + * 2 of the License, or (at your option) any later version. 23 + * 24 + * 1.0 16 Feb 2000, Tigran Aivazian <tigran@sco.com> 25 + * Initial release. 26 + * 1.01 18 Feb 2000, Tigran Aivazian <tigran@sco.com> 27 + * Added read() support + cleanups. 28 + * 1.02 21 Feb 2000, Tigran Aivazian <tigran@sco.com> 29 + * Added 'device trimming' support. open(O_WRONLY) zeroes 30 + * and frees the saved copy of applied microcode. 31 + * 1.03 29 Feb 2000, Tigran Aivazian <tigran@sco.com> 32 + * Made to use devfs (/dev/cpu/microcode) + cleanups. 33 + * 1.04 06 Jun 2000, Simon Trimmer <simon@veritas.com> 34 + * Added misc device support (now uses both devfs and misc). 35 + * Added MICROCODE_IOCFREE ioctl to clear memory. 36 + * 1.05 09 Jun 2000, Simon Trimmer <simon@veritas.com> 37 + * Messages for error cases (non Intel & no suitable microcode). 38 + * 1.06 03 Aug 2000, Tigran Aivazian <tigran@veritas.com> 39 + * Removed ->release(). Removed exclusive open and status bitmap. 40 + * Added microcode_rwsem to serialize read()/write()/ioctl(). 41 + * Removed global kernel lock usage. 42 + * 1.07 07 Sep 2000, Tigran Aivazian <tigran@veritas.com> 43 + * Write 0 to 0x8B msr and then cpuid before reading revision, 44 + * so that it works even if there were no update done by the 45 + * BIOS. Otherwise, reading from 0x8B gives junk (which happened 46 + * to be 0 on my machine which is why it worked even when I 47 + * disabled update by the BIOS) 48 + * Thanks to Eric W. Biederman <ebiederman@lnxi.com> for the fix. 49 + * 1.08 11 Dec 2000, Richard Schaal <richard.schaal@intel.com> and 50 + * Tigran Aivazian <tigran@veritas.com> 51 + * Intel Pentium 4 processor support and bugfixes. 52 + * 1.09 30 Oct 2001, Tigran Aivazian <tigran@veritas.com> 53 + * Bugfix for HT (Hyper-Threading) enabled processors 54 + * whereby processor resources are shared by all logical processors 55 + * in a single CPU package. 56 + * 1.10 28 Feb 2002 Asit K Mallick <asit.k.mallick@intel.com> and 57 + * Tigran Aivazian <tigran@veritas.com>, 58 + * Serialize updates as required on HT processors due to 59 + * speculative nature of implementation. 60 + * 1.11 22 Mar 2002 Tigran Aivazian <tigran@veritas.com> 61 + * Fix the panic when writing zero-length microcode chunk. 62 + * 1.12 29 Sep 2003 Nitin Kamble <nitin.a.kamble@intel.com>, 63 + * Jun Nakajima <jun.nakajima@intel.com> 64 + * Support for the microcode updates in the new format. 65 + * 1.13 10 Oct 2003 Tigran Aivazian <tigran@veritas.com> 66 + * Removed ->read() method and obsoleted MICROCODE_IOCFREE ioctl 67 + * because we no longer hold a copy of applied microcode 68 + * in kernel memory. 69 + * 1.14 25 Jun 2004 Tigran Aivazian <tigran@veritas.com> 70 + * Fix sigmatch() macro to handle old CPUs with pf == 0. 71 + * Thanks to Stuart Swales for pointing out this bug. 72 + */ 73 + #include <linux/capability.h> 74 + #include <linux/kernel.h> 75 + #include <linux/init.h> 76 + #include <linux/sched.h> 77 + #include <linux/smp_lock.h> 78 + #include <linux/cpumask.h> 79 + #include <linux/module.h> 80 + #include <linux/slab.h> 81 + #include <linux/vmalloc.h> 82 + #include <linux/miscdevice.h> 83 + #include <linux/spinlock.h> 84 + #include <linux/mm.h> 85 + #include <linux/fs.h> 86 + #include <linux/mutex.h> 87 + #include <linux/cpu.h> 88 + #include <linux/firmware.h> 89 + #include <linux/platform_device.h> 90 + 91 + #include <asm/msr.h> 92 + #include <asm/uaccess.h> 93 + #include <asm/processor.h> 94 + #include <asm/microcode.h> 95 + 96 + MODULE_DESCRIPTION("Microcode Update Driver"); 97 + MODULE_AUTHOR("Tigran Aivazian <tigran@aivazian.fsnet.co.uk>"); 98 + MODULE_LICENSE("GPL"); 99 + 100 + #define MICROCODE_VERSION "2.00" 101 + 102 + struct microcode_ops *microcode_ops; 103 + 104 + /* no concurrent ->write()s are allowed on /dev/cpu/microcode */ 105 + static DEFINE_MUTEX(microcode_mutex); 106 + 107 + struct ucode_cpu_info ucode_cpu_info[NR_CPUS]; 108 + EXPORT_SYMBOL_GPL(ucode_cpu_info); 109 + 110 + #ifdef CONFIG_MICROCODE_OLD_INTERFACE 111 + static int do_microcode_update(const void __user *buf, size_t size) 112 + { 113 + cpumask_t old; 114 + int error = 0; 115 + int cpu; 116 + 117 + old = current->cpus_allowed; 118 + 119 + for_each_online_cpu(cpu) { 120 + struct ucode_cpu_info *uci = ucode_cpu_info + cpu; 121 + 122 + if (!uci->valid) 123 + continue; 124 + 125 + set_cpus_allowed_ptr(current, &cpumask_of_cpu(cpu)); 126 + error = microcode_ops->request_microcode_user(cpu, buf, size); 127 + if (error < 0) 128 + goto out; 129 + if (!error) 130 + microcode_ops->apply_microcode(cpu); 131 + } 132 + out: 133 + set_cpus_allowed_ptr(current, &old); 134 + return error; 135 + } 136 + 137 + static int microcode_open(struct inode *unused1, struct file *unused2) 138 + { 139 + cycle_kernel_lock(); 140 + return capable(CAP_SYS_RAWIO) ? 0 : -EPERM; 141 + } 142 + 143 + static ssize_t microcode_write(struct file *file, const char __user *buf, 144 + size_t len, loff_t *ppos) 145 + { 146 + ssize_t ret; 147 + 148 + if ((len >> PAGE_SHIFT) > num_physpages) { 149 + printk(KERN_ERR "microcode: too much data (max %ld pages)\n", 150 + num_physpages); 151 + return -EINVAL; 152 + } 153 + 154 + get_online_cpus(); 155 + mutex_lock(&microcode_mutex); 156 + 157 + ret = do_microcode_update(buf, len); 158 + if (!ret) 159 + ret = (ssize_t)len; 160 + 161 + mutex_unlock(&microcode_mutex); 162 + put_online_cpus(); 163 + 164 + return ret; 165 + } 166 + 167 + static const struct file_operations microcode_fops = { 168 + .owner = THIS_MODULE, 169 + .write = microcode_write, 170 + .open = microcode_open, 171 + }; 172 + 173 + static struct miscdevice microcode_dev = { 174 + .minor = MICROCODE_MINOR, 175 + .name = "microcode", 176 + .fops = &microcode_fops, 177 + }; 178 + 179 + static int __init microcode_dev_init(void) 180 + { 181 + int error; 182 + 183 + error = misc_register(&microcode_dev); 184 + if (error) { 185 + printk(KERN_ERR 186 + "microcode: can't misc_register on minor=%d\n", 187 + MICROCODE_MINOR); 188 + return error; 189 + } 190 + 191 + return 0; 192 + } 193 + 194 + static void microcode_dev_exit(void) 195 + { 196 + misc_deregister(&microcode_dev); 197 + } 198 + 199 + MODULE_ALIAS_MISCDEV(MICROCODE_MINOR); 200 + #else 201 + #define microcode_dev_init() 0 202 + #define microcode_dev_exit() do { } while (0) 203 + #endif 204 + 205 + /* fake device for request_firmware */ 206 + struct platform_device *microcode_pdev; 207 + 208 + static ssize_t reload_store(struct sys_device *dev, 209 + struct sysdev_attribute *attr, 210 + const char *buf, size_t sz) 211 + { 212 + struct ucode_cpu_info *uci = ucode_cpu_info + dev->id; 213 + char *end; 214 + unsigned long val = simple_strtoul(buf, &end, 0); 215 + int err = 0; 216 + int cpu = dev->id; 217 + 218 + if (end == buf) 219 + return -EINVAL; 220 + if (val == 1) { 221 + cpumask_t old = current->cpus_allowed; 222 + 223 + get_online_cpus(); 224 + if (cpu_online(cpu)) { 225 + set_cpus_allowed_ptr(current, &cpumask_of_cpu(cpu)); 226 + mutex_lock(&microcode_mutex); 227 + if (uci->valid) { 228 + err = microcode_ops->request_microcode_fw(cpu, 229 + &microcode_pdev->dev); 230 + if (!err) 231 + microcode_ops->apply_microcode(cpu); 232 + } 233 + mutex_unlock(&microcode_mutex); 234 + set_cpus_allowed_ptr(current, &old); 235 + } 236 + put_online_cpus(); 237 + } 238 + if (err) 239 + return err; 240 + return sz; 241 + } 242 + 243 + static ssize_t version_show(struct sys_device *dev, 244 + struct sysdev_attribute *attr, char *buf) 245 + { 246 + struct ucode_cpu_info *uci = ucode_cpu_info + dev->id; 247 + 248 + return sprintf(buf, "0x%x\n", uci->cpu_sig.rev); 249 + } 250 + 251 + static ssize_t pf_show(struct sys_device *dev, 252 + struct sysdev_attribute *attr, char *buf) 253 + { 254 + struct ucode_cpu_info *uci = ucode_cpu_info + dev->id; 255 + 256 + return sprintf(buf, "0x%x\n", uci->cpu_sig.pf); 257 + } 258 + 259 + static SYSDEV_ATTR(reload, 0200, NULL, reload_store); 260 + static SYSDEV_ATTR(version, 0400, version_show, NULL); 261 + static SYSDEV_ATTR(processor_flags, 0400, pf_show, NULL); 262 + 263 + static struct attribute *mc_default_attrs[] = { 264 + &attr_reload.attr, 265 + &attr_version.attr, 266 + &attr_processor_flags.attr, 267 + NULL 268 + }; 269 + 270 + static struct attribute_group mc_attr_group = { 271 + .attrs = mc_default_attrs, 272 + .name = "microcode", 273 + }; 274 + 275 + static void microcode_fini_cpu(int cpu) 276 + { 277 + struct ucode_cpu_info *uci = ucode_cpu_info + cpu; 278 + 279 + mutex_lock(&microcode_mutex); 280 + microcode_ops->microcode_fini_cpu(cpu); 281 + uci->valid = 0; 282 + mutex_unlock(&microcode_mutex); 283 + } 284 + 285 + static void collect_cpu_info(int cpu) 286 + { 287 + struct ucode_cpu_info *uci = ucode_cpu_info + cpu; 288 + 289 + memset(uci, 0, sizeof(*uci)); 290 + if (!microcode_ops->collect_cpu_info(cpu, &uci->cpu_sig)) 291 + uci->valid = 1; 292 + } 293 + 294 + static int microcode_resume_cpu(int cpu) 295 + { 296 + struct ucode_cpu_info *uci = ucode_cpu_info + cpu; 297 + struct cpu_signature nsig; 298 + 299 + pr_debug("microcode: CPU%d resumed\n", cpu); 300 + 301 + if (!uci->mc) 302 + return 1; 303 + 304 + /* 305 + * Let's verify that the 'cached' ucode does belong 306 + * to this cpu (a bit of paranoia): 307 + */ 308 + if (microcode_ops->collect_cpu_info(cpu, &nsig)) { 309 + microcode_fini_cpu(cpu); 310 + return -1; 311 + } 312 + 313 + if (memcmp(&nsig, &uci->cpu_sig, sizeof(nsig))) { 314 + microcode_fini_cpu(cpu); 315 + /* Should we look for a new ucode here? */ 316 + return 1; 317 + } 318 + 319 + return 0; 320 + } 321 + 322 + void microcode_update_cpu(int cpu) 323 + { 324 + struct ucode_cpu_info *uci = ucode_cpu_info + cpu; 325 + int err = 0; 326 + 327 + /* 328 + * Check if the system resume is in progress (uci->valid != NULL), 329 + * otherwise just request a firmware: 330 + */ 331 + if (uci->valid) { 332 + err = microcode_resume_cpu(cpu); 333 + } else { 334 + collect_cpu_info(cpu); 335 + if (uci->valid && system_state == SYSTEM_RUNNING) 336 + err = microcode_ops->request_microcode_fw(cpu, 337 + &microcode_pdev->dev); 338 + } 339 + if (!err) 340 + microcode_ops->apply_microcode(cpu); 341 + } 342 + 343 + static void microcode_init_cpu(int cpu) 344 + { 345 + cpumask_t old = current->cpus_allowed; 346 + 347 + set_cpus_allowed_ptr(current, &cpumask_of_cpu(cpu)); 348 + /* We should bind the task to the CPU */ 349 + BUG_ON(raw_smp_processor_id() != cpu); 350 + 351 + mutex_lock(&microcode_mutex); 352 + microcode_update_cpu(cpu); 353 + mutex_unlock(&microcode_mutex); 354 + 355 + set_cpus_allowed_ptr(current, &old); 356 + } 357 + 358 + static int mc_sysdev_add(struct sys_device *sys_dev) 359 + { 360 + int err, cpu = sys_dev->id; 361 + struct ucode_cpu_info *uci = ucode_cpu_info + cpu; 362 + 363 + if (!cpu_online(cpu)) 364 + return 0; 365 + 366 + pr_debug("microcode: CPU%d added\n", cpu); 367 + memset(uci, 0, sizeof(*uci)); 368 + 369 + err = sysfs_create_group(&sys_dev->kobj, &mc_attr_group); 370 + if (err) 371 + return err; 372 + 373 + microcode_init_cpu(cpu); 374 + return 0; 375 + } 376 + 377 + static int mc_sysdev_remove(struct sys_device *sys_dev) 378 + { 379 + int cpu = sys_dev->id; 380 + 381 + if (!cpu_online(cpu)) 382 + return 0; 383 + 384 + pr_debug("microcode: CPU%d removed\n", cpu); 385 + microcode_fini_cpu(cpu); 386 + sysfs_remove_group(&sys_dev->kobj, &mc_attr_group); 387 + return 0; 388 + } 389 + 390 + static int mc_sysdev_resume(struct sys_device *dev) 391 + { 392 + int cpu = dev->id; 393 + 394 + if (!cpu_online(cpu)) 395 + return 0; 396 + 397 + /* only CPU 0 will apply ucode here */ 398 + microcode_update_cpu(0); 399 + return 0; 400 + } 401 + 402 + static struct sysdev_driver mc_sysdev_driver = { 403 + .add = mc_sysdev_add, 404 + .remove = mc_sysdev_remove, 405 + .resume = mc_sysdev_resume, 406 + }; 407 + 408 + static __cpuinit int 409 + mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu) 410 + { 411 + unsigned int cpu = (unsigned long)hcpu; 412 + struct sys_device *sys_dev; 413 + 414 + sys_dev = get_cpu_sysdev(cpu); 415 + switch (action) { 416 + case CPU_ONLINE: 417 + case CPU_ONLINE_FROZEN: 418 + microcode_init_cpu(cpu); 419 + case CPU_DOWN_FAILED: 420 + case CPU_DOWN_FAILED_FROZEN: 421 + pr_debug("microcode: CPU%d added\n", cpu); 422 + if (sysfs_create_group(&sys_dev->kobj, &mc_attr_group)) 423 + printk(KERN_ERR "microcode: Failed to create the sysfs " 424 + "group for CPU%d\n", cpu); 425 + break; 426 + case CPU_DOWN_PREPARE: 427 + case CPU_DOWN_PREPARE_FROZEN: 428 + /* Suspend is in progress, only remove the interface */ 429 + sysfs_remove_group(&sys_dev->kobj, &mc_attr_group); 430 + pr_debug("microcode: CPU%d removed\n", cpu); 431 + break; 432 + case CPU_DEAD: 433 + case CPU_UP_CANCELED_FROZEN: 434 + /* The CPU refused to come up during a system resume */ 435 + microcode_fini_cpu(cpu); 436 + break; 437 + } 438 + return NOTIFY_OK; 439 + } 440 + 441 + static struct notifier_block __refdata mc_cpu_notifier = { 442 + .notifier_call = mc_cpu_callback, 443 + }; 444 + 445 + static int __init microcode_init(void) 446 + { 447 + struct cpuinfo_x86 *c = &cpu_data(0); 448 + int error; 449 + 450 + if (c->x86_vendor == X86_VENDOR_INTEL) 451 + microcode_ops = init_intel_microcode(); 452 + else if (c->x86_vendor == X86_VENDOR_AMD) 453 + microcode_ops = init_amd_microcode(); 454 + 455 + if (!microcode_ops) { 456 + printk(KERN_ERR "microcode: no support for this CPU vendor\n"); 457 + return -ENODEV; 458 + } 459 + 460 + error = microcode_dev_init(); 461 + if (error) 462 + return error; 463 + microcode_pdev = platform_device_register_simple("microcode", -1, 464 + NULL, 0); 465 + if (IS_ERR(microcode_pdev)) { 466 + microcode_dev_exit(); 467 + return PTR_ERR(microcode_pdev); 468 + } 469 + 470 + get_online_cpus(); 471 + error = sysdev_driver_register(&cpu_sysdev_class, &mc_sysdev_driver); 472 + put_online_cpus(); 473 + if (error) { 474 + microcode_dev_exit(); 475 + platform_device_unregister(microcode_pdev); 476 + return error; 477 + } 478 + 479 + register_hotcpu_notifier(&mc_cpu_notifier); 480 + 481 + printk(KERN_INFO 482 + "Microcode Update Driver: v" MICROCODE_VERSION 483 + " <tigran@aivazian.fsnet.co.uk>" 484 + " <peter.oruba@amd.com>\n"); 485 + 486 + return 0; 487 + } 488 + 489 + static void __exit microcode_exit(void) 490 + { 491 + microcode_dev_exit(); 492 + 493 + unregister_hotcpu_notifier(&mc_cpu_notifier); 494 + 495 + get_online_cpus(); 496 + sysdev_driver_unregister(&cpu_sysdev_class, &mc_sysdev_driver); 497 + put_online_cpus(); 498 + 499 + platform_device_unregister(microcode_pdev); 500 + 501 + microcode_ops = NULL; 502 + 503 + printk(KERN_INFO 504 + "Microcode Update Driver: v" MICROCODE_VERSION " removed.\n"); 505 + } 506 + 507 + module_init(microcode_init); 508 + module_exit(microcode_exit);
+480
arch/x86/kernel/microcode_intel.c
··· 1 + /* 2 + * Intel CPU Microcode Update Driver for Linux 3 + * 4 + * Copyright (C) 2000-2006 Tigran Aivazian <tigran@aivazian.fsnet.co.uk> 5 + * 2006 Shaohua Li <shaohua.li@intel.com> 6 + * 7 + * This driver allows to upgrade microcode on Intel processors 8 + * belonging to IA-32 family - PentiumPro, Pentium II, 9 + * Pentium III, Xeon, Pentium 4, etc. 10 + * 11 + * Reference: Section 8.11 of Volume 3a, IA-32 Intel? Architecture 12 + * Software Developer's Manual 13 + * Order Number 253668 or free download from: 14 + * 15 + * http://developer.intel.com/design/pentium4/manuals/253668.htm 16 + * 17 + * For more information, go to http://www.urbanmyth.org/microcode 18 + * 19 + * This program is free software; you can redistribute it and/or 20 + * modify it under the terms of the GNU General Public License 21 + * as published by the Free Software Foundation; either version 22 + * 2 of the License, or (at your option) any later version. 23 + * 24 + * 1.0 16 Feb 2000, Tigran Aivazian <tigran@sco.com> 25 + * Initial release. 26 + * 1.01 18 Feb 2000, Tigran Aivazian <tigran@sco.com> 27 + * Added read() support + cleanups. 28 + * 1.02 21 Feb 2000, Tigran Aivazian <tigran@sco.com> 29 + * Added 'device trimming' support. open(O_WRONLY) zeroes 30 + * and frees the saved copy of applied microcode. 31 + * 1.03 29 Feb 2000, Tigran Aivazian <tigran@sco.com> 32 + * Made to use devfs (/dev/cpu/microcode) + cleanups. 33 + * 1.04 06 Jun 2000, Simon Trimmer <simon@veritas.com> 34 + * Added misc device support (now uses both devfs and misc). 35 + * Added MICROCODE_IOCFREE ioctl to clear memory. 36 + * 1.05 09 Jun 2000, Simon Trimmer <simon@veritas.com> 37 + * Messages for error cases (non Intel & no suitable microcode). 38 + * 1.06 03 Aug 2000, Tigran Aivazian <tigran@veritas.com> 39 + * Removed ->release(). Removed exclusive open and status bitmap. 40 + * Added microcode_rwsem to serialize read()/write()/ioctl(). 41 + * Removed global kernel lock usage. 42 + * 1.07 07 Sep 2000, Tigran Aivazian <tigran@veritas.com> 43 + * Write 0 to 0x8B msr and then cpuid before reading revision, 44 + * so that it works even if there were no update done by the 45 + * BIOS. Otherwise, reading from 0x8B gives junk (which happened 46 + * to be 0 on my machine which is why it worked even when I 47 + * disabled update by the BIOS) 48 + * Thanks to Eric W. Biederman <ebiederman@lnxi.com> for the fix. 49 + * 1.08 11 Dec 2000, Richard Schaal <richard.schaal@intel.com> and 50 + * Tigran Aivazian <tigran@veritas.com> 51 + * Intel Pentium 4 processor support and bugfixes. 52 + * 1.09 30 Oct 2001, Tigran Aivazian <tigran@veritas.com> 53 + * Bugfix for HT (Hyper-Threading) enabled processors 54 + * whereby processor resources are shared by all logical processors 55 + * in a single CPU package. 56 + * 1.10 28 Feb 2002 Asit K Mallick <asit.k.mallick@intel.com> and 57 + * Tigran Aivazian <tigran@veritas.com>, 58 + * Serialize updates as required on HT processors due to 59 + * speculative nature of implementation. 60 + * 1.11 22 Mar 2002 Tigran Aivazian <tigran@veritas.com> 61 + * Fix the panic when writing zero-length microcode chunk. 62 + * 1.12 29 Sep 2003 Nitin Kamble <nitin.a.kamble@intel.com>, 63 + * Jun Nakajima <jun.nakajima@intel.com> 64 + * Support for the microcode updates in the new format. 65 + * 1.13 10 Oct 2003 Tigran Aivazian <tigran@veritas.com> 66 + * Removed ->read() method and obsoleted MICROCODE_IOCFREE ioctl 67 + * because we no longer hold a copy of applied microcode 68 + * in kernel memory. 69 + * 1.14 25 Jun 2004 Tigran Aivazian <tigran@veritas.com> 70 + * Fix sigmatch() macro to handle old CPUs with pf == 0. 71 + * Thanks to Stuart Swales for pointing out this bug. 72 + */ 73 + #include <linux/capability.h> 74 + #include <linux/kernel.h> 75 + #include <linux/init.h> 76 + #include <linux/sched.h> 77 + #include <linux/smp_lock.h> 78 + #include <linux/cpumask.h> 79 + #include <linux/module.h> 80 + #include <linux/slab.h> 81 + #include <linux/vmalloc.h> 82 + #include <linux/miscdevice.h> 83 + #include <linux/spinlock.h> 84 + #include <linux/mm.h> 85 + #include <linux/fs.h> 86 + #include <linux/mutex.h> 87 + #include <linux/cpu.h> 88 + #include <linux/firmware.h> 89 + #include <linux/platform_device.h> 90 + 91 + #include <asm/msr.h> 92 + #include <asm/uaccess.h> 93 + #include <asm/processor.h> 94 + #include <asm/microcode.h> 95 + 96 + MODULE_DESCRIPTION("Microcode Update Driver"); 97 + MODULE_AUTHOR("Tigran Aivazian <tigran@aivazian.fsnet.co.uk>"); 98 + MODULE_LICENSE("GPL"); 99 + 100 + struct microcode_header_intel { 101 + unsigned int hdrver; 102 + unsigned int rev; 103 + unsigned int date; 104 + unsigned int sig; 105 + unsigned int cksum; 106 + unsigned int ldrver; 107 + unsigned int pf; 108 + unsigned int datasize; 109 + unsigned int totalsize; 110 + unsigned int reserved[3]; 111 + }; 112 + 113 + struct microcode_intel { 114 + struct microcode_header_intel hdr; 115 + unsigned int bits[0]; 116 + }; 117 + 118 + /* microcode format is extended from prescott processors */ 119 + struct extended_signature { 120 + unsigned int sig; 121 + unsigned int pf; 122 + unsigned int cksum; 123 + }; 124 + 125 + struct extended_sigtable { 126 + unsigned int count; 127 + unsigned int cksum; 128 + unsigned int reserved[3]; 129 + struct extended_signature sigs[0]; 130 + }; 131 + 132 + #define DEFAULT_UCODE_DATASIZE (2000) 133 + #define MC_HEADER_SIZE (sizeof(struct microcode_header_intel)) 134 + #define DEFAULT_UCODE_TOTALSIZE (DEFAULT_UCODE_DATASIZE + MC_HEADER_SIZE) 135 + #define EXT_HEADER_SIZE (sizeof(struct extended_sigtable)) 136 + #define EXT_SIGNATURE_SIZE (sizeof(struct extended_signature)) 137 + #define DWSIZE (sizeof(u32)) 138 + #define get_totalsize(mc) \ 139 + (((struct microcode_intel *)mc)->hdr.totalsize ? \ 140 + ((struct microcode_intel *)mc)->hdr.totalsize : \ 141 + DEFAULT_UCODE_TOTALSIZE) 142 + 143 + #define get_datasize(mc) \ 144 + (((struct microcode_intel *)mc)->hdr.datasize ? \ 145 + ((struct microcode_intel *)mc)->hdr.datasize : DEFAULT_UCODE_DATASIZE) 146 + 147 + #define sigmatch(s1, s2, p1, p2) \ 148 + (((s1) == (s2)) && (((p1) & (p2)) || (((p1) == 0) && ((p2) == 0)))) 149 + 150 + #define exttable_size(et) ((et)->count * EXT_SIGNATURE_SIZE + EXT_HEADER_SIZE) 151 + 152 + /* serialize access to the physical write to MSR 0x79 */ 153 + static DEFINE_SPINLOCK(microcode_update_lock); 154 + 155 + static int collect_cpu_info(int cpu_num, struct cpu_signature *csig) 156 + { 157 + struct cpuinfo_x86 *c = &cpu_data(cpu_num); 158 + unsigned int val[2]; 159 + 160 + memset(csig, 0, sizeof(*csig)); 161 + 162 + if (c->x86_vendor != X86_VENDOR_INTEL || c->x86 < 6 || 163 + cpu_has(c, X86_FEATURE_IA64)) { 164 + printk(KERN_ERR "microcode: CPU%d not a capable Intel " 165 + "processor\n", cpu_num); 166 + return -1; 167 + } 168 + 169 + csig->sig = cpuid_eax(0x00000001); 170 + 171 + if ((c->x86_model >= 5) || (c->x86 > 6)) { 172 + /* get processor flags from MSR 0x17 */ 173 + rdmsr(MSR_IA32_PLATFORM_ID, val[0], val[1]); 174 + csig->pf = 1 << ((val[1] >> 18) & 7); 175 + } 176 + 177 + wrmsr(MSR_IA32_UCODE_REV, 0, 0); 178 + /* see notes above for revision 1.07. Apparent chip bug */ 179 + sync_core(); 180 + /* get the current revision from MSR 0x8B */ 181 + rdmsr(MSR_IA32_UCODE_REV, val[0], csig->rev); 182 + pr_debug("microcode: collect_cpu_info : sig=0x%x, pf=0x%x, rev=0x%x\n", 183 + csig->sig, csig->pf, csig->rev); 184 + 185 + return 0; 186 + } 187 + 188 + static inline int update_match_cpu(struct cpu_signature *csig, int sig, int pf) 189 + { 190 + return (!sigmatch(sig, csig->sig, pf, csig->pf)) ? 0 : 1; 191 + } 192 + 193 + static inline int 194 + update_match_revision(struct microcode_header_intel *mc_header, int rev) 195 + { 196 + return (mc_header->rev <= rev) ? 0 : 1; 197 + } 198 + 199 + static int microcode_sanity_check(void *mc) 200 + { 201 + struct microcode_header_intel *mc_header = mc; 202 + struct extended_sigtable *ext_header = NULL; 203 + struct extended_signature *ext_sig; 204 + unsigned long total_size, data_size, ext_table_size; 205 + int sum, orig_sum, ext_sigcount = 0, i; 206 + 207 + total_size = get_totalsize(mc_header); 208 + data_size = get_datasize(mc_header); 209 + if (data_size + MC_HEADER_SIZE > total_size) { 210 + printk(KERN_ERR "microcode: error! " 211 + "Bad data size in microcode data file\n"); 212 + return -EINVAL; 213 + } 214 + 215 + if (mc_header->ldrver != 1 || mc_header->hdrver != 1) { 216 + printk(KERN_ERR "microcode: error! " 217 + "Unknown microcode update format\n"); 218 + return -EINVAL; 219 + } 220 + ext_table_size = total_size - (MC_HEADER_SIZE + data_size); 221 + if (ext_table_size) { 222 + if ((ext_table_size < EXT_HEADER_SIZE) 223 + || ((ext_table_size - EXT_HEADER_SIZE) % EXT_SIGNATURE_SIZE)) { 224 + printk(KERN_ERR "microcode: error! " 225 + "Small exttable size in microcode data file\n"); 226 + return -EINVAL; 227 + } 228 + ext_header = mc + MC_HEADER_SIZE + data_size; 229 + if (ext_table_size != exttable_size(ext_header)) { 230 + printk(KERN_ERR "microcode: error! " 231 + "Bad exttable size in microcode data file\n"); 232 + return -EFAULT; 233 + } 234 + ext_sigcount = ext_header->count; 235 + } 236 + 237 + /* check extended table checksum */ 238 + if (ext_table_size) { 239 + int ext_table_sum = 0; 240 + int *ext_tablep = (int *)ext_header; 241 + 242 + i = ext_table_size / DWSIZE; 243 + while (i--) 244 + ext_table_sum += ext_tablep[i]; 245 + if (ext_table_sum) { 246 + printk(KERN_WARNING "microcode: aborting, " 247 + "bad extended signature table checksum\n"); 248 + return -EINVAL; 249 + } 250 + } 251 + 252 + /* calculate the checksum */ 253 + orig_sum = 0; 254 + i = (MC_HEADER_SIZE + data_size) / DWSIZE; 255 + while (i--) 256 + orig_sum += ((int *)mc)[i]; 257 + if (orig_sum) { 258 + printk(KERN_ERR "microcode: aborting, bad checksum\n"); 259 + return -EINVAL; 260 + } 261 + if (!ext_table_size) 262 + return 0; 263 + /* check extended signature checksum */ 264 + for (i = 0; i < ext_sigcount; i++) { 265 + ext_sig = (void *)ext_header + EXT_HEADER_SIZE + 266 + EXT_SIGNATURE_SIZE * i; 267 + sum = orig_sum 268 + - (mc_header->sig + mc_header->pf + mc_header->cksum) 269 + + (ext_sig->sig + ext_sig->pf + ext_sig->cksum); 270 + if (sum) { 271 + printk(KERN_ERR "microcode: aborting, bad checksum\n"); 272 + return -EINVAL; 273 + } 274 + } 275 + return 0; 276 + } 277 + 278 + /* 279 + * return 0 - no update found 280 + * return 1 - found update 281 + */ 282 + static int 283 + get_matching_microcode(struct cpu_signature *cpu_sig, void *mc, int rev) 284 + { 285 + struct microcode_header_intel *mc_header = mc; 286 + struct extended_sigtable *ext_header; 287 + unsigned long total_size = get_totalsize(mc_header); 288 + int ext_sigcount, i; 289 + struct extended_signature *ext_sig; 290 + 291 + if (!update_match_revision(mc_header, rev)) 292 + return 0; 293 + 294 + if (update_match_cpu(cpu_sig, mc_header->sig, mc_header->pf)) 295 + return 1; 296 + 297 + /* Look for ext. headers: */ 298 + if (total_size <= get_datasize(mc_header) + MC_HEADER_SIZE) 299 + return 0; 300 + 301 + ext_header = mc + get_datasize(mc_header) + MC_HEADER_SIZE; 302 + ext_sigcount = ext_header->count; 303 + ext_sig = (void *)ext_header + EXT_HEADER_SIZE; 304 + 305 + for (i = 0; i < ext_sigcount; i++) { 306 + if (update_match_cpu(cpu_sig, ext_sig->sig, ext_sig->pf)) 307 + return 1; 308 + ext_sig++; 309 + } 310 + return 0; 311 + } 312 + 313 + static void apply_microcode(int cpu) 314 + { 315 + unsigned long flags; 316 + unsigned int val[2]; 317 + int cpu_num = raw_smp_processor_id(); 318 + struct ucode_cpu_info *uci = ucode_cpu_info + cpu; 319 + struct microcode_intel *mc_intel = uci->mc; 320 + 321 + /* We should bind the task to the CPU */ 322 + BUG_ON(cpu_num != cpu); 323 + 324 + if (mc_intel == NULL) 325 + return; 326 + 327 + /* serialize access to the physical write to MSR 0x79 */ 328 + spin_lock_irqsave(&microcode_update_lock, flags); 329 + 330 + /* write microcode via MSR 0x79 */ 331 + wrmsr(MSR_IA32_UCODE_WRITE, 332 + (unsigned long) mc_intel->bits, 333 + (unsigned long) mc_intel->bits >> 16 >> 16); 334 + wrmsr(MSR_IA32_UCODE_REV, 0, 0); 335 + 336 + /* see notes above for revision 1.07. Apparent chip bug */ 337 + sync_core(); 338 + 339 + /* get the current revision from MSR 0x8B */ 340 + rdmsr(MSR_IA32_UCODE_REV, val[0], val[1]); 341 + 342 + spin_unlock_irqrestore(&microcode_update_lock, flags); 343 + if (val[1] != mc_intel->hdr.rev) { 344 + printk(KERN_ERR "microcode: CPU%d update from revision " 345 + "0x%x to 0x%x failed\n", cpu_num, uci->cpu_sig.rev, val[1]); 346 + return; 347 + } 348 + printk(KERN_INFO "microcode: CPU%d updated from revision " 349 + "0x%x to 0x%x, date = %04x-%02x-%02x \n", 350 + cpu_num, uci->cpu_sig.rev, val[1], 351 + mc_intel->hdr.date & 0xffff, 352 + mc_intel->hdr.date >> 24, 353 + (mc_intel->hdr.date >> 16) & 0xff); 354 + uci->cpu_sig.rev = val[1]; 355 + } 356 + 357 + static int generic_load_microcode(int cpu, void *data, size_t size, 358 + int (*get_ucode_data)(void *, const void *, size_t)) 359 + { 360 + struct ucode_cpu_info *uci = ucode_cpu_info + cpu; 361 + u8 *ucode_ptr = data, *new_mc = NULL, *mc; 362 + int new_rev = uci->cpu_sig.rev; 363 + unsigned int leftover = size; 364 + 365 + while (leftover) { 366 + struct microcode_header_intel mc_header; 367 + unsigned int mc_size; 368 + 369 + if (get_ucode_data(&mc_header, ucode_ptr, sizeof(mc_header))) 370 + break; 371 + 372 + mc_size = get_totalsize(&mc_header); 373 + if (!mc_size || mc_size > leftover) { 374 + printk(KERN_ERR "microcode: error!" 375 + "Bad data in microcode data file\n"); 376 + break; 377 + } 378 + 379 + mc = vmalloc(mc_size); 380 + if (!mc) 381 + break; 382 + 383 + if (get_ucode_data(mc, ucode_ptr, mc_size) || 384 + microcode_sanity_check(mc) < 0) { 385 + vfree(mc); 386 + break; 387 + } 388 + 389 + if (get_matching_microcode(&uci->cpu_sig, mc, new_rev)) { 390 + if (new_mc) 391 + vfree(new_mc); 392 + new_rev = mc_header.rev; 393 + new_mc = mc; 394 + } else 395 + vfree(mc); 396 + 397 + ucode_ptr += mc_size; 398 + leftover -= mc_size; 399 + } 400 + 401 + if (new_mc) { 402 + if (!leftover) { 403 + if (uci->mc) 404 + vfree(uci->mc); 405 + uci->mc = (struct microcode_intel *)new_mc; 406 + pr_debug("microcode: CPU%d found a matching microcode update with" 407 + " version 0x%x (current=0x%x)\n", 408 + cpu, new_rev, uci->cpu_sig.rev); 409 + } else 410 + vfree(new_mc); 411 + } 412 + 413 + return (int)leftover; 414 + } 415 + 416 + static int get_ucode_fw(void *to, const void *from, size_t n) 417 + { 418 + memcpy(to, from, n); 419 + return 0; 420 + } 421 + 422 + static int request_microcode_fw(int cpu, struct device *device) 423 + { 424 + char name[30]; 425 + struct cpuinfo_x86 *c = &cpu_data(cpu); 426 + const struct firmware *firmware; 427 + int ret; 428 + 429 + /* We should bind the task to the CPU */ 430 + BUG_ON(cpu != raw_smp_processor_id()); 431 + sprintf(name, "intel-ucode/%02x-%02x-%02x", 432 + c->x86, c->x86_model, c->x86_mask); 433 + ret = request_firmware(&firmware, name, device); 434 + if (ret) { 435 + pr_debug("microcode: data file %s load failed\n", name); 436 + return ret; 437 + } 438 + 439 + ret = generic_load_microcode(cpu, (void*)firmware->data, firmware->size, 440 + &get_ucode_fw); 441 + 442 + release_firmware(firmware); 443 + 444 + return ret; 445 + } 446 + 447 + static int get_ucode_user(void *to, const void *from, size_t n) 448 + { 449 + return copy_from_user(to, from, n); 450 + } 451 + 452 + static int request_microcode_user(int cpu, const void __user *buf, size_t size) 453 + { 454 + /* We should bind the task to the CPU */ 455 + BUG_ON(cpu != raw_smp_processor_id()); 456 + 457 + return generic_load_microcode(cpu, (void*)buf, size, &get_ucode_user); 458 + } 459 + 460 + static void microcode_fini_cpu(int cpu) 461 + { 462 + struct ucode_cpu_info *uci = ucode_cpu_info + cpu; 463 + 464 + vfree(uci->mc); 465 + uci->mc = NULL; 466 + } 467 + 468 + struct microcode_ops microcode_intel_ops = { 469 + .request_microcode_user = request_microcode_user, 470 + .request_microcode_fw = request_microcode_fw, 471 + .collect_cpu_info = collect_cpu_info, 472 + .apply_microcode = apply_microcode, 473 + .microcode_fini_cpu = microcode_fini_cpu, 474 + }; 475 + 476 + struct microcode_ops * __init init_intel_microcode(void) 477 + { 478 + return &microcode_intel_ops; 479 + } 480 +
+37
arch/x86/kernel/paravirt-spinlocks.c
··· 1 + /* 2 + * Split spinlock implementation out into its own file, so it can be 3 + * compiled in a FTRACE-compatible way. 4 + */ 5 + #include <linux/spinlock.h> 6 + #include <linux/module.h> 7 + 8 + #include <asm/paravirt.h> 9 + 10 + static void default_spin_lock_flags(struct raw_spinlock *lock, unsigned long flags) 11 + { 12 + __raw_spin_lock(lock); 13 + } 14 + 15 + struct pv_lock_ops pv_lock_ops = { 16 + #ifdef CONFIG_SMP 17 + .spin_is_locked = __ticket_spin_is_locked, 18 + .spin_is_contended = __ticket_spin_is_contended, 19 + 20 + .spin_lock = __ticket_spin_lock, 21 + .spin_lock_flags = default_spin_lock_flags, 22 + .spin_trylock = __ticket_spin_trylock, 23 + .spin_unlock = __ticket_spin_unlock, 24 + #endif 25 + }; 26 + EXPORT_SYMBOL(pv_lock_ops); 27 + 28 + void __init paravirt_use_bytelocks(void) 29 + { 30 + #ifdef CONFIG_SMP 31 + pv_lock_ops.spin_is_locked = __byte_spin_is_locked; 32 + pv_lock_ops.spin_is_contended = __byte_spin_is_contended; 33 + pv_lock_ops.spin_lock = __byte_spin_lock; 34 + pv_lock_ops.spin_trylock = __byte_spin_trylock; 35 + pv_lock_ops.spin_unlock = __byte_spin_unlock; 36 + #endif 37 + }
+4 -23
arch/x86/kernel/paravirt.c
··· 268 268 return __get_cpu_var(paravirt_lazy_mode); 269 269 } 270 270 271 - void __init paravirt_use_bytelocks(void) 272 - { 273 - #ifdef CONFIG_SMP 274 - pv_lock_ops.spin_is_locked = __byte_spin_is_locked; 275 - pv_lock_ops.spin_is_contended = __byte_spin_is_contended; 276 - pv_lock_ops.spin_lock = __byte_spin_lock; 277 - pv_lock_ops.spin_trylock = __byte_spin_trylock; 278 - pv_lock_ops.spin_unlock = __byte_spin_unlock; 279 - #endif 280 - } 281 - 282 271 struct pv_info pv_info = { 283 272 .name = "bare hardware", 284 273 .paravirt_enabled = 0, ··· 338 349 .write_ldt_entry = native_write_ldt_entry, 339 350 .write_gdt_entry = native_write_gdt_entry, 340 351 .write_idt_entry = native_write_idt_entry, 352 + 353 + .alloc_ldt = paravirt_nop, 354 + .free_ldt = paravirt_nop, 355 + 341 356 .load_sp0 = native_load_sp0, 342 357 343 358 #if defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION) ··· 452 459 453 460 .set_fixmap = native_set_fixmap, 454 461 }; 455 - 456 - struct pv_lock_ops pv_lock_ops = { 457 - #ifdef CONFIG_SMP 458 - .spin_is_locked = __ticket_spin_is_locked, 459 - .spin_is_contended = __ticket_spin_is_contended, 460 - 461 - .spin_lock = __ticket_spin_lock, 462 - .spin_trylock = __ticket_spin_trylock, 463 - .spin_unlock = __ticket_spin_unlock, 464 - #endif 465 - }; 466 - EXPORT_SYMBOL(pv_lock_ops); 467 462 468 463 EXPORT_SYMBOL_GPL(pv_time_ops); 469 464 EXPORT_SYMBOL (pv_cpu_ops);
+2 -37
arch/x86/kernel/process_32.c
··· 76 76 return ((unsigned long *)tsk->thread.sp)[3]; 77 77 } 78 78 79 - #ifdef CONFIG_HOTPLUG_CPU 80 - #include <asm/nmi.h> 81 - 82 - static void cpu_exit_clear(void) 83 - { 84 - int cpu = raw_smp_processor_id(); 85 - 86 - idle_task_exit(); 87 - 88 - cpu_uninit(); 89 - irq_ctx_exit(cpu); 90 - 91 - cpu_clear(cpu, cpu_callout_map); 92 - cpu_clear(cpu, cpu_callin_map); 93 - 94 - numa_remove_cpu(cpu); 95 - c1e_remove_cpu(cpu); 96 - } 97 - 98 - /* We don't actually take CPU down, just spin without interrupts. */ 99 - static inline void play_dead(void) 100 - { 101 - /* This must be done before dead CPU ack */ 102 - cpu_exit_clear(); 103 - mb(); 104 - /* Ack it */ 105 - __get_cpu_var(cpu_state) = CPU_DEAD; 106 - 107 - /* 108 - * With physical CPU hotplug, we should halt the cpu 109 - */ 110 - local_irq_disable(); 111 - /* mask all interrupts, flush any and all caches, and halt */ 112 - wbinvd_halt(); 113 - } 114 - #else 79 + #ifndef CONFIG_SMP 115 80 static inline void play_dead(void) 116 81 { 117 82 BUG(); 118 83 } 119 - #endif /* CONFIG_HOTPLUG_CPU */ 84 + #endif 120 85 121 86 /* 122 87 * The idle thread. There's no useful work to be
+2 -20
arch/x86/kernel/process_64.c
··· 86 86 __exit_idle(); 87 87 } 88 88 89 - #ifdef CONFIG_HOTPLUG_CPU 90 - DECLARE_PER_CPU(int, cpu_state); 91 - 92 - #include <linux/nmi.h> 93 - /* We halt the CPU with physical CPU hotplug */ 94 - static inline void play_dead(void) 95 - { 96 - idle_task_exit(); 97 - c1e_remove_cpu(raw_smp_processor_id()); 98 - 99 - mb(); 100 - /* Ack it */ 101 - __get_cpu_var(cpu_state) = CPU_DEAD; 102 - 103 - local_irq_disable(); 104 - /* mask all interrupts, flush any and all caches, and halt */ 105 - wbinvd_halt(); 106 - } 107 - #else 89 + #ifndef CONFIG_SMP 108 90 static inline void play_dead(void) 109 91 { 110 92 BUG(); 111 93 } 112 - #endif /* CONFIG_HOTPLUG_CPU */ 94 + #endif 113 95 114 96 /* 115 97 * The idle thread. There's no useful work to be
+41 -3
arch/x86/kernel/ptrace.c
··· 40 40 REGSET_GENERAL, 41 41 REGSET_FP, 42 42 REGSET_XFP, 43 + REGSET_IOPERM64 = REGSET_XFP, 43 44 REGSET_TLS, 45 + REGSET_IOPERM32, 44 46 }; 45 47 46 48 /* ··· 555 553 } 556 554 557 555 return 0; 556 + } 557 + 558 + /* 559 + * These access the current or another (stopped) task's io permission 560 + * bitmap for debugging or core dump. 561 + */ 562 + static int ioperm_active(struct task_struct *target, 563 + const struct user_regset *regset) 564 + { 565 + return target->thread.io_bitmap_max / regset->size; 566 + } 567 + 568 + static int ioperm_get(struct task_struct *target, 569 + const struct user_regset *regset, 570 + unsigned int pos, unsigned int count, 571 + void *kbuf, void __user *ubuf) 572 + { 573 + if (!target->thread.io_bitmap_ptr) 574 + return -ENXIO; 575 + 576 + return user_regset_copyout(&pos, &count, &kbuf, &ubuf, 577 + target->thread.io_bitmap_ptr, 578 + 0, IO_BITMAP_BYTES); 558 579 } 559 580 560 581 #ifdef CONFIG_X86_PTRACE_BTS ··· 1410 1385 .size = sizeof(long), .align = sizeof(long), 1411 1386 .active = xfpregs_active, .get = xfpregs_get, .set = xfpregs_set 1412 1387 }, 1388 + [REGSET_IOPERM64] = { 1389 + .core_note_type = NT_386_IOPERM, 1390 + .n = IO_BITMAP_LONGS, 1391 + .size = sizeof(long), .align = sizeof(long), 1392 + .active = ioperm_active, .get = ioperm_get 1393 + }, 1413 1394 }; 1414 1395 1415 1396 static const struct user_regset_view user_x86_64_view = { ··· 1462 1431 .active = regset_tls_active, 1463 1432 .get = regset_tls_get, .set = regset_tls_set 1464 1433 }, 1434 + [REGSET_IOPERM32] = { 1435 + .core_note_type = NT_386_IOPERM, 1436 + .n = IO_BITMAP_BYTES / sizeof(u32), 1437 + .size = sizeof(u32), .align = sizeof(u32), 1438 + .active = ioperm_active, .get = ioperm_get 1439 + }, 1465 1440 }; 1466 1441 1467 1442 static const struct user_regset_view user_x86_32_view = { ··· 1489 1452 #endif 1490 1453 } 1491 1454 1492 - void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code) 1455 + void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, 1456 + int error_code, int si_code) 1493 1457 { 1494 1458 struct siginfo info; 1495 1459 ··· 1499 1461 1500 1462 memset(&info, 0, sizeof(info)); 1501 1463 info.si_signo = SIGTRAP; 1502 - info.si_code = TRAP_BRKPT; 1464 + info.si_code = si_code; 1503 1465 1504 1466 /* User-mode ip? */ 1505 1467 info.si_addr = user_mode_vm(regs) ? (void __user *) regs->ip : NULL; ··· 1586 1548 */ 1587 1549 if (test_thread_flag(TIF_SINGLESTEP) && 1588 1550 tracehook_consider_fatal_signal(current, SIGTRAP, SIG_DFL)) 1589 - send_sigtrap(current, regs, 0); 1551 + send_sigtrap(current, regs, 0, TRAP_BRKPT); 1590 1552 }
+194 -2
arch/x86/kernel/setup.c
··· 582 582 struct x86_quirks *x86_quirks __initdata = &default_x86_quirks; 583 583 584 584 /* 585 + * Some BIOSes seem to corrupt the low 64k of memory during events 586 + * like suspend/resume and unplugging an HDMI cable. Reserve all 587 + * remaining free memory in that area and fill it with a distinct 588 + * pattern. 589 + */ 590 + #ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION 591 + #define MAX_SCAN_AREAS 8 592 + 593 + static int __read_mostly memory_corruption_check = -1; 594 + 595 + static unsigned __read_mostly corruption_check_size = 64*1024; 596 + static unsigned __read_mostly corruption_check_period = 60; /* seconds */ 597 + 598 + static struct e820entry scan_areas[MAX_SCAN_AREAS]; 599 + static int num_scan_areas; 600 + 601 + 602 + static int set_corruption_check(char *arg) 603 + { 604 + char *end; 605 + 606 + memory_corruption_check = simple_strtol(arg, &end, 10); 607 + 608 + return (*end == 0) ? 0 : -EINVAL; 609 + } 610 + early_param("memory_corruption_check", set_corruption_check); 611 + 612 + static int set_corruption_check_period(char *arg) 613 + { 614 + char *end; 615 + 616 + corruption_check_period = simple_strtoul(arg, &end, 10); 617 + 618 + return (*end == 0) ? 0 : -EINVAL; 619 + } 620 + early_param("memory_corruption_check_period", set_corruption_check_period); 621 + 622 + static int set_corruption_check_size(char *arg) 623 + { 624 + char *end; 625 + unsigned size; 626 + 627 + size = memparse(arg, &end); 628 + 629 + if (*end == '\0') 630 + corruption_check_size = size; 631 + 632 + return (size == corruption_check_size) ? 0 : -EINVAL; 633 + } 634 + early_param("memory_corruption_check_size", set_corruption_check_size); 635 + 636 + 637 + static void __init setup_bios_corruption_check(void) 638 + { 639 + u64 addr = PAGE_SIZE; /* assume first page is reserved anyway */ 640 + 641 + if (memory_corruption_check == -1) { 642 + memory_corruption_check = 643 + #ifdef CONFIG_X86_BOOTPARAM_MEMORY_CORRUPTION_CHECK 644 + 1 645 + #else 646 + 0 647 + #endif 648 + ; 649 + } 650 + 651 + if (corruption_check_size == 0) 652 + memory_corruption_check = 0; 653 + 654 + if (!memory_corruption_check) 655 + return; 656 + 657 + corruption_check_size = round_up(corruption_check_size, PAGE_SIZE); 658 + 659 + while(addr < corruption_check_size && num_scan_areas < MAX_SCAN_AREAS) { 660 + u64 size; 661 + addr = find_e820_area_size(addr, &size, PAGE_SIZE); 662 + 663 + if (addr == 0) 664 + break; 665 + 666 + if ((addr + size) > corruption_check_size) 667 + size = corruption_check_size - addr; 668 + 669 + if (size == 0) 670 + break; 671 + 672 + e820_update_range(addr, size, E820_RAM, E820_RESERVED); 673 + scan_areas[num_scan_areas].addr = addr; 674 + scan_areas[num_scan_areas].size = size; 675 + num_scan_areas++; 676 + 677 + /* Assume we've already mapped this early memory */ 678 + memset(__va(addr), 0, size); 679 + 680 + addr += size; 681 + } 682 + 683 + printk(KERN_INFO "Scanning %d areas for low memory corruption\n", 684 + num_scan_areas); 685 + update_e820(); 686 + } 687 + 688 + static struct timer_list periodic_check_timer; 689 + 690 + void check_for_bios_corruption(void) 691 + { 692 + int i; 693 + int corruption = 0; 694 + 695 + if (!memory_corruption_check) 696 + return; 697 + 698 + for(i = 0; i < num_scan_areas; i++) { 699 + unsigned long *addr = __va(scan_areas[i].addr); 700 + unsigned long size = scan_areas[i].size; 701 + 702 + for(; size; addr++, size -= sizeof(unsigned long)) { 703 + if (!*addr) 704 + continue; 705 + printk(KERN_ERR "Corrupted low memory at %p (%lx phys) = %08lx\n", 706 + addr, __pa(addr), *addr); 707 + corruption = 1; 708 + *addr = 0; 709 + } 710 + } 711 + 712 + WARN(corruption, KERN_ERR "Memory corruption detected in low memory\n"); 713 + } 714 + 715 + static void periodic_check_for_corruption(unsigned long data) 716 + { 717 + check_for_bios_corruption(); 718 + mod_timer(&periodic_check_timer, round_jiffies(jiffies + corruption_check_period*HZ)); 719 + } 720 + 721 + void start_periodic_check_for_corruption(void) 722 + { 723 + if (!memory_corruption_check || corruption_check_period == 0) 724 + return; 725 + 726 + printk(KERN_INFO "Scanning for low memory corruption every %d seconds\n", 727 + corruption_check_period); 728 + 729 + init_timer(&periodic_check_timer); 730 + periodic_check_timer.function = &periodic_check_for_corruption; 731 + periodic_check_for_corruption(0); 732 + } 733 + #endif 734 + 735 + static int __init dmi_low_memory_corruption(const struct dmi_system_id *d) 736 + { 737 + printk(KERN_NOTICE 738 + "%s detected: BIOS may corrupt low RAM, working it around.\n", 739 + d->ident); 740 + 741 + e820_update_range(0, 0x10000, E820_RAM, E820_RESERVED); 742 + sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map); 743 + 744 + return 0; 745 + } 746 + 747 + /* List of systems that have known low memory corruption BIOS problems */ 748 + static struct dmi_system_id __initdata bad_bios_dmi_table[] = { 749 + #ifdef CONFIG_X86_RESERVE_LOW_64K 750 + { 751 + .callback = dmi_low_memory_corruption, 752 + .ident = "AMI BIOS", 753 + .matches = { 754 + DMI_MATCH(DMI_BIOS_VENDOR, "American Megatrends Inc."), 755 + }, 756 + }, 757 + { 758 + .callback = dmi_low_memory_corruption, 759 + .ident = "Phoenix BIOS", 760 + .matches = { 761 + DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies, LTD"), 762 + }, 763 + }, 764 + #endif 765 + {} 766 + }; 767 + 768 + /* 585 769 * Determine if we were loaded by an EFI loader. If so, then we have also been 586 770 * passed the efi memmap, systab, etc., so we should use these data structures 587 771 * for initialization. Note, the efi init code path is determined by the ··· 899 715 900 716 finish_e820_parsing(); 901 717 718 + dmi_scan_machine(); 719 + 720 + dmi_check_system(bad_bios_dmi_table); 721 + 902 722 #ifdef CONFIG_X86_32 903 723 probe_roms(); 904 724 #endif ··· 959 771 high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1; 960 772 #endif 961 773 774 + #ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION 775 + setup_bios_corruption_check(); 776 + #endif 777 + 962 778 /* max_pfn_mapped is updated here */ 963 779 max_low_pfn_mapped = init_memory_mapping(0, max_low_pfn<<PAGE_SHIFT); 964 780 max_pfn_mapped = max_low_pfn_mapped; ··· 990 798 #ifdef CONFIG_X86_64 991 799 vsmp_init(); 992 800 #endif 993 - 994 - dmi_scan_machine(); 995 801 996 802 io_delay_init(); 997 803 ··· 1093 903 #endif 1094 904 #endif 1095 905 } 906 + 907 +
+134 -88
arch/x86/kernel/signal_32.c
··· 27 27 #include <asm/uaccess.h> 28 28 #include <asm/i387.h> 29 29 #include <asm/vdso.h> 30 + #include <asm/syscall.h> 30 31 #include <asm/syscalls.h> 31 32 32 33 #include "sigframe.h" ··· 113 112 return do_sigaltstack(uss, uoss, regs->sp); 114 113 } 115 114 115 + #define COPY(x) { \ 116 + err |= __get_user(regs->x, &sc->x); \ 117 + } 118 + 119 + #define COPY_SEG(seg) { \ 120 + unsigned short tmp; \ 121 + err |= __get_user(tmp, &sc->seg); \ 122 + regs->seg = tmp; \ 123 + } 124 + 125 + #define COPY_SEG_STRICT(seg) { \ 126 + unsigned short tmp; \ 127 + err |= __get_user(tmp, &sc->seg); \ 128 + regs->seg = tmp | 3; \ 129 + } 130 + 131 + #define GET_SEG(seg) { \ 132 + unsigned short tmp; \ 133 + err |= __get_user(tmp, &sc->seg); \ 134 + loadsegment(seg, tmp); \ 135 + } 116 136 117 137 /* 118 138 * Do a signal return; undo the signal stack. ··· 142 120 restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, 143 121 unsigned long *pax) 144 122 { 123 + void __user *buf; 124 + unsigned int tmpflags; 145 125 unsigned int err = 0; 146 126 147 127 /* Always make any pending restarted system calls return -EINTR */ 148 128 current_thread_info()->restart_block.fn = do_no_restart_syscall; 149 - 150 - #define COPY(x) err |= __get_user(regs->x, &sc->x) 151 - 152 - #define COPY_SEG(seg) \ 153 - { unsigned short tmp; \ 154 - err |= __get_user(tmp, &sc->seg); \ 155 - regs->seg = tmp; } 156 - 157 - #define COPY_SEG_STRICT(seg) \ 158 - { unsigned short tmp; \ 159 - err |= __get_user(tmp, &sc->seg); \ 160 - regs->seg = tmp|3; } 161 - 162 - #define GET_SEG(seg) \ 163 - { unsigned short tmp; \ 164 - err |= __get_user(tmp, &sc->seg); \ 165 - loadsegment(seg, tmp); } 166 129 167 130 GET_SEG(gs); 168 131 COPY_SEG(fs); ··· 158 151 COPY_SEG_STRICT(cs); 159 152 COPY_SEG_STRICT(ss); 160 153 161 - { 162 - unsigned int tmpflags; 154 + err |= __get_user(tmpflags, &sc->flags); 155 + regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS); 156 + regs->orig_ax = -1; /* disable syscall checks */ 163 157 164 - err |= __get_user(tmpflags, &sc->flags); 165 - regs->flags = (regs->flags & ~FIX_EFLAGS) | 166 - (tmpflags & FIX_EFLAGS); 167 - regs->orig_ax = -1; /* disable syscall checks */ 168 - } 169 - 170 - { 171 - void __user *buf; 172 - 173 - err |= __get_user(buf, &sc->fpstate); 174 - err |= restore_i387_xstate(buf); 175 - } 158 + err |= __get_user(buf, &sc->fpstate); 159 + err |= restore_i387_xstate(buf); 176 160 177 161 err |= __get_user(*pax, &sc->ax); 178 162 return err; ··· 212 214 return 0; 213 215 } 214 216 215 - asmlinkage int sys_rt_sigreturn(unsigned long __unused) 217 + static long do_rt_sigreturn(struct pt_regs *regs) 216 218 { 217 - struct pt_regs *regs = (struct pt_regs *)&__unused; 218 219 struct rt_sigframe __user *frame; 219 220 unsigned long ax; 220 221 sigset_t set; ··· 239 242 return ax; 240 243 241 244 badframe: 242 - force_sig(SIGSEGV, current); 245 + signal_fault(regs, frame, "rt_sigreturn"); 243 246 return 0; 247 + } 248 + 249 + asmlinkage int sys_rt_sigreturn(unsigned long __unused) 250 + { 251 + struct pt_regs *regs = (struct pt_regs *)&__unused; 252 + 253 + return do_rt_sigreturn(regs); 244 254 } 245 255 246 256 /* ··· 341 337 } 342 338 343 339 static int 344 - setup_frame(int sig, struct k_sigaction *ka, sigset_t *set, 345 - struct pt_regs *regs) 340 + __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set, 341 + struct pt_regs *regs) 346 342 { 347 343 struct sigframe __user *frame; 348 344 void __user *restorer; 349 345 int err = 0; 350 - int usig; 351 346 void __user *fpstate = NULL; 352 347 353 348 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate); 354 349 355 350 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) 356 - goto give_sigsegv; 351 + return -EFAULT; 357 352 358 - usig = current_thread_info()->exec_domain 359 - && current_thread_info()->exec_domain->signal_invmap 360 - && sig < 32 361 - ? current_thread_info()->exec_domain->signal_invmap[sig] 362 - : sig; 353 + if (__put_user(sig, &frame->sig)) 354 + return -EFAULT; 363 355 364 - err = __put_user(usig, &frame->sig); 365 - if (err) 366 - goto give_sigsegv; 367 - 368 - err = setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0]); 369 - if (err) 370 - goto give_sigsegv; 356 + if (setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0])) 357 + return -EFAULT; 371 358 372 359 if (_NSIG_WORDS > 1) { 373 - err = __copy_to_user(&frame->extramask, &set->sig[1], 374 - sizeof(frame->extramask)); 375 - if (err) 376 - goto give_sigsegv; 360 + if (__copy_to_user(&frame->extramask, &set->sig[1], 361 + sizeof(frame->extramask))) 362 + return -EFAULT; 377 363 } 378 364 379 365 if (current->mm->context.vdso) ··· 388 394 err |= __put_user(0x80cd, (short __user *)(frame->retcode+6)); 389 395 390 396 if (err) 391 - goto give_sigsegv; 397 + return -EFAULT; 392 398 393 399 /* Set up registers for signal handler */ 394 400 regs->sp = (unsigned long)frame; ··· 403 409 regs->cs = __USER_CS; 404 410 405 411 return 0; 406 - 407 - give_sigsegv: 408 - force_sigsegv(sig, current); 409 - return -EFAULT; 410 412 } 411 413 412 - static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, 413 - sigset_t *set, struct pt_regs *regs) 414 + static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, 415 + sigset_t *set, struct pt_regs *regs) 414 416 { 415 417 struct rt_sigframe __user *frame; 416 418 void __user *restorer; 417 419 int err = 0; 418 - int usig; 419 420 void __user *fpstate = NULL; 420 421 421 422 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate); 422 423 423 424 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) 424 - goto give_sigsegv; 425 + return -EFAULT; 425 426 426 - usig = current_thread_info()->exec_domain 427 - && current_thread_info()->exec_domain->signal_invmap 428 - && sig < 32 429 - ? current_thread_info()->exec_domain->signal_invmap[sig] 430 - : sig; 431 - 432 - err |= __put_user(usig, &frame->sig); 427 + err |= __put_user(sig, &frame->sig); 433 428 err |= __put_user(&frame->info, &frame->pinfo); 434 429 err |= __put_user(&frame->uc, &frame->puc); 435 430 err |= copy_siginfo_to_user(&frame->info, info); 436 431 if (err) 437 - goto give_sigsegv; 432 + return -EFAULT; 438 433 439 434 /* Create the ucontext. */ 440 435 if (cpu_has_xsave) ··· 439 456 regs, set->sig[0]); 440 457 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); 441 458 if (err) 442 - goto give_sigsegv; 459 + return -EFAULT; 443 460 444 461 /* Set up to return from userspace. */ 445 462 restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn); ··· 459 476 err |= __put_user(0x80cd, (short __user *)(frame->retcode+5)); 460 477 461 478 if (err) 462 - goto give_sigsegv; 479 + return -EFAULT; 463 480 464 481 /* Set up registers for signal handler */ 465 482 regs->sp = (unsigned long)frame; 466 483 regs->ip = (unsigned long)ka->sa.sa_handler; 467 - regs->ax = (unsigned long)usig; 484 + regs->ax = (unsigned long)sig; 468 485 regs->dx = (unsigned long)&frame->info; 469 486 regs->cx = (unsigned long)&frame->uc; 470 487 ··· 474 491 regs->cs = __USER_CS; 475 492 476 493 return 0; 477 - 478 - give_sigsegv: 479 - force_sigsegv(sig, current); 480 - return -EFAULT; 481 494 } 482 495 483 496 /* 484 497 * OK, we're invoking a handler: 485 498 */ 499 + static int signr_convert(int sig) 500 + { 501 + struct thread_info *info = current_thread_info(); 502 + 503 + if (info->exec_domain && info->exec_domain->signal_invmap && sig < 32) 504 + return info->exec_domain->signal_invmap[sig]; 505 + return sig; 506 + } 507 + 508 + #define is_ia32 1 509 + #define ia32_setup_frame __setup_frame 510 + #define ia32_setup_rt_frame __setup_rt_frame 511 + 512 + static int 513 + setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, 514 + sigset_t *set, struct pt_regs *regs) 515 + { 516 + int usig = signr_convert(sig); 517 + int ret; 518 + 519 + /* Set up the stack frame */ 520 + if (is_ia32) { 521 + if (ka->sa.sa_flags & SA_SIGINFO) 522 + ret = ia32_setup_rt_frame(usig, ka, info, set, regs); 523 + else 524 + ret = ia32_setup_frame(usig, ka, set, regs); 525 + } else 526 + ret = __setup_rt_frame(sig, ka, info, set, regs); 527 + 528 + if (ret) { 529 + force_sigsegv(sig, current); 530 + return -EFAULT; 531 + } 532 + 533 + return ret; 534 + } 535 + 486 536 static int 487 537 handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka, 488 538 sigset_t *oldset, struct pt_regs *regs) ··· 523 507 int ret; 524 508 525 509 /* Are we from a system call? */ 526 - if ((long)regs->orig_ax >= 0) { 510 + if (syscall_get_nr(current, regs) >= 0) { 527 511 /* If so, check system call restarting.. */ 528 - switch (regs->ax) { 512 + switch (syscall_get_error(current, regs)) { 529 513 case -ERESTART_RESTARTBLOCK: 530 514 case -ERESTARTNOHAND: 531 515 regs->ax = -EINTR; ··· 552 536 likely(test_and_clear_thread_flag(TIF_FORCED_TF))) 553 537 regs->flags &= ~X86_EFLAGS_TF; 554 538 555 - /* Set up the stack frame */ 556 - if (ka->sa.sa_flags & SA_SIGINFO) 557 - ret = setup_rt_frame(sig, ka, info, oldset, regs); 558 - else 559 - ret = setup_frame(sig, ka, oldset, regs); 539 + ret = setup_rt_frame(sig, ka, info, oldset, regs); 560 540 561 541 if (ret) 562 542 return ret; 543 + 544 + #ifdef CONFIG_X86_64 545 + /* 546 + * This has nothing to do with segment registers, 547 + * despite the name. This magic affects uaccess.h 548 + * macros' behavior. Reset it to the normal setting. 549 + */ 550 + set_fs(USER_DS); 551 + #endif 563 552 564 553 /* 565 554 * Clear the direction flag as per the ABI for function entry. ··· 592 571 return 0; 593 572 } 594 573 574 + #define NR_restart_syscall __NR_restart_syscall 595 575 /* 596 576 * Note that 'init' is a special process: it doesn't get signals it doesn't 597 577 * want to handle. Thus you cannot kill init even with a SIGKILL even by ··· 645 623 } 646 624 647 625 /* Did we come from a system call? */ 648 - if ((long)regs->orig_ax >= 0) { 626 + if (syscall_get_nr(current, regs) >= 0) { 649 627 /* Restart the system call - no handlers present */ 650 - switch (regs->ax) { 628 + switch (syscall_get_error(current, regs)) { 651 629 case -ERESTARTNOHAND: 652 630 case -ERESTARTSYS: 653 631 case -ERESTARTNOINTR: ··· 656 634 break; 657 635 658 636 case -ERESTART_RESTARTBLOCK: 659 - regs->ax = __NR_restart_syscall; 637 + regs->ax = NR_restart_syscall; 660 638 regs->ip -= 2; 661 639 break; 662 640 } ··· 679 657 void 680 658 do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags) 681 659 { 660 + #if defined(CONFIG_X86_64) && defined(CONFIG_X86_MCE) 661 + /* notify userspace of pending MCEs */ 662 + if (thread_info_flags & _TIF_MCE_NOTIFY) 663 + mce_notify_user(); 664 + #endif /* CONFIG_X86_64 && CONFIG_X86_MCE */ 665 + 682 666 /* deal with pending signal delivery */ 683 667 if (thread_info_flags & _TIF_SIGPENDING) 684 668 do_signal(regs); ··· 694 666 tracehook_notify_resume(regs); 695 667 } 696 668 669 + #ifdef CONFIG_X86_32 697 670 clear_thread_flag(TIF_IRET); 671 + #endif /* CONFIG_X86_32 */ 672 + } 673 + 674 + void signal_fault(struct pt_regs *regs, void __user *frame, char *where) 675 + { 676 + struct task_struct *me = current; 677 + 678 + if (show_unhandled_signals && printk_ratelimit()) { 679 + printk(KERN_INFO 680 + "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx", 681 + me->comm, me->pid, where, frame, 682 + regs->ip, regs->sp, regs->orig_ax); 683 + print_vma_addr(" in ", regs->ip); 684 + printk(KERN_CONT "\n"); 685 + } 686 + 687 + force_sig(SIGSEGV, me); 698 688 }
+124 -83
arch/x86/kernel/signal_64.c
··· 52 52 return do_sigaltstack(uss, uoss, regs->sp); 53 53 } 54 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 + 55 65 /* 56 66 * Do a signal return; undo the signal stack. 57 67 */ ··· 69 59 restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, 70 60 unsigned long *pax) 71 61 { 62 + void __user *buf; 63 + unsigned int tmpflags; 72 64 unsigned int err = 0; 73 65 74 66 /* Always make any pending restarted system calls return -EINTR */ 75 67 current_thread_info()->restart_block.fn = do_no_restart_syscall; 76 - 77 - #define COPY(x) (err |= __get_user(regs->x, &sc->x)) 78 68 79 69 COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx); 80 70 COPY(dx); COPY(cx); COPY(ip); ··· 90 80 /* Kernel saves and restores only the CS segment register on signals, 91 81 * which is the bare minimum needed to allow mixed 32/64-bit code. 92 82 * App's signal handler can save/restore other segments if needed. */ 93 - { 94 - unsigned cs; 95 - err |= __get_user(cs, &sc->cs); 96 - regs->cs = cs | 3; /* Force into user mode */ 97 - } 83 + COPY_SEG_STRICT(cs); 98 84 99 - { 100 - unsigned int tmpflags; 101 - err |= __get_user(tmpflags, &sc->flags); 102 - regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS); 103 - regs->orig_ax = -1; /* disable syscall checks */ 104 - } 85 + err |= __get_user(tmpflags, &sc->flags); 86 + regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS); 87 + regs->orig_ax = -1; /* disable syscall checks */ 105 88 106 - { 107 - struct _fpstate __user *buf; 108 - err |= __get_user(buf, &sc->fpstate); 109 - err |= restore_i387_xstate(buf); 110 - } 89 + err |= __get_user(buf, &sc->fpstate); 90 + err |= restore_i387_xstate(buf); 111 91 112 92 err |= __get_user(*pax, &sc->ax); 113 93 return err; 114 94 } 115 95 116 - asmlinkage long sys_rt_sigreturn(struct pt_regs *regs) 96 + static long do_rt_sigreturn(struct pt_regs *regs) 117 97 { 118 98 struct rt_sigframe __user *frame; 119 - sigset_t set; 120 99 unsigned long ax; 100 + sigset_t set; 121 101 122 102 frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long)); 123 103 if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) ··· 130 130 return ax; 131 131 132 132 badframe: 133 - signal_fault(regs, frame, "sigreturn"); 133 + signal_fault(regs, frame, "rt_sigreturn"); 134 134 return 0; 135 + } 136 + 137 + asmlinkage long sys_rt_sigreturn(struct pt_regs *regs) 138 + { 139 + return do_rt_sigreturn(regs); 135 140 } 136 141 137 142 /* ··· 200 195 return (void __user *)round_down(sp - size, 64); 201 196 } 202 197 203 - static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, 204 - sigset_t *set, struct pt_regs *regs) 198 + static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, 199 + sigset_t *set, struct pt_regs *regs) 205 200 { 206 201 struct rt_sigframe __user *frame; 207 202 void __user *fp = NULL; ··· 214 209 (unsigned long)fp - sizeof(struct rt_sigframe), 16) - 8; 215 210 216 211 if (save_i387_xstate(fp) < 0) 217 - err |= -1; 212 + return -EFAULT; 218 213 } else 219 214 frame = get_stack(ka, regs, sizeof(struct rt_sigframe)) - 8; 220 215 221 216 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) 222 - goto give_sigsegv; 217 + return -EFAULT; 223 218 224 219 if (ka->sa.sa_flags & SA_SIGINFO) { 225 - err |= copy_siginfo_to_user(&frame->info, info); 226 - if (err) 227 - goto give_sigsegv; 220 + if (copy_siginfo_to_user(&frame->info, info)) 221 + return -EFAULT; 228 222 } 229 223 230 224 /* Create the ucontext. */ ··· 251 247 err |= __put_user(ka->sa.sa_restorer, &frame->pretcode); 252 248 } else { 253 249 /* could use a vstub here */ 254 - goto give_sigsegv; 250 + return -EFAULT; 255 251 } 256 252 257 253 if (err) 258 - goto give_sigsegv; 254 + return -EFAULT; 259 255 260 256 /* Set up registers for signal handler */ 261 257 regs->di = sig; ··· 275 271 regs->cs = __USER_CS; 276 272 277 273 return 0; 278 - 279 - give_sigsegv: 280 - force_sigsegv(sig, current); 281 - return -EFAULT; 282 274 } 283 275 284 276 /* 285 277 * OK, we're invoking a handler 286 278 */ 279 + static int signr_convert(int sig) 280 + { 281 + return sig; 282 + } 283 + 284 + #ifdef CONFIG_IA32_EMULATION 285 + #define is_ia32 test_thread_flag(TIF_IA32) 286 + #else 287 + #define is_ia32 0 288 + #endif 289 + 290 + static int 291 + setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, 292 + sigset_t *set, struct pt_regs *regs) 293 + { 294 + int usig = signr_convert(sig); 295 + int ret; 296 + 297 + /* Set up the stack frame */ 298 + if (is_ia32) { 299 + if (ka->sa.sa_flags & SA_SIGINFO) 300 + ret = ia32_setup_rt_frame(usig, ka, info, set, regs); 301 + else 302 + ret = ia32_setup_frame(usig, ka, set, regs); 303 + } else 304 + ret = __setup_rt_frame(sig, ka, info, set, regs); 305 + 306 + if (ret) { 307 + force_sigsegv(sig, current); 308 + return -EFAULT; 309 + } 310 + 311 + return ret; 312 + } 287 313 288 314 static int 289 315 handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka, ··· 351 317 likely(test_and_clear_thread_flag(TIF_FORCED_TF))) 352 318 regs->flags &= ~X86_EFLAGS_TF; 353 319 354 - #ifdef CONFIG_IA32_EMULATION 355 - if (test_thread_flag(TIF_IA32)) { 356 - if (ka->sa.sa_flags & SA_SIGINFO) 357 - ret = ia32_setup_rt_frame(sig, ka, info, oldset, regs); 358 - else 359 - ret = ia32_setup_frame(sig, ka, oldset, regs); 360 - } else 361 - #endif 362 320 ret = setup_rt_frame(sig, ka, info, oldset, regs); 363 321 364 - if (ret == 0) { 365 - /* 366 - * This has nothing to do with segment registers, 367 - * despite the name. This magic affects uaccess.h 368 - * macros' behavior. Reset it to the normal setting. 369 - */ 370 - set_fs(USER_DS); 322 + if (ret) 323 + return ret; 371 324 372 - /* 373 - * Clear the direction flag as per the ABI for function entry. 374 - */ 375 - regs->flags &= ~X86_EFLAGS_DF; 325 + #ifdef CONFIG_X86_64 326 + /* 327 + * This has nothing to do with segment registers, 328 + * despite the name. This magic affects uaccess.h 329 + * macros' behavior. Reset it to the normal setting. 330 + */ 331 + set_fs(USER_DS); 332 + #endif 376 333 377 - /* 378 - * Clear TF when entering the signal handler, but 379 - * notify any tracer that was single-stepping it. 380 - * The tracer may want to single-step inside the 381 - * handler too. 382 - */ 383 - regs->flags &= ~X86_EFLAGS_TF; 334 + /* 335 + * Clear the direction flag as per the ABI for function entry. 336 + */ 337 + regs->flags &= ~X86_EFLAGS_DF; 384 338 385 - spin_lock_irq(&current->sighand->siglock); 386 - sigorsets(&current->blocked, &current->blocked, &ka->sa.sa_mask); 387 - if (!(ka->sa.sa_flags & SA_NODEFER)) 388 - sigaddset(&current->blocked, sig); 389 - recalc_sigpending(); 390 - spin_unlock_irq(&current->sighand->siglock); 339 + /* 340 + * Clear TF when entering the signal handler, but 341 + * notify any tracer that was single-stepping it. 342 + * The tracer may want to single-step inside the 343 + * handler too. 344 + */ 345 + regs->flags &= ~X86_EFLAGS_TF; 391 346 392 - tracehook_signal_handler(sig, info, ka, regs, 393 - test_thread_flag(TIF_SINGLESTEP)); 394 - } 347 + spin_lock_irq(&current->sighand->siglock); 348 + sigorsets(&current->blocked, &current->blocked, &ka->sa.sa_mask); 349 + if (!(ka->sa.sa_flags & SA_NODEFER)) 350 + sigaddset(&current->blocked, sig); 351 + recalc_sigpending(); 352 + spin_unlock_irq(&current->sighand->siglock); 395 353 396 - return ret; 354 + tracehook_signal_handler(sig, info, ka, regs, 355 + test_thread_flag(TIF_SINGLESTEP)); 356 + 357 + return 0; 397 358 } 398 359 360 + #define NR_restart_syscall \ 361 + test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall : __NR_restart_syscall 399 362 /* 400 363 * Note that 'init' is a special process: it doesn't get signals it doesn't 401 364 * want to handle. Thus you cannot kill init even with a SIGKILL even by ··· 422 391 423 392 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 424 393 if (signr > 0) { 425 - /* Re-enable any watchpoints before delivering the 394 + /* 395 + * Re-enable any watchpoints before delivering the 426 396 * signal to user space. The processor register will 427 397 * have been cleared if the watchpoint triggered 428 398 * inside the kernel. ··· 431 399 if (current->thread.debugreg7) 432 400 set_debugreg(current->thread.debugreg7, 7); 433 401 434 - /* Whee! Actually deliver the signal. */ 402 + /* Whee! Actually deliver the signal. */ 435 403 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) { 436 404 /* 437 405 * A signal was successfully delivered; the saved ··· 454 422 regs->ax = regs->orig_ax; 455 423 regs->ip -= 2; 456 424 break; 425 + 457 426 case -ERESTART_RESTARTBLOCK: 458 - regs->ax = test_thread_flag(TIF_IA32) ? 459 - __NR_ia32_restart_syscall : 460 - __NR_restart_syscall; 427 + regs->ax = NR_restart_syscall; 461 428 regs->ip -= 2; 462 429 break; 463 430 } ··· 472 441 } 473 442 } 474 443 475 - void do_notify_resume(struct pt_regs *regs, void *unused, 476 - __u32 thread_info_flags) 444 + /* 445 + * notification of userspace execution resumption 446 + * - triggered by the TIF_WORK_MASK flags 447 + */ 448 + void 449 + do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags) 477 450 { 478 - #ifdef CONFIG_X86_MCE 451 + #if defined(CONFIG_X86_64) && defined(CONFIG_X86_MCE) 479 452 /* notify userspace of pending MCEs */ 480 453 if (thread_info_flags & _TIF_MCE_NOTIFY) 481 454 mce_notify_user(); 482 - #endif /* CONFIG_X86_MCE */ 455 + #endif /* CONFIG_X86_64 && CONFIG_X86_MCE */ 483 456 484 457 /* deal with pending signal delivery */ 485 458 if (thread_info_flags & _TIF_SIGPENDING) ··· 493 458 clear_thread_flag(TIF_NOTIFY_RESUME); 494 459 tracehook_notify_resume(regs); 495 460 } 461 + 462 + #ifdef CONFIG_X86_32 463 + clear_thread_flag(TIF_IRET); 464 + #endif /* CONFIG_X86_32 */ 496 465 } 497 466 498 467 void signal_fault(struct pt_regs *regs, void __user *frame, char *where) 499 468 { 500 469 struct task_struct *me = current; 470 + 501 471 if (show_unhandled_signals && printk_ratelimit()) { 502 - printk("%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx", 503 - me->comm, me->pid, where, frame, regs->ip, 504 - regs->sp, regs->orig_ax); 472 + printk(KERN_INFO 473 + "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx", 474 + me->comm, me->pid, where, frame, 475 + regs->ip, regs->sp, regs->orig_ax); 505 476 print_vma_addr(" in ", regs->ip); 506 - printk("\n"); 477 + printk(KERN_CONT "\n"); 507 478 } 508 479 509 480 force_sig(SIGSEGV, me);
+5 -1
arch/x86/kernel/smp.c
··· 214 214 struct smp_ops smp_ops = { 215 215 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu, 216 216 .smp_prepare_cpus = native_smp_prepare_cpus, 217 - .cpu_up = native_cpu_up, 218 217 .smp_cpus_done = native_smp_cpus_done, 219 218 220 219 .smp_send_stop = native_smp_send_stop, 221 220 .smp_send_reschedule = native_smp_send_reschedule, 221 + 222 + .cpu_up = native_cpu_up, 223 + .cpu_die = native_cpu_die, 224 + .cpu_disable = native_cpu_disable, 225 + .play_dead = native_play_dead, 222 226 223 227 .send_call_func_ipi = native_send_call_func_ipi, 224 228 .send_call_func_single_ipi = native_send_call_func_single_ipi,
+58 -21
arch/x86/kernel/smpboot.c
··· 52 52 #include <asm/desc.h> 53 53 #include <asm/nmi.h> 54 54 #include <asm/irq.h> 55 + #include <asm/idle.h> 55 56 #include <asm/smp.h> 56 57 #include <asm/trampoline.h> 57 58 #include <asm/cpu.h> ··· 1345 1344 numa_remove_cpu(cpu); 1346 1345 } 1347 1346 1348 - int __cpu_disable(void) 1347 + void cpu_disable_common(void) 1348 + { 1349 + int cpu = smp_processor_id(); 1350 + /* 1351 + * HACK: 1352 + * Allow any queued timer interrupts to get serviced 1353 + * This is only a temporary solution until we cleanup 1354 + * fixup_irqs as we do for IA64. 1355 + */ 1356 + local_irq_enable(); 1357 + mdelay(1); 1358 + 1359 + local_irq_disable(); 1360 + remove_siblinginfo(cpu); 1361 + 1362 + /* It's now safe to remove this processor from the online map */ 1363 + lock_vector_lock(); 1364 + remove_cpu_from_maps(cpu); 1365 + unlock_vector_lock(); 1366 + fixup_irqs(cpu_online_map); 1367 + } 1368 + 1369 + int native_cpu_disable(void) 1349 1370 { 1350 1371 int cpu = smp_processor_id(); 1351 1372 ··· 1386 1363 stop_apic_nmi_watchdog(NULL); 1387 1364 clear_local_APIC(); 1388 1365 1389 - /* 1390 - * HACK: 1391 - * Allow any queued timer interrupts to get serviced 1392 - * This is only a temporary solution until we cleanup 1393 - * fixup_irqs as we do for IA64. 1394 - */ 1395 - local_irq_enable(); 1396 - mdelay(1); 1397 - 1398 - local_irq_disable(); 1399 - remove_siblinginfo(cpu); 1400 - 1401 - /* It's now safe to remove this processor from the online map */ 1402 - lock_vector_lock(); 1403 - remove_cpu_from_maps(cpu); 1404 - unlock_vector_lock(); 1405 - fixup_irqs(cpu_online_map); 1366 + cpu_disable_common(); 1406 1367 return 0; 1407 1368 } 1408 1369 1409 - void __cpu_die(unsigned int cpu) 1370 + void native_cpu_die(unsigned int cpu) 1410 1371 { 1411 1372 /* We don't do anything here: idle task is faking death itself. */ 1412 1373 unsigned int i; ··· 1407 1400 } 1408 1401 printk(KERN_ERR "CPU %u didn't die...\n", cpu); 1409 1402 } 1403 + 1404 + void play_dead_common(void) 1405 + { 1406 + idle_task_exit(); 1407 + reset_lazy_tlbstate(); 1408 + irq_ctx_exit(raw_smp_processor_id()); 1409 + c1e_remove_cpu(raw_smp_processor_id()); 1410 + 1411 + mb(); 1412 + /* Ack it */ 1413 + __get_cpu_var(cpu_state) = CPU_DEAD; 1414 + 1415 + /* 1416 + * With physical CPU hotplug, we should halt the cpu 1417 + */ 1418 + local_irq_disable(); 1419 + } 1420 + 1421 + void native_play_dead(void) 1422 + { 1423 + play_dead_common(); 1424 + wbinvd_halt(); 1425 + } 1426 + 1410 1427 #else /* ... !CONFIG_HOTPLUG_CPU */ 1411 - int __cpu_disable(void) 1428 + int native_cpu_disable(void) 1412 1429 { 1413 1430 return -ENOSYS; 1414 1431 } 1415 1432 1416 - void __cpu_die(unsigned int cpu) 1433 + void native_cpu_die(unsigned int cpu) 1417 1434 { 1418 1435 /* We said "no" in __cpu_disable */ 1419 1436 BUG(); 1420 1437 } 1438 + 1439 + void native_play_dead(void) 1440 + { 1441 + BUG(); 1442 + } 1443 + 1421 1444 #endif
+8
arch/x86/kernel/tlb_32.c
··· 241 241 on_each_cpu(do_flush_tlb_all, NULL, 1); 242 242 } 243 243 244 + void reset_lazy_tlbstate(void) 245 + { 246 + int cpu = raw_smp_processor_id(); 247 + 248 + per_cpu(cpu_tlbstate, cpu).state = 0; 249 + per_cpu(cpu_tlbstate, cpu).active_mm = &init_mm; 250 + } 251 +
+3 -1
arch/x86/kernel/traps_32.c
··· 891 891 { 892 892 struct task_struct *tsk = current; 893 893 unsigned int condition; 894 + int si_code; 894 895 895 896 trace_hardirqs_fixup(); 896 897 ··· 936 935 goto clear_TF_reenable; 937 936 } 938 937 938 + si_code = get_si_code((unsigned long)condition); 939 939 /* Ok, finally something we can handle */ 940 - send_sigtrap(tsk, regs, error_code); 940 + send_sigtrap(tsk, regs, error_code, si_code); 941 941 942 942 /* 943 943 * Disable additional traps. They'll be re-enabled when
+1 -1
arch/x86/kernel/traps_64.c
··· 940 940 tsk->thread.error_code = error_code; 941 941 info.si_signo = SIGTRAP; 942 942 info.si_errno = 0; 943 - info.si_code = TRAP_BRKPT; 943 + info.si_code = get_si_code(condition); 944 944 info.si_addr = user_mode(regs) ? (void __user *)regs->ip : NULL; 945 945 force_sig_info(SIGTRAP, &info, tsk); 946 946
+31 -2
arch/x86/kernel/xsave.c
··· 95 95 * Start with clearing the user buffer. This will present a 96 96 * clean context for the bytes not touched by the fxsave/xsave. 97 97 */ 98 - __clear_user(buf, sig_xstate_size); 98 + err = __clear_user(buf, sig_xstate_size); 99 + if (err) 100 + return err; 99 101 100 102 if (task_thread_info(tsk)->status & TS_XSAVE) 101 103 err = xsave_user(buf); ··· 116 114 117 115 if (task_thread_info(tsk)->status & TS_XSAVE) { 118 116 struct _fpstate __user *fx = buf; 117 + struct _xstate __user *x = buf; 118 + u64 xstate_bv; 119 119 120 120 err = __copy_to_user(&fx->sw_reserved, &fx_sw_reserved, 121 121 sizeof(struct _fpx_sw_bytes)); ··· 125 121 err |= __put_user(FP_XSTATE_MAGIC2, 126 122 (__u32 __user *) (buf + sig_xstate_size 127 123 - FP_XSTATE_MAGIC2_SIZE)); 124 + 125 + /* 126 + * Read the xstate_bv which we copied (directly from the cpu or 127 + * from the state in task struct) to the user buffers and 128 + * set the FP/SSE bits. 129 + */ 130 + err |= __get_user(xstate_bv, &x->xstate_hdr.xstate_bv); 131 + 132 + /* 133 + * For legacy compatible, we always set FP/SSE bits in the bit 134 + * vector while saving the state to the user context. This will 135 + * enable us capturing any changes(during sigreturn) to 136 + * the FP/SSE bits by the legacy applications which don't touch 137 + * xstate_bv in the xsave header. 138 + * 139 + * xsave aware apps can change the xstate_bv in the xsave 140 + * header as well as change any contents in the memory layout. 141 + * xrestore as part of sigreturn will capture all the changes. 142 + */ 143 + xstate_bv |= XSTATE_FPSSE; 144 + 145 + err |= __put_user(xstate_bv, &x->xstate_hdr.xstate_bv); 146 + 147 + if (err) 148 + return err; 128 149 } 129 150 130 151 return 1; ··· 301 272 /* 302 273 * setup the xstate image representing the init state 303 274 */ 304 - void setup_xstate_init(void) 275 + static void __init setup_xstate_init(void) 305 276 { 306 277 init_xstate_buf = alloc_bootmem(xstate_size); 307 278 init_xstate_buf->i387.mxcsr = MXCSR_DEFAULT;
+6 -8
arch/x86/mm/fault.c
··· 914 914 915 915 void vmalloc_sync_all(void) 916 916 { 917 - #ifdef CONFIG_X86_32 918 - unsigned long start = VMALLOC_START & PGDIR_MASK; 919 917 unsigned long address; 920 918 919 + #ifdef CONFIG_X86_32 921 920 if (SHARED_KERNEL_PMD) 922 921 return; 923 922 924 - BUILD_BUG_ON(TASK_SIZE & ~PGDIR_MASK); 925 - for (address = start; address >= TASK_SIZE; address += PGDIR_SIZE) { 923 + for (address = VMALLOC_START & PMD_MASK; 924 + address >= TASK_SIZE && address < FIXADDR_TOP; 925 + address += PMD_SIZE) { 926 926 unsigned long flags; 927 927 struct page *page; 928 928 ··· 935 935 spin_unlock_irqrestore(&pgd_lock, flags); 936 936 } 937 937 #else /* CONFIG_X86_64 */ 938 - unsigned long start = VMALLOC_START & PGDIR_MASK; 939 - unsigned long address; 940 - 941 - for (address = start; address <= VMALLOC_END; address += PGDIR_SIZE) { 938 + for (address = VMALLOC_START & PGDIR_MASK; address <= VMALLOC_END; 939 + address += PGDIR_SIZE) { 942 940 const pgd_t *pgd_ref = pgd_offset_k(address); 943 941 unsigned long flags; 944 942 struct page *page;
+3
arch/x86/mm/init_32.c
··· 31 31 #include <linux/cpumask.h> 32 32 33 33 #include <asm/asm.h> 34 + #include <asm/bios_ebda.h> 34 35 #include <asm/processor.h> 35 36 #include <asm/system.h> 36 37 #include <asm/uaccess.h> ··· 969 968 { 970 969 int codesize, reservedpages, datasize, initsize; 971 970 int tmp; 971 + 972 + start_periodic_check_for_corruption(); 972 973 973 974 #ifdef CONFIG_FLATMEM 974 975 BUG_ON(!mem_map);
+3
arch/x86/mm/init_64.c
··· 31 31 #include <linux/nmi.h> 32 32 33 33 #include <asm/processor.h> 34 + #include <asm/bios_ebda.h> 34 35 #include <asm/system.h> 35 36 #include <asm/uaccess.h> 36 37 #include <asm/pgtable.h> ··· 881 880 void __init mem_init(void) 882 881 { 883 882 long codesize, reservedpages, datasize, initsize; 883 + 884 + start_periodic_check_for_corruption(); 884 885 885 886 pci_iommu_alloc(); 886 887
+27 -8
arch/x86/mm/ioremap.c
··· 24 24 25 25 #ifdef CONFIG_X86_64 26 26 27 - unsigned long __phys_addr(unsigned long x) 28 - { 29 - if (x >= __START_KERNEL_map) 30 - return x - __START_KERNEL_map + phys_base; 31 - return x - PAGE_OFFSET; 32 - } 33 - EXPORT_SYMBOL(__phys_addr); 34 - 35 27 static inline int phys_addr_valid(unsigned long addr) 36 28 { 37 29 return addr < (1UL << boot_cpu_data.x86_phys_bits); 38 30 } 31 + 32 + unsigned long __phys_addr(unsigned long x) 33 + { 34 + if (x >= __START_KERNEL_map) { 35 + x -= __START_KERNEL_map; 36 + VIRTUAL_BUG_ON(x >= KERNEL_IMAGE_SIZE); 37 + x += phys_base; 38 + } else { 39 + VIRTUAL_BUG_ON(x < PAGE_OFFSET); 40 + x -= PAGE_OFFSET; 41 + VIRTUAL_BUG_ON(system_state == SYSTEM_BOOTING ? x > MAXMEM : 42 + !phys_addr_valid(x)); 43 + } 44 + return x; 45 + } 46 + EXPORT_SYMBOL(__phys_addr); 39 47 40 48 #else 41 49 ··· 51 43 { 52 44 return 1; 53 45 } 46 + 47 + #ifdef CONFIG_DEBUG_VIRTUAL 48 + unsigned long __phys_addr(unsigned long x) 49 + { 50 + /* VMALLOC_* aren't constants; not available at the boot time */ 51 + VIRTUAL_BUG_ON(x < PAGE_OFFSET || (system_state != SYSTEM_BOOTING && 52 + is_vmalloc_addr((void *)x))); 53 + return x - PAGE_OFFSET; 54 + } 55 + EXPORT_SYMBOL(__phys_addr); 56 + #endif 54 57 55 58 #endif 56 59
+9 -1
arch/x86/xen/Kconfig
··· 26 26 27 27 config XEN_SAVE_RESTORE 28 28 bool 29 - depends on PM 29 + depends on XEN && PM 30 30 default y 31 + 32 + config XEN_DEBUG_FS 33 + bool "Enable Xen debug and tuning parameters in debugfs" 34 + depends on XEN && DEBUG_FS 35 + default n 36 + help 37 + Enable statistics output and various tuning options in debugfs. 38 + Enabling this option may incur a significant performance overhead.
+10 -2
arch/x86/xen/Makefile
··· 1 - obj-y := enlighten.o setup.o multicalls.o mmu.o \ 1 + ifdef CONFIG_FTRACE 2 + # Do not profile debug and lowlevel utilities 3 + CFLAGS_REMOVE_spinlock.o = -pg 4 + CFLAGS_REMOVE_time.o = -pg 5 + CFLAGS_REMOVE_irq.o = -pg 6 + endif 7 + 8 + obj-y := enlighten.o setup.o multicalls.o mmu.o irq.o \ 2 9 time.o xen-asm_$(BITS).o grant-table.o suspend.o 3 10 4 - obj-$(CONFIG_SMP) += smp.o 11 + obj-$(CONFIG_SMP) += smp.o spinlock.o 12 + obj-$(CONFIG_XEN_DEBUG_FS) += debugfs.o
+123
arch/x86/xen/debugfs.c
··· 1 + #include <linux/init.h> 2 + #include <linux/debugfs.h> 3 + #include <linux/module.h> 4 + 5 + #include "debugfs.h" 6 + 7 + static struct dentry *d_xen_debug; 8 + 9 + struct dentry * __init xen_init_debugfs(void) 10 + { 11 + if (!d_xen_debug) { 12 + d_xen_debug = debugfs_create_dir("xen", NULL); 13 + 14 + if (!d_xen_debug) 15 + pr_warning("Could not create 'xen' debugfs directory\n"); 16 + } 17 + 18 + return d_xen_debug; 19 + } 20 + 21 + struct array_data 22 + { 23 + void *array; 24 + unsigned elements; 25 + }; 26 + 27 + static int u32_array_open(struct inode *inode, struct file *file) 28 + { 29 + file->private_data = NULL; 30 + return nonseekable_open(inode, file); 31 + } 32 + 33 + static size_t format_array(char *buf, size_t bufsize, const char *fmt, 34 + u32 *array, unsigned array_size) 35 + { 36 + size_t ret = 0; 37 + unsigned i; 38 + 39 + for(i = 0; i < array_size; i++) { 40 + size_t len; 41 + 42 + len = snprintf(buf, bufsize, fmt, array[i]); 43 + len++; /* ' ' or '\n' */ 44 + ret += len; 45 + 46 + if (buf) { 47 + buf += len; 48 + bufsize -= len; 49 + buf[-1] = (i == array_size-1) ? '\n' : ' '; 50 + } 51 + } 52 + 53 + ret++; /* \0 */ 54 + if (buf) 55 + *buf = '\0'; 56 + 57 + return ret; 58 + } 59 + 60 + static char *format_array_alloc(const char *fmt, u32 *array, unsigned array_size) 61 + { 62 + size_t len = format_array(NULL, 0, fmt, array, array_size); 63 + char *ret; 64 + 65 + ret = kmalloc(len, GFP_KERNEL); 66 + if (ret == NULL) 67 + return NULL; 68 + 69 + format_array(ret, len, fmt, array, array_size); 70 + return ret; 71 + } 72 + 73 + static ssize_t u32_array_read(struct file *file, char __user *buf, size_t len, 74 + loff_t *ppos) 75 + { 76 + struct inode *inode = file->f_path.dentry->d_inode; 77 + struct array_data *data = inode->i_private; 78 + size_t size; 79 + 80 + if (*ppos == 0) { 81 + if (file->private_data) { 82 + kfree(file->private_data); 83 + file->private_data = NULL; 84 + } 85 + 86 + file->private_data = format_array_alloc("%u", data->array, data->elements); 87 + } 88 + 89 + size = 0; 90 + if (file->private_data) 91 + size = strlen(file->private_data); 92 + 93 + return simple_read_from_buffer(buf, len, ppos, file->private_data, size); 94 + } 95 + 96 + static int xen_array_release(struct inode *inode, struct file *file) 97 + { 98 + kfree(file->private_data); 99 + 100 + return 0; 101 + } 102 + 103 + static struct file_operations u32_array_fops = { 104 + .owner = THIS_MODULE, 105 + .open = u32_array_open, 106 + .release= xen_array_release, 107 + .read = u32_array_read, 108 + }; 109 + 110 + struct dentry *xen_debugfs_create_u32_array(const char *name, mode_t mode, 111 + struct dentry *parent, 112 + u32 *array, unsigned elements) 113 + { 114 + struct array_data *data = kmalloc(sizeof(*data), GFP_KERNEL); 115 + 116 + if (data == NULL) 117 + return NULL; 118 + 119 + data->array = array; 120 + data->elements = elements; 121 + 122 + return debugfs_create_file(name, mode, parent, data, &u32_array_fops); 123 + }
+10
arch/x86/xen/debugfs.h
··· 1 + #ifndef _XEN_DEBUGFS_H 2 + #define _XEN_DEBUGFS_H 3 + 4 + struct dentry * __init xen_init_debugfs(void); 5 + 6 + struct dentry *xen_debugfs_create_u32_array(const char *name, mode_t mode, 7 + struct dentry *parent, 8 + u32 *array, unsigned elements); 9 + 10 + #endif /* _XEN_DEBUGFS_H */
+94 -180
arch/x86/xen/enlighten.c
··· 30 30 #include <xen/interface/xen.h> 31 31 #include <xen/interface/physdev.h> 32 32 #include <xen/interface/vcpu.h> 33 - #include <xen/interface/sched.h> 34 33 #include <xen/features.h> 35 34 #include <xen/page.h> 36 35 #include <xen/hvc-console.h> ··· 56 57 57 58 DEFINE_PER_CPU(struct vcpu_info *, xen_vcpu); 58 59 DEFINE_PER_CPU(struct vcpu_info, xen_vcpu_info); 60 + 61 + enum xen_domain_type xen_domain_type = XEN_NATIVE; 62 + EXPORT_SYMBOL_GPL(xen_domain_type); 59 63 60 64 /* 61 65 * Identity map, in addition to plain kernel map. This needs to be ··· 113 111 * 114 112 * 0: not available, 1: available 115 113 */ 116 - static int have_vcpu_info_placement = 1; 114 + static int have_vcpu_info_placement = 115 + #ifdef CONFIG_X86_32 116 + 1 117 + #else 118 + 0 119 + #endif 120 + ; 121 + 117 122 118 123 static void xen_vcpu_setup(int cpu) 119 124 { ··· 236 227 return HYPERVISOR_get_debugreg(reg); 237 228 } 238 229 239 - static unsigned long xen_save_fl(void) 240 - { 241 - struct vcpu_info *vcpu; 242 - unsigned long flags; 243 - 244 - vcpu = x86_read_percpu(xen_vcpu); 245 - 246 - /* flag has opposite sense of mask */ 247 - flags = !vcpu->evtchn_upcall_mask; 248 - 249 - /* convert to IF type flag 250 - -0 -> 0x00000000 251 - -1 -> 0xffffffff 252 - */ 253 - return (-flags) & X86_EFLAGS_IF; 254 - } 255 - 256 - static void xen_restore_fl(unsigned long flags) 257 - { 258 - struct vcpu_info *vcpu; 259 - 260 - /* convert from IF type flag */ 261 - flags = !(flags & X86_EFLAGS_IF); 262 - 263 - /* There's a one instruction preempt window here. We need to 264 - make sure we're don't switch CPUs between getting the vcpu 265 - pointer and updating the mask. */ 266 - preempt_disable(); 267 - vcpu = x86_read_percpu(xen_vcpu); 268 - vcpu->evtchn_upcall_mask = flags; 269 - preempt_enable_no_resched(); 270 - 271 - /* Doesn't matter if we get preempted here, because any 272 - pending event will get dealt with anyway. */ 273 - 274 - if (flags == 0) { 275 - preempt_check_resched(); 276 - barrier(); /* unmask then check (avoid races) */ 277 - if (unlikely(vcpu->evtchn_upcall_pending)) 278 - force_evtchn_callback(); 279 - } 280 - } 281 - 282 - static void xen_irq_disable(void) 283 - { 284 - /* There's a one instruction preempt window here. We need to 285 - make sure we're don't switch CPUs between getting the vcpu 286 - pointer and updating the mask. */ 287 - preempt_disable(); 288 - x86_read_percpu(xen_vcpu)->evtchn_upcall_mask = 1; 289 - preempt_enable_no_resched(); 290 - } 291 - 292 - static void xen_irq_enable(void) 293 - { 294 - struct vcpu_info *vcpu; 295 - 296 - /* We don't need to worry about being preempted here, since 297 - either a) interrupts are disabled, so no preemption, or b) 298 - the caller is confused and is trying to re-enable interrupts 299 - on an indeterminate processor. */ 300 - 301 - vcpu = x86_read_percpu(xen_vcpu); 302 - vcpu->evtchn_upcall_mask = 0; 303 - 304 - /* Doesn't matter if we get preempted here, because any 305 - pending event will get dealt with anyway. */ 306 - 307 - barrier(); /* unmask then check (avoid races) */ 308 - if (unlikely(vcpu->evtchn_upcall_pending)) 309 - force_evtchn_callback(); 310 - } 311 - 312 - static void xen_safe_halt(void) 313 - { 314 - /* Blocking includes an implicit local_irq_enable(). */ 315 - if (HYPERVISOR_sched_op(SCHEDOP_block, NULL) != 0) 316 - BUG(); 317 - } 318 - 319 - static void xen_halt(void) 320 - { 321 - if (irqs_disabled()) 322 - HYPERVISOR_vcpu_op(VCPUOP_down, smp_processor_id(), NULL); 323 - else 324 - xen_safe_halt(); 325 - } 326 - 327 230 static void xen_leave_lazy(void) 328 231 { 329 232 paravirt_leave_lazy(paravirt_get_lazy_mode()); ··· 245 324 static unsigned long xen_store_tr(void) 246 325 { 247 326 return 0; 327 + } 328 + 329 + /* 330 + * Set the page permissions for a particular virtual address. If the 331 + * address is a vmalloc mapping (or other non-linear mapping), then 332 + * find the linear mapping of the page and also set its protections to 333 + * match. 334 + */ 335 + static void set_aliased_prot(void *v, pgprot_t prot) 336 + { 337 + int level; 338 + pte_t *ptep; 339 + pte_t pte; 340 + unsigned long pfn; 341 + struct page *page; 342 + 343 + ptep = lookup_address((unsigned long)v, &level); 344 + BUG_ON(ptep == NULL); 345 + 346 + pfn = pte_pfn(*ptep); 347 + page = pfn_to_page(pfn); 348 + 349 + pte = pfn_pte(pfn, prot); 350 + 351 + if (HYPERVISOR_update_va_mapping((unsigned long)v, pte, 0)) 352 + BUG(); 353 + 354 + if (!PageHighMem(page)) { 355 + void *av = __va(PFN_PHYS(pfn)); 356 + 357 + if (av != v) 358 + if (HYPERVISOR_update_va_mapping((unsigned long)av, pte, 0)) 359 + BUG(); 360 + } else 361 + kmap_flush_unused(); 362 + } 363 + 364 + static void xen_alloc_ldt(struct desc_struct *ldt, unsigned entries) 365 + { 366 + const unsigned entries_per_page = PAGE_SIZE / LDT_ENTRY_SIZE; 367 + int i; 368 + 369 + for(i = 0; i < entries; i += entries_per_page) 370 + set_aliased_prot(ldt + i, PAGE_KERNEL_RO); 371 + } 372 + 373 + static void xen_free_ldt(struct desc_struct *ldt, unsigned entries) 374 + { 375 + const unsigned entries_per_page = PAGE_SIZE / LDT_ENTRY_SIZE; 376 + int i; 377 + 378 + for(i = 0; i < entries; i += entries_per_page) 379 + set_aliased_prot(ldt + i, PAGE_KERNEL); 248 380 } 249 381 250 382 static void xen_set_ldt(const void *addr, unsigned entries) ··· 400 426 static void xen_write_ldt_entry(struct desc_struct *dt, int entrynum, 401 427 const void *ptr) 402 428 { 403 - unsigned long lp = (unsigned long)&dt[entrynum]; 404 - xmaddr_t mach_lp = virt_to_machine(lp); 429 + xmaddr_t mach_lp = arbitrary_virt_to_machine(&dt[entrynum]); 405 430 u64 entry = *(u64 *)ptr; 406 431 407 432 preempt_disable(); ··· 533 560 } 534 561 535 562 static void xen_load_sp0(struct tss_struct *tss, 536 - struct thread_struct *thread) 563 + struct thread_struct *thread) 537 564 { 538 565 struct multicall_space mcs = xen_mc_entry(0); 539 566 MULTI_stack_switch(mcs.mc, __KERNEL_DS, thread->sp0); ··· 808 835 ret = -EFAULT; 809 836 break; 810 837 #endif 838 + 839 + case MSR_STAR: 840 + case MSR_CSTAR: 841 + case MSR_LSTAR: 842 + case MSR_SYSCALL_MASK: 843 + case MSR_IA32_SYSENTER_CS: 844 + case MSR_IA32_SYSENTER_ESP: 845 + case MSR_IA32_SYSENTER_EIP: 846 + /* Fast syscall setup is all done in hypercalls, so 847 + these are all ignored. Stub them out here to stop 848 + Xen console noise. */ 849 + break; 850 + 811 851 default: 812 852 ret = native_write_msr_safe(msr, low, high); 813 853 } ··· 864 878 SetPagePinned(page); 865 879 866 880 if (!PageHighMem(page)) { 867 - make_lowmem_page_readonly(__va(PFN_PHYS(pfn))); 868 - if (level == PT_PTE) 881 + make_lowmem_page_readonly(__va(PFN_PHYS((unsigned long)pfn))); 882 + if (level == PT_PTE && USE_SPLIT_PTLOCKS) 869 883 pin_pagetable_pfn(MMUEXT_PIN_L1_TABLE, pfn); 870 884 } else 871 885 /* make sure there are no stray mappings of ··· 933 947 934 948 if (PagePinned(page)) { 935 949 if (!PageHighMem(page)) { 936 - if (level == PT_PTE) 950 + if (level == PT_PTE && USE_SPLIT_PTLOCKS) 937 951 pin_pagetable_pfn(MMUEXT_UNPIN_TABLE, pfn); 938 952 make_lowmem_page_readwrite(__va(PFN_PHYS(pfn))); 939 953 } ··· 980 994 } 981 995 #endif 982 996 997 + #ifdef CONFIG_X86_32 983 998 static __init pte_t mask_rw_pte(pte_t *ptep, pte_t pte) 984 999 { 985 1000 /* If there's an existing pte, then don't allow _PAGE_RW to be set */ ··· 999 1012 1000 1013 xen_set_pte(ptep, pte); 1001 1014 } 1015 + #endif 1002 1016 1003 1017 static __init void xen_pagetable_setup_start(pgd_t *base) 1004 1018 { ··· 1066 1078 1067 1079 /* xen_vcpu_setup managed to place the vcpu_info within the 1068 1080 percpu area for all cpus, so make use of it */ 1069 - #ifdef CONFIG_X86_32 1070 1081 if (have_vcpu_info_placement) { 1071 1082 printk(KERN_INFO "Xen: using vcpu_info placement\n"); 1072 1083 ··· 1075 1088 pv_irq_ops.irq_enable = xen_irq_enable_direct; 1076 1089 pv_mmu_ops.read_cr2 = xen_read_cr2_direct; 1077 1090 } 1078 - #endif 1079 1091 } 1080 1092 1081 1093 static unsigned xen_patch(u8 type, u16 clobbers, void *insnbuf, ··· 1095 1109 goto patch_site 1096 1110 1097 1111 switch (type) { 1098 - #ifdef CONFIG_X86_32 1099 1112 SITE(pv_irq_ops, irq_enable); 1100 1113 SITE(pv_irq_ops, irq_disable); 1101 1114 SITE(pv_irq_ops, save_fl); 1102 1115 SITE(pv_irq_ops, restore_fl); 1103 - #endif /* CONFIG_X86_32 */ 1104 1116 #undef SITE 1105 1117 1106 1118 patch_site: ··· 1236 1252 .load_gs_index = xen_load_gs_index, 1237 1253 #endif 1238 1254 1255 + .alloc_ldt = xen_alloc_ldt, 1256 + .free_ldt = xen_free_ldt, 1257 + 1239 1258 .store_gdt = native_store_gdt, 1240 1259 .store_idt = native_store_idt, 1241 1260 .store_tr = xen_store_tr, ··· 1258 1271 .enter = paravirt_enter_lazy_cpu, 1259 1272 .leave = xen_leave_lazy, 1260 1273 }, 1261 - }; 1262 - 1263 - static void __init __xen_init_IRQ(void) 1264 - { 1265 - #ifdef CONFIG_X86_64 1266 - int i; 1267 - 1268 - /* Create identity vector->irq map */ 1269 - for(i = 0; i < NR_VECTORS; i++) { 1270 - int cpu; 1271 - 1272 - for_each_possible_cpu(cpu) 1273 - per_cpu(vector_irq, cpu)[i] = i; 1274 - } 1275 - #endif /* CONFIG_X86_64 */ 1276 - 1277 - xen_init_IRQ(); 1278 - } 1279 - 1280 - static const struct pv_irq_ops xen_irq_ops __initdata = { 1281 - .init_IRQ = __xen_init_IRQ, 1282 - .save_fl = xen_save_fl, 1283 - .restore_fl = xen_restore_fl, 1284 - .irq_disable = xen_irq_disable, 1285 - .irq_enable = xen_irq_enable, 1286 - .safe_halt = xen_safe_halt, 1287 - .halt = xen_halt, 1288 - #ifdef CONFIG_X86_64 1289 - .adjust_exception_frame = xen_adjust_exception_frame, 1290 - #endif 1291 1274 }; 1292 1275 1293 1276 static const struct pv_apic_ops xen_apic_ops __initdata = { ··· 1400 1443 if (HYPERVISOR_xen_version(XENVER_platform_parameters, &pp) == 0) 1401 1444 top = pp.virt_start; 1402 1445 1403 - reserve_top_address(-top + 2 * PAGE_SIZE); 1446 + reserve_top_address(-top); 1404 1447 #endif /* CONFIG_X86_32 */ 1405 1448 } 1406 1449 ··· 1434 1477 return __ka(m2p(maddr)); 1435 1478 } 1436 1479 1437 - #ifdef CONFIG_X86_64 1438 - static void walk(pgd_t *pgd, unsigned long addr) 1439 - { 1440 - unsigned l4idx = pgd_index(addr); 1441 - unsigned l3idx = pud_index(addr); 1442 - unsigned l2idx = pmd_index(addr); 1443 - unsigned l1idx = pte_index(addr); 1444 - pgd_t l4; 1445 - pud_t l3; 1446 - pmd_t l2; 1447 - pte_t l1; 1448 - 1449 - xen_raw_printk("walk %p, %lx -> %d %d %d %d\n", 1450 - pgd, addr, l4idx, l3idx, l2idx, l1idx); 1451 - 1452 - l4 = pgd[l4idx]; 1453 - xen_raw_printk(" l4: %016lx\n", l4.pgd); 1454 - xen_raw_printk(" %016lx\n", pgd_val(l4)); 1455 - 1456 - l3 = ((pud_t *)(m2v(l4.pgd)))[l3idx]; 1457 - xen_raw_printk(" l3: %016lx\n", l3.pud); 1458 - xen_raw_printk(" %016lx\n", pud_val(l3)); 1459 - 1460 - l2 = ((pmd_t *)(m2v(l3.pud)))[l2idx]; 1461 - xen_raw_printk(" l2: %016lx\n", l2.pmd); 1462 - xen_raw_printk(" %016lx\n", pmd_val(l2)); 1463 - 1464 - l1 = ((pte_t *)(m2v(l2.pmd)))[l1idx]; 1465 - xen_raw_printk(" l1: %016lx\n", l1.pte); 1466 - xen_raw_printk(" %016lx\n", pte_val(l1)); 1467 - } 1468 - #endif 1469 - 1470 1480 static void set_page_prot(void *addr, pgprot_t prot) 1471 1481 { 1472 1482 unsigned long pfn = __pa(addr) >> PAGE_SHIFT; 1473 1483 pte_t pte = pfn_pte(pfn, prot); 1474 - 1475 - xen_raw_printk("addr=%p pfn=%lx mfn=%lx prot=%016llx pte=%016llx\n", 1476 - addr, pfn, get_phys_to_machine(pfn), 1477 - pgprot_val(prot), pte.pte); 1478 1484 1479 1485 if (HYPERVISOR_update_va_mapping((unsigned long)addr, pte, 0)) 1480 1486 BUG(); ··· 1614 1694 if (!xen_start_info) 1615 1695 return; 1616 1696 1697 + xen_domain_type = XEN_PV_DOMAIN; 1698 + 1617 1699 BUG_ON(memcmp(xen_start_info->magic, "xen-3", 5) != 0); 1618 1700 1619 1701 xen_setup_features(); ··· 1625 1703 pv_init_ops = xen_init_ops; 1626 1704 pv_time_ops = xen_time_ops; 1627 1705 pv_cpu_ops = xen_cpu_ops; 1628 - pv_irq_ops = xen_irq_ops; 1629 1706 pv_apic_ops = xen_apic_ops; 1630 1707 pv_mmu_ops = xen_mmu_ops; 1708 + 1709 + xen_init_irq_ops(); 1631 1710 1632 1711 #ifdef CONFIG_X86_LOCAL_APIC 1633 1712 /* ··· 1660 1737 1661 1738 /* Prevent unwanted bits from being set in PTEs. */ 1662 1739 __supported_pte_mask &= ~_PAGE_GLOBAL; 1663 - if (!is_initial_xendomain()) 1740 + if (!xen_initial_domain()) 1664 1741 __supported_pte_mask &= ~(_PAGE_PWT | _PAGE_PCD); 1665 1742 1666 1743 /* Don't do the full vcpu_info placement stuff until we have a ··· 1695 1772 boot_params.hdr.ramdisk_size = xen_start_info->mod_len; 1696 1773 boot_params.hdr.cmd_line_ptr = __pa(xen_start_info->cmd_line); 1697 1774 1698 - if (!is_initial_xendomain()) { 1775 + if (!xen_initial_domain()) { 1699 1776 add_preferred_console("xenboot", 0, NULL); 1700 1777 add_preferred_console("tty", 0, NULL); 1701 1778 add_preferred_console("hvc", 0, NULL); 1702 1779 } 1703 1780 1704 1781 xen_raw_console_write("about to get started...\n"); 1705 - 1706 - #if 0 1707 - xen_raw_printk("&boot_params=%p __pa(&boot_params)=%lx __va(__pa(&boot_params))=%lx\n", 1708 - &boot_params, __pa_symbol(&boot_params), 1709 - __va(__pa_symbol(&boot_params))); 1710 - 1711 - walk(pgd, &boot_params); 1712 - walk(pgd, __va(__pa(&boot_params))); 1713 - #endif 1714 1782 1715 1783 /* Start the world */ 1716 1784 #ifdef CONFIG_X86_32
+143
arch/x86/xen/irq.c
··· 1 + #include <linux/hardirq.h> 2 + 3 + #include <xen/interface/xen.h> 4 + #include <xen/interface/sched.h> 5 + #include <xen/interface/vcpu.h> 6 + 7 + #include <asm/xen/hypercall.h> 8 + #include <asm/xen/hypervisor.h> 9 + 10 + #include "xen-ops.h" 11 + 12 + /* 13 + * Force a proper event-channel callback from Xen after clearing the 14 + * callback mask. We do this in a very simple manner, by making a call 15 + * down into Xen. The pending flag will be checked by Xen on return. 16 + */ 17 + void xen_force_evtchn_callback(void) 18 + { 19 + (void)HYPERVISOR_xen_version(0, NULL); 20 + } 21 + 22 + static void __init __xen_init_IRQ(void) 23 + { 24 + #ifdef CONFIG_X86_64 25 + int i; 26 + 27 + /* Create identity vector->irq map */ 28 + for(i = 0; i < NR_VECTORS; i++) { 29 + int cpu; 30 + 31 + for_each_possible_cpu(cpu) 32 + per_cpu(vector_irq, cpu)[i] = i; 33 + } 34 + #endif /* CONFIG_X86_64 */ 35 + 36 + xen_init_IRQ(); 37 + } 38 + 39 + static unsigned long xen_save_fl(void) 40 + { 41 + struct vcpu_info *vcpu; 42 + unsigned long flags; 43 + 44 + vcpu = x86_read_percpu(xen_vcpu); 45 + 46 + /* flag has opposite sense of mask */ 47 + flags = !vcpu->evtchn_upcall_mask; 48 + 49 + /* convert to IF type flag 50 + -0 -> 0x00000000 51 + -1 -> 0xffffffff 52 + */ 53 + return (-flags) & X86_EFLAGS_IF; 54 + } 55 + 56 + static void xen_restore_fl(unsigned long flags) 57 + { 58 + struct vcpu_info *vcpu; 59 + 60 + /* convert from IF type flag */ 61 + flags = !(flags & X86_EFLAGS_IF); 62 + 63 + /* There's a one instruction preempt window here. We need to 64 + make sure we're don't switch CPUs between getting the vcpu 65 + pointer and updating the mask. */ 66 + preempt_disable(); 67 + vcpu = x86_read_percpu(xen_vcpu); 68 + vcpu->evtchn_upcall_mask = flags; 69 + preempt_enable_no_resched(); 70 + 71 + /* Doesn't matter if we get preempted here, because any 72 + pending event will get dealt with anyway. */ 73 + 74 + if (flags == 0) { 75 + preempt_check_resched(); 76 + barrier(); /* unmask then check (avoid races) */ 77 + if (unlikely(vcpu->evtchn_upcall_pending)) 78 + xen_force_evtchn_callback(); 79 + } 80 + } 81 + 82 + static void xen_irq_disable(void) 83 + { 84 + /* There's a one instruction preempt window here. We need to 85 + make sure we're don't switch CPUs between getting the vcpu 86 + pointer and updating the mask. */ 87 + preempt_disable(); 88 + x86_read_percpu(xen_vcpu)->evtchn_upcall_mask = 1; 89 + preempt_enable_no_resched(); 90 + } 91 + 92 + static void xen_irq_enable(void) 93 + { 94 + struct vcpu_info *vcpu; 95 + 96 + /* We don't need to worry about being preempted here, since 97 + either a) interrupts are disabled, so no preemption, or b) 98 + the caller is confused and is trying to re-enable interrupts 99 + on an indeterminate processor. */ 100 + 101 + vcpu = x86_read_percpu(xen_vcpu); 102 + vcpu->evtchn_upcall_mask = 0; 103 + 104 + /* Doesn't matter if we get preempted here, because any 105 + pending event will get dealt with anyway. */ 106 + 107 + barrier(); /* unmask then check (avoid races) */ 108 + if (unlikely(vcpu->evtchn_upcall_pending)) 109 + xen_force_evtchn_callback(); 110 + } 111 + 112 + static void xen_safe_halt(void) 113 + { 114 + /* Blocking includes an implicit local_irq_enable(). */ 115 + if (HYPERVISOR_sched_op(SCHEDOP_block, NULL) != 0) 116 + BUG(); 117 + } 118 + 119 + static void xen_halt(void) 120 + { 121 + if (irqs_disabled()) 122 + HYPERVISOR_vcpu_op(VCPUOP_down, smp_processor_id(), NULL); 123 + else 124 + xen_safe_halt(); 125 + } 126 + 127 + static const struct pv_irq_ops xen_irq_ops __initdata = { 128 + .init_IRQ = __xen_init_IRQ, 129 + .save_fl = xen_save_fl, 130 + .restore_fl = xen_restore_fl, 131 + .irq_disable = xen_irq_disable, 132 + .irq_enable = xen_irq_enable, 133 + .safe_halt = xen_safe_halt, 134 + .halt = xen_halt, 135 + #ifdef CONFIG_X86_64 136 + .adjust_exception_frame = xen_adjust_exception_frame, 137 + #endif 138 + }; 139 + 140 + void __init xen_init_irq_ops() 141 + { 142 + pv_irq_ops = xen_irq_ops; 143 + }
+263 -51
arch/x86/xen/mmu.c
··· 40 40 */ 41 41 #include <linux/sched.h> 42 42 #include <linux/highmem.h> 43 + #include <linux/debugfs.h> 43 44 #include <linux/bug.h> 44 45 45 46 #include <asm/pgtable.h> ··· 58 57 59 58 #include "multicalls.h" 60 59 #include "mmu.h" 60 + #include "debugfs.h" 61 + 62 + #define MMU_UPDATE_HISTO 30 63 + 64 + #ifdef CONFIG_XEN_DEBUG_FS 65 + 66 + static struct { 67 + u32 pgd_update; 68 + u32 pgd_update_pinned; 69 + u32 pgd_update_batched; 70 + 71 + u32 pud_update; 72 + u32 pud_update_pinned; 73 + u32 pud_update_batched; 74 + 75 + u32 pmd_update; 76 + u32 pmd_update_pinned; 77 + u32 pmd_update_batched; 78 + 79 + u32 pte_update; 80 + u32 pte_update_pinned; 81 + u32 pte_update_batched; 82 + 83 + u32 mmu_update; 84 + u32 mmu_update_extended; 85 + u32 mmu_update_histo[MMU_UPDATE_HISTO]; 86 + 87 + u32 prot_commit; 88 + u32 prot_commit_batched; 89 + 90 + u32 set_pte_at; 91 + u32 set_pte_at_batched; 92 + u32 set_pte_at_pinned; 93 + u32 set_pte_at_current; 94 + u32 set_pte_at_kernel; 95 + } mmu_stats; 96 + 97 + static u8 zero_stats; 98 + 99 + static inline void check_zero(void) 100 + { 101 + if (unlikely(zero_stats)) { 102 + memset(&mmu_stats, 0, sizeof(mmu_stats)); 103 + zero_stats = 0; 104 + } 105 + } 106 + 107 + #define ADD_STATS(elem, val) \ 108 + do { check_zero(); mmu_stats.elem += (val); } while(0) 109 + 110 + #else /* !CONFIG_XEN_DEBUG_FS */ 111 + 112 + #define ADD_STATS(elem, val) do { (void)(val); } while(0) 113 + 114 + #endif /* CONFIG_XEN_DEBUG_FS */ 61 115 62 116 /* 63 117 * Just beyond the highest usermode address. STACK_TOP_MAX has a ··· 285 229 } 286 230 287 231 288 - static bool page_pinned(void *ptr) 232 + static bool xen_page_pinned(void *ptr) 289 233 { 290 234 struct page *page = virt_to_page(ptr); 291 235 292 236 return PagePinned(page); 293 237 } 294 238 295 - static void extend_mmu_update(const struct mmu_update *update) 239 + static void xen_extend_mmu_update(const struct mmu_update *update) 296 240 { 297 241 struct multicall_space mcs; 298 242 struct mmu_update *u; 299 243 300 244 mcs = xen_mc_extend_args(__HYPERVISOR_mmu_update, sizeof(*u)); 301 245 302 - if (mcs.mc != NULL) 246 + if (mcs.mc != NULL) { 247 + ADD_STATS(mmu_update_extended, 1); 248 + ADD_STATS(mmu_update_histo[mcs.mc->args[1]], -1); 249 + 303 250 mcs.mc->args[1]++; 304 - else { 251 + 252 + if (mcs.mc->args[1] < MMU_UPDATE_HISTO) 253 + ADD_STATS(mmu_update_histo[mcs.mc->args[1]], 1); 254 + else 255 + ADD_STATS(mmu_update_histo[0], 1); 256 + } else { 257 + ADD_STATS(mmu_update, 1); 305 258 mcs = __xen_mc_entry(sizeof(*u)); 306 259 MULTI_mmu_update(mcs.mc, mcs.args, 1, NULL, DOMID_SELF); 260 + ADD_STATS(mmu_update_histo[1], 1); 307 261 } 308 262 309 263 u = mcs.args; ··· 331 265 /* ptr may be ioremapped for 64-bit pagetable setup */ 332 266 u.ptr = arbitrary_virt_to_machine(ptr).maddr; 333 267 u.val = pmd_val_ma(val); 334 - extend_mmu_update(&u); 268 + xen_extend_mmu_update(&u); 269 + 270 + ADD_STATS(pmd_update_batched, paravirt_get_lazy_mode() == PARAVIRT_LAZY_MMU); 335 271 336 272 xen_mc_issue(PARAVIRT_LAZY_MMU); 337 273 ··· 342 274 343 275 void xen_set_pmd(pmd_t *ptr, pmd_t val) 344 276 { 277 + ADD_STATS(pmd_update, 1); 278 + 345 279 /* If page is not pinned, we can just update the entry 346 280 directly */ 347 - if (!page_pinned(ptr)) { 281 + if (!xen_page_pinned(ptr)) { 348 282 *ptr = val; 349 283 return; 350 284 } 285 + 286 + ADD_STATS(pmd_update_pinned, 1); 351 287 352 288 xen_set_pmd_hyper(ptr, val); 353 289 } ··· 372 300 if (mm == &init_mm) 373 301 preempt_disable(); 374 302 303 + ADD_STATS(set_pte_at, 1); 304 + // ADD_STATS(set_pte_at_pinned, xen_page_pinned(ptep)); 305 + ADD_STATS(set_pte_at_current, mm == current->mm); 306 + ADD_STATS(set_pte_at_kernel, mm == &init_mm); 307 + 375 308 if (mm == current->mm || mm == &init_mm) { 376 309 if (paravirt_get_lazy_mode() == PARAVIRT_LAZY_MMU) { 377 310 struct multicall_space mcs; 378 311 mcs = xen_mc_entry(0); 379 312 380 313 MULTI_update_va_mapping(mcs.mc, addr, pteval, 0); 314 + ADD_STATS(set_pte_at_batched, 1); 381 315 xen_mc_issue(PARAVIRT_LAZY_MMU); 382 316 goto out; 383 317 } else ··· 412 334 413 335 u.ptr = virt_to_machine(ptep).maddr | MMU_PT_UPDATE_PRESERVE_AD; 414 336 u.val = pte_val_ma(pte); 415 - extend_mmu_update(&u); 337 + xen_extend_mmu_update(&u); 338 + 339 + ADD_STATS(prot_commit, 1); 340 + ADD_STATS(prot_commit_batched, paravirt_get_lazy_mode() == PARAVIRT_LAZY_MMU); 416 341 417 342 xen_mc_issue(PARAVIRT_LAZY_MMU); 418 343 } ··· 481 400 /* ptr may be ioremapped for 64-bit pagetable setup */ 482 401 u.ptr = arbitrary_virt_to_machine(ptr).maddr; 483 402 u.val = pud_val_ma(val); 484 - extend_mmu_update(&u); 403 + xen_extend_mmu_update(&u); 404 + 405 + ADD_STATS(pud_update_batched, paravirt_get_lazy_mode() == PARAVIRT_LAZY_MMU); 485 406 486 407 xen_mc_issue(PARAVIRT_LAZY_MMU); 487 408 ··· 492 409 493 410 void xen_set_pud(pud_t *ptr, pud_t val) 494 411 { 412 + ADD_STATS(pud_update, 1); 413 + 495 414 /* If page is not pinned, we can just update the entry 496 415 directly */ 497 - if (!page_pinned(ptr)) { 416 + if (!xen_page_pinned(ptr)) { 498 417 *ptr = val; 499 418 return; 500 419 } 420 + 421 + ADD_STATS(pud_update_pinned, 1); 501 422 502 423 xen_set_pud_hyper(ptr, val); 503 424 } 504 425 505 426 void xen_set_pte(pte_t *ptep, pte_t pte) 506 427 { 428 + ADD_STATS(pte_update, 1); 429 + // ADD_STATS(pte_update_pinned, xen_page_pinned(ptep)); 430 + ADD_STATS(pte_update_batched, paravirt_get_lazy_mode() == PARAVIRT_LAZY_MMU); 431 + 507 432 #ifdef CONFIG_X86_PAE 508 433 ptep->pte_high = pte.pte_high; 509 434 smp_wmb(); ··· 581 490 582 491 u.ptr = virt_to_machine(ptr).maddr; 583 492 u.val = pgd_val_ma(val); 584 - extend_mmu_update(&u); 493 + xen_extend_mmu_update(&u); 585 494 } 586 495 587 496 /* ··· 608 517 { 609 518 pgd_t *user_ptr = xen_get_user_pgd(ptr); 610 519 520 + ADD_STATS(pgd_update, 1); 521 + 611 522 /* If page is not pinned, we can just update the entry 612 523 directly */ 613 - if (!page_pinned(ptr)) { 524 + if (!xen_page_pinned(ptr)) { 614 525 *ptr = val; 615 526 if (user_ptr) { 616 - WARN_ON(page_pinned(user_ptr)); 527 + WARN_ON(xen_page_pinned(user_ptr)); 617 528 *user_ptr = val; 618 529 } 619 530 return; 620 531 } 532 + 533 + ADD_STATS(pgd_update_pinned, 1); 534 + ADD_STATS(pgd_update_batched, paravirt_get_lazy_mode() == PARAVIRT_LAZY_MMU); 621 535 622 536 /* If it's pinned, then we can at least batch the kernel and 623 537 user updates together. */ ··· 651 555 * For 64-bit, we must skip the Xen hole in the middle of the address 652 556 * space, just after the big x86-64 virtual hole. 653 557 */ 654 - static int pgd_walk(pgd_t *pgd, int (*func)(struct page *, enum pt_level), 655 - unsigned long limit) 558 + static int xen_pgd_walk(struct mm_struct *mm, 559 + int (*func)(struct mm_struct *mm, struct page *, 560 + enum pt_level), 561 + unsigned long limit) 656 562 { 563 + pgd_t *pgd = mm->pgd; 657 564 int flush = 0; 658 565 unsigned hole_low, hole_high; 659 566 unsigned pgdidx_limit, pudidx_limit, pmdidx_limit; ··· 689 590 pmdidx_limit = 0; 690 591 #endif 691 592 692 - flush |= (*func)(virt_to_page(pgd), PT_PGD); 693 - 694 593 for (pgdidx = 0; pgdidx <= pgdidx_limit; pgdidx++) { 695 594 pud_t *pud; 696 595 ··· 701 604 pud = pud_offset(&pgd[pgdidx], 0); 702 605 703 606 if (PTRS_PER_PUD > 1) /* not folded */ 704 - flush |= (*func)(virt_to_page(pud), PT_PUD); 607 + flush |= (*func)(mm, virt_to_page(pud), PT_PUD); 705 608 706 609 for (pudidx = 0; pudidx < PTRS_PER_PUD; pudidx++) { 707 610 pmd_t *pmd; ··· 716 619 pmd = pmd_offset(&pud[pudidx], 0); 717 620 718 621 if (PTRS_PER_PMD > 1) /* not folded */ 719 - flush |= (*func)(virt_to_page(pmd), PT_PMD); 622 + flush |= (*func)(mm, virt_to_page(pmd), PT_PMD); 720 623 721 624 for (pmdidx = 0; pmdidx < PTRS_PER_PMD; pmdidx++) { 722 625 struct page *pte; ··· 730 633 continue; 731 634 732 635 pte = pmd_page(pmd[pmdidx]); 733 - flush |= (*func)(pte, PT_PTE); 636 + flush |= (*func)(mm, pte, PT_PTE); 734 637 } 735 638 } 736 639 } 640 + 737 641 out: 642 + /* Do the top level last, so that the callbacks can use it as 643 + a cue to do final things like tlb flushes. */ 644 + flush |= (*func)(mm, virt_to_page(pgd), PT_PGD); 738 645 739 646 return flush; 740 647 } 741 648 742 - static spinlock_t *lock_pte(struct page *page) 649 + /* If we're using split pte locks, then take the page's lock and 650 + return a pointer to it. Otherwise return NULL. */ 651 + static spinlock_t *xen_pte_lock(struct page *page, struct mm_struct *mm) 743 652 { 744 653 spinlock_t *ptl = NULL; 745 654 746 - #if NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS 655 + #if USE_SPLIT_PTLOCKS 747 656 ptl = __pte_lockptr(page); 748 - spin_lock(ptl); 657 + spin_lock_nest_lock(ptl, &mm->page_table_lock); 749 658 #endif 750 659 751 660 return ptl; 752 661 } 753 662 754 - static void do_unlock(void *v) 663 + static void xen_pte_unlock(void *v) 755 664 { 756 665 spinlock_t *ptl = v; 757 666 spin_unlock(ptl); ··· 775 672 MULTI_mmuext_op(mcs.mc, op, 1, NULL, DOMID_SELF); 776 673 } 777 674 778 - static int pin_page(struct page *page, enum pt_level level) 675 + static int xen_pin_page(struct mm_struct *mm, struct page *page, 676 + enum pt_level level) 779 677 { 780 678 unsigned pgfl = TestSetPagePinned(page); 781 679 int flush; ··· 795 691 796 692 flush = 0; 797 693 694 + /* 695 + * We need to hold the pagetable lock between the time 696 + * we make the pagetable RO and when we actually pin 697 + * it. If we don't, then other users may come in and 698 + * attempt to update the pagetable by writing it, 699 + * which will fail because the memory is RO but not 700 + * pinned, so Xen won't do the trap'n'emulate. 701 + * 702 + * If we're using split pte locks, we can't hold the 703 + * entire pagetable's worth of locks during the 704 + * traverse, because we may wrap the preempt count (8 705 + * bits). The solution is to mark RO and pin each PTE 706 + * page while holding the lock. This means the number 707 + * of locks we end up holding is never more than a 708 + * batch size (~32 entries, at present). 709 + * 710 + * If we're not using split pte locks, we needn't pin 711 + * the PTE pages independently, because we're 712 + * protected by the overall pagetable lock. 713 + */ 798 714 ptl = NULL; 799 715 if (level == PT_PTE) 800 - ptl = lock_pte(page); 716 + ptl = xen_pte_lock(page, mm); 801 717 802 718 MULTI_update_va_mapping(mcs.mc, (unsigned long)pt, 803 719 pfn_pte(pfn, PAGE_KERNEL_RO), 804 720 level == PT_PGD ? UVMF_TLB_FLUSH : 0); 805 721 806 - if (level == PT_PTE) 722 + if (ptl) { 807 723 xen_do_pin(MMUEXT_PIN_L1_TABLE, pfn); 808 724 809 - if (ptl) { 810 725 /* Queue a deferred unlock for when this batch 811 726 is completed. */ 812 - xen_mc_callback(do_unlock, ptl); 727 + xen_mc_callback(xen_pte_unlock, ptl); 813 728 } 814 729 } 815 730 ··· 838 715 /* This is called just after a mm has been created, but it has not 839 716 been used yet. We need to make sure that its pagetable is all 840 717 read-only, and can be pinned. */ 841 - void xen_pgd_pin(pgd_t *pgd) 718 + static void __xen_pgd_pin(struct mm_struct *mm, pgd_t *pgd) 842 719 { 843 720 xen_mc_batch(); 844 721 845 - if (pgd_walk(pgd, pin_page, USER_LIMIT)) { 722 + if (xen_pgd_walk(mm, xen_pin_page, USER_LIMIT)) { 846 723 /* re-enable interrupts for kmap_flush_unused */ 847 724 xen_mc_issue(0); 848 725 kmap_flush_unused(); ··· 856 733 xen_do_pin(MMUEXT_PIN_L4_TABLE, PFN_DOWN(__pa(pgd))); 857 734 858 735 if (user_pgd) { 859 - pin_page(virt_to_page(user_pgd), PT_PGD); 736 + xen_pin_page(mm, virt_to_page(user_pgd), PT_PGD); 860 737 xen_do_pin(MMUEXT_PIN_L4_TABLE, PFN_DOWN(__pa(user_pgd))); 861 738 } 862 739 } 863 740 #else /* CONFIG_X86_32 */ 864 741 #ifdef CONFIG_X86_PAE 865 742 /* Need to make sure unshared kernel PMD is pinnable */ 866 - pin_page(virt_to_page(pgd_page(pgd[pgd_index(TASK_SIZE)])), PT_PMD); 743 + xen_pin_page(mm, virt_to_page(pgd_page(pgd[pgd_index(TASK_SIZE)])), 744 + PT_PMD); 867 745 #endif 868 746 xen_do_pin(MMUEXT_PIN_L3_TABLE, PFN_DOWN(__pa(pgd))); 869 747 #endif /* CONFIG_X86_64 */ 870 748 xen_mc_issue(0); 749 + } 750 + 751 + static void xen_pgd_pin(struct mm_struct *mm) 752 + { 753 + __xen_pgd_pin(mm, mm->pgd); 871 754 } 872 755 873 756 /* ··· 881 752 * mfns turned into pfns. Search the list for any unpinned pgds and pin 882 753 * them (unpinned pgds are not currently in use, probably because the 883 754 * process is under construction or destruction). 755 + * 756 + * Expected to be called in stop_machine() ("equivalent to taking 757 + * every spinlock in the system"), so the locking doesn't really 758 + * matter all that much. 884 759 */ 885 760 void xen_mm_pin_all(void) 886 761 { ··· 895 762 896 763 list_for_each_entry(page, &pgd_list, lru) { 897 764 if (!PagePinned(page)) { 898 - xen_pgd_pin((pgd_t *)page_address(page)); 765 + __xen_pgd_pin(&init_mm, (pgd_t *)page_address(page)); 899 766 SetPageSavePinned(page); 900 767 } 901 768 } ··· 908 775 * that's before we have page structures to store the bits. So do all 909 776 * the book-keeping now. 910 777 */ 911 - static __init int mark_pinned(struct page *page, enum pt_level level) 778 + static __init int xen_mark_pinned(struct mm_struct *mm, struct page *page, 779 + enum pt_level level) 912 780 { 913 781 SetPagePinned(page); 914 782 return 0; ··· 917 783 918 784 void __init xen_mark_init_mm_pinned(void) 919 785 { 920 - pgd_walk(init_mm.pgd, mark_pinned, FIXADDR_TOP); 786 + xen_pgd_walk(&init_mm, xen_mark_pinned, FIXADDR_TOP); 921 787 } 922 788 923 - static int unpin_page(struct page *page, enum pt_level level) 789 + static int xen_unpin_page(struct mm_struct *mm, struct page *page, 790 + enum pt_level level) 924 791 { 925 792 unsigned pgfl = TestClearPagePinned(page); 926 793 ··· 931 796 spinlock_t *ptl = NULL; 932 797 struct multicall_space mcs; 933 798 799 + /* 800 + * Do the converse to pin_page. If we're using split 801 + * pte locks, we must be holding the lock for while 802 + * the pte page is unpinned but still RO to prevent 803 + * concurrent updates from seeing it in this 804 + * partially-pinned state. 805 + */ 934 806 if (level == PT_PTE) { 935 - ptl = lock_pte(page); 807 + ptl = xen_pte_lock(page, mm); 936 808 937 - xen_do_pin(MMUEXT_UNPIN_TABLE, pfn); 809 + if (ptl) 810 + xen_do_pin(MMUEXT_UNPIN_TABLE, pfn); 938 811 } 939 812 940 813 mcs = __xen_mc_entry(0); ··· 953 810 954 811 if (ptl) { 955 812 /* unlock when batch completed */ 956 - xen_mc_callback(do_unlock, ptl); 813 + xen_mc_callback(xen_pte_unlock, ptl); 957 814 } 958 815 } 959 816 ··· 961 818 } 962 819 963 820 /* Release a pagetables pages back as normal RW */ 964 - static void xen_pgd_unpin(pgd_t *pgd) 821 + static void __xen_pgd_unpin(struct mm_struct *mm, pgd_t *pgd) 965 822 { 966 823 xen_mc_batch(); 967 824 ··· 973 830 974 831 if (user_pgd) { 975 832 xen_do_pin(MMUEXT_UNPIN_TABLE, PFN_DOWN(__pa(user_pgd))); 976 - unpin_page(virt_to_page(user_pgd), PT_PGD); 833 + xen_unpin_page(mm, virt_to_page(user_pgd), PT_PGD); 977 834 } 978 835 } 979 836 #endif 980 837 981 838 #ifdef CONFIG_X86_PAE 982 839 /* Need to make sure unshared kernel PMD is unpinned */ 983 - pin_page(virt_to_page(pgd_page(pgd[pgd_index(TASK_SIZE)])), PT_PMD); 840 + xen_unpin_page(mm, virt_to_page(pgd_page(pgd[pgd_index(TASK_SIZE)])), 841 + PT_PMD); 984 842 #endif 985 843 986 - pgd_walk(pgd, unpin_page, USER_LIMIT); 844 + xen_pgd_walk(mm, xen_unpin_page, USER_LIMIT); 987 845 988 846 xen_mc_issue(0); 847 + } 848 + 849 + static void xen_pgd_unpin(struct mm_struct *mm) 850 + { 851 + __xen_pgd_unpin(mm, mm->pgd); 989 852 } 990 853 991 854 /* ··· 1008 859 list_for_each_entry(page, &pgd_list, lru) { 1009 860 if (PageSavePinned(page)) { 1010 861 BUG_ON(!PagePinned(page)); 1011 - xen_pgd_unpin((pgd_t *)page_address(page)); 862 + __xen_pgd_unpin(&init_mm, (pgd_t *)page_address(page)); 1012 863 ClearPageSavePinned(page); 1013 864 } 1014 865 } ··· 1019 870 void xen_activate_mm(struct mm_struct *prev, struct mm_struct *next) 1020 871 { 1021 872 spin_lock(&next->page_table_lock); 1022 - xen_pgd_pin(next->pgd); 873 + xen_pgd_pin(next); 1023 874 spin_unlock(&next->page_table_lock); 1024 875 } 1025 876 1026 877 void xen_dup_mmap(struct mm_struct *oldmm, struct mm_struct *mm) 1027 878 { 1028 879 spin_lock(&mm->page_table_lock); 1029 - xen_pgd_pin(mm->pgd); 880 + xen_pgd_pin(mm); 1030 881 spin_unlock(&mm->page_table_lock); 1031 882 } 1032 883 ··· 1056 907 } 1057 908 } 1058 909 1059 - static void drop_mm_ref(struct mm_struct *mm) 910 + static void xen_drop_mm_ref(struct mm_struct *mm) 1060 911 { 1061 912 cpumask_t mask; 1062 913 unsigned cpu; ··· 1086 937 smp_call_function_mask(mask, drop_other_mm_ref, mm, 1); 1087 938 } 1088 939 #else 1089 - static void drop_mm_ref(struct mm_struct *mm) 940 + static void xen_drop_mm_ref(struct mm_struct *mm) 1090 941 { 1091 942 if (current->active_mm == mm) 1092 943 load_cr3(swapper_pg_dir); ··· 1110 961 void xen_exit_mmap(struct mm_struct *mm) 1111 962 { 1112 963 get_cpu(); /* make sure we don't move around */ 1113 - drop_mm_ref(mm); 964 + xen_drop_mm_ref(mm); 1114 965 put_cpu(); 1115 966 1116 967 spin_lock(&mm->page_table_lock); 1117 968 1118 969 /* pgd may not be pinned in the error exit path of execve */ 1119 - if (page_pinned(mm->pgd)) 1120 - xen_pgd_unpin(mm->pgd); 970 + if (xen_page_pinned(mm->pgd)) 971 + xen_pgd_unpin(mm); 1121 972 1122 973 spin_unlock(&mm->page_table_lock); 1123 974 } 975 + 976 + #ifdef CONFIG_XEN_DEBUG_FS 977 + 978 + static struct dentry *d_mmu_debug; 979 + 980 + static int __init xen_mmu_debugfs(void) 981 + { 982 + struct dentry *d_xen = xen_init_debugfs(); 983 + 984 + if (d_xen == NULL) 985 + return -ENOMEM; 986 + 987 + d_mmu_debug = debugfs_create_dir("mmu", d_xen); 988 + 989 + debugfs_create_u8("zero_stats", 0644, d_mmu_debug, &zero_stats); 990 + 991 + debugfs_create_u32("pgd_update", 0444, d_mmu_debug, &mmu_stats.pgd_update); 992 + debugfs_create_u32("pgd_update_pinned", 0444, d_mmu_debug, 993 + &mmu_stats.pgd_update_pinned); 994 + debugfs_create_u32("pgd_update_batched", 0444, d_mmu_debug, 995 + &mmu_stats.pgd_update_pinned); 996 + 997 + debugfs_create_u32("pud_update", 0444, d_mmu_debug, &mmu_stats.pud_update); 998 + debugfs_create_u32("pud_update_pinned", 0444, d_mmu_debug, 999 + &mmu_stats.pud_update_pinned); 1000 + debugfs_create_u32("pud_update_batched", 0444, d_mmu_debug, 1001 + &mmu_stats.pud_update_pinned); 1002 + 1003 + debugfs_create_u32("pmd_update", 0444, d_mmu_debug, &mmu_stats.pmd_update); 1004 + debugfs_create_u32("pmd_update_pinned", 0444, d_mmu_debug, 1005 + &mmu_stats.pmd_update_pinned); 1006 + debugfs_create_u32("pmd_update_batched", 0444, d_mmu_debug, 1007 + &mmu_stats.pmd_update_pinned); 1008 + 1009 + debugfs_create_u32("pte_update", 0444, d_mmu_debug, &mmu_stats.pte_update); 1010 + // debugfs_create_u32("pte_update_pinned", 0444, d_mmu_debug, 1011 + // &mmu_stats.pte_update_pinned); 1012 + debugfs_create_u32("pte_update_batched", 0444, d_mmu_debug, 1013 + &mmu_stats.pte_update_pinned); 1014 + 1015 + debugfs_create_u32("mmu_update", 0444, d_mmu_debug, &mmu_stats.mmu_update); 1016 + debugfs_create_u32("mmu_update_extended", 0444, d_mmu_debug, 1017 + &mmu_stats.mmu_update_extended); 1018 + xen_debugfs_create_u32_array("mmu_update_histo", 0444, d_mmu_debug, 1019 + mmu_stats.mmu_update_histo, 20); 1020 + 1021 + debugfs_create_u32("set_pte_at", 0444, d_mmu_debug, &mmu_stats.set_pte_at); 1022 + debugfs_create_u32("set_pte_at_batched", 0444, d_mmu_debug, 1023 + &mmu_stats.set_pte_at_batched); 1024 + debugfs_create_u32("set_pte_at_current", 0444, d_mmu_debug, 1025 + &mmu_stats.set_pte_at_current); 1026 + debugfs_create_u32("set_pte_at_kernel", 0444, d_mmu_debug, 1027 + &mmu_stats.set_pte_at_kernel); 1028 + 1029 + debugfs_create_u32("prot_commit", 0444, d_mmu_debug, &mmu_stats.prot_commit); 1030 + debugfs_create_u32("prot_commit_batched", 0444, d_mmu_debug, 1031 + &mmu_stats.prot_commit_batched); 1032 + 1033 + return 0; 1034 + } 1035 + fs_initcall(xen_mmu_debugfs); 1036 + 1037 + #endif /* CONFIG_XEN_DEBUG_FS */
-3
arch/x86/xen/mmu.h
··· 18 18 void xen_dup_mmap(struct mm_struct *oldmm, struct mm_struct *mm); 19 19 void xen_exit_mmap(struct mm_struct *mm); 20 20 21 - void xen_pgd_pin(pgd_t *pgd); 22 - //void xen_pgd_unpin(pgd_t *pgd); 23 - 24 21 pteval_t xen_pte_val(pte_t); 25 22 pmdval_t xen_pmd_val(pmd_t); 26 23 pgdval_t xen_pgd_val(pgd_t);
+113 -2
arch/x86/xen/multicalls.c
··· 21 21 */ 22 22 #include <linux/percpu.h> 23 23 #include <linux/hardirq.h> 24 + #include <linux/debugfs.h> 24 25 25 26 #include <asm/xen/hypercall.h> 26 27 27 28 #include "multicalls.h" 29 + #include "debugfs.h" 30 + 31 + #define MC_BATCH 32 28 32 29 33 #define MC_DEBUG 1 30 34 31 - #define MC_BATCH 32 32 35 #define MC_ARGS (MC_BATCH * 16) 36 + 33 37 34 38 struct mc_buffer { 35 39 struct multicall_entry entries[MC_BATCH]; ··· 51 47 static DEFINE_PER_CPU(struct mc_buffer, mc_buffer); 52 48 DEFINE_PER_CPU(unsigned long, xen_mc_irq_flags); 53 49 50 + /* flush reasons 0- slots, 1- args, 2- callbacks */ 51 + enum flush_reasons 52 + { 53 + FL_SLOTS, 54 + FL_ARGS, 55 + FL_CALLBACKS, 56 + 57 + FL_N_REASONS 58 + }; 59 + 60 + #ifdef CONFIG_XEN_DEBUG_FS 61 + #define NHYPERCALLS 40 /* not really */ 62 + 63 + static struct { 64 + unsigned histo[MC_BATCH+1]; 65 + 66 + unsigned issued; 67 + unsigned arg_total; 68 + unsigned hypercalls; 69 + unsigned histo_hypercalls[NHYPERCALLS]; 70 + 71 + unsigned flush[FL_N_REASONS]; 72 + } mc_stats; 73 + 74 + static u8 zero_stats; 75 + 76 + static inline void check_zero(void) 77 + { 78 + if (unlikely(zero_stats)) { 79 + memset(&mc_stats, 0, sizeof(mc_stats)); 80 + zero_stats = 0; 81 + } 82 + } 83 + 84 + static void mc_add_stats(const struct mc_buffer *mc) 85 + { 86 + int i; 87 + 88 + check_zero(); 89 + 90 + mc_stats.issued++; 91 + mc_stats.hypercalls += mc->mcidx; 92 + mc_stats.arg_total += mc->argidx; 93 + 94 + mc_stats.histo[mc->mcidx]++; 95 + for(i = 0; i < mc->mcidx; i++) { 96 + unsigned op = mc->entries[i].op; 97 + if (op < NHYPERCALLS) 98 + mc_stats.histo_hypercalls[op]++; 99 + } 100 + } 101 + 102 + static void mc_stats_flush(enum flush_reasons idx) 103 + { 104 + check_zero(); 105 + 106 + mc_stats.flush[idx]++; 107 + } 108 + 109 + #else /* !CONFIG_XEN_DEBUG_FS */ 110 + 111 + static inline void mc_add_stats(const struct mc_buffer *mc) 112 + { 113 + } 114 + 115 + static inline void mc_stats_flush(enum flush_reasons idx) 116 + { 117 + } 118 + #endif /* CONFIG_XEN_DEBUG_FS */ 119 + 54 120 void xen_mc_flush(void) 55 121 { 56 122 struct mc_buffer *b = &__get_cpu_var(mc_buffer); ··· 133 59 /* Disable interrupts in case someone comes in and queues 134 60 something in the middle */ 135 61 local_irq_save(flags); 62 + 63 + mc_add_stats(b); 136 64 137 65 if (b->mcidx) { 138 66 #if MC_DEBUG ··· 191 115 192 116 if (b->mcidx == MC_BATCH || 193 117 (argidx + args) > MC_ARGS) { 118 + mc_stats_flush(b->mcidx == MC_BATCH ? FL_SLOTS : FL_ARGS); 194 119 xen_mc_flush(); 195 120 argidx = roundup(b->argidx, sizeof(u64)); 196 121 } ··· 235 158 struct mc_buffer *b = &__get_cpu_var(mc_buffer); 236 159 struct callback *cb; 237 160 238 - if (b->cbidx == MC_BATCH) 161 + if (b->cbidx == MC_BATCH) { 162 + mc_stats_flush(FL_CALLBACKS); 239 163 xen_mc_flush(); 164 + } 240 165 241 166 cb = &b->callbacks[b->cbidx++]; 242 167 cb->fn = fn; 243 168 cb->data = data; 244 169 } 170 + 171 + #ifdef CONFIG_XEN_DEBUG_FS 172 + 173 + static struct dentry *d_mc_debug; 174 + 175 + static int __init xen_mc_debugfs(void) 176 + { 177 + struct dentry *d_xen = xen_init_debugfs(); 178 + 179 + if (d_xen == NULL) 180 + return -ENOMEM; 181 + 182 + d_mc_debug = debugfs_create_dir("multicalls", d_xen); 183 + 184 + debugfs_create_u8("zero_stats", 0644, d_mc_debug, &zero_stats); 185 + 186 + debugfs_create_u32("batches", 0444, d_mc_debug, &mc_stats.issued); 187 + debugfs_create_u32("hypercalls", 0444, d_mc_debug, &mc_stats.hypercalls); 188 + debugfs_create_u32("arg_total", 0444, d_mc_debug, &mc_stats.arg_total); 189 + 190 + xen_debugfs_create_u32_array("batch_histo", 0444, d_mc_debug, 191 + mc_stats.histo, MC_BATCH); 192 + xen_debugfs_create_u32_array("hypercall_histo", 0444, d_mc_debug, 193 + mc_stats.histo_hypercalls, NHYPERCALLS); 194 + xen_debugfs_create_u32_array("flush_reasons", 0444, d_mc_debug, 195 + mc_stats.flush, FL_N_REASONS); 196 + 197 + return 0; 198 + } 199 + fs_initcall(xen_mc_debugfs); 200 + 201 + #endif /* CONFIG_XEN_DEBUG_FS */
+66 -179
arch/x86/xen/smp.c
··· 11 11 * useful topology information for the kernel to make use of. As a 12 12 * result, all CPUs are treated as if they're single-core and 13 13 * single-threaded. 14 - * 15 - * This does not handle HOTPLUG_CPU yet. 16 14 */ 17 15 #include <linux/sched.h> 18 - #include <linux/kernel_stat.h> 19 16 #include <linux/err.h> 20 17 #include <linux/smp.h> 21 18 ··· 32 35 33 36 #include "xen-ops.h" 34 37 #include "mmu.h" 35 - 36 - static void __cpuinit xen_init_lock_cpu(int cpu); 37 38 38 39 cpumask_t xen_cpu_initialized_map; 39 40 ··· 59 64 return IRQ_HANDLED; 60 65 } 61 66 62 - static __cpuinit void cpu_bringup_and_idle(void) 67 + static __cpuinit void cpu_bringup(void) 63 68 { 64 69 int cpu = smp_processor_id(); 65 70 66 71 cpu_init(); 72 + touch_softlockup_watchdog(); 67 73 preempt_disable(); 68 74 69 75 xen_enable_sysenter(); ··· 85 89 local_irq_enable(); 86 90 87 91 wmb(); /* make sure everything is out */ 92 + } 93 + 94 + static __cpuinit void cpu_bringup_and_idle(void) 95 + { 96 + cpu_bringup(); 88 97 cpu_idle(); 89 98 } 90 99 ··· 213 212 214 213 cpu_set(cpu, cpu_present_map); 215 214 } 216 - 217 - //init_xenbus_allowed_cpumask(); 218 215 } 219 216 220 217 static __cpuinit int ··· 280 281 struct task_struct *idle = idle_task(cpu); 281 282 int rc; 282 283 283 - #if 0 284 - rc = cpu_up_check(cpu); 285 - if (rc) 286 - return rc; 287 - #endif 288 - 289 284 #ifdef CONFIG_X86_64 290 285 /* Allocate node local memory for AP pdas */ 291 286 WARN_ON(cpu == 0); ··· 332 339 { 333 340 } 334 341 342 + #ifdef CONFIG_HOTPLUG_CPU 343 + static int xen_cpu_disable(void) 344 + { 345 + unsigned int cpu = smp_processor_id(); 346 + if (cpu == 0) 347 + return -EBUSY; 348 + 349 + cpu_disable_common(); 350 + 351 + load_cr3(swapper_pg_dir); 352 + return 0; 353 + } 354 + 355 + static void xen_cpu_die(unsigned int cpu) 356 + { 357 + while (HYPERVISOR_vcpu_op(VCPUOP_is_up, cpu, NULL)) { 358 + current->state = TASK_UNINTERRUPTIBLE; 359 + schedule_timeout(HZ/10); 360 + } 361 + unbind_from_irqhandler(per_cpu(resched_irq, cpu), NULL); 362 + unbind_from_irqhandler(per_cpu(callfunc_irq, cpu), NULL); 363 + unbind_from_irqhandler(per_cpu(debug_irq, cpu), NULL); 364 + unbind_from_irqhandler(per_cpu(callfuncsingle_irq, cpu), NULL); 365 + xen_uninit_lock_cpu(cpu); 366 + xen_teardown_timer(cpu); 367 + 368 + if (num_online_cpus() == 1) 369 + alternatives_smp_switch(0); 370 + } 371 + 372 + static void xen_play_dead(void) 373 + { 374 + play_dead_common(); 375 + HYPERVISOR_vcpu_op(VCPUOP_down, smp_processor_id(), NULL); 376 + cpu_bringup(); 377 + } 378 + 379 + #else /* !CONFIG_HOTPLUG_CPU */ 380 + static int xen_cpu_disable(void) 381 + { 382 + return -ENOSYS; 383 + } 384 + 385 + static void xen_cpu_die(unsigned int cpu) 386 + { 387 + BUG(); 388 + } 389 + 390 + static void xen_play_dead(void) 391 + { 392 + BUG(); 393 + } 394 + 395 + #endif 335 396 static void stop_self(void *v) 336 397 { 337 398 int cpu = smp_processor_id(); ··· 466 419 return IRQ_HANDLED; 467 420 } 468 421 469 - struct xen_spinlock { 470 - unsigned char lock; /* 0 -> free; 1 -> locked */ 471 - unsigned short spinners; /* count of waiting cpus */ 472 - }; 473 - 474 - static int xen_spin_is_locked(struct raw_spinlock *lock) 475 - { 476 - struct xen_spinlock *xl = (struct xen_spinlock *)lock; 477 - 478 - return xl->lock != 0; 479 - } 480 - 481 - static int xen_spin_is_contended(struct raw_spinlock *lock) 482 - { 483 - struct xen_spinlock *xl = (struct xen_spinlock *)lock; 484 - 485 - /* Not strictly true; this is only the count of contended 486 - lock-takers entering the slow path. */ 487 - return xl->spinners != 0; 488 - } 489 - 490 - static int xen_spin_trylock(struct raw_spinlock *lock) 491 - { 492 - struct xen_spinlock *xl = (struct xen_spinlock *)lock; 493 - u8 old = 1; 494 - 495 - asm("xchgb %b0,%1" 496 - : "+q" (old), "+m" (xl->lock) : : "memory"); 497 - 498 - return old == 0; 499 - } 500 - 501 - static DEFINE_PER_CPU(int, lock_kicker_irq) = -1; 502 - static DEFINE_PER_CPU(struct xen_spinlock *, lock_spinners); 503 - 504 - static inline void spinning_lock(struct xen_spinlock *xl) 505 - { 506 - __get_cpu_var(lock_spinners) = xl; 507 - wmb(); /* set lock of interest before count */ 508 - asm(LOCK_PREFIX " incw %0" 509 - : "+m" (xl->spinners) : : "memory"); 510 - } 511 - 512 - static inline void unspinning_lock(struct xen_spinlock *xl) 513 - { 514 - asm(LOCK_PREFIX " decw %0" 515 - : "+m" (xl->spinners) : : "memory"); 516 - wmb(); /* decrement count before clearing lock */ 517 - __get_cpu_var(lock_spinners) = NULL; 518 - } 519 - 520 - static noinline int xen_spin_lock_slow(struct raw_spinlock *lock) 521 - { 522 - struct xen_spinlock *xl = (struct xen_spinlock *)lock; 523 - int irq = __get_cpu_var(lock_kicker_irq); 524 - int ret; 525 - 526 - /* If kicker interrupts not initialized yet, just spin */ 527 - if (irq == -1) 528 - return 0; 529 - 530 - /* announce we're spinning */ 531 - spinning_lock(xl); 532 - 533 - /* clear pending */ 534 - xen_clear_irq_pending(irq); 535 - 536 - /* check again make sure it didn't become free while 537 - we weren't looking */ 538 - ret = xen_spin_trylock(lock); 539 - if (ret) 540 - goto out; 541 - 542 - /* block until irq becomes pending */ 543 - xen_poll_irq(irq); 544 - kstat_this_cpu.irqs[irq]++; 545 - 546 - out: 547 - unspinning_lock(xl); 548 - return ret; 549 - } 550 - 551 - static void xen_spin_lock(struct raw_spinlock *lock) 552 - { 553 - struct xen_spinlock *xl = (struct xen_spinlock *)lock; 554 - int timeout; 555 - u8 oldval; 556 - 557 - do { 558 - timeout = 1 << 10; 559 - 560 - asm("1: xchgb %1,%0\n" 561 - " testb %1,%1\n" 562 - " jz 3f\n" 563 - "2: rep;nop\n" 564 - " cmpb $0,%0\n" 565 - " je 1b\n" 566 - " dec %2\n" 567 - " jnz 2b\n" 568 - "3:\n" 569 - : "+m" (xl->lock), "=q" (oldval), "+r" (timeout) 570 - : "1" (1) 571 - : "memory"); 572 - 573 - } while (unlikely(oldval != 0 && !xen_spin_lock_slow(lock))); 574 - } 575 - 576 - static noinline void xen_spin_unlock_slow(struct xen_spinlock *xl) 577 - { 578 - int cpu; 579 - 580 - for_each_online_cpu(cpu) { 581 - /* XXX should mix up next cpu selection */ 582 - if (per_cpu(lock_spinners, cpu) == xl) { 583 - xen_send_IPI_one(cpu, XEN_SPIN_UNLOCK_VECTOR); 584 - break; 585 - } 586 - } 587 - } 588 - 589 - static void xen_spin_unlock(struct raw_spinlock *lock) 590 - { 591 - struct xen_spinlock *xl = (struct xen_spinlock *)lock; 592 - 593 - smp_wmb(); /* make sure no writes get moved after unlock */ 594 - xl->lock = 0; /* release lock */ 595 - 596 - /* make sure unlock happens before kick */ 597 - barrier(); 598 - 599 - if (unlikely(xl->spinners)) 600 - xen_spin_unlock_slow(xl); 601 - } 602 - 603 - static __cpuinit void xen_init_lock_cpu(int cpu) 604 - { 605 - int irq; 606 - const char *name; 607 - 608 - name = kasprintf(GFP_KERNEL, "spinlock%d", cpu); 609 - irq = bind_ipi_to_irqhandler(XEN_SPIN_UNLOCK_VECTOR, 610 - cpu, 611 - xen_reschedule_interrupt, 612 - IRQF_DISABLED|IRQF_PERCPU|IRQF_NOBALANCING, 613 - name, 614 - NULL); 615 - 616 - if (irq >= 0) { 617 - disable_irq(irq); /* make sure it's never delivered */ 618 - per_cpu(lock_kicker_irq, cpu) = irq; 619 - } 620 - 621 - printk("cpu %d spinlock event irq %d\n", cpu, irq); 622 - } 623 - 624 - static void __init xen_init_spinlocks(void) 625 - { 626 - pv_lock_ops.spin_is_locked = xen_spin_is_locked; 627 - pv_lock_ops.spin_is_contended = xen_spin_is_contended; 628 - pv_lock_ops.spin_lock = xen_spin_lock; 629 - pv_lock_ops.spin_trylock = xen_spin_trylock; 630 - pv_lock_ops.spin_unlock = xen_spin_unlock; 631 - } 632 - 633 422 static const struct smp_ops xen_smp_ops __initdata = { 634 423 .smp_prepare_boot_cpu = xen_smp_prepare_boot_cpu, 635 424 .smp_prepare_cpus = xen_smp_prepare_cpus, 636 - .cpu_up = xen_cpu_up, 637 425 .smp_cpus_done = xen_smp_cpus_done, 426 + 427 + .cpu_up = xen_cpu_up, 428 + .cpu_die = xen_cpu_die, 429 + .cpu_disable = xen_cpu_disable, 430 + .play_dead = xen_play_dead, 638 431 639 432 .smp_send_stop = xen_smp_send_stop, 640 433 .smp_send_reschedule = xen_smp_send_reschedule,
+428
arch/x86/xen/spinlock.c
··· 1 + /* 2 + * Split spinlock implementation out into its own file, so it can be 3 + * compiled in a FTRACE-compatible way. 4 + */ 5 + #include <linux/kernel_stat.h> 6 + #include <linux/spinlock.h> 7 + #include <linux/debugfs.h> 8 + #include <linux/log2.h> 9 + 10 + #include <asm/paravirt.h> 11 + 12 + #include <xen/interface/xen.h> 13 + #include <xen/events.h> 14 + 15 + #include "xen-ops.h" 16 + #include "debugfs.h" 17 + 18 + #ifdef CONFIG_XEN_DEBUG_FS 19 + static struct xen_spinlock_stats 20 + { 21 + u64 taken; 22 + u32 taken_slow; 23 + u32 taken_slow_nested; 24 + u32 taken_slow_pickup; 25 + u32 taken_slow_spurious; 26 + u32 taken_slow_irqenable; 27 + 28 + u64 released; 29 + u32 released_slow; 30 + u32 released_slow_kicked; 31 + 32 + #define HISTO_BUCKETS 30 33 + u32 histo_spin_total[HISTO_BUCKETS+1]; 34 + u32 histo_spin_spinning[HISTO_BUCKETS+1]; 35 + u32 histo_spin_blocked[HISTO_BUCKETS+1]; 36 + 37 + u64 time_total; 38 + u64 time_spinning; 39 + u64 time_blocked; 40 + } spinlock_stats; 41 + 42 + static u8 zero_stats; 43 + 44 + static unsigned lock_timeout = 1 << 10; 45 + #define TIMEOUT lock_timeout 46 + 47 + static inline void check_zero(void) 48 + { 49 + if (unlikely(zero_stats)) { 50 + memset(&spinlock_stats, 0, sizeof(spinlock_stats)); 51 + zero_stats = 0; 52 + } 53 + } 54 + 55 + #define ADD_STATS(elem, val) \ 56 + do { check_zero(); spinlock_stats.elem += (val); } while(0) 57 + 58 + static inline u64 spin_time_start(void) 59 + { 60 + return xen_clocksource_read(); 61 + } 62 + 63 + static void __spin_time_accum(u64 delta, u32 *array) 64 + { 65 + unsigned index = ilog2(delta); 66 + 67 + check_zero(); 68 + 69 + if (index < HISTO_BUCKETS) 70 + array[index]++; 71 + else 72 + array[HISTO_BUCKETS]++; 73 + } 74 + 75 + static inline void spin_time_accum_spinning(u64 start) 76 + { 77 + u32 delta = xen_clocksource_read() - start; 78 + 79 + __spin_time_accum(delta, spinlock_stats.histo_spin_spinning); 80 + spinlock_stats.time_spinning += delta; 81 + } 82 + 83 + static inline void spin_time_accum_total(u64 start) 84 + { 85 + u32 delta = xen_clocksource_read() - start; 86 + 87 + __spin_time_accum(delta, spinlock_stats.histo_spin_total); 88 + spinlock_stats.time_total += delta; 89 + } 90 + 91 + static inline void spin_time_accum_blocked(u64 start) 92 + { 93 + u32 delta = xen_clocksource_read() - start; 94 + 95 + __spin_time_accum(delta, spinlock_stats.histo_spin_blocked); 96 + spinlock_stats.time_blocked += delta; 97 + } 98 + #else /* !CONFIG_XEN_DEBUG_FS */ 99 + #define TIMEOUT (1 << 10) 100 + #define ADD_STATS(elem, val) do { (void)(val); } while(0) 101 + 102 + static inline u64 spin_time_start(void) 103 + { 104 + return 0; 105 + } 106 + 107 + static inline void spin_time_accum_total(u64 start) 108 + { 109 + } 110 + static inline void spin_time_accum_spinning(u64 start) 111 + { 112 + } 113 + static inline void spin_time_accum_blocked(u64 start) 114 + { 115 + } 116 + #endif /* CONFIG_XEN_DEBUG_FS */ 117 + 118 + struct xen_spinlock { 119 + unsigned char lock; /* 0 -> free; 1 -> locked */ 120 + unsigned short spinners; /* count of waiting cpus */ 121 + }; 122 + 123 + static int xen_spin_is_locked(struct raw_spinlock *lock) 124 + { 125 + struct xen_spinlock *xl = (struct xen_spinlock *)lock; 126 + 127 + return xl->lock != 0; 128 + } 129 + 130 + static int xen_spin_is_contended(struct raw_spinlock *lock) 131 + { 132 + struct xen_spinlock *xl = (struct xen_spinlock *)lock; 133 + 134 + /* Not strictly true; this is only the count of contended 135 + lock-takers entering the slow path. */ 136 + return xl->spinners != 0; 137 + } 138 + 139 + static int xen_spin_trylock(struct raw_spinlock *lock) 140 + { 141 + struct xen_spinlock *xl = (struct xen_spinlock *)lock; 142 + u8 old = 1; 143 + 144 + asm("xchgb %b0,%1" 145 + : "+q" (old), "+m" (xl->lock) : : "memory"); 146 + 147 + return old == 0; 148 + } 149 + 150 + static DEFINE_PER_CPU(int, lock_kicker_irq) = -1; 151 + static DEFINE_PER_CPU(struct xen_spinlock *, lock_spinners); 152 + 153 + /* 154 + * Mark a cpu as interested in a lock. Returns the CPU's previous 155 + * lock of interest, in case we got preempted by an interrupt. 156 + */ 157 + static inline struct xen_spinlock *spinning_lock(struct xen_spinlock *xl) 158 + { 159 + struct xen_spinlock *prev; 160 + 161 + prev = __get_cpu_var(lock_spinners); 162 + __get_cpu_var(lock_spinners) = xl; 163 + 164 + wmb(); /* set lock of interest before count */ 165 + 166 + asm(LOCK_PREFIX " incw %0" 167 + : "+m" (xl->spinners) : : "memory"); 168 + 169 + return prev; 170 + } 171 + 172 + /* 173 + * Mark a cpu as no longer interested in a lock. Restores previous 174 + * lock of interest (NULL for none). 175 + */ 176 + static inline void unspinning_lock(struct xen_spinlock *xl, struct xen_spinlock *prev) 177 + { 178 + asm(LOCK_PREFIX " decw %0" 179 + : "+m" (xl->spinners) : : "memory"); 180 + wmb(); /* decrement count before restoring lock */ 181 + __get_cpu_var(lock_spinners) = prev; 182 + } 183 + 184 + static noinline int xen_spin_lock_slow(struct raw_spinlock *lock, bool irq_enable) 185 + { 186 + struct xen_spinlock *xl = (struct xen_spinlock *)lock; 187 + struct xen_spinlock *prev; 188 + int irq = __get_cpu_var(lock_kicker_irq); 189 + int ret; 190 + unsigned long flags; 191 + u64 start; 192 + 193 + /* If kicker interrupts not initialized yet, just spin */ 194 + if (irq == -1) 195 + return 0; 196 + 197 + start = spin_time_start(); 198 + 199 + /* announce we're spinning */ 200 + prev = spinning_lock(xl); 201 + 202 + flags = __raw_local_save_flags(); 203 + if (irq_enable) { 204 + ADD_STATS(taken_slow_irqenable, 1); 205 + raw_local_irq_enable(); 206 + } 207 + 208 + ADD_STATS(taken_slow, 1); 209 + ADD_STATS(taken_slow_nested, prev != NULL); 210 + 211 + do { 212 + /* clear pending */ 213 + xen_clear_irq_pending(irq); 214 + 215 + /* check again make sure it didn't become free while 216 + we weren't looking */ 217 + ret = xen_spin_trylock(lock); 218 + if (ret) { 219 + ADD_STATS(taken_slow_pickup, 1); 220 + 221 + /* 222 + * If we interrupted another spinlock while it 223 + * was blocking, make sure it doesn't block 224 + * without rechecking the lock. 225 + */ 226 + if (prev != NULL) 227 + xen_set_irq_pending(irq); 228 + goto out; 229 + } 230 + 231 + /* 232 + * Block until irq becomes pending. If we're 233 + * interrupted at this point (after the trylock but 234 + * before entering the block), then the nested lock 235 + * handler guarantees that the irq will be left 236 + * pending if there's any chance the lock became free; 237 + * xen_poll_irq() returns immediately if the irq is 238 + * pending. 239 + */ 240 + xen_poll_irq(irq); 241 + ADD_STATS(taken_slow_spurious, !xen_test_irq_pending(irq)); 242 + } while (!xen_test_irq_pending(irq)); /* check for spurious wakeups */ 243 + 244 + kstat_this_cpu.irqs[irq]++; 245 + 246 + out: 247 + raw_local_irq_restore(flags); 248 + unspinning_lock(xl, prev); 249 + spin_time_accum_blocked(start); 250 + 251 + return ret; 252 + } 253 + 254 + static inline void __xen_spin_lock(struct raw_spinlock *lock, bool irq_enable) 255 + { 256 + struct xen_spinlock *xl = (struct xen_spinlock *)lock; 257 + unsigned timeout; 258 + u8 oldval; 259 + u64 start_spin; 260 + 261 + ADD_STATS(taken, 1); 262 + 263 + start_spin = spin_time_start(); 264 + 265 + do { 266 + u64 start_spin_fast = spin_time_start(); 267 + 268 + timeout = TIMEOUT; 269 + 270 + asm("1: xchgb %1,%0\n" 271 + " testb %1,%1\n" 272 + " jz 3f\n" 273 + "2: rep;nop\n" 274 + " cmpb $0,%0\n" 275 + " je 1b\n" 276 + " dec %2\n" 277 + " jnz 2b\n" 278 + "3:\n" 279 + : "+m" (xl->lock), "=q" (oldval), "+r" (timeout) 280 + : "1" (1) 281 + : "memory"); 282 + 283 + spin_time_accum_spinning(start_spin_fast); 284 + 285 + } while (unlikely(oldval != 0 && 286 + (TIMEOUT == ~0 || !xen_spin_lock_slow(lock, irq_enable)))); 287 + 288 + spin_time_accum_total(start_spin); 289 + } 290 + 291 + static void xen_spin_lock(struct raw_spinlock *lock) 292 + { 293 + __xen_spin_lock(lock, false); 294 + } 295 + 296 + static void xen_spin_lock_flags(struct raw_spinlock *lock, unsigned long flags) 297 + { 298 + __xen_spin_lock(lock, !raw_irqs_disabled_flags(flags)); 299 + } 300 + 301 + static noinline void xen_spin_unlock_slow(struct xen_spinlock *xl) 302 + { 303 + int cpu; 304 + 305 + ADD_STATS(released_slow, 1); 306 + 307 + for_each_online_cpu(cpu) { 308 + /* XXX should mix up next cpu selection */ 309 + if (per_cpu(lock_spinners, cpu) == xl) { 310 + ADD_STATS(released_slow_kicked, 1); 311 + xen_send_IPI_one(cpu, XEN_SPIN_UNLOCK_VECTOR); 312 + break; 313 + } 314 + } 315 + } 316 + 317 + static void xen_spin_unlock(struct raw_spinlock *lock) 318 + { 319 + struct xen_spinlock *xl = (struct xen_spinlock *)lock; 320 + 321 + ADD_STATS(released, 1); 322 + 323 + smp_wmb(); /* make sure no writes get moved after unlock */ 324 + xl->lock = 0; /* release lock */ 325 + 326 + /* make sure unlock happens before kick */ 327 + barrier(); 328 + 329 + if (unlikely(xl->spinners)) 330 + xen_spin_unlock_slow(xl); 331 + } 332 + 333 + static irqreturn_t dummy_handler(int irq, void *dev_id) 334 + { 335 + BUG(); 336 + return IRQ_HANDLED; 337 + } 338 + 339 + void __cpuinit xen_init_lock_cpu(int cpu) 340 + { 341 + int irq; 342 + const char *name; 343 + 344 + name = kasprintf(GFP_KERNEL, "spinlock%d", cpu); 345 + irq = bind_ipi_to_irqhandler(XEN_SPIN_UNLOCK_VECTOR, 346 + cpu, 347 + dummy_handler, 348 + IRQF_DISABLED|IRQF_PERCPU|IRQF_NOBALANCING, 349 + name, 350 + NULL); 351 + 352 + if (irq >= 0) { 353 + disable_irq(irq); /* make sure it's never delivered */ 354 + per_cpu(lock_kicker_irq, cpu) = irq; 355 + } 356 + 357 + printk("cpu %d spinlock event irq %d\n", cpu, irq); 358 + } 359 + 360 + void xen_uninit_lock_cpu(int cpu) 361 + { 362 + unbind_from_irqhandler(per_cpu(lock_kicker_irq, cpu), NULL); 363 + } 364 + 365 + void __init xen_init_spinlocks(void) 366 + { 367 + pv_lock_ops.spin_is_locked = xen_spin_is_locked; 368 + pv_lock_ops.spin_is_contended = xen_spin_is_contended; 369 + pv_lock_ops.spin_lock = xen_spin_lock; 370 + pv_lock_ops.spin_lock_flags = xen_spin_lock_flags; 371 + pv_lock_ops.spin_trylock = xen_spin_trylock; 372 + pv_lock_ops.spin_unlock = xen_spin_unlock; 373 + } 374 + 375 + #ifdef CONFIG_XEN_DEBUG_FS 376 + 377 + static struct dentry *d_spin_debug; 378 + 379 + static int __init xen_spinlock_debugfs(void) 380 + { 381 + struct dentry *d_xen = xen_init_debugfs(); 382 + 383 + if (d_xen == NULL) 384 + return -ENOMEM; 385 + 386 + d_spin_debug = debugfs_create_dir("spinlocks", d_xen); 387 + 388 + debugfs_create_u8("zero_stats", 0644, d_spin_debug, &zero_stats); 389 + 390 + debugfs_create_u32("timeout", 0644, d_spin_debug, &lock_timeout); 391 + 392 + debugfs_create_u64("taken", 0444, d_spin_debug, &spinlock_stats.taken); 393 + debugfs_create_u32("taken_slow", 0444, d_spin_debug, 394 + &spinlock_stats.taken_slow); 395 + debugfs_create_u32("taken_slow_nested", 0444, d_spin_debug, 396 + &spinlock_stats.taken_slow_nested); 397 + debugfs_create_u32("taken_slow_pickup", 0444, d_spin_debug, 398 + &spinlock_stats.taken_slow_pickup); 399 + debugfs_create_u32("taken_slow_spurious", 0444, d_spin_debug, 400 + &spinlock_stats.taken_slow_spurious); 401 + debugfs_create_u32("taken_slow_irqenable", 0444, d_spin_debug, 402 + &spinlock_stats.taken_slow_irqenable); 403 + 404 + debugfs_create_u64("released", 0444, d_spin_debug, &spinlock_stats.released); 405 + debugfs_create_u32("released_slow", 0444, d_spin_debug, 406 + &spinlock_stats.released_slow); 407 + debugfs_create_u32("released_slow_kicked", 0444, d_spin_debug, 408 + &spinlock_stats.released_slow_kicked); 409 + 410 + debugfs_create_u64("time_spinning", 0444, d_spin_debug, 411 + &spinlock_stats.time_spinning); 412 + debugfs_create_u64("time_blocked", 0444, d_spin_debug, 413 + &spinlock_stats.time_blocked); 414 + debugfs_create_u64("time_total", 0444, d_spin_debug, 415 + &spinlock_stats.time_total); 416 + 417 + xen_debugfs_create_u32_array("histo_total", 0444, d_spin_debug, 418 + spinlock_stats.histo_spin_total, HISTO_BUCKETS + 1); 419 + xen_debugfs_create_u32_array("histo_spinning", 0444, d_spin_debug, 420 + spinlock_stats.histo_spin_spinning, HISTO_BUCKETS + 1); 421 + xen_debugfs_create_u32_array("histo_blocked", 0444, d_spin_debug, 422 + spinlock_stats.histo_spin_blocked, HISTO_BUCKETS + 1); 423 + 424 + return 0; 425 + } 426 + fs_initcall(xen_spinlock_debugfs); 427 + 428 + #endif /* CONFIG_XEN_DEBUG_FS */
+9 -3
arch/x86/xen/time.c
··· 30 30 #define TIMER_SLOP 100000 31 31 #define NS_PER_TICK (1000000000LL / HZ) 32 32 33 - static cycle_t xen_clocksource_read(void); 34 - 35 33 /* runstate info updated by Xen */ 36 34 static DEFINE_PER_CPU(struct vcpu_runstate_info, runstate); 37 35 ··· 211 213 return xen_khz; 212 214 } 213 215 214 - static cycle_t xen_clocksource_read(void) 216 + cycle_t xen_clocksource_read(void) 215 217 { 216 218 struct pvclock_vcpu_time_info *src; 217 219 cycle_t ret; ··· 448 450 evt->irq = irq; 449 451 450 452 setup_runstate_info(cpu); 453 + } 454 + 455 + void xen_teardown_timer(int cpu) 456 + { 457 + struct clock_event_device *evt; 458 + BUG_ON(cpu == 0); 459 + evt = &per_cpu(xen_clock_events, cpu); 460 + unbind_from_irqhandler(evt->irq, NULL); 451 461 } 452 462 453 463 void xen_setup_cpu_clockevents(void)
+1 -1
arch/x86/xen/xen-asm_32.S
··· 298 298 push %eax 299 299 push %ecx 300 300 push %edx 301 - call force_evtchn_callback 301 + call xen_force_evtchn_callback 302 302 pop %edx 303 303 pop %ecx 304 304 pop %eax
+18 -4
arch/x86/xen/xen-asm_64.S
··· 26 26 /* Pseudo-flag used for virtual NMI, which we don't implement yet */ 27 27 #define XEN_EFLAGS_NMI 0x80000000 28 28 29 - #if 0 30 - #include <asm/percpu.h> 29 + #if 1 30 + /* 31 + x86-64 does not yet support direct access to percpu variables 32 + via a segment override, so we just need to make sure this code 33 + never gets used 34 + */ 35 + #define BUG ud2a 36 + #define PER_CPU_VAR(var, off) 0xdeadbeef 37 + #endif 31 38 32 39 /* 33 40 Enable events. This clears the event mask and tests the pending ··· 42 35 events, then enter the hypervisor to get them handled. 43 36 */ 44 37 ENTRY(xen_irq_enable_direct) 38 + BUG 39 + 45 40 /* Unmask events */ 46 41 movb $0, PER_CPU_VAR(xen_vcpu_info, XEN_vcpu_info_mask) 47 42 ··· 67 58 non-zero. 68 59 */ 69 60 ENTRY(xen_irq_disable_direct) 61 + BUG 62 + 70 63 movb $1, PER_CPU_VAR(xen_vcpu_info, XEN_vcpu_info_mask) 71 64 ENDPATCH(xen_irq_disable_direct) 72 65 ret ··· 85 74 Xen and x86 use opposite senses (mask vs enable). 86 75 */ 87 76 ENTRY(xen_save_fl_direct) 77 + BUG 78 + 88 79 testb $0xff, PER_CPU_VAR(xen_vcpu_info, XEN_vcpu_info_mask) 89 80 setz %ah 90 81 addb %ah,%ah ··· 104 91 if so. 105 92 */ 106 93 ENTRY(xen_restore_fl_direct) 94 + BUG 95 + 107 96 testb $X86_EFLAGS_IF>>8, %ah 108 97 setz PER_CPU_VAR(xen_vcpu_info, XEN_vcpu_info_mask) 109 98 /* Preempt here doesn't matter because that will deal with ··· 137 122 push %r9 138 123 push %r10 139 124 push %r11 140 - call force_evtchn_callback 125 + call xen_force_evtchn_callback 141 126 pop %r11 142 127 pop %r10 143 128 pop %r9 ··· 148 133 pop %rcx 149 134 pop %rax 150 135 ret 151 - #endif 152 136 153 137 ENTRY(xen_adjust_exception_frame) 154 138 mov 8+0(%rsp),%rcx
+8
arch/x86/xen/xen-ops.h
··· 2 2 #define XEN_OPS_H 3 3 4 4 #include <linux/init.h> 5 + #include <linux/clocksource.h> 5 6 #include <linux/irqreturn.h> 6 7 #include <xen/xen-ops.h> 7 8 ··· 32 31 33 32 void __init xen_build_dynamic_phys_to_machine(void); 34 33 34 + void xen_init_irq_ops(void); 35 35 void xen_setup_timer(int cpu); 36 + void xen_teardown_timer(int cpu); 37 + cycle_t xen_clocksource_read(void); 36 38 void xen_setup_cpu_clockevents(void); 37 39 unsigned long xen_tsc_khz(void); 38 40 void __init xen_time_init(void); ··· 53 49 54 50 #ifdef CONFIG_SMP 55 51 void xen_smp_init(void); 52 + 53 + void __init xen_init_spinlocks(void); 54 + __cpuinit void xen_init_lock_cpu(int cpu); 55 + void xen_uninit_lock_cpu(int cpu); 56 56 57 57 extern cpumask_t xen_cpu_initialized_map; 58 58 #else
+1 -1
drivers/block/xen-blkfront.c
··· 1066 1066 1067 1067 static int __init xlblk_init(void) 1068 1068 { 1069 - if (!is_running_on_xen()) 1069 + if (!xen_domain()) 1070 1070 return -ENODEV; 1071 1071 1072 1072 if (register_blkdev(XENVBD_MAJOR, DEV_NAME)) {
+3 -3
drivers/char/hvc_xen.c
··· 108 108 { 109 109 struct hvc_struct *hp; 110 110 111 - if (!is_running_on_xen() || 112 - is_initial_xendomain() || 111 + if (!xen_pv_domain() || 112 + xen_initial_domain() || 113 113 !xen_start_info->console.domU.evtchn) 114 114 return -ENODEV; 115 115 ··· 142 142 143 143 static int xen_cons_init(void) 144 144 { 145 - if (!is_running_on_xen()) 145 + if (!xen_pv_domain()) 146 146 return 0; 147 147 148 148 hvc_instantiate(HVC_COOKIE, 0, &hvc_ops);
+2 -2
drivers/input/xen-kbdfront.c
··· 335 335 336 336 static int __init xenkbd_init(void) 337 337 { 338 - if (!is_running_on_xen()) 338 + if (!xen_domain()) 339 339 return -ENODEV; 340 340 341 341 /* Nothing to do if running in dom0. */ 342 - if (is_initial_xendomain()) 342 + if (xen_initial_domain()) 343 343 return -ENODEV; 344 344 345 345 return xenbus_register_frontend(&xenkbd);
+3 -3
drivers/net/xen-netfront.c
··· 1794 1794 1795 1795 static int __init netif_init(void) 1796 1796 { 1797 - if (!is_running_on_xen()) 1797 + if (!xen_domain()) 1798 1798 return -ENODEV; 1799 1799 1800 - if (is_initial_xendomain()) 1800 + if (xen_initial_domain()) 1801 1801 return 0; 1802 1802 1803 1803 printk(KERN_INFO "Initialising Xen virtual ethernet driver.\n"); ··· 1809 1809 1810 1810 static void __exit netif_exit(void) 1811 1811 { 1812 - if (is_initial_xendomain()) 1812 + if (xen_initial_domain()) 1813 1813 return; 1814 1814 1815 1815 xenbus_unregister_driver(&netfront);
+1 -137
drivers/usb/host/ehci.h
··· 210 210 211 211 /*-------------------------------------------------------------------------*/ 212 212 213 - /* EHCI register interface, corresponds to EHCI Revision 0.95 specification */ 214 - 215 - /* Section 2.2 Host Controller Capability Registers */ 216 - struct ehci_caps { 217 - /* these fields are specified as 8 and 16 bit registers, 218 - * but some hosts can't perform 8 or 16 bit PCI accesses. 219 - */ 220 - u32 hc_capbase; 221 - #define HC_LENGTH(p) (((p)>>00)&0x00ff) /* bits 7:0 */ 222 - #define HC_VERSION(p) (((p)>>16)&0xffff) /* bits 31:16 */ 223 - u32 hcs_params; /* HCSPARAMS - offset 0x4 */ 224 - #define HCS_DEBUG_PORT(p) (((p)>>20)&0xf) /* bits 23:20, debug port? */ 225 - #define HCS_INDICATOR(p) ((p)&(1 << 16)) /* true: has port indicators */ 226 - #define HCS_N_CC(p) (((p)>>12)&0xf) /* bits 15:12, #companion HCs */ 227 - #define HCS_N_PCC(p) (((p)>>8)&0xf) /* bits 11:8, ports per CC */ 228 - #define HCS_PORTROUTED(p) ((p)&(1 << 7)) /* true: port routing */ 229 - #define HCS_PPC(p) ((p)&(1 << 4)) /* true: port power control */ 230 - #define HCS_N_PORTS(p) (((p)>>0)&0xf) /* bits 3:0, ports on HC */ 231 - 232 - u32 hcc_params; /* HCCPARAMS - offset 0x8 */ 233 - #define HCC_EXT_CAPS(p) (((p)>>8)&0xff) /* for pci extended caps */ 234 - #define HCC_ISOC_CACHE(p) ((p)&(1 << 7)) /* true: can cache isoc frame */ 235 - #define HCC_ISOC_THRES(p) (((p)>>4)&0x7) /* bits 6:4, uframes cached */ 236 - #define HCC_CANPARK(p) ((p)&(1 << 2)) /* true: can park on async qh */ 237 - #define HCC_PGM_FRAMELISTLEN(p) ((p)&(1 << 1)) /* true: periodic_size changes*/ 238 - #define HCC_64BIT_ADDR(p) ((p)&(1)) /* true: can use 64-bit addr */ 239 - u8 portroute [8]; /* nibbles for routing - offset 0xC */ 240 - } __attribute__ ((packed)); 241 - 242 - 243 - /* Section 2.3 Host Controller Operational Registers */ 244 - struct ehci_regs { 245 - 246 - /* USBCMD: offset 0x00 */ 247 - u32 command; 248 - /* 23:16 is r/w intr rate, in microframes; default "8" == 1/msec */ 249 - #define CMD_PARK (1<<11) /* enable "park" on async qh */ 250 - #define CMD_PARK_CNT(c) (((c)>>8)&3) /* how many transfers to park for */ 251 - #define CMD_LRESET (1<<7) /* partial reset (no ports, etc) */ 252 - #define CMD_IAAD (1<<6) /* "doorbell" interrupt async advance */ 253 - #define CMD_ASE (1<<5) /* async schedule enable */ 254 - #define CMD_PSE (1<<4) /* periodic schedule enable */ 255 - /* 3:2 is periodic frame list size */ 256 - #define CMD_RESET (1<<1) /* reset HC not bus */ 257 - #define CMD_RUN (1<<0) /* start/stop HC */ 258 - 259 - /* USBSTS: offset 0x04 */ 260 - u32 status; 261 - #define STS_ASS (1<<15) /* Async Schedule Status */ 262 - #define STS_PSS (1<<14) /* Periodic Schedule Status */ 263 - #define STS_RECL (1<<13) /* Reclamation */ 264 - #define STS_HALT (1<<12) /* Not running (any reason) */ 265 - /* some bits reserved */ 266 - /* these STS_* flags are also intr_enable bits (USBINTR) */ 267 - #define STS_IAA (1<<5) /* Interrupted on async advance */ 268 - #define STS_FATAL (1<<4) /* such as some PCI access errors */ 269 - #define STS_FLR (1<<3) /* frame list rolled over */ 270 - #define STS_PCD (1<<2) /* port change detect */ 271 - #define STS_ERR (1<<1) /* "error" completion (overflow, ...) */ 272 - #define STS_INT (1<<0) /* "normal" completion (short, ...) */ 273 - 274 - /* USBINTR: offset 0x08 */ 275 - u32 intr_enable; 276 - 277 - /* FRINDEX: offset 0x0C */ 278 - u32 frame_index; /* current microframe number */ 279 - /* CTRLDSSEGMENT: offset 0x10 */ 280 - u32 segment; /* address bits 63:32 if needed */ 281 - /* PERIODICLISTBASE: offset 0x14 */ 282 - u32 frame_list; /* points to periodic list */ 283 - /* ASYNCLISTADDR: offset 0x18 */ 284 - u32 async_next; /* address of next async queue head */ 285 - 286 - u32 reserved [9]; 287 - 288 - /* CONFIGFLAG: offset 0x40 */ 289 - u32 configured_flag; 290 - #define FLAG_CF (1<<0) /* true: we'll support "high speed" */ 291 - 292 - /* PORTSC: offset 0x44 */ 293 - u32 port_status [0]; /* up to N_PORTS */ 294 - /* 31:23 reserved */ 295 - #define PORT_WKOC_E (1<<22) /* wake on overcurrent (enable) */ 296 - #define PORT_WKDISC_E (1<<21) /* wake on disconnect (enable) */ 297 - #define PORT_WKCONN_E (1<<20) /* wake on connect (enable) */ 298 - /* 19:16 for port testing */ 299 - #define PORT_LED_OFF (0<<14) 300 - #define PORT_LED_AMBER (1<<14) 301 - #define PORT_LED_GREEN (2<<14) 302 - #define PORT_LED_MASK (3<<14) 303 - #define PORT_OWNER (1<<13) /* true: companion hc owns this port */ 304 - #define PORT_POWER (1<<12) /* true: has power (see PPC) */ 305 - #define PORT_USB11(x) (((x)&(3<<10))==(1<<10)) /* USB 1.1 device */ 306 - /* 11:10 for detecting lowspeed devices (reset vs release ownership) */ 307 - /* 9 reserved */ 308 - #define PORT_RESET (1<<8) /* reset port */ 309 - #define PORT_SUSPEND (1<<7) /* suspend port */ 310 - #define PORT_RESUME (1<<6) /* resume it */ 311 - #define PORT_OCC (1<<5) /* over current change */ 312 - #define PORT_OC (1<<4) /* over current active */ 313 - #define PORT_PEC (1<<3) /* port enable change */ 314 - #define PORT_PE (1<<2) /* port enable */ 315 - #define PORT_CSC (1<<1) /* connect status change */ 316 - #define PORT_CONNECT (1<<0) /* device connected */ 317 - #define PORT_RWC_BITS (PORT_CSC | PORT_PEC | PORT_OCC) 318 - } __attribute__ ((packed)); 319 - 320 - #define USBMODE 0x68 /* USB Device mode */ 321 - #define USBMODE_SDIS (1<<3) /* Stream disable */ 322 - #define USBMODE_BE (1<<2) /* BE/LE endianness select */ 323 - #define USBMODE_CM_HC (3<<0) /* host controller mode */ 324 - #define USBMODE_CM_IDLE (0<<0) /* idle state */ 325 - 326 - /* Appendix C, Debug port ... intended for use with special "debug devices" 327 - * that can help if there's no serial console. (nonstandard enumeration.) 328 - */ 329 - struct ehci_dbg_port { 330 - u32 control; 331 - #define DBGP_OWNER (1<<30) 332 - #define DBGP_ENABLED (1<<28) 333 - #define DBGP_DONE (1<<16) 334 - #define DBGP_INUSE (1<<10) 335 - #define DBGP_ERRCODE(x) (((x)>>7)&0x07) 336 - # define DBGP_ERR_BAD 1 337 - # define DBGP_ERR_SIGNAL 2 338 - #define DBGP_ERROR (1<<6) 339 - #define DBGP_GO (1<<5) 340 - #define DBGP_OUT (1<<4) 341 - #define DBGP_LEN(x) (((x)>>0)&0x0f) 342 - u32 pids; 343 - #define DBGP_PID_GET(x) (((x)>>16)&0xff) 344 - #define DBGP_PID_SET(data,tok) (((data)<<8)|(tok)) 345 - u32 data03; 346 - u32 data47; 347 - u32 address; 348 - #define DBGP_EPADDR(dev,ep) (((dev)<<8)|(ep)) 349 - } __attribute__ ((packed)); 213 + #include <linux/usb/ehci_def.h> 350 214 351 215 /*-------------------------------------------------------------------------*/ 352 216
-2
drivers/video/Kconfig
··· 673 673 select FB_CFB_FILLRECT 674 674 select FB_CFB_COPYAREA 675 675 select FB_CFB_IMAGEBLIT 676 - select VIDEO_SELECT 677 676 help 678 677 This is the frame buffer device driver for generic VESA 2.0 679 678 compliant graphic cards. The older VESA 1.2 cards are not supported. ··· 1577 1578 tristate "Cyberblade/i1 support" 1578 1579 depends on FB && PCI && X86_32 && !64BIT 1579 1580 select FB_CFB_IMAGEBLIT 1580 - select VIDEO_SELECT 1581 1581 ---help--- 1582 1582 This driver is supposed to support the Trident Cyberblade/i1 1583 1583 graphics core integrated in the VIA VT8601A North Bridge,
-16
drivers/video/console/Kconfig
··· 43 43 buffer. Each 64KB will give you approximately 16 80x25 44 44 screenfuls of scrollback buffer 45 45 46 - config VIDEO_SELECT 47 - bool "Video mode selection support" 48 - depends on X86 && VGA_CONSOLE 49 - ---help--- 50 - This enables support for text mode selection on kernel startup. If 51 - you want to take advantage of some high-resolution text mode your 52 - card's BIOS offers, but the traditional Linux utilities like 53 - SVGATextMode don't, you can say Y here and set the mode using the 54 - "vga=" option from your boot loader (lilo or loadlin) or set 55 - "vga=ask" which brings up a video mode menu on kernel startup. (Try 56 - "man bootparam" or see the documentation of your boot loader about 57 - how to pass options to the kernel.) 58 - 59 - Read the file <file:Documentation/svga.txt> for more information 60 - about the Video mode selection support. If unsure, say N. 61 - 62 46 config MDA_CONSOLE 63 47 depends on !M68K && !PARISC && ISA 64 48 tristate "MDA text console (dual-headed) (EXPERIMENTAL)"
+2 -2
drivers/video/xen-fbfront.c
··· 680 680 681 681 static int __init xenfb_init(void) 682 682 { 683 - if (!is_running_on_xen()) 683 + if (!xen_domain()) 684 684 return -ENODEV; 685 685 686 686 /* Nothing to do if running in dom0. */ 687 - if (is_initial_xendomain()) 687 + if (xen_initial_domain()) 688 688 return -ENODEV; 689 689 690 690 return xenbus_register_frontend(&xenfb);
+1
drivers/xen/Makefile
··· 1 1 obj-y += grant-table.o features.o events.o manage.o 2 2 obj-y += xenbus/ 3 + obj-$(CONFIG_HOTPLUG_CPU) += cpu_hotplug.o 3 4 obj-$(CONFIG_XEN_XENCOMM) += xencomm.o 4 5 obj-$(CONFIG_XEN_BALLOON) += balloon.o
+15 -160
drivers/xen/balloon.c
··· 53 53 #include <asm/tlb.h> 54 54 55 55 #include <xen/interface/memory.h> 56 - #include <xen/balloon.h> 57 56 #include <xen/xenbus.h> 58 57 #include <xen/features.h> 59 58 #include <xen/page.h> ··· 225 226 } 226 227 227 228 set_xen_guest_handle(reservation.extent_start, frame_list); 228 - reservation.nr_extents = nr_pages; 229 - rc = HYPERVISOR_memory_op( 230 - XENMEM_populate_physmap, &reservation); 229 + reservation.nr_extents = nr_pages; 230 + rc = HYPERVISOR_memory_op(XENMEM_populate_physmap, &reservation); 231 231 if (rc < nr_pages) { 232 232 if (rc > 0) { 233 233 int ret; ··· 234 236 /* We hit the Xen hard limit: reprobe. */ 235 237 reservation.nr_extents = rc; 236 238 ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, 237 - &reservation); 239 + &reservation); 238 240 BUG_ON(ret != rc); 239 241 } 240 242 if (rc >= 0) ··· 418 420 unsigned long pfn; 419 421 struct page *page; 420 422 421 - if (!is_running_on_xen()) 423 + if (!xen_pv_domain()) 422 424 return -ENODEV; 423 425 424 426 pr_info("xen_balloon: Initialising balloon driver.\n"); ··· 462 464 463 465 module_exit(balloon_exit); 464 466 465 - static void balloon_update_driver_allowance(long delta) 466 - { 467 - unsigned long flags; 468 - 469 - spin_lock_irqsave(&balloon_lock, flags); 470 - balloon_stats.driver_pages += delta; 471 - spin_unlock_irqrestore(&balloon_lock, flags); 472 - } 473 - 474 - static int dealloc_pte_fn( 475 - pte_t *pte, struct page *pmd_page, unsigned long addr, void *data) 476 - { 477 - unsigned long mfn = pte_mfn(*pte); 478 - int ret; 479 - struct xen_memory_reservation reservation = { 480 - .nr_extents = 1, 481 - .extent_order = 0, 482 - .domid = DOMID_SELF 483 - }; 484 - set_xen_guest_handle(reservation.extent_start, &mfn); 485 - set_pte_at(&init_mm, addr, pte, __pte_ma(0ull)); 486 - set_phys_to_machine(__pa(addr) >> PAGE_SHIFT, INVALID_P2M_ENTRY); 487 - ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation); 488 - BUG_ON(ret != 1); 489 - return 0; 490 - } 491 - 492 - static struct page **alloc_empty_pages_and_pagevec(int nr_pages) 493 - { 494 - unsigned long vaddr, flags; 495 - struct page *page, **pagevec; 496 - int i, ret; 497 - 498 - pagevec = kmalloc(sizeof(page) * nr_pages, GFP_KERNEL); 499 - if (pagevec == NULL) 500 - return NULL; 501 - 502 - for (i = 0; i < nr_pages; i++) { 503 - page = pagevec[i] = alloc_page(GFP_KERNEL); 504 - if (page == NULL) 505 - goto err; 506 - 507 - vaddr = (unsigned long)page_address(page); 508 - 509 - scrub_page(page); 510 - 511 - spin_lock_irqsave(&balloon_lock, flags); 512 - 513 - if (xen_feature(XENFEAT_auto_translated_physmap)) { 514 - unsigned long gmfn = page_to_pfn(page); 515 - struct xen_memory_reservation reservation = { 516 - .nr_extents = 1, 517 - .extent_order = 0, 518 - .domid = DOMID_SELF 519 - }; 520 - set_xen_guest_handle(reservation.extent_start, &gmfn); 521 - ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, 522 - &reservation); 523 - if (ret == 1) 524 - ret = 0; /* success */ 525 - } else { 526 - ret = apply_to_page_range(&init_mm, vaddr, PAGE_SIZE, 527 - dealloc_pte_fn, NULL); 528 - } 529 - 530 - if (ret != 0) { 531 - spin_unlock_irqrestore(&balloon_lock, flags); 532 - __free_page(page); 533 - goto err; 534 - } 535 - 536 - totalram_pages = --balloon_stats.current_pages; 537 - 538 - spin_unlock_irqrestore(&balloon_lock, flags); 539 - } 540 - 541 - out: 542 - schedule_work(&balloon_worker); 543 - flush_tlb_all(); 544 - return pagevec; 545 - 546 - err: 547 - spin_lock_irqsave(&balloon_lock, flags); 548 - while (--i >= 0) 549 - balloon_append(pagevec[i]); 550 - spin_unlock_irqrestore(&balloon_lock, flags); 551 - kfree(pagevec); 552 - pagevec = NULL; 553 - goto out; 554 - } 555 - 556 - static void free_empty_pages_and_pagevec(struct page **pagevec, int nr_pages) 557 - { 558 - unsigned long flags; 559 - int i; 560 - 561 - if (pagevec == NULL) 562 - return; 563 - 564 - spin_lock_irqsave(&balloon_lock, flags); 565 - for (i = 0; i < nr_pages; i++) { 566 - BUG_ON(page_count(pagevec[i]) != 1); 567 - balloon_append(pagevec[i]); 568 - } 569 - spin_unlock_irqrestore(&balloon_lock, flags); 570 - 571 - kfree(pagevec); 572 - 573 - schedule_work(&balloon_worker); 574 - } 575 - 576 - static void balloon_release_driver_page(struct page *page) 577 - { 578 - unsigned long flags; 579 - 580 - spin_lock_irqsave(&balloon_lock, flags); 581 - balloon_append(page); 582 - balloon_stats.driver_pages--; 583 - spin_unlock_irqrestore(&balloon_lock, flags); 584 - 585 - schedule_work(&balloon_worker); 586 - } 587 - 588 - 589 - #define BALLOON_SHOW(name, format, args...) \ 590 - static ssize_t show_##name(struct sys_device *dev, \ 591 - char *buf) \ 592 - { \ 593 - return sprintf(buf, format, ##args); \ 594 - } \ 467 + #define BALLOON_SHOW(name, format, args...) \ 468 + static ssize_t show_##name(struct sys_device *dev, \ 469 + struct sysdev_attribute *attr, \ 470 + char *buf) \ 471 + { \ 472 + return sprintf(buf, format, ##args); \ 473 + } \ 595 474 static SYSDEV_ATTR(name, S_IRUGO, show_##name, NULL) 596 475 597 476 BALLOON_SHOW(current_kb, "%lu\n", PAGES2KB(balloon_stats.current_pages)); ··· 479 604 (balloon_stats.hard_limit!=~0UL) ? PAGES2KB(balloon_stats.hard_limit) : 0); 480 605 BALLOON_SHOW(driver_kb, "%lu\n", PAGES2KB(balloon_stats.driver_pages)); 481 606 482 - static ssize_t show_target_kb(struct sys_device *dev, char *buf) 607 + static ssize_t show_target_kb(struct sys_device *dev, struct sysdev_attribute *attr, 608 + char *buf) 483 609 { 484 610 return sprintf(buf, "%lu\n", PAGES2KB(balloon_stats.target_pages)); 485 611 } ··· 490 614 const char *buf, 491 615 size_t count) 492 616 { 493 - char memstring[64], *endchar; 617 + char *endchar; 494 618 unsigned long long target_bytes; 495 619 496 620 if (!capable(CAP_SYS_ADMIN)) 497 621 return -EPERM; 498 622 499 - if (count <= 1) 500 - return -EBADMSG; /* runt */ 501 - if (count > sizeof(memstring)) 502 - return -EFBIG; /* too long */ 503 - strcpy(memstring, buf); 623 + target_bytes = memparse(buf, &endchar); 504 624 505 - target_bytes = memparse(memstring, &endchar); 506 625 balloon_set_new_target(target_bytes >> PAGE_SHIFT); 507 626 508 627 return count; ··· 563 692 sysdev_unregister(sysdev); 564 693 sysdev_class_unregister(&balloon_sysdev_class); 565 694 return error; 566 - } 567 - 568 - static void unregister_balloon(struct sys_device *sysdev) 569 - { 570 - int i; 571 - 572 - sysfs_remove_group(&sysdev->kobj, &balloon_info_group); 573 - for (i = 0; i < ARRAY_SIZE(balloon_attrs); i++) 574 - sysdev_remove_file(sysdev, balloon_attrs[i]); 575 - sysdev_unregister(sysdev); 576 - sysdev_class_unregister(&balloon_sysdev_class); 577 - } 578 - 579 - static void balloon_sysfs_exit(void) 580 - { 581 - unregister_balloon(&balloon_sysdev); 582 695 } 583 696 584 697 MODULE_LICENSE("GPL");
+90
drivers/xen/cpu_hotplug.c
··· 1 + #include <linux/notifier.h> 2 + 3 + #include <xen/xenbus.h> 4 + 5 + #include <asm-x86/xen/hypervisor.h> 6 + #include <asm/cpu.h> 7 + 8 + static void enable_hotplug_cpu(int cpu) 9 + { 10 + if (!cpu_present(cpu)) 11 + arch_register_cpu(cpu); 12 + 13 + cpu_set(cpu, cpu_present_map); 14 + } 15 + 16 + static void disable_hotplug_cpu(int cpu) 17 + { 18 + if (cpu_present(cpu)) 19 + arch_unregister_cpu(cpu); 20 + 21 + cpu_clear(cpu, cpu_present_map); 22 + } 23 + 24 + static void vcpu_hotplug(unsigned int cpu) 25 + { 26 + int err; 27 + char dir[32], state[32]; 28 + 29 + if (!cpu_possible(cpu)) 30 + return; 31 + 32 + sprintf(dir, "cpu/%u", cpu); 33 + err = xenbus_scanf(XBT_NIL, dir, "availability", "%s", state); 34 + if (err != 1) { 35 + printk(KERN_ERR "XENBUS: Unable to read cpu state\n"); 36 + return; 37 + } 38 + 39 + if (strcmp(state, "online") == 0) { 40 + enable_hotplug_cpu(cpu); 41 + } else if (strcmp(state, "offline") == 0) { 42 + (void)cpu_down(cpu); 43 + disable_hotplug_cpu(cpu); 44 + } else { 45 + printk(KERN_ERR "XENBUS: unknown state(%s) on CPU%d\n", 46 + state, cpu); 47 + } 48 + } 49 + 50 + static void handle_vcpu_hotplug_event(struct xenbus_watch *watch, 51 + const char **vec, unsigned int len) 52 + { 53 + unsigned int cpu; 54 + char *cpustr; 55 + const char *node = vec[XS_WATCH_PATH]; 56 + 57 + cpustr = strstr(node, "cpu/"); 58 + if (cpustr != NULL) { 59 + sscanf(cpustr, "cpu/%u", &cpu); 60 + vcpu_hotplug(cpu); 61 + } 62 + } 63 + 64 + static int setup_cpu_watcher(struct notifier_block *notifier, 65 + unsigned long event, void *data) 66 + { 67 + static struct xenbus_watch cpu_watch = { 68 + .node = "cpu", 69 + .callback = handle_vcpu_hotplug_event}; 70 + 71 + (void)register_xenbus_watch(&cpu_watch); 72 + 73 + return NOTIFY_DONE; 74 + } 75 + 76 + static int __init setup_vcpu_hotplug_event(void) 77 + { 78 + static struct notifier_block xsn_cpu = { 79 + .notifier_call = setup_cpu_watcher }; 80 + 81 + if (!xen_pv_domain()) 82 + return -ENODEV; 83 + 84 + register_xenstore_notifier(&xsn_cpu); 85 + 86 + return 0; 87 + } 88 + 89 + arch_initcall(setup_vcpu_hotplug_event); 90 +
+29 -11
drivers/xen/events.c
··· 84 84 /* Xen will never allocate port zero for any purpose. */ 85 85 #define VALID_EVTCHN(chn) ((chn) != 0) 86 86 87 - /* 88 - * Force a proper event-channel callback from Xen after clearing the 89 - * callback mask. We do this in a very simple manner, by making a call 90 - * down into Xen. The pending flag will be checked by Xen on return. 91 - */ 92 - void force_evtchn_callback(void) 93 - { 94 - (void)HYPERVISOR_xen_version(0, NULL); 95 - } 96 - EXPORT_SYMBOL_GPL(force_evtchn_callback); 97 - 98 87 static struct irq_chip xen_dynamic_chip; 99 88 100 89 /* Constructor for packed IRQ information. */ ··· 162 173 { 163 174 struct shared_info *s = HYPERVISOR_shared_info; 164 175 sync_set_bit(port, &s->evtchn_pending[0]); 176 + } 177 + 178 + static inline int test_evtchn(int port) 179 + { 180 + struct shared_info *s = HYPERVISOR_shared_info; 181 + return sync_test_bit(port, &s->evtchn_pending[0]); 165 182 } 166 183 167 184 ··· 358 363 switch (type_from_irq(irq)) { 359 364 case IRQT_VIRQ: 360 365 per_cpu(virq_to_irq, cpu_from_evtchn(evtchn)) 366 + [index_from_irq(irq)] = -1; 367 + break; 368 + case IRQT_IPI: 369 + per_cpu(ipi_to_irq, cpu_from_evtchn(evtchn)) 361 370 [index_from_irq(irq)] = -1; 362 371 break; 363 372 default: ··· 740 741 741 742 if (VALID_EVTCHN(evtchn)) 742 743 clear_evtchn(evtchn); 744 + } 745 + 746 + void xen_set_irq_pending(int irq) 747 + { 748 + int evtchn = evtchn_from_irq(irq); 749 + 750 + if (VALID_EVTCHN(evtchn)) 751 + set_evtchn(evtchn); 752 + } 753 + 754 + bool xen_test_irq_pending(int irq) 755 + { 756 + int evtchn = evtchn_from_irq(irq); 757 + bool ret = false; 758 + 759 + if (VALID_EVTCHN(evtchn)) 760 + ret = test_evtchn(evtchn); 761 + 762 + return ret; 743 763 } 744 764 745 765 /* Poll waiting for an irq to become pending. In the usual case, the
+1 -1
drivers/xen/grant-table.c
··· 508 508 unsigned int max_nr_glist_frames, nr_glist_frames; 509 509 unsigned int nr_init_grefs; 510 510 511 - if (!is_running_on_xen()) 511 + if (!xen_domain()) 512 512 return -ENODEV; 513 513 514 514 nr_grant_frames = 1;
+4 -4
drivers/xen/xenbus/xenbus_probe.c
··· 814 814 DPRINTK(""); 815 815 816 816 err = -ENODEV; 817 - if (!is_running_on_xen()) 817 + if (!xen_domain()) 818 818 goto out_error; 819 819 820 820 /* Register ourselves with the kernel bus subsystem */ ··· 829 829 /* 830 830 * Domain0 doesn't have a store_evtchn or store_mfn yet. 831 831 */ 832 - if (is_initial_xendomain()) { 832 + if (xen_initial_domain()) { 833 833 /* dom0 not yet supported */ 834 834 } else { 835 835 xenstored_ready = 1; ··· 846 846 goto out_unreg_back; 847 847 } 848 848 849 - if (!is_initial_xendomain()) 849 + if (!xen_initial_domain()) 850 850 xenbus_probe(NULL); 851 851 852 852 return 0; ··· 937 937 unsigned long timeout = jiffies + 10*HZ; 938 938 struct device_driver *drv = xendrv ? &xendrv->driver : NULL; 939 939 940 - if (!ready_to_wait_for_devices || !is_running_on_xen()) 940 + if (!ready_to_wait_for_devices || !xen_domain()) 941 941 return; 942 942 943 943 while (exists_disconnected_device(drv)) {
+2
include/asm-generic/siginfo.h
··· 199 199 */ 200 200 #define TRAP_BRKPT (__SI_FAULT|1) /* process breakpoint */ 201 201 #define TRAP_TRACE (__SI_FAULT|2) /* process trace trap */ 202 + #define TRAP_BRANCH (__SI_FAULT|3) /* process taken branch trap */ 203 + #define TRAP_HWBKPT (__SI_FAULT|4) /* hardware breakpoint/watchpoint */ 202 204 #define NSIGTRAP 2 203 205 204 206 /*
-5
include/asm-parisc/siginfo.h
··· 3 3 4 4 #include <asm-generic/siginfo.h> 5 5 6 - /* 7 - * SIGTRAP si_codes 8 - */ 9 - #define TRAP_BRANCH (__SI_FAULT|3) /* process taken branch trap */ 10 - #define TRAP_HWBKPT (__SI_FAULT|4) /* hardware breakpoint or watchpoint */ 11 6 #undef NSIGTRAP 12 7 #define NSIGTRAP 4 13 8
+17
include/asm-x86/bios_ebda.h
··· 16 16 17 17 void reserve_ebda_region(void); 18 18 19 + #ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION 20 + /* 21 + * This is obviously not a great place for this, but we want to be 22 + * able to scatter it around anywhere in the kernel. 23 + */ 24 + void check_for_bios_corruption(void); 25 + void start_periodic_check_for_corruption(void); 26 + #else 27 + static inline void check_for_bios_corruption(void) 28 + { 29 + } 30 + 31 + static inline void start_periodic_check_for_corruption(void) 32 + { 33 + } 34 + #endif 35 + 19 36 #endif /* ASM_X86__BIOS_EBDA_H */
-2
include/asm-x86/boot.h
··· 2 2 #define ASM_X86__BOOT_H 3 3 4 4 /* Don't touch these, unless you really know what you're doing. */ 5 - #define DEF_INITSEG 0x9000 6 5 #define DEF_SYSSEG 0x1000 7 - #define DEF_SETUPSEG 0x9020 8 6 #define DEF_SYSSIZE 0x7F00 9 7 10 8 /* Internal svga startup constants */
+14 -1
include/asm-x86/desc.h
··· 24 24 desc->d = info->seg_32bit; 25 25 desc->g = info->limit_in_pages; 26 26 desc->base2 = (info->base_addr & 0xff000000) >> 24; 27 + /* 28 + * Don't allow setting of the lm bit. It is useless anyway 29 + * because 64bit system calls require __USER_CS: 30 + */ 31 + desc->l = 0; 27 32 } 28 33 29 34 extern struct desc_ptr idt_descr; ··· 102 97 native_write_gdt_entry(dt, entry, desc, type) 103 98 #define write_idt_entry(dt, entry, g) \ 104 99 native_write_idt_entry(dt, entry, g) 105 - #endif 100 + 101 + static inline void paravirt_alloc_ldt(struct desc_struct *ldt, unsigned entries) 102 + { 103 + } 104 + 105 + static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries) 106 + { 107 + } 108 + #endif /* CONFIG_PARAVIRT */ 106 109 107 110 static inline void native_write_idt_entry(gate_desc *idt, int entry, 108 111 const gate_desc *gate)
+47
include/asm-x86/microcode.h
··· 1 + #ifndef ASM_X86__MICROCODE_H 2 + #define ASM_X86__MICROCODE_H 3 + 4 + struct cpu_signature { 5 + unsigned int sig; 6 + unsigned int pf; 7 + unsigned int rev; 8 + }; 9 + 10 + struct device; 11 + 12 + struct microcode_ops { 13 + int (*request_microcode_user) (int cpu, const void __user *buf, size_t size); 14 + int (*request_microcode_fw) (int cpu, struct device *device); 15 + 16 + void (*apply_microcode) (int cpu); 17 + 18 + int (*collect_cpu_info) (int cpu, struct cpu_signature *csig); 19 + void (*microcode_fini_cpu) (int cpu); 20 + }; 21 + 22 + struct ucode_cpu_info { 23 + struct cpu_signature cpu_sig; 24 + int valid; 25 + void *mc; 26 + }; 27 + extern struct ucode_cpu_info ucode_cpu_info[]; 28 + 29 + #ifdef CONFIG_MICROCODE_INTEL 30 + extern struct microcode_ops * __init init_intel_microcode(void); 31 + #else 32 + static inline struct microcode_ops * __init init_intel_microcode(void) 33 + { 34 + return NULL; 35 + } 36 + #endif /* CONFIG_MICROCODE_INTEL */ 37 + 38 + #ifdef CONFIG_MICROCODE_AMD 39 + extern struct microcode_ops * __init init_amd_microcode(void); 40 + #else 41 + static inline struct microcode_ops * __init init_amd_microcode(void) 42 + { 43 + return NULL; 44 + } 45 + #endif 46 + 47 + #endif /* ASM_X86__MICROCODE_H */
+1 -2
include/asm-x86/mmzone_64.h
··· 7 7 8 8 #ifdef CONFIG_NUMA 9 9 10 - #define VIRTUAL_BUG_ON(x) 10 + #include <linux/mmdebug.h> 11 11 12 12 #include <asm/smp.h> 13 13 ··· 29 29 { 30 30 unsigned nid; 31 31 VIRTUAL_BUG_ON(!memnodemap); 32 - VIRTUAL_BUG_ON((addr >> memnode_shift) >= memnodemapsize); 33 32 nid = memnodemap[addr >> memnode_shift]; 34 33 VIRTUAL_BUG_ON(nid >= MAX_NUMNODES || !node_data[nid]); 35 34 return nid;
+5
include/asm-x86/page_32.h
··· 73 73 #endif 74 74 75 75 #ifndef __ASSEMBLY__ 76 + #define __phys_addr_const(x) ((x) - PAGE_OFFSET) 77 + #ifdef CONFIG_DEBUG_VIRTUAL 78 + extern unsigned long __phys_addr(unsigned long); 79 + #else 76 80 #define __phys_addr(x) ((x) - PAGE_OFFSET) 81 + #endif 77 82 #define __phys_reloc_hide(x) RELOC_HIDE((x), 0) 78 83 79 84 #ifdef CONFIG_FLATMEM
+20
include/asm-x86/paravirt.h
··· 124 124 int entrynum, const void *desc, int size); 125 125 void (*write_idt_entry)(gate_desc *, 126 126 int entrynum, const gate_desc *gate); 127 + void (*alloc_ldt)(struct desc_struct *ldt, unsigned entries); 128 + void (*free_ldt)(struct desc_struct *ldt, unsigned entries); 129 + 127 130 void (*load_sp0)(struct tss_struct *tss, struct thread_struct *t); 128 131 129 132 void (*set_iopl_mask)(unsigned mask); ··· 328 325 int (*spin_is_locked)(struct raw_spinlock *lock); 329 326 int (*spin_is_contended)(struct raw_spinlock *lock); 330 327 void (*spin_lock)(struct raw_spinlock *lock); 328 + void (*spin_lock_flags)(struct raw_spinlock *lock, unsigned long flags); 331 329 int (*spin_trylock)(struct raw_spinlock *lock); 332 330 void (*spin_unlock)(struct raw_spinlock *lock); 333 331 }; ··· 833 829 val = paravirt_rdtscp(&__aux); \ 834 830 (aux) = __aux; \ 835 831 } while (0) 832 + 833 + static inline void paravirt_alloc_ldt(struct desc_struct *ldt, unsigned entries) 834 + { 835 + PVOP_VCALL2(pv_cpu_ops.alloc_ldt, ldt, entries); 836 + } 837 + 838 + static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries) 839 + { 840 + PVOP_VCALL2(pv_cpu_ops.free_ldt, ldt, entries); 841 + } 836 842 837 843 static inline void load_TR_desc(void) 838 844 { ··· 1406 1392 static __always_inline void __raw_spin_lock(struct raw_spinlock *lock) 1407 1393 { 1408 1394 PVOP_VCALL1(pv_lock_ops.spin_lock, lock); 1395 + } 1396 + 1397 + static __always_inline void __raw_spin_lock_flags(struct raw_spinlock *lock, 1398 + unsigned long flags) 1399 + { 1400 + PVOP_VCALL2(pv_lock_ops.spin_lock_flags, lock, flags); 1409 1401 } 1410 1402 1411 1403 static __always_inline int __raw_spin_trylock(struct raw_spinlock *lock)
-35
include/asm-x86/processor.h
··· 586 586 write_cr4(cr4); 587 587 } 588 588 589 - struct microcode_header { 590 - unsigned int hdrver; 591 - unsigned int rev; 592 - unsigned int date; 593 - unsigned int sig; 594 - unsigned int cksum; 595 - unsigned int ldrver; 596 - unsigned int pf; 597 - unsigned int datasize; 598 - unsigned int totalsize; 599 - unsigned int reserved[3]; 600 - }; 601 - 602 - struct microcode { 603 - struct microcode_header hdr; 604 - unsigned int bits[0]; 605 - }; 606 - 607 - typedef struct microcode microcode_t; 608 - typedef struct microcode_header microcode_header_t; 609 - 610 - /* microcode format is extended from prescott processors */ 611 - struct extended_signature { 612 - unsigned int sig; 613 - unsigned int pf; 614 - unsigned int cksum; 615 - }; 616 - 617 - struct extended_sigtable { 618 - unsigned int count; 619 - unsigned int cksum; 620 - unsigned int reserved[3]; 621 - struct extended_signature sigs[0]; 622 - }; 623 - 624 589 typedef struct { 625 590 unsigned long seg; 626 591 } mm_segment_t;
+3 -3
include/asm-x86/ptrace.h
··· 177 177 178 178 #ifdef CONFIG_X86_32 179 179 extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, 180 - int error_code); 181 - #else 182 - void signal_fault(struct pt_regs *regs, void __user *frame, char *where); 180 + int error_code, int si_code); 183 181 #endif 182 + 183 + void signal_fault(struct pt_regs *regs, void __user *frame, char *where); 184 184 185 185 extern long syscall_trace_enter(struct pt_regs *); 186 186 extern void syscall_trace_leave(struct pt_regs *);
+26 -8
include/asm-x86/smp.h
··· 50 50 struct smp_ops { 51 51 void (*smp_prepare_boot_cpu)(void); 52 52 void (*smp_prepare_cpus)(unsigned max_cpus); 53 - int (*cpu_up)(unsigned cpu); 54 53 void (*smp_cpus_done)(unsigned max_cpus); 55 54 56 55 void (*smp_send_stop)(void); 57 56 void (*smp_send_reschedule)(int cpu); 57 + 58 + int (*cpu_up)(unsigned cpu); 59 + int (*cpu_disable)(void); 60 + void (*cpu_die)(unsigned int cpu); 61 + void (*play_dead)(void); 58 62 59 63 void (*send_call_func_ipi)(cpumask_t mask); 60 64 void (*send_call_func_single_ipi)(int cpu); ··· 98 94 return smp_ops.cpu_up(cpu); 99 95 } 100 96 97 + static inline int __cpu_disable(void) 98 + { 99 + return smp_ops.cpu_disable(); 100 + } 101 + 102 + static inline void __cpu_die(unsigned int cpu) 103 + { 104 + smp_ops.cpu_die(cpu); 105 + } 106 + 107 + static inline void play_dead(void) 108 + { 109 + smp_ops.play_dead(); 110 + } 111 + 101 112 static inline void smp_send_reschedule(int cpu) 102 113 { 103 114 smp_ops.smp_send_reschedule(cpu); ··· 128 109 smp_ops.send_call_func_ipi(mask); 129 110 } 130 111 112 + void cpu_disable_common(void); 131 113 void native_smp_prepare_boot_cpu(void); 132 114 void native_smp_prepare_cpus(unsigned int max_cpus); 133 115 void native_smp_cpus_done(unsigned int max_cpus); 134 116 int native_cpu_up(unsigned int cpunum); 117 + int native_cpu_disable(void); 118 + void native_cpu_die(unsigned int cpu); 119 + void native_play_dead(void); 120 + void play_dead_common(void); 121 + 135 122 void native_send_call_func_ipi(cpumask_t mask); 136 123 void native_send_call_func_single_ipi(int cpu); 137 - 138 - extern int __cpu_disable(void); 139 - extern void __cpu_die(unsigned int cpu); 140 124 141 125 void smp_store_cpu_info(int id); 142 126 #define cpu_physical_id(cpu) per_cpu(x86_cpu_to_apicid, cpu) ··· 226 204 # endif 227 205 228 206 #endif /* CONFIG_X86_LOCAL_APIC */ 229 - 230 - #ifdef CONFIG_HOTPLUG_CPU 231 - extern void cpu_uninit(void); 232 - #endif 233 207 234 208 #endif /* __ASSEMBLY__ */ 235 209 #endif /* ASM_X86__SMP_H */
+31 -36
include/asm-x86/spinlock.h
··· 21 21 22 22 #ifdef CONFIG_X86_32 23 23 # define LOCK_PTR_REG "a" 24 + # define REG_PTR_MODE "k" 24 25 #else 25 26 # define LOCK_PTR_REG "D" 27 + # define REG_PTR_MODE "q" 26 28 #endif 27 29 28 30 #if defined(CONFIG_X86_32) && \ ··· 56 54 * much between them in performance though, especially as locks are out of line. 57 55 */ 58 56 #if (NR_CPUS < 256) 59 - static inline int __ticket_spin_is_locked(raw_spinlock_t *lock) 60 - { 61 - int tmp = ACCESS_ONCE(lock->slock); 62 - 63 - return (((tmp >> 8) & 0xff) != (tmp & 0xff)); 64 - } 65 - 66 - static inline int __ticket_spin_is_contended(raw_spinlock_t *lock) 67 - { 68 - int tmp = ACCESS_ONCE(lock->slock); 69 - 70 - return (((tmp >> 8) - tmp) & 0xff) > 1; 71 - } 57 + #define TICKET_SHIFT 8 72 58 73 59 static __always_inline void __ticket_spin_lock(raw_spinlock_t *lock) 74 60 { ··· 79 89 80 90 static __always_inline int __ticket_spin_trylock(raw_spinlock_t *lock) 81 91 { 82 - int tmp; 83 - short new; 92 + int tmp, new; 84 93 85 - asm volatile("movw %2,%w0\n\t" 94 + asm volatile("movzwl %2, %0\n\t" 86 95 "cmpb %h0,%b0\n\t" 96 + "leal 0x100(%" REG_PTR_MODE "0), %1\n\t" 87 97 "jne 1f\n\t" 88 - "movw %w0,%w1\n\t" 89 - "incb %h1\n\t" 90 98 LOCK_PREFIX "cmpxchgw %w1,%2\n\t" 91 99 "1:" 92 100 "sete %b1\n\t" 93 101 "movzbl %b1,%0\n\t" 94 - : "=&a" (tmp), "=Q" (new), "+m" (lock->slock) 102 + : "=&a" (tmp), "=&q" (new), "+m" (lock->slock) 95 103 : 96 104 : "memory", "cc"); 97 105 ··· 104 116 : "memory", "cc"); 105 117 } 106 118 #else 107 - static inline int __ticket_spin_is_locked(raw_spinlock_t *lock) 108 - { 109 - int tmp = ACCESS_ONCE(lock->slock); 110 - 111 - return (((tmp >> 16) & 0xffff) != (tmp & 0xffff)); 112 - } 113 - 114 - static inline int __ticket_spin_is_contended(raw_spinlock_t *lock) 115 - { 116 - int tmp = ACCESS_ONCE(lock->slock); 117 - 118 - return (((tmp >> 16) - tmp) & 0xffff) > 1; 119 - } 119 + #define TICKET_SHIFT 16 120 120 121 121 static __always_inline void __ticket_spin_lock(raw_spinlock_t *lock) 122 122 { ··· 122 146 /* don't need lfence here, because loads are in-order */ 123 147 "jmp 1b\n" 124 148 "2:" 125 - : "+Q" (inc), "+m" (lock->slock), "=r" (tmp) 149 + : "+r" (inc), "+m" (lock->slock), "=&r" (tmp) 126 150 : 127 151 : "memory", "cc"); 128 152 } ··· 136 160 "movl %0,%1\n\t" 137 161 "roll $16, %0\n\t" 138 162 "cmpl %0,%1\n\t" 163 + "leal 0x00010000(%" REG_PTR_MODE "0), %1\n\t" 139 164 "jne 1f\n\t" 140 - "addl $0x00010000, %1\n\t" 141 165 LOCK_PREFIX "cmpxchgl %1,%2\n\t" 142 166 "1:" 143 167 "sete %b1\n\t" 144 168 "movzbl %b1,%0\n\t" 145 - : "=&a" (tmp), "=r" (new), "+m" (lock->slock) 169 + : "=&a" (tmp), "=&q" (new), "+m" (lock->slock) 146 170 : 147 171 : "memory", "cc"); 148 172 ··· 158 182 } 159 183 #endif 160 184 161 - #define __raw_spin_lock_flags(lock, flags) __raw_spin_lock(lock) 185 + static inline int __ticket_spin_is_locked(raw_spinlock_t *lock) 186 + { 187 + int tmp = ACCESS_ONCE(lock->slock); 188 + 189 + return !!(((tmp >> TICKET_SHIFT) ^ tmp) & ((1 << TICKET_SHIFT) - 1)); 190 + } 191 + 192 + static inline int __ticket_spin_is_contended(raw_spinlock_t *lock) 193 + { 194 + int tmp = ACCESS_ONCE(lock->slock); 195 + 196 + return (((tmp >> TICKET_SHIFT) - tmp) & ((1 << TICKET_SHIFT) - 1)) > 1; 197 + } 162 198 163 199 #ifdef CONFIG_PARAVIRT 164 200 /* ··· 260 272 { 261 273 __ticket_spin_unlock(lock); 262 274 } 275 + 276 + static __always_inline void __raw_spin_lock_flags(raw_spinlock_t *lock, 277 + unsigned long flags) 278 + { 279 + __raw_spin_lock(lock); 280 + } 281 + 263 282 #endif /* CONFIG_PARAVIRT */ 264 283 265 284 static inline void __raw_spin_unlock_wait(raw_spinlock_t *lock)
+10
include/asm-x86/tlbflush.h
··· 119 119 { 120 120 } 121 121 122 + static inline void reset_lazy_tlbstate(void) 123 + { 124 + } 125 + 122 126 #else /* SMP */ 123 127 124 128 #include <asm/smp.h> ··· 155 151 char __cacheline_padding[L1_CACHE_BYTES-8]; 156 152 }; 157 153 DECLARE_PER_CPU(struct tlb_state, cpu_tlbstate); 154 + 155 + void reset_lazy_tlbstate(void); 156 + #else 157 + static inline void reset_lazy_tlbstate(void) 158 + { 159 + } 158 160 #endif 159 161 160 162 #endif /* SMP */
+12
include/asm-x86/traps.h
··· 1 1 #ifndef ASM_X86__TRAPS_H 2 2 #define ASM_X86__TRAPS_H 3 3 4 + #include <asm/debugreg.h> 5 + 4 6 /* Common in X86_32 and X86_64 */ 5 7 asmlinkage void divide_error(void); 6 8 asmlinkage void debug(void); ··· 37 35 void do_invalid_op(struct pt_regs *, long); 38 36 void do_general_protection(struct pt_regs *, long); 39 37 void do_nmi(struct pt_regs *, long); 38 + 39 + static inline int get_si_code(unsigned long condition) 40 + { 41 + if (condition & DR_STEP) 42 + return TRAP_TRACE; 43 + else if (condition & (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3)) 44 + return TRAP_HWBKPT; 45 + else 46 + return TRAP_BRKPT; 47 + } 40 48 41 49 extern int panic_on_unrecovered_nmi; 42 50 extern int kstack_depth_to_print;
+12 -2
include/asm-x86/xen/hypervisor.h
··· 54 54 /* arch/i386/kernel/setup.c */ 55 55 extern struct shared_info *HYPERVISOR_shared_info; 56 56 extern struct start_info *xen_start_info; 57 - #define is_initial_xendomain() (xen_start_info->flags & SIF_INITDOMAIN) 58 57 59 58 /* arch/i386/mach-xen/evtchn.c */ 60 59 /* Force a proper event-channel callback from Xen. */ ··· 66 67 #define MULTI_UVMFLAGS_INDEX 3 67 68 #define MULTI_UVMDOMID_INDEX 4 68 69 69 - #define is_running_on_xen() (xen_start_info ? 1 : 0) 70 + enum xen_domain_type { 71 + XEN_NATIVE, 72 + XEN_PV_DOMAIN, 73 + XEN_HVM_DOMAIN, 74 + }; 75 + 76 + extern enum xen_domain_type xen_domain_type; 77 + 78 + #define xen_domain() (xen_domain_type != XEN_NATIVE) 79 + #define xen_pv_domain() (xen_domain_type == XEN_PV_DOMAIN) 80 + #define xen_initial_domain() (xen_pv_domain() && xen_start_info->flags & SIF_INITDOMAIN) 81 + #define xen_hvm_domain() (xen_domain_type == XEN_HVM_DOMAIN) 70 82 71 83 #endif /* ASM_X86__XEN__HYPERVISOR_H */
+1
include/linux/elf.h
··· 360 360 #define NT_PPC_SPE 0x101 /* PowerPC SPE/EVR registers */ 361 361 #define NT_PPC_VSX 0x102 /* PowerPC VSX registers */ 362 362 #define NT_386_TLS 0x200 /* i386 TLS slots (struct user_desc) */ 363 + #define NT_386_IOPERM 0x201 /* x86 io permission bitmap (1=deny) */ 363 364 364 365 365 366 /* Note header in a PT_NOTE section */
+1 -1
include/linux/kernel.h
··· 182 182 183 183 extern int get_option(char **str, int *pint); 184 184 extern char *get_options(const char *str, int nints, int *ints); 185 - extern unsigned long long memparse(char *ptr, char **retptr); 185 + extern unsigned long long memparse(const char *ptr, char **retptr); 186 186 187 187 extern int core_kernel_text(unsigned long addr); 188 188 extern int __kernel_text_address(unsigned long addr);
+4 -9
include/linux/mm.h
··· 7 7 8 8 #include <linux/gfp.h> 9 9 #include <linux/list.h> 10 + #include <linux/mmdebug.h> 10 11 #include <linux/mmzone.h> 11 12 #include <linux/rbtree.h> 12 13 #include <linux/prio_tree.h> ··· 219 218 * files which need it (119 of them) 220 219 */ 221 220 #include <linux/page-flags.h> 222 - 223 - #ifdef CONFIG_DEBUG_VM 224 - #define VM_BUG_ON(cond) BUG_ON(cond) 225 - #else 226 - #define VM_BUG_ON(condition) do { } while(0) 227 - #endif 228 221 229 222 /* 230 223 * Methods to modify the page usage count. ··· 914 919 } 915 920 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */ 916 921 917 - #if NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS 922 + #if USE_SPLIT_PTLOCKS 918 923 /* 919 924 * We tuck a spinlock to guard each pagetable page into its struct page, 920 925 * at page->private, with BUILD_BUG_ON to make sure that this will not ··· 927 932 } while (0) 928 933 #define pte_lock_deinit(page) ((page)->mapping = NULL) 929 934 #define pte_lockptr(mm, pmd) ({(void)(mm); __pte_lockptr(pmd_page(*(pmd)));}) 930 - #else 935 + #else /* !USE_SPLIT_PTLOCKS */ 931 936 /* 932 937 * We use mm->page_table_lock to guard all pagetable pages of the mm. 933 938 */ 934 939 #define pte_lock_init(page) do {} while (0) 935 940 #define pte_lock_deinit(page) do {} while (0) 936 941 #define pte_lockptr(mm, pmd) ({(void)(pmd); &(mm)->page_table_lock;}) 937 - #endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */ 942 + #endif /* USE_SPLIT_PTLOCKS */ 938 943 939 944 static inline void pgtable_page_ctor(struct page *page) 940 945 {
+6 -4
include/linux/mm_types.h
··· 21 21 22 22 struct address_space; 23 23 24 - #if NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS 24 + #define USE_SPLIT_PTLOCKS (NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS) 25 + 26 + #if USE_SPLIT_PTLOCKS 25 27 typedef atomic_long_t mm_counter_t; 26 - #else /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */ 28 + #else /* !USE_SPLIT_PTLOCKS */ 27 29 typedef unsigned long mm_counter_t; 28 - #endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */ 30 + #endif /* !USE_SPLIT_PTLOCKS */ 29 31 30 32 /* 31 33 * Each physical page in the system has a struct page associated with ··· 67 65 * see PAGE_MAPPING_ANON below. 68 66 */ 69 67 }; 70 - #if NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS 68 + #if USE_SPLIT_PTLOCKS 71 69 spinlock_t ptl; 72 70 #endif 73 71 struct kmem_cache *slab; /* SLUB: Pointer to slab */
+18
include/linux/mmdebug.h
··· 1 + #ifndef LINUX_MM_DEBUG_H 2 + #define LINUX_MM_DEBUG_H 1 3 + 4 + #include <linux/autoconf.h> 5 + 6 + #ifdef CONFIG_DEBUG_VM 7 + #define VM_BUG_ON(cond) BUG_ON(cond) 8 + #else 9 + #define VM_BUG_ON(cond) do { } while (0) 10 + #endif 11 + 12 + #ifdef CONFIG_DEBUG_VIRTUAL 13 + #define VIRTUAL_BUG_ON(cond) BUG_ON(cond) 14 + #else 15 + #define VIRTUAL_BUG_ON(cond) do { } while (0) 16 + #endif 17 + 18 + #endif
+3 -3
include/linux/sched.h
··· 352 352 extern void arch_unmap_area(struct mm_struct *, unsigned long); 353 353 extern void arch_unmap_area_topdown(struct mm_struct *, unsigned long); 354 354 355 - #if NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS 355 + #if USE_SPLIT_PTLOCKS 356 356 /* 357 357 * The mm counters are not protected by its page_table_lock, 358 358 * so must be incremented atomically. ··· 363 363 #define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member) 364 364 #define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member) 365 365 366 - #else /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */ 366 + #else /* !USE_SPLIT_PTLOCKS */ 367 367 /* 368 368 * The mm counters are protected by its page_table_lock, 369 369 * so can be incremented directly. ··· 374 374 #define inc_mm_counter(mm, member) (mm)->_##member++ 375 375 #define dec_mm_counter(mm, member) (mm)->_##member-- 376 376 377 - #endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */ 377 + #endif /* !USE_SPLIT_PTLOCKS */ 378 378 379 379 #define get_mm_rss(mm) \ 380 380 (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
+160
include/linux/usb/ehci_def.h
··· 1 + /* 2 + * Copyright (c) 2001-2002 by David Brownell 3 + * 4 + * This program is free software; you can redistribute it and/or modify it 5 + * under the terms of the GNU General Public License as published by the 6 + * Free Software Foundation; either version 2 of the License, or (at your 7 + * option) any later version. 8 + * 9 + * This program is distributed in the hope that it will be useful, but 10 + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 + * for more details. 13 + * 14 + * You should have received a copy of the GNU General Public License 15 + * along with this program; if not, write to the Free Software Foundation, 16 + * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 + */ 18 + 19 + #ifndef __LINUX_USB_EHCI_DEF_H 20 + #define __LINUX_USB_EHCI_DEF_H 21 + 22 + /* EHCI register interface, corresponds to EHCI Revision 0.95 specification */ 23 + 24 + /* Section 2.2 Host Controller Capability Registers */ 25 + struct ehci_caps { 26 + /* these fields are specified as 8 and 16 bit registers, 27 + * but some hosts can't perform 8 or 16 bit PCI accesses. 28 + */ 29 + u32 hc_capbase; 30 + #define HC_LENGTH(p) (((p)>>00)&0x00ff) /* bits 7:0 */ 31 + #define HC_VERSION(p) (((p)>>16)&0xffff) /* bits 31:16 */ 32 + u32 hcs_params; /* HCSPARAMS - offset 0x4 */ 33 + #define HCS_DEBUG_PORT(p) (((p)>>20)&0xf) /* bits 23:20, debug port? */ 34 + #define HCS_INDICATOR(p) ((p)&(1 << 16)) /* true: has port indicators */ 35 + #define HCS_N_CC(p) (((p)>>12)&0xf) /* bits 15:12, #companion HCs */ 36 + #define HCS_N_PCC(p) (((p)>>8)&0xf) /* bits 11:8, ports per CC */ 37 + #define HCS_PORTROUTED(p) ((p)&(1 << 7)) /* true: port routing */ 38 + #define HCS_PPC(p) ((p)&(1 << 4)) /* true: port power control */ 39 + #define HCS_N_PORTS(p) (((p)>>0)&0xf) /* bits 3:0, ports on HC */ 40 + 41 + u32 hcc_params; /* HCCPARAMS - offset 0x8 */ 42 + #define HCC_EXT_CAPS(p) (((p)>>8)&0xff) /* for pci extended caps */ 43 + #define HCC_ISOC_CACHE(p) ((p)&(1 << 7)) /* true: can cache isoc frame */ 44 + #define HCC_ISOC_THRES(p) (((p)>>4)&0x7) /* bits 6:4, uframes cached */ 45 + #define HCC_CANPARK(p) ((p)&(1 << 2)) /* true: can park on async qh */ 46 + #define HCC_PGM_FRAMELISTLEN(p) ((p)&(1 << 1)) /* true: periodic_size changes*/ 47 + #define HCC_64BIT_ADDR(p) ((p)&(1)) /* true: can use 64-bit addr */ 48 + u8 portroute [8]; /* nibbles for routing - offset 0xC */ 49 + } __attribute__ ((packed)); 50 + 51 + 52 + /* Section 2.3 Host Controller Operational Registers */ 53 + struct ehci_regs { 54 + 55 + /* USBCMD: offset 0x00 */ 56 + u32 command; 57 + /* 23:16 is r/w intr rate, in microframes; default "8" == 1/msec */ 58 + #define CMD_PARK (1<<11) /* enable "park" on async qh */ 59 + #define CMD_PARK_CNT(c) (((c)>>8)&3) /* how many transfers to park for */ 60 + #define CMD_LRESET (1<<7) /* partial reset (no ports, etc) */ 61 + #define CMD_IAAD (1<<6) /* "doorbell" interrupt async advance */ 62 + #define CMD_ASE (1<<5) /* async schedule enable */ 63 + #define CMD_PSE (1<<4) /* periodic schedule enable */ 64 + /* 3:2 is periodic frame list size */ 65 + #define CMD_RESET (1<<1) /* reset HC not bus */ 66 + #define CMD_RUN (1<<0) /* start/stop HC */ 67 + 68 + /* USBSTS: offset 0x04 */ 69 + u32 status; 70 + #define STS_ASS (1<<15) /* Async Schedule Status */ 71 + #define STS_PSS (1<<14) /* Periodic Schedule Status */ 72 + #define STS_RECL (1<<13) /* Reclamation */ 73 + #define STS_HALT (1<<12) /* Not running (any reason) */ 74 + /* some bits reserved */ 75 + /* these STS_* flags are also intr_enable bits (USBINTR) */ 76 + #define STS_IAA (1<<5) /* Interrupted on async advance */ 77 + #define STS_FATAL (1<<4) /* such as some PCI access errors */ 78 + #define STS_FLR (1<<3) /* frame list rolled over */ 79 + #define STS_PCD (1<<2) /* port change detect */ 80 + #define STS_ERR (1<<1) /* "error" completion (overflow, ...) */ 81 + #define STS_INT (1<<0) /* "normal" completion (short, ...) */ 82 + 83 + /* USBINTR: offset 0x08 */ 84 + u32 intr_enable; 85 + 86 + /* FRINDEX: offset 0x0C */ 87 + u32 frame_index; /* current microframe number */ 88 + /* CTRLDSSEGMENT: offset 0x10 */ 89 + u32 segment; /* address bits 63:32 if needed */ 90 + /* PERIODICLISTBASE: offset 0x14 */ 91 + u32 frame_list; /* points to periodic list */ 92 + /* ASYNCLISTADDR: offset 0x18 */ 93 + u32 async_next; /* address of next async queue head */ 94 + 95 + u32 reserved [9]; 96 + 97 + /* CONFIGFLAG: offset 0x40 */ 98 + u32 configured_flag; 99 + #define FLAG_CF (1<<0) /* true: we'll support "high speed" */ 100 + 101 + /* PORTSC: offset 0x44 */ 102 + u32 port_status [0]; /* up to N_PORTS */ 103 + /* 31:23 reserved */ 104 + #define PORT_WKOC_E (1<<22) /* wake on overcurrent (enable) */ 105 + #define PORT_WKDISC_E (1<<21) /* wake on disconnect (enable) */ 106 + #define PORT_WKCONN_E (1<<20) /* wake on connect (enable) */ 107 + /* 19:16 for port testing */ 108 + #define PORT_LED_OFF (0<<14) 109 + #define PORT_LED_AMBER (1<<14) 110 + #define PORT_LED_GREEN (2<<14) 111 + #define PORT_LED_MASK (3<<14) 112 + #define PORT_OWNER (1<<13) /* true: companion hc owns this port */ 113 + #define PORT_POWER (1<<12) /* true: has power (see PPC) */ 114 + #define PORT_USB11(x) (((x)&(3<<10)) == (1<<10)) /* USB 1.1 device */ 115 + /* 11:10 for detecting lowspeed devices (reset vs release ownership) */ 116 + /* 9 reserved */ 117 + #define PORT_RESET (1<<8) /* reset port */ 118 + #define PORT_SUSPEND (1<<7) /* suspend port */ 119 + #define PORT_RESUME (1<<6) /* resume it */ 120 + #define PORT_OCC (1<<5) /* over current change */ 121 + #define PORT_OC (1<<4) /* over current active */ 122 + #define PORT_PEC (1<<3) /* port enable change */ 123 + #define PORT_PE (1<<2) /* port enable */ 124 + #define PORT_CSC (1<<1) /* connect status change */ 125 + #define PORT_CONNECT (1<<0) /* device connected */ 126 + #define PORT_RWC_BITS (PORT_CSC | PORT_PEC | PORT_OCC) 127 + } __attribute__ ((packed)); 128 + 129 + #define USBMODE 0x68 /* USB Device mode */ 130 + #define USBMODE_SDIS (1<<3) /* Stream disable */ 131 + #define USBMODE_BE (1<<2) /* BE/LE endianness select */ 132 + #define USBMODE_CM_HC (3<<0) /* host controller mode */ 133 + #define USBMODE_CM_IDLE (0<<0) /* idle state */ 134 + 135 + /* Appendix C, Debug port ... intended for use with special "debug devices" 136 + * that can help if there's no serial console. (nonstandard enumeration.) 137 + */ 138 + struct ehci_dbg_port { 139 + u32 control; 140 + #define DBGP_OWNER (1<<30) 141 + #define DBGP_ENABLED (1<<28) 142 + #define DBGP_DONE (1<<16) 143 + #define DBGP_INUSE (1<<10) 144 + #define DBGP_ERRCODE(x) (((x)>>7)&0x07) 145 + # define DBGP_ERR_BAD 1 146 + # define DBGP_ERR_SIGNAL 2 147 + #define DBGP_ERROR (1<<6) 148 + #define DBGP_GO (1<<5) 149 + #define DBGP_OUT (1<<4) 150 + #define DBGP_LEN(x) (((x)>>0)&0x0f) 151 + u32 pids; 152 + #define DBGP_PID_GET(x) (((x)>>16)&0xff) 153 + #define DBGP_PID_SET(data, tok) (((data)<<8)|(tok)) 154 + u32 data03; 155 + u32 data47; 156 + u32 address; 157 + #define DBGP_EPADDR(dev, ep) (((dev)<<8)|(ep)) 158 + } __attribute__ ((packed)); 159 + 160 + #endif /* __LINUX_USB_EHCI_DEF_H */
-61
include/xen/balloon.h
··· 1 - /****************************************************************************** 2 - * balloon.h 3 - * 4 - * Xen balloon driver - enables returning/claiming memory to/from Xen. 5 - * 6 - * Copyright (c) 2003, B Dragovic 7 - * Copyright (c) 2003-2004, M Williamson, K Fraser 8 - * 9 - * This program is free software; you can redistribute it and/or 10 - * modify it under the terms of the GNU General Public License version 2 11 - * as published by the Free Software Foundation; or, when distributed 12 - * separately from the Linux kernel or incorporated into other 13 - * software packages, subject to the following license: 14 - * 15 - * Permission is hereby granted, free of charge, to any person obtaining a copy 16 - * of this source file (the "Software"), to deal in the Software without 17 - * restriction, including without limitation the rights to use, copy, modify, 18 - * merge, publish, distribute, sublicense, and/or sell copies of the Software, 19 - * and to permit persons to whom the Software is furnished to do so, subject to 20 - * the following conditions: 21 - * 22 - * The above copyright notice and this permission notice shall be included in 23 - * all copies or substantial portions of the Software. 24 - * 25 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 26 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 28 - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 30 - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 31 - * IN THE SOFTWARE. 32 - */ 33 - 34 - #ifndef __XEN_BALLOON_H__ 35 - #define __XEN_BALLOON_H__ 36 - 37 - #include <linux/spinlock.h> 38 - 39 - #if 0 40 - /* 41 - * Inform the balloon driver that it should allow some slop for device-driver 42 - * memory activities. 43 - */ 44 - void balloon_update_driver_allowance(long delta); 45 - 46 - /* Allocate/free a set of empty pages in low memory (i.e., no RAM mapped). */ 47 - struct page **alloc_empty_pages_and_pagevec(int nr_pages); 48 - void free_empty_pages_and_pagevec(struct page **pagevec, int nr_pages); 49 - 50 - void balloon_release_driver_page(struct page *page); 51 - 52 - /* 53 - * Prevent the balloon driver from changing the memory reservation during 54 - * a driver critical region. 55 - */ 56 - extern spinlock_t balloon_lock; 57 - #define balloon_lock(__flags) spin_lock_irqsave(&balloon_lock, __flags) 58 - #define balloon_unlock(__flags) spin_unlock_irqrestore(&balloon_lock, __flags) 59 - #endif 60 - 61 - #endif /* __XEN_BALLOON_H__ */
+2
include/xen/events.h
··· 46 46 47 47 /* Clear an irq's pending state, in preparation for polling on it */ 48 48 void xen_clear_irq_pending(int irq); 49 + void xen_set_irq_pending(int irq); 50 + bool xen_test_irq_pending(int irq); 49 51 50 52 /* Poll waiting for an irq to become pending. In the usual case, the 51 53 irq will be disabled so it won't deliver an interrupt. */
+9
lib/Kconfig.debug
··· 495 495 496 496 If unsure, say N. 497 497 498 + config DEBUG_VIRTUAL 499 + bool "Debug VM translations" 500 + depends on DEBUG_KERNEL && X86 501 + help 502 + Enable some costly sanity checks in virtual to page code. This can 503 + catch mistakes with virt_to_page() and friends. 504 + 505 + If unsure, say N. 506 + 498 507 config DEBUG_WRITECOUNT 499 508 bool "Debug filesystem writers count" 500 509 depends on DEBUG_KERNEL
+1 -1
lib/cmdline.c
··· 126 126 * megabyte, or one gigabyte, respectively. 127 127 */ 128 128 129 - unsigned long long memparse(char *ptr, char **retptr) 129 + unsigned long long memparse(const char *ptr, char **retptr) 130 130 { 131 131 char *endptr; /* local pointer to end of parsed string */ 132 132
+7
mm/vmalloc.c
··· 180 180 pmd_t *pmd; 181 181 pte_t *ptep, pte; 182 182 183 + /* 184 + * XXX we might need to change this if we add VIRTUAL_BUG_ON for 185 + * architectures that do not vmalloc module space 186 + */ 187 + VIRTUAL_BUG_ON(!is_vmalloc_addr(vmalloc_addr) && 188 + !is_module_address(addr)); 189 + 183 190 if (!pgd_none(*pgd)) { 184 191 pud = pud_offset(pgd, addr); 185 192 if (!pud_none(*pud)) {
+2 -2
scripts/Kbuild.include
··· 105 105 # Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586) 106 106 107 107 cc-option = $(call try-run,\ 108 - $(CC) $(KBUILD_CFLAGS) $(1) -S -xc /dev/null -o "$$TMP",$(1),$(2)) 108 + $(CC) $(KBUILD_CFLAGS) $(1) -c -xc /dev/null -o "$$TMP",$(1),$(2)) 109 109 110 110 # cc-option-yn 111 111 # Usage: flag := $(call cc-option-yn,-march=winchip-c6) 112 112 cc-option-yn = $(call try-run,\ 113 - $(CC) $(KBUILD_CFLAGS) $(1) -S -xc /dev/null -o "$$TMP",y,n) 113 + $(CC) $(KBUILD_CFLAGS) $(1) -c -xc /dev/null -o "$$TMP",y,n) 114 114 115 115 # cc-option-align 116 116 # Prefix align with either -falign or -malign