From patchwork Sun Jun 25 15:35:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: YE Chengfeng X-Patchwork-Id: 13292006 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 99C00EB64DD for ; Sun, 25 Jun 2023 15:37:24 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 465A9839; Sun, 25 Jun 2023 17:36:31 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 465A9839 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1687707441; bh=qKTR/ZKDVGmH9mfeh6XyTyOSwVssM/91blIQPOx1O8w=; h=From:To:CC:Subject:Date:List-Id:List-Archive:List-Help:List-Owner: List-Post:List-Subscribe:List-Unsubscribe:From; b=ctyyMxs+vtjxEIT0GjPizoBa/rtxHN/2MaLe6YpddCJUZODyry/Nm7Swv3XJKAEBn umeqN9OXQduUbzCNfv999xRAyqytXz8vg1etMIy9echk80ANBBB7piihI74PJFXRED 6jKxqQM//oD0igy1wej8n47GZ0TZ9FhtZ0MQ7OCA= Received: by alsa1.perex.cz (Postfix, from userid 50401) id A105DF80124; Sun, 25 Jun 2023 17:36:07 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 477F5F80124; Sun, 25 Jun 2023 17:36:07 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 5485FF80246; Sun, 25 Jun 2023 17:36:02 +0200 (CEST) Received: from JPN01-TYC-obe.outbound.protection.outlook.com (mail-tycjpn01on20724.outbound.protection.outlook.com [IPv6:2a01:111:f403:7010::724]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id BF566F80124 for ; Sun, 25 Jun 2023 17:35:55 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz BF566F80124 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key, unprotected) header.d=connect.ust.hk header.i=@connect.ust.hk header.a=rsa-sha256 header.s=selector2 header.b=i9mkEXbE ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cLywr+2Q0qS7HfzPyNs9qVUn7AxedHLtFUY89iiuf4/Kptak/2eme3Elwkwfkxcnyjtgyy4RN8SH4zorgcxmnXqDJySGryYrO2bhFpvtv6uZfewcQi7+WVuPdggIZ35gg8Gr6fFQPS/F03JseSilZYWh+Op5hoz0bUzt7AFfu0m8vVQPpnjywjkdDyUE7eAaefo+3aOrgmoEbC+aPgmgix8XVlbSHkgUewJloQVZrGMAu1BiC3VfsLnSX7IjALx5KTlgVmwhzXIG+niAYEshhSczv8mQyQq1qY0DXfkE9TnHZXYe/IlZmOf/UmJTZqelC4WbQb72D8aY+KD22zLQRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=qKTR/ZKDVGmH9mfeh6XyTyOSwVssM/91blIQPOx1O8w=; b=EOBmIxOFIvi14xHRibHH5HJL9phkVd7WX3qceY9fBoTeBtj5iZYZM/EEfNBALxCZjmsXzVi8KZxIRt1yUT1yH6Pqqh6Fj+/B838SYcq+IxjNga2Kx4d8BrhvNpF26d9ZeHUYxkzFC21sVIg6KV8aX6nKXyyiFW6sy/IeP0V8Uxww3ixQ0Oh+raeQ1/8timCDrK+wHEDUuzONKQxFF1ogixocx8Kb5tI8OZUtAq8rKg9pLHG/6lcAhQSYXTStayPGNZ0LMLqAXspTc2v/0OENMbx6v0zcqc77OiQ5ZAYf9WG2SzSZPyfmqwUXI9QWPbZ7a5dy2eEHXyUNGfmQDMQqzA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=connect.ust.hk; dmarc=pass action=none header.from=connect.ust.hk; dkim=pass header.d=connect.ust.hk; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=connect.ust.hk; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qKTR/ZKDVGmH9mfeh6XyTyOSwVssM/91blIQPOx1O8w=; b=i9mkEXbEhIw0AJxkCQIxWd36bQKNTY5AiZ7EWNyvMN+GadqktB8OyLh82/C9dWylslHVRv9S3Ycz+d0P4Z9AhwnSXrBybPrpHPSZekxY6An5DA2Xn2Y49nu5h7weomTDXtnHtuXOJ29iig5TQ/Aozn0GfIzw8FUhCrNArHSp/00= Received: from TYCP286MB1188.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:b7::8) by TYWP286MB3192.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:2d4::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.24; Sun, 25 Jun 2023 15:35:48 +0000 Received: from TYCP286MB1188.JPNP286.PROD.OUTLOOK.COM ([fe80::b429:5aa3:12f1:6b8]) by TYCP286MB1188.JPNP286.PROD.OUTLOOK.COM ([fe80::b429:5aa3:12f1:6b8%4]) with mapi id 15.20.6521.026; Sun, 25 Jun 2023 15:35:48 +0000 From: YE Chengfeng To: "perex@perex.cz" , "tiwai@suse.com" , "yunjunlee@chromium.org" CC: "alsa-devel@alsa-project.org" , "linux-kernel@vger.kernel.org" Subject: [PATCH] ALSA: dummy: Fix &dpcm->lock deadlock issues Thread-Topic: [PATCH] ALSA: dummy: Fix &dpcm->lock deadlock issues Thread-Index: AQHZp3fywsqsa+nIJUORNCRxL38reA== Date: Sun, 25 Jun 2023 15:35:48 +0000 Message-ID: Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=connect.ust.hk; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: TYCP286MB1188:EE_|TYWP286MB3192:EE_ x-ms-office365-filtering-correlation-id: a99eeb09-9268-46f2-673a-08db7591d9c4 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: L8t5qlKIErCyZCKvSHn8KJYo67P4AQmU4/C4/NTKgbDS0JgTlNjRdbsRVIVS5C9C9L0xj1vO3aoxJ5LoOGwyi0IusOdlnLsz3Z1Bi9Cf/6mrwNzT9FEQebIDj0A+XmK+MwXQXKiL2nKniSATrku9Yc+Oz35h0ICKJLh0PgTY2G1aObWsq41pekOJUjn0l8NZOFI0gMw+Y45pCWu9cRKYBHWShgUt3kUFgMJQ25HCRY50lW8M2D17ue3GzWmjbK4qkMfuve2hQpqgU7+U/yIce4K1mzVMDL3k5GFDHd3CVrJVWTbxZ1CGUBf0LM6aFo1klR4ng+ABPekgTTkpU8XYKURfbQoKasSN007cgzTkS583TAQiElwUqRbGhDB1XWFjiLNzjmFT/fVsR7x0/DkNjCzhxI/ckqjeVVlccDCN3SuSPi1h8vj0IR7mthaZ5RHxt0ZaCB8nX3MVIUL7sD7HR4xX6P7GK2QCyxkqg89CmzpPt2VKbYjuey2er3PZL3uMf8fiZIPRIVrHTvaMd5QSVkszPaY5kK8r6mIDy7JF/sdtUHfDRcwb1cOCXEIsH4a11YQb6dbuwuUuunuhw3zZx18GXmcS92YFYeoF8MZaVVR3mdtPqlR8QnICl3xTO++w x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:TYCP286MB1188.JPNP286.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(346002)(376002)(366004)(136003)(39860400002)(451199021)(122000001)(38100700002)(38070700005)(83380400001)(33656002)(86362001)(478600001)(54906003)(110136005)(7696005)(71200400001)(41300700001)(66946007)(66556008)(55016003)(66476007)(786003)(64756008)(66446008)(316002)(8676002)(76116006)(8936002)(26005)(4326008)(6506007)(186003)(9686003)(2906002)(91956017)(5660300002)(52536014);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?eucgb2312_cn?b?YXpCZVBTSTNOM0pYQ2FwOWVR?= =?eucgb2312_cn?b?eEtDTytJL25pWkd3UVVURGw3ei9UWEdaNGduaVZ0WGJidmRKaDdXb2NXdzB3REts?= =?eucgb2312_cn?b?UGhSeWJ5VnVEbGJ5bDJ2bHBKbE9Xb2MrTkVpbUFxWW5JZ3R3Q3MrSDJIVUwxakl6?= =?eucgb2312_cn?b?YXhsY0NwSHdXNGlXVHJFU3BWTEFYYjdQNGVpbFliL3ZEZXRDTVhZZ1o4TTIrUWJt?= =?eucgb2312_cn?b?YU5MTGp0N09GTlF0eURLampnSFBHQkRqYllmV3VieFRmSUdzS1kxaTRhdUwvVWsw?= =?eucgb2312_cn?b?ZmYyT1pnQ2k4d0NacFYwMHhaRVJUTUdEcmZIVzI3V29QNnk1bG5CQ1ZJUEgvY1Yx?= =?eucgb2312_cn?b?OCtZcmpZTmdKUVplQnk1dFVaQXYycjFxSDBlRnBJQzNTRW9ZMjBYcEpBblg1SEVT?= =?eucgb2312_cn?b?dVozWmxZMGRlSHVoVjhMaU5oNEdXTT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5OUpqcEdLUldLNA==?= MIME-Version: 1.0 X-OriginatorOrg: connect.ust.hk X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: TYCP286MB1188.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: a99eeb09-9268-46f2-673a-08db7591d9c4 X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Jun 2023 15:35:48.7207 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 6c1d4152-39d0-44ca-88d9-b8d6ddca0708 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: YGlIBYG3Tkubc/8wkAjvE1bQ0FZuTnmwMnovWr2XQkhEHnJuiV5UhwveL79hFD7qJncvKHod2laKfDhKOBWT8g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYWP286MB3192 Message-ID-Hash: PTYYQULC2AGV662KY4A5H2LG6W6VMUG3 X-Message-ID-Hash: PTYYQULC2AGV662KY4A5H2LG6W6VMUG3 X-MailFrom: cyeaa@connect.ust.hk X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The timer dummy_systimer_callback is executed under softirq context, thus other process context code requiring the same lock should disable interrupt. Otherwise there would be potential deadlock issues when the code executing under process context (i.e., dummy_systimer_pointer, dummy_systimer_start, dummy_systimer_stop) is preempted by the timer while holding the lock. Deadlock scenario: dummy_systimer_pointer -> spin_lock(&dpcm->lock); -> dummy_systimer_callback -> spin_lock_irqsave(&dpcm->lock, flags); Fix the potential deadlock by using spin_lock_irqsave. Signed-off-by: Chengfeng Ye --- sound/drivers/dummy.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c index 9c17b49a2ae1..04fb4f17e05c 100644 --- a/sound/drivers/dummy.c +++ b/sound/drivers/dummy.c @@ -268,19 +268,23 @@ static void dummy_systimer_update(struct dummy_systimer_pcm *dpcm) static int dummy_systimer_start(struct snd_pcm_substream *substream) { struct dummy_systimer_pcm *dpcm = substream->runtime->private_data; - spin_lock(&dpcm->lock); + unsigned long flags; + + spin_lock_irqsave(&dpcm->lock, flags); dpcm->base_time = jiffies; dummy_systimer_rearm(dpcm); - spin_unlock(&dpcm->lock); + spin_unlock_irqrestore(&dpcm->lock, flags); return 0; } static int dummy_systimer_stop(struct snd_pcm_substream *substream) { struct dummy_systimer_pcm *dpcm = substream->runtime->private_data; - spin_lock(&dpcm->lock); + unsigned long flags; + + spin_lock_irqsave(&dpcm->lock, flags); del_timer(&dpcm->timer); - spin_unlock(&dpcm->lock); + spin_unlock_irqrestore(&dpcm->lock, flags); return 0; } @@ -320,11 +324,12 @@ dummy_systimer_pointer(struct snd_pcm_substream *substream) { struct dummy_systimer_pcm *dpcm = substream->runtime->private_data; snd_pcm_uframes_t pos; + unsigned long flags; - spin_lock(&dpcm->lock); + spin_lock_irqsave(&dpcm->lock, flags); dummy_systimer_update(dpcm); pos = dpcm->frac_pos / HZ; - spin_unlock(&dpcm->lock); + spin_unlock_irqrestore(&dpcm->lock, flags); return pos; }