Skip to content

Commit 4f242fc

Browse files
npigginmpe
authored andcommitted
powerpc/pseries: warn if recursing into the hcall tracing code
The hcall tracing code has a recursion check built in, which skips tracing if we are already tracing an hcall. However if the tracing code has problems with recursion, this check may not catch all cases because the tracing code could be invoked from a different tracepoint first, then make an hcall that gets traced, then recurse. Add an explicit warning if recursion is detected here, which might help to notice tracing code making hcalls. Really the core trace code should have its own recursion checking and warnings though. Signed-off-by: Nicholas Piggin <npiggin@gmail.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20210508101455.1578318-5-npiggin@gmail.com
1 parent 7058f4b commit 4f242fc

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

  • arch/powerpc/platforms/pseries

arch/powerpc/platforms/pseries/lpar.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,8 +1829,14 @@ void hcall_tracepoint_unregfunc(void)
18291829
#endif
18301830

18311831
/*
1832-
* Since the tracing code might execute hcalls we need to guard against
1833-
* recursion.
1832+
* Keep track of hcall tracing depth and prevent recursion. Warn if any is
1833+
* detected because it may indicate a problem. This will not catch all
1834+
* problems with tracing code making hcalls, because the tracing might have
1835+
* been invoked from a non-hcall, so the first hcall could recurse into it
1836+
* without warning here, but this better than nothing.
1837+
*
1838+
* Hcalls with specific problems being traced should use the _notrace
1839+
* plpar_hcall variants.
18341840
*/
18351841
static DEFINE_PER_CPU(unsigned int, hcall_trace_depth);
18361842

@@ -1844,7 +1850,7 @@ notrace void __trace_hcall_entry(unsigned long opcode, unsigned long *args)
18441850

18451851
depth = this_cpu_ptr(&hcall_trace_depth);
18461852

1847-
if (*depth)
1853+
if (WARN_ON_ONCE(*depth))
18481854
goto out;
18491855

18501856
(*depth)++;
@@ -1865,7 +1871,7 @@ notrace void __trace_hcall_exit(long opcode, long retval, unsigned long *retbuf)
18651871

18661872
depth = this_cpu_ptr(&hcall_trace_depth);
18671873

1868-
if (*depth)
1874+
if (*depth) /* Don't warn again on the way out */
18691875
goto out;
18701876

18711877
(*depth)++;

0 commit comments

Comments
 (0)