From patchwork Wed Nov 30 16:29:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13060062 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 44B03C433FE for ; Wed, 30 Nov 2022 16:31:22 +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 718F81674; Wed, 30 Nov 2022 17:30:30 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 718F81674 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1669825880; bh=1Eimjbcycq7qNsawd2rnV+J25oc3+SKoshi04EAzFkY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=MMwI5ykHAOZSnOuaJsWThrYshAt1g5MtEzatm7FFLF2mypT2D0/+zFBeaY2j9GJgL POQn8izCxmcGe1Z3d5QQkM2RRQ4SdZ2wWd30Vmxts+fflHMxDjRHVwX/t7SD4wodEj 4olPz+QUBPJLKHFF36N+Ga14Gr6A2tsG87C/TzoI= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 8824FF80568; Wed, 30 Nov 2022 17:29:59 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id C33A8F80567; Wed, 30 Nov 2022 17:29:57 +0100 (CET) Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) (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 4FC10F804FF for ; Wed, 30 Nov 2022 17:29:45 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 4FC10F804FF Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="n0aRt/pd" Received: by mail-ej1-x633.google.com with SMTP id b2so26370375eja.7 for ; Wed, 30 Nov 2022 08:29:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=j66AM6yEw+h2e5Qpe0Paz47YsLXnYSCCs7ToLjEkFbE=; b=n0aRt/pdbaNOD5yGncwAgWDPkLo4jlUKxpzjr6sOKj98U8h4lH/BuCf4E3aibhIRBJ mgsFuYISxGomjVjanltzfkXr0OmE8zIMPNJVZmWtULUGeuvNnWRKvfo7UYAzQrT/XiKP pFNUvT7rXmw2LZ9GHzQ1Ro0ndCmzNOfulp4PU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=j66AM6yEw+h2e5Qpe0Paz47YsLXnYSCCs7ToLjEkFbE=; b=Ei7aK3gJKWd0OI789hDUXmGrsDuFjkPgSqxyfmzeBI83mkprEzIPh1rP953Fl0ZKjL 6tUHmv2rl7wVY8AOJvaS7TrJKmu9lHK3DKwaQMvX8aHcwjXIxQi0mvqepBHFbz3HhS38 sHAwaNZ1YRYIQ6JkBPgWDawKd4a9nka1Ryj6e0MVQWL1A6S6vnYpOa1Mj2QMQ51yGGuF Mv7I6PbTG4H12t3Rvh2JchLhOPVSx47xXV3cTCmImx4Oqh9omHOzOa1WLfivpbkS3rT3 b3Iu2dRqyBI1lgcTDadkQM4CW6UmfnGMxELlS4bAJBjLGQz+BqyBBI49kOmzxSFhvJKD UFfg== X-Gm-Message-State: ANoB5pmlDve74izXr3+TQMPOO86baEp+JzV5LZNOAWW9SNBtMRq1dqrv u2iNfNSLrPXn/wbot21dAKKlDA== X-Google-Smtp-Source: AA0mqf5t+AxtPgn9XE9oAuO13iEBvxrVJRUaFve2VxlhVUExpKerWrweeRvgV18uCHkh3j71qtM0WA== X-Received: by 2002:a17:906:d281:b0:782:7790:f132 with SMTP id ay1-20020a170906d28100b007827790f132mr36684458ejb.649.1669825783467; Wed, 30 Nov 2022 08:29:43 -0800 (PST) Received: from alco.roam.corp.google.com (80.71.134.83.ipv4.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id cz15-20020a0564021caf00b004589da5e5cesm786114edb.41.2022.11.30.08.29.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Nov 2022 08:29:43 -0800 (PST) From: Ricardo Ribalda Date: Wed, 30 Nov 2022 17:29:20 +0100 Subject: [PATCH v7 1/2] kexec: Introduce kexec_with_frozen_processes MIME-Version: 1.0 Message-Id: <20221127-snd-freeze-v7-1-127c582f1ca4@chromium.org> References: <20221127-snd-freeze-v7-0-127c582f1ca4@chromium.org> In-Reply-To: <20221127-snd-freeze-v7-0-127c582f1ca4@chromium.org> To: Steven Rostedt , Peter Ujfalusi , Pierre-Louis Bossart , Jaroslav Kysela , Kai Vehmanen , Chromeos Kdump , Mark Brown , Ranjani Sridharan , Eric Biederman , Bard Liao , Daniel Baluta , Liam Girdwood , Takashi Iwai X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=1993; i=ribalda@chromium.org; h=from:subject:message-id; bh=1Eimjbcycq7qNsawd2rnV+J25oc3+SKoshi04EAzFkY=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjh4Tx9PZMNMSbqgT4Zoi7Sgxh6fRc9tbmVbCyGYlc GC5OS5KJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY4eE8QAKCRDRN9E+zzrEiGYkD/ 92N9Y4V14IUNRrC8n+NTCv5nr0Wh9MTAk9THEm+4TIUCb3UqoCmq2H9bF+N8XEN7J+RjxcUMQ0l/xe eA1eVXygt0w07oYoesMwZ8P7LTlvhN2Jkm9ePDQAcWLVFjgGixsThZokKgDa52sWE+eccR9biUr/Mu C4mLr7I+i1qYzVsANymbClIuaNEJPCGeHNqRSGCBOocwyqSWkSZEqHGIifb6LBHiecliMPwC4p36F0 yAhSh//F1oavhYQ/FQ2LMRG2/JMI6bTknYSGNyH/fTctVslP9foINRXJ3hAChrfxKlytpyG9mDWxfk UVN/LaV9JBwmwyJ2qwiqUB+l4s9LYU9QV+lwwOHZX15hcCfmZyB0AtcroP6Z48I6ERTbXa7Ng1Y5jJ V2A9QJAeZat9nfEwQsxpJxi1TLPsmQgBcjuTUZaYWxbjymLBC7u+4RWeJDjvSi0m29D8XhOgD+igKV aswBMZwtgA6SkzeIY/fP3el9EjPT8GQTYKoK2b//ArUC0pW5UCPiJ1OK4JzJkkF9E6P20/8dvtJk9h 2hFLnUS8s8iJ7aTazJ2WGGRPmRzzaDaK/YPbNZOiz7fbHWMbEB+spCGEX25Dgajb/qft6Ed3s1Aphi Fw++kttBHt8qnh2ZGuWwVaNdTPJY6vGashuAdgbrvcW/Pj/Jis2FalTkK9qA== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 Cc: alsa-devel@alsa-project.org, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Ricardo Ribalda , sound-open-firmware@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" Drivers running .shutdown() might want to wait for userspace to complete before exiting. If userspace is frozen and we are running kexec they will stall the computer. Add a way for them to figure out if they should just skip waiting for userspace. Cc: stable@vger.kernel.org Fixes: 83bfc7e793b5 ("ASoC: SOF: core: unregister clients and machine drivers in .shutdown") Signed-off-by: Ricardo Ribalda --- include/linux/kexec.h | 3 +++ kernel/kexec_core.c | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 41a686996aaa..c22711e0f7b5 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -426,6 +426,8 @@ extern int kexec_load_disabled; /* flag to track if kexec reboot is in progress */ extern bool kexec_in_progress; +bool kexec_with_frozen_processes(void); + int crash_shrink_memory(unsigned long new_size); ssize_t crash_get_memory_size(void); @@ -507,6 +509,7 @@ static inline void __crash_kexec(struct pt_regs *regs) { } static inline void crash_kexec(struct pt_regs *regs) { } static inline int kexec_should_crash(struct task_struct *p) { return 0; } static inline int kexec_crash_loaded(void) { return 0; } +static inline bool kexec_with_frozen_processes(void) { return false; } #define kexec_in_progress false #endif /* CONFIG_KEXEC_CORE */ diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c index ca2743f9c634..8bc8257ee7ca 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c @@ -54,6 +54,11 @@ note_buf_t __percpu *crash_notes; /* Flag to indicate we are going to kexec a new kernel */ bool kexec_in_progress = false; +bool kexec_with_frozen_processes(void) +{ + return kexec_in_progress && pm_freezing; +} +EXPORT_SYMBOL(kexec_with_frozen_processes); /* Location of the reserved area for the crash kernel */ struct resource crashk_res = { From patchwork Wed Nov 30 16:29:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13060063 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 52E29C433FE for ; Wed, 30 Nov 2022 16:31:28 +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 83A4E1702; Wed, 30 Nov 2022 17:30:36 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 83A4E1702 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1669825886; bh=s0WnrFHmqOACfzcMu26gBeBYl3edpjiybthmxKpH+/s=; h=From:Date:Subject:References:In-Reply-To:To:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=EwIhRLBPpMBa9z1inwc7y1ahCo0GvXPp4a2eb43KxCzgxmekBH8XPepS9Tm4H+FZY 1Y5wd0rWm36kAc0g8p3ADzrfkqNutXmopPmJSOSg0DDhqPdZDrL3FsrbVDCsb1u7dn mgnLEz44iP+YLyFouNlZ95zBtLWtpqsq2loVQEis= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 6C487F80578; Wed, 30 Nov 2022 17:30:00 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 013FCF80567; Wed, 30 Nov 2022 17:29:57 +0100 (CET) Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) (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 69BC6F80166 for ; Wed, 30 Nov 2022 17:29:46 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 69BC6F80166 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="mOuVUHz6" Received: by mail-ed1-x536.google.com with SMTP id z92so14340058ede.1 for ; Wed, 30 Nov 2022 08:29:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=6ETFY98Djerultq4KLtR6AVoerFeGGcqSarOrF7urjY=; b=mOuVUHz6VN9M0sllJmsb8AWyBmul/XEfCrj9eIQSCZjFUDF2baPxWJOeDVOMZSnvsC oM6RwONvZ3w12cZNmJ2WZFy0tsZnMQ+WSa7DS7CobK466Rr9nc5/LzgOdRYMc+GKKsFD WvEoE1qPjS5SexDn61VP+p0uIRiEE8bDv8VtY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6ETFY98Djerultq4KLtR6AVoerFeGGcqSarOrF7urjY=; b=HruN4+5bEysikMlPz+0shFNL2DuJnXCUniYdwcs81lEyNcb/UW66GIO5ajPwtjPEPW bI/l6PSakZgyz+VwUQH0fRrftEx3b/rw+CvcSeGEgnn+2m7EnsM7DgjpFsbQVF8Oaf2I DWM2i/IuqGdOJEezBatHb3lTLvKjCcVzPtA1i3/gPCaIWFcYWyM71tBidn4aYmSSwkIA m96AmEiXLwwR8NDbuwFgLrW8GqAuLIP0FJgNHHhgCCvNSohxUVjROBYEdMzVpDgiqnxk DXhXiNGGNCwSBBlnAjgwdqPOFW4TKou8zVe0kYf0DoY4kNJ6o1bl+EFMWlihhOYjZpaB vMAg== X-Gm-Message-State: ANoB5plH8BAnrGwjaThTrGhfui4x5al2CWPgSGgYBksKcJb+uQJOd4aY g9AYhfPoKUMldRZIi0jDvtYwDw== X-Google-Smtp-Source: AA0mqf4PjxFiboFRsFVuSbBdqbmaMnkL1+svg0ftRlMBulSysWMsHV2ZIZrCJx8REYR+ImWj8qndAA== X-Received: by 2002:a05:6402:3226:b0:461:37c2:e85c with SMTP id g38-20020a056402322600b0046137c2e85cmr46479326eda.74.1669825784487; Wed, 30 Nov 2022 08:29:44 -0800 (PST) Received: from alco.roam.corp.google.com (80.71.134.83.ipv4.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id cz15-20020a0564021caf00b004589da5e5cesm786114edb.41.2022.11.30.08.29.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Nov 2022 08:29:44 -0800 (PST) From: Ricardo Ribalda Date: Wed, 30 Nov 2022 17:29:21 +0100 Subject: [PATCH v7 2/2] ASoC: SOF: Fix deadlock when shutdown a frozen userspace MIME-Version: 1.0 Message-Id: <20221127-snd-freeze-v7-2-127c582f1ca4@chromium.org> References: <20221127-snd-freeze-v7-0-127c582f1ca4@chromium.org> In-Reply-To: <20221127-snd-freeze-v7-0-127c582f1ca4@chromium.org> To: Steven Rostedt , Peter Ujfalusi , Pierre-Louis Bossart , Jaroslav Kysela , Kai Vehmanen , Chromeos Kdump , Mark Brown , Ranjani Sridharan , Eric Biederman , Bard Liao , Daniel Baluta , Liam Girdwood , Takashi Iwai X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=2186; i=ribalda@chromium.org; h=from:subject:message-id; bh=s0WnrFHmqOACfzcMu26gBeBYl3edpjiybthmxKpH+/s=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjh4Tz1DIcr4kWbbZ1fXNR7GOJEmWiNmJULPm1G4vq 7JEKT8SJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY4eE8wAKCRDRN9E+zzrEiCmTD/ 9r90EMfLYitLj+CAj5pTW15Y84UH1h3P61FQVh32MliSSUHIdaXNjseCKrv7e+tRpc41lSmcj/OW74 WxrUoPxQ1Hktiy++0SXNp4dS91cD+tbXSaBxWj4qoKjJOq0JH+W60hWylFoZ2/Om+iyC2ul4p4tlqS dLqbMKMExGlamGKbby4s30fBpiAf8AlaeucTa92XDjOkMh27VVRldIAwqJWJopV9PuD8JzoMUGZ90L /bXspDsLDMWxAklJhaDhZXnyaUb/nXV4fyfpMkrIVptlxBnU7Bjt7lnxMRO6nmXIE0ukVeedXvacU5 8mxayfCFK1shZEtL7dOFQsmKWJFX3dFCX6NGYbw1A452mgfZZS4rLwkVpBlzKdrir8u6NwERyd5sEI InfH5v89rrFOTctLuieBszRFPTd6pZhoS0reV7c1tyqR87MJvAXGNdvnEJawj9LSFmQXUOF3fxBho+ NXeyIahMvQZrYm43EwYWLNdvflN+eBi5mRkOWJlLb1IsHfDZdZV3Esdzse4iw2k/dHLRN2j2cN4NMq evboar7x2Z0aZo1yEP9zFjFAS3V7tnv2ZayHWT3F5veuN2sPxKpy4/MQSY8tibH0uGYZDi7/UCdIlX 4+H6VL5A+bSxCSTd/vzO13wZs8Y+XagJNmDmIxBL/e3Tf4M7ZjMznFTHqfuw== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 Cc: alsa-devel@alsa-project.org, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Ricardo Ribalda , sound-open-firmware@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" During kexec(), the userspace might frozen. Therefore we cannot wait for it to complete. During a kexec with frozen processe do not unregister the clients. This fixes: [ 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: [ 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 Cc: stable@vger.kernel.org Fixes: 83bfc7e793b5 ("ASoC: SOF: core: unregister clients and machine drivers in .shutdown") Signed-off-by: Ricardo Ribalda --- sound/soc/sof/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sound/soc/sof/core.c b/sound/soc/sof/core.c index 3e6141d03770..4301f347bb90 100644 --- a/sound/soc/sof/core.c +++ b/sound/soc/sof/core.c @@ -9,6 +9,7 @@ // #include +#include #include #include #include @@ -484,7 +485,8 @@ int snd_sof_device_shutdown(struct device *dev) * make sure clients and machine driver(s) are unregistered to force * all userspace devices to be closed prior to the DSP shutdown sequence */ - sof_unregister_clients(sdev); + if (!kexec_with_frozen_processes()) + sof_unregister_clients(sdev); snd_sof_machine_unregister(sdev, pdata);