xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/svm: eliminate unnecessary NR_CPUS-sized arrays
@ 2010-07-08 15:34 Jan Beulich
  0 siblings, 0 replies; only message in thread
From: Jan Beulich @ 2010-07-08 15:34 UTC (permalink / raw)
  To: xen-devel@lists.xensource.com

[-- Attachment #1: Type: text/plain, Size: 2543 bytes --]

Replace them with per-CPU data.

Signed-off-by: Jan Beulich <jbeulich@novell.com>

--- 2010-06-15.orig/xen/arch/x86/hvm/svm/svm.c	2010-06-14 08:49:36.000000000 +0200
+++ 2010-06-15/xen/arch/x86/hvm/svm/svm.c	2010-07-06 15:09:06.000000000 +0200
@@ -68,10 +68,10 @@ static struct hvm_function_table svm_fun
 enum handler_return { HNDL_done, HNDL_unhandled, HNDL_exception_raised };
 
 /* va of hardware host save area     */
-static void *hsa[NR_CPUS] __read_mostly;
+static DEFINE_PER_CPU_READ_MOSTLY(void *, hsa);
 
 /* vmcb used for extended host state */
-static void *root_vmcb[NR_CPUS] __read_mostly;
+static DEFINE_PER_CPU_READ_MOSTLY(void *, root_vmcb);
 
 static bool_t amd_erratum383_found __read_mostly;
 
@@ -643,7 +643,7 @@ static void svm_ctxt_switch_from(struct 
     vpmu_save(v);
 
     svm_sync_vmcb(v);
-    svm_vmload(root_vmcb[cpu]);
+    svm_vmload(per_cpu(root_vmcb, cpu));
 
 #ifdef __x86_64__
     /* Resume use of ISTs now that the host TR is reinstated. */
@@ -679,7 +679,7 @@ static void svm_ctxt_switch_to(struct vc
 
     svm_restore_dr(v);
 
-    svm_vmsave(root_vmcb[cpu]);
+    svm_vmsave(per_cpu(root_vmcb, cpu));
     svm_vmload(v->arch.hvm_svm.vmcb);
     vpmu_load(v);
 
@@ -821,18 +821,18 @@ static int svm_do_pmu_interrupt(struct c
 
 static void svm_cpu_dead(unsigned int cpu)
 {
-    free_xenheap_page(hsa[cpu]);
-    hsa[cpu] = NULL;
-    free_vmcb(root_vmcb[cpu]);
-    root_vmcb[cpu] = NULL;
+    free_xenheap_page(per_cpu(hsa, cpu));
+    per_cpu(hsa, cpu) = NULL;
+    free_vmcb(per_cpu(root_vmcb, cpu));
+    per_cpu(root_vmcb, cpu) = NULL;
 }
 
 static int svm_cpu_up_prepare(unsigned int cpu)
 {
-    if ( ((hsa[cpu] == NULL) &&
-          ((hsa[cpu] = alloc_host_save_area()) == NULL)) ||
-         ((root_vmcb[cpu] == NULL) &&
-          ((root_vmcb[cpu] = alloc_vmcb()) == NULL)) )
+    if ( ((per_cpu(hsa, cpu) == NULL) &&
+          ((per_cpu(hsa, cpu) = alloc_host_save_area()) == NULL)) ||
+         ((per_cpu(root_vmcb, cpu) == NULL) &&
+          ((per_cpu(root_vmcb, cpu) = alloc_vmcb()) == NULL)) )
     {
         svm_cpu_dead(cpu);
         return -ENOMEM;
@@ -880,7 +880,7 @@ static int svm_cpu_up(void)
     write_efer(read_efer() | EFER_SVME);
 
     /* Initialize the HSA for this core. */
-    wrmsrl(MSR_K8_VM_HSAVE_PA, (uint64_t)virt_to_maddr(hsa[cpu]));
+    wrmsrl(MSR_K8_VM_HSAVE_PA, (uint64_t)virt_to_maddr(per_cpu(hsa, cpu)));
 
     /* check for erratum 383 */
     svm_init_erratum_383(c);




[-- Attachment #2: svm-no-NR_CPUS.patch --]
[-- Type: text/plain, Size: 2537 bytes --]

Replace them with per-CPU data.

Signed-off-by: Jan Beulich <jbeulich@novell.com>

--- 2010-06-15.orig/xen/arch/x86/hvm/svm/svm.c	2010-06-14 08:49:36.000000000 +0200
+++ 2010-06-15/xen/arch/x86/hvm/svm/svm.c	2010-07-06 15:09:06.000000000 +0200
@@ -68,10 +68,10 @@ static struct hvm_function_table svm_fun
 enum handler_return { HNDL_done, HNDL_unhandled, HNDL_exception_raised };
 
 /* va of hardware host save area     */
-static void *hsa[NR_CPUS] __read_mostly;
+static DEFINE_PER_CPU_READ_MOSTLY(void *, hsa);
 
 /* vmcb used for extended host state */
-static void *root_vmcb[NR_CPUS] __read_mostly;
+static DEFINE_PER_CPU_READ_MOSTLY(void *, root_vmcb);
 
 static bool_t amd_erratum383_found __read_mostly;
 
@@ -643,7 +643,7 @@ static void svm_ctxt_switch_from(struct 
     vpmu_save(v);
 
     svm_sync_vmcb(v);
-    svm_vmload(root_vmcb[cpu]);
+    svm_vmload(per_cpu(root_vmcb, cpu));
 
 #ifdef __x86_64__
     /* Resume use of ISTs now that the host TR is reinstated. */
@@ -679,7 +679,7 @@ static void svm_ctxt_switch_to(struct vc
 
     svm_restore_dr(v);
 
-    svm_vmsave(root_vmcb[cpu]);
+    svm_vmsave(per_cpu(root_vmcb, cpu));
     svm_vmload(v->arch.hvm_svm.vmcb);
     vpmu_load(v);
 
@@ -821,18 +821,18 @@ static int svm_do_pmu_interrupt(struct c
 
 static void svm_cpu_dead(unsigned int cpu)
 {
-    free_xenheap_page(hsa[cpu]);
-    hsa[cpu] = NULL;
-    free_vmcb(root_vmcb[cpu]);
-    root_vmcb[cpu] = NULL;
+    free_xenheap_page(per_cpu(hsa, cpu));
+    per_cpu(hsa, cpu) = NULL;
+    free_vmcb(per_cpu(root_vmcb, cpu));
+    per_cpu(root_vmcb, cpu) = NULL;
 }
 
 static int svm_cpu_up_prepare(unsigned int cpu)
 {
-    if ( ((hsa[cpu] == NULL) &&
-          ((hsa[cpu] = alloc_host_save_area()) == NULL)) ||
-         ((root_vmcb[cpu] == NULL) &&
-          ((root_vmcb[cpu] = alloc_vmcb()) == NULL)) )
+    if ( ((per_cpu(hsa, cpu) == NULL) &&
+          ((per_cpu(hsa, cpu) = alloc_host_save_area()) == NULL)) ||
+         ((per_cpu(root_vmcb, cpu) == NULL) &&
+          ((per_cpu(root_vmcb, cpu) = alloc_vmcb()) == NULL)) )
     {
         svm_cpu_dead(cpu);
         return -ENOMEM;
@@ -880,7 +880,7 @@ static int svm_cpu_up(void)
     write_efer(read_efer() | EFER_SVME);
 
     /* Initialize the HSA for this core. */
-    wrmsrl(MSR_K8_VM_HSAVE_PA, (uint64_t)virt_to_maddr(hsa[cpu]));
+    wrmsrl(MSR_K8_VM_HSAVE_PA, (uint64_t)virt_to_maddr(per_cpu(hsa, cpu)));
 
     /* check for erratum 383 */
     svm_init_erratum_383(c);

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-07-08 15:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-08 15:34 [PATCH] x86/svm: eliminate unnecessary NR_CPUS-sized arrays Jan Beulich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).