Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2648265pxb; Mon, 18 Apr 2022 05:32:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwi99WB1mhq6RrMAuFbxqxVy8pYWsELFKZwuRPZuNqwdiV9fSZXiTf3GmsJTOqd3uzJFrv X-Received: by 2002:a05:6402:d2:b0:413:2e50:d6fd with SMTP id i18-20020a05640200d200b004132e50d6fdmr11846327edu.171.1650285121870; Mon, 18 Apr 2022 05:32:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650285121; cv=none; d=google.com; s=arc-20160816; b=Fjjy6pabGVzNT1ysO4eYPZQO5B+NNHb4keJw6wbwWjsreZzoOxyM8JrlpH6Twrmbdx MGZrL7CUQTz0h48U64cvf3ad9sUacNIr0Qav2aMwmLMaz+PckgkOg2P28mDHzEeCOJaf yCT+9VWEVIAmM2oAyZkcEjj88PqFD+EFQHVQhwZAWuD+xUksCeKpDPiace/ZZe7G1dYF ZDIZF7hvE2D8TqOshdp/11M7NIsEniEVVUp5dXl1nwFvUqM/iUVOEqFSI/no6hSHw083 q7yurqhhsTFIAJS4jB/6NXF9dwLJSrlxcJ6oSrbGGpSIq8oymiIaUxosYdOres+ejOiI cFEA== 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 :message-id:date:subject:cc:to:from; bh=Gxr1PiDAxKmzlT9cRMNMwlv2B/5dV263mnJXiItn1Uc=; b=xrKFpbWF2qZr+B9gvYfnxbbX4qQJttTt6x361DIfSTwhoFs4Co2cXWmOobQYYRXnMa 7Aim677v7aBMeQmmiHs8CT5jJUasbA9JY0Uz7OYAb0uscKyVO4mS1sXxV6zEPsdAb1QK QsSin/pCIhggy4+BY38ahAZL84Z5EyfUS2m7mI+hnuWi27aUV7a2IIIBJBo1pSy80Urj Tzy3AZf1ZC2+c+CkWYQMxC5xFnU2wcWxMMdPNVjngJGkYKbgjBWd2yzgUgEnyNiQktww FmLILfU3PHS/zamqUguuBNxCrAdAhym5a5XGRd8RjjA8ZnIV5G+Vv0760+EL2P2ZdpX6 aM2A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q17-20020a17090676d100b006df8f537b79si5842003ejn.528.2022.04.18.05.31.31; Mon, 18 Apr 2022 05:32:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233955AbiDQK60 (ORCPT + 99 others); Sun, 17 Apr 2022 06:58:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229559AbiDQK6W (ORCPT ); Sun, 17 Apr 2022 06:58:22 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DA971010; Sun, 17 Apr 2022 03:55:44 -0700 (PDT) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Kh6Nn1xYyzFpXF; Sun, 17 Apr 2022 18:53:13 +0800 (CST) Received: from dggpemm500017.china.huawei.com (7.185.36.178) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sun, 17 Apr 2022 18:55:41 +0800 Received: from huawei.com (10.175.101.6) by dggpemm500017.china.huawei.com (7.185.36.178) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sun, 17 Apr 2022 18:55:40 +0800 From: Wenchao Hao To: Mike Christie , Lee Duncan , Chris Leech , "James E . J . Bottomley" , "Martin K . Petersen" , , , CC: , Wenchao Hao Subject: [PATCH v2] scsi: iscsi: Fix multiple iscsi session unbind event sent to userspace Date: Sun, 17 Apr 2022 20:06:28 -0400 Message-ID: <20220418000627.474784-1-haowenchao@huawei.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500017.china.huawei.com (7.185.36.178) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_12_24, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I found an issue that kernel would send ISCSI_KEVENT_UNBIND_SESSION for multiple times which should be fixed. This patch introduce target_unbound in iscsi_cls_session to make sure session would send only one ISCSI_KEVENT_UNBIND_SESSION. But this would break issue fixed in commit 13e60d3ba287 ("scsi: iscsi: Report unbind session event when the target has been removed"). The issue is iscsid died for any reason after it send unbind session to kernel, once iscsid restart again, it loss kernel's ISCSI_KEVENT_UNBIND_SESSION event. Now kernel think iscsi_cls_session has already sent an ISCSI_KEVENT_UNBIND_SESSION event and would not send it any more. Which would cause userspace unable to logout. Actually the session is in invalid state(it's target_id is INVALID), iscsid should not sync this session in it's restart. So we need to check session's target unbound state during iscsid restart, if session is in unbound state, do not sync this session and perform session teardown. It's reasonable because once a session is unbound, we can not recover it any more(mainly because it's target id is INVALID) Changes from V1: - Using target_unbound rather than state to indicate session has been unbound Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_transport_iscsi.c | 21 +++++++++++++++++++++ include/scsi/scsi_transport_iscsi.h | 1 + 2 files changed, 22 insertions(+) diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c index 2c0dd64159b0..43ba31e595b4 100644 --- a/drivers/scsi/scsi_transport_iscsi.c +++ b/drivers/scsi/scsi_transport_iscsi.c @@ -1958,6 +1958,14 @@ static void __iscsi_unbind_session(struct work_struct *work) ISCSI_DBG_TRANS_SESSION(session, "Unbinding session\n"); + spin_lock_irqsave(&session->lock, flags); + if (session->target_unbound) { + spin_unlock_irqrestore(&session->lock, flags); + return; + } + session->target_unbound = 1; + spin_unlock_irqrestore(&session->lock, flags); + /* Prevent new scans and make sure scanning is not in progress */ mutex_lock(&ihost->mutex); spin_lock_irqsave(&session->lock, flags); @@ -2058,6 +2066,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id) session->target_id = target_id; dev_set_name(&session->dev, "session%u", session->sid); + session->target_unbound = 0; err = device_add(&session->dev); if (err) { iscsi_cls_session_printk(KERN_ERR, session, @@ -4319,6 +4328,15 @@ iscsi_session_attr(def_taskmgmt_tmo, ISCSI_PARAM_DEF_TASKMGMT_TMO, 0); iscsi_session_attr(discovery_parent_idx, ISCSI_PARAM_DISCOVERY_PARENT_IDX, 0); iscsi_session_attr(discovery_parent_type, ISCSI_PARAM_DISCOVERY_PARENT_TYPE, 0); +static ssize_t +show_priv_session_target_unbound(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent); + return sysfs_emit(buf, "%d\n", session->target_unbound); +} +static ISCSI_CLASS_ATTR(priv_sess, target_unbound, S_IRUGO, + show_priv_session_target_unbound, NULL); static ssize_t show_priv_session_state(struct device *dev, struct device_attribute *attr, char *buf) @@ -4422,6 +4440,7 @@ static struct attribute *iscsi_session_attrs[] = { &dev_attr_priv_sess_recovery_tmo.attr, &dev_attr_priv_sess_state.attr, &dev_attr_priv_sess_creator.attr, + &dev_attr_priv_sess_target_unbound.attr, &dev_attr_sess_chap_out_idx.attr, &dev_attr_sess_chap_in_idx.attr, &dev_attr_priv_sess_target_id.attr, @@ -4534,6 +4553,8 @@ static umode_t iscsi_session_attr_is_visible(struct kobject *kobj, return S_IRUGO | S_IWUSR; else if (attr == &dev_attr_priv_sess_state.attr) return S_IRUGO; + else if (attr == &dev_attr_priv_sess_target_unbound.attr) + return S_IRUGO; else if (attr == &dev_attr_priv_sess_creator.attr) return S_IRUGO; else if (attr == &dev_attr_priv_sess_target_id.attr) diff --git a/include/scsi/scsi_transport_iscsi.h b/include/scsi/scsi_transport_iscsi.h index 9acb8422f680..877632c25e56 100644 --- a/include/scsi/scsi_transport_iscsi.h +++ b/include/scsi/scsi_transport_iscsi.h @@ -256,6 +256,7 @@ struct iscsi_cls_session { struct workqueue_struct *workq; unsigned int target_id; + int target_unbound; /* make sure unbind session only once */ bool ida_used; /* -- 2.32.0