Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3576917rwb; Tue, 20 Sep 2022 01:31:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM54Sj+hF/3ddR5HEd6jhaPwaETdwaU9XKlwc6Q4ifU9ICvCobTWg2WRXZ8M4gg/vRenkpND X-Received: by 2002:a17:902:ced0:b0:178:9bd4:b730 with SMTP id d16-20020a170902ced000b001789bd4b730mr3854330plg.36.1663662702247; Tue, 20 Sep 2022 01:31:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663662702; cv=none; d=google.com; s=arc-20160816; b=aLtDGbunqP4a2pJEdFmC4GtNcnkqQ7fbopGpShc2/tUKBFrwMyv0/wS2vCelEY6LPb aztnamrE2enjl0rjJrsSd1RUw46rMDw2NfEb1obL7ghwyCCCkg7isK8B6Za+mIDRUdt4 G3C1HqrFD+O+F87CdfQUw8T0f52aWBRf8ENu+Mu+8vkkp3oiwsW2WrARh9BM+JPoxIso XcYlDyaEi3pEyGQ8Vh71m/xGvdKzWCa9JM3mwJFAfEVJuTYVULItoYPv98Psb3OXTrhX pcl3JeKO1mpmZeNlfdtuFodHGAA5/Btx+oTmpru8h9lgCtQvVq4SCBHHYkdaohaJ2Tkd oUVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=uljKteLcdMKgaKi6NdCH43/cQ/kfBWDIxk28LfJDddc=; b=AFdP4oJIq/Y82nIWxx3nF7UsPXOQzpW8CQm2VCeNYrmHy+jgvAMGgJCUSQmNCsKxlc Lu0gLSOVveQ663zwXmhVLUhvkrZP7dY98pmxNZLhZ8yeZoBWVKggmJSyojYEtpZ0+zms 8bfyyfuTXSq+oBoPyBGDZA4o8Dvdh7hH44eiidBfXt+2FYNhM9d2PPgO+HqdxSlF1ghs 3RsrPYHOJeoX4E1Er/gK09C/L9m4ZLGiLbYobjK0BlHUNtCLhGbjev2jRIxT6csf4xdP KScddmLW/l/4jYPBag+IH8m8qTLtGE0VrSfRVsFYMOkoZ3vimxJ9Yc579NRxsyQm7tJ+ tpxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f9PSvtGC; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nh4-20020a17090b364400b0020388f845e9si4099435pjb.52.2022.09.20.01.31.30; Tue, 20 Sep 2022 01:31:42 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f9PSvtGC; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231195AbiITHo3 (ORCPT + 99 others); Tue, 20 Sep 2022 03:44:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231139AbiITHoH (ORCPT ); Tue, 20 Sep 2022 03:44:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7F9F5E644 for ; Tue, 20 Sep 2022 00:42:58 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 1F17862072 for ; Tue, 20 Sep 2022 07:42:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE9CDC433D6; Tue, 20 Sep 2022 07:42:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663659775; bh=nWPqcQ+k8fQn2uzfqc5Cff9bIXh9MOsUqh6sUrWx750=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=f9PSvtGCYG0K8iqdBca6m9ANsvqfiaBIBFyI36VFb4Z5mWHm4jYS5djU6gjAHlF2G aXFecMhNvuzYvmNRKlbWVKnP2nf1Ut+oF0hBToI9IvpkMqPC2lGOXt1J6tss1a8w1n vn1HoVR7Qbb3d6QF47tuyqrXHZ0RJW/dK3qSNm6iiP15OGfX4WqrGhVuP9sz6F5Xii cYH7rxC0mcC+8Rn4f2DASpYvbSFwnsItVKbayHJjrc78bWfSsn/A9/cE6rHoccDfbt HTMVeT8e0FbC9hK7qi0Xir8lW2R+ZzS68WjSxy8abbN+GXoL9uEYnduhR6p6SonnMN u3iMm452hjvcA== Message-ID: <53ba30f1-c867-f34e-b262-08df67ef26fb@kernel.org> Date: Tue, 20 Sep 2022 09:42:44 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: Re: [PATCH] trace/osnoise: Fix possible recursive locking in stop_per_cpu_kthreads To: Nico Pache , linux-kernel@vger.kernel.org Cc: rostedt@goodmis.org, mingo@redhat.com References: <20220919144932.3064014-1-npache@redhat.com> Content-Language: en-US From: Daniel Bristot de Oliveira In-Reply-To: <20220919144932.3064014-1-npache@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, 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 Hi Nico! On 9/19/22 16:49, Nico Pache wrote: > There is a recursive lock on the cpu_hotplug_lock. > > In kernel/trace/trace_osnoise.c:_per_cpu_kthreads: > - start_per_cpu_kthreads calls cpus_read_lock() and if > start_kthreads returns a error it will call stop_per_cpu_kthreads. > - stop_per_cpu_kthreads then calls cpus_read_lock() again causing > deadlock. Yep, I see the problem. > Fix this by calling cpus_read_unlock() before calling > stop_per_cpu_kthreads. This behavior can also be seen in commit > f46b16520a08 ("trace/hwlat: Implement the per-cpu mode"). Correct, we have a similar function that *without* this problem. > This error was noticed during the LTP ftrace-stress-test: > > WARNING: possible recursive locking detected > -------------------------------------------- > sh/275006 is trying to acquire lock: > ffffffffb02f5400 (cpu_hotplug_lock){++++}-{0:0}, at: stop_per_cpu_kthreads > > but task is already holding lock: > ffffffffb02f5400 (cpu_hotplug_lock){++++}-{0:0}, at: start_per_cpu_kthreads > > other info that might help us debug this: > Possible unsafe locking scenario: > > CPU0 > ---- > lock(cpu_hotplug_lock); > lock(cpu_hotplug_lock); > > *** DEADLOCK *** > > May be due to missing lock nesting notation > > 3 locks held by sh/275006: > #0: ffff8881023f0470 (sb_writers#24){.+.+}-{0:0}, at: ksys_write > #1: ffffffffb084f430 (trace_types_lock){+.+.}-{3:3}, at: rb_simple_write > #2: ffffffffb02f5400 (cpu_hotplug_lock){++++}-{0:0}, at: start_per_cpu_kthreads > > Fixes: c8895e271f79 ("trace/osnoise: Support hotplug operations") > Signed-off-by: Nico Pache Acked-by: Daniel Bristot de Oliveira Thanks! -- Daniel