Score:0

Enable Intel Turbo Boost from userspace with secureboot enabled

id flag

On my Laptop (Acer ES1-562-5191) I have an Intel Core i5-7200U which normally runs at 2.50GHz. I have turbo boost enabled and it works. Everything is fine except for the fact that at a certain power level (around 15%) Turbo Boost gets disabled. It doesn't get re-enabled after charging the laptop. The only way to fix this is to restart the laptop.

Before I enabled Secure Boot I was able to easily re-enable turbo boost, but because of kernel lockdown, I am unable to write to those files now.

I have tried several tools to do this and as far as I know, it is impossible.

The solutions I have in my head are to either: Find a way to re-enable turbo boost after it has been disabled, or find a way to stop the computer from disabling it.

$ uname -a
Linux Jaco-LAPTOP 5.11.0-22-generic #23-Ubuntu SMP Thu Jun 17 00:34:23 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
$ lspci
00:00.0 Host bridge: Intel Corporation Xeon E3-1200 v6/7th Gen Core Processor Host Bridge/DRAM Registers (rev 02)
00:02.0 VGA compatible controller: Intel Corporation HD Graphics 620 (rev 02)
00:14.0 USB controller: Intel Corporation Sunrise Point-LP USB 3.0 xHCI Controller (rev 21)
00:15.0 Signal processing controller: Intel Corporation Sunrise Point-LP Serial IO I2C Controller #0 (rev 21)
00:15.1 Signal processing controller: Intel Corporation Sunrise Point-LP Serial IO I2C Controller #1 (rev 21)
00:16.0 Communication controller: Intel Corporation Sunrise Point-LP CSME HECI #1 (rev 21)
00:17.0 SATA controller: Intel Corporation Sunrise Point-LP SATA Controller [AHCI mode] (rev 21)
00:1c.0 PCI bridge: Intel Corporation Sunrise Point-LP PCI Express Root Port #5 (rev f1)
00:1c.5 PCI bridge: Intel Corporation Sunrise Point-LP PCI Express Root Port #6 (rev f1)
00:1f.0 ISA bridge: Intel Corporation Sunrise Point-LP LPC Controller (rev 21)
00:1f.2 Memory controller: Intel Corporation Sunrise Point-LP PMC (rev 21)
00:1f.3 Audio device: Intel Corporation Sunrise Point-LP HD Audio (rev 21)
00:1f.4 SMBus: Intel Corporation Sunrise Point-LP SMBus (rev 21)
01:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 15)
02:00.0 Network controller: Intel Corporation Dual Band Wireless-AC 3168NGW [Stone Peak] (rev 10)

Writing to the MSR registers is the ultimate way in which most software changes the turbo boost state. This does not work.

# wrmsr -p0 0x1a0 0x4000850089
wrmsr: pwrite: Operation not permitted

Here you can see an example dmesg output from both i7z and wrmsr.

# dmesg
...
[40160.847525] Lockdown: i7z: raw MSR access is restricted; see man kernel_lockdown.7
[41009.622949] Lockdown: wrmsr: raw MSR access is restricted; see man kernel_lockdown.7

Any suggestions?

Score:0
gn flag

It is on purpose that more recent kernels have defaulted to disabling user write access to MSRs (Machine Specific Registers), as too many were getting into serious troubles, including destroying their processor.

To enable MSR write access you need to add msr.allow_writes=on to your grub command line. Example, with other stuff that I have:

GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1 consoleblank=314 intel_pstate=active intel_pstate=no_hwp msr.allow_writes=on cpuidle.governor=teo"

You can also access the parameter after boot and after the msr module has been loaded at:

doug@s19:~/config/etc/default$ ls -l /sys/module/msr/parameters/allow_writes
ls: cannot access '/sys/module/msr/parameters/allow_writes': No such file or directory
doug@s19:~/config/etc/default$ sudo modprobe msr
doug@s19:~/config/etc/default$ ls -l /sys/module/msr/parameters/allow_writes
-rw------- 1 root root 4096 Jul 13 08:31 /sys/module/msr/parameters/allow_writes
doug@s19:~/config/etc/default$ sudo cat /sys/module/msr/parameters/allow_writes
on

where the options are [on/off/default]. And the default is defined by a kernel configuration parameter, I think.

Now, if you don't want to enable via the grub command line, you can also just do it later on via:

doug@s19:~$ ls -l /sys/module/msr/parameters/allow_writes
ls: cannot access '/sys/module/msr/parameters/allow_writes': No such file or directory
doug@s19:~$ sudo modprobe msr
doug@s19:~$ ls -l /sys/module/msr/parameters/allow_writes
-rw------- 1 root root 4096 Jul 13 08:42 /sys/module/msr/parameters/allow_writes
doug@s19:~$ sudo cat /sys/module/msr/parameters/allow_writes
default
doug@s19:~$ echo on | sudo tee /sys/module/msr/parameters/allow_writes
on
doug@s19:~$ sudo cat /sys/module/msr/parameters/allow_writes
on

EDIT: By the way, the command you were trying to write would disable turbo, not enable it. Example:

doug@s19:~$ sudo rdmsr 0x1a0
850089
doug@s19:~$ cat /sys/devices/system/cpu/intel_pstate/no_turbo
0
doug@s19:~$ sudo wrmsr 0x1a0 0x4000850089
doug@s19:~$ cat /sys/devices/system/cpu/intel_pstate/no_turbo
1
doug@s19:~$ sudo rdmsr 0x1a0
4000850089
id flag
I set msr.allow_writes=on in the kernel command line and it still doesn't work. I checked the contents of /sys/module/msr/parameters/allow_writes and it is on. Still getting the same error.
Doug Smythies avatar
gn flag
O.K., I did not know that secure boot overrides this stuff. Did you try `Alt + SysRq + X` to disable the higher level lock? Note: I do not know how current that information is, and did not test it myself.
id flag
Yeah... I tried using `Alt + SysRq + X` As far as I can tell from dmesg, it doesn't do anything.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.