Re: [RFC PATCH 2/2] tracing: Teach FETCH_MTD_symbol to handle per-cpudata

From: Masami Hiramatsu
Date: Wed Nov 27 2013 - 06:30:27 EST


(2013/11/27 2:44), Oleg Nesterov wrote:
> FETCH_FUNC_NAME(symbol) blindly dereferences sc->addr + sc->offset,
> this is not what we want if this symbol is per-cpu. Change this code
> to use this_cpu_ptr(sc->addr) in this case.

This looks good for me :)

Thanks!

> Note: this doesn't work for modules, but module's per-cpu data is
> not visible for kallsyms_lookup_name() anyway.
>
> Signed-off-by: Oleg Nesterov <oleg@xxxxxxxxxx>
> ---
> kernel/trace/trace_probe.c | 22 ++++++++++++++++++----
> 1 files changed, 18 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
> index 097cc80..a0144b6 100644
> --- a/kernel/trace/trace_probe.c
> +++ b/kernel/trace/trace_probe.c
> @@ -252,14 +252,28 @@ static struct symbol_cache *alloc_symbol_cache(const char *sym, long offset)
> return sc;
> }
>
> +static void *sc_calc_addr(struct symbol_cache *sc)
> +{
> + void *addr = (void*)sc->addr;
> +
> + if (addr) {
> + if (addr >= (void *)__per_cpu_start &&
> + addr < (void *)__per_cpu_end)
> + addr = this_cpu_ptr(addr);
> +
> + addr += sc->offset;
> + }
> +
> + return addr;
> +}
> +
> #define DEFINE_FETCH_symbol(type) \
> static __kprobes void FETCH_FUNC_NAME(symbol, type)(struct pt_regs *regs,\
> void *data, void *dest) \
> { \
> - struct symbol_cache *sc = data; \
> - long off = sc->offset; \
> - if (sc->addr) \
> - fetch_memory_##type(regs, (void *)sc->addr + off, dest);\
> + void *addr = sc_calc_addr(data); \
> + if (addr) \
> + fetch_memory_##type(regs, addr, dest); \
> else \
> *(type *)dest = 0; \
> }
>


--
Masami HIRAMATSU
IT Management Research Dept. Linux Technology Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@xxxxxxxxxxx


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/