Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4309446pxu; Tue, 1 Dec 2020 01:32:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJwJODT5P3ThKA7eEHnuhPSxZ/oMop+5+YL/3aqg8azBrTzG5fkYS/65EuKhAezobWzkF17b X-Received: by 2002:a17:906:2a4b:: with SMTP id k11mr2027064eje.467.1606815157529; Tue, 01 Dec 2020 01:32:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606815157; cv=none; d=google.com; s=arc-20160816; b=KYEBLaxo3fWJIiBZnE2Ox/pcQgP8cb8HWh3zvSGKTgR59mYIFe4cC+VrWqTdC7ZqEU GGXYka+SxRQz5xfsbAxSITZhJnVqBy7nrA/+BAkdpDuHHfxAWUprEb9pgMjkLbza635d COxBde/STsJC5ER8XWzog7TnbVmG8u8Shp9CVdzX3D4ZShLfJdq+EAk2KBMKZLJIPhWw OVlVetW3uBGrJ1qgLVNkVuhPYoJ7iPrsbeHoATnlpuMfNSILT9SFPuWk+xUpKc6sFwGO 3G9MnieIAOZ4lgxCJg+5E0/92ZgqTWBctHJhjISVnEXIEtD9OJcFwD4vKgntVihD87Uh XtOg== 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=n03mtX8VusUspR/Rd7wuvCNzIiAc1pe7KvCJU6homGM=; b=fnhEhECXF+KUJW+vgbp+Ze1xgiYvmphRqm8oGVNRLD4pYTOnZomlIQxj3yuI+banvL +LJa/Epx/uzhF9IrLP1v3kDrXnUR9/yRavdvw3fIO8JRUyvnk/yrq87I1PUcV6TyCNJb EV57Ztr4Epr5MdsTjAXX1w9TuTrQB5h8lPcsERL8t74l19L+jYd3i8UfqqBEaz6BrvNM V1y8ZOBKYWnuHeli23+LzjKGK569+Y5J4Eu0Dol0M5i1ehvlEaiDaY0q8/vakMN+hKBa L4nITGVfOyPxmYRh+feIYAqj0qZ0ar0+/4nXgRfeyNtAgJB81+gZwrHX3ADLeQcLxx+3 /Cgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dJ8Bd5iT; 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 f5si744003edw.358.2020.12.01.01.32.14; Tue, 01 Dec 2020 01:32:37 -0800 (PST) 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=dJ8Bd5iT; 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 S2388478AbgLAJBI (ORCPT + 99 others); Tue, 1 Dec 2020 04:01:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:37414 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388473AbgLAJBG (ORCPT ); Tue, 1 Dec 2020 04:01:06 -0500 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 CA74B221FF; Tue, 1 Dec 2020 09:00:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606813225; bh=muE24eixzSgiB3UpGqlnzGPKxwVuB3tYFUCgeSEmiq8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dJ8Bd5iTYyvIMqgkSSRJ7Xw6h27+R8uZ75JfQb9UaKLdGXDaAZDHPBbI8fqig+UNe ugpeAIbRb7J/K7Oyij0I/T3pd6LSMS0HTZwX7Q7MeKjFbvVgv1aHTM9WCc/VZ00nOa ljKyCNsRxLZrD1MHFbMwCamdTvVV9mMRrqEuenC0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mike Christie , Lee Duncan , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.19 24/57] scsi: libiscsi: Fix NOP race condition Date: Tue, 1 Dec 2020 09:53:29 +0100 Message-Id: <20201201084650.367300584@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201084647.751612010@linuxfoundation.org> References: <20201201084647.751612010@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: Lee Duncan [ Upstream commit fe0a8a95e7134d0b44cd407bc0085b9ba8d8fe31 ] iSCSI NOPs are sometimes "lost", mistakenly sent to the user-land iscsid daemon instead of handled in the kernel, as they should be, resulting in a message from the daemon like: iscsid: Got nop in, but kernel supports nop handling. This can occur because of the new forward- and back-locks, and the fact that an iSCSI NOP response can occur before processing of the NOP send is complete. This can result in "conn->ping_task" being NULL in iscsi_nop_out_rsp(), when the pointer is actually in the process of being set. To work around this, we add a new state to the "ping_task" pointer. In addition to NULL (not assigned) and a pointer (assigned), we add the state "being set", which is signaled with an INVALID pointer (using "-1"). Link: https://lore.kernel.org/r/20201106193317.16993-1-leeman.duncan@gmail.com Reviewed-by: Mike Christie Signed-off-by: Lee Duncan Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/libiscsi.c | 23 +++++++++++++++-------- include/scsi/libiscsi.h | 3 +++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index 7a05c72717666..1c69515e870cb 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c @@ -571,8 +571,8 @@ static void iscsi_complete_task(struct iscsi_task *task, int state) if (conn->task == task) conn->task = NULL; - if (conn->ping_task == task) - conn->ping_task = NULL; + if (READ_ONCE(conn->ping_task) == task) + WRITE_ONCE(conn->ping_task, NULL); /* release get from queueing */ __iscsi_put_task(task); @@ -781,6 +781,9 @@ __iscsi_conn_send_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr, task->conn->session->age); } + if (unlikely(READ_ONCE(conn->ping_task) == INVALID_SCSI_TASK)) + WRITE_ONCE(conn->ping_task, task); + if (!ihost->workq) { if (iscsi_prep_mgmt_task(conn, task)) goto free_task; @@ -988,8 +991,11 @@ static int iscsi_send_nopout(struct iscsi_conn *conn, struct iscsi_nopin *rhdr) struct iscsi_nopout hdr; struct iscsi_task *task; - if (!rhdr && conn->ping_task) - return -EINVAL; + if (!rhdr) { + if (READ_ONCE(conn->ping_task)) + return -EINVAL; + WRITE_ONCE(conn->ping_task, INVALID_SCSI_TASK); + } memset(&hdr, 0, sizeof(struct iscsi_nopout)); hdr.opcode = ISCSI_OP_NOOP_OUT | ISCSI_OP_IMMEDIATE; @@ -1004,11 +1010,12 @@ static int iscsi_send_nopout(struct iscsi_conn *conn, struct iscsi_nopin *rhdr) task = __iscsi_conn_send_pdu(conn, (struct iscsi_hdr *)&hdr, NULL, 0); if (!task) { + if (!rhdr) + WRITE_ONCE(conn->ping_task, NULL); iscsi_conn_printk(KERN_ERR, conn, "Could not send nopout\n"); return -EIO; } else if (!rhdr) { /* only track our nops */ - conn->ping_task = task; conn->last_ping = jiffies; } @@ -1021,7 +1028,7 @@ static int iscsi_nop_out_rsp(struct iscsi_task *task, struct iscsi_conn *conn = task->conn; int rc = 0; - if (conn->ping_task != task) { + if (READ_ONCE(conn->ping_task) != task) { /* * If this is not in response to one of our * nops then it must be from userspace. @@ -1961,7 +1968,7 @@ static void iscsi_start_tx(struct iscsi_conn *conn) */ static int iscsi_has_ping_timed_out(struct iscsi_conn *conn) { - if (conn->ping_task && + if (READ_ONCE(conn->ping_task) && time_before_eq(conn->last_recv + (conn->recv_timeout * HZ) + (conn->ping_timeout * HZ), jiffies)) return 1; @@ -2096,7 +2103,7 @@ enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *sc) * Checking the transport already or nop from a cmd timeout still * running */ - if (conn->ping_task) { + if (READ_ONCE(conn->ping_task)) { task->have_checked_conn = true; rc = BLK_EH_RESET_TIMER; goto done; diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h index c9bd935f4fd1c..1ee0f30ae190b 100644 --- a/include/scsi/libiscsi.h +++ b/include/scsi/libiscsi.h @@ -145,6 +145,9 @@ struct iscsi_task { void *dd_data; /* driver/transport data */ }; +/* invalid scsi_task pointer */ +#define INVALID_SCSI_TASK (struct iscsi_task *)-1l + static inline int iscsi_task_has_unsol_data(struct iscsi_task *task) { return task->unsol_r2t.data_length > task->unsol_r2t.sent; -- 2.27.0