The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: James Morse <james.morse@arm.com>
To: x86@kernel.org, linux-kernel@vger.kernel.org
Cc: Reinette Chatre <reinette.chatre@intel.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	H Peter Anvin <hpa@zytor.com>, Babu Moger <Babu.Moger@amd.com>,
	James Morse <james.morse@arm.com>,
	shameerali.kolothum.thodi@huawei.com,
	D Scott Phillips OS <scott@os.amperecomputing.com>,
	carl@os.amperecomputing.com, lcherian@marvell.com,
	bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com,
	baolin.wang@linux.alibaba.com,
	Jamie Iles <quic_jiles@quicinc.com>,
	Xin Hao <xhao@linux.alibaba.com>,
	peternewman@google.com, dfustini@baylibre.com,
	amitsinght@marvell.com, David Hildenbrand <david@redhat.com>,
	Rex Nie <rex.nie@jaguarmicro.com>,
	Dave Martin <dave.martin@arm.com>, Koba Ko <kobak@nvidia.com>,
	Shanker Donthineni <sdonthineni@nvidia.com>,
	fenghuay@nvidia.com, Dave Martin <Dave.Martin@arm.com>,
	Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>,
	Babu Moger <babu.moger@amd.com>, Tony Luck <tony.luck@intel.com>
Subject: [PATCH v8:for-boris 09/30] x86/resctrl: Add helper for setting CPU default properties
Date: Tue, 11 Mar 2025 18:36:54 +0000	[thread overview]
Message-ID: <20250311183715.16445-10-james.morse@arm.com> (raw)
In-Reply-To: <20250311183715.16445-1-james.morse@arm.com>

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 <Dave.Martin@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: James Morse <james.morse@arm.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Amit Singh Tomar <amitsinght@marvell.com> # arm64
Tested-by: Shanker Donthineni <sdonthineni@nvidia.com> # arm64
Tested-by: Babu Moger <babu.moger@amd.com>
Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Fenghua Yu <fenghuay@nvidia.com>
---
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 8b1b6ce1e51b..6908cd0e6e40 100644
--- a/arch/x86/include/asm/resctrl.h
+++ b/arch/x86/include/asm/resctrl.h
@@ -4,8 +4,9 @@
 
 #ifdef CONFIG_X86_CPU_RESCTRL
 
-#include <linux/sched.h>
 #include <linux/jump_label.h>
+#include <linux/percpu.h>
+#include <linux/sched.h>
 
 /*
  * 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 = this_cpu_ptr(&pqr_state);
-	u32 closid = state->default_closid;
-	u32 rmid = state->default_rmid;
+	u32 closid = READ_ONCE(state->default_closid);
+	u32 rmid = READ_ONCE(state->default_rmid);
 	u32 tmp;
 
 	/*
@@ -132,6 +133,13 @@ static inline unsigned int resctrl_arch_round_mon_val(unsigned int val)
 	return val * scale;
 }
 
+static inline void resctrl_arch_set_cpu_default_closid_rmid(int cpu, u32 closid,
+							    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/resctrl/rdtgroup.c
index cd8f65c12124..f706e5a288b1 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -3731,14 +3731,21 @@ static int rdtgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
 static int rdtgroup_rmdir_mon(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask)
 {
 	struct rdtgroup *prdtgrp = rdtgrp->mon.parent;
+	u32 closid, rmid;
 	int cpu;
 
 	/* Give any tasks back to the parent group */
 	rdt_move_group_tasks(rdtgrp, prdtgrp, tmpmask);
 
-	/* 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 = prdtgrp->closid;
+	rmid = prdtgrp->mon.rmid;
 	for_each_cpu(cpu, &rdtgrp->cpu_mask)
-		per_cpu(pqr_state.default_rmid, cpu) = 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.
@@ -3771,6 +3778,7 @@ static int rdtgroup_ctrl_remove(struct rdtgroup *rdtgrp)
 
 static int rdtgroup_rmdir_ctrl(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask)
 {
+	u32 closid, rmid;
 	int cpu;
 
 	/* Give any tasks back to the default group */
