Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp629918pxb; Tue, 5 Apr 2022 16:33:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysnmY9kZhhrw74pIBQzbuCLMh5pCdZrVT3w0O6WQN8vqAfo+TG+I4QYR3B8Jf+8Z0a9B+S X-Received: by 2002:a17:90a:e7cc:b0:1ca:ad40:b285 with SMTP id kb12-20020a17090ae7cc00b001caad40b285mr6669938pjb.91.1649201608376; Tue, 05 Apr 2022 16:33:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649201608; cv=none; d=google.com; s=arc-20160816; b=aEFXByD+5v+TZ3/54EHp8uvA2CcUFnqIwsPuat5QTjw9/A7mRm2mGOnrlf6xRwr+G4 jkN/Zju9yjFqGqKNlblj/3+oZbc81Xah4cswPWrQIG7RMcQibUzFHwn+T4UXjCw61e4I ahdeKcBBDn3/CmOHybqZlKslIwJkJ/wGMJQtNkChk1L5xvMXSBUqn0Y/rwywqHE5VCUg 2nRyEOS1IVNXoO2E9zYU0Y4X2h3TE7Br3+CihAB4fQ/JH3xPjdBWGHANk6X+TW90dM7k fgPNQyv22Jux88MXOF5S2+Php61REl1WrXKF/2ZWEJEyKg175+PfNssbJR6O75SaoPPu 1wuA== 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=joKsAXZjENmwxzeNqTEoesobEALm7Zdj91MN2wTBNo4=; b=sb4G4r1ccOI0Gz2prWumlwwwdJ8DwJoCJiNO7sTp1KECsSMVQlTPsHOxg1+bHrDd/D SrgNLpcWNugSE3OUvli2nsk15c91b1id6Rk0Bz6l1BlEAKSQrXf3XlslZS6nLFcd6+WZ Ha1/oWAP7iA0t0OpHTjaqJipTpA+BmX+sLGDJncvtRHaost/VmGYonXnhBIk14yQ7/Vq J0WqPcoNIyNLLJPdsRgMNud83J0JiShLbNeHst/9t0/x364nBoyUGWt6ww7T9WfEvkU0 fs3KaSsY95XZpXFm6fyQ/a44Rtu+xZ0bcwNo4CVTx2nSpmsgEBxDsm2H9QsvAAxeGahY nSKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sp2ayaC7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id oo6-20020a17090b1c8600b001bf756ef81csi4169072pjb.139.2022.04.05.16.33.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 16:33:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sp2ayaC7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E6E9A2BB26; Tue, 5 Apr 2022 16:17:45 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348073AbiDEKpm (ORCPT + 99 others); Tue, 5 Apr 2022 06:45:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234409AbiDEIdz (ORCPT ); Tue, 5 Apr 2022 04:33:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFEE3DE7; Tue, 5 Apr 2022 01:31:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1970F61001; Tue, 5 Apr 2022 08:31:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 264CCC385A1; Tue, 5 Apr 2022 08:31:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649147514; bh=tzu4ubjxmqozK98KomH+7/MS5yAMop4h8j39lIkn8Dk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sp2ayaC7Q0UOMT7+2UrkmAnJayYWkziRqIhhif8wrVoGo9x+8rFqBf66oHiMIX38W OOImkwqV/L5j0nfCTWUpCO/ogdY6+RIX5Jm+pvzLQQLvYKdU9V6QTgqRtWxUpZo5Mm s+nF/OrJ4y59Qlv2wf2bcvzIpM9Za61nHiHXDdFQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Laurence Oberman , Ming Lei , David Jeffery , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.16 0023/1017] scsi: fnic: Finish scsi_cmnd before dropping the spinlock Date: Tue, 5 Apr 2022 09:15:36 +0200 Message-Id: <20220405070354.863867911@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 From: David Jeffery [ Upstream commit 733ab7e1b5d1041204c4ca7373f6e6f9d08e3283 ] When aborting a SCSI command through fnic, there is a race with the fnic interrupt handler which can result in the SCSI command and its request being completed twice. If the interrupt handler claims the command by setting CMD_SP to NULL first, the abort handler assumes the interrupt handler has completed the command and returns SUCCESS, causing the request for the scsi_cmnd to be re-queued. But the interrupt handler may not have finished the command yet. After it drops the spinlock protecting CMD_SP, it does memory cleanup before finally calling scsi_done() to complete the scsi_cmnd. If the call to scsi_done occurs after the abort handler finishes and re-queues the request, the completion of the scsi_cmnd will advance and try to double complete a request already queued for retry. This patch fixes the issue by moving scsi_done() and any other use of scsi_cmnd to before the spinlock is released by the interrupt handler. Link: https://lore.kernel.org/r/20220311184359.2345319-1-djeffery@redhat.com Reviewed-by: Laurence Oberman Reviewed-by: Ming Lei Signed-off-by: David Jeffery Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/fnic/fnic_scsi.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/fnic/fnic_scsi.c b/drivers/scsi/fnic/fnic_scsi.c index 88c549f257db..40a52feb315d 100644 --- a/drivers/scsi/fnic/fnic_scsi.c +++ b/drivers/scsi/fnic/fnic_scsi.c @@ -986,8 +986,6 @@ static void fnic_fcpio_icmnd_cmpl_handler(struct fnic *fnic, CMD_SP(sc) = NULL; CMD_FLAGS(sc) |= FNIC_IO_DONE; - spin_unlock_irqrestore(io_lock, flags); - if (hdr_status != FCPIO_SUCCESS) { atomic64_inc(&fnic_stats->io_stats.io_failures); shost_printk(KERN_ERR, fnic->lport->host, "hdr status = %s\n", @@ -996,8 +994,6 @@ static void fnic_fcpio_icmnd_cmpl_handler(struct fnic *fnic, fnic_release_ioreq_buf(fnic, io_req, sc); - mempool_free(io_req, fnic->io_req_pool); - cmd_trace = ((u64)hdr_status << 56) | (u64)icmnd_cmpl->scsi_status << 48 | (u64)icmnd_cmpl->flags << 40 | (u64)sc->cmnd[0] << 32 | @@ -1021,6 +1017,12 @@ static void fnic_fcpio_icmnd_cmpl_handler(struct fnic *fnic, } else fnic->lport->host_stats.fcp_control_requests++; + /* Call SCSI completion function to complete the IO */ + scsi_done(sc); + spin_unlock_irqrestore(io_lock, flags); + + mempool_free(io_req, fnic->io_req_pool); + atomic64_dec(&fnic_stats->io_stats.active_ios); if (atomic64_read(&fnic->io_cmpl_skip)) atomic64_dec(&fnic->io_cmpl_skip); @@ -1049,9 +1051,6 @@ static void fnic_fcpio_icmnd_cmpl_handler(struct fnic *fnic, if(io_duration_time > atomic64_read(&fnic_stats->io_stats.current_max_io_time)) atomic64_set(&fnic_stats->io_stats.current_max_io_time, io_duration_time); } - - /* Call SCSI completion function to complete the IO */ - scsi_done(sc); } /* fnic_fcpio_itmf_cmpl_handler -- 2.34.1