From patchwork Mon Apr 29 17:47:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 13647461 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (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 A9872126F27; Mon, 29 Apr 2024 17:48:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714412910; cv=fail; b=AxBXfaGNs5WPhY6BOzr325QK8xZ/kZYvWsD5JlwbhV4poa5Y0V+fKDVc0ZR24yrKVZEK1E1ccKhZhDUlRqQIZQj3XmK4NV+IeOa2Q6Q7xjT94L5UEFltGpeZxw/lLzmLXP0RghBB/zRD8F8AV7cbUJERCA8bwaN9gAt7ZyNVM3A= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714412910; c=relaxed/simple; bh=28fm4A2Aiai5npxxwX91OpqMgXkPQ2bqm4FOXhPIHic=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=W02K6DPLBzayg2Bd3OVkqnEjfOfRw28bz3sHItH6Pcrb3npDCdPxtq4L+5wFIm/lMjCXnSXRFKDM3Ig/HWrl0wrUvWjb2FoYfx7IxC7ljk0WYVKcxz3LQE90MFy3QB/NXVoTgmEbSam/aRLUZbP8PnHtMF+K4EmrKIyJOOsNj40= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=RilswQLX; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=L13vMsmY; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="RilswQLX"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="L13vMsmY" Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TGwkOW004998; Mon, 29 Apr 2024 17:47:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=y12rgvXV3sQB8e2sOodhJZ7wA7IP2AnMyHMpvXbMM5E=; b=RilswQLXveaUksSe8WOQ14uJy8jFYvzBRMsyd4O9bC1RQfkThYLsToW+/t73lK6ddrWt r2dRn6Eqo3UU2WD7Y9ef9hkclC/rT1JIVK0DqLObmb/tXNxnkENZcLX8sZHv932MKASa vEsdyAg6KCyO9QckRvDKoxQWM2sw6Kv5JHaWEChnfRJJZKB2U+d5No4RDV84RF3oOsRk oMrzR1nu8r1fYrxItgUiLQX7agGfWFu9b132LvJUjgVkt605xObyK74AZ+ZbxCploXv0 1da4JCu78BR5uv1D1C/fwdv06v7Hzu0UQgX6m/8OuG/Hi0o8JyXMyFsa6LglzpKVBQle ig== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrsdek68m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 17:47:26 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TGKquG005250; Mon, 29 Apr 2024 17:47:25 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2169.outbound.protection.outlook.com [104.47.59.169]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt67aj4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 17:47:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FWl7Z4GRMJwgZhz1JU5clC1WfioXwzEz3qlDG+11B2kZVO6vm+vUNmfNJ06zDn0qEEORZlNxYiSuvx6ytFwQ/WagxemvnKxVKSmykuMjiM665+HcjnBU6EblZ2asnS85ujpL5cBjulbYzQqqfLWzTYnNeQJUkvY8t5G0T/TteeUppYqxakrnTOFb3HynH5MNBYXurUtrRxdEw4a0M655ohmTtWrt3I0749nhp+AM9lE3ZXfLSo9Nw88c8gffrwG2ORBtZOezZZW5Tqs5ZlrQthjvhSfMpr04agTSoPNTDc3MF1gx6hnQvELEF/iqeOGCOEHMR4Ig9CaVUxfpZT6fVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=y12rgvXV3sQB8e2sOodhJZ7wA7IP2AnMyHMpvXbMM5E=; b=fB20Umqi8x3SP75YmVCRDLmKvErZEZsCFiKzm+o3+VYQ203Ah2wOqFtNCRYk7Lw6KUnDjlC2OJU9TS7jWiHdj7um9cq3u0hrS6PFC+eWkzrkcVN4p8zWFMqEDAGV4ox4UZOWGKovnvzSpHLsscnqhdBRMGdRVhRefIZj/SjR/0Gylv4ebMIh002MI3Ope0WCelRE7N0FX+RmILE4bwrJelFzkr6TsGt4fzD2TmOxNrH0cDG1mt2tZu4qziv87Yw8XJz887LdcfcFT+qa4sKZRv8cUmRxHpxDePGcrvazkREGf2KzfkZbVbpJIyMp2v/Uxwknreg+W37Hxrezge6Q1w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=y12rgvXV3sQB8e2sOodhJZ7wA7IP2AnMyHMpvXbMM5E=; b=L13vMsmYf5vnLPfPfSy324HNMaOOFGS9YvKMNaIZcgXsePeX2Qj28Z5ohUd9QucHmx54AU03CFKx4QOHKdOzHiKU8gQJdinXeQhQH83o3pCMFy46K59J7iNfb8JhOrCrKH+qae6VcnXM9daHxHiiRm9s62UIMMor0tMUqXRDgi8= Received: from PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) by SA1PR10MB6318.namprd10.prod.outlook.com (2603:10b6:806:251::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.34; Mon, 29 Apr 2024 17:47:21 +0000 Received: from PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca]) by PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca%3]) with mapi id 15.20.7519.031; Mon, 29 Apr 2024 17:47:21 +0000 From: Stephen Brennan To: Steven Rostedt , Masami Hiramatsu , Mark Rutland Cc: Guo Ren , Huacai Chen , WANG Xuerui , "James E.J. Bottomley" , Helge Deller , Michael Ellerman , Nicholas Piggin , Christophe Leroy , "Aneesh Kumar K.V" , "Naveen N. Rao" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-csky@vger.kernel.org, loongarch@lists.linux.dev, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, Stephen Brennan Subject: [PATCH v2] kprobe/ftrace: bail out if ftrace was killed Date: Mon, 29 Apr 2024 10:47:18 -0700 Message-Id: <20240429174718.1347900-1-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240426225834.993353-1-stephen.s.brennan@oracle.com> References: <20240426225834.993353-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: BL1PR13CA0431.namprd13.prod.outlook.com (2603:10b6:208:2c3::16) To PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) Precedence: bulk X-Mailing-List: linux-parisc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH8PR10MB6597:EE_|SA1PR10MB6318:EE_ X-MS-Office365-Filtering-Correlation-Id: f8bc9224-7010-451d-e20d-08dc68746bac X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|1800799015|376005|366007; X-Microsoft-Antispam-Message-Info: tDvMsGvtLLsIA4uROdSVSXd7jyYjxkAWczwmIDi8cmCIoNQNU4aet7xTo2OnQ560/8iYB60/OuLF0f8TNCGF8MaE3uQIIVTHeQ++DR9b4nF3NytUUfdpKQRg9H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XyBoDajyC9t+DLFf0vH2putetMQ0jtiuqimwc1bhiX4Bqz9Tn39NYiOLk1yDPc+0qSCiCS9Qzkv8fqgW45/pdWPaQRzgnosyWBqPg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH8PR10MB6597.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(7416005)(1800799015)(376005)(366007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XWR9rtOEwBKaFLtOsNbrZ4z1bJ0Snefj56B0AqA8b/BG+rKuPLKbKJn8D67cB5W1APjrAuOGJsWjMz6T4Q/e/hRNA//4eTtN6RlP/0TIQdxXy+UKz2KGJVYWn4cqZ9F2iLL6HtQGF+48T9Zi3TQA4uUYSXHoBFHLcI+i2YgSC6DIdS9EnScajsowm5Uu9y6vLYH9lKsGjFbPF2BiJjvVT3j7HwgJDcdcFJ/hSbR3T4B2M9chuca+kjTOEda1dFMQHalRQP4r4PrH/iEZVMPZpEY557inxW7ilUjpxjSI2CZzhMk/dhCZIq75rUDRyAMdWkfQBBqqVciWpCVI4a6Bs8iOc5DLzQI2/oG4zIQnT+YzYjXLarjLMVMYFrsnYgyXJPv26VdaEIrmsuTWOuIS6mZ+v9QYjdOzAhwfX6hECCUrUjbczDme5PEArhA/K3lCKVoQV4qLummL9H3eySEKydlK4yvDZJpdtOGz03j1ZWGIY48rYw+8axJGA6SgF/br+RX07ZlFI7WKs1u3OaCToZiRBUrHt1IXOJVxpaKOoSdRLOokESkx5nuOYBOm6QdbWrXkmTiEKC/FHxTaixjKPYgkXv6G+PM++4pny/MkKusDGaigdM+5hVPzB4AoeFRVuC4XEMU+WFNog+QQNrAbutBONAmOQLuEvG1XuTAgaoJf7YZSW4U2nCv+gwOHBPqAud4iXegvpJJ9MNO6kWcaWLdbkj2UJQVgad82CeLlxDelUoUENne4bXL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azk3HsFCuSrRqog+FXcoYBYt+utLnj9eGA4z4BOJsc5BYhx3tGOIY5Ja+WjswWRkFM8LuthmGKV9FDLfrpOTBdDwtVzHp/cfqmb9OKMyRxOcmSaYEvHVmb00ym9AnJfKRE8ZK5R8DyfKxPeRwVbW9KTguCUzk4soqaaKtwTyn0hv+dr6ztPan+OU5Uqj4/TYleno56gSM59ealST7AGTOag7fQrxEBY8lJ2r0zxrkXgnLYNNshskhCbJaZfBfym6preOWWbHOsnrLxwhFwbUY+Y74VJI2V/8Wy2vi9R780oAc0aBl8G4WtUNSWdaxwdTmB8GOQ9AtSt2QB4x97TVW18lt1IE/a07JQnkXRIJk1qqFVgWufDqOkU06KbCcaFzIaNQbtgbq1TWbnGh7jW5zVg+h8QyvhOylJX1lsOT6mHy1R1C8MCYRKWkAWfVzcYdZhTwEln/EY8HHQGcyBS3hTTsd8e58KA1yVhls5g9GJR2qCzS/DjGufFTAZczyDlgaapKGU5fzBMV9S1p4U= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f8bc9224-7010-451d-e20d-08dc68746bac X-MS-Exchange-CrossTenant-AuthSource: PH8PR10MB6597.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Apr 2024 17:47:21.3859 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 2rLhAyd4NwUpWtUIKRi3YIq6armQMu7Ql3bzTvNy6uu8xjUa+LNWiQerI4acKfpDuOnIqigo1Cn7pMe5fW/1AmL2NOoPrF6WH9G/WY0Ew+s= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB6318 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_15,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 adultscore=0 phishscore=0 mlxscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290114 X-Proofpoint-GUID: NnhIAKVzDJkWjyOtunQv4fx_keVhDJ4X X-Proofpoint-ORIG-GUID: NnhIAKVzDJkWjyOtunQv4fx_keVhDJ4X If an error happens in ftrace, ftrace_kill() will prevent disarming kprobes. Eventually, the ftrace_ops associated with the kprobes will be freed, yet the kprobes will still be active, and when triggered, they will use the freed memory, likely resulting in a page fault and panic. This behavior can be reproduced quite easily, by creating a kprobe and then triggering a ftrace_kill(). For simplicity, we can simulate an ftrace error with a kernel module like [1]: [1]: https://github.com/brenns10/kernel_stuff/tree/master/ftrace_killer sudo perf probe --add commit_creds sudo perf trace -e probe:commit_creds # In another terminal make sudo insmod ftrace_killer.ko # calls ftrace_kill(), simulating bug # Back to perf terminal # ctrl-c sudo perf probe --del commit_creds After a short period, a page fault and panic would occur as the kprobe continues to execute and uses the freed ftrace_ops. While ftrace_kill() is supposed to be used only in extreme circumstances, it is invoked in FTRACE_WARN_ON() and so there are many places where an unexpected bug could be triggered, yet the system may continue operating, possibly without the administrator noticing. If ftrace_kill() does not panic the system, then we should do everything we can to continue operating, rather than leave a ticking time bomb. Signed-off-by: Stephen Brennan --- Difference from v1: removed both existing declarations of ftrace_is_dead() from kernel/trace/trace.h. arch/csky/kernel/probes/ftrace.c | 3 +++ arch/loongarch/kernel/ftrace_dyn.c | 3 +++ arch/parisc/kernel/ftrace.c | 3 +++ arch/powerpc/kernel/kprobes-ftrace.c | 3 +++ arch/riscv/kernel/probes/ftrace.c | 3 +++ arch/s390/kernel/ftrace.c | 3 +++ arch/x86/kernel/kprobes/ftrace.c | 3 +++ include/linux/ftrace.h | 2 ++ kernel/trace/trace.h | 2 -- 9 files changed, 23 insertions(+), 2 deletions(-) diff --git a/arch/csky/kernel/probes/ftrace.c b/arch/csky/kernel/probes/ftrace.c index 834cffcfbce3..3931bf9f707b 100644 --- a/arch/csky/kernel/probes/ftrace.c +++ b/arch/csky/kernel/probes/ftrace.c @@ -12,6 +12,9 @@ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip, struct kprobe_ctlblk *kcb; struct pt_regs *regs; + if (unlikely(ftrace_is_dead())) + return; + bit = ftrace_test_recursion_trylock(ip, parent_ip); if (bit < 0) return; diff --git a/arch/loongarch/kernel/ftrace_dyn.c b/arch/loongarch/kernel/ftrace_dyn.c index 73858c9029cc..82c952cb5be0 100644 --- a/arch/loongarch/kernel/ftrace_dyn.c +++ b/arch/loongarch/kernel/ftrace_dyn.c @@ -287,6 +287,9 @@ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip, struct kprobe *p; struct kprobe_ctlblk *kcb; + if (unlikely(ftrace_is_dead())) + return; + bit = ftrace_test_recursion_trylock(ip, parent_ip); if (bit < 0) return; diff --git a/arch/parisc/kernel/ftrace.c b/arch/parisc/kernel/ftrace.c index 621a4b386ae4..3660834f54c3 100644 --- a/arch/parisc/kernel/ftrace.c +++ b/arch/parisc/kernel/ftrace.c @@ -206,6 +206,9 @@ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip, struct kprobe *p; int bit; + if (unlikely(ftrace_is_dead())) + return; + bit = ftrace_test_recursion_trylock(ip, parent_ip); if (bit < 0) return; diff --git a/arch/powerpc/kernel/kprobes-ftrace.c b/arch/powerpc/kernel/kprobes-ftrace.c index 072ebe7f290b..85eb55aa1457 100644 --- a/arch/powerpc/kernel/kprobes-ftrace.c +++ b/arch/powerpc/kernel/kprobes-ftrace.c @@ -21,6 +21,9 @@ void kprobe_ftrace_handler(unsigned long nip, unsigned long parent_nip, struct pt_regs *regs; int bit; + if (unlikely(ftrace_is_dead())) + return; + bit = ftrace_test_recursion_trylock(nip, parent_nip); if (bit < 0) return; diff --git a/arch/riscv/kernel/probes/ftrace.c b/arch/riscv/kernel/probes/ftrace.c index 7142ec42e889..8814fbe4c888 100644 --- a/arch/riscv/kernel/probes/ftrace.c +++ b/arch/riscv/kernel/probes/ftrace.c @@ -11,6 +11,9 @@ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip, struct kprobe_ctlblk *kcb; int bit; + if (unlikely(ftrace_is_dead())) + return; + bit = ftrace_test_recursion_trylock(ip, parent_ip); if (bit < 0) return; diff --git a/arch/s390/kernel/ftrace.c b/arch/s390/kernel/ftrace.c index c46381ea04ec..ccbe8ccf945b 100644 --- a/arch/s390/kernel/ftrace.c +++ b/arch/s390/kernel/ftrace.c @@ -296,6 +296,9 @@ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip, struct kprobe *p; int bit; + if (unlikely(ftrace_is_dead())) + return; + bit = ftrace_test_recursion_trylock(ip, parent_ip); if (bit < 0) return; diff --git a/arch/x86/kernel/kprobes/ftrace.c b/arch/x86/kernel/kprobes/ftrace.c index dd2ec14adb77..c73f9ab7ff50 100644 --- a/arch/x86/kernel/kprobes/ftrace.c +++ b/arch/x86/kernel/kprobes/ftrace.c @@ -21,6 +21,9 @@ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip, struct kprobe_ctlblk *kcb; int bit; + if (unlikely(ftrace_is_dead())) + return; + bit = ftrace_test_recursion_trylock(ip, parent_ip); if (bit < 0) return; diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 54d53f345d14..ba83e99c1fbe 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -399,6 +399,7 @@ int ftrace_lookup_symbols(const char **sorted_syms, size_t cnt, unsigned long *a #define register_ftrace_function(ops) ({ 0; }) #define unregister_ftrace_function(ops) ({ 0; }) static inline void ftrace_kill(void) { } +static inline int ftrace_is_dead(void) { return 0; } static inline void ftrace_free_init_mem(void) { } static inline void ftrace_free_mem(struct module *mod, void *start, void *end) { } static inline int ftrace_lookup_symbols(const char **sorted_syms, size_t cnt, unsigned long *addrs) @@ -914,6 +915,7 @@ static inline bool is_ftrace_trampoline(unsigned long addr) /* totally disable ftrace - can not re-enable after this */ void ftrace_kill(void); +int ftrace_is_dead(void); static inline void tracer_disable(void) { diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 64450615ca0c..70a37ee41813 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -1026,7 +1026,6 @@ static inline int ftrace_trace_task(struct trace_array *tr) return this_cpu_read(tr->array_buffer.data->ftrace_ignore_pid) != FTRACE_PID_IGNORE; } -extern int ftrace_is_dead(void); int ftrace_create_function_files(struct trace_array *tr, struct dentry *parent); void ftrace_destroy_function_files(struct trace_array *tr); @@ -1046,7 +1045,6 @@ static inline int ftrace_trace_task(struct trace_array *tr) { return 1; } -static inline int ftrace_is_dead(void) { return 0; } static inline int ftrace_create_function_files(struct trace_array *tr, struct dentry *parent)