public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Chengfeng Ye <dg573847474@gmail.com>,
	Manish Rangankar <mrangankar@marvell.com>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	Sasha Levin <sashal@kernel.org>,
	njavali@marvell.com, GR-QLogic-Storage-Upstream@marvell.com,
	jejb@linux.ibm.com, linux-scsi@vger.kernel.org
Subject: [PATCH AUTOSEL 6.1 04/10] scsi: qedi: Fix potential deadlock on &qedi_percpu->p_work_lock
Date: Tue, 22 Aug 2023 07:36:22 -0400	[thread overview]
Message-ID: <20230822113628.3551393-4-sashal@kernel.org> (raw)
In-Reply-To: <20230822113628.3551393-1-sashal@kernel.org>

From: Chengfeng Ye <dg573847474@gmail.com>

[ Upstream commit dd64f80587190265ca8a0f4be6c64c2fda6d3ac2 ]

As &qedi_percpu->p_work_lock is acquired by hard IRQ qedi_msix_handler(),
other acquisitions of the same lock under process context should disable
IRQ, otherwise deadlock could happen if the IRQ preempts the execution
while the lock is held in process context on the same CPU.

qedi_cpu_offline() is one such function which acquires the lock in process
context.

[Deadlock Scenario]
qedi_cpu_offline()
    ->spin_lock(&p->p_work_lock)
        <irq>
        ->qedi_msix_handler()
        ->edi_process_completions()
        ->spin_lock_irqsave(&p->p_work_lock, flags); (deadlock here)

This flaw was found by an experimental static analysis tool I am developing
for IRQ-related deadlocks.

The tentative patch fix the potential deadlock by spin_lock_irqsave()
under process context.

Signed-off-by: Chengfeng Ye <dg573847474@gmail.com>
Link: https://lore.kernel.org/r/20230726125655.4197-1-dg573847474@gmail.com
Acked-by: Manish Rangankar <mrangankar@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/scsi/qedi/qedi_main.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/qedi/qedi_main.c b/drivers/scsi/qedi/qedi_main.c
index 9fd68d362698f..2ee109fb65616 100644
--- a/drivers/scsi/qedi/qedi_main.c
+++ b/drivers/scsi/qedi/qedi_main.c
@@ -1977,8 +1977,9 @@ static int qedi_cpu_offline(unsigned int cpu)
 	struct qedi_percpu_s *p = this_cpu_ptr(&qedi_percpu);
 	struct qedi_work *work, *tmp;
 	struct task_struct *thread;
+	unsigned long flags;
 
-	spin_lock_bh(&p->p_work_lock);
+	spin_lock_irqsave(&p->p_work_lock, flags);
 	thread = p->iothread;
 	p->iothread = NULL;
 
@@ -1989,7 +1990,7 @@ static int qedi_cpu_offline(unsigned int cpu)
 			kfree(work);
 	}
 
-	spin_unlock_bh(&p->p_work_lock);
+	spin_unlock_irqrestore(&p->p_work_lock, flags);
 	if (thread)
 		kthread_stop(thread);
 	return 0;
-- 
2.40.1


  parent reply	other threads:[~2023-08-22 11:37 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-22 11:36 [PATCH AUTOSEL 6.1 01/10] idmaengine: make FSL_EDMA and INTEL_IDMA64 depends on HAS_IOMEM Sasha Levin
2023-08-22 11:36 ` [PATCH AUTOSEL 6.1 02/10] platform/x86/amd/pmf: Fix unsigned comparison with less than zero Sasha Levin
2023-08-22 11:36 ` [PATCH AUTOSEL 6.1 03/10] scsi: lpfc: Remove reftag check in DIF paths Sasha Levin
2023-08-22 11:36 ` Sasha Levin [this message]
2023-08-22 11:36 ` [PATCH AUTOSEL 6.1 05/10] net: hns3: restore user pause configure when disable autoneg Sasha Levin
2023-08-22 11:36 ` [PATCH AUTOSEL 6.1 06/10] drm/amd/pm: skip the RLC stop when S0i3 suspend for SMU v13.0.4/11 Sasha Levin
2023-08-22 11:36 ` [PATCH AUTOSEL 6.1 07/10] drm/amdgpu: Match against exact bootloader status Sasha Levin
2023-08-22 11:36 ` [PATCH AUTOSEL 6.1 08/10] drm/amdkfd: ignore crat by default Sasha Levin
2023-08-22 15:41   ` Deucher, Alexander
2023-09-04  0:36     ` Sasha Levin
2023-08-22 11:36 ` [PATCH AUTOSEL 6.1 09/10] drm/amdkfd: disable IOMMUv2 support for KV/CZ Sasha Levin
2023-08-22 15:41   ` Deucher, Alexander
2023-08-22 11:36 ` [PATCH AUTOSEL 6.1 10/10] drm/amdkfd: disable IOMMUv2 support for Raven Sasha Levin
2023-08-22 15:41   ` Deucher, Alexander

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230822113628.3551393-4-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=GR-QLogic-Storage-Upstream@marvell.com \
    --cc=dg573847474@gmail.com \
    --cc=jejb@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=mrangankar@marvell.com \
    --cc=njavali@marvell.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox