Skip to contentSkip to conversation

x86,fs/resctrl: Support for Global Bandwidth Enforcement and Priviledge Level Zero Association

RFC PATCH Superseded Babu Moger 8 participants 114 messages Jan 21 – Feb 24 Page 2 of 2

Subsystems (5)
Documentation x86 KVM Scheduler +1 more subsystems

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#96 lore raw

Re: [RFC PATCH 13/19] x86/resctrl: Add PLZA state tracking and context switch handling

In reply to Moger, Babu

Hi Babu,

Quoted 66 lines · Babu

Hi Tony,

Thanks for the comment.

Quoted 24 lines · Tony
Quoted 10 lines · Babu Moger
arch/x86/include/asm/resctrl.h +5 -0
@@ -138,6 +143,20 @@ static inline void __resctrl_sched_in(struct
 task_struct *tsk)
           state->cur_rmid = rmid;
           wrmsr(MSR_IA32_PQR_ASSOC, rmid, closid);
       }
+
+    if (static_branch_likely(&rdt_plza_enable_key)) {
+        tmp = READ_ONCE(tsk->plza);
+        if (tmp)
+            plza = tmp;

arch/x86/include/asm/resctrl.h static inline void __resctrl_sched_in(struct · line 161

Quoted 10 lines
arch/x86/include/asm/resctrl.h +9 -0
+
+        if (plza != state->cur_plza) {
+            state->cur_plza = plza;
+            wrmsr(MSR_IA32_PQR_PLZA_ASSOC,
+                  RMID_EN | state->plza_rmid,
+                  (plza ? PLZA_EN : 0) | CLOSID_EN | state-
 >plza_closid);
+        }
+    }
+

Babu,

Quoted 7 lines

This addition to the context switch code surprised me. After your talk at LPC I had imagined that PLZA would be a single global setting so that every syscall/page-fault/interrupt would run with a different CLOSID (presumably one configured with more cache and memory bandwidth).

But this patch series looks like things are more flexible with the ability to set different values (of RMID as well as CLOSID) per group.

Yes. this similar what we have with MSR_IA32_PQR_ASSOC. The association can be done either thru CPUs (just one MSR write) or task based association(more MSR write as task moves around).

Quoted 9 lines

It looks like it is possible to have some resctrl group with very limited resources just bump up a bit when in ring0, while other groups may get some different amount.

The additions for plza to the Documentation aren't helping me understand how users will apply this.

Do you have some more examples?

Group creation is similar to what we have currently.

1. create a regular group and setup the limits.

   # mkdir /sys/fs/resctrl/group

2. Assign tasks or CPUs.

   # echo 1234 > /sys/fs/resctrl/group/tasks

   This is a regular group.

3. Now you figured that you need to change things in CPL0 for this task.

4. Now create a PLZA group now and tweek the limits,

   # mkdir /sys/fs/resctrl/group1
Quoted 7 lines
   # echo 1 > /sys/fs/resctrl/group1/plza
   # echo "MB:0=100" > /sys/fs/resctrl/group1/schemata

5. Assign the same task to the plza group.

   # echo 1234 > /sys/fs/resctrl/group1/tasks

Reusing 'tasks' files for kernel configuration risks confusing existing user space tools that don't know about the new plza option. E.g. this may be a problem if the user manually set the plza and then tried to use their existing tool for understanding or configuring resctrl settings.

Quoted 10 lines

Now the task 1234 will be using the limits from group1 when running in CPL0.

I will add few more details in my next revision.

Thanks
Babu

Thanks,

Ben

author reviewer
#97 lore raw

RFC PATCH 14/19 x86,fs/resctrl: Add the functionality to configure PLZA

In reply to Babu Moger

Privilege Level Zero Association (PLZA) is configured by writing to MSR_IA32_PQR_PLZA_ASSOC. PLZA is disabled by default on all logical processors in the QOS Domain. System software must follow the following sequence.

1. Set the closid, closid_en, rmid and rmid_en fields of MSR_IA32_PQR_PLZA_ASSOC to the desired configuration on all logical processors in the QOS Domain.

2. Set MSR_IA32_PQR_PLZA_ASSOC[PLZA_EN]=1 for
all logical processors in the QOS domain where PLZA should be enabled.

MSR_IA32_PQR_PLZA_ASSOC[PLZA_EN] may have a different value on every logical processor in the QOS domain. The system software should perform this as a read-modify-write to avoid changing the value of closid_en, closid, rmid_en, and rmid fields of MSR_IA32_PQR_PLZA_ASSOC.

---
 arch/x86/include/asm/resctrl.h            |  7 +++++++
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 25 +++++++++++++++++++++++
 include/linux/resctrl.h                   | 11 ++++++++++
 3 files changed, 43 insertions(+)
arch/x86/include/asm/resctrl.h +7 -0
index 76de7d6051b7..89b38948be1a 100644
@@ -193,6 +193,13 @@ static inline bool resctrl_arch_match_rmid(struct task_struct *tsk, u32 ignored,
 	return READ_ONCE(tsk->rmid) == rmid;
 }
 
+static inline void resctrl_arch_set_cpu_plza(int cpu, u32 closid, u32 rmid, u32 enable)
+{
+	WRITE_ONCE(per_cpu(pqr_state.default_plza, cpu), enable);
+	WRITE_ONCE(per_cpu(pqr_state.plza_closid, cpu), closid);
+	WRITE_ONCE(per_cpu(pqr_state.plza_rmid, cpu), rmid);
+}
+
 static inline void resctrl_arch_sched_in(struct task_struct *tsk)
 {
 	if (static_branch_likely(&rdt_enable_key))
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +25 -0
index b20e705606b8..79ed41bde810 100644
@@ -131,3 +131,28 @@ int resctrl_arch_io_alloc_enable(struct rdt_resource *r, bool enable)
 
 	return 0;
 }
+
+static void resctrl_plza_set_one_amd(void *arg)
+{
+	union qos_pqr_plza_assoc *plza = arg;
+
+	wrmsrl(MSR_IA32_PQR_PLZA_ASSOC, plza->full);
+}
+
+void resctrl_arch_plza_setup(struct rdt_resource *r, u32 closid, u32 rmid)
+{
+	union qos_pqr_plza_assoc plza = { 0 };
+	struct rdt_ctrl_domain *d;
+	int cpu;
+
+	plza.split.rmid = rmid;
+	plza.split.rmid_en = 1;
+	plza.split.closid = closid;
+	plza.split.closid_en = 1;
+
+	list_for_each_entry(d, &r->ctrl_domains, hdr.list) {
+		for_each_cpu(cpu, &d->hdr.cpu_mask)
+			resctrl_arch_set_cpu_plza(cpu, closid, rmid, 0);
+		on_each_cpu_mask(&d->hdr.cpu_mask, resctrl_plza_set_one_amd, &plza, 1);
+	}
+}
include/linux/resctrl.h +11 -0
index ae252a0e6d92..ef26253ad24a 100644
@@ -704,6 +704,17 @@ int resctrl_arch_io_alloc_enable(struct rdt_resource *r, bool enable);
  */
 bool resctrl_arch_get_io_alloc_enabled(struct rdt_resource *r);
 
+/*
+ * resctrl_arch_plza_setup() - Reset all private state associated with
+ *				   all rmids and eventids.
+ * @r:		The resctrl resource.
+ * @closid:	The CLOSID to be configered for PLZA.
+ * @rmid:	The RMID to be configered for PLZA.
+ *
+ * This can be called from any CPU.
+ */
+void resctrl_arch_plza_setup(struct rdt_resource *r, u32 closid, u32 rmid);
+
 extern unsigned int resctrl_rmid_realloc_threshold;
 extern unsigned int resctrl_rmid_realloc_limit;
 
Signature · 1 line
2.34.1
maintainer
#98 lore raw

Re: [RFC PATCH 14/19] x86,fs/resctrl: Add the functionality to configure PLZA

Quoted 9 lines · Babu Moger

Privilege Level Zero Association (PLZA) is configured by writing to MSR_IA32_PQR_PLZA_ASSOC. PLZA is disabled by default on all logical processors in the QOS Domain. System software must follow the following sequence.

1. Set the closid, closid_en, rmid and rmid_en fields of MSR_IA32_PQR_PLZA_ASSOC to the desired configuration on all logical processors in the QOS Domain.

Quoted 7 lines

2. Set MSR_IA32_PQR_PLZA_ASSOC[PLZA_EN]=1 for
all logical processors in the QOS domain where PLZA should be enabled.

MSR_IA32_PQR_PLZA_ASSOC[PLZA_EN] may have a different value on every logical processor in the QOS domain. The system software should perform this as a read-modify-write to avoid changing the value of closid_en, closid, rmid_en, and rmid fields of MSR_IA32_PQR_PLZA_ASSOC.

Architecturally this is true. But in the implementation for resctrl there is only one PLZA group. So the CLOSID and RMID fields are identical on every logical processor. The only changing bit is the PLZA_EN.

The code could be simpler if you just maintained a single global with the CLOSID/RMID bits initialized by resctrl_arch_plza_setup().

union qos_pqr_plza_assoc plza_value; // needs a better name

Change the PLZA_EN define to be

#define PLZA_EN BIT_ULL(63)

and then the hook into the __resctrl_sched_in() becomes:

	if (static_branch_likely(&rdt_plza_enable_key)) {
		u32 plza = READ_ONCE(state->default_plza); // note, moved this inside the static branch
		tmp = READ_ONCE(tsk->plza);
		if (tmp)
			plza = tmp;

		if (plza != state->cur_plza) {
			state->cur_plza = plza;
			wrmsrq(MSR_IA32_PQR_PLZA_ASSOC,
			       (plza ? PLZA_EN : 0) | plza_value.full);
		}
	}

[Earlier e-mail about clearing the high half of MSR_IA32_PQR_PLZA_ASSOC was wrong. My debug trace printed the wrong value. The argument to the wrmsrl() is correct].

-Tony

#99 lore raw

Re: [RFC PATCH 14/19] x86,fs/resctrl: Add the functionality to configure PLZA

Hi Tony,

Quoted 13 lines · Tony
Quoted 12 lines · Babu Moger

Privilege Level Zero Association (PLZA) is configured by writing to MSR_IA32_PQR_PLZA_ASSOC. PLZA is disabled by default on all logical processors in the QOS Domain. System software must follow the following sequence.

1. Set the closid, closid_en, rmid and rmid_en fields of MSR_IA32_PQR_PLZA_ASSOC to the desired configuration on all logical processors in the QOS Domain.

2. Set MSR_IA32_PQR_PLZA_ASSOC[PLZA_EN]=1 for
all logical processors in the QOS domain where PLZA should be enabled.

Quoted 8 lines
Quoted 4 lines

MSR_IA32_PQR_PLZA_ASSOC[PLZA_EN] may have a different value on every logical processor in the QOS domain. The system software should perform this as a read-modify-write to avoid changing the value of closid_en, closid, rmid_en, and rmid fields of MSR_IA32_PQR_PLZA_ASSOC.

Architecturally this is true. But in the implementation for resctrl there is only one PLZA group. So the CLOSID and RMID fields are identical on every logical processor. The only changing bit is the PLZA_EN.

Correct.

Quoted 6 lines

The code could be simpler if you just maintained a single global with the CLOSID/RMID bits initialized by resctrl_arch_plza_setup().

union qos_pqr_plza_assoc plza_value; // needs a better name

Yea. That is a good point.   We don't have to store CLOSID/RMID in

per-CPU state. Will do those changes in my next revision.

Quoted 20 lines

Change the PLZA_EN define to be

#define PLZA_EN BIT_ULL(63)

and then the hook into the __resctrl_sched_in() becomes:

	if (static_branch_likely(&rdt_plza_enable_key)) {
		u32 plza = READ_ONCE(state->default_plza); // note, moved this inside the static branch
		tmp = READ_ONCE(tsk->plza);
		if (tmp)
			plza = tmp;

		if (plza != state->cur_plza) {
			state->cur_plza = plza;
			wrmsrq(MSR_IA32_PQR_PLZA_ASSOC,
			       (plza ? PLZA_EN : 0) | plza_value.full);
		}
	}
Quoted 3 lines

[Earlier e-mail about clearing the high half of MSR_IA32_PQR_PLZA_ASSOC was wrong. My debug trace printed the wrong value. The argument to the wrmsrl() is correct].

Got it. Thanks

Babu

author reviewer
#100 lore raw

RFC PATCH 15/19 fs/resctrl: Introduce PLZA attribute in rdtgroup interface

In reply to Babu Moger

Add plza attribute to display Privilege Level Zero Association for the resctrl group.

---
 fs/resctrl/internal.h |  2 ++
 fs/resctrl/rdtgroup.c | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)
