Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp390840imm; Tue, 9 Oct 2018 20:33:07 -0700 (PDT) X-Google-Smtp-Source: ACcGV61qRRtjBuCNF4t1UtHfmxatyOC+kSiu0smkr7R4ssr8C9lyxb0eCXOB85f6CRbOPdzj+m5Y X-Received: by 2002:a17:902:6e17:: with SMTP id u23-v6mr32227078plk.28.1539142387237; Tue, 09 Oct 2018 20:33:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539142387; cv=none; d=google.com; s=arc-20160816; b=RMfmyErY2y6gp9y0mVqDRRqSWIBL8sR3FrMX+AN/29XAMNflXWbNm4unlOQuRA65q7 JNiBrbF9Hf5OVqUXgN/Yo+L9Pkmu2MlZQXbz3W7DlM0Su9RHdQRgby7mgVPNE1Hthtve w5/HbWLEXPx+P8jWGibYilxZlHKr+w2+MVH2/5Tlqt0ePWvKqs2NiGP8p9wRsOSNZ/oV BebL/54pyFoCVTAdGQmbKXQsl9uJZY4i9xhaXYtHKPclFNiv4CD+5GG6IuOsEEoHLHwa Uarkl9JzJr2YAmzxlAohK8TAf9i1ksKUdQ4VCl7RQEkyfVCS+wt8K/tS2V4t+f0megph +xjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=ETFkaumUuSHT6CiuTfnPMrMne7F7uFSas2JUkAqwtEk=; b=wRCfXT5n+tY2txsXyXGOjd53HLTLOfriA7pMD/FwldtbAgZgjpreVXD42aO1diHsHm 2vJLGc2QqSHS2yHIm3gDxr68cShx3vDtOpGAX7KDdV03DQM8b0Qp7GmkYwujemBxe/8U rGZCamDJ3uGBniR+MJBlywoL6VaS/MhY3WBsphHjo2PUvKtZLjDvfrC4pHEE11SQaz74 nGvqes4vsaaVuUVh90eMRe697G9R176mhEHd5AC2ylwOQTmNtFLK8D5CmoUk669CEoBn TuJeVA0Th2uOba90m2Cpn7M7f6l34e2gZep1yuzSigW5LW6YCQXPTEi0eMLO4MKDS78X s1ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linux-iscsi.org header.s=default.private header.b=WT0UJO1l; 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 v191-v6si21437936pgd.157.2018.10.09.20.32.52; Tue, 09 Oct 2018 20:33:07 -0700 (PDT) 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=fail header.i=@linux-iscsi.org header.s=default.private header.b=WT0UJO1l; 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 S1727178AbeJJKvT (ORCPT + 99 others); Wed, 10 Oct 2018 06:51:19 -0400 Received: from mail.linux-iscsi.org ([67.23.28.174]:53477 "EHLO linux-iscsi.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726843AbeJJKvS (ORCPT ); Wed, 10 Oct 2018 06:51:18 -0400 Received: from linux-iscsi.org (localhost [127.0.0.1]) by linux-iscsi.org (Postfix) with ESMTP id 6EC3540AC2; Wed, 10 Oct 2018 03:23:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=linux-iscsi.org; s=default.private; t=1539141800; bh=zMTIUP2MlU7RLc8HUIrGlFL38x6A20f dcgWjRxMRT/A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To: References; b=WT0UJO1lQdF1AziyAfRtFE455csTHdgqRJCXpS2BLSTfNMdiA+Ng nTrfoQTabWzbiY2CH5FjE2/rQs/osuAiTWuSbnN9nt2zDoZ+fgJnAdEXKfQ79XQ+PDl Jtpc+jadFPKr6L+S5f1TMkGSBXrQBP3nfaf4zS56hAwtBh0ayKRg= From: "Nicholas A. Bellinger" To: target-devel Cc: linux-scsi , lkml , "Martin K. Petersen" , Mike Christie , Hannes Reinecke , Christoph Hellwig , Sagi Grimberg , "Bryant G. Ly" , "Peter Zijlstra (Intel)" , Nicholas Bellinger , Bart Van Assche Subject: [PATCH 2/2] target: Fix target_wait_for_sess_cmds breakage with active signals Date: Wed, 10 Oct 2018 03:23:10 +0000 Message-Id: <1539141790-13557-3-git-send-email-nab@linux-iscsi.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1539141790-13557-1-git-send-email-nab@linux-iscsi.org> References: <1539141790-13557-1-git-send-email-nab@linux-iscsi.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nicholas Bellinger With the addition of commit 00d909a107 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 interruptted, 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: 00d909a107 ("scsi: target: Make the session shutdown code also wait for commands that are being aborted") 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 --- drivers/target/target_core_transport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 86c0156..fc3093d2 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -2754,7 +2754,7 @@ static void target_release_cmd_kref(struct kref *kref) 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_session *se_sess) 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); -- 1.9.1