From patchwork Sun Dec 20 20:36:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 11984005 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7155C3527A for ; Sun, 20 Dec 2020 20:37:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A4B5E23AAA for ; Sun, 20 Dec 2020 20:37:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727279AbgLTUhj (ORCPT ); Sun, 20 Dec 2020 15:37:39 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:35042 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727364AbgLTUhi (ORCPT ); Sun, 20 Dec 2020 15:37:38 -0500 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1608496610; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nORQTpQodPfeTe8lJyiJShfHTTi5K70XuvveQ+buD5A=; b=DRfZ4BqMCMissNHgLCEX06AgTOneMmGDTo0j5i+aRdewCPlQeif4+gTikNgxN+BLxSCreu zFitA9IO8ljeD+TwT5TJBNTsFra6/WLJ1tfQP1/KAq4tvoPPbmedXtUlL+/IeEbH6lVZI/ clzLOgtXjHx7rIQPleHKdqu8HoTyW+PMOv54bJZ9qlTbuxpkkhJy/kzlJS4RPJzedX8JNx GcSo/nD7pyC6VwKUm68qH4BEIdyStgWCe6NC0RDe0SeM6KcoyTuI0NEwUjAW5/s2G+9sO2 /Z6+ZNifyXUV2cvzOjw8R0BznEmfvJ0dGA0hBgN49CZgvkPvFUd1HvkNe095Sg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1608496610; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nORQTpQodPfeTe8lJyiJShfHTTi5K70XuvveQ+buD5A=; b=yO+4q2YASYqA2jGOJnq/IRp/rTN0D/j0+E6sI67CZkNF7sFAqPQvgCOF9cp3AJJlIWCtOc aETdIqPiAw40+bAA== To: target-devel@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K. Petersen" , Thomas Gleixner , "Ahmed S . Darwish" , Sebastian Andrzej Siewior Subject: [PATCH 1/6] scsi: target: iscsi: Avoid in_interrupt() usage in iscsit_close_session(). Date: Sun, 20 Dec 2020 21:36:33 +0100 Message-Id: <20201220203638.43615-2-bigeasy@linutronix.de> In-Reply-To: <20201220203638.43615-1-bigeasy@linutronix.de> References: <20201220203638.43615-1-bigeasy@linutronix.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org iscsit_close_session() uses in_interrupt() to decide if it needs to check the return value of iscsit_check_session_usage_count() if it was not able to sleep. The usage of in_interrupt() in drivers is phased out and Linus clearly requested that code which changes behaviour depending on context should either be separated or the context be conveyed in an argument passed by the caller, which usually knows the context. iscsit_close_session() has two callers: - iscsit_handle_time2retain_timeout() A timer_list callback. - iscsit_close_connection() Runs in preemptible context, acquires a mutex. Add an argument to iscsit_close_session() indicating if sleeping is possible. Signed-off-by: Sebastian Andrzej Siewior --- drivers/target/iscsi/iscsi_target.c | 10 +++++----- drivers/target/iscsi/iscsi_target.h | 2 +- drivers/target/iscsi/iscsi_target_erl0.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index 518fac4864cfa..5abf03125388a 100644 --- a/drivers/target/iscsi/iscsi_target.c +++ b/drivers/target/iscsi/iscsi_target.c @@ -4327,7 +4327,7 @@ int iscsit_close_connection( atomic_read(&sess->session_fall_back_to_erl0)) { spin_unlock_bh(&sess->conn_lock); complete_all(&sess->session_wait_comp); - iscsit_close_session(sess); + iscsit_close_session(sess, true); return 0; } else if (atomic_read(&sess->session_logout)) { @@ -4337,7 +4337,7 @@ int iscsit_close_connection( if (atomic_read(&sess->session_close)) { spin_unlock_bh(&sess->conn_lock); complete_all(&sess->session_wait_comp); - iscsit_close_session(sess); + iscsit_close_session(sess, true); } else { spin_unlock_bh(&sess->conn_lock); } @@ -4353,7 +4353,7 @@ int iscsit_close_connection( if (atomic_read(&sess->session_close)) { spin_unlock_bh(&sess->conn_lock); complete_all(&sess->session_wait_comp); - iscsit_close_session(sess); + iscsit_close_session(sess, true); } else { spin_unlock_bh(&sess->conn_lock); } @@ -4366,7 +4366,7 @@ int iscsit_close_connection( * If the iSCSI Session for the iSCSI Initiator Node exists, * forcefully shutdown the iSCSI NEXUS. */ -int iscsit_close_session(struct iscsi_session *sess) +int iscsit_close_session(struct iscsi_session *sess, bool can_sleep) { struct iscsi_portal_group *tpg = sess->tpg; struct se_portal_group *se_tpg = &tpg->tpg_se_tpg; @@ -4399,7 +4399,7 @@ int iscsit_close_session(struct iscsi_session *sess) * time2retain handler) and contain and active session usage count we * restart the timer and exit. */ - if (!in_interrupt()) { + if (can_sleep) { iscsit_check_session_usage_count(sess); } else { if (iscsit_check_session_usage_count(sess) == 2) { diff --git a/drivers/target/iscsi/iscsi_target.h b/drivers/target/iscsi/iscsi_target.h index 7409ce2a66078..b35a96ded9c19 100644 --- a/drivers/target/iscsi/iscsi_target.h +++ b/drivers/target/iscsi/iscsi_target.h @@ -41,7 +41,7 @@ extern void iscsit_thread_get_cpumask(struct iscsi_conn *); extern int iscsi_target_tx_thread(void *); extern int iscsi_target_rx_thread(void *); extern int iscsit_close_connection(struct iscsi_conn *); -extern int iscsit_close_session(struct iscsi_session *); +extern int iscsit_close_session(struct iscsi_session *, bool can_sleep); extern void iscsit_fail_session(struct iscsi_session *); extern void iscsit_stop_session(struct iscsi_session *, int, int); extern int iscsit_release_sessions_for_tpg(struct iscsi_portal_group *, int); diff --git a/drivers/target/iscsi/iscsi_target_erl0.c b/drivers/target/iscsi/iscsi_target_erl0.c index b4abd7b68e6da..102c9cbf59f38 100644 --- a/drivers/target/iscsi/iscsi_target_erl0.c +++ b/drivers/target/iscsi/iscsi_target_erl0.c @@ -765,7 +765,7 @@ void iscsit_handle_time2retain_timeout(struct timer_list *t) iscsit_fill_cxn_timeout_err_stats(sess); spin_unlock_bh(&se_tpg->session_lock); - iscsit_close_session(sess); + iscsit_close_session(sess, false); } void iscsit_start_time2retain_handler(struct iscsi_session *sess) From patchwork Sun Dec 20 20:36:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 11984003 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA507C35273 for ; Sun, 20 Dec 2020 20:37:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 840CB23AC1 for ; Sun, 20 Dec 2020 20:37:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726584AbgLTUhj (ORCPT ); Sun, 20 Dec 2020 15:37:39 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:35040 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727279AbgLTUhi (ORCPT ); Sun, 20 Dec 2020 15:37:38 -0500 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1608496611; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1Nar8nTUQtP5/0fAlBqnn/4nL26kAXwaNThUNCyKfz4=; b=fp7wJLZBST481ADMuy1DcyzeVd2UsYAsKCRm9Fnr3ABjjP0InW26HbdxAqc8pYySaTrGcD kMdWM/I0Fbp6gCRyONK4bn017dHiyzzcQ3Aztm/xGh32W9XcrasdRwj+dkaXP6J6v0sJ1V 8hSfgEZibnV71UzB2PeI1p1axnTKuRHOaOxCn2NeuTLorN/cGLtmeB36K/oRMdszvaCgBv lcdjGvckgQx1XE+7mDx8IEj/u1/HJabSh1BOwZJzzBLr1MGstvKzqSvSGUVs5KrSLC9Rio V/v6HdlS3WdCMNoE8EWLouAQY/ih5+Q7bKNDyPqnzUJtdipwNvGKYeyhmOgDBw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1608496611; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1Nar8nTUQtP5/0fAlBqnn/4nL26kAXwaNThUNCyKfz4=; b=/gsqXaoYw+NZ3shVUrLQzRNgn8bCDfjX93ClCuePFqTt6+4vcNupYCE4o8uhcn+OBe4hie DEa5HHuI8GmBumCA== To: target-devel@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K. Petersen" , Thomas Gleixner , "Ahmed S . Darwish" , Sebastian Andrzej Siewior Subject: [PATCH 2/6] scsi: target: iscsi: Avoid in_interrupt() usage in iscsit_check_session_usage_count(). Date: Sun, 20 Dec 2020 21:36:34 +0100 Message-Id: <20201220203638.43615-3-bigeasy@linutronix.de> In-Reply-To: <20201220203638.43615-1-bigeasy@linutronix.de> References: <20201220203638.43615-1-bigeasy@linutronix.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org iscsit_check_session_usage_count() uses in_interrupt() to find out if it is safe to invoke wait_for_completion(). The usage of in_interrupt() in drivers is phased out and Linus clearly requested that code which changes behaviour depending on context should either be separated or the context be conveyed in an argument passed by the caller, which usually knows the context. There is only one caller of iscsit_check_session_usage_count() which already has an argument indicating if it is safe to sleep. Extend iscsit_check_session_usage_count() by an argument indicating if it may sleep. Signed-off-by: Sebastian Andrzej Siewior --- drivers/target/iscsi/iscsi_target.c | 4 ++-- drivers/target/iscsi/iscsi_target_util.c | 4 ++-- drivers/target/iscsi/iscsi_target_util.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index 5abf03125388a..13de37ff9dc9f 100644 --- a/drivers/target/iscsi/iscsi_target.c +++ b/drivers/target/iscsi/iscsi_target.c @@ -4400,9 +4400,9 @@ int iscsit_close_session(struct iscsi_session *sess, bool can_sleep) * restart the timer and exit. */ if (can_sleep) { - iscsit_check_session_usage_count(sess); + iscsit_check_session_usage_count(sess, can_sleep); } else { - if (iscsit_check_session_usage_count(sess) == 2) { + if (iscsit_check_session_usage_count(sess, can_sleep) == 2) { atomic_set(&sess->session_logout, 0); iscsit_start_time2retain_handler(sess); return 0; diff --git a/drivers/target/iscsi/iscsi_target_util.c b/drivers/target/iscsi/iscsi_target_util.c index 45ba07c6ec270..50028b1d3b849 100644 --- a/drivers/target/iscsi/iscsi_target_util.c +++ b/drivers/target/iscsi/iscsi_target_util.c @@ -779,13 +779,13 @@ void iscsit_free_cmd(struct iscsi_cmd *cmd, bool shutdown) } EXPORT_SYMBOL(iscsit_free_cmd); -int iscsit_check_session_usage_count(struct iscsi_session *sess) +int iscsit_check_session_usage_count(struct iscsi_session *sess, bool can_sleep) { spin_lock_bh(&sess->session_usage_lock); if (sess->session_usage_count != 0) { sess->session_waiting_on_uc = 1; spin_unlock_bh(&sess->session_usage_lock); - if (in_interrupt()) + if (!can_sleep) return 2; wait_for_completion(&sess->session_waiting_on_uc_comp); diff --git a/drivers/target/iscsi/iscsi_target_util.h b/drivers/target/iscsi/iscsi_target_util.h index 68e84803b0a1a..a2c2401f29452 100644 --- a/drivers/target/iscsi/iscsi_target_util.h +++ b/drivers/target/iscsi/iscsi_target_util.h @@ -40,7 +40,7 @@ extern void iscsit_free_queue_reqs_for_conn(struct iscsi_conn *); extern void iscsit_release_cmd(struct iscsi_cmd *); extern void __iscsit_free_cmd(struct iscsi_cmd *, bool); extern void iscsit_free_cmd(struct iscsi_cmd *, bool); -extern int iscsit_check_session_usage_count(struct iscsi_session *); +extern int iscsit_check_session_usage_count(struct iscsi_session *sess, bool can_sleep); extern void iscsit_dec_session_usage_count(struct iscsi_session *); extern void iscsit_inc_session_usage_count(struct iscsi_session *); extern struct iscsi_conn *iscsit_get_conn_from_cid(struct iscsi_session *, u16); From patchwork Sun Dec 20 20:36:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 11984001 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7461CC3526F for ; Sun, 20 Dec 2020 20:37:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3EF4F23B27 for ; Sun, 20 Dec 2020 20:37:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727478AbgLTUhi (ORCPT ); Sun, 20 Dec 2020 15:37:38 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:35044 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726584AbgLTUhi (ORCPT ); Sun, 20 Dec 2020 15:37:38 -0500 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1608496611; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zibiflgoABDQGFRLKGg4iGri3wabbL89Q1mDTS5SIqI=; b=ndVr9p9nW3E+m18AbhRg3SHMvL6DyylmXgoLbR8pNr9hiPKHfIivkmVaiLb4tJWyEanaZQ rYzF63aeuNTKIwaC/s9M7gOUhMtMUHNXYM3q4+7MXlz25HfEt7T+S1oXrg5RkxHhOKksWc 0VQmGoM8xYDRD2gCZG0wpueSZK80bG3AbFriqueOKhD7pZ2HCFHksBk95YEwhy6hbVHkqa f1/4gSpsdkzRYiCcFIjslmtvhbrYRnshyYDnDUQaA3ZEi+kdLYfxIVUmCC2xLYmdvAAIAM Hyf8btZLBcK6iiGr0MSxmYEKlVk5MoynSmV0fOPyy2wnQ//qr9y2T5m5LrggsA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1608496611; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zibiflgoABDQGFRLKGg4iGri3wabbL89Q1mDTS5SIqI=; b=D3btzimxY51lUzuLDpwSZA9XyG1ooEZfnfYgh3JpCsN3J2y2uOkr2JCqzWzpv4SIbr/p1R 0jQvtKIxKaFThMDw== To: target-devel@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K. Petersen" , Thomas Gleixner , "Ahmed S . Darwish" , Sebastian Andrzej Siewior Subject: [PATCH 3/6] scsi: target: iscsi: Redo iscsit_check_session_usage_count() return code. Date: Sun, 20 Dec 2020 21:36:35 +0100 Message-Id: <20201220203638.43615-4-bigeasy@linutronix.de> In-Reply-To: <20201220203638.43615-1-bigeasy@linutronix.de> References: <20201220203638.43615-1-bigeasy@linutronix.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org The return value of iscsit_check_session_usage_count() is only checked if it was not allowed to sleep. If it returns `2' then a timer is prepared. If it returns something else or if it was allowed to sleep then it is ignored. Let iscsit_check_session_usage_count() return true if it needs to arm the timer - otherwise false. This simplifies the code flow of the only caller. Signed-off-by: Sebastian Andrzej Siewior --- drivers/target/iscsi/iscsi_target.c | 12 ++++-------- drivers/target/iscsi/iscsi_target_util.c | 9 +++++---- drivers/target/iscsi/iscsi_target_util.h | 2 +- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index 13de37ff9dc9f..d0e7ed8f28cc8 100644 --- a/drivers/target/iscsi/iscsi_target.c +++ b/drivers/target/iscsi/iscsi_target.c @@ -4399,14 +4399,10 @@ int iscsit_close_session(struct iscsi_session *sess, bool can_sleep) * time2retain handler) and contain and active session usage count we * restart the timer and exit. */ - if (can_sleep) { - iscsit_check_session_usage_count(sess, can_sleep); - } else { - if (iscsit_check_session_usage_count(sess, can_sleep) == 2) { - atomic_set(&sess->session_logout, 0); - iscsit_start_time2retain_handler(sess); - return 0; - } + if (iscsit_check_session_usage_count(sess, can_sleep)) { + atomic_set(&sess->session_logout, 0); + iscsit_start_time2retain_handler(sess); + return 0; } transport_deregister_session(sess->se_sess); diff --git a/drivers/target/iscsi/iscsi_target_util.c b/drivers/target/iscsi/iscsi_target_util.c index 50028b1d3b849..9468b017b4a73 100644 --- a/drivers/target/iscsi/iscsi_target_util.c +++ b/drivers/target/iscsi/iscsi_target_util.c @@ -779,21 +779,22 @@ void iscsit_free_cmd(struct iscsi_cmd *cmd, bool shutdown) } EXPORT_SYMBOL(iscsit_free_cmd); -int iscsit_check_session_usage_count(struct iscsi_session *sess, bool can_sleep) +bool iscsit_check_session_usage_count(struct iscsi_session *sess, + bool can_sleep) { spin_lock_bh(&sess->session_usage_lock); if (sess->session_usage_count != 0) { sess->session_waiting_on_uc = 1; spin_unlock_bh(&sess->session_usage_lock); if (!can_sleep) - return 2; + return true; wait_for_completion(&sess->session_waiting_on_uc_comp); - return 1; + return false; } spin_unlock_bh(&sess->session_usage_lock); - return 0; + return false; } void iscsit_dec_session_usage_count(struct iscsi_session *sess) diff --git a/drivers/target/iscsi/iscsi_target_util.h b/drivers/target/iscsi/iscsi_target_util.h index a2c2401f29452..8ee1c133a9b7b 100644 --- a/drivers/target/iscsi/iscsi_target_util.h +++ b/drivers/target/iscsi/iscsi_target_util.h @@ -40,7 +40,7 @@ extern void iscsit_free_queue_reqs_for_conn(struct iscsi_conn *); extern void iscsit_release_cmd(struct iscsi_cmd *); extern void __iscsit_free_cmd(struct iscsi_cmd *, bool); extern void iscsit_free_cmd(struct iscsi_cmd *, bool); -extern int iscsit_check_session_usage_count(struct iscsi_session *sess, bool can_sleep); +extern bool iscsit_check_session_usage_count(struct iscsi_session *sess, bool can_sleep); extern void iscsit_dec_session_usage_count(struct iscsi_session *); extern void iscsit_inc_session_usage_count(struct iscsi_session *); extern struct iscsi_conn *iscsit_get_conn_from_cid(struct iscsi_session *, u16); From patchwork Sun Dec 20 20:36:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 11983997 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7F69C4361B for ; Sun, 20 Dec 2020 20:37:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A123023AAA for ; Sun, 20 Dec 2020 20:37:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726623AbgLTUhd (ORCPT ); Sun, 20 Dec 2020 15:37:33 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:35032 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726584AbgLTUhd (ORCPT ); Sun, 20 Dec 2020 15:37:33 -0500 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1608496611; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b1Tq+vKn3zogodZ1Ha32Khnj/Q3NSikwulOM53VWqvg=; b=tnT36zHODpXbUp7I0N6RB/2slS2ZrZT6x5CyR80cfmMe8MHoi01mB2b30diKxhHLQNM0gv DVuvxr2opShIjztF9LZBmxa1dIM0ikUJyEvmKg9BpMJkVZsYd8axLWFfvJtxaIbzGkrwcu lRlyiAHqmZMdnVmfvyJnrFkdLkRnY3kXQYYF5IwcehZ9cydvgUgrTQ+LDffrWfJ0lJoB26 n/JCCLVooGVO7bFBTv+zJwRUgboCTawPEximTNgwSyrBU8U6rCygz6H2aomaYg2F2qFD+N jaG8SSbtuE+Vs1sqQIQ3e5MxQtJGs8oP0c2v5G793bG6yyz33WZQXUCULRNIQg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1608496611; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b1Tq+vKn3zogodZ1Ha32Khnj/Q3NSikwulOM53VWqvg=; b=h+U104yUsgEM7FtwOzOfkqAmIxLV7l5j1c1rVBucZlc1Z30BgzTqi4d7Qwg7IJ/Vbyg2mx pQ+xruDydjIk+IAA== To: target-devel@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K. Petersen" , Thomas Gleixner , "Ahmed S . Darwish" , Sebastian Andrzej Siewior Subject: [PATCH 4/6] scsi: target: Remove in_interrupt() usage in core_alua_check_nonop_delay() Date: Sun, 20 Dec 2020 21:36:36 +0100 Message-Id: <20201220203638.43615-5-bigeasy@linutronix.de> In-Reply-To: <20201220203638.43615-1-bigeasy@linutronix.de> References: <20201220203638.43615-1-bigeasy@linutronix.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org core_alua_check_nonop_delay() uses in_interrupt() to decide if it is safe to sleep. The usage of in_interrupt() in drivers is phased out and Linus clearly requested that code which changes behaviour depending on context should either be separated or the context be conveyed in an argument passed by the caller, which usually knows the context. core_alua_check_nonop_delay() has two callers: - target_submit_cmd_map_sgls() Kernel doc says it that it must be called from process context. Also has a BUG_ON(in_interrupt()). - iscsit_setup_scsi_cmd() Invokes iscsit_add_reject_cmd() which does GFP_KERNEL allocation and target_cmd_init_cdb() which may do GFP_KERNEL allocations. Remove the in_interrupt() check because all callers are from preemptible context. Signed-off-by: Sebastian Andrzej Siewior --- drivers/target/target_core_alua.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/target/target_core_alua.c b/drivers/target/target_core_alua.c index 6b72afee2f8b7..5517c7dd51441 100644 --- a/drivers/target/target_core_alua.c +++ b/drivers/target/target_core_alua.c @@ -860,8 +860,6 @@ int core_alua_check_nonop_delay( { if (!(cmd->se_cmd_flags & SCF_ALUA_NON_OPTIMIZED)) return 0; - if (in_interrupt()) - return 0; /* * The ALUA Active/NonOptimized access state delay can be disabled * in via configfs with a value of zero From patchwork Sun Dec 20 20:36:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 11984007 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B917C4361B for ; Sun, 20 Dec 2020 20:38:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 10D9D23AAA for ; Sun, 20 Dec 2020 20:38:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727759AbgLTUiQ (ORCPT ); Sun, 20 Dec 2020 15:38:16 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:35046 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727364AbgLTUiP (ORCPT ); Sun, 20 Dec 2020 15:38:15 -0500 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1608496611; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zlosfdauJl7ZrE12d2cuqqAT3nkgvFdbnMq5MkaS7pg=; b=plw/cqawwFOF/MX7S/joVviLZSXDG1Emjf6Cdd9AJeJnPxZJUhN3q5f04HeWAn2IsnWMem rlbCLGybGbr6nKAkd+NddKhFeCZI3HSMww9BXKG1QrIpUIDh1Ne1DgUuLpRGTLlv9bZwrw mDIJkIu8IVXU9s1nZhjTo+9ziU0r1iwGRfIwcf/BmqWgAioO3JCAslPzxBSYzXd9Wip4TV JAc1ilQqsxLarBas55SnHjlcBM7NJCk058/rDzM4T+y95DMOdZg/+08BOj+6nu1tikIZvb e8/FUtMZeEHrhzYebAkOvWmqI4QDmM/iTf501DLlWwNotlOUiWTR18OEJ64gqw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1608496611; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zlosfdauJl7ZrE12d2cuqqAT3nkgvFdbnMq5MkaS7pg=; b=hHtBOj1gZGhrW/XJWUnxRfVO1LCGetjbZNoGmg6Zy16+w7P+OUd23soK/sQc+dduI06I8J dBsJZ+BWzcOLJoBg== To: target-devel@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K. Petersen" , Thomas Gleixner , "Ahmed S . Darwish" , Sebastian Andrzej Siewior Subject: [PATCH 5/6] scsi: target: Replace in_interrupt() usage in target_submit_cmd_map_sgls() Date: Sun, 20 Dec 2020 21:36:37 +0100 Message-Id: <20201220203638.43615-6-bigeasy@linutronix.de> In-Reply-To: <20201220203638.43615-1-bigeasy@linutronix.de> References: <20201220203638.43615-1-bigeasy@linutronix.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org target_submit_cmd_map_sgls() uses in_interrupt() to crash if it returns true. The usage of in_interrupt() in drivers is phased out and Linus clearly requested that code which changes behaviour depending on context should either be separated or the context be conveyed in an argument passed by the caller, which usually knows the context. The usage of in_interrupt() is clearly for debugging. might_sleep() is better at this because it also detects other contexts in which it is not allowed to sleep, like preempt-disabled section. Replace BUG_ON(in_interrupt) with might_sleep(). Signed-off-by: Sebastian Andrzej Siewior --- drivers/target/target_core_transport.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index fca4bd079d02c..b4fdc3f41e90a 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -1613,10 +1613,11 @@ int target_submit_cmd_map_sgls(struct se_cmd *se_cmd, struct se_session *se_sess sense_reason_t rc; int ret; + might_sleep(); + se_tpg = se_sess->se_tpg; BUG_ON(!se_tpg); BUG_ON(se_cmd->se_tfo || se_cmd->se_sess); - BUG_ON(in_interrupt()); if (flags & TARGET_SCF_USE_CPUID) se_cmd->se_cmd_flags |= SCF_USE_CPUID; From patchwork Sun Dec 20 20:36:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 11984009 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A850C2BBCD for ; Sun, 20 Dec 2020 20:38:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4A63F23B27 for ; Sun, 20 Dec 2020 20:38:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728042AbgLTUiT (ORCPT ); Sun, 20 Dec 2020 15:38:19 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:35050 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727364AbgLTUiT (ORCPT ); Sun, 20 Dec 2020 15:38:19 -0500 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1608496612; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6ezRzP13O5uDREeae/5F86kNFRcMlGKxJeWNhoVQ62s=; b=EtGv773DOdTihRd6WkcqCPzsszra1PyVfHm+O8RZ/RYoNlMUCfjwlzmFL6e0omJyOjj10o jh9r6cQurFZ7HOZ+PW8hShQWM+ib2QRM8b6TSAqfbms1dABiBhSO7dMv+5zTDQUgB5iwCE j+sk1D9m+NkMvEmXj0/olm3WrA1gD88ZAvWN7vGsne80PqwKR5Hy6Nzzz9Enw1n99SxrpJ QPSbgX//jjK49QK24NgrJOKbD4U6tu4/uJPA9rhQFAY7t9UTprgj378jLm6YEYyGI6bsuL kMv3Dcw94lTxeYhkP0h5cLTF79iclE+3/dAIofHYx8WoyJBiDQiaKb0nE4fzRA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1608496612; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6ezRzP13O5uDREeae/5F86kNFRcMlGKxJeWNhoVQ62s=; b=m4m/EVSikyK9R8cZSHyNcNyZ8d/YDn9JAcPUZEvnrxCiQikKkDM5VdxBolDWDatPlhGijz C41o+/28wLd4qWAw== To: target-devel@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K. Petersen" , Thomas Gleixner , "Ahmed S . Darwish" , Sebastian Andrzej Siewior Subject: [PATCH 6/6] scsi: target: Remove in_interrupt() check in transport_handle_cdb_direct() Date: Sun, 20 Dec 2020 21:36:38 +0100 Message-Id: <20201220203638.43615-7-bigeasy@linutronix.de> In-Reply-To: <20201220203638.43615-1-bigeasy@linutronix.de> References: <20201220203638.43615-1-bigeasy@linutronix.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org From: "Ahmed S. Darwish" transport_handle_cdb_direct() uses in_interrupt() to detect if it is safe to sleep. It produces a stack trace and returns with an error which is clearly for debugging. The usage of in_interrupt() in drivers is phased out and Linus clearly requested that code which changes behaviour depending on context should either be separated or the context be conveyed in an argument passed by the caller, which usually knows the context. transport_handle_cdb_direct() has a comment saying that it may only be invoked from process context. It invokes transport_generic_new_cmd() which performs GFP_KERNEL memory allocations. in_interrupt() does not detect all the contexts where it is invalid to sleep (for the blocking GFP_KERNEL allocation) as it fails to detect sections with disabled preemption. Replace the in_interrupt() based check with a might_sleep() annotation. Signed-off-by: Ahmed S. Darwish Signed-off-by: Sebastian Andrzej Siewior --- drivers/target/target_core_transport.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index b4fdc3f41e90a..d47bfd8b0f87c 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -1512,17 +1512,14 @@ int transport_handle_cdb_direct( { sense_reason_t ret; + might_sleep(); + if (!cmd->se_lun) { dump_stack(); pr_err("cmd->se_lun is NULL\n"); return -EINVAL; } - if (in_interrupt()) { - dump_stack(); - pr_err("transport_generic_handle_cdb cannot be called" - " from interrupt context\n"); - return -EINVAL; - } + /* * Set TRANSPORT_NEW_CMD state and CMD_T_ACTIVE to ensure that * outstanding descriptors are handled correctly during shutdown via