Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp194402pxx; Wed, 28 Oct 2020 02:21:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfJrnhy9wfpYPcp7a/AewllY7TqqjX2V5FHwipXGrnZwe97FUZT61jY0pUeQxKVMfXasiW X-Received: by 2002:a05:6402:1ad9:: with SMTP id ba25mr6869584edb.120.1603876884768; Wed, 28 Oct 2020 02:21:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603876884; cv=none; d=google.com; s=arc-20160816; b=VGznWOxdE4UJr4/n1V9W96E922HcL228kGpzxzmuMzSQWOxYhWloNosB7sBHEysTMa gn51AWj6opOYfmgv85dOnnpBHTlDo1y/5szy0c9yaWJEVg3yuKiyejnoyMH4rBDLHJli wTb/2DqzCTmu8onH+fWErJIMX6i6yeiYbELBJ2McqeaGipA7LXbsjW/sg12P8/GwnoQx lXqSCBiiwlc3o/glEIUv22NIxQKtdQKkaWC6Xx3FvjzkRvBzAUR07Tkiwx164aIAvkmk dBXxyyGf3iIsksSR5hYad9LRgrqriwim0an/k3fYQ5Dj2pJ1xgqHL59A4urQwM4imDEn Rj3g== 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=UBDot/48d0finfrZgVemDsjuL4h+D0D3rmiM4XJCUQs=; b=VJvnOccaVb2s0OlSaHs+VpCvmBpKooEgPjjfs+/bYcqbcLdQW9J32hlPigDzc3uJKx 50dcm85v40hhBA8SsqnMwt25LWAjMRhsWoNrKyVD+lpMhQoSghKgo0rImPkXY0h8sJGR XutxDF+boAtNex4FeCEBHlph1Ci/34NU6/TMLMkjnCvlbvqQGEJafe7+4Px+3l9bH6wL pL0I9nJVjLimFilHiwukWfEbVs0482KW2TihV6hLVMzTF/s7MQihiQcOURUf32DBdPQT moSBHcqeRoS9+29hbrZxwOqIHAphHjV3ngO7H2XfdbYT84QIxR/Y7pNRDLXs6W9dOTeB xtLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UcMHDwLt; 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 i19si2816688ejh.153.2020.10.28.02.21.02; Wed, 28 Oct 2020 02:21:24 -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=UcMHDwLt; 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 S1757464AbgJ0OTl (ORCPT + 99 others); Tue, 27 Oct 2020 10:19:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:39448 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757226AbgJ0OQw (ORCPT ); Tue, 27 Oct 2020 10:16:52 -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 C1C0422263; Tue, 27 Oct 2020 14:16:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603808211; bh=8yHdRGj2/9Sfgc6fcwYzlH5G2QZh3n45m0COG9acsDk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UcMHDwLt3UDauZ/j/E8jYY8PUnMUNW3E8fa6c/GWFYATP/xGEUOnM9dHzEYCaR2me sMbMHlLg8yVUGyb2CTOjXDCaEWqDnYoR3mV8Y2X7Sm/1EGGWt8uA8nFSzukTG/nha4 NoKgv/r3IcBWm3or38+a9S2Vuj6l43EeKRGV8+Zs= 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 4.14 176/191] scsi: qedi: Protect active command list to avoid list corruption Date: Tue, 27 Oct 2020 14:50:31 +0100 Message-Id: <20201027134918.195128456@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134909.701581493@linuxfoundation.org> References: <20201027134909.701581493@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 2e5e04a7623fa..e688300faeefd 100644 --- a/drivers/scsi/qedi/qedi_fw.c +++ b/drivers/scsi/qedi/qedi_fw.c @@ -62,6 +62,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); @@ -72,6 +73,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); @@ -127,6 +129,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); @@ -137,6 +140,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); @@ -231,11 +235,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) || @@ -299,11 +305,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 4d7971c3f339b..c55fb411c8a55 100644 --- a/drivers/scsi/qedi/qedi_iscsi.c +++ b/drivers/scsi/qedi/qedi_iscsi.c @@ -983,11 +983,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