Patch NPT on Ryzen for Better Performance | Level One Techs

Thanks :slight_smile:

No, this is the first time I have been involved to this level with something of this nature. I’d appreciate any advice available on this.

That would be great, people have already been generous with donations for the NPT fix already, it really took me by surprise how much interest there is in this. The fist time I looked into PCI passthrough was about 10 years ago on Xen and very broken, I gave up on it quickly when I found that my new motherboard had a broken IOMMU implementation.

I wont say that I am an expert in all this, most of it is self taught. I didn’t even know how KVM worked two weeks ago and spent several days working through the AMD specifications testing each part of the system searching for the problem. I still have a lot to learn about KVM’s inner workings and how things play along with IOMMU.

There are several bugs I would like to fix in Qemu also that are not CPU/Hardware related, such as a bug in the i8042 PS2 controller implementation I am yet to dig into in detail (seems like a race condition, the virtual device has no interlocking and can and does get entered by multiple threads simultaneously).


Are you also the one that did the thing with “laptop gsync panels?” if so I hexedited the driver and was able to confirm that. They shut that down so fast I’m still reeling over it.

PM issue fixed.

Thanks :). And no, that one wasn’t me. PM sent.

I’m not sure how this works, Wendell might know better.

I had the same experience when I realized my 3770k didn’t support IOMMU. Very sad.

Yeah, everyone in my department is running Linux with a windows VM and a 480 or a 580 passed through for proprietary windows stuff and games. When the NPT patch hit patchwork, one of my underlings came running into my office with a huge smile on. You’re a hero in our office.


Wendel! You are my Hero again!

I compiled a patched Linux kernel just yet! Thanks alot for the guide! I never did it before (because there was no reason :wink: )

Tested yet 2 Benchmarks: Unigine Vally: DX11 (high preset, AA off) and Resident Evil 6 Bench Tool: DX9c (all High, AA off)
both on a passthroughed Sapphire RX 560 oc to 1434 MHz CPU and 2GHz VRAM.

Before the Patch:
Unigine ~52 FPS; 2170 Points (min FPS 18,5 / max FPS 103,8)
RE6 BT ~3700 Points

After the Patch:
Unigine ~ 58,4; 2443 Points (min FPS 28,0 / max FPS 107,2)
RE6 BT ~9600 Points

DirectX9c Games got a huuuuugh boost! DX11 Games where always playable but slightly choppy.

Now its veeeery smooth on my System.
Btw. I’m rocking the following System:

Ryzen 5 1600x OC to 3.925Ghz
RAM: Corsair Vengeance 3200 @ 3200MHz of course
Board: Asus Crosshair 6 Hero BIOS 17.01
Host Disk: Crucial M500 m2 SSD
Guest Disk: QCow2 Image
GPU: Sapphire RX 560 Pulse 4GB + Arctic Accelero Xtreme IV 280x Custom Cooler

Im quite happy with the results :wink:

Mit freundlichen Grüßen

Update 2017-11-02:
I have to add: in my case a crucial package was not installed on my Ubuntu to do the Kernel compile. Please take care the package libssl-dev is installed via apt or synpatic package-manager.

1 Like

Hi all,

I started yesterday a larger benchmark session with a wide varity of DX11, DX9c, DX12 and on Vulkan API Games. I want to compair NPT=1 vs NPT=0 vs Native Windows 10 performance and post my resultes (probably in a new Thread…). I hope some one find it usefull or “entertaining” :wink:
Here the list of Games/Benchmarks that i wanne to use (i.g. started to use):


  • Unigine Vally (DX11)
  • Unigine Heaven (DX11)
  • Unigine Superposition (DX11)
  • Resident Evil 6 Bechmark Tool (DX9c)
  • Resident Evil 5 Benchmark 1 (DX9c)
  • Resident Evil 5 Benchmark 2 (DX9c)
  • Tomb Raider
  • Rise of Tomb Raider (DX12)
  • Steam VR Performance Test
  • Ashes of the Singularity: Escalation (DX12 and Vulkan)

Now I will not use my RX 560 card for the Passthrough, instead I pass my XFX R9 280x thru my VM. On earlier tests I noticed around 30% performance loss compaired to native use. My RX 560 “only” lost around 10% Performance with the buggy Nested Page Tables (what was quite intresting).

I think I can post the NPT=1 numbers this evening (German Time)…

Viele Grüße
Marf :slight_smile:

Edit 2017-11-03:
As promised, I created just yet a new Thread where I will post my benchmark numbers. Please understand… WIP … :wink:
You will find the thread here: GPU Passthrough Performance Numbers: Ryzen NPT Patch vs Buggy NPT vs Native Windows


