Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp208309pxh; Thu, 7 Apr 2022 19:04:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyT/BymKI/OkrBKUKDszKxZgiTHaPlSAS2P2l8eqRK5Z6vpSQ4etapM2gNsYW7MNLwyBPbp X-Received: by 2002:a05:6a00:2311:b0:4e1:52bf:e466 with SMTP id h17-20020a056a00231100b004e152bfe466mr17206584pfh.77.1649383494285; Thu, 07 Apr 2022 19:04:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649383494; cv=none; d=google.com; s=arc-20160816; b=Jo9t/ptdtPZTIxm9oQNgN8fA0azkazT15lfvMYBrQK1C+6rlAJDfaA9FNDh99m3eW+ hzSutMyhCQpTRW+sDD/b0RjdvM3N9tyJQ/QxZ3sX3JeVfybRWl/Nyjh/2FHTtXsGhBfb 5cIn4dMxQZQ7jIhfbNI9/LLgL033ilLexozWPlbWRgKFz9nv10Av9BzyJgcAMfnXjdfJ JO8kC58g/8PojB9T5j+A1+Gqwtym80uENANGYMrIs/MC4pfe9ciKo8EkwucV451iN/uI 7XxJALVU+VnIAagKsWTEv1yPFsu6D/UWwYzhAISwLErZPtlP1Mub+VDzFB41WMaPfRDF CoDg== 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=idvXFNcAyCOx5orwxQXB2/wk4osNjUa9lpiW5SpKfVY=; b=KCE6sFPC0WMnd0uDy2vnfT2bImct6jfo3bpzS7iFmgZV+jIFKD9kMa34l6Vz9W92Tm msJaWWozg8oWKhV196128TxYFOh8DNXe7Npnar/kvd9HuC9zxu+FdhUPnaRHGXCR/3Xw xjjAU3dTxJWfM405pT1Xi5E9d1+JuHIGjwEsO4JcAWNZ+YsDYm3CyhUcN9EoTgFN2B71 8NnTJe9rEOpnJCQXQBMpuTUILXdrXG2r2qItLPuKy04SSOTDPdWqrGJ7GmEonoGXyfh6 iECU7QUk/SZikpF3e4fLvxMVees89+lAqFwvh2VS84620uZlaxcs+Yq/JEL6EGJr4qVS km1g== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id bg16-20020a056a02011000b003991d7cd361si14150824pgb.622.2022.04.07.19.04.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 19:04:54 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8683E25F3; Thu, 7 Apr 2022 18:36:56 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233472AbiDHBiy (ORCPT + 99 others); Thu, 7 Apr 2022 21:38:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233418AbiDHBiw (ORCPT ); Thu, 7 Apr 2022 21:38:52 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64C8610FAE8 for ; Thu, 7 Apr 2022 18:36:50 -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 20D0AB829B5 for ; Fri, 8 Apr 2022 01:36:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 873DCC385A0; Fri, 8 Apr 2022 01:36:46 +0000 (UTC) Date: Thu, 7 Apr 2022 21:36:44 -0400 From: Steven Rostedt To: Guenter Roeck Cc: LKML , Thomas Gleixner , jstultz@google.com, Stephen Boyd , Linus Torvalds , Andrew Morton , Peter Zijlstra , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , Eric Dumazet Subject: Re: [RFC][PATCH] timers: Add del_time_free() to be called before freeing timers Message-ID: <20220407213644.767ae1c7@gandalf.local.home> In-Reply-To: <63d4c8d8-89c6-33ed-8178-be9ea86e53b9@roeck-us.net> References: <20220407161745.7d6754b3@gandalf.local.home> <20220407215802.GB186606@roeck-us.net> <20220407185144.5ac036b7@gandalf.local.home> <63d4c8d8-89c6-33ed-8178-be9ea86e53b9@roeck-us.net> 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=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Thu, 7 Apr 2022 17:58:09 -0700 Guenter Roeck wrote: > >>> Add a del_timer_free() that not only does a del_timer_sync() but will mark > >> > >> This limits the use case to situations where del_timer_sync() can actually > >> be called. There is, however, code where this is not possible. > >> Specifically, it doesn't work if the code triggered with the timer uses a > >> lock, and del_timer() is also called under that same lock. An example for > >> that is the code in sound/synth/emux/emux.c. How do you suggest to handle > >> that situation ? > > > > Easy. Tell me how that situation is not a bug? > > > > Sure, fixing the problem is of course the right thing to do. But replacing > del_timer() with your suggested version of del_timer_free() doesn't work I meant replacing the entire block with del_timer_free(). diff --git a/sound/synth/emux/emux.c b/sound/synth/emux/emux.c index 5ed8e36d2e04..f631e090e074 100644 --- a/sound/synth/emux/emux.c +++ b/sound/synth/emux/emux.c @@ -131,10 +131,7 @@ int snd_emux_free(struct snd_emux *emu) if (! emu) return -EINVAL; - spin_lock_irqsave(&emu->voice_lock, flags); - if (emu->timer_active) - del_timer(&emu->tlist); - spin_unlock_irqrestore(&emu->voice_lock, flags); + del_timer_free(&emu->tlist); snd_emux_proc_free(emu); snd_emux_delete_virmidi(emu); It doesn't hurt to delete it if it wasn't queued. I'm not sure what the dance with spinlocks are all about. The above may actually be enough. I don't see where the timer could be enqueued again after that. That code goes back to original git history, so it was probably trying to do it's own del_timer_sync() albeit poorly. > with this code because it would deadlock. Sure, that would not fix the > underlying problem anyway, but that isn't the point I was trying to make: > I think it would be beneficial to be able to replace del_timer() with a > version that can not result in deadlocks but would still identify problems > such as the one in the code in emux.c. > > Can we have del_timer_free() and del_timer_sync_free() ? Or am I missing > something and that doesn't really make sense ? No, that doesn't make sense. -- Steve