Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp26778rdb; Wed, 29 Nov 2023 18:36:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IHK+VD/YtlCjEY0gYcpPcya3iVcdPtfteLFa7MHitKqKzMujpSl65MKvfKQihEfuJcEXVD+ X-Received: by 2002:a05:6a20:8e12:b0:18c:f73:6133 with SMTP id y18-20020a056a208e1200b0018c0f736133mr26763036pzj.28.1701311799185; Wed, 29 Nov 2023 18:36:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701311799; cv=none; d=google.com; s=arc-20160816; b=fM1MwXNjwwqQRc+Opahd4ptboh7gFCzJcW5Wp8YkplgXeScl1tZlozOLLYCtkd8wK6 APK54itJL5ZNiw4IqgdJz+RSPu1vRzlMlYlMhO9LqWoQDdvWUiazoQGc9BRDfU+9mpnY VLOsFIbipBiVPxHR9IJxVn1HItqAJxC1A/OQsLk8gQvvgL1/ge5DoT0mQ51HDkOF3Qbw GRdR3Enlf5B0XNCEDHra62F87NOqXx/W4T4L9zW7AIohHShzK513jpMsw3IKQb0nrTYh HqApbMLGK4yOLvbh8ov2mTdJarJ1ASURyVy41s5Y92QLk4TF3/BlkrPeV5vxscmuz+ZZ dw1w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BSER2qzVj/wyJjFbmfWsB5F9NUePq8Tbl/wt0/5Jm6s=; fh=bKSAdOD9sjDLFpuVEw2QY/iOhn17PgYAzgX/PkCBS1w=; b=i2SLW+h3Z0DQzXxOjjx9PPVODggJNproRuMz3tIuZj0Ny1QTclK8ifg7tt9hMK0Fot PlElANMMq7tM4S4drggcnhSP+axZlATUQS8QuLE8gwj8KkjVC4YVl7sfAvMpBfkgv9Dh 4MxZdFX0Ge0Q7t1lt4bmxLajGpnpP78W0AS9YTamNkOyFQ76V6uIe4yBYGU4luJNoKL6 Jy3B6OvC/zan9vnGElUXE+WJn89vKwrLur1bqtnvLVV61xNMFREr/kLLg4/X7ENzei7o v60C1cMkTZeQ0HvM1YJzUnwjk/YxRVOnRJv2rG+hz8gL4LW0mJcGZFZ3y+EOZRwtgpgc QfWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=Gw3msPXC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=cisco.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id pb16-20020a17090b3c1000b002800b13adb7si322278pjb.72.2023.11.29.18.36.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 18:36:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=Gw3msPXC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=cisco.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 1A4B7802AF32; Wed, 29 Nov 2023 18:36:38 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344224AbjK3CgN (ORCPT + 99 others); Wed, 29 Nov 2023 21:36:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344193AbjK3CgH (ORCPT ); Wed, 29 Nov 2023 21:36:07 -0500 Received: from rcdn-iport-6.cisco.com (rcdn-iport-6.cisco.com [173.37.86.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B96D410CE; Wed, 29 Nov 2023 18:36:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=7030; q=dns/txt; s=iport; t=1701311772; x=1702521372; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JvEGXaLrNCFPFeDwmaOkKpxfE7Auuypd9GbMREVx2PU=; b=Gw3msPXCxH0x1T9OF5acoFaQil5Xz7JYWCFLxHYbnQdgS6+cg1d7hblm 2KDh+mHboGlkwFp0LvTtY+pwC+JcOZOQCxCROUg6fioiHBdgzsw1yzp0u NTtdpmcVKMWvJOQpYALqgNS/w1ood6ce6kpOqQQsBVTe5fepdR5alW41t w=; X-CSE-ConnectionGUID: go6uUI8STv6k3R7CnCqYpQ== X-CSE-MsgGUID: lWebOpZnRPyyOMugXESbvg== X-IronPort-AV: E=Sophos;i="6.04,237,1695686400"; d="scan'208";a="149445319" Received: from rcdn-core-9.cisco.com ([173.37.93.145]) by rcdn-iport-6.cisco.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 02:36:12 +0000 Received: from localhost.cisco.com ([10.193.101.253]) (authenticated bits=0) by rcdn-core-9.cisco.com (8.15.2/8.15.2) with ESMTPSA id 3AU2YA4B007614 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 30 Nov 2023 02:36:11 GMT From: Karan Tilak Kumar To: sebaddel@cisco.com Cc: arulponn@cisco.com, djhawar@cisco.com, gcboffa@cisco.com, mkai2@cisco.com, satishkh@cisco.com, jejb@linux.ibm.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Karan Tilak Kumar Subject: [PATCH v4 09/13] scsi: fnic: Remove usage of host_lock Date: Wed, 29 Nov 2023 18:33:58 -0800 Message-Id: <20231130023402.802282-10-kartilak@cisco.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231130023402.802282-1-kartilak@cisco.com> References: <20231130023402.802282-1-kartilak@cisco.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Authenticated-User: kartilak@cisco.com X-Outbound-SMTP-Client: 10.193.101.253, [10.193.101.253] X-Outbound-Node: rcdn-core-9.cisco.com X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 29 Nov 2023 18:36:38 -0800 (PST) Remove usage of host_lock. Replace with fnic_lock, where necessary. fnic does not use host_lock. fnic uses fnic_lock. Use fnic lock to protect fnic members in fnic_queuecommand. Add log messages in error cases. Changes between v2 and v3: Squash the following commits into one: scsi: fnic: Remove usage of host_lock scsi: fnic: Use fnic_lock to protect fnic structures in queuecommand Reviewed-by: Sesidhar Baddela Reviewed-by: Arulprabhu Ponnusamy Signed-off-by: Karan Tilak Kumar --- drivers/scsi/fnic/fnic_scsi.c | 55 ++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/drivers/scsi/fnic/fnic_scsi.c b/drivers/scsi/fnic/fnic_scsi.c index f32781f8fdd0..ffdbdbfcdf57 100644 --- a/drivers/scsi/fnic/fnic_scsi.c +++ b/drivers/scsi/fnic/fnic_scsi.c @@ -170,17 +170,14 @@ __fnic_set_state_flags(struct fnic *fnic, unsigned long st_flags, unsigned long clearbits) { unsigned long flags = 0; - unsigned long host_lock_flags = 0; spin_lock_irqsave(&fnic->fnic_lock, flags); - spin_lock_irqsave(fnic->lport->host->host_lock, host_lock_flags); if (clearbits) fnic->state_flags &= ~st_flags; else fnic->state_flags |= st_flags; - spin_unlock_irqrestore(fnic->lport->host->host_lock, host_lock_flags); spin_unlock_irqrestore(&fnic->fnic_lock, flags); return; @@ -427,14 +424,27 @@ static int fnic_queuecommand_lck(struct scsi_cmnd *sc) int io_lock_acquired = 0; struct fc_rport_libfc_priv *rp; - if (unlikely(fnic_chk_state_flags_locked(fnic, FNIC_FLAGS_IO_BLOCKED))) + spin_lock_irqsave(&fnic->fnic_lock, flags); + + if (unlikely(fnic_chk_state_flags_locked(fnic, FNIC_FLAGS_IO_BLOCKED))) { + spin_unlock_irqrestore(&fnic->fnic_lock, flags); + FNIC_SCSI_DBG(KERN_ERR, fnic->lport->host, + "fnic<%d>: %s: %d: fnic IO blocked flags: 0x%lx. Returning SCSI_MLQUEUE_HOST_BUSY\n", + fnic->fnic_num, __func__, __LINE__, fnic->state_flags); return SCSI_MLQUEUE_HOST_BUSY; + } - if (unlikely(fnic_chk_state_flags_locked(fnic, FNIC_FLAGS_FWRESET))) + if (unlikely(fnic_chk_state_flags_locked(fnic, FNIC_FLAGS_FWRESET))) { + spin_unlock_irqrestore(&fnic->fnic_lock, flags); + FNIC_SCSI_DBG(KERN_ERR, fnic->lport->host, + "fnic<%d>: %s: %d: fnic flags: 0x%lx. Returning SCSI_MLQUEUE_HOST_BUSY\n", + fnic->fnic_num, __func__, __LINE__, fnic->state_flags); return SCSI_MLQUEUE_HOST_BUSY; + } rport = starget_to_rport(scsi_target(sc->device)); if (!rport) { + spin_unlock_irqrestore(&fnic->fnic_lock, flags); FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, "returning DID_NO_CONNECT for IO as rport is NULL\n"); sc->result = DID_NO_CONNECT << 16; @@ -444,6 +454,7 @@ static int fnic_queuecommand_lck(struct scsi_cmnd *sc) ret = fc_remote_port_chkready(rport); if (ret) { + spin_unlock_irqrestore(&fnic->fnic_lock, flags); FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, "rport is not ready\n"); atomic64_inc(&fnic_stats->misc_stats.rport_not_ready); @@ -454,6 +465,7 @@ static int fnic_queuecommand_lck(struct scsi_cmnd *sc) rp = rport->dd_data; if (!rp || rp->rp_state == RPORT_ST_DELETE) { + spin_unlock_irqrestore(&fnic->fnic_lock, flags); FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, "rport 0x%x removed, returning DID_NO_CONNECT\n", rport->port_id); @@ -465,6 +477,7 @@ static int fnic_queuecommand_lck(struct scsi_cmnd *sc) } if (rp->rp_state != RPORT_ST_READY) { + spin_unlock_irqrestore(&fnic->fnic_lock, flags); FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, "rport 0x%x in state 0x%x, returning DID_IMM_RETRY\n", rport->port_id, rp->rp_state); @@ -474,17 +487,17 @@ static int fnic_queuecommand_lck(struct scsi_cmnd *sc) return 0; } - if (lp->state != LPORT_ST_READY || !(lp->link_up)) + if (lp->state != LPORT_ST_READY || !(lp->link_up)) { + spin_unlock_irqrestore(&fnic->fnic_lock, flags); + FNIC_SCSI_DBG(KERN_ERR, fnic->lport->host, + "fnic<%d>: %s: %d: state not ready: %d/link not up: %d Returning HOST_BUSY\n", + fnic->fnic_num, __func__, __LINE__, lp->state, lp->link_up); return SCSI_MLQUEUE_HOST_BUSY; + } atomic_inc(&fnic->in_flight); - /* - * Release host lock, use driver resource specific locks from here. - * Don't re-enable interrupts in case they were disabled prior to the - * caller disabling them. - */ - spin_unlock(lp->host->host_lock); + spin_unlock_irqrestore(&fnic->fnic_lock, flags); fnic_priv(sc)->state = FNIC_IOREQ_NOT_INITED; fnic_priv(sc)->flags = FNIC_NO_FLAGS; @@ -569,8 +582,6 @@ static int fnic_queuecommand_lck(struct scsi_cmnd *sc) mempool_free(io_req, fnic->io_req_pool); } atomic_dec(&fnic->in_flight); - /* acquire host lock before returning to SCSI */ - spin_lock(lp->host->host_lock); return ret; } else { atomic64_inc(&fnic_stats->io_stats.active_ios); @@ -598,8 +609,6 @@ static int fnic_queuecommand_lck(struct scsi_cmnd *sc) spin_unlock_irqrestore(io_lock, flags); atomic_dec(&fnic->in_flight); - /* acquire host lock before returning to SCSI */ - spin_lock(lp->host->host_lock); return ret; } @@ -1477,18 +1486,17 @@ static inline int fnic_queue_abort_io_req(struct fnic *fnic, int tag, struct fnic_io_req *io_req) { struct vnic_wq_copy *wq = &fnic->hw_copy_wq[0]; - struct Scsi_Host *host = fnic->lport->host; struct misc_stats *misc_stats = &fnic->fnic_stats.misc_stats; unsigned long flags; - spin_lock_irqsave(host->host_lock, flags); + spin_lock_irqsave(&fnic->fnic_lock, flags); if (unlikely(fnic_chk_state_flags_locked(fnic, FNIC_FLAGS_IO_BLOCKED))) { - spin_unlock_irqrestore(host->host_lock, flags); + spin_unlock_irqrestore(&fnic->fnic_lock, flags); return 1; } else atomic_inc(&fnic->in_flight); - spin_unlock_irqrestore(host->host_lock, flags); + spin_unlock_irqrestore(&fnic->fnic_lock, flags); spin_lock_irqsave(&fnic->wq_copy_lock[0], flags); @@ -1923,20 +1931,19 @@ static inline int fnic_queue_dr_io_req(struct fnic *fnic, struct fnic_io_req *io_req) { struct vnic_wq_copy *wq = &fnic->hw_copy_wq[0]; - struct Scsi_Host *host = fnic->lport->host; struct misc_stats *misc_stats = &fnic->fnic_stats.misc_stats; struct scsi_lun fc_lun; int ret = 0; unsigned long intr_flags; - spin_lock_irqsave(host->host_lock, intr_flags); + spin_lock_irqsave(&fnic->fnic_lock, intr_flags); if (unlikely(fnic_chk_state_flags_locked(fnic, FNIC_FLAGS_IO_BLOCKED))) { - spin_unlock_irqrestore(host->host_lock, intr_flags); + spin_unlock_irqrestore(&fnic->fnic_lock, intr_flags); return FAILED; } else atomic_inc(&fnic->in_flight); - spin_unlock_irqrestore(host->host_lock, intr_flags); + spin_unlock_irqrestore(&fnic->fnic_lock, intr_flags); spin_lock_irqsave(&fnic->wq_copy_lock[0], intr_flags); -- 2.31.1