Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp343712pxj; Thu, 20 May 2021 10:34:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJ+maJqTqfmMJBe9M1I3p+oykSha15M2hp5YZAKsoPSaaYhMGaEv0Un2uQxvQ/lvvLaTkY X-Received: by 2002:a17:906:c01a:: with SMTP id e26mr5882391ejz.300.1621532085787; Thu, 20 May 2021 10:34:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621532085; cv=none; d=google.com; s=arc-20160816; b=VdTytOlhxYictv0crrNxJmiKd12oVbHLIVIZq139R7stsHM6GcYk8V1MlJDZbBQeD/ 6gETq/hggy2ptea732/znsXFBMhgOOzRrPm0/fRhWgJsmm7jM0jpmBle4Tno6SYc+m3C svVzp8f4yv8BldfJ5xb7z/xGv9hQRruJUzrHOtZ95fOUxp81kqCUXaupH0W2LZURcgu0 ULu2Ug2DQwfcU7/VGBZhYCABP3KXcTSHCN3cPbNUSPb0i/SJs0EyRQXeC7fgFQmJDis1 CbAko2V7fJXtFPkmFwR9SFTP64lR9IRC6Zzp9/EASJh3kUswyKEBf2V1aEgmp69slx47 Ywzg== 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=bakKu2u5fnoQIWCyLzhPSPRCx9LEO+Ebl5NHqfCW2ZQ=; b=KDCBr/bxvl/j20UxDaJUOVlzMP7ROJC9UBkrCuGa/1ObIZAPcCoLfhMwVgZ/vR0Wnr mvUiTEqCOvcAT3jm1ghJFIZxnJJLz2m2T2VITicoYermTkQutooJA6C91AiyUnmPiVn3 Vu8tem0O2O7m3WUP99lyGvuarg4DiMvUOCWtsVq8gDRE9ib3GSe9RPUjuKL0QzNOcrYg M0tJnPccGKP1DRPFq8vG2UiB3DtbX87A3Jj9rHZhjIHW77Tr4J7dh2g1bN2h3vdp/lt0 m+e9e2ytHc10FeCmO+h8yD/tRjuT0uOsTXR3PyAalWugCw2Fibw5uULHLjVYt+Q5zELs BN6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Fi6g5V8+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w1si2752321edt.513.2021.05.20.10.34.21; Thu, 20 May 2021 10:34:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Fi6g5V8+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231648AbhETKCQ (ORCPT + 99 others); Thu, 20 May 2021 06:02:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:59060 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232683AbhETJ5t (ORCPT ); Thu, 20 May 2021 05:57:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 574A561413; Thu, 20 May 2021 09:38:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503484; bh=7pr1gT2zu4ViCIn79nfuxOnVjImZACenSZ+23zagixw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fi6g5V8+AgyjZj8Zn+xixHEaVYqNYaME3L/1G/4fC6K1xfZ4Fq42p3EL8T2QQ2Ffq WTY423v9Womu5u7ADEf+RC/8ri7v0ndMQ1JwVd7C6e1MrLO+LN/LgfPLbefQpFJ/yM Rr+JdbGfCIH1lhD3foK/KjdNw17dlFN6/UenRdnY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Brian King , Tyrel Datwyler , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.19 242/425] scsi: ibmvfc: Fix invalid state machine BUG_ON() Date: Thu, 20 May 2021 11:20:11 +0200 Message-Id: <20210520092139.380189408@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Brian King [ Upstream commit 15cfef8623a449d40d16541687afd58e78033be3 ] This fixes an issue hitting the BUG_ON() in ibmvfc_do_work(). When going through a host action of IBMVFC_HOST_ACTION_RESET, we change the action to IBMVFC_HOST_ACTION_TGT_DEL, then drop the host lock, and reset the CRQ, which changes the host state to IBMVFC_NO_CRQ. If, prior to setting the host state to IBMVFC_NO_CRQ, ibmvfc_init_host() is called, it can then end up changing the host action to IBMVFC_HOST_ACTION_INIT. If we then change the host state to IBMVFC_NO_CRQ, we will then hit the BUG_ON(). Make a couple of changes to avoid this. Leave the host action to be IBMVFC_HOST_ACTION_RESET or IBMVFC_HOST_ACTION_REENABLE until after we drop the host lock and reset or reenable the CRQ. Also harden the host state machine to ensure we cannot leave the reset / reenable state until we've finished processing the reset or reenable. Link: https://lore.kernel.org/r/20210413001009.902400-1-tyreld@linux.ibm.com Fixes: 73ee5d867287 ("[SCSI] ibmvfc: Fix soft lockup on resume") Signed-off-by: Brian King [tyreld: added fixes tag] Signed-off-by: Tyrel Datwyler [mkp: fix comment checkpatch warnings] Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/ibmvscsi/ibmvfc.c | 57 ++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c index 50078a199fea..b811436a46d0 100644 --- a/drivers/scsi/ibmvscsi/ibmvfc.c +++ b/drivers/scsi/ibmvscsi/ibmvfc.c @@ -506,8 +506,17 @@ static void ibmvfc_set_host_action(struct ibmvfc_host *vhost, if (vhost->action == IBMVFC_HOST_ACTION_ALLOC_TGTS) vhost->action = action; break; + case IBMVFC_HOST_ACTION_REENABLE: + case IBMVFC_HOST_ACTION_RESET: + vhost->action = action; + break; case IBMVFC_HOST_ACTION_INIT: case IBMVFC_HOST_ACTION_TGT_DEL: + case IBMVFC_HOST_ACTION_LOGO: + case IBMVFC_HOST_ACTION_QUERY_TGTS: + case IBMVFC_HOST_ACTION_TGT_DEL_FAILED: + case IBMVFC_HOST_ACTION_NONE: + default: switch (vhost->action) { case IBMVFC_HOST_ACTION_RESET: case IBMVFC_HOST_ACTION_REENABLE: @@ -517,15 +526,6 @@ static void ibmvfc_set_host_action(struct ibmvfc_host *vhost, break; } break; - case IBMVFC_HOST_ACTION_LOGO: - case IBMVFC_HOST_ACTION_QUERY_TGTS: - case IBMVFC_HOST_ACTION_TGT_DEL_FAILED: - case IBMVFC_HOST_ACTION_NONE: - case IBMVFC_HOST_ACTION_RESET: - case IBMVFC_HOST_ACTION_REENABLE: - default: - vhost->action = action; - break; } } @@ -4346,26 +4346,45 @@ static void ibmvfc_do_work(struct ibmvfc_host *vhost) case IBMVFC_HOST_ACTION_INIT_WAIT: break; case IBMVFC_HOST_ACTION_RESET: - vhost->action = IBMVFC_HOST_ACTION_TGT_DEL; spin_unlock_irqrestore(vhost->host->host_lock, flags); rc = ibmvfc_reset_crq(vhost); + spin_lock_irqsave(vhost->host->host_lock, flags); - if (rc == H_CLOSED) + if (!rc || rc == H_CLOSED) vio_enable_interrupts(to_vio_dev(vhost->dev)); - if (rc || (rc = ibmvfc_send_crq_init(vhost)) || - (rc = vio_enable_interrupts(to_vio_dev(vhost->dev)))) { - ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD); - dev_err(vhost->dev, "Error after reset (rc=%d)\n", rc); + if (vhost->action == IBMVFC_HOST_ACTION_RESET) { + /* + * The only action we could have changed to would have + * been reenable, in which case, we skip the rest of + * this path and wait until we've done the re-enable + * before sending the crq init. + */ + vhost->action = IBMVFC_HOST_ACTION_TGT_DEL; + + if (rc || (rc = ibmvfc_send_crq_init(vhost)) || + (rc = vio_enable_interrupts(to_vio_dev(vhost->dev)))) { + ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD); + dev_err(vhost->dev, "Error after reset (rc=%d)\n", rc); + } } break; case IBMVFC_HOST_ACTION_REENABLE: - vhost->action = IBMVFC_HOST_ACTION_TGT_DEL; spin_unlock_irqrestore(vhost->host->host_lock, flags); rc = ibmvfc_reenable_crq_queue(vhost); + spin_lock_irqsave(vhost->host->host_lock, flags); - if (rc || (rc = ibmvfc_send_crq_init(vhost))) { - ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD); - dev_err(vhost->dev, "Error after enable (rc=%d)\n", rc); + if (vhost->action == IBMVFC_HOST_ACTION_REENABLE) { + /* + * The only action we could have changed to would have + * been reset, in which case, we skip the rest of this + * path and wait until we've done the reset before + * sending the crq init. + */ + vhost->action = IBMVFC_HOST_ACTION_TGT_DEL; + if (rc || (rc = ibmvfc_send_crq_init(vhost))) { + ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD); + dev_err(vhost->dev, "Error after enable (rc=%d)\n", rc); + } } break; case IBMVFC_HOST_ACTION_LOGO: -- 2.30.2