From patchwork Sun Jan 15 10:32:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dawei Li X-Patchwork-Id: 43827 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp678540wrn; Sun, 15 Jan 2023 02:33:35 -0800 (PST) X-Google-Smtp-Source: AMrXdXtjl+fYqbNvP5PMx0uIgSGSM3wv7YlvTyXt5i/KB8mh8p0UhIGNYwtqAoc5wW9AegwwhFoK X-Received: by 2002:a17:906:40ca:b0:861:b4c5:63ba with SMTP id a10-20020a17090640ca00b00861b4c563bamr14566726ejk.41.1673778815276; Sun, 15 Jan 2023 02:33:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1673778815; cv=pass; d=google.com; s=arc-20160816; b=HN1a8aA+2WNXCkpKhhXtqXFwjWCOW7z0059dIoK8FoaaSLMZPBe6Devpb1wprx9QKD 9vHu2kg+7R5x39lCiQM+hE3dCLFOD+AiFE9kzl2wvJtY7gJyvyFXgyNbsCzZwPPVa9UX n5ef8PVe1vZB0XigUZ8S5hO0NVfHoy5xf940jPSJ9ucsGTgyVBoFDzLzVdPCyvQvIbJY sUG9MDUYHtmnObY/fdQl+WNHncuSGVlUM1jXVT55oTws4Aq1hzCAwUAtN4/M6DzjpTT2 Kx2p+m6dKhqQ3Q6TsKtaCy8stE5aJKBGUgf/a0V5UYhVA0Ij0kdaI7EzPFKlIoFf692B Tceg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7/z5IhOIPXlG5Tpw7qq8tOb5ZzZF8eAXGh4FcWVVGQ4=; b=DVbThsJwPIibX7lrrzFLyDLdTLdbT+Y2GAm2xqnMLSx+zFFDaMFOeIParJ4S5PfeYW fKIPl5g5fppa1zQoUb3mJxIfH4EFLVaETtlIA1JXngvc9gSFuEIJiQl5CC95oLQ8fv3T 48k2kbcbEEvKcfsv7a186liekSseJfP7d6zBzG72MHRBLMqoXhFlbGeHNRE82WxigaPx JbywT5Jx1iAj5AEpj0H7W0lSbho5zFMdlEVM5QrBpqLIU5fhB2AAsUMtWTDROrdFJKSe APfTUTZBJemjRW3FSVF5jol96gukgTbzb3gqM/r3kN9EA7kAyjZdA2W6VLnamNmVO45Y wBrw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=Yebh6Bti; arc=pass (i=1); 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cx26-20020a05640222ba00b0048c7e8f3dcasi24538812edb.483.2023.01.15.02.33.12; Sun, 15 Jan 2023 02:33:35 -0800 (PST) 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; dkim=pass header.i=@outlook.com header.s=selector1 header.b=Yebh6Bti; arc=pass (i=1); 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229848AbjAOKca (ORCPT + 99 others); Sun, 15 Jan 2023 05:32:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230433AbjAOKcX (ORCPT ); Sun, 15 Jan 2023 05:32:23 -0500 Received: from JPN01-OS0-obe.outbound.protection.outlook.com (mail-os0jpn01olkn2097.outbound.protection.outlook.com [40.92.98.97]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A496BC16B; Sun, 15 Jan 2023 02:32:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kUtS0bepUHxrIe1SpVHrepYAa7FqTmblJvfkgtKN5NOHF4ibbakk0hcnar+jY8hm+EmjQSeo5rarkK74wGMjFalE5cMpBGLs9OyAA+L31UQC6gcGObKPBv4jAOkjz+2HfLeJchE9k/bvHIcBmJum9ZONvWEpFLYMLvOOYtcjOwDL0dkdML800rVYn02zqyZxpcRDtfH6XltFZKd4xW2hS5LL5Fx+8vu0sFCKPvhl8pB8PgDG06k9QZcYMt75yGkuhXzshuZ3aa4u+y6+N7yvMTSEtpcgPN3uZBgLnIXsRnZdrn9J1V+2SfU7cPNT2KnZfKlZF32jZyRJV547a5r89Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7/z5IhOIPXlG5Tpw7qq8tOb5ZzZF8eAXGh4FcWVVGQ4=; b=Tx6RApHgBfFrXbgDlPqUVELVdRgF1fGNr5r6JWyImYRT/oT5LDZiSZMLJwyfDBda7FQK+gLuZG2DkziOXsBzQQ5enZw25OcSdyTMYPGzCmNyDw8AXd/eslyNp5Eaot3J5crVpnIO+wpWPjvs77sWSpPgB7XuTDJ9P5PBrzsgVKJHD4zoY7mLHQyo/1hT6r0g427qHZmcV0uqH0+72elKDpH58PZ7ALb9zLx2iUSdpPgQhrbjTJ4rd9ugUwAzAvRAvXiBbAGyhk2Pc8DBlpI/veFFTy+BU1SGY8rfKPYEZBsK8E8Rs7mDbBJseduATYQ6PwZTEg4YNva0APYN+OrbRg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7/z5IhOIPXlG5Tpw7qq8tOb5ZzZF8eAXGh4FcWVVGQ4=; b=Yebh6Bti0XrLK8+ydDTxuR7gaqi3TnhyYHC2KS3/uPE2Kgxm0brmagf2lywJOoUz0RrTRgo1VxueeddAdJ//pV3LD7stQtsUdRtsqIIom8hgFoPNwYpzrLttrn0692+vhndM5unr/1OKzmieYby/ytT0UJBC+6ONDCDfg6wRq/hVO6w6LMdP2LzbieRyUVcWnFSN/UY6y+/N04KAqFe82UzaoYpb13WKsIwlskzQxVop05R8R/8c/PVNbnY/5R88fg0BaXvTFhtN0efUWbtpqXk4PpdUOoF1q7Puw5E+my80YwpjP4wmq6u0RNT3VA5YyeOhEj8KuOXTiSgamwqnLw== Received: from TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:152::9) by OS3P286MB2025.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a0::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.12; Sun, 15 Jan 2023 10:32:20 +0000 Received: from TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM ([fe80::ff96:9cb6:e047:c605]) by TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM ([fe80::ff96:9cb6:e047:c605%4]) with mapi id 15.20.6002.012; Sun, 15 Jan 2023 10:32:20 +0000 From: Dawei Li To: linkinjeon@kernel.org, sfrench@samba.org Cc: senozhatsky@chromium.org, tom@talpey.com, hyc.lee@gmail.com, linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/6] ksmbd: Implements sess->rpc_handle_list as xarray Date: Sun, 15 Jan 2023 18:32:05 +0800 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230115103209.146002-1-set_pte_at@outlook.com> References: <20230115103209.146002-1-set_pte_at@outlook.com> X-TMN: [EdmPNEYwTS/yCGMCV7L4MtMVsF/Kc7EzOaVbGLojHmk=] X-ClientProxiedBy: TYAPR01CA0210.jpnprd01.prod.outlook.com (2603:1096:404:29::30) To TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:152::9) X-Microsoft-Original-Message-ID: <20230115103209.146002-3-set_pte_at@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYCP286MB2323:EE_|OS3P286MB2025:EE_ X-MS-Office365-Filtering-Correlation-Id: 4db69377-ec9a-4aad-d839-08daf6e3c7ec X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MD3OLuawmpKAwR2XgCiNISZTQoldvNp+SMKSMjLYDW5VnGJv9Ify+ZU+8zJ7EXxXV4VWkPDqHCMguDKOYOHHpAdf/twcqeFsVYZ79/vfvOU170kb9qQLp0jXFXORkEK8UytuHnnJ3OCNCAVRJTwpDWygdWEWNzsi+6ntRAzVkJOJGyi7LDPfjeSBFfhFjCzePpaiK60r2hzOmFGEMiSZ0U4RKFTTJRKj8xxsW9e4ETmXKbJo6xDE8ul7r+KzhsZH1pZTmnuSmmiUbhK1o1ldOfuFEpAKucJMQyfPZIGkYtWucrVxRJiCy/raGHRIyh2pH7C+5Xwqe8bGPTm46CGBSKyL46qsjnw0FnMwdsYBk53cUAXePWd5ChUh2VSWBZg0RmBFnwTF1suSzIx9wvY5dnpwt2swlFLwaPbJRzeoueYcB+MgLGI0H5SRRkzptXd5dEfyz6P3f/V7LR3+Qt/9qZe68x/DwvQqzfEX/AS32P8Y1kVexlbCqdZchLKYkoqczV4e+PVts4jMIwhsMu03rBVW0xF0KkLnb43i7m40iSSuElpYkZMkzI98BB3pv5Lp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WIWRwkBS2gInKwFZGW1XtfEG2r6p5oieQevXNpu/U1AD3OXxmmpKIAefO5XxhF4SIBNdulCDi9boCDDMyEQN850WS2cmXpG/fEOgRTq2CARwZ+QooqCZZaI7mR5c9NnRLfZzIYcSsX993ew9t/vkscGTcSdZcFnm+b0mPW5C6kz0WvMBskFCK78f0cPxucuo4x8HwlTNAPLpf5imLogvFh6n5kYbdyHiMlS9gFhJFNFn0tbOVJk/MjUe+3FPA6avd251HjzduHhuQ1DnbroR5gd1o9Rb+P2Ki+cumHMzBotzK1KKAITO0Mittb7uJt4epGQlrGlZg= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4db69377-ec9a-4aad-d839-08daf6e3c7ec X-MS-Exchange-CrossTenant-AuthSource: TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jan 2023 10:32:20.1511 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: OS3P286MB2025 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755084294983884686?= X-GMAIL-MSGID: =?utf-8?q?1755084294983884686?= For some ops on rpc handle: 1. ksmbd_session_rpc_method(), possibly on high frequency. 2. ksmbd_session_rpc_close(). id is used as indexing key to lookup channel, in that case, linear search based on list may suffer a bit for performance. Implements sess->rpc_handle_list as xarray. Signed-off-by: Dawei Li --- fs/ksmbd/mgmt/user_session.c | 37 ++++++++++++++---------------------- fs/ksmbd/mgmt/user_session.h | 2 +- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/fs/ksmbd/mgmt/user_session.c b/fs/ksmbd/mgmt/user_session.c index a2b128dedcfc..1ca2aae4c299 100644 --- a/fs/ksmbd/mgmt/user_session.c +++ b/fs/ksmbd/mgmt/user_session.c @@ -25,7 +25,6 @@ static DECLARE_RWSEM(sessions_table_lock); struct ksmbd_session_rpc { int id; unsigned int method; - struct list_head list; }; static void free_channel_list(struct ksmbd_session *sess) @@ -58,15 +57,14 @@ static void __session_rpc_close(struct ksmbd_session *sess, static void ksmbd_session_rpc_clear_list(struct ksmbd_session *sess) { struct ksmbd_session_rpc *entry; + long index; - while (!list_empty(&sess->rpc_handle_list)) { - entry = list_entry(sess->rpc_handle_list.next, - struct ksmbd_session_rpc, - list); - - list_del(&entry->list); + xa_for_each(&sess->rpc_handle_list, index, entry) { + xa_erase(&sess->rpc_handle_list, index); __session_rpc_close(sess, entry); } + + xa_destroy(&sess->rpc_handle_list); } static int __rpc_method(char *rpc_name) @@ -102,13 +100,13 @@ int ksmbd_session_rpc_open(struct ksmbd_session *sess, char *rpc_name) entry = kzalloc(sizeof(struct ksmbd_session_rpc), GFP_KERNEL); if (!entry) - return -EINVAL; + return -ENOMEM; - list_add(&entry->list, &sess->rpc_handle_list); entry->method = method; entry->id = ksmbd_ipc_id_alloc(); if (entry->id < 0) goto free_entry; + xa_store(&sess->rpc_handle_list, entry->id, entry, GFP_KERNEL); resp = ksmbd_rpc_open(sess, entry->id); if (!resp) @@ -117,9 +115,9 @@ int ksmbd_session_rpc_open(struct ksmbd_session *sess, char *rpc_name) kvfree(resp); return entry->id; free_id: + xa_erase(&sess->rpc_handle_list, entry->id); ksmbd_rpc_id_free(entry->id); free_entry: - list_del(&entry->list); kfree(entry); return -EINVAL; } @@ -128,24 +126,17 @@ void ksmbd_session_rpc_close(struct ksmbd_session *sess, int id) { struct ksmbd_session_rpc *entry; - list_for_each_entry(entry, &sess->rpc_handle_list, list) { - if (entry->id == id) { - list_del(&entry->list); - __session_rpc_close(sess, entry); - break; - } - } + entry = xa_erase(&sess->rpc_handle_list, id); + if (entry) + __session_rpc_close(sess, entry); } int ksmbd_session_rpc_method(struct ksmbd_session *sess, int id) { struct ksmbd_session_rpc *entry; - list_for_each_entry(entry, &sess->rpc_handle_list, list) { - if (entry->id == id) - return entry->method; - } - return 0; + entry = xa_load(&sess->rpc_handle_list, id); + return entry ? entry->method : 0; } void ksmbd_session_destroy(struct ksmbd_session *sess) @@ -327,7 +318,7 @@ static struct ksmbd_session *__session_create(int protocol) set_session_flag(sess, protocol); xa_init(&sess->tree_conns); xa_init(&sess->ksmbd_chann_list); - INIT_LIST_HEAD(&sess->rpc_handle_list); + xa_init(&sess->rpc_handle_list); sess->sequence_number = 1; ret = __init_smb2_session(sess); diff --git a/fs/ksmbd/mgmt/user_session.h b/fs/ksmbd/mgmt/user_session.h index 44a3c67b2bd9..b6a9e7a6aae4 100644 --- a/fs/ksmbd/mgmt/user_session.h +++ b/fs/ksmbd/mgmt/user_session.h @@ -52,7 +52,7 @@ struct ksmbd_session { struct xarray ksmbd_chann_list; struct xarray tree_conns; struct ida tree_conn_ida; - struct list_head rpc_handle_list; + struct xarray rpc_handle_list; __u8 smb3encryptionkey[SMB3_ENC_DEC_KEY_SIZE]; __u8 smb3decryptionkey[SMB3_ENC_DEC_KEY_SIZE];