mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] riscv: ftrace: only use pre-function NOPs with call ops
@ 2026-07-06 12:35 Rui Qi
  2026-08-29  3:45 ` Rui Qi
  0 siblings, 1 reply; 2+ messages in thread
From: Rui Qi @ 2026-07-06 12:35 UTC (permalink / raw)
  To: palmer, pjw, aou
  Cc: Rui Qi, stable, Alexandre Ghiti, Andy Chiu, Puranjay Mohan,
	open list:RISC-V ARCHITECTURE, open list

Commit c217157bcd1d ("riscv: Implement
HAVE_DYNAMIC_FTRACE_WITH_CALL_OPS") changed CC_FLAGS_FTRACE to use
-fpatchable-function-entry=8,4 or -fpatchable-function-entry=4,2
for all dynamic ftrace builds. That layout makes the compiler place an
8-byte area before the function entry, which is used as the per-callsite
ftrace_ops literal when CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS is enabled.

RISC-V can still build with CONFIG_DYNAMIC_FTRACE=y and
CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS=n, for example when
CONFIG_CFI_CLANG is enabled because HAVE_DYNAMIC_FTRACE_WITH_CALL_OPS
is selected only when !CFI_CLANG. In that configuration
ftrace_call_adjust() does not skip the pre-function literal area and
only returns addr + MCOUNT_AUIPC_SIZE. With the pre-function layout,
that points into the pre-entry padding instead of the callsite jalr, so
dynamic ftrace records the wrong patch address.

Use the pre-function literal layout only when call ops are enabled.
Otherwise keep the previous patchable-function-entry counts so the
recorded address matches ftrace_call_adjust() non-call-ops path.

Fixes: c217157bcd1d ("riscv: Implement HAVE_DYNAMIC_FTRACE_WITH_CALL_OPS")
Cc: stable@vger.kernel.org
Signed-off-by: Rui Qi <qirui.001@bytedance.com>
---
 arch/riscv/Makefile | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
index 3070c3874305..235730a243aa 100644
--- a/arch/riscv/Makefile
+++ b/arch/riscv/Makefile
@@ -14,11 +14,19 @@ endif
 ifeq ($(CONFIG_DYNAMIC_FTRACE),y)
 	LDFLAGS_vmlinux += --no-relax
 	KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
+ifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS),y)
 ifeq ($(CONFIG_RISCV_ISA_C),y)
 	CC_FLAGS_FTRACE := -fpatchable-function-entry=8,4
 else
 	CC_FLAGS_FTRACE := -fpatchable-function-entry=4,2
 endif
+else
+ifeq ($(CONFIG_RISCV_ISA_C),y)
+	CC_FLAGS_FTRACE := -fpatchable-function-entry=4
+else
+	CC_FLAGS_FTRACE := -fpatchable-function-entry=2
+endif
+endif
 endif
 
 ifeq ($(CONFIG_CMODEL_MEDLOW),y)
-- 
2.20.1

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] riscv: ftrace: only use pre-function NOPs with call ops
  2026-07-06 12:35 [PATCH] riscv: ftrace: only use pre-function NOPs with call ops Rui Qi
@ 2026-08-29  3:45 ` Rui Qi
  0 siblings, 0 replies; 2+ messages in thread
From: Rui Qi @ 2026-08-29  3:45 UTC (permalink / raw)
  To: palmer, pjw, aou, Masami Hiramatsu (Google), Steven Rostedt
  Cc: stable, Alexandre Ghiti, Andy Chiu, Puranjay Mohan,
	open list:RISC-V ARCHITECTURE, open list, Mark Rutland, stable,
	linux-trace-kernel

On 7/6/26 8:35 PM, Rui Qi wrote:
> Commit c217157bcd1d ("riscv: Implement
> HAVE_DYNAMIC_FTRACE_WITH_CALL_OPS") changed CC_FLAGS_FTRACE to use
> -fpatchable-function-entry=8,4 or -fpatchable-function-entry=4,2
> for all dynamic ftrace builds. That layout makes the compiler place an
> 8-byte area before the function entry, which is used as the per-callsite
> ftrace_ops literal when CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS is enabled.
> 
> RISC-V can still build with CONFIG_DYNAMIC_FTRACE=y and
> CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS=n, for example when
> CONFIG_CFI_CLANG is enabled because HAVE_DYNAMIC_FTRACE_WITH_CALL_OPS
> is selected only when !CFI_CLANG. In that configuration
> ftrace_call_adjust() does not skip the pre-function literal area and
> only returns addr + MCOUNT_AUIPC_SIZE. With the pre-function layout,
> that points into the pre-entry padding instead of the callsite jalr, so
> dynamic ftrace records the wrong patch address.
> 
> Use the pre-function literal layout only when call ops are enabled.
> Otherwise keep the previous patchable-function-entry counts so the
> recorded address matches ftrace_call_adjust() non-call-ops path.
> 
> Fixes: c217157bcd1d ("riscv: Implement HAVE_DYNAMIC_FTRACE_WITH_CALL_OPS")
> Cc: stable@vger.kernel.org
> Signed-off-by: Rui Qi <qirui.001@bytedance.com>
> ---
>  arch/riscv/Makefile | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
> index 3070c3874305..235730a243aa 100644
> --- a/arch/riscv/Makefile
> +++ b/arch/riscv/Makefile
> @@ -14,11 +14,19 @@ endif
>  ifeq ($(CONFIG_DYNAMIC_FTRACE),y)
>  	LDFLAGS_vmlinux += --no-relax
>  	KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
> +ifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS),y)
>  ifeq ($(CONFIG_RISCV_ISA_C),y)
>  	CC_FLAGS_FTRACE := -fpatchable-function-entry=8,4
>  else
>  	CC_FLAGS_FTRACE := -fpatchable-function-entry=4,2
>  endif
> +else
> +ifeq ($(CONFIG_RISCV_ISA_C),y)
> +	CC_FLAGS_FTRACE := -fpatchable-function-entry=4
> +else
> +	CC_FLAGS_FTRACE := -fpatchable-function-entry=2
> +endif
> +endif
>  endif
>  
>  ifeq ($(CONFIG_CMODEL_MEDLOW),y)


Hi,

Gentle ping on this patch. It's been about two months since submission
without any review feedback.

The patch fixes a bug where ftrace_call_adjust() returns the wrong
patch address when CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS is disabled
(e.g., under CONFIG_CFI_CLANG), because the pre-function literal
layout is still used unconditionally.

Adding the ftrace maintainers and mailing list, which were missing
from the original submission — that likely explains the lack of
response.

Link:
https://lore.kernel.org/r/20260706123554.455065-1-qirui.001@bytedance.com

Thanks,
Rui

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-29  3:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-06 12:35 [PATCH] riscv: ftrace: only use pre-function NOPs with call ops Rui Qi
2026-08-29  3:45 ` Rui Qi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®