From: "Jan Beulich" Subject: [PATCH] x86: replace literal numbers Date: Fri, 21 Sep 2012 12:33:07 +0100 Message-ID: <505C6C93020000780009CF0C@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part57665663.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel 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. --=__Part57665663.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline In various cases, 256 was being used instead of NR_VECTORS or a derived ARRAY_SIZE() expression. In one case (guest_has_trap_callback()), a wrong (unrelated) constant was used instead of NR_VECTORS. Signed-off-by: Jan Beulich --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -368,8 +368,9 @@ int switch_compat(struct domain *d) =20 static inline bool_t standalone_trap_ctxt(struct vcpu *v) { - BUILD_BUG_ON(256 * sizeof(*v->arch.pv_vcpu.trap_ctxt) > PAGE_SIZE); - return 256 * sizeof(*v->arch.pv_vcpu.trap_ctxt) + sizeof(*v) > = PAGE_SIZE; + BUILD_BUG_ON(NR_VECTORS * sizeof(*v->arch.pv_vcpu.trap_ctxt) > = PAGE_SIZE); + return NR_VECTORS * sizeof(*v->arch.pv_vcpu.trap_ctxt) + sizeof(*v) + > PAGE_SIZE; } =20 int vcpu_initialise(struct vcpu *v) @@ -426,7 +427,7 @@ int vcpu_initialise(struct vcpu *v) } else v->arch.pv_vcpu.trap_ctxt =3D (void *)v + PAGE_SIZE - - 256 * sizeof(*v->arch.pv_vcpu.trap_ctxt); + NR_VECTORS * sizeof(*v->arch.pv_vcpu.trap_ctxt); =20 /* PV guests by default have a 100Hz ticker. */ v->periodic_period =3D MILLISECS(10); @@ -701,7 +702,7 @@ int arch_set_info_guest( fixup_guest_stack_selector(d, c.nat->kernel_ss); fixup_guest_code_selector(d, c.nat->user_regs.cs); =20 - for ( i =3D 0; i < 256; i++ ) + for ( i =3D 0; i < ARRAY_SIZE(c.nat->trap_ctxt); i++ ) { if ( !is_canonical_address(c.nat->trap_ctxt[i].address) ) return -EINVAL; @@ -724,7 +725,7 @@ int arch_set_info_guest( fixup_guest_code_selector(d, c.cmp->event_callback_cs); fixup_guest_code_selector(d, c.cmp->failsafe_callback_cs); =20 - for ( i =3D 0; i < 256; i++ ) + for ( i =3D 0; i < ARRAY_SIZE(c.cmp->trap_ctxt); i++ ) fixup_guest_code_selector(d, c.cmp->trap_ctxt[i].cs); =20 /* LDT safety checks. */ --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -3542,7 +3542,7 @@ int guest_has_trap_callback(struct domai BUG_ON(vcpuid >=3D d->max_vcpus); =20 /* Sanity check - XXX should be more fine grained. */ - BUG_ON(trap_nr > TRAP_syscall); + BUG_ON(trap_nr >=3D NR_VECTORS); =20 v =3D d->vcpu[vcpuid]; t =3D &v->arch.pv_vcpu.trap_ctxt[trap_nr]; @@ -3610,7 +3610,7 @@ long do_set_trap_table(XEN_GUEST_HANDLE( /* If no table is presented then clear the entire virtual IDT. */ if ( guest_handle_is_null(traps) ) { - memset(dst, 0, 256 * sizeof(*dst)); + memset(dst, 0, NR_VECTORS * sizeof(*dst)); init_int80_direct_trap(curr); return 0; } --- a/xen/arch/x86/x86_64/compat/traps.c +++ b/xen/arch/x86/x86_64/compat/traps.c @@ -317,7 +317,7 @@ int compat_set_trap_table(XEN_GUEST_HAND /* If no table is presented then clear the entire virtual IDT. */ if ( guest_handle_is_null(traps) ) { - memset(dst, 0, 256 * sizeof(*dst)); + memset(dst, 0, NR_VECTORS * sizeof(*dst)); return 0; } =20 --=__Part57665663.0__= Content-Type: text/plain; name="x86-use-NR_VECTORS.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-use-NR_VECTORS.patch" x86: replace literal numbers=0A=0AIn various cases, 256 was being used = instead of NR_VECTORS or a derived=0AARRAY_SIZE() expression. In one case = (guest_has_trap_callback()), a=0Awrong (unrelated) constant was used = instead of NR_VECTORS.=0A=0ASigned-off-by: Jan Beulich = =0A=0A--- a/xen/arch/x86/domain.c=0A+++ b/xen/arch/x86/domain.c=0A@@ = -368,8 +368,9 @@ int switch_compat(struct domain *d)=0A =0A static inline = bool_t standalone_trap_ctxt(struct vcpu *v)=0A {=0A- BUILD_BUG_ON(256 * = sizeof(*v->arch.pv_vcpu.trap_ctxt) > PAGE_SIZE);=0A- return 256 * = sizeof(*v->arch.pv_vcpu.trap_ctxt) + sizeof(*v) > PAGE_SIZE;=0A+ = BUILD_BUG_ON(NR_VECTORS * sizeof(*v->arch.pv_vcpu.trap_ctxt) > PAGE_SIZE);= =0A+ return NR_VECTORS * sizeof(*v->arch.pv_vcpu.trap_ctxt) + sizeof(*v)= =0A+ > PAGE_SIZE;=0A }=0A =0A int vcpu_initialise(struct vcpu = *v)=0A@@ -426,7 +427,7 @@ int vcpu_initialise(struct vcpu *v)=0A = }=0A else=0A v->arch.pv_vcpu.trap_ctxt =3D (void *)v + = PAGE_SIZE -=0A- 256 * sizeof(*v->arch.pv_vcpu.trap_ctxt);=0A= + NR_VECTORS * sizeof(*v->arch.pv_vcpu.trap_ctxt);=0A =0A = /* PV guests by default have a 100Hz ticker. */=0A v->periodi= c_period =3D MILLISECS(10);=0A@@ -701,7 +702,7 @@ int arch_set_info_guest(= =0A fixup_guest_stack_selector(d, c.nat->kernel_ss);=0A = fixup_guest_code_selector(d, c.nat->user_regs.cs);=0A =0A- = for ( i =3D 0; i < 256; i++ )=0A+ for ( i =3D 0; i < ARRAY_SIZE(= c.nat->trap_ctxt); i++ )=0A {=0A if ( = !is_canonical_address(c.nat->trap_ctxt[i].address) )=0A = return -EINVAL;=0A@@ -724,7 +725,7 @@ int arch_set_info_guest(=0A = fixup_guest_code_selector(d, c.cmp->event_callback_cs);=0A = fixup_guest_code_selector(d, c.cmp->failsafe_callback_cs);=0A =0A- = for ( i =3D 0; i < 256; i++ )=0A+ for ( i =3D 0; i < = ARRAY_SIZE(c.cmp->trap_ctxt); i++ )=0A fixup_guest_code_sel= ector(d, c.cmp->trap_ctxt[i].cs);=0A =0A /* LDT safety checks. = */=0A--- a/xen/arch/x86/traps.c=0A+++ b/xen/arch/x86/traps.c=0A@@ -3542,7 = +3542,7 @@ int guest_has_trap_callback(struct domai=0A BUG_ON(vcpuid = >=3D d->max_vcpus);=0A =0A /* Sanity check - XXX should be more fine = grained. */=0A- BUG_ON(trap_nr > TRAP_syscall);=0A+ BUG_ON(trap_nr = >=3D NR_VECTORS);=0A =0A v =3D d->vcpu[vcpuid];=0A t =3D &v->arch.p= v_vcpu.trap_ctxt[trap_nr];=0A@@ -3610,7 +3610,7 @@ long do_set_trap_table(X= EN_GUEST_HANDLE(=0A /* If no table is presented then clear the entire = virtual IDT. */=0A if ( guest_handle_is_null(traps) )=0A {=0A- = memset(dst, 0, 256 * sizeof(*dst));=0A+ memset(dst, 0, NR_VECTORS= * sizeof(*dst));=0A init_int80_direct_trap(curr);=0A = return 0;=0A }=0A--- a/xen/arch/x86/x86_64/compat/traps.c=0A+++ = b/xen/arch/x86/x86_64/compat/traps.c=0A@@ -317,7 +317,7 @@ int compat_set_t= rap_table(XEN_GUEST_HAND=0A /* If no table is presented then clear the = entire virtual IDT. */=0A if ( guest_handle_is_null(traps) )=0A = {=0A- memset(dst, 0, 256 * sizeof(*dst));=0A+ memset(dst, 0, = NR_VECTORS * sizeof(*dst));=0A return 0;=0A }=0A =0A --=__Part57665663.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.xen.org http://lists.xen.org/xen-devel --=__Part57665663.0__=--