Skip to contentSkip to conversation

modules fix incorrect percpu usage

PATCH In review Mathieu Desnoyers 4 participants 6 messages Mar 30, 2010 – Mar 31, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 modules fix incorrect percpu usage

Should use per_cpu_ptr() to obfuscate the per cpu pointers (RELOC_HIDE is needed for per cpu pointers).

Introduced by commit:

module.c: commit 6b588c18f8dacfa6d7957c33c5ff832096e752d3

It applies to mainline as of 2.6.34-rc2. This patch should be queued for the stable branch, for kernels 2.6.29.x to 2.6.33.x.
(based on 2.6.33.1, also applies to 2.6.34-rc2 -tip)

CC Randy Dunlap <[email protected]>
CC Eric Dumazet <[email protected]>
CC Rusty Russell <[email protected]>
CC Peter Zijlstra <[email protected]>
CC Tejun Heo <[email protected]>
CC Ingo Molnar <[email protected]>
CC Andrew Morton <[email protected]>
CC Linus Torvalds <[email protected]>
CC Greg Kroah-Hartman <[email protected]>
CC Steven Rostedt <[email protected]>
CC stable <[email protected]>
---
 kernel/module.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/module.c +1 -1
Index: linux-2.6-lttng/kernel/module.c
===================================================================
@@ -412,7 +412,7 @@ static void percpu_modcopy(void *pcpudes
 	int cpu;
 
 	for_each_possible_cpu(cpu)
-		memcpy(pcpudest + per_cpu_offset(cpu), from, size);
+		memcpy(per_cpu_ptr(pcpudest, cpu), from, size);
 }
 
 #else /* ... !CONFIG_SMP */
Signature · 4 lines
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
#1 lore raw
Quoted 10 lines · On Tue, 30 Mar 2010 09:52:08 -0400 Mathieu Desnoyers…

Should use per_cpu_ptr() to obfuscate the per cpu pointers (RELOC_HIDE is needed for per cpu pointers).

Introduced by commit:

module.c: commit 6b588c18f8dacfa6d7957c33c5ff832096e752d3

It applies to mainline as of 2.6.34-rc2. This patch should be queued for the stable branch, for kernels 2.6.29.x to 2.6.33.x.
(based on 2.6.33.1, also applies to 2.6.34-rc2 -tip)

Why do you beleive this should be backported to -stable? What are the user-visible effects of this change?

#2 lore raw
Quoted 8 lines · * Andrew Morton ([email protected]) wrote:
Quoted 5 lines · On Tue, 30 Mar 2010 09:52:08 -0400 Mathieu Desnoyers…

Should use per_cpu_ptr() to obfuscate the per cpu pointers (RELOC_HIDE is needed for per cpu pointers).

Introduced by commit:

Quoted 9 lines
Quoted 5 lines

module.c: commit 6b588c18f8dacfa6d7957c33c5ff832096e752d3

It applies to mainline as of 2.6.34-rc2. This patch should be queued for the stable branch, for kernels 2.6.29.x to 2.6.33.x.
(based on 2.6.33.1, also applies to 2.6.34-rc2 -tip)

Why do you beleive this should be backported to -stable? What are the user-visible effects of this change?

As for the user-visible impact of this specific patch, I guess nobody noticed any problem because we've been lucky enough that the compiler did not generate the inappropriate optimization pattern there.

This inappropriate use of per_cpu_ptr() elsewhere (in __module_ref_addr() from module.h) caused a NULL pointer exception on Randy's machine.

So either we consider that the code is better left untouched, or we apply this patch to module.c in order to prevent compiler optimizations from subtly breaking the generated assembly with specific configurations of the current or future versions of the compiler. At that level, it becomes a policy question about what should go in -stable, for which I will defer to Greg and you. I would perfectly understand if you consider that it does not belong to -stable, because there is no perceived user impact so far.

Thanks,

Mathieu

Signature · 4 lines
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
#3 lore raw
Quoted 11 lines · Mathieu Desnoyers
Quoted 3 lines

Why do you beleive this should be backported to -stable? What are the user-visible effects of this change?

As for the user-visible impact of this specific patch, I guess nobody noticed any problem because we've been lucky enough that the compiler did not generate the inappropriate optimization pattern there.

This inappropriate use of per_cpu_ptr() elsewhere (in __module_ref_addr() from module.h) caused a NULL pointer exception on Randy's machine.

Quoted 7 lines

So either we consider that the code is better left untouched, or we apply this patch to module.c in order to prevent compiler optimizations from subtly breaking the generated assembly with specific configurations of the current or future versions of the compiler. At that level, it becomes a policy question about what should go in -stable, for which I will defer to Greg and you. I would perfectly understand if you consider that it does not belong to -stable, because there is no perceived user impact so far.

I don't know. A possible "NULL pointer dereference" seems to me to be a pretty big user visible impact.

I guess the question is, what's the risk of adding this change?

-- Steve

#4 lore raw
Quoted 4 lines · Steven Rostedt

I don't know. A possible "NULL pointer dereference" seems to me to be a pretty big user visible impact.

I guess the question is, what's the risk of adding this change?

AFAICS, the risk is fairly low. per_cpu_ptr(pcpudest, cpu) is SHIFT_PERCPU_PTR((ptr), per_cpu_offset((cpu))) which is just a fancy way of saying "typeof(ptr)((unsigned long)(ptr) + per_cpu_offset(cpu))" with enough obfuscation to prevent gcc from optimizing it incorrectly.

Thanks.

Signature · 1 line
tejun
Acked-by on v1 1/1
#5 lore raw
In reply to Mathieu Desnoyers
Quoted 11 lines · Mathieu Desnoyers

Should use per_cpu_ptr() to obfuscate the per cpu pointers (RELOC_HIDE is needed for per cpu pointers).

Introduced by commit:

module.c: commit 6b588c18f8dacfa6d7957c33c5ff832096e752d3

It applies to mainline as of 2.6.34-rc2. This patch should be queued for the stable branch, for kernels 2.6.29.x to 2.6.33.x.
(based on 2.6.33.1, also applies to 2.6.34-rc2 -tip)

Quoted 12 lines
CC Randy Dunlap <[email protected]>
CC Eric Dumazet <[email protected]>
CC Rusty Russell <[email protected]>
CC Peter Zijlstra <[email protected]>
CC Tejun Heo <[email protected]>
CC Ingo Molnar <[email protected]>
CC Andrew Morton <[email protected]>
CC Linus Torvalds <[email protected]>
CC Greg Kroah-Hartman <[email protected]>
CC Steven Rostedt <[email protected]>
CC stable <[email protected]>

Thanks.

Signature · 1 line
tejun