From nobody Fri Dec 19 07:32:35 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 11CE0181CE9 for ; Fri, 14 Jun 2024 15:01:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718377300; cv=none; b=AoMkbXHtaIjd9cwCGIwiUEx6kGXaRYMXx61jnLbZd97h8h2kiy+unwWUFB9OQmBDc3TYzCq0S0rmpqzqg4rroI6Yi/KbdORa7j2QsimEATE4hNein3fKepj19/xKR5FO5A0gGvGyv2Za0wqquykDmLx/OtC+sIH7McChygXKSgk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718377300; c=relaxed/simple; bh=0vBC4O2+09BRB6PwuahCJkPYzRmPZQzPTrIQXb5sj6o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oGHye/thsjVwu9mQfIQtGWvO3MdenXWlrQdCrnT4tp4MdV0dvfxp4vD9cch0jhjXUTNUVroiz+Zgeb6/09TTiufYJ5RICNyFNID3jL5DyAm2eaWDjTwIKfT3bBzrVcEnoYOJV2lgnM+u3pPMbcaDIxvDwTy9vSIdIBzOPVKIiuQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EB5A51756; Fri, 14 Jun 2024 08:02:02 -0700 (PDT) Received: from merodach.members.linode.com (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 29D323F5A1; Fri, 14 Jun 2024 08:01:35 -0700 (PDT) From: James Morse To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: Fenghua Yu , Reinette Chatre , Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , Babu Moger , James Morse , shameerali.kolothum.thodi@huawei.com, D Scott Phillips OS , carl@os.amperecomputing.com, lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com, dfustini@baylibre.com, amitsinght@marvell.com, David Hildenbrand , Rex Nie , Dave Martin , Dave Martin , Shaopeng Tan Subject: [PATCH v3 09/38] x86/resctrl: Add helper for setting CPU default properties Date: Fri, 14 Jun 2024 15:00:04 +0000 Message-Id: <20240614150033.10454-10-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240614150033.10454-1-james.morse@arm.com> References: <20240614150033.10454-1-james.morse@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" rdtgroup_rmdir_ctrl() and rdtgroup_rmdir_mon() set the per-CPU pqr_state for CPUs that were part of the rmdir()'d group. Another architecture might not have a 'pqr_state', its hardware may need the values in a different format. MPAM's equivalent of RMID values are not unique, and always need the CLOSID to be provided too. There is only one caller that modifies a single value, (rdtgroup_rmdir_mon()). MPAM always needs both CLOSID and RMID for the hardware value as these are written to the same system register. As rdtgroup_rmdir_mon() has the CLOSID on hand, only provide a helper to set both values. These values are read by __resctrl_sched_in(), but may be written by a different CPU without any locking, add READ/WRTE_ONCE() to avoid torn values. Co-developed-by: Dave Martin Signed-off-by: Dave Martin Signed-off-by: James Morse Tested-by: Peter Newman Tested-by: Shaopeng Tan --- Changes since v1: * In rdtgroup_rmdir_mon(), (re)set CPU default closid based on the parent control group, to avoid the appearance of referencing something that we're in the process of destroying (even if it doesn't make a difference because the victim mon group necessarily has the same closid as the parent control group). Update comment to match. No (intentional) functional change. --- arch/x86/include/asm/resctrl.h | 14 +++++++++++--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 20 ++++++++++++++------ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/arch/x86/include/asm/resctrl.h b/arch/x86/include/asm/resctrl.h index 12dbd2588ca7..f61382258743 100644 --- a/arch/x86/include/asm/resctrl.h +++ b/arch/x86/include/asm/resctrl.h @@ -4,8 +4,9 @@ =20 #ifdef CONFIG_X86_CPU_RESCTRL =20 -#include #include +#include +#include =20 /* * This value can never be a valid CLOSID, and is used when mapping a @@ -96,8 +97,8 @@ static inline void resctrl_arch_disable_mon(void) static inline void __resctrl_sched_in(struct task_struct *tsk) { struct resctrl_pqr_state *state =3D this_cpu_ptr(&pqr_state); - u32 closid =3D state->default_closid; - u32 rmid =3D state->default_rmid; + u32 closid =3D READ_ONCE(state->default_closid); + u32 rmid =3D READ_ONCE(state->default_rmid); u32 tmp; =20 /* @@ -132,6 +133,13 @@ static inline unsigned int resctrl_arch_round_mon_val(= unsigned int val) return val * scale; } =20 +static inline void resctrl_arch_set_cpu_default_closid_rmid(int cpu, u32 c= losid, + u32 rmid) +{ + WRITE_ONCE(per_cpu(pqr_state.default_closid, cpu), closid); + WRITE_ONCE(per_cpu(pqr_state.default_rmid, cpu), rmid); +} + static inline void resctrl_arch_set_closid_rmid(struct task_struct *tsk, u32 closid, u32 rmid) { diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/r= esctrl/rdtgroup.c index ba43173d5b66..af83b833c523 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -3652,14 +3652,21 @@ static int rdtgroup_mkdir(struct kernfs_node *paren= t_kn, const char *name, static int rdtgroup_rmdir_mon(struct rdtgroup *rdtgrp, cpumask_var_t tmpma= sk) { struct rdtgroup *prdtgrp =3D rdtgrp->mon.parent; + u32 closid, rmid; int cpu; =20 /* Give any tasks back to the parent group */ rdt_move_group_tasks(rdtgrp, prdtgrp, tmpmask); =20 - /* Update per cpu rmid of the moved CPUs first */ + /* + * Update per cpu closid/rmid of the moved CPUs first. + * Note: the closid will not change, but the arch code still needs it. + */ + closid =3D prdtgrp->closid; + rmid =3D prdtgrp->mon.rmid; for_each_cpu(cpu, &rdtgrp->cpu_mask) - per_cpu(pqr_state.default_rmid, cpu) =3D prdtgrp->mon.rmid; + resctrl_arch_set_cpu_default_closid_rmid(cpu, closid, rmid); + /* * Update the MSR on moved CPUs and CPUs which have moved * task running on them. @@ -3692,6 +3699,7 @@ static int rdtgroup_ctrl_remove(struct rdtgroup *rdtg= rp) =20 static int rdtgroup_rmdir_ctrl(struct rdtgroup *rdtgrp, cpumask_var_t tmpm= ask) { + u32 closid, rmid; int cpu; =20 /* Give any tasks back to the default group */ @@ -3702,10 +3710,10 @@ static int rdtgroup_rmdir_ctrl(struct rdtgroup *rdt= grp, cpumask_var_t tmpmask) &rdtgroup_default.cpu_mask, &rdtgrp->cpu_mask); =20 /* Update per cpu closid and rmid of the moved CPUs first */ - for_each_cpu(cpu, &rdtgrp->cpu_mask) { - per_cpu(pqr_state.default_closid, cpu) =3D rdtgroup_default.closid; - per_cpu(pqr_state.default_rmid, cpu) =3D rdtgroup_default.mon.rmid; - } + closid =3D rdtgroup_default.closid; + rmid =3D rdtgroup_default.mon.rmid; + for_each_cpu(cpu, &rdtgrp->cpu_mask) + resctrl_arch_set_cpu_default_closid_rmid(cpu, closid, rmid); =20 /* * Update the MSR on moved CPUs and CPUs which have moved --=20 2.39.2