Skip to content

Commit

Permalink
fgraph: Use BUILD_BUG_ON() to make sure we have structures divisible …
Browse files Browse the repository at this point in the history
…by long

Instead of using "ALIGN()", use BUILD_BUG_ON() as the structures should
always be divisible by sizeof(long).

Co-developed with Masami Hiramatsu:
Link: https://lore.kernel.org/linux-trace-kernel/171509093949.162236.14518699447151894536.stgit@devnote2
Link: http://lkml.kernel.org/r/[email protected]
Link: https://lore.kernel.org/linux-trace-kernel/[email protected]

Cc: Mark Rutland <[email protected]>
Cc: Mathieu Desnoyers <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Alexei Starovoitov <[email protected]>
Cc: Florent Revest <[email protected]>
Cc: Martin KaFai Lau <[email protected]>
Cc: bpf <[email protected]>
Cc: Sven Schnelle <[email protected]>
Cc: Alexei Starovoitov <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Daniel Borkmann <[email protected]>
Cc: Alan Maguire <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Guo Ren <[email protected]>
Reviewed-by: Masami Hiramatsu (Google) <[email protected]>
Suggested-by: Peter Zijlstra <[email protected]>
Signed-off-by: Steven Rostedt (VMware) <[email protected]>
Signed-off-by: Masami Hiramatsu (Google) <[email protected]>
Signed-off-by: Steven Rostedt (Google) <[email protected]>
  • Loading branch information
rostedt committed Jun 4, 2024
1 parent 42675b7 commit 59e5f04
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion kernel/trace/fgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* SHADOW_STACK_MAX_OFFSET: The max offset of the stack for a new frame to be added
*/
#define FGRAPH_FRAME_SIZE sizeof(struct ftrace_ret_stack)
#define FGRAPH_FRAME_OFFSET (ALIGN(FGRAPH_FRAME_SIZE, sizeof(long)) / sizeof(long))
#define FGRAPH_FRAME_OFFSET DIV_ROUND_UP(FGRAPH_FRAME_SIZE, sizeof(long))
#define SHADOW_STACK_SIZE (PAGE_SIZE)
#define SHADOW_STACK_OFFSET \
(ALIGN(SHADOW_STACK_SIZE, sizeof(long)) / sizeof(long))
Expand Down Expand Up @@ -103,6 +103,8 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func,
if (!current->ret_stack)
return -EBUSY;

BUILD_BUG_ON(SHADOW_STACK_SIZE % sizeof(long));

/*
* We must make sure the ret_stack is tested before we read
* anything else.
Expand Down Expand Up @@ -326,6 +328,8 @@ ftrace_graph_get_ret_stack(struct task_struct *task, int idx)
{
int index = task->curr_ret_stack;

BUILD_BUG_ON(FGRAPH_FRAME_SIZE % sizeof(long));

index -= FGRAPH_FRAME_OFFSET * (idx + 1);
if (index < 0)
return NULL;
Expand Down

0 comments on commit 59e5f04

Please sign in to comment.