[PATCH v2 11/16] bitfield: Common up validation of the mask parameter

david.laight.linux@gmail.com posted 16 patches 1 day, 11 hours ago
[PATCH v2 11/16] bitfield: Common up validation of the mask parameter
Posted by david.laight.linux@gmail.com 1 day, 11 hours ago
From: David Laight <david.laight.linux@gmail.com>

There are three places where the mask is checked for being non-zero
and contiguous.
Add a simple expression that checks it and use in all three places.

Signed-off-by: David Laight <david.laight.linux@gmail.com>
---
 include/linux/bitfield.h | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h
index 138f4c14786d..6f454ef43d24 100644
--- a/include/linux/bitfield.h
+++ b/include/linux/bitfield.h
@@ -45,13 +45,15 @@
 
 #define __bf_shf(x) (__builtin_ffsll(x) - 1)
 
+#define __BF_VALIDATE_MASK(mask) \
+	(!(mask) || ((mask) & ((mask) + ((mask) & -(mask)))))
+
 #define __BF_FIELD_CHECK_MASK(_mask, _pfx)				\
 	do {								\
 		BUILD_BUG_ON_MSG(!__builtin_constant_p(_mask),		\
 				 _pfx "mask is not constant");		\
-		BUILD_BUG_ON_MSG((_mask) == 0, _pfx "mask is zero");	\
-		__BUILD_BUG_ON_NOT_POWER_OF_2((_mask) +			\
-					      (1ULL << __bf_shf(_mask))); \
+		BUILD_BUG_ON_MSG(__BF_VALIDATE_MASK(_mask),		\
+				 _pfx "mask is zero or not contiguous");	\
 	} while (0)
 
 #define __BF_FIELD_CHECK_VAL(mask, val, pfx)			\
@@ -122,8 +124,6 @@
 		__BF_FIELD_PREP(_mask, _val, "FIELD_PREP: ");		\
 	})
 
