powerpc: Fix unpaired probe_hcall_entry and probe_hcall_exit
authorLi Zhong <zhong@linux.vnet.ibm.com>
Sun, 18 Dec 2011 16:03:04 +0000 (16:03 +0000)
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>
Tue, 3 Jan 2012 01:09:27 +0000 (12:09 +1100)
Unpaired calling of probe_hcall_entry and probe_hcall_exit might happen
as following, which could cause incorrect preempt count.

__trace_hcall_entry => trace_hcall_entry -> probe_hcall_entry =>
get_cpu_var => preempt_disable

__trace_hcall_exit => trace_hcall_exit -> probe_hcall_exit =>
put_cpu_var => preempt_enable

where:
A => B and A -> B means A calls B, but
=> means A will call B through function name, and B will definitely be
called.
-> means A will call B through function pointer, so B might not be
called if the function pointer is not set.

So error happens when only one of probe_hcall_entry and probe_hcall_exit
get called during a hcall.

This patch tries to move the preempt count operations from
probe_hcall_entry and probe_hcall_exit to its callers.

Reported-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Li Zhong <zhong@linux.vnet.ibm.com>
Tested-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
CC: stable@kernel.org [v2.6.32+]
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
arch/powerpc/platforms/pseries/hvCall_inst.c
arch/powerpc/platforms/pseries/lpar.c

index f106662f4381e23384082ffe65534e6f7cafaa91..c9311cfdfcaced8b283e53aab5e6e96e152ad39b 100644 (file)
@@ -109,7 +109,7 @@ static void probe_hcall_entry(void *ignored, unsigned long opcode, unsigned long
        if (opcode > MAX_HCALL_OPCODE)
                return;
 
-       h = &get_cpu_var(hcall_stats)[opcode / 4];
+       h = &__get_cpu_var(hcall_stats)[opcode / 4];
        h->tb_start = mftb();
        h->purr_start = mfspr(SPRN_PURR);
 }
@@ -126,8 +126,6 @@ static void probe_hcall_exit(void *ignored, unsigned long opcode, unsigned long
        h->num_calls++;
        h->tb_total += mftb() - h->tb_start;
        h->purr_total += mfspr(SPRN_PURR) - h->purr_start;
-
-       put_cpu_var(hcall_stats);
 }
 
 static int __init hcall_inst_init(void)
index 27a49508b410711beebff40be49524c28ee3bddc..dc36ea6c77275549768d056353447768faf1d9e7 100644 (file)
@@ -554,6 +554,7 @@ void __trace_hcall_entry(unsigned long opcode, unsigned long *args)
                goto out;
 
        (*depth)++;
+       preempt_disable();
        trace_hcall_entry(opcode, args);
        (*depth)--;
 
@@ -576,6 +577,7 @@ void __trace_hcall_exit(long opcode, unsigned long retval,
 
        (*depth)++;
        trace_hcall_exit(opcode, retval, retbuf);
+       preempt_enable();
        (*depth)--;
 
 out: