mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-07-23 05:07:37 -04:00
Since the leafloop test program was moved into the main Perf binary as a workload, it inherited the same compiler options as Perf. In this case the -fstack-protector option broke the assumption that simple leaf frames don't have a stack frame on Arm. This causes test_arm_callgraph_fp.sh to pass even if the stack isn't augmented with the link register, making the test useless. Fix it by rewriting the leaf function in assembly seeing as it's so simple. Adding -fno-stack-protector would also work, but wouldn't be robust against other future compiler option additions. The local variables and 'a' variable were never needed so remove them to simplify. Reviewed-by: Ian Rogers <irogers@google.com> Assisted-by: GitHub-Copilot:GPT-5.5 Signed-off-by: James Clark <james.clark@linaro.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
69 lines
1.2 KiB
C
69 lines
1.2 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#include <signal.h>
|
|
#include <stdlib.h>
|
|
#include <linux/compiler.h>
|
|
#include <unistd.h>
|
|
#include "../tests.h"
|
|
|
|
/* We want to check these symbols in perf script */
|
|
noinline void leaf(void);
|
|
noinline void parent(void);
|
|
|
|
static volatile sig_atomic_t done asm("leafloop_done");
|
|
|
|
static void sighandler(int sig __maybe_unused)
|
|
{
|
|
done = 1;
|
|
}
|
|
|
|
#if defined(__aarch64__)
|
|
/*
|
|
* Write leaf() in assembly so it stays as a minimal leaf function with no
|
|
* stack frame and won't get silently broken in the future by any Perf wide
|
|
* compilation options like -fstack-protector-all.
|
|
*/
|
|
asm(
|
|
".pushsection .text,\"ax\",%progbits\n"
|
|
".global leaf\n"
|
|
".type leaf, %function\n"
|
|
"leaf:\n"
|
|
" adrp x1, leafloop_done\n"
|
|
" ldr w2, [x1, #:lo12:leafloop_done]\n"
|
|
" cbz w2, leaf\n"
|
|
" ret\n"
|
|
".size leaf, .-leaf\n"
|
|
".popsection\n"
|
|
);
|
|
|
|
#else
|
|
|
|
noinline void leaf(void)
|
|
{
|
|
while (!done)
|
|
;
|
|
}
|
|
|
|
#endif
|
|
|
|
noinline void parent(void)
|
|
{
|
|
leaf();
|
|
}
|
|
|
|
static int leafloop(int argc, const char **argv)
|
|
{
|
|
int sec = 1;
|
|
|
|
if (argc > 0)
|
|
sec = atoi(argv[0]);
|
|
|
|
signal(SIGINT, sighandler);
|
|
signal(SIGALRM, sighandler);
|
|
alarm(sec);
|
|
|
|
parent();
|
|
return 0;
|
|
}
|
|
|
|
DEFINE_WORKLOAD(leafloop);
|