From patchwork Sat Sep 21 15:14:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Katson X-Patchwork-Id: 13808932 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 99FCFCF9C5B for ; Sat, 21 Sep 2024 15:16:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:To:Subject: Message-ID:Date:From:MIME-Version:Reply-To:Cc:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=y4toA0DTsLAnroyJrX9jpEqq0PwuZKFR5rqa5B5fSfQ=; b=EUFqdhNWjfFG5NuqSErh03RJV5 P8fbiycKu2e0koQwDbscuU/LXMLw27O5LFtXm39x+8jadNTQMhz0G+WkAMPtLc9cSE7QwHrFZCWpb bXoSKlAJI9bd2/VK59SPLoroHM8nKduLAfVc4mUWByBCzf7CKILHbMwRYpVsfsKbWmwXdjXDbspz2 mOorVGwJ93fzr2KD3p4mtzTfm5qd79Zfm8CgUj3MsH41R3CUb7Q8OjYvMaa4o2EKZFjaofqe0Msbd 3/glOOnNzHABEv8T2CfqVludO4QOJw9+IAylmKXgKNBJjnpZPts1nEybvDNycBOJJ9ir+Jlmyh7ho wAGSCR+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1ss1qP-0000000Dpg1-2XK3; Sat, 21 Sep 2024 15:16:21 +0000 Received: from mail-yw1-x112e.google.com ([2607:f8b0:4864:20::112e]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1ss1pA-0000000Dpac-0p9r for linux-arm-kernel@lists.infradead.org; Sat, 21 Sep 2024 15:15:05 +0000 Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-6c49c9018ebso28031487b3.3 for ; Sat, 21 Sep 2024 08:15:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726931702; x=1727536502; darn=lists.infradead.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=y4toA0DTsLAnroyJrX9jpEqq0PwuZKFR5rqa5B5fSfQ=; b=ZZBqtXDo2O0uNf1nTiELCTxslr65J8dUO/2MvxEl84ipLxUfDp4dt4/OrJBbCVromP jPF3EYYlLDSZ5vzAwFS4mWCma4JiDxlB7VVpUWrnR4cfhPlXJfaSZPBe3/lkOxB9yZjF DZzZE5kGszTkewBNrOruTzCNKbEDvai7xBRrBe45JJv30vFrrIrQMimlDTcvpO7rXLeG BWu4rnjSOQ1wU7a5ZGxbvPVqu6bYVXWWC2IRCVeAnA0bvV61O4Oevpf1LKYz62VgCLJD 0dlzFQxPyjXGmjxvFsjE3HBOMzIk6ZlXweFmy+SaouzpbBoHfZr9Z+jLw7/HXfvEZj2j Ubcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726931702; x=1727536502; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=y4toA0DTsLAnroyJrX9jpEqq0PwuZKFR5rqa5B5fSfQ=; b=qKO5JGJ07VgYUV/4d5v4I1NO5KYYR08n6G+ZEetydLkNuqa6MTtAsoczD2gVhkF9la xnFQXr1YjMRifulLv1kMF9rFrxPU2Nc10htBo+FQ975IYYPezueo98FwJ8GblWWHo9Sx 3gSR6VFq3q+b/bYZjlo5cueaGl9a+Xe1RS2BdFfczwKpPtYO5AJoOHY/NicFLZHFY+Ed Jz+lVlruQtROgPDYHmz0k7u1/H7Rc52wMP+oOGJAIusiWR6sehjYxGisxpvp3Z62c9rC ihRACvsE3fV25eJu8rNBPUWK+LekEGQJe/leXxi2Q7bM27tygaFV4i7+6Fj+jJR9Q6k9 Py/Q== X-Gm-Message-State: AOJu0YzJTzCPP5ywTqzh6Uy8oNrbEdUyWCH8ASsUQfX41DmGqgJikY70 5phTgkO1GW98gMPMI9o3kV0+4VW1aVNLVM5QY5oLINvCtcC6umQTGfmlFYWmwq+4BH++g/o2/VF hUsmJMG8OIFzl83PRR0Az8vNKH2vONonbiFM= X-Google-Smtp-Source: AGHT+IE8JYcu/rRn9sXS0h2X+7mHQmEbOVYGIvDdeAqogyqrrK5SubYZj031ZlQoqcEPGkOOk0wmx2qVgYgypGk3iNc= X-Received: by 2002:a05:690c:7084:b0:6ac:8cfc:1cbc with SMTP id 00721157ae682-6dff2b39a82mr41137647b3.45.1726931702310; Sat, 21 Sep 2024 08:15:02 -0700 (PDT) MIME-Version: 1.0 From: Igor Katson Date: Sat, 21 Sep 2024 16:14:51 +0100 Message-ID: Subject: [QUESTION] arm/perf_callchain.c user stack frame traversal broken on gcc and clang To: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240921_081504_262741_577AFFB2 X-CRM114-Status: GOOD ( 12.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi, I was debugging why on my ARMv7 router "perf record --call-graph=fp" didn't produce valid backtraces. --call-graph=dwarf had other issues that I couldn't resolve yet, so I was trying to make --call-graph=fp work. Turned out arch/arm/kernel/perf_callchain.c expects APCS stack frame layout, which neither modern GCC or clang output with "-fno-omit-frame-pointer". GCC has an option "-mapcs-frame" which is deprecated. It seems using this option is the only way of producing a frame layout that will work with the mainline kernel. Here's a tiny patch that made it work on my system. The question is: does it make sense to try to merge this as an actual patch (I've never done this before)? There must be a reason it hasn't been fixed yet. I don't know how bad of a hack this is, so hence asking here and not submitting as a patch but as a question instead. if (tail + 1 >= buftail.fp) return NULL; - return buftail.fp - 1; + return buftail.fp; } void @@ -75,7 +75,7 @@ perf_callchain_user(struct perf_callchai if (!current->mm) return; - tail = (struct frame_tail __user *)regs->ARM_fp - 1; + tail = (struct frame_tail __user *)regs->ARM_fp; while ((entry->nr < entry->max_stack) && tail && !((unsigned long)tail & 0x3)) --- a/arch/arm/kernel/perf_callchain.c +++ b/arch/arm/kernel/perf_callchain.c @@ -22,7 +22,7 @@ */ struct frame_tail { struct frame_tail __user *fp; - unsigned long sp; unsigned long lr; } __attribute__((packed)); @@ -56,7 +56,7 @@ user_backtrace(struct frame_tail __user