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.

Linux development is distributed - profoundly so

The standard introduction to git starts with an explanation of what it means to use a “distributed” version control system. It’s pointed out that every developer has a complete local copy of the repository and can work independently and offline, often contra…

via Blogs on Drew DeVault's blog September 2, 2020

Eshell versus M-x shell

I’ve used and defended Eshell for years. Sadly, Eshell has some long standing issues that I grew tired of in the long run. So I’ve decided to switch to M-x shell and see how much of my Eshell workflow I could port. Language and the underlying shell pr…

via Pierre Neidhardt's homepage June 26, 2020

Thermoelectric Stoves: Ditch the Solar Panels?

Wood stoves equipped with thermoelectric generators can produce electricity that is more sustainable, more reliable, and less costly than power from solar PV panels.

via LOW←TECH MAGAZINE May 26, 2020

Generated by openring