Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1326043rwb; Tue, 27 Sep 2022 11:22:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM43HIEao1jBN9aOX7Kg5AZJMWfm7ZOFwf/1NkfuH0XZI+IA+9btes46QY6M0Wior7kSCUNq X-Received: by 2002:a17:902:d508:b0:178:b7b1:beb3 with SMTP id b8-20020a170902d50800b00178b7b1beb3mr28767294plg.102.1664302928736; Tue, 27 Sep 2022 11:22:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664302928; cv=none; d=google.com; s=arc-20160816; b=dyPbUnPR+hfjk1X1AmXlK7fx+3SPvqLz0fMWKPCa6TK80rC1CLdp2RGqzMz0C+x6VX KYCLn71Xa1qkPChybUIfuwHAknrO6hRHbehDhZ7WGfuw0NCA0ZF6SxhYb9oS5k3k4XTD +S5hKNyCgfE2/5JuaNbcCZf3x3Qjzvu3dabxqLctZgj+Rcq0WFlL3GKHUB/1tRzzMDhq 3Fs6lcLOBLwyZlk+czq3Bs99w+SsccKmp04zzcWTCGEl/je1wRTOhMcDN++dluT0dQIx fB9l9C6yYinajtpBMraxjlcAalyJqjhIM3/6L/SU9hHiyhF1y6NyLCGBB4fM5kMliGBa ZuTA== 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 :references:in-reply-to:message-id:subject:cc:to:from:date; bh=cTJfA9bo0GCQ4hdYdmxf9+98LbfPjLovm76PKXW8mgk=; b=GhkMcRocGNnCYzcenXrl3hdBXHGOhSy28hPeHu1oZf+6LKnqdr9sXcc6FNkSVsG/41 bAeyN7xlXVe4EIHMkCGcHfeZHY6FU4Bfj6BZmKz2J4RrTlphkOEXBGBqYXdzTZJjFfCw PVG3gb8/Hc9+OazTCxwArvafqKrXJ2zfp1J2BTBElAXBnSZCm7xCXHuYOs5IQ9fdK1zp +Oa2b5lxN52bmJQ13ki3YCnuXC4OLR1snrVcjFweAvjNMQnrVV8yU3tzjTbFduUAVcK0 3wqsHppkUeizlKTA+SKWN0cM6wSixxhls3cBL/iXB2muSFw4yzfnc2s+eG2hXobSbJ+X 9KmA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u7-20020a17090341c700b001755d722578si2870898ple.524.2022.09.27.11.21.57; Tue, 27 Sep 2022 11:22:08 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231854AbiI0QeE (ORCPT + 99 others); Tue, 27 Sep 2022 12:34:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232667AbiI0Qd6 (ORCPT ); Tue, 27 Sep 2022 12:33:58 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 690FD1D88DE for ; Tue, 27 Sep 2022 09:33:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id EC9DCB81C5B for ; Tue, 27 Sep 2022 16:33:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F888C433D6; Tue, 27 Sep 2022 16:33:51 +0000 (UTC) Date: Tue, 27 Sep 2022 12:35:00 -0400 From: Steven Rostedt To: Song Liu Cc: , , "Naveen N . Rao" Subject: Re: [PATCH v2] ftrace: fix recursive locking direct_mutex in ftrace_modify_direct_caller Message-ID: <20220927123500.76b07f73@gandalf.local.home> In-Reply-To: <20220927004146.1215303-1-song@kernel.org> References: <20220927004146.1215303-1-song@kernel.org> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS 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 Minor nit, just change the subject to start with a capital letter. ftrace: Fix recursive locking direct_mutex in ftrace_modify_direct_caller Other than that, this looks good. Do you want to put this through your tree, or do you want me to take it? Reviewed-by: Steven Rostedt (Google) -- Steve On Mon, 26 Sep 2022 17:41:46 -0700 Song Liu wrote: > Naveen reported recursive locking of direct_mutex with sample > ftrace-direct-modify.ko: > > [ 74.762406] WARNING: possible recursive locking detected > [ 74.762887] 6.0.0-rc6+ #33 Not tainted > [ 74.763216] -------------------------------------------- > [ 74.763672] event-sample-fn/1084 is trying to acquire lock: > [ 74.764152] ffffffff86c9d6b0 (direct_mutex){+.+.}-{3:3}, at: \ > register_ftrace_function+0x1f/0x180 > [ 74.764922] > [ 74.764922] but task is already holding lock: > [ 74.765421] ffffffff86c9d6b0 (direct_mutex){+.+.}-{3:3}, at: \ > modify_ftrace_direct+0x34/0x1f0 > [ 74.766142] > [ 74.766142] other info that might help us debug this: > [ 74.766701] Possible unsafe locking scenario: > [ 74.766701] > [ 74.767216] CPU0 > [ 74.767437] ---- > [ 74.767656] lock(direct_mutex); > [ 74.767952] lock(direct_mutex); > [ 74.768245] > [ 74.768245] *** DEADLOCK *** > [ 74.768245] > [ 74.768750] May be due to missing lock nesting notation > [ 74.768750] > [ 74.769332] 1 lock held by event-sample-fn/1084: > [ 74.769731] #0: ffffffff86c9d6b0 (direct_mutex){+.+.}-{3:3}, at: \ > modify_ftrace_direct+0x34/0x1f0 > [ 74.770496] > [ 74.770496] stack backtrace: > [ 74.770884] CPU: 4 PID: 1084 Comm: event-sample-fn Not tainted ... > [ 74.771498] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), ... > [ 74.772474] Call Trace: > [ 74.772696] > [ 74.772896] dump_stack_lvl+0x44/0x5b > [ 74.773223] __lock_acquire.cold.74+0xac/0x2b7 > [ 74.773616] lock_acquire+0xd2/0x310 > [ 74.773936] ? register_ftrace_function+0x1f/0x180 > [ 74.774357] ? lock_is_held_type+0xd8/0x130 > [ 74.774744] ? my_tramp2+0x11/0x11 [ftrace_direct_modify] > [ 74.775213] __mutex_lock+0x99/0x1010 > [ 74.775536] ? register_ftrace_function+0x1f/0x180 > [ 74.775954] ? slab_free_freelist_hook.isra.43+0x115/0x160 > [ 74.776424] ? ftrace_set_hash+0x195/0x220 > [ 74.776779] ? register_ftrace_function+0x1f/0x180 > [ 74.777194] ? kfree+0x3e1/0x440 > [ 74.777482] ? my_tramp2+0x11/0x11 [ftrace_direct_modify] > [ 74.777941] ? __schedule+0xb40/0xb40 > [ 74.778258] ? register_ftrace_function+0x1f/0x180 > [ 74.778672] ? my_tramp1+0xf/0xf [ftrace_direct_modify] > [ 74.779128] register_ftrace_function+0x1f/0x180 > [ 74.779527] ? ftrace_set_filter_ip+0x33/0x70 > [ 74.779910] ? __schedule+0xb40/0xb40 > [ 74.780231] ? my_tramp1+0xf/0xf [ftrace_direct_modify] > [ 74.780678] ? my_tramp2+0x11/0x11 [ftrace_direct_modify] > [ 74.781147] ftrace_modify_direct_caller+0x5b/0x90 > [ 74.781563] ? 0xffffffffa0201000 > [ 74.781859] ? my_tramp1+0xf/0xf [ftrace_direct_modify] > [ 74.782309] modify_ftrace_direct+0x1b2/0x1f0 > [ 74.782690] ? __schedule+0xb40/0xb40 > [ 74.783014] ? simple_thread+0x2a/0xb0 [ftrace_direct_modify] > [ 74.783508] ? __schedule+0xb40/0xb40 > [ 74.783832] ? my_tramp2+0x11/0x11 [ftrace_direct_modify] > [ 74.784294] simple_thread+0x76/0xb0 [ftrace_direct_modify] > [ 74.784766] kthread+0xf5/0x120 > [ 74.785052] ? kthread_complete_and_exit+0x20/0x20 > [ 74.785464] ret_from_fork+0x22/0x30 > [ 74.785781] > > Fix this by using register_ftrace_function_nolock in > ftrace_modify_direct_caller. > > Fixes: 53cd885bc5c3 ("ftrace: Allow IPMODIFY and DIRECT ops on the same function") > Reported-and-tested-by: Naveen N. Rao > Signed-off-by: Song Liu >