Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp94825imm; Thu, 21 Jun 2018 14:35:07 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIf2eL7ot1TMHIgi/sch5eQNropbDSl/82/5xOmDSZ8V2gHlQfWg/KyLo2oAnA83IQh94Vn X-Received: by 2002:a63:7906:: with SMTP id u6-v6mr23774226pgc.284.1529616907394; Thu, 21 Jun 2018 14:35:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529616907; cv=none; d=google.com; s=arc-20160816; b=XQdVQ9TKxdJUEQ86/4HGjq5e4FUgaA/onmmVSMf3NGcUMq21mqALN99UdF9z7+TE6g UTOCSbPgRDooNr7Zparpkfz5FG6Y+E1Etit4tG+qF0chCazspvwH4c4JpjVwQP97XQX1 RVKbd5SS6M25rJI3Cydv+DqIGriIfQ7YniI5c3vdodOcAAEKpKEHXqMnw7bPJ5TCk3LI FD6lwqd7EQUbnGcZ6zFw4f1re4HJAT5aCMtWMRh0xaT5ebIgny8hnGCYPLwMZDfmq4Eq FqV8S+pY95jRofV5Lrsr9Y/h9WfY4sqMu8LIPXwOZ1WXA4YXvqCAq6jEpwSMVO2aL4tZ Ntiw== 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:arc-authentication-results; bh=jpZNJHBBUaFgsshEoBzRwf4a8gtQRhGpCjXWABd7Qzc=; b=dWCI6B4opYgzFovj5qFQlt1ts+cA9SFaI82h84H3Q/SdFZYdDrOMeMImPniF/F71Z6 L01SIhTBrOo3KuTQODWOmwAqZK2kkZj81kurK7rCYJKGiUlp9Uy7pVeFiKo5MLrxwtHr s0sPgzyGIZADH5YW2nKK8H1iLQQlz6RroegnjxT1wXwImNy29m2jxie3z+lHf2hXqYoj z8Ee7usuSb1AFF/XrBn8oN0vK83sn68gsftyLJRQJZLi3OXf9/Ee5eoAyDx83+nUUbNz pylr4+nFbwiYhKdHCCmFFVmjiamD1ec3Fi095sE2/IM3/kMyv00PbGkQk9yp3LaR7uZN O/Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=V6QmJr54; 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 x14-v6si4751974pgq.242.2018.06.21.14.34.52; Thu, 21 Jun 2018 14:35: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=@infradead.org header.s=bombadil.20170209 header.b=V6QmJr54; 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 S934062AbeFUVcz (ORCPT + 99 others); Thu, 21 Jun 2018 17:32:55 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:41802 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933963AbeFUV3K (ORCPT ); Thu, 21 Jun 2018 17:29:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=jpZNJHBBUaFgsshEoBzRwf4a8gtQRhGpCjXWABd7Qzc=; b=V6QmJr54rLUDuXjwxXfeoZK8a Li5rLTQ9PlGKyFW5wyv7Ywl46wZJte0Cut/aReEyTeYQIaQAJTZPSJ16DVKAFfR06L9Ze/kocKbeZ 2/migke4fI4SoXKJzjly89GtJLu3jybcu5H/zGjmUYz1dzu1uqhsCrLegy6SottaOGT3sbu8fBa1b i+SKhle14ImwaqdX4KJyutRweMI4sAnVR10BoZn97k01cLRO5tSrjrB0Yhmgq0AN1zjtjv16P61lT A0lizpOaKPppkcKcRc98Um43aL2ipWbWG/AD4GzBG/983Y149DxwIz0wFWxBXxsL1K5FS03U8bEWK Z1K2di2KA==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fW78g-0001cH-5M; Thu, 21 Jun 2018 21:29:10 +0000 From: Matthew Wilcox To: linux-kernel@vger.kernel.org Cc: Matthew Wilcox , "Nicholas A. Bellinger" , Bart Van Assche , Hannes Reinecke , Kees Cook , Varun Prakash , Sagi Grimberg , Philippe Ombredanne , Greg Kroah-Hartman , Kate Stewart , Thomas Gleixner , "David S. Miller" , Denys Vlasenko , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Subject: [PATCH 18/26] target/iscsi: Allocate session IDs from an IDA Date: Thu, 21 Jun 2018 14:28:27 -0700 Message-Id: <20180621212835.5636-19-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180621212835.5636-1-willy@infradead.org> References: <20180621212835.5636-1-willy@infradead.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since the session is never looked up by ID, we can use the more space-efficient IDA instead of the IDR. I think I found a bug where we never reuse session ID 0, but there may be a good reason for it, so I've merely documented it in this patch. Not reusing session ID 0 doesn't even leak memory. Signed-off-by: Matthew Wilcox --- drivers/target/iscsi/iscsi_target.c | 10 ++-------- drivers/target/iscsi/iscsi_target.h | 4 +--- drivers/target/iscsi/iscsi_target_login.c | 20 ++++++-------------- 3 files changed, 9 insertions(+), 25 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index 8e223799347a..94bad43c41ff 100644 --- a/drivers/target/iscsi/iscsi_target.c +++ b/drivers/target/iscsi/iscsi_target.c @@ -57,9 +57,8 @@ static DEFINE_SPINLOCK(tiqn_lock); static DEFINE_MUTEX(np_lock); static struct idr tiqn_idr; -struct idr sess_idr; +DEFINE_IDA(sess_ida); struct mutex auth_id_lock; -spinlock_t sess_idr_lock; struct iscsit_global *iscsit_global; @@ -700,9 +699,7 @@ static int __init iscsi_target_init_module(void) spin_lock_init(&iscsit_global->ts_bitmap_lock); mutex_init(&auth_id_lock); - spin_lock_init(&sess_idr_lock); idr_init(&tiqn_idr); - idr_init(&sess_idr); ret = target_register_template(&iscsi_ops); if (ret) @@ -4375,10 +4372,7 @@ int iscsit_close_session(struct iscsi_session *sess) pr_debug("Decremented number of active iSCSI Sessions on" " iSCSI TPG: %hu to %u\n", tpg->tpgt, tpg->nsessions); - spin_lock(&sess_idr_lock); - idr_remove(&sess_idr, sess->session_index); - spin_unlock(&sess_idr_lock); - + ida_free(&sess_ida, sess->session_index); kfree(sess->sess_ops); sess->sess_ops = NULL; spin_unlock_bh(&se_tpg->session_lock); diff --git a/drivers/target/iscsi/iscsi_target.h b/drivers/target/iscsi/iscsi_target.h index 42de1843aa40..48bac0acf8c7 100644 --- a/drivers/target/iscsi/iscsi_target.h +++ b/drivers/target/iscsi/iscsi_target.h @@ -55,9 +55,7 @@ extern struct kmem_cache *lio_ooo_cache; extern struct kmem_cache *lio_qr_cache; extern struct kmem_cache *lio_r2t_cache; -extern struct idr sess_idr; +extern struct ida sess_ida; extern struct mutex auth_id_lock; -extern spinlock_t sess_idr_lock; - #endif /*** ISCSI_TARGET_H ***/ diff --git a/drivers/target/iscsi/iscsi_target_login.c b/drivers/target/iscsi/iscsi_target_login.c index 99501785cdc1..561d2ad38989 100644 --- a/drivers/target/iscsi/iscsi_target_login.c +++ b/drivers/target/iscsi/iscsi_target_login.c @@ -336,22 +336,16 @@ static int iscsi_login_zero_tsih_s1( timer_setup(&sess->time2retain_timer, iscsit_handle_time2retain_timeout, 0); - idr_preload(GFP_KERNEL); - spin_lock_bh(&sess_idr_lock); - ret = idr_alloc(&sess_idr, NULL, 0, 0, GFP_NOWAIT); - if (ret >= 0) - sess->session_index = ret; - spin_unlock_bh(&sess_idr_lock); - idr_preload_end(); - + ret = ida_alloc(&sess_ida, GFP_KERNEL); if (ret < 0) { - pr_err("idr_alloc() for sess_idr failed\n"); + pr_err("Session ID allocation failed %d\n", ret); iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, ISCSI_LOGIN_STATUS_NO_RESOURCES); kfree(sess); return -ENOMEM; } + sess->session_index = ret; sess->creation_time = get_jiffies_64(); /* * The FFP CmdSN window values will be allocated from the TPG's @@ -1163,11 +1157,9 @@ void iscsi_target_login_sess_out(struct iscsi_conn *conn, goto old_sess_out; if (conn->sess->se_sess) transport_free_session(conn->sess->se_sess); - if (conn->sess->session_index != 0) { - spin_lock_bh(&sess_idr_lock); - idr_remove(&sess_idr, conn->sess->session_index); - spin_unlock_bh(&sess_idr_lock); - } + /* Um, 0 is a valid ID. I suppose we never free it? */ + if (conn->sess->session_index != 0) + ida_free(&sess_ida, conn->sess->session_index); kfree(conn->sess->sess_ops); kfree(conn->sess); conn->sess = NULL; -- 2.17.1