From 1fd44fdc30428d3e72cfc109337ae6eac86a5830 Mon Sep 17 00:00:00 2001 From: erpalma Date: Tue, 22 Dec 2020 09:45:49 +0100 Subject: [PATCH] Add allow_writes=on to the MSR module parameters. Workaround for #206, #215 and #228 --- lenovo_fix.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lenovo_fix.py b/lenovo_fix.py index add118a..a3f9ca7 100755 --- a/lenovo_fix.py +++ b/lenovo_fix.py @@ -196,6 +196,21 @@ def get_value_for_bits(val, from_bit=0, to_bit=63): return (val & mask) >> from_bit +def set_msr_allow_writes(): + log('[I] Trying to unlock MSR allow_writes.') + if not os.path.exists('/sys/module/msr'): + try: + subprocess.check_call(('modprobe', 'msr')) + except subprocess.CalledProcessError: + return + if os.path.exists('/sys/module/msr/parameters/allow_writes'): + try: + with open('/sys/module/msr/parameters/allow_writes', 'w') as f: + f.write('on') + except: + warning('Unable to set MSR allow_writes to on. You might experience warnings in kernel logs.') + + def is_on_battery(config): try: for path in glob.glob(config.get('GENERAL', 'Sysfs_Power_Path', fallback=DEFAULT_SYSFS_POWER_PATH)): @@ -813,6 +828,8 @@ def main(): check_kernel() check_cpu() + set_msr_allow_writes() + log('[I] Loading config file.') config = load_config() power['source'] = 'BATTERY' if is_on_battery(config) else 'AC'