<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/git/stable/linux.git/block/badblocks.c, branch linux-6.14.y</title>
<subtitle>Linux kernel stable tree</subtitle>
<id>https://git.rulkc.org/pub/scm/linux/kernel/git/stable/linux.git/atom?h=linux-6.14.y</id>
<link rel='self' href='https://git.rulkc.org/pub/scm/linux/kernel/git/stable/linux.git/atom?h=linux-6.14.y'/>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/linux/kernel/git/stable/linux.git/'/>
<updated>2025-05-29T09:12:50+00:00</updated>
<entry>
<title>badblocks: Fix a nonsense WARN_ON() which checks whether a u64 variable &lt; 0</title>
<updated>2025-05-29T09:12:50+00:00</updated>
<author>
<name>Coly Li</name>
<email>colyli@kernel.org</email>
</author>
<published>2025-03-09T16:05:56+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=006eabaa377e2c936c4f295bba7d6ec66349286d'/>
<id>urn:sha1:006eabaa377e2c936c4f295bba7d6ec66349286d</id>
<content type='text'>
[ Upstream commit 7e76336e14de9a2b67af96012ddd46c5676cf340 ]

In _badblocks_check(), there are lines of code like this,
1246         sectors -= len;
[snipped]
1251         WARN_ON(sectors &lt; 0);

The WARN_ON() at line 1257 doesn't make sense because sectors is
unsigned long long type and never to be &lt;0.

Fix it by checking directly checking whether sectors is less than len.

Reported-by: Dan Carpenter &lt;dan.carpenter@linaro.org&gt;
Signed-off-by: Coly Li &lt;colyli@kernel.org&gt;
Reviewed-by: Yu Kuai &lt;yukuai3@huawei.com&gt;
Link: https://lore.kernel.org/r/20250309160556.42854-1-colyli@kernel.org
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>badblocks: use sector_t instead of int to avoid truncation of badblocks length</title>
<updated>2025-04-10T12:44:06+00:00</updated>
<author>
<name>Zheng Qixing</name>
<email>zhengqixing@huawei.com</email>
</author>
<published>2025-02-27T07:55:07+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=aa64194db3370b0d20d008752b354f19b0e9a65c'/>
<id>urn:sha1:aa64194db3370b0d20d008752b354f19b0e9a65c</id>
<content type='text'>
[ Upstream commit d301f164c3fbff611bd71f57dfa553b9219f0f5e ]

There is a truncation of badblocks length issue when set badblocks as
follow:

echo "2055 4294967299" &gt; bad_blocks
cat bad_blocks
2055 3

Change 'sectors' argument type from 'int' to 'sector_t'.

This change avoids truncation of badblocks length for large sectors by
replacing 'int' with 'sector_t' (u64), enabling proper handling of larger
disk sizes and ensuring compatibility with 64-bit sector addressing.

Fixes: 9e0e252a048b ("badblocks: Add core badblock management code")
Signed-off-by: Zheng Qixing &lt;zhengqixing@huawei.com&gt;
Reviewed-by: Yu Kuai &lt;yukuai3@huawei.com&gt;
Acked-by: Coly Li &lt;colyli@kernel.org&gt;
Link: https://lore.kernel.org/r/20250227075507.151331-13-zhengqixing@huaweicloud.com
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>badblocks: return boolean from badblocks_set() and badblocks_clear()</title>
<updated>2025-04-10T12:44:06+00:00</updated>
<author>
<name>Zheng Qixing</name>
<email>zhengqixing@huawei.com</email>
</author>
<published>2025-02-27T07:55:05+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=6ac9e65d930552563942bc4e97e8bb7d20ef5903'/>
<id>urn:sha1:6ac9e65d930552563942bc4e97e8bb7d20ef5903</id>
<content type='text'>
[ Upstream commit c8775aefba959cdfbaa25408a84d3dd15bbeb991 ]

Change the return type of badblocks_set() and badblocks_clear()
from int to bool, indicating success or failure. Specifically:

- _badblocks_set() and _badblocks_clear() functions now return
true for success and false for failure.
- All calls to these functions are updated to handle the new
boolean return type.
- This change improves code clarity and ensures a more consistent
handling of success and failure states.

Signed-off-by: Zheng Qixing &lt;zhengqixing@huawei.com&gt;
Reviewed-by: Yu Kuai &lt;yukuai3@huawei.com&gt;
Acked-by: Coly Li &lt;colyli@kernel.org&gt;
Acked-by: Ira Weiny &lt;ira.weiny@intel.com&gt;
Link: https://lore.kernel.org/r/20250227075507.151331-11-zhengqixing@huaweicloud.com
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
Stable-dep-of: d301f164c3fb ("badblocks: use sector_t instead of int to avoid truncation of badblocks length")
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>badblocks: fix missing bad blocks on retry in _badblocks_check()</title>
<updated>2025-04-10T12:44:06+00:00</updated>
<author>
<name>Zheng Qixing</name>
<email>zhengqixing@huawei.com</email>
</author>
<published>2025-02-27T07:55:04+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=dd2c2c13c03c25166fc6caa85c27dcf10fe79280'/>
<id>urn:sha1:dd2c2c13c03c25166fc6caa85c27dcf10fe79280</id>
<content type='text'>
[ Upstream commit 5236f041fa6c81c71eabad44897e54a0d6d5bbf6 ]

