zen_workaround.py PermissionError (Ryzen 3700U)
I'm having trouble getting the zen_workaround.py script working on my Ryzen 3700U-based laptop.
lscpu reports cpu model is "AMD Ryzen 7 3700U with Radeon Vega Mobile Gfx"
I'm using rr 5.4 as packaged by Debian (I've diffed the workaround script and it's the same as in the github repo, other than a link referencing the Zen page on the mozilla wiki rather than the github wiki).
$ sudo /usr/share/doc/rr/examples/zen_workaround.py
Traceback (most recent call last):
File "/usr/share/doc/rr/examples/zen_workaround.py", line 46, in <module>
os.write(msr, struct.pack('<q', val))
PermissionError: [Errno 1] Operation not permitted
So it's opening /dev/cpu/7/msr and seeking, but the actual write fails...
Anything obvious I'm missing?
What kernel is this?
oops, should have mentioned that:
$ uname -r
5.10.0-1-amd64
Same problem on kernel 5.13.12-200.fc34.x86_64, rr version 5.4.0
I hit the same problem.
> dmesg | head -1
[ 0.000000] Linux version 5.10.0-8-amd64 ([email protected]) (gcc-10 (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2) #1 SMP Debian 5.10.46-4 (2021-08-03)
I also have the same problem; Ryzen 3700X
dmesg | head -1
[ 0.000000] Linux version 5.11.0-38-generic (buildd@lgw01-amd64-041) (gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #42~20.04.1-Ubuntu SMP Tue Sep 28 20:41:07 UTC 2021 (Ubuntu 5.11.0-38.42~20.04.1-generic 5.11.22)
Also in the link Will rr work on my system?, this does not work on Ryzen 3700X, because that stat does not exist:
perf stat -e br_inst_retired.conditional true
But when I look this up, this basically counts, if I'm not mistaken, retired conditional branch instructions. It seems as though, the real command for this on AMD (or Zen architectures, or perhaps this is specific to different Linuxes? I am uninformed on the subject) is:
perf stat -e ex_ret_cond true
Right? Because that exists as a command on this machine with a Ryzen 3700X and gives a non-zero value. Also says in the description that it is "Retired condtional branch instructions"
I've solved this issue for my Zen-architecture desktop (Ryzen 3700X);
The problem this boils down to is that UEFI Secure Boot is turned on. From what I can gather, this makes it so the Linux Kernel entirely prevents writing to MSR. If you disable secure boot, the zen_workaround.py script will work.
Th current script explicit checks the permission error and tries to produce nice user-readable errors. Can anyone that had the issue recheck if that works? I think this issue can be closed.
I'll make a new issue on the conditional documentation as @theIDinside hinted - they are different.
@GitMensch yes; I forgot to tag this specific issue when I submitted the changes to the script that checks for UEFI secure boot. I've only had the possibility to test it on my machine and it works (famous last words). But from what I can gather, a lot of linux'es use the same setup, possibly all of them (UEFI variables being in the same place, which is where the script reads the settings from) - and as far as UEFI being the culprit for it not working, discussions around it can be found for instance here