Haswell early reboot, Mavericks, locked MSRs, and HP Envy 15-J063CL (i7-4700MQ)

Discussion in 'Mavericks Laptop Support' started by RehabMan, Nov 3, 2013.

Tags:
  1. RehabMan

    RehabMan Moderator

    Joined:
    May 3, 2012
    Messages:
    133,914
    Mobo:
    Intel DH67BL
    CPU:
    Core i7-2600K
    Graphics:
    Intel HD 3000
    Mac:
    MacBook Air
    Mobile Phone:
    iOS
    Nov 3, 2013 at 4:05 AM #1
    RehabMan

    RehabMan Moderator

    Joined:
    May 3, 2012
    Messages:
    133,914
    Mobo:
    Intel DH67BL
    CPU:
    Core i7-2600K
    Graphics:
    Intel HD 3000
    Mac:
    MacBook Air
    Mobile Phone:
    iOS
    *** Please note Yosemite guide: http://www.tonymacx86.com/yosemite-...ng-kernel-haswell-cpus-xcpm-early-reboot.html

    Haswell/Mavericks Troubles

    Many people with Haswell laptops (and some desktops) have been running into a new problem Apple has thrown at us. The new Mavericks kernel has power management moved down into the kernel. For this reason, my MacBookAir6,2 running Mavericks does not load AppleIntelCPUPowerManagement. In the past, we patched AppleIntelCPUPowerManagement to avoid the kernel writing to locked CPU MSRs (machine specific registers, credit RevoGirl). Some BIOSes lock some of these registers (the common one is 0xE2, I don't know if others can be locked as well). The problem is that touching these registers when they are locked causes an unexpected fault and you get a KP. It seems this KP is so early, that the kernel is unprepared to handle it, and the computer reboots.

    Some people have found that if they use a kernel modified for AMD systems, they are able to boot (see here: http://www.tonymacx86.com/mountain-lion-laptop-support/110981-asus-g750jx-4.html#post697066). I tried this and it indeed works. But other things break... I was able to install (using that kernel), but I couldn't boot with caches (always had to use "-f"). Booting with caches caused a KP. In addition, there was no power management. CPU was running at x24 always.

    But...

    I decided to see what I could do by building my own kernel. My main thought was to make some changes, see if I could avoid touching locked MSRs with modifications to the source code with the idea to fold the changes into a patch. So, I downloaded the kernel source from opensource.apple.com, found out how to build it (thanks google!), and tried to use it. On first try, I didn't make any changes... and I was surprised that I was able to start the installer with the newly built kernel! No changes and it just works. WTF?

    Turns out the sources for the kernel do not include the parts for xnu power management. Since it isn't there, it doesn't cause the problem. But of course, AppleIntelCPUPowerManagement expects for PM to be provided by the kernel, so it doesn't work. It doesn't crash, but still no power management. Since 10.8.5 does not have this change, I decided to try the (patched) AppleIntelCPUPowerManagement from 10.8.5 (v214). And that actually works.

    I don't really like doing rollbacks like that, but it is probably a workable solution until something better comes along. I still think it might be possible to patch the kernel to avoid the MSR writing problem. See updates below on patches.

    Update 2013-11-25

    With some prodding by Pike's blog, I went back to my original patch that I had attempted a number of weeks ago, and I found the mistakes I had made with my patch (this was prior to building the kernel from sources). The details are on my blog here: http://racerrehabman.wordpress.com/2013/11/25/maverickshaswell-kernel-patch-for-early-reboot/

    As a result, I'm now running a patched mach_kernel (not built from source, but patched from retail), MacBookPro11,2 smbios.plist, AppleIntelCPUPowerManagement.kext, ssdt.aml generated with Pike's script (plugin-type=1). Of course, AppleIntelCPUPowerManagement does not load, as all CPU power management is handled by the kernel (xcpm). In other words, it is running just as a real Haswell MacBookPro would as far as power management. The only "problem" that I can see, is that I'm not getting pstates between x8 and x24, much like the results with iMac14,2. I wonder if something is missing (taking the place of X86PlatformPlugin plists?) that the bootloader/DSDT/SSDT should be injecting to inform the kernel's xcpm behavior? More investigation is needed. I will investigate by watching the behavior of my real MacBookAir6,2 and perhaps a friend's real MacBookPro11,x.

    I will update this post should I find more information.

    Just for ease of reference here is the currently recommended patches...

    Update 2014-10-18

    I updated my blog and this post with the patches for the recently released Yosemite 10.10.

    The xcpm patches for Yosemite 10.10:
    Code (Text):

    perl -pi -e 's|\xe2\x00\x00\x00\x02\x00\x00\x00|\x00\x00\x00\x00\x02\x00\x00\x00|g' kernel
    perl -pi -e 's|\xe2\x00\x00\x00\x4c\x00\x00\x00|\x00\x00\x00\x00\x4c\x00\x00\x00|g' kernel
    perl -pi -e 's|\xe2\x00\x00\x00\x90\x01\x00\x00|\x00\x00\x00\x00\x90\x01\x00\x00|g' kernel
     
    Please note the kernel resides at /System/Library/Kernels/kernel.

    Update 2014-02-25

    10.9.x Local APIC mach_kernel patch updated to work with new 10.9.2 mach_kernel. The new patch is more generic and works with all 10.9.x.

    The xcpm patch works with all 10.9.x, no changes for 10.9.2.

    Code (Text):

    # for xpcm related panic/reboot 10.9.x kernel
    perl -pi -e 's|\x74\x6c(\x48\x83\xc7\x28\x90\x8b\x05..\x5e\x00\x85\x47\xdc)\x74\x54(\x8b\x4f\xd8\x45\x85\xc0\x74\x08\x44\x39\xc1\x44\x89\xc1)\x75\x44(\x0f\x32\x89\xc0\x48\xc1\xe2\x20\x48\x09\xc2\x48\x89\x57\xf8\x48\x8b\x47\xe8\x48\x85\xc0\x74\x06\x48\xf7\xd0\x48\x21\xc2\x48\x0b\x57\xf0\x49\x89\xd1\x49\xc1\xe9\x20\x89\xd0\x8b\x4f\xd8\x4c\x89\xca)(\x0f\x30\x8b\x4f\xd8\x0f\x32\x89\xc0\x48\xc1\xe2\x20\x48\x09\xc2\x48\x89\x17\x48\x83\xc7\x30\xff\xce)\x75\x99(\x5d\xc3)\x90{7}|\x74\x73${1}\x74\x5b${2}\x75\x4b${3}\x66\x81\xf9\xe2\x00\x74\x02${4}\x75\x92${5}|g' mach_kernel
     
    Code (Text):

    # for xpcm related panic/reboot 10.8.5 kernel
    perl -pi -e 's|\x74\x69(\x48\x83\xc7\x28\x90\x8b\x05\xfe\xce\x5f\x00\x85\x47\xdc)\x74\x51(\x8b\x4f\xd8\x45\x85\xc0\x74\x05\x44\x39\xc1)\x75\x44(\x0f\x32\x89\xc0\x48\xc1\xe2\x20\x48\x09\xc2\x48\x89\x57\xf8\x48\x8b\x47\xe8\x48\x85\xc0\x74\x06\x48\xf7\xd0\x48\x21\xc2\x48\x0b\x57\xf0\x49\x89\xd1\x49\xc1\xe9\x20\x89\xd0\x8b\x4f\xd8\x4c\x89\xca)(\x0f\x30\x8b\x4f\xd8\x0f\x32\x89\xc0\x48\xc1\xe2\x20\x48\x09\xc2\x48\x89\x17\x48\x83\xc7\x30\xff\xce)\x75\x9c(\x5d\xc3)\x90{7}(\x90{3})|\x74\x70${1}\x74\x58${2}\x75\x4b${3}\x66\x81\xf9\xe2\x00\x74\x02${4}\x75\x95${5}${6}|g' mach_kernel
     
    Code (Text):

    # for Local APIC panic (also causes instant reboot) 10.9.x kernel
    perl -pi -e 's|(\x25\x1c\x00\x00\x00\x48\x8d\x0d..\x5e\x00\x3b\x01)\x74(\x11\x48\x8d\x3d...\x00\x44)|${1}\xeb${2}|g' mach_kernel
     
    Code (Text):

    # for Local APIC panic (also causes instant reboot) 10.8.5 kernel
    perl -pi -e 's|(\x25\x14\x00\x00\x00\x48\x8d\x0d\x50\x37\x60\x00\x3b\x01)\x74(\x10\x48\x8d\x3d\xfc\x12\x3f\x00\x89)|${1}\xeb${2}|g' mach_kernel
     
    How to patch your kernel

    The vanilla mach_kernel is located on your USB installer after running Unibeast. Here's how to patch it:

    Code (Text):

    # in Terminal, assuming your USB is called Installer
    cp /Volumes/Installer/mach_kernel ~/Desktop/mach_kernel_backup
    cp /Volumes/Installer/mach_kernel ~/Desktop/mach_kernel
    cd ~/Desktop
    # now copy/paste one or more of the perl patches from above into Terminal
    perl ...[from above]... mach_kernel
    perl ...[from above]... mach_kernel
    # patched mach_kernel is now at ~/Desktop/mach_kernel
    sudo cp mach_kernel /Volumes/Installer/mach_kernel
     
    After you install OS X to your HDD, you will have vanilla mach_kernel on the HDD, leading to the same instant reboot problem. So, you must re-enter the OS X installer, and go into Terminal (using Utilities -> Terminal) and replace the mach_kernel with the patched version:
    Code (Text):

    # in Terminal from the OS X installer, assuming your HDD volume is called "Macintosh HD"
    cp /mach_kernel "/Volumes/Macintosh HD/mach_kernel"
     
    After that, you can exit the installer, and boot into the installed partition to finish installation and reach the desktop.

    MD5 sums for mach_kernel

    Check your md5 sums with:
    Code (Text):

    md5 mach_kernel
     
    10.10 kernel
    vanilla: 9f1768fddec369e545d938f0f4f76350
    xcpm patched: eb21ca4bd7aba97d5e7b080a481fc173

    10.9.5 mach_kernel
    vanilla: 8f9adba4ca2f55907b8ec8d4bbf4c555
    xpcm patched: 0563c5d1fd99db17198d53ad60c9d9ba
    lapic patched: 0dd9c1bf48b4377553d0dfbfc2c49e8c
    patched with both: 49f889eeb27689bec3d1aea30e2ed328

    10.9.4 mach_kernel
    vanilla: 3d0ad5a7a8ef3b1d4e6ea33e92e4d3b5
    xpcm patched: 921c850e3062e750730b0e99f5eaa381
    lapic patched: 855f9bf2fd7bcf570fa40e4406d1c661
    patched with both: e0307d0e1151468c551274ac78d6dbbf

    10.9.3 mach_kernel
    vanilla: 5ba55b0d446094f82e48e8a413ddfaec
    xcpm patched: 6848b1904426d5e270a2db6fada67fb0
    lapic patched: f600afe2413450a9405fd8dc4c555043
    patched with both: 33e741649352c1545a269cf0700d65e0

    10.9.2 mach_kernel
    vanilla: 15ce54d9b6edc47e282fdf038f71738c
    xcpm patched: aeb9203dc754afac23bf9696833032fe
    lapic patched: e146cd0e8baa61b6c394ec44e4f5eaf4
    patched with both: 68d82160351204af5dad5d7414fdefa9

    10.9 mach_kernel
    vanilla: 06b687fa00945c97e06ad1919625793c
    xcpm patched: 88bf62a7955b9e20cdb19906bdda6b43
    lapic patched: 6ac911a71dc47d6c6233d28b60c9dbb7
    patched with both: 9b2bdec07dc8a8d95a7a510700bad7fb

    10.8.5 mach_kernel
    vanilla: e835be83eb956af0b63d28f69bfb22b3
    xcpm patched: 539c3a1e2fef063384b44543765b8a39
    lapic patched: 00bdc1a157c6f380eae816565c46033f
    patched with both: 88dbe889c7b21ee951907c894bae6248


    Computer Specifics
    HP Envy 15-J063CL (Costco)
    i7-4700MQ @2.4Ghz, 12GB RAM
    HM87 chipset
    HD4600 graphics (1080p panel)
    BCM4352 ac WiFi (works with only injection)
    RTL8111/8168/8411 (works with RealtekRTL8111)
    (I am not certain that I'm keeping this laptop...)

    Working:
    - power management (currently using iMac14,2... could be improved)
    - booting with caches
    - HD4600 graphics (this computer uses eDP)
    - HDMI
    - USB3 (before sleep)
    - trackpad/keyboard (Synaptics)
    - sleep
    - sleep triggered by lid
    - shutdown/restart
    - backlit keyboard on/off (must be hardwired)
    - Camera (kind of grainy, but could be poor lighting)
    - USB3 (after sleep w/ -gux_defer_usb2)
    - display brightness (using PNLF patch + blinkscreen)
    - audio yet (patched AppleHDA)

    Not Working/Not Started/In progress

    Not Tested
    - Bluetooth


    PStates:
    *
    iMac14,2 (X86PlatformPlugin)
    DPCIManager PStates: 8,24,25,26,27,28,29,30,31,32
    *
    MacBookPro8,3 (ACPI_SMC_PlatformPlugin)
    DPCIManager PStates: 8,12,16,20,24,26,28,30,31,32

    MacBookPro11,2 (xcpm, patched mach_kernel)
    DPCIManager PStates: 8,24,25,26,27,29,30,32,33


    DSDT Patches:

    I have published my DSDT patch project on github. It relies heavily on my generic laptop DSDT patch repo. Read the README.md and setup carefully in order to use.

    https://github.com/RehabMan/HP-Envy-DSDT-Patch


    See my blog for perl patch for mach_kernel.
    *
    *
    10.9 kernel built from Apple's sources is provided below:

    Update 2014-02-13

    Attached mach_kernel built from Apple's sources removed. There is no reason to use it. Use the provided patches to create a mach_kernel that works with machines with locked MSR 0xE2.
     
  2. Bozster

    Bozster

    Joined:
    May 30, 2011
    Messages:
    69
    Mobo:
    Intel i7 3939k / 32gb / Dual GTX 580
    CPU:
    Intel i7 3939k 4.2Ghz
    Graphics:
    dual GTX 580
    Mac:
    MacBook Air, Mac Pro
    Mobile Phone:
    Android, iOS
    Nov 3, 2013 at 2:34 PM #2
    Bozster

    Bozster

    Joined:
    May 30, 2011
    Messages:
    69
    Mobo:
    Intel i7 3939k / 32gb / Dual GTX 580
    CPU:
    Intel i7 3939k 4.2Ghz
    Graphics:
    dual GTX 580
    Mac:
    MacBook Air, Mac Pro
    Mobile Phone:
    Android, iOS
    So Rehabman do you suggest I use your kernel over the AMD one I used?

    I don't need to put -f in my boot arguments I boot with default ones. Basically I'm not getting kernel panic like you do with that HP but you are right that powermanagement doesn't work. I can't sleep .. I thought I can but I can't.

    So if everything works for ASUS, do you suggest I still use your kernel, OR to use the 10.8.5 power management kext you suggested. If I understand correctly you are saying that this should fix the sleep issue?

    Also, one problem I noticed is that hardware acceleration doesn't work if smbios is set as macbook pro (or anything else but Mac Pro 5.1). However in this case I lose touchpad because mac pro 5.1 doesn't obviously load the laptop stuff like touchpad.

    Any suggestions about that? I'm thinking in modifying Apple GraphicsPowerManagement and see what's set under MacPro5,1 and replicate that to MBP10.1 or any latest MBP available in order to try to solve this hardware acceleration issue.
     
  3. RehabMan

    RehabMan Moderator

    Joined:
    May 3, 2012
    Messages:
    133,914
    Mobo:
    Intel DH67BL
    CPU:
    Core i7-2600K
    Graphics:
    Intel HD 3000
    Mac:
    MacBook Air
    Mobile Phone:
    iOS
    Nov 3, 2013 at 3:14 PM #3
    RehabMan

    RehabMan Moderator

    Joined:
    May 3, 2012
    Messages:
    133,914
    Mobo:
    Intel DH67BL
    CPU:
    Core i7-2600K
    Graphics:
    Intel HD 3000
    Mac:
    MacBook Air
    Mobile Phone:
    iOS
    Connect a USB keyboard. Some people report they can continue by just pressing the spacebar.

    Did you create your USB installer with laptop support?
     
  4. RehabMan

    RehabMan Moderator

    Joined:
    May 3, 2012
    Messages:
    133,914
    Mobo:
    Intel DH67BL
    CPU:
    Core i7-2600K
    Graphics:
    Intel HD 3000
    Mac:
    MacBook Air
    Mobile Phone:
    iOS
    Nov 3, 2013 at 3:18 PM #4
    RehabMan

    RehabMan Moderator

    Joined:
    May 3, 2012
    Messages:
    133,914
    Mobo:
    Intel DH67BL
    CPU:
    Core i7-2600K
    Graphics:
    Intel HD 3000
    Mac:
    MacBook Air
    Mobile Phone:
    iOS
    I've got full power management and sleep working... So yeah, you probably want this kernel over the AMD one.

    Hardware accel (graphics) depends on injecting the correct properties for graphics (and probably compatible smbios). I use a DSDT patch to inject ig-platform=0a260006 (in my case the graphics stuff was actually in an SSDT). Also I rename GFX0 -> IGPU for better power management.

    PM works with iMac13,2 and "Ivy style" SSDT or with MacBookPro8,3 and "Sandy style" SSDT.
     
  5. T1hom7as

    T1hom7as

    Joined:
    Feb 26, 2012
    Messages:
    867
    Mobo:
    Acer Aspire 5750G
    CPU:
    Intel Core i7 2630QM @ 2GHz
    Graphics:
    NVIDIA GeForce GT 540M + Intel HD Graphics 3000
    Mobile Phone:
    iOS
    Nov 3, 2013 at 3:51 PM #5
    T1hom7as

    T1hom7as

    Joined:
    Feb 26, 2012
    Messages:
    867
    Mobo:
    Acer Aspire 5750G
    CPU:
    Intel Core i7 2630QM @ 2GHz
    Graphics:
    NVIDIA GeForce GT 540M + Intel HD Graphics 3000
    Mobile Phone:
    iOS
  6. RehabMan

    RehabMan Moderator

    Joined:
    May 3, 2012
    Messages:
    133,914
    Mobo:
    Intel DH67BL
    CPU:
    Core i7-2600K
    Graphics:
    Intel HD 3000
    Mac:
    MacBook Air
    Mobile Phone:
    iOS
    Nov 3, 2013 at 5:06 PM #6
    RehabMan

    RehabMan Moderator

    Joined:
    May 3, 2012
    Messages:
    133,914
    Mobo:
    Intel DH67BL
    CPU:
    Core i7-2600K
    Graphics:
    Intel HD 3000
    Mac:
    MacBook Air
    Mobile Phone:
    iOS
  7. tdeghrtrdeh

    tdeghrtrdeh

    Joined:
    Oct 25, 2013
    Messages:
    100
    Mobo:
    Envy TS 15
    CPU:
    i7 4700MQ
    Graphics:
    Nvidis 740GT
    Mac:
    iMac, MacBook
    Mobile Phone:
    iOS
    Nov 3, 2013 at 11:44 PM #7
    tdeghrtrdeh

    tdeghrtrdeh

    Joined:
    Oct 25, 2013
    Messages:
    100
    Mobo:
    Envy TS 15
    CPU:
    i7 4700MQ
    Graphics:
    Nvidis 740GT
    Mac:
    iMac, MacBook
    Mobile Phone:
    iOS
    Hmmmm....
    here i was and thought i had bought uncompatible hardware!
    searching high and low for ACPI that was missing...

    Then you brew a new Kernel and the MF works ....im impressed.
    Good job.

    So i made the usb installer form Unibeast, copied your mach_kernel to the usb and it worked.
    and to be able to boot the HD i had to copy over the mach_kernel as well.

    Kext installs though, its giving me troubles.
    - HD4600 graphics (this computer uses eDP) i only get 1024x768(dont think it proberly installed)
    - USB3 (before sleep)
    - trackpad/keyboard (Synaptics) do you have a kext for this?
    - backlit keyboard on/off (must be hardwired)
    - Camera (kind of grainy, but could be poor lighting) works great out of the box....

    its the J008eo model i have of that laptop.
    http://h10025.www1.hp.com/ewfrf/wc/...da&lc=da&os=4158&product=5400183&sw_lang=#N46

    any help appreciated.
    Good job.
     
  8. RehabMan

    RehabMan Moderator

    Joined:
    May 3, 2012
    Messages:
    133,914
    Mobo:
    Intel DH67BL
    CPU:
    Core i7-2600K
    Graphics:
    Intel HD 3000
    Mac:
    MacBook Air
    Mobile Phone:
    iOS
    Nov 4, 2013 at 1:05 AM #8
    RehabMan

    RehabMan Moderator

    Joined:
    May 3, 2012
    Messages:
    133,914
    Mobo:
    Intel DH67BL
    CPU:
    Core i7-2600K
    Graphics:
    Intel HD 3000
    Mac:
    MacBook Air
    Mobile Phone:
    iOS
    trackpad/keyboard kext: https://github.com/RehabMan/OS-X-Voodoo-PS2-Controller
    battery kext: https://github.com/RehabMan/OS-X-ACPI-Battery-Driver
    various useful DSDT patches: https://github.com/RehabMan/Laptop-DSDT-Patch

    Graphics can be supported by:
    "HD4000 High Resolution" modified to inject 0a260006 { 0x06, 0x00, 0x26, 0x0a }
    "Brightness Fix" will get the slider but it is non-functional (but gives lid sleep)
    "Graphics Mode"=1920x1080x32 in org.chameleon.Boot.plist
    (you can use IGPlatformID=0a260006 temporarily)

    Implemement power management: http://www.tonymacx86.com/mountain-...nagement-sandy-bridge-ivy-bridge-laptops.html

    But use iMac14,2 (SSDT from ProBook Installer) or MacBookPro8,3 (generate with MaciASL).

    Your USB3 may be configured differently, but there are DSDT patches for USB in the patch repo above (to be used with AppleUSBXHCI) or you can use GenericUSBXHCI without DSDT patches (currently what I'm using).

    Note: The point of this post was really about the kernel, not about this specific laptop, so please do not turn it into a thread about troubleshooting your install. Thanks. I will write a more complete guide for this laptop when/if I get done with it.
     
  9. tdeghrtrdeh

    tdeghrtrdeh

    Joined:
    Oct 25, 2013
    Messages:
    100
    Mobo:
    Envy TS 15
    CPU:
    i7 4700MQ
    Graphics:
    Nvidis 740GT
    Mac:
    iMac, MacBook
    Mobile Phone:
    iOS
    Nov 4, 2013 at 3:02 PM #9
    tdeghrtrdeh

    tdeghrtrdeh

    Joined:
    Oct 25, 2013
    Messages:
    100
    Mobo:
    Envy TS 15
    CPU:
    i7 4700MQ
    Graphics:
    Nvidis 740GT
    Mac:
    iMac, MacBook
    Mobile Phone:
    iOS
     
  10. RehabMan

    RehabMan Moderator

    Joined:
    May 3, 2012
    Messages:
    133,914
    Mobo:
    Intel DH67BL
    CPU:
    Core i7-2600K
    Graphics:
    Intel HD 3000
    Mac:
    MacBook Air
    Mobile Phone:
    iOS
    Nov 4, 2013 at 3:31 PM #10
    RehabMan

    RehabMan Moderator

    Joined:
    May 3, 2012
    Messages:
    133,914
    Mobo:
    Intel DH67BL
    CPU:
    Core i7-2600K
    Graphics:
    Intel HD 3000
    Mac:
    MacBook Air
    Mobile Phone:
    iOS
    If this is your first hack, you've picked a tricky one. Some of this stuff makes more sense if you've done an "easier" hack before.
     

Share This Page