From patchwork Wed Apr 19 12:50:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 85399 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp371344vqo; Wed, 19 Apr 2023 06:05:32 -0700 (PDT) X-Google-Smtp-Source: AKy350a6FF6LjPPfrAIB8aI53YBWs8axFM+7BSdNm61eYcD2xsBjEf0yy9L6jJKEAIyhxSD1Z1Th X-Received: by 2002:a05:6a00:24c9:b0:62d:bf69:e9e0 with SMTP id d9-20020a056a0024c900b0062dbf69e9e0mr2910236pfv.17.1681909532002; Wed, 19 Apr 2023 06:05:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681909531; cv=none; d=google.com; s=arc-20160816; b=u+Dx8+JxMkny4gYJz8FIblY5jSX0H/KN7+iFDnlv/oxRWgCjBtqz7PQf0qdtTh47Ud HcuzYQoSNHNnsiLp7kMIjmyMAAr636gRcRuvgujYAxSn4dgWeH4OOjGjbGRPPrbOONKv 86K530t1LCCYQVV7FwRwdvCl87AxAY3VIgQuFSdErRSjHEpkfQt2Q+csRxeHiH4ABIKY jSeZ4CvvPOQfz07TguyqwkfgMRHj9vVs5uEZnVRU/gnbAglOE5hJ1q5wNXqu1rmukXo5 xewhWOWfqc+ahkcwNUQta4S806cqFUirmaSCRDo1cXSht6NiLj2efkgoMRXHSve7sPD8 SXjA== 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=M55eRuHQJrupxqsaP770qxmiyWjSxTprBCDKIWruVU8=; b=P76GiUx2cMNVshqPa96UHViMpW1UafoUIsAZ9E55HiHOxv1fv1SlqjPgn/XdvVoRz1 RhMQ2FhpW1tcrGfyo3XtooNrO3+ygDHZKRvpc3iXgD7Jm9tqdFK9AUFsq7KgTvv5q1Op h21ngc69YnHMb2Ak0sfdlNvtqgXZgkxfqqDhp0a/flJ2fxZCUdJFIAm3TvJ5G0poFOXF C9IRckNU+WQwmPJ17506Rn3SQYxQy22xxlpiAc271dTgKrMP+IwSdJxL0GsgHPhxGoUm ELE6cm9mu5SIOKpDtQihXLiZAIxNdWzGUaBK7vvs/0IbWBg+qI6lqDjrE3FgLo5rfdOn g0LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=LXjy63dN; 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 w25-20020aa79559000000b006262bc88219si10501547pfq.160.2023.04.19.06.05.17; Wed, 19 Apr 2023 06:05:31 -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=@google.com header.s=20221208 header.b=LXjy63dN; 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 S232982AbjDSMuy (ORCPT + 99 others); Wed, 19 Apr 2023 08:50:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232992AbjDSMuv (ORCPT ); Wed, 19 Apr 2023 08:50:51 -0400 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 79EB96EAD for ; Wed, 19 Apr 2023 05:50:41 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-54fde069e4aso133812847b3.3 for ; Wed, 19 Apr 2023 05:50:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681908640; x=1684500640; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=M55eRuHQJrupxqsaP770qxmiyWjSxTprBCDKIWruVU8=; b=LXjy63dN+KA/a+ihM+Hvrk/noXBuUo93Q35thIox5tSdDL2o71/NMZqFSYRW0EBM4P EFX9I9zPzMnxSNaBMaLHxoq+qKvEcsWsmeEXD3h2XX8VP1TN70UUtZrcF025i79nZDqa VYi1WpoKBj5pu+akQ/sWrJLnII87r+R3KLUmrXRQRQY92oMrME3VBmxN7sElDqCBoWrx lXo+oopgXDC+bwQHMXVYMf3RRHvxlbwsNLPAsX5CrT4gmHs2cj/cjZhAZINSVAWMoNCH n+pDViYF29j82CWSRE3IgGrfv302KxrSw7qSMoOyeUOz03lZl110Yp6DcbGXZyKaYWi0 XLZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681908640; x=1684500640; 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=M55eRuHQJrupxqsaP770qxmiyWjSxTprBCDKIWruVU8=; b=IrvAPAUWWjfKV2APoqSn9/F+gIDeCIR3qKbb4e07tPYzvZeEdZrq9e1A//r8ue0P8a kpa1oKGQ1N4yWVa/bW98gxZWfnRJo3dRpAhyM9HZSBB8rrc5QeUYiCLEZJEwxMH4gld/ FhAJT1Zz8Qbfp5OH1UjJQGaULcpMlxn7ccWTqVMWZutJf2ZRdyPOGCujWj5w70BAJSFq N1NhIagVcMveGmq7OyoyUaYRektHbUpcuV2pD8/auCuByJlyfNUu3lmDBZ6qexEIBs+T WmZWHxf6ZEKD8DZFMUSEhePcxfK10jx/zeft3h1j4W8PGmK8UC0/WmoDjogizPryeLhr JjdA== X-Gm-Message-State: AAQBX9e8vaVuvay+Lj8zQ/RvRCcGUg1kk37x7GBu0OKBppwnij0SYRbd D1pxbbIT06v8m5dtDosqqfla2D7seuN+D/j3Pg== X-Received: from peternewman0.zrh.corp.google.com ([2a00:79e0:9d:6:b36e:a25e:826d:b66a]) (user=peternewman job=sendgmr) by 2002:a25:c245:0:b0:997:c919:4484 with SMTP id s66-20020a25c245000000b00997c9194484mr11392762ybf.6.1681908640818; Wed, 19 Apr 2023 05:50:40 -0700 (PDT) Date: Wed, 19 Apr 2023 14:50:13 +0200 In-Reply-To: <20230419125015.693566-1-peternewman@google.com> Mime-Version: 1.0 References: <20230419125015.693566-1-peternewman@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230419125015.693566-2-peternewman@google.com> Subject: [PATCH v6 1/3] x86/resctrl: Factor rdtgroup lock for multi-file ops From: Peter Newman To: fenghua.yu@intel.com, reinette.chatre@intel.com Cc: Babu.Moger@amd.com, bp@alien8.de, dave.hansen@linux.intel.com, eranian@google.com, gupasani@google.com, hpa@zytor.com, james.morse@arm.com, linux-kernel@vger.kernel.org, mingo@redhat.com, skodak@google.com, tglx@linutronix.de, tony.luck@intel.com, x86@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,T_SCC_BODY_TEXT_LINE,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?1763609969114572646?= X-GMAIL-MSGID: =?utf-8?q?1763609969114572646?= rdtgroup_kn_lock_live() can only release a kernfs reference for a single file before waiting on the rdtgroup_mutex, limiting its usefulness for 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}(). No functional change. Signed-off-by: Peter Newman Reviewed-by: Reinette Chatre --- 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 6ad33f355861..51b869149e76 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -2301,6 +2301,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); @@ -2308,8 +2328,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); @@ -2328,17 +2347,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 Wed Apr 19 12:50:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 85395 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp362319vqo; Wed, 19 Apr 2023 05:53:00 -0700 (PDT) X-Google-Smtp-Source: AKy350Y1bzlhaJcWYsCYhWtD5K34/r+SdTH81/LZmDx2wVHP4C4xzqkalfDcq7Um482DzN16s0hB X-Received: by 2002:a17:90b:3605:b0:247:56b3:4f2 with SMTP id ml5-20020a17090b360500b0024756b304f2mr2853011pjb.7.1681908780694; Wed, 19 Apr 2023 05:53:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681908780; cv=none; d=google.com; s=arc-20160816; b=rsVYM2aRE+kaZE21qVrbedP9ScCtNY6RfWG5dtVA/eNSJ5yh6DYQaV3WbPw/tSdVfX C7iru4yMQGyKiJvwBaEya11t+9z0UH2Vrzn5gxNib7UVA8741rQv9QziWNYvLLI1uEzc d4BpH/x8S8ex32LuEGlt8lPuYSX+vC3PIee9QMYBSrSgBs7MwQoc44AyMd7xn44ppx7w b8/dMHqjKZsrofjWOu1n2mIzOrT/eZa0jxg4eJbnNFaDVbR5lIwzjFQLawmEhBU42mF+ rOkD6RhH/fUqU4g/WPauqpi14qHkjfaWA4P3ICI26G5MM3XuVJjydrqlK5ZRjjYv0N79 oN3g== 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=2VyinE+DDb/Q7Dr6L/ZifSAtwYa3P2xEDwWdnlneadk=; b=dAuxfGLLEmintaJ71nSMxonF9T7AcF+feTmD7qF57dItg2vbbPWQ5wI5SeRP0uXYMZ q4oDybUNyQo0BZLsYrDYuytXTqzfJP64pWoVdnzUNKR4TZGvf1ifWtRgak82vQ4G59yy Rhcmyhe5n2+f6coDeQkQ0L4lrSaa1aeb8JJwbovjmq+meIohmGf/6tSVwZ1aGkDLdrf0 oJx29UWMGPRvVjMQtGaVnDbI9hXbnsUwA1lMoLnFXeE1J2XMeBmtcv4+zvgUKpMOGYFc wfrOgxtP+pVWFdawJKAIT4Ly5UI3+oZXlkEYwrv6u2dY6YenWIajBffmMcFi6YPTJAQ2 XNPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=svjbIScM; 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 i3-20020a17090acf8300b00246eebc793esi1635388pju.180.2023.04.19.05.52.46; Wed, 19 Apr 2023 05:53:00 -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=@google.com header.s=20221208 header.b=svjbIScM; 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 S233157AbjDSMu5 (ORCPT + 99 others); Wed, 19 Apr 2023 08:50:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232869AbjDSMux (ORCPT ); Wed, 19 Apr 2023 08:50:53 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F1657695 for ; Wed, 19 Apr 2023 05:50:44 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id l124-20020a252582000000b00b8f5572bcdaso15868733ybl.13 for ; Wed, 19 Apr 2023 05:50:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681908643; x=1684500643; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=2VyinE+DDb/Q7Dr6L/ZifSAtwYa3P2xEDwWdnlneadk=; b=svjbIScMa28a4IqxeHSqZo7K9kjy2RdzU5ujfVKTAYQVvPZ9WYuAEpj3wnPqI9Srys YkqpOPCSqFQqVkLJ9eb8xlsqXM3qc5Y3GY8rGcXXHjyO+VxGuahJadcWV0aAnz9N1XtA 6PuDQdV6eyq1DjZqy62QFRJ1pu+RAQqjQF73JkhPovFBaVddJ3wf9r5hVxvICinyyUnV 9fpEHLxOWGIWVueEQRRKTp6F/M2zYS96qDGPYYezWJv0X8fwiZcWnhyyBkjCTYXogWPM SbXnWPh7SNOpOEN8qXdsDUIkMlXCOzSuFO2IYKtgtIndj19fiZrVvfDRog2H/uBBzOkw WejA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681908643; x=1684500643; 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=2VyinE+DDb/Q7Dr6L/ZifSAtwYa3P2xEDwWdnlneadk=; b=C1PGVzwwgpav7/+df+D8A/VnOOEkqr9GaC0/gQqskEkhBNXDjuwa8e+J8779PPqk4S BuY7j/tWcNSbpfjX3Ab7UN5SgIsmOmcxYTnQiC3BIZlEbDrBFGLPxRewC+XT3AXqhclb XzBAZ/AV1w1n1U32p/ojwRDIyxEcApns2fWHn4w+vny9L8f0UbcQtGCx7MPyg3nsN0yu v5+Pm1ufRyRNmh91ElmUoe5m8nas7Ih3IVPG8gtlk4KLWi8nh3gzyubDvPsOaTb3DH1T KUWSzem4CTCNEop2jbykt7KMppSc8J032E0saXkkNij3CCyrc+rDPikCEQESpA63tdXO b2NA== X-Gm-Message-State: AAQBX9fTiQrkKIzR4DQGhnEq7vFoSPQvM6efmVqQp1CJjHqwX+qhvngR RbPHA5GbkKCPJnKNqVUiiKIys6bwFJwde01UqA== X-Received: from peternewman0.zrh.corp.google.com ([2a00:79e0:9d:6:b36e:a25e:826d:b66a]) (user=peternewman job=sendgmr) by 2002:a25:d1cc:0:b0:b95:65ad:4399 with SMTP id i195-20020a25d1cc000000b00b9565ad4399mr2913072ybg.8.1681908643819; Wed, 19 Apr 2023 05:50:43 -0700 (PDT) Date: Wed, 19 Apr 2023 14:50:14 +0200 In-Reply-To: <20230419125015.693566-1-peternewman@google.com> Mime-Version: 1.0 References: <20230419125015.693566-1-peternewman@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230419125015.693566-3-peternewman@google.com> Subject: [PATCH v6 2/3] x86/resctrl: Implement rename op for mon groups From: Peter Newman To: fenghua.yu@intel.com, reinette.chatre@intel.com Cc: Babu.Moger@amd.com, bp@alien8.de, dave.hansen@linux.intel.com, eranian@google.com, gupasani@google.com, hpa@zytor.com, james.morse@arm.com, linux-kernel@vger.kernel.org, mingo@redhat.com, skodak@google.com, tglx@linutronix.de, tony.luck@intel.com, x86@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,T_SCC_BODY_TEXT_LINE,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?1763609181544064618?= X-GMAIL-MSGID: =?utf-8?q?1763609181544064618?= To change the resources allocated to a large group of tasks, such as an application container, a container manager must write all of the tasks' IDs into the tasks file interface of the new control group. This is challenging when the container's task list is always changing. In addition, if the container manager is using monitoring groups to separately track the bandwidth of containers assigned to the same control group, when moving a container, it must first move the container's tasks to the default monitoring group of the new control group before it can move these tasks into the container's replacement monitoring group under the destination control group. This is undesirable because it makes bandwidth usage during the move unattributable to the correct tasks and resets monitoring event counters and cache usage information for the group. Implement the rename operation only for resctrlfs monitor groups to enable users to move a monitoring group from one control group to another. This effects a change in resources allocated to all the tasks in the monitoring group while otherwise leaving the monitoring data intact. Signed-off-by: Peter Newman Reviewed-by: Reinette Chatre --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 128 +++++++++++++++++++++++++ 1 file changed, 128 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index 51b869149e76..6a301233b9ef 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -3514,6 +3514,133 @@ static int rdtgroup_rmdir(struct kernfs_node *kn) return ret; } +/** + * mongrp_reparent() - replace parent CTRL_MON group of a MON group + * @rdtgrp: the MON group whose parent should be replaced + * @new_prdtgrp: replacement parent CTRL_MON group for @rdtgrp + * @cpus: cpumask provided by the caller for use during this call + * + * Replaces the parent CTRL_MON group for a MON group, resulting in all member + * tasks' CLOSID immediately changing to that of the new parent group. + * Monitoring data for the group is unaffected by this operation. + */ +static void mongrp_reparent(struct rdtgroup *rdtgrp, + struct rdtgroup *new_prdtgrp, + cpumask_var_t cpus) +{ + struct rdtgroup *prdtgrp = rdtgrp->mon.parent; + + WARN_ON(rdtgrp->type != RDTMON_GROUP); + WARN_ON(new_prdtgrp->type != RDTCTRL_GROUP); + + /* Nothing to do when simply renaming a MON group. */ + if (prdtgrp == new_prdtgrp) + return; + + WARN_ON(list_empty(&prdtgrp->mon.crdtgrp_list)); + list_move_tail(&rdtgrp->mon.crdtgrp_list, + &new_prdtgrp->mon.crdtgrp_list); + + rdtgrp->mon.parent = new_prdtgrp; + rdtgrp->closid = new_prdtgrp->closid; + + /* Propagate updated closid to all tasks in this group. */ + rdt_move_group_tasks(rdtgrp, rdtgrp, cpus); + + update_closid_rmid(cpus, 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; + cpumask_var_t tmpmask; + int ret; + + rdtgrp = kernfs_to_rdtgroup(kn); + new_prdtgrp = kernfs_to_rdtgroup(new_parent); + if (!rdtgrp || !new_prdtgrp) + return -ENOENT; + + /* 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); + + rdt_last_cmd_clear(); + + /* + * Don't allow kernfs_to_rdtgroup() to return a parent rdtgroup if + * either kernfs_node is a file. + */ + if (kernfs_type(kn) != KERNFS_DIR || + kernfs_type(new_parent) != KERNFS_DIR) { + rdt_last_cmd_puts("Source and destination must be directories"); + ret = -EPERM; + goto out; + } + + if ((rdtgrp->flags & RDT_DELETED) || (new_prdtgrp->flags & RDT_DELETED)) { + ret = -ENOENT; + goto out; + } + + if (rdtgrp->type != RDTMON_GROUP || !kn->parent || + !is_mon_groups(kn->parent, kn->name)) { + rdt_last_cmd_puts("Source must be a MON group\n"); + ret = -EPERM; + goto out; + } + + if (!is_mon_groups(new_parent, new_name)) { + rdt_last_cmd_puts("Destination must be a mon_groups subdirectory\n"); + ret = -EPERM; + goto out; + } + + /* + * If the MON group is monitoring CPUs, the CPUs must be assigned to the + * current parent CTRL_MON group and therefore cannot be assigned to + * the new parent, making the move illegal. + */ + if (!cpumask_empty(&rdtgrp->cpu_mask) && + rdtgrp->mon.parent != new_prdtgrp) { + rdt_last_cmd_puts("Cannot move a MON group that monitors CPUs\n"); + ret = -EPERM; + goto out; + } + + /* + * Allocate the cpumask for use in mongrp_reparent() to avoid the + * possibility of failing to allocate it after kernfs_rename() has + * succeeded. + */ + if (!zalloc_cpumask_var(&tmpmask, GFP_KERNEL)) { + ret = -ENOMEM; + goto out; + } + + /* + * Perform all input validation and allocations needed to ensure + * mongrp_reparent() will succeed before calling kernfs_rename(), + * otherwise it would be necessary to revert this call if + * mongrp_reparent() failed. + */ + ret = kernfs_rename(kn, new_parent, new_name); + if (!ret) + mongrp_reparent(rdtgrp, new_prdtgrp, tmpmask); + + free_cpumask_var(tmpmask); + +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)) @@ -3531,6 +3658,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, }; From patchwork Wed Apr 19 12:50:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 85398 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp370657vqo; Wed, 19 Apr 2023 06:04:45 -0700 (PDT) X-Google-Smtp-Source: AKy350ZnGxB0x0fipIJWXui3Dgkk8RY6DikyWdVglAIN1/wJPgof0BX0Ahs4sFQxlr5x80Xb0u8x X-Received: by 2002:a05:6a00:2316:b0:63d:4756:6e9a with SMTP id h22-20020a056a00231600b0063d47566e9amr3798571pfh.27.1681909485177; Wed, 19 Apr 2023 06:04:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681909485; cv=none; d=google.com; s=arc-20160816; b=LKciAxXkep03F0lnFgXDzNvbZBO721s/MDSGgsGl+3qmfNKb+5jpzwWeM/UpzXP/Xt 5Z1ch2duwfw/rWMh/+fXlC81dFKzHOzUiRvIb8TNwK2r8Z0e5s9B14ygJy4EqoJXjRIG tjIvU9YjajRuEKxh/e6ig01nOWVFdeZx64Dt+yzF6DeF2b/4TBlrHvl9AGTwaUhYlUft sUmKIUIrGv8d0EGhNe3ceanHwu1zW7QWiNiaYmc1CReexj285OnNs8TtTku1/sqYydwQ EsxVXMF+IIJduuIi7i/mE3tXe/os1Mkoxf0znR4tAfyePBSf9sHt55dzSk4IxPh2m/Lh mQQw== 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=qxACaIFQGSNpRzNrd0szUQtmVWzyEP8n7N2A/6ory1w=; b=Szeh4SkOXQW8t0uLdUXRTltFQ7kFf47bCF5zaWfdnrQ5GZDkEM+wx5ludM9ujkif4k 93B5BotsmwtwVB1ZFha75o4hQvULZvcdsT4QWFEX7GF6BdBdss7FmtZKP/JtxL5voN1B M0G7OxkTT3c7uix99941IJEvesWYTeZTpl+L+GiUIE836pOwk4qI2eUu8zgyScvX8QMb OF73y0OE5V8bvYGWE41kSoaU3pnx9eQPwRBCyXBdOSOjTDUAGk2mgKWwLhxvPAndEIfX T0SodcLPNx8nllPfJ6iChVaXX14DC0t67JI4eiZt9YK7wQ+jEsGOsjpwdudQgdUFGSMs FKSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=f8BJoFC7; 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 w71-20020a63824a000000b0051f869d7089si1754494pgd.74.2023.04.19.06.04.32; Wed, 19 Apr 2023 06:04:45 -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=@google.com header.s=20221208 header.b=f8BJoFC7; 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 S233285AbjDSMvH (ORCPT + 99 others); Wed, 19 Apr 2023 08:51:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233181AbjDSMu7 (ORCPT ); Wed, 19 Apr 2023 08:50:59 -0400 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 83CA1B76B for ; Wed, 19 Apr 2023 05:50:47 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-54f8b46f399so196280237b3.10 for ; Wed, 19 Apr 2023 05:50:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681908646; x=1684500646; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=qxACaIFQGSNpRzNrd0szUQtmVWzyEP8n7N2A/6ory1w=; b=f8BJoFC7tHMQtMMZnfHw8I7h0dvExKxzjkvC1CMzEqKyAmbkh0GKgpFLaAWbEVpRjA KwfORX59VwoQc9As8pK/qPW6dAwLa0GNz5YGckzd2SxjJAB+WusEdU5iE9hLk6K40ddH ewr//TybzLFRVfXLg43mMTSXfIThG52oMVeKsfCAnfnBfKGzuikbe8QyrRSsxmhsBMhm Tbuqw/GX+fnSmwH6+sk1ehjQgOV2M7TStxE5Cu6h1H1Xnn+tKVwb/Ft/TycpMOP5gvgD Lee6Gl6yu5sPMpAHI7kNDmwgdQYDFy1pHTXuYqKuSGsxnu1+HBkxrkyzN37oY0dSXHWK 9vOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681908646; x=1684500646; 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=qxACaIFQGSNpRzNrd0szUQtmVWzyEP8n7N2A/6ory1w=; b=DVK7ovFmHkKEFkZpN6u/ZbehZQL9OlVhwSP9a7hCgvzk954WrkJaNRfENPS92V7NGn tAJr3LgM2QC9tMooxtWd2uLcCu4zi8TQxu03yjGdAX+ABbc9KD8ZjdGS2RBqY87jIpJV 6HcntZIY3OFvYqT9Gn4PqMMqd6He36kBtwj1hXWu71TSvm0USQyNTWceD2hsWlXPxjUW pKceL2DUzgZ3KZf/c8wnSsyJK2OTgqkkTXpPAT+aF22b1VkqV/c+2xH586Yx/zWnpECt Ea+bPb6kLZnXZpnZacytwxKr455LpRpo8jSpdDWYGba55wxctUw60rGfgZRLo30BXfla s/ZQ== X-Gm-Message-State: AAQBX9dn0WW74qmxiiQu/uztr3lt3JA5WL07KdC62SkclGi4t2izS4Qp syhTkOR/CHYf1/jdGG1gnCxhOfSstKy9ngdGJA== X-Received: from peternewman0.zrh.corp.google.com ([2a00:79e0:9d:6:b36e:a25e:826d:b66a]) (user=peternewman job=sendgmr) by 2002:a25:d256:0:b0:b95:6caa:a2cb with SMTP id j83-20020a25d256000000b00b956caaa2cbmr3621411ybg.10.1681908646729; Wed, 19 Apr 2023 05:50:46 -0700 (PDT) Date: Wed, 19 Apr 2023 14:50:15 +0200 In-Reply-To: <20230419125015.693566-1-peternewman@google.com> Mime-Version: 1.0 References: <20230419125015.693566-1-peternewman@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230419125015.693566-4-peternewman@google.com> Subject: [PATCH v6 3/3] Documentation/x86: Documentation for MON group move feature From: Peter Newman To: fenghua.yu@intel.com, reinette.chatre@intel.com Cc: Babu.Moger@amd.com, bp@alien8.de, dave.hansen@linux.intel.com, eranian@google.com, gupasani@google.com, hpa@zytor.com, james.morse@arm.com, linux-kernel@vger.kernel.org, mingo@redhat.com, skodak@google.com, tglx@linutronix.de, tony.luck@intel.com, x86@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,T_SCC_BODY_TEXT_LINE,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?1763609920205103995?= X-GMAIL-MSGID: =?utf-8?q?1763609920205103995?= Describe new support for moving MON groups to a new parent CTRL_MON group and its restrictions. Signed-off-by: Peter Newman Reviewed-by: Reinette Chatre --- Documentation/x86/resctrl.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Documentation/x86/resctrl.rst b/Documentation/x86/resctrl.rst index 387ccbcb558f..cb05d90111b4 100644 --- a/Documentation/x86/resctrl.rst +++ b/Documentation/x86/resctrl.rst @@ -287,6 +287,13 @@ Removing a directory will move all tasks and cpus owned by the group it represents to the parent. Removing one of the created CTRL_MON groups will automatically remove all MON groups below it. +Moving MON group directories to a new parent CTRL_MON group is supported +for the purpose of changing the resource allocations of a MON group +without impacting its monitoring data or assigned tasks. This operation +is not allowed for MON groups which monitor CPUs. No other move +operation is currently allowed other than simply renaming a CTRL_MON or +MON group. + All groups contain the following files: "tasks":