Piker-Alpha / AppleIntelInfo

Replacement for AppleIntelCPUPowerManagementInfo.kext
163 stars 40 forks source link

Compiled on Sierra 10.12. System restarts on kextload #11

Open MacNB opened 7 years ago

MacNB commented 7 years ago

Recently upgraded 10.9.5 to 10.12. CPU is Xeon E5450 (4 cores/4 threads) On kextload, the screen clears to black and restarts.

CPU may not be supported but panic ?

Piker-Alpha commented 7 years ago

Sorry. I don't seem to get any notifications from Github.

Ok so I guess that your system is booting up fine and then you try to load the kext with kextload but that fails. Correct?

Did you compile the kext yourself or did you download it from some place?

MacNB commented 7 years ago

No problem. Yes I compiled it myself. OS: 10.12. All working fine. Xcode: 7.0.1 In xcode I click Product->build for->Running. Builds successfully. i change owner & permissions for the built kext (0:0 & 755). Load the kext with sudo kextload. The screen clears and reboots the system.

Piker-Alpha commented 7 years ago

Ok. We need to find the code that fails. Have you tried to set logMSRs in the plist to false? If this settings doesn't help, then all other the other settings (see README).

mabellon commented 7 years ago

@Piker-Alpha

I was able to use an early version before upgrading to Sierra. I recently upgraded my MacBook 2016 (Skylake Core m3) to Sierra and tried the latest AppleIntelInfo from GitHub. I was getting a kernel panic on kextload. After some debugging, and review of your commits over the last while it seems the issue is caused by: rdmsr64(MSR_THERM2_CTL). This was added in commit ce53c51. After removing this and subsequent THERM2 code everything seems fine.

I'm not sure if this is what everyone else was hitting or not, but it's definitely a bug in the current codebase. I can't understand what this would have to do with upgrading to Sierra and is likely just coincidence. My brief read of the Intel docs suggest that perhaps you need a CPUID check before reading this MSR.

Hope this helps.

Piker-Alpha commented 7 years ago

Excellent news. Can you please verify my latest commit

MacNB commented 7 years ago

Hi Piker-Alpha Sorry I didn't get back to you. Recap: Xeon E5450 CPU, on Sierra 10.12.3; on kextload of v2.1, system reboots. Loading it on El Capitan 10.11.6, it's the same --- system reboots.

I turned off each of settings in Info.plist, one by one and on each load of the kext, it reboots the system.

Could not see anything the Console logs that indicated the fault. The fault seems so catastrophic that nothing gets logged.

I tried an older version 1.5 binary that I had, it is the same -- reboots the system.

Piker-Alpha commented 7 years ago

Please use my latest commit (AppleIntelInfo.kext v2.2) and disable the build settings (see new comment) because the kexts should load without crashing when all settings are zero. That is your first step. After that you can enable the build settings one by one. I think that your processor has some issues with MSR.

MacNB commented 7 years ago

Hi Piker-Alpha I edited the AppleIntelInfo.h and changed the build settings as follows:

/*
 * Build settings (0 = disable feature / 1 = enable feature)
 */

#define REPORT_MSRS                      0
#define REPORT_IGPU_P_STATES      0
#define REPORT_C_STATES                0
#define REPORT_IPG_STYLE              0
#define REPORT_INTEL_REGS            0
#define ENABLE_HWP                         0

#define WRITE_LOG_REPORT        1

Build was successful but on loading the kext, system reboots.

Then I changed: #define WRITE_LOG_REPORT 0 Now the system does not crash because kextutil cannot load the kext . There’s a libkern link error:

SR-Mac-530:~ MacNB$ sudo chown -R 0:0 /Users/MacNB/Downloads/AppleIntelInfo-master/AppleIntelInfo.kext 
Password:
SR-Mac-530:~ MacNB$ sudo chmod -R 755 /Users/MacNB/Downloads/AppleIntelInfo-master/AppleIntelInfo.kext 

