From patchwork Fri May 7 20:55:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 12245189 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88EE1C433B4 for ; Fri, 7 May 2021 20:57:39 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 177C560FD8 for ; Fri, 7 May 2021 20:57:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 177C560FD8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=bnUWbsXsheKXIJ1DbT2BnjOaeBBsqCtu59CK5pGOoEM=; b=L+qTlaTcr2pvYUbT4Hsut2g/K 5cOhYMQWRh2zqUdpCLDkJO5V0xywLnt7Use1d89fr0vVIwPi1c7vpfHsrLu5E3EaTt3QZ8KylFq8L Iz54aFhWaQby1tNPhbYWAHMfkt9oZZ9+u+VC24XBMGlCZAOd6dqyF0WvIbMCcSPqSnp+fJgmytU0N eNmHEydgWrU4dzS2NrQEhcFLw+GUka+KkzLJziGpqaHW+Nk4NMbSX6ot6kzEnw5oQa9ow+ZG7d+ZJ f9d/IewMjR1M0stL7QCNNYYaT0614vdbzM8w73+H1T5vnmmvhR9/pJIW3ptGOsS9uJUtGg7wmv84D KOx9oz9Ng==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lf7WD-0082gV-3H; Fri, 07 May 2021 20:56:17 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lf7Vg-0082dA-7H for linux-arm-kernel@desiato.infradead.org; Fri, 07 May 2021 20:55:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=fDVsOdAVuMhU9NSPpB3f6fpg/PnSrq0B5y1jEjDIJ0Q=; b=ehpYuru7OCMByrDcTDtPbkUAR4 D/B5FRZ1vB1rGpE57TwfxyPwngQtNCMK/T3DhGjrwmx2caiUtt8SBOC8LkqEfsFBVQJ73L628Ynd5 Nt9iq2BhlPGdF3VPukQ3Amz/NpLvj1S8Igz/uFIanu+LIHloeUxMFpuc264SQS0L6UlSrilX+J41i 7UX8OWYvjLGN/xsTaLDIyolaVqNg8runUv4a148v7wvagSoroXNo7Pk/bI2zRELUZIs0JHGa7HOuF 7VwFF1qyr34llnD4ScVqfoaxI0Y3Wt/BG+xKeIOs6SNIO2MhlId9ouIun1pQJoaanZWqTEiYZH+C1 OeJpel4A==; Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lf7Vd-007BBx-Hh for linux-arm-kernel@lists.infradead.org; Fri, 07 May 2021 20:55:43 +0000 Received: by mail-pj1-x102e.google.com with SMTP id z6-20020a17090a1706b0290155e8a752d8so6153525pjd.4 for ; Fri, 07 May 2021 13:55:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fDVsOdAVuMhU9NSPpB3f6fpg/PnSrq0B5y1jEjDIJ0Q=; b=iD4tT85K8xm9TDTBgGU2oOwO9GUijBqfHLjv3EXuS9Zw0hEezZnEc0WCBIpu18QYz8 SRhrpjVQ0YUviI9ogflFsSK1t6zORia+iIH3J3U41imjKQG4Eo1LvC3k3oBTIF1vy7yz CqNy0k1EtObpp1znQt6FQP7wEKvTnu5ggjqSk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fDVsOdAVuMhU9NSPpB3f6fpg/PnSrq0B5y1jEjDIJ0Q=; b=eBC32wyFEw2SUUMb/OtQK5T8O2NDDnhZrgrTXAtOCOwTm3YOYqKXAURLjM83WNKGv0 S2rcmSqmf+NeJbCyhAK8PVG4PFezcEutA0/MqQnBUvCs4KLw63PSoeeMlrIaEYeE/2zC fAyvcJ1IyizPpt5Rb4eMYD+U2B7FDy/ap/X2PWdQQ0LXgH1h3cdctVLxHawAuPFB0Qb0 BWOSLCnfbIYPSW53KgIMeNAPcaealP3WnXLbduoN6Z9z+wnZQVJvhzX5Ntu0ZI93IckV ju+3BTSiJ7OswmoXMThpXwz9WwVAKQaADJMUmFGUxoWqCYHwC7yrtn0FkPvgv8DCLkUz +PTQ== X-Gm-Message-State: AOAM531gDGjLIrmBszYhLjIz8V7MvApoEXADMkpzHyE3UZMBZB75BFGu Bei1DJI8XGgvhyUyrHJ2EIh5Fg== X-Google-Smtp-Source: ABdhPJwIhmCrqWymkSZsKHAEaKiN1ow1As3pPhFdtCJfJRUezNcgFZBgBc7MgNBLDSOmDyqpmXPmoA== X-Received: by 2002:a17:90b:19c4:: with SMTP id nm4mr2729502pjb.102.1620420940597; Fri, 07 May 2021 13:55:40 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:201:3c7e:d35:3a19:632f]) by smtp.gmail.com with ESMTPSA id ge4sm13161565pjb.49.2021.05.07.13.55.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 13:55:40 -0700 (PDT) From: Douglas Anderson To: Catalin Marinas , Will Deacon Cc: Nick Desaulniers , Seth LaForge , Ricky Liang , Douglas Anderson , Alexander Shishkin , Arnaldo Carvalho de Melo , Ingo Molnar , Jiri Olsa , Mark Rutland , Namhyung Kim , Nathan Chancellor , Peter Zijlstra , clang-built-linux@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: [PATCH 3/3] arm64: perf: Add a config option saying 32-bit thumb code uses R11 for FP Date: Fri, 7 May 2021 13:55:13 -0700 Message-Id: <20210507135509.3.Ib4ca8cf998782d53b9613b12a6aca65605b91c72@changeid> X-Mailer: git-send-email 2.31.1.607.g51e8a6a459-goog In-Reply-To: <20210507205513.640780-1-dianders@chromium.org> References: <20210507205513.640780-1-dianders@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210507_135541_607946_FE06E60C X-CRM114-Status: GOOD ( 24.52 ) 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 The frame pointer story for 32-bit ARM/Thumb code is a bit of a nightmare. See the patch ("arm64: perf: perf_callchain_user() compat support clang/non-APCS-gcc-arm") (including the inline comments) for some details. Apparently, all hope is not lost for some resolution to this story. Recently it's been agreed upon that the frame pointer should be R11 across both ARM and Thumb. This should, at least, allow us to crawl through mixed code. Unfortunately I can't think of any automagic way to figure out if code is using R7 or R11 for the frame pointer. We'll force the person compiling the kernel to choose one or the other. NOTE: apparently as-of right now (2021Q1) there are no compilers out there that actually support this. Thus this patch is untested. However, it's so simple that it feels right to land it now while everyone is thinking about it. I have, at least, confirmed that tracing Thumb code produced with the old compiler _breaks_ when I set this option. ;-) Signed-off-by: Douglas Anderson --- arch/arm64/Kconfig | 12 ++++++++++++ arch/arm64/kernel/perf_callchain.c | 12 ++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 9f1d8566bbf9..f123736ac535 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1062,6 +1062,18 @@ config ARCH_SPARSEMEM_ENABLE select SPARSEMEM_VMEMMAP_ENABLE select SPARSEMEM_VMEMMAP +config PERF_COMPAT_THUMB_FP_R11 + bool "Assume userspace 32-bit Thumb code uses R11 for Frame pointer" + help + Historically R11 was the frame pointer (FP) for 32-bit ARM code + and R7 was the frame pointer for 32-bit Thumb code. This resulted in + the inability to use the FP for stack crawling with mixed code. + The 2019Q4 Issue of AAPCS revised the frame pointer to be R11 for + BOTH ARM and Thumb. If your userspace was built with this new + standard then say "yes" here. + depends on PERF_EVENTS + depends on COMPAT + config HW_PERF_EVENTS def_bool y depends on ARM_PMU diff --git a/arch/arm64/kernel/perf_callchain.c b/arch/arm64/kernel/perf_callchain.c index b3cd9f371469..c8187acdbf3f 100644 --- a/arch/arm64/kernel/perf_callchain.c +++ b/arch/arm64/kernel/perf_callchain.c @@ -311,12 +311,16 @@ static void compat_perf_callchain_user(struct perf_callchain_entry_ctx *entry, /* * Assuming userspace is compiled with frame pointers then it's in - * R11 for ARM code and R7 for thumb code. If it's thumb mode we'll - * also set the low bit of the PC to match how the PC indicates thumb - * mode when crawling down the stack. + * R11 for ARM code and R7 for thumb code (unless you've got a really + * new compiler). If it's thumb mode we'll also set the low bit of + * the PC to match how the PC indicates thumb mode when crawling + * down the stack. */ if (compat_thumb_mode(regs)) { - fp = regs->regs[7]; + if (IS_ENABLED(CONFIG_PERF_COMPAT_THUMB_FP_R11)) + fp = regs->regs[11]; + else + fp = regs->regs[7]; pc |= BIT(0); } else { fp = regs->compat_fp;