From patchwork Wed Feb 1 16:34:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florent Revest X-Patchwork-Id: 13124726 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 78697C05027 for ; Wed, 1 Feb 2023 16:36:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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:In-Reply-To:References: List-Owner; bh=SixJOiaxDzN29H4wevT0l/XtbdcHCZK7fkg1xO+YwoI=; b=0YBKtRJUHzUxck haSgpeyndkjQd7OFlJ7Ekdstfzao7vfn50jcsFubaR8wHn9vuzpKj2NFTVtQkaXOhjpzlPaUQ/gBc tlcXQW3vSMLAE5iF559Ss6V0L5/8qt9Ljy/dNZplNqF+HXQ3UckSGg0Id/Mjl3PtND2rZvY/ESZu0 T9FRcDxEGn0kbeouhwaZ+Zz2cLD9QTwjj0LP1eC1r74nIpRdO5rKiYPLhcEifOAAx38nyHBY664A3 nI3GUe6AXAl/K3G12awLL5/hsYpfvl7lf27ArRLc/XgsuP7Xy8J7GsVrnR0fLd9xvK1S5JobkbabH CBJ2Xggv4p38KsNssBCw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNG54-00CoSE-Qb; Wed, 01 Feb 2023 16:35:30 +0000 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNG51-00CoOE-DV for linux-arm-kernel@lists.infradead.org; Wed, 01 Feb 2023 16:35:29 +0000 Received: by mail-wm1-x332.google.com with SMTP id m5-20020a05600c4f4500b003db03b2559eso1923582wmq.5 for ; Wed, 01 Feb 2023 08:35:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ogquxG5XLdGczboibIaLv1v+sI1rVWj8OVZyg325S98=; b=OqDLJPqNgNTjv+tJkw0JVlEEnytMVwnS/r+9V/2FKWOtmXea2c1oNHkbLhHfsaoPb6 ABgxtqiJR2l1iWo/91F2ArCyfyfFlfeXEwvW1djmxV3bWjU1UFqd2xWtLD+JHZVZKkyB OqVr5X6HRQ+fiPdrTztgkFSF+oMEz0W9GIOS0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ogquxG5XLdGczboibIaLv1v+sI1rVWj8OVZyg325S98=; b=aGVa7AsIjmvdpgyj/A25WmD2SkIrkEpEWAA09e/tKqr/h1+dZXIYFOjFJtBDFnNech xI44s+Iot84F72fq6MqM6l5I5hReg2MpFOjqgnFIVre99/lvZpc+apsHL8UqspWSx/rU JhOtlejcfNq/7i43PR2fwd4UjT49/5Hy3xXI7ixNynr88NuRrUNjICn49qkEPiRInmmY XZQ28kwHOcafGP56KcCXR0Kh1O53jig67whrNwz0dxfJ4Vn6R8Yzf26dQvLDcT/msiCF DspXkLbDnpNBTx0fvQzvBUWd3JlfVLlIvjBUPn+ecaV0o50j3OpC2UHWyTFHwM7cvNmt Yudg== X-Gm-Message-State: AO0yUKVo6g0MZ8BvU1gaRRgUVvihKkUKZYF2928wNc7/5ZM4sIdUhQRV 9KOQElKJ91GqMGijjfEMsLDCXkdin3UnRUEL1SA= X-Google-Smtp-Source: AK7set8qjoGgTsYwyJ3LRLtxhldsGEurrzyEfjQAtmQT56+MJE4pgQklXhOB5XitFcad606GvpR/fQ== X-Received: by 2002:a05:600c:6018:b0:3dc:1ad6:55fd with SMTP id az24-20020a05600c601800b003dc1ad655fdmr2743120wmb.32.1675269322418; Wed, 01 Feb 2023 08:35:22 -0800 (PST) Received: from revest.zrh.corp.google.com ([2a00:79e0:9d:6:4399:89a1:4a86:9630]) by smtp.gmail.com with ESMTPSA id r38-20020a05600c322600b003dd7edcc960sm2058522wmp.45.2023.02.01.08.35.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 08:35:21 -0800 (PST) From: Florent Revest To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org Cc: catalin.marinas@arm.com, will@kernel.org, rostedt@goodmis.org, mhiramat@kernel.org, mark.rutland@arm.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kpsingh@kernel.org, jolsa@kernel.org, xukuohai@huaweicloud.com, Florent Revest Subject: [PATCH 0/8] Add ftrace direct call for arm64 Date: Wed, 1 Feb 2023 17:34:12 +0100 Message-Id: <20230201163420.1579014-1-revest@chromium.org> X-Mailer: git-send-email 2.39.1.519.gcb327c4b5f-goog MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230201_083527_494782_53ECB25B X-CRM114-Status: GOOD ( 15.94 ) 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 This series adds ftrace direct call support to arm64. This makes BPF tracing programs (fentry/fexit/fmod_ret/lsm) work on arm64. It is meant to apply on top of the arm64 tree which contains Mark Rutland's series on CALL_OPS [1] under the for-next/ftrace tag. The first three patches consolidate the two existing ftrace APIs for registering direct calls. They are split to make the reviewers lives easier but if it'd be a preferred style, I'd be happy to squash them in the next revision. Currently, there is both a _ftrace_direct and _ftrace_direct_multi API. Apart from samples and selftests, there are no users of the _ftrace_direct API left in-tree so this deletes it and renames the _ftrace_direct_multi API to _ftrace_direct for simplicity. The main benefit of this refactoring is that, with the API that's left, an ftrace_ops backing a direct call will only ever point to one direct call. We can therefore store the direct called trampoline address in the ops (patch 4) and look it up from the ftrace trampoline on arm64 (patch 7) in the case when the destination would be out of reach of a BL instruction at the ftrace callsite. (in this case, ftrace_caller acts as a lightweight intermediary trampoline) This series has been tested on both arm64 and x86_64 with: 1- CONFIG_FTRACE_SELFTEST (cf: patch 6) 2- samples/ftrace/*.ko (cf: patch 8) 3- tools/testing/selftests/bpf/test_progs (both -t lsm and -t fentry_fexit) This follows up on prior art by Xu Kuohai [2]. The implementation here is totally different but the fix for ftrace selftests (patch 6) is a trivial rebase of a patch originally by Xu so I kept his authorship and trailers untouched on that patch, I hope that's ok. 1: https://lore.kernel.org/all/20230123134603.1064407-1-mark.rutland@arm.com/ 2: https://lore.kernel.org/bpf/20220913162732.163631-1-xukuohai@huaweicloud.com/ Florent Revest (7): ftrace: Replace uses of _ftrace_direct APIs with _ftrace_direct_multi ftrace: Remove the legacy _ftrace_direct API ftrace: Rename _ftrace_direct_multi APIs to _ftrace_direct APIs ftrace: Store direct called addresses in their ops ftrace: Make DIRECT_CALLS work WITH_ARGS and !WITH_REGS arm64: ftrace: Add direct call support arm64: ftrace: Add direct called trampoline samples support Xu Kuohai (1): ftrace: Fix dead loop caused by direct call in ftrace selftest arch/arm64/Kconfig | 4 + arch/arm64/include/asm/ftrace.h | 24 ++ arch/arm64/kernel/asm-offsets.c | 6 + arch/arm64/kernel/entry-ftrace.S | 70 +++- arch/arm64/kernel/ftrace.c | 36 +- include/linux/ftrace.h | 51 +-- kernel/bpf/trampoline.c | 14 +- kernel/trace/Kconfig | 2 +- kernel/trace/ftrace.c | 433 +------------------- kernel/trace/trace_selftest.c | 14 +- samples/Kconfig | 2 +- samples/ftrace/ftrace-direct-modify.c | 41 +- samples/ftrace/ftrace-direct-multi-modify.c | 44 +- samples/ftrace/ftrace-direct-multi.c | 28 +- samples/ftrace/ftrace-direct-too.c | 35 +- samples/ftrace/ftrace-direct.c | 33 +- 16 files changed, 333 insertions(+), 504 deletions(-)