fs/resctrl/internal.h +2 -0
index 1a9b29119f88..c107c1328be6 100644
@@ -215,6 +215,7 @@ struct mongroup {
  *				monitor only or ctrl_mon group
  * @mon:			mongroup related data
  * @mode:			mode of resource group
+ * @plza:			Is Privilege Level Zero Association enabled?
  * @mba_mbps_event:		input monitoring event id when mba_sc is enabled
  * @plr:			pseudo-locked region
  */
@@ -228,6 +229,7 @@ struct rdtgroup {
 	enum rdt_group_type		type;
 	struct mongroup			mon;
 	enum rdtgrp_mode		mode;
+	bool				plza;
 	enum resctrl_event_id		mba_mbps_event;
 	struct pseudo_lock_region	*plr;
 };
fs/resctrl/rdtgroup.c +32 -0
index 616be6633a6d..d467b52a0c74 100644
@@ -880,6 +880,22 @@ static int rdtgroup_rmid_show(struct kernfs_open_file *of,
 	return ret;
 }
 
+static int rdtgroup_plza_show(struct kernfs_open_file *of,
+			      struct seq_file *s, void *v)
+{
+	struct rdtgroup *rdtgrp;
+	int ret = 0;
+
+	rdtgrp = rdtgroup_kn_lock_live(of->kn);
+	if (rdtgrp)
+		seq_printf(s, "%u\n", rdtgrp->plza);
+	else
+		ret = -ENOENT;
+	rdtgroup_kn_unlock(of->kn);
+
+	return ret;
+}
+
 #ifdef CONFIG_PROC_CPU_RESCTRL
 /*
  * A task can only be part of one resctrl control group and of one monitor
@@ -2153,6 +2169,12 @@ static struct rftype res_common_files[] = {
 		.seq_show	= rdtgroup_closid_show,
 		.fflags		= RFTYPE_CTRL_BASE | RFTYPE_DEBUG,
 	},
+	{
+		.name		= "plza",
+		.mode		= 0444,
+		.kf_ops		= &rdtgroup_kf_single_ops,
+		.seq_show	= rdtgroup_plza_show,
+	},
 };
 
 static int rdtgroup_add_files(struct kernfs_node *kn, unsigned long fflags)
@@ -2251,6 +2273,14 @@ static void io_alloc_init(void)
 	}
 }
 
+static void resctrl_plza_init(void)
+{
+	struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
+
+	if (r->plza_capable)
+		resctrl_file_fflags_init("plza", RFTYPE_CTRL_BASE);
+}
+
 void resctrl_file_fflags_init(const char *config, unsigned long fflags)
 {
 	struct rftype *rft;
@@ -4609,6 +4639,8 @@ int resctrl_init(void)
 
 	io_alloc_init();
 
+	resctrl_plza_init();
+
 	ret = resctrl_l3_mon_resource_init();
 	if (ret)
 		return ret;
Signature · 1 line
2.34.1
author reviewer
#101 lore raw

RFC PATCH 16/19 fs/resctrl: Implement rdtgroup_plza_write() to configure PLZA in a group

In reply to Babu Moger

Introduce rdtgroup_plza_write() group which enables per group control of PLZA through the resctrl filesystem and ensure that enabling or disabling PLZA is propagated consistently across all CPUs belonging to the group.

Enforce the capability checks, exclude default, pseudo-locked and CTRL_MON groups with sub monitors. Also, ensure that only one group can have PLZA enabled at a time.

---
 Documentation/filesystems/resctrl.rst |  5 ++
 fs/resctrl/rdtgroup.c                 | 88 ++++++++++++++++++++++++++-
 2 files changed, 92 insertions(+), 1 deletion(-)
Documentation/filesystems/resctrl.rst +5 -0
index 1de55b5cb0e3..8edcc047ffe5 100644
@@ -626,6 +626,11 @@ When control is enabled all CTRL_MON groups will also contain:
 	Available only with debug option. The identifier used by hardware
 	for the control group. On x86 this is the CLOSID.
 
+"plza":
+        When enabled, CPUs or tasks in the resctrl group follow the group's
+        limits while running at Privilege Level 0 (CPL-0). This can only be
+        enabled for CTRL_MON groups.
+
 When monitoring is enabled all MON groups will also contain:
 
 "mon_data":
fs/resctrl/rdtgroup.c +87 -1

118 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#102 lore raw

Re: [RFC PATCH 16/19] fs/resctrl: Implement rdtgroup_plza_write() to configure PLZA in a group

Quoted 8 lines · Babu Moger

Introduce rdtgroup_plza_write() group which enables per group control of PLZA through the resctrl filesystem and ensure that enabling or disabling PLZA is propagated consistently across all CPUs belonging to the group.

Enforce the capability checks, exclude default, pseudo-locked and CTRL_MON groups with sub monitors. Also, ensure that only one group can have PLZA enabled at a time.

...

Quoted 7 lines
(quoted diff) +7 -0
+static ssize_t rdtgroup_plza_write(struct kernfs_open_file *of, char *buf,
+				   size_t nbytes, loff_t off)
+{
+	struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
+	struct rdtgroup *rdtgrp, *prgrp;
+	int cpu, ret = 0;
+	bool enable;

...

Review

Quoted 3 lines
(quoted diff) +3 -0
+	/* Enable or disable PLZA state and update per CPU state if there is a change */
+	if (enable != rdtgrp->plza) {
+		resctrl_arch_plza_setup(r, rdtgrp->closid, rdtgrp->mon.rmid);

What is this for? If I've just created a group with no tasks, and empty CPU mask ... it seems that this writes the MSR_IA32_PQR_PLZA_ASSOC on every CPU in every domain.

Review

Quoted 11 lines
(quoted diff) +11 -0
+		for_each_cpu(cpu, &rdtgrp->cpu_mask)
+			resctrl_arch_set_cpu_plza(cpu, rdtgrp->closid,
+						  rdtgrp->mon.rmid, enable);
+		rdtgrp->plza = enable;
+	}
+
+unlock:
+	rdtgroup_kn_unlock(of->kn);
+
+	return ret ?: nbytes;
+}

