Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4618401pxj; Wed, 12 May 2021 09:21:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlh6X47N75fA/UAZ3iZWuIYQtypCciE/Yi4wJGhK2vXJfRXiZYmCd2lOvzAkGG2VfpRbGg X-Received: by 2002:a05:6402:848:: with SMTP id b8mr44612311edz.159.1620836465594; Wed, 12 May 2021 09:21:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620836465; cv=none; d=google.com; s=arc-20160816; b=sNxfgtjusKqJQIwOJkJmhUXd/FgrbLo+apsIsoU7BpgPDk45ltkTDWdnMq4etTNGHJ EwRFh6Tp/NhB57Ci0/SA3xJ2TGWbXOYcf4WbUtYxOs91JI8HdSyoZBxomh9Qq/cM0Aah Prr7Uo8O2y2AdHSABeWMlXF0Crfi5zfxh8JadultO0+b3x2NrpJ6sueCxoWCzFI1aPfb zC0oNfcDI8YGseuI3aImyFsf7q59UX6D8bxOeWCi1f0HcGW2uYdhaKRgkQarbE3fYiDr cBIbha2Gfv98M1YxFn5FsFuVIG7FVP/ZDWPhjwc9o2AZKA+kAj42tUndImVtoil3bxVM YhTQ== 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=jO+fI5E98Q87ts4ElqiNFBOnww9dQ8ABBfN/7Z/AuEg=; b=orr3HXvMgDdnSjjuWf6p3LDlCFziX1D7r86xiqt4nJXYsDlwznNX2amcv5MGT+zrbg sVZnJylNpnIB8e67IpUlGaOL0OaGOY733y7THJ1mOq5OqIDLXLdXL+sD+LhjXiv6dsCy 4N35sr8JpgMPHccsb6DmENlGCpiGo1+68pFxiEOpzwRvctgcXuxSzyNZs6l60wPq3Tl3 xfHommJXkA+ypDJhH+bWK0PALNPfxvZPoWs7IYWpUKFplXAgkqVbm7EgS2TaZlnN8C0e kKBp0KW8X6HvmCwcQmGRriXljreKVHAXJWtZP1HtZRupqIMk2g1/xrFMM1OT/3dTGYRC rfbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xhGYzNab; 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 m9si469185ejj.281.2021.05.12.09.20.41; Wed, 12 May 2021 09:21:05 -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=xhGYzNab; 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 S240414AbhELQSC (ORCPT + 99 others); Wed, 12 May 2021 12:18:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:48842 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235014AbhELPfH (ORCPT ); Wed, 12 May 2021 11:35:07 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5DEC761C3B; Wed, 12 May 2021 15:17:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832658; bh=fIr65z4NK8tZr1QKOnU5iY784j2AMy7Wfee6aDTAmtc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xhGYzNabRnkFxaYrhD3QRCbUrAKYvGDNer4BRqjtAIsuWfHFHgJ/cPZgLonUD9P38 a3lcxWemoi/vqOqqmR2jjDt6JLs14lgcs8bS2/mKwlP9mgjQTLy75xdimCVJL2MeES iDR9xpXsjCpmGOOZseSIFjxIuXQpTyX4RgFj9rgI= 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 5.10 335/530] scsi: ibmvfc: Fix invalid state machine BUG_ON() Date: Wed, 12 May 2021 16:47:25 +0200 Message-Id: <20210512144830.813719434@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@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 57c9a71fa33a..f6d6539c657f 100644 --- a/drivers/scsi/ibmvscsi/ibmvfc.c +++ b/drivers/scsi/ibmvscsi/ibmvfc.c @@ -532,8 +532,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: @@ -543,15 +552,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; } } @@ -4658,26 +4658,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