Skip to content

Commit 57e420c

Browse files
nathanchanceaxboe
authored andcommitted
blk-iocost: Avoid using clamp() on inuse in __propagate_weights()
After a recent change to clamp() and its variants [1] that increases the coverage of the check that high is greater than low because it can be done through inlining, certain build configurations (such as s390 defconfig) fail to build with clang with: block/blk-iocost.c:1101:11: error: call to '__compiletime_assert_557' declared with 'error' attribute: clamp() low limit 1 greater than high limit active 1101 | inuse = clamp_t(u32, inuse, 1, active); | ^ include/linux/minmax.h:218:36: note: expanded from macro 'clamp_t' 218 | #define clamp_t(type, val, lo, hi) __careful_clamp(type, val, lo, hi) | ^ include/linux/minmax.h:195:2: note: expanded from macro '__careful_clamp' 195 | __clamp_once(type, val, lo, hi, __UNIQUE_ID(v_), __UNIQUE_ID(l_), __UNIQUE_ID(h_)) | ^ include/linux/minmax.h:188:2: note: expanded from macro '__clamp_once' 188 | BUILD_BUG_ON_MSG(statically_true(ulo > uhi), \ | ^ __propagate_weights() is called with an active value of zero in ioc_check_iocgs(), which results in the high value being less than the low value, which is undefined because the value returned depends on the order of the comparisons. The purpose of this expression is to ensure inuse is not more than active and at least 1. This could be written more simply with a ternary expression that uses min(inuse, active) as the condition so that the value of that condition can be used if it is not zero and one if it is. Do this conversion to resolve the error and add a comment to deter people from turning this back into clamp(). Fixes: 7caa471 ("blkcg: implement blk-iocost") Link: https://lore.kernel.org/r/[email protected]/ [1] Suggested-by: David Laight <[email protected]> Reported-by: Linux Kernel Functional Testing <[email protected]> Closes: https://lore.kernel.org/llvm/CA+G9fYsD7mw13wredcZn0L-KBA3yeoVSTuxnss-AEWMN3ha0cA@mail.gmail.com/ Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Signed-off-by: Nathan Chancellor <[email protected]> Acked-by: Tejun Heo <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 2f4873f commit 57e420c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

block/blk-iocost.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,14 @@ static void __propagate_weights(struct ioc_gq *iocg, u32 active, u32 inuse,
10981098
inuse = DIV64_U64_ROUND_UP(active * iocg->child_inuse_sum,
10991099
iocg->child_active_sum);
11001100
} else {
1101-
inuse = clamp_t(u32, inuse, 1, active);
1101+
/*
1102+
* It may be tempting to turn this into a clamp expression with
1103+
* a lower limit of 1 but active may be 0, which cannot be used
1104+
* as an upper limit in that situation. This expression allows
1105+
* active to clamp inuse unless it is 0, in which case inuse
1106+
* becomes 1.
1107+
*/
1108+
inuse = min(inuse, active) ?: 1;
11021109
}
11031110

11041111
iocg->last_inuse = iocg->inuse;

0 commit comments

Comments
 (0)