Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp14580246rwb; Mon, 28 Nov 2022 02:48:27 -0800 (PST) X-Google-Smtp-Source: AA0mqf7sOhUS82u6MjelmJowHX/ARmEfb+WKaFMDK5vjssQHhC+lv5FGvS2g3sS7NEqEE3/UXGxb X-Received: by 2002:a17:906:1e4a:b0:78d:3505:6f3e with SMTP id i10-20020a1709061e4a00b0078d35056f3emr41564267ejj.611.1669632507477; Mon, 28 Nov 2022 02:48:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669632507; cv=none; d=google.com; s=arc-20160816; b=A00vwR5degi+02RJVIY2zm8/jmG5PKLzgOPuiOizSOwJ+TGPyaKdyM98ch7cgs6uIT V5qo1+4kF2sDSPS0gC8/UyBou2LnKDpjBMPIurGg91RbczT2u19nMiOQ6ngmpLAbehKq gf8fkFbIBjpQR/Q/mYsbncdz0ef36G6IO3506tBLCY+6Ae7kDHN+mycMffXTm1NQ3IfD LAVqIADjcyOuSyd0hTmTnl85wzLvUU2JTQioAwnEnrO7aY9++5U/FDtqD1VGePZdM3L9 17fY8i11GGTNfMFjcQVhKg1c/EkCBIPs5LSnLTl2T/SfSxVo+9NF2x+5wy3t2u0olsKH 7EqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature:dkim-signature; bh=+hcAPsRKjwfGIqTFf3niuYUk+88SwB3jKyrNLAhms58=; b=yh36MVcd+42zyZNUSjdCRxP8Ecv4OTP8kB+iYTiTCmrAdf1kq8RCefSU2b6WPXUWTj l7aca/FOuuZlJQyHtXO/D9ZF7gEVGX5ZT8KnQv2nA58CTi72vBYtMKV7jZ86oVpmLvbD gb5I8inbZRtETVa8dzl6+kf1m1cnXKZ6hO8m4uuk+MalzxmUiN33KGMYdHwB3h8fSkCk hmAfC1eoAVp7MS2ZZcnY9BQGUMy3xmSq6tLSWnz2rLYYn3F4hSYgnf4dDLbjxN3Zt/2S /hiuvk9hfGl1QTTD/bgU84fMc755QOYGEIaQiOHAIlJNXH3t8kg0n3rkrzhGQNFI3enj PWeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=G75Y+Ue8; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dz10-20020a0564021d4a00b0046b2966d088si2390029edb.502.2022.11.28.02.48.07; Mon, 28 Nov 2022 02:48:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=G75Y+Ue8; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230035AbiK1JyA (ORCPT + 84 others); Mon, 28 Nov 2022 04:54:00 -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 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham 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 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 >