From patchwork Mon Oct 31 22:47:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 622022 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 66FA9FA3744 for ; Mon, 31 Oct 2022 22:47:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229923AbiJaWrp (ORCPT ); Mon, 31 Oct 2022 18:47:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229542AbiJaWrn (ORCPT ); Mon, 31 Oct 2022 18:47:43 -0400 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EF7012AD5 for ; Mon, 31 Oct 2022 15:47:43 -0700 (PDT) Received: by mail-pj1-f45.google.com with SMTP id v4-20020a17090a088400b00212cb0ed97eso11463034pjc.5 for ; Mon, 31 Oct 2022 15:47:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=73dxzlm048Biqtr6aKwohKxv7jZHIoAym6uGuW/+ewc=; b=ymC4r5np5IfsF1D2OrpCu2Vef0wJN9s97WrW9JeCOuW8Q2bd1ezzaqSvAc24WXfKN6 tp7ymGylW8MUpLmYMdX+3qR6l34fLW8GySdsVnzyEcMoOn+lsOCcH/sT0QQolXaTfO+/ jZP7o81BA2pObLwuQL+tULlf/jSYHeVj58swkfY+/a10RPxhJX1LLFN0FvR0EfrDPwPU hxi3SVOKM3NuvY/hdmSr4iUaxIUKjgV0hy1evWryuweKohfsXOPgSDe4rhkFevK7Km5S T94vdBnr0aNNc7VxAGcysqEMbblhpsK7dPD4LyZv3qbK3pTDaSY4XcSzSZdxNhTf3rZJ XVgQ== X-Gm-Message-State: ACrzQf0/EY4CjljyPgb9TonOfSM4qBOGuqtyfBkVvEUnptmmbG4Wjjgu jVVTNaLXVkOsFpkAotxXPHc= X-Google-Smtp-Source: AMsMyM50dHHgZNruETBOyejxjfHSu8kj6WDSNVYTbwbzqD6sbCs6SmoLXhelA0gSM57viPd6tABbgA== X-Received: by 2002:a17:902:b945:b0:181:c6b6:abc with SMTP id h5-20020a170902b94500b00181c6b60abcmr16423415pls.75.1667256462601; Mon, 31 Oct 2022 15:47:42 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:8574:e82f:b860:3ad0]) by smtp.gmail.com with ESMTPSA id x6-20020a626306000000b00565c8634e55sm5096019pfb.135.2022.10.31.15.47.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Oct 2022 15:47:41 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Hannes Reinecke , Dan Carpenter Subject: [PATCH 1/4] scsi: alua: Move a scsi_device_put() call out of alua_check_vpd() Date: Mon, 31 Oct 2022 15:47:25 -0700 Message-Id: <20221031224728.2607760-2-bvanassche@acm.org> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog In-Reply-To: <20221031224728.2607760-1-bvanassche@acm.org> References: <20221031224728.2607760-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This patch fixes the following smatch warning: drivers/scsi/device_handler/scsi_dh_alua.c:1013 alua_rtpg_queue() warn: sleeping in atomic context alua_check_vpd() <- disables preempt -> alua_rtpg_queue() -> scsi_device_put() Cc: Hannes Reinecke Cc: Dan Carpenter Reported-by: Dan Carpenter Signed-off-by: Bart Van Assche --- drivers/scsi/device_handler/scsi_dh_alua.c | 23 ++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c index 610a51538f03..f7bc81cc59ab 100644 --- a/drivers/scsi/device_handler/scsi_dh_alua.c +++ b/drivers/scsi/device_handler/scsi_dh_alua.c @@ -324,6 +324,7 @@ static int alua_check_vpd(struct scsi_device *sdev, struct alua_dh_data *h, struct alua_port_group *pg, *old_pg = NULL; bool pg_updated = false; unsigned long flags; + bool put_sdev; group_id = scsi_vpd_tpg_id(sdev, &rel_port); if (group_id < 0) { @@ -373,11 +374,14 @@ static int alua_check_vpd(struct scsi_device *sdev, struct alua_dh_data *h, list_add_rcu(&h->node, &pg->dh_list); spin_unlock_irqrestore(&pg->lock, flags); - alua_rtpg_queue(rcu_dereference_protected(h->pg, + put_sdev = alua_rtpg_queue(rcu_dereference_protected(h->pg, lockdep_is_held(&h->pg_lock)), sdev, NULL, true); spin_unlock(&h->pg_lock); + if (put_sdev) + scsi_device_put(sdev); + if (old_pg) kref_put(&old_pg->kref, release_port_group); @@ -968,9 +972,10 @@ static void alua_rtpg_work(struct work_struct *work) * RTPG already has been scheduled. * * Returns true if and only if alua_rtpg_work() will be called asynchronously. - * That function is responsible for calling @qdata->fn(). + * That function is responsible for calling @qdata->fn(). If this function + * returns true, the caller is responsible for invoking scsi_device_put(@sdev). */ -static bool alua_rtpg_queue(struct alua_port_group *pg, +static bool __must_check alua_rtpg_queue(struct alua_port_group *pg, struct scsi_device *sdev, struct alua_queue_data *qdata, bool force) { @@ -1009,8 +1014,6 @@ static bool alua_rtpg_queue(struct alua_port_group *pg, else kref_put(&pg->kref, release_port_group); } - if (sdev) - scsi_device_put(sdev); return true; } @@ -1117,10 +1120,12 @@ static int alua_activate(struct scsi_device *sdev, rcu_read_unlock(); mutex_unlock(&h->init_mutex); - if (alua_rtpg_queue(pg, sdev, qdata, true)) + if (alua_rtpg_queue(pg, sdev, qdata, true)) { + scsi_device_put(sdev); fn = NULL; - else + } else { err = SCSI_DH_DEV_OFFLINED; + } kref_put(&pg->kref, release_port_group); out: if (fn) @@ -1146,7 +1151,9 @@ static void alua_check(struct scsi_device *sdev, bool force) return; } rcu_read_unlock(); - alua_rtpg_queue(pg, sdev, NULL, force); + + if (alua_rtpg_queue(pg, sdev, NULL, force)) + scsi_device_put(sdev); kref_put(&pg->kref, release_port_group); } From patchwork Mon Oct 31 22:47:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 620412 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 AE0BEFA3741 for ; Mon, 31 Oct 2022 22:47:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229961AbiJaWrr (ORCPT ); Mon, 31 Oct 2022 18:47:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229935AbiJaWrp (ORCPT ); Mon, 31 Oct 2022 18:47:45 -0400 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0697614D17 for ; Mon, 31 Oct 2022 15:47:45 -0700 (PDT) Received: by mail-pl1-f178.google.com with SMTP id p21so8146115plr.7 for ; Mon, 31 Oct 2022 15:47:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MapLoBMbG0Bhg1AX8rjvQRMJT4NqZWs+WU5rHhIdvd8=; b=I39598ud9Ox6RqP9qMm2H9fUSranx+/V0HHQphNnavVmTrHptsqdyzZIPvy+iwCLVx zU4fGZp2kLoLSHAyJNTbitloRjsBPFRorDbMxJs+OVCzGKpB96S0MG6iwDNglog49rO6 ffqqMRJqBXlTdKQQMj2ztdJeaMXgneOjMoiORgIqXnbu9fWRHQnvX56HPgCLLgAQh2vh lfRkjlUFitMrSQNIzUwbmiXUMXprZ4FO4ytzAQv/jQhabZfq3dqwurei2CNNjUZDOm1s BF+zyLmpnJ9QfwB3rnpQDUbVpt1gQ9wWb8gfe/n/eJ4iOczt+nnYOf0FKpWpUw4P2roQ g6gw== X-Gm-Message-State: ACrzQf3xHXo2zSMK29/HyeY0a+/VY+oB3WMK3ZiJZn5g2shuy/6J8ONO c2nNXlvS8rSyLTTlaXawWQg= X-Google-Smtp-Source: AMsMyM7unrUg0w4fGGjAIURb6/B15MvsAYxU1rLMIqXH5XvePUsRwMzNuUoqTc3sy0bUpcEH3vj0hQ== X-Received: by 2002:a17:902:bd47:b0:17f:685b:27ee with SMTP id b7-20020a170902bd4700b0017f685b27eemr15755677plx.22.1667256464387; Mon, 31 Oct 2022 15:47:44 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:8574:e82f:b860:3ad0]) by smtp.gmail.com with ESMTPSA id x6-20020a626306000000b00565c8634e55sm5096019pfb.135.2022.10.31.15.47.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Oct 2022 15:47:43 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Hannes Reinecke , Dan Carpenter Subject: [PATCH 2/4] scsi: alua: Move a scsi_device_put() call out of alua_rtpg_select_sdev() Date: Mon, 31 Oct 2022 15:47:26 -0700 Message-Id: <20221031224728.2607760-3-bvanassche@acm.org> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog In-Reply-To: <20221031224728.2607760-1-bvanassche@acm.org> References: <20221031224728.2607760-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Move a scsi_device_put() call from alua_rtpg_select_sdev() to its callers. This patch fixes the following smatch complaint: drivers/scsi/device_handler/scsi_dh_alua.c:853 alua_rtpg_select_sdev() warn: sleeping in atomic context alua_rtpg_work() <- disables preempt -> alua_rtpg_select_sdev() -> scsi_device_put() Cc: Hannes Reinecke Cc: Dan Carpenter Reported-by: Dan Carpenter Signed-off-by: Bart Van Assche --- drivers/scsi/device_handler/scsi_dh_alua.c | 38 ++++++++++++++-------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c index f7bc81cc59ab..693cd827e138 100644 --- a/drivers/scsi/device_handler/scsi_dh_alua.c +++ b/drivers/scsi/device_handler/scsi_dh_alua.c @@ -815,14 +815,19 @@ static unsigned alua_stpg(struct scsi_device *sdev, struct alua_port_group *pg) return SCSI_DH_RETRY; } -static bool alua_rtpg_select_sdev(struct alua_port_group *pg) +/* + * The caller must call scsi_device_put() on the returned pointer if it is not + * NULL. + */ +static struct scsi_device * __must_check +alua_rtpg_select_sdev(struct alua_port_group *pg) { struct alua_dh_data *h; - struct scsi_device *sdev = NULL; + struct scsi_device *sdev = NULL, *prev_sdev; lockdep_assert_held(&pg->lock); if (WARN_ON(!pg->rtpg_sdev)) - return false; + return NULL; /* * RCU protection isn't necessary for dh_list here @@ -849,22 +854,22 @@ static bool alua_rtpg_select_sdev(struct alua_port_group *pg) pr_warn("%s: no device found for rtpg\n", (pg->device_id_len ? (char *)pg->device_id_str : "(nameless PG)")); - return false; + return NULL; } sdev_printk(KERN_INFO, sdev, "rtpg retry on different device\n"); - scsi_device_put(pg->rtpg_sdev); + prev_sdev = pg->rtpg_sdev; pg->rtpg_sdev = sdev; - return true; + return prev_sdev; } static void alua_rtpg_work(struct work_struct *work) { struct alua_port_group *pg = container_of(work, struct alua_port_group, rtpg_work.work); - struct scsi_device *sdev; + struct scsi_device *sdev, *prev_sdev = NULL; LIST_HEAD(qdata_list); int err = SCSI_DH_OK; struct alua_queue_data *qdata, *tmp; @@ -905,7 +910,7 @@ static void alua_rtpg_work(struct work_struct *work) /* If RTPG failed on the current device, try using another */ if (err == SCSI_DH_RES_TEMP_UNAVAIL && - alua_rtpg_select_sdev(pg)) + (prev_sdev = alua_rtpg_select_sdev(pg))) err = SCSI_DH_IMM_RETRY; if (err == SCSI_DH_RETRY || err == SCSI_DH_IMM_RETRY || @@ -917,9 +922,7 @@ static void alua_rtpg_work(struct work_struct *work) pg->interval = ALUA_RTPG_RETRY_DELAY; pg->flags |= ALUA_PG_RUN_RTPG; spin_unlock_irqrestore(&pg->lock, flags); - queue_delayed_work(kaluad_wq, &pg->rtpg_work, - pg->interval * HZ); - return; + goto queue_rtpg; } if (err != SCSI_DH_OK) pg->flags &= ~ALUA_PG_RUN_STPG; @@ -934,9 +937,7 @@ static void alua_rtpg_work(struct work_struct *work) pg->interval = 0; pg->flags &= ~ALUA_PG_RUNNING; spin_unlock_irqrestore(&pg->lock, flags); - queue_delayed_work(kaluad_wq, &pg->rtpg_work, - pg->interval * HZ); - return; + goto queue_rtpg; } } @@ -950,6 +951,9 @@ static void alua_rtpg_work(struct work_struct *work) pg->rtpg_sdev = NULL; spin_unlock_irqrestore(&pg->lock, flags); + if (prev_sdev) + scsi_device_put(prev_sdev); + list_for_each_entry_safe(qdata, tmp, &qdata_list, entry) { list_del(&qdata->entry); if (qdata->callback_fn) @@ -961,6 +965,12 @@ static void alua_rtpg_work(struct work_struct *work) spin_unlock_irqrestore(&pg->lock, flags); scsi_device_put(sdev); kref_put(&pg->kref, release_port_group); + return; + +queue_rtpg: + if (prev_sdev) + scsi_device_put(prev_sdev); + queue_delayed_work(kaluad_wq, &pg->rtpg_work, pg->interval * HZ); } /** From patchwork Mon Oct 31 22:47:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 622021 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 9D26FECAAA1 for ; Mon, 31 Oct 2022 22:47:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229992AbiJaWrt (ORCPT ); Mon, 31 Oct 2022 18:47:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229956AbiJaWrr (ORCPT ); Mon, 31 Oct 2022 18:47:47 -0400 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E499215733 for ; Mon, 31 Oct 2022 15:47:46 -0700 (PDT) Received: by mail-pl1-f175.google.com with SMTP id c24so12003799pls.9 for ; Mon, 31 Oct 2022 15:47:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q5K7L4ibRKPx9mBzDYLIMTolb/4bdgW8u1F5Fm8YTkU=; b=SvTnHp7bSSXMGd/3XT+cRlomRaZVoOMQrBPWjyyIUivgQzxsrcDsbkoQLUtqzFOhgX 7gudlHzriEEqHclsRCE6YKYiEnzgDmrq3COfwrWG7xYVSMe16QSNq+Ec7TB8cSvRRGKG rgRHGt1JG0JD1DVZYASv7XeAgGEnDRkXiKuX0LPP6kRe7ZC1n5VnqgQ6MS+1MVhtm8EJ NHhRiopVzNGQd5YEaTAk/XJVjV/3++Wr3GUZDUTvwP3rORncN6BQ5dvTALlCI+z6uI4Z GgzHxCDBSFWUeGaWhHBj6gMfWdDFYkKAMk7972H51ez8loVy55d/S83w/bjg1/JKHOle YoNw== X-Gm-Message-State: ACrzQf1vddXqnnniXW6Dy3Q9P9cJfAiHXzfOz0vjRkXp35BysgSP4aHp 4gmB767tGKhejDP/xzrxrzw= X-Google-Smtp-Source: AMsMyM77sWqY1Ki/eAGzzZrCiLng8sUOR9LhwjAIeMQAVhC/NjqQTTuatenvqaZwIDD1ipqmyt/iVA== X-Received: by 2002:a17:902:a612:b0:17e:539:c415 with SMTP id u18-20020a170902a61200b0017e0539c415mr15863483plq.173.1667256466263; Mon, 31 Oct 2022 15:47:46 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:8574:e82f:b860:3ad0]) by smtp.gmail.com with ESMTPSA id x6-20020a626306000000b00565c8634e55sm5096019pfb.135.2022.10.31.15.47.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Oct 2022 15:47:45 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Anil Gurumurthy , Sudarsana Kalluru Subject: [PATCH 3/4] scsi: bfa: Convert bfad_reset_sdev_bflags() from a macro into a function Date: Mon, 31 Oct 2022 15:47:27 -0700 Message-Id: <20221031224728.2607760-4-bvanassche@acm.org> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog In-Reply-To: <20221031224728.2607760-1-bvanassche@acm.org> References: <20221031224728.2607760-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Before modifying bfad_reset_sdev_bflags(), convert it from a macro into a function. Cc: Anil Gurumurthy Cc: Sudarsana Kalluru Signed-off-by: Bart Van Assche --- drivers/scsi/bfa/bfad_bsg.c | 27 +++++++++++++++++++++++++++ drivers/scsi/bfa/bfad_im.h | 26 -------------------------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c index be8dfbe13e90..73754032e25c 100644 --- a/drivers/scsi/bfa/bfad_bsg.c +++ b/drivers/scsi/bfa/bfad_bsg.c @@ -2540,6 +2540,33 @@ bfad_iocmd_vf_clr_stats(struct bfad_s *bfad, void *cmd) return 0; } +/* + * Set the SCSI device sdev_bflags - sdev_bflags are used by the + * SCSI mid-layer to choose LUN Scanning mode REPORT_LUNS vs. Sequential Scan + * + * Internally iterates over all the ITNIM's part of the im_port & sets the + * sdev_bflags for the scsi_device associated with LUN #0. + */ +static void bfad_reset_sdev_bflags(struct bfad_im_port_s *im_port, + int lunmask_cfg) +{ + const u32 scan_flags = BLIST_NOREPORTLUN | BLIST_SPARSELUN; + struct bfad_itnim_s *itnim; + struct scsi_device *sdev; + + list_for_each_entry(itnim, &im_port->itnim_mapped_list, list_entry) { + sdev = scsi_device_lookup(im_port->shost, itnim->channel, + itnim->scsi_tgt_id, 0); + if (sdev) { + if (lunmask_cfg == BFA_TRUE) + sdev->sdev_bflags |= scan_flags; + else + sdev->sdev_bflags &= ~scan_flags; + scsi_device_put(sdev); + } + } +} + /* Function to reset the LUN SCAN mode */ static void bfad_iocmd_lunmask_reset_lunscan_mode(struct bfad_s *bfad, int lunmask_cfg) diff --git a/drivers/scsi/bfa/bfad_im.h b/drivers/scsi/bfa/bfad_im.h index c03b225ea1ba..4353feedf76a 100644 --- a/drivers/scsi/bfa/bfad_im.h +++ b/drivers/scsi/bfa/bfad_im.h @@ -198,30 +198,4 @@ irqreturn_t bfad_intx(int irq, void *dev_id); int bfad_im_bsg_request(struct bsg_job *job); int bfad_im_bsg_timeout(struct bsg_job *job); -/* - * Macro to set the SCSI device sdev_bflags - sdev_bflags are used by the - * SCSI mid-layer to choose LUN Scanning mode REPORT_LUNS vs. Sequential Scan - * - * Internally iterate's over all the ITNIM's part of the im_port & set's the - * sdev_bflags for the scsi_device associated with LUN #0. - */ -#define bfad_reset_sdev_bflags(__im_port, __lunmask_cfg) do { \ - struct scsi_device *__sdev = NULL; \ - struct bfad_itnim_s *__itnim = NULL; \ - u32 scan_flags = BLIST_NOREPORTLUN | BLIST_SPARSELUN; \ - list_for_each_entry(__itnim, &((__im_port)->itnim_mapped_list), \ - list_entry) { \ - __sdev = scsi_device_lookup((__im_port)->shost, \ - __itnim->channel, \ - __itnim->scsi_tgt_id, 0); \ - if (__sdev) { \ - if ((__lunmask_cfg) == BFA_TRUE) \ - __sdev->sdev_bflags |= scan_flags; \ - else \ - __sdev->sdev_bflags &= ~scan_flags; \ - scsi_device_put(__sdev); \ - } \ - } \ -} while (0) - #endif From patchwork Mon Oct 31 22:47:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 620411 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 6F2EFECAAA1 for ; Mon, 31 Oct 2022 22:47:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229956AbiJaWry (ORCPT ); Mon, 31 Oct 2022 18:47:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230022AbiJaWru (ORCPT ); Mon, 31 Oct 2022 18:47:50 -0400 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73D1F15737 for ; Mon, 31 Oct 2022 15:47:49 -0700 (PDT) Received: by mail-pj1-f47.google.com with SMTP id c15-20020a17090a1d0f00b0021365864446so11466502pjd.4 for ; Mon, 31 Oct 2022 15:47:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AGJA+sOwnLK/4cwPoFnL1ULIW3kGKI5Ced+JfTYKsKw=; b=hkmA5F4eM52wiF9lFyBGGL0g7Wb4iraOCoV1T7Ur0U/JrQxavE9UZwryqrUe3XLiS7 nBCVYeTC49pkAMbXaW/j3jFw7lUKRgCyCuG92rkqoHyxtQgN1QFit99H8TgzOImrqtbu 5sgOUqxu3J5/xe9kOxy4bisvRdTd1FuoIcgEMso1enlNoqY6D+uuIKCFiQ8dmWjvO+nO nb9MMSGUv4m4wLYdR8ETMOlArg7KA/Ms9TuKbXgHcxvKyA91lcDUD2nB9XPurnbEAkuz qWrkSiFnYOG30ruXCQ1pDrvMvFWG+OhO9ngK5t1Ykk1ymA+oF1P618H3VNMJfrFTR6nZ 8uag== X-Gm-Message-State: ACrzQf3a62Xt6uZ66ujjlN/LLSfPGk8njRKeRlsnrHUGUFWYldolJOIJ lfp9WQ036fJc6Dy+bU2ktJY= X-Google-Smtp-Source: AMsMyM6pcKPk2+QWppTJY0i0PcVYj8zQHsLStF8vvr39GhIypiFfmXmEIby01bAp9V5HKIcUE1qEnw== X-Received: by 2002:a17:902:8e84:b0:178:71f2:113c with SMTP id bg4-20020a1709028e8400b0017871f2113cmr16275312plb.79.1667256468891; Mon, 31 Oct 2022 15:47:48 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:8574:e82f:b860:3ad0]) by smtp.gmail.com with ESMTPSA id x6-20020a626306000000b00565c8634e55sm5096019pfb.135.2022.10.31.15.47.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Oct 2022 15:47:47 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Anil Gurumurthy , Sudarsana Kalluru , Dan Carpenter Subject: [PATCH 4/4] scsi: bfa: Rework bfad_reset_sdev_bflags() Date: Mon, 31 Oct 2022 15:47:28 -0700 Message-Id: <20221031224728.2607760-5-bvanassche@acm.org> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog In-Reply-To: <20221031224728.2607760-1-bvanassche@acm.org> References: <20221031224728.2607760-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Since commit f93ed747e2c7 ("scsi: core: Release SCSI devices synchronously") it is no longer allowed to call scsi_device_put() from atomic context. Hence this patch that reworks bfad_reset_sdev_bflags() such that scsi_device_put() is no longer called. This patch fixes the following smatch warning: drivers/scsi/bfa/bfad_bsg.c:2551 bfad_iocmd_lunmask_reset_lunscan_mode() warn: sleeping in atomic context bfad_iocmd_lunmask() <- disables preempt -> bfad_iocmd_lunmask_reset_lunscan_mode() -> scsi_device_put() Cc: Anil Gurumurthy Cc: Sudarsana Kalluru Cc: Dan Carpenter Reported-by: Dan Carpenter Signed-off-by: Bart Van Assche --- drivers/scsi/bfa/bfad_bsg.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c index 73754032e25c..79d4f7ee5bcb 100644 --- a/drivers/scsi/bfa/bfad_bsg.c +++ b/drivers/scsi/bfa/bfad_bsg.c @@ -2553,18 +2553,20 @@ static void bfad_reset_sdev_bflags(struct bfad_im_port_s *im_port, const u32 scan_flags = BLIST_NOREPORTLUN | BLIST_SPARSELUN; struct bfad_itnim_s *itnim; struct scsi_device *sdev; + unsigned long flags; + spin_lock_irqsave(im_port->shost->host_lock, flags); list_for_each_entry(itnim, &im_port->itnim_mapped_list, list_entry) { - sdev = scsi_device_lookup(im_port->shost, itnim->channel, - itnim->scsi_tgt_id, 0); + sdev = __scsi_device_lookup(im_port->shost, itnim->channel, + itnim->scsi_tgt_id, 0); if (sdev) { if (lunmask_cfg == BFA_TRUE) sdev->sdev_bflags |= scan_flags; else sdev->sdev_bflags &= ~scan_flags; - scsi_device_put(sdev); } } + spin_unlock_irqrestore(im_port->shost->host_lock, flags); } /* Function to reset the LUN SCAN mode */