linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/resctrl: Take care of PF_EXITING task in callback
@ 2020-01-08 16:13 Xiaochen Shen
  2020-01-13 13:14 ` [tip: x86/cache] x86/resctrl: Do not reconfigure exiting tasks tip-bot2 for Xiaochen Shen
  0 siblings, 1 reply; 2+ messages in thread
From: Xiaochen Shen @ 2020-01-08 16:13 UTC (permalink / raw)
  To: tglx, mingo, bp, hpa, tony.luck, fenghua.yu, reinette.chatre
  Cc: x86, linux-kernel, pei.p.jia, xiaochen.shen

When writing a pid to file "tasks", a callback function move_myself()
is queued to this task to be called when the task returns from kernel
mode or exits. The purpose of move_myself() is to activate the newly
assigned closid and/or rmid associated with this task. This activation
is done by calling resctrl_sched_in() from move_myself(), the same
function that is called when switching to this task.

If this work is successfully queued but then the task enters PF_EXITING
status (e.g., receiving signal SIGKILL, SIGTERM) prior to the execution
of the callback move_myself() then move_myself() still calls
resctrl_sched_in() since the task status is not currently considered.

When a task is exiting then the data structure of the task itself will
be freed soon, calling resctrl_sched_in() to write the register that
control's the task's resources is unnecessary and it implies extra
performance overhead.

Add check on task status in move_myself() and return immediately if the
task is PF_EXITING.

Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 2e3b06d6bbc6..205925d802d8 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -532,11 +532,15 @@ static void move_myself(struct callback_head *head)
 		kfree(rdtgrp);
 	}
 
+	if (unlikely(current->flags & PF_EXITING))
+		goto out;
+
 	preempt_disable();
 	/* update PQR_ASSOC MSR to make resource group go into effect */
 	resctrl_sched_in();
 	preempt_enable();
 
+out:
 	kfree(callback);
 }
 
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [tip: x86/cache] x86/resctrl: Do not reconfigure exiting tasks
  2020-01-08 16:13 [PATCH] x86/resctrl: Take care of PF_EXITING task in callback Xiaochen Shen
@ 2020-01-13 13:14 ` tip-bot2 for Xiaochen Shen
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot2 for Xiaochen Shen @ 2020-01-13 13:14 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Xiaochen Shen, Borislav Petkov, Reinette Chatre, x86, LKML

The following commit has been merged into the x86/cache branch of tip:

Commit-ID:     dc433797c6f639e46824585bbf943578f13d54bf
Gitweb:        https://git.kernel.org/tip/dc433797c6f639e46824585bbf943578f13d54bf
Author:        Xiaochen Shen <xiaochen.shen@intel.com>
AuthorDate:    Thu, 09 Jan 2020 00:13:46 +08:00
Committer:     Borislav Petkov <bp@suse.de>
CommitterDate: Mon, 13 Jan 2020 14:10:21 +01:00

x86/resctrl: Do not reconfigure exiting tasks

When writing a pid to file "tasks", a callback function move_myself() is
queued to this task to be called when the task returns from kernel mode
or exits. The purpose of move_myself() is to activate the newly assigned
closid and/or rmid associated with this task. This activation is done by
calling resctrl_sched_in() from move_myself(), the same function that is
called when switching to this task.

If this work is successfully queued but then the task enters PF_EXITING
status (e.g., receiving signal SIGKILL, SIGTERM) prior to the
execution of the callback move_myself(), move_myself() still calls
resctrl_sched_in() since the task status is not currently considered.

When a task is exiting, the data structure of the task itself will
be freed soon. Calling resctrl_sched_in() to write the register that
controls the task's resources is unnecessary and it implies extra
performance overhead.

Add check on task status in move_myself() and return immediately if the
task is PF_EXITING.

 [ bp: Massage. ]

Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Link: https://lkml.kernel.org/r/1578500026-21152-1-git-send-email-xiaochen.shen@intel.com
---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 2e3b06d..205925d 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -532,11 +532,15 @@ static void move_myself(struct callback_head *head)
 		kfree(rdtgrp);
 	}
 
+	if (unlikely(current->flags & PF_EXITING))
+		goto out;
+
 	preempt_disable();
 	/* update PQR_ASSOC MSR to make resource group go into effect */
 	resctrl_sched_in();
 	preempt_enable();
 
+out:
 	kfree(callback);
 }
 

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-01-13 13:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-08 16:13 [PATCH] x86/resctrl: Take care of PF_EXITING task in callback Xiaochen Shen
2020-01-13 13:14 ` [tip: x86/cache] x86/resctrl: Do not reconfigure exiting tasks tip-bot2 for Xiaochen Shen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).