git: a94baf23cf61 - stable/13 - Restore variable aliasing in the context of cpu set operations

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Fri, 14 Jan 2022 18:10:34 UTC
The branch stable/13 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=a94baf23cf612b06bfe97ab35627391c64e13c4e

commit a94baf23cf612b06bfe97ab35627391c64e13c4e
Author:     Stefan Eßer <se@FreeBSD.org>
AuthorDate: 2022-01-01 10:41:54 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-01-14 16:17:31 +0000

    Restore variable aliasing in the context of cpu set operations
    
    (cherry picked from commit a19bd8e30eba1673782376a93e9787ed9b490e4e)
---
 sys/kern/kern_rmlock.c | 3 ++-
 sys/kern/sched_4bsd.c  | 6 ++++--
 sys/kern/subr_kdb.c    | 3 ++-
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/sys/kern/kern_rmlock.c b/sys/kern/kern_rmlock.c
index 5e64f79e3836..08a01fca9827 100644
--- a/sys/kern/kern_rmlock.c
+++ b/sys/kern/kern_rmlock.c
@@ -548,7 +548,8 @@ _rm_wlock(struct rmlock *rm)
 
 	if (CPU_CMP(&rm->rm_writecpus, &all_cpus)) {
 		/* Get all read tokens back */
-		CPU_ANDNOT(&readcpus, &all_cpus, &rm->rm_writecpus);
+		readcpus = all_cpus;
+		CPU_ANDNOT(&readcpus, &readcpus, &rm->rm_writecpus);
 		rm->rm_writecpus = all_cpus;
 
 		/*
diff --git a/sys/kern/sched_4bsd.c b/sys/kern/sched_4bsd.c
index 7e6fe03c80e4..3d99d3aca0e2 100644
--- a/sys/kern/sched_4bsd.c
+++ b/sys/kern/sched_4bsd.c
@@ -1172,7 +1172,8 @@ forward_wakeup(int cpunum)
 	}
 
 	if (forward_wakeup_use_mask) {
-		CPU_ANDNOT(&map, &idle_cpus_mask, &dontuse);
+		map = idle_cpu_mask;
+		CPU_ANDNOT(&map, &map, &dontuse);
 
 		/* If they are both on, compare and use loop if different. */
 		if (forward_wakeup_use_loop) {
@@ -1358,7 +1359,8 @@ sched_add(struct thread *td, int flags)
 	        kick_other_cpu(td->td_priority, cpu);
 	} else {
 		if (!single_cpu) {
-			CPU_ANDNOT(&tidlemsk, &idle_cpus_mask, &hlt_cpus_mask);
+			tidlemsk = idle_cpus_mask;
+			CPU_ANDNOT(&tidlemsk, &tidlemsk, &hlt_cpus_mask);
 			CPU_CLR(cpuid, &tidlemsk);
 
 			if (!CPU_ISSET(cpuid, &idle_cpus_mask) &&
diff --git a/sys/kern/subr_kdb.c b/sys/kern/subr_kdb.c
index 2218c20586f2..14a0205fc098 100644
--- a/sys/kern/subr_kdb.c
+++ b/sys/kern/subr_kdb.c
@@ -707,7 +707,8 @@ kdb_trap(int type, int code, struct trapframe *tf)
 
 	if (!SCHEDULER_STOPPED()) {
 #ifdef SMP
-		CPU_ANDNOT(&other_cpus, &all_cpus, &stopped_cpus);
+		other_cpus = all_cpus;
+		CPU_ANDNOT(&other_cpus, &other_cpus, &stopped_cpus);
 		CPU_CLR(PCPU_GET(cpuid), &other_cpus);
 		stop_cpus_hard(other_cpus);
 #endif