Re: [RFC PATCH 2/5] powerpc: Exception hooks for context tracking subsystem

2013-02-16 Thread Li Zhong
On Sun, 2013-02-10 at 15:10 +0100, Frederic Weisbecker wrote:
 2013/2/1 Li Zhong zh...@linux.vnet.ibm.com:
  This is the exception hooks for context tracking subsystem, including
  data access, program check, single step, instruction breakpoint, machine 
  check,
  alignment, fp unavailable, altivec assist, unknown exception, whose handlers
  might use RCU.
 
  This patch corresponds to
  [PATCH] x86: Exception hooks for userspace RCU extended QS
commit 6ba3c97a38803883c2eee489505796cb0a727122
 
  Signed-off-by: Li Zhong zh...@linux.vnet.ibm.com
 
 Looks good!
 
 I guess we should move exception_enter/exit definition to the generic
 code. They should be the same for all archs after all. 

Indeed.

 Also we are
 relying on user_mode(regs) but this may be buggy with some corner
 cases. For example if an exception happen after a call to user_exit()

I guess you mean user_enter() here, or am I confused?

 (on syscall exit) but before we actually resume in userspace, the
 exception will exit in kernel mode from the context tracking POV.
 
 So instead on relying on the regs, which are not sync with the context
 tracking state, we should use something like:
 
 prev_state = exception_enter();
 ...
 exception_exit(prev_state);
 
 Also preempt_schedule_irq() is concerned as well by this problem. So I
 should convert it to that scheme as well. I'm going to prepare some
 patches.
 
 Feel free to merge this patch in the powerpc tree, I'll do the
 conversion along the way.

Or if your patches gets merged earlier than these, I can update my code
according to yours.

Thanks, Zhong

 
 Thanks.
 


___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [RFC PATCH 2/5] powerpc: Exception hooks for context tracking subsystem

2013-02-10 Thread Frederic Weisbecker
2013/2/1 Li Zhong zh...@linux.vnet.ibm.com:
 This is the exception hooks for context tracking subsystem, including
 data access, program check, single step, instruction breakpoint, machine 
 check,
 alignment, fp unavailable, altivec assist, unknown exception, whose handlers
 might use RCU.

 This patch corresponds to
 [PATCH] x86: Exception hooks for userspace RCU extended QS
   commit 6ba3c97a38803883c2eee489505796cb0a727122

 Signed-off-by: Li Zhong zh...@linux.vnet.ibm.com

Looks good!

I guess we should move exception_enter/exit definition to the generic
code. They should be the same for all archs after all. Also we are
relying on user_mode(regs) but this may be buggy with some corner
cases. For example if an exception happen after a call to user_exit()
(on syscall exit) but before we actually resume in userspace, the
exception will exit in kernel mode from the context tracking POV.

So instead on relying on the regs, which are not sync with the context
tracking state, we should use something like:

prev_state = exception_enter();
...
exception_exit(prev_state);

Also preempt_schedule_irq() is concerned as well by this problem. So I
should convert it to that scheme as well. I'm going to prepare some
patches.

Feel free to merge this patch in the powerpc tree, I'll do the
conversion along the way.

Thanks.
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[RFC PATCH 2/5] powerpc: Exception hooks for context tracking subsystem

2013-02-01 Thread Li Zhong
This is the exception hooks for context tracking subsystem, including
data access, program check, single step, instruction breakpoint, machine check,
alignment, fp unavailable, altivec assist, unknown exception, whose handlers
might use RCU.

This patch corresponds to
[PATCH] x86: Exception hooks for userspace RCU extended QS
  commit 6ba3c97a38803883c2eee489505796cb0a727122

Signed-off-by: Li Zhong zh...@linux.vnet.ibm.com
---
 arch/powerpc/include/asm/context_tracking.h |   20 +++
 arch/powerpc/kernel/exceptions-64s.S|4 +-
 arch/powerpc/kernel/traps.c |   79 ---
 arch/powerpc/mm/fault.c |   15 -
 arch/powerpc/mm/hash_utils_64.c |   17 ++
 5 files changed, 112 insertions(+), 23 deletions(-)
 create mode 100644 arch/powerpc/include/asm/context_tracking.h

diff --git a/arch/powerpc/include/asm/context_tracking.h 
b/arch/powerpc/include/asm/context_tracking.h
new file mode 100644
index 000..3adccd8
--- /dev/null
+++ b/arch/powerpc/include/asm/context_tracking.h
@@ -0,0 +1,20 @@
+#ifndef _ASM_POWERPC_CONTEXT_TRACKING_H
+#define _ASM_POWERPC_CONTEXT_TRACKING_H
+
+#include linux/context_tracking.h
+#include asm/ptrace.h
+
+static inline void exception_enter(struct pt_regs *regs)
+{
+   user_exit();
+}
+
+static inline void exception_exit(struct pt_regs *regs)
+{
+#ifdef CONFIG_CONTEXT_TRACKING
+   if (user_mode(regs))
+   user_enter();
+#endif
+}
+
+#endif
diff --git a/arch/powerpc/kernel/exceptions-64s.S 
b/arch/powerpc/kernel/exceptions-64s.S
index 4665e82..b877cf2 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -1184,15 +1184,17 @@ END_MMU_FTR_SECTION_IFCLR(MMU_FTR_SLB)
rlwimi  r4,r0,32-13,30,30   /* becomes _PAGE_USER access bit */
ori r4,r4,1 /* add _PAGE_PRESENT */
rlwimi  r4,r5,22+2,31-2,31-2/* Set _PAGE_EXEC if trap is 0x400 */
+   addir6,r1,STACK_FRAME_OVERHEAD
 
/*
 * r3 contains the faulting address
 * r4 contains the required access permissions
 * r5 contains the trap number
+* r6 contains the address of pt_regs
 *
 * at return r3 = 0 for success, 1 for page fault, negative for error
 */
-   bl  .hash_page  /* build HPTE if possible */
+   bl  .hash_page_ct   /* build HPTE if possible */
cmpdi   r3,0/* see if hash_page succeeded */
 
/* Success */
diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
index 3251840..d7c0414 100644
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -59,6 +59,7 @@
 #include asm/fadump.h
 #include asm/switch_to.h
 #include asm/debug.h
+#include asm/context_tracking.h
 
 #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
 int (*__debugger)(struct pt_regs *regs) __read_mostly;
@@ -660,6 +661,8 @@ void machine_check_exception(struct pt_regs *regs)
 {
int recover = 0;
 
+   exception_enter(regs);
+
__get_cpu_var(irq_stat).mce_exceptions++;
 
/* See if any machine dependent calls. In theory, we would want
@@ -674,7 +677,7 @@ void machine_check_exception(struct pt_regs *regs)
recover = cur_cpu_spec-machine_check(regs);
 
if (recover  0)
-   return;
+   goto exit;
 
 #if defined(CONFIG_8xx)  defined(CONFIG_PCI)
/* the qspan pci read routines can cause machine checks -- Cort
@@ -684,20 +687,23 @@ void machine_check_exception(struct pt_regs *regs)
 * -- BenH
 */
bad_page_fault(regs, regs-dar, SIGBUS);
-   return;
+   goto exit;
 #endif
 
if (debugger_fault_handler(regs))
-   return;
+   goto exit;
 
if (check_io_access(regs))
-   return;
+   goto exit;
 
die(Machine check, regs, SIGBUS);
 
/* Must die if the interrupt is not recoverable */
if (!(regs-msr  MSR_RI))
panic(Unrecoverable Machine check);
+
+exit:
+   exception_exit(regs);
 }
 
 void SMIException(struct pt_regs *regs)
@@ -707,20 +713,29 @@ void SMIException(struct pt_regs *regs)
 
 void unknown_exception(struct pt_regs *regs)
 {
+   exception_enter(regs);
+
printk(Bad trap at PC: %lx, SR: %lx, vector=%lx\n,
   regs-nip, regs-msr, regs-trap);
 
_exception(SIGTRAP, regs, 0, 0);
+
+   exception_exit(regs);
 }
 
 void instruction_breakpoint_exception(struct pt_regs *regs)
 {
+   exception_enter(regs);
+
if (notify_die(DIE_IABR_MATCH, iabr_match, regs, 5,
5, SIGTRAP) == NOTIFY_STOP)
-   return;
+   goto exit;
if (debugger_iabr_match(regs))
-   return;
+   goto exit;
_exception(SIGTRAP, regs, TRAP_BRKPT, regs-nip);
+
+exit:
+   exception_exit(regs);
 }