diff --git a/Changelog.md b/Changelog.md index 060e289693f8425ef4abc5fff41e12b28af7782e..2363077d711c190ddf335a820964ed849ec1f5d3 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,6 +3,8 @@ OpenCore Changelog #### v0.7.9 - Added auto-detect `macOS Installer` volume name for use when `.disk_label` file cannot be displayed - Added `--restore-nosnoop` flag to AudioDxe, making v0.7.7 fix for Windows sound opt-in +- Added new method to disable trim when `SetApfsTrimTimeout` is set to zero +- Fixed `SetApfsTrimTimeout` on macOS 12 (only works when set to zero) #### v0.7.8 - Updated ocvalidate to warn about insecure `DmgLoading` with secure `SecureBootModel` (already disallowed in runtime) diff --git a/Docs/Configuration.md5 b/Docs/Configuration.md5 index 80ebff7ffc9993e30d2d25c50a416faeff5a1061..d90a7605be92ea0dd036480891de04cc2d4fdc46 100644 --- a/Docs/Configuration.md5 +++ b/Docs/Configuration.md5 @@ -1 +1 @@ -8fe92652e6b6bf444b97fb743cae2a52 +63ebe375542ad0f079cc7071555dd405 diff --git a/Docs/Configuration.pdf b/Docs/Configuration.pdf index de99604c3e58a584ade54c42ffc09f6e013f8ecf..2fa9776940d5761eace9c5846b8c6c341fd8f4aa 100644 Binary files a/Docs/Configuration.pdf and b/Docs/Configuration.pdf differ diff --git a/Docs/Configuration.tex b/Docs/Configuration.tex index 35889977dee325f7b7802f678e575b6d6f8ca58d..40c64575830085fd696c6306eb7977ec7e78e3ea 100755 --- a/Docs/Configuration.tex +++ b/Docs/Configuration.tex @@ -2748,6 +2748,9 @@ blocking. \href{https://interface31.ru/tech_it/2015/04/mozhno-li-effektivno-ispolzovat-ssd-bez-podderzhki-trim.html}{article} for details. + As of macOS 12.0, it is no longer possible to set trim timeout for APFS filesystems. + However, trim can be disabled when the timeout value is set to \texttt{0}. + \item \texttt{ThirdPartyDrives}\\ \textbf{Type}: \texttt{plist\ boolean}\\ diff --git a/Docs/Differences/Differences.pdf b/Docs/Differences/Differences.pdf index e34f7cfb22d06923bd42083189c12a3d36b5fd9a..117db958a35746980521e9f6f5f8e1e4a4fe17e6 100644 Binary files a/Docs/Differences/Differences.pdf and b/Docs/Differences/Differences.pdf differ diff --git a/Docs/Differences/Differences.tex b/Docs/Differences/Differences.tex index 9d22d8da89207168a0b68701e9ff8770be7a6d95..b8a94a536747501a82531021911e8f86c7a4c3cb 100644 --- a/Docs/Differences/Differences.tex +++ b/Docs/Differences/Differences.tex @@ -1,7 +1,7 @@ \documentclass[]{article} %DIF LATEXDIFF DIFFERENCE FILE -%DIF DEL PreviousConfiguration.tex Wed Feb 9 09:37:10 2022 -%DIF ADD ../Configuration.tex Wed Feb 9 23:42:58 2022 +%DIF DEL PreviousConfiguration.tex Thu Feb 10 15:29:05 2022 +%DIF ADD ../Configuration.tex Thu Feb 10 19:56:56 2022 \usepackage{lmodern} \usepackage{amssymb,amsmath} @@ -118,7 +118,7 @@ %DIF HYPERREF PREAMBLE %DIF PREAMBLE \providecommand{\DIFadd}[1]{\texorpdfstring{\DIFaddtex{#1}}{#1}} %DIF PREAMBLE \providecommand{\DIFdel}[1]{\texorpdfstring{\DIFdeltex{#1}}{}} %DIF PREAMBLE -%DIF LISTINGS PREAMBLE %DIF PREAMBLE +%DIF COLORLISTINGS PREAMBLE %DIF PREAMBLE \RequirePackage{listings} %DIF PREAMBLE \RequirePackage{color} %DIF PREAMBLE \lstdefinelanguage{DIFcode}{ %DIF PREAMBLE @@ -2808,7 +2808,11 @@ blocking. \href{https://interface31.ru/tech_it/2015/04/mozhno-li-effektivno-ispolzovat-ssd-bez-podderzhki-trim.html}{article} for details. -\item + \DIFaddbegin \DIFadd{As of macOS 12.0, it is no longer possible to set trim timeout for APFS filesystems. + However, trim can be disabled when the timeout value is set to }\texttt{\DIFadd{0}}\DIFadd{. +} + +\DIFaddend \item \texttt{ThirdPartyDrives}\\ \textbf{Type}: \texttt{plist\ boolean}\\ \textbf{Failsafe}: \texttt{false}\\ diff --git a/Docs/Errata/Errata.pdf b/Docs/Errata/Errata.pdf index 385b11c2443631a4b6c1b36b9b067ed356c057eb..0039f0e9aa0269319c182563c3c414f0b40ff8ea 100644 Binary files a/Docs/Errata/Errata.pdf and b/Docs/Errata/Errata.pdf differ diff --git a/Library/OcAppleKernelLib/CommonPatches.c b/Library/OcAppleKernelLib/CommonPatches.c index 3f6846d71c557a09c8a668ef8873691e54426475..eda057043c5adc2e67e07bbd3ab5c7ca667916be 100644 --- a/Library/OcAppleKernelLib/CommonPatches.c +++ b/Library/OcAppleKernelLib/CommonPatches.c @@ -1979,45 +1979,38 @@ mApfsTimeoutPatch = { .Limit = 0 }; -STATIC -UINT8 -mApfsTimeoutV2Find[] = { - 0x40, 0x42, 0x0F, 0x00 -}; +VOID +PatchSetApfsTimeout ( + IN UINT32 Timeout + ) +{ + // FIXME: This is really ugly, make quirks take a context param. + DEBUG ((DEBUG_INFO, "OCAK: Registering %u APFS timeout\n", Timeout)); + CopyMem (&mApfsTimeoutReplace[2], &Timeout, sizeof (Timeout)); +} STATIC UINT8 -mApfsTimeoutV2Replace[] = { - 0x00, 0x02, 0x00, 0x00 +mApfsDisableTrimReplace[] = { + 0x31, 0xC0, ///< xor eax, eax + 0xC3 ///< ret }; - STATIC PATCHER_GENERIC_PATCH -mApfsTimeoutV2Patch = { - .Comment = DEBUG_POINTER ("ApfsTimeout V2"), - .Base = "_spaceman_scan_free_blocks", - .Find = mApfsTimeoutV2Find, +mApfsDisableTrimPatch = { + .Comment = DEBUG_POINTER ("ApfsTimeout disable trim"), + .Base = "_spaceman_iterate_free_extents_internal", + .Find = NULL, .Mask = NULL, - .Replace = mApfsTimeoutV2Replace, + .Replace = mApfsDisableTrimReplace, .ReplaceMask = NULL, - .Size = sizeof (mApfsTimeoutV2Find), - .Count = 2, + .Size = sizeof (mApfsDisableTrimReplace), + .Count = 1, .Skip = 0, - .Limit = 4096 + .Limit = 0 }; -VOID -PatchSetApfsTimeout ( - IN UINT32 Timeout - ) -{ - // FIXME: This is really ugly, make quirks take a context param. - DEBUG ((DEBUG_INFO, "OCAK: Registering %u APFS timeout\n", Timeout)); - CopyMem (&mApfsTimeoutReplace[2], &Timeout, sizeof (Timeout)); - CopyMem (&mApfsTimeoutV2Replace[0], &Timeout, sizeof (Timeout)); -} - STATIC EFI_STATUS PatchSetApfsTrimTimeout ( @@ -2036,23 +2029,33 @@ PatchSetApfsTrimTimeout ( return EFI_NOT_FOUND; } - if (KernelVersion >= KERNEL_VERSION_MONTEREY_MIN) { - Status = PatcherApplyGenericPatch (Patcher, &mApfsTimeoutV2Patch); + // + // Disable trim using another patch when timeout is 0. + // + if (mApfsTimeoutReplace[2] == 0) { + Status = PatcherApplyGenericPatch (Patcher, &mApfsDisableTrimPatch); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_INFO, "OCAK: Failed to apply patch SetApfsTrimTimeoutV2 - %r\n", Status)); + DEBUG ((DEBUG_INFO, "OCAK: Failed to apply patch ApfsDisableTrim - %r\n", Status)); } else { - DEBUG ((DEBUG_INFO, "OCAK: Patch success SetApfsTrimTimeoutV2\n")); + DEBUG ((DEBUG_INFO, "OCAK: Patch success ApfsDisableTrim\n")); } - } else { + + return Status; + } + + if (KernelVersion < KERNEL_VERSION_MONTEREY_MIN) { Status = PatcherApplyGenericPatch (Patcher, &mApfsTimeoutPatch); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_INFO, "OCAK: Failed to apply patch SetApfsTrimTimeout - %r\n", Status)); } else { DEBUG ((DEBUG_INFO, "OCAK: Patch success SetApfsTrimTimeout\n")); } + + return Status; } - return Status; + DEBUG ((DEBUG_INFO, "OCAK: Skipping patch SetApfsTrimTimeout on macOS 12.0+\n")); + return EFI_SUCCESS; } //