Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp131265pxh; Thu, 7 Apr 2022 16:20:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxjxOCvqG51oY71ro/+n9vSF+2dLxbgXFCAIGpl1N15ZUdLwv/rl9NojkyQuo2Zr8ST2Sf X-Received: by 2002:a63:b55d:0:b0:398:5eeb:e637 with SMTP id u29-20020a63b55d000000b003985eebe637mr12780974pgo.314.1649373636113; Thu, 07 Apr 2022 16:20:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649373636; cv=none; d=google.com; s=arc-20160816; b=mnhoD8kw8l/QdO5YJ9hxyZSOVNPl454g6Wxo4sREGPrD6vn4X3rtgGh2hjWki4xtqF 1YyEdZAh5XKmZtF21sSWxvhNz+ME2YWXQdecfVx/X/TIEKU9xtOV7ES9ybWyCyrWGtSD nqLWCgiAPf3hxlsIHA/lXcuXJGLWm8XMF1x4pecz82eYTyxHHXeVRaJPWRxK6F4Uv6Yp bp/XgrHM7vvJpq6HA25lKJ9d0SIqjiz+cVFsIY8w8iowaMfJOuIMhp3Lf3b0RQ+6PDI/ ZvALl7XEyd0/vyZw3s0oPttO2xd8nnrQT5COoTpw+iWKa9/Tf39YOiMT15DPFrQfwwfC T5RA== 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=ltxLhiqi4d+5I41C4sWjEL19BpFqpxKsoW4ZXNhcEnA=; b=HxIf37NOLKxdQtlTRFY4iFvKLvB7PPYeGzBzAfqClbBJP39pqwLLNvOaZwtrg+4a1G YFBJWcNNSP2VJZCJjDBXTYbKvfQmYYw/f7DlR+BAsvVnsgh2ZIGRPV7sbM++7V1Otfgn 8z5dMOtSneyj0YqOZdFYi8Z//ZkciDT2eEqi+yX6UAJ5GHdpFtkFv0CFFIkPHuiHtsa4 4VmTf4Nt3KQYAEdKK+oNqu6ZoU/7u3waLSa14KicMDT55YQuK1pSCz+zINSofua35CSx 0G8WnETkaeCVfMKDe/5gmmvGZSumP2+shev1LYP6XtiWNbzhIegGNVbPYcznYHHMWPJZ rFMg== 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 n9-20020a170903110900b00156ea908d59si1145200plh.304.2022.04.07.16.20.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 16:20:36 -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 68AFF16AA64; Thu, 7 Apr 2022 15:52:05 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232440AbiDGWxx (ORCPT + 99 others); Thu, 7 Apr 2022 18:53:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232406AbiDGWxv (ORCPT ); Thu, 7 Apr 2022 18:53:51 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DD69169B32 for ; Thu, 7 Apr 2022 15:51: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 C1CD8B82956 for ; Thu, 7 Apr 2022 22:51:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3583FC385A8; Thu, 7 Apr 2022 22:51:46 +0000 (UTC) Date: Thu, 7 Apr 2022 18:51: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: <20220407185144.5ac036b7@gandalf.local.home> In-Reply-To: <20220407215802.GB186606@roeck-us.net> References: <20220407161745.7d6754b3@gandalf.local.home> <20220407215802.GB186606@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 14:58:02 -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? That code you point out at emux.c looks extremely buggy as well. In other words, if you can't call del_timer_free() for the reason you mention above, the code is very likely to have race conditions. I cannot think of a situation that it is safe to do this. In fact, I think that just replacing that with del_timer_free() may be good enough. At least to show why it blows up later. I'm confused in what they are doing by taking that lock. I can see: CPU1 CPU2 ---- ---- snd_emux_timer_callback() spin_lock(voice_lock) if (timer_active) del_timer() spin_unlock(voice_lock) [..] do_again++ [..] if (do_again) { mod_timer() timer_active = 1; } [..] free(emu); BOOM!! Hmm, perhaps I should change the code in __mod_timer() to: if (WARN_ON(timer->flags & TIMER_FREED)) return; To not rearm it. -- Steve