]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commit
kvm: svm: Add support for additional SVM NPF error codes
authorTom Lendacky <thomas.lendacky@amd.com>
Wed, 23 Nov 2016 17:01:38 +0000 (12:01 -0500)
committerRadim Krčmář <rkrcmar@redhat.com>
Thu, 24 Nov 2016 17:32:26 +0000 (18:32 +0100)
commit147277540bbc54119172481c8ef6d930cc9fbfc2
tree6ebc574edba395060753311647ea571d1fe4c361
parentae0f5499511e5b1723792c848e44d661d0d4e22f
kvm: svm: Add support for additional SVM NPF error codes

AMD hardware adds two additional bits to aid in nested page fault handling.

Bit 32 - NPF occurred while translating the guest's final physical address
Bit 33 - NPF occurred while translating the guest page tables

The guest page tables fault indicator can be used as an aid for nested
virtualization. Using V0 for the host, V1 for the first level guest and
V2 for the second level guest, when both V1 and V2 are using nested paging
there are currently a number of unnecessary instruction emulations. When
V2 is launched shadow paging is used in V1 for the nested tables of V2. As
a result, KVM marks these pages as RO in the host nested page tables. When
V2 exits and we resume V1, these pages are still marked RO.

Every nested walk for a guest page table is treated as a user-level write
access and this causes a lot of NPFs because the V1 page tables are marked
RO in the V0 nested tables. While executing V1, when these NPFs occur KVM
sees a write to a read-only page, emulates the V1 instruction and unprotects
the page (marking it RW). This patch looks for cases where we get a NPF due
to a guest page table walk where the page was marked RO. It immediately
unprotects the page and resumes the guest, leading to far fewer instruction
emulations when nested virtualization is used.

Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Reviewed-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/mmu.c
arch/x86/kvm/svm.c