SR-Mac-530:~ MacNB$ sudo kextutil -v 2 /Users/MacNB/Downloads/AppleIntelInfo-master/AppleIntelInfo.kext 
Defaulting to kernel file '/System/Library/Kernels/kernel'
Diagnostics for /Users/MacNB/Downloads/AppleIntelInfo-master/AppleIntelInfo.kext:
Code Signing Failure: not code signed
/Users/MacNB/Downloads/AppleIntelInfo-master/AppleIntelInfo.kext appears to be loadable (not including linkage for on-disk libraries).
kext-dev-mode allowing invalid signature -67062 0xFFFFFFFFFFFEFA0A for kext "/Users/MacNB/Downloads/AppleIntelInfo-master/AppleIntelInfo.kext"
kext signature failure override allowing invalid signature -67062 0xFFFFFFFFFFFEFA0A for kext "/Users/MacNB/Downloads/AppleIntelInfo-master/AppleIntelInfo.kext"
Loading /Users/MacNB/Downloads/AppleIntelInfo-master/AppleIntelInfo.kext.
Reading load info for 6 kexts.
Created mkext for architecture x86_64 containing 1 kexts.
Loading /Users/MacNB/Downloads/AppleIntelInfo-master/AppleIntelInfo.kext.
(kernel) Received request from user space to load kext com.pikeralpha.driver.AppleIntelInfo.
(kernel) Loading kext com.pikeralpha.driver.AppleIntelInfo.
(kernel) Allocated link buffer for kext com.pikeralpha.driver.AppleIntelInfo at 0xffffff7f92d3d000 (20480 bytes).
(kernel) kxld[com.pikeralpha.driver.AppleIntelInfo]: The following symbols are unresolved for this kext:
(kernel) kxld[com.pikeralpha.driver.AppleIntelInfo]:    __ZN14AppleIntelInfo11writeReportEv
(kernel) Can't load kext com.pikeralpha.driver.AppleIntelInfo - link failed.
(kernel) Failed to load executable for kext com.pikeralpha.driver.AppleIntelInfo.
(kernel) Kext com.pikeralpha.driver.AppleIntelInfo failed to load (0xdc008016).
(kernel) Failed to load kext com.pikeralpha.driver.AppleIntelInfo (error 0xdc008016).
Failed to load /Users/MacNB/Downloads/AppleIntelInfo-master/AppleIntelInfo.kext - (libkern/kext) link error.
Failed to load /Users/MacNB/Downloads/AppleIntelInfo-master/AppleIntelInfo.kext - (libkern/kext) link error.
Check library declarations for your kext with kextlibs(8).

Ran kextlibs:

SR-Mac-530:~ MacNB$ kextlibs -undef /Users/MacNB/Downloads/AppleIntelInfo-master/AppleIntelInfo.kext
For all architectures:
    com.apple.kpi.iokit = 16.4
    com.apple.kpi.libkern = 16.4

For x86_64:
    2 symbols not found in any library kext:
    _vfs_context_current
    __ZN14AppleIntelInfo11writeReportEv

SR-Mac-530:~ MacNB$ 
  1. So disabling build settings still restarts the system.
  2. setting #define WRITE_LOG_REPORT 0 makes the kext unloadble.
Piker-Alpha commented 7 years ago

@MacNB,

Setting WRITE_LOG_REPORT to 0 is currently still unsupported – the output of log show --predicate 'senderImagePath CONTAINS "AppleIntelInfo"' --info --last Xm is still a mess – but it should get fixed/be improved with a future update. Also. You should run sudo kextlibs with -unsupported

The call to vfs_context_current(); should be replaced with vfs_context_create(NULL); and we should also add a few lines to stop()

    if (mCtx)
    {
        vfs_context_rele(mCtx);
    } 

Note: Note all MSR's are supported on all processors, and that is likely the cause of the crash. We need to figure out the problematic spots.

@bigkahuna666,

The file: /tmp/AppleIntelInfo.dat will only be there if the kext loads without crashing/throwing out errors. This is not the case right now and thus we need to solve that first.

MacNB commented 7 years ago

Thx Piker-Alpha. I made the following changes:


