Skip to contentSkip to conversation

cleanup dead code in nodemasks and cpumasks

PATCH In review Yury Norov 1 participant 6 messages Mar 13, 2025 – Mar 24, 2025

Subsystems (2)
lore
Share & tools
lore

Yury Norov

author maintainer
#0 lore raw

cover cleanup dead code in nodemasks and cpumasks

Cleanup dead code in nodemasks and cpumasks, and while there, fix set_icache_stale_mask() that misuses atomic cpumask_assign_cpu().

Yury Norov (4):
nodemask: drop nodes_shift
cpumask: add non-atomic __assign_cpu()
riscv: switch set_icache_stale_mask() to using non-atomic assign_cpu()
cpumask: drop cpumask_assign_cpu()

 arch/riscv/mm/cacheflush.c |  2 +-
 include/linux/cpumask.h    | 19 +++----------------
 include/linux/nodemask.h   | 19 -------------------
 3 files changed, 4 insertions(+), 36 deletions(-)
Signature · 1 line
2.43.0
author maintainer
#1 lore raw

PATCH 1/4 nodemask: drop nodes_shift

nodes_shift_{left,right} are not used. Drop them.

---
 include/linux/nodemask.h | 19 -------------------
 1 file changed, 19 deletions(-)
include/linux/nodemask.h +0 -19
index 9fd7a0ce9c1a..b1a26ef5912e 100644
@@ -39,9 +39,6 @@
  * int nodes_full(mask)			Is mask full (all bits sets)?
  * int nodes_weight(mask)		Hamming weight - number of set bits
  *
- * void nodes_shift_right(dst, src, n)	Shift right
- * void nodes_shift_left(dst, src, n)	Shift left
- *
  * unsigned int first_node(mask)	Number lowest set bit, or MAX_NUMNODES
  * unsigend int next_node(node, mask)	Next node past 'node', or MAX_NUMNODES
  * unsigned int next_node_in(node, mask) Next node past 'node', or wrap to first,
@@ -241,22 +238,6 @@ static __always_inline int __nodes_weight(const nodemask_t *srcp, unsigned int n
 	return bitmap_weight(srcp->bits, nbits);
 }
 
-#define nodes_shift_right(dst, src, n) \
-			__nodes_shift_right(&(dst), &(src), (n), MAX_NUMNODES)
-static __always_inline void __nodes_shift_right(nodemask_t *dstp,
-					const nodemask_t *srcp, int n, int nbits)
-{
-	bitmap_shift_right(dstp->bits, srcp->bits, n, nbits);
-}
-
-#define nodes_shift_left(dst, src, n) \
-			__nodes_shift_left(&(dst), &(src), (n), MAX_NUMNODES)
-static __always_inline void __nodes_shift_left(nodemask_t *dstp,
-					const nodemask_t *srcp, int n, int nbits)
-{
-	bitmap_shift_left(dstp->bits, srcp->bits, n, nbits);
-}
-
 /* FIXME: better would be to fix all architectures to never return
           > MAX_NUMNODES, then the silly min_ts could be dropped. */
 
Signature · 1 line
2.43.0
author maintainer
#2 lore raw

PATCH 2/4 cpumask: add non-atomic __assign_cpu()

In reply to Yury Norov

Similarly to atomic, add a non-atomic version.

---
 include/linux/cpumask.h | 3 +++
 1 file changed, 3 insertions(+)
include/linux/cpumask.h +3 -0
index 9289d4612170..f8caa025c6bb 100644
@@ -1074,6 +1074,9 @@ void init_cpu_possible(const struct cpumask *src);
 #define assign_cpu(cpu, mask, val)	\
 	assign_bit(cpumask_check(cpu), cpumask_bits(mask), (val))
 
+#define __assign_cpu(cpu, mask, val)	\
+	__assign_bit(cpumask_check(cpu), cpumask_bits(mask), (val))
+
 #define set_cpu_possible(cpu, possible)	assign_cpu((cpu), &__cpu_possible_mask, (possible))
 #define set_cpu_enabled(cpu, enabled)	assign_cpu((cpu), &__cpu_enabled_mask, (enabled))
 #define set_cpu_present(cpu, present)	assign_cpu((cpu), &__cpu_present_mask, (present))
Signature · 1 line
2.43.0
author maintainer
#3 lore raw

PATCH 3/4 riscv: switch set_icache_stale_mask() to using non-atomic assign_cpu()

In reply to Yury Norov

The atomic cpumask_assign_cpu() follows non-atomic cpumask_setall(), which makes the whole operation non-atomic. Fix this by relaxing to non-atomic __assign_cpu().

Fixes 7c1e5b9690b0e14 ("riscv: Disable preemption while handling PR_RISCV_CTX_SW_FENCEI_OFF")
---
 arch/riscv/mm/cacheflush.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/mm/cacheflush.c +1 -1
index b81672729887..b8e96dfff19d 100644
@@ -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
Signature · 1 line
2.43.0
author maintainer
#4 lore raw

PATCH 4/4 cpumask: drop cpumask_assign_cpu()

In reply to Yury Norov

Commit decde1fa209323c7 ("cpumask: Add assign cpu") was merged bypassing cpumasks reviewers. It adds atomic and non-atomic cpumask_assign_cpu() helpers.

In the same merge window, commit 5c563ee90a22d3 ("cpumask: introduce assign_cpu() macro") added the same functionality. So now we have it duplicated.

__cpumask_assign_cpu() has never been used since introducing, and because this series reworks the only user of cpumask_assign_cpu(), both functions become a dead code.

---
 include/linux/cpumask.h | 16 ----------------
 1 file changed, 16 deletions(-)
include/linux/cpumask.h +0 -16
index f8caa025c6bb..ddeefb2744b1 100644
@@ -558,22 +558,6 @@ static __always_inline void __cpumask_clear_cpu(int cpu, struct cpumask *dstp)
 	__clear_bit(cpumask_check(cpu), cpumask_bits(dstp));
 }
 
-/**
- * cpumask_assign_cpu - assign a cpu in a cpumask
- * @cpu: cpu number (< nr_cpu_ids)
- * @dstp: the cpumask pointer
- * @bool: the value to assign
- */
-static __always_inline void cpumask_assign_cpu(int cpu, struct cpumask *dstp, bool value)
-{
-	assign_bit(cpumask_check(cpu), cpumask_bits(dstp), value);
-}
-
-static __always_inline void __cpumask_assign_cpu(int cpu, struct cpumask *dstp, bool value)
-{
-	__assign_bit(cpumask_check(cpu), cpumask_bits(dstp), value);
-}
-
 /**
  * cpumask_test_cpu - test for a cpu in a cpumask
  * @cpu: cpu number (< nr_cpu_ids)
Signature · 1 line
2.43.0
author maintainer
#5 lore raw
In reply to Yury Norov

Ping?

If no objections, I'll schedule it for 6.15.

Quoted 16 lines · Yury Norov

Cleanup dead code in nodemasks and cpumasks, and while there, fix set_icache_stale_mask() that misuses atomic cpumask_assign_cpu().

Yury Norov (4):
nodemask: drop nodes_shift
cpumask: add non-atomic __assign_cpu()
riscv: switch set_icache_stale_mask() to using non-atomic assign_cpu()
cpumask: drop cpumask_assign_cpu()

 arch/riscv/mm/cacheflush.c |  2 +-
 include/linux/cpumask.h    | 19 +++----------------
 include/linux/nodemask.h   | 19 -------------------
 3 files changed, 4 insertions(+), 36 deletions(-)
Signature · 1 line
2.43.0