前言
虽然自臭名昭著的 Spectre 和 Meltdown 漏洞首次公布已经过去将近 4 年,但直到现在依然有处理器推测执行漏洞和其他处理器漏洞不断被公布。这些漏洞大部分是通过 CPU 微码和操作系统补丁来解决的,但因为推测执行技术本就是让处理器提升效率的,打上补丁之后处理器性能不可避免的会受到影响。如果你发现系统越更新越慢,那么你可能是 Intel 处理器的受害者(因为 Intel 处理器受到的漏洞影响最多,甚至还包括 TSX 这种技术)。通过在双路 E5-2620 v3 + CentOS 8 4.18 内核环境下的测试,关闭 Linux 内核的漏洞缓解措施之后, Geekbench 5 单核性能提升了 3.3%,多核分数提升了 2.6%,虽然性能提升不大,但你要知道 Intel 从 Haswell 到 Broadwell 架构和从 Broadwell 到 Skylake 架构的每次 IPC 提升也就 3%-4% 左右,对于这种性能本就捉襟见肘的老架构处理器来说,蚊子腿也是肉,毕竟家用也没什么重要数据,但在生产场景下还是不要使用了。
Windows
修改注册表,关闭 Windows 上相关漏洞的缓解措施。注意这两条注册表可能不能完全消除 CPU 微码补丁对性能的影响。
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v FeatureSettingsOverride /t REG_DWORD /d 3 /f
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v FeatureSettingsOverrideMask /t REG_DWORD /d 3 /f
重启系统
RHEL
修改内核启动参数
vim /etc/default/grub
在 GRUB_CMDLINE_LINUX=
此行最后加入下面的参数:
noibrs noibpb nopti nospectre_v2 nospectre_v1 l1tf=off nospec_store_bypass_disable no_stf_barrier mds=off tsx=on tsx_async_abort=off mitigations=off
重新生成 grub.cfg
文件
grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
grub2-mkconfig -o /boot/grub2/grub.cfg
重启系统
systemctl reboot
VMware ESXi
可以在高级设置中关闭一个漏洞的 Mitigation ,但没有其余的可供关闭的选项。
参考链接
- Transient execution CPU vulnerability
- The Performance Impact Of MDS / Zombieload Plus The Overall Cost Now Of Spectre/Meltdown/L1TF/MDS
- Windows Server guidance to protect against speculative execution side-channel vulnerabilities
- Speculative Execution Exploit Performance Impacts - Describing the performance impacts to security patches for CVE-2017-5754 CVE-2017-5753 and CVE-2017-5715
- VMware Performance Impact for CVE-2017-5753, CVE-2017-5715, CVE-2017-5754 (aka Spectre and Meltdown) (52337)
- Make linux fast again