From patchwork Mon Nov 28 09:10:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13057170 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 880B6C433FE for ; Mon, 28 Nov 2022 09:12:01 +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 059C6168E; Mon, 28 Nov 2022 10:11:09 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 059C6168E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1669626719; bh=4IJsRzjRUBmI8ELm76XeH219TKYxoCY1FpvtAWp9NN8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=bdvtz2xRvPoHs0x4ddV6zOrrWTkBUqUHAxFrAjtJQZJzWzYq2LbMIjvMEUjGSwXK0 2cI5N19mYGkOBUgnkRry+NqPxpLAazPiy50zv8IAOuSlKOFhfGP1+p5O22pa6u2XyO eh3KrmSuole6REySQRx5No9bkE0LI/NBqsK+pM6k= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 9E4B3F8028B; Mon, 28 Nov 2022 10:10:49 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id D2826F800B6; Mon, 28 Nov 2022 10:10:45 +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 790CDF8016E for ; Mon, 28 Nov 2022 10:10:38 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 790CDF8016E Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Y7Z/PxFa" Received: by mail-ej1-x633.google.com with SMTP id ud5so24125361ejc.4 for ; Mon, 28 Nov 2022 01:10:38 -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=0C3tubLwb2GLSH1X3VvRqQXs2H60xiiDuvmjMSeKtSo=; b=Y7Z/PxFaD/VnaXhXyOGe1ep7kAm/dknEPXug0yeRdRkaUlQkVv9MCvcaYEiJvLRkry lrCXQY1WoeLSJF2Z7gMjS6IbqVD1pg69EtBDV99XqW42zef9KsDOYIqKUd+OeVB9qiVy +H1ykGL80zvjtHMdSMcV9/mXB6AqG1c8naFrQ= 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=0C3tubLwb2GLSH1X3VvRqQXs2H60xiiDuvmjMSeKtSo=; b=p0lKdjilc4uonif++8eTb78KsT/d/tt3XnuX2L0m95PZgFofmUcI2N2O+A0wc5GF03 cTvjFUibMFjUHWvqbnxIWiFDJ0pueZEba8P/nIIRAXymfe2w24z9rb74OImTfI++mXWb M9jh4+lZzQ6Lfp/6OwSMs5xmWn9j75rH6AmwotVVJTe5FSBOksXbc4i5TGaHbiU2gfyA Vfm68OU/m9XGcYIgLtNIVxCn6UAE/NbB3siuKwdKUmE9TZb92WihUYolhpKiYcziVSOX y8UzmLElxls1pnPRw/54ItmYF9A7NtVg+GxCv+opYiKrwIzOMezKGHBH7TPJtHpQBmub 9m2Q== X-Gm-Message-State: ANoB5pmbq4xvUkdCzIPmstoAd4MfZbctCn4raQ1o7RQAVSkgMm9eJYdy dnVqRNPTgJ8z1vW5NpOGB4J4qQ== X-Google-Smtp-Source: AA0mqf568e9xybgGK/wRSf+mQyS6fCinnYqI4Pilk6TRGk3gvya6YcaAW/Z72IJuzNUxNiJTm7kIqw== X-Received: by 2002:a17:906:f189:b0:7ae:3fa3:d7c6 with SMTP id gs9-20020a170906f18900b007ae3fa3d7c6mr40230014ejb.494.1669626637275; Mon, 28 Nov 2022 01:10:37 -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 p35-20020a056402502300b00463b9d47e1fsm4932346eda.71.2022.11.28.01.10.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 01:10:36 -0800 (PST) From: Ricardo Ribalda Date: Mon, 28 Nov 2022 10:10:13 +0100 Subject: [PATCH v3 1/2] freezer: Add processes_frozen() MIME-Version: 1.0 Message-Id: <20221127-snd-freeze-v3-1-a2eda731ca14@chromium.org> References: <20221127-snd-freeze-v3-0-a2eda731ca14@chromium.org> In-Reply-To: <20221127-snd-freeze-v3-0-a2eda731ca14@chromium.org> To: Takashi Iwai , Len Brown , Pierre-Louis Bossart , Kai Vehmanen , Ranjani Sridharan , Mark Brown , Jaroslav Kysela , Pavel Machek , "Rafael J. Wysocki" X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=1657; i=ribalda@chromium.org; h=from:subject:message-id; bh=4IJsRzjRUBmI8ELm76XeH219TKYxoCY1FpvtAWp9NN8=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjhHsGpUmHDy4LbKwnpR9Rk9CtwMEd0pQpdx1IE0fb 6zgFBL2JAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY4R7BgAKCRDRN9E+zzrEiO42EA CHpbt3xEX9Nc3qtOSj8Ch4ZuO/hdfkPBhyD4C5+ZvwkIovXOt2hSP+891sKUfkvG7jPbx1tB/SgbSI 6sdu+55LjjUnH2dANbcNuS79O2FpFCYNPpE7Ay2qDBZZuDb+WP27IOBVfrv7L8+ACy2tqqjELzCwnT Q/cZViMSJcGnr5llb+IkzVUz3GVqKc3UKyglcwyP+e+McJFKPsxcUUXhniivY1uTPl4I/maBS/zhbq JqBbCuNwXr6Ef3ySgmBCEYGWwuNhbray7QfkYId1aJJa/JnGQ9jQyMM8cdB23ByMOtwVXsBCFUxTUa pV2JI//mgbwcjyFitY+33Alk8p+CsZw5/sWyW7TXQTH6t0nZyRLCz3zBvQPAi2HaL1w2E+++dpVUNz a86ZD49Njb4GiF19mePCzi3LfsNW07Bz/82Y8NAvyip9oOn4tHhyg2og9wav1n+LzgJj9Fem71kBlz 75EWG3p/2TiX1aZEaHPCDEX6489tafeRTG1taPq/CgRlcPPxrOfQiOu60xgrq5jDxY7kknT/c0sR22 bZgxjhGx1MwW6PyoDItmvdmEbbPpFnuWZm1THQuvBTpjP+8H6RUt8LvdpbByM41YDFFj/J0qmtyzGX eqihKxGfFODDE3f1r8ri8YaQZECqCn/S4KZvPmGqw+WYi2FVvZ9JYmvN0cPQ== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 Cc: "Joel Fernandes \(Google\)" , alsa-devel@alsa-project.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda 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" Add a way to let the drivers know if the processes are frozen. This is needed by drivers that are waiting for processes to end on their shutdown path. Signed-off-by: Ricardo Ribalda --- include/linux/freezer.h | 2 ++ kernel/freezer.c | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/linux/freezer.h b/include/linux/freezer.h index b303472255be..ca861ace0689 100644 --- a/include/linux/freezer.h +++ b/include/linux/freezer.h @@ -47,6 +47,7 @@ extern int freeze_processes(void); extern int freeze_kernel_threads(void); extern void thaw_processes(void); extern void thaw_kernel_threads(void); +bool processes_frozen(void); static inline bool try_to_freeze(void) { @@ -80,6 +81,7 @@ static inline int freeze_processes(void) { return -ENOSYS; } static inline int freeze_kernel_threads(void) { return -ENOSYS; } static inline void thaw_processes(void) {} static inline void thaw_kernel_threads(void) {} +static inline bool processes_frozen(void) { return false; } static inline bool try_to_freeze(void) { return false; } diff --git a/kernel/freezer.c b/kernel/freezer.c index 4fad0e6fca64..08828c4e12fd 100644 --- a/kernel/freezer.c +++ b/kernel/freezer.c @@ -233,3 +233,14 @@ bool set_freezable(void) return try_to_freeze(); } EXPORT_SYMBOL(set_freezable); + +/** + * processes_frozen - Check if the processes are frozen + * + * Let drivers know if they shall wait for processes. + */ +bool processes_frozen(void) +{ + return pm_freezing; +} +EXPORT_SYMBOL(processes_frozen); From patchwork Mon Nov 28 09:10:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13057171 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 4040AC4332F for ; Mon, 28 Nov 2022 09:12:29 +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 078BB16B5; Mon, 28 Nov 2022 10:11:37 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 078BB16B5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1669626747; bh=kX5q/LQa03Qii9iO9IQ/nJfIRw9n1NXI7ONu/Y5ZJ24=; h=From:Date:Subject:References:In-Reply-To:To:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=oqlaS+FsRbRZ4EXX7JDLxJFMOcCpXEOfP7TaIwKFZ87ilrggR8OFyd+07l3O+NRsx 2EfY+Z2UNRe/XZdHqt/fqc2n7uBD5yNNarXbYeW27LD7/BGWAMKU0xghKjymyB7Bnt Bxmaw0HZPqvUWrDAklnM5YeFdtNAGrSh5pm/PFTc= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 1FBA9F8053D; Mon, 28 Nov 2022 10:10:51 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 45C05F80557; Mon, 28 Nov 2022 10:10:50 +0100 (CET) Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) (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 C17FAF8020D for ; Mon, 28 Nov 2022 10:10:39 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz C17FAF8020D Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="CGIt3hTL" Received: by mail-ej1-x62c.google.com with SMTP id b2so7805373eja.7 for ; Mon, 28 Nov 2022 01:10:39 -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=9ubdN1bACjKh+qjO28e9C129nQGAl5iy3AArXYr64tA=; b=CGIt3hTLCHNo7o4kNPYEi01hMNFq6HcqbpnhXDpYaolzFNCWPKZDVAiKB0j/C5S+O0 0XBTmjLWIAsGP7fP+zKvcfefLmGVkmOKMAulmY0h4aUBuLvXLckOD+81KwAaEuJjZUni TtdfCWzaJp5TO9hlGKgX6DsLDa3FClxwPkUlo= 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=9ubdN1bACjKh+qjO28e9C129nQGAl5iy3AArXYr64tA=; b=UFCgL9rujruWAxeGW6m87ymM/3vfZw1tNFWNxN1dsmieeO8Ycy8PQyIMhDKclUUpTK Vf0Ovco/zZfhPc7F9gYSNgzuwaYqkDxMOuUPL0Og74s3gVqv3AuHSt9wHpselmotcQ8v onyABza4Upn+ffPwSBhDc+2/R5tKQ6RVIJvpvVXZbFydyzM5oiJ5hlYek+8HtpddwyXv 62CGlBCLU4vaftB8KbllFU31Jcxp9exLXb+2nZTimUD/wl2MLZKzm3dWVX6P8nVXOFGN 1DziqNzLFDCiFwgFuKs2mujrfQUbmeDXMJJ7l8BlMwAsA5xAlkLSmylBXwceI28mflav Z5pQ== X-Gm-Message-State: ANoB5pkrQEwBrbiXeNxccB3xduoWIg1i5Ow86VyTa6gqB+Gc7cYOxBfp x7sDhpNr1pWufbXAsGjaGjdBgA== X-Google-Smtp-Source: AA0mqf7CDadNIIxLmDaGMGWeVngi50o9v9Dqym8FZqs9w0o8qAyuABJVXcuAWg331ZRRka79f2HTMg== X-Received: by 2002:a17:906:65c4:b0:7ad:d250:b907 with SMTP id z4-20020a17090665c400b007add250b907mr42053835ejn.737.1669626637954; Mon, 28 Nov 2022 01:10:37 -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 p35-20020a056402502300b00463b9d47e1fsm4932346eda.71.2022.11.28.01.10.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 01:10:37 -0800 (PST) From: Ricardo Ribalda Date: Mon, 28 Nov 2022 10:10:14 +0100 Subject: [PATCH v3 2/2] ALSA: core: Fix deadlock when shutdown a frozen userspace MIME-Version: 1.0 Message-Id: <20221127-snd-freeze-v3-2-a2eda731ca14@chromium.org> References: <20221127-snd-freeze-v3-0-a2eda731ca14@chromium.org> In-Reply-To: <20221127-snd-freeze-v3-0-a2eda731ca14@chromium.org> To: Takashi Iwai , Len Brown , Pierre-Louis Bossart , Kai Vehmanen , Ranjani Sridharan , Mark Brown , Jaroslav Kysela , Pavel Machek , "Rafael J. Wysocki" X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=2405; i=ribalda@chromium.org; h=from:subject:message-id; bh=kX5q/LQa03Qii9iO9IQ/nJfIRw9n1NXI7ONu/Y5ZJ24=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjhHsK3xG667lVW6abqTwHNWMFth1Fvx2d+BxA++3v Kyqt7PGJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY4R7CgAKCRDRN9E+zzrEiHESEA CH6yG+4PYU2KPtT5xs5JZ3tJVMf2A/fn6qpW4cAnsLipCsTlfOiePAN1wcBS5ofPRJp0YcP38QoFX/ ru3NhJ4QwocI5S9bqFFkLYq2NgKN4/RAwtvl0ODLqIlqsZgS4+QqHUQFyu6x2i6iAAgpSAH7dRWHPQ gd1rFeUjycV+Eb7yEPekd2NhF9P8BYCVIvvtceM20Y2G0NFKZaS59NVs8xSssTz4wL39E3dFj08Zne AVkUr2z80tttz2l7BKr6LDTC4tJHN+Qm9oEd0uEumZQ/BY3arElxHfG6twOR3Sawt15eWV59bQLLsf eWwbgxtUwTjSD2QTGC4aAtd03VrZhUPohtn/sMkvasE86nMJJJvRQlnPldg+h+r2K93jQX8L8FRhZN PNoC9mxMuZCRq1falbvBOri3SWEterzZ+ZSg1KN38/e/m+ace1HOWEfIVcU8vB3Hz0CwdLmI38vbrn CSJlv31Lpjey1qOwNsnWSAY/Qzko/OqCvzrJkHSbSmYLUtAnvsis01HZJkcsoUTOuOpkSKTxDr4C6d 4TCVkwVMjud6BJynkM/qKgHEFJZAsEHG6AfWlHqUzmpEP6PmSe4LvP0UV+tmi4kA7dcHqLwZtxkuE6 tBq2wZ3oRpgTh8whQ1+4Emlv31nvmWoo58hmWc2V/JKJM+IpxnBDPM/rxU2g== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 Cc: "Joel Fernandes \(Google\)" , alsa-devel@alsa-project.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda 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" If the user space is frozen, we cannot wait for it to complete. 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 Fixes: 83bfc7e793b5 ("ASoC: SOF: core: unregister clients and machine drivers in .shutdown") Signed-off-by: Ricardo Ribalda --- sound/core/init.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sound/core/init.c b/sound/core/init.c index 5377f94eb211..bc038b49d4d3 100644 --- a/sound/core/init.c +++ b/sound/core/init.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -573,6 +574,11 @@ void snd_card_disconnect_sync(struct snd_card *card) return; } + if (processes_frozen()) { + dev_err(card->dev, "Userspace is frozen, skipping sync\n"); + return; + } + spin_lock_irq(&card->files_lock); wait_event_lock_irq(card->remove_sleep, list_empty(&card->files_list), @@ -658,6 +664,13 @@ int snd_card_free(struct snd_card *card) ret = snd_card_free_when_closed(card); if (ret) return ret; + + /* + * If userspace is frozen the wait from completion will never end. + */ + if (processes_frozen()) + return 0; + /* wait, until all devices are ready for the free operation */ wait_for_completion(&released);