From: Keir Fraser Date: Fri, 28 Sep 2007 14:03:50 +0000 (+0100) Subject: hvm: Enable HAP by default (NPT on AMD SVM systems). X-Git-Tag: 3.2.0-rc1~305^2~6 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=65c67b479214731a9064474fd14133f3043bf84d;p=xen.git hvm: Enable HAP by default (NPT on AMD SVM systems). Signed-off-by: Keir Fraser --- diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index d77262eb39..447b158a27 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -49,6 +49,10 @@ #include #include +/* Xen command-line option to disable hardware-assisted paging */ +static int opt_hap_disabled; +invbool_param("hap", opt_hap_disabled); + int hvm_enabled __read_mostly; unsigned int opt_hvm_debug_level __read_mostly; @@ -74,6 +78,14 @@ void hvm_enable(struct hvm_function_table *fns) hvm_funcs = *fns; hvm_enabled = 1; + + if ( hvm_funcs.hap_supported ) + { + if ( opt_hap_disabled ) + hvm_funcs.hap_supported = 0; + printk("HVM: Hardware Assisted Paging %sabled\n", + hvm_funcs.hap_supported ? "en" : "dis"); + } } void hvm_set_guest_time(struct vcpu *v, u64 gtime) diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index d0cc5f21cd..d6db5bf028 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -69,9 +69,6 @@ static void *hsa[NR_CPUS] __read_mostly; /* vmcb used for extended host state */ static void *root_vmcb[NR_CPUS] __read_mostly; -/* hardware assisted paging bits */ -extern int opt_hap_enabled; - static void inline __update_guest_eip( struct cpu_user_regs *regs, int inst_len) { @@ -936,18 +933,14 @@ static struct hvm_function_table svm_function_table = { .event_pending = svm_event_pending }; -static void svm_npt_detect(void) +static int svm_npt_detect(void) { u32 eax, ebx, ecx, edx; /* Check CPUID for nested paging support. */ cpuid(0x8000000A, &eax, &ebx, &ecx, &edx); - if ( !(edx & 1) && opt_hap_enabled ) - { - printk("SVM: Nested paging is not supported by this CPU.\n"); - opt_hap_enabled = 0; - } + return (edx & 1); } int start_svm(struct cpuinfo_x86 *c) @@ -978,8 +971,6 @@ int start_svm(struct cpuinfo_x86 *c) write_efer(read_efer() | EFER_SVME); - svm_npt_detect(); - /* Initialize the HSA for this core. */ phys_hsa = (u64) virt_to_maddr(hsa[cpu]); phys_hsa_lo = (u32) phys_hsa; @@ -994,11 +985,10 @@ int start_svm(struct cpuinfo_x86 *c) setup_vmcb_dump(); + svm_function_table.hap_supported = svm_npt_detect(); + hvm_enable(&svm_function_table); - if ( opt_hap_enabled ) - printk("SVM: Nested paging enabled.\n"); - return 1; } diff --git a/xen/arch/x86/mm/paging.c b/xen/arch/x86/mm/paging.c index 25f323151d..a8c56b175d 100644 --- a/xen/arch/x86/mm/paging.c +++ b/xen/arch/x86/mm/paging.c @@ -28,9 +28,7 @@ #include #include -/* Xen command-line option to enable hardware-assisted paging */ -int opt_hap_enabled; -boolean_param("hap", opt_hap_enabled); +#define hap_enabled(d) (hvm_funcs.hap_supported && is_hvm_domain(d)) /* Printouts */ #define PAGING_PRINTK(_f, _a...) \ @@ -363,14 +361,14 @@ void paging_domain_init(struct domain *d) shadow_domain_init(d); /* ... but we will use hardware assistance if it's available. */ - if ( opt_hap_enabled && is_hvm_domain(d) ) + if ( hap_enabled(d) ) hap_domain_init(d); } /* vcpu paging struct initialization goes here */ void paging_vcpu_init(struct vcpu *v) { - if ( opt_hap_enabled && is_hvm_vcpu(v) ) + if ( hap_enabled(v->domain) ) hap_vcpu_init(v); else shadow_vcpu_init(v); @@ -434,7 +432,7 @@ int paging_domctl(struct domain *d, xen_domctl_shadow_op_t *sc, } /* Here, dispatch domctl to the appropriate paging code */ - if ( opt_hap_enabled && is_hvm_domain(d) ) + if ( hap_enabled(d) ) return hap_domctl(d, sc, u_domctl); else return shadow_domctl(d, sc, u_domctl); @@ -443,7 +441,7 @@ int paging_domctl(struct domain *d, xen_domctl_shadow_op_t *sc, /* Call when destroying a domain */ void paging_teardown(struct domain *d) { - if ( opt_hap_enabled && is_hvm_domain(d) ) + if ( hap_enabled(d) ) hap_teardown(d); else shadow_teardown(d); @@ -455,7 +453,7 @@ void paging_teardown(struct domain *d) /* Call once all of the references to the domain have gone away */ void paging_final_teardown(struct domain *d) { - if ( opt_hap_enabled && is_hvm_domain(d) ) + if ( hap_enabled(d) ) hap_final_teardown(d); else shadow_final_teardown(d); @@ -465,7 +463,7 @@ void paging_final_teardown(struct domain *d) * creation. */ int paging_enable(struct domain *d, u32 mode) { - if ( opt_hap_enabled && is_hvm_domain(d) ) + if ( hap_enabled(d) ) return hap_enable(d, mode | PG_HAP_enable); else return shadow_enable(d, mode | PG_SH_enable); diff --git a/xen/include/asm-x86/hvm/hvm.h b/xen/include/asm-x86/hvm/hvm.h index f2cc1f99a7..e1af3c20be 100644 --- a/xen/include/asm-x86/hvm/hvm.h +++ b/xen/include/asm-x86/hvm/hvm.h @@ -72,6 +72,9 @@ enum hvm_intack { struct hvm_function_table { char *name; + /* Support Hardware-Assisted Paging? */ + int hap_supported; + /* * Initialise/destroy HVM domain/vcpu resources */