Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp313151lqp; Thu, 21 Mar 2024 01:48:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWqK5UhyhuUC6OCDNbH8aEv5a14iv1thvcQgDZZ8kgKqh/9Y+DA81/49UmUq7QdGkiuoBB3M6QETuKJg3CTHQKI/P+xtUabDlerBCcmIw== X-Google-Smtp-Source: AGHT+IERML2ML6IELg5qpJS48SI4jQ4qGh86tuKA8tssImLc525FuYvCqf5dQTB88nTAJJRDyL30 X-Received: by 2002:a05:6a00:2304:b0:6e7:2e76:5358 with SMTP id h4-20020a056a00230400b006e72e765358mr4430506pfh.29.1711010922532; Thu, 21 Mar 2024 01:48:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711010922; cv=pass; d=google.com; s=arc-20160816; b=ClD7WgGpDqnAhXZFhKbcqVtoPNumrZUkPo4jrOska9iwwNW0KxcpU2IN5ACkt9f6Ir +qV9ZeDMex2WOfW0/BszWq55ANfCUTRfX54/5r/kcNNsL5PYPYl3UUMY3cKwEXeI3/AG exQE7LxsptT17a0Wf+qjSJWENju70a+M7thSOW9KvD3IyZBCnKyT7tMsdVSDUvtUdNoW mngwVX3oBPIHpAHHoEoDl5lKQNwfnxnGhWmom/dUlfCzof2geKLR6vvc4wEoFw1Dcub4 M7c/+WBTsMX/c/2A2U7mYQ0wq4fid7xL4w9rcE45CKSI2Yx5zijd/VWf+kLGqGlUuAS6 rfTA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=TjDUSd5WOhhuO2gWVvgw1Inp/LAwQf4BfeHnpXJb3nk=; fh=sdh6jFTHFBgX3aTRtnwoz+2NJ855TNaKwyjLTdqf4UU=; b=U1+YgfaqlPV1Bfo/KXUJuRK2k+Q0L56qnDznBnYrCKcoGRiymgLXmwLOXr48kCVE7d M1p2XpnCvWFZQ4oZ/mLuHx8dANlNZcXRPhXqDSf2XxeqsFCn9abXu2u0MycKDQ1LwAnB +Ae6UO12AHS/LaR+9GBH8VL37vvrJcXBiyr5w4s9GlWfYHK9sMUTPFJkf/h7jrXzrdHn b1dING3G1R+0cWFLq030Z48XY+gv4hl5eL3D77t4I9vVlslysgYr97j+aTtjuP1oaFKU 9B28KIBep6J4lPV0XThqB5lSYAwVv+s8iMB7xrSioTqls7D4K0DfT+1EXjgW6axgv7i3 7YGA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Gmijaw2Q; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-109814-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109814-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 34-20020a630d62000000b005dc7e8a6d6fsi12012472pgn.520.2024.03.21.01.48.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 01:48:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-109814-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Gmijaw2Q; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-109814-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109814-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id E73CAB21795 for ; Thu, 21 Mar 2024 08:48:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 77F522772A; Thu, 21 Mar 2024 08:48:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Gmijaw2Q" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9AB56C2E6; Thu, 21 Mar 2024 08:48:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711010911; cv=none; b=POkeegujKDJefQwtBXXOKE92IFqx8jXe3BcdF1rksGqYf/BrZ2LA00T4v61GETlSo9/7DhDn3C9xnUTuX4u+lYBdXxEI41Artw8siklMNr3RBxCtTPersmXEeEXSdqVJ/bOtKwfMzib29hcuNtj3ZrIK1Wffk6NnrYjyvILvjhk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711010911; c=relaxed/simple; bh=15ZtzjY1fNYkJ0k0FnRr+bctv3Yg6O2wYPUdrRw1jU4=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=M2vQxA5NaM9Nx2pQQmOpN9211CHDnpr2XPDzo8FBU19OLBLSj7bfRbAH5HmEzi2w4eG+rrafw7KVVyCMGQdj5d2UaARLdGMDhRV6SsDfMegTCPbySHnRrLdMl0TlY71j7xmlW0glVNhB3XxAOS4dkROYizMpldLc/cxQggdoipE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Gmijaw2Q; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7DD6C433C7; Thu, 21 Mar 2024 08:48:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711010911; bh=15ZtzjY1fNYkJ0k0FnRr+bctv3Yg6O2wYPUdrRw1jU4=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=Gmijaw2QPhHATpi68Owc0NGfwiqqzkpz2elHJSZbXKXUtlFJaiMVN25OSGx/pyYsx CZ3kVp43itxG2hgscjbik/tkL8uZt3tSxsi+IPsN7Ba2XGwFTfC5uohzxBijORayQ9 n7Pgt7AeV1UUBPYTjeKHvYoOxeaTy6llr4/LY+l1nrprWsOPmriJOk+3172fXQ/Ju6 7OPpeamnaOUlwa8S0taZC5fBwzPqk9tv/NEb+TNeCZUUsms2jmV871Vo1WF4ExCJbK H7RV8eaovOIrHEuRjj9rLqqA3jpYLvK3ND9HQwNKifeA7kF+8TmQmFrTtg1E/urVUR obBYTsqsWcF7g== From: =?utf-8?B?QmrDtnJuIFTDtnBlbA==?= To: Andy Chiu Cc: Puranjay Mohan , Mark Rutland , Paul Walmsley , Palmer Dabbelt , Albert Ou , Steven Rostedt , Masami Hiramatsu , Sami Tolvanen , Guo Ren , Ley Foon Tan , Deepak Gupta , Sia Jee Heng , Bjorn Topel , Song Shuai , Cl'ement L'eger , Al Viro , Jisheng Zhang , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Robbin Ehn , Brendan Sweeney Subject: Re: [RFC PATCH] riscv: Implement HAVE_DYNAMIC_FTRACE_WITH_CALL_OPS In-Reply-To: References: <20240306165904.108141-1-puranjay12@gmail.com> <87ttlhdeqb.fsf@all.your.base.are.belong.to.us> <8734suqsth.fsf@all.your.base.are.belong.to.us> <87zfv0onre.fsf@all.your.base.are.belong.to.us> <87il1oedx8.fsf@all.your.base.are.belong.to.us> Date: Thu, 21 Mar 2024 09:48:27 +0100 Message-ID: <87msqsotr8.fsf@all.your.base.are.belong.to.us> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Andy, Pulling out the A option: >> > A) Use auipc/jalr, only patch jalr to take us to a common >> > dispatcher/trampoline >> > >> > | # probably on a data cache-line !=3D fu= nc .text to avoid ping-pong >> > | ... >> > | func: >> > | ...make sure ra isn't messed up... >> > | aupic >> > | nop <=3D> jalr # Text patch point -> common_dispatch >> > | ACTUAL_FUNC >> > | >> > | common_dispatch: >> > | load based on ra >> > | jalr >> > | ... >> > >> > The auipc is never touched, and will be overhead. Also, we need a mv to >> > store ra in a scratch register as well -- like Arm. We'll have two insn >> > per-caller overhead for a disabled caller. > > My patch series takes a similar "in-function dispatch" approach. A > difference is that the is > embedded within each function entry. I'd like to have it moved to a > run-time allocated array to reduce total text size. This is what arm64 has as well. It's a 8B + 1-2 dirt cheap movish like instructions (save ra, prepare jump with auipc). I think that's a reasonable overhead. > Another difference is that my series changes the first instruction to > "j ACTUAL_FUNC" for the "ftrace disable" case. As long as the > architecture guarantees the atomicity of the first instruction, then > we are safe. For example, we are safe if the first instruction could > only be "mv tmp, ra" or "j ACTUAL_FUNC". And since the loaded address is > always valid, we can fix "mv + jalr" down so we don't have to > play with the exception handler trick. The guarantee from arch would > require ziccif (in RVA22) though, but I think it is the same for us > (unless with stop_machine). For ziccif, I would rather call that out > during boot than blindly assume. I'm maybe biased, but I'd prefer the A) over your version with the unconditional jump. A) has the overhead of two, I'd say, free instructions (again "Meten is Weten!" ;-)). > However, one thing I am not very sure is: do we need a destination > address in a "per-function" manner? It seems like most of the time the > destination address can only be ftrace_call, or ftrace_regs_call. If > the number of destination addresses is very few, then we could > potentially reduce the size of > . Yes, we do need a per-function manner. BPF, e.g., uses dynamically/JIT:ed trampolines/targets. Bj=C3=B6rn