From patchwork Tue Nov 15 15:45:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 20442 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2803274wru; Tue, 15 Nov 2022 07:50:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf54B+Z/0Vm9KBD935WrVdr3CgytWk82u7RSKsNKXauWEQgngYwEssAdGXbkHp47XrY4svJx X-Received: by 2002:aa7:c0d6:0:b0:467:7519:6bff with SMTP id j22-20020aa7c0d6000000b0046775196bffmr13865447edp.301.1668527452701; Tue, 15 Nov 2022 07:50:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668527452; cv=none; d=google.com; s=arc-20160816; b=iEVgjXlk1Aut9fBZt0IgtCETqb9yI/fS/ctfq4R/ra327xvmyXIBkD1ZBHG8m/mE23 8qheOc8dyI1QkOpi/nCgAsjz3HrMsjQmpoTehUcQcjG0ZDUEGSzdgJbkTDtLReWvRDPq B3JlhPYlYqAEINBj4nSgBrg23yG8BAyR9Ild/H7Ji6NE+5OZEtP9zSFg6G+zl9a489Cd 9pPA5G/9XuRiEyCsBpb0KU+zLxyRxjqU52jVq47QSsLMp1J4hIW2aWtnP8WGSQmicmzA IfJc7bd8V8Bxv+rOu07w8UP1q7/8o2VIam9OTEvh80GgkqJtFc1H2HXDB2xiKV/VliGf KzXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=cUFeRtZYB7UeTgxIn2ZhYMocLTGExrmRKO4xcP78LzE=; b=LqCuLSdK9+9w1Sq/3NyUcslKACiphDp7BHR6JdwKSYLogzSwpySuRgKzcCxusZbErE Nvh/TgVU2y1W4gRXB75xlJZfFi75ITRd8lkz7s2VWPk+A8qNMDTw7NEhlz36BNl+lMbE LQ3QXmU+aizXj8czIkB/GnEWnja4y75vjikT6IVbDfPTL8rrOsA9XFXHprYGBKclxGSk UdYaYrBeVElVZEHMO65vZz9A3ivUZWpeo1rqVRt4rLPeTrpjH1hDAo0nvLJxmtIneLZM vgUrjikRkLSbz0ZiyiKiG37VNii2fqb9b9Olsp2O5gAbW1Vkr0EC4bd1KeH5F7MUKsnU hqCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Si5zz34w; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x25-20020aa7d399000000b00461c9bb5205si10559691edq.152.2022.11.15.07.50.28; Tue, 15 Nov 2022 07:50:52 -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=@google.com header.s=20210112 header.b=Si5zz34w; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231330AbiKOPpx (ORCPT + 99 others); Tue, 15 Nov 2022 10:45:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231347AbiKOPps (ORCPT ); Tue, 15 Nov 2022 10:45:48 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 779FF10565 for ; Tue, 15 Nov 2022 07:45:47 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-370624ca2e8so138944817b3.16 for ; Tue, 15 Nov 2022 07:45:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=cUFeRtZYB7UeTgxIn2ZhYMocLTGExrmRKO4xcP78LzE=; b=Si5zz34w8W5OUKEmuwma1mET23o1UNMM0e+o9fGg5w5QBLXN0EQOINeapJXw0xkhN5 jIBGAQpEgsaEeu2F7RJfTUTekBnD5xmh7oO3DT9e/g5GH9xCDINR/nnIH1JQBtjCA8Ky cGd2mkkePepc9zsCKoQBhNWoANyqmXIHeOPNSUqILXJ+JDo0m+Fg58+w9dEi+qyzv9PK mkkEjCyPJL2UD0KfMddbIdEX6IIwT+BCGM1qp7vQZJ89JXMBRgZua0U4jSF0TfY/8A3L P5OCi+bq6OzDA/4TybR/avT7cMQ6ZUIN1MQpCKdkmJhl6PAQflUILq9El2VnyO7VmIPI Ckig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cUFeRtZYB7UeTgxIn2ZhYMocLTGExrmRKO4xcP78LzE=; b=UAoHqmIwUjv6pmHoHfLUzdnwzEEavYeH5PIg7sBNDDyfPF/szhhHAxawbSnelet5v9 z0C+rTMXMmMjyT+TW96ti0hrcMVK7WPJFJGkZqJWXx9oenxvbYNyHvw2uuDnntNLVeJr r4hN+leZO8qlwdt0o+9sr6ouXLGjrUhTAC6umz2gpNxv1hIXIdYj/G6wvKdNUvvbUKHK 7sBOQuExuKbLpKo7OAjBcxD910I9MbGVJ7oTkOoQfTHCzbevutu17iH+xWVSAiWUDy3C VafdGZfURm6GY7nByFRNSSM9fgGzQqgnsukO1BlRo8HPwk7WzopofWAry5rP+/Dam4+q 37FA== X-Gm-Message-State: ANoB5pmqsQSnvWCN+RWeDRP6OajdBGKggHz8xkbxLT2QpE5PV+NWQmG5 qP4LYytun7sphLNWJfh6IIc18IJgS/0egFZvPg== X-Received: from peternewman10.zrh.corp.google.com ([2a00:79e0:9d:6:fe62:9ede:ae13:6fda]) (user=peternewman job=sendgmr) by 2002:a25:40ce:0:b0:6d5:34ad:10c5 with SMTP id n197-20020a2540ce000000b006d534ad10c5mr28033116yba.494.1668527146292; Tue, 15 Nov 2022 07:45:46 -0800 (PST) Date: Tue, 15 Nov 2022 16:45:14 +0100 In-Reply-To: <20221115154515.952783-1-peternewman@google.com> Mime-Version: 1.0 References: <20221115154515.952783-1-peternewman@google.com> X-Mailer: git-send-email 2.38.1.493.g58b659f92b-goog Message-ID: <20221115154515.952783-2-peternewman@google.com> Subject: [PATCH v1 1/2] x86/resctrl: factor rdtgroup lock for multi-file ops From: Peter Newman To: Fenghua Yu , Reinette Chatre Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , James Morse , Stephane Eranian , Gaurang Upasani , Babu Moger , linux-kernel@vger.kernel.org, Peter Newman X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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?1749577842571151076?= X-GMAIL-MSGID: =?utf-8?q?1749577842571151076?= To help implement kernfs operations on multiple files, such as rename, factor the work needed to respectively break and unbreak active protection on an individual file into rdtgroup_kn_{get,put}(). The existing rdtgroup_kn_lock_live() could only release the kernfs lock for a single file before waiting on the rdtgroup_mutex. This refactoring should not result in any functional change. Signed-off-by: Peter Newman --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 35 ++++++++++++++++---------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index e5a48f05e787..03b51543c26d 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -2026,6 +2026,26 @@ static struct rdtgroup *kernfs_to_rdtgroup(struct kernfs_node *kn) } } +static void rdtgroup_kn_get(struct rdtgroup *rdtgrp, struct kernfs_node *kn) +{ + atomic_inc(&rdtgrp->waitcount); + kernfs_break_active_protection(kn); +} + +static void rdtgroup_kn_put(struct rdtgroup *rdtgrp, struct kernfs_node *kn) +{ + if (atomic_dec_and_test(&rdtgrp->waitcount) && + (rdtgrp->flags & RDT_DELETED)) { + if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP || + rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) + rdtgroup_pseudo_lock_remove(rdtgrp); + kernfs_unbreak_active_protection(kn); + rdtgroup_remove(rdtgrp); + } else { + kernfs_unbreak_active_protection(kn); + } +} + struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn) { struct rdtgroup *rdtgrp = kernfs_to_rdtgroup(kn); @@ -2033,8 +2053,7 @@ struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn) if (!rdtgrp) return NULL; - atomic_inc(&rdtgrp->waitcount); - kernfs_break_active_protection(kn); + rdtgroup_kn_get(rdtgrp, kn); mutex_lock(&rdtgroup_mutex); @@ -2053,17 +2072,7 @@ void rdtgroup_kn_unlock(struct kernfs_node *kn) return; mutex_unlock(&rdtgroup_mutex); - - if (atomic_dec_and_test(&rdtgrp->waitcount) && - (rdtgrp->flags & RDT_DELETED)) { - if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP || - rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) - rdtgroup_pseudo_lock_remove(rdtgrp); - kernfs_unbreak_active_protection(kn); - rdtgroup_remove(rdtgrp); - } else { - kernfs_unbreak_active_protection(kn); - } + rdtgroup_kn_put(rdtgrp, kn); } static int mkdir_mondata_all(struct kernfs_node *parent_kn, From patchwork Tue Nov 15 15:45:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 20443 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2803341wru; Tue, 15 Nov 2022 07:51:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf5T4FIHg+hqXork5oT+eCbmugAQjepkxhWbYA7JZLY9c133MnOL5PeBJYd806YNQKRUsFTp X-Received: by 2002:a17:90a:ad0c:b0:212:fa9a:12df with SMTP id r12-20020a17090aad0c00b00212fa9a12dfmr1083388pjq.231.1668527460500; Tue, 15 Nov 2022 07:51:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668527460; cv=none; d=google.com; s=arc-20160816; b=tvLB1OeNLjnabLI3Dbev4hMoZTnkVF0Tfv3Xc2Hf5s5Kr6aZ9YfmgCrxPFb3RB8cmn 9F/8eC7j5BQeUFYQ4jUu9WY0B26uRigTU4s/pjZq7o2KA4k5XqJ7t/AfzwDkZ3i4G21u Ajm0b4WfjK/lykjOzNxBdh3jToaMn+vw17cNeVYs8iWaYsBhlewPSONjEB5bihuVvcS8 WLDeh7vUJdm/OFf/mUznr+eIaJWnfD/MEVH+aMf2Hx3pJRs1DPOM8/ggtA5H/1s05eR/ Nzucdo9/VrNgTpu+BepEsOH7caLAOXa4q0H2LUbmDnv3AXvDK0QduE16zCxmb7MUI+70 Qkng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=pjQjIGRt7ZTx9YZ7YrUkwZQipfJByQX3G269/cjvZtQ=; b=OVl3d2EeG3XPe3tZh5Tm+Mke0zwOXkqbhvJNOaZy2l/1PxVRvQIFAml5Am7YFUdQK6 vaBhDisKKFPwSsyisNgrlU3rKTHn5FxLXHejw7huEHP3JJKQVpK8c9w0aRZDGVH6zC7P gKm1nTWc5tqaPmF+GonvGk5LZfFRiqsmyj8DRKzbbGXRBDCKjFGlVRtbyMgdI+rN/SwS LMhd+XZWmv1/zflVFwdfjT2ZgW5xhubBMxEjdt5ZwPgqGgNDUnNcRBOOxcJRP/AqzOex Pvx8FuAJfinunWZqBED96qWouIf6p/NbCyexZdPT4CCJ0EJIwp3rWeI/8wJoNPvqIGfI YAYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=RElAvdrE; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t18-20020a1709028c9200b00188abb9027csi10257651plo.437.2022.11.15.07.50.46; Tue, 15 Nov 2022 07:51:00 -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=@google.com header.s=20210112 header.b=RElAvdrE; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238363AbiKOPqG (ORCPT + 99 others); Tue, 15 Nov 2022 10:46:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238351AbiKOPp7 (ORCPT ); Tue, 15 Nov 2022 10:45:59 -0500 Received: from mail-wr1-x449.google.com (mail-wr1-x449.google.com [IPv6:2a00:1450:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D1012DA90 for ; Tue, 15 Nov 2022 07:45:53 -0800 (PST) Received: by mail-wr1-x449.google.com with SMTP id l1-20020adfa381000000b0024184dfcb5eso1611497wrb.21 for ; Tue, 15 Nov 2022 07:45:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=pjQjIGRt7ZTx9YZ7YrUkwZQipfJByQX3G269/cjvZtQ=; b=RElAvdrEvhQXywsCTL33Q2ew+AwuTN9EMLviv1irsM11oZ4YRyyHcuapjihI39FsfW EPyG5jK0EqQ4+wnHrp2zS5KNv4AeGZG2xlh81eoQtXrr4dZGm0UH5c6+vxP5eV5G1tX7 IYPoQg9tfGBwhG7m6yNJYQTjlCvUxz38e4KJdjtJcr8IysWl5rhL/RyWVPfhdMNo48Pb 6fut/qFgpCy1JqDDLXS1rmXaN+KI0fxvMaD6p5cb2XfrNSEy8kaN/az0t6R52ns9c+Zs wvURAsgYvTkFNGhi9nJqX2FltgByeBsCNT34sZbBQFBIJBb5I+5NjF6LDUHt5Q5nUbjm iJNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pjQjIGRt7ZTx9YZ7YrUkwZQipfJByQX3G269/cjvZtQ=; b=YBQMVkbPG4RUIE7Vpw0vzjBzY/JFZq+Su/B8gVFCavUVd//jafe9HTaNpjsUxY7b67 J/oEGTK69ragfKgMd/rGhD6vXLCdQrNGREx/teNhCl6R09oad2UfuCGwkMs38/89cnoQ +1CIiDXknwFFFG7DhE5+PGc1zDlhiEDj4gsNtMu4dSWVuzBLJh4v3Qqp0uR2xUIc0Qjo lLAd8fZrs3RNONFC4Fz2qGLVLw7/UxjM0RgrFqLSnyO8rY+YGYN1zIKcVgl8R/2h6vNA lEG21crfyw+YivgFcLQTsx4SgCkW8eO4W2tdxkKbDAqprISDJQKmyERAmYgv2AhRWLr9 ss/g== X-Gm-Message-State: ANoB5pktjFoXmDAZwnyy/vhh1AVYqPvfWXFkMJalRwQimPQn9AxP4uwK 4SBgP9eEYJNtVvpo9NtiCyjmiMzR1GLhBtNN9A== X-Received: from peternewman10.zrh.corp.google.com ([2a00:79e0:9d:6:fe62:9ede:ae13:6fda]) (user=peternewman job=sendgmr) by 2002:a05:600c:3b19:b0:3cf:7514:a80d with SMTP id m25-20020a05600c3b1900b003cf7514a80dmr375420wms.0.1668527151450; Tue, 15 Nov 2022 07:45:51 -0800 (PST) Date: Tue, 15 Nov 2022 16:45:15 +0100 In-Reply-To: <20221115154515.952783-1-peternewman@google.com> Mime-Version: 1.0 References: <20221115154515.952783-1-peternewman@google.com> X-Mailer: git-send-email 2.38.1.493.g58b659f92b-goog Message-ID: <20221115154515.952783-3-peternewman@google.com> Subject: [PATCH v1 2/2] x86/resctrl: Implement rename op for mon groups From: Peter Newman To: Fenghua Yu , Reinette Chatre Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , James Morse , Stephane Eranian , Gaurang Upasani , Babu Moger , linux-kernel@vger.kernel.org, Peter Newman X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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?1749577850715292706?= X-GMAIL-MSGID: =?utf-8?q?1749577850715292706?= Implement the rename operation for resctrlfs mon groups to effect a change in CLOSID for a MON group while otherwise leaving the group intact. This operation is useful as a solution to changing the class of service of a running container without impacting its resource usage counters on systems which do not implement enough CLOSIDs to give every container it's own CTRL_MON group. Previously, on such systems, it would have been necessary to move every task individually to a new CTRL_MON group using the tasks file. This approach races with the creation of new tasks in the group, making it practically unusable. It's important to note that this solution relies on the fact that Intel and AMD hardware allow the RMID to be assigned independently of the CLOSID. Without this, this operation may not be as useful. Signed-off-by: Peter Newman --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 66 ++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index 03b51543c26d..d6562d98b816 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -3230,6 +3230,71 @@ static int rdtgroup_rmdir(struct kernfs_node *kn) return ret; } +static void mongrp_move(struct rdtgroup *rdtgrp, struct rdtgroup *new_prdtgrp) +{ + struct rdtgroup *prdtgrp = rdtgrp->mon.parent; + struct task_struct *p, *t; + + WARN_ON(list_empty(&prdtgrp->mon.crdtgrp_list)); + list_del(&rdtgrp->mon.crdtgrp_list); + + list_add_tail(&rdtgrp->mon.crdtgrp_list, + &new_prdtgrp->mon.crdtgrp_list); + rdtgrp->mon.parent = new_prdtgrp; + + read_lock(&tasklist_lock); + for_each_process_thread(p, t) { + if (is_closid_match(t, prdtgrp) && is_rmid_match(t, rdtgrp)) + WRITE_ONCE(t->closid, new_prdtgrp->closid); + } + read_unlock(&tasklist_lock); + + update_closid_rmid(cpu_online_mask, NULL); +} + +static int rdtgroup_rename(struct kernfs_node *kn, + struct kernfs_node *new_parent, const char *new_name) +{ + struct rdtgroup *new_prdtgrp; + struct rdtgroup *rdtgrp; + int ret; + + rdtgrp = kernfs_to_rdtgroup(kn); + new_prdtgrp = kernfs_to_rdtgroup(new_parent); + if (!rdtgrp || !new_prdtgrp) + return -EPERM; + + /* Release both kernfs active_refs before obtaining rdtgroup mutex. */ + rdtgroup_kn_get(rdtgrp, kn); + rdtgroup_kn_get(new_prdtgrp, new_parent); + + mutex_lock(&rdtgroup_mutex); + + if ((rdtgrp->flags & RDT_DELETED) || (new_prdtgrp->flags & RDT_DELETED)) { + ret = -ESRCH; + goto out; + } + + /* Only a mon group can be moved to a new mon_groups directory. */ + if (rdtgrp->type != RDTMON_GROUP || + !is_mon_groups(new_parent, kn->name)) { + ret = -EPERM; + goto out; + } + + ret = kernfs_rename(kn, new_parent, new_name); + if (ret) + goto out; + + mongrp_move(rdtgrp, new_prdtgrp); + +out: + mutex_unlock(&rdtgroup_mutex); + rdtgroup_kn_put(rdtgrp, kn); + rdtgroup_kn_put(new_prdtgrp, new_parent); + return ret; +} + static int rdtgroup_show_options(struct seq_file *seq, struct kernfs_root *kf) { if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L3)) @@ -3247,6 +3312,7 @@ static int rdtgroup_show_options(struct seq_file *seq, struct kernfs_root *kf) static struct kernfs_syscall_ops rdtgroup_kf_syscall_ops = { .mkdir = rdtgroup_mkdir, .rmdir = rdtgroup_rmdir, + .rename = rdtgroup_rename, .show_options = rdtgroup_show_options, };