]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
5.10-stable patches
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 11 Aug 2024 15:59:52 +0000 (17:59 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 11 Aug 2024 15:59:52 +0000 (17:59 +0200)
added patches:
sched-cputime-fix-mul_u64_u64_div_u64-precision-for-cputime.patch

queue-5.10/sched-cputime-fix-mul_u64_u64_div_u64-precision-for-cputime.patch [new file with mode: 0644]
queue-5.10/series

diff --git a/queue-5.10/sched-cputime-fix-mul_u64_u64_div_u64-precision-for-cputime.patch b/queue-5.10/sched-cputime-fix-mul_u64_u64_div_u64-precision-for-cputime.patch
new file mode 100644 (file)
index 0000000..7c23bd8
--- /dev/null
@@ -0,0 +1,58 @@
+From 77baa5bafcbe1b2a15ef9c37232c21279c95481c Mon Sep 17 00:00:00 2001
+From: Zheng Zucheng <zhengzucheng@huawei.com>
+Date: Fri, 26 Jul 2024 02:32:35 +0000
+Subject: sched/cputime: Fix mul_u64_u64_div_u64() precision for cputime
+
+From: Zheng Zucheng <zhengzucheng@huawei.com>
+
+commit 77baa5bafcbe1b2a15ef9c37232c21279c95481c upstream.
+
+In extreme test scenarios:
+the 14th field utime in /proc/xx/stat is greater than sum_exec_runtime,
+utime = 18446744073709518790 ns, rtime = 135989749728000 ns
+
+In cputime_adjust() process, stime is greater than rtime due to
+mul_u64_u64_div_u64() precision problem.
+before call mul_u64_u64_div_u64(),
+stime = 175136586720000, rtime = 135989749728000, utime = 1416780000.
+after call mul_u64_u64_div_u64(),
+stime = 135989949653530
+
+unsigned reversion occurs because rtime is less than stime.
+utime = rtime - stime = 135989749728000 - 135989949653530
+                     = -199925530
+                     = (u64)18446744073709518790
+
+Trigger condition:
+  1). User task run in kernel mode most of time
+  2). ARM64 architecture
+  3). TICK_CPU_ACCOUNTING=y
+      CONFIG_VIRT_CPU_ACCOUNTING_NATIVE is not set
+
+Fix mul_u64_u64_div_u64() conversion precision by reset stime to rtime
+
+Fixes: 3dc167ba5729 ("sched/cputime: Improve cputime_adjust()")
+Signed-off-by: Zheng Zucheng <zhengzucheng@huawei.com>
+Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
+Cc: <stable@vger.kernel.org>
+Link: https://lkml.kernel.org/r/20240726023235.217771-1-zhengzucheng@huawei.com
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ kernel/sched/cputime.c |    6 ++++++
+ 1 file changed, 6 insertions(+)
+
+--- a/kernel/sched/cputime.c
++++ b/kernel/sched/cputime.c
+@@ -579,6 +579,12 @@ void cputime_adjust(struct task_cputime
+       }
+       stime = mul_u64_u64_div_u64(stime, rtime, stime + utime);
++      /*
++       * Because mul_u64_u64_div_u64() can approximate on some
++       * achitectures; enforce the constraint that: a*b/(b+c) <= a.
++       */
++      if (unlikely(stime > rtime))
++              stime = rtime;
+ update:
+       /*
index f54adfd17b2291c1aa4648f836ebb0a704d12b1a..89df40339aedec2703f3e83160fee601a4d0a737 100644 (file)
@@ -288,3 +288,4 @@ media-uvcvideo-fix-the-bandwdith-quirk-on-usb-3.x.patch
 jbd2-avoid-memleak-in-jbd2_journal_write_metadata_bu.patch
 s390-sclp-prevent-release-of-buffer-in-i-o.patch
 sunrpc-fix-a-race-to-wake-a-sync-task.patch
+sched-cputime-fix-mul_u64_u64_div_u64-precision-for-cputime.patch