From patchwork Thu Mar 30 13:55:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 77205 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1169722vqo; Thu, 30 Mar 2023 07:30:18 -0700 (PDT) X-Google-Smtp-Source: AK7set+Tf+lh40mFBfceA8aV/ouoBut+8VCvXAAR54ALSCDl0qdw08nrM+L1mtxo8QIS8dqvcdbS X-Received: by 2002:a05:6a20:84a2:b0:cc:5f27:d003 with SMTP id u34-20020a056a2084a200b000cc5f27d003mr18506129pzd.56.1680186618284; Thu, 30 Mar 2023 07:30:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680186618; cv=none; d=google.com; s=arc-20160816; b=tCUn/jx7iKUnpBgH3WL+0l1ajMWmEZuotUgsa9sn24Mo7NmTaMixwcm9nsJIV2A8Yg TetY+zTD5xodwpKKfTpcZRxp4siFX5O858rELu2xcfIRCxUl63FJGaF1p9fb2Lm6QLfh QZl03kYPa1pqQV5JXf83RrNd7DGc8CqMS6oLEHVwzPPMDp7v9sqb3GV5e6koqJi+DQZ5 hTicvFuu8e1lvZezsgLV7dnDjKBnDyLiF1G3bBPaqWvRgMpF26ZW9HEgppsU6WGSwbyH xzVkOiF7yIkCQX1O9eSme7BBml8VRpeXHvekCgpo8NoO+plQLnNZHvcJvw5tou7wlUxd ofNw== 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=Db8tOgMamx6SeqgPHUVcNRbWY9TzQjouDMjbLfKO9Bs=; b=YGC36Lgez0ENHevxLA6Jmb9v7ycE/9KLL6UhVwvUyxJGYUPDksUBX1h4VLKgPZvtpR QuGtu2yuFtD2PqfWZjHoBi08EYWmIFrBu/d9TQ+IX9o22Hp/GYvyPz874HufHy6vbsyQ +xGfSj+cHafATecxuKppjX9SKhnmBecJC5r1IjqU7EPeCnh9vqLq0mHUs6BL1LmWS0+e f5KEi330LX7QnHCgAV252viDbi6rIjqwi0Ll7X3nQAnHkdEWGirNNI17Y4oNZdPIz3Rp AnGLDh5vQdeGScqMG0Z4uHFJM6QKvow3W9DcRCHsSqEspOitf1A8ef6PZlPwLgfIJSHi gQGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=smbJl9qF; 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 i23-20020aa796f7000000b00625488ab85esi8064967pfq.4.2023.03.30.07.30.03; Thu, 30 Mar 2023 07:30:18 -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=20210112 header.b=smbJl9qF; 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 S232222AbjC3N4U (ORCPT + 99 others); Thu, 30 Mar 2023 09:56:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232090AbjC3N4Q (ORCPT ); Thu, 30 Mar 2023 09:56:16 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3EA67ED3 for ; Thu, 30 Mar 2023 06:56:14 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id p12-20020a25420c000000b00b6eb3c67574so18710889yba.11 for ; Thu, 30 Mar 2023 06:56:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680184574; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Db8tOgMamx6SeqgPHUVcNRbWY9TzQjouDMjbLfKO9Bs=; b=smbJl9qFP0l+li/hTveSDyoWOwzoPsoLgc8Y/ZUlzb4z79RlsRniVMcWs8fQnlPjSe aZIByw2LkyVG+iujSfkEbBIxijps0U3JAGOLzKQD9VF1QS6DCfGVK5PsbLIIh3MtvbGo T3VY05+yvWDx1cCieWInbheUEtsfNdp1dtZDEiXe5SSdR+eR8joFUtII4AWaimvlXvG/ sfl8ELaGwsoupYMFHqtKEz38EFqsNC1R1YPxJO4rYlNrGruq5MFrZBGFSN37GhwGY3YM EiffeAwYzCqWYR2AfbaJ5EMGJt94EYC2UWzEKmgiyjaM0LGsMIo42eXzY/vwAOpfHseR 5XvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680184574; 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=Db8tOgMamx6SeqgPHUVcNRbWY9TzQjouDMjbLfKO9Bs=; b=gU9E7ULLyDdmcirBkjTeTWqU4+iGJdrcdwnCLHw7oP7fkqL5krbwnGGb/oOrnYis3f Jx+p2aNKbLcrYy/La0AzK0NIOheOmkO346hXUuI2Y4z881rqzphx07V3Fh0AyBxhjrAE 57WpW+bRcoF7FfJByqZfijavVtvNdlwIjLysTBS68fZUD+nVuvUKF4I2A93ERrJRcmVj 7fOi7n+AJEPS4zYjCqlxwQsv4XX5Fm6IZsl31TFTyUNHoCO8o9biOxCEeXKTJjrBInLj P25jVRmkbTToM/VOVB3/ZdQBMe76u6h8/yzX8R2wXJ0OzGa44SRQyXYEltfxkOZ4qaeY 70oQ== X-Gm-Message-State: AAQBX9eiwQxG2JrDdXoFDNb9fot4l2s91+f2wduds3/LdH6P1KlFiI5n 07YzujE2xLt8AK7bNISKFfeqk1Ud01trBIPKXg== X-Received: from peternewman-vh.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:30cc]) (user=peternewman job=sendgmr) by 2002:a25:d9d6:0:b0:b80:e387:f6af with SMTP id q205-20020a25d9d6000000b00b80e387f6afmr50312ybg.2.1680184574244; Thu, 30 Mar 2023 06:56:14 -0700 (PDT) Date: Thu, 30 Mar 2023 15:55:56 +0200 In-Reply-To: <20230330135558.1019658-1-peternewman@google.com> Mime-Version: 1.0 References: <20230330135558.1019658-1-peternewman@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230330135558.1019658-2-peternewman@google.com> Subject: [PATCH v5 1/3] x86/resctrl: Factor rdtgroup lock for multi-file ops From: Peter Newman To: reinette.chatre@intel.com, fenghua.yu@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=-7.7 required=5.0 tests=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=unavailable 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?1761803363411653155?= X-GMAIL-MSGID: =?utf-8?q?1761803363411653155?= 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 Thu Mar 30 13:55:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 77208 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1174869vqo; Thu, 30 Mar 2023 07:37:32 -0700 (PDT) X-Google-Smtp-Source: AKy350YWX8g/pwrdJt82rU5tcRJTGILqCTtZEhAzemLHYjDcd4kWq8AGvtc5VDK7eLlTWSLpBn8S X-Received: by 2002:a17:906:8a41:b0:92b:6f92:7705 with SMTP id gx1-20020a1709068a4100b0092b6f927705mr21346201ejc.40.1680187052764; Thu, 30 Mar 2023 07:37:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680187052; cv=none; d=google.com; s=arc-20160816; b=iHMiBzD4Dll2QA9sbxtz+mYivb7xz1ckc4YFHjadCca5jf/7tz4TXP8L+ppDCWAvYH HOnaXa6eTm0RfLroimbGlfh4TnSUykgmCQgr7e8V6AqVR9euL0UHEYEgrhq8a6Uiyjiw /lgoc4X72EQDCcE72IJKfFxDIt9unitShZbjfslRs9os7wxMpX/PjM3DNfj4SuxH0ttB Ul9S3Uv/JfKq7umh+sd87pTikay6mFE5NtyAD8ZAzAODEGUyfDy6lIX0sI6KzShpFiea WvMNwGlj4aREKq/sEw16CjZ+KQouOfEU2jucSV7A7wEE35D/e2B+ZRiBQYEmxvFsNDz1 Zv6w== 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=zUSjvVavoBhnwCV+A2EoFMdaaeZRtxo2g0qg4wUbJ74=; b=PFXTWqdQ9nNuPc5QSoW4jEYkADRAKSh91rmKN2UlTU1jQkppd+T0KH4k2kKTTxLXce IhF0s6CEEzhp3oNwt60RsrCUrmuEtQinRN/FwDJIkV8pBSM1l6w4B7i3+VtfcUczUrTu F5EivmzcMZ4G/bRLLa/8Y7V3zWWDJpQ5S5tQ6gABxtR4NeHsTuKFAgPqm01EmEVXF+hy Zbj9xAlJaZv45Q+tgVK+2vjBWSVvPI2aH/i+gmo63v7Ve8OEQiLp1vBy/2CDoVOb9LD6 QRbiLRsg8eh+J9RqOJG+6yffRBRk6g35O+WzPk0mGFmtwSifms8o06D9baRPiQ0+EmpG 0i5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=nFdvgINn; 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 kg3-20020a17090776e300b00930894e4fa9si32562594ejc.324.2023.03.30.07.36.58; Thu, 30 Mar 2023 07:37:32 -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=20210112 header.b=nFdvgINn; 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 S232194AbjC3N4W (ORCPT + 99 others); Thu, 30 Mar 2023 09:56:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232200AbjC3N4S (ORCPT ); Thu, 30 Mar 2023 09:56:18 -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 F2F51A25D for ; Thu, 30 Mar 2023 06:56:16 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3-20020a251103000000b00b732e362449so18678539ybr.0 for ; Thu, 30 Mar 2023 06:56:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680184576; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=zUSjvVavoBhnwCV+A2EoFMdaaeZRtxo2g0qg4wUbJ74=; b=nFdvgINnXhDVlxrpogSpIYRXtjdRAXbnf98m/kRuK0EodxG5mqWMFnMpFcSH25JVGl Z26KpRi3NFGwWmA9HQDbA1ACoWItP92uCourv1Ebd7O6dnEL/y+kfdvI0W4rut6hpLEM vEPkUHtWrMb8nvj/yLpco1djR0W50o/oG8TGgORPshYudSPJT16BkvwHov5Qn0Xgeygj Qq8kAFtLYMHx/uK+Y0Md97BmZGw8keSkM59ndMeMJRIDTE624FRo+xvc2NlSusnp11OJ og214TR3Ix4mQocZSps+n19URYkCaiIeO5+MlpRGvsY7L8jiPnA0t5SXV0JFnHNo9L1S 70pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680184576; 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=zUSjvVavoBhnwCV+A2EoFMdaaeZRtxo2g0qg4wUbJ74=; b=noEyJGo9bwj31tDqMLIZvHDS2yGa0hh9uRr7vvQpbZls9mw1Zqmb+foLEXOYqqaZ6A Pc70Ys4iw9JDZqbV1khRy768CE39Bl8NPQbzmGxUaAaPJHJJHEPZyLEEyKW95tL4wbK1 LE39S7GW0jCEqTOgPL0i2Hc6t7WGn1qPKwUwW1ITl4bxtesfPHye85p5wcikyAKs/2ms hFW/bL8wHTm2MYo6GtnZPIQXwebyNkK4YcX0cDaHPJfRfTwYQ0QELvYkTgOKEvKLX77B CmXni6TFwskcnrwE65V70Bce+3gji38Ye1FNpBgE6fSs2+q4Zzf2UBtfqC/i7swr0V2O PiJQ== X-Gm-Message-State: AAQBX9eT6QV8SR6s4GlZBfw9kSNt4OkK7ItJXh4BLbtMVSLRFzrvAeTT 55NJJ6uS2c8Zw03dkAQ2msqhva5dCqLJVoiwYg== X-Received: from peternewman-vh.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:30cc]) (user=peternewman job=sendgmr) by 2002:a81:9993:0:b0:544:bbd2:74be with SMTP id q141-20020a819993000000b00544bbd274bemr3549820ywg.4.1680184576236; Thu, 30 Mar 2023 06:56:16 -0700 (PDT) Date: Thu, 30 Mar 2023 15:55:57 +0200 In-Reply-To: <20230330135558.1019658-1-peternewman@google.com> Mime-Version: 1.0 References: <20230330135558.1019658-1-peternewman@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230330135558.1019658-3-peternewman@google.com> Subject: [PATCH v5 2/3] x86/resctrl: Implement rename op for mon groups From: Peter Newman To: reinette.chatre@intel.com, fenghua.yu@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=-7.7 required=5.0 tests=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=unavailable 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?1761803819002845671?= X-GMAIL-MSGID: =?utf-8?q?1761803819002845671?= 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. If a container manager is additionally tracking containers' bandwidth usage by placing tasks from each into their own monitoring group, it must first move the tasks to the default monitoring group of the new control group before it can move the tasks into their new monitoring groups. 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..86de22d8e23a 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 group 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 Thu Mar 30 13:55:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 77219 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1179143vqo; Thu, 30 Mar 2023 07:44:26 -0700 (PDT) X-Google-Smtp-Source: AK7set8YvkRuocQmvj4cgfMKKyKq0LyCaPceFsU1F517vIl5ZS2aXNqWY1FxNexq+yF9Qj66jDwX X-Received: by 2002:a05:6a20:ca7:b0:cd:f17:5292 with SMTP id dt39-20020a056a200ca700b000cd0f175292mr16607624pzb.44.1680187465968; Thu, 30 Mar 2023 07:44:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680187465; cv=none; d=google.com; s=arc-20160816; b=ZLI6oEQzyOXxQILxta/hIj1qHlf9Rdr2kd1/+fq0hNIsppbsMqE3g9T4To8qzdYvBu 2xPQAUfZKcPcOMA3nLmZwOWvUpTkG6RZD67Pkpw9T10epxng/sAONa1v+CaKzcwfaI8r yQl2pDu33vVIw16+zSEQVYHHu0/38KG6bMfOc9GO67IJ9kTms4BpwnA1gUM0hpsgcMri U5Sx18Gdqt347E2TxEUHR/aRw78AAJeSec5psWZx82/JyWaT20oU+sc5VEFgUEkaKSFt 0rRXCUwTl14vscfUVSTV5mRzWmOXDSiG16sY3mrY906q4W83Y/Bpq33Wq5MX6YNYzyAD 3wBQ== 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=FhHLbziee4a81RNVkwycWkVgS8ETVW18Svhu+GP0co8=; b=jxvNw4Ur+iAy7o1mz2Jj2MjF6Sv7Dt51je6oU7/DAjDe32WIWv6j6nnco9CnTlQHoG WgQvV87U86J7E+FTGPTJxt+vNH/u+nRVss7Yfc+sgLsttRLjGHR/Al7tQmKNwC1OQOqR zV3qgvKeck4TSlqCntZK+ZOqDvMrOlz6iGsiHS9ZT3BANva33XE0arruGG1bms5bf/go fYyU+3b9AZUAX7WtPVhlB00dRBAEEh+xbLe8foyHf7ohyxJwYXQvTUlkK5NAnAB05tMt AethKqqNNw/xxPczdqPt9e1nXIEiitx5zQazMYABO7eLsMLXludzFjxCVXoxDw3ocxzA msRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=TyIuTP4E; 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 k20-20020a056a00135400b006255ffe925fsi25213531pfu.162.2023.03.30.07.44.11; Thu, 30 Mar 2023 07:44:25 -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=20210112 header.b=TyIuTP4E; 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 S232224AbjC3N4Z (ORCPT + 99 others); Thu, 30 Mar 2023 09:56:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232220AbjC3N4U (ORCPT ); Thu, 30 Mar 2023 09:56:20 -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 4462C9773 for ; Thu, 30 Mar 2023 06:56:19 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5416d3a321eso189188817b3.12 for ; Thu, 30 Mar 2023 06:56:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680184578; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=FhHLbziee4a81RNVkwycWkVgS8ETVW18Svhu+GP0co8=; b=TyIuTP4E/yt61TucQWoc7ll1E7roUOPolzxGJTLTcqFDT2S/awduj2ZxA31PhqG1eF pViFXGegRdXk1ZTQ1OZiFE84LpP8jzsgn5zGDzv8AfrdWtz6bUP4a38bqGQjQBPJ7ZPH VkpbiejhTh9WxOtxYFgi2Qmq/M4rZEvietQrflSUdzWuJf++ttuV3FQxBs8pvHzOH7dS pIF9Zlu0Zj8zj2b8UjbcSAC+Qa2zita4jFlJyqqgUMuEAE0ugdalIvKQZ0IclWc6ztrh 2J5QMvqUqijxIcADyhc2S97LPFZtPxcQJxl2OXorPFY8J7zdu5g4232yUJThobhUeYdo WN2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680184578; 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=FhHLbziee4a81RNVkwycWkVgS8ETVW18Svhu+GP0co8=; b=h1Z4pKfq4Pcr5ZBR9ha4gqmHXfjk7LR1xQcEyMkVPR+WdbYDSuoOmqo+ijLdPh+JTU SKQQMw/rWMvV7OEJqzKqoJJKdJuzXZ0SBhGTBSucP/fzoM3VjSsV0s1mQv6wmIEqC648 HMJ/usjnXwIE73DUp9OaUMWI7jdVmNXsjp+o3DKhMRhstZcDIizfzx3YE2BTWLvuufxr oC1d5UZTAaD/Qs/kFzQbJuXQYA8tBF7N4ikMHjAdIle9tFwnxnrh58jtCZ7/b3PKbEWv K8/ubMZZzkGmJe8k74HQW+qd7noZpc/idg+M1+Jmf1VH3y46RKZCDfjjT3pfqj7WpmyD ChLg== X-Gm-Message-State: AAQBX9cK3Uv+jTA62R8EhRcJONcftwy7RTPa7KCHrwiFC5G6X5mNCWAC 0a6TffFLUbC46RWQDPIIVb3RVkoqLxv8HxtDvg== X-Received: from peternewman-vh.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:30cc]) (user=peternewman job=sendgmr) by 2002:a05:6902:1024:b0:b77:3f5a:8a53 with SMTP id x4-20020a056902102400b00b773f5a8a53mr11703160ybt.12.1680184578517; Thu, 30 Mar 2023 06:56:18 -0700 (PDT) Date: Thu, 30 Mar 2023 15:55:58 +0200 In-Reply-To: <20230330135558.1019658-1-peternewman@google.com> Mime-Version: 1.0 References: <20230330135558.1019658-1-peternewman@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230330135558.1019658-4-peternewman@google.com> Subject: [PATCH v5 3/3] Documentation/x86: Documentation for MON group move feature From: Peter Newman To: reinette.chatre@intel.com, fenghua.yu@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=-7.7 required=5.0 tests=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=unavailable 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?1761804252255341314?= X-GMAIL-MSGID: =?utf-8?q?1761804252255341314?= Describe new support for moving MON groups to a new parent CTRL_MON group and its restrictions. Signed-off-by: Peter Newman 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":