Hi all,
Today's linux-next merge of the kvm tree got a conflict in:
include/linux/bits.h
between commits:
b77cb9640f1f ("bits: introduce fixed-type genmasks")
34b80df456ca ("bits: Introduce fixed-type BIT")
from the drm-xe tree and commit:
3c7a8e190bc5 ("uapi: introduce uapi-friendly macros for GENMASK")
from the kvm tree.
I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging. You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.
--
Cheers,
Stephen Rothwell
diff --cc include/linux/bits.h
index 811846ce110e,0eb24d21aac2..000000000000
--- a/include/linux/bits.h
+++ b/include/linux/bits.h
@@@ -4,10 -4,9 +4,11 @@@
#include <linux/const.h>
#include <vdso/bits.h>
+ #include <uapi/linux/bits.h>
#include <asm/bitsperlong.h>
+#define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE)
+
#define BIT_MASK(nr) (UL(1) << ((nr) % BITS_PER_LONG))
#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
#define BIT_ULL_MASK(nr) (ULL(1) << ((nr) % BITS_PER_LONG_LONG))
@@@ -33,42 -29,11 +34,42 @@@
* disable the input check if that is the case.
*/
#define GENMASK_INPUT_CHECK(h, l) 0
+#define BIT_INPUT_CHECK(type, b) 0
#endif
-#define GENMASK(h, l) \
- (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
-#define GENMASK_ULL(h, l) \
- (GENMASK_INPUT_CHECK(h, l) + __GENMASK_ULL(h, l))
+/*
+ * Generate a mask for the specified type @t. Additional checks are made to
+ * guarantee the value returned fits in that type, relying on
+ * shift-count-overflow compiler check to detect incompatible arguments.
+ * For example, all these create build errors or warnings:
+ *
+ * - GENMASK(15, 20): wrong argument order
+ * - GENMASK(72, 15): doesn't fit unsigned long
+ * - GENMASK_U32(33, 15): doesn't fit in a u32
+ */
- #define __GENMASK(t, h, l) \
++#define ___GENMASK(t, h, l) \
+ (GENMASK_INPUT_CHECK(h, l) + \
+ (((t)~0ULL - ((t)(1) << (l)) + 1) & \
+ ((t)~0ULL >> (BITS_PER_TYPE(t) - 1 - (h)))))
+
- #define GENMASK(h, l) __GENMASK(unsigned long, h, l)
- #define GENMASK_ULL(h, l) __GENMASK(unsigned long long, h, l)
- #define GENMASK_U8(h, l) __GENMASK(u8, h, l)
- #define GENMASK_U16(h, l) __GENMASK(u16, h, l)
- #define GENMASK_U32(h, l) __GENMASK(u32, h, l)
- #define GENMASK_U64(h, l) __GENMASK(u64, h, l)
++#define GENMASK(h, l) ___GENMASK(unsigned long, h, l)
++#define GENMASK_ULL(h, l) ___GENMASK(unsigned long long, h, l)
++#define GENMASK_U8(h, l) ___GENMASK(u8, h, l)
++#define GENMASK_U16(h, l) ___GENMASK(u16, h, l)
++#define GENMASK_U32(h, l) ___GENMASK(u32, h, l)
++#define GENMASK_U64(h, l) ___GENMASK(u64, h, l)
+
+/*
- * Fixed-type variants of BIT(), with additional checks like __GENMASK(). The
++ * Fixed-type variants of BIT(), with additional checks like ___GENMASK() The
+ * following examples generate compiler warnings due to shift-count-overflow:
+ *
+ * - BIT_U8(8)
+ * - BIT_U32(-1)
+ * - BIT_U32(40)
+ */
+#define BIT_U8(b) ((u8)(BIT_INPUT_CHECK(u8, b) + BIT(b)))
+#define BIT_U16(b) ((u16)(BIT_INPUT_CHECK(u16, b) + BIT(b)))
+#define BIT_U32(b) ((u32)(BIT_INPUT_CHECK(u32, b) + BIT(b)))
+#define BIT_U64(b) ((u64)(BIT_INPUT_CHECK(u64, b) + BIT(b)))
#endif /* __LINUX_BITS_H */
On Thu, Feb 22, 2024 at 4:58 AM Stephen Rothwell <[email protected]> wrote:
>
> Hi all,
>
> Today's linux-next merge of the kvm tree got a conflict in:
>
> include/linux/bits.h
>
> between commits:
>
> b77cb9640f1f ("bits: introduce fixed-type genmasks")
> 34b80df456ca ("bits: Introduce fixed-type BIT")
>
> from the drm-xe tree and commit:
>
> 3c7a8e190bc5 ("uapi: introduce uapi-friendly macros for GENMASK")
>
> from the kvm tree.
>
> I fixed it up (see below) and can carry the fix as necessary. This
> is now fixed as far as linux-next is concerned, but any non trivial
> conflicts should be mentioned to your upstream maintainer when your tree
> is submitted for merging. You may also want to consider cooperating
> with the maintainer of the conflicting tree to minimise any particularly
> complex conflicts.
Lucas, Oded, Thomas,
do you have a topic branch that I can merge?
Paolo
On Thu, Feb 22, 2024 at 11:42:01AM +0100, Paolo Bonzini wrote:
>On Thu, Feb 22, 2024 at 4:58 AM Stephen Rothwell <[email protected]> wrote:
>>
>> Hi all,
>>
>> Today's linux-next merge of the kvm tree got a conflict in:
>>
>> include/linux/bits.h
>>
>> between commits:
>>
>> b77cb9640f1f ("bits: introduce fixed-type genmasks")
>> 34b80df456ca ("bits: Introduce fixed-type BIT")
>>
>> from the drm-xe tree and commit:
>>
>> 3c7a8e190bc5 ("uapi: introduce uapi-friendly macros for GENMASK")
>>
>> from the kvm tree.
>>
>> I fixed it up (see below) and can carry the fix as necessary. This
>> is now fixed as far as linux-next is concerned, but any non trivial
>> conflicts should be mentioned to your upstream maintainer when your tree
>> is submitted for merging. You may also want to consider cooperating
>> with the maintainer of the conflicting tree to minimise any particularly
>> complex conflicts.
>
>Lucas, Oded, Thomas,
>
>do you have a topic branch that I can merge?
Yury set up a new tree and the patch we had in drm-xe-next will
(eventually) go through that tree. We also had some issues with those
patches, so they are currently on the back burner. Current discussion
going on at https://lore.kernel.org/intel-xe/[email protected]/T/#mc0d83438c5b6164eabea85bb3b5eef7503dade84
I'm surprised to see 3c7a8e190bc5 ("uapi: introduce uapi-friendly macros
for GENMASK") with no acks from maintainer though. Btw, aren't you
missing some includes in include/uapi/linux/bits.h?
thanks
Lucas De Marchi
>
>Paolo
>
On 3/1/24 19:17, Lucas De Marchi wrote:
> I'm surprised to see 3c7a8e190bc5 ("uapi: introduce uapi-friendly macros
> for GENMASK") with no acks from maintainer though.
The patch sat on the list for a couple months, then I went ahead and
committed it.
The changes to include/linux/bits.h are just code movement from kernel
to uapi header (plus the uglification of BITS_PER_LONG and
BITS_PER_LONG_LONG per uapi rules) so I think that's fine.
But I'll drop an email to them to ask them if they want MAINTAINERS to
include the new file.
> Btw, aren't you missing some includes in include/uapi/linux/bits.h?
Yeah, uapi/linux/const.h is needed to use the macros in bits.h. I
didn't notice because KVM headers include it anyway and, on the
include/linux/ side, include/linux/bits.h gets it via include/linux/const.h.
Paolo