Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3253549pxf; Mon, 22 Mar 2021 01:37:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8ox4iuEE9m0vf2qQMo6gdWsFeXxii5EbbEJfEp3Z/xtmAI5UdPBtFKvEBPYvTcSuUOJ5Q X-Received: by 2002:a17:907:7014:: with SMTP id wr20mr18289701ejb.179.1616402261000; Mon, 22 Mar 2021 01:37:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616402260; cv=none; d=google.com; s=arc-20160816; b=K0nILQa3tAB+dAxkxAss1+wAiOzZAiwfw5XSAJ8p6o5mlk0hncFcXbrP+3bKJOZ0X3 o+yTK0W/NxF9YvhavAv16VSJd119pAkEGaWCg+QS4trc+ruVD1srRTbkY/P4GUZ54I0q Nj25SNqhrYZBCTZ+G0bCd8ye3GuZF68i3cCgqROxEBx6FMKlPTNCFDqWlGL0HgQHDqkW klpOr7hYvR60ynL9S6gOE0J6+Y4OxUuHDgNU4j/pOMNPrE/jNrGy1VunA1CouC9iIk3q dkwq7GJbBqrrtXQeMtsx7JYO9lfHIPZXUALGabFytvtdks6dWGs/4wQv4NRCacwy0GdJ 1DdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=QoevHkEyhDjxsOKj6fJ4R4SgOfRQylQoV4S5iGinLZU=; b=E3i7x+y7/ERUNPHpUACMzkbtUxX8CL+9wuIp9R7GsguAK27Fn7eOuvwTgvKjgn4jt6 CZlxrIRqA2wTd71CijLG6BDbcDt1Loed79ts9eKpQZP9yu0/8GEv9KeEs9hP6Id96BeR +bWSLGE9I6CseNTeafZjC3KJnSWNui0hBVAZ5uSdy3IDFcAKcffI7q0SPM5oQNCFxqAL PTZj/MyzD+ytR7V1VI1mmyvO4nGtZVXsMTKTGre6X7NXR3Aakdv2hjR2es0xqyZjvDq5 tXWa9gj6TEUxjfV0qYJwV6UUBcYE14cdP3urQJhDOemSqCfPaRoFCxcgcCmdLhkKRc0Y pw+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=D1nWnujJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bx25si11454283edb.242.2021.03.22.01.37.18; Mon, 22 Mar 2021 01:37:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=D1nWnujJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229871AbhCVIfw (ORCPT + 99 others); Mon, 22 Mar 2021 04:35:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229508AbhCVIfg (ORCPT ); Mon, 22 Mar 2021 04:35:36 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E87E0C061574; Mon, 22 Mar 2021 01:35:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=QoevHkEyhDjxsOKj6fJ4R4SgOfRQylQoV4S5iGinLZU=; b=D1nWnujJVHJ4MgUjzDSpImYZAf /0UT4qq4l0rO6u1vGolh/id2xfThwNNw5HdMWaZxUGPcTXKXqO1LDhF39j5rCORszzvOoltjdYdzi vdHViRlfbrRePQfgaOZCC0sekOtwgXBHtiMrNLHVCi1LdnOCUS1ybjRcqei7y1qQAOoLfxKMsYwW1 GtrmEnJdbEh1Z0+7iF0yKKJTBLQh+IxCENArr9jqTOQebxFH9r5aSDx0/1efNNz0tdVOs54ENgh3q eDpsL/6Vn0RAcDq9U/SJnruG64G1sNujBf3bVTc6pEqv/tudiNTP1WTpcmuoBn5tUTKLWmOxk6VRB bCblmvMg==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lOG1N-008DOR-LV; Mon, 22 Mar 2021 08:34:55 +0000 Date: Mon, 22 Mar 2021 08:34:45 +0000 From: Matthew Wilcox To: Namjae Jeon Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-cifs@vger.kernel.org, linux-cifsd-devel@lists.sourceforge.net, smfrench@gmail.com, senozhatsky@chromium.org, hyc.lee@gmail.com, viro@zeniv.linux.org.uk, hch@lst.de, hch@infradead.org, ronniesahlberg@gmail.com, aurelien.aptel@gmail.com, aaptel@suse.com, sandeen@sandeen.net, dan.carpenter@oracle.com, colin.king@canonical.com, rdunlap@infradead.org, Sergey Senozhatsky , Steve French Subject: Re: [PATCH 2/5] cifsd: add server-side procedures for SMB3 Message-ID: <20210322083445.GJ1719932@casper.infradead.org> References: <20210322051344.1706-1-namjae.jeon@samsung.com> <20210322051344.1706-3-namjae.jeon@samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210322051344.1706-3-namjae.jeon@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 22, 2021 at 02:13:41PM +0900, Namjae Jeon wrote: > +++ b/fs/cifsd/mgmt/ksmbd_ida.c > @@ -0,0 +1,69 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (C) 2018 Samsung Electronics Co., Ltd. > + */ > + > +#include "ksmbd_ida.h" > + > +struct ksmbd_ida *ksmbd_ida_alloc(void) > +{ > + struct ksmbd_ida *ida; > + > + ida = kmalloc(sizeof(struct ksmbd_ida), GFP_KERNEL); > + if (!ida) > + return NULL; > + > + ida_init(&ida->map); > + return ida; > +} ... why? Everywhere that you call ksmbd_ida_alloc(), you would be better off just embedding the struct ida into the struct that currently has a pointer to it. Or declaring it statically. Then you can even initialise it statically using DEFINE_IDA() and eliminate the initialiser functions. I'd remove the ksmbd_ida abstraction, although I like this wrapper: > +int ksmbd_acquire_smb2_tid(struct ksmbd_ida *ida) > +{ > + int id; > + > + do { > + id = __acquire_id(ida, 0, 0); > + } while (id == 0xFFFF); > + > + return id; Very clever, given your constraint. I might do it as: int id = ida_alloc(ida, GFP_KERNEL); if (id == 0xffff) id = ida_alloc(ida, GFP_KERNEL); return id; Although ... > + tree_conn = ksmbd_alloc(sizeof(struct ksmbd_tree_connect)); > + if (!tree_conn) { > + status.ret = -ENOMEM; > + goto out_error; > + } > + > + tree_conn->id = ksmbd_acquire_tree_conn_id(sess); > + if (tree_conn->id < 0) { > + status.ret = -EINVAL; > + goto out_error; > + } > + > + peer_addr = KSMBD_TCP_PEER_SOCKADDR(sess->conn); > + resp = ksmbd_ipc_tree_connect_request(sess, > + sc, > + tree_conn, > + peer_addr); > + if (!resp) { > + status.ret = -EINVAL; > + goto out_error; > + } > + > + status.ret = resp->status; > + if (status.ret != KSMBD_TREE_CONN_STATUS_OK) > + goto out_error; > + > + tree_conn->flags = resp->connection_flags; > + tree_conn->user = sess->user; > + tree_conn->share_conf = sc; > + status.tree_conn = tree_conn; > + > + list_add(&tree_conn->list, &sess->tree_conn_list); This is basically the only function which calls that, and this is a relatively common anti-pattern when using the IDA -- you've allocated a unique ID, but then you stuff the object in a list and ... > +struct ksmbd_tree_connect *ksmbd_tree_conn_lookup(struct ksmbd_session *sess, > + unsigned int id) > +{ > + struct ksmbd_tree_connect *tree_conn; > + struct list_head *tmp; > + > + list_for_each(tmp, &sess->tree_conn_list) { > + tree_conn = list_entry(tmp, struct ksmbd_tree_connect, list); > + if (tree_conn->id == id) > + return tree_conn; > + } ... walk the linked list looking for an ID match. You'd be much better off using an allocating XArray: https://www.kernel.org/doc/html/latest/core-api/xarray.html Then you could lookup tree connections in O(log(n)) time instead of O(n) time.