All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/8] bits: Fixed-type GENMASK()/BIT()
@ 2025-03-05 13:00 ` Vincent Mailhol via B4 Relay
  0 siblings, 0 replies; 56+ messages in thread
From: Vincent Mailhol @ 2025-03-05 13:00 UTC (permalink / raw)
  To: Yury Norov, Lucas De Marchi, Rasmus Villemoes, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Andrew Morton
  Cc: linux-kernel, intel-gfx, dri-devel, Andi Shyti, David Laight,
	Dmitry Baryshkov, Andy Shevchenko, Vincent Mailhol, Jani Nikula

Introduce some fixed width variant of the GENMASK() and the BIT()
macros in bits.h. Note that the main goal is not to get the correct
type, but rather to enforce more checks at compile time. For example:

  GENMASK_U16(16, 0)

will raise a build bug.

This series is a continuation of:

  https://lore.kernel.org/intel-xe/20240208074521.577076-1-lucas.demarchi@intel.com

from Lucas De Marchi. Above series is one year old. I really think
that this was a good idea and I do not want this series to die. So I
am volunteering to revive it.

Meanwhile, many changes occurred in bits.h. The most significant
change is that __GENMASK() was moved to the uapi headers.

In this v4, I introduce one big change: split the definition of the
asm and non-asm GENMASK(). I think this is controversial. Especially,
Yuri commented that he did not want such split. So I initially
implemented a first draft in which both the asm and non-asm version
would rely on the same helper macro, i.e. adding this:

  #define __GENMASK_t(t, w, h, l)			\
  	(((t)~_ULL(0) - ((t)1 << (l)) + 1) &		\
  	 ((t)~_ULL(0) >> (w - 1 - (h))))
    
to uapi/bits.h. And then, the different GENMASK()s would look like
this:

  #define __GENMASK(h, l) __GENMASK_t(unsigned long, __BITS_PER_LONG, h, l)
    
and so on.
    
I implemented it, and the final result looks quite ugly. Not only do
we need to manually provide the width each time, the biggest concern
is that adding this to the uapi is asking for trouble. Who knows how
people are going to use this? And once it is in the uapi, there is
virtually no way back.

Finally, I do not think it makes sense to expose the fixed width
variants to the asm. The fixed width integers type are a C
concept. For asm, the long and long long variants seems sufficient.

And so, after implementing both, the asm and non-asm split seems way
more clean and I think this is the best compromise. Let me know what
you think :)

Changes from v3:

        - Rebase on v6.14-rc5

        - Fix a typo in GENMASK_U128() comment.

        - Split the asm and non-asm definition of 

        - Replace ~0ULL by ~ULL(0)

        - Since v3, __GENMASK() was moved to the uapi and people
          started using directly. Introduce GENMASK_t() instead.

v3: https://lore.kernel.org/intel-xe/20240208074521.577076-1-lucas.demarchi@intel.com

Changes from v2:

	- Document both in commit message and code about the strict type
	  checking and give examples how it´d break with invalid params.

v2: https://lore.kernel.org/intel-xe/20240124050205.3646390-1-lucas.demarchi@intel.com
v1: https://lore.kernel.org/intel-xe/20230509051403.2748545-1-lucas.demarchi@intel.com
--
2.43.0

---
Lucas De Marchi (3):
      bits: introduce fixed-type BIT
      drm/i915: Convert REG_GENMASK* to fixed-width GENMASK_*
      test_bits: add tests for fixed-type genmasks

Vincent Mailhol (4):
      bits: fix typo 'unsigned __init128' -> 'unsigned __int128'
      bits: split the definition of the asm and non-asm GENMASK()
      test_bits: add tests for __GENMASK() and __GENMASK_ULL()
      test_bits: add tests for fixed-type BIT

Yury Norov (1):
      bits: introduce fixed-type genmasks

 drivers/gpu/drm/i915/i915_reg_defs.h | 108 ++++-------------------------------
 include/linux/bitops.h               |   1 -
 include/linux/bits.h                 |  65 +++++++++++++++++----
 lib/test_bits.c                      |  47 +++++++++++++++
 4 files changed, 111 insertions(+), 110 deletions(-)
---
base-commit: 7eb172143d5508b4da468ed59ee857c6e5e01da6
change-id: 20250228-fixed-type-genmasks-8d1a555f34e8

Best regards,
-- 
Vincent Mailhol <mailhol.vincent@wanadoo.fr>


^ permalink raw reply	[flat|nested] 56+ messages in thread
* Re: [PATCH v4 3/8] bits: introduce fixed-type genmasks
@ 2025-03-18 23:18 kernel test robot
  0 siblings, 0 replies; 56+ messages in thread
From: kernel test robot @ 2025-03-18 23:18 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp

:::::: 
:::::: Manual check reason: "low confidence static check first_new_problem: arch/arm/kernel/cacheinfo.c:47:21: sparse: sparse: trying to concatenate 9586-character string (8191 bytes max)"
:::::: 

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20250305-fixed-type-genmasks-v4-3-1873dcdf6723@wanadoo.fr>
References: <20250305-fixed-type-genmasks-v4-3-1873dcdf6723@wanadoo.fr>
TO: Vincent Mailhol via B4 Relay <devnull+mailhol.vincent.wanadoo.fr@kernel.org>

Hi Vincent,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 7eb172143d5508b4da468ed59ee857c6e5e01da6]

url:    https://github.com/intel-lab-lkp/linux/commits/Vincent-Mailhol-via-B4-Relay/bits-fix-typo-unsigned-__init128-unsigned-__int128/20250305-210248
base:   7eb172143d5508b4da468ed59ee857c6e5e01da6
patch link:    https://lore.kernel.org/r/20250305-fixed-type-genmasks-v4-3-1873dcdf6723%40wanadoo.fr
patch subject: [PATCH v4 3/8] bits: introduce fixed-type genmasks
:::::: branch date: 13 days ago
:::::: commit date: 13 days ago
config: arm-randconfig-r122-20250318 (https://download.01.org/0day-ci/archive/20250319/202503190705.CNDxMfGV-lkp@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 14.2.0
reproduce: (https://download.01.org/0day-ci/archive/20250319/202503190705.CNDxMfGV-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/r/202503190705.CNDxMfGV-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
>> arch/arm/kernel/cacheinfo.c:47:21: sparse: sparse: trying to concatenate 9586-character string (8191 bytes max)

vim +47 arch/arm/kernel/cacheinfo.c

a9ff94477836cb Dmitry Baryshkov 2025-01-14  32  
a9ff94477836cb Dmitry Baryshkov 2025-01-14  33  /* Also valid for v7m */
a9ff94477836cb Dmitry Baryshkov 2025-01-14  34  static inline int cache_line_size_cp15(void)
a9ff94477836cb Dmitry Baryshkov 2025-01-14  35  {
a9ff94477836cb Dmitry Baryshkov 2025-01-14  36  	u32 ctr = read_cpuid_cachetype();
a9ff94477836cb Dmitry Baryshkov 2025-01-14  37  	u32 format = FIELD_GET(CTR_FORMAT_MASK, ctr);
a9ff94477836cb Dmitry Baryshkov 2025-01-14  38  
a9ff94477836cb Dmitry Baryshkov 2025-01-14  39  	if (format == CTR_FORMAT_ARMV7) {
a9ff94477836cb Dmitry Baryshkov 2025-01-14  40  		u32 cwg = FIELD_GET(CTR_CWG_MASK, ctr);
a9ff94477836cb Dmitry Baryshkov 2025-01-14  41  
a9ff94477836cb Dmitry Baryshkov 2025-01-14  42  		return cwg ? 4 << cwg : ARCH_DMA_MINALIGN;
a9ff94477836cb Dmitry Baryshkov 2025-01-14  43  	} else if (WARN_ON_ONCE(format != CTR_FORMAT_ARMV6)) {
a9ff94477836cb Dmitry Baryshkov 2025-01-14  44  		return ARCH_DMA_MINALIGN;
a9ff94477836cb Dmitry Baryshkov 2025-01-14  45  	}
a9ff94477836cb Dmitry Baryshkov 2025-01-14  46  
a9ff94477836cb Dmitry Baryshkov 2025-01-14 @47  	return 8 << max(FIELD_GET(CTR_ISIZE_LEN_MASK, ctr),
a9ff94477836cb Dmitry Baryshkov 2025-01-14  48  			FIELD_GET(CTR_DSIZE_LEN_MASK, ctr));
a9ff94477836cb Dmitry Baryshkov 2025-01-14  49  }
a9ff94477836cb Dmitry Baryshkov 2025-01-14  50  

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

^ permalink raw reply	[flat|nested] 56+ messages in thread

end of thread, other threads:[~2025-03-24 13:24 UTC | newest]

Thread overview: 56+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-05 13:00 [PATCH v4 0/8] bits: Fixed-type GENMASK()/BIT() Vincent Mailhol
2025-03-05 13:00 ` Vincent Mailhol via B4 Relay
2025-03-05 13:00 ` [PATCH v4 1/8] bits: fix typo 'unsigned __init128' -> 'unsigned __int128' Vincent Mailhol
2025-03-05 13:00   ` Vincent Mailhol via B4 Relay
2025-03-05 14:30   ` Yury Norov
2025-03-05 14:36     ` Andy Shevchenko
2025-03-05 14:38       ` Yury Norov
2025-03-05 16:09         ` Vincent Mailhol
2025-03-05 14:34   ` Andy Shevchenko
2025-03-05 13:00 ` [PATCH v4 2/8] bits: split the definition of the asm and non-asm GENMASK() Vincent Mailhol
2025-03-05 13:00   ` Vincent Mailhol via B4 Relay
2025-03-05 13:00 ` [PATCH v4 3/8] bits: introduce fixed-type genmasks Vincent Mailhol
2025-03-05 13:00   ` Vincent Mailhol via B4 Relay
2025-03-05 14:30   ` Andy Shevchenko
2025-03-05 14:38     ` Vincent Mailhol
2025-03-05 14:41       ` Andy Shevchenko
2025-03-06 14:48       ` Lucas De Marchi
2025-03-05 15:22   ` Yury Norov
2025-03-05 15:50     ` Andy Shevchenko
2025-03-19  1:46     ` Yury Norov
2025-03-19  3:34       ` Anshuman Khandual
2025-03-19  4:13         ` Anshuman Khandual
2025-03-21 17:05           ` Yury Norov
2025-03-22 11:46             ` Vincent Mailhol
2025-03-05 15:47   ` Yury Norov
2025-03-05 15:52     ` Jani Nikula
2025-03-05 16:48     ` Vincent Mailhol
2025-03-05 19:45       ` Andy Shevchenko
2025-03-06  9:22         ` Vincent Mailhol
2025-03-06  9:28           ` Andy Shevchenko
2025-03-05 13:00 ` [PATCH v4 4/8] bits: introduce fixed-type BIT Vincent Mailhol
2025-03-05 13:00   ` Vincent Mailhol via B4 Relay
2025-03-05 14:33   ` Andy Shevchenko
2025-03-05 14:48     ` Vincent Mailhol
2025-03-05 15:48       ` Andy Shevchenko
2025-03-05 17:17         ` Vincent Mailhol
2025-03-05 19:56           ` Andy Shevchenko
2025-03-05 21:50             ` David Laight
2025-03-06  8:12               ` Jani Nikula
2025-03-06  9:12               ` Andy Shevchenko
2025-03-06  9:38                 ` Vincent Mailhol
2025-03-05 21:13         ` David Laight
2025-03-05 13:00 ` [PATCH v4 5/8] drm/i915: Convert REG_GENMASK* to fixed-width GENMASK_* Vincent Mailhol
2025-03-05 13:00   ` Vincent Mailhol via B4 Relay
2025-03-05 14:37   ` Andy Shevchenko
2025-03-05 13:00 ` [PATCH v4 6/8] test_bits: add tests for __GENMASK() and __GENMASK_ULL() Vincent Mailhol
2025-03-05 13:00   ` Vincent Mailhol via B4 Relay
2025-03-05 13:00 ` [PATCH v4 7/8] test_bits: add tests for fixed-type genmasks Vincent Mailhol
2025-03-05 13:00   ` Vincent Mailhol via B4 Relay
2025-03-05 13:00 ` [PATCH v4 8/8] test_bits: add tests for fixed-type BIT Vincent Mailhol
2025-03-05 13:00   ` Vincent Mailhol via B4 Relay
2025-03-05 15:59 ` [PATCH v4 0/8] bits: Fixed-type GENMASK()/BIT() Jani Nikula
2025-03-07 16:07 ` ✗ Fi.CI.CHECKPATCH: warning for bits: Fixed-type GENMASK()/BIT() (rev2) Patchwork
2025-03-07 16:07 ` ✗ Fi.CI.SPARSE: " Patchwork
2025-03-07 16:32 ` ✓ i915.CI.BAT: success " Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2025-03-18 23:18 [PATCH v4 3/8] bits: introduce fixed-type genmasks kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.