From patchwork Tue Oct 10 23:33:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Moger, Babu" X-Patchwork-Id: 151048 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp200140vqb; Tue, 10 Oct 2023 16:34:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFjzkDaJqOG1ntTTX6Mm9YYs32oDSG/J9zKxTvv6mcEHplXKTQnufM7+o2LosFQXCe+IuwH X-Received: by 2002:a17:90b:17c3:b0:27c:f653:37b2 with SMTP id me3-20020a17090b17c300b0027cf65337b2mr2182589pjb.1.1696980866934; Tue, 10 Oct 2023 16:34:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1696980866; cv=pass; d=google.com; s=arc-20160816; b=Ktk2QUFtzehLv6iKtmQp/WrM4oHLUHG2p7Ymx7rS3I9BcZjqZUTk4eMLqxq90Op+3p qU1aNK/vgxPHHxLrJFOAkYM/3IXhD6mBsF3cXgz9ALEU1Nb2VIjvjq3XqzaTXd/dO/5W 7xAOU3Mj06vz0Fnx7Tus47g+lQYSImqCevlZrrVkBK5+oz4pRv1LYLtL/jCOozN5eeSg u43jn00uASwf7MQsjS59QqyAIKX7iIL/MtOmoRJ2EJPx8Un4n8GnaPHJKSdCRJ/mMqH6 wCB6XWDHWZEfvgc63q0AQoem8sxgaa3qLseUPSTmDneGRXoR5ruMkODG8NEhZFtToI7B TS7A== 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=17+APesLAgJrzKT0p23QwGARelWvZo7zmLb7Gnj/sjE=; fh=a8QQDpsyeps30vd5Li+WI6v6dtcd7xKVvftia9bksQM=; b=zJoiIpYVgEoOiuofnemx1gQ+5j2gDg/pR6C7VLWYH0QpoUtt0+G8vV6zWVqAGyZctf 7H4Mz7dExlfoBxVeu5wBHD1ZFNLndLqbV2yDDuPvv5YMDeT9rvDf0rfgkr1e8YirWNBX ZIla0ZQ8dwkSDgEi0IyR0kaB/wh2/a3uSJUuFtVOeHUwiSgBoSuhm3JL1PefBalrOXy6 wgpia/6XE/oKxoH+aTheDfcvV+DnpVVTKlzgXzzBSTHVd20FvCO/8xGyG9rS1OZxuFhO FBvU38J37nDyf9lstSGDPDP84p+i0JrhjvNPFJwk9zIuhwwr60xu1zUGytPu/9NHkUWJ YjYA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=wGiDeWkS; 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:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id gj2-20020a17090b108200b002775281b839si7499871pjb.39.2023.10.10.16.34.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 16:34:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=wGiDeWkS; 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:7 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 snail.vger.email (Postfix) with ESMTP id EEB898104388; Tue, 10 Oct 2023 16:34:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229713AbjJJXeQ (ORCPT + 19 others); Tue, 10 Oct 2023 19:34:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344181AbjJJXd7 (ORCPT ); Tue, 10 Oct 2023 19:33:59 -0400 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2049.outbound.protection.outlook.com [40.107.237.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB31BAF; Tue, 10 Oct 2023 16:33:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YIS4MfX1CnlXO5LT2lFSzf8ReC9KYD+JSnPZ1Eyu0Wu3HUIGTsN/A4eiApwg1M5fROFrxjpsE0LgvldWhjCUQVHUoazuAOubCtLz0inaXUZM3+AKpg5am5x/MJSA4ArCZWXd6/7jDrgcQbWWFFjpHgbbjdLbidAk3Tls4RDt5+QxImlIuVT0ZJZ6itMBlI/KJKGusI8ZlVDXou9TWWJAx3fcZcby8EK6D3svd0cH2IyI9k3iM6KojbWBde4xIW/EHS8j9O0y5aoLn6tyrR68UAwTt+A0rlRKHuu3eoFJJOaMh2NHi9LDHYlNKVJuA90woJQaO8jfuhBj0ijzFupCpg== 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=17+APesLAgJrzKT0p23QwGARelWvZo7zmLb7Gnj/sjE=; b=Yohr93ej1JnBuHFxtKVTmYKMeZD8ppNVJjfl05SG6/6LxQu5efFqBQZVxYv21bLMe/A42a1Z6SQYNnkKmlwkVf+KRMMGctXbR8GbfBRT6nRcyEjUZF4RaLXD1pM662TTen/fNoZfD9pYV7oWJ9cQa7dNY7jXeBTN2Ccy2p9mQCOiXKg6oWjl8QxgIrVqR8sg/NmbvNOjdA6NNX3FrZOHEpWxBnSovBmgTItYdS3sGl9xq4VkkvfJ8Jo89RUR3LWnWoEyXBrq54KSOs+k3KkXvhXf3IHDE0YO31PASCpMnkpPgDxwXyr0tWFrKXewkSDvt7qYZaTSWjzrgZZx8H0wvQ== 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=17+APesLAgJrzKT0p23QwGARelWvZo7zmLb7Gnj/sjE=; b=wGiDeWkS4GvAantDHFYnTtioaylF8W1zxRqKbI3q11uUJbpZcVMoS6gc7yB/XYGLqPmqTxnYRZgEf/RzALWCVctIU3AXhSoDKCVXeLF+eyvEpKyIl+0egQcshGA/mVrtQ+EAEOflYyBXT/rvZHWZid1d+2OpP6dFtSwG8BcBHmk= Received: from BL1P222CA0007.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::12) by LV2PR12MB5965.namprd12.prod.outlook.com (2603:10b6:408:172::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.38; Tue, 10 Oct 2023 23:33:53 +0000 Received: from BL6PEPF0001AB51.namprd04.prod.outlook.com (2603:10b6:208:2c7:cafe::24) by BL1P222CA0007.outlook.office365.com (2603:10b6:208:2c7::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.38 via Frontend Transport; Tue, 10 Oct 2023 23:33:53 +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 BL6PEPF0001AB51.mail.protection.outlook.com (10.167.242.75) 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, 10 Oct 2023 23:33:53 +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; Tue, 10 Oct 2023 18:33:51 -0500 From: Babu Moger To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v12 06/10] x86/resctrl: Move default group file creation to mount Date: Tue, 10 Oct 2023 18:33:31 -0500 Message-ID: <20231010233335.998475-7-babu.moger@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231010233335.998475-1-babu.moger@amd.com> References: <20231010233335.998475-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: BL6PEPF0001AB51:EE_|LV2PR12MB5965:EE_ X-MS-Office365-Filtering-Correlation-Id: 90a03560-7414-497c-4f45-08dbc9e95d43 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kw7XCzTcDJAaw1oSDkY9pNXXp7KGDDegIvusmdZiyUKaMimqQ6hLsJe6MQsDpremopk6MCJvRynNNVB6Zrvj28FemkcJmcmhU9/QAtAvlnD2m3PCuLUd8ZdUKL4RdTN2OYOrhC2/g926/VXq5ja77TbhQHjHHgCHgpr1LUPTZrsa9r2npr6bX9dHIos6euOw8+d94aEQf02hHk68+fNKmUNCYLa+nJ70xmxygrhUAyJbGpEaD94aAl7JWK0gLQzznApwPF1TJ2U7tWEIOBTkoVq4Set2XxdHy55G4RsZQLo6Jo8TQlUKw3Wz5R6vCgsOkw/nLXBZCO4EVS+nY/KJTe0Y7gmMy0JCX5I8O97m4OxiPN5XBL3z+XRqwWyc8Zpam8PBUWbTPfIu7sVj7ae6DNHDeHCP4LKwmFxy371lmCdKYo6ylJt36dMa/MgrhzIilLp1z2q5ld7JA+6ez0lDQIhZNwVnqQ7qPJPyyak7xIq38SD6FqtGRyqLE2C/Gb48ffuMuMRCyvwA2Chqzlo6l1qNZcqdeGZegKGcjOppcDem66Ey+EBX4ru2g4m/jaYhA4shHuobrCSBEN3MeoJfBZU2wWlyDc4ZymknBq+/uId9SZOEnYEBvaoWQEg+0jRNOFGbiuPhv+MWcISDHIXN+4HyVFQ+ZYN6ulAzIQ0rTSeIzZ8cqqwbbPe9ZehbSINTyoEOb+xD/xZ6cXphavzjs6ES2AqV0ySb8lUVZoSu6pydK2qnERwIXGWRNOzooG1YBSTsR3y66rlqN59V7qzXaw== 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)(396003)(376002)(39860400002)(136003)(346002)(230922051799003)(64100799003)(82310400011)(451199024)(1800799009)(186009)(46966006)(36840700001)(40470700004)(40480700001)(7696005)(40460700003)(2616005)(41300700001)(1076003)(356005)(81166007)(82740400003)(16526019)(26005)(36756003)(70586007)(70206006)(110136005)(54906003)(86362001)(316002)(47076005)(83380400001)(5660300002)(44832011)(7416002)(7406005)(426003)(336012)(66574015)(36860700001)(2906002)(8936002)(4326008)(8676002)(478600001)(6666004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Oct 2023 23:33:53.1687 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 90a03560-7414-497c-4f45-08dbc9e95d43 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: BL6PEPF0001AB51.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5965 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, URIBL_BLOCKED autolearn=no 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 10 Oct 2023 16:34:26 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779413409296164315 X-GMAIL-MSGID: 1779413409296164315 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 --- 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 3ea874c80c22..a34657f0bd0c 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) @@ -2511,10 +2514,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(); @@ -2523,6 +2530,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; @@ -2579,6 +2592,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); @@ -2649,7 +2664,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; @@ -2819,6 +2833,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); @@ -3700,10 +3715,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, @@ -3711,6 +3724,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; @@ -3720,19 +3747,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) @@ -3854,13 +3869,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) @@ -3893,8 +3906,6 @@ int __init rdtgroup_init(void) cleanup_mountpoint: sysfs_remove_mount_point(fs_kobj, "resctrl"); -cleanup_root: - kernfs_destroy_root(rdt_root); return ret; } @@ -3904,5 +3915,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); }