Skip to content

Commit

Permalink
OcAppleKernelLib: Added global MSR 35h fix to ProvideCurrentCpuInfo
Browse files Browse the repository at this point in the history
This allows `-cpu host` in KVM
  • Loading branch information
vit9696 committed Feb 12, 2022
1 parent 9d7bb64 commit ad4414c
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 12 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ OpenCore Changelog
- Added script to build qemu recovery images to macrecovery
- Fixed selecting `SecureBootModel` on hypervisors (should be `x86legacy`)
- Added kext blocking `Strategy` for prelinked and newer
- Added global MSR 35h fix to `ProvideCurrentCpuInfo`, allowing `-cpu host` in KVM

#### v0.7.8
- Updated ocvalidate to warn about insecure `DmgLoading` with secure `SecureBootModel` (already disallowed in runtime)
Expand Down
2 changes: 1 addition & 1 deletion Docs/Configuration.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5653169e52602ebc7ba6439a3e23b6bc
af8312e880f1b5c8f1773e840ef3dbf0
Binary file modified Docs/Configuration.pdf
Binary file not shown.
2 changes: 2 additions & 0 deletions Docs/Configuration.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2721,6 +2721,8 @@ \subsection{Quirks Properties}\label{kernelpropsquirks}
\tightlist
\item For Microsoft Hyper-V it provides the correct TSC and FSB values
to the kernel, as well as disables CPU topology validation (10.8+).
\item For KVM and other hypervisors it provides precomputed MSR 35h
values solving kernel panic with \texttt{-cpu host}.
\item For Intel CPUs it adds support for asymmetrical SMP systems
(e.g. Intel Alder Lake) by patching core count to thread count along
with the supplemental required changes (10.14+).
Expand Down
Binary file modified Docs/Differences/Differences.pdf
Binary file not shown.
8 changes: 5 additions & 3 deletions Docs/Differences/Differences.tex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
\documentclass[]{article}
%DIF LATEXDIFF DIFFERENCE FILE
%DIF DEL PreviousConfiguration.tex Sat Feb 12 00:03:53 2022
%DIF ADD ../Configuration.tex Sat Feb 12 00:03:53 2022
%DIF DEL PreviousConfiguration.tex Thu Feb 10 18:56:25 2022
%DIF ADD ../Configuration.tex Sat Feb 12 04:35:26 2022

\usepackage{lmodern}
\usepackage{amssymb,amsmath}
Expand Down Expand Up @@ -2786,7 +2786,9 @@ \subsection{Quirks Properties}\label{kernelpropsquirks}
\tightlist
\item For Microsoft Hyper-V it provides the correct TSC and FSB values
to the kernel, as well as disables CPU topology validation (10.8+).
\item For Intel CPUs it adds support for asymmetrical SMP systems
\item For \DIFaddbegin \DIFadd{KVM and other hypervisors it provides precomputed MSR 35h
values solving kernel panic with }\texttt{\DIFadd{-cpu host}}\DIFadd{.
}\item \DIFadd{For }\DIFaddend Intel CPUs it adds support for asymmetrical SMP systems
(e.g. Intel Alder Lake) by patching core count to thread count along
with the supplemental required changes (10.14+).
\end{itemize}
Expand Down
Binary file modified Docs/Errata/Errata.pdf
Binary file not shown.
27 changes: 19 additions & 8 deletions Library/OcAppleKernelLib/CpuidPatches.c
Original file line number Diff line number Diff line change
Expand Up @@ -1215,14 +1215,15 @@ mProvideCurrentCpuInfoTopologyCorePerPackageV2Patch = {

STATIC
EFI_STATUS
PatchProvideCurrentCpuInfoForAmpCpu (
PatchProvideCurrentCpuInfoMSR35h (
IN OUT PATCHER_CONTEXT *Patcher,
IN OC_CPU_INFO *CpuInfo,
IN UINT32 KernelVersion
)
{
EFI_STATUS Status;
UINT32 CoreThreadCount;
BOOLEAN IsAmpCpu;

//
// TODO: We can support older, just there is no real need.
Expand All @@ -1233,8 +1234,20 @@ PatchProvideCurrentCpuInfoForAmpCpu (
return EFI_SUCCESS;
}

CoreThreadCount =
(((UINT32) CpuInfo->ThreadCount) << 16U) | ((UINT32) CpuInfo->ThreadCount);
IsAmpCpu = (CpuInfo->ThreadCount % CpuInfo->CoreCount) != 0;

//
// Provide real values for normal CPUs.
// Provide Thread=Thread for AMP (ADL) CPUs.
//
if (IsAmpCpu) {
CoreThreadCount =
(((UINT32) CpuInfo->ThreadCount) << 16U) | ((UINT32) CpuInfo->ThreadCount);
} else {
CoreThreadCount =
(((UINT32) CpuInfo->CoreCount) << 16U) | ((UINT32) CpuInfo->ThreadCount);
}

CopyMem (
&mProvideCurrentCpuInfoTopologyCoreCountReplace[1],
&CoreThreadCount,
Expand All @@ -1248,7 +1261,7 @@ PatchProvideCurrentCpuInfoForAmpCpu (

DEBUG ((DEBUG_INFO, "OCAK: Patching MSR 35h to %08x - %r\n", CoreThreadCount, Status));

if (EFI_ERROR (Status)) {
if (EFI_ERROR (Status) || !IsAmpCpu) {
return Status;
}

Expand Down Expand Up @@ -1318,9 +1331,8 @@ PatchProvideCurrentCpuInfo (

ASSERT (Patcher != NULL);

if (!CpuInfo->Hypervisor && CpuInfo->Vendor[0] == CPUID_VENDOR_INTEL) {
return PatchProvideCurrentCpuInfoForAmpCpu (Patcher, CpuInfo, KernelVersion);
}
Status = EFI_SUCCESS;
Status |= PatchProvideCurrentCpuInfoMSR35h (Patcher, CpuInfo, KernelVersion);

Start = ((UINT8 *) MachoGetMachHeader (&Patcher->MachContext));

Expand All @@ -1337,7 +1349,6 @@ PatchProvideCurrentCpuInfo (
//
// Pull required symbols.
//
Status = EFI_SUCCESS;
Status |= PatcherGetSymbolAddress (Patcher, "_tsc_init", (UINT8 **) &TscInitFunc);
Status |= PatcherGetSymbolAddress (Patcher, "_tmrCvt", (UINT8 **) &TmrCvtFunc);

Expand Down

0 comments on commit ad4414c

Please sign in to comment.