The bad blocks check would miss bad blocks when retrying under contention,
as checking parameters are not reset. These stale values from the previous
attempt could lead to incorrect scanning in the subsequent retry.

Move seqlock to outer function and reinitialize checking state for each
retry. This ensures a clean state for each check attempt, preventing any
missed bad blocks.

Fixes: 3ea3354cb9f0 ("badblocks: improve badblocks_check() for multiple ranges handling")
Signed-off-by: Zheng Qixing &lt;zhengqixing@huawei.com&gt;
Reviewed-by: Yu Kuai &lt;yukuai3@huawei.com&gt;
Acked-by: Coly Li &lt;colyli@kernel.org&gt;
Link: https://lore.kernel.org/r/20250227075507.151331-10-zhengqixing@huaweicloud.com
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>badblocks: fix merge issue when new badblocks align with pre+1</title>
<updated>2025-04-10T12:44:06+00:00</updated>
<author>
<name>Li Nan</name>
<email>linan122@huawei.com</email>
</author>
<published>2025-02-27T07:55:03+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=c58df052cf56edf3cd7a01536017cd6b31498aed'/>
<id>urn:sha1:c58df052cf56edf3cd7a01536017cd6b31498aed</id>
<content type='text'>
[ Upstream commit 9ec65dec634a752ab0a1203510ee190356e4cf1a ]

There is a merge issue when adding badblocks as follow:
  echo 0 10 &gt; bad_blocks
  echo 30 10 &gt; bad_blocks
  echo 20 10 &gt; bad_blocks
  cat bad_blocks
  0 10
  20 10    //should be merged with (30 10)
  30 10

In this case, if new badblocks does not intersect with prev, it is added
by insert_at(). If there is an intersection with prev+1, the merge will
be processed in the next re_insert loop.

However, when the end of the new badblocks is exactly equal to the offset
of prev+1, no further re_insert loop occurs, and the two badblocks are not
merge.

Fix it by inc prev, badblocks can be merged during the subsequent code.

Fixes: aa511ff8218b ("badblocks: switch to the improved badblock handling code")
Signed-off-by: Li Nan &lt;linan122@huawei.com&gt;
Reviewed-by: Yu Kuai &lt;yukuai3@huawei.com&gt;
Link: https://lore.kernel.org/r/20250227075507.151331-9-zhengqixing@huaweicloud.com
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>badblocks: fix the using of MAX_BADBLOCKS</title>
<updated>2025-04-10T12:44:06+00:00</updated>
<author>
<name>Li Nan</name>
<email>linan122@huawei.com</email>
</author>
<published>2025-02-27T07:55:01+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=a517d3dac67c735d8644ac2ee6c2c5a6f1f60a10'/>
<id>urn:sha1:a517d3dac67c735d8644ac2ee6c2c5a6f1f60a10</id>
<content type='text'>
[ Upstream commit 37446680dfbfbba7cbedd680047182f70a0b857b ]

The number of badblocks cannot exceed MAX_BADBLOCKS, but it should be
allowed to equal MAX_BADBLOCKS.

Fixes: aa511ff8218b ("badblocks: switch to the improved badblock handling code")
Fixes: c3c6a86e9efc ("badblocks: add helper routines for badblock ranges handling")
Signed-off-by: Li Nan &lt;linan122@huawei.com&gt;
Reviewed-by: Zhu Yanjun &lt;yanjun.zhu@linux.dev&gt;
Reviewed-by: Yu Kuai &lt;yukuai3@huawei.com&gt;
Acked-by: Coly Li &lt;colyli@kernel.org&gt;
Link: https://lore.kernel.org/r/20250227075507.151331-7-zhengqixing@huaweicloud.com
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>badblocks: return error if any badblock set fails</title>
<updated>2025-04-10T12:44:06+00:00</updated>
<author>
<name>Li Nan</name>
<email>linan122@huawei.com</email>
</author>
<published>2025-02-27T07:55:00+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=8e5785cba5420dad67d3c0ad04431acdd3902439'/>
<id>urn:sha1:8e5785cba5420dad67d3c0ad04431acdd3902439</id>
<content type='text'>
[ Upstream commit 7f500f0a59b1d7345a05ec4ae703babf34b7e470 ]

_badblocks_set() returns success if at least one badblock is set
successfully, even if others fail. This can lead to data inconsistencies
in raid, where a failed badblock set should trigger the disk to be kicked
out to prevent future reads from failed write areas.

_badblocks_set() should return error if any badblock set fails. Instead
of relying on 'rv', directly returning 'sectors' for clearer logic. If all
badblocks are successfully set, 'sectors' will be 0, otherwise it
indicates the number of badblocks that have not been set yet, thus
signaling failure.

