From patchwork Tue Mar 21 14:04:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florent Revest X-Patchwork-Id: 6969 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1808103wrt; Tue, 21 Mar 2023 07:23:52 -0700 (PDT) X-Google-Smtp-Source: AK7set8krtHEh87ciTPkvNScMQdImEgNCdyInIEtdSu00BxIWj1B1S8gx5UPtYhUiua4i2K/xhbT X-Received: by 2002:a17:902:c702:b0:1a1:c0e6:d8d6 with SMTP id p2-20020a170902c70200b001a1c0e6d8d6mr1968762plp.54.1679408631779; Tue, 21 Mar 2023 07:23:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679408631; cv=none; d=google.com; s=arc-20160816; b=0a39Ce8Cdn0ZOd/sOrfFgbfNf5a6FlbuzkkvgE+l+kpTdJSCjypUlQN0bPrTpfSs4a wgnTe+A3oqRtVhfc05rbEZWEHSLXLsMhkmKbBQim8QE0jj4k9aeDkkpGtg8/DPjEcKAM aJbDsEbPAyM4Iau4kgHVbs1XjgTa/Y0VdPyDzbEKr1f04MlY5BC6++EovT7u2rTit0z6 p8wcwe5mkeMxwjsypIPtA524ru8MU+sHA2YLcnkY4LvKeIp7wR/5jr3Ob5br0q29ESiv 12mUmQ9g/q7BmKnac9qsven9vHd/votw8D6OTLRmcm063dOeNRhBS4yI2glcwwng7W5h frOg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=Eyc9M815DDWPE+a5iQ5MddjThl1AbQtLO2yVDEfZLUY=; b=HUKnq63PK+QI8x6D/OU6og60skenmSG/dAcuP10fgnh8n7/mo4Q2YF+OI0YqwYc5nt DSx/xAt3n9cFXYrBFYhoBGI7xFdLb0VEpvCygE14aWYp+8lk07ZPdbQBldUlWAK36+yc 2KT80zFwac0Pe16I/uwxVlF1Jvbx+7YSKfB2Ms7C90+l+zyFVvctoK2QTBXiLTB/x6Fy br38NkYUgybwEDf6AgvFWNmBQFlKJMLrXy8LacA/QJFX/lD7O03cyxWyTwttoUYdQvJV vfb5rvmV64TnjyXXVgcI1ueKoae7k8mrfVFb03fVjj8vBma+P++yZEHN9LpD5MiOjNSM Ttcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=GXjeLkvK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d16-20020a170902ced000b001992ede12a5si15102183plg.27.2023.03.21.07.23.37; Tue, 21 Mar 2023 07:23:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=GXjeLkvK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231341AbjCUOEj (ORCPT + 99 others); Tue, 21 Mar 2023 10:04:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229971AbjCUOEi (ORCPT ); Tue, 21 Mar 2023 10:04:38 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6C32166C1 for ; Tue, 21 Mar 2023 07:04:36 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id p16so9634326wmq.5 for ; Tue, 21 Mar 2023 07:04:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1679407475; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Eyc9M815DDWPE+a5iQ5MddjThl1AbQtLO2yVDEfZLUY=; b=GXjeLkvKjytTCw5uvgmOTPE72dJ3RoJKaN4OhBTYpmZH634OeIJ9U9cmpyukPU8pf2 p8z8E2TpYumBVVrBbBaHDwvUeaUd79xpcPLLvl3WT2i2BfepOcb+8fAFNrfBc65/QV4i bTRYMbd1T8XGBarkJrOeUnNdwTh26TkUUqe1k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679407475; 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=Eyc9M815DDWPE+a5iQ5MddjThl1AbQtLO2yVDEfZLUY=; b=JSVdykNFutU5jWDySZVhoh7abuFa7rZi5YBIq/NVIh0QfSSSj0rerr/5dLey5g7Kwc dfyHdvWREUsPCwN1V2yg3sMMFzLx7pHNRD+qmCP96n85EpOGHgJFrTSRFFRTZg7Pdsi/ TZRUZTdfEL/jdQGFL1ds5feQhmyLavWJYmWNAM2gPyvsPRS/T8ZU/dWzS8CneZ3gb8H2 Qi7oCH6VhYer9H+8qH1yj7cNhres9RbQ16ym7owPklkyyfoToVp70VBdCIxdg721dCBD Vmm22q4+JTQh2QwBEuIeNi64+kam4OcjxjMyC8FXCpy4n7gonrveOfYxY8Z3k3NBr/HL 2T+A== X-Gm-Message-State: AO0yUKVFG/2zVObW9pxLWs7zLWVpMkZDB9NKeUU2D1H5CR101eomTros Drn1ubl2Amrr8wKAsj+POhEiLq4yXxqLVKemEd0= X-Received: by 2002:a1c:f210:0:b0:3eb:39e0:3530 with SMTP id s16-20020a1cf210000000b003eb39e03530mr2480006wmc.41.1679407474866; Tue, 21 Mar 2023 07:04:34 -0700 (PDT) Received: from revest.zrh.corp.google.com ([2a00:79e0:9d:6:4b8c:8b16:90d:8d9a]) by smtp.gmail.com with ESMTPSA id f12-20020a1cc90c000000b003e20cf0408esm13620896wmb.40.2023.03.21.07.04.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Mar 2023 07:04:34 -0700 (PDT) From: Florent Revest To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: rostedt@goodmis.org, mhiramat@kernel.org, mark.rutland@arm.com, ast@kernel.org, daniel@iogearbox.net, kpsingh@kernel.org, revest@chromium.org, jolsa@kernel.org Subject: [PATCH v2 0/7] Refactor ftrace direct call APIs Date: Tue, 21 Mar 2023 15:04:17 +0100 Message-Id: <20230321140424.345218-1-revest@chromium.org> X-Mailer: git-send-email 2.40.0.rc2.332.ga46443480c-goog MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760987585491453578?= X-GMAIL-MSGID: =?utf-8?q?1760987585491453578?= Differences since v1 [1]: - Use a READ_ONCE() to read the direct call address in call_direct_funcs - Added an Acked-by from Mark This series refactors ftrace direct call APIs in preparation for arm64 support. It is roughly a subset of [2] rebased on v6.3-rc2 and meant to be taken by Steven's tree before all the arm64 specific bits. The first patch was suggested by Steven in a review of [1], it makes it more obvious to the caller that filters probably need to be freed when unregistering a direct call. The next three patches consolidate the two existing ftrace APIs for registering direct calls. They are only split to make the reviewer's life easier. 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 5) and, in the future arm64 series, look it up from the ftrace trampoline. (in the meantime, it makes call_direct_funcs a bit simpler too) Ftrace direct calls technically don't need DYNAMIC_FTRACE_WITH_REGS so this extends its support to DYNAMIC_FTRACE_WITH_ARGS (patch 6). arm64 won't support DYNAMIC_FTRACE_WITH_REGS. Finally, it fixes the ABI of the stub direct call trampoline used in ftrace selftests. This has been tested on x86_64 with: 1- CONFIG_FTRACE_SELFTEST 2- samples/ftrace/*.ko 1: https://lore.kernel.org/all/20230316173811.1223508-1-revest@chromium.org/T/#t 2: https://lore.kernel.org/all/20230207182135.2671106-1-revest@chromium.org/T/#t Florent Revest (6): ftrace: Let unregister_ftrace_direct_multi() call ftrace_free_filter() 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 Mark Rutland (1): ftrace: selftest: remove broken trace_direct_tramp arch/s390/kernel/mcount.S | 5 + arch/x86/kernel/ftrace_32.S | 5 + arch/x86/kernel/ftrace_64.S | 4 + include/linux/ftrace.h | 61 +-- kernel/bpf/trampoline.c | 12 +- kernel/trace/Kconfig | 2 +- kernel/trace/ftrace.c | 438 ++------------------ kernel/trace/trace_selftest.c | 19 +- samples/Kconfig | 2 +- samples/ftrace/ftrace-direct-modify.c | 10 +- samples/ftrace/ftrace-direct-multi-modify.c | 9 +- samples/ftrace/ftrace-direct-multi.c | 5 +- samples/ftrace/ftrace-direct-too.c | 10 +- samples/ftrace/ftrace-direct.c | 10 +- 14 files changed, 101 insertions(+), 491 deletions(-) Acked-by: Jiri Olsa