Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3781383pxb; Mon, 4 Oct 2021 09:27:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyel6TdnV84B9VsPPvOIrZHJh3gFmA9vU0+H14wQmSqbrS6AShSDupdXcIbAXbYU1poTumj X-Received: by 2002:a50:ccc4:: with SMTP id b4mr19484628edj.83.1633364852608; Mon, 04 Oct 2021 09:27:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633364852; cv=none; d=google.com; s=arc-20160816; b=Nr1k52YSNIV51uMU9C7jDsF7ozYyIG+1Wm+n/hv6iJT2+5jLHl5WeypTVY4mmB6UXu nsesPq8ijy3eGSSks91rqmTaVolJiMuuLodS4qshSrcCj7sENkwhgZYpRU5smp1SBAoH xjdBmhWVyAdPQV1XGyIE11qc6auaxY3w22o9tURVBK6I0jEVuGMNqXKaG8YfSzbIHwzv O90Vx9oee5h+aWBDDwyPeJy2PMJk1H6eIW1WondzwT3ExX8cw34ptB4haFjmuxoW1dH5 8/W6+xrpXlAxMhu/HteioAVUq9qt6M/gWOSdnsjqOn5W8OlBSV2xZNsWP8sbhyn6gF3W mVPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fY3w5phr1V0yxDGU9CovEVo9eOSg1UHdNi/V0+EHzwM=; b=JgVUHacAlFsywQ8V0yuSZ50KtANdUQeWvHfAlAg5xZh3tHO3qE/VP+dCqmLiNzkX4x QIPXjXYEwl+0jUXl15fW9cxFb416k/8QuooTbmufuiWwMNctaoQ9TUFzopseooTdI+CE jqxRGmUHGr+wqxiiUNIcuIJmRLE4rHHnP59Mic4dbgwEzCr1DfXPRnvvpfk8kZtKI6Ua NsPAKpBYYvIY4MI3c/+kR4M7cyNNbwjaxEiPeUMmqULAk3dEqWgfZ304orEDx099HUkt FhvRmc+mQXtqawToNpuTE5Xb/PsiCCbv3jV52GPgzxWXUfH9tH5pBej3Kq9E/vQ+4CPY HclA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GLmUC2GW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e1si19439898ejm.383.2021.10.04.09.26.58; Mon, 04 Oct 2021 09:27:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GLmUC2GW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237555AbhJDNee (ORCPT + 99 others); Mon, 4 Oct 2021 09:34:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:43756 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237639AbhJDNc3 (ORCPT ); Mon, 4 Oct 2021 09:32:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B7F6D61BA0; Mon, 4 Oct 2021 13:14:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633353279; bh=ap0g6NF3rpaBSS/SVuRhMs15u8lIqxKDNNUs00IC4uo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GLmUC2GWMsLyT5F+dzGWY11ryIWi/X8ww4RJhAGdXuBU6vMVkTT2ymVigOHZVThaA Cq2vGn1zy1Qc9nV0H5iJ1lxC0bAuyN7nKTtoEI98VWv4NzslKqWpGPHj7gdIeZXPdj R4QzM6cMXd0hEtqb+ROBmAE4lhMvYBuClec/5qN8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ian Rogers , Jiri Olsa , Alexander Shishkin , Ard Biesheuvel , Mark Rutland , Miguel Ojeda , Namhyung Kim , Peter Zijlstra , Stephane Eranian , clang-built-linux@googlegroups.com, Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.14 023/172] perf test: Fix DWARF unwind for optimized builds. Date: Mon, 4 Oct 2021 14:51:13 +0200 Message-Id: <20211004125045.713703969@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125044.945314266@linuxfoundation.org> References: <20211004125044.945314266@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ian Rogers [ Upstream commit 5c34aea341b16e29fde6e6c8d4b18866cd99754d ] To ensure the stack frames are on the stack tail calls optimizations need to be inhibited. If your compiler supports an attribute use it, otherwise use an asm volatile barrier. The barrier fix was suggested here: https://lore.kernel.org/lkml/20201028081123.GT2628@hirez.programming.kicks-ass.net/ Tested with an optimized clang build and by forcing the asm barrier route with an optimized clang build. A GCC bug tracking a proper disable_tail_calls is: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97831 Fixes: 9ae1e990f1ab ("perf tools: Remove broken __no_tail_call attribute") v2. is a rebase. The original fix patch generated quite a lot of discussion over the right place for the fix: https://lore.kernel.org/lkml/20201114000803.909530-1-irogers@google.com/ The patch reflects my preference of it being near the use, so that future code cleanups don't break this somewhat special usage. Signed-off-by: Ian Rogers Acked-by: Jiri Olsa Cc: Alexander Shishkin Cc: Ard Biesheuvel Cc: Mark Rutland Cc: Miguel Ojeda Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Cc: clang-built-linux@googlegroups.com Link: http://lore.kernel.org/lkml/20210922173812.456348-1-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/tests/dwarf-unwind.c | 39 +++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/tools/perf/tests/dwarf-unwind.c b/tools/perf/tests/dwarf-unwind.c index a288035eb362..c756284b3b13 100644 --- a/tools/perf/tests/dwarf-unwind.c +++ b/tools/perf/tests/dwarf-unwind.c @@ -20,6 +20,23 @@ /* For bsearch. We try to unwind functions in shared object. */ #include +/* + * The test will assert frames are on the stack but tail call optimizations lose + * the frame of the caller. Clang can disable this optimization on a called + * function but GCC currently (11/2020) lacks this attribute. The barrier is + * used to inhibit tail calls in these cases. + */ +#ifdef __has_attribute +#if __has_attribute(disable_tail_calls) +#define NO_TAIL_CALL_ATTRIBUTE __attribute__((disable_tail_calls)) +#define NO_TAIL_CALL_BARRIER +#endif +#endif +#ifndef NO_TAIL_CALL_ATTRIBUTE +#define NO_TAIL_CALL_ATTRIBUTE +#define NO_TAIL_CALL_BARRIER __asm__ __volatile__("" : : : "memory"); +#endif + static int mmap_handler(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, @@ -91,7 +108,7 @@ static int unwind_entry(struct unwind_entry *entry, void *arg) return strcmp((const char *) symbol, funcs[idx]); } -noinline int test_dwarf_unwind__thread(struct thread *thread) +NO_TAIL_CALL_ATTRIBUTE noinline int test_dwarf_unwind__thread(struct thread *thread) { struct perf_sample sample; unsigned long cnt = 0; @@ -122,7 +139,7 @@ noinline int test_dwarf_unwind__thread(struct thread *thread) static int global_unwind_retval = -INT_MAX; -noinline int test_dwarf_unwind__compare(void *p1, void *p2) +NO_TAIL_CALL_ATTRIBUTE noinline int test_dwarf_unwind__compare(void *p1, void *p2) { /* Any possible value should be 'thread' */ struct thread *thread = *(struct thread **)p1; @@ -141,7 +158,7 @@ noinline int test_dwarf_unwind__compare(void *p1, void *p2) return p1 - p2; } -noinline int test_dwarf_unwind__krava_3(struct thread *thread) +NO_TAIL_CALL_ATTRIBUTE noinline int test_dwarf_unwind__krava_3(struct thread *thread) { struct thread *array[2] = {thread, thread}; void *fp = &bsearch; @@ -160,14 +177,22 @@ noinline int test_dwarf_unwind__krava_3(struct thread *thread) return global_unwind_retval; } -noinline int test_dwarf_unwind__krava_2(struct thread *thread) +NO_TAIL_CALL_ATTRIBUTE noinline int test_dwarf_unwind__krava_2(struct thread *thread) { - return test_dwarf_unwind__krava_3(thread); + int ret; + + ret = test_dwarf_unwind__krava_3(thread); + NO_TAIL_CALL_BARRIER; + return ret; } -noinline int test_dwarf_unwind__krava_1(struct thread *thread) +NO_TAIL_CALL_ATTRIBUTE noinline int test_dwarf_unwind__krava_1(struct thread *thread) { - return test_dwarf_unwind__krava_2(thread); + int ret; + + ret = test_dwarf_unwind__krava_2(thread); + NO_TAIL_CALL_BARRIER; + return ret; } int test__dwarf_unwind(struct test *test __maybe_unused, int subtest __maybe_unused) -- 2.33.0