ia64/xen-unstable

changeset 16010:b4c8cd753b88

hvm: Enable HAP by default (NPT on AMD SVM systems).
Signed-off-by: Keir Fraser <keir@xensource.com>
author Keir Fraser <keir@xensource.com>
date Fri Sep 28 15:03:50 2007 +0100 (2007-09-28)
parents 8817a53c030f
children 96f46954c7f1
files xen/arch/x86/hvm/hvm.c xen/arch/x86/hvm/svm/svm.c xen/arch/x86/mm/paging.c xen/include/asm-x86/hvm/hvm.h
line diff
     1.1 --- a/xen/arch/x86/hvm/hvm.c	Thu Sep 27 18:08:11 2007 +0100
     1.2 +++ b/xen/arch/x86/hvm/hvm.c	Fri Sep 28 15:03:50 2007 +0100
     1.3 @@ -49,6 +49,10 @@
     1.4  #include <public/version.h>
     1.5  #include <public/memory.h>
     1.6  
     1.7 +/* Xen command-line option to disable hardware-assisted paging */
     1.8 +static int opt_hap_disabled;
     1.9 +invbool_param("hap", opt_hap_disabled);
    1.10 +
    1.11  int hvm_enabled __read_mostly;
    1.12  
    1.13  unsigned int opt_hvm_debug_level __read_mostly;
    1.14 @@ -74,6 +78,14 @@ void hvm_enable(struct hvm_function_tabl
    1.15  
    1.16      hvm_funcs   = *fns;
    1.17      hvm_enabled = 1;
    1.18 +
    1.19 +    if ( hvm_funcs.hap_supported )
    1.20 +    {
    1.21 +        if ( opt_hap_disabled )
    1.22 +            hvm_funcs.hap_supported = 0;
    1.23 +        printk("HVM: Hardware Assisted Paging %sabled\n",
    1.24 +               hvm_funcs.hap_supported ? "en" : "dis");
    1.25 +    }
    1.26  }
    1.27  
    1.28  void hvm_set_guest_time(struct vcpu *v, u64 gtime)
     2.1 --- a/xen/arch/x86/hvm/svm/svm.c	Thu Sep 27 18:08:11 2007 +0100
     2.2 +++ b/xen/arch/x86/hvm/svm/svm.c	Fri Sep 28 15:03:50 2007 +0100
     2.3 @@ -69,9 +69,6 @@ static void *hsa[NR_CPUS] __read_mostly;
     2.4  /* vmcb used for extended host state */
     2.5  static void *root_vmcb[NR_CPUS] __read_mostly;
     2.6  
     2.7 -/* hardware assisted paging bits */
     2.8 -extern int opt_hap_enabled;
     2.9 -
    2.10  static void inline __update_guest_eip(
    2.11      struct cpu_user_regs *regs, int inst_len) 
    2.12  {
    2.13 @@ -936,18 +933,14 @@ static struct hvm_function_table svm_fun
    2.14      .event_pending        = svm_event_pending
    2.15  };
    2.16  
    2.17 -static void svm_npt_detect(void)
    2.18 +static int svm_npt_detect(void)
    2.19  {
    2.20      u32 eax, ebx, ecx, edx;
    2.21  
    2.22      /* Check CPUID for nested paging support. */
    2.23      cpuid(0x8000000A, &eax, &ebx, &ecx, &edx);
    2.24  
    2.25 -    if ( !(edx & 1) && opt_hap_enabled )
    2.26 -    {
    2.27 -        printk("SVM: Nested paging is not supported by this CPU.\n");
    2.28 -        opt_hap_enabled = 0;
    2.29 -    }
    2.30 +    return (edx & 1);
    2.31  }
    2.32  
    2.33  int start_svm(struct cpuinfo_x86 *c)
    2.34 @@ -978,8 +971,6 @@ int start_svm(struct cpuinfo_x86 *c)
    2.35  
    2.36      write_efer(read_efer() | EFER_SVME);
    2.37  
    2.38 -    svm_npt_detect();
    2.39 -
    2.40      /* Initialize the HSA for this core. */
    2.41      phys_hsa = (u64) virt_to_maddr(hsa[cpu]);
    2.42      phys_hsa_lo = (u32) phys_hsa;
    2.43 @@ -994,11 +985,10 @@ int start_svm(struct cpuinfo_x86 *c)
    2.44  
    2.45      setup_vmcb_dump();
    2.46  
    2.47 +    svm_function_table.hap_supported = svm_npt_detect();
    2.48 +
    2.49      hvm_enable(&svm_function_table);
    2.50  
    2.51 -    if ( opt_hap_enabled )
    2.52 -        printk("SVM: Nested paging enabled.\n");
    2.53 -        
    2.54      return 1;
    2.55  }
    2.56  
     3.1 --- a/xen/arch/x86/mm/paging.c	Thu Sep 27 18:08:11 2007 +0100
     3.2 +++ b/xen/arch/x86/mm/paging.c	Fri Sep 28 15:03:50 2007 +0100
     3.3 @@ -28,9 +28,7 @@
     3.4  #include <asm/guest_access.h>
     3.5  #include <xsm/xsm.h>
     3.6  
     3.7 -/* Xen command-line option to enable hardware-assisted paging */
     3.8 -int opt_hap_enabled;
     3.9 -boolean_param("hap", opt_hap_enabled);
    3.10 +#define hap_enabled(d) (hvm_funcs.hap_supported && is_hvm_domain(d))
    3.11  
    3.12  /* Printouts */
    3.13  #define PAGING_PRINTK(_f, _a...)                                     \
    3.14 @@ -363,14 +361,14 @@ void paging_domain_init(struct domain *d
    3.15      shadow_domain_init(d);
    3.16  
    3.17      /* ... but we will use hardware assistance if it's available. */
    3.18 -    if ( opt_hap_enabled && is_hvm_domain(d) )
    3.19 +    if ( hap_enabled(d) )
    3.20          hap_domain_init(d);
    3.21  }
    3.22  
    3.23  /* vcpu paging struct initialization goes here */
    3.24  void paging_vcpu_init(struct vcpu *v)
    3.25  {
    3.26 -    if ( opt_hap_enabled && is_hvm_vcpu(v) )
    3.27 +    if ( hap_enabled(v->domain) )
    3.28          hap_vcpu_init(v);
    3.29      else
    3.30          shadow_vcpu_init(v);
    3.31 @@ -434,7 +432,7 @@ int paging_domctl(struct domain *d, xen_
    3.32      }
    3.33  
    3.34      /* Here, dispatch domctl to the appropriate paging code */
    3.35 -    if ( opt_hap_enabled && is_hvm_domain(d) )
    3.36 +    if ( hap_enabled(d) )
    3.37          return hap_domctl(d, sc, u_domctl);
    3.38      else
    3.39          return shadow_domctl(d, sc, u_domctl);
    3.40 @@ -443,7 +441,7 @@ int paging_domctl(struct domain *d, xen_
    3.41  /* Call when destroying a domain */
    3.42  void paging_teardown(struct domain *d)
    3.43  {
    3.44 -    if ( opt_hap_enabled && is_hvm_domain(d) )
    3.45 +    if ( hap_enabled(d) )
    3.46          hap_teardown(d);
    3.47      else
    3.48          shadow_teardown(d);
    3.49 @@ -455,7 +453,7 @@ void paging_teardown(struct domain *d)
    3.50  /* Call once all of the references to the domain have gone away */
    3.51  void paging_final_teardown(struct domain *d)
    3.52  {
    3.53 -    if ( opt_hap_enabled && is_hvm_domain(d) )
    3.54 +    if ( hap_enabled(d) )
    3.55          hap_final_teardown(d);
    3.56      else
    3.57          shadow_final_teardown(d);
    3.58 @@ -465,7 +463,7 @@ void paging_final_teardown(struct domain
    3.59   * creation. */
    3.60  int paging_enable(struct domain *d, u32 mode)
    3.61  {
    3.62 -    if ( opt_hap_enabled && is_hvm_domain(d) )
    3.63 +    if ( hap_enabled(d) )
    3.64          return hap_enable(d, mode | PG_HAP_enable);
    3.65      else
    3.66          return shadow_enable(d, mode | PG_SH_enable);
     4.1 --- a/xen/include/asm-x86/hvm/hvm.h	Thu Sep 27 18:08:11 2007 +0100
     4.2 +++ b/xen/include/asm-x86/hvm/hvm.h	Fri Sep 28 15:03:50 2007 +0100
     4.3 @@ -72,6 +72,9 @@ enum hvm_intack {
     4.4  struct hvm_function_table {
     4.5      char *name;
     4.6  
     4.7 +    /* Support Hardware-Assisted Paging? */
     4.8 +    int hap_supported;
     4.9 +
    4.10      /*
    4.11       * Initialise/destroy HVM domain/vcpu resources
    4.12       */