Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3474613imu; Sun, 11 Nov 2018 15:57:19 -0800 (PST) X-Google-Smtp-Source: AJdET5c6qEzRnjwAT3bRnFBTIBn6mVUehzna3cYDfLOHNxHFnkxUrDA9V3Egqk+cGvwGl5gT2WPe X-Received: by 2002:a62:fc52:: with SMTP id e79mr723900pfh.8.1541980639093; Sun, 11 Nov 2018 15:57:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541980639; cv=none; d=google.com; s=arc-20160816; b=U4BI36NZC0/O+ZaSiDVFY6NV/qBTpmBv6NRznh91bzKtbhW+HNzlJA26v4NkUgkeaL BxvPHHPfW5e6Fv0USYeWa/ZpCdIzmNIWYUCT8fPtbGMBeGuPaVi1tGovdYC9X6aN2FWo lAtaZB0GfuwJ31AuAopgXe8WjrJci/OethWd08zWcb2Xgd0eCAEc5mv3MO+/N8tNsPVk 1qnjQLjC8vo9FKzQlGMPRas7VKRRCGIjtCfK1KwdagKrhK4nvh8M0sxgennrN7ds4uOe j80IJTIQLtCY9k157yaeqoVesaXH54CdWglNTBrw2PtF70KG2gAIieChNRCeoDGNpjlc huQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/mZGJ8LlpnH4pWe0hgqfETvAc+FX8Dib2dpEtzawuJo=; b=I3hsfCJHDXxvj6S082FXU/ZoLaA7ADGZXaWBl83cu2nKCScy19CPagEYP5YsSQZqks cXzpkj0ivk6SZOe4uaikf5b3z55blb9cGIkE3QbWKxYy7vk3yedkQyBxWUe4lfaRl0MW UxEw613YBbOKpbTqxhHfy6rKDPAczoA1oZMCwly841SiSnQmWWqFpG4p2c2MqtAXvxLQ kht+cK/v5N0NYLy2gWrkitPDZksOectHpJo6xnwcboQk+s4Zdk1iOdHsAO/8cvRx6trp /l7a+kxtbnTsElSMAWNe0X2JyQHKZz720933CLA9mX/SwflkySSTI0vpVmLSFNnGGs+V 2qWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mCw0n8SR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a123-v6si13821117pgc.219.2018.11.11.15.57.04; Sun, 11 Nov 2018 15:57:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mCw0n8SR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732776AbeKLJrG (ORCPT + 99 others); Mon, 12 Nov 2018 04:47:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:34210 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732545AbeKLISN (ORCPT ); Mon, 12 Nov 2018 03:18:13 -0500 Received: from localhost (unknown [206.108.79.134]) (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 578F8208A3; Sun, 11 Nov 2018 22:28:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975297; bh=cux8fSc2fDv2yXExKQ8ySzYqNEu9wlubW/+MtZzv4kM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mCw0n8SRDgutq5fBiO6WTcRZMdQzxkEG3lD+2E+nqGedQoJusmtQu0k0D6CHUobow q28rtSrR+PLXnky3rc/8m2Nif+qTb1EqV/2uAjYYdCSVqnZxWxBu6SUzBHA3dhlUv2 eZYjKLLgfSaQw8CD4lp/Smz2qPBXnxSRLcu3UoG8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bart Van Assche , Mike Christie , Hannes Reinecke , Christoph Hellwig , Sagi Grimberg , "Bryant G. Ly" , Nicholas Bellinger , "Bryant G. Ly" , "Martin K. Petersen" Subject: [PATCH 4.19 216/361] scsi: target: Fix target_wait_for_sess_cmds breakage with active signals Date: Sun, 11 Nov 2018 14:19:23 -0800 Message-Id: <20181111221650.189093046@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Nicholas Bellinger commit 38fe73cc2c96fbc9942b07220f2a4f1bab37392d upstream. With the addition of commit 00d909a10710 ("scsi: target: Make the session shutdown code also wait for commands that are being aborted") in v4.19-rc, it incorrectly assumes no signals will be pending for task_struct executing the normal session shutdown and I/O quiesce code-path. For example, iscsi-target and iser-target issue SIGINT to all kthreads as part of session shutdown. This has been the behaviour since day one. As-is when signals are pending with se_cmds active in se_sess->sess_cmd_list, wait_event_interruptible_lock_irq_timeout() returns a negative number and immediately kills the machine because of the do while (ret <= 0) loop that was added in commit 00d909a107 to spin while backend I/O is taking any amount of extended time (say 30 seconds) to complete. Here's what it looks like in action with debug plus delayed backend I/O completion: [ 4951.909951] se_sess: 000000003e7e08fa before target_wait_for_sess_cmds [ 4951.914600] target_wait_for_sess_cmds: signal_pending: 1 [ 4951.918015] wait_event_interruptible_lock_irq_timeout ret: -512 signal_pending: 1 loop count: 0 [ 4951.921639] wait_event_interruptible_lock_irq_timeout ret: -512 signal_pending: 1 loop count: 1 [ 4951.921944] wait_event_interruptible_lock_irq_timeout ret: -512 signal_pending: 1 loop count: 2 [ 4951.921944] wait_event_interruptible_lock_irq_timeout ret: -512 signal_pending: 1 loop count: 3 [ 4951.921944] wait_event_interruptible_lock_irq_timeout ret: -512 signal_pending: 1 loop count: 4 [ 4951.921944] wait_event_interruptible_lock_irq_timeout ret: -512 signal_pending: 1 loop count: 5 [ 4951.921944] wait_event_interruptible_lock_irq_timeout ret: -512 signal_pending: 1 loop count: 6 [ 4951.921944] wait_event_interruptible_lock_irq_timeout ret: -512 signal_pending: 1 loop count: 7 [ 4951.921944] wait_event_interruptible_lock_irq_timeout ret: -512 signal_pending: 1 loop count: 8 [ 4951.921944] wait_event_interruptible_lock_irq_timeout ret: -512 signal_pending: 1 loop count: 9 ... followed by the usual RCU CPU stalls and deadlock. There was never a case pre commit 00d909a107 where wait_for_complete(&se_cmd->cmd_wait_comp) was able to be interrupted, so to address this for v4.19+ moving forward go ahead and use wait_event_lock_irq_timeout() instead so new code works with all fabric drivers. Also for commit 00d909a107, fix a minor regression in target_release_cmd_kref() to only wake_up the new se_sess->cmd_list_wq only when shutdown has actually been triggered via se_sess->sess_tearing_down. Fixes: 00d909a10710 ("scsi: target: Make the session shutdown code also wait for commands that are being aborted") Cc: # v4.19+ Cc: Bart Van Assche Cc: Mike Christie Cc: Hannes Reinecke Cc: Christoph Hellwig Cc: Sagi Grimberg Cc: Bryant G. Ly Tested-by: Nicholas Bellinger Signed-off-by: Nicholas Bellinger Reviewed-by: Bryant G. Ly Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/target/target_core_transport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -2754,7 +2754,7 @@ static void target_release_cmd_kref(stru if (se_sess) { spin_lock_irqsave(&se_sess->sess_cmd_lock, flags); list_del_init(&se_cmd->se_cmd_list); - if (list_empty(&se_sess->sess_cmd_list)) + if (se_sess->sess_tearing_down && list_empty(&se_sess->sess_cmd_list)) wake_up(&se_sess->cmd_list_wq); spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); } @@ -2907,7 +2907,7 @@ void target_wait_for_sess_cmds(struct se spin_lock_irq(&se_sess->sess_cmd_lock); do { - ret = wait_event_interruptible_lock_irq_timeout( + ret = wait_event_lock_irq_timeout( se_sess->cmd_list_wq, list_empty(&se_sess->sess_cmd_list), se_sess->sess_cmd_lock, 180 * HZ);