x86/intel_rdt.c: Disable preempt for intel_rdt_sched_in() in move_myself()
PATCH 1/1 x86/intel_rdt.c: Disable preempt for intel_rdt_sched_in() in move_myself()
From: Fenghua Yu <[email protected]>
intel_rdt_sched_in() calls this_cpu_ptr() read and write pqr_state and update PQR_ASSOC on current cpu. If execution of the function is preempted and switched to another CPU, the results are wrong. If CONFIG_DEBUG_PREEMPT is turned on, the issue is reported as "BUG: smp_processor_id() running in preemptible code." when moving a task to a rdtgroup in move_myself().
Disable preempt before intel_rdt_sched_in() and eanble preempt after the function in move_myself() to solve the issue.
--- arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/include/asm/intel_rdt.h +3 -0
@@ -192,6 +192,9 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of,* resctrl file system. * - Caches the per cpu CLOSid values and does the MSR write only * when a task with a different CLOSid is scheduled in. +* - Caller needs to disable preempt before calling this function. +* The function doesn't check preemptible. Scheduler hot path +* disables preempt already. */ static inline void intel_rdt_sched_in (void ) {
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c +2 -0
@@ -326,8 +326,10 @@ static void move_myself(struct callback_head *head)kfree (rdtgrp); } +get_cpu ();/* update PQR_ASSOC MSR to make resource group go into effect */ intel_rdt_sched_in (); +put_cpu ();kfree (callback); }
Quoted 1 line · Fenghua Yu
From: Fenghua Yu <[email protected]>
Subject: x86/intel_rdt.c: Disable preempt for intel_rdt_sched_in() in move_myself()
- The prefix is crap. git log arch/x86/kernel/cpu/intel_rdt.c should tell you what's the proper prefix is.
It's preemption not preempt and this wants to be a proper sentence:
x86/intel_rdt: Call intel_rdt_sched_in() with preemption disabled
Quoted 6 lines
intel_rdt_sched_in()callsthis_cpu_ptr()read and writepqr_stateand updatePQR_ASSOCon current cpu. If execution of the function is preempted and switched to another CPU, the results are wrong. IfCONFIG_DEBUG_PREEMPTis turned on, the issue is reported as "BUG:smp_processor_id()running in preemptible code." when moving a task to a rdtgroup inmove_myself().
When will you finally start to describe problems proper instead of telling fairy tales about how you debugged the symptoms?
intel_rdt_sched_in() must be called with preemption disabled because the function accesses percpu variables (pqr_state and closid).
If a task moves itself via move_myself() preemption is enabled, which violates the calling convention and can result in incorrect closid selection when the task gets preempted or migrated.
Add the required protection and a comment about the calling convention.
That's concise and precise.
Quoted 1 line
Disable preempt before
intel_rdt_sched_in()and eanble preempt after
s/preempt/preemtion/
s/eanble/enable/
Oh well.
Quoted 1 line
the function in
move_myself()to solve the issue.
And next time you write: Add one before foo() and subtract one after the function ....
Changelogs need to tell the WHY and not the WHAT. We can see the WHAT from looking at the patch.
Quoted 10 lines
Signed-off-by Fenghua Yu <[email protected]>--- arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 2 ++ 1 file changed, 2 insertions(+)arch/x86/include/asm/intel_rdt.h +0
-0
arch/x86/include/asm/intel_rdt.h int rdtgroup_schemata_show(struct kernfs_open_file *of, · line 195
Quoted 4 lines
arch/x86/include/asm/intel_rdt.h +1
-0@@ -192,6 +192,9 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of,* resctrl file system. * - Caches the per cpu CLOSid values and does the MSR write only * when a task with a different CLOSid is scheduled in. +* - Caller needs to disable preempt before calling this function.
s/preempt/preemtion/
* - Must be called with preemption disabled.
arch/x86/include/asm/intel_rdt.h int rdtgroup_schemata_show(struct kernfs_open_file *of, · line 197
Quoted 2 lines
arch/x86/include/asm/intel_rdt.h +2
-0+* The function doesn't check preemptible. Scheduler hot path +* disables preempt already.
This part makes no sense whatsoever. -ENOPARSE
The important information is the calling convention, i.e.:
* - Must be called with preemption disabled.
and that's enough.
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c static void move_myself(struct callback_head *head) · line 329
Quoted 12 lines
arch/x86/include/asm/intel_rdt.h +0
-0*/ static inline void intel_rdt_sched_in (void ) {arch/x86/kernel/cpu/intel_rdt_rdtgroup.c +1
-0@@ -326,8 +326,10 @@ static void move_myself(struct callback_head *head)kfree (rdtgrp); } +get_cpu ();
Bah! What's wrong with preempt_disable()?
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c static void move_myself(struct callback_head *head) · line 335
Quoted 6 lines
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c +1
-0/* update PQR_ASSOC MSR to make resource group go into effect */ intel_rdt_sched_in (); +put_cpu ();kfree (callback); }
Thanks,
tglx