]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
riscv: Fix another race in pmap_pinit()
authorMark Johnston <markj@FreeBSD.org>
Tue, 22 Feb 2022 14:26:33 +0000 (09:26 -0500)
committerMark Johnston <markj@FreeBSD.org>
Tue, 1 Mar 2022 15:17:40 +0000 (10:17 -0500)
commit302c426103379da3d7bdd4bafff4ada807e2ffbb
tree7e28b21366d7b631270cc6c5eafd0f580c15dbd3
parent15a16379453983788fdcb030006b59ff4807f61f
riscv: Fix another race in pmap_pinit()

Commit c862d5f2a789 ("riscv: Fix a race in pmap_pinit()") did not really
fix the race.  Alan writes,

 Suppose that N entries in the L1 tables are in use, and we are in the
 middle of the memcpy().  Specifically, we have read the zero-filled
 (N+1)st entry from the kernel L1 table.  Then, we are preempted.  Now,
 another core/thread does pmap_growkernel(), which fills the (N+1)st
 entry.  Finally, we return to the original core/thread, and overwrite
 the valid entry with the zero that we earlier read.

Try to fix the race properly, by copying kernel L1 entries while holding
the allpmaps lock.  To avoid doing unnecessary work while holding this
global lock, copy only the entries that we expect to be valid.

Fixes: c862d5f2a789 ("riscv: Fix a race in pmap_pinit()")
Reported by: alc, jrtc27
Reviewed by: alc
Sponsored by: The FreeBSD Foundation

(cherry picked from commit d5c0a7b6d3923d2a6967810d0aa3e148a39351c1)
sys/riscv/riscv/pmap.c