Skip to content

Commit 5e2f30b

Browse files
davidhildenbrandbonzini
authored andcommitted
KVM: nVMX: get rid of nested_get_page()
nested_get_page() just sounds confusing. All we want is a page from G1. This is even unrelated to nested. Let's introduce kvm_vcpu_gpa_to_page() so we don't get too lengthy lines. Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: David Hildenbrand <david@redhat.com> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com> [Squash pasto fix from Wanpeng Li. - Paolo] Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 90a2db6 commit 5e2f30b

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

arch/x86/kvm/vmx.c

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -891,14 +891,6 @@ static inline struct vmcs12 *get_vmcs12(struct kvm_vcpu *vcpu)
891891
return to_vmx(vcpu)->nested.cached_vmcs12;
892892
}
893893

894-
static struct page *nested_get_page(struct kvm_vcpu *vcpu, gpa_t addr)
895-
{
896-
struct page *page = kvm_vcpu_gfn_to_page(vcpu, addr >> PAGE_SHIFT);
897-
if (is_error_page(page))
898-
return NULL;
899-
900-
return page;
901-
}
902894

903895
static void nested_release_page(struct page *page)
904896
{
@@ -7156,8 +7148,8 @@ static int handle_vmon(struct kvm_vcpu *vcpu)
71567148
return kvm_skip_emulated_instruction(vcpu);
71577149
}
71587150

