Patch NPT For Ryzen CPU Arch Linux
Published 2017-10-28 on Anjan's Homepage
Note: This patch has been merged with upstream. Simply update your archlinux machine and npt should just work.
The new npt patch allows you to enable npt on ryzen cpus and get native performance in a virtual machine. Please be advised that this patch is not mainline and may cause other problems. As always, make backups.
For this procedure we will be using the Arch Build System so that pacman will manage all of the files and so we can rollback a kernel by looking into /var/cache/pacman/pkg/
and using pacman -U
.
mkdir builds cd builds
Make sure you have subversion installed and then:
svn checkout --depth=empty svn://svn.archlinux.org/packages cd packages svn update linux cd linux/repos/core-x86_64/
Edit the PKGBUILD
file to include the following near prepare(){
# add upstream patch patch -p1 -i ../patch-${pkgver} # ADD THE FOLLOWING LINE TO THE PKGBUILD patch -p1 -i ../patch-ryzen
Next, we put the npt patch into the src folder.
cd src
vim patch-ryzen
and copy paste the following lines:
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index af256b786a70..af09baa3d736 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -3626,6 +3626,13 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr) u32 ecx = msr->index; u64 data = msr->data; switch (ecx) { + case MSR_IA32_CR_PAT: + if (!kvm_mtrr_valid(vcpu, MSR_IA32_CR_PAT, data)) + return 1; + vcpu->arch.pat = data; + svm->vmcb->save.g_pat = data; + mark_dirty(svm->vmcb, VMCB_NPT); + break; case MSR_IA32_TSC: kvm_write_tsc(vcpu, msr); break;
Finally, in order to build the package and install the new patched kernel:
cd ..
makepkg -si
Make sure `/etc/modprobe.d/kvmamd.conf` has npt enabled:
options kvm_amd npt=1
and reboot
References:
https://wiki.archlinux.org/index.php/Creating_packages
https://wiki.archlinux.org/index.php/Arch_Build_System
https://level1techs.com/article/patch-npt-ryzen-better-performance
Have a comment on one of my posts? Start a discussion in my public inbox by sending an email to ~anjan/public-inbox@lists.sr.ht [mailing list etiquette]
Articles from blogs I follow around the net
These articles/blogs do not represent my own opinions or views.Text processing on the Command Line - sharing my tools
Text processing on the command line - sharing my tools Introduction I'm quite fond of the command-line and spend a larger chunk of my life in a terminal emulator than I dare admit. I try to embrace the unix philosophy of using tools that "do one thing…
via Proycon's website July 7, 2024Linux phones are not automatically secure
A common point in the Linux community is that escaping the walled garden of ecosystems like Android or iOS is already a means to higher security. Having no contact with Google or Apple servers ever again, nor cloud providers ever snooping on your private …
via TuxPhones - Linux phones, tablets and portable devices January 25, 2023Generated by openring