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://
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}

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);

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


Have a comment on one of my posts? Start a discussion in my public inbox by sending an email to ~anjan/ [mailing list etiquette]

Articles from blogs I follow around the net

These articles/blogs do not represent my own opinions or views.

Todo.txt-more: Efficiently managing your todo list and your time

Todo.txt More: Efficiently managing your todo list and your time Introduction I tend to get fairly enthusiastic when it comes to lists, even more so when there's a chance to optimise my productivity. The end of the year is a time for looking backward an…

via Proycon's website December 31, 2022

The PineTab2 is a new, faster Linux tablet - and it's not alone

In their December update, Pine64 announced the PineTab2, which is the successor to their PineTab from 2018. As a major change, the PineTab2 upgrades the slow A53-based A64 SoC with an A55-based Rockchip RK3566, the same chip that was used for the Quartz64…

via TuxPhones - Linux phones, tablets and portable devices December 19, 2022

I shall toil at a reduced volume

Over the last nine years I have written 300,000 words for this blog on the topics which are important to me. I am not certain that I have much left to say. I can keep revisiting these topics for years, each time adding a couple more years of wisdom and impro…

via Drew DeVault's blog December 1, 2022

Generated by openring