From patchwork Wed Jan 25 10:13:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 48090 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp199491wrn; Wed, 25 Jan 2023 02:24:56 -0800 (PST) X-Google-Smtp-Source: AMrXdXv0/3SDFEZy93/jk8pLElPE2OMtEBied6kHF1N4qLtcc2fEt9l9p75cPABrlZg3u6Z/BF0G X-Received: by 2002:aa7:874c:0:b0:57f:f2cd:6180 with SMTP id g12-20020aa7874c000000b0057ff2cd6180mr31539440pfo.0.1674642295997; Wed, 25 Jan 2023 02:24:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674642295; cv=none; d=google.com; s=arc-20160816; b=pFMVroPni2PZtRWWufhQ0xl9+34wmSPM1KeNq/eO/URgBjrQHrJBMbTguD3RlWTXid RE6BSnpzBP/Gyqi6cfDRwZJEEXxIIZnYNDnD8ekn53+uIbDETkbw+hKU4U25YryM7yqs SKbjVIzpxK6DRVsk9kB/p6lDeusQSrFYdBKEDN4GKDArbamP2kRuwc8m9+4XiCyNkW3u 1176ocqsWMAQdfel/lvTGDynSzTPkYJWNJXqpOP+0kt7uOfXbxbYszP6aAgt5QxIfRt9 QzmMmZ0vkakJJdns2hqu8wZHIzAXZr4539bFOqIK/U0B346q6vTHEfc2VhKYrIFJuF+4 9nRA== 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=heLbD3mGJYiSLYw01jzlG4oQZAdBRW0StN/Xjg7KmmU=; b=pMyay+y6j0Sm4lUCEwaW0YyQjMxHdY/EpRVlgWmzSVLzkkl1RirJWfyx/dtdP2CtFP RJeF/qiIAZXrTld5Tu3dIo1MWL1H9Z4YzqPgXG7y8sYEh5LlL5kqm/FOEb9twBT4Q0La fZMUxwQf6C1/3L7iOhIHRb/Ctnql8ZHciK0NeqIGE1NAqzNUCn5AH1CAnU3m9hJqnV92 LwSuchXgfg/lkxfWQDwKG/g9XwS80oLISR056n2kmyLRvTZDP+5XEA9hTPI9eozLHH5V uouHnNz/1w8ROxu0qO8FysWLWDT93TIDNfNDpuc0UxKr2/JmaSBh1XoICr2ibc0bSd2/ DlzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Th14K2HT; 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 b63-20020a621b42000000b0058158371654si4856085pfb.368.2023.01.25.02.24.43; Wed, 25 Jan 2023 02:24:55 -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=Th14K2HT; 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 S235319AbjAYKNy (ORCPT + 99 others); Wed, 25 Jan 2023 05:13:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235280AbjAYKNu (ORCPT ); Wed, 25 Jan 2023 05:13:50 -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 C0D2013502 for ; Wed, 25 Jan 2023 02:13:47 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id z17-20020a256651000000b007907852ca4dso19450926ybm.16 for ; Wed, 25 Jan 2023 02:13:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=heLbD3mGJYiSLYw01jzlG4oQZAdBRW0StN/Xjg7KmmU=; b=Th14K2HTVuAxor9Fx9q3Xy5v5o3773fGlKrMPidDRNgJYlCoaDOCwYh2TpFQ2l5ksz /8IZZzhgATWifp2hRAlsFEaDE9uwMgxmJfCrJm9s/XXkazoDIz/Qhf606nhToseZGQFv lqk/PlcxoDLPW129p6EO0rJXpAhFADFgmFf0aZTa6O2Ft2RHSe4stYbcLrJCmhuay8aH wHOe4UWzsm+op9vlAKcD69x+IBndt3UsXq9RzuNvsvGG3YO7A53ixYRIepgQV1y2Gk2P ytP7pVWbDhaMNAVHX2y6pvo/kYSmOXbWH57iH4sKJncE6ukUZM2hZFRPDogjK1xacjNH vw4w== 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=heLbD3mGJYiSLYw01jzlG4oQZAdBRW0StN/Xjg7KmmU=; b=Mzal7/otAx8b5bp1to1YWo+buPpzn/19GWdCWWvb+qIgZ6h79khoiz2lCYRbTF472n yF7ZB66AaBlso0aCROrZssc8YHr1+Pitv9wHVinq4WWpQEM1ri9fw2O19lPJkuVwd9I1 nF1Wx1AlOfhAdUDOgOsKL9+WrJXbWnfTFX1PnKuTuIHf+kYkQ6uP38CjuPyywU1MnTr0 xX+FOPqRHOQsrLrGhjqIYSSfvgSLQMrYUBeydKz3DQKOMycNPaQ1SfXqmE+Kqe/NDanq rd+JFEzsyf0KEjXXQKdl6wuH8WYy2S+I/Ebur9GdEof7rylTKAlBLzvpxYDcLYTGSKId hkJw== X-Gm-Message-State: AFqh2kqQdh21U7x8uIgABqnGTqrICgnUoe32c9kdTznQuTH/3sN3qWM5 guL5GJofwfFWOunyLUjNIO2KY/Cn9wGZnxVwkg== X-Received: from peternewman10.zrh.corp.google.com ([2a00:79e0:9d:6:e533:80e6:38fe:22c]) (user=peternewman job=sendgmr) by 2002:a25:4d55:0:b0:7b4:fa63:5519 with SMTP id a82-20020a254d55000000b007b4fa635519mr3595149ybb.270.1674641626979; Wed, 25 Jan 2023 02:13:46 -0800 (PST) Date: Wed, 25 Jan 2023 11:13:32 +0100 In-Reply-To: <20230125101334.1069060-1-peternewman@google.com> Mime-Version: 1.0 References: <20230125101334.1069060-1-peternewman@google.com> X-Mailer: git-send-email 2.39.1.405.gd4c25cc71f-goog Message-ID: <20230125101334.1069060-2-peternewman@google.com> Subject: [PATCH v3 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, tony.luck@intel.com, tglx@linutronix.de, 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?1755989719976324152?= X-GMAIL-MSGID: =?utf-8?q?1755989719976324152?= rdtgroup_kn_lock_live() can only release a kernfs lock 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}(). This should not result in any functional change. Signed-off-by: Peter Newman --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 35 ++++++++++++++++---------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index 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 Jan 25 10:13:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 48087 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp198834wrn; Wed, 25 Jan 2023 02:23:07 -0800 (PST) X-Google-Smtp-Source: AK7set8RAW1tUKPOXOxvPOdSwlRP/H1v6QBaLCBAZ0Kjd2hx1uDpjlqkiKYggVsp2JyTzQVBfbvy X-Received: by 2002:a17:903:41c3:b0:196:2d55:5b8c with SMTP id u3-20020a17090341c300b001962d555b8cmr1140826ple.4.1674642187102; Wed, 25 Jan 2023 02:23:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674642187; cv=none; d=google.com; s=arc-20160816; b=lRjTKCwSaFs5XBM8SgdGkdHvRFevMdtwNkt8qb3NPwVNoCSsIU6EkfsBqBV8tWSiqe r8OnwpLAoVGjFmpjVNEl97Q/XhUXbbiS7Puayxqq0TFNy7/6yXtdqWUmnbbhspGRS0xt jG+U9D9pUz8DCavLjjaRZZXgnJx/DCjYi0/iCvaIEaGV3duApdw2KnjcJxyhg2c+ubbi uPyr0Mhxr4ipr+5OzKRHYm3U5TR2DMYgFAap3bZC9lGCaSlfpWh/IbU6tjuyDBjYDSlx B1xVPLe/74Ds5o80zURdS2CWcdCpdsE0WzmBTCfbFfNpAGMUYF/qpZouKJNOfxm+eOiY e62Q== 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=BcXbKXfFCZQ65tuD3mFQUJWR038yCPdErih0bDBe5/g=; b=XyNi9pUwQgFvtrWKheyoX6Uo871RTAjoCfjmcARC9E26MBSzsHuJ3Jmhj+1bNGPti/ XEl8oMloIgGOhxD9P/bOYCqMElnrrkkClvMtl0lSKysLL7JdccW4sx5bOoI0bKe1g1tW wKXIn6n5P5zbBwLn3dd94tyEDDMXM1rtKY/Uj8gM4Je35iOwC7tiBrgpLD6htiem1y38 IfWIyfhFcFkOwo9OccB3kXDqD8VnsDXdqXzgP97QxhfmSbTPOXs/XOBiZ2BEBUd2kESa vfvg3yvv7Llt59OZ0BtBp9TWxyBGSX4n/ZrOwBlTLrfNueWUuHuNU+67qlhtwltBc9Nv pc1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="JVs98/Qd"; 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 n1-20020a170902e54100b0019269969d09si5918971plf.319.2023.01.25.02.22.55; Wed, 25 Jan 2023 02:23:07 -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="JVs98/Qd"; 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 S235476AbjAYKOE (ORCPT + 99 others); Wed, 25 Jan 2023 05:14:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235435AbjAYKOB (ORCPT ); Wed, 25 Jan 2023 05:14:01 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11F2D4588B for ; Wed, 25 Jan 2023 02:13:50 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5073cf66299so3177157b3.17 for ; Wed, 25 Jan 2023 02:13:50 -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=BcXbKXfFCZQ65tuD3mFQUJWR038yCPdErih0bDBe5/g=; b=JVs98/QdBEeM/4DZBc3DtaO3NheWS9ikg5NYi6FuMMM25iHCQ/O3qX3Pj3Pr/HmMoa kpCAQ6S0I1TT6pupwtJMbSUncFNMTaS+Y5gj4BuPperHK7F54pJOBj5jqp3Rb2W/ETrC qPN5TcgtzSb6Eioi9yaWXASW2bt5mP9WTz1xrvkMwccT9fmSB9TN/ElOZQDzbaUDjmEu aMkN91fpLlf3O6wWlZMsPv14voNumw5cA0skKP7rPC12oaTVg1Jf74AqaIpRbolpUv4A +HKSyyhyxXLP3TovBq0eu1jtaTgQpBU2mGb5q2jFaHWfP8b0wl1GybzRYi/8+vnxkPwd qsdQ== 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=BcXbKXfFCZQ65tuD3mFQUJWR038yCPdErih0bDBe5/g=; b=g8nrIAk+FNbewBtfdt7dC0QNIUROVJYio60cwwklaKdtzeSusqCGjQopkgMcEvhD4t T2YNT5ss3il8NxjESJZ58yoTaoSLeFI+KqyXtvze1+28hxT2421OjeSrcHuq3uFtiAq9 LYQy2rugZGzKXivjOMc2BRdIFC/g1L+r93g03KIEX2f8P7C3dtTL0ZbZ/npvZU7OpLrG fpGNf4PiLOTEF7SWOKIB3hIpGJt3z/zIoszuu5y+o+iEIDsHAB6kXt/HpZjHc/Tu3Kma Vit0KI8XvjTRA+87TQ/qQ872pBiRb8jf9+xuSU9OpdTiCmlhh0VjV+O1VjRo4Dmy99Iu ztaQ== X-Gm-Message-State: AFqh2kqOWUOnZVi9uM8v6nNT3xiPrQ14+oEaZ2yyKkJVeiYl8zRTjT/g 4rR9+QytKAdoh6MIc9ekQSFIiiLh625/cMvnWg== X-Received: from peternewman10.zrh.corp.google.com ([2a00:79e0:9d:6:e533:80e6:38fe:22c]) (user=peternewman job=sendgmr) by 2002:a81:1951:0:b0:4fe:8186:e5fa with SMTP id 78-20020a811951000000b004fe8186e5famr2299814ywz.140.1674641629953; Wed, 25 Jan 2023 02:13:49 -0800 (PST) Date: Wed, 25 Jan 2023 11:13:33 +0100 In-Reply-To: <20230125101334.1069060-1-peternewman@google.com> Mime-Version: 1.0 References: <20230125101334.1069060-1-peternewman@google.com> X-Mailer: git-send-email 2.39.1.405.gd4c25cc71f-goog Message-ID: <20230125101334.1069060-3-peternewman@google.com> Subject: [PATCH v3 2/3] x86/resctrl: Factor work to update task CLOSID/RMID 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, tony.luck@intel.com, tglx@linutronix.de, 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?1755989606020946891?= X-GMAIL-MSGID: =?utf-8?q?1755989606020946891?= Functions that update a task's CLOSID or RMID must determine whether the task is concurrently running to determine whether the task needs to be interrupted. Negotiating the race conditions involved is nuanced, so spare new types of task group-moving functionality from needing to understand the fine details. Factor the task_struct::{closid,rmid} update along with the synchronized concurrently-running-task check from rdt_move_group_tasks() into a new rdt_move_one_task() helper. Use this helper in __rdtgroup_move_task() as well. This should not result in any functional change. Signed-off-by: Peter Newman --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 60 +++++++++++++------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index c3fb525d52e9..b2081bc1bbfd 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -528,6 +528,31 @@ static void rdtgroup_remove(struct rdtgroup *rdtgrp) kfree(rdtgrp); } +static void rdt_move_one_task(struct task_struct *t, u32 closid, u32 rmid, + cpumask_var_t mask) +{ + WRITE_ONCE(t->closid, closid); + WRITE_ONCE(t->rmid, rmid); + + /* + * Order the closid/rmid stores above before the loads + * in task_curr(). This pairs with the full barrier + * between the rq->curr update and resctrl_sched_in() + * during context switch. + */ + smp_mb(); + + /* + * If the task is on a CPU, set the CPU in the mask. + * The detection is inaccurate as tasks might move or + * schedule before the smp function call takes place. + * In such a case the function call is pointless, but + * there is no other side effect. + */ + if (IS_ENABLED(CONFIG_SMP) && mask && task_curr(t)) + cpumask_set_cpu(task_cpu(t), mask); +} + static void _update_task_closid_rmid(void *task) { /* @@ -566,25 +591,17 @@ static int __rdtgroup_move_task(struct task_struct *tsk, */ if (rdtgrp->type == RDTCTRL_GROUP) { - WRITE_ONCE(tsk->closid, rdtgrp->closid); - WRITE_ONCE(tsk->rmid, rdtgrp->mon.rmid); + rdt_move_one_task(tsk, rdtgrp->closid, rdtgrp->mon.rmid, NULL); } else if (rdtgrp->type == RDTMON_GROUP) { if (rdtgrp->mon.parent->closid == tsk->closid) { - WRITE_ONCE(tsk->rmid, rdtgrp->mon.rmid); + rdt_move_one_task(tsk, tsk->closid, rdtgrp->mon.rmid, + NULL); } else { rdt_last_cmd_puts("Can't move task to different control group\n"); return -EINVAL; } } - /* - * Ensure the task's closid and rmid are written before determining if - * the task is current that will decide if it will be interrupted. - * This pairs with the full barrier between the rq->curr update and - * resctrl_sched_in() during context switch. - */ - smp_mb(); - /* * By now, the task's closid and rmid are set. If the task is current * on a CPU, the PQR_ASSOC MSR needs to be updated to make the resource @@ -2409,26 +2426,7 @@ static void rdt_move_group_tasks(struct rdtgroup *from, struct rdtgroup *to, for_each_process_thread(p, t) { if (!from || is_closid_match(t, from) || is_rmid_match(t, from)) { - WRITE_ONCE(t->closid, to->closid); - WRITE_ONCE(t->rmid, to->mon.rmid); - - /* - * Order the closid/rmid stores above before the loads - * in task_curr(). This pairs with the full barrier - * between the rq->curr update and resctrl_sched_in() - * during context switch. - */ - smp_mb(); - - /* - * If the task is on a CPU, set the CPU in the mask. - * The detection is inaccurate as tasks might move or - * schedule before the smp function call takes place. - * In such a case the function call is pointless, but - * there is no other side effect. - */ - if (IS_ENABLED(CONFIG_SMP) && mask && task_curr(t)) - cpumask_set_cpu(task_cpu(t), mask); + rdt_move_one_task(t, to->closid, to->mon.rmid, mask); } } read_unlock(&tasklist_lock); From patchwork Wed Jan 25 10:13:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 48088 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp198964wrn; Wed, 25 Jan 2023 02:23:23 -0800 (PST) X-Google-Smtp-Source: AMrXdXuhXeW7vBlhR9iEjf9hxVymiM6cBGiV1lif5BWF8U9El+RUGHjxNOa2C0E3HfHvKEd2k1zu X-Received: by 2002:a05:6402:10d4:b0:48f:fcc9:665e with SMTP id p20-20020a05640210d400b0048ffcc9665emr41666596edu.0.1674642203574; Wed, 25 Jan 2023 02:23:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674642203; cv=none; d=google.com; s=arc-20160816; b=Mcdm0GTi/9gHqAt8Ove7RaiwH2rSHSqPMSaglrdlQTm1q48Qh0eiBuFgi/aUMT2hrU dakAaE0MsvfpKjuT6yC39+g5ANSZSTgq71/LJgxmOBBTtwLR0ZcxbIGql7cKjGRA1IlQ uDeHHhXTcECN+9+xl+CwGhVRiPX5TtRRVWgu7Pb0qXYoD93HLM86KF/5JjiVNpPmKEij 9yI0bAHJWfNhpuDn9qJOZnPlupZzFjVLsbCopRJhroUfMk8u/MrHAVUrN4N6BLbtdmWT F28zHjvNr+AO8VeQLrf290b2k6Lan/ldMZPu/Q6hI8RCG84vZ7MlAgZOjTS8qQ/qeQIB jf+Q== 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=tFANQsplcfYmN7Cu3ZOpiMje75MfpJ9o5dr0Y/I/sbo=; b=GK1FN82GT2wYYWp/7Pm9fGh0GCgoscLwYM4bNFb/ozJ01gjoMQsN8MED1IwbeAoYJd W16I7EDQXVeLSzWeIVW8GxctFnvBuUvjIuA8mLvKXMyvUuUfsabEpOlF6M2Np9xelsZe SfqyCqnASmkjD49RYaSvO7UVwk2T/PHFnGhmM+UYKKlx8onc7lv8L/0K0IuJ7GfEe2on i+lDAZnN73BFyl8qT0D0KFlgbQ65kIGEASYy0dvo2hbi3GqWCvWpsMp3xeDoYcTtnf0y Woxx07Z05ciqp51F7Yut4NOmcmo8wxyiMzTJHgX+WCgH818PP8RI5rKevxxof/3oN5xD Zxdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=O8VIBCPk; 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 ec27-20020a0564020d5b00b0045731196587si3459260edb.64.2023.01.25.02.22.59; Wed, 25 Jan 2023 02:23:23 -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=O8VIBCPk; 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 S234431AbjAYKOG (ORCPT + 99 others); Wed, 25 Jan 2023 05:14:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235487AbjAYKOC (ORCPT ); Wed, 25 Jan 2023 05:14:02 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0306A13502 for ; Wed, 25 Jan 2023 02:13:54 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-4cddba76f55so185675157b3.23 for ; Wed, 25 Jan 2023 02:13:53 -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=tFANQsplcfYmN7Cu3ZOpiMje75MfpJ9o5dr0Y/I/sbo=; b=O8VIBCPkSHVXBUTdp+6dObEdarVkoyg8VZeXFQryzghwGEbgSgaG51+9JdcnG5iYBg MUfKU4+EXidCxnEa0lc1wn6DDGQzCx9pwBFR6nufNT3tbXnavgu8XFN3j5y+R0clCaQJ RkmcsXkJVg7j5ytpKWgXYWxvyjwHcRIdfMFDUHZC8xMV7Z5baskFowkjOHxfzh4PzrhQ OTNhAtUBiE78GJUyrieidEbeN/NLfKPNOsAhO9It64x87uTm+NgA9D3gAA2NGWyOObGq pR9/yyvDIcWntbPuWjso3LfIXtTTtNxCJZTCOcbsbkj0w8HBwKbz1XUxtOovk3Lj4R7D B2Fg== 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=tFANQsplcfYmN7Cu3ZOpiMje75MfpJ9o5dr0Y/I/sbo=; b=JUamtVDqNByxvm4NNgTBAR/g4gvEBpqCZBA+KurhthlGVFYzXZU/ZM2A7bpu1damo0 YcH82Z8/uCPkCH5UzvfEQ9n2rfrAgGWVCTBvhNpsK+U3WSmACQqNSoyTT0QJxn/56C00 1FEG9RKOj/wYqIBifEeLNdloSWGQxKHH6hF1S7Sw61MimnZfJwCdpGfhn6X/W+AUcYzc qNabXjuXABywUd8OwVz5hMy4pknBb+mV3Pv0sfcuqPDbvE/RoYy5QDsWsZcYF7puwTGX gETYKN1Le6gzNx8NY/0377VqaZ1zvZ81Etud2xCEmCFuhxSA9BL2wp5LuuDTEVgKPaWF pk8g== X-Gm-Message-State: AFqh2krfCynZyXWl9Uee3W6Ednm/p3LEpx+7fPoqi17B2N6VbdupHFCx okaA4lgZMem5I/ITeCbzMbm510bcRQylKAjY+g== X-Received: from peternewman10.zrh.corp.google.com ([2a00:79e0:9d:6:e533:80e6:38fe:22c]) (user=peternewman job=sendgmr) by 2002:a25:7dc7:0:b0:766:2e0a:55ff with SMTP id y190-20020a257dc7000000b007662e0a55ffmr3693462ybc.325.1674641633188; Wed, 25 Jan 2023 02:13:53 -0800 (PST) Date: Wed, 25 Jan 2023 11:13:34 +0100 In-Reply-To: <20230125101334.1069060-1-peternewman@google.com> Mime-Version: 1.0 References: <20230125101334.1069060-1-peternewman@google.com> X-Mailer: git-send-email 2.39.1.405.gd4c25cc71f-goog Message-ID: <20230125101334.1069060-4-peternewman@google.com> Subject: [PATCH v3 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, tony.luck@intel.com, tglx@linutronix.de, 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?1755989623104742307?= X-GMAIL-MSGID: =?utf-8?q?1755989623104742307?= 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 | 75 ++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index b2081bc1bbfd..595f83a517c6 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -3238,6 +3238,80 @@ static int rdtgroup_rmdir(struct kernfs_node *kn) return ret; } +static void mongrp_move(struct rdtgroup *rdtgrp, struct rdtgroup *new_prdtgrp, + cpumask_var_t cpus) +{ + 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)) + rdt_move_one_task(t, new_prdtgrp->closid, t->rmid, + cpus); + } + read_unlock(&tasklist_lock); + + 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; + + if (!zalloc_cpumask_var(&tmpmask, GFP_KERNEL)) + return -ENOMEM; + + rdtgrp = kernfs_to_rdtgroup(kn); + new_prdtgrp = kernfs_to_rdtgroup(new_parent); + if (!rdtgrp || !new_prdtgrp) { + free_cpumask_var(tmpmask); + 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, 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)) @@ -3255,6 +3329,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, };