From patchwork Wed Jul 19 23:22:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Moger, Babu" X-Patchwork-Id: 122929 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2790633vqt; Wed, 19 Jul 2023 17:17:30 -0700 (PDT) X-Google-Smtp-Source: APBJJlGCw7jQ5apNnSyvO1l5DokRhhSrLHJee0MRjgCfQiO74eeuC+q7ISP01juu86UvFlfPAfX1 X-Received: by 2002:aa7:c0cd:0:b0:51d:ad30:5ed7 with SMTP id j13-20020aa7c0cd000000b0051dad305ed7mr3319878edp.35.1689812250231; Wed, 19 Jul 2023 17:17:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1689812250; cv=pass; d=google.com; s=arc-20160816; b=JGfurl0IcsucckhaALZXiKSIbkWLR/i4V+GD3t2MOiyt5evIWsvV/mLt0TBvTRHDrk 8fpXHguG/a6Em/MRZM4yNp06S1zQJcrgzXRbYRfZImM7Oe3bIPeisN2YMofLS3e6EE45 KY5uZUunJf10gwSD43ZsRHUjY/Tr7e9pHru9zAwz0GrHS96qFOYjgE+UeTmAzI0l9ZfB R7ghnHyfdvPlpkOMKp96YM0buthwO4Plg8Q8I+D/x1uE2tzDd5TvmWyaXxO94pJeIH19 y9D9S88xpz3Eq2C2iWXuPVR8BGgZKRxRZrFgmydLoP1XbrXf6J+HBmCySPtQTk8EPnsQ 5CoA== 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 :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:dkim-signature; bh=QrD9V2/prOMs2/duKMdtxaSRbb0w0K/uqb3zoiUjYlg=; fh=h28vckfI3GX5WFto8VbLoaUMI0xqlhwXGWb2ZADi/Dw=; b=Monp50FsoV4dePUrgDT4YUiWI7Tehr0p9wDzVT9I43NewR4EsoCg+8sngeHAofzFH9 SshcGoBFRIe1pLSiRs7rmqNK4TTInCKA65yXYCQ/FHxgyEd656mfqjOzTaGzx5giH0MY 4J0pbLzshrcD3enzBynKRACehpuMYpMv61lzOz1l9UGpcM8ohN+cja3iZjsorQPCNlXw oUCLtJO0KpVn97SOfHnSojqBMpMVGx2XnerubFomup6i8NUwipoIl40ItR1Z67bkHYHd yPxs3hrJjid+yOCD57loN0tXPhf+OGwHUFNIxQsqF2THkkxn/nqdcT3KoUyNp+ikboF3 cJpA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=JifsHEmM; 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::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d3-20020aa7c1c3000000b0051de1341e01si3460426edp.228.2023.07.19.17.17.06; Wed, 19 Jul 2023 17:17:30 -0700 (PDT) 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=@amd.com header.s=selector1 header.b=JifsHEmM; 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::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229642AbjGSXWh (ORCPT + 99 others); Wed, 19 Jul 2023 19:22:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230233AbjGSXWf (ORCPT ); Wed, 19 Jul 2023 19:22:35 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2082.outbound.protection.outlook.com [40.107.92.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71E841FF9; Wed, 19 Jul 2023 16:22:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OzwR/WxAJb8trhv8YHGD3/vEPsMp49LYmEhSHpECkkBkJDShVVLcams2HAzrrvS0euZPtfga3nRJpp3Ra/ThXGcFe8we+ca5cWXBI3l1JcD5X3Piq3LQ+iNIcTCLCFfV07zUoEzadNAffPODONFPCXu+Tvr/ivki1oQxY9r9DtL6Ed9oaJJS0qO1BZz/bUzUJI49AHhVrFxfhmd+1URYKIqb0w1jguQGTUNYaHv4ETg0QkcGNy1U55FemO3q3/l+ane5yYGXemwW/XgmP2OXHTMFwRWrTE4v6ldhgIpp3W9yVl7lKUh6oNFdTNWaKeMOdZfXuR3w3F7fSYfQ9w2lNQ== 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=QrD9V2/prOMs2/duKMdtxaSRbb0w0K/uqb3zoiUjYlg=; b=MBWO4z1p9w7vg/55/lNcMEnRqN52Nka4N8dKehg51Vq0K9/M9dPTtHUjCTB4kBcOnFtkVX6xqmQxctN9iRtG916xqBSHg8N535lhMkWntjxGj4AcPZZRgvXt1xDEAqwrVU1wmsCHBlZEsWT7a5Vrvs0QmBr/4EZM11K1QgAiuT4uvw3yL4cYQN+7a6j9UQGDsiLE0QQXFsNSDmRTPtqndqw0g5j+8N69aezAf1dVe2Db5kLneSCjiphsWd78DiStupiDZVkJnPKFhdWtim2N7NabaXKecUR1vWERFeSp3/MUBWZzaWFkVROpmzkdNNr21aaDhZd7fQ021GDFCGGPlQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org 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=QrD9V2/prOMs2/duKMdtxaSRbb0w0K/uqb3zoiUjYlg=; b=JifsHEmMMFrEfyDp4GM2y+5FliKNFZa4UZjHSNJqOwGRX14rp5rA8p4mCW9sWFGNkH9kuzSGK9CZZxorS6LTG+bONAkyrilo0Z1gTcdpSPHXURbByvwvaK3h4SHg6ghCWILjndgm13PPV9Rp9Yk9wiLHbWlyiMPM6gzFBuknx4I= Received: from DM5PR07CA0098.namprd07.prod.outlook.com (2603:10b6:4:ae::27) by IA0PR12MB8301.namprd12.prod.outlook.com (2603:10b6:208:40b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Wed, 19 Jul 2023 23:22:16 +0000 Received: from DM6NAM11FT073.eop-nam11.prod.protection.outlook.com (2603:10b6:4:ae:cafe::f8) by DM5PR07CA0098.outlook.office365.com (2603:10b6:4:ae::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.24 via Frontend Transport; Wed, 19 Jul 2023 23:22:16 +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 DM6NAM11FT073.mail.protection.outlook.com (10.13.173.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6588.34 via Frontend Transport; Wed, 19 Jul 2023 23:22:15 +0000 Received: from [127.0.1.1] (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.23; Wed, 19 Jul 2023 18:22:12 -0500 Subject: [PATCH v6 6/8] x86/resctrl: Move default control group creation during mount From: Babu Moger To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Date: Wed, 19 Jul 2023 18:22:11 -0500 Message-ID: <168980893158.1619861.8945141367681744527.stgit@bmoger-ubuntu> In-Reply-To: <168980872063.1619861.420806535295905172.stgit@bmoger-ubuntu> References: <168980872063.1619861.420806535295905172.stgit@bmoger-ubuntu> User-Agent: StGit/1.1.dev103+g5369f4c 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: DM6NAM11FT073:EE_|IA0PR12MB8301:EE_ X-MS-Office365-Filtering-Correlation-Id: 48509f08-1341-4f2c-e3b2-08db88aefd39 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CSH5z4GsSB0gEfynm4UUe7x2nJDTxt0pFhm0uQHx++ucEK8tO8ly36qiRzCkJuQ9SfYFSJdM4VZ9Z7+5jv4vDF4syH4jf2Cnm9xvukRkQUv4VcaPNcGxRQ1F3Wfg5F29oGoSxxXvp9xVAPZMOXQyFSequr/K+xZe1JNn+uNUEOOTu0EPtPJFmsziuAAQOcBK3u5/hozlTYyZ7eN1qeANurNNpD/g9qnaEIe7w58E2/jkXTUSMsSKgYlorbEpDiTBskThHdxnU0PNaV6c0qK2O6H0cCHynTCet4b7gPhAw/3GKthPBMJzqaFg18aKYZK5Q5M5D56np2+LHNPYX+meEQhOfLDaH8qv//VHW8gbDXjQri25Tdgtfbs0gAsPSdi46wf5wNw6nAO8O/d8fwm6Gv9Jf4ba36wSuZLyAd1GhrzcSIwTxU8xO/pl1UN49uhmUM6FSBF4sOkcNQ82+vmJOxhWCDoNLo5XDfjHYbpNQN3LBBD4/X5CsBdE6vNmE4C6W23IMpSGhlDItsMWJ//QoGTwgzNxn0jFtNBNWStJ4lLrQqE+TpLF/0cyDj2WLK0YPwNGVA5zDwuxa4dczpLdEg6Az7J5+15bMdMe79YkD3OedC1/wkBUs90b+29uiTtQ6yli1R7D3hrQniEUGqSlJenMDCkODKCAgc2QcTC9EUkQXKhkND0Y0u3/LJefgGuR8eNEi3Zh1zf71pHXc+SMzSI7ePowEt1Dxdx0McD/Dn8jHWr4+vn2F9VpcSutKts7k9xMbreH3Q7JzfgrH/pOy3Q33ASmPDAa/dY1XJQOI4U= 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:(13230028)(7916004)(4636009)(39860400002)(376002)(136003)(396003)(346002)(82310400008)(451199021)(46966006)(40470700004)(36840700001)(7416002)(86362001)(2906002)(33716001)(103116003)(7406005)(44832011)(40460700003)(40480700001)(36860700001)(186003)(16526019)(336012)(83380400001)(426003)(9686003)(47076005)(26005)(82740400003)(81166007)(356005)(16576012)(110136005)(70206006)(54906003)(70586007)(478600001)(4326008)(5660300002)(316002)(41300700001)(8936002)(8676002)(71626016)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jul 2023 23:22:15.5611 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 48509f08-1341-4f2c-e3b2-08db88aefd39 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: DM6NAM11FT073.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8301 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,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, T_SCC_BODY_TEXT_LINE,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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771896570185995403 X-GMAIL-MSGID: 1771896570185995403 The resctrl default control group is created during kernel init time. If the new files are to be added to the default group during the mount based on the mount option, then each file needs to be created separately and call kernfs_activate. This can avoided if all the files are created during the mount and destroyed during the umount. Move the root and default group creation in rdt_get_tree and removal in rdt_kill_sb. Suggested-by: Reinette Chatre Signed-off-by: Babu Moger --- arch/x86/kernel/cpu/resctrl/internal.h | 1 + arch/x86/kernel/cpu/resctrl/rdtgroup.c | 51 ++++++++++++++------------------ 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index 783c3e36633c..885b656d1088 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -601,5 +601,6 @@ void rdt_domain_reconfigure_cdp(struct rdt_resource *r); void __init thread_throttle_mode_init(void); void __init mbm_config_rftype_init(const char *config); void rdt_staged_configs_clear(void); +int rdtgroup_setup_root(void); #endif /* _ASM_X86_RESCTRL_INTERNAL_H */ diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index 9a7204f71d2d..e0570bce76a2 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -2512,10 +2512,16 @@ static int rdt_get_tree(struct fs_context *fc) goto out; } - ret = rdt_enable_ctx(ctx); + ret = rdtgroup_setup_root(); if (ret) goto out; + ctx->kfc.root = rdt_root; + + ret = rdt_enable_ctx(ctx); + if (ret) + goto out_root; + ret = schemata_list_create(); if (ret) { schemata_list_destroy(); @@ -2524,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; @@ -2582,6 +2594,9 @@ static int rdt_get_tree(struct fs_context *fc) if (ctx->enable_mba_mbps) set_mba_sc(false); cdp_disable_all(); +out_root: + list_del(&rdtgroup_default.rdtgroup_list); + kernfs_destroy_root(rdt_root); out: rdt_last_cmd_clear(); mutex_unlock(&rdtgroup_mutex); @@ -2652,7 +2667,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; @@ -2821,7 +2835,9 @@ static void rdt_kill_sb(struct super_block *sb) cdp_disable_all(); rmdir_all_sub(); rdt_pseudo_lock_release(); - rdtgroup_default.mode = RDT_MODE_SHAREABLE; + /* Remove the default group and cleanup the root */ + list_del(&rdtgroup_default.rdtgroup_list); + kernfs_destroy_root(rdt_root); schemata_list_destroy(); static_branch_disable_cpuslocked(&rdt_alloc_enable_key); static_branch_disable_cpuslocked(&rdt_mon_enable_key); @@ -3704,10 +3720,8 @@ static struct kernfs_syscall_ops rdtgroup_kf_syscall_ops = { .show_options = rdtgroup_show_options, }; -static int __init rdtgroup_setup_root(void) +int rdtgroup_setup_root(void) { - int ret; - rdt_root = kernfs_create_root(&rdtgroup_kf_syscall_ops, KERNFS_ROOT_CREATE_DEACTIVATED | KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK, @@ -3715,28 +3729,17 @@ static int __init rdtgroup_setup_root(void) if (IS_ERR(rdt_root)) return PTR_ERR(rdt_root); - mutex_lock(&rdtgroup_mutex); - rdtgroup_default.closid = 0; rdtgroup_default.mon.rmid = 0; rdtgroup_default.type = RDTCTRL_GROUP; + rdtgroup_default.mode = RDT_MODE_SHAREABLE; INIT_LIST_HEAD(&rdtgroup_default.mon.crdtgrp_list); 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; + return 0; } static void domain_destroy_mon_state(struct rdt_domain *d) @@ -3858,13 +3861,9 @@ 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; - ret = sysfs_create_mount_point(fs_kobj, "resctrl"); if (ret) - goto cleanup_root; + return ret; ret = register_filesystem(&rdt_fs_type); if (ret) @@ -3897,9 +3896,6 @@ int __init rdtgroup_init(void) cleanup_mountpoint: sysfs_remove_mount_point(fs_kobj, "resctrl"); -cleanup_root: - kernfs_destroy_root(rdt_root); - return ret; } @@ -3908,5 +3904,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); }