From patchwork Wed Mar 8 13:14:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 66232 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp331724wrd; Wed, 8 Mar 2023 05:31:03 -0800 (PST) X-Google-Smtp-Source: AK7set+F/4sUoZ7jrY9zFiQu8t3ZVEuuZn/F1n6oefSjX45l1iLlBKEeTZGQIB27idqa33wLmoOZ X-Received: by 2002:a17:906:49c1:b0:878:5524:e932 with SMTP id w1-20020a17090649c100b008785524e932mr19136262ejv.5.1678282263696; Wed, 08 Mar 2023 05:31:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678282263; cv=none; d=google.com; s=arc-20160816; b=c44WcsiYmRILemCdkPObqhy9d/T19x+GZZ6veGtqUBTt6ocIz6bm7Ga9hyalcGDRVQ vfwHQzKE8CvVg2BM6C3MlL288fDjMNOX712ATWv80k4Y1KVM/L6oxZt/vZH3vLaAWTSp ys9xvmpYNVX42IOFMhjJByZEwHuJA9TQj9HLivPdQWh/64TruA4oUdoGf+xkX05u8I/d Z3dXcSGryamNMyOTsLUOpdPQjMkQI1DJccx598IOsM9M4Q8ryQv09Y/blcrGX8GO3g1d tidTLMzRw0gvEbHGHi6LGUiVVKqTYgFnUQWbj9YhYJ+Y90jmFbFiiP4fnnt2iRHf3T5z mloA== 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=geKZ0b9prEjt0Vyx6WHp2kYThqOYNTypo8c4MCHr/Ug=; b=pcl0ABKtryGIZrWjts1Hu0nHVR7tK3jh8dZncefDuoMwCj+Sk0JD6xmAMI4n4TJCik /ojws08LwxuDP/yRxjosGx9YEn4XscziVnncXDQMtMvq0nS7Hfwi2ph/m2VSSUTZ8+mY gu+xawnhG4DqK6H3ajfNkKp/k9pJh6XizR9p4bfIK6DSbDArMTkS2quf17QwFg0xZ81x t/NoMrUI6xUXDpm89qDs6zstWXhgHpldkei5Pj5cWftVcMMbAttShcT024ANGEmfoUMk 2aPPDaHYgDqIueDSi9Ml+gRgHvZ0AwSHqRj+9TP5n5DOezzrlBP2O5i1rQ0wLy65Pwxd Ij0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=htYNEPtk; 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 b8-20020aa7c6c8000000b004c06f87b08csi4044460eds.488.2023.03.08.05.30.40; Wed, 08 Mar 2023 05:31:03 -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=htYNEPtk; 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 S230517AbjCHNTA (ORCPT + 99 others); Wed, 8 Mar 2023 08:19:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231435AbjCHNS2 (ORCPT ); Wed, 8 Mar 2023 08:18:28 -0500 Received: from mail-wm1-x34a.google.com (mail-wm1-x34a.google.com [IPv6:2a00:1450:4864:20::34a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9558160A81 for ; Wed, 8 Mar 2023 05:15:07 -0800 (PST) Received: by mail-wm1-x34a.google.com with SMTP id m31-20020a05600c3b1f00b003e9de8c95easo5861816wms.2 for ; Wed, 08 Mar 2023 05:15:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678281305; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=geKZ0b9prEjt0Vyx6WHp2kYThqOYNTypo8c4MCHr/Ug=; b=htYNEPtk6BdX8z3OZd8E1kcZH+GqH/PCqaiMJMhmag7qj17psAkY2Q4aOOaLwjtnKA ICKCRsPwtxEk2RNuOTIBzhMA1Mt+gL91pBWSMnnb/hZhK5eR+5irRQ394J1SuHaRRivX 2RniGgFV5szp0oEbB1EmyNEweQaK2vHlHyMQi6pVlQP0lBxP53m0WvQheg9e6AIIyv7g 9ZrVgv/xplCIwomQ2sIwvZW3P6V8VMF0JxHIMBX4cJjdMi4mtmY+z3fdEn1+9Oyn1kcz X4HAN3S6l/Y85mtD4ZMZic7/xgPPDaIN58ioUIRx5QMh3VK14D+BufUr1a0h5R2Otf/2 31sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678281305; 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=geKZ0b9prEjt0Vyx6WHp2kYThqOYNTypo8c4MCHr/Ug=; b=38X34LkOqMktEvrzfnicyJ0vwLaqDgO4CGb3/QhzWOZmlOqB8lAksx687/w/XEtUTy yvTTksGWcA+LVJuXTNpLCmKLQuqxOl6BqajatfTs7TM9j5Tu6+CaX3Sjbacv6vW9dL2Y RXUqOh3JGwf3PXdPjfr5UAr++dUKOVMpxwMhgFL14cieBTGYgqvGytdn4yr9PmfTgGiL /oPEZ2HiDih8gcV6wasscqB/SX5AXse4kQYYNizNRf/FczDH1HHAqKgFLM4Kz7vArKb/ n+fWgvPB9xOm+FGGrhRenrxLqsAoJQnSb8Nw1y5LvyMBhEt9rPsaBUk1Y6J20jtwEr5u X1zQ== X-Gm-Message-State: AO0yUKWzyzyoJfZVQMVQZOJJg8LRkjTgc5u2h69D7dT2SVkxExLWseyW QaFLJUKHtrGSWZb71mJ998Ms9d7YYtGB6F0JfQ== X-Received: from peternewman-vh.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:30cc]) (user=peternewman job=sendgmr) by 2002:a5d:608a:0:b0:2c8:2cbc:7a2e with SMTP id w10-20020a5d608a000000b002c82cbc7a2emr3545133wrt.4.1678281305672; Wed, 08 Mar 2023 05:15:05 -0800 (PST) Date: Wed, 8 Mar 2023 14:14:50 +0100 In-Reply-To: <20230308131452.383914-1-peternewman@google.com> Mime-Version: 1.0 References: <20230308131452.383914-1-peternewman@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Message-ID: <20230308131452.383914-2-peternewman@google.com> Subject: [PATCH v4 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=-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?1759806502929825675?= X-GMAIL-MSGID: =?utf-8?q?1759806502929825675?= 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 5993da21d822..c3fb525d52e9 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -2028,6 +2028,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); @@ -2035,8 +2055,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); @@ -2055,17 +2074,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 Mar 8 13:14:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 66224 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp330795wrd; Wed, 8 Mar 2023 05:29:22 -0800 (PST) X-Google-Smtp-Source: AK7set/MqW5UdSyW4U/EKxPVO4l8sCmLNapjTModw0QRrVb7jcqRpRM4Pmg0boNhJY/olM/Ck+Ab X-Received: by 2002:a05:6402:1655:b0:4bf:c590:3c4e with SMTP id s21-20020a056402165500b004bfc5903c4emr17786098edx.4.1678282162660; Wed, 08 Mar 2023 05:29:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678282162; cv=none; d=google.com; s=arc-20160816; b=KHc7Hq9brUNMcPo2gs4lmCHisGuSnuz4qpl4G253lpEHSxBhItQ9uLIIizq4q1F98W 7NBdoyzaXMBsmTgb233slkq+7/wcvo79iqE75A5Cja8GfjwVR/EjXI2NbYkzjjgFG1ab dc9C5sn64oulw89RzTzcGEDT5jGl0etWjN2m1i3PBIaLyAQ1FDxMq8xO1UTFzGIapcZT a07NE8+IDB9yahTCsePy3rgx7h8kGvWxA+6BWtKqxQ/rtwmeweF0aElpHSkAH4zztGic h60Z8FVWRLRcSFTZioYuNn657RZrbXmclFLyV5uUVgQBRSCoU2qGfWHaX75oCh/xHc78 bnaA== 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=IWv04zwKPneNYxLs1BbPEMCnf2deIeuFiHgPUvk4fKo=; b=SdOXtMiaeoAoUGvr7OJWxBBslTh+IhkDGFGAYA1NrOK+lAetYlIqKwdh6Yi6fL6/6/ 4M2YKnd2jNicvU8sQlzQ+YTIPF0uDK0UPVJ+WZZh05vHAJl9CJbXQjCmpMdXirWvgNNb 42VED+JYOZzQJv4r5jp7QYc0A7bAwrM5+XtJU2IXs2+/z/Nd7ZPzr+EnEDzPOv42r0Uf FqA6XQ4V4GrG2oqO0tfDvqeoAyk9+qKZIEW40LUMpMESI0/9gh6d2bbQRBXB+cfa3KE1 0NEhimuCS6JX+HcE/HxIi+IzfaHwXR9FuYAudkPt+vzi9EQHvpmn/hKwnJO7xZe7VD2q Ca7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ncgPRVco; 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 hd34-20020a17090796a200b008dbc41587a8si3885397ejc.730.2023.03.08.05.28.58; Wed, 08 Mar 2023 05:29:22 -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=ncgPRVco; 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 S230512AbjCHNTH (ORCPT + 99 others); Wed, 8 Mar 2023 08:19:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231491AbjCHNSb (ORCPT ); Wed, 8 Mar 2023 08:18:31 -0500 Received: from mail-wm1-x349.google.com (mail-wm1-x349.google.com [IPv6:2a00:1450:4864:20::349]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C3F1CDA28 for ; Wed, 8 Mar 2023 05:15:10 -0800 (PST) Received: by mail-wm1-x349.google.com with SMTP id l31-20020a05600c1d1f00b003e8626cdd42so5858372wms.3 for ; Wed, 08 Mar 2023 05:15:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678281308; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=IWv04zwKPneNYxLs1BbPEMCnf2deIeuFiHgPUvk4fKo=; b=ncgPRVcobR0NbnPhgiLgKATtFzK1Pwszpc66U8K4etCXhJRBDORnkwokA8SHqOPvpp R6wmTfiSI5L8MeNQxGP4csKkyoUJB42k3+SFCx4CC7n4AG/8Uv/9V6+NvIgciVVz2xjZ QBoaRNYoNF4vj4yq9vOhI9vcspOEOw3utNKB9hKAfrMxApTVGdUVJQ2CWvw5AbicENuR wqigJLtZqufisVbuPvB3yhEeIN71AZrj1By87XjShYV6sVaXFYx7xI+bOrDyT50aPIMe gJXb4llltVotqkXjEEcozWwRj4C1oUOFJdz4MVjdsHPgOgTmO7SnGmZ4zhsJfudpgLPC g2Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678281308; 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=IWv04zwKPneNYxLs1BbPEMCnf2deIeuFiHgPUvk4fKo=; b=cvdPTp9deYfdGxtM9Y7A/VMgWULzPt1yvO8j6r7pMpk7MorUaYk1Bksb+suv8FeO96 a7/bVKa1RqiHm/c3WXcfVFKbIgEG6k4tFCPYyrR+ZOY6YiMBtEfra5kFkWMwDQceKyQw JbaAOzovLct7D8T2DA2AF11WYF+X1IlZ8ZSmqkPFagrdRqdo6X7ctmf0+bQcDb8PGWvu WtvCHkiYiTQOO1MNDDyS4DzNZh4x/AbHeRsU0j36Z3CfT7nN0isyp0oFKfYiZS5Azwhf nuB1hIjKZXv9A6WtxPf4kewwbCxZZGh1SWKTECYvMsy0812eBKGUtZpFiL6Psb56haN6 OOkw== X-Gm-Message-State: AO0yUKVjPUorjEzmLBQQh1M7xtP0agLh29P1rYvJu2HdAia6MT3S/y5c mLpLGnPFw0odh8e5Zh7nhp/u1LtWegPRfZOx2A== X-Received: from peternewman-vh.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:30cc]) (user=peternewman job=sendgmr) by 2002:a05:600c:54ce:b0:3df:97a1:75e0 with SMTP id iw14-20020a05600c54ce00b003df97a175e0mr3872239wmb.2.1678281308150; Wed, 08 Mar 2023 05:15:08 -0800 (PST) Date: Wed, 8 Mar 2023 14:14:51 +0100 In-Reply-To: <20230308131452.383914-1-peternewman@google.com> Mime-Version: 1.0 References: <20230308131452.383914-1-peternewman@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Message-ID: <20230308131452.383914-3-peternewman@google.com> Subject: [PATCH v4 2/3] x86/resctrl: Parameterize rdt_move_group_tasks() task matching 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=-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?1759806396971815447?= X-GMAIL-MSGID: =?utf-8?q?1759806396971815447?= Allow rdt_move_group_tasks() to be used for new group-scope operations. This function is currently only used to implement rmdir on a group or unmounting resctrlfs. Callers now provide a filtering function to indicate which tasks should be moved. No functional change. Signed-off-by: Peter Newman --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 34 +++++++++++++++++++------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index c3fb525d52e9..84af23a29612 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -2393,22 +2393,29 @@ static int reset_all_ctrls(struct rdt_resource *r) } /* - * Move tasks from one to the other group. If @from is NULL, then all tasks - * in the systems are moved unconditionally (used for teardown). + * Move tasks from one to the other group. + * + * @from: passed unmodified to task_match_fn() for each task + * @to: group providing new config values for matching tasks + * @task_match_fn: callback returning true when a task requires update + * @mask: output-parameter indicating set of CPUs impacted by this + * operation * * If @mask is not NULL the cpus on which moved tasks are running are set * in that mask so the update smp function call is restricted to affected * cpus. */ -static void rdt_move_group_tasks(struct rdtgroup *from, struct rdtgroup *to, - struct cpumask *mask) +static void rdt_move_group_tasks(struct rdtgroup *from, + struct rdtgroup *to, + struct cpumask *mask, + bool task_match_fn(struct task_struct *, + struct rdtgroup *)) { struct task_struct *p, *t; read_lock(&tasklist_lock); for_each_process_thread(p, t) { - if (!from || is_closid_match(t, from) || - is_rmid_match(t, from)) { + if (task_match_fn(t, from)) { WRITE_ONCE(t->closid, to->closid); WRITE_ONCE(t->rmid, to->mon.rmid); @@ -2451,6 +2458,15 @@ static void free_all_child_rdtgrp(struct rdtgroup *rdtgrp) } } +/* + * If @from is NULL, then all tasks in the systems are moved unconditionally + * (used for teardown). + */ +static bool rmdir_match(struct task_struct *t, struct rdtgroup *from) +{ + return !from || is_closid_match(t, from) || is_rmid_match(t, from); +} + /* * Forcibly remove all of subdirectories under root. */ @@ -2459,7 +2475,7 @@ static void rmdir_all_sub(void) struct rdtgroup *rdtgrp, *tmp; /* Move all tasks to the default resource group */ - rdt_move_group_tasks(NULL, &rdtgroup_default, NULL); + rdt_move_group_tasks(NULL, &rdtgroup_default, NULL, rmdir_match); list_for_each_entry_safe(rdtgrp, tmp, &rdt_all_groups, rdtgroup_list) { /* Free any child rmids */ @@ -3124,7 +3140,7 @@ static int rdtgroup_rmdir_mon(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask) int cpu; /* Give any tasks back to the parent group */ - rdt_move_group_tasks(rdtgrp, prdtgrp, tmpmask); + rdt_move_group_tasks(rdtgrp, prdtgrp, tmpmask, rmdir_match); /* Update per cpu rmid of the moved CPUs first */ for_each_cpu(cpu, &rdtgrp->cpu_mask) @@ -3164,7 +3180,7 @@ static int rdtgroup_rmdir_ctrl(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask) int cpu; /* Give any tasks back to the default group */ - rdt_move_group_tasks(rdtgrp, &rdtgroup_default, tmpmask); + rdt_move_group_tasks(rdtgrp, &rdtgroup_default, tmpmask, rmdir_match); /* Give any CPUs back to the default group */ cpumask_or(&rdtgroup_default.cpu_mask, From patchwork Wed Mar 8 13:14:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 66223 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp330749wrd; Wed, 8 Mar 2023 05:29:17 -0800 (PST) X-Google-Smtp-Source: AK7set/BtH/mCbwpBcOtKXbyTkaqcYwyI/1yjlbQ8zeZAAq+CaIY8nyBGUJeLA+BX0OHBbPk+BTn X-Received: by 2002:a17:907:86a6:b0:84d:3403:f4f2 with SMTP id qa38-20020a17090786a600b0084d3403f4f2mr22912690ejc.62.1678282157043; Wed, 08 Mar 2023 05:29:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678282157; cv=none; d=google.com; s=arc-20160816; b=Y1fu9zOmOoqtne6AC0CJNvE3SS5uoCPB9FOAoxRmVIxQiKcsqB9s6GM/ZdCz6OW1NC RppMw8tUn/i+HB5ohtiYtetaaV4QseUKKpPsxE6Ek7pdloY2A102bb33jtZKaPJ7JLmw RIoTemr3NnqV39ONm0e0sxjk+v4lwIkI5XD1f0R23TmM2MHJm5iZ4EFFY0NG3swlFheb doe+ElSm5yJzmEDJS07xk26tDBwyx3gffg4HA6wcj8j9zp+JcwKHLjvAPkQc2ROE38Fp L17W2mU5h+rh/OemVo15oix0I7JX81y/R1Y/oAGnjMhvKgvd3Z0t5GsteFjOVB5ozNcZ zmiQ== 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=V2OWyyThXDzCsX5dfUI5J1YeLCRnmlzAhR0ONAX2q6c=; b=mW7a5nLbL5fO0NE95/HrZ9eytjHQEnFMW5rmW+rMcXHRh5uya3h7dmGP74v2gWsD0L jatsA53GwinNRRKnFT7Kpr/cpwN56vCVFkmH19ekWswJ4TFwB9Sq1Iz+Njj+Z2lQj4P4 BR1tlx3ZXmHmvCNeDff7+qUUyL66yqTt0Ahn3QA3xZ8lKgLTw9KzZUqiMmoOpZISkKzL UQSlkbuevRBcTn9vejwTfGvioxrtmRLHwf8JZC2OZznKPQzn/05QTyCf0TQikZVfdqmt qAeonogqaHtBTYYEHzs9BhgekU8Tai4LSrwNd9464PyUYkVKkWgjN6G+kl9EgAvc4Tfg sseQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=eTJmEafz; 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 jt24-20020a170906dfd800b008c85af719fasi14265330ejc.435.2023.03.08.05.28.53; Wed, 08 Mar 2023 05:29:17 -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=eTJmEafz; 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 S231192AbjCHNTL (ORCPT + 99 others); Wed, 8 Mar 2023 08:19:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231521AbjCHNSc (ORCPT ); Wed, 8 Mar 2023 08:18:32 -0500 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 1EE52CB644 for ; Wed, 8 Mar 2023 05:15:12 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id x64-20020a25ce43000000b00ae6d5855d78so17677021ybe.12 for ; Wed, 08 Mar 2023 05:15:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678281310; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=V2OWyyThXDzCsX5dfUI5J1YeLCRnmlzAhR0ONAX2q6c=; b=eTJmEafz02AisZ86AJ7inkOANlOT7YZR4TTp+I8VfysjvCRHGV5+hEnzifTlMdyGnd 1OkVVwur8jZvZfVKIvD9VHxyoxfNZEWw1qiuj//mPyrwtI323ZqXudRxscC6NcGUtt9b GDzRFPzvXF0f2MuhwNCeMubC3iMwCqqYks0OA45nqs6alr9+UIhzN7PqRl0AuWDC1kxp ycCyhtGuklso+a7joCnePh3oGkgMoZo6lWkkVwoITX1ged6hCbxieBiPNl5k6yU0jsIk rlMQrW3UihIYZXRc4Z8pIymKbVqitmmzsBaf730S9iTB6LkkSdR2FLCe2X0Blqklm6FH oy+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678281310; 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=V2OWyyThXDzCsX5dfUI5J1YeLCRnmlzAhR0ONAX2q6c=; b=7Kn2Qwpg9p6KvdDXS482GVbWPHPRDZ+iS8Q/hiK0PWPO4xX0WheQ68z5RoQIQ1cH32 Wr4nnDCYKzmqA4ThW05BEHg7TThiXFdm9ObvMrCZVYA6gQDRgtTlyVpAt3mRTp4Vf7sA 1Lxnxa4w+ikqNNEr7vCscJZLKSaF2hnSYVBhbIfe47vdnUgzpbL6b/6/Qym6sPjWqmtq ygZKIMVhGN4OYxdzqMcPwNrAh/thKUwWh5AqR90ISFdtKkFWAjgl7a6chO+ERceDP4th Km1FgKdnd4JoM4bDR22OaCUKwouvUjOqUwYWanJj77JbCteby8N7w8jTxgoXl+S3lqIS waZw== X-Gm-Message-State: AO0yUKWNwUJ5gnHrPdxuOfkp8WJwNOa4UMuEVelM9+O3m+8RroRFhPud SMIXYbdgJoRobkKF4QkKRh9SOsmyXRKKM4AqLQ== X-Received: from peternewman-vh.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:30cc]) (user=peternewman job=sendgmr) by 2002:a05:6902:10e:b0:98e:6280:74ca with SMTP id o14-20020a056902010e00b0098e628074camr8955336ybh.1.1678281310581; Wed, 08 Mar 2023 05:15:10 -0800 (PST) Date: Wed, 8 Mar 2023 14:14:52 +0100 In-Reply-To: <20230308131452.383914-1-peternewman@google.com> Mime-Version: 1.0 References: <20230308131452.383914-1-peternewman@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Message-ID: <20230308131452.383914-4-peternewman@google.com> Subject: [PATCH v4 3/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=-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?1759806391069898286?= X-GMAIL-MSGID: =?utf-8?q?1759806391069898286?= To change the class of service for 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 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. To address this, implement the rename operation for resctrlfs mon groups to effect a change in CLOSID for a MON group while otherwise leaving the monitoring group intact. Signed-off-by: Peter Newman --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 127 +++++++++++++++++++++++++ 1 file changed, 127 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index 84af23a29612..6d576013fc16 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -3256,6 +3256,132 @@ static int rdtgroup_rmdir(struct kernfs_node *kn) return ret; } +static bool mongrp_reparent_match(struct task_struct *t, struct rdtgroup *from) +{ + WARN_ON(from->type != RDTMON_GROUP); + + /* RMID match implies CLOSID match. */ + return is_rmid_match(t, from); +} + +/** + * 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_del(&rdtgrp->mon.crdtgrp_list); + + list_add_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, mongrp_reparent_match); + + 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; + + /* + * 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) + return -EPERM; + + rdtgrp = kernfs_to_rdtgroup(kn); + new_prdtgrp = kernfs_to_rdtgroup(new_parent); + if (!rdtgrp || !new_prdtgrp) + return -EPERM; + + if (!zalloc_cpumask_var(&tmpmask, GFP_KERNEL)) + return -ENOMEM; + + /* 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(); + + if ((rdtgrp->flags & RDT_DELETED) || (new_prdtgrp->flags & RDT_DELETED)) { + ret = -ESRCH; + 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, they 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; + } + + /* + * Perform all input validation 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) + goto out; + + mongrp_reparent(rdtgrp, new_prdtgrp, tmpmask); + +out: + mutex_unlock(&rdtgroup_mutex); + rdtgroup_kn_put(rdtgrp, kn); + rdtgroup_kn_put(new_prdtgrp, new_parent); + free_cpumask_var(tmpmask); + return ret; +} + static int rdtgroup_show_options(struct seq_file *seq, struct kernfs_root *kf) { if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L3)) @@ -3273,6 +3399,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, };