* [PATCH] x86: replace literal numbers
@ 2012-09-21 11:33 Jan Beulich
2012-09-28 8:21 ` Ping: " Jan Beulich
0 siblings, 1 reply; 3+ messages in thread
From: Jan Beulich @ 2012-09-21 11:33 UTC (permalink / raw)
To: xen-devel
[-- Attachment #1: Type: text/plain, Size: 3159 bytes --]
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 <jbeulich@suse.com>
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -368,8 +368,9 @@ int switch_compat(struct domain *d)
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;
}
int vcpu_initialise(struct vcpu *v)
@@ -426,7 +427,7 @@ int vcpu_initialise(struct vcpu *v)
}
else
v->arch.pv_vcpu.trap_ctxt = (void *)v + PAGE_SIZE -
- 256 * sizeof(*v->arch.pv_vcpu.trap_ctxt);
+ NR_VECTORS * sizeof(*v->arch.pv_vcpu.trap_ctxt);
/* PV guests by default have a 100Hz ticker. */
v->periodic_period = 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);
- for ( i = 0; i < 256; i++ )
+ for ( i = 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);
- for ( i = 0; i < 256; i++ )
+ for ( i = 0; i < ARRAY_SIZE(c.cmp->trap_ctxt); i++ )
fixup_guest_code_selector(d, c.cmp->trap_ctxt[i].cs);
/* 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 >= d->max_vcpus);
/* Sanity check - XXX should be more fine grained. */
- BUG_ON(trap_nr > TRAP_syscall);
+ BUG_ON(trap_nr >= NR_VECTORS);
v = d->vcpu[vcpuid];
t = &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;
}
[-- Attachment #2: x86-use-NR_VECTORS.patch --]
[-- Type: text/plain, Size: 3185 bytes --]
x86: replace literal numbers
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 <jbeulich@suse.com>
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -368,8 +368,9 @@ int switch_compat(struct domain *d)
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;
}
int vcpu_initialise(struct vcpu *v)
@@ -426,7 +427,7 @@ int vcpu_initialise(struct vcpu *v)
}
else
v->arch.pv_vcpu.trap_ctxt = (void *)v + PAGE_SIZE -
- 256 * sizeof(*v->arch.pv_vcpu.trap_ctxt);
+ NR_VECTORS * sizeof(*v->arch.pv_vcpu.trap_ctxt);
/* PV guests by default have a 100Hz ticker. */
v->periodic_period = 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);
- for ( i = 0; i < 256; i++ )
+ for ( i = 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);
- for ( i = 0; i < 256; i++ )
+ for ( i = 0; i < ARRAY_SIZE(c.cmp->trap_ctxt); i++ )
fixup_guest_code_selector(d, c.cmp->trap_ctxt[i].cs);
/* 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 >= d->max_vcpus);
/* Sanity check - XXX should be more fine grained. */
- BUG_ON(trap_nr > TRAP_syscall);
+ BUG_ON(trap_nr >= NR_VECTORS);
v = d->vcpu[vcpuid];
t = &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;
}
[-- Attachment #3: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Ping: [PATCH] x86: replace literal numbers
2012-09-21 11:33 [PATCH] x86: replace literal numbers Jan Beulich
@ 2012-09-28 8:21 ` Jan Beulich
2012-09-28 8:37 ` Keir Fraser
0 siblings, 1 reply; 3+ messages in thread
From: Jan Beulich @ 2012-09-28 8:21 UTC (permalink / raw)
To: xen-devel
[-- Attachment #1: Type: text/plain, Size: 3159 bytes --]
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 <jbeulich@suse.com>
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -374,8 +374,9 @@ int switch_compat(struct domain *d)
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;
}
int vcpu_initialise(struct vcpu *v)
@@ -432,7 +433,7 @@ int vcpu_initialise(struct vcpu *v)
}
else
v->arch.pv_vcpu.trap_ctxt = (void *)v + PAGE_SIZE -
- 256 * sizeof(*v->arch.pv_vcpu.trap_ctxt);
+ NR_VECTORS * sizeof(*v->arch.pv_vcpu.trap_ctxt);
/* PV guests by default have a 100Hz ticker. */
v->periodic_period = MILLISECS(10);
@@ -702,7 +703,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);
- for ( i = 0; i < 256; i++ )
+ for ( i = 0; i < ARRAY_SIZE(c.nat->trap_ctxt); i++ )
{
if ( !is_canonical_address(c.nat->trap_ctxt[i].address) )
return -EINVAL;
@@ -725,7 +726,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);
- for ( i = 0; i < 256; i++ )
+ for ( i = 0; i < ARRAY_SIZE(c.cmp->trap_ctxt); i++ )
fixup_guest_code_selector(d, c.cmp->trap_ctxt[i].cs);
/* LDT safety checks. */
--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -3506,7 +3506,7 @@ int guest_has_trap_callback(struct domai
BUG_ON(vcpuid >= d->max_vcpus);
/* Sanity check - XXX should be more fine grained. */
- BUG_ON(trap_nr > TRAP_syscall);
+ BUG_ON(trap_nr >= NR_VECTORS);
v = d->vcpu[vcpuid];
t = &v->arch.pv_vcpu.trap_ctxt[trap_nr];
@@ -3574,7 +3574,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;
}
[-- Attachment #2: x86-use-NR_VECTORS.patch --]
[-- Type: text/plain, Size: 3185 bytes --]
x86: replace literal numbers
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 <jbeulich@suse.com>
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -374,8 +374,9 @@ int switch_compat(struct domain *d)
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;
}
int vcpu_initialise(struct vcpu *v)
@@ -432,7 +433,7 @@ int vcpu_initialise(struct vcpu *v)
}
else
v->arch.pv_vcpu.trap_ctxt = (void *)v + PAGE_SIZE -
- 256 * sizeof(*v->arch.pv_vcpu.trap_ctxt);
+ NR_VECTORS * sizeof(*v->arch.pv_vcpu.trap_ctxt);
/* PV guests by default have a 100Hz ticker. */
v->periodic_period = MILLISECS(10);
@@ -702,7 +703,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);
- for ( i = 0; i < 256; i++ )
+ for ( i = 0; i < ARRAY_SIZE(c.nat->trap_ctxt); i++ )
{
if ( !is_canonical_address(c.nat->trap_ctxt[i].address) )
return -EINVAL;
@@ -725,7 +726,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);
- for ( i = 0; i < 256; i++ )
+ for ( i = 0; i < ARRAY_SIZE(c.cmp->trap_ctxt); i++ )
fixup_guest_code_selector(d, c.cmp->trap_ctxt[i].cs);
/* LDT safety checks. */
--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -3506,7 +3506,7 @@ int guest_has_trap_callback(struct domai
BUG_ON(vcpuid >= d->max_vcpus);
/* Sanity check - XXX should be more fine grained. */
- BUG_ON(trap_nr > TRAP_syscall);
+ BUG_ON(trap_nr >= NR_VECTORS);
v = d->vcpu[vcpuid];
t = &v->arch.pv_vcpu.trap_ctxt[trap_nr];
@@ -3574,7 +3574,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;
}
[-- Attachment #3: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Ping: [PATCH] x86: replace literal numbers
2012-09-28 8:21 ` Ping: " Jan Beulich
@ 2012-09-28 8:37 ` Keir Fraser
0 siblings, 0 replies; 3+ messages in thread
From: Keir Fraser @ 2012-09-28 8:37 UTC (permalink / raw)
To: Jan Beulich, xen-devel
On 28/09/2012 09:21, "Jan Beulich" <JBeulich@suse.com> wrote:
> 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 <jbeulich@suse.com>
Acked-by: Keir Fraser <keir@xen.org>
> --- a/xen/arch/x86/domain.c
> +++ b/xen/arch/x86/domain.c
> @@ -374,8 +374,9 @@ int switch_compat(struct domain *d)
>
> 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;
> }
>
> int vcpu_initialise(struct vcpu *v)
> @@ -432,7 +433,7 @@ int vcpu_initialise(struct vcpu *v)
> }
> else
> v->arch.pv_vcpu.trap_ctxt = (void *)v + PAGE_SIZE -
> - 256 * sizeof(*v->arch.pv_vcpu.trap_ctxt);
> + NR_VECTORS * sizeof(*v->arch.pv_vcpu.trap_ctxt);
>
> /* PV guests by default have a 100Hz ticker. */
> v->periodic_period = MILLISECS(10);
> @@ -702,7 +703,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);
>
> - for ( i = 0; i < 256; i++ )
> + for ( i = 0; i < ARRAY_SIZE(c.nat->trap_ctxt); i++ )
> {
> if ( !is_canonical_address(c.nat->trap_ctxt[i].address) )
> return -EINVAL;
> @@ -725,7 +726,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);
>
> - for ( i = 0; i < 256; i++ )
> + for ( i = 0; i < ARRAY_SIZE(c.cmp->trap_ctxt); i++ )
> fixup_guest_code_selector(d, c.cmp->trap_ctxt[i].cs);
>
> /* LDT safety checks. */
> --- a/xen/arch/x86/traps.c
> +++ b/xen/arch/x86/traps.c
> @@ -3506,7 +3506,7 @@ int guest_has_trap_callback(struct domai
> BUG_ON(vcpuid >= d->max_vcpus);
>
> /* Sanity check - XXX should be more fine grained. */
> - BUG_ON(trap_nr > TRAP_syscall);
> + BUG_ON(trap_nr >= NR_VECTORS);
>
> v = d->vcpu[vcpuid];
> t = &v->arch.pv_vcpu.trap_ctxt[trap_nr];
> @@ -3574,7 +3574,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;
> }
>
>
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-09-28 8:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-21 11:33 [PATCH] x86: replace literal numbers Jan Beulich
2012-09-28 8:21 ` Ping: " Jan Beulich
2012-09-28 8:37 ` Keir Fraser
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).