Move translate_gpa() initialization for the nested context into init_kvm_nested_mmu()
PATCH 1/1 Move translate_gpa() initialization for the nested context into init_kvm_nested_mmu()
This is the right place to set the function pointer. In addition, change function name from translate_nested_gpa() to translate_gpa_nested() to match the naming convention of other functions (e.g., paging64_gva_to_gpa_nested()).
Signed-off-by Zhihui Zhang <[email protected]>
--- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/mmu.c | 2 +- arch/x86/kvm/x86.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
arch/x86/include/asm/kvm_host.h +1 -1
@@ -916,7 +916,7 @@ void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu);int kvm_mmu_load (struct kvm_vcpu *vcpu);void kvm_mmu_unload (struct kvm_vcpu *vcpu);void kvm_mmu_sync_roots (struct kvm_vcpu *vcpu); -gpa_t translate_nested_gpa (struct kvm_vcpu *vcpu,gpa_t gpa,u32 access); +gpa_t translate_gpa_nested (struct kvm_vcpu *vcpu,gpa_t gpa,u32 access);gpa_t kvm_mmu_gva_to_gpa_read (struct kvm_vcpu *vcpu,gva_t gva,struct x86_exception *exception); gpa_t kvm_mmu_gva_to_gpa_fetch(struct kvm_vcpu *vcpu, gva_t gva,
arch/x86/kvm/mmu.c +1 -1
@@ -3804,6 +3804,7 @@ static void init_kvm_nested_mmu(struct kvm_vcpu *vcpu) g_context->get_cr3 = get_cr3; g_context->get_pdptr = kvm_pdptr_read; g_context->inject_page_fault = kvm_inject_page_fault; + g_context->translate_gpa = translate_gpa_nested;/* * Note that arch.mmu.gva_to_gpa translates l2_gva to l1_gpa. The
@@ -4230,7 +4231,6 @@ int kvm_mmu_create(struct kvm_vcpu *vcpu) vcpu->arch.walk_mmu = &vcpu->arch.mmu; vcpu->arch.mmu.root_hpa =INVALID_PAGE ; vcpu->arch.mmu.translate_gpa = translate_gpa; - vcpu->arch.nested_mmu.translate_gpa = translate_nested_gpa;return alloc_mmu_pages (vcpu); }
arch/x86/kvm/x86.c +1 -1
@@ -3938,7 +3938,7 @@ void kvm_get_segment(struct kvm_vcpu *vcpu, kvm_x86_ops->get_segment (vcpu, var, seg); } -gpa_t translate_nested_gpa (struct kvm_vcpu *vcpu,gpa_t gpa,u32 access) +gpa_t translate_gpa_nested (struct kvm_vcpu *vcpu,gpa_t gpa,u32 access) {gpa_t t_gpa;struct x86_exception exception;
Signature · 1 line
1.8.1.2
Quoted 5 lines · Zhihui Zhang
This is the right place to set the function pointer. In addition, change function name from
translate_nested_gpa()totranslate_gpa_nested()to match the naming convention of other functions (e.g.,paging64_gva_to_gpa_nested()).Signed-off-by Zhihui Zhang <[email protected]>
Why is it the right place? The assignment was executed once per VM-creation, now its executed once per kvm_mmu_reset_context (which is a downside). Another downside is that
vcpu->arch.mmu.translate_gpa = translate_gpa; vcpu->arch.nested_mmu.translate_gpa = translate_nested_gpa;
You lose this proximity.