[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240214135958.23ed55e1@gandalf.local.home>
Date: Wed, 14 Feb 2024 13:59:58 -0500
From: Steven Rostedt <rostedt@...dmis.org>
To: "Masami Hiramatsu (Google)" <mhiramat@...nel.org>
Cc: Alexei Starovoitov <alexei.starovoitov@...il.com>, Florent Revest
<revest@...omium.org>, linux-trace-kernel@...r.kernel.org, LKML
<linux-kernel@...r.kernel.org>, Martin KaFai Lau <martin.lau@...ux.dev>,
bpf <bpf@...r.kernel.org>, Sven Schnelle <svens@...ux.ibm.com>, Alexei
Starovoitov <ast@...nel.org>, Jiri Olsa <jolsa@...nel.org>, Arnaldo
Carvalho de Melo <acme@...nel.org>, Daniel Borkmann <daniel@...earbox.net>,
Alan Maguire <alan.maguire@...cle.com>, Mark Rutland
<mark.rutland@....com>, Peter Zijlstra <peterz@...radead.org>, Thomas
Gleixner <tglx@...utronix.de>, Guo Ren <guoren@...nel.org>
Subject: Re: [PATCH v7 19/36] function_graph: Implement
fgraph_reserve_data() and fgraph_retrieve_data()
On Wed, 7 Feb 2024 00:11:01 +0900
"Masami Hiramatsu (Google)" <mhiramat@...nel.org> wrote:
> From: Ste
> +/**
> + * fgraph_reserve_data - Reserve storage on the task's ret_stack
> + * @idx: The index of fgraph_array
> + * @size_bytes: The size in bytes to reserve
> + *
> + * Reserves space of up to FGRAPH_MAX_DATA_SIZE bytes on the
> + * task's ret_stack shadow stack, for a given fgraph_ops during
> + * the entryfunc() call. If entryfunc() returns zero, the storage
> + * is discarded. An entryfunc() can only call this once per iteration.
> + * The fgraph_ops retfunc() can retrieve this stored data with
> + * fgraph_retrieve_data().
> + *
> + * Returns: On success, a pointer to the data on the stack.
> + * Otherwise, NULL if there's not enough space left on the
> + * ret_stack for the data, or if fgraph_reserve_data() was called
> + * more than once for a single entryfunc() call.
> + */
> +void *fgraph_reserve_data(int idx, int size_bytes)
> +{
> + unsigned long val;
> + void *data;
> + int curr_ret_stack = current->curr_ret_stack;
> + int data_size;
> +
> + if (size_bytes > FGRAPH_MAX_DATA_SIZE)
> + return NULL;
> +
> + /* Convert to number of longs + data word */
> + data_size = DIV_ROUND_UP(size_bytes, sizeof(long));
Hmm, the above is a fast path. I wonder if we should add a patch to make that into:
if (unlikely(size_bytes & (sizeof(long) - 1)))
data_size = DIV_ROUND_UP(size_bytes, sizeof(long));
else
data_size = size_bytes >> (sizeof(long) == 4 ? 2 : 3);
to keep from doing the division.
-- Steve
> +
> + val = get_fgraph_entry(current, curr_ret_stack - 1);
> + data = ¤t->ret_stack[curr_ret_stack];
> +
> + curr_ret_stack += data_size + 1;
> + if (unlikely(curr_ret_stack >= SHADOW_STACK_MAX_INDEX))
> + return NULL;
> +
> + val = make_fgraph_data(idx, data_size, __get_index(val) + data_size + 1);
> +
> + /* Set the last word to be reserved */
> + current->ret_stack[curr_ret_stack - 1] = val;
> +
> + /* Make sure interrupts see this */
> + barrier();
> + current->curr_ret_stack = curr_ret_stack;
> + /* Again sync with interrupts, and reset reserve */
> + current->ret_stack[curr_ret_stack - 1] = val;
> +
> + return data;
> +}
> +
Powered by blists - more mailing lists