From: Yu Kuai <yukuai3@xxxxxxxxxx> [ Upstream commit 2afe17794cfed5f80295b1b9facd66e6f65e5002 ] It's supposed to be COUNTER_MAX / 2, not COUNTER_MAX. Link: https://lore.kernel.org/linux-raid/20250524061320.370630-14-yukuai1@xxxxxxxxxxxxxxx Signed-off-by: Yu Kuai <yukuai3@xxxxxxxxxx> Reviewed-by: Christoph Hellwig <hch@xxxxxx> Reviewed-by: Hannes Reinecke <hare@xxxxxxx> Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx> --- Now I have a clear understanding. Let me analyze the specific code change in the commit: **YES** This commit should be backported to stable kernel trees. Here's my extensive analysis: ## Analysis of the Bug Fix ### 1. The Bug The code in `md_bitmap_new_disk_sb()` incorrectly validates `write_behind` against `COUNTER_MAX` instead of `COUNTER_MAX / 2`: ```c - if (write_behind > COUNTER_MAX) + if (write_behind > COUNTER_MAX / 2) write_behind = COUNTER_MAX / 2; ``` ### 2. Why This is a Real Bug The comment immediately above this code explicitly states: ```c /* - FIXME: write_behind for RAID1. If not specified, what - is a good choice? We choose COUNTER_MAX / 2 arbitrarily. */ ``` The intent is clearly to limit write_behind to `COUNTER_MAX / 2`, but the validation check was incorrectly comparing against `COUNTER_MAX`. This creates an inconsistency where: - Values between `COUNTER_MAX / 2` and `COUNTER_MAX` would pass the check - But then get clamped to `COUNTER_MAX / 2` anyway - This means the validation isn't serving its intended purpose ### 3. Impact on Users This bug affects: - **dm-raid users**: When creating new bitmap superblocks for RAID arrays with write-behind configured - **Data consistency**: While not causing data corruption, it creates confusion about the actual limits - **Configuration validation**: Users might set values that appear to be accepted but are silently reduced ### 4. Consistency with Other Code The fix aligns with the pattern used elsewhere: - In `dm-raid.c`: The validation correctly checks `value / 2 > COUNTER_MAX` (equivalent check for sector-based values) - The clamping value of `COUNTER_MAX / 2` is consistently used as the default throughout the codebase ### 5. Backport Criteria This commit meets the stable kernel backport criteria: - **It fixes a bug**: Incorrect validation logic that doesn't match the intended behavior - **Simple and contained**: One-line change with minimal risk - **Clear fix**: The correct value is obvious from the surrounding code and comment - **User-visible impact**: Affects configuration validation for dm-raid users ### 6. Similar Historical Commits Looking at the similar commits provided: - Commit #1 (backported): Added validation to prevent setting max_write_behind without write-mostly devices - Commit #4 (backported): Fixed missing bitmap updates with write-mostly devices Both of these were backported and dealt with correctness issues in the write-behind functionality, establishing a pattern that such fixes are considered stable-worthy. ### 7. Risk Assessment - **Low risk**: Single character change ('/' to '/ 2') - **Well-understood**: The correct limit is documented in the comment - **No ABI changes**: Just tightens an existing validation check - **Fail-safe**: Makes the validation more restrictive, not less ## Conclusion This is a clear bug fix that corrects an incorrect validation check to match the documented and intended behavior. The fix is trivial, safe, and addresses a real issue that affects dm-raid users. It should be backported to ensure consistent behavior across stable kernel versions. drivers/md/md-bitmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c index 27409d05f0532..3e4b7b14995a8 100644 --- a/drivers/md/md-bitmap.c +++ b/drivers/md/md-bitmap.c @@ -787,7 +787,7 @@ static int md_bitmap_new_disk_sb(struct bitmap *bitmap) * is a good choice? We choose COUNTER_MAX / 2 arbitrarily. */ write_behind = bitmap->mddev->bitmap_info.max_write_behind; - if (write_behind > COUNTER_MAX) + if (write_behind > COUNTER_MAX / 2) write_behind = COUNTER_MAX / 2; sb->write_behind = cpu_to_le32(write_behind); bitmap->mddev->bitmap_info.max_write_behind = write_behind; -- 2.39.5