]> www.infradead.org Git - users/jedix/linux-maple.git/commit
blk-throttle: Add an additional overflow check to the call calculate_bytes/io_allowed
authorZizhi Wo <wozizhi@huawei.com>
Thu, 17 Apr 2025 13:20:54 +0000 (21:20 +0800)
committerJens Axboe <axboe@kernel.dk>
Tue, 6 May 2025 01:08:34 +0000 (19:08 -0600)
commit18b8144a1bd8be5a88cc438c0c9213bae1be1a9d
tree57b366492aa44d49468fd25414db18db1effdbfd
parent7b89d46051ab310096994303b969768c4a9eb18f
blk-throttle: Add an additional overflow check to the call calculate_bytes/io_allowed

Now the tg->[bytes/io]_disp type is signed, and calculate_bytes/io_allowed
return type is unsigned. Even if the bps/iops limit is not set to max, the
return value of the function may still exceed INT_MAX or LLONG_MAX, which
can cause overflow in outer variables. In such cases, we can add additional
checks accordingly.

And in throtl_trim_slice(), if the BPS/IOPS limit is set to max, there's
no need to call calculate_bytes/io_allowed(). Introduces the helper
functions throtl_trim_bps/iops to simplifies the process. For cases when
the calculated trim value exceeds INT_MAX (causing an overflow), we reset
tg->[bytes/io]_disp to zero, so return original tg->[bytes/io]_disp because
it is the size that is actually trimmed.

Signed-off-by: Zizhi Wo <wozizhi@huawei.com>
Reviewed-by: Yu Kuai <yukuai3@huawei.com>
Link: https://lore.kernel.org/r/20250417132054.2866409-4-wozizhi@huaweicloud.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-throttle.c