]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
5.15-stable patches
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 15 Jan 2023 14:31:47 +0000 (15:31 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 15 Jan 2023 14:31:47 +0000 (15:31 +0100)
added patches:
edac-device-fix-period-calculation-in-edac_device_reset_delay_period.patch
x86-resctrl-fix-task-closid-rmid-update-race.patch

queue-5.15/edac-device-fix-period-calculation-in-edac_device_reset_delay_period.patch [new file with mode: 0644]
queue-5.15/series
queue-5.15/x86-resctrl-fix-task-closid-rmid-update-race.patch [new file with mode: 0644]

diff --git a/queue-5.15/edac-device-fix-period-calculation-in-edac_device_reset_delay_period.patch b/queue-5.15/edac-device-fix-period-calculation-in-edac_device_reset_delay_period.patch
new file mode 100644 (file)
index 0000000..d11a7f7
--- /dev/null
@@ -0,0 +1,65 @@
+From e84077437902ec99eba0a6b516df772653f142c7 Mon Sep 17 00:00:00 2001
+From: Eliav Farber <farbere@amazon.com>
+Date: Thu, 20 Oct 2022 12:44:58 +0000
+Subject: EDAC/device: Fix period calculation in edac_device_reset_delay_period()
+
+From: Eliav Farber <farbere@amazon.com>
+
+commit e84077437902ec99eba0a6b516df772653f142c7 upstream.
+
+Fix period calculation in case user sets a value of 1000.  The input of
+round_jiffies_relative() should be in jiffies and not in milli-seconds.
+
+  [ bp: Use the same code pattern as in edac_device_workq_setup() for
+    clarity. ]
+
+Fixes: c4cf3b454eca ("EDAC: Rework workqueue handling")
+Signed-off-by: Eliav Farber <farbere@amazon.com>
+Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
+Cc: <stable@kernel.org>
+Link: https://lore.kernel.org/r/20221020124458.22153-1-farbere@amazon.com
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/edac/edac_device.c |   17 ++++++++---------
+ drivers/edac/edac_module.h |    2 +-
+ 2 files changed, 9 insertions(+), 10 deletions(-)
+
+--- a/drivers/edac/edac_device.c
++++ b/drivers/edac/edac_device.c
+@@ -424,17 +424,16 @@ static void edac_device_workq_teardown(s
+  *    Then restart the workq on the new delay
+  */
+ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
+-                                      unsigned long value)
++                                  unsigned long msec)
+ {
+-      unsigned long jiffs = msecs_to_jiffies(value);
++      edac_dev->poll_msec = msec;
++      edac_dev->delay     = msecs_to_jiffies(msec);
+-      if (value == 1000)
+-              jiffs = round_jiffies_relative(value);
+-
+-      edac_dev->poll_msec = value;
+-      edac_dev->delay     = jiffs;
+-
+-      edac_mod_work(&edac_dev->work, jiffs);
++      /* See comment in edac_device_workq_setup() above */
++      if (edac_dev->poll_msec == 1000)
++              edac_mod_work(&edac_dev->work, round_jiffies_relative(edac_dev->delay));
++      else
++              edac_mod_work(&edac_dev->work, edac_dev->delay);
+ }
+ int edac_device_alloc_index(void)
+--- a/drivers/edac/edac_module.h
++++ b/drivers/edac/edac_module.h
+@@ -56,7 +56,7 @@ bool edac_stop_work(struct delayed_work
+ bool edac_mod_work(struct delayed_work *work, unsigned long delay);
+ extern void edac_device_reset_delay_period(struct edac_device_ctl_info
+-                                         *edac_dev, unsigned long value);
++                                         *edac_dev, unsigned long msec);
+ extern void edac_mc_reset_delay_period(unsigned long value);
+ extern void *edac_align_ptr(void **p, unsigned size, int n_elems);
index ae76c157916fc11ec4d718cb4fd8e5dc9db56e7e..8c81065c4f0b95ae7bcefd6ec0584d6ed8c64104 100644 (file)
@@ -40,3 +40,5 @@ sched-core-fix-use-after-free-bug-in-dup_user_cpus_ptr.patch
 netfilter-ipset-fix-overflow-before-widen-in-the-bitmap_ip_create-function.patch
 powerpc-imc-pmu-fix-use-of-mutex-in-irqs-disabled-section.patch
 x86-boot-avoid-using-intel-mnemonics-in-at-t-syntax-asm.patch
