From mboxrd@z Thu Jan 1 00:00:00 1970 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 3426BC4167D for ; Mon, 28 Nov 2022 09:54:56 +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 EF12683B; Mon, 28 Nov 2022 10:54:04 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz EF12683B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1669629295; bh=pEdCzcnthDYNmOzhVuMXcyXl0uTgXK+CXHSjQ/ihJuA=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=k7bNQPqbQZiqiDkD3Q2Bo5vmnty7GvdvzQ7j5+34IAEy7DpO3zUhscRhgAoLr2KEe sWfBkVrVQZxekR1FCNTotjW1FCjCccC/lmJ2ZMRNM3Ekwx2DEHY1uwHPCckzkXy8BH 16906CzAOWyDoWqo44r8qEtORqKYaMn9C5UyLHw4= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 8D7E5F80166; Mon, 28 Nov 2022 10:54:04 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 5CEC9F8020D; Mon, 28 Nov 2022 10:54:03 +0100 (CET) Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) (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 86748F80166 for ; Mon, 28 Nov 2022 10:53:56 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 86748F80166 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="G75Y+Ue8"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="KmbZdHqO" 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-out2.suse.de (Postfix) with ESMTPS id 72F081FD99; Mon, 28 Nov 2022 09:53:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1669629236; 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=+hcAPsRKjwfGIqTFf3niuYUk+88SwB3jKyrNLAhms58=; b=G75Y+Ue8ViCx0MK6I4JA+FLD47vZQg56H6snFSCOa96tyv9r2F7qJa9gyapr9Bsvjd9XTS ZaWyejWENfaNzfx7yLm7O4Q8h8XD6nGbwJlZhZ+CtcN0e7diIG6XZzofVtsNVMM5zlSpCR XIBgBbnWMYf6a5tl5Q2JVRpdT6nHl4Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1669629236; 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=+hcAPsRKjwfGIqTFf3niuYUk+88SwB3jKyrNLAhms58=; b=KmbZdHqORB7knhE2TbaV0MNkNg41I+2A8pG5sCxSUwX9QXm3egsN6j2uNufWbg0gqix9j2 jcN8uQ/gy4NLV5AQ== 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 35A3C1326E; Mon, 28 Nov 2022 09:53:56 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ZZtJDDSFhGM0DQAAMHmgww (envelope-from ); Mon, 28 Nov 2022 09:53:56 +0000 Date: Mon, 28 Nov 2022 10:53:55 +0100 Message-ID: <87tu2jz9os.wl-tiwai@suse.de> From: Takashi Iwai To: Ricardo Ribalda Subject: Re: [PATCH v3 0/2] ALSA: core: Fix deadlock when shutdown a frozen userspace In-Reply-To: References: <20221127-snd-freeze-v3-0-a2eda731ca14@chromium.org> <87wn7fzb2g.wl-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: Len Brown , alsa-devel@alsa-project.org, Kai Vehmanen , "Rafael J. Wysocki" , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Ranjani Sridharan , Takashi Iwai , Mark Brown , Pavel Machek , "Joel Fernandes \(Google\)" , Pierre-Louis Bossart 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, 28 Nov 2022 10:26:36 +0100, Ricardo Ribalda wrote: > > Hi Takashi > > Thanks for your prompt reply > > On Mon, 28 Nov 2022 at 10:24, Takashi Iwai wrote: > > > > On Mon, 28 Nov 2022 10:10:12 +0100, > > Ricardo Ribalda wrote: > > > > > > Since 83bfc7e793b5 ("ASoC: SOF: core: unregister clients and machine drivers in .shutdown") > > > we wait for userspace to close its fds. > > > > IMO, the fix above brought more problem. If you'd need to want to > > avoid later accesses during shutdown, the driver should rather just > > disconnect devices without waiting for the user-space completion. > > And, for that, a simple call of snd_card_disconnect() should suffice. > > > > > But that will never occur with a frozen userspace (like during kexec()). > > > > > > Lets detect the frozen userpace and act accordingly. > > > > ... and skipping the user-space sync at snd_card_disconnect_sync() as > > of this patch set is a dangerous move, I'm afraid. The user-space > > gets frozen also at the normal suspend/resume, and it implies that the > > sync will be lost even for the normal PM, too (although it must be a > > very corner case). > > > > And what about checking kexec_in_progress instead? I still think that the call of snd_card_disconnect_sync() itself at shutdown is somehow wrong. If this only comes from the SOF code path above, we should address in that code path instead. OTOH, you showed two code paths: one is [ 84.943749] Freezing user space processes ... (elapsed 0.111 seconds) done. [ 246.784446] INFO: task kexec-lite:5123 blocked for more than 122 seconds. [ 246.819035] Call Trace: [ 246.821782] [ 246.824186] __schedule+0x5f9/0x1263 [ 246.828231] schedule+0x87/0xc5 [ 246.831779] snd_card_disconnect_sync+0xb5/0x127 ... [ 246.889249] snd_sof_device_shutdown+0xb4/0x150 [ 246.899317] pci_device_shutdown+0x37/0x61 [ 246.903990] device_shutdown+0x14c/0x1d6 [ 246.908391] kernel_kexec+0x45/0xb9 and another is [ 246.893222] INFO: task kexec-lite:4891 blocked for more than 122 seconds. [ 246.927709] Call Trace: [ 246.930461] [ 246.932819] __schedule+0x5f9/0x1263 [ 246.936855] ? fsnotify_grab_connector+0x5c/0x70 [ 246.942045] schedule+0x87/0xc5 [ 246.945567] schedule_timeout+0x49/0xf3 [ 246.949877] wait_for_completion+0x86/0xe8 [ 246.954463] snd_card_free+0x68/0x89 ... [ 247.001080] platform_device_unregister+0x12/0x35 The former is likely the SOF code path by the commit you mentioned (but it's not 100% clear because you trimmed the stack trace), and this should be reconsidered. But, the latter seems to be independent from that. If that's the code path where the unbind is triggered before kexec, your fix might not work, either; it could be already at the wait_event*() when kexec starts. Maybe a simpler workaround would be to replace it with wait_event_killable*() stuff. But whether we can discontinue the sync there is still another thing to consider... Takashi > > Thanks! > > > > > thanks, > > > > Takashi > > > > > > > > To: Jaroslav Kysela > > > To: Takashi Iwai > > > To: "Rafael J. Wysocki" > > > To: Pavel Machek > > > To: Len Brown > > > To: Kai Vehmanen > > > To: Ranjani Sridharan > > > To: Pierre-Louis Bossart > > > To: Mark Brown > > > Cc: alsa-devel@alsa-project.org > > > Cc: linux-kernel@vger.kernel.org > > > Cc: "Joel Fernandes (Google)" > > > Cc: linux-pm@vger.kernel.org > > > Signed-off-by: Ricardo Ribalda > > > --- > > > Changes in v3: > > > - Wrap pm_freezing in a function > > > - Link to v2: https://lore.kernel.org/r/20221127-snd-freeze-v2-0-d8a425ea9663@chromium.org > > > > > > Changes in v2: > > > - Only use pm_freezing if CONFIG_FREEZER > > > - Link to v1: https://lore.kernel.org/r/20221127-snd-freeze-v1-0-57461a366ec2@chromium.org > > > > > > --- > > > Ricardo Ribalda (2): > > > freezer: Add processes_frozen() > > > ALSA: core: Fix deadlock when shutdown a frozen userspace > > > > > > include/linux/freezer.h | 2 ++ > > > kernel/freezer.c | 11 +++++++++++ > > > sound/core/init.c | 13 +++++++++++++ > > > 3 files changed, 26 insertions(+) > > > --- > > > base-commit: 4312098baf37ee17a8350725e6e0d0e8590252d4 > > > change-id: 20221127-snd-freeze-1ee143228326 > > > > > > Best regards, > > > -- > > > Ricardo Ribalda > > > > > > > -- > Ricardo Ribalda > From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEA47C43217 for ; Mon, 28 Nov 2022 09:54:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230016AbiK1Jx7 (ORCPT ); Mon, 28 Nov 2022 04:53:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229773AbiK1Jx7 (ORCPT ); Mon, 28 Nov 2022 04:53:59 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E674F95BB; Mon, 28 Nov 2022 01:53:57 -0800 (PST) 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-out2.suse.de (Postfix) with ESMTPS id 72F081FD99; Mon, 28 Nov 2022 09:53:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1669629236; 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=+hcAPsRKjwfGIqTFf3niuYUk+88SwB3jKyrNLAhms58=; b=G75Y+Ue8ViCx0MK6I4JA+FLD47vZQg56H6snFSCOa96tyv9r2F7qJa9gyapr9Bsvjd9XTS ZaWyejWENfaNzfx7yLm7O4Q8h8XD6nGbwJlZhZ+CtcN0e7diIG6XZzofVtsNVMM5zlSpCR XIBgBbnWMYf6a5tl5Q2JVRpdT6nHl4Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1669629236; 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=+hcAPsRKjwfGIqTFf3niuYUk+88SwB3jKyrNLAhms58=; b=KmbZdHqORB7knhE2TbaV0MNkNg41I+2A8pG5sCxSUwX9QXm3egsN6j2uNufWbg0gqix9j2 jcN8uQ/gy4NLV5AQ== 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 35A3C1326E; Mon, 28 Nov 2022 09:53:56 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ZZtJDDSFhGM0DQAAMHmgww (envelope-from ); Mon, 28 Nov 2022 09:53:56 +0000 Date: Mon, 28 Nov 2022 10:53:55 +0100 Message-ID: <87tu2jz9os.wl-tiwai@suse.de> From: Takashi Iwai To: Ricardo Ribalda Cc: Takashi Iwai , Len Brown , Pierre-Louis Bossart , Kai Vehmanen , Ranjani Sridharan , Mark Brown , Jaroslav Kysela , Pavel Machek , "Rafael J. Wysocki" , alsa-devel@alsa-project.org, "Joel Fernandes (Google)" , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: Re: [PATCH v3 0/2] ALSA: core: Fix deadlock when shutdown a frozen userspace In-Reply-To: References: <20221127-snd-freeze-v3-0-a2eda731ca14@chromium.org> <87wn7fzb2g.wl-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 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org On Mon, 28 Nov 2022 10:26:36 +0100, Ricardo Ribalda wrote: > > Hi Takashi > > Thanks for your prompt reply > > On Mon, 28 Nov 2022 at 10:24, Takashi Iwai wrote: > > > > On Mon, 28 Nov 2022 10:10:12 +0100, > > Ricardo Ribalda wrote: > > > > > > Since 83bfc7e793b5 ("ASoC: SOF: core: unregister clients and machine drivers in .shutdown") > > > we wait for userspace to close its fds. > > > > IMO, the fix above brought more problem. If you'd need to want to > > avoid later accesses during shutdown, the driver should rather just > > disconnect devices without waiting for the user-space completion. > > And, for that, a simple call of snd_card_disconnect() should suffice. > > > > > But that will never occur with a frozen userspace (like during kexec()). > > > > > > Lets detect the frozen userpace and act accordingly. > > > > ... and skipping the user-space sync at snd_card_disconnect_sync() as > > of this patch set is a dangerous move, I'm afraid. The user-space > > gets frozen also at the normal suspend/resume, and it implies that the > > sync will be lost even for the normal PM, too (although it must be a > > very corner case). > > > > And what about checking kexec_in_progress instead? I still think that the call of snd_card_disconnect_sync() itself at shutdown is somehow wrong. If this only comes from the SOF code path above, we should address in that code path instead. OTOH, you showed two code paths: one is [ 84.943749] Freezing user space processes ... (elapsed 0.111 seconds) done. [ 246.784446] INFO: task kexec-lite:5123 blocked for more than 122 seconds. [ 246.819035] Call Trace: [ 246.821782] [ 246.824186] __schedule+0x5f9/0x1263 [ 246.828231] schedule+0x87/0xc5 [ 246.831779] snd_card_disconnect_sync+0xb5/0x127 ... [ 246.889249] snd_sof_device_shutdown+0xb4/0x150 [ 246.899317] pci_device_shutdown+0x37/0x61 [ 246.903990] device_shutdown+0x14c/0x1d6 [ 246.908391] kernel_kexec+0x45/0xb9 and another is [ 246.893222] INFO: task kexec-lite:4891 blocked for more than 122 seconds. [ 246.927709] Call Trace: [ 246.930461] [ 246.932819] __schedule+0x5f9/0x1263 [ 246.936855] ? fsnotify_grab_connector+0x5c/0x70 [ 246.942045] schedule+0x87/0xc5 [ 246.945567] schedule_timeout+0x49/0xf3 [ 246.949877] wait_for_completion+0x86/0xe8 [ 246.954463] snd_card_free+0x68/0x89 ... [ 247.001080] platform_device_unregister+0x12/0x35 The former is likely the SOF code path by the commit you mentioned (but it's not 100% clear because you trimmed the stack trace), and this should be reconsidered. But, the latter seems to be independent from that. If that's the code path where the unbind is triggered before kexec, your fix might not work, either; it could be already at the wait_event*() when kexec starts. Maybe a simpler workaround would be to replace it with wait_event_killable*() stuff. But whether we can discontinue the sync there is still another thing to consider... Takashi > > Thanks! > > > > > thanks, > > > > Takashi > > > > > > > > To: Jaroslav Kysela > > > To: Takashi Iwai > > > To: "Rafael J. Wysocki" > > > To: Pavel Machek > > > To: Len Brown > > > To: Kai Vehmanen > > > To: Ranjani Sridharan > > > To: Pierre-Louis Bossart > > > To: Mark Brown > > > Cc: alsa-devel@alsa-project.org > > > Cc: linux-kernel@vger.kernel.org > > > Cc: "Joel Fernandes (Google)" > > > Cc: linux-pm@vger.kernel.org > > > Signed-off-by: Ricardo Ribalda > > > --- > > > Changes in v3: > > > - Wrap pm_freezing in a function > > > - Link to v2: https://lore.kernel.org/r/20221127-snd-freeze-v2-0-d8a425ea9663@chromium.org > > > > > > Changes in v2: > > > - Only use pm_freezing if CONFIG_FREEZER > > > - Link to v1: https://lore.kernel.org/r/20221127-snd-freeze-v1-0-57461a366ec2@chromium.org > > > > > > --- > > > Ricardo Ribalda (2): > > > freezer: Add processes_frozen() > > > ALSA: core: Fix deadlock when shutdown a frozen userspace > > > > > > include/linux/freezer.h | 2 ++ > > > kernel/freezer.c | 11 +++++++++++ > > > sound/core/init.c | 13 +++++++++++++ > > > 3 files changed, 26 insertions(+) > > > --- > > > base-commit: 4312098baf37ee17a8350725e6e0d0e8590252d4 > > > change-id: 20221127-snd-freeze-1ee143228326 > > > > > > Best regards, > > > -- > > > Ricardo Ribalda > > > > > > > -- > Ricardo Ribalda >