diff options
| author | Konstantin Belousov <kib@FreeBSD.org> | 2026-04-18 18:42:56 +0000 |
|---|---|---|
| committer | Konstantin Belousov <kib@FreeBSD.org> | 2026-04-20 17:42:28 +0000 |
| commit | 950fd59955e10429c1325c327f0141a7e97fcfe5 (patch) | |
| tree | 03a4d5b12dba84405db76c20607b906618d24b03 | |
| parent | 9b844b495e8e63439ffe523757ac7444a16317af (diff) | |
membarrier(2): use atomic for lockless read of curproc->p_flag2
Reviewed by: markj, Ricardo Branco <rbranco@suse.com>
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D56507
| -rw-r--r-- | sys/kern/kern_membarrier.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/sys/kern/kern_membarrier.c b/sys/kern/kern_membarrier.c index f0660bd7360e..6d210a1b1783 100644 --- a/sys/kern/kern_membarrier.c +++ b/sys/kern/kern_membarrier.c @@ -120,7 +120,7 @@ kern_membarrier(struct thread *td, int cmd, unsigned flags, int cpu_id) struct thread *td1; cpuset_t cs; uint64_t *swt; - int c, error; + int c, error, f; bool first; if (flags != 0 || (cmd & ~MEMBARRIER_SUPPORTED_CMDS) != 0) @@ -133,6 +133,7 @@ kern_membarrier(struct thread *td, int cmd, unsigned flags, int cpu_id) p = td->td_proc; error = 0; + f = atomic_load_int(&td->td_proc->p_flag2); switch (cmd) { case MEMBARRIER_CMD_GLOBAL: @@ -155,7 +156,7 @@ kern_membarrier(struct thread *td, int cmd, unsigned flags, int cpu_id) break; case MEMBARRIER_CMD_GLOBAL_EXPEDITED: - if ((td->td_proc->p_flag2 & P2_MEMBAR_GLOBE) == 0) { + if ((f & P2_MEMBAR_GLOBE) == 0) { error = EPERM; } else { CPU_ZERO(&cs); @@ -171,7 +172,7 @@ kern_membarrier(struct thread *td, int cmd, unsigned flags, int cpu_id) break; case MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED: - if ((p->p_flag2 & P2_MEMBAR_GLOBE) == 0) { + if ((f & P2_MEMBAR_GLOBE) == 0) { PROC_LOCK(p); p->p_flag2 |= P2_MEMBAR_GLOBE; PROC_UNLOCK(p); @@ -179,7 +180,7 @@ kern_membarrier(struct thread *td, int cmd, unsigned flags, int cpu_id) break; case MEMBARRIER_CMD_PRIVATE_EXPEDITED: - if ((td->td_proc->p_flag2 & P2_MEMBAR_PRIVE) == 0) { + if ((f & P2_MEMBAR_PRIVE) == 0) { error = EPERM; } else { pmap_active_cpus(vmspace_pmap(p->p_vmspace), &cs); @@ -188,7 +189,7 @@ kern_membarrier(struct thread *td, int cmd, unsigned flags, int cpu_id) break; case MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED: - if ((p->p_flag2 & P2_MEMBAR_PRIVE) == 0) { + if ((f & P2_MEMBAR_PRIVE) == 0) { PROC_LOCK(p); p->p_flag2 |= P2_MEMBAR_PRIVE; PROC_UNLOCK(p); @@ -196,7 +197,7 @@ kern_membarrier(struct thread *td, int cmd, unsigned flags, int cpu_id) break; case MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE: - if ((td->td_proc->p_flag2 & P2_MEMBAR_PRIVE_SYNCORE) == 0) { + if ((f & P2_MEMBAR_PRIVE_SYNCORE) == 0) { error = EPERM; } else { /* |
