Skip to contentSkip to conversation

x86_64: remove wrong setting about CONSTANT_TSC for intel cpu

PATCH In review Yinghai Lu 4 participants 9 messages Feb 26, 2008 x86

lore
Share & tools
lore

Yinghai Lu

author
#0 lore raw

PATCH 1/1 x86_64: remove wrong setting about CONSTANT_TSC for intel cpu

early_init_intel is introduced by

commit 2b16a2353814a513cdb5c5c739b76a19d7ea39ce

Author: Andi Kleen <[email protected]>
Date:   Wed Jan 30 13:32:40 2008 +0100

x86: move X86_FEATURE_CONSTANT_TSC into early cpu feature detection

set CONSTANT_TSC for intel cpus

but it already set in init_intel

don't need to set that two times in early_init_intel() and init_intel. this patch remove one.

also fix error in early_init_intel and reference about x86_capality, because it is array already.., prevent possible data corruption...

this should be applied for 2.6.25

arch/x86/kernel/setup_64.c +1 -4
index 62d3f14..210134c 100644
@@ -1027,7 +1027,7 @@ static void __cpuinit early_init_intel(struct cpuinfo_x86 *c)
 {
 	if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
 	    (c->x86 == 0x6 && c->x86_model >= 0x0e))
-		set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability);
+		set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
 }
 
 static void __cpuinit init_intel(struct cpuinfo_x86 *c)
@@ -1071,9 +1071,6 @@ static void __cpuinit init_intel(struct cpuinfo_x86 *c)
 
 	if (c->x86 == 15)
 		c->x86_cache_alignment = c->x86_clflush_size * 2;
-	if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
-	    (c->x86 == 0x6 && c->x86_model >= 0x0e))
-		set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
 	if (c->x86 == 6)
 		set_cpu_cap(c, X86_FEATURE_REP_GOOD);
 	set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
#1 lore raw
Quoted 10 lines · Yinghai Lu

early_init_intel is introduced by

commit 2b16a2353814a513cdb5c5c739b76a19d7ea39ce

Author: Andi Kleen <[email protected]>
Date:   Wed Jan 30 13:32:40 2008 +0100

x86: move X86_FEATURE_CONSTANT_TSC into early cpu feature detection

set CONSTANT_TSC for intel cpus

Quoted 8 lines

but it already set in init_intel

don't need to set that two times in early_init_intel() and init_intel. this patch remove one.

also fix error in early_init_intel and reference about x86_capality, because it is array already.., prevent possible data corruption...

this should be applied for 2.6.25

thanks Yinghai, applied.

Ingo

#2 lore raw
In reply to Yinghai Lu
Quoted 2 lines · Yinghai Lu

also fix error in early_init_intel and reference about x86_capality, because it is array already.., prevent possible data corruption...

hm, why should there be data corruption:

arch/x86/kernel/setup_64.c static void __cpuinit early_init_intel(struct cpuinfo_x86 *c) · line 1030

Quoted 2 lines
arch/x86/kernel/setup_64.c +1 -1
-		set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability);
+		set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);

cpu_cpu_cap() is currently defined as:

#define set_cpu_cap(c, bit) set_bit(bit, (unsigned long *)((c)->x86_capability)

which is the same. set_cpu_cap() is indeed the cleaner form to do this so your patch is correct as a cleanup.

Ingo

#3 lore raw
Quoted 13 lines · Ingo Molnar
Quoted 2 lines · Yinghai Lu

also fix error in early_init_intel and reference about x86_capality, because it is array already.., prevent possible data corruption...

hm, why should there be data corruption:

arch/x86/kernel/setup_64.c static void __cpuinit early_init_intel(struct cpuinfo_x86 *c) · line 1030

Quoted 2 lines
arch/x86/kernel/setup_64.c +1 -1
-             set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability);
+             set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
Quoted 6 lines

cpu_cpu_cap() is currently defined as:

  #define set_cpu_cap(c, bit)     set_bit(bit, (unsigned long *)((c)->x86_capability)

which is the same. set_cpu_cap() is indeed the cleaner form to do this so your patch is correct as a cleanup.

set_cpu_cap is right
==
set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability); ===> is wrong should be
set_bit(X86_FEATURE_CONSTANT_TSC, c->x86_capability);

x86_capability is a array ...

so this could prevent some data corruption.

YH

#4 lore raw
Quoted 10 lines · Yinghai Lu
Quoted 4 lines
  #define set_cpu_cap(c, bit)     set_bit(bit, (unsigned long *)((c)->x86_capability)

which is the same. set_cpu_cap() is indeed the cleaner form to do this so your patch is correct as a cleanup.

set_cpu_cap is right
==
set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability); ===> is wrong should be
set_bit(X86_FEATURE_CONSTANT_TSC, c->x86_capability);

Quoted 3 lines

x86_capability is a array ...

so this could prevent some data corruption.

ah, right you are! The commit was done in a sloppy, incomplete way, leaving around lots of direct c->x86_capability references and giving room for this bug ...

Btw., there's one other place that has the same bug. I'll fix that up too.

Ingo

#5 lore raw
Quoted 11 lines · Ingo Molnar
Quoted 9 lines

set_cpu_cap is right
==
set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability); ===> is wrong should be
set_bit(X86_FEATURE_CONSTANT_TSC, c->x86_capability);

x86_capability is a array ...

so this could prevent some data corruption.

ah, right you are! [...]

actually, not: &c->x86_capability and c->x86_capability result in the same address (it's an array, not a pointer), so there's no "data corruption". If x86_capability were a pointer then you would be right - so this is all worth cleaning up.

Ingo

#6 lore raw
In reply to Yinghai Lu
Quoted 10 lines · Yinghai Lu
Quoted 2 lines

which is the same. set_cpu_cap() is indeed the cleaner form to do this so your patch is correct as a cleanup.

set_cpu_cap is right
==
set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability); ===> is wrong should be
set_bit(X86_FEATURE_CONSTANT_TSC, c->x86_capability);

x86_capability is a array ...

For an array, the & is optional and has no effect.

So they mean the same thing.

-hpa

#7 lore raw
Quoted 9 lines · H. Peter Anvin
Quoted 8 lines · Yinghai Lu
Quoted 2 lines

which is the same. set_cpu_cap() is indeed the cleaner form to do this so your patch is correct as a cleanup.

set_cpu_cap is right
==
set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability); ===> is wrong should be
set_bit(X86_FEATURE_CONSTANT_TSC, c->x86_capability);

Quoted 5 lines
Quoted 1 line

x86_capability is a array ...

For an array, the & is optional and has no effect.

So they mean the same thing.

yeah. It's unnecessary entropy nevertheless and i've cleaned it all up in x86.git.

Ingo

#8 lore raw
In reply to H. Peter Anvin
Quoted 9 lines · H. Peter Anvin
Quoted 8 lines · Yinghai Lu
Quoted 2 lines

which is the same. set_cpu_cap() is indeed the cleaner form to do this so your patch is correct as a cleanup.

set_cpu_cap is right
==
set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability); ===> is wrong should be
set_bit(X86_FEATURE_CONSTANT_TSC, c->x86_capability);

Quoted 4 lines
Quoted 2 lines

x86_capability is a array ...

For an array, the & is optional and has no effect.

good to know.

YH