From patchwork Tue Oct 17 00:23:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Moger, Babu" X-Patchwork-Id: 153826 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3808714vqb; Mon, 16 Oct 2023 17:24:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHJ0qeLmLp7oEDAGNbBiY3PJM5Dq3CDXYHYrj+thQDkmNnNCU+pqxn1aXmN8XxSvFqrscKr X-Received: by 2002:a05:6a20:d80d:b0:163:c167:964a with SMTP id iv13-20020a056a20d80d00b00163c167964amr570227pzb.1.1697502245754; Mon, 16 Oct 2023 17:24:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697502245; cv=pass; d=google.com; s=arc-20160816; b=clwp8m8YyppVSrkUKRJaSAxf2+72Jw1OqRHnu90mBDVfiewPzDS+4scS/Rs/wqcPzM yCd/mMnlbXE4DKwRzdJDH+y/MlPUqwyDE5yRJw6qsKlFKh5ehJUFD10r27FBE1Mt30RA EPbtQ6kcyL42A/dfmZ2X74VbewQfILncTC2RBI/wXbOH4hLiNBtN3/aJ1AyL41LoWiyS tJgVhqlsMmRPJgMMjnVUpz1vPWXH6Ms1RilDyZNxPtlbIVw69Glr+oQN39PlSGvCkPme ie01GADTimHTeEU8O2i58KwuiWlHHxDjaJwFleHP6EKabroBVAY4PHlpykPoBMe2TF0L U44A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=27DSedx2hGE4Bg3gVP5x0PPZ7tUFt+K2UTQLHt1cg8w=; fh=a8QQDpsyeps30vd5Li+WI6v6dtcd7xKVvftia9bksQM=; b=sIXMXmxo70VtGhzzPqC8UQIyZLcpgSm6ZJiwLiQYhWo7o1pCObjx5q7ugGBEQuUUSZ GstlvN/o/Z15qFUTwmFAjRKeAgX4meVDx8msC73Cc3dFWNFbgi+GT8NPzrtMsOtSrIj7 GdNOukAtEnZJD6AfjvLs95BD0c1bAmlLDXDZ+kPwT019E7rPkOTxmEmerLJ7gN/8ls2A Wr7qYOkngmEZFezWx2+asLQjQ8SJE+l5TcADqj2muaUCb6s4xBcyoHMJ/fb14OI4eO+x 02wPXSXM/WeShVv6aFDRTnqU9qMEQRUCQAfxjqvAAg9igrneeP03qLR09MIWSzZYQhxF UqkQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=gdBuLzrx; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id l1-20020a170902f68100b001c754f13381si497830plg.455.2023.10.16.17.24.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 17:24:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=gdBuLzrx; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 5629680203D3; Mon, 16 Oct 2023 17:24:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234286AbjJQAXv (ORCPT + 18 others); Mon, 16 Oct 2023 20:23:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234223AbjJQAXo (ORCPT ); Mon, 16 Oct 2023 20:23:44 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2057.outbound.protection.outlook.com [40.107.243.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2B93FE; Mon, 16 Oct 2023 17:23:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PJ8O0IMY3SGxAWmcY6YxRJ4glckZq3hw3/q9MlFJce5TA7pbzw/fmaMrh6BwFuCp0vG8B9lpWiCoM1u9yTTMTMJavq5eDZ8NC5WUI5BnKH1lonxeAqBnkqNmI52IxysECMSGzBzhqB73mtMajS1chK+Sq/DyTJcPtXWRjUlHQRmrZHYGRmlp5BlOEwatrkpna0/9htrpJ2vpjk8h8ObsWd8eNoxtngF4Qmo9uxZBHBrDQMd5xYSqn55kmnNgwW29QHq7ZdS5bkSZRxxmgmB1iIklA07XMeX67PPuLxxZSKXzRjX8lgZtcRnLyQ/fn2x0Grddupfzvh2flGIiHfZMXQ== 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=27DSedx2hGE4Bg3gVP5x0PPZ7tUFt+K2UTQLHt1cg8w=; b=chRPlQ2Vi4LH99iO3GtRgVkANs2F92RFXoblviNARWhiHW05laBhFO5rcCWcw97jqcUJ7JXNHsxf3qc1xSPNiEvalLAI0qpW3zMXCxRkEcB72oRPIK4PP4hXSs+PQmG6zN+Ap62KCyrEsFx8ms+UyKQvuM7oJaWztT9lARJx2ii2vFCXlqpxxJCQxa3qbKV6uix9gye8FO7mYAgWsbZz5lFDd2M4EDJzV7VqASkOmy4krm7RW5FK0YFDcLOYUeks0tGBsfu4M2Nc4kwO1IglkESx5FzjEY+J8z8e5iO9cPbOgLR3mRNuhrm1vGn54yr/R6hHarpBc5haKkOr/+WPpg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=27DSedx2hGE4Bg3gVP5x0PPZ7tUFt+K2UTQLHt1cg8w=; b=gdBuLzrxMjTJUmr4orkoGwEgJvkpkMzYx09u9eMd9T5/NusKqyJf2iWwg2MvxdBGOgw63jE/Tku7mYbBgNcNSnqaTeBB+A0rxjA9wVXV8Vr11m8kCphq634QBDhS1Ac+Lrn4DvQ/UGCtQ4xHx6CW7gpvooFwFLMQXBkSQ7FCzPY= Received: from SJ0PR03CA0153.namprd03.prod.outlook.com (2603:10b6:a03:338::8) by SA1PR12MB6726.namprd12.prod.outlook.com (2603:10b6:806:255::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35; Tue, 17 Oct 2023 00:23:37 +0000 Received: from MWH0EPF000989E7.namprd02.prod.outlook.com (2603:10b6:a03:338:cafe::26) by SJ0PR03CA0153.outlook.office365.com (2603:10b6:a03:338::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36 via Frontend Transport; Tue, 17 Oct 2023 00:23:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MWH0EPF000989E7.mail.protection.outlook.com (10.167.241.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.22 via Frontend Transport; Tue, 17 Oct 2023 00:23:36 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Mon, 16 Oct 2023 19:23:34 -0500 From: Babu Moger To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 5/9] x86/resctrl: Move default group file creation to mount Date: Mon, 16 Oct 2023 19:23:04 -0500 Message-ID: <20231017002308.134480-6-babu.moger@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231017002308.134480-1-babu.moger@amd.com> References: <20231017002308.134480-1-babu.moger@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000989E7:EE_|SA1PR12MB6726:EE_ X-MS-Office365-Filtering-Correlation-Id: 17378192-e38e-4f41-81f7-08dbcea74e1f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zUE9CtBsrw2KJrlKCKPwnNxFwF6jTW4ebBQs+I7LM2JDkzOBPtX2ISU7f6w07PI44Gi6oLKzDqECF/ZCanjFtrEDD872AiYvxd+x2vdck7fPZ3rhMKcVl5efRYh1jFhtAQCQNZ4a3907/jhoemI0uPuVr8BBjOy+UkNY0qpvf88Xe6tA74oG14RdR82Af3LvDAgjhrxcucobpwR8hPkJe4b4LmC3FnzJgrIu8h0jKiAVTDsDm28uozqwLqgSjfcR0OSZLNKLt5/ER3DOI1R12cIMVoQ1RlXlZeS7DhIzc1hmCQ1TXAxZjkEhfFovROIb2YjDQZYQgOhACgbFnLCoinjH3lUa0z0CSAyepZzKJJ5Ir0Lt8L4kJNI8BnV7U0P1aZDGp5DnOny0kD6eyYL5SyXNYqEhcMAME3C5LAGtbGYmFhRBDxqZuR5rj6b/sqhrDFDGJaR2rscWpHUFWcnlvGw4puFctZLbrobCcvHzeGJy37J1lqVonEG6QZJbpGy63aiugP7bDCng6dU4vikbxZ7pWTcCNdF/wU2rc7S5t2TXJEN+ZWzvIKCWPOjIK5MZr/cegbM1PiG1cYweT185jknL8ze89254S0dOcgebLWSrjrGX9vsIZ44WoHLuv0CNmOSmPbLc6+r9KQvSMN2efX4CAvH5VBsV5WtQk1umDXcVKCSXAgO2MygDOxY1YHSyrnScV3ZshOZsKmI1LpwKEYrTsWcJoL3JRck4crbw6aH5/KFznnEn0wt0Y5ovlLNf3suzm+G4/TP8wjoTqsQ2Pw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(136003)(376002)(396003)(346002)(39860400002)(230922051799003)(451199024)(186009)(1800799009)(64100799003)(82310400011)(46966006)(40470700004)(36840700001)(40480700001)(40460700003)(478600001)(110136005)(70206006)(70586007)(54906003)(2616005)(47076005)(83380400001)(356005)(36860700001)(86362001)(82740400003)(6666004)(316002)(41300700001)(26005)(1076003)(16526019)(7696005)(66574015)(426003)(336012)(36756003)(5660300002)(81166007)(44832011)(7406005)(7416002)(8676002)(2906002)(4326008)(8936002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2023 00:23:36.6886 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 17378192-e38e-4f41-81f7-08dbcea74e1f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000989E7.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB6726 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 16 Oct 2023 17:24:00 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779960114952381445 X-GMAIL-MSGID: 1779960114952381445 The default resource group and its files are created during kernel init time. Upcoming changes will make some resctrl files optional based on a mount parameter. If optional files are to be added to the default group based on the mount option, then each new file needs to be created separately and call kernfs_activate() again. Create all files of the default resource group during resctrl mount, destroyed during unmount, to avoid scattering resctrl file addition across two separate code flows. Signed-off-by: Babu Moger Tested-by: Peter Newman Reviewed-by: Peter Newman Tested-by: Tan Shaopeng Reviewed-by: Tan Shaopeng Reviewed-by: Fenghua Yu Reviewed-by: Reinette Chatre Reviewed-by: Ilpo Järvinen --- v14: No changes v13: No changes v12: No changes --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 58 +++++++++++++++----------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index d1b5fd70ccbb..55da93b5ca53 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -54,6 +54,9 @@ static struct kernfs_node *kn_mondata; static struct seq_buf last_cmd_status; static char last_cmd_status_buf[512]; +static int rdtgroup_setup_root(struct rdt_fs_context *ctx); +static void rdtgroup_destroy_root(void); + struct dentry *debugfs_resctrl; void rdt_last_cmd_clear(void) @@ -2529,10 +2532,14 @@ static int rdt_get_tree(struct fs_context *fc) goto out; } - ret = rdt_enable_ctx(ctx); + ret = rdtgroup_setup_root(ctx); if (ret) goto out; + ret = rdt_enable_ctx(ctx); + if (ret) + goto out_root; + ret = schemata_list_create(); if (ret) { schemata_list_destroy(); @@ -2541,6 +2548,12 @@ static int rdt_get_tree(struct fs_context *fc) closid_init(); + ret = rdtgroup_add_files(rdtgroup_default.kn, RFTYPE_CTRL_BASE); + if (ret) + goto out_schemata_free; + + kernfs_activate(rdtgroup_default.kn); + ret = rdtgroup_create_info_dir(rdtgroup_default.kn); if (ret < 0) goto out_schemata_free; @@ -2597,6 +2610,8 @@ static int rdt_get_tree(struct fs_context *fc) schemata_list_destroy(); out_ctx: rdt_disable_ctx(); +out_root: + rdtgroup_destroy_root(); out: rdt_last_cmd_clear(); mutex_unlock(&rdtgroup_mutex); @@ -2667,7 +2682,6 @@ static int rdt_init_fs_context(struct fs_context *fc) if (!ctx) return -ENOMEM; - ctx->kfc.root = rdt_root; ctx->kfc.magic = RDTGROUP_SUPER_MAGIC; fc->fs_private = &ctx->kfc; fc->ops = &rdt_fs_context_ops; @@ -2837,6 +2851,7 @@ static void rdt_kill_sb(struct super_block *sb) rdt_pseudo_lock_release(); rdtgroup_default.mode = RDT_MODE_SHAREABLE; schemata_list_destroy(); + rdtgroup_destroy_root(); static_branch_disable_cpuslocked(&rdt_alloc_enable_key); static_branch_disable_cpuslocked(&rdt_mon_enable_key); static_branch_disable_cpuslocked(&rdt_enable_key); @@ -3718,10 +3733,8 @@ static struct kernfs_syscall_ops rdtgroup_kf_syscall_ops = { .show_options = rdtgroup_show_options, }; -static int __init rdtgroup_setup_root(void) +static int rdtgroup_setup_root(struct rdt_fs_context *ctx) { - int ret; - rdt_root = kernfs_create_root(&rdtgroup_kf_syscall_ops, KERNFS_ROOT_CREATE_DEACTIVATED | KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK, @@ -3729,6 +3742,20 @@ static int __init rdtgroup_setup_root(void) if (IS_ERR(rdt_root)) return PTR_ERR(rdt_root); + ctx->kfc.root = rdt_root; + rdtgroup_default.kn = kernfs_root_to_node(rdt_root); + + return 0; +} + +static void rdtgroup_destroy_root(void) +{ + kernfs_destroy_root(rdt_root); + rdtgroup_default.kn = NULL; +} + +static void __init rdtgroup_setup_default(void) +{ mutex_lock(&rdtgroup_mutex); rdtgroup_default.closid = 0; @@ -3738,19 +3765,7 @@ static int __init rdtgroup_setup_root(void) list_add(&rdtgroup_default.rdtgroup_list, &rdt_all_groups); - ret = rdtgroup_add_files(kernfs_root_to_node(rdt_root), RFTYPE_CTRL_BASE); - if (ret) { - kernfs_destroy_root(rdt_root); - goto out; - } - - rdtgroup_default.kn = kernfs_root_to_node(rdt_root); - kernfs_activate(rdtgroup_default.kn); - -out: mutex_unlock(&rdtgroup_mutex); - - return ret; } static void domain_destroy_mon_state(struct rdt_domain *d) @@ -3872,13 +3887,11 @@ int __init rdtgroup_init(void) seq_buf_init(&last_cmd_status, last_cmd_status_buf, sizeof(last_cmd_status_buf)); - ret = rdtgroup_setup_root(); - if (ret) - return ret; + rdtgroup_setup_default(); ret = sysfs_create_mount_point(fs_kobj, "resctrl"); if (ret) - goto cleanup_root; + return ret; ret = register_filesystem(&rdt_fs_type); if (ret) @@ -3911,8 +3924,6 @@ int __init rdtgroup_init(void) cleanup_mountpoint: sysfs_remove_mount_point(fs_kobj, "resctrl"); -cleanup_root: - kernfs_destroy_root(rdt_root); return ret; } @@ -3922,5 +3933,4 @@ void __exit rdtgroup_exit(void) debugfs_remove_recursive(debugfs_resctrl); unregister_filesystem(&rdt_fs_type); sysfs_remove_mount_point(fs_kobj, "resctrl"); - kernfs_destroy_root(rdt_root); }