From patchwork Tue Aug 31 09:50:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 12466813 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham 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 D5221C432BE for ; Tue, 31 Aug 2021 09:50:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BBD7E6101C for ; Tue, 31 Aug 2021 09:50:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240662AbhHaJvo (ORCPT ); Tue, 31 Aug 2021 05:51:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:49627 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234216AbhHaJvW (ORCPT ); Tue, 31 Aug 2021 05:51:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630403427; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t8XYUgR9kHcOYFdSNrWNV6bYolumP9ymhRdSASBvoKM=; b=ZE15u+td5r1mW2/OqEBqoALMSlkl9lFGXp+G6nqsqryGxJy9RS1ryjPcNenslW+WLPi1LG SmMkKa/uLaELj8ETAdWBl6vGIlDAvWXZiUIiDLouyBstahbcaa2PkBSTzRzvMLnN3YIGd5 4ufHCfgLN45XtT3h53F0AZl8RpFyXO0= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-334-oZH62Jt-NXWGuTl8f_KSZw-1; Tue, 31 Aug 2021 05:50:26 -0400 X-MC-Unique: oZH62Jt-NXWGuTl8f_KSZw-1 Received: by mail-wm1-f72.google.com with SMTP id k5-20020a7bc3050000b02901e081f69d80so5761740wmj.8 for ; Tue, 31 Aug 2021 02:50:25 -0700 (PDT) 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=t8XYUgR9kHcOYFdSNrWNV6bYolumP9ymhRdSASBvoKM=; b=lSEXU5OTmoJy1VpsacSAjJJpviWPp6iqtnIwOOmK0Ma9SkC2QthXi6cN4c7R/URyTP p5ymL2hhuBjycOeOiVtGDr570NfK3KMdeM94HgHvuoreuGhACECJGvxgptWQSjx50Ham IBZmLI8PacUwsEN8FKllfjaAu9eEF6EtmA8tQNp0fwZ/KwQbZGMELVSdYc49V1NSkqlp 6QjSpJgsn7Ws0kMzJkNbuY/1KMPgdm6DfRCJRB6f2kGm7mby7aMGfgQekwFYIZahAlry umJAYP54iZT6pbK7xbInkTrF7R5915iZdrx1xfK55UFZDLUAl9EjH1iFYlDpmMFX7NsW JBvw== X-Gm-Message-State: AOAM531XxywxLs9YUxGhsh+taS3nLAu8O+oAHD19+MeJc3OQqE3KuvIX 5uHk9+zaN3Mt8w7WeaqQY3kcDoE8vaRQxMJFKIy703lduzALjcJsFXMfT05r4jkqjpzbbDy4KiE 68D1NZIWP2iBt X-Received: by 2002:a05:600c:a08:: with SMTP id z8mr3237222wmp.52.1630403424876; Tue, 31 Aug 2021 02:50:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmw4QOsPrdbgK9ka9SXfqxCs3jTWhJePp5bIWBfxduD2YjHbSYNsMxcmqk6mS4WTpJhWp5+w== X-Received: by 2002:a05:600c:a08:: with SMTP id z8mr3237201wmp.52.1630403424699; Tue, 31 Aug 2021 02:50:24 -0700 (PDT) Received: from krava.redhat.com ([94.113.247.3]) by smtp.gmail.com with ESMTPSA id y11sm21530442wru.0.2021.08.31.02.50.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Aug 2021 02:50:24 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa To: "Steven Rostedt (VMware)" Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Subject: [PATCH 1/8] x86/ftrace: Remove extra orig rax move Date: Tue, 31 Aug 2021 11:50:10 +0200 Message-Id: <20210831095017.412311-2-jolsa@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210831095017.412311-1-jolsa@kernel.org> References: <20210831095017.412311-1-jolsa@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org There's identical move 2 lines earlier. Signed-off-by: Jiri Olsa --- arch/x86/kernel/ftrace_64.S | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/x86/kernel/ftrace_64.S b/arch/x86/kernel/ftrace_64.S index 7c273846c687..a8eb084a7a9a 100644 --- a/arch/x86/kernel/ftrace_64.S +++ b/arch/x86/kernel/ftrace_64.S @@ -251,7 +251,6 @@ SYM_INNER_LABEL(ftrace_regs_call, SYM_L_GLOBAL) * If ORIG_RAX is anything but zero, make this a call to that. * See arch_ftrace_set_direct_caller(). */ - movq ORIG_RAX(%rsp), %rax testq %rax, %rax SYM_INNER_LABEL(ftrace_regs_caller_jmp, SYM_L_GLOBAL) jnz 1f From patchwork Tue Aug 31 09:50:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 12466815 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham 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 75CD2C4320E for ; Tue, 31 Aug 2021 09:50:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5DC9A6103A for ; Tue, 31 Aug 2021 09:50:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240723AbhHaJvp (ORCPT ); Tue, 31 Aug 2021 05:51:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:31531 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240730AbhHaJv2 (ORCPT ); Tue, 31 Aug 2021 05:51:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630403433; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eqAj4ZrmrtKDThZEc8WrAKFFOfUsJKx4HE/+LaO0ups=; b=COg2VWl0oU8+KShi4vTMCLtrHzMoyIqvUtR/w8mfmp7J9kZVPCIyrtwvKuVdpON8kPZ0X3 PBebcz+mwzmZq93IkYNkbDa/X8vaQfgWcyGPFL+EIjqz7yLkIPJT/CKvilZgZUHrrAcHbu JgHAMQq8mAvIcXIukncHLKczk1C0oNA= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-252-HmtxhHV5Ml-iuQshxCPhQg-1; Tue, 31 Aug 2021 05:50:32 -0400 X-MC-Unique: HmtxhHV5Ml-iuQshxCPhQg-1 Received: by mail-wm1-f70.google.com with SMTP id p11-20020a05600c204b00b002f05aff1663so1126364wmg.2 for ; Tue, 31 Aug 2021 02:50:32 -0700 (PDT) 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=eqAj4ZrmrtKDThZEc8WrAKFFOfUsJKx4HE/+LaO0ups=; b=RTm2PY+kYl1EOAR2sVQj+GPju4ZhBHYPW2qLdLrGp15Z+E3dF4NnG3wQQP46DCb+sC Ylahs5+XxORggZoZFVVWKjUozYZofAV8OzGJGeLhX+LFlFqvRq13CcaU1ACaD7chnzzp 79XN4Bx6t1X9lNwT5mezbp8IjCkSnx0nVlYy5577JEPM7X4e924/7M6lJSM7vD8V3cAu SmyACvkjmTQMhnCBkqKtWEDBA7ErWJprDA+LR6TfgxCAIHaApEjQsmF/9imSIj8IqcuP gPtFJAkMrTjkLlQAkqE03+IxTF/p4/u0j6vPPpZxbwyQ3unEfsxGn5S9Vtj5KL/LeeAY Uusw== X-Gm-Message-State: AOAM532oGW00/Rs88fAE2KZCTm4GEsGoJQ8rzCKMFgDQpbVIr5OAy3rB KCDCiarY7xj8qO1/BW3Wz98A7rGpBtdVlIkssYakdAph/Tq6eREfdCTwyduXH84onClVjZ52S2K m99XzGJvpB1+d X-Received: by 2002:a5d:634f:: with SMTP id b15mr29948174wrw.220.1630403431302; Tue, 31 Aug 2021 02:50:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyT+c1jjGRY2d3dwjvaR2TIlhGUOehXrslKaZ7jFbw+KAWrwQ4Lb33Z8Ifttxyc/c4WrcMAmQ== X-Received: by 2002:a5d:634f:: with SMTP id b15mr29948160wrw.220.1630403431114; Tue, 31 Aug 2021 02:50:31 -0700 (PDT) Received: from krava.redhat.com ([94.113.247.3]) by smtp.gmail.com with ESMTPSA id f23sm2150379wmc.3.2021.08.31.02.50.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Aug 2021 02:50:30 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa To: "Steven Rostedt (VMware)" Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Subject: [PATCH 2/8] x86/ftrace: Remove fault protection code in prepare_ftrace_return Date: Tue, 31 Aug 2021 11:50:11 +0200 Message-Id: <20210831095017.412311-3-jolsa@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210831095017.412311-1-jolsa@kernel.org> References: <20210831095017.412311-1-jolsa@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org From: "Steven Rostedt (VMware)" Removing the fault protection code when writing return_hooker to stack. As Steven noted: > That protection was there from the beginning due to being "paranoid", > considering ftrace was bricking network cards. But that protection > would not have even protected against that. Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Jiri Olsa --- arch/x86/kernel/ftrace.c | 38 +++----------------------------------- 1 file changed, 3 insertions(+), 35 deletions(-) diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c index 1b3ce3b4a2a2..c555624da989 100644 --- a/arch/x86/kernel/ftrace.c +++ b/arch/x86/kernel/ftrace.c @@ -625,12 +625,10 @@ int ftrace_disable_ftrace_graph_caller(void) * Hook the return address and push it in the stack of return addrs * in current thread info. */ -void prepare_ftrace_return(unsigned long self_addr, unsigned long *parent, +void prepare_ftrace_return(unsigned long ip, unsigned long *parent, unsigned long frame_pointer) { unsigned long return_hooker = (unsigned long)&return_to_handler; - unsigned long old; - int faulted; /* * When resuming from suspend-to-ram, this function can be indirectly @@ -650,37 +648,7 @@ void prepare_ftrace_return(unsigned long self_addr, unsigned long *parent, if (unlikely(atomic_read(¤t->tracing_graph_pause))) return; - /* - * Protect against fault, even if it shouldn't - * happen. This tool is too much intrusive to - * ignore such a protection. - */ - asm volatile( - "1: " _ASM_MOV " (%[parent]), %[old]\n" - "2: " _ASM_MOV " %[return_hooker], (%[parent])\n" - " movl $0, %[faulted]\n" - "3:\n" - - ".section .fixup, \"ax\"\n" - "4: movl $1, %[faulted]\n" - " jmp 3b\n" - ".previous\n" - - _ASM_EXTABLE(1b, 4b) - _ASM_EXTABLE(2b, 4b) - - : [old] "=&r" (old), [faulted] "=r" (faulted) - : [parent] "r" (parent), [return_hooker] "r" (return_hooker) - : "memory" - ); - - if (unlikely(faulted)) { - ftrace_graph_stop(); - WARN_ON(1); - return; - } - - if (function_graph_enter(old, self_addr, frame_pointer, parent)) - *parent = old; + if (!function_graph_enter(*parent, ip, frame_pointer, parent)) + *parent = return_hooker; } #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ From patchwork Tue Aug 31 09:50:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 12466817 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham 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 53180C432BE for ; Tue, 31 Aug 2021 09:50:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3B50A61029 for ; Tue, 31 Aug 2021 09:50:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234216AbhHaJvp (ORCPT ); Tue, 31 Aug 2021 05:51:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:49784 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240734AbhHaJvf (ORCPT ); Tue, 31 Aug 2021 05:51:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630403440; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6i+vmebuDOOghhLAstCSS2o/gKVEVgaCIAFpYy/d7w4=; b=DRtVVAkQveF8RY3LWq78kHmOPTEA5ZyJlA/3fjz3cLut9aG2fLHEh0NRuYhsm06oSqBBXM lKnX9FhCSJcn55EfdYSeywstlbLkOzjl9PWwlgA8ABsXs9EJ07G2TcLVIR62SlNcuaDOX5 rIlRRbdcabZrSA5XGTZr7UAExMsCQek= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-126-DApYzNlxN5iUGhGBmG4K3g-1; Tue, 31 Aug 2021 05:50:38 -0400 X-MC-Unique: DApYzNlxN5iUGhGBmG4K3g-1 Received: by mail-wr1-f70.google.com with SMTP id l1-20020adff481000000b00156e670a09dso3896222wro.1 for ; Tue, 31 Aug 2021 02:50:38 -0700 (PDT) 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=6i+vmebuDOOghhLAstCSS2o/gKVEVgaCIAFpYy/d7w4=; b=p7nSx4MCPe5meXIHknwjk+QiaZ8YfgjDpa1zgPYVhToqY5iuXkBuxMfCnyo41P/xwq Sznw0Z4WYhYzYoL1oP4mfazWnwfiXDg1x75/aId3GWZVtCncE2B1fX9pI6lHNRr842ef ENudynVTnU0dOHkm4XAtNvsrOiF7Pmy3F5CWh7QCf7AMpVift4TLChm+4K21itpBz7LS 9FIkJ+fVl23kjCvs87k27SN5NnHaotkjhfZoHTIjj044etRCNyk0jEB6WapZYt/EuHu+ ENY9o5ZyB7Dg2cHRZ8zlFDKykaxaKaYkRVxRT17x0ey6vs8oKUTHhDGsu8jSNBhQpwNq 2QuA== X-Gm-Message-State: AOAM530sq9tdWJPRMnGN2XUJzEUK944C0jeUS7mQpWjlVctjWFUYJ4+P m3qnpwts52plk6tnqEtqRK06C0CkMObTqy3dNwuFIBE8bhYujnnpD3mUqgd0EMGjHnzM9AGLY+D LfuL/kY+MZnSM X-Received: by 2002:a5d:4689:: with SMTP id u9mr30401973wrq.330.1630403437700; Tue, 31 Aug 2021 02:50:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZje1w3zbpxcG3Pn/8Bstzk1Hrr/hQybjuNQDhGqMbyqhR6qxgEG0pi7+Q8BULAX8c1EXCYg== X-Received: by 2002:a5d:4689:: with SMTP id u9mr30401947wrq.330.1630403437472; Tue, 31 Aug 2021 02:50:37 -0700 (PDT) Received: from krava.redhat.com ([94.113.247.3]) by smtp.gmail.com with ESMTPSA id t11sm2117512wmi.23.2021.08.31.02.50.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Aug 2021 02:50:37 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa To: "Steven Rostedt (VMware)" Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Subject: [PATCH 3/8] x86/ftrace: Make function graph use ftrace directly Date: Tue, 31 Aug 2021 11:50:12 +0200 Message-Id: <20210831095017.412311-4-jolsa@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210831095017.412311-1-jolsa@kernel.org> References: <20210831095017.412311-1-jolsa@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org From: "Steven Rostedt (VMware)" We don't need special hook for graph tracer entry point, but instead we can use graph_ops::func function to install the return_hooker. This moves the graph tracing setup _before_ the direct trampoline prepares the stack, so the return_hooker will be called when the direct trampoline is finished. This simplifies the code, because we don't need to take into account the direct trampoline setup when preparing the graph tracer hooker and we can allow function graph tracer on entries registered with direct trampoline. [fixed compile error reported by kernel test robot ] Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Jiri Olsa --- arch/x86/include/asm/ftrace.h | 9 +++++++-- arch/x86/kernel/ftrace.c | 37 ++++++++++++++++++++++++++++++++--- arch/x86/kernel/ftrace_64.S | 29 +-------------------------- include/linux/ftrace.h | 9 +++++++++ kernel/trace/fgraph.c | 6 ++++-- 5 files changed, 55 insertions(+), 35 deletions(-) diff --git a/arch/x86/include/asm/ftrace.h b/arch/x86/include/asm/ftrace.h index 9f3130f40807..024d9797646e 100644 --- a/arch/x86/include/asm/ftrace.h +++ b/arch/x86/include/asm/ftrace.h @@ -57,6 +57,13 @@ arch_ftrace_get_regs(struct ftrace_regs *fregs) #define ftrace_instruction_pointer_set(fregs, _ip) \ do { (fregs)->regs.ip = (_ip); } while (0) + +struct ftrace_ops; +#define ftrace_graph_func ftrace_graph_func +void ftrace_graph_func(unsigned long ip, unsigned long parent_ip, + struct ftrace_ops *op, struct ftrace_regs *fregs); +#else +#define FTRACE_GRAPH_TRAMP_ADDR FTRACE_GRAPH_ADDR #endif #ifdef CONFIG_DYNAMIC_FTRACE @@ -65,8 +72,6 @@ struct dyn_arch_ftrace { /* No extra data needed for x86 */ }; -#define FTRACE_GRAPH_TRAMP_ADDR FTRACE_GRAPH_ADDR - #endif /* CONFIG_DYNAMIC_FTRACE */ #endif /* __ASSEMBLY__ */ #endif /* CONFIG_FUNCTION_TRACER */ diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c index c555624da989..804fcc6ef2c7 100644 --- a/arch/x86/kernel/ftrace.c +++ b/arch/x86/kernel/ftrace.c @@ -527,7 +527,7 @@ static void *addr_from_call(void *ptr) return ptr + CALL_INSN_SIZE + call.disp; } -void prepare_ftrace_return(unsigned long self_addr, unsigned long *parent, +void prepare_ftrace_return(unsigned long ip, unsigned long *parent, unsigned long frame_pointer); /* @@ -541,7 +541,8 @@ static void *static_tramp_func(struct ftrace_ops *ops, struct dyn_ftrace *rec) void *ptr; if (ops && ops->trampoline) { -#ifdef CONFIG_FUNCTION_GRAPH_TRACER +#if !defined(CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS) && \ + defined(CONFIG_FUNCTION_GRAPH_TRACER) /* * We only know about function graph tracer setting as static * trampoline. @@ -589,8 +590,9 @@ void arch_ftrace_trampoline_free(struct ftrace_ops *ops) #ifdef CONFIG_FUNCTION_GRAPH_TRACER #ifdef CONFIG_DYNAMIC_FTRACE -extern void ftrace_graph_call(void); +#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS +extern void ftrace_graph_call(void); static const char *ftrace_jmp_replace(unsigned long ip, unsigned long addr) { return text_gen_insn(JMP32_INSN_OPCODE, (void *)ip, (void *)addr); @@ -618,7 +620,17 @@ int ftrace_disable_ftrace_graph_caller(void) return ftrace_mod_jmp(ip, &ftrace_stub); } +#else /* !CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS */ +int ftrace_enable_ftrace_graph_caller(void) +{ + return 0; +} +int ftrace_disable_ftrace_graph_caller(void) +{ + return 0; +} +#endif /* CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS */ #endif /* !CONFIG_DYNAMIC_FTRACE */ /* @@ -629,6 +641,7 @@ void prepare_ftrace_return(unsigned long ip, unsigned long *parent, unsigned long frame_pointer) { unsigned long return_hooker = (unsigned long)&return_to_handler; + int bit; /* * When resuming from suspend-to-ram, this function can be indirectly @@ -648,7 +661,25 @@ void prepare_ftrace_return(unsigned long ip, unsigned long *parent, if (unlikely(atomic_read(¤t->tracing_graph_pause))) return; + bit = ftrace_test_recursion_trylock(ip, *parent); + if (bit < 0) + return; + if (!function_graph_enter(*parent, ip, frame_pointer, parent)) *parent = return_hooker; + + ftrace_test_recursion_unlock(bit); +} + +#ifdef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS +void ftrace_graph_func(unsigned long ip, unsigned long parent_ip, + struct ftrace_ops *op, struct ftrace_regs *fregs) +{ + struct pt_regs *regs = &fregs->regs; + unsigned long *stack = (unsigned long *)kernel_stack_pointer(regs); + + prepare_ftrace_return(ip, (unsigned long *)stack, 0); } +#endif + #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ diff --git a/arch/x86/kernel/ftrace_64.S b/arch/x86/kernel/ftrace_64.S index a8eb084a7a9a..7a879901f103 100644 --- a/arch/x86/kernel/ftrace_64.S +++ b/arch/x86/kernel/ftrace_64.S @@ -174,11 +174,6 @@ SYM_INNER_LABEL(ftrace_caller_end, SYM_L_GLOBAL) SYM_FUNC_END(ftrace_caller); SYM_FUNC_START(ftrace_epilogue) -#ifdef CONFIG_FUNCTION_GRAPH_TRACER -SYM_INNER_LABEL(ftrace_graph_call, SYM_L_GLOBAL) - jmp ftrace_stub -#endif - /* * This is weak to keep gas from relaxing the jumps. * It is also used to copy the retq for trampolines. @@ -288,15 +283,6 @@ SYM_FUNC_START(__fentry__) cmpq $ftrace_stub, ftrace_trace_function jnz trace -fgraph_trace: -#ifdef CONFIG_FUNCTION_GRAPH_TRACER - cmpq $ftrace_stub, ftrace_graph_return - jnz ftrace_graph_caller - - cmpq $ftrace_graph_entry_stub, ftrace_graph_entry - jnz ftrace_graph_caller -#endif - SYM_INNER_LABEL(ftrace_stub, SYM_L_GLOBAL) retq @@ -314,25 +300,12 @@ trace: CALL_NOSPEC r8 restore_mcount_regs - jmp fgraph_trace + jmp ftrace_stub SYM_FUNC_END(__fentry__) EXPORT_SYMBOL(__fentry__) #endif /* CONFIG_DYNAMIC_FTRACE */ #ifdef CONFIG_FUNCTION_GRAPH_TRACER -SYM_FUNC_START(ftrace_graph_caller) - /* Saves rbp into %rdx and fills first parameter */ - save_mcount_regs - - leaq MCOUNT_REG_SIZE+8(%rsp), %rsi - movq $0, %rdx /* No framepointers needed */ - call prepare_ftrace_return - - restore_mcount_regs - - retq -SYM_FUNC_END(ftrace_graph_caller) - SYM_FUNC_START(return_to_handler) subq $24, %rsp diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index a69f363b61bf..d399621a67ee 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -779,6 +779,15 @@ static inline bool is_ftrace_trampoline(unsigned long addr) } #endif /* CONFIG_DYNAMIC_FTRACE */ +#ifdef CONFIG_FUNCTION_GRAPH_TRACER +#ifndef ftrace_graph_func +#define ftrace_graph_func ftrace_stub +#define FTRACE_OPS_GRAPH_STUB FTRACE_OPS_FL_STUB +#else +#define FTRACE_OPS_GRAPH_STUB 0 +#endif +#endif /* CONFIG_FUNCTION_GRAPH_TRACER */ + /* totally disable ftrace - can not re-enable after this */ void ftrace_kill(void); diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c index b8a0d1d564fb..22061d38fc00 100644 --- a/kernel/trace/fgraph.c +++ b/kernel/trace/fgraph.c @@ -115,6 +115,7 @@ int function_graph_enter(unsigned long ret, unsigned long func, { struct ftrace_graph_ent trace; +#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS /* * Skip graph tracing if the return location is served by direct trampoline, * since call sequence and return addresses are unpredictable anyway. @@ -124,6 +125,7 @@ int function_graph_enter(unsigned long ret, unsigned long func, if (ftrace_direct_func_count && ftrace_find_rec_direct(ret - MCOUNT_INSN_SIZE)) return -EBUSY; +#endif trace.func = func; trace.depth = ++current->curr_ret_depth; @@ -333,10 +335,10 @@ unsigned long ftrace_graph_ret_addr(struct task_struct *task, int *idx, #endif /* HAVE_FUNCTION_GRAPH_RET_ADDR_PTR */ static struct ftrace_ops graph_ops = { - .func = ftrace_stub, + .func = ftrace_graph_func, .flags = FTRACE_OPS_FL_INITIALIZED | FTRACE_OPS_FL_PID | - FTRACE_OPS_FL_STUB, + FTRACE_OPS_GRAPH_STUB, #ifdef FTRACE_GRAPH_TRAMP_ADDR .trampoline = FTRACE_GRAPH_TRAMP_ADDR, /* trampoline_size is only needed for dynamically allocated tramps */ From patchwork Tue Aug 31 09:50:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 12466819 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham 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 E7A1DC43214 for ; Tue, 31 Aug 2021 09:50:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D4D536102A for ; Tue, 31 Aug 2021 09:50:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240730AbhHaJvr (ORCPT ); Tue, 31 Aug 2021 05:51:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42406 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240735AbhHaJvl (ORCPT ); Tue, 31 Aug 2021 05:51:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630403446; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Cg/efFypXdgTTjnQMuhwdn9EcUQgpWsXBxL2SLIRi+8=; b=fc+LjW8PBc/pWgRGseXZviR4/cc/Nh8ZHNCvAvG1gZxjbuW0wHt7u7tk8MVd56V7hqnHas yJ4WcJhV3C6px4/pDGrODmy6t+t2pUYEe1pVQbSsJq+bA6PbKzaLXRa8VpSY0VlCY9erQb tiDGIgjFKbJYky9R79aZG6DZHE0Ddfo= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-553-bSVeVucWOwyHnpPj1cSIrQ-1; Tue, 31 Aug 2021 05:50:45 -0400 X-MC-Unique: bSVeVucWOwyHnpPj1cSIrQ-1 Received: by mail-wm1-f69.google.com with SMTP id k5-20020a7bc3050000b02901e081f69d80so5761976wmj.8 for ; Tue, 31 Aug 2021 02:50:44 -0700 (PDT) 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=Cg/efFypXdgTTjnQMuhwdn9EcUQgpWsXBxL2SLIRi+8=; b=MIDQgOhJQNOTXC0wVnUqDKMSExXgIw+eK9nhz5Vqwi2WOjl60iTDlNmIJ6ypzdT46/ sKitWvCo4/0F9hePLKMsSsh6A1EwXbms3SBtIY1JIQvd81LWiCpjk0awAORWyQzqv+N6 Sok9FBCpshOksAb0oWFuZz6rleFj2lPKr3TB/WPKygJz1ohTOd2kx5ZiOVrpsQQB4b6C kARyNG6hYx9DceJtIz3d38o7KXuuqkySOSln0ufGaGAPOyWTAFQACVWt/Qpg4uuZ//y+ bpFeaMo0z6j1uGNcSAbg03pQrC94XzfWDIfaXm1qWurkdEFe21ytFhy4whSYWr173Usj ftyw== X-Gm-Message-State: AOAM532MdMIC+gTJhMx55E88KvU3S1zajkkzqtygMHMRmfWwhMlW8nIF 15S0wQnD14Sr7gHEDwGgik+hEetp/j6GOZPdBgKrcEDaMEpZ0ArCVp7M6VRw796xIJxGxRgyrbM h2TiYBU5R+9fm X-Received: by 2002:a1c:210a:: with SMTP id h10mr3304117wmh.117.1630403444006; Tue, 31 Aug 2021 02:50:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxLrCTL6wHFHkUVrKt6C7WD1cERTFV3oeo83tug8iHKfag1xxQzcrp/Vw+EVlu/3wl2x43Vg== X-Received: by 2002:a1c:210a:: with SMTP id h10mr3304107wmh.117.1630403443841; Tue, 31 Aug 2021 02:50:43 -0700 (PDT) Received: from krava.redhat.com ([94.113.247.3]) by smtp.gmail.com with ESMTPSA id f3sm1962985wmj.28.2021.08.31.02.50.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Aug 2021 02:50:43 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa To: "Steven Rostedt (VMware)" Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Subject: [PATCH 4/8] tracing: Add trampoline/graph selftest Date: Tue, 31 Aug 2021 11:50:13 +0200 Message-Id: <20210831095017.412311-5-jolsa@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210831095017.412311-1-jolsa@kernel.org> References: <20210831095017.412311-1-jolsa@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Adding selftest for checking that direct trampoline can co-exist together with graph tracer on same function. This is supported for CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS config option, which is defined only for x86_64 for now. Signed-off-by: Jiri Olsa --- kernel/trace/trace_selftest.c | 49 ++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/kernel/trace/trace_selftest.c b/kernel/trace/trace_selftest.c index adf7ef194005..f8e55b949cdd 100644 --- a/kernel/trace/trace_selftest.c +++ b/kernel/trace/trace_selftest.c @@ -750,6 +750,8 @@ static struct fgraph_ops fgraph_ops __initdata = { .retfunc = &trace_graph_return, }; +noinline __noclone static void trace_direct_tramp(void) { } + /* * Pretty much the same than for the function tracer from which the selftest * has been borrowed. @@ -760,6 +762,7 @@ trace_selftest_startup_function_graph(struct tracer *trace, { int ret; unsigned long count; + char *func_name __maybe_unused; #ifdef CONFIG_DYNAMIC_FTRACE if (ftrace_filter_param) { @@ -808,8 +811,52 @@ trace_selftest_startup_function_graph(struct tracer *trace, goto out; } - /* Don't test dynamic tracing, the function tracer already did */ +#ifdef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS + tracing_reset_online_cpus(&tr->array_buffer); + set_graph_array(tr); + /* + * Some archs *cough*PowerPC*cough* add characters to the + * start of the function names. We simply put a '*' to + * accommodate them. + */ + func_name = "*" __stringify(DYN_FTRACE_TEST_NAME); + ftrace_set_global_filter(func_name, strlen(func_name), 1); + + /* + * Register direct function together with graph tracer + * and make sure we get graph trace. + */ + ret = register_ftrace_direct((unsigned long) DYN_FTRACE_TEST_NAME, + (unsigned long) trace_direct_tramp); + if (ret) + goto out; + + ret = register_ftrace_graph(&fgraph_ops); + if (ret) { + warn_failed_init_tracer(trace, ret); + goto out; + } + + DYN_FTRACE_TEST_NAME(); + + count = 0; + + tracing_stop(); + /* check the trace buffer */ + ret = trace_test_buffer(&tr->array_buffer, &count); + + unregister_ftrace_graph(&fgraph_ops); + + tracing_start(); + + if (!ret && !count) { + ret = -1; + goto out; + } +#endif + + /* Don't test dynamic tracing, the function tracer already did */ out: /* Stop it if we failed */ if (ret) From patchwork Tue Aug 31 09:50:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 12466821 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham 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 C17DFC432BE for ; Tue, 31 Aug 2021 09:50:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A43B5600CC for ; Tue, 31 Aug 2021 09:50:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240744AbhHaJvu (ORCPT ); Tue, 31 Aug 2021 05:51:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53941 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240742AbhHaJvs (ORCPT ); Tue, 31 Aug 2021 05:51:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630403453; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uK5Gw3luJndbFn1Fa9N5OtQXbRTUWbF3Z2jHUj38PoM=; b=VE1DY2MdZC/XqfJz22z24l4aEfoqSfXeX5ZeRkClDhJqiCUM/JR+wQ11X30aH9uAil65X1 7X7Gu2+GEhAV2VO00MtDqBr2QGes9bSdSHrsCL9/9N3P1IJzjZEnW9aAuLkFS8ipRC+HpY y/udP9Bm/LBEQ8IpFopKNSdU3JVhg9Y= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-281-sgDiljMlMFS2PhB1ZFzAuA-1; Tue, 31 Aug 2021 05:50:51 -0400 X-MC-Unique: sgDiljMlMFS2PhB1ZFzAuA-1 Received: by mail-wm1-f72.google.com with SMTP id a201-20020a1c7fd2000000b002e748bf0544so1034709wmd.2 for ; Tue, 31 Aug 2021 02:50:51 -0700 (PDT) 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=uK5Gw3luJndbFn1Fa9N5OtQXbRTUWbF3Z2jHUj38PoM=; b=WZeH+KyWZx3JmGWgwSSp+exeSLg9wPctYNl/rKuK6Lu24QDJ6C6W0Avb0Eh7Nyx9i0 TtG4UEVbMPvk95RwGgqkIFPvC+ODTp/7YtDjAvcmWesunqe4btQ7S47DYlpWzEbUJTWH tMdMr4y3y94a1P/2vWvNDO36TMkuEJkQNZwUuYyh5wX2GqFpJWwmiYSMrPDRY0e1L5m6 JNpLe9LhsNNzszUIQ0BGpCmOAH9eAFHY5OjNlANi91PdQPpECn7u5BGRoVVbbFf4PCiF YG1FJ3UEXo/2WWlILpDRNg5yumqpraBEKnug85Rr/Du75t/yjzCYHwNhqRYv/yk12Flg GvfQ== X-Gm-Message-State: AOAM533+MNbYyCSIQ5kWHLrsIi2LmIvsatI+iUy6sWmnNZQQVj+3j4wD 8jVy+KKJMRb59Lq+JPeojcONqoM/dPsKvE4yizNlGOXhxYZSnO38vyK+ehspyPSLYInrpYilqSZ X4/+4LUPsvGHh X-Received: by 2002:a7b:c316:: with SMTP id k22mr3235167wmj.56.1630403450390; Tue, 31 Aug 2021 02:50:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQDlQOr4yHaAI0wp/1WVyoRB28jMuZLOwEex+kYyerzAXTeemfWIxW7uAJAQsdfdrnE4qMgg== X-Received: by 2002:a7b:c316:: with SMTP id k22mr3235150wmj.56.1630403450186; Tue, 31 Aug 2021 02:50:50 -0700 (PDT) Received: from krava.redhat.com ([94.113.247.3]) by smtp.gmail.com with ESMTPSA id b18sm17953773wrr.89.2021.08.31.02.50.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Aug 2021 02:50:49 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa To: "Steven Rostedt (VMware)" Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Subject: [PATCH 5/8] ftrace: Add ftrace_add_rec_direct function Date: Tue, 31 Aug 2021 11:50:14 +0200 Message-Id: <20210831095017.412311-6-jolsa@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210831095017.412311-1-jolsa@kernel.org> References: <20210831095017.412311-1-jolsa@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Factor out the code that adds (ip, addr) tuple to direct_functions hash in new ftrace_add_rec_direct function. It will be used in following patches. Signed-off-by: Jiri Olsa --- kernel/trace/ftrace.c | 60 ++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 7b180f61e6d3..c60217d81040 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -2394,6 +2394,39 @@ unsigned long ftrace_find_rec_direct(unsigned long ip) return entry->direct; } +static struct ftrace_func_entry* +ftrace_add_rec_direct(unsigned long ip, unsigned long addr, + struct ftrace_hash **free_hash) +{ + struct ftrace_func_entry *entry; + + if (ftrace_hash_empty(direct_functions) || + direct_functions->count > 2 * (1 << direct_functions->size_bits)) { + struct ftrace_hash *new_hash; + int size = ftrace_hash_empty(direct_functions) ? 0 : + direct_functions->count + 1; + + if (size < 32) + size = 32; + + new_hash = dup_hash(direct_functions, size); + if (!new_hash) + return NULL; + + *free_hash = direct_functions; + direct_functions = new_hash; + } + + entry = kmalloc(sizeof(*entry), GFP_KERNEL); + if (!entry) + return NULL; + + entry->ip = ip; + entry->direct = addr; + __add_hash_entry(direct_functions, entry); + return entry; +} + static void call_direct_funcs(unsigned long ip, unsigned long pip, struct ftrace_ops *ops, struct ftrace_regs *fregs) { @@ -5110,27 +5143,6 @@ int register_ftrace_direct(unsigned long ip, unsigned long addr) } ret = -ENOMEM; - if (ftrace_hash_empty(direct_functions) || - direct_functions->count > 2 * (1 << direct_functions->size_bits)) { - struct ftrace_hash *new_hash; - int size = ftrace_hash_empty(direct_functions) ? 0 : - direct_functions->count + 1; - - if (size < 32) - size = 32; - - new_hash = dup_hash(direct_functions, size); - if (!new_hash) - goto out_unlock; - - free_hash = direct_functions; - direct_functions = new_hash; - } - - entry = kmalloc(sizeof(*entry), GFP_KERNEL); - if (!entry) - goto out_unlock; - direct = ftrace_find_direct_func(addr); if (!direct) { direct = ftrace_alloc_direct_func(addr); @@ -5140,9 +5152,9 @@ int register_ftrace_direct(unsigned long ip, unsigned long addr) } } - entry->ip = ip; - entry->direct = addr; - __add_hash_entry(direct_functions, entry); + entry = ftrace_add_rec_direct(ip, addr, &free_hash); + if (!entry) + goto out_unlock; ret = ftrace_set_filter_ip(&direct_ops, ip, 0, 0); if (ret) From patchwork Tue Aug 31 09:50:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 12466827 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, 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 87BFDC432BE for ; Tue, 31 Aug 2021 09:52:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 692FB61058 for ; Tue, 31 Aug 2021 09:52:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240807AbhHaJxE (ORCPT ); Tue, 31 Aug 2021 05:53:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:51258 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240785AbhHaJxC (ORCPT ); Tue, 31 Aug 2021 05:53:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630403527; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LSGXz5zVkm4f250jTbRF6daIOdS+MoPdJeoX8bvDLJI=; b=FLwOo/Q4AVUic2DBmZ3oTuyYEvB7DjhB4GLSDjGc6J/ah1KWxB8Y1LGFxjHbRuoeOhxeRc 55VUzOlanDtzoHHUv2g5VnA1h/HbV4tXgj3nn/mi4E0tytSC+YeNldRARPjRQ7b6F6LAQJ Sp84bdVdEGo2BylGOooVcjR9/kVJwfk= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-27-QDvS53KOM-G1HGvxYRZbaQ-1; Tue, 31 Aug 2021 05:50:58 -0400 X-MC-Unique: QDvS53KOM-G1HGvxYRZbaQ-1 Received: by mail-wr1-f71.google.com with SMTP id v18-20020adfe2920000b029013bbfb19640so3855763wri.17 for ; Tue, 31 Aug 2021 02:50:58 -0700 (PDT) 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=LSGXz5zVkm4f250jTbRF6daIOdS+MoPdJeoX8bvDLJI=; b=V/lhUiBwRjKiY/DiOj8B/EzdehzYJXMKlMJhxMt1unKGYwNJpb62rS2eYtG1X4wEYl v+5U5jq6vTdmQgmL7wQOPuF+6W7qK/aKSGkh8/suyNJE3e9zyz8EtP0mgE6GeaPvzRvH mSTauf0vhCW3CEP6AcYJcgtK3yPB0ePsfsFFmmMsPgu5rynO/7IuYdXlWYUv+dHQYKj9 Sj7+2m/qRAq1qo/CAh+BbaHzqw2RgiieA0GpAvEEa5ymUNfpKU9i18BIBpkR0ZgGMo6S YthXpLvYFcRNunkPqgUR9/hrw+/DVjoUFceLcFXAAbEd+2aullqGBZDTK2m0g0iF8369 67qA== X-Gm-Message-State: AOAM533Dlj7dv8i8sVnmnkZRf6I/35YtK5lP6fWt/7K3c+Zy6jXrrVJK iouU8ABQftgIKrMYp/F4odnRjwr1VLh77swjATq4RZN5+vm8er4iqbIECdSUiZaSotcT0kaKW3+ C6hSxR+mdqSN0 X-Received: by 2002:a7b:cd88:: with SMTP id y8mr3366206wmj.24.1630403456620; Tue, 31 Aug 2021 02:50:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxlq+Ojis0honlAiaLLzNSjgQeVRglyDlMRqLeiDYCnLJvpLvP0AheHktCif43/fBYU6dnmw== X-Received: by 2002:a7b:cd88:: with SMTP id y8mr3366193wmj.24.1630403456462; Tue, 31 Aug 2021 02:50:56 -0700 (PDT) Received: from krava.redhat.com ([94.113.247.3]) by smtp.gmail.com with ESMTPSA id q14sm11278818wrc.31.2021.08.31.02.50.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Aug 2021 02:50:56 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa To: "Steven Rostedt (VMware)" Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Subject: [PATCH 6/8] ftrace: Add multi direct register/unregister interface Date: Tue, 31 Aug 2021 11:50:15 +0200 Message-Id: <20210831095017.412311-7-jolsa@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210831095017.412311-1-jolsa@kernel.org> References: <20210831095017.412311-1-jolsa@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Adding interface to register multiple direct functions within single call. Adding following functions: register_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr) unregister_ftrace_direct_multi(struct ftrace_ops *ops) The register_ftrace_direct_multi registers direct function (addr) with all functions in ops filter. The ops filter can be updated before with ftrace_set_filter_ip calls. All requested functions must not have direct function currently registered, otherwise register_ftrace_direct_multi will fail. The unregister_ftrace_direct_multi unregisters ops related direct functions. Signed-off-by: Jiri Olsa --- include/linux/ftrace.h | 11 ++++ kernel/trace/ftrace.c | 111 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index d399621a67ee..e40b5201c16e 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -316,7 +316,10 @@ int ftrace_modify_direct_caller(struct ftrace_func_entry *entry, unsigned long old_addr, unsigned long new_addr); unsigned long ftrace_find_rec_direct(unsigned long ip); +int register_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr); +int unregister_ftrace_direct_multi(struct ftrace_ops *ops); #else +struct ftrace_ops; # define ftrace_direct_func_count 0 static inline int register_ftrace_direct(unsigned long ip, unsigned long addr) { @@ -346,6 +349,14 @@ static inline unsigned long ftrace_find_rec_direct(unsigned long ip) { return 0; } +static inline int register_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr) +{ + return -ENODEV; +} +static inline int unregister_ftrace_direct_multi(struct ftrace_ops *ops) +{ + return -ENODEV; +} #endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */ #ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index c60217d81040..7243769493c9 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -5407,6 +5407,117 @@ int modify_ftrace_direct(unsigned long ip, return ret; } EXPORT_SYMBOL_GPL(modify_ftrace_direct); + +#define MULTI_FLAGS (FTRACE_OPS_FL_IPMODIFY | FTRACE_OPS_FL_DIRECT | \ + FTRACE_OPS_FL_SAVE_REGS) + +static int check_direct_multi(struct ftrace_ops *ops) +{ + if (!(ops->flags & FTRACE_OPS_FL_INITIALIZED)) + return -EINVAL; + if ((ops->flags & MULTI_FLAGS) != MULTI_FLAGS) + return -EINVAL; + return 0; +} + +int register_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr) +{ + struct ftrace_hash *hash, *free_hash = NULL; + struct ftrace_func_entry *entry, *new; + int err = -EBUSY, size, i; + + if (ops->func || ops->trampoline) + return -EINVAL; + if (!(ops->flags & FTRACE_OPS_FL_INITIALIZED)) + return -EINVAL; + if (ops->flags & FTRACE_OPS_FL_ENABLED) + return -EINVAL; + + hash = ops->func_hash->filter_hash; + if (ftrace_hash_empty(hash)) + return -EINVAL; + + mutex_lock(&direct_mutex); + + /* Make sure requested entries are not already registered.. */ + size = 1 << hash->size_bits; + for (i = 0; i < size; i++) { + hlist_for_each_entry(entry, &hash->buckets[i], hlist) { + if (ftrace_find_rec_direct(entry->ip)) + goto out_unlock; + } + } + + /* ... and insert them to direct_functions hash. */ + err = -ENOMEM; + for (i = 0; i < size; i++) { + hlist_for_each_entry(entry, &hash->buckets[i], hlist) { + new = ftrace_add_rec_direct(entry->ip, addr, &free_hash); + if (!new) + goto out_remove; + entry->direct = addr; + } + } + + ops->func = call_direct_funcs; + ops->flags = MULTI_FLAGS; + ops->trampoline = FTRACE_REGS_ADDR; + + err = register_ftrace_function(ops); + + out_remove: + if (err) { + for (i = 0; i < size; i++) { + hlist_for_each_entry(entry, &hash->buckets[i], hlist) { + new = __ftrace_lookup_ip(direct_functions, entry->ip); + if (new) { + remove_hash_entry(direct_functions, new); + kfree(new); + } + } + } + } + + out_unlock: + mutex_unlock(&direct_mutex); + + if (free_hash) { + synchronize_rcu_tasks(); + free_ftrace_hash(free_hash); + } + return err; +} +EXPORT_SYMBOL_GPL(register_ftrace_direct_multi); + +int unregister_ftrace_direct_multi(struct ftrace_ops *ops) +{ + struct ftrace_hash *hash = ops->func_hash->filter_hash; + struct ftrace_func_entry *entry, *new; + int err, size, i; + + if (check_direct_multi(ops)) + return -EINVAL; + if (!(ops->flags & FTRACE_OPS_FL_ENABLED)) + return -EINVAL; + + mutex_lock(&direct_mutex); + err = unregister_ftrace_function(ops); + + size = 1 << hash->size_bits; + for (i = 0; i < size; i++) { + hlist_for_each_entry(entry, &hash->buckets[i], hlist) { + new = __ftrace_lookup_ip(direct_functions, entry->ip); + if (new) { + remove_hash_entry(direct_functions, new); + kfree(new); + } + } + } + + mutex_unlock(&direct_mutex); + return err; +} +EXPORT_SYMBOL_GPL(unregister_ftrace_direct_multi); #endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */ /** From patchwork Tue Aug 31 09:50:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 12466823 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham 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 231DDC432BE for ; Tue, 31 Aug 2021 09:51:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F144A61058 for ; Tue, 31 Aug 2021 09:51:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240758AbhHaJwX (ORCPT ); Tue, 31 Aug 2021 05:52:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:48711 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240766AbhHaJwB (ORCPT ); Tue, 31 Aug 2021 05:52:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630403465; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t6bvp9pXHWwYkD8tY68DycfX16y6E0FnbXtjvnYOkio=; b=f/OIp5AgKVf8uBpFRwCqaistxiqf7Ge7a0KmoDzUT58eQdLLHO5YUswAbD3cTm8YaYFwcq aDK35IspCZXvRknJ4jV/1Rrbjo84v52fDy1x+S2Aq3Se6R7vwBFmHtZB2Kkge4nq0Iaebr 6e+CppDVIAQApr/U6rKPMrL48B2Co68= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-188-w0n1IXZZNu6FdHebQCDhQA-1; Tue, 31 Aug 2021 05:51:04 -0400 X-MC-Unique: w0n1IXZZNu6FdHebQCDhQA-1 Received: by mail-wm1-f72.google.com with SMTP id g3-20020a1c2003000000b002e751c4f439so1019005wmg.7 for ; Tue, 31 Aug 2021 02:51:04 -0700 (PDT) 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=t6bvp9pXHWwYkD8tY68DycfX16y6E0FnbXtjvnYOkio=; b=X5BEvjZZF2N73PQbY//KX9bghA+8DrNDDM3Fyko269Y9kfF9ETBZjy0pEg7BLw7Dqq AYg/yjN9HOToi3I1H7zYXUHCR+Fq7zpzNlZ4mS3gTwkJLb8c3cJipgM7NDG8T767SMnw MgrFXLi5N2oNzuyN2eFq5XCvSHXeakun0wcRjfr1mv2KoIHkA1Gfd/P1gcUgu3hIDc+B BsVc0Bq+xsApQj4bA++CYNE+oI9jmy9hGAL8T7tnDk6v7ts1C1KLadGbYqHtHLltOLZy Mx5B1G7oqwGWMjW4xfH80NM3FWKIIynqBAEUodRcEBKtFi8NH7yBOy+RhAOjTXNHRiQy bF1Q== X-Gm-Message-State: AOAM530kEaPtF5fFT/XkDAyAeGoncoRPoFcqEMP/fsvP6Du/RMDOfEj/ SoErorOSYZILClBBmff7Fnnh6zwd1xMGQYVYi3veJxtLyB5ybrWInt3JNMCT1ZoLRi2KoBT6Sgk xR9Q5PsSQXG6m X-Received: by 2002:a1c:2547:: with SMTP id l68mr3401839wml.23.1630403462944; Tue, 31 Aug 2021 02:51:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPyCWrQg3mVkjhGw+uezNrWGR5cdnracfdsEemYrpJbkF1MzgGClBoUlUPi8OGKfJP6S3o6A== X-Received: by 2002:a1c:2547:: with SMTP id l68mr3401829wml.23.1630403462787; Tue, 31 Aug 2021 02:51:02 -0700 (PDT) Received: from krava.redhat.com ([94.113.247.3]) by smtp.gmail.com with ESMTPSA id t11sm2118614wmi.23.2021.08.31.02.51.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Aug 2021 02:51:02 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa To: "Steven Rostedt (VMware)" Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Subject: [PATCH 7/8] ftrace: Add multi direct modify interface Date: Tue, 31 Aug 2021 11:50:16 +0200 Message-Id: <20210831095017.412311-8-jolsa@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210831095017.412311-1-jolsa@kernel.org> References: <20210831095017.412311-1-jolsa@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Adding interface to modify registered direct function for ftrace_ops. Adding following function: modify_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr) The function changes the currently registered direct function for all attached functions. Signed-off-by: Jiri Olsa --- include/linux/ftrace.h | 6 ++++++ kernel/trace/ftrace.c | 43 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index e40b5201c16e..f3ba6366f7af 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -318,6 +318,8 @@ int ftrace_modify_direct_caller(struct ftrace_func_entry *entry, unsigned long ftrace_find_rec_direct(unsigned long ip); int register_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr); int unregister_ftrace_direct_multi(struct ftrace_ops *ops); +int modify_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr); + #else struct ftrace_ops; # define ftrace_direct_func_count 0 @@ -357,6 +359,10 @@ static inline int unregister_ftrace_direct_multi(struct ftrace_ops *ops) { return -ENODEV; } +static inline int modify_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr) +{ + return -ENODEV; +} #endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */ #ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 7243769493c9..59940a6a907c 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -5518,6 +5518,49 @@ int unregister_ftrace_direct_multi(struct ftrace_ops *ops) return err; } EXPORT_SYMBOL_GPL(unregister_ftrace_direct_multi); + +int modify_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr) +{ + struct ftrace_hash *hash = ops->func_hash->filter_hash; + struct ftrace_func_entry *entry, *iter; + int i, size; + int err; + + if (check_direct_multi(ops)) + return -EINVAL; + if (!(ops->flags & FTRACE_OPS_FL_ENABLED)) + return -EINVAL; + + mutex_lock(&direct_mutex); + mutex_lock(&ftrace_lock); + + /* + * Shutdown the ops, change 'direct' pointer for each + * ops entry in direct_functions hash and startup the + * ops back again. + */ + err = ftrace_shutdown(ops, 0); + if (err) + goto out_unlock; + + size = 1 << hash->size_bits; + for (i = 0; i < size; i++) { + hlist_for_each_entry(iter, &hash->buckets[i], hlist) { + entry = __ftrace_lookup_ip(direct_functions, iter->ip); + if (!entry) + continue; + entry->direct = addr; + } + } + + err = ftrace_startup(ops, 0); + + out_unlock: + mutex_unlock(&ftrace_lock); + mutex_unlock(&direct_mutex); + return err; +} +EXPORT_SYMBOL_GPL(modify_ftrace_direct_multi); #endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */ /** From patchwork Tue Aug 31 09:50:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 12466825 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=-16.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,USER_AGENT_GIT autolearn=ham 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 E802DC432BE for ; Tue, 31 Aug 2021 09:51:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CA38360295 for ; Tue, 31 Aug 2021 09:51:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240718AbhHaJw0 (ORCPT ); Tue, 31 Aug 2021 05:52:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32711 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240776AbhHaJwH (ORCPT ); Tue, 31 Aug 2021 05:52:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630403471; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AjVYZzchk8zj3iEUBSEoZP/smDG6NngufYLxpwikn0s=; b=FsXqkUy4GF5t6ns15KQ/03UOJpQ4brRcs44Fjr2W0kZZ9hZLIu9ia7N7JLnWIV3MBxQvvD U+wSXZOKNjptrCVgMZHlbONfR73Nq9qPYRfSssPzesGxougerkubFp/AvDhNR7UP1908qk 46RWnfjWXPz1yizPdfaa6G0TI7/cnts= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-51-6ag7eqrkMOqcirfWWkudBQ-1; Tue, 31 Aug 2021 05:51:10 -0400 X-MC-Unique: 6ag7eqrkMOqcirfWWkudBQ-1 Received: by mail-wr1-f72.google.com with SMTP id v6-20020adfe4c6000000b001574f9d8336so3874655wrm.15 for ; Tue, 31 Aug 2021 02:51:10 -0700 (PDT) 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=AjVYZzchk8zj3iEUBSEoZP/smDG6NngufYLxpwikn0s=; b=aQWYIR7RBiJCgfXXAChOacHlj336y/u0/v2NH/Xoq/AtqSCqiYVq+6FpuRROfNsu7/ s3es/ij2pjUECyBHt17CAIWFNnqUJHr7lZS/UlISAzsrsJxQmCaYjkPymVZ3mV26tBY6 9NUL7xAWABMH5+Au8yDOda4T7vpJfegPpWcC3B4KsIWahsH8NpU6iONBAhDKOX6uPypO uU6ingAluTgGrxV/wvwO6dYNQ+Q0qIuU6/4V8fL7WQlSgYISXGKzm7353k14JR+shfTP W1MUYCCe5be7Y16sdQRW52254Od+vVYIR4zWff+KLl/JtmPldFYVlKNuYGFrMhc4EWci BkGA== X-Gm-Message-State: AOAM532CKswXbZTT2YOF1q0yv8aun1GjIU1FErNgDHnNH9P4uqFY4DMZ 8UhjEPOndktIJWVr3lxKWCWwXAHbu2EzjkjiA3TObrK7RUT2c07qwRq5a83jFhq32BB5UrMgNhL ccB/3wwQTd/oL X-Received: by 2002:a1c:a9d2:: with SMTP id s201mr3166756wme.81.1630403469371; Tue, 31 Aug 2021 02:51:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBBv+cAWt3n9YpUfaV64/t01+7Vy21+B6e6ffqZqyyGakQW3qOFiYCrsmEDUZPUlRX8Ea5mQ== X-Received: by 2002:a1c:a9d2:: with SMTP id s201mr3166747wme.81.1630403469216; Tue, 31 Aug 2021 02:51:09 -0700 (PDT) Received: from krava.redhat.com ([94.113.247.3]) by smtp.gmail.com with ESMTPSA id j17sm17638724wrh.67.2021.08.31.02.51.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Aug 2021 02:51:09 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa To: "Steven Rostedt (VMware)" Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Subject: [PATCH 8/8] ftrace/samples: Add multi direct interface test module Date: Tue, 31 Aug 2021 11:50:17 +0200 Message-Id: <20210831095017.412311-9-jolsa@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210831095017.412311-1-jolsa@kernel.org> References: <20210831095017.412311-1-jolsa@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Adding simple module that uses multi direct interface: register_ftrace_direct_multi unregister_ftrace_direct_multi The init function registers trampoline for 2 functions, and exit function unregisters them. Signed-off-by: Jiri Olsa --- samples/ftrace/Makefile | 1 + samples/ftrace/ftrace-direct-multi.c | 52 ++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 samples/ftrace/ftrace-direct-multi.c diff --git a/samples/ftrace/Makefile b/samples/ftrace/Makefile index 4ce896e10b2e..ab1d1c05c288 100644 --- a/samples/ftrace/Makefile +++ b/samples/ftrace/Makefile @@ -3,6 +3,7 @@ obj-$(CONFIG_SAMPLE_FTRACE_DIRECT) += ftrace-direct.o obj-$(CONFIG_SAMPLE_FTRACE_DIRECT) += ftrace-direct-too.o obj-$(CONFIG_SAMPLE_FTRACE_DIRECT) += ftrace-direct-modify.o +obj-$(CONFIG_SAMPLE_FTRACE_DIRECT) += ftrace-direct-multi.o CFLAGS_sample-trace-array.o := -I$(src) obj-$(CONFIG_SAMPLE_TRACE_ARRAY) += sample-trace-array.o diff --git a/samples/ftrace/ftrace-direct-multi.c b/samples/ftrace/ftrace-direct-multi.c new file mode 100644 index 000000000000..76b34d46d11c --- /dev/null +++ b/samples/ftrace/ftrace-direct-multi.c @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include + +#include /* for handle_mm_fault() */ +#include +#include + +void my_direct_func(unsigned long ip) +{ + trace_printk("ip %lx\n", ip); +} + +extern void my_tramp(void *); + +asm ( +" .pushsection .text, \"ax\", @progbits\n" +" .type my_tramp, @function\n" +" .globl my_tramp\n" +" my_tramp:" +" pushq %rbp\n" +" movq %rsp, %rbp\n" +" pushq %rdi\n" +" movq 8(%rbp), %rdi\n" +" call my_direct_func\n" +" popq %rdi\n" +" leave\n" +" ret\n" +" .size my_tramp, .-my_tramp\n" +" .popsection\n" +); + +static struct ftrace_ops direct; + +static int __init ftrace_direct_multi_init(void) +{ + ftrace_set_filter_ip(&direct, (unsigned long) wake_up_process, 0, 0); + ftrace_set_filter_ip(&direct, (unsigned long) schedule, 0, 0); + + return register_ftrace_direct_multi(&direct, (unsigned long) my_tramp); +} + +static void __exit ftrace_direct_multi_exit(void) +{ + unregister_ftrace_direct_multi(&direct); +} + +module_init(ftrace_direct_multi_init); +module_exit(ftrace_direct_multi_exit); + +MODULE_AUTHOR("Jiri Olsa"); +MODULE_DESCRIPTION("Example use case of using register_ftrace_direct_multi()"); +MODULE_LICENSE("GPL");