@@ -3781,10 +3789,10 @@ static int rdtgroup_rmdir_ctrl(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask)
 		   &rdtgroup_default.cpu_mask, &rdtgrp->cpu_mask);
 
 	/* 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) = rdtgroup_default.closid;
-		per_cpu(pqr_state.default_rmid, cpu) = rdtgroup_default.mon.rmid;
-	}
+	closid = rdtgroup_default.closid;
+	rmid = rdtgroup_default.mon.rmid;
+	for_each_cpu(cpu, &rdtgrp->cpu_mask)
+		resctrl_arch_set_cpu_default_closid_rmid(cpu, closid, rmid);
 
 	/*
 	 * Update the MSR on moved CPUs and CPUs which have moved
-- 
2.39.5


  parent reply	other threads:[~2025-03-11 18:40 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-11 18:36 [PATCH v8:for-boris 00/30] x86/resctrl: Move the resctrl filesystem code to /fs/resctrl James Morse
2025-03-11 18:36 ` [PATCH v8:for-boris 01/30] x86/resctrl: Fix allocation of cleanest CLOSID on platforms with no monitors James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:36 ` [PATCH v8:for-boris 02/30] x86/resctrl: Add a helper to avoid reaching into the arch code resource list James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:36 ` [PATCH v8:for-boris 03/30] x86/resctrl: Remove fflags from struct rdt_resource James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:36 ` [PATCH v8:for-boris 04/30] x86/resctrl: Use schema type to determine how to parse schema values James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:36 ` [PATCH v8:for-boris 05/30] x86/resctrl: Use schema type to determine the schema format string James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:36 ` [PATCH v8:for-boris 06/30] x86/resctrl: Remove data_width and the tabular format James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:36 ` [PATCH v8:for-boris 07/30] x86/resctrl: Add max_bw to struct resctrl_membw James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:36 ` [PATCH v8:for-boris 08/30] x86/resctrl: Generate default_ctrl instead of sharing it James Morse
2025-03-12  4:46   ` Reinette Chatre
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:36 ` James Morse [this message]
2025-03-12 17:20   ` [tip: x86/cache] x86/resctrl: Add helper for setting CPU default properties tip-bot2 for James Morse
2025-03-11 18:36 ` [PATCH v8:for-boris 10/30] x86/resctrl: Remove rdtgroup from update_cpu_closid_rmid() James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:36 ` [PATCH v8:for-boris 11/30] x86/resctrl: Expose resctrl fs's init function to the rest of the kernel James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:36 ` [PATCH v8:for-boris 12/30] x86/resctrl: Move rdt_find_domain() to be visible to arch and fs code James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:36 ` [PATCH v8:for-boris 13/30] x86/resctrl: Move resctrl types to a separate header James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:36 ` [PATCH v8:for-boris 14/30] x86/resctrl: Add an arch helper to reset one resource James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:37 ` [PATCH v8:for-boris 15/30] x86/resctrl: Move monitor exit work to a resctrl exit call James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:37 ` [PATCH v8:for-boris 16/30] x86/resctrl: Move monitor init work to a resctrl init call James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:37 ` [PATCH v8:for-boris 17/30] x86/resctrl: Rewrite and move the for_each_*_rdt_resource() walkers James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:37 ` [PATCH v8:for-boris 18/30] x86/resctrl: Move the is_mbm_*_enabled() helpers to asm/resctrl.h James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:37 ` [PATCH v8:for-boris 19/30] x86/resctrl: Add resctrl_arch_is_evt_configurable() to abstract BMEC James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:37 ` [PATCH v8:for-boris 20/30] x86/resctrl: Change mon_event_config_{read,write}() to be arch helpers James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:37 ` [PATCH v8:for-boris 21/30] x86/resctrl: Move mba_mbps_default_event init to filesystem code James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:37 ` [PATCH v8:for-boris 22/30] x86/resctrl: Move mbm_cfg_mask to struct rdt_resource James Morse
2025-03-12  4:47   ` Reinette Chatre
2025-03-12  9:13     ` Borislav Petkov
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:37 ` [PATCH v8:for-boris 23/30] x86/resctrl: Add resctrl_arch_ prefix to pseudo lock functions James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:37 ` [PATCH v8:for-boris 24/30] x86/resctrl: Allow an architecture to disable pseudo lock James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:37 ` [PATCH v8:for-boris 25/30] x86/resctrl: Make prefetch_disable_bits belong to the arch code James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:37 ` [PATCH v8:for-boris 26/30] x86/resctrl: Make resctrl_arch_pseudo_lock_fn() take a plr James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:37 ` [PATCH v8:for-boris 27/30] x86/resctrl: Move RFTYPE flags to be managed by resctrl James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:37 ` [PATCH v8:for-boris 28/30] x86/resctrl: Handle throttle_mode for SMBA resources James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:37 ` [PATCH v8:for-boris 29/30] x86/resctrl: Move get_config_index() to a header James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-11 18:37 ` [PATCH v8:for-boris 30/30] x86/resctrl: Move get_{mon,ctrl}_domain_from_cpu() to live with their callers James Morse
2025-03-12 17:20   ` [tip: x86/cache] " tip-bot2 for James Morse
2025-03-12  0:29 ` [PATCH v8:for-boris 00/30] x86/resctrl: Move the resctrl filesystem code to /fs/resctrl Moger, Babu
2025-03-12  1:53 ` Luck, Tony
2025-03-12  5:04 ` Reinette Chatre
2025-03-12 10:55 ` Shaopeng Tan (Fujitsu)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250311183715.16445-10-james.morse@arm.com \
    --to=james.morse@arm.com \
    --cc=Babu.Moger@amd.com \
    --cc=amitsinght@marvell.com \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=bobo.shaobowang@huawei.com \
    --cc=bp@alien8.de \
    --cc=carl@os.amperecomputing.com \
    --cc=dave.martin@arm.com \
    --cc=david@redhat.com \
    --cc=dfustini@baylibre.com \
    --cc=fenghuay@nvidia.com \
    --cc=hpa@zytor.com \
    --cc=kobak@nvidia.com \
    --cc=lcherian@marvell.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peternewman@google.com \
    --cc=quic_jiles@quicinc.com \
    --cc=reinette.chatre@intel.com \
    --cc=rex.nie@jaguarmicro.com \
    --cc=scott@os.amperecomputing.com \
    --cc=sdonthineni@nvidia.com \
    --cc=shameerali.kolothum.thodi@huawei.com \
    --cc=tan.shaopeng@fujitsu.com \
    --cc=tan.shaopeng@jp.fujitsu.com \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --cc=x86@kernel.org \
    --cc=xhao@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox