-
Notifications
You must be signed in to change notification settings - Fork 23
OcAppleKernelLib: Added patch for MSR MISC_PWR_MGMT (1AAh) #12
Conversation
…e system firmware has locked that register. This change allows Skylake-SP (Xeon Scalable) CPUs to boot with their native CPU ID rather than emulating an older chip. Might also help Xeon W chips which share the same ID.
@mrmiller please make the patch unconditional. If this MSR is locked, all the others are pretty much certainly locked as well. Even if we put aside our firmware logic knowledge, there is one more reason: MSR values are local per core, and GIGABYTE once forgot to update BSP (primary core) |
…ways apply the patch.
Sounds good! Removed the check for whether the MSR is locked or not. |
Sorry for not noticing this earlier, but actually there are two more issues with this patch.
|
Will do.
Will do.
I count 4 calls to The risk seems to be that we match against a sequence we shouldn't have and change something unrelated. It seems somewhat unlikely for this 7 byte sequence, but I'm not sure Count does a good job protecting us from a bad replacement anyways. |
DEBUG ((DEBUG_WARN, "OCAK: Failed to patch writes to MSR_MISC_PWR_MGMT - %r, trying dbg\n", Status)); | ||
Status = PatcherApplyGenericPatch (Patcher, &mMiscPwrMgmtDbgPatch); | ||
} | ||
|
||
if (!RETURN_ERROR (Status)) { | ||
++ Replacements; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be ++Replacements;
without space probably, and add a DEBUG_INFO
log here, so that we have in the log that the patch has happened. Thanks!
Looking at the debug kernel, there seems to be an additional function that writes to MSR
So we could look for the sequence |
Hello,
|
As for the call under If so, then there seems to be no need to do the precise matching, just remove EDIT: 4 ones. Sorry for my blindness. |
Yes, it definitely should be. I hadn't looked at the debug kernel until just now and noticed the same thing.
I agree. We don't really need to patch the reads for that MSR, but we currently are as well. What do you think about expanding the Find sequence slightly to look for the (To be pedantic, there are 4 matches to the current sequence... 2 call |
@mrmiller of course it was 4, I just managed to overlook it. But you made a good claim for 0 vs 4, and with the second debug hit it is probably better to use count 0 for both.
void __cdecl xcpm_enable_hw_coordination()
{
uint64_t_0 msrval; // [rsp+8h] [rbp-8h]
msrval = xcpm_rdmsr64(0x1AAu) & 0xFFFFFFFFFFFFFFFELL;
xcpm_wrmsr64(0x1AAu, msrval);
}
void __cdecl xcpm_hwp_enable()
{
uint64_t_0 msrval; // [rsp+8h] [rbp-8h]
msrval = xcpm_rdmsr64(0x1AAu) | 0x40;
xcpm_wrmsr64(0x1AAu, msrval);
xcpm_wrmsr64(0x770u, 1uLL);
if ( xcpm_config.xcpm_hwp_pkg_mode )
xcpm_wrmsr64(0x774u, 0x40000FFFF07uLL);
} So I think patching reads and writes is ok. It is worse to extend the patch as there are many ways to assign I also noted that you print nothing on success. Please do it for both debug and release patches separately, so that we have a log entry for debugging. |
Better not, so that we are consistent with CFG Lock patch. |
…ites to the MSR 1AAh. Add logging.
Alright, removed the limitations on the patch applications for both and added a log line for success. |
Anyway... It simply is worth nothing. Up to you. ^^ |
I'm not an opcode wizard so I'll leave this to you two to debate which is more clear and elegant. They're functionally equivalent so I'm happy to change both or neither! |
Well, whatever, let's ignore it. Finally, the changes look good enough to me. Let's wait vit for the last review and we are about to merge it. :) |
Thanks, merged! |
Tested this patch on my Xenon W-2175 and it works like a charm. Thank´s all of you for your contribution. |
Hmm... are you sure that log was generated using the latest version? I don't see any entries related to the new change and the other entries like |
No it was generated with the patch above. |
No worries! I started by testing it as a patch in my config too. Just was curious because the log didn’t look like it came from the latest OC so wanted to confirm. So happy to hear it works for you too! |
here we go. |
Beautiful. Thanks for testing it! |
Patch kernel writes to MISC_PWR_MGMT (1AAh) if the system firmware has locked that register (flag
0x2000
).This change allows Skylake-SP (Xeon Scalable) CPUs to boot with their native CPU ID rather than emulating an older chip. I suspect it will also work for Xeon W chips which share the same ID and capabilities.
I'm not sure if this should be part of
AppleXcpmExtraMsrs
or not but starting with it there based on @vit9696's suggestion. See acidanthera/bugtracker#365.CCing @PMheart who I believe was involved in similar discussions working around issues with Xeon W, e.g. this CPUID patch.
This discussion thread about Xeon Ws may also be relevant.