+edac-device-fix-period-calculation-in-edac_device_reset_delay_period.patch
+x86-resctrl-fix-task-closid-rmid-update-race.patch
diff --git a/queue-5.15/x86-resctrl-fix-task-closid-rmid-update-race.patch b/queue-5.15/x86-resctrl-fix-task-closid-rmid-update-race.patch
new file mode 100644 (file)
index 0000000..47a8b73
--- /dev/null
@@ -0,0 +1,109 @@
+From fe1f0714385fbcf76b0cbceb02b7277d842014fc Mon Sep 17 00:00:00 2001
+From: Peter Newman <peternewman@google.com>
+Date: Tue, 20 Dec 2022 17:11:23 +0100
+Subject: x86/resctrl: Fix task CLOSID/RMID update race
+
+From: Peter Newman <peternewman@google.com>
+
+commit fe1f0714385fbcf76b0cbceb02b7277d842014fc upstream.
+
+When the user moves a running task to a new rdtgroup using the task's
+file interface or by deleting its rdtgroup, the resulting change in
+CLOSID/RMID must be immediately propagated to the PQR_ASSOC MSR on the
+task(s) CPUs.
+
+x86 allows reordering loads with prior stores, so if the task starts
+running between a task_curr() check that the CPU hoisted before the
+stores in the CLOSID/RMID update then it can start running with the old
+CLOSID/RMID until it is switched again because __rdtgroup_move_task()
+failed to determine that it needs to be interrupted to obtain the new
+CLOSID/RMID.
+
+Refer to the diagram below:
+
+CPU 0                                   CPU 1
+-----                                   -----
+__rdtgroup_move_task():
+  curr <- t1->cpu->rq->curr
+                                        __schedule():
+                                          rq->curr <- t1
+                                        resctrl_sched_in():
+                                          t1->{closid,rmid} -> {1,1}
+  t1->{closid,rmid} <- {2,2}
+  if (curr == t1) // false
+   IPI(t1->cpu)
+
+A similar race impacts rdt_move_group_tasks(), which updates tasks in a
+deleted rdtgroup.
+
+In both cases, use smp_mb() to order the task_struct::{closid,rmid}
+stores before the loads in task_curr().  In particular, in the
+rdt_move_group_tasks() case, simply execute an smp_mb() on every
+iteration with a matching task.
+
+It is possible to use a single smp_mb() in rdt_move_group_tasks(), but
+this would require two passes and a means of remembering which
+task_structs were updated in the first loop. However, benchmarking
+results below showed too little performance impact in the simple
+approach to justify implementing the two-pass approach.
+
+Times below were collected using `perf stat` to measure the time to
+remove a group containing a 1600-task, parallel workload.
+
+CPU: Intel(R) Xeon(R) Platinum P-8136 CPU @ 2.00GHz (112 threads)
+
+  # mkdir /sys/fs/resctrl/test
+  # echo $$ > /sys/fs/resctrl/test/tasks
+  # perf bench sched messaging -g 40 -l 100000
+
+task-clock time ranges collected using:
+
+  # perf stat rmdir /sys/fs/resctrl/test
+
+Baseline:                     1.54 - 1.60 ms
+smp_mb() every matching task: 1.57 - 1.67 ms
+
+  [ bp: Massage commit message. ]
+
+Fixes: ae28d1aae48a ("x86/resctrl: Use an IPI instead of task_work_add() to update PQR_ASSOC MSR")
+Fixes: 0efc89be9471 ("x86/intel_rdt: Update task closid immediately on CPU in rmdir and unmount")
+Signed-off-by: Peter Newman <peternewman@google.com>
+Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
+Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
+Reviewed-by: Babu Moger <babu.moger@amd.com>
+Cc: <stable@kernel.org>
+Link: https://lore.kernel.org/r/20221220161123.432120-1-peternewman@google.com
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ arch/x86/kernel/cpu/resctrl/rdtgroup.c |   12 +++++++++++-
+ 1 file changed, 11 insertions(+), 1 deletion(-)
+
+--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
++++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+@@ -580,8 +580,10 @@ static int __rdtgroup_move_task(struct t
+       /*
+        * Ensure the task's closid and rmid are written before determining if
+        * the task is current that will decide if it will be interrupted.
++       * This pairs with the full barrier between the rq->curr update and
++       * resctrl_sched_in() during context switch.
+        */
+-      barrier();
++      smp_mb();
+       /*
+        * By now, the task's closid and rmid are set. If the task is current
+@@ -2364,6 +2366,14 @@ static void rdt_move_group_tasks(struct
+                       WRITE_ONCE(t->rmid, to->mon.rmid);
+                       /*
++                       * Order the closid/rmid stores above before the loads
++                       * in task_curr(). This pairs with the full barrier
++                       * between the rq->curr update and resctrl_sched_in()
++                       * during context switch.
++                       */
++                      smp_mb();
++
++                      /*
+                        * If the task is on a CPU, set the CPU in the mask.
+                        * The detection is inaccurate as tasks might move or
+                        * schedule before the smp function call takes place.