It also appears that marking a task as PLZA is permanent. Moving it to another group doesn't unmark it. Is this intentional?

# mkdir group1 group2 plza_group
# echo 1 > plza_group/plza
# echo $$ > group1/tasks
# echo $$ > plza_group/tasks

My shell is now in group1 and in the plza_group

# grep $$ */tasks
group1/tasks:4125
plza_group/tasks:4125

Move shell to group2

# echo $$ > group2/tasks
# grep $$ */tasks
group2/tasks:4125
plza_group/tasks:4125

Succcess in moving to group2, but still in plza_group

-Tony

N.B. I don't have a PLZA enabled system. So I faked it with this patch.

From 1655fea0049947218fa5400916d57109be8521ef Mon Sep 17 00:00:00 2001
From: Tony Luck <[email protected]>
Date: Wed, 28 Jan 2026 13:02:51 -0800
Subject: [PATCH] fake PLZA

---
 arch/x86/include/asm/resctrl.h            | 10 ++++++----
 arch/x86/kernel/cpu/resctrl/core.c        |  4 ++--
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c |  3 ++-
 3 files changed, 10 insertions(+), 7 deletions(-)
arch/x86/include/asm/resctrl.h +6 -4
index 2c11787c5253..7ee35bebb64c 100644
@@ -90,14 +90,16 @@ static inline void resctrl_arch_disable_mon(void)
 
 static inline void resctrl_arch_enable_plza(void)
 {
-	static_branch_enable_cpuslocked(&rdt_plza_enable_key);
-	static_branch_inc_cpuslocked(&rdt_enable_key);
+	pr_info("resctrl_arch_enable_plza\n");
+	//static_branch_enable_cpuslocked(&rdt_plza_enable_key);
+	//static_branch_inc_cpuslocked(&rdt_enable_key);
 }
 
 static inline void resctrl_arch_disable_plza(void)
 {
-	static_branch_disable_cpuslocked(&rdt_plza_enable_key);
-	static_branch_dec_cpuslocked(&rdt_enable_key);
+	pr_info("resctrl_arch_disable_plza\n");
+	//static_branch_disable_cpuslocked(&rdt_plza_enable_key);
+	//static_branch_dec_cpuslocked(&rdt_enable_key);
 }
 
 /*
arch/x86/kernel/cpu/resctrl/core.c +2 -2
index e41fe5fa3f30..780cdfb0e7cd 100644
@@ -295,7 +295,7 @@ static __init bool __rdt_get_mem_config_amd(struct rdt_resource *r)
 
 	r->alloc_capable = true;
 
-	if (rdt_cpu_has(X86_FEATURE_PLZA))
+	if (1 || rdt_cpu_has(X86_FEATURE_PLZA))
 		r->plza_capable = true;
 
 	return true;
@@ -318,7 +318,7 @@ static void rdt_get_cache_alloc_cfg(int idx, struct rdt_resource *r)
 		r->cache.arch_has_sparse_bitmasks = ecx.split.noncont;
 	r->alloc_capable = true;
 
-	if (rdt_cpu_has(X86_FEATURE_PLZA))
+	if (1 || rdt_cpu_has(X86_FEATURE_PLZA))
 		r->plza_capable = true;
 }
 
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +2 -1
index 79ed41bde810..24a37ebed13a 100644
@@ -136,7 +136,8 @@ static void resctrl_plza_set_one_amd(void *arg)
 {
 	union qos_pqr_plza_assoc *plza = arg;
 
-	wrmsrl(MSR_IA32_PQR_PLZA_ASSOC, plza->full);
+	pr_info("wrmsr(MSR_IA32_PQR_PLZA_ASSOC, 0x%lx)\n", plza->full);
+	//wrmsrl(MSR_IA32_PQR_PLZA_ASSOC, plza->full);
 }
 
 void resctrl_arch_plza_setup(struct rdt_resource *r, u32 closid, u32 rmid)
Signature · 1 line
2.52.0
maintainer
#103 lore raw

Re: [RFC PATCH 16/19] fs/resctrl: Implement rdtgroup_plza_write() to configure PLZA in a group

Quoted 21 lines · Tony
Quoted 8 lines · Babu Moger

Introduce rdtgroup_plza_write() group which enables per group control of PLZA through the resctrl filesystem and ensure that enabling or disabling PLZA is propagated consistently across all CPUs belonging to the group.

Enforce the capability checks, exclude default, pseudo-locked and CTRL_MON groups with sub monitors. Also, ensure that only one group can have PLZA enabled at a time.

...

Quoted 7 lines
(quoted diff) +7 -0
+static ssize_t rdtgroup_plza_write(struct kernfs_open_file *of, char *buf,
+				   size_t nbytes, loff_t off)
+{
+	struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
+	struct rdtgroup *rdtgrp, *prgrp;
+	int cpu, ret = 0;
+	bool enable;

...

Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+	/* Enable or disable PLZA state and update per CPU state if there is a change */
+	if (enable != rdtgrp->plza) {
+		resctrl_arch_plza_setup(r, rdtgrp->closid, rdtgrp->mon.rmid);

What is this for? If I've just created a group with no tasks, and empty CPU mask ... it seems that this writes the MSR_IA32_PQR_PLZA_ASSOC on every CPU in every domain.

I think I see now. There are THREE enable bits in your MSR_IA32_PQR_PLZA_ASSOC.
One each for CLOSID and RMID, and an overall PLZA_EN in the high bit.

At this step you setup the CLOSID/RMID with their enable bits, but leaving the PLZA_EN off.

Is this a subtle optimzation for the context switch? Is the WRMSR faster if it only toggle PLZA_EN leaving all the other bits unchanged?

This might not be working as expected. The context switch code does:

		wrmsr(MSR_IA32_PQR_PLZA_ASSOC,
		      RMID_EN | state->plza_rmid,
		      (plza ? PLZA_EN : 0) | CLOSID_EN | state->plza_closid);

This doesn't just clear the PLZA_EN bit, it zeroes the high dword of the MSR.

Quoted 2 lines

It also appears that marking a task as PLZA is permanent. Moving it to another group doesn't unmark it. Is this intentional?

Ditto assigning a CPU to the PLZA group. Once done it can't be undone (except by turing off PLZA?).

-Tony

[More comments about this coming against patch 16]

#104 lore raw

Re: [RFC PATCH 16/19] fs/resctrl: Implement rdtgroup_plza_write() to configure PLZA in a group

Hi Tony,

Quoted 21 lines · Tony
Quoted 20 lines · Tony
Quoted 8 lines · Babu Moger

Introduce rdtgroup_plza_write() group which enables per group control of PLZA through the resctrl filesystem and ensure that enabling or disabling PLZA is propagated consistently across all CPUs belonging to the group.

Enforce the capability checks, exclude default, pseudo-locked and CTRL_MON groups with sub monitors. Also, ensure that only one group can have PLZA enabled at a time.

...

Quoted 7 lines
(quoted diff) +7 -0
+static ssize_t rdtgroup_plza_write(struct kernfs_open_file *of, char *buf,
+				   size_t nbytes, loff_t off)
+{
+	struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
+	struct rdtgroup *rdtgrp, *prgrp;
+	int cpu, ret = 0;
+	bool enable;

...

Quoted 6 lines
Quoted 6 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+	/* Enable or disable PLZA state and update per CPU state if there is a change */
+	if (enable != rdtgrp->plza) {
+		resctrl_arch_plza_setup(r, rdtgrp->closid, rdtgrp->mon.rmid);

What is this for? If I've just created a group with no tasks, and empty CPU mask ... it seems that this writes the MSR_IA32_PQR_PLZA_ASSOC on every CPU in every domain.

Here is the reason.

Some fields of PQR_PLZA_ASSOC must be set to the same value for all HW threads in the QOS domain for consistent operation (Per-QosDomain).

 The user should use the following sequence to set these values to a consistent state.

1.

Set PQR_PLZA_ASSOC[PLZA_EN]=0 for all HW threads in the QOS Domain

2.

Set the COS_EN, COS, RMID_EN, and RMID fields of PQR_PLZA_ASSOC to the desired configuration on all HW threads in the QOS Domain

3.

Set PQR_PLZA_ASSOC[PLZA_EN]=1 for all HW threads in the QOS Domain where PLZA should be enabled.

*

The user should perform this as a read-modify-write to avoid changing the value of COS_EN, COS, RMID_EN, and RMID fields of PQR_PLZA_ASSOC.

Basically, we have to set all the fields to consistent state to setup the PLZA first.   Then setup PLZA_EN bit on each thread based on current association.

Quoted 9 lines

I think I see now. There are THREE enable bits in your MSR_IA32_PQR_PLZA_ASSOC.
One each for CLOSID and RMID, and an overall PLZA_EN in the high bit.

At this step you setup the CLOSID/RMID with their enable bits, but leaving the PLZA_EN off.

Is this a subtle optimzation for the context switch? Is the WRMSR faster if it only toggle PLZA_EN leaving all the other bits unchanged?

I really did not think of optimization here. Mostly followed the spec.

Quoted 18 lines

This might not be working as expected. The context switch code does:

		wrmsr(MSR_IA32_PQR_PLZA_ASSOC,
		      RMID_EN | state->plza_rmid,
		      (plza ? PLZA_EN : 0) | CLOSID_EN | state->plza_closid);

This doesn't just clear the PLZA_EN bit, it zeroes the high dword of the MSR.

Quoted 2 lines

It also appears that marking a task as PLZA is permanent. Moving it to another group doesn't unmark it. Is this intentional?

Ditto assigning a CPU to the PLZA group. Once done it can't be undone (except by turing off PLZA?).

-Tony

[More comments about this coming against patch 16]

#105 lore raw

Re: [RFC PATCH 16/19] fs/resctrl: Implement rdtgroup_plza_write() to configure PLZA in a group

In reply to Luck, Tony

Hi Tony,

Quoted 51 lines · Tony
Quoted 8 lines · Babu Moger

Introduce rdtgroup_plza_write() group which enables per group control of PLZA through the resctrl filesystem and ensure that enabling or disabling PLZA is propagated consistently across all CPUs belonging to the group.

Enforce the capability checks, exclude default, pseudo-locked and CTRL_MON groups with sub monitors. Also, ensure that only one group can have PLZA enabled at a time.

...

Quoted 7 lines
(quoted diff) +7 -0
+static ssize_t rdtgroup_plza_write(struct kernfs_open_file *of, char *buf,
+				   size_t nbytes, loff_t off)
+{
+	struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
+	struct rdtgroup *rdtgrp, *prgrp;
+	int cpu, ret = 0;
+	bool enable;

...

Review

Quoted 3 lines
(quoted diff) +3 -0
+	/* Enable or disable PLZA state and update per CPU state if there is a change */
+	if (enable != rdtgrp->plza) {
+		resctrl_arch_plza_setup(r, rdtgrp->closid, rdtgrp->mon.rmid);

What is this for? If I've just created a group with no tasks, and empty CPU mask ... it seems that this writes the MSR_IA32_PQR_PLZA_ASSOC on every CPU in every domain.

Review

Quoted 11 lines
(quoted diff) +11 -0
+		for_each_cpu(cpu, &rdtgrp->cpu_mask)
+			resctrl_arch_set_cpu_plza(cpu, rdtgrp->closid,
+						  rdtgrp->mon.rmid, enable);
+		rdtgrp->plza = enable;
+	}
+
+unlock:
+	rdtgroup_kn_unlock(of->kn);
+
+	return ret ?: nbytes;
+}

It also appears that marking a task as PLZA is permanent. Moving it to another group doesn't unmark it. Is this intentional?

# mkdir group1 group2 plza_group
# echo 1 > plza_group/plza
# echo $$ > group1/tasks
# echo $$ > plza_group/tasks

My shell is now in group1 and in the plza_group

# grep $$ */tasks
group1/tasks:4125
plza_group/tasks:4125
Quoted 7 lines

Move shell to group2

# echo $$ > group2/tasks
# grep $$ */tasks
group2/tasks:4125
plza_group/tasks:4125

Succcess in moving to group2, but still in plza_group

You are moving the task from group1 to group2. This basically changes the association in

MSR_IA32_PQR_ASSOC register, It does not change the PLZA association.

To change it:

a. You either remove task from plza group which triggers task update (tsk->plza = 0)

echo >> /sys/fs/resctrl/plza_group/tasks

b. Or you can change the group as regular group.

  echo 0 > /sys/fs/resctrl/plza_group/plza

Thanks for the trying it out.

- Babu

maintainer
#106 lore raw

Re: [RFC PATCH 16/19] fs/resctrl: Implement rdtgroup_plza_write() to configure PLZA in a group

In reply to Babu Moger

Hi Babu,

fs/resctrl/rdtgroup.c static int rdtgroup_plza_show(struct kernfs_open_file *of, · line 902

Quoted 4 lines · Babu Moger
fs/resctrl/rdtgroup.c +4 -0
+static ssize_t rdtgroup_plza_write(struct kernfs_open_file *of, char *buf,
+				   size_t nbytes, loff_t off)
+{
+	struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);

Hardcoding PLZA configuration to the L3 resource is unexpected, especially since PLZA's impact and configuration on MBA is mentioned a couple of times in this series and discussions that followed. There also does not seem to be any "per resource" PLZA capability but instead when system supports PLZA RDT_RESOURCE_L2, RDT_RESOURCE_L3, and RDT_RESOURCE_MBA are automatically (if resources are present) set to support it.

From what I understand PLZA enables user space to configure CLOSID and RMID used in CPL=0 independent from resource. That is, when a user configures PLZA with this interface all allocation information for all resources in resource group's schemata applies.

Since this implementation makes "plza" a per-resource property it makes possible scenarios where some resources support plza while others do not. From what I can tell this is not reflected by the schemata file associated with a "plza" resource group that continues to enable user space to change allocations of all resources, whether they support plza or not.

Why was PLZA determined to be a per-resource property? It instead seems to have larger scope? The cycle introduced in patch #9 where the arch sets a per-'resctrl fs' resource property and then forces resctrl fs to query the arch for its own property seems unnecessary. Could this support just be a global property that resctrl fs can query from the arch?

Quoted 29 lines
fs/resctrl/rdtgroup.c +29 -0
+	struct rdtgroup *rdtgrp, *prgrp;
+	int cpu, ret = 0;
+	bool enable;
+
+	ret = kstrtobool(buf, &enable);
+	if (ret)
+		return ret;
+
+	rdtgrp = rdtgroup_kn_lock_live(of->kn);
+	if (!rdtgrp) {
+		rdtgroup_kn_unlock(of->kn);
+		return -ENOENT;
+	}
+
+	rdt_last_cmd_clear();
+
+	if (!r->plza_capable) {
+		rdt_last_cmd_puts("PLZA is not supported in the system\n");
+		ret = -EINVAL;
+		goto unlock;
+	}
+
+	if (rdtgrp == &rdtgroup_default) {
+		rdt_last_cmd_puts("Cannot set PLZA on a default group\n");
+		ret = -EINVAL;
+		goto unlock;
+	}
+
+	if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) {

fs/resctrl/rdtgroup.c static int rdtgroup_plza_show(struct kernfs_open_file *of, · line 941

Quoted 10 lines
fs/resctrl/rdtgroup.c +10 -0
+		rdt_last_cmd_puts("Resource group is pseudo-locked\n");
+		ret = -EINVAL;
+		goto unlock;
+	}
+
+	if (!list_empty(&rdtgrp->mon.crdtgrp_list)) {
+		rdt_last_cmd_puts("Cannot change CTRL_MON group with sub monitor groups\n");
+		ret = -EINVAL;
+		goto unlock;
+	}

From what I can tell it is still possible to add monitor groups after a CTRL_MON group is designated "plza".

If repurposing a CTRL_MON group to operate with different constraints we should take care how user can still continue to interact with existing files/directories as a group transitions between plza and non-plza. One option could be to hide files as needed to prevent user from interacting with them, another option needs to add extra checks on all the paths that interact with these files and directories.

Reinette

#107 lore raw

Re: [RFC PATCH 16/19] fs/resctrl: Implement rdtgroup_plza_write() to configure PLZA in a group

Hi Reinette,

Quoted 14 lines · Reinette Chatre

Hi Babu,

fs/resctrl/rdtgroup.c static int rdtgroup_plza_show(struct kernfs_open_file *of, · line 902

Quoted 4 lines · Babu Moger
fs/resctrl/rdtgroup.c +4 -0
+static ssize_t rdtgroup_plza_write(struct kernfs_open_file *of, char *buf,
+				   size_t nbytes, loff_t off)
+{
+	struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);

Hardcoding PLZA configuration to the L3 resource is unexpected, especially since PLZA's impact and configuration on MBA is mentioned a couple of times in this series and discussions that followed. There also does not seem to be any "per resource" PLZA capability but instead when system supports PLZA RDT_RESOURCE_L2, RDT_RESOURCE_L3, and RDT_RESOURCE_MBA are automatically (if resources are present) set to support it.

Yes. That is correct. If system supports PLZA, it applies to all the resources.

Quoted 6 lines
Quoted 2 lines

From what I understand PLZA enables user space to configure CLOSID and RMID

used in CPL=0 independent from resource. That is, when a user configures PLZA with this interface all allocation information for all resources in resource group's schemata applies.

Quoted 7 lines

Since this implementation makes "plza" a per-resource property it makes possible scenarios where some resources support plza while others do not. From what I can tell this is not reflected by the schemata file associated with a "plza" resource group that continues to enable user space to change allocations of all resources, whether they support plza or not.

Why was PLZA determined to be a per-resource property? It instead seems to

There is no specific reason. Seemed easy to access the property. Will change it.

Quoted 4 lines

have larger scope? The cycle introduced in patch #9 where the arch sets a per-'resctrl fs' resource property and then forces resctrl fs to query the arch for its own property seems unnecessary. Could this support just be a global property that resctrl fs can query from the arch?

Yes. That seems like a better approach.

Quoted 41 lines
Quoted 40 lines
fs/resctrl/rdtgroup.c +39 -0
+	struct rdtgroup *rdtgrp, *prgrp;
+	int cpu, ret = 0;
+	bool enable;
+
+	ret = kstrtobool(buf, &enable);
+	if (ret)
+		return ret;
+
+	rdtgrp = rdtgroup_kn_lock_live(of->kn);
+	if (!rdtgrp) {
+		rdtgroup_kn_unlock(of->kn);
+		return -ENOENT;
+	}
+
+	rdt_last_cmd_clear();
+
+	if (!r->plza_capable) {
+		rdt_last_cmd_puts("PLZA is not supported in the system\n");
+		ret = -EINVAL;
+		goto unlock;
+	}
+
+	if (rdtgrp == &rdtgroup_default) {
+		rdt_last_cmd_puts("Cannot set PLZA on a default group\n");
+		ret = -EINVAL;
+		goto unlock;
+	}
+
+	if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) {
+		rdt_last_cmd_puts("Resource group is pseudo-locked\n");
+		ret = -EINVAL;
+		goto unlock;
+	}
+
+	if (!list_empty(&rdtgrp->mon.crdtgrp_list)) {
+		rdt_last_cmd_puts("Cannot change CTRL_MON group with sub monitor groups\n");
+		ret = -EINVAL;
+		goto unlock;
+	}
Quoted 3 lines
Quoted 1 line

From what I can tell it is still possible to add monitor groups after a

CTRL_MON group is designated "plza".

Good point. I missed it.

Quoted 5 lines

If repurposing a CTRL_MON group to operate with different constraints we should take care how user can still continue to interact with existing files/directories as a group transitions between plza and non-plza. One option could be to hide files as needed to prevent user from interacting with them, another option needs to add extra checks on all the paths that interact with these files and directories.

Yes. Adding extra checks seemed good idea. Will do.

Thanks
Babu

author reviewer
#108 lore raw

RFC PATCH 17/19 fs/resctrl: Update PLZA configuration when cpu_mask changes

In reply to Babu Moger

When PLZA is active for a resctrl group, per-CPU PLZA state must track CPU mask changes.

Introduce cpus_ctrl_plza_write() to update PLZA on CPUs entering or leaving the group.

---
 fs/resctrl/rdtgroup.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
fs/resctrl/rdtgroup.c +30 -1
index 042ae7d63aea..bea017f9bd40 100644
@@ -508,6 +508,33 @@ static int cpus_ctrl_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask,
 	return 0;
 }
 
+static int cpus_ctrl_plza_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask,
+				cpumask_var_t tmpmask)
+{
+	int cpu;
+
+	/* Check if the cpus are dropped from the group */
+	cpumask_andnot(tmpmask, &rdtgrp->cpu_mask, newmask);
+	if (!cpumask_empty(tmpmask)) {
+		for_each_cpu(cpu, tmpmask)
+			resctrl_arch_set_cpu_plza(cpu, rdtgrp->closid,
+						  rdtgrp->mon.rmid, false);
+	}
+
+	/* If the CPUs are added then enable PLZA on the added CPUs. */
+	cpumask_andnot(tmpmask, newmask, &rdtgrp->cpu_mask);
+	if (!cpumask_empty(tmpmask)) {
+		for_each_cpu(cpu, tmpmask)
+			resctrl_arch_set_cpu_plza(cpu, rdtgrp->closid,
+						  rdtgrp->mon.rmid, true);
+	}
+
+	/* Update the group with new mask */
+	cpumask_copy(&rdtgrp->cpu_mask, newmask);
+
+	return 0;
+}
+
 static ssize_t rdtgroup_cpus_write(struct kernfs_open_file *of,
 				   char *buf, size_t nbytes, loff_t off)
 {
@@ -563,7 +590,9 @@ static ssize_t rdtgroup_cpus_write(struct kernfs_open_file *of,
 		goto unlock;
 	}
 
-	if (rdtgrp->type == RDTCTRL_GROUP)
+	if (rdtgrp->plza)
+		ret = cpus_ctrl_plza_write(rdtgrp, newmask, tmpmask);
+	else if (rdtgrp->type == RDTCTRL_GROUP)
 		ret = cpus_ctrl_write(rdtgrp, newmask, tmpmask, tmpmask1);
 	else if (rdtgrp->type == RDTMON_GROUP)
 		ret = cpus_mon_write(rdtgrp, newmask, tmpmask);
Signature · 1 line
2.34.1
author reviewer
#109 lore raw

RFC PATCH 18/19 x86/resctrl: Refactor show_rdt_tasks() to support PLZA task matching

In reply to Babu Moger

Refactor show_rdt_tasks() to use a new rdt_task_match() helper that checks t->plza when PLZA is enabled for a group, falling back to CLOSID/RMID matching otherwise. This ensures correct task display for PLZA-enabled groups.

---
 fs/resctrl/rdtgroup.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
fs/resctrl/rdtgroup.c +15 -5
index bea017f9bd40..a116daa53f17 100644
@@ -845,6 +845,15 @@ static ssize_t rdtgroup_tasks_write(struct kernfs_open_file *of,
 	return ret ?: nbytes;
 }
 
+static inline bool rdt_task_match(struct task_struct *t,
+				  struct rdtgroup *r, bool plza)
+{
+	if (plza)
+		return t->plza;
+
+	return is_closid_match(t, r) || is_rmid_match(t, r);
+}
+
 static void show_rdt_tasks(struct rdtgroup *r, struct seq_file *s)
 {
 	struct task_struct *p, *t;
@@ -852,11 +861,12 @@ static void show_rdt_tasks(struct rdtgroup *r, struct seq_file *s)
 
 	rcu_read_lock();
 	for_each_process_thread(p, t) {
-		if (is_closid_match(t, r) || is_rmid_match(t, r)) {
-			pid = task_pid_vnr(t);
-			if (pid)
-				seq_printf(s, "%d\n", pid);
-		}
+		if (!rdt_task_match(t, r, r->plza))
+			continue;
+
+		pid = task_pid_vnr(t);
+		if (pid)
+			seq_printf(s, "%d\n", pid);
 	}
 	rcu_read_unlock();
 }
Signature · 1 line
2.34.1
author reviewer
#110 lore raw

RFC PATCH 19/19 fs/resctrl: Add per-task PLZA enable support via rdtgroup

In reply to Babu Moger

Introduce support for enabling PLZA on a per-task basis through the resctrl control-group interface.

Add an architecture helper to set the PLZA state in the task structure and extend the rdtgroup task handling path to apply PLZA when associating a task with a control group. PLZA can only be enabled for control groups; attempts to enable it for monitoring groups are rejected.

Proper memory ordering is enforced to ensure that task closid and rmid updates are visible before determining whether the task is currently running. If the task is active on a CPU, the relevant MSRs are updated immediately; otherwise, PLZA state is programmed on the next context switch.

---
 arch/x86/include/asm/resctrl.h |  5 +++
 fs/resctrl/rdtgroup.c          | 69 +++++++++++++++++++++++++++++++++-
 2 files changed, 73 insertions(+), 1 deletion(-)
arch/x86/include/asm/resctrl.h +5 -0
index 89b38948be1a..2c11787c5253 100644
@@ -200,6 +200,11 @@ static inline void resctrl_arch_set_cpu_plza(int cpu, u32 closid, u32 rmid, u32
 	WRITE_ONCE(per_cpu(pqr_state.plza_rmid, cpu), rmid);
 }
 
+static inline void resctrl_arch_set_task_plza(struct task_struct *tsk, u32 enable)
+{
+	WRITE_ONCE(tsk->plza, enable);
+}
+
 static inline void resctrl_arch_sched_in(struct task_struct *tsk)
 {
 	if (static_branch_likely(&rdt_enable_key))
fs/resctrl/rdtgroup.c +68 -1

105 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#111 lore raw
In reply to Babu Moger
Quoted 9 lines · Babu Moger

Privilege Level Zero Association (PLZA)

Privilege Level Zero Association (PLZA) allows the hardware to automatically associate execution in Privilege Level Zero (CPL=0) with a specific COS (Class of Service) and/or RMID (Resource Monitoring Identifier). The QoS feature set already has a mechanism to associate execution on each logical processor with an RMID or COS. PLZA allows the system to override this per-thread association for a thread that is executing with CPL=0.

Adding Drew, and prodding Dave & James, for this discussion.

At LPC it was stated that both ARM and RISC-V already have support to run kernel code with different quality of service parameters from user code.

I'm thinking that Babu's implementation for resctrl may be over engineered. Specifically the part that allows users to put some tasks into the PLZA group, while leaving others in a mode where kernel code runs with same QoS parameters as user code.

That comes at a cost of complexity, and performance in the context switch code.

But maybe I'm missing some practical case where users want that behaviour.

-Tony

maintainer
#112 lore raw

Adding Ben

Quoted 29 lines · Tony
Quoted 9 lines · Babu Moger

Privilege Level Zero Association (PLZA)

Privilege Level Zero Association (PLZA) allows the hardware to automatically associate execution in Privilege Level Zero (CPL=0) with a specific COS (Class of Service) and/or RMID (Resource Monitoring Identifier). The QoS feature set already has a mechanism to associate execution on each logical processor with an RMID or COS. PLZA allows the system to override this per-thread association for a thread that is executing with CPL=0.

Adding Drew, and prodding Dave & James, for this discussion.

At LPC it was stated that both ARM and RISC-V already have support to run kernel code with different quality of service parameters from user code.

I'm thinking that Babu's implementation for resctrl may be over engineered. Specifically the part that allows users to put some tasks into the PLZA group, while leaving others in a mode where kernel code runs with same QoS parameters as user code.

That comes at a cost of complexity, and performance in the context switch code.

But maybe I'm missing some practical case where users want that behaviour.

-Tony

#113 lore raw
Quoted 19 lines · Reinette Chatre

Adding Ben

Quoted 16 lines · Tony
Quoted 9 lines · Babu Moger

Privilege Level Zero Association (PLZA)

Privilege Level Zero Association (PLZA) allows the hardware to automatically associate execution in Privilege Level Zero (CPL=0) with a specific COS (Class of Service) and/or RMID (Resource Monitoring Identifier). The QoS feature set already has a mechanism to associate execution on each logical processor with an RMID or COS. PLZA allows the system to override this per-thread association for a thread that is executing with CPL=0.

Adding Drew, and prodding Dave & James, for this discussion.

At LPC it was stated that both ARM and RISC-V already have support to run kernel code with different quality of service parameters from user code.

Sorry, for RISC-V, I should clarify that there is no hardware feature that changes the QoS identifier value when switching between kernel mode and user mode. This could be done in the kernel task switching code, but there is no implicit hardware operation.

Thanks,
Drew