Skip to content

Commit

Permalink
KVM: Add kvm_x86_ops get_tdp_level()
Browse files Browse the repository at this point in the history
The function get_tdp_level() provided the number of tdp level for EPT and
NPT rather than the NPT specific macro.

Signed-off-by: Sheng Yang <sheng.yang@intel.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
  • Loading branch information
Sheng Yang authored and Avi Kivity committed May 4, 2008
1 parent 8c6d6ad commit 67253af
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions arch/x86/kvm/mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,7 @@ static int tdp_page_fault(struct kvm_vcpu *vcpu, gva_t gpa,
spin_lock(&vcpu->kvm->mmu_lock);
kvm_mmu_free_some_pages(vcpu);
r = __direct_map(vcpu, gpa, error_code & PFERR_WRITE_MASK,
largepage, gfn, pfn, TDP_ROOT_LEVEL);
largepage, gfn, pfn, kvm_x86_ops->get_tdp_level());
spin_unlock(&vcpu->kvm->mmu_lock);

return r;
Expand Down Expand Up @@ -1450,7 +1450,7 @@ static int init_kvm_tdp_mmu(struct kvm_vcpu *vcpu)
context->page_fault = tdp_page_fault;
context->free = nonpaging_free;
context->prefetch_page = nonpaging_prefetch_page;
context->shadow_root_level = TDP_ROOT_LEVEL;
context->shadow_root_level = kvm_x86_ops->get_tdp_level();
context->root_hpa = INVALID_PAGE;

if (!is_paging(vcpu)) {
Expand Down
6 changes: 0 additions & 6 deletions arch/x86/kvm/mmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@

#include <linux/kvm_host.h>

#ifdef CONFIG_X86_64
#define TDP_ROOT_LEVEL PT64_ROOT_LEVEL
#else
#define TDP_ROOT_LEVEL PT32E_ROOT_LEVEL
#endif

#define PT64_PT_BITS 9
#define PT64_ENT_PER_PAGE (1 << PT64_PT_BITS)
#define PT32_PT_BITS 10
Expand Down
10 changes: 10 additions & 0 deletions arch/x86/kvm/svm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1863,6 +1863,15 @@ static bool svm_cpu_has_accelerated_tpr(void)
return false;
}

static int get_npt_level(void)
{
#ifdef CONFIG_X86_64
return PT64_ROOT_LEVEL;
#else
return PT32E_ROOT_LEVEL;
#endif
}

static struct kvm_x86_ops svm_x86_ops = {
.cpu_has_kvm_support = has_svm,
.disabled_by_bios = is_disabled,
Expand Down Expand Up @@ -1920,6 +1929,7 @@ static struct kvm_x86_ops svm_x86_ops = {
.inject_pending_vectors = do_interrupt_requests,

.set_tss_addr = svm_set_tss_addr,
.get_tdp_level = get_npt_level,
};

static int __init svm_init(void)
Expand Down
6 changes: 6 additions & 0 deletions arch/x86/kvm/vmx.c
Original file line number Diff line number Diff line change
Expand Up @@ -2788,6 +2788,11 @@ static void __init vmx_check_processor_compat(void *rtn)
}
}

static int get_ept_level(void)
{
return VMX_EPT_DEFAULT_GAW + 1;
}

static struct kvm_x86_ops vmx_x86_ops = {
.cpu_has_kvm_support = cpu_has_kvm_support,
.disabled_by_bios = vmx_disabled_by_bios,
Expand Down Expand Up @@ -2844,6 +2849,7 @@ static struct kvm_x86_ops vmx_x86_ops = {
.inject_pending_vectors = do_interrupt_requests,

.set_tss_addr = vmx_set_tss_addr,
.get_tdp_level = get_ept_level,
};

static int __init vmx_init(void)
Expand Down
1 change: 1 addition & 0 deletions arch/x86/kvm/vmx.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,5 +351,6 @@ enum vmcs_field {
#define VMX_EPT_EXTENT_INDIVIDUAL_BIT (1ull << 24)
#define VMX_EPT_EXTENT_CONTEXT_BIT (1ull << 25)
#define VMX_EPT_EXTENT_GLOBAL_BIT (1ull << 26)
#define VMX_EPT_DEFAULT_GAW 3

#endif
1 change: 1 addition & 0 deletions include/asm-x86/kvm_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ struct kvm_x86_ops {
struct kvm_run *run);

int (*set_tss_addr)(struct kvm *kvm, unsigned int addr);
int (*get_tdp_level)(void);
};

extern struct kvm_x86_ops *kvm_x86_ops;
Expand Down

0 comments on commit 67253af

Please sign in to comment.