1
0
Fork 0
alistair23-linux/arch/x86/kernel/cpu
Fenghua Yu ae28d1aae4 x86/resctrl: Use an IPI instead of task_work_add() to update PQR_ASSOC MSR
Currently, when moving a task to a resource group the PQR_ASSOC MSR is
updated with the new closid and rmid in an added task callback. If the
task is running, the work is run as soon as possible. If the task is not
running, the work is executed later in the kernel exit path when the
kernel returns to the task again.

Updating the PQR_ASSOC MSR as soon as possible on the CPU a moved task
is running is the right thing to do. Queueing work for a task that is
not running is unnecessary (the PQR_ASSOC MSR is already updated when
the task is scheduled in) and causing system resource waste with the way
in which it is implemented: Work to update the PQR_ASSOC register is
queued every time the user writes a task id to the "tasks" file, even if
the task already belongs to the resource group.

This could result in multiple pending work items associated with a
single task even if they are all identical and even though only a single
update with most recent values is needed. Specifically, even if a task
is moved between different resource groups while it is sleeping then it
is only the last move that is relevant but yet a work item is queued
during each move.

This unnecessary queueing of work items could result in significant
system resource waste, especially on tasks sleeping for a long time.
For example, as demonstrated by Shakeel Butt in [1] writing the same
task id to the "tasks" file can quickly consume significant memory. The
same problem (wasted system resources) occurs when moving a task between
different resource groups.

As pointed out by Valentin Schneider in [2] there is an additional issue
with the way in which the queueing of work is done in that the task_struct
update is currently done after the work is queued, resulting in a race with
the register update possibly done before the data needed by the update is
available.

To solve these issues, update the PQR_ASSOC MSR in a synchronous way
right after the new closid and rmid are ready during the task movement,
only if the task is running. If a moved task is not running nothing
is done since the PQR_ASSOC MSR will be updated next time the task is
scheduled. This is the same way used to update the register when tasks
are moved as part of resource group removal.

[1] https://lore.kernel.org/lkml/CALvZod7E9zzHwenzf7objzGKsdBmVwTgEJ0nPgs0LUFU3SN5Pw@mail.gmail.com/
[2] https://lore.kernel.org/lkml/20201123022433.17905-1-valentin.schneider@arm.com

 [ bp: Massage commit message and drop the two update_task_closid_rmid()
   variants. ]

Fixes: e02737d5b8 ("x86/intel_rdt: Add tasks files")
Reported-by: Shakeel Butt <shakeelb@google.com>
Reported-by: Valentin Schneider <valentin.schneider@arm.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Reviewed-by: James Morse <james.morse@arm.com>
Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/17aa2fb38fc12ce7bb710106b3e7c7b45acb9e94.1608243147.git.reinette.chatre@intel.com
2021-01-08 09:03:36 +01:00
..
mce A set of updates for entry/exit handling: 2020-12-14 17:13:53 -08:00
microcode - A single cleanup removing "break" after a return statement (Tom Rix) 2020-12-14 13:13:15 -08:00
mtrr x86/mtrr: Correct the range check before performing MTRR type lookups 2021-01-06 13:01:13 +01:00
resctrl x86/resctrl: Use an IPI instead of task_work_add() to update PQR_ASSOC MSR 2021-01-08 09:03:36 +01:00
sgx x86/sgx: Return -EINVAL on a zero length buffer in sgx_ioc_enclave_add_pages() 2020-12-03 19:54:40 +01:00
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
Makefile x86/sgx: Initialize metadata for Enclave Page Cache (EPC) sections 2020-11-17 14:36:13 +01:00
acrn.c x86/acrn: Remove redundant chars from ACRN signature 2020-08-07 01:32:00 +02:00
amd.c x86/cpu/amd: Remove dead code for TSEG region remapping 2020-12-08 18:45:21 +01:00
aperfmperf.c x86/cpu: Avoid cpuinfo-induced IPIing of idle CPUs 2020-11-06 16:59:11 -08:00
bugs.c x86/speculation: Fix prctl() when spectre_v2_user={seccomp,prctl},ibpb 2020-11-25 20:17:09 +01:00
cacheinfo.c x86/CPU/AMD: Remove amd_get_nb_id() 2020-11-19 11:43:17 +01:00
centaur.c x86/cpu/centaur: Add Centaur family >=7 CPUs initialization support 2020-09-11 10:53:19 +02:00
common.c This feature enhances the current guest memory encryption support 2020-10-14 10:21:34 -07:00
cpu.h treewide: Convert macro and uses of __section(foo) to __section("foo") 2020-10-25 14:51:49 -07:00
cpuid-deps.c x86: Enumerate AVX512 FP16 CPUID feature flag 2020-12-11 19:00:58 -05:00
cyrix.c x86/cpu/cyrix: Use correct macros for Cyrix calls on Geode processors 2019-03-21 12:28:50 +01:00
feat_ctl.c x86/cpu/intel: Add a nosgx kernel parameter 2020-11-17 14:36:13 +01:00
hygon.c x86/cpu/amd: Remove dead code for TSEG region remapping 2020-12-08 18:45:21 +01:00
hypervisor.c x86/paravirt: Remove const mark from x86_hyper_xen_hvm variable 2019-07-17 08:09:59 +02:00
intel.c A set of locking fixes and updates: 2020-08-10 19:07:44 -07:00
intel_epb.c x86: intel_epb: Do not build when CONFIG_PM is unset 2019-05-30 10:58:36 +02:00
intel_pconfig.c x86/pconfig: Detect PCONFIG targets 2018-03-12 12:10:54 +01:00
match.c x86/cpu: Add a steppings field to struct x86_cpu_id 2020-04-20 12:19:21 +02:00
mkcapflags.sh x86/cpu: Print VMX flags in /proc/cpuinfo using VMX_FEATURES_* 2020-01-13 18:36:02 +01:00
mshyperv.c x86/hyperv: Enable 15-bit APIC ID if the hypervisor supports it 2020-11-04 11:10:52 +01:00
perfctr-watchdog.c x86/perf: Add hardware performance events support for Zhaoxin CPU. 2020-04-30 20:14:35 +02:00
powerflags.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
proc.c x86/cpu: Print VMX flags in /proc/cpuinfo using VMX_FEATURES_* 2020-01-13 18:36:02 +01:00
rdrand.c x86/rdrand: Sanity-check RDRAND output 2019-10-01 19:55:32 +02:00
scattered.c x86/cpu: Add VM page flush MSR availablility as a CPUID feature 2020-12-14 11:09:30 -05:00
topology.c x86/topology: Set cpu_die_id only if DIE_TYPE found 2020-11-19 11:43:25 +01:00
transmeta.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
tsx.c Merge branch 'x86-cpu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2020-01-28 12:46:42 -08:00
umc.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
umwait.c KVM: VMX: Stop context switching MSR_IA32_UMWAIT_CONTROL 2020-06-22 20:54:57 -04:00
vmware.c KVM: SVM: Add GHCB accessor functions for retrieving fields 2020-12-14 11:09:32 -05:00
zhaoxin.c x86/cpu: Reinitialize IA32_FEAT_CTL MSR on BSP during wakeup 2020-06-15 14:18:37 +02:00