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 46A8DC00144 for ; Mon, 1 Aug 2022 10:14:45 +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 92BB61622; Mon, 1 Aug 2022 12:13:53 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 92BB61622 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1659348883; bh=S6YXp6giJwghFbfK4thEHyHWnvfDGlvW5+zBnCyBGhc=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ML4mY30NF6up6kWPoKwBBEfSoVj+j/MzmHYma6sbDo++AICqbZN1Nq1I7Z5oraOCT cj0iWE/yHweNs+sxTJgUMsjdKsF7I9KV8jX7QdXCB0zgf9mKKzyXpPN9addU45ZY2d u9Zkt5o3xCGH14hcCoattG3kcjfbH/RCDq7kItx0= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 259D4F80152; Mon, 1 Aug 2022 12:13:53 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 4ECE1F80246; Mon, 1 Aug 2022 12:13:51 +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 28572F8014B for ; Mon, 1 Aug 2022 12:13:42 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 28572F8014B Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="o9nnGZZo"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="NTqz01wf" 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 F09714D957; Mon, 1 Aug 2022 10:13:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1659348821; 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=7THYvZ0O7wCVbf7liqSCw2uPlvSZ9IGRNnLo7dEv32s=; b=o9nnGZZoAZPyy9KjNB29nd0LJqaCzbO9KiZXzTCaK0sN4pOVf47VYVVIKHcvsZELtFho1Z +fRkMCYO6zJVVr4lYijRTHWmtS6GI6YQxT5VJIO5QoMuNOBh4X9PVoZ+jONxQxSbxIEtio uI9v5ErQY7X08wEFVOGWGDRw34Y/Bfk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1659348821; 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=7THYvZ0O7wCVbf7liqSCw2uPlvSZ9IGRNnLo7dEv32s=; b=NTqz01wfkXSNMxNj6xerijz/Y7F2GNT3mfXkuwvk4QksTxNh2gXBoYzKTwbL3MLFn+IyQe UAgoAYgO2kMNntCw== 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 CB1A213AAE; Mon, 1 Aug 2022 10:13:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id QiNzMFWn52J0XwAAMHmgww (envelope-from ); Mon, 01 Aug 2022 10:13:41 +0000 Date: Mon, 01 Aug 2022 12:13:41 +0200 Message-ID: <871qu0nuei.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: References: <20220728125945.29533-1-tiwai@suse.de> <20220728125945.29533-2-tiwai@suse.de> 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 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. thanks, Takashi