Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7211331rwb; Tue, 15 Nov 2022 09:03:31 -0800 (PST) X-Google-Smtp-Source: AA0mqf7zeB0YqlP+uUgT8lj2+SyRWkb3lopdQN2hZCJayyfDNgja2ObaK0t1ndgifYog1F2C7fyC X-Received: by 2002:aa7:c9c2:0:b0:45c:c64d:a6ac with SMTP id i2-20020aa7c9c2000000b0045cc64da6acmr15816081edt.416.1668531811631; Tue, 15 Nov 2022 09:03:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668531811; cv=none; d=google.com; s=arc-20160816; b=MPsesNPmYzuJp3B/TQlRoudLqnpLbcl+aTHpaKAAF2QVlYRkFK2s/0Wi+ctuOoLi2g KAxpxmJwLL1U0SEqbUiNHUuafI0+otXI3vHzUJmfg1cRHWKs5DDYQEraaWuUP01X9M4t GqSy2SkSFyM/jJRZO27LzDw3gg7d/QJrXT92G+mdHnxhxdTeGDkAhWKALpNdzCTAszlQ GSBJDrAzAk7+2IYd8bMleOumCg3gWriy/HTUJRkw+caraKbMHxs4yXsLNFstqEBYTd19 cfkFFwnqCFuxOGIprdStRHkqSnWE2i3/kuDnr+uDX4x2myqYyntASP47JHu+Tuf2T2Bl pC/g== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z16-20020a1709060f1000b007806a130086si10105846eji.302.2022.11.15.09.02.55; Tue, 15 Nov 2022 09:03:31 -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 + 90 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 Content-Type: text/plain; charset="UTF-8" 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 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, }; -- 2.38.1.493.g58b659f92b-goog