By the way, it can also fix an issue: when a newly set unack badblock is
included in an existing ack badblock, the setting will return an error.
···
  echo "0 100" /sys/block/md0/md/dev-loop1/bad_blocks
  echo "0 100" /sys/block/md0/md/dev-loop1/unacknowledged_bad_blocks
  -bash: echo: write error: No space left on device
```
After fix, it will return success.

Fixes: aa511ff8218b ("badblocks: switch to the improved badblock handling code")
Signed-off-by: Li Nan &lt;linan122@huawei.com&gt;
Reviewed-by: Yu Kuai &lt;yukuai3@huawei.com&gt;
Acked-by: Coly Li &lt;colyli@kernel.org&gt;
Link: https://lore.kernel.org/r/20250227075507.151331-6-zhengqixing@huaweicloud.com
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>badblocks: return error directly when setting badblocks exceeds 512</title>
<updated>2025-04-10T12:44:06+00:00</updated>
<author>
<name>Li Nan</name>
<email>linan122@huawei.com</email>
</author>
<published>2025-02-27T07:54:59+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=a87d76deebf87b36ef541c91fc73f43815870d0b'/>
<id>urn:sha1:a87d76deebf87b36ef541c91fc73f43815870d0b</id>
<content type='text'>
[ Upstream commit 28243dcd1f49cc8be398a1396d16a45527882ce5 ]

In the current handling of badblocks settings, a lot of processing has
been done for scenarios where the number of badblocks exceeds 512.
This makes the code look quite complex and also introduces some issues,

For example, if there is 512 badblocks already:
  for((i=0; i&lt;510; i++)); do ((sector=i*2)); echo "$sector 1" &gt; bad_blocks; done
  echo 2100 10 &gt; bad_blocks
  echo 2200 10 &gt; bad_blocks
Set new one, exceed 512:
  echo 2000 500 &gt; bad_blocks
Expected:
  2000 500
Actual:
  2100 400

In fact, a disk shouldn't have too many badblocks, and for disks with
512 badblocks, attempting to set more bad blocks doesn't make much sense.
At that point, the more appropriate action would be to replace the disk.
Therefore, to resolve these issues and simplify the code somewhat, return
error directly when setting badblocks exceeds 512.

Fixes: aa511ff8218b ("badblocks: switch to the improved badblock handling code")
Signed-off-by: Li Nan &lt;linan122@huawei.com&gt;
Reviewed-by: Yu Kuai &lt;yukuai3@huawei.com&gt;
Link: https://lore.kernel.org/r/20250227075507.151331-5-zhengqixing@huaweicloud.com
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>badblocks: attempt to merge adjacent badblocks during ack_all_badblocks</title>
<updated>2025-04-10T12:44:06+00:00</updated>
<author>
<name>Li Nan</name>
<email>linan122@huawei.com</email>
</author>
<published>2025-02-27T07:54:58+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=4048fdec7ae21c5518aa6e05b5e82b6da2f4b603'/>
<id>urn:sha1:4048fdec7ae21c5518aa6e05b5e82b6da2f4b603</id>
<content type='text'>
[ Upstream commit 32e9ad4d11f69949ff331e35a417871ee0d31d99 ]

If ack and unack badblocks are adjacent, they will not be merged and will
remain as two separate badblocks. Even after the bad blocks are written
to disk and both become ack, they will still remain as two independent
bad blocks. This is not ideal as it wastes the limited space for
badblocks. Therefore, during ack_all_badblocks(), attempt to merge
badblocks if they are adjacent.

Fixes: aa511ff8218b ("badblocks: switch to the improved badblock handling code")
Signed-off-by: Li Nan &lt;linan122@huawei.com&gt;
Reviewed-by: Yu Kuai &lt;yukuai3@huawei.com&gt;
Acked-by: Coly Li &lt;colyli@kernel.org&gt;
Link: https://lore.kernel.org/r/20250227075507.151331-4-zhengqixing@huaweicloud.com
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>badblocks: factor out a helper try_adjacent_combine</title>
<updated>2025-04-10T12:44:06+00:00</updated>
<author>
<name>Li Nan</name>
<email>linan122@huawei.com</email>
</author>
<published>2025-02-27T07:54:57+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=ebd06a54fd717cedf4f482c2368a46eb41a59418'/>
<id>urn:sha1:ebd06a54fd717cedf4f482c2368a46eb41a59418</id>
<content type='text'>
[ Upstream commit 270b68fee9688428e0a98d4a2c3e6d4c434a84ba ]

Factor out try_adjacent_combine(), and it will be used in the later patch.

Signed-off-by: Li Nan &lt;linan122@huawei.com&gt;
Reviewed-by: Yu Kuai &lt;yukuai3@huawei.com&gt;
Link: https://lore.kernel.org/r/20250227075507.151331-3-zhengqixing@huaweicloud.com
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
Stable-dep-of: 32e9ad4d11f6 ("badblocks: attempt to merge adjacent badblocks during ack_all_badblocks")
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
</feed>