bool AppleIntelInfo::start(IOService *provider)
{
    if (IOService::start(provider))
    {
        simpleLock = IOSimpleLockAlloc();

        if (simpleLock)
        {
            // mCtx = vfs_context_current(); <== removed and added statement below
                    mCtx = vfs_context_create(NULL);

and


void AppleIntelInfo::stop(IOService *provider)
{
    if (mCtx)
    {
        vfs_context_rele(mCtx);
    }

and now there are no kernlib errors. Of course, the system still reboots.

I have two such systems (Dell Inspiron 530). One has the Xeon E5450 (Harpertown arch) and the other has Core-2-Quad Q9300 (Yorkfield arch) running El Capitan. Both run fine.

I downloaded MacCPUID app from Intel. The chipset is P33 [8086:29c0] MacCPUID tells me that both CPU's have MSR feature (but not which ones). I ran the kext on Q9300 based system and it too reboots the system on kextload.

Could it be a platform issue as opposed to a CPU issue ? How do we find the spot of reboot within the kext (I know how to build a kext but not debug it) ?

Piker-Alpha commented 7 years ago

@MacNB

What is the lowest version number of the kext that worked for you?

Also. I made some changes for AppleIntelInfo v1.6 and the RAPL MSR's are likely to trigger a reboot/crash. In short. Take the oldest version possible and work your way up from there.

Please note that I have plans to take care of the RAPL MSR's in a next update, but I cannot say when that version will be released. I have to do all this in spare time at work.

Edit: Version 2.3 is out and includes the RAPL compatibility checks.

MacNB commented 7 years ago

@Piker-Alpha Many thanks (as always) for spending your precious spare time for the community.

The new version builds fine but has dependency issues and does not load at all.

SR-Mac-530:~ MacNB$ sudo kextutil -I -v 2 /Users/MacNB/Downloads/AppleIntelInfo-master-2/AppleIntelInfo.kext 
Defaulting to kernel file '/System/Library/Kernels/kernel'
/Users/MacNB/Downloads/AppleIntelInfo-master-2/AppleIntelInfo.kext - no compatible dependency found for com.apple.kpi.mach.
/Users/MacNB/Downloads/AppleIntelInfo-master-2/AppleIntelInfo.kext - no compatible dependency found for com.apple.kpi.iokit.
/Users/MacNB/Downloads/AppleIntelInfo-master-2/AppleIntelInfo.kext - no compatible dependency found for com.apple.kpi.libkern.
/Users/MacNB/Downloads/AppleIntelInfo-master-2/AppleIntelInfo.kext - no compatible dependency found for com.apple.kpi.bsd.
/Users/MacNB/Downloads/AppleIntelInfo-master-2/AppleIntelInfo.kext - no compatible dependency found for com.apple.kpi.mach.
/Users/MacNB/Downloads/AppleIntelInfo-master-2/AppleIntelInfo.kext - no compatible dependency found for com.apple.kpi.iokit.
/Users/MacNB/Downloads/AppleIntelInfo-master-2/AppleIntelInfo.kext - no compatible dependency found for com.apple.kpi.libkern.
/Users/MacNB/Downloads/AppleIntelInfo-master-2/AppleIntelInfo.kext - no compatible dependency found for com.apple.kpi.bsd.
/Users/MacNB/Downloads/AppleIntelInfo-master-2/AppleIntelInfo.kext - no compatible dependency found for com.apple.kpi.mach.
/Users/MacNB/Downloads/AppleIntelInfo-master-2/AppleIntelInfo.kext - no compatible dependency found for com.apple.kpi.iokit.
/Users/MacNB/Downloads/AppleIntelInfo-master-2/AppleIntelInfo.kext - no compatible dependency found for com.apple.kpi.libkern.
/Users/MacNB/Downloads/AppleIntelInfo-master-2/AppleIntelInfo.kext - no compatible dependency found for com.apple.kpi.bsd.
Diagnostics for /Users/MacNB/Downloads/AppleIntelInfo-master-2/AppleIntelInfo.kext:
Dependency Resolution Failures: 
    Only incompatible kexts found for these libraries: 
        com.apple.kpi.mach
        com.apple.kpi.iokit
        com.apple.kpi.libkern
        com.apple.kpi.bsd

Code Signing Failure: not code signed
SR-Mac-530:~ MacNB$

I changed the Info.plist dependencies from 16.5 to 15.6 and it it's same as before -- reboots my system.

So I tried it my laptop (Sandybridge i5-2410M CPU) after changing the dependencies in the Info.plist and it too reboots the laptop. The previous version (v2.2) worked fine on the same laptop.

Piker-Alpha commented 7 years ago

Sorry. My fault. I didn't pay enough attention to a question from a co-worker who compiled it in XCode. Changes undone in one of the latest commits. Thanks.

MacNB commented 7 years ago

@Piker-Alpha Thx. Dependencies fixed but this new v2.3 reboots my laptop (Sandybridge i5-2410M CPU). I went back to v2.2 on the laptop and that works fine.

On the two desktops (Xeon E5450 and Q9300), they also reboot on load with this new v2.3. EDIT: I tried it with build settings to:

/*
 * Build settings (0 = disable feature / 1 = enable feature)
 */

#define REPORT_RAPL_MSRS        0
#define REPORT_MSRS         0
#define REPORT_IGPU_P_STATES        0
#define REPORT_C_STATES         0
#define REPORT_IPG_STYLE        0
#define REPORT_INTEL_REGS       0
#define ENABLE_HWP          0

#define WRITE_LOG_REPORT        1

but makes no difference -- still reboots the system.

I can't remember running previous old versions on these desktops so cannot tell if the old version ran or not. I did find a binary for v1.0 and v1.5 and they both do same -- reboot the system.

EDIT: For the laptop CPU model is 2A:

sysctl -x machdep.cpu.model
machdep.cpu.model: 0x0000002a

For the Xeon E5450 and Q9300 CPUs, the model is

sysctl -x machdep.cpu.model
machdep.cpu.model: 0x00000017
Piker-Alpha commented 7 years ago

Thanks. By the way. Did you compile the source code for your copy of v2.2 yourself?

MacNB commented 7 years ago

Yes I built it my self. Used Xcode 8.2.1

Piker-Alpha commented 7 years ago

AppleIntelInfo.kext v2.3 works on a i5-2500K and i7-2600K after taking out line 1005 in AppleIntelInfo.cpp compiled on 10.9.5 and Xcode Version 6.0 (6A215l)

MacNB commented 7 years ago

OK Thx. I commented out that line 1005 and now it loads on the laptop with i5-2410M CPU.

Still no joy on the desktops (with Xeon E5450 & Q9300 CPUs).

Piker-Alpha commented 7 years ago

Ok cool. Thank you for this confirmation. One issue less to worry about, but solving the incompatibility issues for older processors is going to take some time – need to check all MSR's...

Update: Checks for IA32_APERF and IA32_MPERF added.

We also need to check for C6 (MSR_PKG_C6_RESIDENCY/MSR_PKGC6_IRTL) and C7 (MSR_PKG_C7_RESIDENCY/MSR_PKGC7_IRTL) compatibility – back in the old days you only had C1 and C3.

Can you comment them out and see if that works?

Update-2: I added a lot more checks and would love to hear from you if it still crashes.

MacNB commented 7 years ago

Thx for your perseverance. Made those changes you mentioned (hopefully) but no change -- still reboots. I commented-out the following lines:

// IOLOG("MSR_PKGC6_IRTL...................(0x60b) : 0x%llX\n", (unsigned long long)rdmsr64(MSR_PKGC6_IRTL));

// IOLOG("MSR_PKGC7_IRTL...................(0x60c) : 0x%llX\n", (unsigned long long)rdmsr64(MSR_PKGC7_IRTL));

// IOLOG("MSR_PKG_C6_RESIDENCY.............(0x3f9) : 0x%llX\n", (unsigned long long)rdmsr64(MSR_PKG_C6_RESIDENCY));

// IOLOG("MSR_PKG_C7_RESIDENCY.............(0x3fa) : 0x%llX\n", (unsigned long long)rdmsr64(MSR_PKG_C7_RESIDENCY));

Let me know how else I can help.

Piker-Alpha commented 7 years ago

Are you using the latest source code? I think that it should work with:

#define REPORT_MSRS         0
#define REPORT_RAPL_MSRS        0
#define REPORT_HWP          0
#define REPORT_HDC          0

#define REPORT_IGPU_P_STATES        0
#define REPORT_C_STATES         0
#define REPORT_IPG_STYLE        0
#define REPORT_INTEL_REGS       0

#define ENABLE_HWP          0

#define WRITE_LOG_REPORT        1

What we want, at first, it to stop it from crashing at launch. After that works, then we can try to locate the problematic spots in the source code.

MacNB commented 7 years ago

Yes I used your latest sources, changes the build settings as per your last msg above. I even commented out the previous four IOLOG statements but still reboots.

Some access to the h/w is causing a fatal exception I guess but wouldn't know where to search. Here try different things to help solve this one :)

Piker-Alpha commented 7 years ago

Ok. We may be running into another issue. Please boot with -cpuid and tell me what you see in the log. What we are looking for is the CPUID output. Please attach that here, or e-mail me. Thanks!

MacNB commented 7 years ago

I entered -cpuid into Clover's boot args option but do not see any log entries in Console. Clover's log (bdmesg output) showed:

2:929  0:000  === [ GetCPUProperties ] ==================================
2:929  0:000  CPU Vendor = 756E6547 Model=10676
2:929  0:000  got cores from CPUID_1 = 4
2:929  0:000  The CPU not supported turbo
2:929  0:000  BrandString = Intel(R) Xeon(R) CPU           E5450  @ 3.00GHz
2:929  0:000  MSR dumps:
2:929  0:000    @0x00CD=80C
2:929  0:000    @0x0198=91D091D0600091D
2:929  0:000  FSBFrequency=444MHz DMIvalue=333330kHz
2:929  0:000  Corrected FSBFrequency=333MHz
2:929  0:000  Vendor/Model/Stepping: 0x756E6547/0x17/0x6
2:929  0:000  Family/ExtFamily: 0x6/0x0
2:929  0:000  MaxDiv/MinDiv: 9.0/6
2:929  0:000  Turbo: 10/0/0/0
2:929  0:000  Features: 0xBFEBFBFF
2:929  0:000  Threads: 4
2:929  0:000  Cores: 4
2:929  0:000  FSB: 333 MHz
2:929  0:000  CPU: 4000 MHz
2:929  0:000  TSC: 4000 MHz
2:929  0:000  PIS: 1333 MHz

Is that what you were looking for ?

Piker-Alpha commented 7 years ago

Unfortunately not. Please add debug=0x12a to your boot arguments and run debugMachKernel.sh

MacNB commented 7 years ago

I ran debugMackKernel.sh changed kernel flags in /Library/Preferences/SystemConfiguration/com.apple.Boot.plist to

<dict>
        <key>Kernel Flags</key>
        <string>debug=0x12a acpi_layer=0x08 acpi_level=0x02 msgbuf=309212 -cpuid</string>
</dict>

Made no difference --- still no CPUID in any log file.

Piker-Alpha commented 7 years ago

Your boot arguments are fine, but I would add -s. This way you can see that the extra (long) output is there (after running debugMackKernel.sh). The next step is to run:

log show --info --debug --start "2017-02-27" > log.txt
open log.txt

Search for "cpuid" and/or "cpuid_fn".

Note that there is something weird going on with the output of the log command. The timezone appears to be way off. I need the --start "2017-02-27" arguments or the output of today isn't even there.

Hope this helps.

MacNB commented 7 years ago

Yes it did. I used todays date it was fine:

SR-Mac-530:~ MacNB$ log show --info --debug --start "2017-02-28" | grep cpuid
2017-02-28 17:10:26.448473+0000 0x65       Default     0x0                  0      kernel: Kernel boot args: 'arch=x86_64 npci=0x2000 kext-dev-mode=1  debug=0x12a acpi_layer=0x08 acpi_level=0x02 msgbuf=309212 -cpuid -s'
2017-02-28 17:16:37.572217+0000 0x298      Default     0x0                  0      kernel: cpuid_set_generic_info(0xffffff801b0f7038)
2017-02-28 17:16:37.574550+0000 0x298      Default     0x0                  0      kernel: cpuid_fn(0x00000000) eax:0x0000000a ebx:0x756e6547 ecx:0x6c65746e edx:0x49656e69
2017-02-28 17:16:37.576988+0000 0x298      Default     0x0                  0      kernel: cpuid_fn(0x80000000) eax:0x80000008 ebx:0x00000000 ecx:0x00000000 edx:0x00000000
2017-02-28 17:16:37.579364+0000 0x298      Default     0x0                  0      kernel: cpuid_fn(0x80000002) eax:0x65746e49 ebx:0x2952286c ecx:0x6f655820 edx:0x2952286e
2017-02-28 17:16:37.581696+0000 0x298      Default     0x0                  0      kernel: cpuid_fn(0x80000003) eax:0x55504320 ebx:0x20202020 ecx:0x20202020 edx:0x45202020
2017-02-28 17:16:37.584020+0000 0x298      Default     0x0                  0      kernel: cpuid_fn(0x80000004) eax:0x30353435 ebx:0x20402020 ecx:0x30302e33 edx:0x007a4847
2017-02-28 17:16:37.586310+0000 0x298      Default     0x0                  0      kernel: cpuid_fn(0x80000006) eax:0x00000000 ebx:0x00000000 ecx:0x18008040 edx:0x00000000
2017-02-28 17:16:37.588698+0000 0x298      Default     0x0                  0      kernel: cpuid_fn(0x80000008) eax:0x00003026 ebx:0x00000000 ecx:0x00000000 edx:0x00000000
2017-02-28 17:16:37.591009+0000 0x298      Default     0x0                  0      kernel: cpuid_fn(0x00000001) eax:0x00010676 ebx:0x00040800 ecx:0x000ce3bd edx:0xbfebfbff
2017-02-28 17:16:37.593268+0000 0x298      Default     0x0                  0      kernel: cpuid_fn(0x80000001) eax:0x00000000 ebx:0x00000000 ecx:0x00000001 edx:0x20100800
2017-02-28 17:16:37.622580+0000 0x298      Default     0x0                  0      kernel: cpuid_fn(0x80000007) eax:0x00000000 ebx:0x00000000 ecx:0x00000000 edx:0x00000000
2017-02-28 17:16:37.626355+0000 0x298      Default     0x0                  0      kernel: cpuid_fn(0x00000005) eax:0x00000040 ebx:0x00000040 ecx:0x00000003 edx:0x00002220
2017-02-28 17:16:37.636822+0000 0x298      Default     0x0                  0      kernel: cpuid_fn(0x00000006) eax:0x00000001 ebx:0x00000002 ecx:0x00000001 edx:0x00000000
2017-02-28 17:16:37.657994+0000 0x298      Default     0x0                  0      kernel: cpuid_fn(0x0000000a) eax:0x07280202 ebx:0x00000000 ecx:0x00000000 edx:0x00000503
2017-02-28 17:16:37.672607+0000 0x298      Default     0x0                  0      kernel: cpuid_set_cpufamily(0xffffff801b0f7038) returning 0x78ea4fbc
2017-02-28 17:16:37.674256+0000 0x298      Default     0x0                  0      kernel: cpuid_set_cache_info(0xffffff801b0f7038)
2017-02-28 17:16:37.676505+0000 0x298      Default     0x0                  0      kernel: cpuid_fn(0x00000002) eax:0x05b0b101 ebx:0x005657f0 ecx:0x00000000 edx:0x2cb4304e
2017-02-28 17:16:37.678904+0000 0x298      Default     0x0                  0      kernel: cpuid_fn(0x00000000) eax:0x0000000a ebx:0x756e6547 ecx:0x6c65746e edx:0x49656e69
2017-02-28 17:16:37.680563+0000 0x298      Default     0x0                  0      kernel: cpuid(4) index=0 eax=0xc000121
2017-02-28 17:16:37.687296+0000 0x298      Default     0x0                  0      kernel: cpuid(4) index=1 eax=0xc000122
2017-02-28 17:16:37.693640+0000 0x298      Default     0x0                  0      kernel: cpuid(4) index=2 eax=0xc004143
2017-02-28 17:16:37.700379+0000 0x298      Default     0x0                  0      kernel: cpuid(4) index=3 eax=0x0
2017-02-28 17:16:37.713120+0000 0x298      Default     0x0                  0      kernel: cpuid_set_info():
SR-Mac-530:~ MacNB$

I didn't save the whole log but just grep'ed for 'cpuid' Hope that gives a clue to debug.