Re: [PATCH 4/4] iommu/arm-smmu-v3: Remove cmpxchg() in arm_smmu_cmdq_issue_cmdlist()

From: John Garry
Date: Fri Jun 26 2020 - 06:06:50 EST


On 23/06/2020 14:55, Rikard Falkeborn wrote:
Den tis 23 juni 2020 12:21John Garry <john.garry@xxxxxxxxxx <mailto:john.garry@xxxxxxxxxx>> skrev:

On 23/06/2020 10:35, Rikard Falkeborn wrote:
>
>Â Â ÂI'd say that GENMASK_INPUT_CHECK() should be able to handle a
l=0 and
>Â Â Âh=unsigned value, so I doubt this warn.
>
>Â Â ÂUsing GENMASK((int)cmdq->q.llq.max_n_shift, 0) resolves it,
but it
>Â Â Âlooks
>Â Â Âlike GENMASK_INPUT_CHECK() could be improved.
>
>
> Indeed it could, it is fixed in -next.

ok, thanks for the pointer, but I still see this on today's -next with
this patch:

make W=1 drivers/iommu/arm-smmu-v3.o


Oh, ok thanks for reporting. I guess different gcc versions have different behaviour. I guess we'll have to change the comparison to (!((h) == (l) || (h) > (l))) instead (not sure I got all parenthesis and logic correct but you get the idea).


Yeah, so this looks to fix it:

--- a/include/linux/bits.h
+++ b/include/linux/bits.h
@@ -23,7 +23,8 @@
#include <linux/build_bug.h>
#define GENMASK_INPUT_CHECK(h, l) \
(BUILD_BUG_ON_ZERO(__builtin_choose_expr( \
- __builtin_constant_p((l) > (h)), (l) > (h), 0)))
+ __builtin_constant_p(!((h) == (l) ||(h) > (l))), !((h) == (l) ||(h) > (l)), 0)))
+

We may be able to just use (h) == (l) as the const expr to make it more concise, but that may be confusing.

I only tested with my toolchain based on 7.5.0

Thanks,
John