An update for anyone watching: I made 2 concurrent mistakes while testing the patch, causing me much confusion for an couple of hours. I both failed to apply the patch correctly (first time using a custom kernel) and failed to properly re-enable NPT. This explains why I was experiencing less-than-ideal performance. After remedying these 2 errors performance improved hugely, and I am (more or less :wink: ) officially done tinkering. This passthrough thing is now final the solution to all my woes! Benchmarks in this thread: GPU Passthrough Performance Numbers: Ryzen NPT Patch vs Buggy NPT vs Native Windows


Having trouble applying the patch on fedora 27 (trying kernel 4.13.11-301), and I’m out of ideas for on how to fix it. I’m able to compile the kernel on its own, or even just with a working Aur-acs patch. However adding the NTP patch on top of that causes rpmbuild to fail before I even start compiling.

Here are the commands I use to reproduce this

fedpkg clone -a kernel
git checkout -b my_kernel origin/f27
sudo dnf builddep kernel.spec
./scripts/ Aur-acs.patch
./scripts/ ryzen.patch
make release
sudo fedpkg local

pulled the patch from patchwork kernel, and I applied the aur-acs fixes (which compiled just fine on its own). I don’t think its required, but I installed my matching kernel-devel package just in case. (also util-linux)
I’m going to assume I’m missing something obvious, but if you need any more information I can provide it. Sorry if this is an inappropriate thread for this, at this point.

I’m sorry I can’t be of more help - I found this stage challenging too. In the end I downloaded the kernel from, applied the patch and built it using variations on Wendell’s commands with help from this page:

Perhaps it’s a missing dependency issue? I fear any advice of mine beyond here is likely to cause more harm than good. I recommend reading that Fedora wiki thoroughly though

1 Like

OK, I think I got it working. I had to use another method to apply the patch (We can pretend I used the “cat | patch” method as described in the fedora wiki and not just gedit like the filthy casual I am). I’ll run some tests tomorrow to see if I really got it working. Maybe I’ll throw together a few benchmarks against the kernel without the ntp patch if I have the time. Thanks for your help.

1 Like

@dailan post the build log (use pastebin or something similar), it’s very unlikely that anyone here is going to replicate your steps to figure out the error you were getting.

Unless I’m missing something, the build-log doesn’t seem to have any useful information. Here it is. It does, however, point to this code. The warning about unexpanded macros seems to be harmless.
AND just in case, my current ryzen.patch file. If anyone wants any more information, I would be happy to provide it.

Alright here are some quick and dirty benchmarks, the difference that this patch made was night and day.

In total war warhammer II’s campaign benchmark at 1080p
Before: Min 10, Max 25, Average 16.9 FPS
After: Min 43, Max 86, Average 61.6 FPS

In total war warhammer II’s battle benchmark at 1080p
Before: Min 6, Max 17, Average 10.8 FPS
After: Min 43, Max 61, Average 54.3 FPS

In Civ 6’s graphics benchmark at 34440x1440
Before: 99th 65.95, Average 47.66 frame times in MS
After: 99th 24.16, Average 18.68 frame times in MS

Civ 6’s AI benchmark at 3440x1440
Before: Average 33.2 second turns
After: Average 26.5 second turns

Skyrim (just eyeballing it) outside
Before: Min 1, Max 35, Average 20 FPS
After: Min 30, Max 50, Average 40 FPS

Skyrim (just eyeballing it) inside
Before: Min 30, Max 55, Average 40 FPS
After: Min 60, Max 60, Average 60 FPS

I am using my old card GTS 450 for passing through to my Ubuntu VM, but this card suffers from a reset bug. I have tried detaching the card via command line and then shutdown VM, tried rom dump and feed it in the config - nothing helps. Every time I shut down the VM or reboot, I get black screen and I need to reboot host PC.
Is there any way to power cycle PCIe from host command line in order to initialize it more than once?
BTW, I am on Ryzen 1600 and Asus X370-pro with the latest BIOS (1001).

This is a hardware bug that can’t be fixed. On some GPU that have dual-bios (my Fury Nitro for example) can be reset by switching to the other BIOS.

OK and what about that patch that Wendell is talking about in the stream starting @11:35? Kernel 4.15 patch with power cycle to the PCIe?

1 Like

Basically this (as I understand at least):

1 Like

I’m not super up to date on it, because I’m not using Vega or any other GPUs that suffer from this bug (at least, not for passthrough)

I’m going to defer to @mihawk90 and Wendell since they’re clearly following it more closely.

actually not really, just reading a bit :stuck_out_tongue:

Still following it more closely than I am. I just stay away from GPU with the issue.