FAILED: patch "[PATCH] mm/page-writeback: avoid 32-bit overflow in dirty threshold shares" failed to apply to 6.6-stable tree
Subsystems (3)
Sasha Levin
maintainerThe patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 9597c2056e05bd79df9d343a9b42e84a54de1c52
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 9597c2056e05bd79df9d343a9b42e84a54de1c52 Mon Sep 17 00:00:00 2001
From: Hungyu Lin <[email protected]>
Date: Wed, 21 Oct 2026 06:06:54 +0000
Subject: [PATCH] mm/page-writeback: avoid 32-bit overflow in dirty threshold
shares
The ratios used by __wb_calc_thresh() are scaled to parts per million, but the threshold and ratio operands are unsigned long. On 32-bit kernels, their multiplication can wrap before the result is assigned to u64.
For example, with a threshold of 25600 pages and the default maximum ratio of 1000000, wb_max_thresh becomes 4125 pages instead of 25600. The shared threshold and minimum share calculations can overflow in the same way, producing incorrect per-writeback dirty limits.
Use a u64 threshold for the three ratio multiplications and div_u64() to retain the existing division order and rounding.
--- mm/page-writeback.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
mm/page-writeback.c +5 -3
@@ -883,6 +883,7 @@ static unsigned long __wb_calc_thresh(struct dirty_throttle_control *dtc, {struct wb_domain *dom =dtc_dom (dtc);struct bdi_writeback *wb = dtc->wb; +u64 threshold = thresh;u64 wb_thresh;u64 wb_max_thresh;unsigned long numerator, denominator;
@@ -894,13 +895,14 @@ static unsigned long __wb_calc_thresh(struct dirty_throttle_control *dtc,fprop_fraction_percpu (&dom->completions, dtc->wb_completions, &numerator, &denominator); - wb_thresh = (thresh * (100 *BDI_RATIO_SCALE - bdi_min_ratio)) / (100 *BDI_RATIO_SCALE ); + wb_thresh =div_u64 (threshold * (100 *BDI_RATIO_SCALE - bdi_min_ratio), +100 *BDI_RATIO_SCALE ); wb_thresh *= numerator; wb_thresh =div64_ul (wb_thresh, denominator);wb_min_max_ratio (wb, &wb_min_ratio, &wb_max_ratio); - wb_thresh += (thresh * wb_min_ratio) / (100 *BDI_RATIO_SCALE ); + wb_thresh +=div_u64 (threshold * wb_min_ratio,100 *BDI_RATIO_SCALE );/* * It's very possible that wb_thresh is close to 0 not because the
@@ -916,7 +918,7 @@ static unsigned long __wb_calc_thresh(struct dirty_throttle_control *dtc, wb_thresh =max (wb_thresh, (thresh - dtc->dirty) /8 ); } - wb_max_thresh = thresh * wb_max_ratio / (100 *BDI_RATIO_SCALE ); + wb_max_thresh =div_u64 (threshold * wb_max_ratio,100 *BDI_RATIO_SCALE );if (wb_thresh > wb_max_thresh) wb_thresh = wb_max_thresh;
Signature · 1 line
2.53.0
PATCH 1/1 mm/page-writeback: avoid 32-bit overflow in dirty threshold shares
[ Upstream commit 9597c2056e05bd79df9d343a9b42e84a54de1c52 ]
The ratios used by __wb_calc_thresh() are scaled to parts per million, but the threshold and ratio operands are unsigned long. On 32-bit kernels, their multiplication can wrap before the result is assigned to u64.
For example, with a threshold of 25600 pages and the default maximum ratio of 1000000, wb_max_thresh becomes 4125 pages instead of 25600. The shared threshold and minimum share calculations can overflow in the same way, producing incorrect per-writeback dirty limits.
Use a u64 threshold for the three ratio multiplications and div_u64() to retain the existing division order and rounding.
In 6.6, __wb_calc_thresh() gets the threshold from dtc->thresh and has no freerun adjustment here. Widen the local threshold and compute the maximum share once for the existing clamp.
--- mm/page-writeback.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
mm/page-writeback.c +8 -5
@@ -883,8 +883,9 @@ static void mdtc_calc_avail(struct dirty_throttle_control *mdtc,static unsigned long __wb_calc_thresh (struct dirty_throttle_control *dtc) {struct wb_domain *dom =dtc_dom (dtc); -unsigned long thresh = dtc->thresh; +u64 thresh = dtc->thresh;u64 wb_thresh; +u64 wb_max_thresh;unsigned long numerator, denominator;unsigned long wb_min_ratio, wb_max_ratio;
@@ -894,15 +895,17 @@ static unsigned long __wb_calc_thresh(struct dirty_throttle_control *dtc)fprop_fraction_percpu (&dom->completions, dtc->wb_completions, &numerator, &denominator); - wb_thresh = (thresh * (100 *BDI_RATIO_SCALE - bdi_min_ratio)) / (100 *BDI_RATIO_SCALE ); + wb_thresh =div_u64 (thresh * (100 *BDI_RATIO_SCALE - bdi_min_ratio), +100 *BDI_RATIO_SCALE ); wb_thresh *= numerator; wb_thresh =div64_ul (wb_thresh, denominator);wb_min_max_ratio (dtc->wb, &wb_min_ratio, &wb_max_ratio); - wb_thresh += (thresh * wb_min_ratio) / (100 *BDI_RATIO_SCALE ); -if (wb_thresh > (thresh * wb_max_ratio) / (100 *BDI_RATIO_SCALE )) - wb_thresh = thresh * wb_max_ratio / (100 *BDI_RATIO_SCALE ); + wb_thresh +=div_u64 (thresh * wb_min_ratio,100 *BDI_RATIO_SCALE ); + wb_max_thresh =div_u64 (thresh * wb_max_ratio,100 *BDI_RATIO_SCALE ); +if (wb_thresh > wb_max_thresh) + wb_thresh = wb_max_thresh;return wb_thresh; }
Signature · 1 line
2.50.1 (Apple Git-155)