From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Jan Beulich" Subject: [PATCH] x86/svm: eliminate unnecessary NR_CPUS-sized arrays Date: Thu, 08 Jul 2010 16:34:48 +0100 Message-ID: <4C360C38020000780000A485@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartE9C49D08.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartE9C49D08.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Replace them with per-CPU data. Signed-off-by: Jan Beulich --- 2010-06-15.orig/xen/arch/x86/hvm/svm/svm.c 2010-06-14 08:49:36.0000000= 00 +0200 +++ 2010-06-15/xen/arch/x86/hvm/svm/svm.c 2010-07-06 15:09:06.0000000= 00 +0200 @@ -68,10 +68,10 @@ static struct hvm_function_table svm_fun enum handler_return { HNDL_done, HNDL_unhandled, HNDL_exception_raised }; =20 /* va of hardware host save area */ -static void *hsa[NR_CPUS] __read_mostly; +static DEFINE_PER_CPU_READ_MOSTLY(void *, hsa); =20 /* vmcb used for extended host state */ -static void *root_vmcb[NR_CPUS] __read_mostly; +static DEFINE_PER_CPU_READ_MOSTLY(void *, root_vmcb); =20 static bool_t amd_erratum383_found __read_mostly; =20 @@ -643,7 +643,7 @@ static void svm_ctxt_switch_from(struct=20 vpmu_save(v); =20 svm_sync_vmcb(v); - svm_vmload(root_vmcb[cpu]); + svm_vmload(per_cpu(root_vmcb, cpu)); =20 #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 =20 svm_restore_dr(v); =20 - svm_vmsave(root_vmcb[cpu]); + svm_vmsave(per_cpu(root_vmcb, cpu)); svm_vmload(v->arch.hvm_svm.vmcb); vpmu_load(v); =20 @@ -821,18 +821,18 @@ static int svm_do_pmu_interrupt(struct c =20 static void svm_cpu_dead(unsigned int cpu) { - free_xenheap_page(hsa[cpu]); - hsa[cpu] =3D NULL; - free_vmcb(root_vmcb[cpu]); - root_vmcb[cpu] =3D NULL; + free_xenheap_page(per_cpu(hsa, cpu)); + per_cpu(hsa, cpu) =3D NULL; + free_vmcb(per_cpu(root_vmcb, cpu)); + per_cpu(root_vmcb, cpu) =3D NULL; } =20 static int svm_cpu_up_prepare(unsigned int cpu) { - if ( ((hsa[cpu] =3D=3D NULL) && - ((hsa[cpu] =3D alloc_host_save_area()) =3D=3D NULL)) || - ((root_vmcb[cpu] =3D=3D NULL) && - ((root_vmcb[cpu] =3D alloc_vmcb()) =3D=3D NULL)) ) + if ( ((per_cpu(hsa, cpu) =3D=3D NULL) && + ((per_cpu(hsa, cpu) =3D alloc_host_save_area()) =3D=3D NULL)) = || + ((per_cpu(root_vmcb, cpu) =3D=3D NULL) && + ((per_cpu(root_vmcb, cpu) =3D alloc_vmcb()) =3D=3D NULL)) ) { svm_cpu_dead(cpu); return -ENOMEM; @@ -880,7 +880,7 @@ static int svm_cpu_up(void) write_efer(read_efer() | EFER_SVME); =20 /* 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))); =20 /* check for erratum 383 */ svm_init_erratum_383(c); --=__PartE9C49D08.0__= Content-Type: text/plain; name="svm-no-NR_CPUS.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="svm-no-NR_CPUS.patch" Replace them with per-CPU data.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- 2010-06-15.orig/xen/arch/x86/hvm/svm/svm.c 2010-06-14 = 08:49:36.000000000 +0200=0A+++ 2010-06-15/xen/arch/x86/hvm/svm/svm.c = 2010-07-06 15:09:06.000000000 +0200=0A@@ -68,10 +68,10 @@ static struct = hvm_function_table svm_fun=0A enum handler_return { HNDL_done, HNDL_unhandl= ed, HNDL_exception_raised };=0A =0A /* va of hardware host save area = */=0A-static void *hsa[NR_CPUS] __read_mostly;=0A+static DEFINE_PER_CPU_REA= D_MOSTLY(void *, hsa);=0A =0A /* vmcb used for extended host state = */=0A-static void *root_vmcb[NR_CPUS] __read_mostly;=0A+static DEFINE_PER_C= PU_READ_MOSTLY(void *, root_vmcb);=0A =0A static bool_t amd_erratum383_foun= d __read_mostly;=0A =0A@@ -643,7 +643,7 @@ static void svm_ctxt_switch_from= (struct =0A vpmu_save(v);=0A =0A svm_sync_vmcb(v);=0A- = svm_vmload(root_vmcb[cpu]);=0A+ svm_vmload(per_cpu(root_vmcb, cpu));=0A = =0A #ifdef __x86_64__=0A /* Resume use of ISTs now that the host TR is = reinstated. */=0A@@ -679,7 +679,7 @@ static void svm_ctxt_switch_to(struct = vc=0A =0A svm_restore_dr(v);=0A =0A- svm_vmsave(root_vmcb[cpu]);=0A+= svm_vmsave(per_cpu(root_vmcb, cpu));=0A svm_vmload(v->arch.hvm_svm.= vmcb);=0A vpmu_load(v);=0A =0A@@ -821,18 +821,18 @@ static int = svm_do_pmu_interrupt(struct c=0A =0A static void svm_cpu_dead(unsigned int = cpu)=0A {=0A- free_xenheap_page(hsa[cpu]);=0A- hsa[cpu] =3D = NULL;=0A- free_vmcb(root_vmcb[cpu]);=0A- root_vmcb[cpu] =3D = NULL;=0A+ free_xenheap_page(per_cpu(hsa, cpu));=0A+ per_cpu(hsa, = cpu) =3D NULL;=0A+ free_vmcb(per_cpu(root_vmcb, cpu));=0A+ per_cpu(ro= ot_vmcb, cpu) =3D NULL;=0A }=0A =0A static int svm_cpu_up_prepare(unsigned = int cpu)=0A {=0A- if ( ((hsa[cpu] =3D=3D NULL) &&=0A- = ((hsa[cpu] =3D alloc_host_save_area()) =3D=3D NULL)) ||=0A- = ((root_vmcb[cpu] =3D=3D NULL) &&=0A- ((root_vmcb[cpu] =3D = alloc_vmcb()) =3D=3D NULL)) )=0A+ if ( ((per_cpu(hsa, cpu) =3D=3D NULL) = &&=0A+ ((per_cpu(hsa, cpu) =3D alloc_host_save_area()) =3D=3D = NULL)) ||=0A+ ((per_cpu(root_vmcb, cpu) =3D=3D NULL) &&=0A+ = ((per_cpu(root_vmcb, cpu) =3D alloc_vmcb()) =3D=3D NULL)) )=0A {=0A = svm_cpu_dead(cpu);=0A return -ENOMEM;=0A@@ -880,7 +880,7 @@ = static int svm_cpu_up(void)=0A write_efer(read_efer() | EFER_SVME);=0A = =0A /* Initialize the HSA for this core. */=0A- wrmsrl(MSR_K8_VM_HSA= VE_PA, (uint64_t)virt_to_maddr(hsa[cpu]));=0A+ wrmsrl(MSR_K8_VM_HSAVE_PA= , (uint64_t)virt_to_maddr(per_cpu(hsa, cpu)));=0A =0A /* check for = erratum 383 */=0A svm_init_erratum_383(c);=0A --=__PartE9C49D08.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__PartE9C49D08.0__=--