7159-
page = nested_get_page(vcpu, vmptr);
7160-
if (page == NULL) {
7151+
page = kvm_vcpu_gpa_to_page(vcpu, vmptr);
7152+
if (is_error_page(page)) {
71617153
nested_vmx_failInvalid(vcpu);
71627154
return kvm_skip_emulated_instruction(vcpu);
71637155
}
@@ -7625,8 +7617,8 @@ static int handle_vmptrld(struct kvm_vcpu *vcpu)
76257617
if (vmx->nested.current_vmptr != vmptr) {
76267618
struct vmcs12 *new_vmcs12;
76277619
struct page *page;
7628-
page = nested_get_page(vcpu, vmptr);
7629-
if (page == NULL) {
7620+
page = kvm_vcpu_gpa_to_page(vcpu, vmptr);
7621+
if (is_error_page(page)) {
76307622
nested_vmx_failInvalid(vcpu);
76317623
return kvm_skip_emulated_instruction(vcpu);
76327624
}
@@ -9632,6 +9624,7 @@ static void nested_get_vmcs12_pages(struct kvm_vcpu *vcpu,
96329624
struct vmcs12 *vmcs12)
96339625
{
96349626
struct vcpu_vmx *vmx = to_vmx(vcpu);
9627+
struct page *page;
96359628
u64 hpa;
96369629

96379630
if (nested_cpu_has2(vmcs12, SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES)) {
@@ -9641,17 +9634,19 @@ static void nested_get_vmcs12_pages(struct kvm_vcpu *vcpu,
96419634
* physical address remains valid. We keep a reference
96429635
* to it so we can release it later.
96439636
*/
9644-
if (vmx->nested.apic_access_page) /* shouldn't happen */
9637+
if (vmx->nested.apic_access_page) { /* shouldn't happen */
96459638
nested_release_page(vmx->nested.apic_access_page);
9646-
vmx->nested.apic_access_page =
9647-
nested_get_page(vcpu, vmcs12->apic_access_addr);
9639+
vmx->nested.apic_access_page = NULL;
9640+
}
9641+
page = kvm_vcpu_gpa_to_page(vcpu, vmcs12->apic_access_addr);
96489642
/*
96499643
* If translation failed, no matter: This feature asks
96509644
* to exit when accessing the given address, and if it
96519645
* can never be accessed, this feature won't do
96529646
* anything anyway.
96539647
*/
9654-
if (vmx->nested.apic_access_page) {
9648+
if (!is_error_page(page)) {
9649+
vmx->nested.apic_access_page = page;
96559650
hpa = page_to_phys(vmx->nested.apic_access_page);
96569651
vmcs_write64(APIC_ACCESS_ADDR, hpa);
96579652
} else {
@@ -9666,10 +9661,11 @@ static void nested_get_vmcs12_pages(struct kvm_vcpu *vcpu,
96669661
}
96679662

96689663
if (nested_cpu_has(vmcs12, CPU_BASED_TPR_SHADOW)) {
9669-
if (vmx->nested.virtual_apic_page) /* shouldn't happen */
9664+
if (vmx->nested.virtual_apic_page) { /* shouldn't happen */
96709665
nested_release_page(vmx->nested.virtual_apic_page);
9671-
vmx->nested.virtual_apic_page =
9672-
nested_get_page(vcpu, vmcs12->virtual_apic_page_addr);
9666+
vmx->nested.virtual_apic_page = NULL;
9667+
}
9668+
page = kvm_vcpu_gpa_to_page(vcpu, vmcs12->virtual_apic_page_addr);
96739669

96749670
/*
96759671
* If translation failed, VM entry will fail because
@@ -9684,7 +9680,8 @@ static void nested_get_vmcs12_pages(struct kvm_vcpu *vcpu,
96849680
* control. But such a configuration is useless, so
96859681
* let's keep the code simple.
96869682
*/
9687-
if (vmx->nested.virtual_apic_page) {
9683+
if (!is_error_page(page)) {
9684+
vmx->nested.virtual_apic_page = page;
96889685
hpa = page_to_phys(vmx->nested.virtual_apic_page);
96899686
vmcs_write64(VIRTUAL_APIC_PAGE_ADDR, hpa);
96909687
}
@@ -9694,15 +9691,13 @@ static void nested_get_vmcs12_pages(struct kvm_vcpu *vcpu,
96949691
if (vmx->nested.pi_desc_page) { /* shouldn't happen */
96959692
kunmap(vmx->nested.pi_desc_page);
96969693
nested_release_page(vmx->nested.pi_desc_page);
9694+
vmx->nested.pi_desc_page = NULL;
96979695
}
9698-
vmx->nested.pi_desc_page =
9699-
nested_get_page(vcpu, vmcs12->posted_intr_desc_addr);
9700-
vmx->nested.pi_desc =
9701-
(struct pi_desc *)kmap(vmx->nested.pi_desc_page);
9702-
if (!vmx->nested.pi_desc) {
9703-
nested_release_page_clean(vmx->nested.pi_desc_page);
9696+
page = kvm_vcpu_gpa_to_page(vcpu, vmcs12->posted_intr_desc_addr);
9697+
if (is_error_page(page))
97049698
return;
9705-
}
9699+
vmx->nested.pi_desc_page = page;
9700+
vmx->nested.pi_desc = kmap(vmx->nested.pi_desc_page);
97069701
vmx->nested.pi_desc =
97079702
(struct pi_desc *)((void *)vmx->nested.pi_desc +
97089703
(unsigned long)(vmcs12->posted_intr_desc_addr &
@@ -9784,8 +9779,8 @@ static inline bool nested_vmx_merge_msr_bitmap(struct kvm_vcpu *vcpu,
97849779
if (!nested_cpu_has_virt_x2apic_mode(vmcs12))
97859780
return false;
97869781

9787-
page = nested_get_page(vcpu, vmcs12->msr_bitmap);
9788-
if (!page)
9782+
page = kvm_vcpu_gpa_to_page(vcpu, vmcs12->msr_bitmap);
9783+
if (is_error_page(page))
97899784
return false;
97909785
msr_bitmap_l1 = (unsigned long *)kmap(page);
97919786

@@ -11392,8 +11387,8 @@ static int vmx_write_pml_buffer(struct kvm_vcpu *vcpu)
1139211387

1139311388
gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS) & ~0xFFFull;
1139411389

11395-
page = nested_get_page(vcpu, vmcs12->pml_address);
11396-
if (!page)
11390+
page = kvm_vcpu_gpa_to_page(vcpu, vmcs12->pml_address);
11391+
if (is_error_page(page))
1139711392
return 0;
1139811393

1139911394
pml_address = kmap(page);

include/linux/kvm_host.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,12 @@ static inline hpa_t pfn_to_hpa(kvm_pfn_t pfn)
985985
return (hpa_t)pfn << PAGE_SHIFT;
986986
}
987987

988+
static inline struct page *kvm_vcpu_gpa_to_page(struct kvm_vcpu *vcpu,
989+
gpa_t gpa)
990+
{
991+
return kvm_vcpu_gfn_to_page(vcpu, gpa_to_gfn(gpa));
992+
}
993+
988994
static inline bool kvm_is_error_gpa(struct kvm *kvm, gpa_t gpa)
989995
{
990996
unsigned long hva = gfn_to_hva(kvm, gpa_to_gfn(gpa));

0 commit comments

Comments
 (0)