Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3677520pxv; Mon, 26 Jul 2021 09:13:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLOy3S5IB+3T05CH6t4gc5f1LuPFsY/J4Y73JTR7SVhm/jSh8tovDPfkXFltu8FrHjrsLT X-Received: by 2002:a05:6402:50d4:: with SMTP id h20mr6925616edb.7.1627315979843; Mon, 26 Jul 2021 09:12:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627315979; cv=none; d=google.com; s=arc-20160816; b=Lx7fbM2+eOsga65Nq0Qepg1xbYj8/hiatLMm6rUemENsbQuw/o2tvRZm1F9H6JG2/B MFMRQGFsGwxCIS6KNDXzkHXd2iK9o38SVkCi2DmTNR0X1mbATfB+binfLyuuV3NPYEwF B+9Obhy78gTHAyJJSxN4AHMBy+MExOgF9C9trsLqZ7/JU98VQtw/Q9xBvHYpx3iSxZJc fBe1o4cn5rpQxBI1KimG/zuXLmtDvRu3NuyPU+lpVm2isMbifnK0L98GYeTwv5BzwTdo 8Jhx1/tk/pg6IOqvlFllOFcoFNeyLQs5V4Mz4G/Hf7XJbH7GbP49zVEJS3GTUml0vOFn JfGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dTqiS9B5lvdzzOGgb05P8w9Nd94OxnxlKuPaia6saiY=; b=A3SslQsCHX3hAo2Fyu0B47n9zxIwZ8jQLU6BwrAx116G0jAte8Ffgz+fb/dKoUpfx/ CbAFzGk0QO5eTnYp/YqiacVV7xOMo9QPZQhGFUBVswAXHRUjj0yqzlCqtBqc6VDaKLqz miVsCImaykTzBa+zNuoKSrxUwSa3vsPskUlLOMOMOlsgWdM9lwliwExfPJhQNnQlqtrV gLtCrd6Jp5VQnjVIGqEss/bfAhy80RU3o7LFM67i81WchrtYLBHoFuXKhIgOJBqzYwE0 fkTyzLmkut439NApqOr9EtKLFNQrkMOBZakvY4kFwRsLx8gt4ZQG97RSjwFfzCxMsGBk 9AeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uAn6je2p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q1si253778ejr.43.2021.07.26.09.12.36; Mon, 26 Jul 2021 09:12:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uAn6je2p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232602AbhGZPac (ORCPT + 99 others); Mon, 26 Jul 2021 11:30:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:57800 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236740AbhGZPRd (ORCPT ); Mon, 26 Jul 2021 11:17:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2CB7960F57; Mon, 26 Jul 2021 15:58:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627315081; bh=UDqDBBM7L8wBvV1Uv2np8RExwmYpEa2pmfRTiy/N2hY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uAn6je2pXnHVFUwPHOAIeY22yPfv6znmHmyFsAJX+7CkzZ6cpJ9daqXBEmY5oYUvp G/0vkgOa0dnW5wJAbO3tpFUw1I4SnlcZ4YkVvwlSZ6NtF4zbRdKU58l45BWZL3Oo+V nssUvP5B5mRFYqGF8nqc12pCLpjT4xJB9r72HTWc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jia-Ju Bai , Takashi Iwai Subject: [PATCH 5.4 074/108] ALSA: sb: Fix potential ABBA deadlock in CSP driver Date: Mon, 26 Jul 2021 17:39:15 +0200 Message-Id: <20210726153834.057945144@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153831.696295003@linuxfoundation.org> References: <20210726153831.696295003@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Takashi Iwai commit 1c2b9519159b470ef24b2638f4794e86e2952ab7 upstream. SB16 CSP driver may hit potentially a typical ABBA deadlock in two code paths: In snd_sb_csp_stop(): spin_lock_irqsave(&p->chip->mixer_lock, flags); spin_lock(&p->chip->reg_lock); In snd_sb_csp_load(): spin_lock_irqsave(&p->chip->reg_lock, flags); spin_lock(&p->chip->mixer_lock); Also the similar pattern is seen in snd_sb_csp_start(). Although the practical impact is very small (those states aren't triggered in the same running state and this happens only on a real hardware, decades old ISA sound boards -- which must be very difficult to find nowadays), it's a real scenario and has to be fixed. This patch addresses those deadlocks by splitting the locks in snd_sb_csp_start() and snd_sb_csp_stop() for avoiding the nested locks. Reported-by: Jia-Ju Bai Cc: Link: https://lore.kernel.org/r/7b0fcdaf-cd4f-4728-2eae-48c151a92e10@gmail.com Link: https://lore.kernel.org/r/20210716132723.13216-1-tiwai@suse.de Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/isa/sb/sb16_csp.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/sound/isa/sb/sb16_csp.c +++ b/sound/isa/sb/sb16_csp.c @@ -814,6 +814,7 @@ static int snd_sb_csp_start(struct snd_s mixR = snd_sbmixer_read(p->chip, SB_DSP4_PCM_DEV + 1); snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV, mixL & 0x7); snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV + 1, mixR & 0x7); + spin_unlock_irqrestore(&p->chip->mixer_lock, flags); spin_lock(&p->chip->reg_lock); set_mode_register(p->chip, 0xc0); /* c0 = STOP */ @@ -853,6 +854,7 @@ static int snd_sb_csp_start(struct snd_s spin_unlock(&p->chip->reg_lock); /* restore PCM volume */ + spin_lock_irqsave(&p->chip->mixer_lock, flags); snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV, mixL); snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV + 1, mixR); spin_unlock_irqrestore(&p->chip->mixer_lock, flags); @@ -878,6 +880,7 @@ static int snd_sb_csp_stop(struct snd_sb mixR = snd_sbmixer_read(p->chip, SB_DSP4_PCM_DEV + 1); snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV, mixL & 0x7); snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV + 1, mixR & 0x7); + spin_unlock_irqrestore(&p->chip->mixer_lock, flags); spin_lock(&p->chip->reg_lock); if (p->running & SNDRV_SB_CSP_ST_QSOUND) { @@ -892,6 +895,7 @@ static int snd_sb_csp_stop(struct snd_sb spin_unlock(&p->chip->reg_lock); /* restore PCM volume */ + spin_lock_irqsave(&p->chip->mixer_lock, flags); snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV, mixL); snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV + 1, mixR); spin_unlock_irqrestore(&p->chip->mixer_lock, flags);