From patchwork Thu Apr 6 10:18:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ranjan Kumar X-Patchwork-Id: 671913 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C24A5C7618D for ; Thu, 6 Apr 2023 10:18:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236189AbjDFKSt (ORCPT ); Thu, 6 Apr 2023 06:18:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235960AbjDFKSr (ORCPT ); Thu, 6 Apr 2023 06:18:47 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADE623C38 for ; Thu, 6 Apr 2023 03:18:46 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id e15-20020a17090ac20f00b0023d1b009f52so42391063pjt.2 for ; Thu, 06 Apr 2023 03:18:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1680776326; x=1683368326; h=mime-version:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=aYJmxtYnagjHYhCXBKAxDVR5nqfd+Rutzv+fT1Bo2AI=; b=Ptal98SWzoJ77s5996dT/DM+dL4fIjHgnAuv9YNmKRO66OdvZZ6QAB8tsZ9N439Q+p U+aXcNpuwlA2SErADOKKjun0PtWUM0maKdIZ9Uj3aGgZGjztRAUJR4BzeZ0PPjK41mhY A1LwewEQZcMDgdSdE767fGIN6SV+Ll/naZ3Yw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680776326; x=1683368326; h=mime-version:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=aYJmxtYnagjHYhCXBKAxDVR5nqfd+Rutzv+fT1Bo2AI=; b=Njv/WTp+VW55Jq8+KGq07vPi3Dy9BaeywsIPjxbs8ibZqdmBsWkbqOSEq1iOwDOWdx 80sWUJo6Rz7J+x7X5D/SSnjorL+dwNeUtXqxFxx6d/RS2mRomz4PdL7il9NrAgCPJx0R FppLcsWw0PpsU7WdgPQIVXcMNU03DZjATAgz0By975yJBMxy0VHTTjKAAYMmfhzTQuHn 1Wb6PzNVRo//7fHjDV+uGmnCLV2H95JuRaGxsyMkf+naJUJlBwI4ls/vy4Fo3n3NChy2 t2YRpEx5Qq3S/YYCeoA/yCFmcOuPuhxD76PDtB2bxVjf3tt/q/dBJW2EMu2ZjfapFoW/ BD4A== X-Gm-Message-State: AAQBX9dAzhvYAJdzKfsfVVFRT/Dz1G7cHdxJme3MVpxHWw1BVBE+T1TM zdWNde11taC/cgBjYusO5DsV0BLgydLIyo9gz5/LGuomDhxCI3podjjzPKFKxe7lf6JOvZ+PFfR WiP0dZKuPdps31TBsWaxOffzOGlhksTzTplaxPsNQFeENoM4DnHqhEgWw3NNi8F2i+IabQHqaHK 69GobxTV8uBw== X-Google-Smtp-Source: AKy350ZQk7yNufMjcVEuW4I+lVNL/qV4BfQ8oIwl44pv7143dQjHqbetWf0/Ji06mq+yliLykXbV8g== X-Received: by 2002:a17:902:f94d:b0:1a1:f95a:2505 with SMTP id kx13-20020a170902f94d00b001a1f95a2505mr4233154plb.29.1680776325753; Thu, 06 Apr 2023 03:18:45 -0700 (PDT) Received: from localhost.localdomain ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id p7-20020a63f447000000b0051322a5aa64sm858721pgk.3.2023.04.06.03.18.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 03:18:44 -0700 (PDT) From: Ranjan Kumar To: linux-scsi@vger.kernel.org, martin.petersen@oracle.com Cc: rajsekhar.chundru@broadcom.com, sathya.prakash@broadcom.com, sumit.saxena@broadcom.com, sreekanth.reddy@broadcom.com, Ranjan Kumar Subject: [PATCH] mpi3mr: IRQ save variants of spinlock to protect chain frame allocation Date: Thu, 6 Apr 2023 15:48:19 +0530 Message-Id: <20230406101819.10109-1-ranjan.kumar@broadcom.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Driver use spin lock without irqsave when it needs to acquire a chain frame to protect chain frame allocation from multiple submission threads. If there is any I/O queued from an interrupt context and if that requires a chain frame and if the chain lock is held by the CPU which got interrupted then there will be a possible deadlock. Signed-off-by: Ranjan Kumar --- drivers/scsi/mpi3mr/mpi3mr_os.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c index 6d55698ea4d1..ee6af3d4d667 100644 --- a/drivers/scsi/mpi3mr/mpi3mr_os.c +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c @@ -3311,19 +3311,19 @@ static int mpi3mr_get_chain_idx(struct mpi3mr_ioc *mrioc) { u8 retry_count = 5; int cmd_idx = -1; + unsigned long flags; + spin_lock_irqsave(&mrioc->chain_buf_lock, flags); do { - spin_lock(&mrioc->chain_buf_lock); cmd_idx = find_first_zero_bit(mrioc->chain_bitmap, mrioc->chain_buf_count); if (cmd_idx < mrioc->chain_buf_count) { set_bit(cmd_idx, mrioc->chain_bitmap); - spin_unlock(&mrioc->chain_buf_lock); break; } - spin_unlock(&mrioc->chain_buf_lock); cmd_idx = -1; } while (retry_count--); + spin_unlock_irqrestore(&mrioc->chain_buf_lock, flags); return cmd_idx; }