Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1122948pxx; Tue, 27 Oct 2020 08:46:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzu14mGQBaLDkfrZ/Rv4qMt178gdTyJmCA7rP6Aks1LIF6T39n4GDWpwW1JMC0GZh1z9qIu X-Received: by 2002:a17:906:fc10:: with SMTP id ov16mr3141946ejb.417.1603813486552; Tue, 27 Oct 2020 08:44:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603813486; cv=none; d=google.com; s=arc-20160816; b=TEJMHwGi/rHNtj5mD/Njj7L0Y3Izrz4hg7ZZpkNLEducO2XnhZmoejzGnnOHuxd/6a k6fVNqlgHrTB0v2mbNkVAfbZAqYpBWBlzmNla9ecXugKemfmBVJ6K6naHCtb5gsM1toI VoquUbJv9oJWLn7auRNkTqSk0R8yjUh35kbr+BA8fFeHdGlBI7pEG/3cwJYbxa470huT I7Y6k8HH/d6sU/GfXN6UIaAfaBzvDUjnOwx2rFUzMOE7aGAzC1BxkWwWF6zMCa06FSto 0aaZ/qtx24VCSXEywcd4Y0voaBL58q6d1YEack1owLHcteL6ZpgbvmGotIljN2xflYzh u3Hw== 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=fElbLoPkDA000/lcA1VYnxCpPZOWYs18AiqFjmUZfFE=; b=VSVMp6f1v6zKTQ5o04Ocd4FSjb4lgQrBXS/kewYmjWB4y0BMrgO/f5KYzP/XC5x3Vn d0iTT38D7bwBagx0w7A9gjP6q80r4BbOmPEA4dfJNtYrR9CCDTqYY9Fu5pCJGbL1EgY3 UbclVaLvaIiLrEH8da9RWhyu4CCE2HWAx8WOWzUU2WL3uRsO666vf3wYzGJ5lUz8Sfc6 qZZbjSP8pO4KJcOCK1SL5BIIzJNxq+0iPAaxSkewL+/NFCGoPHNcI85Dt98hFsob9vtJ OY1K+irx194FIAazmNYdOoDelHmVrs4YtCyJ3Az/BPG98dp4gW2t/yA4A5UNtelvs89Q p7rQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=X1Vl3kl+; 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=fail (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 df6si1089489edb.540.2020.10.27.08.44.23; Tue, 27 Oct 2020 08:44:46 -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=@kernel.org header.s=default header.b=X1Vl3kl+; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1764973AbgJ0Ore (ORCPT + 99 others); Tue, 27 Oct 2020 10:47:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:47310 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1764725AbgJ0Or1 (ORCPT ); Tue, 27 Oct 2020 10:47:27 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BA3FA206E5; Tue, 27 Oct 2020 14:47:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603810046; bh=Ck5uXjcqkJWjRaRK710mHc/p5bO+scT1b6bdGcbO9Og=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X1Vl3kl+6TvxzbDsa1gnVTz7KTzsiTADQj1WB7uaru21ZaIrwVkwdh0IJKDXZXV5U Ms7qOWJBXn6NMFmdSTHh5oSoHEQV8xOnHlNvlh1CE6+zJo492benWcF+D5NwxsRCYI O3dribAphoMcY0i9wZM4dE5GeHZTHxkvoqnkMTvE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nilesh Javali , Manish Rangankar , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.4 383/408] scsi: qedi: Protect active command list to avoid list corruption Date: Tue, 27 Oct 2020 14:55:21 +0100 Message-Id: <20201027135512.767718605@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@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: Nilesh Javali [ Upstream commit c0650e28448d606c84f76c34333dba30f61de993 ] Protect active command list for non-I/O commands like login response, logout response, text response, and recovery cleanup of active list to avoid list corruption. Link: https://lore.kernel.org/r/20200908095657.26821-5-mrangankar@marvell.com Signed-off-by: Nilesh Javali Signed-off-by: Manish Rangankar Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/qedi/qedi_fw.c | 8 ++++++++ drivers/scsi/qedi/qedi_iscsi.c | 2 ++ 2 files changed, 10 insertions(+) diff --git a/drivers/scsi/qedi/qedi_fw.c b/drivers/scsi/qedi/qedi_fw.c index 946cebc4c9322..32586800620bd 100644 --- a/drivers/scsi/qedi/qedi_fw.c +++ b/drivers/scsi/qedi/qedi_fw.c @@ -59,6 +59,7 @@ static void qedi_process_logout_resp(struct qedi_ctx *qedi, "Freeing tid=0x%x for cid=0x%x\n", cmd->task_id, qedi_conn->iscsi_conn_id); + spin_lock(&qedi_conn->list_lock); if (likely(cmd->io_cmd_in_list)) { cmd->io_cmd_in_list = false; list_del_init(&cmd->io_cmd); @@ -69,6 +70,7 @@ static void qedi_process_logout_resp(struct qedi_ctx *qedi, cmd->task_id, qedi_conn->iscsi_conn_id, &cmd->io_cmd); } + spin_unlock(&qedi_conn->list_lock); cmd->state = RESPONSE_RECEIVED; qedi_clear_task_idx(qedi, cmd->task_id); @@ -122,6 +124,7 @@ static void qedi_process_text_resp(struct qedi_ctx *qedi, "Freeing tid=0x%x for cid=0x%x\n", cmd->task_id, qedi_conn->iscsi_conn_id); + spin_lock(&qedi_conn->list_lock); if (likely(cmd->io_cmd_in_list)) { cmd->io_cmd_in_list = false; list_del_init(&cmd->io_cmd); @@ -132,6 +135,7 @@ static void qedi_process_text_resp(struct qedi_ctx *qedi, cmd->task_id, qedi_conn->iscsi_conn_id, &cmd->io_cmd); } + spin_unlock(&qedi_conn->list_lock); cmd->state = RESPONSE_RECEIVED; qedi_clear_task_idx(qedi, cmd->task_id); @@ -222,11 +226,13 @@ static void qedi_process_tmf_resp(struct qedi_ctx *qedi, tmf_hdr = (struct iscsi_tm *)qedi_cmd->task->hdr; + spin_lock(&qedi_conn->list_lock); if (likely(qedi_cmd->io_cmd_in_list)) { qedi_cmd->io_cmd_in_list = false; list_del_init(&qedi_cmd->io_cmd); qedi_conn->active_cmd_count--; } + spin_unlock(&qedi_conn->list_lock); if (((tmf_hdr->flags & ISCSI_FLAG_TM_FUNC_MASK) == ISCSI_TM_FUNC_LOGICAL_UNIT_RESET) || @@ -288,11 +294,13 @@ static void qedi_process_login_resp(struct qedi_ctx *qedi, ISCSI_LOGIN_RESPONSE_HDR_DATA_SEG_LEN_MASK; qedi_conn->gen_pdu.resp_wr_ptr = qedi_conn->gen_pdu.resp_buf + pld_len; + spin_lock(&qedi_conn->list_lock); if (likely(cmd->io_cmd_in_list)) { cmd->io_cmd_in_list = false; list_del_init(&cmd->io_cmd); qedi_conn->active_cmd_count--; } + spin_unlock(&qedi_conn->list_lock); memset(task_ctx, '\0', sizeof(*task_ctx)); diff --git a/drivers/scsi/qedi/qedi_iscsi.c b/drivers/scsi/qedi/qedi_iscsi.c index 0f2622a48311c..755f66b1ff9c7 100644 --- a/drivers/scsi/qedi/qedi_iscsi.c +++ b/drivers/scsi/qedi/qedi_iscsi.c @@ -972,11 +972,13 @@ static void qedi_cleanup_active_cmd_list(struct qedi_conn *qedi_conn) { struct qedi_cmd *cmd, *cmd_tmp; + spin_lock(&qedi_conn->list_lock); list_for_each_entry_safe(cmd, cmd_tmp, &qedi_conn->active_cmd_list, io_cmd) { list_del_init(&cmd->io_cmd); qedi_conn->active_cmd_count--; } + spin_unlock(&qedi_conn->list_lock); } static void qedi_ep_disconnect(struct iscsi_endpoint *ep) -- 2.25.1