-#define __BF_CHECK_POW2(n)	BUILD_BUG_ON_ZERO(((n) & ((n) - 1)) != 0)
-
 /**
  * FIELD_PREP_CONST() - prepare a constant bitfield element
  * @_mask: shifted mask defining the field's length and position
@@ -138,12 +138,10 @@
  */
 #define FIELD_PREP_CONST(_mask, _val)					\
 	(								\
-		/* mask must be non-zero */				\
-		BUILD_BUG_ON_ZERO((_mask) == 0) +			\
+		/* mask must be non-zero and contiguous */		\
+		BUILD_BUG_ON_ZERO(__BF_VALIDATE_MASK(_mask)) +		\
 		/* check if value fits */				\
 		BUILD_BUG_ON_ZERO(~((_mask) >> __bf_shf(_mask)) & (_val)) + \
-		/* check if mask is contiguous */			\
-		__BF_CHECK_POW2((_mask) + (1ULL << __bf_shf(_mask))) +	\
 		/* and create the value */				\
 		(((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask))	\
 	)
@@ -189,7 +187,7 @@ extern void __compiletime_error("bad bitfield mask")
 __bad_mask(void);
 static __always_inline u64 field_multiplier(u64 field)
 {
-	if ((field | (field - 1)) & ((field | (field - 1)) + 1))
+	if (__BF_VALIDATE_MASK(field))
 		__bad_mask();
 	return field & -field;
 }
-- 
2.39.5
Re: [PATCH v2 11/16] bitfield: Common up validation of the mask parameter
Posted by kernel test robot 22 minutes ago
Hi,

kernel test robot noticed the following build errors:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.19-rc1 next-20251212]
[cannot apply to westeri-thunderbolt/next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/david-laight-linux-gmail-com/nfp-Call-FIELD_PREP-in-NFP_ETH_SET_BIT_CONFIG-wrapper/20251213-040625
base:   linus/master
patch link:    https://lore.kernel.org/r/20251212193721.740055-12-david.laight.linux%40gmail.com
patch subject: [PATCH v2 11/16] bitfield: Common up validation of the mask parameter
config: i386-randconfig-053-20251213 (https://download.01.org/0day-ci/archive/20251214/202512141305.J3aPiiBv-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251214/202512141305.J3aPiiBv-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202512141305.J3aPiiBv-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/gpu/drm/xe/xe_guc.c:639:19: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
     639 |                 klvs[count++] = PREP_GUC_KLV_TAG(OPT_IN_FEATURE_EXT_CAT_ERR_TYPE);
         |                                 ^
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:62:2: note: expanded from macro 'PREP_GUC_KLV_TAG'
      62 |         PREP_GUC_KLV_CONST(MAKE_GUC_KLV_KEY(TAG), MAKE_GUC_KLV_LEN(TAG))
         |         ^
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:38:20: note: expanded from macro 'PREP_GUC_KLV_CONST'
      38 |         (FIELD_PREP_CONST(GUC_KLV_0_KEY, (key)) | \
         |                           ^
   drivers/gpu/drm/xe/abi/guc_klvs_abi.h:36:35: note: expanded from macro 'GUC_KLV_0_KEY'
      36 | #define GUC_KLV_0_KEY                           (0xffffu << 16)
         |                                                          ^
>> drivers/gpu/drm/xe/xe_guc.c:639:19: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:62:2: note: expanded from macro 'PREP_GUC_KLV_TAG'
      62 |         PREP_GUC_KLV_CONST(MAKE_GUC_KLV_KEY(TAG), MAKE_GUC_KLV_LEN(TAG))
         |         ^
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:39:20: note: expanded from macro 'PREP_GUC_KLV_CONST'
      39 |          FIELD_PREP_CONST(GUC_KLV_0_LEN, (len)))
         |                           ^
   drivers/gpu/drm/xe/abi/guc_klvs_abi.h:37:35: note: expanded from macro 'GUC_KLV_0_LEN'
      37 | #define GUC_KLV_0_LEN                           (0xffffu << 0)
         |                                                          ^
   drivers/gpu/drm/xe/xe_guc.c:642:19: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
     642 |                 klvs[count++] = PREP_GUC_KLV_TAG(OPT_IN_FEATURE_DYNAMIC_INHIBIT_CONTEXT_SWITCH);
         |                                 ^
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:62:2: note: expanded from macro 'PREP_GUC_KLV_TAG'
      62 |         PREP_GUC_KLV_CONST(MAKE_GUC_KLV_KEY(TAG), MAKE_GUC_KLV_LEN(TAG))
         |         ^
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:38:20: note: expanded from macro 'PREP_GUC_KLV_CONST'
      38 |         (FIELD_PREP_CONST(GUC_KLV_0_KEY, (key)) | \
         |                           ^
   drivers/gpu/drm/xe/abi/guc_klvs_abi.h:36:35: note: expanded from macro 'GUC_KLV_0_KEY'
      36 | #define GUC_KLV_0_KEY                           (0xffffu << 16)
         |                                                          ^
   drivers/gpu/drm/xe/xe_guc.c:642:19: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:62:2: note: expanded from macro 'PREP_GUC_KLV_TAG'
      62 |         PREP_GUC_KLV_CONST(MAKE_GUC_KLV_KEY(TAG), MAKE_GUC_KLV_LEN(TAG))
         |         ^
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:39:20: note: expanded from macro 'PREP_GUC_KLV_CONST'
      39 |          FIELD_PREP_CONST(GUC_KLV_0_LEN, (len)))
         |                           ^
   drivers/gpu/drm/xe/abi/guc_klvs_abi.h:37:35: note: expanded from macro 'GUC_KLV_0_LEN'
      37 | #define GUC_KLV_0_LEN                           (0xffffu << 0)
         |                                                          ^
   4 errors generated.
--
>> drivers/gpu/drm/xe/xe_guc_submit.c:371:12: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
     371 |         *emit++ = PREP_GUC_KLV_TAG(SCHEDULING_POLICIES_RENDER_COMPUTE_YIELD);
         |                   ^
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:62:2: note: expanded from macro 'PREP_GUC_KLV_TAG'
      62 |         PREP_GUC_KLV_CONST(MAKE_GUC_KLV_KEY(TAG), MAKE_GUC_KLV_LEN(TAG))
         |         ^
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:38:20: note: expanded from macro 'PREP_GUC_KLV_CONST'
      38 |         (FIELD_PREP_CONST(GUC_KLV_0_KEY, (key)) | \
         |                           ^
   drivers/gpu/drm/xe/abi/guc_klvs_abi.h:36:35: note: expanded from macro 'GUC_KLV_0_KEY'
      36 | #define GUC_KLV_0_KEY                           (0xffffu << 16)
         |                                                          ^
>> drivers/gpu/drm/xe/xe_guc_submit.c:371:12: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:62:2: note: expanded from macro 'PREP_GUC_KLV_TAG'
      62 |         PREP_GUC_KLV_CONST(MAKE_GUC_KLV_KEY(TAG), MAKE_GUC_KLV_LEN(TAG))
         |         ^
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:39:20: note: expanded from macro 'PREP_GUC_KLV_CONST'
      39 |          FIELD_PREP_CONST(GUC_KLV_0_LEN, (len)))
         |                           ^
   drivers/gpu/drm/xe/abi/guc_klvs_abi.h:37:35: note: expanded from macro 'GUC_KLV_0_LEN'
      37 | #define GUC_KLV_0_LEN                           (0xffffu << 0)
         |                                                          ^
   2 errors generated.
--
>> drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c:163:3: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
     163 |                 PREP_GUC_KLV_TAG(VF_CFG_GGTT_START),
         |                 ^
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:62:2: note: expanded from macro 'PREP_GUC_KLV_TAG'
      62 |         PREP_GUC_KLV_CONST(MAKE_GUC_KLV_KEY(TAG), MAKE_GUC_KLV_LEN(TAG))
         |         ^
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:38:20: note: expanded from macro 'PREP_GUC_KLV_CONST'
      38 |         (FIELD_PREP_CONST(GUC_KLV_0_KEY, (key)) | \
         |                           ^
   drivers/gpu/drm/xe/abi/guc_klvs_abi.h:36:35: note: expanded from macro 'GUC_KLV_0_KEY'
      36 | #define GUC_KLV_0_KEY                           (0xffffu << 16)
         |                                                          ^
>> drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c:163:3: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:62:2: note: expanded from macro 'PREP_GUC_KLV_TAG'
      62 |         PREP_GUC_KLV_CONST(MAKE_GUC_KLV_KEY(TAG), MAKE_GUC_KLV_LEN(TAG))
         |         ^
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:39:20: note: expanded from macro 'PREP_GUC_KLV_CONST'
      39 |          FIELD_PREP_CONST(GUC_KLV_0_LEN, (len)))
         |                           ^
   drivers/gpu/drm/xe/abi/guc_klvs_abi.h:37:35: note: expanded from macro 'GUC_KLV_0_LEN'
      37 | #define GUC_KLV_0_LEN                           (0xffffu << 0)
         |                                                          ^
   drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c:166:3: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
     166 |                 PREP_GUC_KLV_TAG(VF_CFG_GGTT_SIZE),
         |                 ^
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:62:2: note: expanded from macro 'PREP_GUC_KLV_TAG'
      62 |         PREP_GUC_KLV_CONST(MAKE_GUC_KLV_KEY(TAG), MAKE_GUC_KLV_LEN(TAG))
         |         ^
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:38:20: note: expanded from macro 'PREP_GUC_KLV_CONST'
      38 |         (FIELD_PREP_CONST(GUC_KLV_0_KEY, (key)) | \
         |                           ^
   drivers/gpu/drm/xe/abi/guc_klvs_abi.h:36:35: note: expanded from macro 'GUC_KLV_0_KEY'
      36 | #define GUC_KLV_0_KEY                           (0xffffu << 16)
         |                                                          ^
   drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c:166:3: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:62:2: note: expanded from macro 'PREP_GUC_KLV_TAG'
      62 |         PREP_GUC_KLV_CONST(MAKE_GUC_KLV_KEY(TAG), MAKE_GUC_KLV_LEN(TAG))
         |         ^
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:39:20: note: expanded from macro 'PREP_GUC_KLV_CONST'
      39 |          FIELD_PREP_CONST(GUC_KLV_0_LEN, (len)))
         |                           ^
   drivers/gpu/drm/xe/abi/guc_klvs_abi.h:37:35: note: expanded from macro 'GUC_KLV_0_LEN'
      37 | #define GUC_KLV_0_LEN                           (0xffffu << 0)
         |                                                          ^
   drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c:177:3: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
     177 |                 PREP_GUC_KLV_TAG(VF_CFG_BEGIN_CONTEXT_ID),
         |                 ^
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:62:2: note: expanded from macro 'PREP_GUC_KLV_TAG'
      62 |         PREP_GUC_KLV_CONST(MAKE_GUC_KLV_KEY(TAG), MAKE_GUC_KLV_LEN(TAG))
         |         ^
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:38:20: note: expanded from macro 'PREP_GUC_KLV_CONST'
      38 |         (FIELD_PREP_CONST(GUC_KLV_0_KEY, (key)) | \
         |                           ^
   drivers/gpu/drm/xe/abi/guc_klvs_abi.h:36:35: note: expanded from macro 'GUC_KLV_0_KEY'
      36 | #define GUC_KLV_0_KEY                           (0xffffu << 16)
         |                                                          ^
   drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c:177:3: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:62:2: note: expanded from macro 'PREP_GUC_KLV_TAG'
      62 |         PREP_GUC_KLV_CONST(MAKE_GUC_KLV_KEY(TAG), MAKE_GUC_KLV_LEN(TAG))
         |         ^
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:39:20: note: expanded from macro 'PREP_GUC_KLV_CONST'
      39 |          FIELD_PREP_CONST(GUC_KLV_0_LEN, (len)))
         |                           ^
   drivers/gpu/drm/xe/abi/guc_klvs_abi.h:37:35: note: expanded from macro 'GUC_KLV_0_LEN'
      37 | #define GUC_KLV_0_LEN                           (0xffffu << 0)
         |                                                          ^
   drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c:179:3: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
     179 |                 PREP_GUC_KLV_TAG(VF_CFG_NUM_CONTEXTS),
         |                 ^
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:62:2: note: expanded from macro 'PREP_GUC_KLV_TAG'
      62 |         PREP_GUC_KLV_CONST(MAKE_GUC_KLV_KEY(TAG), MAKE_GUC_KLV_LEN(TAG))
         |         ^
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:38:20: note: expanded from macro 'PREP_GUC_KLV_CONST'
      38 |         (FIELD_PREP_CONST(GUC_KLV_0_KEY, (key)) | \
         |                           ^
   drivers/gpu/drm/xe/abi/guc_klvs_abi.h:36:35: note: expanded from macro 'GUC_KLV_0_KEY'
      36 | #define GUC_KLV_0_KEY                           (0xffffu << 16)
         |                                                          ^
   drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c:179:3: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:62:2: note: expanded from macro 'PREP_GUC_KLV_TAG'
      62 |         PREP_GUC_KLV_CONST(MAKE_GUC_KLV_KEY(TAG), MAKE_GUC_KLV_LEN(TAG))
         |         ^
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:39:20: note: expanded from macro 'PREP_GUC_KLV_CONST'
      39 |          FIELD_PREP_CONST(GUC_KLV_0_LEN, (len)))
         |                           ^
   drivers/gpu/drm/xe/abi/guc_klvs_abi.h:37:35: note: expanded from macro 'GUC_KLV_0_LEN'
      37 | #define GUC_KLV_0_LEN                           (0xffffu << 0)
         |                                                          ^
   drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c:189:3: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
     189 |                 PREP_GUC_KLV_TAG(VF_CFG_BEGIN_DOORBELL_ID),
         |                 ^
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:62:2: note: expanded from macro 'PREP_GUC_KLV_TAG'
      62 |         PREP_GUC_KLV_CONST(MAKE_GUC_KLV_KEY(TAG), MAKE_GUC_KLV_LEN(TAG))
         |         ^
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:38:20: note: expanded from macro 'PREP_GUC_KLV_CONST'
      38 |         (FIELD_PREP_CONST(GUC_KLV_0_KEY, (key)) | \
         |                           ^
   drivers/gpu/drm/xe/abi/guc_klvs_abi.h:36:35: note: expanded from macro 'GUC_KLV_0_KEY'
      36 | #define GUC_KLV_0_KEY                           (0xffffu << 16)
         |                                                          ^
   drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c:189:3: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:62:2: note: expanded from macro 'PREP_GUC_KLV_TAG'
      62 |         PREP_GUC_KLV_CONST(MAKE_GUC_KLV_KEY(TAG), MAKE_GUC_KLV_LEN(TAG))
         |         ^
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:39:20: note: expanded from macro 'PREP_GUC_KLV_CONST'
      39 |          FIELD_PREP_CONST(GUC_KLV_0_LEN, (len)))
         |                           ^
   drivers/gpu/drm/xe/abi/guc_klvs_abi.h:37:35: note: expanded from macro 'GUC_KLV_0_LEN'
      37 | #define GUC_KLV_0_LEN                           (0xffffu << 0)
         |                                                          ^
   drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c:191:3: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
     191 |                 PREP_GUC_KLV_TAG(VF_CFG_NUM_DOORBELLS),
         |                 ^
--
>> drivers/gpu/drm/xe/xe_sriov_packet.c:381:16: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
     381 |         klvs[len++] = PREP_GUC_KLV_CONST(MIGRATION_KLV_DEVICE_DEVID_KEY,
         |                       ^
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:38:20: note: expanded from macro 'PREP_GUC_KLV_CONST'
      38 |         (FIELD_PREP_CONST(GUC_KLV_0_KEY, (key)) | \
         |                           ^
   drivers/gpu/drm/xe/abi/guc_klvs_abi.h:36:35: note: expanded from macro 'GUC_KLV_0_KEY'
      36 | #define GUC_KLV_0_KEY                           (0xffffu << 16)
         |                                                          ^
>> drivers/gpu/drm/xe/xe_sriov_packet.c:381:16: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:39:20: note: expanded from macro 'PREP_GUC_KLV_CONST'
      39 |          FIELD_PREP_CONST(GUC_KLV_0_LEN, (len)))
         |                           ^
   drivers/gpu/drm/xe/abi/guc_klvs_abi.h:37:35: note: expanded from macro 'GUC_KLV_0_LEN'
      37 | #define GUC_KLV_0_LEN                           (0xffffu << 0)
         |                                                          ^
   drivers/gpu/drm/xe/xe_sriov_packet.c:384:16: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
     384 |         klvs[len++] = PREP_GUC_KLV_CONST(MIGRATION_KLV_DEVICE_REVID_KEY,
         |                       ^
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:38:20: note: expanded from macro 'PREP_GUC_KLV_CONST'
      38 |         (FIELD_PREP_CONST(GUC_KLV_0_KEY, (key)) | \
         |                           ^
   drivers/gpu/drm/xe/abi/guc_klvs_abi.h:36:35: note: expanded from macro 'GUC_KLV_0_KEY'
      36 | #define GUC_KLV_0_KEY                           (0xffffu << 16)
         |                                                          ^
   drivers/gpu/drm/xe/xe_sriov_packet.c:384:16: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
   drivers/gpu/drm/xe/xe_guc_klv_helpers.h:39:20: note: expanded from macro 'PREP_GUC_KLV_CONST'
      39 |          FIELD_PREP_CONST(GUC_KLV_0_LEN, (len)))
         |                           ^
   drivers/gpu/drm/xe/abi/guc_klvs_abi.h:37:35: note: expanded from macro 'GUC_KLV_0_LEN'
      37 | #define GUC_KLV_0_LEN                           (0xffffu << 0)
         |                                                          ^
   4 errors generated.


vim +639 drivers/gpu/drm/xe/xe_guc.c

9c7d93a8f1ec04 Daniele Ceraolo Spurio 2025-06-25  616  
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  617  #define OPT_IN_MAX_DWORDS 16
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  618  int xe_guc_opt_in_features_enable(struct xe_guc *guc)
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  619  {
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  620  	struct xe_device *xe = guc_to_xe(guc);
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  621  	CLASS(xe_guc_buf, buf)(&guc->buf, OPT_IN_MAX_DWORDS);
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  622  	u32 count = 0;
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  623  	u32 *klvs;
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  624  	int ret;
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  625  
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  626  	if (!xe_guc_buf_is_valid(buf))
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  627  		return -ENOBUFS;
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  628  
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  629  	klvs = xe_guc_buf_cpu_ptr(buf);
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  630  
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  631  	/*
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  632  	 * The extra CAT error type opt-in was added in GuC v70.17.0, which maps
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  633  	 * to compatibility version v1.7.0.
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  634  	 * Note that the GuC allows enabling this KLV even on platforms that do
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  635  	 * not support the extra type; in such case the returned type variable
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  636  	 * will be set to a known invalid value which we can check against.
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  637  	 */
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  638  	if (GUC_SUBMIT_VER(guc) >= MAKE_GUC_VER(1, 7, 0))
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25 @639  		klvs[count++] = PREP_GUC_KLV_TAG(OPT_IN_FEATURE_EXT_CAT_ERR_TYPE);
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  640  
9c7d93a8f1ec04 Daniele Ceraolo Spurio 2025-06-25  641  	if (supports_dynamic_ics(guc))
9c7d93a8f1ec04 Daniele Ceraolo Spurio 2025-06-25  642  		klvs[count++] = PREP_GUC_KLV_TAG(OPT_IN_FEATURE_DYNAMIC_INHIBIT_CONTEXT_SWITCH);
9c7d93a8f1ec04 Daniele Ceraolo Spurio 2025-06-25  643  
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  644  	if (count) {
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  645  		xe_assert(xe, count <= OPT_IN_MAX_DWORDS);
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  646  
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  647  		ret = __guc_opt_in_features_enable(guc, xe_guc_buf_flush(buf), count);
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  648  		if (ret < 0) {
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  649  			xe_gt_err(guc_to_gt(guc),
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  650  				  "failed to enable GuC opt-in features: %pe\n",
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  651  				  ERR_PTR(ret));
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  652  			return ret;
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  653  		}
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  654  	}
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  655  
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  656  	return 0;
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  657  }
a7ffcea8631af9 Daniele Ceraolo Spurio 2025-06-25  658  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki