Commit 8b2198f0 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'bitmap-for-6.16-rc1' of https://github.com/norov/linux

Pull bitmap updates from Yury Norov:

 - dead code cleanups for cpumasks and nodemasks (me)

 - fixed-width flavors of GENMASK() and BIT() (Vincent, Lucas and me)

 - FIELD_MODIFY() helper (Luo)

 - for_each_node_with_cpus() optimization (me)

 - bitmap-str fixes (Andy)

* tag 'bitmap-for-6.16-rc1' of https://github.com/norov/linux:
  topology: make for_each_node_with_cpus() O(N)
  bitfield: Add FIELD_MODIFY() helper
  bitmap-str: Add missing header(s)
  bitmap-str: Get rid of 'extern' for function prototypes
  build_bug.h: more user friendly error messages in BUILD_BUG_ON_ZERO()
  test_bits: add tests for BIT_U*()
  test_bits: add tests for GENMASK_U*()
  drm/i915: Convert REG_GENMASK*() to fixed-width GENMASK_U*()
  bits: introduce fixed-type BIT_U*()
  bits: introduce fixed-type GENMASK_U*()
  bits: add comments and newlines to #if, #else and #endif directives
  cpumask: drop cpumask_assign_cpu()
  riscv: switch set_icache_stale_mask() to using non-atomic assign_cpu()
  cpumask: add non-atomic __assign_cpu()
  nodemask: drop nodes_shift
parents 546b1c9e 895ee6a2
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -172,7 +172,7 @@ static void set_icache_stale_mask(void)
	stale_cpu = cpumask_test_cpu(cpu, mask);

	cpumask_setall(mask);
	cpumask_assign_cpu(cpu, mask, stale_cpu);
	__assign_cpu(cpu, mask, stale_cpu);
	put_cpu();
}
#endif
+11 −97
Original line number Diff line number Diff line
@@ -9,76 +9,19 @@
#include <linux/bitfield.h>
#include <linux/bits.h>

/**
 * REG_BIT() - Prepare a u32 bit value
 * @__n: 0-based bit number
 *
 * Local wrapper for BIT() to force u32, with compile time checks.
 *
 * @return: Value with bit @__n set.
 */
#define REG_BIT(__n)							\
	((u32)(BIT(__n) +						\
	       BUILD_BUG_ON_ZERO(__is_constexpr(__n) &&		\
				 ((__n) < 0 || (__n) > 31))))

/**
 * REG_BIT8() - Prepare a u8 bit value
 * @__n: 0-based bit number
 *
 * Local wrapper for BIT() to force u8, with compile time checks.
 *
 * @return: Value with bit @__n set.
 */
#define REG_BIT8(__n)                                                   \
	((u8)(BIT(__n) +                                                \
	       BUILD_BUG_ON_ZERO(__is_constexpr(__n) &&         \
				 ((__n) < 0 || (__n) > 7))))

/**
 * REG_GENMASK() - Prepare a continuous u32 bitmask
 * @__high: 0-based high bit
 * @__low: 0-based low bit
 *
 * Local wrapper for GENMASK() to force u32, with compile time checks.
 *
 * @return: Continuous bitmask from @__high to @__low, inclusive.
 */
#define REG_GENMASK(__high, __low)					\
	((u32)(GENMASK(__high, __low) +					\
	       BUILD_BUG_ON_ZERO(__is_constexpr(__high) &&	\
				 __is_constexpr(__low) &&		\
				 ((__low) < 0 || (__high) > 31 || (__low) > (__high)))))

/**
 * REG_GENMASK64() - Prepare a continuous u64 bitmask
 * @__high: 0-based high bit
 * @__low: 0-based low bit
 *
 * Local wrapper for GENMASK_ULL() to force u64, with compile time checks.
 *
 * @return: Continuous bitmask from @__high to @__low, inclusive.
/*
 * Wrappers over the generic fixed width BIT_U*() and GENMASK_U*()
 * implementations, for compatibility reasons with previous implementation.
 */
#define REG_GENMASK64(__high, __low)					\
	((u64)(GENMASK_ULL(__high, __low) +				\
	       BUILD_BUG_ON_ZERO(__is_constexpr(__high) &&		\
				 __is_constexpr(__low) &&		\
				 ((__low) < 0 || (__high) > 63 || (__low) > (__high)))))
#define REG_GENMASK(high, low)		GENMASK_U32(high, low)
#define REG_GENMASK64(high, low)	GENMASK_U64(high, low)
#define REG_GENMASK16(high, low)	GENMASK_U16(high, low)
#define REG_GENMASK8(high, low)		GENMASK_U8(high, low)

/**
 * REG_GENMASK8() - Prepare a continuous u8 bitmask
 * @__high: 0-based high bit
 * @__low: 0-based low bit
 *
 * Local wrapper for GENMASK() to force u8, with compile time checks.
 *
 * @return: Continuous bitmask from @__high to @__low, inclusive.
 */
#define REG_GENMASK8(__high, __low)                                     \
	((u8)(GENMASK(__high, __low) +                                  \
	       BUILD_BUG_ON_ZERO(__is_constexpr(__high) &&      \
				 __is_constexpr(__low) &&               \
				 ((__low) < 0 || (__high) > 7 || (__low) > (__high)))))
#define REG_BIT(n)			BIT_U32(n)
#define REG_BIT64(n)			BIT_U64(n)
#define REG_BIT16(n)			BIT_U16(n)
#define REG_BIT8(n)			BIT_U8(n)

/*
 * Local integer constant expression version of is_power_of_2().
@@ -143,35 +86,6 @@
 */
#define REG_FIELD_GET64(__mask, __val)	((u64)FIELD_GET(__mask, __val))

/**
 * REG_BIT16() - Prepare a u16 bit value
 * @__n: 0-based bit number
 *
 * Local wrapper for BIT() to force u16, with compile time
 * checks.
 *
 * @return: Value with bit @__n set.
 */
#define REG_BIT16(__n)                                                   \
	((u16)(BIT(__n) +                                                \
	       BUILD_BUG_ON_ZERO(__is_constexpr(__n) &&         \
				 ((__n) < 0 || (__n) > 15))))

/**
 * REG_GENMASK16() - Prepare a continuous u8 bitmask
 * @__high: 0-based high bit
 * @__low: 0-based low bit
 *
 * Local wrapper for GENMASK() to force u16, with compile time
 * checks.
 *
 * @return: Continuous bitmask from @__high to @__low, inclusive.
 */
#define REG_GENMASK16(__high, __low)                                     \
	((u16)(GENMASK(__high, __low) +                                  \
	       BUILD_BUG_ON_ZERO(__is_constexpr(__high) &&      \
				 __is_constexpr(__low) &&               \
				 ((__low) < 0 || (__high) > 15 || (__low) > (__high)))))

/**
 * REG_FIELD_PREP16() - Prepare a u16 bitfield value
+19 −2
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
#define _LINUX_BITFIELD_H

#include <linux/build_bug.h>
#include <linux/typecheck.h>
#include <asm/byteorder.h>

/*
@@ -38,8 +39,7 @@
 *	  FIELD_PREP(REG_FIELD_D, 0x40);
 *
 * Modify:
 *  reg &= ~REG_FIELD_C;
 *  reg |= FIELD_PREP(REG_FIELD_C, c);
 *  FIELD_MODIFY(REG_FIELD_C, &reg, c);
 */

#define __bf_shf(x) (__builtin_ffsll(x) - 1)
@@ -156,6 +156,23 @@
		(typeof(_mask))(((_reg) & (_mask)) >> __bf_shf(_mask));	\
	})

/**
 * FIELD_MODIFY() - modify a bitfield element
 * @_mask: shifted mask defining the field's length and position
 * @_reg_p: pointer to the memory that should be updated
 * @_val: value to store in the bitfield
 *
 * FIELD_MODIFY() modifies the set of bits in @_reg_p specified by @_mask,
 * by replacing them with the bitfield value passed in as @_val.
 */
#define FIELD_MODIFY(_mask, _reg_p, _val)						\
	({										\
		typecheck_pointer(_reg_p);						\
		__BF_FIELD_CHECK(_mask, *(_reg_p), _val, "FIELD_MODIFY: ");		\
		*(_reg_p) &= ~(_mask);							\
		*(_reg_p) |= (((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask));	\
	})

extern void __compiletime_error("value doesn't fit into mask")
__field_overflow(void);
extern void __compiletime_error("bad bitfield mask")
+6 −4
Original line number Diff line number Diff line
@@ -2,12 +2,14 @@
#ifndef __LINUX_BITMAP_STR_H
#define __LINUX_BITMAP_STR_H

#include <linux/types.h>

int bitmap_parse_user(const char __user *ubuf, unsigned int ulen, unsigned long *dst, int nbits);
int bitmap_print_to_pagebuf(bool list, char *buf, const unsigned long *maskp, int nmaskbits);
extern int bitmap_print_bitmask_to_buf(char *buf, const unsigned long *maskp,
					int nmaskbits, loff_t off, size_t count);
extern int bitmap_print_list_to_buf(char *buf, const unsigned long *maskp,
					int nmaskbits, loff_t off, size_t count);
int bitmap_print_bitmask_to_buf(char *buf, const unsigned long *maskp, int nmaskbits,
				loff_t off, size_t count);
int bitmap_print_list_to_buf(char *buf, const unsigned long *maskp, int nmaskbits,
			     loff_t off, size_t count);
int bitmap_parse(const char *buf, unsigned int buflen, unsigned long *dst, int nbits);
int bitmap_parselist(const char *buf, unsigned long *maskp, int nmaskbits);
int bitmap_parselist_user(const char __user *ubuf, unsigned int ulen,
+0 −1
Original line number Diff line number Diff line
@@ -8,7 +8,6 @@

#include <uapi/linux/kernel.h>

#define BITS_PER_TYPE(type)	(sizeof(type) * BITS_PER_BYTE)
#define BITS_TO_LONGS(nr)	__KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(long))
#define BITS_TO_U64(nr)		__KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(u64))
#define BITS_TO_U32(nr)		__KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(u32))
Loading