Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6AFD2C00144 for ; Mon, 1 Aug 2022 10:49:51 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 5E2C4857; Mon, 1 Aug 2022 12:48:59 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 5E2C4857 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1659350989; bh=gHcEV0SEILLKvXWrYx1UbBCSpckPXxHpQvUsvC+OM5c=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=t/PwQtwpQt4eX0AOFk/U8CucWQ8ngZeH/srFAB8ZRrKd1Pe9LSJDXAqX36rO4whN/ TVBHHagATn6S4EIzZMpyIrC58FZmkuKKbPIkxVanQhFrvpNWCpYjI+ZqhRaJ1GqIi+ aDALHYigERHCUPR9BLuFUniH3sNkUfPAtiudIBls= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id EF06CF80152; Mon, 1 Aug 2022 12:48:58 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 9EFF7F8023B; Mon, 1 Aug 2022 12:48:57 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 8061DF8013D for ; Mon, 1 Aug 2022 12:48:50 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 8061DF8013D Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="r3bp/qQ6"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="RSEYKPia" Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 895754DA61; Mon, 1 Aug 2022 10:48:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1659350929; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=az74vuft2wC8E+2o3hgx4srhX55I77sEaizPCF+H688=; b=r3bp/qQ682wWiRijJJTVcim6F+KJnIbEYXEiJr3rBwKsQ8lGmZo+Yjj12lEe2JOrYYzMQs 88QvTPQZb5qEEBaQxs7HsTuc6pG8JP81YzVlY5mNqmBlW6s4oh95rjp9Sd6ragtqbT21rL T89uBjCmsxaB5kG60alfVr42Sh3N/6M= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1659350929; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=az74vuft2wC8E+2o3hgx4srhX55I77sEaizPCF+H688=; b=RSEYKPiaLmyfJSzWnjByKLjViGfBOxcUnWDNbxnSPOfW/V9g+IVN4V4wmWPEiIL+dD2Dcz UsTC4lh8KBjy9oCA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 6F83D13A72; Mon, 1 Aug 2022 10:48:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id lhJVGpGv52IebwAAMHmgww (envelope-from ); Mon, 01 Aug 2022 10:48:49 +0000 Date: Mon, 01 Aug 2022 12:48:49 +0200 Message-ID: <87y1w8me7i.wl-tiwai@suse.de> From: Takashi Iwai To: Jaroslav Kysela Subject: Re: [PATCH v2 1/4] ALSA: core: Add async signal helpers In-Reply-To: <408af362-0839-e4f0-8dea-15103b269836@perex.cz> References: <20220728125945.29533-1-tiwai@suse.de> <20220728125945.29533-2-tiwai@suse.de> <871qu0nuei.wl-tiwai@suse.de> <408af362-0839-e4f0-8dea-15103b269836@perex.cz> User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Cc: alsa-devel@alsa-project.org X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On Mon, 01 Aug 2022 12:43:36 +0200, Jaroslav Kysela wrote: > > On 01. 08. 22 12:13, Takashi Iwai wrote: > > On Mon, 01 Aug 2022 10:05:59 +0200, > > Jaroslav Kysela wrote: > >> > >> On 28. 07. 22 14:59, Takashi Iwai wrote: > >>> Currently the call of kill_fasync() from an interrupt handler might > >>> lead to potential spin deadlocks, as spotted by syzkaller. > >>> Unfortunately, it's not so trivial to fix this lock chain as it's > >>> involved with the tasklist_lock that is touched in allover places. > >>> > >>> As a temporary workaround, this patch provides the way to defer the > >>> async signal notification in a work. The new helper functions, > >>> snd_fasync_helper() and snd_kill_faync() are replacements for > >>> fasync_helper() and kill_fasync(), respectively. In addition, > >>> snd_fasync_free() needs to be called at the destructor of the relevant > >>> file object. > >>> > >>> Signed-off-by: Takashi Iwai > >> > >> ... > >> > >>> +void snd_kill_fasync(struct snd_fasync *fasync, int signal, int poll) > >>> +{ > >>> + unsigned long flags; > >>> + > >>> + if (!fasync || !fasync->on) > >>> + return; > >>> + spin_lock_irqsave(&snd_fasync_lock, flags); > >>> + fasync->signal = signal; > >>> + fasync->poll = poll; > >>> + list_move(&fasync->list, &snd_fasync_list); > >>> + schedule_work(&snd_fasync_work); > >>> + spin_unlock_irqrestore(&snd_fasync_lock, flags); > >>> +} > >> > >> The schedule_work() may be called outside the spinlock - it calls > >> queue_work_on() / __queue_work() which has already own protection for > >> the concurrent execution. > > > > It can be outside, too, but scheduling earlier reduces the possible > > unnecessary scheduling. Suppose that a list is added while the work > > is already running in another CPU. If we call schedule_work() outside > > this lock, it might be already the time after the work has processed > > the queued item, and hence it can be a superfluous scheduling call. > > It's really a negligible optimization. It would be better to not block > other CPUs here to allow insertion of the new event. Also the > __queue_work() is a bit complex code, so the call outside the spin > lock may be better. It depends on how often this code path is used. Supposing the rare use case of this, we don't need to care too much, IMO. And, if we really want better concurrency, it should be replaced with RCU :) > But either code is acceptable for me. As I've already queued the patches in the original form in the last week, let's keep it as is. thanks, Takashi